Lazarus

Free Pascal => Unix => Topic started by: derMischka81 on February 16, 2021, 01:28:19 pm

Title: problems with the AArch64 inline Assembler
Post by: derMischka81 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)
Title: Re: problems with the AArch64 inline Assembler
Post by: Zvoni 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
Title: Re: problems with the AArch64 inline Assembler
Post by: PascalDragon 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 (https://www.lazarusforum.de/viewtopic.php?f=9&t=13436&p=119741&sid=95d46e2a0c24300b6e38609ec9dfd2e0#p119741)? 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 (https://thinkingeek.com/2016/10/23/exploring-aarch64-assembler-chapter-3/).
Title: Re: problems with the AArch64 inline Assembler
Post by: Jonas Maebe 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