github.com/brownsys/tracing-framework-go@v0.0.0-20161210174012-0542a62412fe/go/darwin_amd64/test/intrinsic.dir/main.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 T "runtime/internal/sys" 10 ) 11 12 var A = []uint64{0x0102030405060708, 0x1122334455667788} 13 var B = []uint64{0x0807060504030201, 0x8877665544332211} 14 15 var errors int 16 17 func logf(f string, args ...interface{}) { 18 errors++ 19 fmt.Printf(f, args...) 20 if errors > 100 { // 100 is enough spewage 21 panic("100 errors is plenty is enough") 22 } 23 } 24 25 func test(i, x uint64) { 26 t := T.Ctz64(x) // ERROR "intrinsic substitution for Ctz64" 27 if i != t { 28 logf("Ctz64(0x%x) expected %d but got %d\n", x, i, t) 29 } 30 x = -x 31 t = T.Ctz64(x) // ERROR "intrinsic substitution for Ctz64" 32 if i != t { 33 logf("Ctz64(0x%x) expected %d but got %d\n", x, i, t) 34 } 35 36 if i <= 32 { 37 x32 := uint32(x) 38 t32 := T.Ctz32(x32) // ERROR "intrinsic substitution for Ctz32" 39 if uint32(i) != t32 { 40 logf("Ctz32(0x%x) expected %d but got %d\n", x32, i, t32) 41 } 42 x32 = -x32 43 t32 = T.Ctz32(x32) // ERROR "intrinsic substitution for Ctz32" 44 if uint32(i) != t32 { 45 logf("Ctz32(0x%x) expected %d but got %d\n", x32, i, t32) 46 } 47 } 48 if i <= 16 { 49 x16 := uint16(x) 50 t16 := T.Ctz16(x16) // ERROR "intrinsic substitution for Ctz16" 51 if uint16(i) != t16 { 52 logf("Ctz16(0x%x) expected %d but got %d\n", x16, i, t16) 53 } 54 x16 = -x16 55 t16 = T.Ctz16(x16) // ERROR "intrinsic substitution for Ctz16" 56 if uint16(i) != t16 { 57 logf("Ctz16(0x%x) expected %d but got %d\n", x16, i, t16) 58 } 59 } 60 } 61 62 func main() { 63 // Test Bswap first because the other test relies on it 64 // working correctly (to implement bit reversal). 65 for i := range A { 66 x := A[i] 67 y := B[i] 68 X := T.Bswap64(x) // ERROR "intrinsic substitution for Bswap64" 69 Y := T.Bswap64(y) // ERROR "intrinsic substitution for Bswap64" 70 if y != X { 71 logf("Bswap64(0x%08x) expected 0x%08x but got 0x%08x\n", x, y, X) 72 } 73 if x != Y { 74 logf("Bswap64(0x%08x) expected 0x%08x but got 0x%08x\n", y, x, Y) 75 } 76 77 x32 := uint32(X) 78 y32 := uint32(Y >> 32) 79 80 X32 := T.Bswap32(x32) // ERROR "intrinsic substitution for Bswap32" 81 Y32 := T.Bswap32(y32) // ERROR "intrinsic substitution for Bswap32" 82 if y32 != X32 { 83 logf("Bswap32(0x%08x) expected 0x%08x but got 0x%08x\n", x32, y32, X32) 84 } 85 if x32 != Y32 { 86 logf("Bswap32(0x%08x) expected 0x%08x but got 0x%08x\n", y32, x32, Y32) 87 } 88 } 89 90 // Zero is a special case, be sure it is done right. 91 if T.Ctz16(0) != 16 { // ERROR "intrinsic substitution for Ctz16" 92 logf("ctz16(0) != 16") 93 } 94 if T.Ctz32(0) != 32 { // ERROR "intrinsic substitution for Ctz32" 95 logf("ctz32(0) != 32") 96 } 97 if T.Ctz64(0) != 64 { // ERROR "intrinsic substitution for Ctz64" 98 logf("ctz64(0) != 64") 99 } 100 101 for i := uint64(0); i <= 64; i++ { 102 for j := uint64(1); j <= 255; j += 2 { 103 for k := uint64(1); k <= 65537; k += 128 { 104 x := (j * k) << i 105 test(i, x) 106 } 107 } 108 } 109 }