OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [ken/] [shift.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $G $D/$F.go && $L $F.$A && ./$A.out
2
 
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.
6
 
7
package main
8
 
9
var     ians    [18]int;
10
var     uans    [18]uint;
11
var     pass    string;
12
 
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");
19
        }
20
}
21
 
22
func
23
index(t1,t2,t3 int) int {
24
        return ((t1*3) + t2)*2 + t3;
25
}
26
 
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");
33
        }
34
}
35
 
36
func
37
main() {
38
        var i int;
39
        var u,c uint;
40
 
41
        /*
42
         * test constant evaluations
43
         */
44
        pass = "con";   // constant part
45
 
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);
50
 
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);
55
 
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);
60
 
61
        /*
62
         * test variable evaluations
63
         */
64
        pass = "var";   // variable part
65
 
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;
73
                }
74
                switch t2 {
75
                case 0: c =    0;
76
                case 1: c =    5;
77
                case 2: c = 1025;
78
                }
79
                switch t3 {
80
                case 0: i <<= c; u <<= c;
81
                case 1: i >>= c; u >>= c;
82
                }
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);
87
                }
88
        }
89
        }
90
        }
91
}
92
 
93
func
94
init() {
95
        /*
96
         * set the 'correct' answer
97
         */
98
 
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;
105
 
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;
112
 
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;
119
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.