On 18/05/2016 17:05, Sergey Fedorov wrote:
> Please look at this:
> 
> $ cat >a.c <<EOF
> int atomic_exchange(int *x, int v)
> {
>     return __atomic_exchange_n(x, v, __ATOMIC_ACQUIRE);
> }
> 
> int sync_lock_test_and_set(int *x, int v)
> {
>     __sync_lock_test_and_set(x, v);
> }
> EOF
> 
> Disassembly of section .text:
> 
> 00000000 <atomic_exchange>:
>    0:    e1902f9f     ldrex    r2, [r0]
>    4:    e1803f91     strex    r3, r1, [r0]
>    8:    e3530000     cmp    r3, #0
>    c:    1afffffb     bne    0 <atomic_exchange>
>   10:    ee070fba     mcr    15, 0, r0, cr7, cr10, {5}
>   14:    e1a00002     mov    r0, r2
>   18:    e12fff1e     bx    lr
> 
> 00000078 <sync_lock_test_and_set>:
>   78:    e1902f9f     ldrex    r2, [r0]
>   7c:    e1803f91     strex    r3, r1, [r0]
>   80:    e3530000     cmp    r3, #0
>   84:    1afffffb     bne    78 <sync_lock_test_and_set>
>   88:    ee070fba     mcr    15, 0, r0, cr7, cr10, {5}
>   8c:    e12fff1e     bx    lr
> 
> 
> atomic_compare_exchange() looks pretty good, doesn't it? Could we use it
> to implement qemu_spin_lock()?

I guess you mean atomic_exchange?  That one looks good, indeed it's
equivalent to __sync_lock_test_and_set.

But honestly I think it would be even better to just use
__sync_lock_test_and_set in the spinlock implementation and not add this
to atomics.h.  There's already enough issues with the current subset of
atomics, I am not really happy to add non-SC read-modify-write
operations to the mix.

Thanks,

Paolo

Reply via email to