3

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;
Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
hikari
  • 3,393
  • 1
  • 33
  • 72

1 Answers1

1
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;
LU RD
  • 34,438
  • 5
  • 88
  • 296
  • Whilst the routine is not used explicitly by GraphicsEx, it might be used by a .obj file that is linked into one of the GraphicsEx units. – David Heffernan Oct 08 '11 at 07:41
  • Don't assume parameter passing will be the same in 64 bit. Completely different ABI. – David Heffernan Oct 08 '11 at 08:41
  • 1
    @David, Correct, this type of parameter passing convention was used in 32 bit by linux/GCC. In 64 bit, it is done differently, see [X86_calling_conventions](http://en.wikipedia.org/wiki/X86_calling_conventions) – LU RD Oct 08 '11 at 09:38