[LLVMdev] Floating point atomic load and add
Tyler Denniston
tyler at csail.mit.edu
Fri Apr 24 14:34:17 PDT 2015
Got it. Thanks!
Quoting Tim Northover <t.p.northover at gmail.com>:
>> Hmm, ok. Can you briefly expand on how I should emulate this behavior? I
>> don't understand what you mean by adding a loop around cmpxchg.
>
> Probably easiest to write down in C:
>
> #include <stdatomic.h>
> void foo(_Atomic(float) *addr, float increment) {
> float oldval = *addr, newval;
> do {
> newval = oldval + increment;
> } while (__c11_atomic_compare_exchange_weak(
> addr, &oldval, newval, memory_order_seq_cst, memory_order_relaxed));
> }
>
> Basically you keep trying to just swap in the new value until you've
> managed to do it atomically (or possibly with an intervening ABA
> change, but that doesn't matter usually).
>
> Tim.
More information about the llvm-dev
mailing list