Looking for more library optimization patterns
Ivan Kazmenko
gassa at mail.ru
Sat Feb 15 14:18:46 PST 2014
On Thursday, 30 January 2014 at 18:36:09 UTC, bearophile wrote:
> A de-optimization I'd really like in LDC (and dmd) is to not
> call the run-time functions when you perform a verctor
> operation on arrays statically known to be very short:
>
> void main() {
> int[3] a, b;
> a[] += b[];
> }
>
> And just rewrite that with a for loop (as done for cases where
> the run time function is not available), and let ldc2 compile
> it on its own.
For short loops, an unrolled version like
a[0] += b[0];
a[1] += b[1];
a[2] += b[2];
may well be faster than a simple loop as the following one:
foreach (immutable i; 0..3) {
a[i] += b[i];
}
At least on x86/64.
Will that optimization happen too, at a later stage?
Ivan Kazmenko.
More information about the digitalmars-d-ldc
mailing list