1 |
14 |
hellwig |
/*
|
2 |
|
|
* mkshtest.c -- generate shift test program
|
3 |
|
|
*/
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
#include <stdio.h>
|
7 |
|
|
#include <stdlib.h>
|
8 |
|
|
#include <string.h>
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
#define N0 ((unsigned) 0x48E6F0B2)
|
12 |
|
|
#define N1 ((unsigned) 0xC8E6F0B3)
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
int chooseReg(void) {
|
16 |
|
|
int r;
|
17 |
|
|
|
18 |
|
|
r = (rand() >> 8) % 16;
|
19 |
|
|
return r + 8;
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
void chooseRegs(int *r1, int *r2, int *r3, int *r4) {
|
24 |
|
|
*r1 = chooseReg();
|
25 |
|
|
do {
|
26 |
|
|
*r2 = chooseReg();
|
27 |
|
|
} while (*r2 == *r1);
|
28 |
|
|
do {
|
29 |
|
|
*r3 = chooseReg();
|
30 |
|
|
} while (*r3 == *r2 || *r3 == *r1);
|
31 |
|
|
do {
|
32 |
|
|
*r4 = chooseReg();
|
33 |
|
|
} while (*r4 == *r3 || *r4 == *r2 || *r4 == *r1);
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
int newLabel(void) {
|
38 |
|
|
static int lbl = 1000;
|
39 |
|
|
return lbl++;
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
unsigned sar(unsigned n, int shamt) {
|
44 |
|
|
unsigned mask;
|
45 |
|
|
|
46 |
|
|
mask = (n & 0x80000000) ? ~((unsigned) 0xFFFFFFFF >> shamt) : 0x00000000;
|
47 |
|
|
return mask | (n >> shamt);
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
int main(void) {
|
52 |
|
|
int shamt;
|
53 |
|
|
int src;
|
54 |
|
|
int sha;
|
55 |
|
|
int dst;
|
56 |
|
|
int ref;
|
57 |
|
|
int lbl;
|
58 |
|
|
|
59 |
|
|
printf("\tadd\t$7,$0,'.'\n");
|
60 |
|
|
for (shamt = 0; shamt < 32; shamt++) {
|
61 |
|
|
/* sll, N0 */
|
62 |
|
|
printf("\t; sll, n0\n");
|
63 |
|
|
chooseRegs(&src, &sha, &dst, &ref);
|
64 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", src, N0);
|
65 |
|
|
printf("\tadd\t$%d,$0,%d\n", sha, shamt);
|
66 |
|
|
printf("\tsll\t$%d,$%d,$%d\n", dst, src, sha);
|
67 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", ref, N0 << shamt);
|
68 |
|
|
lbl = newLabel();
|
69 |
|
|
printf("\tbeq\t$%d,$%d,L%d\n", dst, ref, lbl);
|
70 |
|
|
printf("\tadd\t$7,$0,'?'\n");
|
71 |
|
|
printf("L%d:\n", lbl);
|
72 |
|
|
/* slli, N0 */
|
73 |
|
|
printf("\t; slli, n0\n");
|
74 |
|
|
chooseRegs(&src, &sha, &dst, &ref);
|
75 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", src, N0);
|
76 |
|
|
printf("\tsll\t$%d,$%d,%d\n", dst, src, shamt);
|
77 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", ref, N0 << shamt);
|
78 |
|
|
lbl = newLabel();
|
79 |
|
|
printf("\tbeq\t$%d,$%d,L%d\n", dst, ref, lbl);
|
80 |
|
|
printf("\tadd\t$7,$0,'?'\n");
|
81 |
|
|
printf("L%d:\n", lbl);
|
82 |
|
|
/* sll, N1 */
|
83 |
|
|
printf("\t; sll, n1\n");
|
84 |
|
|
chooseRegs(&src, &sha, &dst, &ref);
|
85 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", src, N1);
|
86 |
|
|
printf("\tadd\t$%d,$0,%d\n", sha, shamt);
|
87 |
|
|
printf("\tsll\t$%d,$%d,$%d\n", dst, src, sha);
|
88 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", ref, N1 << shamt);
|
89 |
|
|
lbl = newLabel();
|
90 |
|
|
printf("\tbeq\t$%d,$%d,L%d\n", dst, ref, lbl);
|
91 |
|
|
printf("\tadd\t$7,$0,'?'\n");
|
92 |
|
|
printf("L%d:\n", lbl);
|
93 |
|
|
/* slli, N1 */
|
94 |
|
|
printf("\t; slli, n1\n");
|
95 |
|
|
chooseRegs(&src, &sha, &dst, &ref);
|
96 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", src, N1);
|
97 |
|
|
printf("\tsll\t$%d,$%d,%d\n", dst, src, shamt);
|
98 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", ref, N1 << shamt);
|
99 |
|
|
lbl = newLabel();
|
100 |
|
|
printf("\tbeq\t$%d,$%d,L%d\n", dst, ref, lbl);
|
101 |
|
|
printf("\tadd\t$7,$0,'?'\n");
|
102 |
|
|
printf("L%d:\n", lbl);
|
103 |
|
|
|
104 |
|
|
/* slr, N0 */
|
105 |
|
|
printf("\t; slr, n0\n");
|
106 |
|
|
chooseRegs(&src, &sha, &dst, &ref);
|
107 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", src, N0);
|
108 |
|
|
printf("\tadd\t$%d,$0,%d\n", sha, shamt);
|
109 |
|
|
printf("\tslr\t$%d,$%d,$%d\n", dst, src, sha);
|
110 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", ref, N0 >> shamt);
|
111 |
|
|
lbl = newLabel();
|
112 |
|
|
printf("\tbeq\t$%d,$%d,L%d\n", dst, ref, lbl);
|
113 |
|
|
printf("\tadd\t$7,$0,'?'\n");
|
114 |
|
|
printf("L%d:\n", lbl);
|
115 |
|
|
/* slri, N0 */
|
116 |
|
|
printf("\t; slri, n0\n");
|
117 |
|
|
chooseRegs(&src, &sha, &dst, &ref);
|
118 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", src, N0);
|
119 |
|
|
printf("\tslr\t$%d,$%d,%d\n", dst, src, shamt);
|
120 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", ref, N0 >> shamt);
|
121 |
|
|
lbl = newLabel();
|
122 |
|
|
printf("\tbeq\t$%d,$%d,L%d\n", dst, ref, lbl);
|
123 |
|
|
printf("\tadd\t$7,$0,'?'\n");
|
124 |
|
|
printf("L%d:\n", lbl);
|
125 |
|
|
/* slr, N1 */
|
126 |
|
|
printf("\t; slr, n1\n");
|
127 |
|
|
chooseRegs(&src, &sha, &dst, &ref);
|
128 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", src, N1);
|
129 |
|
|
printf("\tadd\t$%d,$0,%d\n", sha, shamt);
|
130 |
|
|
printf("\tslr\t$%d,$%d,$%d\n", dst, src, sha);
|
131 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", ref, N1 >> shamt);
|
132 |
|
|
lbl = newLabel();
|
133 |
|
|
printf("\tbeq\t$%d,$%d,L%d\n", dst, ref, lbl);
|
134 |
|
|
printf("\tadd\t$7,$0,'?'\n");
|
135 |
|
|
printf("L%d:\n", lbl);
|
136 |
|
|
/* slri, N1 */
|
137 |
|
|
printf("\t; slri, n1\n");
|
138 |
|
|
chooseRegs(&src, &sha, &dst, &ref);
|
139 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", src, N1);
|
140 |
|
|
printf("\tslr\t$%d,$%d,%d\n", dst, src, shamt);
|
141 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", ref, N1 >> shamt);
|
142 |
|
|
lbl = newLabel();
|
143 |
|
|
printf("\tbeq\t$%d,$%d,L%d\n", dst, ref, lbl);
|
144 |
|
|
printf("\tadd\t$7,$0,'?'\n");
|
145 |
|
|
printf("L%d:\n", lbl);
|
146 |
|
|
|
147 |
|
|
/* sar, N0 */
|
148 |
|
|
printf("\t; sar, n0\n");
|
149 |
|
|
chooseRegs(&src, &sha, &dst, &ref);
|
150 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", src, N0);
|
151 |
|
|
printf("\tadd\t$%d,$0,%d\n", sha, shamt);
|
152 |
|
|
printf("\tsar\t$%d,$%d,$%d\n", dst, src, sha);
|
153 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", ref, sar(N0, shamt));
|
154 |
|
|
lbl = newLabel();
|
155 |
|
|
printf("\tbeq\t$%d,$%d,L%d\n", dst, ref, lbl);
|
156 |
|
|
printf("\tadd\t$7,$0,'?'\n");
|
157 |
|
|
printf("L%d:\n", lbl);
|
158 |
|
|
/* sari, N0 */
|
159 |
|
|
printf("\t; sari, n0\n");
|
160 |
|
|
chooseRegs(&src, &sha, &dst, &ref);
|
161 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", src, N0);
|
162 |
|
|
printf("\tsar\t$%d,$%d,%d\n", dst, src, shamt);
|
163 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", ref, sar(N0, shamt));
|
164 |
|
|
lbl = newLabel();
|
165 |
|
|
printf("\tbeq\t$%d,$%d,L%d\n", dst, ref, lbl);
|
166 |
|
|
printf("\tadd\t$7,$0,'?'\n");
|
167 |
|
|
printf("L%d:\n", lbl);
|
168 |
|
|
/* sar, N1 */
|
169 |
|
|
printf("\t; sar, n1\n");
|
170 |
|
|
chooseRegs(&src, &sha, &dst, &ref);
|
171 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", src, N1);
|
172 |
|
|
printf("\tadd\t$%d,$0,%d\n", sha, shamt);
|
173 |
|
|
printf("\tsar\t$%d,$%d,$%d\n", dst, src, sha);
|
174 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", ref, sar(N1, shamt));
|
175 |
|
|
lbl = newLabel();
|
176 |
|
|
printf("\tbeq\t$%d,$%d,L%d\n", dst, ref, lbl);
|
177 |
|
|
printf("\tadd\t$7,$0,'?'\n");
|
178 |
|
|
printf("L%d:\n", lbl);
|
179 |
|
|
/* sari, N1 */
|
180 |
|
|
printf("\t; sari, n1\n");
|
181 |
|
|
chooseRegs(&src, &sha, &dst, &ref);
|
182 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", src, N1);
|
183 |
|
|
printf("\tsar\t$%d,$%d,%d\n", dst, src, shamt);
|
184 |
|
|
printf("\tadd\t$%d,$0,0x%08X\n", ref, sar(N1, shamt));
|
185 |
|
|
lbl = newLabel();
|
186 |
|
|
printf("\tbeq\t$%d,$%d,L%d\n", dst, ref, lbl);
|
187 |
|
|
printf("\tadd\t$7,$0,'?'\n");
|
188 |
|
|
printf("L%d:\n", lbl);
|
189 |
|
|
}
|
190 |
|
|
printf("out:\n");
|
191 |
|
|
printf("\tadd\t$6,$0,0xF0300000\n");
|
192 |
|
|
printf("out1:\n");
|
193 |
|
|
printf("\tldw\t$5,$6,8\n");
|
194 |
|
|
printf("\tand\t$5,$5,1\n");
|
195 |
|
|
printf("\tbeq\t$5,$0,out1\n");
|
196 |
|
|
printf("\tstw\t$7,$6,12\n");
|
197 |
|
|
printf("halt:\n");
|
198 |
|
|
printf("\tj\thalt\n");
|
199 |
|
|
return 0;
|
200 |
|
|
}
|