NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: port-sh3/60773: sh3 __sync_val_compare_and_swap_1 test failures
The following reply was made to PR toolchain/60773; it has been noted by GNATS.
From: Valery Ushakov <uwe%stderr.spb.ru@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: Taylor R Campbell <riastradh%NetBSD.org@localhost>,
Nick Hudson <skrll%NetBSD.org@localhost>
Subject: Re: port-sh3/60773: sh3 __sync_val_compare_and_swap_1 test failures
Date: Thu, 24 Sep 2026 20:17:00 +0300
On Thu, Sep 24, 2026 at 00:20:02 +0000, Valery Ushakov via gnats wrote:
> common/lib/libc/atomic/atomic_cas_8_cas.c defines
> sync_val_compare_and_swap_1 to return signed int8_t
>
> _atomic_cas_8 returns correct uin8_t value 0x88, then
> sync_val_compare_and_swap_1 sign extends it before returning.
For the record, just to make it explicit. Consider simplified:
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#define OLDVAL (0x1122334455667788UL)
#define NEWVAL (0x8090a0b0c0d0e0f0UL)
int
main()
{
volatile uint8_t val;
uint8_t oldval;
uint8_t newval;
uint8_t expval;
uint8_t expres;
uint8_t res;
val = (uint8_t)OLDVAL;
oldval = (uint8_t)OLDVAL;
newval = (uint8_t)NEWVAL;
expval = (uint8_t)NEWVAL;
expres = (uint8_t)OLDVAL;
res = __sync_val_compare_and_swap_1(&val, oldval, newval);
printf("expected %x, res = %x\n", expres, res);
return 0;
}
=> 0x7a095778 <_atomic_cas_8+16>: jsr @r0
(gdb) si
0x7a09563c in ?? () from /usr/lib/libc.so.12
1: x/i $pc
=> 0x7a09563c: extu.b r5,r5
We have entered _atomic_cas_8_up (static, so no symbol):
(gdb) finish
Run till exit from #0 0x7a09563c in ?? () from /usr/lib/libc.so.12
0x7a09577c in _atomic_cas_8 () from /usr/lib/libc.so.12
1: x/i $pc
=> 0x7a09577c <_atomic_cas_8+20>: lds.l @r15+,pr
(gdb) p/x $r0
$1 = 0x88
We've got correct old uint8_t value (unsigned)
(gdb) si
0x7a09577e in _atomic_cas_8 () from /usr/lib/libc.so.12
1: x/i $pc
=> 0x7a09577e <_atomic_cas_8+22>: rts
(gdb)
0x7a031536 in __sync_val_compare_and_swap_1 () from /usr/lib/libc.so.12
1: x/i $pc
=> 0x7a031536 <__sync_val_compare_and_swap_1+18>: exts.b r0,r0
(gdb) si
0x7a031538 in __sync_val_compare_and_swap_1 () from /usr/lib/libc.so.12
1: x/i $pc
=> 0x7a031538 <__sync_val_compare_and_swap_1+20>: lds.l @r15+,pr
(gdb) p/x $r0
$2 = 0xffffff88
Now we are back to __sync_val_compare_and_swap_1 and it needs to
return int8_t (signed) value so it converts the uint8_t result of
_atomic_cas_8_up by sign-extending (exts.b) the r0.
-uwe
Home |
Main Index |
Thread Index |
Old Index