Results 1 to 4 of 4

Thread: Surprise! Why multiplication by inline const may work 3 times slower in 64-bit code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    My methodology wasn't entirely fair. Why? Because some functions like Frac() run *much* slower on very large numbers -- exactly the range where they produce meaningless noise.
    I limited tome tests to +/- one million (a reasonably expected range in a game) and added another version of fake quick sin, based on Trunc() instead of Frac(), which runs nearly twice faster on x86 compared to my Frac() based fake sin (but only marginally faster on x86-64).
    Did not test if it really returns sine and not some pink polka-dotted cryptid, though.

    A good news: Round() and Trunc() are nearly as fast as a multiplication (0.62 gigaflops vs 0.82 in 32-bit code, 0.74 vs 0.83 in 64-bit code).
    And Frac(), in the -1000000.0..1000000.0 range, is only 4.7 times slower than multiplication in 64-bit code and only 8.9 times slower in 32-bit code.

    P.S. Where are my manners...
    Code:
      function ebd_sin(a: float): float; inline;
      begin
        a:= Frac(a * float(0.318309886183790671537767526745031));// 1 / 3.141592653589793));
        a:= (float(1.0) - a) * a;
        Result:= float (129600.0) * a / (float(40500.0) - a);
      end;
    Code:
    function tricky_sin(a: float): float; inline;
      var b: float;
      begin
        b:= a * float(0.318309886183790671537767526745031);// 1 / 3.141592653589793
        a:= b - Trunc(b);
        a:= (float(1.0) - a) * a;
        Result:= float (129600.0) * a / (float(40500.0) - a);
      end;
    Last edited by Chebmaster; 15-05-2023 at 12:07 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •