Closed
Description
https://godbolt.org/z/hhK4h1Es1
bool cmp_min_signed_value_i32(uint32_t x) {
return x == 0x80000000;
}
bool cmp_min_signed_value_i64(uint64_t x) {
return x == 0x8000000000000000ULL;
}
cmp_min_signed_value_i32(unsigned int): # @cmp_min_signed_value_i32(unsigned int)
cmpl $-2147483648, %edi # imm = 0x80000000
sete %al
retq
cmp_min_signed_value_i64(unsigned long): # @cmp_min_signed_value_i64(unsigned long)
movabsq $-9223372036854775808, %rax # imm = 0x8000000000000000
cmpq %rax, %rdi
sete %al
retq
For cases where we're testing for i32/i64 min_signed_value values, we could just negate the result and copy the overflow flag:
cmp_min_signed_value_i32:
negl %edi
seto %al
retq
cmp_min_signed_value_i64:
negq %rdi
seto %al
retq
i8/i16 might require sign-extension to avoid stalls, which might not be worth it:
cmp_min_signed_value_i8:
movsx %dl, %edi
negb %dl
seto %al
retq
cmp_min_signed_value_i16:
movsx %di, %edi
negw %di
seto %al
retq