Aaand I'm totally lost...
Determinism means the same calculations would give perfectly matching results, to the last bit, regardless of platform - i386 / x86_64 / arm, regardless of compiler version and compiler settings.
And there is standard for that, most CPUs conform to it, bus some may not (because, bugs) resulting in owners of some AMD CPUs get random disconnects from MMO game sessions.
Determinism is vital for achieving reproductive behavior - e.g. the same input signals will always result with the same simulation.
It's how demos in Doom 2 were recorded: just a tiny sequence of key presses and mouse movement.
Unfortunately, functions like sine, exponent or square root are not so lucky. They are *not* deterministic.
Hence, the quest of finding replacements that achieve roughly the same result using only basic math. The one above is very simple and fast and very precise - its max error is 1.254% (it gives 0.1058 instead of 0.1045)
On weaksauce CPUs such replacements may be simply used to speed things up.
See also
https://en.wikipedia.org/wiki/Fast_inverse_square_root and know it is now embedded in modern CPUs, they support this in hardware while Carmack's solution causes slowdown when you use SSE2 (at least, Free Pascal compiler gets confused and generates travesty like unload from XMM register to RAM - load into general-purpose rregister - do the bit-logic shit - unload into memory - load back into XMM register) so instead of, say,
- Code: Select all
function FastInverseSquareRoot(a: float): float; inline;
var
i: longint;
begin
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;
I have to use
- Code: Select all
function FastInverseSquareRoot(a: float): float; inline; assembler;
asm
RSQRTSS xmm7, [a]
MOVSS [Result], xmm7
end['xmm7'];