Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / testsuite / go.test / test / ken / shift.go
blob157a07aec54bf5f4e179e8002dc1382c934b1822
1 // $G $D/$F.go && $L $F.$A && ./$A.out
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 package main
9 var ians [18]int;
10 var uans [18]uint;
11 var pass string;
13 func
14 testi(i int, t1,t2,t3 int) {
15 n := ((t1*3) + t2)*2 + t3;
16 if i != ians[n] {
17 print("itest ", t1,t2,t3,pass,
18 " is ", i, " sb ", ians[n], "\n");
22 func
23 index(t1,t2,t3 int) int {
24 return ((t1*3) + t2)*2 + t3;
27 func
28 testu(u uint, t1,t2,t3 int) {
29 n := index(t1,t2,t3);
30 if u != uans[n] {
31 print("utest ", t1,t2,t3,pass,
32 " is ", u, " sb ", uans[n], "\n");
36 func
37 main() {
38 var i int;
39 var u,c uint;
42 * test constant evaluations
44 pass = "con"; // constant part
46 testi( int(1234) << 0, 0,0,0);
47 testi( int(1234) >> 0, 0,0,1);
48 testi( int(1234) << 5, 0,1,0);
49 testi( int(1234) >> 5, 0,1,1);
51 testi(int(-1234) << 0, 1,0,0);
52 testi(int(-1234) >> 0, 1,0,1);
53 testi(int(-1234) << 5, 1,1,0);
54 testi(int(-1234) >> 5, 1,1,1);
56 testu(uint(5678) << 0, 2,0,0);
57 testu(uint(5678) >> 0, 2,0,1);
58 testu(uint(5678) << 5, 2,1,0);
59 testu(uint(5678) >> 5, 2,1,1);
62 * test variable evaluations
64 pass = "var"; // variable part
66 for t1:=0; t1<3; t1++ { // +int, -int, uint
67 for t2:=0; t2<3; t2++ { // 0, +small, +large
68 for t3:=0; t3<2; t3++ { // <<, >>
69 switch t1 {
70 case 0: i = 1234;
71 case 1: i = -1234;
72 case 2: u = 5678;
74 switch t2 {
75 case 0: c = 0;
76 case 1: c = 5;
77 case 2: c = 1025;
79 switch t3 {
80 case 0: i <<= c; u <<= c;
81 case 1: i >>= c; u >>= c;
83 switch t1 {
84 case 0: testi(i,t1,t2,t3);
85 case 1: testi(i,t1,t2,t3);
86 case 2: testu(u,t1,t2,t3);
93 func
94 init() {
96 * set the 'correct' answer
99 ians[index(0,0,0)] = 1234;
100 ians[index(0,0,1)] = 1234;
101 ians[index(0,1,0)] = 39488;
102 ians[index(0,1,1)] = 38;
103 ians[index(0,2,0)] = 0;
104 ians[index(0,2,1)] = 0;
106 ians[index(1,0,0)] = -1234;
107 ians[index(1,0,1)] = -1234;
108 ians[index(1,1,0)] = -39488;
109 ians[index(1,1,1)] = -39;
110 ians[index(1,2,0)] = 0;
111 ians[index(1,2,1)] = -1;
113 uans[index(2,0,0)] = 5678;
114 uans[index(2,0,1)] = 5678;
115 uans[index(2,1,0)] = 181696;
116 uans[index(2,1,1)] = 177;
117 uans[index(2,2,0)] = 0;
118 uans[index(2,2,1)] = 0;