You could argue that the setb and ret are not part of the leap year check itself. For example if the compiled inlined the call into a caller doing:
if(is_leap_year_fast()) {...}
Then the ret would obviously go away and the setb wouldn't be necessary as it could generate directly a conditional jmp from the result of the cmp.
Re:A leap year check in three instructions
by npendleton on Friday May 16, 2025 @08:22AM
(#44004560)
Hah, great point!
Terrible nitpick, but this is actually 3 operations, not instructions. On x86 you get 4:
On ARM you get a bit more due to instruction encoding: Compiler explorer reference: https://godbolt.org/z/7ajYqbT9z