u/407C_Huffer

Why is the version of this function with extra operations and a conditional return faster?

https://pastebin.com/pGHuE4PF

arr_u64_t<N> is an alias for std::array<std::uint64_t, N>

On the bottom of version 2 of the function a multiprecision subtraction is removed as well as an extra array declaration and the conditional return. This results in version2 being slower by something like 40%! What gives? I tried examining the code in Compiler Explorer but it was way too much to make sense of. Compiler is MSVC.

edit: Godbolt: https://godbolt.org/z/G8497c3os

reddit.com
u/407C_Huffer — 6 days ago