Howto reference a table in a structure in assembler
Greg Smith
rys@epaibm.rtpnc.epa.gov
Thu Nov 16 19:04:00 GMT 2006
I have a program that calls functions from a table indexed by a byte
value from an array. Some of the byte values require a second lookup.
I am trying to optimize these cases.
For example:
typedef void (func)(unsigned char *, struct x *);
struct x {
. . .
func tab[256];
. . .
func tab_a7[256];
. . .
}
/* call primary function */
call x->tab[a[0]](a, x);
/* function a7 calls secondary function */
void a7(unsigned char *a, struct x *x) {
call x->tab_a7[a[1]](a, x);
}
This is all well and good, but I would like to eliminate some of
the overhead in the secondary function (just saving a few instructions
helps out tremendously ... this is a hardware emulator).
For i686, a is in register %eax and x is in %edx. I would like
to do something like
void a7(unsigned char *a, struct x *x) {
goto x->tab_a7[a[1]];
}
However, this does
movzbl 1(%eax),%eax
jmp *1540(%eax,%edx)
clobbering %eax. I would like to do instead (if I have to do it in
assembler):
movzbl 1(%eax),%ecx
jmp *tab_a7(%ecx,%edx)
But, how do I specify the tab_a7 offset to the assembler? I certainly
don't want to hard code it.
Or, is there a better way?
Thank you,
Greg Smith
More information about the Gcc-help
mailing list