1 #include <stdio.h>
2
3 unsigned long long mem[] = { 0x3FF0000000000001ULL, 0x3FF0000000000000ULL,
4 0x00000000ffffffffULL, 0x1234563388994400ULL,
5 0x0000004412369801ULL, 0x111111eeeeeee220ULL,
6 0xAAAAABBBBBCCCDDDULL, 0xaa55cc2266dd2200ULL,
7 0x3FF0045698720001ULL, 0x3FF0000000000000ULL,
8 0x00000000ffffffffULL, 0x0007200059762458ULL,
9 0xaa55c200abcdefabULL, 0x852369741afedbc6ULL };
10
11
12
13 #define TEST1(instruction, RD, RS, RT, RSval, RTval) \
14 { \
15 unsigned long long result; \
16 __asm__ volatile ( \
17 "move $"#RS", %1\n\t" \
18 "move $"#RT", %2\n\t" \
19 instruction" $"#RD", $"#RS", $"#RT", 1\n\t" \
20 "move %0, $"#RD"\n\t" \
21 : "=&r"(result) \
22 : "r"(RSval), "r"(RTval) \
23 : #RD, #RS, #RT, "memory" \
24 ); \
25 printf(instruction":: %llx\n", result); \
26 }
27
28 #define TEST2(instruction, RS, RT, RSval, RTval) \
29 { \
30 unsigned long long result; \
31 __asm__ volatile ( \
32 "move $"#RS", %1\n\t" \
33 "move $"#RT", %2\n\t" \
34 instruction" $"#RS", $"#RT", 1\n\t" \
35 "move %0, $"#RS"\n\t" \
36 : "=&r"(result) \
37 : "r"(RSval), "r"(RTval) \
38 : #RS, #RT, "memory" \
39 ); \
40 printf(instruction":: %llx\n", result); \
41 }
42
43 #define TEST3(instruction, RS, RSval) \
44 { \
45 unsigned long long result; \
46 __asm__ volatile ( \
47 "move $"#RS", %1\n\t" \
48 instruction" $"#RS", $"#RS", 1\n\t" \
49 "move %0, $"#RS"\n\t" \
50 : "=&r"(result) \
51 : "r"(RSval) \
52 : #RS, "memory" \
53 ); \
54 printf(instruction":: %llx\n", result); \
55 }
56
57 #define TEST4(instruction, RS, RT, RSval, RTval) \
58 { \
59 unsigned long long result; \
60 __asm__ volatile ( \
61 "move $"#RS", %1\n\t" \
62 "move $"#RT", %2\n\t" \
63 instruction" $"#RS", $"#RT" \n\t" \
64 "move %0, $"#RS"\n\t" \
65 : "=&r"(result) \
66 : "r"(RSval), "r"(RTval) \
67 : #RS, #RT, "memory" \
68 ); \
69 printf(instruction":: %llx\n", result); \
70 }
71
72 #define TEST5(instruction, RD, RS, RT, RSval, RTval) \
73 { \
74 unsigned long long result; \
75 __asm__ volatile ( \
76 "move $"#RS", %1\n\t" \
77 "move $"#RT", %2\n\t" \
78 instruction" $"#RD", $"#RS", $"#RT" \n\t" \
79 "move %0, $"#RD"\n\t" \
80 : "=&r"(result) \
81 : "r"(RSval), "r"(RTval) \
82 : #RD, #RS, #RT, "memory" \
83 ); \
84 printf(instruction":: %llx\n", result); \
85 }
86
87 #define TEST6(instruction, RSval, RD) \
88 { \
89 unsigned long long out = 0; \
90 __asm__ __volatile__( \
91 ".set push \n\t" \
92 ".set noreorder \n\t" \
93 "lbl"instruction#RSval ": \n\t" \
94 "or $0, $0, $0 \n\t" \
95 "and $0, $0, $0 \n\t" \
96 instruction" $"#RD ", lbl"instruction#RSval "\n\t" \
97 "move %0, $"#RD "\n\t" \
98 ".set pop \n\t" \
99 : "=r" (out) \
100 : \
101 : "t0", "t1" \
102 ); \
103 printf("%s :: out: 0x%llx\n", instruction, out); \
104 }
105
106
main()107 int main() {
108
109 #if (__mips_isa_rev>=6)
110 printf("dalign\n");
111 TEST1("dalign" , t0, t1, t2, mem[0], 0);
112 TEST1("dalign" , t1, t2, t3, mem[1], 1);
113 TEST1("dalign" , t2, t3, v0, mem[2], 2);
114 TEST1("dalign" , t3, v0, v1, mem[3], 3);
115 TEST1("dalign" , v0, v1, a0, mem[4], 4);
116 TEST1("dalign" , v1, a0, a1, mem[5], 5);
117 TEST1("dalign" , a0, a1, a2, mem[6], 6);
118 TEST1("dalign" , a1, a2, a3, mem[7], 7);
119 TEST1("dalign" , s0, s1, s2, mem[8], 8);
120 TEST1("dalign" , s1, s2, s3, mem[9], 9);
121 TEST1("dalign" , s2, s3, s4, mem[10], 10);
122 TEST1("dalign" , s3, s4, s5, mem[11], 11);
123 TEST1("dalign" , s4, s5, s6, mem[12], 12);
124 TEST1("dalign" , s5, s6, s7, mem[13], 13);
125
126 printf("\ndaui\n");
127 TEST2("daui" , t0, t1, mem[0], 0);
128 TEST2("daui" , t1, t2, mem[1], 1);
129 TEST2("daui" , t2, t3, mem[2], 2);
130 TEST2("daui" , t3, v0, mem[3], 3);
131 TEST2("daui" , v0, v1, mem[4], 4);
132 TEST2("daui" , v1, a0, mem[5], 5);
133 TEST2("daui" , a0, a1, mem[6], 6);
134 TEST2("daui" , a1, a2, mem[7], 7);
135 TEST2("daui" , a2, a3, mem[8], 8);
136 TEST2("daui" , s0, s1, mem[9], 9);
137 TEST2("daui" , s2, s3, mem[10], 10);
138 TEST2("daui" , s3, s4, mem[11], 11);
139 TEST2("daui" , s4, s5, mem[12], 12);
140 TEST2("daui" , s5, s6, mem[13], 13);
141
142 printf("\ndahi\n");
143 TEST3("dahi" , t0, mem[0]);
144 TEST3("dahi" , t1, mem[1]);
145 TEST3("dahi" , t2, mem[2]);
146 TEST3("dahi" , t3, mem[3]);
147 TEST3("dahi" , v0, mem[4]);
148 TEST3("dahi" , v1, mem[5]);
149 TEST3("dahi" , a0, mem[6]);
150 TEST3("dahi" , a1, mem[7]);
151 TEST3("dahi" , a2, mem[8]);
152 TEST3("dahi" , a3, mem[9]);
153 TEST3("dahi" , s0, mem[10]);
154 TEST3("dahi" , s1, mem[11]);
155 TEST3("dahi" , s2, mem[12]);
156 TEST3("dahi" , s3, mem[13]);
157
158 printf("\ndati\n");
159 TEST3("dati" , t0, mem[0]);
160 TEST3("dati" , t1, mem[1]);
161 TEST3("dati" , t2, mem[2]);
162 TEST3("dati" , t3, mem[3]);
163 TEST3("dati" , v0, mem[4]);
164 TEST3("dati" , v1, mem[5]);
165 TEST3("dati" , a0, mem[6]);
166 TEST3("dati" , a1, mem[7]);
167 TEST3("dati" , a2, mem[8]);
168 TEST3("dati" , a3, mem[9]);
169 TEST3("dati" , s0, mem[10]);
170 TEST3("dati" , s1, mem[11]);
171 TEST3("dati" , s2, mem[12]);
172 TEST3("dati" , s3, mem[13]);
173
174 printf("\ndbitswap\n");
175 TEST4("dbitswap" , t0, t1, mem[0], 0);
176 TEST4("dbitswap" , t1, t2, mem[1], 1);
177 TEST4("dbitswap" , t2, t3, mem[2], 2);
178 TEST4("dbitswap" , t3, v0, mem[3], 3);
179 TEST4("dbitswap" , v0, v1, mem[4], 4);
180 TEST4("dbitswap" , v1, a0, mem[5], 5);
181 TEST4("dbitswap" , a0, a1, mem[6], 6);
182 TEST4("dbitswap" , a1, a2, mem[7], 7);
183 TEST4("dbitswap" , a2, a3, mem[8], 8);
184 TEST4("dbitswap" , a3, s0, mem[9], 9);
185 TEST4("dbitswap" , s0, s1, mem[10], 10);
186 TEST4("dbitswap" , s1, s2, mem[11], 11);
187 TEST4("dbitswap" , s2, s3, mem[12], 12);
188 TEST4("dbitswap" , s3, s4, mem[13], 13);
189
190 printf("\nddiv\n");
191 TEST5("ddiv" , t0, t1, t2, mem[0], mem[1]);
192 TEST5("ddiv" , t1, t2, t3, mem[1], mem[2]);
193 TEST5("ddiv" , t2, t3, v0, mem[2], mem[3]);
194 TEST5("ddiv" , t3, v0, v1, mem[3], mem[4]);
195 TEST5("ddiv" , v0, v1, a0, mem[4], mem[5]);
196 TEST5("ddiv" , v1, a0, a1, mem[5], mem[6]);
197 TEST5("ddiv" , a0, a1, a2, mem[6], mem[7]);
198 TEST5("ddiv" , a1, a2, a3, mem[7], mem[8]);
199 TEST5("ddiv" , a2, a3, s0, mem[8], mem[9]);
200 TEST5("ddiv" , a3, s0, s1, mem[9], mem[10]);
201 TEST5("ddiv" , s0, s1, s2, mem[10], mem[11]);
202 TEST5("ddiv" , s2, s3, s4, mem[11], mem[12]);
203 TEST5("ddiv" , s3, s4, s5, mem[12], mem[13]);
204 TEST5("ddiv" , s4, s5, s6, mem[13], mem[0]);
205
206 printf("\ndmod\n");
207 TEST5("dmod" , t0, t1, t2, mem[0], mem[1]);
208 TEST5("dmod" , t1, t2, t3, mem[1], mem[2]);
209 TEST5("dmod" , t2, t3, v0, mem[2], mem[3]);
210 TEST5("dmod" , t3, v0, v1, mem[3], mem[4]);
211 TEST5("dmod" , v0, v1, a0, mem[4], mem[5]);
212 TEST5("dmod" , v1, a0, a1, mem[5], mem[6]);
213 TEST5("dmod" , a0, a1, a2, mem[6], mem[7]);
214 TEST5("dmod" , a1, a2, a3, mem[7], mem[8]);
215 TEST5("dmod" , a2, a3, s0, mem[8], mem[9]);
216 TEST5("dmod" , a3, s0, s1, mem[9], mem[10]);
217 TEST5("dmod" , s0, s1, s2, mem[10], mem[11]);
218 TEST5("dmod" , s2, s3, s4, mem[11], mem[12]);
219 TEST5("dmod" , s3, s4, s5, mem[12], mem[13]);
220 TEST5("dmod" , s4, s5, s6, mem[13], mem[0]);
221
222 printf("\nddivu\n");
223 TEST5("ddivu" , t0, t1, t2, mem[0], mem[1]);
224 TEST5("ddivu" , t1, t2, t3, mem[1], mem[2]);
225 TEST5("ddivu" , t2, t3, v0, mem[2], mem[3]);
226 TEST5("ddivu" , t3, v0, v1, mem[3], mem[4]);
227 TEST5("ddivu" , v0, v1, a0, mem[4], mem[5]);
228 TEST5("ddivu" , v1, a0, a1, mem[5], mem[6]);
229 TEST5("ddivu" , a0, a1, a2, mem[6], mem[7]);
230 TEST5("ddivu" , a1, a2, a3, mem[7], mem[8]);
231 TEST5("ddivu" , a2, a3, s0, mem[8], mem[9]);
232 TEST5("ddivu" , a3, s0, s1, mem[9], mem[10]);
233 TEST5("ddivu" , s0, s1, s2, mem[10], mem[11]);
234 TEST5("ddivu" , s2, s3, s4, mem[11], mem[12]);
235 TEST5("ddivu" , s3, s4, s5, mem[12], mem[13]);
236 TEST5("ddivu" , s4, s5, s6, mem[13], mem[0]);
237
238 printf("\ndmodu\n");
239 TEST5("dmodu" , t0, t1, t2, mem[0], mem[1]);
240 TEST5("dmodu" , t1, t2, t3, mem[1], mem[2]);
241 TEST5("dmodu" , t2, t3, v0, mem[2], mem[3]);
242 TEST5("dmodu" , t3, v0, v1, mem[3], mem[4]);
243 TEST5("dmodu" , v0, v1, a0, mem[4], mem[5]);
244 TEST5("dmodu" , v1, a0, a1, mem[5], mem[6]);
245 TEST5("dmodu" , a0, a1, a2, mem[6], mem[7]);
246 TEST5("dmodu" , a1, a2, a3, mem[7], mem[8]);
247 TEST5("dmodu" , a2, a3, s0, mem[8], mem[9]);
248 TEST5("dmodu" , a3, s0, s1, mem[9], mem[10]);
249 TEST5("dmodu" , s0, s1, s2, mem[10], mem[11]);
250 TEST5("dmodu" , s2, s3, s4, mem[11], mem[12]);
251 TEST5("dmodu" , s3, s4, s5, mem[12], mem[13]);
252 TEST5("dmodu" , s4, s5, s6, mem[13], mem[0]);
253
254 printf("\ndlsa\n");
255 TEST1("dlsa" , t0, t1, t2, mem[0], 0);
256 TEST1("dlsa" , t1, t2, t3, mem[1], 1);
257 TEST1("dlsa" , t2, t3, v0, mem[2], 2);
258 TEST1("dlsa" , t3, v0, v1, mem[3], 3);
259 TEST1("dlsa" , v0, v1, a0, mem[4], 4);
260 TEST1("dlsa" , v1, a0, a1, mem[5], 5);
261 TEST1("dlsa" , a0, a1, a2, mem[6], 6);
262 TEST1("dlsa" , a1, a2, a3, mem[7], 7);
263 TEST1("dlsa" , s0, s1, s2, mem[8], 8);
264 TEST1("dlsa" , s1, s2, s3, mem[9], 9);
265 TEST1("dlsa" , s2, s3, s4, mem[10], 10);
266 TEST1("dlsa" , s3, s4, s5, mem[11], 11);
267 TEST1("dlsa" , s4, s5, s6, mem[12], 12);
268 TEST1("dlsa" , s5, s6, s7, mem[13], 13);
269
270 printf("\ndmul\n");
271 TEST5("dmul" , t0, t1, t2, mem[0], mem[1]);
272 TEST5("dmul" , t1, t2, t3, mem[1], mem[2]);
273 TEST5("dmul" , t2, t3, v0, mem[2], mem[3]);
274 TEST5("dmul" , t3, v0, v1, mem[3], mem[4]);
275 TEST5("dmul" , v0, v1, a0, mem[4], mem[5]);
276 TEST5("dmul" , v1, a0, a1, mem[5], mem[6]);
277 TEST5("dmul" , a0, a1, a2, mem[6], mem[7]);
278 TEST5("dmul" , a1, a2, a3, mem[7], mem[8]);
279 TEST5("dmul" , a2, a3, s0, mem[8], mem[9]);
280 TEST5("dmul" , a3, s0, s1, mem[9], mem[10]);
281 TEST5("dmul" , s0, s1, s2, mem[10], mem[11]);
282 TEST5("dmul" , s2, s3, s4, mem[11], mem[12]);
283 TEST5("dmul" , s3, s4, s5, mem[12], mem[13]);
284 TEST5("dmul" , s4, s5, s6, mem[13], mem[0]);
285
286 printf("\ndmuh\n");
287 TEST5("dmuh" , t0, t1, t2, mem[0], mem[1]);
288 TEST5("dmuh" , t1, t2, t3, mem[1], mem[2]);
289 TEST5("dmuh" , t2, t3, v0, mem[2], mem[3]);
290 TEST5("dmuh" , t3, v0, v1, mem[3], mem[4]);
291 TEST5("dmuh" , v0, v1, a0, mem[4], mem[5]);
292 TEST5("dmuh" , v1, a0, a1, mem[5], mem[6]);
293 TEST5("dmuh" , a0, a1, a2, mem[6], mem[7]);
294 TEST5("dmuh" , a1, a2, a3, mem[7], mem[8]);
295 TEST5("dmuh" , a2, a3, s0, mem[8], mem[9]);
296 TEST5("dmuh" , a3, s0, s1, mem[9], mem[10]);
297 TEST5("dmuh" , s0, s1, s2, mem[10], mem[11]);
298 TEST5("dmuh" , s2, s3, s4, mem[11], mem[12]);
299 TEST5("dmuh" , s3, s4, s5, mem[12], mem[13]);
300 TEST5("dmuh" , s4, s5, s6, mem[13], mem[0]);
301
302 printf("\ndmulu\n");
303 TEST5("dmulu" , t0, t1, t2, mem[0], mem[1]);
304 TEST5("dmulu" , t1, t2, t3, mem[1], mem[2]);
305 TEST5("dmulu" , t2, t3, v0, mem[2], mem[3]);
306 TEST5("dmulu" , t3, v0, v1, mem[3], mem[4]);
307 TEST5("dmulu" , v0, v1, a0, mem[4], mem[5]);
308 TEST5("dmulu" , v1, a0, a1, mem[5], mem[6]);
309 TEST5("dmulu" , a0, a1, a2, mem[6], mem[7]);
310 TEST5("dmulu" , a1, a2, a3, mem[7], mem[8]);
311 TEST5("dmulu" , a2, a3, s0, mem[8], mem[9]);
312 TEST5("dmulu" , a3, s0, s1, mem[9], mem[10]);
313 TEST5("dmulu" , s0, s1, s2, mem[10], mem[11]);
314 TEST5("dmulu" , s2, s3, s4, mem[11], mem[12]);
315 TEST5("dmulu" , s3, s4, s5, mem[12], mem[13]);
316 TEST5("dmulu" , s4, s5, s6, mem[13], mem[0]);
317
318 printf("\ndmuhu\n");
319 TEST5("dmuhu" , t0, t1, t2, mem[0], mem[1]);
320 TEST5("dmuhu" , t1, t2, t3, mem[1], mem[2]);
321 TEST5("dmuhu" , t2, t3, v0, mem[2], mem[3]);
322 TEST5("dmuhu" , t3, v0, v1, mem[3], mem[4]);
323 TEST5("dmuhu" , v0, v1, a0, mem[4], mem[5]);
324 TEST5("dmuhu" , v1, a0, a1, mem[5], mem[6]);
325 TEST5("dmuhu" , a0, a1, a2, mem[6], mem[7]);
326 TEST5("dmuhu" , a1, a2, a3, mem[7], mem[8]);
327 TEST5("dmuhu" , a2, a3, s0, mem[8], mem[9]);
328 TEST5("dmuhu" , a3, s0, s1, mem[9], mem[10]);
329 TEST5("dmuhu" , s0, s1, s2, mem[10], mem[11]);
330 TEST5("dmuhu" , s2, s3, s4, mem[11], mem[12]);
331 TEST5("dmuhu" , s3, s4, s5, mem[12], mem[13]);
332 TEST5("dmuhu" , s4, s5, s6, mem[13], mem[0]);
333
334 printf("\nldpc\n");
335 TEST6("ldpc", 0, v0);
336 TEST6("ldpc", 4, v1);
337 TEST6("ldpc", 16, a0);
338 TEST6("ldpc", 64, a1);
339 TEST6("ldpc", 256, a3);
340 TEST6("ldpc", 1024, t0);
341 TEST6("ldpc", 4096, t1);
342 TEST6("ldpc", 16384, t2);
343
344 printf("\nlwupc\n");
345 TEST6("lwupc", 0, v0);
346 TEST6("lwupc", 4, v1);
347 TEST6("lwupc", 16, a0);
348 TEST6("lwupc", 64, a1);
349 TEST6("lwupc", 256, a3);
350 TEST6("lwupc", 1024, t0);
351 TEST6("lwupc", 4096, t1);
352 TEST6("lwupc", 16384, t2);
353 #endif
354 }
355
356