2 ms·
The shift in the second one should be 31, if I understand what you're doing correctly. The third one is incorrect. Consider, for example, the integer 0xFFFFFFF
by pbsd 13y ago
The shift in the second one should be 31, if I understand what you're doing correctly.
The third one is incorrect. Consider, for example, the integer 0xFFFFFFFF00000001, which is -4294967295 in 2's complement. It passes your test, but is not representable as a 32-bit signed integer. An alternative might be:
movsxd rax, edi ; signextend(rdi mod 2^32) == rdi
cmp rax, rdi
setz al
ret
- haberman 13y agoBrilliant, I love it. Thanks for the corrections.