Recent

Author Topic: Final code and more.  (Read 9459 times)

mika

  • Full Member
  • ***
  • Posts: 102
Re: Final code and more.
« Reply #15 on: August 22, 2021, 10:41:36 am »
-al will force to use external assembler.
The -al option only controls whether source code lines are inserted in the generated assembler listing. The assembler listing is generated independent of whether an internal or external assembler is used to generate the object files.
Code: Text  [Select][+][-]
  1. -al        List sourcecode lines in assembler file

To specify an alternative object file writer (assembler) use the -A option. To inform FPC to use e.g. as as the assembler:
Code: Text  [Select][+][-]
  1. -Aas       Assemble using GNU AS
-A options supposed to be about "Output format" of generated assembler file. In reality, it's preapproved list of external assemblers and output format is just side effect.

All -a options triggers use of external assembler regardless you want or not.

So, you can not have assembler file in format of your choice and still use internal assembler.
On top of it -Adefault is documented as "use default assembler" but actually produces compiler error: Illegal parameter: -Adefault
And "-al List sourcecode lines in assembler file" has a typo.

There is no clear cut here.

ccrause

  • Hero Member
  • *****
  • Posts: 856
Re: Final code and more.
« Reply #16 on: August 22, 2021, 11:43:05 am »
-A options supposed to be about "Output format" of generated assembler file. In reality, it's preapproved list of external assemblers and output format is just side effect.

All -a options triggers use of external assembler regardless you want or not.

So, you can not have assembler file in format of your choice and still use internal assembler.
On top of it -Adefault is documented as "use default assembler" but actually produces compiler error: Illegal parameter: -Adefault
And "-al List sourcecode lines in assembler file" has a typo.

There is no clear cut here.
You are correct, it seems there is indeed a change to external assembler when using the -a option.  I've tested this on Linux Mint 64-but using the -s option to show the assembling & linking commands for the internal ELF assembler (-Aelf):
Code: Pascal  [Select][+][-]
  1. ~/LazProjs/testasm$ ls
  2. asmtest.pp
  3. ~/LazProjs/testasm$ cat asmtest.pp
  4. program asmtest;
  5.  
  6. {$asmmode intel}
  7.  
  8. begin
  9.   asm
  10.     push rax
  11.     mov rax, 12345
  12.     pop rax
  13.   end;
  14. end.
  15.  
  16. ~/LazProjs/testasm$ ~/fpc/installs/lib/fpc/3.2.2/fpc -s -Aelf asmtest.pp
  17. ~/LazProjs/testasm$ ls
  18. asmtest.o  asmtest.pp  link248729.res  ppas.sh
  19. ~/LazProjs/testasm$ cat ppas.sh
  20. #!/bin/sh
  21. DoExitAsm ()
  22. { echo "An error occurred while assembling $1"; exit 1; }
  23. DoExitLink ()
  24. { echo "An error occurred while linking $1"; exit 1; }
  25. echo Linking asmtest
  26. OFS=$IFS
  27. IFS="
  28. "
  29. /usr/bin/ld -b elf64-x86-64 -m elf_x86_64       -L. -o asmtest -T link248729.res -e _start
  30. if [ $? != 0 ]; then DoExitLink asmtest; fi
  31. IFS=$OFS
Here, an object file is already produced, with no extra assembler step in the generated script (ppas.sh).

When adding -a:
Code: Text  [Select][+][-]
  1. ~/LazProjs/testasm$ ls
  2. asmtest.pp
  3. ~/LazProjs/testasm$ ~/fpc/installs/lib/fpc/3.2.2/fpc -s -a -Aelf asmtest.pp
  4. ~/LazProjs/testasm$ ls
  5. asmtest.pp  asmtest.s  link249366.res  ppas.sh
  6. ~/LazProjs/testasm$ cat ppas.sh
  7. #!/bin/sh
  8. DoExitAsm ()
  9. { echo "An error occurred while assembling $1"; exit 1; }
  10. DoExitLink ()
  11. { echo "An error occurred while linking $1"; exit 1; }
  12. echo Assembling asmtest
  13. /usr/bin/as --64 -o asmtest.o   asmtest.s
  14. if [ $? != 0 ]; then DoExitAsm asmtest; fi
  15. echo Linking asmtest
  16. OFS=$IFS
  17. IFS="
  18. "
  19. /usr/bin/ld -b elf64-x86-64 -m elf_x86_64       -L. -o asmtest -T link249366.res -e _start
  20. if [ $? != 0 ]; then DoExitLink asmtest; fi
  21. IFS=$OFS
  22.  
This case doesn't produce an object file and adds an external assembler call to the script.

I think you should file an issue, probably against the command line options description of -a to better describe the actions taken by the compiler.

mika

  • Full Member
  • ***
  • Posts: 102
Re: Final code and more.
« Reply #17 on: August 22, 2021, 01:23:13 pm »
I think you should file an issue, probably against the command line options description of -a to better describe the actions taken by the compiler.
I already got burnt on those descriptions in past. Now i know. If someone can see importance of this, then file bug report on your own behalf.
I would like a new compiler option "force use internal assembler if there is one" and still produce assembler file if requested one. Chances to get this feature added is low unless i do it myself.

ccrause

  • Hero Member
  • *****
  • Posts: 856
