On Friday, 23 August 2013 at 05:28:22 UTC, Tyler Jameson Little wrote:
I assume this is something that can be done at runtime:

    int[] a = [1, 2, 3];
    int[] b = [2, 2, 2];
auto c = a[] * b[]; // dynamically allocates on the stack; computes w/SIMD
    writeln(c); // prints [2, 4, 6]

This would be pretty trivial to implement but the question is whether it's a good idea:

Heap allocation is out of the question as it's much too slow to be hidden behind what are supposed to be fast vector operations.

Explicit runtime stack allocation could work, but it's not something we do much of in D. I know Maxime (https://github.com/maximecb/Higgs) uses alloca a bit, but if I remember correctly it wasn't all smooth going.

What definitely should work, but currently doesn't, is this:
     int[3] a = [1, 2, 3];
     int[3] b = [2, 2, 2];
     auto c = a[] * b[]; // statically allocated on stack.

as it can be totally taken care of statically by the type system. Actually I think it's just a straight up compiler bug, because this *does* work:
     int[3] a = [1, 2, 3];
     int[3] b = [2, 2, 2];
     int[3] c = a[] * b[]; // statically allocated on stack.


It looks like it's rejecting the array op before it's worked out what to resolve auto to.

Reply via email to