[fpc-devel] Optimization theory

Martin fpc at mfriebe.de
Mon Jun 25 01:18:42 CEST 2018


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]



More information about the fpc-devel mailing list