Fast switch statement

Steven Kucera stevenkucera at gmail.com
Fri Apr 5 03:27:03 PDT 2013


Hi,

OK thanks guys. LDC compiled a jump table. The code runs ~15% 
faster than dmd2, even though checking the ASM it did not inline 
functions it could have, and core.bitop.bsf compiled to a 
function call instead of an ASM instruction.

Can you force a function to be inline, and/or make core.bitop.bsf 
an instruction with ldc? (in the latter case, maybe the last 
resort is to dip into assembly?)

Steve

On Thursday, 4 April 2013 at 09:51:15 UTC, John Colvin wrote:
> On Thursday, 4 April 2013 at 01:06:45 UTC, Steve Kucera wrote:
>> Hi,
>>
>> I am using DMD 2.062 on Windows 7 64-bit.
>>
>> I am writing performance critical functions that need switch 
>> statements to use an indirect jump table... current I'm 
>> analysing the assembly dump, and the code is compiled to 
>> nested ifs instead. This happens with switch and final switch. 
>> Is there any way to force the compiler to use a jump table?
>>
>> Steve
>
> Ldc or gdc may be able to do this for you if dmd cannot.
>
> Other than that, the inline asm in dmd is easy enough to use.



More information about the Digitalmars-d-learn mailing list