Recent

Author Topic: problems with the AArch64 inline Assembler  (Read 4578 times)

derMischka81

  • Newbie
  • Posts: 6
problems with the AArch64 inline Assembler
« on: February 16, 2021, 01:28:19 pm »
I use the inline Asssembler on my RPi3 with 64Bit OS.

I have problems with the following inline Assembler instruction

Code: Pascal  [Select][+][-]
  1. asm
  2.   add x1, x1, x7, lsl #3
  3. end;
  4.  

The Instruction should do the following thing:

x1 := x1 + (x7 shl 3)

but if I compile and check the results inklusive the assembly window I can see that the BarrelShift (lsl #3) is missing.


The Next Problem is a branch to a Object-function.

Code: Pascal  [Select][+][-]
  1. TTestObj1.testproc;
  2. begin
  3. end;
  4.  
  5. TTestObj2.asmprob;nostackframe;assembler;
  6. asm
  7.   stp x0, x30, [sp, #-16]!
  8.  
  9.   ldr x0, [x0, FTestObj1]
  10.   bl TTestObj1.testproc
  11.  
  12.   ldp x0, x30 [sp], #16
  13. end;
  14.  

The Branch-Value/Address is not correct --> jumps to the branch line self (infinite loop)
« Last Edit: February 16, 2021, 01:42:33 pm by derMischka81 »

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: problems with the AArch64 inline Assembler
« Reply #1 on: February 16, 2021, 03:33:55 pm »
I was under the impression, that the ADD in Assembly has three operands: Destination, Source1, Source2
You have 4 operands
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: problems with the AArch64 inline Assembler
« Reply #2 on: February 17, 2021, 09:43:35 am »
I use the inline Asssembler on my RPi3 with 64Bit OS.

I have problems with the following inline Assembler instruction

Code: Pascal  [Select][+][-]
  1. asm
  2.   add x1, x1, x7, lsl #3
  3. end;
  4.  

The Instruction should do the following thing:

x1 := x1 + (x7 shl 3)

but if I compile and check the results inklusive the assembly window I can see that the BarrelShift (lsl #3) is missing.

You are aware that I as a compiler developer had already replied to this in on your thread in German forum? And that you should report this on the bug tracker?

The Next Problem is a branch to a Object-function.

Code: Pascal  [Select][+][-]
  1. TTestObj1.testproc;
  2. begin
  3. end;
  4.  
  5. TTestObj2.asmprob;nostackframe;assembler;
  6. asm
  7.   stp x0, x30, [sp, #-16]!
  8.  
  9.   ldr x0, [x0, FTestObj1]
  10.   bl TTestObj1.testproc
  11.  
  12.   ldp x0, x30 [sp], #16
  13. end;
  14.  

The Branch-Value/Address is not correct --> jumps to the branch line self (infinite loop)

I think you better use a combination of ADRP and ADR to load the address into a register and branch to that. What exactly the assembler reader generates for your code I'd need to check.

I was under the impression, that the ADD in Assembly has three operands: Destination, Source1, Source2
You have 4 operands

The ADD instruction (among others) can also have an additional shift left as fourth parameter. See for example here.

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Re: problems with the AArch64 inline Assembler
« Reply #3 on: February 17, 2021, 02:26:00 pm »
I use the inline Asssembler on my RPi3 with 64Bit OS.

I have problems with the following inline Assembler instruction

Code: Pascal  [Select][+][-]
  1. asm
  2.   add x1, x1, x7, lsl #3
  3. end;
  4.  
This bug is fixed in trunk and fixes_3_2.

Quote
Code: Pascal  [Select][+][-]
  1. TTestObj1.testproc;
  2. begin
  3. end;
  4.  
  5. TTestObj2.asmprob;nostackframe;assembler;
  6. asm
  7.   stp x0, x30, [sp, #-16]!
  8.  
  9.   ldr x0, [x0, FTestObj1]
  10.   bl TTestObj1.testproc
  11.  
  12.   ldp x0, x30 [sp], #16
  13. end;
  14.  
While not yet supported, for now this at least gives a compilation error rather than resulting in invalid code. The compiler does not yet parse "ldr x0, [x0, FTestObj1]" correctly either though (it seems to ignore the "FTestObj1"; even if it does not exist, no compilation error is printed).

The RTL uses very little AArch64 inline assembly and since it's a new architecture, existing inline assembly tests are not checked for it (they would have to be translated first). So there are probably quite a few more bugs in its assembler reader...

 

TinyPortal © 2005-2018