<HTML>
<div>One other problem with this method, and I think it has caused problems before - https://bugs.freepascal.org/view.php?id=32079 - is what happens if an invalid value is passed in for the opcode. Granted, a sanity check can be employed.</div><div><br>
</div><div>One would need to develop some tight timing tests to determine the fastest method for a given number of cases. As Florian once stated... it takes a large number of jumps before the standard linear subtraction search (where the ordinal difference is subtracted from each case branch in turn) becomes prohibitive. On modern processors it can be as high as 64.<br>
</div><div><br>
</div><div>Gareth aka. Kit<br>
</div> <br>
<br>
<span style="font-weight: bold;">On Mon 25/06/18 11: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">
<defanged_meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<defanged_body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 25/06/2018 05:23, J. Gareth Moreton
wrote:<br>
</div>
<blockquote type="cite" cite="mid:5587.1529896980@web-cluster.fastnet.co.uk">
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>
</blockquote>
<br>
While probably not worth it, but if you want to save memory (and
only few entries have data): Use 2 maps:<br>
<br>
map1: array[opcode] of byte; // I do not know how efficient reading
bytes is....<br>
maps the (hopefully fewer than 255 active entries)<br>
<br>
map2: array[byte] of codepointer<br>
<br>
<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></a><br>
<br>
</defanged_body></defanged_meta></blockquote></HTML>