Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
January 14, 2015 Inlining std.atomic.AtomicFence | ||||
---|---|---|---|---|
| ||||
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 |
January 16, 2015 Re: Inlining std.atomic.AtomicFence | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dan Olson | 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 |
January 18, 2015 Re: Inlining std.atomic.AtomicFence | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Nadlinger | Good, nice to know there is a plan to solve this. |
January 19, 2015 Re: Inlining std.atomic.AtomicFence | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dan Olson | 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 |
January 20, 2015 Re: Inlining std.atomic.AtomicFence | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dan Olson | 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?
|
January 20, 2015 Re: Inlining std.atomic.AtomicFence | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | 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 |
Copyright © 1999-2021 by the D Language Foundation