This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Compiling switches for bytecode interpreters


A simple optimisation which could benefit a range of widely-used bytecode
interpreters (such as those for Perl and Python), and hence many users of
systems other than GCC, would be to omit the range check on the switch
value when it is known to be within the limits of a lookup table already
generated for a switch. For example:

switch ((byte)opcode) { ... }

In this case, opcode is known to be a byte. There's probably a case for
every possible byte in the switch, so GCC will compile a lookup table.
There's now no point making a redundant range check.

According to my investigations and those of Martin Richards (inventor of
BCPL and the corresponding Cintcode interpreter) no version of GCC we've
tried makes this optimisation. We could use label values to force the use
of a lookup table, but prefer to write ANSI compliant code.

Could this optimisation be added? Has it been requested before?

I'm mostly just interested to know what the position is (if any); the
virtual machine community is so fragmented that it's difficult to tell
what's going on!

-- 
http://sc3d.org/rrt/ | certain, a.  insufficiently analysed



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]