<html><br />
if you have not bout book you can always try search in internet.<br />
<br />
I did some research in magic div constants. As already known, there are good case where you can replace division by<br />
<br />
mov magic<br />
mul<br />
shr<br />
<br />
and bad case<br />
<br />
mov magic<br />
mul<br />
add<br />
rcr<br />
shr<br />
<br />
<br />
Bad cases are approximately 1/3 of all cases.<br />
For unsigned byte, word and dword divisions by constant on 64 bit cpu can be converted as good cases.<br />
<br />
Here is possibility for improvements.<br />
<div class="noTransl">----- Reply to message -----<br />
<b>Subject: </b>Re: [fpc-devel] The "magic div" algorithm<br />
<b>From: </b> J. Gareth Moreton via fpc-devel <a href="mailto:fpc-devel@lists.freepascal.org"><fpc-devel@lists.freepascal.org></a><br />
<b>To: </b> <a href="mailto:fpc-devel@lists.freepascal.org"><fpc-devel@lists.freepascal.org></a></div>
<blockquote>
<p>Something tells me I should purchase that book - I sense it could reveal some interesting insights.</p>
<p>Note that while I understand the concept of turning integer division into multiplication (indeed, I implemented the first version into x86 before it was improved with the "calc_divconst_magic_unsigned" routine, and then implemented it for AArch64), the algorithm that is used in "calc_divconst_magic_unsigned" I don't quite get if just for the lack of comments and references, although I am studying it more closely.</p>
<p>Still, I figure I'll put down Hacker's Delight as a future purchase so I have a reputable source rather than just an online one (I know there's one somewhere that isn't behind a paywall).</p>
<p>Gareth aka. Kit</p>
<div class="moz-cite-prefix_558a67e61c1109d0eff3f65fe8fd6d85 ">On 20/08/2021 18:46, Marģers . via fpc-devel wrote:</div>
<blockquote>
<blockquote> is there a reference to the algorithm that's used to calculate the<br />
reciprocal constants used in the integer division optimisations for x86 and AArch64?</blockquote>
<br />
Hacker’s Delight<br />
Second Edition<br />
Henry S. Warren, Jr.<br />
<br />
<fieldset class="mimeAttachmentHeader_596558ff63dca32a5a75022dd0a65562 "> </fieldset>
<pre class="moz-quote-pre_40a086740531b8038f3821db0c0f88d2 ">
_______________________________________________
fpc-devel maillist - <a class="moz-txt-link-abbreviated_6edeedb7913ed797008f7ecfc073df5f " href="fpc-devel@lists.freepascal.org" rel="noopener noreferrer" target="_blank">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext_dfb7fdc1991dd19b1da6b1004f48124b " href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel" rel="noopener noreferrer" target="_blank">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
</blockquote>
<div>
<table style="border-top: 1px solid #D3D4DE; ">
<tbody>
<tr>
<td style="width: 55px; padding-top: 13px; "><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" rel="noopener noreferrer" target="_blank"><img height="29" src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" style="width: 46px; height: 29px; " width="46" /></a></td>
<td style="width: 470px; padding-top: 12px; color: #41424e; font-size: 13px; font-family: Arial, Helvetica, sans-serif; line-height: 18px; ">Virus-free. <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" rel="noopener noreferrer" style="color: #4453ea; " target="_blank">www.avast.com</a></td>
</tr>
</tbody>
</table>
</div>
</blockquote>
</html>