]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove nlz function
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 21 Apr 2020 06:04:59 +0000 (13:04 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 21 Apr 2020 18:15:14 +0000 (18:15 +0000)
Use nlzX variants instead. While at it, also remove tests involve
nlz/nlo/nto/log2, since when we are calling directly "math/bits"
functions.

Passes toolstash-check.

Change-Id: I83899741a29e05bc2c19d73652961ac795001781
Reviewed-on: https://go-review.googlesource.com/c/go/+/229138
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/fmtmap_test.go
src/cmd/compile/internal/ssa/rewrite.go
src/cmd/compile/internal/ssa/rewrite_test.go

index bdf7cc80eefddd7618657b9392d78e2f421a9df7..5a24296c5eb7bee561a88836a48291f3e352c271 100644 (file)
@@ -157,7 +157,6 @@ var knownFormats = map[string]string{
        "int64 %+d":                                       "",
        "int64 %-10d":                                     "",
        "int64 %.5d":                                      "",
-       "int64 %X":                                        "",
        "int64 %d":                                        "",
        "int64 %v":                                        "",
        "int64 %x":                                        "",
index 628fdc9baa8e83b2b3695734e65ee3c53e0575b9..3c37c5c5ec509608c67401abaeb529e068f1ceba 100644 (file)
@@ -386,7 +386,6 @@ func isSameSym(sym interface{}, name string) bool {
 }
 
 // nlz returns the number of leading zeros.
-func nlz(x int64) int64 { return int64(bits.LeadingZeros64(uint64(x))) } // TODO: remove when no longer used
 func nlz64(x int64) int { return bits.LeadingZeros64(uint64(x)) }
 func nlz32(x int32) int { return bits.LeadingZeros32(uint32(x)) }
 func nlz16(x int16) int { return bits.LeadingZeros16(uint16(x)) }
@@ -407,7 +406,7 @@ func oneBit64(x int64) bool { return x&(x-1) == 0 && x != 0 }
 
 // nlo returns the number of leading ones.
 func nlo(x int64) int64 {
-       return nlz(^x)
+       return int64(nlz64(^x))
 }
 
 // nto returns the number of trailing ones.
index 8a097b04f6071d5d01da89d26a892f5f51efe81b..4321c307dc6e8b0d461aad4ec545117bfd7670a3 100644 (file)
@@ -6,104 +6,6 @@ package ssa
 
 import "testing"
 
-// TestNlzNto tests nlz/nto of the same number which is used in some of
-// the rewrite rules.
-func TestNlzNto(t *testing.T) {
-       // construct the bit pattern 000...111, nlz(x) + nto(0) = 64
-       var x int64
-       for i := int64(0); i < 64; i++ {
-               if got := nto(x); got != i {
-                       t.Errorf("expected nto(0x%X) = %d, got %d", x, i, got)
-               }
-               if got := nlz(x); got != 64-i {
-                       t.Errorf("expected nlz(0x%X) = %d, got %d", x, 64-i, got)
-               }
-               x = (x << 1) | 1
-       }
-
-       x = 0
-       // construct the bit pattern 000...111, with bit 33 set as well.
-       for i := int64(0); i < 64; i++ {
-               tx := x | (1 << 32)
-               // nto should be the number of bits we've shifted on, with an extra bit
-               // at iter 32
-               ntoExp := i
-               if ntoExp == 32 {
-                       ntoExp = 33
-               }
-               if got := nto(tx); got != ntoExp {
-                       t.Errorf("expected nto(0x%X) = %d, got %d", tx, ntoExp, got)
-               }
-
-               // sinec bit 33 is set, nlz can be no greater than 31
-               nlzExp := 64 - i
-               if nlzExp > 31 {
-                       nlzExp = 31
-               }
-               if got := nlz(tx); got != nlzExp {
-                       t.Errorf("expected nlz(0x%X) = %d, got %d", tx, nlzExp, got)
-               }
-               x = (x << 1) | 1
-       }
-
-}
-
-func TestNlz(t *testing.T) {
-       var nlzTests = []struct {
-               v   int64
-               exp int64
-       }{{0x00, 64},
-               {0x01, 63},
-               {0x0F, 60},
-               {0xFF, 56},
-               {0xffffFFFF, 32},
-               {-0x01, 0}}
-
-       for _, tc := range nlzTests {
-               if got := nlz(tc.v); got != tc.exp {
-                       t.Errorf("expected nlz(0x%X) = %d, got %d", tc.v, tc.exp, got)
-               }
-       }
-}
-
-func TestNto(t *testing.T) {
-       var ntoTests = []struct {
-               v   int64
-               exp int64
-       }{{0x00, 0},
-               {0x01, 1},
-               {0x0F, 4},
-               {0xFF, 8},
-               {0xffffFFFF, 32},
-               {-0x01, 64}}
-
-       for _, tc := range ntoTests {
-               if got := nto(tc.v); got != tc.exp {
-                       t.Errorf("expected nto(0x%X) = %d, got %d", tc.v, tc.exp, got)
-               }
-       }
-}
-
-func TestLog2(t *testing.T) {
-       var log2Tests = []struct {
-               v   int64
-               exp int64
-       }{{0, -1}, // nlz expects log2(0) == -1
-               {1, 0},
-               {2, 1},
-               {4, 2},
-               {7, 2},
-               {8, 3},
-               {9, 3},
-               {1024, 10}}
-
-       for _, tc := range log2Tests {
-               if got := log2(tc.v); got != tc.exp {
-                       t.Errorf("expected log2(%d) = %d, got %d", tc.v, tc.exp, got)
-               }
-       }
-}
-
 // We generate memmove for copy(x[1:], x[:]), however we may change it to OpMove,
 // because size is known. Check that OpMove is alias-safe, or we did call memmove.
 func TestMove(t *testing.T) {