bounds checking and optimization
Bruce Carneal
bcarneal at gmail.com
Sun Jun 27 17:49:22 UTC 2021
The following code auto vectorizes nicely, as you'd hope:
void abc(const(int)[] a, const(int)[] b, int[] c) @nogc
nothrow pure @trusted {
const bound = c.length;
(a.length == bound) || assert(0);
(b.length == bound) || assert(0);
foreach(i; 0..bound)
c.ptr[i] = a.ptr[i] + b.ptr[i];
}
If you drop the .ptr suffixes the bounds checks are elided,
correctly, but the code is not auto vectorized.
Similarly, if you drop the .ptr suffixes and compile @safe, the
bounds checks are elided but the code is not auto vectorized.
It would be great if known-within-bound indexing could yield fast
code without requiring either .ptr or @trusted. IOW, I'm hoping
for faster safe code. Is that easily achieved in cases like the
above or is it quite hard?
More information about the digitalmars-d-ldc
mailing list