Re: Final code and more.
« Reply #18 on: August 25, 2021, 02:35:40 pm »
I think you should file an issue, probably against the command line options description of -a to better describe the actions taken by the compiler.
I already got burnt on those descriptions in past. Now i know. If someone can see importance of this, then file bug report on your own behalf.
Some progress on this topic. The reason for the current behaviour where -s and -a switches to external assembler is because the internal assembler produces binary output only.  If the user requests text output, it is currently achieved by switching to an external assembler, and the help output was updated to reflect this.  Also -Adefault is now accepted as a valid option.

Quote
I would like a new compiler option "force use internal assembler if there is one" and still produce assembler file if requested one. Chances to get this feature added is low unless i do it myself.
Yes. Alternatively use a tool such as objdump or dumpbin to disassemble the output from the internal assembler and/or linker.

mika

  • Full Member
  • ***
  • Posts: 102
Re: Final code and more.
« Reply #19 on: August 29, 2021, 02:25:53 pm »
Returning to original problem. Even it's possible use external assembler for compilation of your own source code, rtl and packages are precompiled with internal assembler. Thus every program compiled by fpc has near jumps where short jump can be possible.

Example for fpc 3.2.2
system unit 81 instance of misuse of near jumps
sysutils - 70
clasess - 88
and compilser itself ppcx64 - 1121

I do understand, that choosing jump length is moving target, thus increases compilation time if best optimal solution chosen.

Seenkao

  • Hero Member
  • *****
  • Posts: 550
    • New ZenGL.
Re: Final code and more.
« Reply #20 on: August 30, 2021, 10:13:01 am »
Благодарю за предоставленную информацию!

И в данное время возник следующий вопрос, по ассемблеру (чтоб не плодить лишние топики).
Я объявляю переменные в байтах, но в окончательном коде, они всё равно используют не байты, а двойные слова, например не al, а eax (код привожу ниже).

С чем это связано?
Мне писать процедуры на ассемблере, чтоб они использовали правильные данные?

Google translate:
Thank you for the information provided!

And at this time the next question arose, in the assembler (so as not to produce unnecessary topics).
I declare variables in bytes, but in the final code, they still use not bytes, but double words, for example, not al, but eax (I give the code below).

What is the reason for this?
Should I write routines in assembler so that they use the correct data?

Code: Pascal  [Select][+][-]
  1. var
  2.   m, n, z: Byte;
  3.  
  4. ... // file *.s (assembler + pascal)
  5. # [69] n := 255 - m;
  6.         movzbl  %al,%eax         // <<<<<
  7.         movl    $255,%ecx         // <<<<<<
  8.         subl    %eax,%ecx        //<<<<<<
  9. .Ll28:
  10. # [70] z := Byte(Str[3]) - 48;
  11.         movq    -8(%rbp),%rax     // <<<<
  12.         movzbl  2(%rax),%eax      // <<<<
  13.         subl    $48,%eax          // <<<< Not Byte!!!!!
  14. .Ll29:
  15. # [71] if z > n then
  16.         cmpb    %al,%cl
  17.         jb      .Lj13
  18.  
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

ccrause

  • Hero Member
  • *****
  • Posts: 856
Re: Final code and more.
« Reply #21 on: August 30, 2021, 12:19:55 pm »
I declare variables in bytes, but in the final code, they still use not bytes, but double words, for example, not al, but eax (I give the code below).
It may be to avoid partial register stalls.  In other words to produce faster code in general, not smaller code.

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: Final code and more.
« Reply #22 on: August 30, 2021, 02:09:10 pm »
I declare variables in bytes, but in the final code, they still use not bytes, but double words, for example, not al, but eax (I give the code below).
From Ordinal types:

As a pascal compiler, Free Pascal does automatic type conversion and upgrading in expressions where different kinds of integer types are used:
  • Every platform has a “native” integer size, depending on whether the platform is 8-bit, 16-bit, 32-bit or 64-bit. E. g. on AVR this is 8-bit.
  • Every integer smaller than the “native” size is promoted to a signed version of the “native” size. Integers equal to the “native” size keep their signedness.
  • The result of binary arithmetic operators (+, -, *, etc.) is determined in the following way:
    • If at least one of the operands is larger than the native integer size, the result is chosen to be the smallest type that encompasses the ranges of the types of both operands. This means that mixing an unsigned with a smaller or equal in size signed will produce a signed type that is larger than both of them.
    • If both operands have the same signedness, the result is the same type as them. The only exception is subtracting (-): in the case of unsigned - unsigned subtracting produces a signed result in FPC (as in Delphi, but not in TP7).
    • Mixing signed and unsigned operands of the “native” int size produces a larger signed result. This means that mixing longint and longword on 32-bit platforms will produce an int64. Similarly, mixing byte and shortint on 8-bit platforms (AVR) will produce a smallint.


Seenkao

  • Hero Member
  • *****
  • Posts: 550
    • New ZenGL.
Re: Final code and more.
« Reply #23 on: August 31, 2021, 10:28:40 am »
Благодарю! Да я слышал об этом. Но проверяя определённый код, данными задержками можно пренебречь (видимо).
Google translate:
Thanks to! Yes, I heard about it. But by checking a certain code, these delays can be neglected (apparently).

ASerge, в данном случае используются только байты, но он всё равно их переводит в двойные слова.
Google translate:
ASerge, in this case, only bytes are used, but it still translates them into double words.
« Last Edit: August 31, 2021, 10:31:26 am by Seenkao »
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

 

TinyPortal © 2005-2018