Recent

Author Topic: How to write to Self from assembler in record constructor?  (Read 4423 times)

deadbeef

  • New Member
  • *
  • Posts: 18
Re: How to write to Self from assembler in record constructor?
« Reply #15 on: February 10, 2022, 10:41:19 am »
How can I load a const into an XMM register?
This either loads garbage or causes SIGSEGV.
Code: Pascal  [Select][+][-]
  1. const
  2.   SOME_BITS: UInt32 = $80000000;
  3.   asm
  4.     movss XMM0, [SOME_BITS]
  5.   end;
  6.  

avk

  • Hero Member
  • *****
  • Posts: 752
Re: How to write to Self from assembler in record constructor?
« Reply #16 on: February 10, 2022, 11:02:40 am »
...
So lazarus uses the XMM registers for float arguments, is there a bit more info on this?
...

FPC just follows the Win64 ABI.

How can I load a const into an XMM register?
...

maybe
Code: Pascal  [Select][+][-]
  1.   asm
  2.     movss XMM0, [rip+SOME_BITS]
  3.   end;
  4.  
« Last Edit: February 10, 2022, 11:35:23 am by avk »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: How to write to Self from assembler in record constructor?
« Reply #17 on: February 10, 2022, 01:45:25 pm »
No, EBX is not the default for the register calling convention. The registers used are EAX, EDX and ECX (in that order) as is mentioned here as well.
You did not understand me. Those registers are free to use (scratch). EBX is NOT free to use since it holds self. (At least in Delphi 32 bit, tested with D7)
Is this really passed as parameter or is it merely using EBX inside a method to hold Self? Cause the Delphi documentation itself writes this:

Quote
The register convention uses up to three CPU registers to pass parameters, while the other conventions pass all parameters on the stack.

And the mentioned registers there are EAX, EDX and ECX (and not EBX) as mentioned in the C++ Builder equivalent of the documentation (C++ Builder __fastcall is equivalent to Delphi register):

Quote
Use the __fastcall modifier to declare functions that expect parameters to be passed in registers. The first three parameters are passed (from left to right) in EAX, EDX, and ECX, if they fit in the register. The registers are not used if the parameter is a floating-point or struct type.

Seenkao

  • Hero Member
  • *****
  • Posts: 549
    • New ZenGL.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

ASerge

  • Hero Member
  • *****
  • Posts: 2240
Re: How to write to Self from assembler in record constructor?
« Reply #19 on: February 10, 2022, 11:58:40 pm »
I'm trying to get some code I wrote for Delphi running but I can't figure out how to write the data into Self from the record constructor.
So how do I get my XMM0 written to the Data array with a single instruction?
as a workaround add:
Code: Pascal  [Select][+][-]
  1. var
  2.   Self: TXPoint absolute Self;
before asm.

deadbeef

  • New Member
  • *
  • Posts: 18
Re: How to write to Self from assembler in record constructor?
« Reply #20 on: February 11, 2022, 06:37:54 am »
@ASerge: This looks so redundant but works great.

 

TinyPortal © 2005-2018