Re: D generates large assembly for simple function
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
Re: D generates large assembly for simple function
On 01/27/2018 11:42 AM, Matt wrote: Godbolt link: https://godbolt.org/g/t5S976 Careful 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
Re: D generates large assembly for simple function
On 01/27/2018 11:42 AM, Matt wrote: Godbolt link: https://godbolt.org/g/t5S976 According to that link D and C++ both produce 4 lines of assembly, Rust 7, and Go 38 (for that function). Ali
Re: D generates large assembly for simple function
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: Godbolt link: https://godbolt.org/g/t5S976 The actual code is : imul edi, edi mov eax, edi ret The rest is runtime initialization. which you can remove using an undocumented -betterC switch. 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.
Re: D generates large assembly for simple function
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: Godbolt link: https://godbolt.org/g/t5S976 The actual code is : imul edi, edi mov eax, edi ret The rest is runtime initialization. which you can remove using an undocumented -betterC switch. It's not undocumented: https://dlang.org/spec/betterc.html
Re: D generates large assembly for simple function
On Sat, Jan 27, 2018 at 07:41:21PM +, 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 -- Век живи - век учись. А дураком помрёшь.
Re: D generates large assembly for simple function
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
Re: D generates large assembly for simple function
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: Godbolt link: https://godbolt.org/g/t5S976 The actual code is : imul edi, edi mov eax, edi ret 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.
Re: D generates large assembly for simple function
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: Godbolt link: https://godbolt.org/g/t5S976 The actual code is : imul edi, edi mov eax, edi ret The rest is runtime initialization. which you can remove using an undocumented -betterC switch. 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.
Re: D generates large assembly for simple function
Godbolt link: https://godbolt.org/g/t5S976
Re: D generates large assembly for simple function
On Saturday, 27 January 2018 at 19:42:01 UTC, Matt wrote: Godbolt link: https://godbolt.org/g/t5S976 The actual code is : imul edi, edi mov eax, edi ret The rest is runtime initialization. which you can remove using an undocumented -betterC switch.