This is the mail archive of the gcc-help@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]
Other format: [Raw text]

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


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