NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: PR/56839: GCC emits wrong codes for compare_and_swap_1 bultins on armv5 (el & eb)
The following reply was made to PR port-arm/56839; it has been noted by GNATS.
From: Martin Husemann <martin%duskware.de@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc:
Subject: Re: PR/56839: GCC emits wrong codes for compare_and_swap_1 bultins
on armv5 (el & eb)
Date: Thu, 19 Mar 2026 15:27:07 +0100
I tried what we last discussed (finaly) but new gcc is not happy
with it:
../common/lib/libc/atomic/atomic_init_testset.c:370:1: error: conflicting types for built-in function '__sync_val_compare_and_swap_2'; expected 'short unsigned int(volatile void *, short unsigned int, short unsigned int)' [-Werror=builtin-declaration-mismatch]
370 | __sync_val_compare_and_swap_2(volatile int16_t *addr, int16_t old, int16_t new)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rin, did I misunderstand what you meant to do?
Or did something get fixed and the __sync_val_compare_and_swap_N optimization
is now gone?
Here is the full patch I tested:
Index: atomic_cas_16_cas.c
===================================================================
RCS file: /cvsroot/src/common/lib/libc/atomic/atomic_cas_16_cas.c,v
retrieving revision 1.3
diff -u -p -r1.3 atomic_cas_16_cas.c
--- atomic_cas_16_cas.c 21 Feb 2014 16:06:48 -0000 1.3
+++ atomic_cas_16_cas.c 19 Mar 2026 14:25:45 -0000
@@ -36,12 +36,15 @@
#endif
#include <sys/atomic.h>
-bool bool_compare_and_swap_2(volatile uint16_t *, uint16_t, uint16_t, ...)
+bool bool_compare_and_swap_2(volatile int16_t *, int16_t, int16_t, ...)
asm("__sync_bool_compare_and_swap_2");
bool
-bool_compare_and_swap_2(volatile uint16_t *addr, uint16_t oldval,
- uint16_t newval, ...)
+bool_compare_and_swap_2(volatile int16_t *addr, int16_t oldval,
+ int16_t newval, ...)
{
- return atomic_cas_16(addr, oldval, newval) == oldval;
+ const uint16_t oldv = (uint16_t)oldval;
+ const uint16_t newv = (uint16_t)newval;
+
+ return atomic_cas_16((volatile uint16_t *)addr, oldv, newv) == oldv;
}
Index: atomic_cas_32_cas.c
===================================================================
RCS file: /cvsroot/src/common/lib/libc/atomic/atomic_cas_32_cas.c,v
retrieving revision 1.2
diff -u -p -r1.2 atomic_cas_32_cas.c
--- atomic_cas_32_cas.c 8 Jan 2026 08:55:25 -0000 1.2
+++ atomic_cas_32_cas.c 19 Mar 2026 14:25:45 -0000
@@ -37,12 +37,15 @@
#include <sys/atomic.h>
-bool bool_compare_and_swap_4(volatile uint32_t *, uint32_t, uint32_t, ...)
+bool bool_compare_and_swap_4(volatile int32_t *, int32_t, int32_t, ...)
asm("__sync_bool_compare_and_swap_4");
bool
-bool_compare_and_swap_4(volatile uint32_t *addr, uint32_t oldval,
- uint32_t newval, ...)
+bool_compare_and_swap_4(volatile int32_t *addr, int32_t oldval,
+ int32_t newval, ...)
{
- return atomic_cas_32(addr, oldval, newval) == oldval;
+ const uint32_t oldv = (uint32_t)oldval;
+ const uint32_t newv = (uint32_t)newval;
+
+ return atomic_cas_32((volatile uint32_t *)addr, oldv, newv) == oldv;
}
Index: atomic_cas_64_cas.c
===================================================================
RCS file: /cvsroot/src/common/lib/libc/atomic/atomic_cas_64_cas.c,v
retrieving revision 1.3
diff -u -p -r1.3 atomic_cas_64_cas.c
--- atomic_cas_64_cas.c 8 Jan 2026 08:55:25 -0000 1.3
+++ atomic_cas_64_cas.c 19 Mar 2026 14:25:45 -0000
@@ -39,14 +39,17 @@
#ifdef __HAVE_ATOMIC64_OPS
-bool bool_compare_and_swap_8(volatile uint64_t *, uint64_t, uint64_t, ...)
+bool bool_compare_and_swap_8(volatile int64_t *, int64_t, int64_t, ...)
asm("__sync_bool_compare_and_swap_8");
bool
-bool_compare_and_swap_8(volatile uint64_t *addr, uint64_t oldval,
- uint64_t newval, ...)
+bool_compare_and_swap_8(volatile int64_t *addr, int64_t oldval,
+ int64_t newval, ...)
{
- return atomic_cas_64(addr, oldval, newval) == oldval;
+ const uin64_t oldv = (uint64_t)oldval;
+ const uin64_t newv = (uint64_t)newval;
+
+ return atomic_cas_64((volatile uint64 *)addr, oldv, newv) == oldv;
}
#endif
Index: atomic_cas_8_cas.c
===================================================================
RCS file: /cvsroot/src/common/lib/libc/atomic/atomic_cas_8_cas.c,v
retrieving revision 1.3
diff -u -p -r1.3 atomic_cas_8_cas.c
--- atomic_cas_8_cas.c 21 Feb 2014 16:06:48 -0000 1.3
+++ atomic_cas_8_cas.c 19 Mar 2026 14:25:45 -0000
@@ -35,13 +35,17 @@
#include <stdbool.h>
#endif
#include <sys/atomic.h>
+#include <stdarg.h>
-bool bool_compare_and_swap_1(volatile uint8_t *, uint8_t, uint8_t, ...)
+bool bool_compare_and_swap_1(volatile int8_t *, int8_t, int8_t, ...)
asm("__sync_bool_compare_and_swap_1");
bool
-bool_compare_and_swap_1(volatile uint8_t *addr, uint8_t oldval,
- uint8_t newval, ...)
+bool_compare_and_swap_1(volatile int8_t *addr, int8_t oldval,
+ int8_t newval, ...)
{
- return atomic_cas_8(addr, oldval, newval) == oldval;
+ uint8_t oldv = (uint8_t)oldval;
+ uint8_t newv = (uint8_t)newval;
+
+ return atomic_cas_8((volatile uint8_t *)addr, oldv, newv) == oldv;
}
Index: atomic_cas_by_cas32.c
===================================================================
RCS file: /cvsroot/src/common/lib/libc/atomic/atomic_cas_by_cas32.c,v
retrieving revision 1.4
diff -u -p -r1.4 atomic_cas_by_cas32.c
--- atomic_cas_by_cas32.c 3 Sep 2014 19:30:47 -0000 1.4
+++ atomic_cas_by_cas32.c 19 Mar 2026 14:25:45 -0000
@@ -64,7 +64,14 @@ _atomic_cas_16(volatile uint16_t *addr,
return old;
}
-crt_alias(__sync_val_compare_and_swap_2,_atomic_cas_16)
+int16_t
+__sync_val_compare_and_swap_2(volatile int16_t *addr, int16_t old, int16_t new)
+{
+ const uint16_t oldv = (uint16_t)oldval;
+ const uint16_t newv = (uint16_t)newval;
+
+ return _atomic_cas_16((volatile uint16_t *)addr, oldv, newv);
+}
uint8_t
_atomic_cas_8(volatile uint8_t *addr, uint8_t old, uint8_t new)
@@ -88,4 +95,11 @@ _atomic_cas_8(volatile uint8_t *addr, ui
return old;
}
-crt_alias(__sync_val_compare_and_swap_1,_atomic_cas_8)
+int8_t
+__sync_val_compare_and_swap_1(volatile int8_t *addr, int8_t old, int8_t new)
+{
+ const uint8_t oldv = (uint8_t)oldval;
+ const uint8_t newv = (uint8_t)newval;
+
+ return _atomic_cas_8((volatile uint8_t *)addr, oldv, newv);
+}
Index: atomic_init_testset.c
===================================================================
RCS file: /cvsroot/src/common/lib/libc/atomic/atomic_init_testset.c,v
retrieving revision 1.21
diff -u -p -r1.21 atomic_init_testset.c
--- atomic_init_testset.c 9 Jan 2026 08:44:57 -0000 1.21
+++ atomic_init_testset.c 19 Mar 2026 14:25:45 -0000
@@ -345,8 +345,41 @@ __strong_alias(_atomic_cas_ptr_ni,_atomi
atomic_op_alias(atomic_cas_64,_atomic_cas_64)
atomic_op_alias(atomic_cas_64_ni,_atomic_cas_64)
__strong_alias(_atomic_cas_64_ni,_atomic_cas_64)
-crt_alias(__sync_val_compare_and_swap_8,_atomic_cas_64)
+
+int64_t
+__sync_val_compare_and_swap_8(volatile int64_t *addr, int64_t old, int64_t new)
+{
+ const uint64_t oldv = (uint64_t)old;
+ const uint64_t newv = (uint64_t)new;
+
+ return _atomic_cas_64((volatile uint64_t *)addr, oldv, newv);
+}
+
#endif
-crt_alias(__sync_val_compare_and_swap_4,_atomic_cas_32)
-crt_alias(__sync_val_compare_and_swap_2,_atomic_cas_16)
-crt_alias(__sync_val_compare_and_swap_1,_atomic_cas_8)
+
+int32_t
+__sync_val_compare_and_swap_4(volatile int32_t *addr, int32_t old, int32_t new)
+{
+ const uint32_t oldv = (uint32_t)old;
+ const uint32_t newv = (uint32_t)new;
+
+ return _atomic_cas_32((volatile uint32_t *)addr, oldv, newv);
+}
+
+int16_t
+__sync_val_compare_and_swap_2(volatile int16_t *addr, int16_t old, int16_t new)
+{
+ const uint16_t oldv = (uint16_t)old;
+ const uint16_t newv = (uint16_t)new;
+
+ return _atomic_cas_16((volatile uint16_t *)addr, oldv, newv);
+}
+
+int8_t
+__sync_val_compare_and_swap_1(volatile int8_t *addr, int8_t old, int8_t new)
+{
+ const uint8_t oldv = (uint8_t)old;
+ const uint8_t newv = (uint8_t)new;
+
+ return _atomic_cas_8((volatile uint8_t *)addr, oldv, newv);
+}
Martin
Home |
Main Index |
Thread Index |
Old Index