Recent

Author Topic: How I can see assembler code when Optimization level > 1  (Read 1475 times)

ydd

  • Jr. Member
  • **
  • Posts: 78
How I can see assembler code when Optimization level > 1
« on: November 18, 2020, 04:28:48 am »
I do not need to debug it, just to see

for example - asm code without optimization for:
  i := Length(S);

look like:

Test.lpr:134                         i := Length(S);
00000001000018C3 488b1d46170800           mov    0x81746(%rip),%rbx        # 0x100083010
00000001000018CA 4885db                   test   %rbx,%rbx
00000001000018CD 7404                     je     0x1000018d3 <main+51>
00000001000018CF 488b5bf8                 mov    -0x8(%rbx),%rbx
00000001000018D3 4889d8                   mov    %rbx,%rax
00000001000018D6 482d00000080             sub    $0xffffffff80000000,%rax
00000001000018DC 48baffffffff00000000     movabs $0xffffffff,%rdx
00000001000018E6 4839d0                   cmp    %rdx,%rax
00000001000018E9 7605                     jbe    0x1000018f0 <main+80>
00000001000018EB e880b90000               callq  0x10000d270 <fpc_rangeerror>
00000001000018F0 89d8                     mov    %ebx,%eax
00000001000018F2 890528170800             mov    %eax,0x81728(%rip)        # 0x100083020

I believe it is possible to optimize it.
I want to see asm code when optimization is turned on.

For Delphi 2005 same code look like:

Without optimization:

Main.pas.279: i := Length(S);
004309D1 A148964300       mov eax,[$00439648]
004309D6 A354964300       mov [$00439654],eax
004309DB 833D5496430000   cmp dword ptr [$00439654],$00
004309E2 740F             jz $004309f3
004309E4 A154964300       mov eax,[$00439654]
004309E9 83E804           sub eax,$04
004309EC 8B00             mov eax,[eax]
004309EE A354964300       mov [$00439654],eax
004309F3 A154964300       mov eax,[$00439654]
004309F8 A350964300       mov [$00439650],eax

With optimization:

Main.pas.279: i := Length(S);
0042F9D3 8B1548864300     mov edx,[$00438648]
0042F9D9 8BC2             mov eax,edx
0042F9DB 85C0             test eax,eax
0042F9DD 7405             jz $0042f9e4
0042F9DF 83E804           sub eax,$04
0042F9E2 8B00             mov eax,[eax]
« Last Edit: November 18, 2020, 04:36:25 am by ydd »

bytebites

  • Hero Member
  • *****
  • Posts: 642
Re: How I can see assembler code when Optimization level > 1
« Reply #1 on: November 18, 2020, 08:47:37 am »
Code: Pascal  [Select][+][-]
  1. O1
  2. I:=Length(S);
  3. 0000000000414DF9 488d0540d91200           lea    rax,[rip+0x12d940]      
  4. 0000000000414E00 488b18                   mov    rbx,QWORD PTR [rax]
  5. 0000000000414E03 4885db                   test   rbx,rbx
  6. 0000000000414E06 7404                     je     0x414e0c <main+188>
  7. 0000000000414E08 488b5bf8                 mov    rbx,QWORD PTR [rbx-0x8]
  8. 0000000000414E0C 4889d8                   mov    rax,rbx
  9. 0000000000414E0F 482d00000080             sub    rax,0xffffffff80000000
  10.  
  11. O4
  12. I:=Length(S);
  13. 000000000040BFA4 48c7c0d0335300           mov    rax,0x5333d0
  14. 000000000040BFAB 488b00                   mov    rax,QWORD PTR [rax]
  15. 000000000040BFAE 4885c0                   test   rax,rax
  16. 000000000040BFB1 7404                     je     0x40bfb7 <main+151>
  17. 000000000040BFB3 488b40f8                 mov    rax,QWORD PTR [rax-0x8]
  18.  

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: How I can see assembler code when Optimization level > 1
« Reply #2 on: November 18, 2020, 09:12:53 am »
I want to see asm code when optimization is turned on.

Simply compile your code with the option -al. The resulting assembly file will then be called YourFile.s (in the same directory as the ppu and o files) and will contain the assembly code as its used for the final object file.

ydd

  • Jr. Member
  • **
  • Posts: 78
Re: How I can see assembler code when Optimization level > 1
« Reply #3 on: November 18, 2020, 02:05:48 pm »
Simply compile your code with the option -al. The resulting assembly file will then be called YourFile.s (in the same directory as the ppu and o files) and will contain the assembly code as its used for the final object file.

thank you, problem solved!

 

TinyPortal © 2005-2018