Fast switch statement

Jonathan M Davis jmdavisProg at gmx.com
Wed Apr 3 18:20:53 PDT 2013


On Thursday, April 04, 2013 03:06:44 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?

If you have performance-critical code, then use gdc or ldc (probably ldc, 
since you're on Windows). dmd's optimizer is nowhere near as good as theirs 
are. dmd is very well optimized for compiling quickly, but it fails in 
optimizing the code that it generates. It's okay at it, but it really doesn't 
compare to gdc or ldc (which use gcc and LLVM as their backends respectively). 
And dmd doesn't have much in the way of switches which affect optimization, so 
if neither -O, -inline, or -release gets you jump tables, then I expect that 
there's no way that dmd is going to give you jump tables.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list