On 24/06/2018 23:28, J. Gareth Moreton wrote:
On paper, a binary search is the fastest method to locate a data
pointer associated with a key (in this case, an opcode).
Forgive me for stepping in, given that I hardly looked at your work, nor
the particular part of fpc.
But the fastest way should be a hash look up (O(n) = 1)
I might have missed something, so maybe I am completely out of line....
You have an enum. This could be used as a hash key (no need to
calculate, just take the raw value, and you have a perfect hash).
All you need to do is once build the hash table.
lookup = Array[tasmop] of CodePointer;
in unit initialization set the codepointer for the known opcodes.
Then you do not need to search. just
codepointer := lookup[taicpu(p).opcode]
_______________________________________________
fpc-devel maillist - [email protected]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel