[cfe-dev] atomic intrinsics
Jeffrey Yasskin
jyasskin at google.com
Thu Oct 7 01:58:36 PDT 2010
On Wed, Oct 6, 2010 at 9:19 AM, Howard Hinnant <hhinnant at apple.com> wrote:
> In the hopes of clarification, I've put three design descriptions up at:
>
> http://libcxx.llvm.org/atomic_design.html
>
> A and/or B is what Eric proposed. C is what I've been working toward. A is my preference. But I can't implement A without buy-in from the front end team. Heck, I can't actually implement any of them without said buy-in. :-) I chose C originally because that was where I thought I could most likely get buy-in.
>
> If any of those docs are unclear, just let me know and I'll attempt to clarify what is intended.
* volatile: The optimizers can do a better job with non-volatile
atomic operations. I believe in your initial atomic_flag
implementation you forwarded the argument's volatility to the
intrinsic, and if the compiler implements the intrinsics it can detect
whether the argument is volatile and optimize accordingly, so that's
all good. But in these API proposals you only have the volatile
intrinsics listed, which might mislead compiler authors to think that
every atomic op has to be volatile. I think it'd be worth mentioning
that notionally there are volatile and non-volatile versions of each
intrinsic.
* "POD" isn't quite the right restriction. [atomics.types.generic]p1
says "The type of the template argument T shall be trivially
copyable." There may be an NB comment suggesting an extra restriction,
but I don't remember exactly what it said.
* I'm not sure if you want this in the API doc, but the choice of
mutex vs. lock-free instructions to implement each size/type is an ABI
decision, and that needs to be noted somewhere for each target. That
is, if clang-2.9 implements the 16-byte atomic by calling out to
compiler-rt, which uses a spinlock to make it atomic, and then
clang-2.10 implements it by using the cmpxchg16b instruction, that's
an ABI change. To avoid ABI changes, we'd need to implement all the
atomics up to the largest platform-supported size using instructions
in the first version that supports them at all.
Jeffrey
More information about the cfe-dev
mailing list