<HTML>
Of course, there's nothing to stop us from having a smaller table with an actual hash, but that may give too much constant overhead, especially a modulus operation.<br>
<div><br>
</div><div>Gareth aka. Kit<br>
</div> <br>
<br>
<span style="font-weight: bold;">On Mon 25/06/18 04:23 , "J. Gareth Moreton" gareth@moreton-family.com sent:<br>
</span><blockquote style="BORDER-LEFT: #F5F5F5 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT:0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
Actually you're right - that is the fastest method (it's written O(1), by the way, if it doesn't depend on n). The drawback is that the large majority of instructions don't have such an optimisation procedure, so the table would be extremely sparse. There are 1,109 individual instructions on x86 that FPC currently supports. Come to think of it, even that is not too bad as far as memory goes - you're looking at 8,872 bytes on i386 (4 bytes for the instruction and 4 bytes for a pointer) and 17,744 bytes on x86-64 (8 bytes for each field), both are potentially cacheable on the CPU hence won't be too costly in regards to looking it up. Not sure why I overlooked that one. Thanks Martin.<br>
<div><br>
</div><div>Gareth aka. Kit</div><div><br>
</div><br>
<span style="font-weight: bold;">On Mon 25/06/18 00:18 , Martin fpc@mfriebe.de sent:<br>
</span><blockquote style="BORDER-LEFT: #F5F5F5 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">On 24/06/2018 23:28, J. Gareth Moreton wrote:
<br>
<span style="color: rgb(102, 102, 102);">> On paper, a binary search is the fastest method to locate a data
</span><br>
<span style="color: rgb(102, 102, 102);">> pointer associated with a key (in this case, an opcode).
</span><br>
<br>
Forgive me for stepping in, given that I hardly looked at your work, nor
<br>
the particular part of fpc.
<br>
But the fastest way should be a hash look up (O(n) = 1)
<br>
<br>
I might have missed something, so maybe I am completely out of line....
<br>
<br>
You have an enum. This could be used as a hash key (no need to
<br>
calculate, just take the raw value, and you have a perfect hash).
<br>
<br>
All you need to do is once build the hash table.
<br>
lookup = Array[tasmop] of CodePointer;
<br>
in unit initialization set the codepointer for the known opcodes.
<br>
<br>
Then you do not need to search. just
<br>
codepointer := lookup[taicpu(p).opcode]
<br>
_______________________________________________
<br>
fpc-devel maillist - <a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<br>
<a target="_blank" href="<a href=" http:="" lists.freepascal.org="" cgi-bin="" mailman="" listinfo="" fpc-devel"="">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>"><span style="color: red;">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</span>
<br>
<br>
<br>
</blockquote>
_______________________________________________<br>
fpc-devel maillist - <a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a><br>
<a target="_blank" href="<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>"><span style="color: red;">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</span></a><br>
<br>
</blockquote></HTML>