> As far as I understand it, this should have been a relatively easy
> change to make and maintain; lvm.c has #defines ready for you to make
> such a modification (vmdispatch, vmcase, vmbreak).
> https://www.lua.org/source/5.3/lvm.c.html#vmdispatch
Last time I tested, the following definitions would do the trick.
-- Roberto
/*---------------------------------------------------------------------*/
#undef vmdispatch
#undef vmcase
#undef vmbreak
#define vmdispatch(x) goto *disptab[x];
#define vmcase(l) L_##l:
#define vmbreak vmfetch(); vmdispatch(GET_OPCODE(i));
I think gcc has already optimize switch/case into jump table.
I test it in gcc 4.9.2 :
gcc -std=gnu99 -O2 -S -Wall -c lvm.c
.L358:
movl %ebx, %r15d
movl %ebx, %eax
shrl $6, %r15d
andl $63, %eax
movzbl %r15b, %edx
movq %rdx, %r9
movq %rdx, %r15
salq $4, %r9
cmpl $45, %eax
leaq (%rdi,%r9), %rsi
ja .L357
movslq 0(%r13,%rax,4), %rax
addq %r13, %rax
jmp *%rax
.section .rdata,"dr"
.align 4
.L360:
.long .L359-.L360
.long .L361-.L360
.long .L362-.L360
.....
It use jmp *%rax for switch case. The trick only remove the unused default case.