Browse thread
What's "advantage of gcc-specific features"?
-
Yu-Hui Liu
-
Jonathan Roewen
- Michael Benfield
- David MENTRE
-
Jonathan Roewen
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2006-04-22 (07:24) |
From: | Michael Benfield <mike.benfield@g...> |
Subject: | Re: [Caml-list] What's "advantage of gcc-specific features"? |
In case Mr. Roewen's reply was too terse or if you don't know much about virtual machine implementation (not that I do...), here is a fuller explanation of why the interepreter can be faster in GCC: In GCC, unlike standard C, you can take the address of a goto label as described here: http://gcc.gnu.org/onlinedocs/gcc-4.0.2/gcc/Labels-as-Values.html#Labels-as-Values So whereas normally in a C implementation you would do something like this: start: switch(*ptr) { case INSTRUCTION_1: do_stuff(); ptr++; goto start; case INSTRUCTION_2: do_stuff2(); ptr++; goto start; /* ... etc ... */ } That is, each instruction for the virtual machine is represented as an otherwise meaningless integer and you have to do a switch statement for each one, and however your C compiler optimizes that, is what you get. On the other hand, if you can take the address of a label, you can go through the virtual machine instructions and replace each arbitrary integer instruction with the address of a goto label corresponding to that instruction. Then you can do this: instruction_1: do_stuff(); ptr++; goto *ptr; instruction_2: do_stuff2(); ptr++; goto *ptr; /* ... etc ... */ Since this provides a speedup for every VM instruction, it's quite a boost. I think it's rather unfortunate this is not part of standard C.