Name: Anonymous 2013-02-17 19:15
I'm thinking of writing a simple "bytecode" interpreter in C. I'm tempted to use the GNU C extension that provides labels as values/"computed goto" for the main interpreter loop as a nice speedup over a naive switch implementation1, but in the interest of portability, I'd rather not use that extension, even if it is apparently well supported by GCC, ICC, and Clang.
If instead wrote the interpreter as a collection of functions that modify a state data structure defined in the same source file, and performed dispatch with a table of pointers to those functions, could I expect similar performance characteristics (or even identical compiler output) when compared to the "computed goto" implementation?
And of course, before anyone assumes uncharitable things about me, I'm well aware that both implementations should ``compile down to'' a jump table. The question is whether C compilers are smart enough to optimize the function pointer table implementation that way.
1 http://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables/
If instead wrote the interpreter as a collection of functions that modify a state data structure defined in the same source file, and performed dispatch with a table of pointers to those functions, could I expect similar performance characteristics (or even identical compiler output) when compared to the "computed goto" implementation?
And of course, before anyone assumes uncharitable things about me, I'm well aware that both implementations should ``compile down to'' a jump table. The question is whether C compilers are smart enough to optimize the function pointer table implementation that way.
1 http://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables/