www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - Inlining std.atomic.AtomicFence

reply Dan Olson <zans.is.for.cans yahoo.com> writes:
In LDC, how do we make std.atomic.atomicFence inline?

    void atomicFence() nothrow
    {
        llvm_memory_fence();
    }

I was working on fixing a race condition in the unittest for this module and
the assembly for the unitest has a nice ARM dmb instructions (arm memory
fence).  But then I had similar testcode in another module and atomicFence did
not inline, even with -Os -inline.

Changing atomicFence to a template function does make it inline into a dmb
instruction but that changes the core.atomic API I suppose.  Is there a better
solution?
--
Dan
Jan 14 2015
next sibling parent reply David Nadlinger via digitalmars-d-ldc <digitalmars-d-ldc puremagic.com> writes:
Hi Dan,

On Wed, Jan 14, 2015 at 6:08 PM, Dan Olson via digitalmars-d-ldc
<digitalmars-d-ldc puremagic.com> wrote:
 In LDC, how do we make std.atomic.atomicFence inline?
The short answer: Fix inlining and implement forceinline. Cross-module inlining is not functional at all since the big code emission strategy change. This is a big problem, as it also causes issues like std.array.front not being inlined for template instances that are already available from imported modules (e.g. from Phobos). After this is fixed, we should also implement a forceinline attribute/pragma/… to make sure "single instruction wrappers" such as this are actually inlined even in debug mode. Just applying the LLVM attribute alone obviously won't work for situations where the definition isn't emitted in the first place (such as in your test case). Jernej had a go at the latter in https://github.com/ldc-developers/ldc/issues/561. Might be worth a look. David
Jan 16 2015
parent reply Dan Olson <zans.is.for.cans yahoo.com> writes:
Good, nice to know there is a plan to solve this.
Jan 18 2015
parent David Nadlinger via digitalmars-d-ldc <digitalmars-d-ldc puremagic.com> writes:
On Sun, Jan 18, 2015 at 5:36 PM, Dan Olson via digitalmars-d-ldc
<digitalmars-d-ldc puremagic.com> wrote:
 Good, nice to know there is a plan to solve this.
Now we just need somebody to execute it. ;) David
Jan 19 2015
prev sibling parent reply "Kagamin" <spam here.lot> writes:
On Wednesday, 14 January 2015 at 17:08:13 UTC, Dan Olson wrote:
 In LDC, how do we make std.atomic.atomicFence inline?

     void atomicFence() nothrow
     {
         llvm_memory_fence();
     }
Wouldn't alias atomicFence = llvm_memory_fence; do it?
Jan 20 2015
parent David Nadlinger via digitalmars-d-ldc <digitalmars-d-ldc puremagic.com> writes:
On Tue, Jan 20, 2015 at 9:33 AM, Kagamin via digitalmars-d-ldc
<digitalmars-d-ldc puremagic.com> wrote:
 Wouldn't
  alias atomicFence = llvm_memory_fence;
 do it?
An issue with this is that the signature of llvm_memory_fence does not match atomicFence() (it takes an extra, optional ordering parameter). In this specific case, this discrepancy might be acceptable, but there are also other intrinsics where we need to adapt the arguments and/or return values. David
Jan 20 2015