Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Computed Goto ≈ Function Pointers?

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/

Name: Anonymous 2013-02-17 19:17

GOTO MY ANUS

Name: Anonymous 2013-02-17 19:26

Shouldn't you write the core interpreter in assembly?

Name: Anonymous 2013-02-17 19:31

>>2
N O  T H A N K  Y O U !

  /\___/\
/ /    ヽ ::: \
| (●), 、(●)、 |
|  ,,ノ(、_, )ヽ、,,   |
|   ,;‐=‐ヽ   .:::::|
\  `ニニ´  .:::/
/`ー‐--‐‐―´´\
       .n:n    nn
      nf|||    | | |^!n
      f|.| | ∩  ∩|..| |.|
      |: ::  ! }  {! ::: :|
      ヽ  ,イ   ヽ  :イ


>>3
For the time being, I only want to implement toy languages and emulators for imaginary computers, so I don't care enough about execution speed to write interpreters in assembly.

Name: Anonymous 2013-02-17 19:35

>>4
lol le tannasin is egin

Name: Anonymous 2013-02-18 7:49

>>5
T-thanks...

Name: Anonymous 2013-02-18 8:47

>>6
Baka Anon-kun. Why are you so silly?

Name: Anonymous 2013-02-18 21:30

>>3
who the fuck would be that retarded

Name: Anonymous 2013-02-19 1:12

Name: Anonymous 2013-02-19 1:15

>>3
Anything is preferable to C. Unless you want security holes in your program, that is.

Name: Anonymous 2013-02-19 3:28

Anything is preferable to my dubs. Unless you want my dubs holes in your my dubs, that is.

Name: Anonymous 2013-02-19 4:51

>>1
You can pipe C to tcc on a shell, and output as execution like a script. Been done before and posted here. Scavenge it.

Name: Anonymous 2013-02-19 10:12

>>9
and it's no surprise that guy wasn't smart enough to be hired by the geniuses at google and mozilla to work on the much better designed javascript (both as a language and implementation platform), which utterly beat that thing in anything you care to name

instead he wastes what little talent he has on a dead language that nobody cares about

Name: Anonymous 2013-02-19 12:56

>>13
google and mozilla, geniuses
much better designed javascript
lua is a dead language
IHBT.
He makes a lot more money than you do from corporate sponsorships towards his open source dynamic language implementation.

Why don't you go back to /proggit/ and brag to your dudebros there about slinging SCALABLE node.js picture galleries there, Lua troll?

Name: Anonymous 2013-02-19 13:30

I opt for computable COMEFROM.  It's a matter of syntax really, so if you can implement GOTO, you can implement COMEFROM

Name: Anonymous 2013-02-19 13:44

>The question is whether C compilers are smart enough to optimize the function pointer table implementation that way.
If you have static-qualified functions, then possibly yes.

Name: >>16 2013-02-19 13:45

inb4 lrn2BBCODE

Name: Anonymous 2013-02-19 13:47

>>15
COMEFROM my_hot_throbbing_boypussy

Name: Anonymous 2013-02-19 14:47

>>14
We've tried sending the Javashit guy to the imagereddits many times to no avail. Like Ahmed, he's stuck to shitpost /prog/ for eternity. I have to say, I used to be somewhere between indifferent and annoyed of JS but he made sure I completely despise it.

Name: Anonymous 2013-02-19 16:49

>>14
hey, if you want to keep using obsolete shit, not my problem then

take a look at asm.js and cry

Name: Anonymous 2013-02-19 17:23

>>20
The synagogue is two blocks away, kike.

Name: Anonymous 2013-02-19 18:00

>>21
Allalalalalaluakbar!

Name: Anonymous 2013-02-19 18:04

>>22
Shghchzzzghalom, hymie!

Name: Anonymous 2013-02-19 19:48

I sure love JEWS and Muslims. But why do JEWS and Muslims love /prog/? We don't have anything interesting here, other than the JEWS and Muslims themselves. What brought them here?

Their cultures fascinate me.

Name: Anonymous 2013-02-19 19:48

Forgot to bump my love-filled post.

Name: Anonymous 2013-02-19 19:54

>>25
don't forget to press Ctrl+W now

Name: Anonymous 2013-02-19 19:59

>>26
I'm using Pentadactyl.

Don't change these.
Name: Email:
Entire Thread Thread List