简体   繁体   English

Delphi XE2 64bit:GraphicEx中的inline asm

[英]Delphi XE2 64bit: inline asm in GraphicEx

How would this turn out from asm to pure delphi? 怎么会从asm变成纯粹的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. 我无法编译需要GraphicEx的组件,在JPG单元中给出了一个错误,即内联汇编不支持64位。

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;
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. 进入此功能后,double将存储在FPU中。 The double is then put into the local var f and truncated to an integer. 然后将double放入局部var f并截断为整数。 So forget my answer. 所以忘了我的回答。

This routine is not used in GraphicEx so just try to comment it away. 此例程未在GraphicEx中使用,因此请尝试将其注释掉。

Update 2. 更新2。

As David says, it could be used by linked in .obj files. 正如大卫所说,它可以被链接在.obj文件中使用。 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) : 假设它们是64位目标文件,它们执行相同的参数传递(在FPU堆栈中为double),这里有一个可以使用的函数(在64位模式下):

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM