diff options
| author | Xiang W <[email protected]> | 2021-04-06 11:34:38 +0800 |
|---|---|---|
| committer | Anup Patel <[email protected]> | 2021-04-09 18:51:02 +0530 |
| commit | 70ffc3e2e690f2b7bcea456f49206b636420ef5f (patch) | |
| tree | 8a5adc76377e80884965fabc73457904110fb2a9 /lib | |
| parent | 4d8e2f135d659697337f8d4a33fec60cd475f0dc (diff) | |
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 <[email protected]>
Reviewed-by: Anup Patel <[email protected]>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sbi/riscv_atomic.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/sbi/riscv_atomic.c b/lib/sbi/riscv_atomic.c index 558bca8c..528686f4 100644 --- a/lib/sbi/riscv_atomic.c +++ b/lib/sbi/riscv_atomic.c @@ -28,25 +28,23 @@ void atomic_write(atomic_t *atom, long value) long atomic_add_return(atomic_t *atom, long value) { long ret; - +#if __SIZEOF_LONG__ == 4 __asm__ __volatile__(" amoadd.w.aqrl %1, %2, %0" : "+A"(atom->counter), "=r"(ret) : "r"(value) : "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; } long atomic_sub_return(atomic_t *atom, long value) { - long ret; - - __asm__ __volatile__(" amoadd.w.aqrl %1, %2, %0" - : "+A"(atom->counter), "=r"(ret) - : "r"(-value) - : "memory"); - - return ret - value; + return atomic_add_return(atom, -value); } #define __axchg(ptr, new, size) \ |
