[Issue 22466] New: Small array initialization and assignment shouldn't defer to memset

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Nov 1 18:31:15 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22466

          Issue ID: 22466
           Summary: Small array initialization and assignment shouldn't
                    defer to memset
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: stanislav.blinov at gmail.com

// dmd -betterC

extern(C) void main(int argc, char** argv)
{
    int[4] arr = 1;
}

Results in:
bugs/smallarray.d:(.text.main[main]+0x1f): undefined reference to `_memset32'

That is a meager four 32-bit stores. It's an unnecessary pessimization to defer
this to a *function call*, source of which may or may not be visible to the
compiler, implementation of which would have branches. Compiler should just
emit the four stores here.

This is not just for ints, other built-in types should also benefit. Upper
bound for avoiding the function call may be up to 512 bits worth of stores (to
correspond to current SIMD widths).

--


More information about the Digitalmars-d-bugs mailing list