Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/asm: Allow data references to labels in assembly (support for jump tables) #10870
I've noticed a couple comments in Go assembly routines "TODO replace this with a jump table in the future" and when I tried implementing an assembly routine with a jump table I realized why it hasn't been tried yet. The assembler does not support using labels in data, so there's no easy way to construct the jump table. My incomplete understanding of x64 architecture is that jumps are signed 32 bit offsets from the instruction pointer, which seems like it would make it difficult to implement. Maybe there's also a way to do a jump to a 64bit virtual address, I don't know.
Anyway if it's not too difficult, this would be a nice to have.
In hand-written asm you can do jump tables, though slighly less efficient than you may want (requires 1 more instruction for dispatch).
(full read, compete example included: go-asm-dispatch-tables)
But please, measure result performance carefully.
@martisch : Probably not. The compiler "assembles" its own instructions, so the assembler proper would need no changes. We might need some common support in the obj library.
It would be weird for the compiler to generate code that the assembler can't, though.