On 02/27/2012 02:06 PM, Jonathan M Davis wrote:

> I'm not saying that dmd doesn't ever optimize switch statements. I'm just
> saying that as I understand it, it doesn't always do so (its performance with
> ranged case statements isn't great for instance). Odds are that it _does_
> optimize straight integer case statements fairly well, because that's the
> classic C stuff (and if you've verified that, all the better - I haven't).

I have played with this optimization recently. (Could be dmd 2.057.) No, dmd did not optimize a straightforward switch statement over a ubyte expression with about two hundred ubyte cases.

The assembly contained conditional jump statements, not a table. And yes, I did try with -O.

But I am not sure that a lookup table really is an optimization with modern CPUs. A series of conditional jumps that fit the CPU's cache could be faster than a table that's outside of the cache. I think accessing the cache is hundreds of times faster than accessing memory outside of the cache.

Ali

Reply via email to