mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-25 15:51:41 +01:00
lib: sbi: fix atomic_add_return
The unsigned length may be 4 bytes or 8 bytes, amoadd.w only applies to 4 bytes hence this patch. Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:
@@ -28,25 +28,23 @@ void atomic_write(atomic_t *atom, long value)
|
|||||||
long atomic_add_return(atomic_t *atom, long value)
|
long atomic_add_return(atomic_t *atom, long value)
|
||||||
{
|
{
|
||||||
long ret;
|
long ret;
|
||||||
|
#if __SIZEOF_LONG__ == 4
|
||||||
__asm__ __volatile__(" amoadd.w.aqrl %1, %2, %0"
|
__asm__ __volatile__(" amoadd.w.aqrl %1, %2, %0"
|
||||||
: "+A"(atom->counter), "=r"(ret)
|
: "+A"(atom->counter), "=r"(ret)
|
||||||
: "r"(value)
|
: "r"(value)
|
||||||
: "memory");
|
: "memory");
|
||||||
|
#elif __SIZEOF_LONG__ == 8
|
||||||
|
__asm__ __volatile__(" amoadd.d.aqrl %1, %2, %0"
|
||||||
|
: "+A"(atom->counter), "=r"(ret)
|
||||||
|
: "r"(value)
|
||||||
|
: "memory");
|
||||||
|
#endif
|
||||||
return ret + value;
|
return ret + value;
|
||||||
}
|
}
|
||||||
|
|
||||||
long atomic_sub_return(atomic_t *atom, long value)
|
long atomic_sub_return(atomic_t *atom, long value)
|
||||||
{
|
{
|
||||||
long ret;
|
return atomic_add_return(atom, -value);
|
||||||
|
|
||||||
__asm__ __volatile__(" amoadd.w.aqrl %1, %2, %0"
|
|
||||||
: "+A"(atom->counter), "=r"(ret)
|
|
||||||
: "r"(-value)
|
|
||||||
: "memory");
|
|
||||||
|
|
||||||
return ret - value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define __axchg(ptr, new, size) \
|
#define __axchg(ptr, new, size) \
|
||||||
|
Reference in New Issue
Block a user