package p
import "math"
func f(x int64) bool {
return x == math.MinInt64
}
On amd64, the core of this compiles to:
0x0005 00005 (z.go:6) MOVQ $-9223372036854775808, CX
0x000f 00015 (z.go:6) CMPQ AX, CX
0x0012 00018 (z.go:6) SETEQ "".~r1+16(SP)
It would be cheaper and smaller instead to decrement CX and check the flags for underflow. A similar trick can be used for checking min and max ints and uints of all sizes. It might also be useful in the division fix-up code, where we must check for min int divisor.
cc @randall77 @dr2chase @martisch @mundaym
On amd64, the core of this compiles to:
It would be cheaper and smaller instead to decrement CX and check the flags for underflow. A similar trick can be used for checking min and max ints and uints of all sizes. It might also be useful in the division fix-up code, where we must check for min int divisor.
cc @randall77 @dr2chase @martisch @mundaym