digitalmars.D.learn - Compiler Explorer Assembly Output for C, C++ and D (dlang)
- Tariq Siddiqui (8/8) May 27 2021 When using Compiler Explorer (https://godbolt.org/) to compare
- Dennis (4/6) May 27 2021 D generates extra symbols per module for things like module
- Tariq Siddiqui (3/9) May 27 2021 Thanks for your answer, -betterC works well with simple code but
- Dennis (12/14) May 27 2021 Templates are supported in -betterC, what's not supported can be
- Basile B. (3/11) May 27 2021 In addition to other answers, see
- Gavin Ray (26/27) May 27 2021 Thank you for sharing this!
- Alain De Vos (2/2) May 27 2021 Sidequestion.
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
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
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:Thanks for your answer, -betterC works well with simple code but when using templates in code -betterC compilation failed.- 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
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
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
On Thursday, 27 May 2021 at 10:48:43 UTC, Basile B. wrote:https://forum.dlang.org/post/myrjutqyzpzlyltrdkwc forum.dlang.orgThank 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
Sidequestion. For what purpose is the registration of dso used ?
May 27 2021