Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 Sep 2025 16:21:51 -0400
From:      Justin Hibbits <chmeee@has.gonegalt.net>
To:        Konstantin Belousov <kib@FreeBSD.org>
Cc:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   Re: git: b31abc95eb73 - main - arm, powerpc, riscv: implement  atomic_set/clear_16
Message-ID:  <20250920162151.05aad15b@ralga.knownspace>
In-Reply-To: <202509201934.58KJYO0O040235@gitrepo.freebsd.org>
References:  <202509201934.58KJYO0O040235@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 20 Sep 2025 19:34:24 GMT
Konstantin Belousov <kib@FreeBSD.org> wrote:

> The branch main has been updated by kib:
> 
> URL:
> https://cgit.FreeBSD.org/src/commit/?id=b31abc95eb730d566891e134ba14af852645f772
> 
> commit b31abc95eb730d566891e134ba14af852645f772
> Author:     Konstantin Belousov <kib@FreeBSD.org>
> AuthorDate: 2025-09-19 18:01:47 +0000
> Commit:     Konstantin Belousov <kib@FreeBSD.org>
> CommitDate: 2025-09-20 19:23:54 +0000
> 
>     arm, powerpc, riscv: implement atomic_set/clear_16
>     
>     Reviewed by:    jrtc27, markj
>     Sponsored by:   The FreeBSD Foundation
>     MFC after:      1 week
>     Differential revision:  https://reviews.freebsd.org/D52626
> ---
>  sys/arm/include/atomic.h     |  3 +++
>  sys/powerpc/include/atomic.h | 33 ++++++++++++++++++++++++++++++++-
>  sys/riscv/include/atomic.h   |  3 +++
>  sys/sys/_atomic_subword.h    | 28 ++++++++++++++++++++++++++++
>  4 files changed, 66 insertions(+), 1 deletion(-)
> 
> diff --git a/sys/arm/include/atomic.h b/sys/arm/include/atomic.h
> index f3313b136656..c180ceaca142 100644
> --- a/sys/arm/include/atomic.h
> +++ b/sys/arm/include/atomic.h
> @@ -1110,4 +1110,7 @@ atomic_thread_fence_seq_cst(void)
>   */
>  #include <sys/_atomic_subword.h>
>  
> +#define	atomic_set_short		atomic_set_16
> +#define	atomic_clear_short		atomic_clear_16
> +
>  #endif /* _MACHINE_ATOMIC_H_ */
> diff --git a/sys/powerpc/include/atomic.h
> b/sys/powerpc/include/atomic.h index 015a283e2de7..b2d7549e5bd0 100644
> --- a/sys/powerpc/include/atomic.h
> +++ b/sys/powerpc/include/atomic.h
> @@ -1137,7 +1137,38 @@ atomic_thread_fence_seq_cst(void)
>  #define	atomic_cmpset_short	atomic_cmpset_16
>  #define	atomic_fcmpset_char	atomic_fcmpset_8
>  #define	atomic_fcmpset_short	atomic_fcmpset_16
> -#endif
> +#define	atomic_set_short	atomic_set_16
> +#define	atomic_clear_short	atomic_clear_16
> +#else
> +
> +static __inline void
> +atomic_set_short(volatile u_short *p, u_short bit)
> +{
> +	u_short v;
> +
> +	v = atomic_load_short(p);
> +	for (;;) {
> +		if (atomic_fcmpset_16(p, &v, v | bit))
> +			break;
> +	}
> +}
> +
> +static __inline void
> +atomic_clear_short(volatile u_short *p, u_short bit)
> +{
> +	u_short v;
> +
> +	v = atomic_load_short(p);
> +	for (;;) {
> +		if (atomic_fcmpset_16(p, &v, v & ~bit))
> +			break;
> +	}
> +}
> +
> +#define	atomic_set_16		atomic_set_short
> +#define	atomic_clear_16		atomic_clear_short
> +
> +#endif	/* ISA_206_ATOMICS */
>  
>  /* These need sys/_atomic_subword.h on non-ISA-2.06-atomic
> platforms. */ ATOMIC_CMPSET_ACQ_REL(char);
> diff --git a/sys/riscv/include/atomic.h b/sys/riscv/include/atomic.h
> index 74ffc171b028..c90cb02c482c 100644
> --- a/sys/riscv/include/atomic.h
> +++ b/sys/riscv/include/atomic.h
> @@ -656,4 +656,7 @@ atomic_thread_fence_seq_cst(void)
>  
>  #include <sys/_atomic_subword.h>
>  
> +#define	atomic_set_short		atomic_set_16
> +#define	atomic_clear_short		atomic_clear_16
> +
>  #endif /* _MACHINE_ATOMIC_H_ */
> diff --git a/sys/sys/_atomic_subword.h b/sys/sys/_atomic_subword.h
> index dee5a3bed871..284e2bfa340f 100644
> --- a/sys/sys/_atomic_subword.h
> +++ b/sys/sys/_atomic_subword.h
> @@ -205,4 +205,32 @@ atomic_load_acq_16(const volatile uint16_t *p)
>  #undef _ATOMIC_BYTE_SHIFT
>  #undef _ATOMIC_HWORD_SHIFT
>  
> +#ifndef atomic_set_16
> +static __inline void
> +atomic_set_16(volatile uint16_t *p, uint16_t bit)
> +{
> +	uint16_t v;
> +
> +	v = atomic_load_16(p);
> +	for (;;) {
> +		if (atomic_fcmpset_16(p, &v, v | bit))
> +			break;
> +	}
> +}
> +#endif
> +
> +#ifndef atomic_clear_16
> +static __inline void
> +atomic_clear_16(volatile uint16_t *p, uint16_t bit)
> +{
> +	uint16_t v;
> +
> +	v = atomic_load_16(p);
> +	for (;;) {
> +		if (atomic_fcmpset_16(p, &v, v & ~bit))
> +			break;
> +	}
> +}
> +#endif
> +
>  #endif	/* _SYS__ATOMIC_SUBWORD_H_ */

I'll do a follow-up on this soon (next few days) for the
ISA_206_ATOMICS case.

- Justin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20250920162151.05aad15b>