64 bit atomics

190 views
Skip to first unread message

foo64

unread,
Dec 12, 2012, 8:24:02 PM12/12/12
to andro...@googlegroups.com
I'm porting a C++ engine which needs 32 and 64 bit atomic operations. I researched and implemented the GCC built-in __sync_* functions, but when it came time to link I got these kind of errors for the 64 bit operations:

error: undefined reference to '__sync_fetch_and_or_8'
error: undefined reference to '__sync_lock_test_and_set_8'
error: undefined reference to '__sync_fetch_and_and_8'
error: undefined reference to '__sync_fetch_and_add_8'
error: undefined reference to '__sync_val_compare_and_swap_8'

I'm targetting armeabi-v7a, which I've read has some assembly instructions for 64 bit atomic (ldrexd/strexd), so is there a way to access them via the GCC built-in atomics? If not, what are the other options?

- use a mutex to protect each 64 bit operation
- write assembly code to take advantage of ldrexd/strexd
- pass a super secret flag to the NDK toolchain to enable 64 bit intrinsics?
- wait for ARMv8? :)

Thanks!

David Turner

unread,
Dec 13, 2012, 6:46:12 AM12/13/12
to andro...@googlegroups.com
This is being worked on. The next NDK release will support these operations. See https://android-review.googlesource.com/#/c/46714/
(Note that this is not 100% enough, i.e. the current GCC code will crash on ARMv5TE / ARMv6 devices which run on a kernel older than 3.1).
 
In the meantime, for "armeabi-v7a", you could use your own LDREXD/STREXD calls. Technically, you can use them on ARMv6 devices too, but not on ARMv5TE (which corresponds to the "armeabi" technically), though I don't think there are many devices in the field that are not ARMv6 today.


Thanks!

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/m0YbikrxSkgJ.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

David Turner

unread,
Dec 13, 2012, 6:58:59 AM12/13/12
to andro...@googlegroups.com
On Thu, Dec 13, 2012 at 12:46 PM, David Turner <di...@android.com> wrote:
 
In the meantime, for "armeabi-v7a", you could use your own LDREXD/STREXD calls. Technically, you can use them on ARMv6 devices too, but not on ARMv5TE (which corresponds to the "armeabi" technically), though I don't think there are many devices in the field that are not ARMv6 today.

Actually, scratch that, they were introduced in ARMv6K, which appeared after ARMv6. Not sure about real support on existing devices then.

foo64

unread,
Dec 13, 2012, 11:57:47 AM12/13/12
to andro...@googlegroups.com
Thanks for the reply! For now, I think I'll just use mutexes to keep it simple.

I'm assuming that the __atomic_xxx functions defined on this page suffer the same 64-bit fate in the NDK? http://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html#_005f_005fatomic-Builtins
Reply all
Reply to author
Forward
0 new messages