github.com/gocuntian/go@v0.0.0-20160610041250-fee02d270bf8/src/runtime/internal/sys/intrinsics_test.go (about) 1 package sys_test 2 3 import ( 4 "runtime/internal/sys" 5 "testing" 6 ) 7 8 func TestCtz64(t *testing.T) { 9 for i := uint(0); i <= 64; i++ { 10 x := uint64(5) << i 11 if got := sys.Ctz64(x); got != uint64(i) { 12 t.Errorf("Ctz64(%d)=%d, want %d", x, got, i) 13 } 14 } 15 } 16 func TestCtz32(t *testing.T) { 17 for i := uint(0); i <= 32; i++ { 18 x := uint32(5) << i 19 if got := sys.Ctz32(x); got != uint32(i) { 20 t.Errorf("Ctz32(%d)=%d, want %d", x, got, i) 21 } 22 } 23 } 24 func TestCtz16(t *testing.T) { 25 for i := uint(0); i <= 16; i++ { 26 x := uint16(5) << i 27 if got := sys.Ctz16(x); got != uint16(i) { 28 t.Errorf("Ctz16(%d)=%d, want %d", x, got, i) 29 } 30 } 31 } 32 func TestCtz8(t *testing.T) { 33 for i := uint(0); i <= 8; i++ { 34 x := uint8(5) << i 35 if got := sys.Ctz8(x); got != uint8(i) { 36 t.Errorf("Ctz8(%d)=%d, want %d", x, got, i) 37 } 38 } 39 } 40 41 func TestBswap64(t *testing.T) { 42 x := uint64(0x1122334455667788) 43 y := sys.Bswap64(x) 44 if y != 0x8877665544332211 { 45 t.Errorf("Bswap(%x)=%x, want 0x8877665544332211", x, y) 46 } 47 } 48 func TestBswap32(t *testing.T) { 49 x := uint32(0x11223344) 50 y := sys.Bswap32(x) 51 if y != 0x44332211 { 52 t.Errorf("Bswap(%x)=%x, want 0x44332211", x, y) 53 } 54 }