Question

How would this turn out from asm to pure delphi? I cant compile a component that needs GraphicEx, giving me an error in JPG unit that inline assembly isn't suported for 64 bit.

function __ftol: Integer;
var
  f: double;
begin
  asm
    lea    eax, f             //  BC++ passes floats on the FPU stack
    fstp  qword ptr [eax]     //  Delphi passes floats on the CPU stack
  end;
  Result := Trunc(f);
end;
Was it helpful?

Solution

function __ftol( f : double) : Integer;
begin
  Result := Trunc(f);
end;

Update : Sorry I'm wrong. The double is stored in the FPU upon entry to this function. The double is then put into the local var f and truncated to an integer. So forget my answer.

This routine is not used in GraphicEx so just try to comment it away.

Update 2.

As David says, it could be used by linked in .obj files. Assuming they are 64 bit object files doing the same parameter passing (double in FPU stack), here is a function that can be used (in 64 bit mode) :

function __ftol : Integer;
// Assumes double value is in FPU stack on entry
// Make a truncation to integer and put it into function result
var
  TmpVal: Int64;
  SaveCW, ScratchCW: word;

asm
  .NOFRAME 

  fnstcw word ptr [SaveCW]
  fnstcw word ptr [ScratchCW]
  or word ptr [ScratchCW], 0F00h  ;// trunc toward zero, full precision
  fldcw word ptr [ScratchCW]
  fistp qword ptr [TmpVal]
  fldcw word ptr [SaveCW]
  mov rax, TmpVal
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top