Hello list,
Is it possible to write code in Go ABI0 assembler that implements a jump
table? Motivation example: implement in Go ABI0 assembler this example C
function:
int switch_func(int op) {
int result;
switch (op) {
case 0:
result = 100;
break;
case 1:
result = 200;
break;
case 2:
result = 300;
break;
default:
result = -1;
break;
}
return result;
}
I am now compiling this to a binary search, something like:
TEXT ·switch_func(SB),$32-20
GO_ARGS
NO_LOCAL_POINTERS
MOVL op+8(FP), AX
CMPL AX, $1
JLT lbb5
CMPL AX, $1
JEQ lbb4
CMPL AX, $2
JNE lbb6
MOVL $300, AX
JMP lbb8
lbb4:
MOVL $200, AX
JMP lbb8
lbb5:
CMPL AX, $0
JEQ lbb7
lbb6:
MOVL $4294967295, AX
JMP lbb8
lbb7:
MOVL $100, AX
lbb8:
MOVL AX, ret+16(FP)
RET
It works, but for a hot switch with many cases, like in the QuickJS VM
loop, the overhead is still substantial. Hence I am looking into the
options for compiling it instead as a jump table.
All my attempts so far failed. Does somebody know better and/or have a
working example?
TIA for any information/links etc.
-j
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/golang-nuts/CAA40n-VzMwD_%2BhBKX_xDC0X4Zjd6C7MtkeqrNW5ViVqDpgVUKw%40mail.gmail.com.