LDC 0.12.0 has been released

David Nadlinger code at klickverbot.at
Wed Oct 23 12:19:21 PDT 2013


On Wed, Oct 23, 2013 at 8:40 PM, bearophile <bearophileHUGS at lycos.com> wrote:
> If I compile some C-looking D code using -noruntime can't LDC2 not put those
> runtime routine inside the binary and produce a smaller binary?
>
> -----------------------
>
> A small test program:
>
>
> void main() {
>     import core.stdc.stdio, std.math;
>     immutable r = 11;
>     foreach (immutable y; -r .. r + 1) {
>         foreach (immutable x; -2 * r .. 2 * r + 1) {
>             bool circle(in int c, in int r) pure nothrow {
>                 return r ^^ 2 >= (x / 2) ^^ 2 + (y - c) ^^ 2;
>             }
>             putchar(circle(-r / 2, r / 6) ? '#' :
>                     circle( r / 2, r / 6) ? '.' :
>                     circle(-r / 2, r / 2) ? '.' :
>                     circle( r / 2, r / 2) ? '#' :
>                     circle(     0, r)     ? "#."[x < 0] :
>                                           ' ');
>         }
>         '\n'.putchar;
>     }
> }

This program shouldn't even need to pull in std.math with LDC (we
don't follow DMD w.r.t. the wonky requirement of importing std.math to
use ^^). And indeed, if you remove the std.math import, no Phobos
modules are pulled in.

> Compiling using ldc 0.12 with ldmd2 -O -release -inline -noboundscheck
> -output-s it produces (note the __d_allocmemory, dmd doesn't inline the
> lambda but it doesn't perform that call):

You are right, it shouldn't even allocate the lambda in the first
place, but even if it did, one of the optimization passes should
actually promote the allocation to the stack. Investigating…

David


More information about the digitalmars-d-ldc mailing list