gcc and 128-bit compare/exchange
Brian Inglis
Brian.Inglis@SystematicSw.ab.ca
Wed Mar 11 16:30:00 GMT 2020
On 2020-03-11 00:13, Eliot Moss wrote:
> On 3/11/2020 1:31 AM, Brian Inglis wrote:
>
>>>>> A quick followup: I was able to get __sync_val_compare_and_swap_16 to work
>>>>> (and its bool form). That will do for now, though of course it's deprecated.
>
> This does get me the inlined asm code.
>
>> Digging further into the murk where a simple builtin inline cmpxchg16b isn't.
>>
>> Doing what you're doing now seems easier and better supported than alternatives.
>> You can drop stdatomic.h and -latomic as the low level functions are builtins.
>>
>> You could also write your own inline function using cmpxchg16b directly in asm.
>>
>> Looks like because of cpu and library requirements, you would have to enable
>> indirect inline functions in gcc, write libatomic library functions which
>> support gcc indirect inline functions, to test cpu cx16 feature, then setup
>> indirection, to bypass mutexes.
>
> There are two issues here:
>
> 1) Whether the call is inlined.
>
> 2) Whether I get the compare-exchange instruction or a block of code protected
> by a pthread mutex.
>
> The __atomic functions do not inline, as far as I know, from my testing on true
> Linux platforms. But Linux _does_ give me the compare-exchange version of
> the function.
>
> What I am really reporting is that Cygwin is giving the pthread mutex form
> when it should not be. My CPU clearly has the capability, and the compiler clearly
> knows how to emit the instruction, since the __sync form does it. What is
> mysterious and tangled is why libatomic / libc are not delivering the desired
> version of the atomic compare-exchange function.
>
> My _guess_ is that having that as an option depends somehow on how gcc is
> built, e.g., its build configuration. I don't know enough about how those
> ifunc mechanisms work to know if that is it, or if it's something else, but
> the behavior seems to be Cygwin-specific. Hence my report.
There are gcc bugzilla comments about requiring gcc to be built with glibc
libatomic to guarantee indirect inline functions support, and presumably glibc
detecting gcc indirect inline functions support, and not supporting other libc
variants including musl, newlib, uclibc, etc.
The problem is that newlib is BSD licensed and glibc is GPL and you can not
contaminate newlib by looking at or including GPL code, although you may be able
to do so in the Cygwin winsup library.
--
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada
This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
More information about the Cygwin
mailing list