digitalmars.D.learn - D generates large assembly for simple function
- Matt (5/5) Jan 27 2018 Playing around with Godbolt, D seems to generate an embarassing
- Matt (1/1) Jan 27 2018 Godbolt link: https://godbolt.org/g/t5S976
- Stefan Koch (7/8) Jan 27 2018 The actual code is :
- Stefan Koch (4/12) Jan 27 2018 ah ... -betterC is only for dmd.
- Johan Engelen (3/4) Jan 27 2018 `-betterC` works from LDC 1.1.0.
- kdevel (4/10) Jan 27 2018 Could you please paste the source code? I mean in say 5 years
- Seb (3/11) Jan 27 2018 It's not undocumented:
- Seb (9/17) Jan 27 2018 BTW as asm.dlang.org is dead, you can use run.dlang.io for these
- =?UTF-8?Q?Ali_=c3=87ehreli?= (4/5) Jan 27 2018 According to that link D and C++ both produce 4 lines of assembly, Rust
- Johan Engelen (9/10) Jan 28 2018 Careful with these comparisons guys. Know what you are looking at.
- welkam (2/4) Jan 28 2018 Wise words
- H. S. Teoh (9/14) Jan 27 2018 If you're looking for efficiency of generated code, use gdc or ldc.
Playing around with Godbolt, D seems to generate an embarassing amount of assembly for a simple function (50ish for squaring an int vs 4 for C++ and 7 for Rust). Even Go compiles to less assembly. Is there something I'm missing?
Jan 27 2018
On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote:Godbolt link: https://godbolt.org/g/t5S976The actual code is : imul edi, edi mov eax, edi ret The rest is runtime initialization. which you can remove using an undocumented -betterC switch.
Jan 27 2018
On Saturday, 27 January 2018 at 19:43:50 UTC, Stefan Koch wrote:On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote:ah ... -betterC is only for dmd. try using the gdc compiler instead of ldc. it does not emit runtime stuff if it's not used.Godbolt link: https://godbolt.org/g/t5S976The actual code is : imul edi, edi mov eax, edi ret The rest is runtime initialization. which you can remove using an undocumented -betterC switch.
Jan 27 2018
On Saturday, 27 January 2018 at 19:45:35 UTC, Stefan Koch wrote:ah ... -betterC is only for dmd.`-betterC` works from LDC 1.1.0. - Johan
Jan 27 2018
On Saturday, 27 January 2018 at 19:43:50 UTC, Stefan Koch wrote:On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote:Could you please paste the source code? I mean in say 5 years when there will be no more godbolt.org someone reading this thread will not know what it was about.Godbolt link: https://godbolt.org/g/t5S976The actual code is : imul edi, edi mov eax, edi ret
Jan 27 2018
On Saturday, 27 January 2018 at 19:43:50 UTC, Stefan Koch wrote:On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote:It's not undocumented: https://dlang.org/spec/betterc.htmlGodbolt link: https://godbolt.org/g/t5S976The actual code is : imul edi, edi mov eax, edi ret The rest is runtime initialization. which you can remove using an undocumented -betterC switch.
Jan 27 2018
On Saturday, 27 January 2018 at 19:43:50 UTC, Stefan Koch wrote:On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote:BTW as asm.dlang.org is dead, you can use run.dlang.io for these things, e.g. DMD: https://run.dlang.io/is/lLL1aJ LDC: https://run.dlang.io/is/sVn5tu (-output-s / -asm are only added for extra convenience) Since a couple of days, it even does demangling of the symbols. Though, of course, if you want to look only at LDC's output, godbolt is still the better choice.Godbolt link: https://godbolt.org/g/t5S976The actual code is : imul edi, edi mov eax, edi ret The rest is runtime initialization. which you can remove using an undocumented -betterC switch.
Jan 27 2018
On 01/27/2018 11:42 AM, Matt wrote:Godbolt link: https://godbolt.org/g/t5S976According to that link D and C++ both produce 4 lines of assembly, Rust 7, and Go 38 (for that function). Ali
Jan 27 2018
On 01/27/2018 11:42 AM, Matt wrote:Godbolt link: https://godbolt.org/g/t5S976Careful with these comparisons guys. Know what you are looking at. Rust does not eliminate setting the framepointer register, and so it looks "bad" [1]. Clang also sets the framepointer for macOS ABI regardless of optimization level. https://godbolt.org/g/eeo81n [1] See https://github.com/rust-lang/rust/pull/47152 -Johan
Jan 28 2018
On Sunday, 28 January 2018 at 14:33:04 UTC, Johan Engelen wrote:Careful with these comparisons guys. Know what you are looking at.Wise words
Jan 28 2018
On Sat, Jan 27, 2018 at 07:41:21PM +0000, Matt via Digitalmars-d-learn wrote:Playing around with Godbolt, D seems to generate an embarassing amount of assembly for a simple function (50ish for squaring an int vs 4 for C++ and 7 for Rust). Even Go compiles to less assembly. Is there something I'm missing?If you're looking for efficiency of generated code, use gdc or ldc. While dmd is the reference compiler with the latest and greatest bleeding-edge features, it's not known to be the best at generating optimized code, even if you run it with -O. If code size / efficiency is important to you, I highly recommend using gdc or ldc instead. T -- Век живи - век учись. А дураком помрёшь.
Jan 27 2018