Computed gotos on Reddit

Walter Bright newshound2 at digitalmars.com
Wed Jul 25 10:47:53 PDT 2012


On 7/25/2012 10:29 AM, Dmitry Olshansky wrote:
>> Is it possible you could code it up and test it using inline asm?
>
> Mm... I could try. So the trick is to add say this:
> Dispatch:
> asm{
>        ...
>       lea EAX,jmp_table[EBX][EBX*4]
>       jmp EAX
> jmp_table:
>        jmp Lcase1;
>        jmp Lcase2;
>        jmp Lcase3;
> }
> Lcase1:
>      ...
>      goto Dispatch
> instead of current switch and replace case with labels. Sounds not half bad.
>
> Then I could even replace that one goto Dispatch with same
>       lea EAX,jmp_table[EBX][EBX*4]
>       jmp EAX
>
> I'll give it a shot. The only thing that worries me is that I will step on
> compiler's toes breaking his register allocation scheme (it would have to work
> around my inline asm).

Use the same register for both schemes, and it should then give comparable results.

> Any tips on which spare registers to use (I guess ecx is no go, as there is
> 'this' pointer present) ?

I wouldn't worry about it. EAX is good.



More information about the Digitalmars-d mailing list