<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>If the code breaks down to "x div <span class="pl-c1">1000000000"
        (with </span><span class="pl-c1"><span class="pl-c1">1000000000
          as an explicit constant and x being a 64-bit integer), then
          yes it will.  If the divisor is a variable though, then it
          won't.  However, the "magic div" algorithm only works for
          numerators up to a given bit size; if the number exceeds it,
          you'll lose precision and risk getting an incorrect answer (a
          warning for if you want to try to implement the algorithm
          yourself).</span></span></p>
    <p><span class="pl-c1"><span class="pl-c1">Gareth aka. Kit<br>
        </span></span></p>
    <div class="moz-cite-prefix">On 16/11/2021 17:52, Benito van der
      Zander via fpc-devel wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:9e9f088a-1404-ba33-0a9d-c12c0d6afb76@benibela.de">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <div id="smartTemplate4-template">Hi,<span class="pl-c1"><br>
        </span></div>
      <div><span class="pl-c1"><br>
        </span></div>
      <div><span class="pl-c1">in my big decimal unit, I need to divide
          by 1000000000 all the time, e.g.</span> <a
          class="moz-txt-link-freetext"
href="https://github.com/benibela/bigdecimalmath/blob/master/bigdecimalmath.pas#L1324-L1325"
          moz-do-not-send="true">https://github.com/benibela/bigdecimalmath/blob/master/bigdecimalmath.pas#L1324-L1325</a></div>
      <div><br>
      </div>
      <div>would the magic div help there much?<br>
      </div>
      <div><br>
        Bye,<br>
        Benito </div>
      <div class="moz-cite-prefix">On 09.11.21 22:12, J. Gareth Moreton
        via fpc-devel wrote:<br>
      </div>
      <blockquote type="cite"
        cite="mid:a2672ca8-e399-b11e-aa7e-963a02d8edd0@moreton-family.com">
        <meta http-equiv="Content-Type" content="text/html;
          charset=UTF-8">
        <p>This one for Marģers specifically,</p>
        <p>You'll be pleased to know that your insight has been
          partially implemented!</p>
        <p><a class="moz-txt-link-freetext"
            href="https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/51"
            moz-do-not-send="true">https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/51</a></p>
        <p>This only expands 32-bit divisions to 64-bit, since the
          smaller sizes requires more work at the node level, but is
          certainly possible and will happily continue to experiment
          with seeing if it can be implemented.  This was fun to do!</p>
        <p>The test "bench/bdiv.pp" (also "tests/test/cg/tmoddiv6.pp"
          which just includes the given file) is my benchmark test for
          division and modulus operations if anyone wants to see if they
          can make the fundamental routine faster on any platform.</p>
        <p>Gareth aka. Kit<br>
        </p>
        <div class="moz-cite-prefix">On 24/08/2021 20:14, Marģers . via
          fpc-devel wrote:<br>
        </div>
        <blockquote type="cite"
          cite="mid:1629832449.6125450124779@mail.inbox.lv">
          <meta http-equiv="content-type" content="text/html;
            charset=UTF-8">
          I came up with even shorter variant of div<br>
          example <br>
          function teDWordDivBy7_v4( divided : dword):dword; assembler;
          nostackframe;<br>
          asm<br>
               mov ecx,divided<br>
               mov rax,2635249153693862181<br>
               mul rcx<br>
               mov eax,edx<br>
          end;<br>
          <br>
          current version for comparison<br>
          <br>
          function teDWordDivBy7_v0( divided : dword):dword; assembler;
          nostackframe;<br>
          asm<br>
               mov ecx,divided<br>
               mov eax,613566757<br>
               mul ecx<br>
               add edx,ecx<br>
               rcr edx,1<br>
               shr edx,2<br>
               mov eax,edx<br>
          end;<br>
          <br>
           
          <blockquote>
            <blockquote>
              <blockquote>
                <div>
                  <table>
                    <tbody>
                      <tr>
                        <td> </td>
                        <td> </td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </blockquote>
            </blockquote>
          </blockquote>
          <br>
          <fieldset class="mimeAttachmentHeader"></fieldset>
          <pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-devel maillist  -  <a class="moz-txt-link-abbreviated moz-txt-link-freetext" href="mailto:fpc-devel@lists.freepascal.org" moz-do-not-send="true">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel" moz-do-not-send="true">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
        </blockquote>
        <div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br>
          <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"
                    target="_blank" moz-do-not-send="true"><img
src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif"
                      alt="" style="width: 46px; height: 29px;"
                      moz-do-not-send="true" width="46" height="29"></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"
                    target="_blank" style="color: #4453ea;"
                    moz-do-not-send="true">www.avast.com</a> </td>
              </tr>
            </tbody>
          </table>
          <a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1"
            height="1" moz-do-not-send="true"> </a></div>
        <br>
        <fieldset class="mimeAttachmentHeader"></fieldset>
        <pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-devel maillist  -  <a class="moz-txt-link-abbreviated moz-txt-link-freetext" href="mailto:fpc-devel@lists.freepascal.org" moz-do-not-send="true">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel" moz-do-not-send="true">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
      </blockquote>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-devel maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
    </blockquote>
  </body>
</html>