Jump to page: 1 2
Thread overview
D generates large assembly for simple function
Jan 27, 2018
Matt
Jan 27, 2018
Matt
Jan 27, 2018
Stefan Koch
Jan 27, 2018
Stefan Koch
Jan 27, 2018
Johan Engelen
Jan 27, 2018
kdevel
Jan 28, 2018
Seb
Jan 28, 2018
Seb
Jan 28, 2018
Ali Çehreli
Jan 28, 2018
Johan Engelen
Jan 28, 2018
welkam
Jan 27, 2018
H. S. Teoh
January 27, 2018
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?
January 27, 2018
Godbolt link: https://godbolt.org/g/t5S976
January 27, 2018
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.
January 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:
>> 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.
January 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:
>> 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.
January 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


January 27, 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

-- 
Век живи - век учись. А дураком помрёшь.
January 28, 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:
>> 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
January 28, 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:
>> 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.
January 27, 2018
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
« First   ‹ Prev
1 2