Results 1 to 8 of 8

Thread: Opengl - get rid of glu dll

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    I wasn't aware of the 'absolute' keyword
    Be wary it doesn't always work. If you have register variables optimization on, the compiler sometimes gets confused.
    Example: my attempt to implement Carmack's fast inverse square root.
    Code:
        function FastInverseSquareRoot(a: float): float; inline;
        var
          i: longint absolute Result;
        begin
          Result:= a;
          i:= $5f3759df - (i shr 1);
          Result*= 1.5 - (a * 0.5 * Result * Result);
          Result*= 1.5 - (a * 0.5 * Result * Result);
        end;
    - it failed craptacularly. The compiler did not give an error but generated totally rubbish code seqence (I turned on ASM output to check).

    So I had to settle on
    Code:
        // https://en.wikipedia.org/wiki/Fast_inverse_square_root
        function FastInverseSquareRoot(a: float): float; inline;
        var
          i: longint;// absolute Result; //code generator FAILS to marry SSE2 and general-purpose registers
        begin
          //Result:= a;
          i:= longint(pointer(@a)^);
          i:= $5f3759df - (i shr 1);
          Result:= float(pointer(@i)^);
          Result*= 1.5 - (a * 0.5 * Result * Result);
          Result*= 1.5 - (a * 0.5 * Result * Result);
        end;
    P.S. So I'd group absolute together with goto: necessary for backward compatibility but not recommended to use unless you have a very good understanding of processes involved.
    Last edited by Chebmaster; 13-03-2018 at 08:28 AM.

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
  •