3 ms·
Note that you can get a significant speedup by using "restrict" on the pointer in the "sum()" function to tell the compiler that there is no mutation or aliasin
by gavinray 3y ago
Note that you can get a significant speedup by using "restrict" on the pointer in the "sum()" function to tell the compiler that there is no mutation or aliasing happening during the call's lifetime.
On Godbolt, with a size of 100MB (due to limits), this improves the speed using LLVM 17 (https://godbolt.org/z/6dW1h8aev https://godbolt.org/z/6dW1h8aev) from:
1 15.1
2 15.9
To (https://godbolt.org/z/sh3489Mxv https://godbolt.org/z/sh3489Mxv)
1 12.8
2 13.7
- scode2 3y agoIsn't higher better?
- d0mine 3y agoyes. The result is max bandwidth in GB/s https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/blob/master/2024/01/13/bandwidth.cpp https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/...
- LegionMammal978 3y agoThat __restrict isn't useful to the compiler in this function, since it can already infer that there is no mutation from the access patterns: it's a leaf function with only non-atomic reads and no writes. (It's mostly only useful when you interleave reading from one pointer with writing to another with the same type, or when you call an opaque function before reading from a pointer.) Indeed, if you look at the generated assembly, the two are identical. The timing differences are likely random variation.