computed goto

With gcc it is possible to store a label as a value and execute goto with that value, called a ‘computed goto.’

Information on this is available at http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html

This is useful because in certain cases it enables you to remove all of the overhead of a switch statement by indexing the label addresses based on the argument to the switch, thus jumping directly to the code you want on a certain input.

When I attempt this with nvcc I get the following output.

Assertion failure at line 123 of …/…/be/opt/opt_lab.cxx:

Compiler Error in file /tmp/tmpxft_00002d90_00000000-7_vm.cpp3.i during Global Optimization – Mainopt Lowering phase:

Unexpected control transfer instruction !

I take it this means computed gotos are unsupported in nvcc. Is this impossible? Will it be added in the future? This sort of thing would be straightforward to implement directly in ptx, but I would prefer to avoid this.

If you can post a small self-contained repro case I can file a compiler bug.

Please see the attached file. I’m compiling with the nvcc from the 64 bit ubuntu 8.10 toolkit, no flags.
goto.cu (210 Bytes)

A computed goto sounds like it could end up producing an indirect jump, which is not supported by current hardware. Apparently this will change with Fermi, though…

Try loading address of label and jumping there… You should be able to do that atleast in PTX…

So, that gives you the start…

btw, On light vein – IF, FOR, WHILE are all computed Gotos only :-)