[LLVMdev] Floating point atomic load and add
Tyler Denniston
tyler at csail.mit.edu
Sun Apr 26 06:31:57 PDT 2015
As a followup: could I do a "strong" cmpxchg and leave out the loop?
(According to
http://en.cppreference.com/w/c/atomic/atomic_compare_exchange that is
preferable when possible).
Here is (my understanding of) the equivalent LLVM:
void emitAtomicFPAdd(Value *ptr, Value *incr) {
LoadInst *oldval = builder->CreateLoad(ptr);
Value *newval = builder->CreateAdd(oldval, incr);
Instruction *cmpxchg =
builder->CreateAtomicCmpXchg(ptr, oldval, newval,
AtomicOrdering::SequentiallyConsistent,
AtomicOrdering::SequentiallyConsistent);
}
Quoting Tim Northover <t.p.northover at gmail.com>:
>> } while (__c11_atomic_compare_exchange_weak(
>> addr, &oldval, newval, memory_order_seq_cst, memory_order_relaxed));
>
> Actually, I think this condition is inverted. Should be "while
> (!_c11...". Sorry about that.
>
> Tim.
More information about the llvm-dev
mailing list