1 #include <stdio.h>
2
3 #define TESTINST_DROTR(instruction, in, SA) \
4 { \
5 unsigned long long out; \
6 __asm__ __volatile__( \
7 "move $t0, $zero" "\n\t" \
8 "move $t1, %1" "\n\t" \
9 instruction" $t0, $t1, "#SA "\n\t" \
10 "move %0, $t0" "\n\t" \
11 : "=r" (out) \
12 : "r" (in) \
13 : "t0", "t1" \
14 ); \
15 printf("%s :: in 0x%llx, out 0x%llx, SA %d\n", \
16 instruction, (long long) in, out, SA); \
17 }
18
19 #define TESTINST_DROTRV(instruction, in, SA) \
20 { \
21 unsigned long long out; \
22 __asm__ __volatile__( \
23 "move $t0, $zero" "\n\t" \
24 "move $t1, %1" "\n\t" \
25 "move $t2, %2" "\n\t" \
26 instruction" $t0, $t1, $t2" "\n\t" \
27 "move %0, $t0" "\n\t" \
28 : "=r" (out) \
29 : "r" (in), "r" (SA) \
30 : "t0", "t1", "t2" \
31 ); \
32 printf("%s :: in 0x%llx, out 0x%llx, SA %d\n", \
33 instruction, (long long) in, out, SA); \
34 }
35
36 #define TESTINST_DSWAP(instruction, in) \
37 { \
38 unsigned long long out; \
39 __asm__ __volatile__( \
40 "move $t0, $0" "\n\t" \
41 "move $t1, $0" "\n\t" \
42 "move $t1, %1" "\n\t" \
43 instruction" $t0, $t1" "\n\t" \
44 "move %0, $t0" "\n\t" \
45 : "=r" (out) \
46 : "r" (in) \
47 : "t0", "t1" \
48 ); \
49 printf("%s :: in 0x%llx, out 0x%llx\n", \
50 instruction, (long long) in, out); \
51 }
52
main()53 int main()
54 {
55 #if (__mips == 64) && (__mips_isa_rev >= 2)
56 printf("--- DROTR ---\n");
57 TESTINST_DROTR("drotr", 0x2000ffffffffffff, 16);
58 TESTINST_DROTR("drotr", 0xffff0000ffffffff, 16);
59 TESTINST_DROTR("drotr", 0x2000ffffffffffff, 8);
60 TESTINST_DROTR("drotr", 0x2000ffffffffffff, 4);
61 TESTINST_DROTR("drotr", 0x2000ffffffffffff, 5);
62 TESTINST_DROTR("drotr", 0x31415927ffffffff, 10);
63 TESTINST_DROTR("drotr", 0x2000ffffffffffff, 4);
64 TESTINST_DROTR("drotr", 0x2000ffffffffffff, 0);
65 TESTINST_DROTR("drotr", 0xeeeeffffffffffff, 16);
66 TESTINST_DROTR("drotr", 0x2000ffffffffbbbb, 31);
67 TESTINST_DROTR("drotr", 0x2000ffffffffffff, 16);
68 TESTINST_DROTR("drotr", 0x2000ffffffffffff, 0);
69 TESTINST_DROTR("drotr", 0x7fffffffffffffff, 16);
70 TESTINST_DROTR("drotr", 0x2000ffffffffffff, 2);
71 TESTINST_DROTR("drotr", 0x2000ffffffffffff, 24);
72 TESTINST_DROTR("drotr", 0xfffffff31415927f, 16);
73 TESTINST_DROTR("drotr", 0xffffffffffff0008, 3);
74 TESTINST_DROTR("drotr", 0xffff0000ffffffff, 16);
75 TESTINST_DROTR("drotr", 0xff0000ffffffffff, 16);
76 TESTINST_DROTR("drotr", 0xfffffffff0000fff, 16);
77
78 printf("--- DROTR32 ---\n");
79 TESTINST_DROTR("drotr32", 0x2000ffffffffffff, 16);
80 TESTINST_DROTR("drotr32", 0xffff0000ffffffff, 16);
81 TESTINST_DROTR("drotr32", 0x2000ffffffffffff, 8);
82 TESTINST_DROTR("drotr32", 0x2000ffffffffffff, 4);
83 TESTINST_DROTR("drotr32", 0x2000ffffffffffff, 5);
84 TESTINST_DROTR("drotr32", 0x31415927ffffffff, 10);
85 TESTINST_DROTR("drotr32", 0x2000ffffffffffff, 4);
86 TESTINST_DROTR("drotr32", 0x2000ffffffffffff, 0);
87 TESTINST_DROTR("drotr32", 0xeeeeffffffffffff, 16);
88 TESTINST_DROTR("drotr32", 0x2000ffffffffffff, 31);
89 TESTINST_DROTR("drotr32", 0x2000ffffffffbbbb, 16);
90 TESTINST_DROTR("drotr32", 0x2000ffffffffffff, 0);
91 TESTINST_DROTR("drotr32", 0x7fffffffffffffff, 16);
92 TESTINST_DROTR("drotr32", 0x2000ffffffffffff, 2);
93 TESTINST_DROTR("drotr32", 0x2000ffffffffffff, 24);
94 TESTINST_DROTR("drotr32", 0xfffffff31415927f, 16);
95 TESTINST_DROTR("drotr32", 0xffffffffffff0008, 3);
96 TESTINST_DROTR("drotr32", 0xffff0000ffffffff, 16);
97 TESTINST_DROTR("drotr32", 0xff0000ffffffffff, 16);
98 TESTINST_DROTR("drotr32", 0xfffffffff0000fff, 16);
99
100 printf("--- DROTRV ---\n");
101 TESTINST_DROTRV("drotrv", 0x2000ffffffffffff, 16);
102 TESTINST_DROTRV("drotrv", 0xffff0000ffffffff, 16);
103 TESTINST_DROTRV("drotrv", 0x2000ffffffffffff, 8);
104 TESTINST_DROTRV("drotrv", 0x2000ffffffffffff, 4);
105 TESTINST_DROTRV("drotrv", 0x2000ffffffffffff, 5);
106 TESTINST_DROTRV("drotrv", 0x31415927ffffffff, 10);
107 TESTINST_DROTRV("drotrv", 0x2000ffffffffffff, 4);
108 TESTINST_DROTRV("drotrv", 0x2000ffffffffffff, 0);
109 TESTINST_DROTRV("drotrv", 0xeeeeffffffffffff, 16);
110 TESTINST_DROTRV("drotrv", 0x2000ffffffffffff, 31);
111 TESTINST_DROTRV("drotrv", 0x2000ffffffffbbbb, 16);
112 TESTINST_DROTRV("drotrv", 0x2000ffffffffffff, 0);
113 TESTINST_DROTRV("drotrv", 0x7fffffffffffffff, 16);
114 TESTINST_DROTRV("drotrv", 0x2000ffffffffffff, 2);
115 TESTINST_DROTRV("drotrv", 0x2000ffffffffffff, 24);
116 TESTINST_DROTRV("drotrv", 0xfffffff31415927f, 16);
117 TESTINST_DROTRV("drotrv", 0xffffffffffff0008, 3);
118 TESTINST_DROTRV("drotrv", 0xffff0000ffffffff, 16);
119 TESTINST_DROTRV("drotrv", 0xff0000ffffffffff, 16);
120 TESTINST_DROTRV("drotrv", 0xfffffffff0000fff, 16);
121
122 printf("--- DSBH ---\n");
123 TESTINST_DSWAP("dsbh", 0x2000ffffffffffff);
124 TESTINST_DSWAP("dsbh", 0xffff0000ffffffff);
125 TESTINST_DSWAP("dsbh", 0x2000ffffffffffff);
126 TESTINST_DSWAP("dsbh", 0x2000ffffeeeeffff);
127 TESTINST_DSWAP("dsbh", 0x2000ffffffffffff);
128 TESTINST_DSWAP("dsbh", 0x31415927ffffffff);
129 TESTINST_DSWAP("dsbh", 0x2000ffffffffffff);
130 TESTINST_DSWAP("dsbh", 0x2000ffffffccccff);
131 TESTINST_DSWAP("dsbh", 0xeeeeffffffffffff);
132 TESTINST_DSWAP("dsbh", 0x2000ffff0000ffff);
133 TESTINST_DSWAP("dsbh", 0x2000ffffffffbbbb);
134 TESTINST_DSWAP("dsbh", 0x2000ffffffffffff);
135 TESTINST_DSWAP("dsbh", 0x7fffffff5555ffff);
136 TESTINST_DSWAP("dsbh", 0x2000ffffff123123);
137 TESTINST_DSWAP("dsbh", 0x2000ffffffffffff);
138 TESTINST_DSWAP("dsbh", 0xfffffff31415927f);
139 TESTINST_DSWAP("dsbh", 0xffffffffffff0008);
140 TESTINST_DSWAP("dsbh", 0xffff0000ffff88ff);
141 TESTINST_DSWAP("dsbh", 0xff0000ffffffffff);
142 TESTINST_DSWAP("dsbh", 0xfff10ffff0000fff);
143
144 printf("--- DSHD ---\n");
145 TESTINST_DSWAP("dshd", 0x2002ffffffffffff);
146 TESTINST_DSWAP("dshd", 0xffff0000ffffffff);
147 TESTINST_DSWAP("dshd", 0x2000ffffffffffff);
148 TESTINST_DSWAP("dshd", 0x2000ffffffddddff);
149 TESTINST_DSWAP("dshd", 0x2000ffffffffeeee);
150 TESTINST_DSWAP("dshd", 0x31415927ffffffff);
151 TESTINST_DSWAP("dshd", 0x2000ffffffffaaaa);
152 TESTINST_DSWAP("dshd", 0x2000ffffffbbbbff);
153 TESTINST_DSWAP("dshd", 0xeeeeff33ff22ffff);
154 TESTINST_DSWAP("dshd", 0x2000ffffffffffff);
155 TESTINST_DSWAP("dshd", 0x2000ffffffffbbbb);
156 TESTINST_DSWAP("dshd", 0x2000ffffffffffff);
157 TESTINST_DSWAP("dshd", 0x7fffffffddddffff);
158 TESTINST_DSWAP("dshd", 0x2000ffffffff2222);
159 TESTINST_DSWAP("dshd", 0x2000ffffffffffff);
160 TESTINST_DSWAP("dshd", 0xfffffff31415927f);
161 TESTINST_DSWAP("dshd", 0xffffffffffff0008);
162 TESTINST_DSWAP("dshd", 0xffff0000ffffffff);
163 TESTINST_DSWAP("dshd", 0xff0000ffffffffff);
164 TESTINST_DSWAP("dshd", 0xfffffffff0000fff);
165
166 printf("--- WSBH ---\n");
167 TESTINST_DSWAP("wsbh", 0x2000ffffffffffff);
168 TESTINST_DSWAP("wsbh", 0xffff0000ffffffff);
169 TESTINST_DSWAP("wsbh", 0x2000ffffffffffff);
170 TESTINST_DSWAP("wsbh", 0x2000ffffeeeeffff);
171 TESTINST_DSWAP("wsbh", 0x2000ffffffffffff);
172 TESTINST_DSWAP("wsbh", 0x31415927ffffffff);
173 TESTINST_DSWAP("wsbh", 0x2000ffffffffffff);
174 TESTINST_DSWAP("wsbh", 0x2000ffffffccccff);
175 TESTINST_DSWAP("wsbh", 0xeeeeffffffffffff);
176 TESTINST_DSWAP("wsbh", 0x2000ffff0000ffff);
177 TESTINST_DSWAP("wsbh", 0x2000ffffffffbbbb);
178 TESTINST_DSWAP("wsbh", 0x2000ffffffffffff);
179 TESTINST_DSWAP("wsbh", 0x7fffffff5555ffff);
180 TESTINST_DSWAP("wsbh", 0x2000ffffff123123);
181 TESTINST_DSWAP("wsbh", 0x2000ffffffffffff);
182 TESTINST_DSWAP("wsbh", 0xfffffff31415927f);
183 TESTINST_DSWAP("wsbh", 0xffffffffffff0008);
184 TESTINST_DSWAP("wsbh", 0xffff0000ffff88ff);
185 TESTINST_DSWAP("wsbh", 0xff0000ffffffffff);
186 TESTINST_DSWAP("wsbh", 0xfff10ffff0000fff);
187 #else
188 printf("This test is testing mips64r2 instructions.\n");
189 #endif
190
191 return 0;
192 }
193