This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Optimizing a Switch
- From: "Nicolas Cannasse" <ncannasse at motion-twin dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Thu, 11 Aug 2005 16:28:35 +0200
- Subject: Optimizing a Switch
Hi list,
I need to optimize a switch statement in an interpreter which is basicly :
while(true) {
switch( *pc++ ) {
case OPcode1:
....
case opcode2:
....
(more opcodes)
}
}
I managed to store my PC into a register, so now the generated code of the
switch is the following :
L530:
movl (%ebx), %edx
addl $4, %ebx
cmpl $130, %edx // if outside of the range
ja L530
jmp *L384(,%edx,4) // use jmptable
I would like to get rid of the two instructions "cmpl" and "ja" by
specifying somehow that all the cases in my switch are defined (since I'm
checking the bytecode before executing). I think MSVC have some __assume
statement for this case. Is there any GCC-specific way of doing this ?
Thanks,
Nicolas