|
Boost : |
Subject: Re: [boost] Notice: Boost.Atomic (atomic operations library)
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2009-11-30 11:02:14
Helge Bahmann wrote:
> as promised I have started extracting an atomic operations library.
Hi Helge,
This will be a very useful contribution to Boost - thanks for proposing it.
I have worked on a number of different ARM platforms with their own
idiosyncrasies and I would be happy to help add support for them. The
challenge is that there are numerous combinations of processor version,
compiler version and OS to think about, and it's not clear what the
best choice is especially if binary compatibility is needed. Here is
the situation as I understand it (and maybe other ARM users can
confirm/deny this):
Architecture v6 introduced 32-bit load-locked/store-conditional
instructions. Architecture v7 introduced 16- and 8-bit versions.
Earlier architecture versions are still sufficiently widespread that
efficient support is still desirable. I've never found a gcc macro to
indicate the target architecture version passed to -march. Newer
versions of gcc may generate these instructions when the atomic
builtins are used, but versions of gcc that don't do this are
sufficiently widespread that they should still be supported efficiently.
ARM Linux has kernel support that provides compare-and-swap even on
processors that don't support it by guaranteeing to not interrupt code
in certain address ranges. This has the cost of a function call, i.e.
it's slower than inline assembler but a lot faster than a system call.
Kernels that don't support this are now sufficiently old that I think
they can be ignored. Newer versions of gcc may use this mechanism when
the atomic builtins are used, but versions of gcc that don't do this
are sufficiently widespread that they should still be supported efficiently.
I believe that OS X on ARM (i.e. the iPhone) always runs on
architecture v6 or newer. However Apple supply a version of gcc that
is too old to support ARM atomics via the builtins. The "recommended"
way to do atomics is via a set of function calls described here: http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man3/atomic.3.html
I have not looked at what these functions do or tried to benchmark
them. They are also available on other OS X platforms.
I note that you don't seem to use the gcc atomic builtins even on
platforms where they have worked for a while e.g. x86. Any reason for that?
Cheers, Phil.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk