Compile time macro trouble.

Taylor Hillegeist via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Sun Mar 13 06:31:22 PDT 2016


On Sunday, 13 March 2016 at 12:52:01 UTC, Lass Safin wrote:
> On Sunday, 13 March 2016 at 06:15:34 UTC, Taylor Hillegeist 
> wrote:
>> [...]
>
> Try using DMD, it may just be a bug in LDC.
> In DMD you can also force inline with the attribute 
> pragma(inline, true) (or force it not to with pragma(inline, 
> false).
>
> Another thing: I wouldn't use ref here. Do it like this instead:
>
> int X(int i) { return i = i / 3; }
>
> int i = 491;
> i = X(i);
>
> If you look at the assembly which LDC generates you see this:
>
> mangled_name:
> movl    (%rdi), %eax
> shll    $2, %eax
> retq
>
> As you can see, it dereferences a pointer inside %rdi, which 
> means when you call the function, a pointer gets send to it. 
> This means a the caller has to push the value onto the stack 
> (or heap). This costs precious cycles. The callee also has to 
> load the value from memory.
>
> This may also be why it isn't inlined. Perhaps LLVM detects 
> that inlining it won't improve performance, so it refrains from 
> increasing the code size.

Well as nice as that would be to use dmd, I don't think it has a 
arm backend. Also I think GDC does the same thing, and I wonder 
if it is a configuration issue on my end. It seems like I may 
need some optimization flags, or something.


More information about the digitalmars-d-ldc mailing list