Hello, I'm wondering how I can create an atomic load and add instruction for floating point values. If I use IRBuilder::CreateAtomicRMW() I get the error message: "atomicrmw operand must have integer type". I am using LLVM 3.4 and the only system I need to support is x86.
On 24 April 2015 at 13:53, Tyler Denniston <tyler at csail.mit.edu> wrote:> I'm wondering how I can create an atomic load and add instruction for > floating point values. If I use IRBuilder::CreateAtomicRMW() I get the > error message: "atomicrmw operand must have integer type".I don't think x86 allows you to use a lock prefix on floating point instructions, just basic arithmetic and cmpxchg. You'll probably need to put a loop around cmpxchg instructions to emulate it. (and might well need to cast the pointers to integer type for the cmpxchg, I know we talked about allowing floats there but I'm not sure it's happened yet). Cheers. Tim.
Quoting Tim Northover <t.p.northover at gmail.com>:> On 24 April 2015 at 13:53, Tyler Denniston <tyler at csail.mit.edu> wrote: >> I'm wondering how I can create an atomic load and add instruction for >> floating point values. If I use IRBuilder::CreateAtomicRMW() I get the >> error message: "atomicrmw operand must have integer type". > > I don't think x86 allows you to use a lock prefix on floating point > instructions, just basic arithmetic and cmpxchg. You'll probably need > to put a loop around cmpxchg instructions to emulate it. (and might > well need to cast the pointers to integer type for the cmpxchg, I know > we talked about allowing floats there but I'm not sure it's happened > yet).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. Thanks, Tyler
On 04/24/2015 01:53 PM, Tyler Denniston wrote:> Hello, > > I'm wondering how I can create an atomic load and add instruction for > floating point values. If I use IRBuilder::CreateAtomicRMW() I get the > error message: "atomicrmw operand must have integer type".The AtomicRMW instruction doesn't natively support floating point types. You can emulate what you're looking for with a bitcast of the float to an appropriately sized integer, a AtomicRMW on that, and then a bitcast of the result. This would have the result of CASing in the bitpattern of the original float which is probably what you intend.> > I am using LLVM 3.4 and the only system I need to support is x86. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
On 26 Apr 2015, at 20:54, Philip Reames <listmail at philipreames.com> wrote:> > The AtomicRMW instruction doesn't natively support floating point types. You can emulate what you're looking for with a bitcast of the float to an appropriately sized integer, a AtomicRMW on that, and then a bitcast of the result. This would have the result of CASing in the bitpattern of the original float which is probably what you intend.AtomicRMW operations in the C11 spec are somewhat insane, as they require saving and restoring the FP state in the compare and exchange loop[1]. It’s probably quite difficult to define an AtomicRMW instructions on floating point values in the IR that would have useful semantics. Anything that does atomic operations on floating point values is likely to have some fairly complex language-level semantics. David [1] I think that this can possibly be avoided if you use Intel’s transactional memory support to implement the atomic RMW, as the instructions that change the floating point environment will cause a transaction abort, but I’m not 100% sure.
Apparently Analagous Threads
- [LLVMdev] Floating point atomic load and add
- [LLVMdev] Floating point atomic load and add
- [LLVMdev] Atomic ops cannot be built from C/OCaml bindings
- [LLVMdev] Atomic ops cannot be built from C/OCaml bindings
- RFC: Extending atomic loads and stores to floating point and vector types