2 ms·
They used -O2, which produces the straight forward loop. [0] But with -O3, for NUMBER > 51, is uses some other odd loop. [1] Seems to be O(n) no matter what t
by martincmartin 6y ago
They used -O2, which produces the straight forward loop. [0]
But with -O3, for NUMBER > 51, is uses some other odd loop. [1]
Seems to be O(n) no matter what though.
[0]: https://godbolt.org/z/czcaYf https://godbolt.org/z/czcaYf
[1]: https://godbolt.org/z/sP194Y https://godbolt.org/z/sP194Y
- saagarjha 6y agoClang knows what’s up: https://godbolt.org/z/7zKffz https://godbolt.org/z/7zKffz. GCC is adding the numbers four at a time by stuffing 0, 1, 2, 3 in an XMM register, taking a packed addition within the register, and then doing a pairwise packed addition of the register with 4, 4, 4, 4 to get the next four numbers.