Date : Wed, 14 Feb 1996 11:58:11 +0000 (GMT)
From : Mark Cooke <mpc@...>
Subject: Re : Optimization
On Wed, 14 Feb 1996, Tom Seddon wrote:
> On Tue, 13 Feb 1996, Mark Cooke wrote:
>
> > Depending on your compiler. A potentially better trick is to use
an array
> > of function pointers. Mileage will vary with compiler.
> gcc does this:
>
> mov eax,opcode
> mov eax,[opcodesjumptable+eax*4]
> jmp [eax]
>
> which is about as fast as you can get I think!
Heh - that's not too bad :-). Almost on a par with having the opcodes
aligned on page boundaries, and doing:
mov ah,opcode 1
xor al,al 1
jmp [ax] 5
Which is what my DOS assembly version does. It means your opcodes all
have to be < 256 bytes, but that isn't a problem :-). Checking CPU clocks
it doesn't appear to make a difference on a 486, but I would guess
intuitively that you stand more chance of a cache miss with the extra
read from the table for the gcc code. Can't expect any better from gcc
though. It's a nice solution - and using C is probably a lot easier than
mesing around in assembler...especially 'gas' :-)
Mark
Mark Cooke The views expressed above are mine
Systems Programmer and do not reflect in any way the
University Of Birmingham current policy of my employers.