Source file
test/ken/shift.go
1
2
3
4
5
6
7
8
9 package main
10
11 var ians [18]int;
12 var uans [18]uint;
13 var pass string;
14
15 func
16 testi(i int, t1,t2,t3 int) {
17 n := ((t1*3) + t2)*2 + t3;
18 if i != ians[n] {
19 print("itest ", t1,t2,t3,pass,
20 " is ", i, " sb ", ians[n], "\n");
21 }
22 }
23
24 func
25 index(t1,t2,t3 int) int {
26 return ((t1*3) + t2)*2 + t3;
27 }
28
29 func
30 testu(u uint, t1,t2,t3 int) {
31 n := index(t1,t2,t3);
32 if u != uans[n] {
33 print("utest ", t1,t2,t3,pass,
34 " is ", u, " sb ", uans[n], "\n");
35 }
36 }
37
38 func
39 main() {
40 var i int;
41 var u,c uint;
42
43
46 pass = "con";
47
48 testi( int(1234) << 0, 0,0,0);
49 testi( int(1234) >> 0, 0,0,1);
50 testi( int(1234) << 5, 0,1,0);
51 testi( int(1234) >> 5, 0,1,1);
52
53 testi(int(-1234) << 0, 1,0,0);
54 testi(int(-1234) >> 0, 1,0,1);
55 testi(int(-1234) << 5, 1,1,0);
56 testi(int(-1234) >> 5, 1,1,1);
57
58 testu(uint(5678) << 0, 2,0,0);
59 testu(uint(5678) >> 0, 2,0,1);
60 testu(uint(5678) << 5, 2,1,0);
61 testu(uint(5678) >> 5, 2,1,1);
62
63
66 pass = "var";
67
68 for t1:=0; t1<3; t1++ {
69 for t2:=0; t2<3; t2++ {
70 for t3:=0; t3<2; t3++ {
71 switch t1 {
72 case 0: i = 1234;
73 case 1: i = -1234;
74 case 2: u = 5678;
75 }
76 switch t2 {
77 case 0: c = 0;
78 case 1: c = 5;
79 case 2: c = 1025;
80 }
81 switch t3 {
82 case 0: i <<= c; u <<= c;
83 case 1: i >>= c; u >>= c;
84 }
85 switch t1 {
86 case 0: testi(i,t1,t2,t3);
87 case 1: testi(i,t1,t2,t3);
88 case 2: testu(u,t1,t2,t3);
89 }
90 }
91 }
92 }
93 }
94
95 func
96 init() {
97
100
101 ians[index(0,0,0)] = 1234;
102 ians[index(0,0,1)] = 1234;
103 ians[index(0,1,0)] = 39488;
104 ians[index(0,1,1)] = 38;
105 ians[index(0,2,0)] = 0;
106 ians[index(0,2,1)] = 0;
107
108 ians[index(1,0,0)] = -1234;
109 ians[index(1,0,1)] = -1234;
110 ians[index(1,1,0)] = -39488;
111 ians[index(1,1,1)] = -39;
112 ians[index(1,2,0)] = 0;
113 ians[index(1,2,1)] = -1;
114
115 uans[index(2,0,0)] = 5678;
116 uans[index(2,0,1)] = 5678;
117 uans[index(2,1,0)] = 181696;
118 uans[index(2,1,1)] = 177;
119 uans[index(2,2,0)] = 0;
120 uans[index(2,2,1)] = 0;
121 }
122
View as plain text