Inlining problem of core.bitops

bearophile bearophileHUGS at lycos.com
Sat Dec 21 04:39:55 PST 2013


A little test program:


import core.bitop;

uint foo1(in uint x) pure nothrow {
     return bsf(x);
}

version(LDC) {
     import ldc.intrinsics;

     uint foo2(in uint x) pure nothrow {
         return llvm_cttz(x, true);
     }

     uint foo3(in uint x) pure nothrow {
         return llvm_cttz(x, false);
     }
}

void main() {}

-------------------------

DMD gives me this asm, showing the direct use of bsf instruction:

dmd -O -release -inline test.d


_D4test4foo1FNaNbxkZk:
     push    EAX
     bsf EAX,AL
     pop ECX
     ret

-------------------------

Wile ldc2 doesn't inline core.bitop.bsf, but it inlines llvm_cttz:


ldmd2 -O -release -inline -output-s test.d

LDC - the LLVM D compiler (0.12.1):
   based on DMD v2.063.2 and LLVM 3.3.1
   Default target: i686-pc-mingw32


__D4test4foo1FNaNbxkZk:
     calll   __D4core5bitop3bsfFNaNbNfkZi
     ret

__D4test4foo2FNaNbxkZk:
     bsfl    %eax, %eax
     ret

__D4test4foo3FNaNbxkZk:
     movl    $32, %ecx
     bsfl    %eax, %eax
     cmovel  %ecx, %eax
     ret

-------------------------

I have seen the same problem with core.bitop.popcnt versus 
llvm_ctpop().

Bye,
bearophile


More information about the digitalmars-d-ldc mailing list