Computed gotos on Reddit

Walter Bright newshound2 at digitalmars.com
Mon Jul 23 16:19:43 PDT 2012


On 7/23/2012 3:23 PM, bearophile wrote:
> This fallacy implies that if you want to actually see a compiler able to perform
> a certain optimization, such optimization must be rather "easy", this means it
> must be easy for the compiler to infer as true all the conditions necessary to
> apply that optimization (and then you need someone to actually implement it, in
> a community as small as the D one optimizations can't be top priority).

It is easy. Note that the compiler already generates a jump table, this would 
just leave off the default check. In fact, the compiler could do a better job 
doing data flow analysis with final switch than computed goto, because the jump 
targets are constrained and are all known at compile time.

BTW, if computed gotos were put into the language, one would also require 
someone to implement it. You're not saving anything.


> The other problem with optimizations is that often if you can't rely on them,
> that means you can't be certain they are used in the code you are writing, then
> it's like they don't exist. A good example of this is the Scheme standard
> requiring all Scheme compilers to implement the tail call optimization.

Sorry, but I cannot buy this as an argument for loading in more language 
features. Even worse, requiring that a certain semantic construct be implemented 
in a certain way precludes the implementer from finding an even better way to do it.


> You see those "jmp *%ecx"
> at the end of each case. Computed gotos in this case are not just a single
> index-jump, there is an index-jump at the end of each case. Is your future
> hypothetical D compiler able to do that?

Of course. There's no magic technology there. It's just a minor variation on the 
well known loop rotation technique (which dmd does do). Computed gotos are a 
rather hackish design that goes around the horn rather than doing what is needed 
directly.




More information about the Digitalmars-d mailing list