Quote Originally Posted by Delfi
Quote Originally Posted by dmantione
:shock: :shock: Do you have any idea how slow a trunc is?
why would trunc be slow? it executes on the FPU, right?
This is the trunc implementation in FPC

[pascal]
{$define FPC_SYSTEM_HAS_TRUNC}
function fpc_trunc_real(d : ValReal) : int64;assembler;compilerproc;
var
oldcw,
newcw : word;
res : int64;
asm
fnstcw oldcw
fwait
movw oldcw,%cx
orw $0x0f00,%cx
movw %cx,newcw
fldcw newcw
fldt d
fistpq res
fwait
movl res,%eax
movl res+4,%edx
fldcw oldcw
end;
[/pascal]

Note all the hackery with the FPU control word, necessary to make the FPU truncate instead of round. Tinkering with the fpucw is terribly expensive.