www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Compiler Explorer Assembly Output for C, C++ and D (dlang)

reply Tariq Siddiqui <m.tariqsiddiqui gmail.com> writes:
When using Compiler Explorer (https://godbolt.org/) to compare 
assembly output of simple programs, why D language assembly 
output is so long compared to C or C++ output. The simple square 
function output is the same for C, C++, and D, but the D output 
has additional lines that are not highlighted when hovering over 
the square function in the source code.

  - What are these additional lines?
  - How can I remove these lines from being generated?
May 27 2021
next sibling parent reply Dennis <dkorpel gmail.com> writes:
On Thursday, 27 May 2021 at 08:47:50 UTC, Tariq Siddiqui wrote:
  - What are these additional lines?
D generates extra symbols per module for things like module constructors, unittests and class introspection (I think).
  - How can I remove these lines from being generated?
Pass the `-betterC` flag to dmd/ldc2.
May 27 2021
parent reply Tariq Siddiqui <m.tariqsiddiqui gmail.com> writes:
On Thursday, 27 May 2021 at 09:11:35 UTC, Dennis wrote:
 On Thursday, 27 May 2021 at 08:47:50 UTC, Tariq Siddiqui wrote:
  - What are these additional lines?
D generates extra symbols per module for things like module constructors, unittests and class introspection (I think).
  - How can I remove these lines from being generated?
Pass the `-betterC` flag to dmd/ldc2.
Thanks for your answer, -betterC works well with simple code but when using templates in code -betterC compilation failed.
May 27 2021
parent Dennis <dkorpel gmail.com> writes:
On Thursday, 27 May 2021 at 10:27:42 UTC, Tariq Siddiqui wrote:
 Thanks for your answer, -betterC works well with simple code 
 but when using templates in code -betterC compilation failed.
Templates are supported in -betterC, what's not supported can be found here: https://dlang.org/spec/betterc.html#consequences You're probably using or importing something that depends on Druntime. For LDC, you can try adding this instead of using `-betterC`: ``` pragma(LDC_no_moduleinfo); ``` Though once you use non-betterC functions, your assembly will easily get messy compared to C's assembly.
May 27 2021
prev sibling parent reply Basile B. <b2.temp gmx.com> writes:
On Thursday, 27 May 2021 at 08:47:50 UTC, Tariq Siddiqui wrote:
 When using Compiler Explorer (https://godbolt.org/) to compare 
 assembly output of simple programs, why D language assembly 
 output is so long compared to C or C++ output. The simple 
 square function output is the same for C, C++, and D, but the D 
 output has additional lines that are not highlighted when 
 hovering over the square function in the source code.

  - What are these additional lines?
  - How can I remove these lines from being generated?
In addition to other answers, see https://forum.dlang.org/post/myrjutqyzpzlyltrdkwc forum.dlang.org
May 27 2021
parent reply Gavin Ray <gavinray site.com> writes:
On Thursday, 27 May 2021 at 10:48:43 UTC, Basile B. wrote:
 https://forum.dlang.org/post/myrjutqyzpzlyltrdkwc forum.dlang.org
Thank you for sharing this! The difference between setting `pragma(LDC_no_moduleinfo);` at the top, and `-Os -gline-tables-only` in compiler flags is drastic. - Standard - https://d.godbolt.org/z/env355M71 - No module info + flags - https://d.godbolt.org/z/4KxxvonY5 You wind up with ```c int example.square(int): mov eax, edi imul eax, edi ret ``` ``` define i32 _D7example6squareFiZi(i32 %num_arg) %1 = mul i32 %num_arg, %num_arg, !dbg !7 ret i32 %1, !dbg !7 } "frame-pointer"="none" "target-cpu"="x86-64" "target-features"="+cx16" } ```
May 27 2021
parent Alain De Vos <devosalain ymail.com> writes:
Sidequestion.
For what purpose is the registration of dso used ?
May 27 2021