aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/prove_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/compile/internal/ssa/prove_test.go')
-rw-r--r--src/cmd/compile/internal/ssa/prove_test.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/cmd/compile/internal/ssa/prove_test.go b/src/cmd/compile/internal/ssa/prove_test.go
index 6315049870..1d91736ff0 100644
--- a/src/cmd/compile/internal/ssa/prove_test.go
+++ b/src/cmd/compile/internal/ssa/prove_test.go
@@ -6,11 +6,11 @@ package ssa
import (
"math"
+ "math/bits"
"testing"
)
-func testLimitUnaryOpSigned8(t *testing.T, opName string, op func(l limit, bitsize uint) limit, opImpl func(int8) int8) {
- sizeLimit := noLimitForBitsize(8)
+func testLimitUnaryOpSigned8(t *testing.T, opName string, initLimit limit, op func(l limit, bitsize uint) limit, opImpl func(int8) int8) {
for min := math.MinInt8; min <= math.MaxInt8; min++ {
for max := min; max <= math.MaxInt8; max++ {
realSmallest, realBiggest := int8(math.MaxInt8), int8(math.MinInt8)
@@ -26,7 +26,7 @@ func testLimitUnaryOpSigned8(t *testing.T, opName string, op func(l limit, bitsi
l := limit{int64(min), int64(max), 0, math.MaxUint64}
l = op(l, 8)
- l = l.intersect(sizeLimit) // We assume this is gonna be used by newLimit which is seeded by the op size already.
+ l = l.intersect(initLimit) // We assume this is gonna be used by newLimit which is seeded by the op size already.
if l.min != int64(realSmallest) || l.max != int64(realBiggest) {
t.Errorf("%s(%d..%d) = %d..%d; want %d..%d", opName, min, max, l.min, l.max, realSmallest, realBiggest)
@@ -35,8 +35,7 @@ func testLimitUnaryOpSigned8(t *testing.T, opName string, op func(l limit, bitsi
}
}
-func testLimitUnaryOpUnsigned8(t *testing.T, opName string, op func(l limit, bitsize uint) limit, opImpl func(uint8) uint8) {
- sizeLimit := noLimitForBitsize(8)
+func testLimitUnaryOpUnsigned8(t *testing.T, opName string, initLimit limit, op func(l limit, bitsize uint) limit, opImpl func(uint8) uint8) {
for min := 0; min <= math.MaxUint8; min++ {
for max := min; max <= math.MaxUint8; max++ {
realSmallest, realBiggest := uint8(math.MaxUint8), uint8(0)
@@ -52,7 +51,7 @@ func testLimitUnaryOpUnsigned8(t *testing.T, opName string, op func(l limit, bit
l := limit{math.MinInt64, math.MaxInt64, uint64(min), uint64(max)}
l = op(l, 8)
- l = l.intersect(sizeLimit) // We assume this is gonna be used by newLimit which is seeded by the op size already.
+ l = l.intersect(initLimit) // We assume this is gonna be used by newLimit which is seeded by the op size already.
if l.umin != uint64(realSmallest) || l.umax != uint64(realBiggest) {
t.Errorf("%s(%d..%d) = %d..%d; want %d..%d", opName, min, max, l.umin, l.umax, realSmallest, realBiggest)
@@ -62,15 +61,19 @@ func testLimitUnaryOpUnsigned8(t *testing.T, opName string, op func(l limit, bit
}
func TestLimitNegSigned(t *testing.T) {
- testLimitUnaryOpSigned8(t, "neg", limit.neg, func(x int8) int8 { return -x })
+ testLimitUnaryOpSigned8(t, "neg", noLimitForBitsize(8), limit.neg, func(x int8) int8 { return -x })
}
func TestLimitNegUnsigned(t *testing.T) {
- testLimitUnaryOpUnsigned8(t, "neg", limit.neg, func(x uint8) uint8 { return -x })
+ testLimitUnaryOpUnsigned8(t, "neg", noLimitForBitsize(8), limit.neg, func(x uint8) uint8 { return -x })
}
func TestLimitComSigned(t *testing.T) {
- testLimitUnaryOpSigned8(t, "com", limit.com, func(x int8) int8 { return ^x })
+ testLimitUnaryOpSigned8(t, "com", noLimitForBitsize(8), limit.com, func(x int8) int8 { return ^x })
}
func TestLimitComUnsigned(t *testing.T) {
- testLimitUnaryOpUnsigned8(t, "com", limit.com, func(x uint8) uint8 { return ^x })
+ testLimitUnaryOpUnsigned8(t, "com", noLimitForBitsize(8), limit.com, func(x uint8) uint8 { return ^x })
+}
+
+func TestLimitCtzUnsigned(t *testing.T) {
+ testLimitUnaryOpUnsigned8(t, "ctz", limit{-128, 127, 0, 8}, limit.ctz, func(x uint8) uint8 { return uint8(bits.TrailingZeros8(x)) })
}