__sync_lock_test_and_set on ARM

David Daney ddaney@avtrex.com
Wed Sep 12 17:32:00 GMT 2007


Phil Endecott wrote:
> Hi David,
>
> David Daney wrote:
>> Phil Endecott wrote:
>>> This raises another issue, which is whether there is any way for 
>>> code to determine which of the atomic builtins are provided, i.e. 
>>> I'd like to write:
>>>
>>> #if HAS__sync_lock_test_and_set
>>> .. locking code using __sync_lock_test_and_set
>>> #elseif HAS__sync_something_else
>>> .. locking code using builtins that expand to LDREX and STREX
>>> #else
>>> #warn "no atomic ops, falling back to pthread mutex"
>>> ...
>>> #endif
>>>
>>
>> The proper symbol to test would be something like: 
>> __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 or 
>> __GCC_HAVE_SYNC_LOCK_TEST_AND_SET_4  they are automatically set by 
>> GCC when the builtin functions are available.
>
> Really?  I don't see anything like that in the output of
>
> gcc -dM -E - < /dev/null|grep -i sync
> or
> grep -R HAVE_SYNC /usr/include/
>
> on my x86 system, which does have a selection of atomic builtins.
>
$ /home/daney/gccsvn/mips64-trunk/gcc/xgcc 
-B/home/daney/gccsvn/mips64-trunk/gcc/ --version
xgcc (GCC) 4.3.0 20070911 (experimental) [trunk revision 128398]
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ /home/daney/gccsvn/mips64-trunk/gcc/xgcc 
-B/home/daney/gccsvn/mips64-trunk/gcc/ -E -dM st.c | grep SYNC
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1

Hmm.




More information about the Gcc-help mailing list