This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Atomic floats on x86_64
- From: NightStrike <nightstrike at gmail dot com>
- To: Andrew Haley <aph at redhat dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Mon, 10 Nov 2014 10:49:14 -0500
- Subject: Re: Atomic floats on x86_64
- Authentication-results: sourceware.org; auth=none
- References: <CAF1jjLsWNjKFacHn8V_fnc73K9mF9u04G554=qmmcqKw4uN6Jw at mail dot gmail dot com> <54607E4F dot 9070805 at redhat dot com> <CAF1jjLtq14CZ+j--myUwnrpscB9vK-D-d8PrUO8ikdZoKmg1VA at mail dot gmail dot com> <5460DA7D dot 8020008 at redhat dot com>
On Mon, Nov 10, 2014 at 10:32 AM, Andrew Haley <aph@redhat.com> wrote:
> On 11/10/2014 12:50 PM, NightStrike wrote:
>> On Mon, Nov 10, 2014 at 3:58 AM, Andrew Haley <aph@redhat.com> wrote:
>>> On 09/11/14 18:56, NightStrike wrote:
>>>> Is it a bug that I can atomically store a float using __atomic_store,
>>>> but not __atomic_store_n? I'd really like to be able to do it without
>>>> the extra layer of indirection and the extra requirement of a temp
>>>> variable that I don't need.
>>>
>>> I don't get this. Can you explain a bit more, or provide a test case?
>>> There shouldn't be any loss of performance.
>>
>> For me, it's not a matter of performance (at least I hope, I didn't
>> measure). It's more a matter of convenience. I can't just atomically
>> stick a literal into a float. I have to create temp variables
>> instead.
>
> This stuff is part of C11. Given that what you need is
>
> float b;
> atomic_store_explicit(&b, 5.0f, memory_order_release);
>
> I'm having a very difficult time understanding what problem in GCC
> you're trying to solve. If you really insist on using an old GCC
> or an old standard you can use a trivial inline function.
I'm not using an old gcc, I'm using 4.9.1.
And, it was my understanding that using the builtins was an allowable
way to get atomic functionality in C99.
Further, discussions on IRC a bit ago advised me that I need to use
the builtins if I want to use atomic operations on data shared between
C and C++. If I use the C11 functions, then I can't do that.
The problem isn't too complicated. The atomic builtins don't support
floating point types directly, only generally through pointers. It
seems like that would be natural to improve upon.