4 ms·
Interesting - in the godbolt.org link, looks like both GCC and Clang optimize the code to run at compile time, so the resulting function is just "mov eax, 24".
by olvy0 4y ago
Interesting - in the godbolt.org link, looks like both GCC and Clang optimize the code to run at compile time, so the resulting function is just "mov eax, 24".
But MSVC latest instead generates the full runtime code and function call.
- phoe-krk 4y agoStrangely, clang 13+ seems to have regressed - it emits runtime code as well, whereas clang 12 has just "mov eax, 24". Should this be reported anywhere?
- colatkinson 4y agoI wonder if it hit some max execution time heuristic or something like that. As a quick test, I added a static_assert() that depends on the returned value, which seems to force complete evaluation to happen at compile time. With that, all 3 compilers generate the expected single-instruction implementation: https://godbolt.org/z/onMannzM5 https://godbolt.org/z/onMannzM5