[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 2/3] atomics: Use __atomic_*_n() variant primiti
From: |
Pranith Kumar |
Subject: |
Re: [Qemu-devel] [PATCH 2/3] atomics: Use __atomic_*_n() variant primitives |
Date: |
Mon, 29 Aug 2016 11:38:45 -0400 |
Paolo Bonzini writes:
> On 24/08/2016 22:44, Pranith Kumar wrote:
>> Use the __atomic_*_n() primitives which take the value as argument. It
>> is not necessary to store the value locally before calling the
>> primitive, hence saving us a stack store and load.
>
> If you do this, you might as well do it for __atomic_load and
> __atomic_compare_exchange. However, you'd still need typeof_strip_qual
> for __atomic_compare_exchange's "_old" local variable.
OK, I will update the patch doing the same for load and compare exchange.
>
> The question is, does this actually cause a change in generated code? I
> would be very surprised if it did, but then it's perfectly possible to
> have a bug in GCC.
It looks like it does. I tested atomic_load() with previous and the
atomic_load_n() version and it generates the following code:
current:
mov 0x200c4a(%rip),%eax # 601030 <value>
mov %eax,-0x4(%rsp)
mov -0x4(%rsp),%eax
atomic_load_n():
mov 0x200c4a(%rip),%eax # 601030 <value>
So looks like it's worth it.
Thanks,
--
Pranith