5 #define xglue(x, y) x ## y
6 #define glue(x, y) xglue(x, y)
7 #define stringify(s) tostring(s)
17 #define __init_call __attribute__ ((unused,__section__ (".initcall.init")))
19 static void *call_start __init_call = NULL;
21 #define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O | CC_A)
24 #include "test-i386.h"
27 #include "test-i386.h"
30 #include "test-i386.h"
33 #include "test-i386.h"
36 #include "test-i386.h"
39 #include "test-i386.h"
43 #include "test-i386.h"
47 #include "test-i386.h"
52 #include "test-i386.h"
57 #include "test-i386.h"
62 #include "test-i386.h"
67 #include "test-i386.h"
70 #define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O)
73 #include "test-i386-shift.h"
76 #include "test-i386-shift.h"
79 #include "test-i386-shift.h"
82 #include "test-i386-shift.h"
85 #include "test-i386-shift.h"
89 #include "test-i386-shift.h"
93 #include "test-i386-shift.h"
96 /* lea test (modrm support) */
97 #define TEST_LEA(STR)\
99 asm("leal " STR ", %0"\
101 : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi), "D" (edi));\
102 printf("lea %s = %08x\n", STR, res);\
105 #define TEST_LEA16(STR)\
107 asm(".code16 ; .byte 0x67 ; leal " STR ", %0 ; .code32"\
109 : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi), "D" (edi));\
110 printf("lea %s = %08x\n", STR, res);\
116 int eax, ebx, ecx, edx, esi, edi, res;
133 TEST_LEA("0x40(%%eax)");
134 TEST_LEA("0x40(%%ebx)");
135 TEST_LEA("0x40(%%ecx)");
136 TEST_LEA("0x40(%%edx)");
137 TEST_LEA("0x40(%%esi)");
138 TEST_LEA("0x40(%%edi)");
140 TEST_LEA("0x4000(%%eax)");
141 TEST_LEA("0x4000(%%ebx)");
142 TEST_LEA("0x4000(%%ecx)");
143 TEST_LEA("0x4000(%%edx)");
144 TEST_LEA("0x4000(%%esi)");
145 TEST_LEA("0x4000(%%edi)");
147 TEST_LEA("(%%eax, %%ecx)");
148 TEST_LEA("(%%ebx, %%edx)");
149 TEST_LEA("(%%ecx, %%ecx)");
150 TEST_LEA("(%%edx, %%ecx)");
151 TEST_LEA("(%%esi, %%ecx)");
152 TEST_LEA("(%%edi, %%ecx)");
154 TEST_LEA("0x40(%%eax, %%ecx)");
155 TEST_LEA("0x4000(%%ebx, %%edx)");
157 TEST_LEA("(%%ecx, %%ecx, 2)");
158 TEST_LEA("(%%edx, %%ecx, 4)");
159 TEST_LEA("(%%esi, %%ecx, 8)");
161 TEST_LEA("(,%%eax, 2)");
162 TEST_LEA("(,%%ebx, 4)");
163 TEST_LEA("(,%%ecx, 8)");
165 TEST_LEA("0x40(,%%eax, 2)");
166 TEST_LEA("0x40(,%%ebx, 4)");
167 TEST_LEA("0x40(,%%ecx, 8)");
170 TEST_LEA("-10(%%ecx, %%ecx, 2)");
171 TEST_LEA("-10(%%edx, %%ecx, 4)");
172 TEST_LEA("-10(%%esi, %%ecx, 8)");
174 TEST_LEA("0x4000(%%ecx, %%ecx, 2)");
175 TEST_LEA("0x4000(%%edx, %%ecx, 4)");
176 TEST_LEA("0x4000(%%esi, %%ecx, 8)");
178 /* limited 16 bit addressing test */
179 TEST_LEA16("0x4000");
180 TEST_LEA16("(%%bx)");
181 TEST_LEA16("(%%si)");
182 TEST_LEA16("(%%di)");
183 TEST_LEA16("0x40(%%bx)");
184 TEST_LEA16("0x40(%%si)");
185 TEST_LEA16("0x40(%%di)");
186 TEST_LEA16("0x4000(%%bx)");
187 TEST_LEA16("0x4000(%%si)");
188 TEST_LEA16("(%%bx,%%si)");
189 TEST_LEA16("(%%bx,%%di)");
190 TEST_LEA16("0x40(%%bx,%%si)");
191 TEST_LEA16("0x40(%%bx,%%di)");
192 TEST_LEA16("0x4000(%%bx,%%si)");
193 TEST_LEA16("0x4000(%%bx,%%di)");
196 #define TEST_JCC(JCC, v1, v2)\
198 asm("movl $1, %0\n\t"\
204 : "r" (v1), "r" (v2));\
205 printf("%-10s %d\n", JCC, res);\
208 /* various jump tests */
213 TEST_JCC("jne", 1, 1);
214 TEST_JCC("jne", 1, 0);
216 TEST_JCC("je", 1, 1);
217 TEST_JCC("je", 1, 0);
219 TEST_JCC("jl", 1, 1);
220 TEST_JCC("jl", 1, 0);
221 TEST_JCC("jl", 1, -1);
223 TEST_JCC("jle", 1, 1);
224 TEST_JCC("jle", 1, 0);
225 TEST_JCC("jle", 1, -1);
227 TEST_JCC("jge", 1, 1);
228 TEST_JCC("jge", 1, 0);
229 TEST_JCC("jge", -1, 1);
231 TEST_JCC("jg", 1, 1);
232 TEST_JCC("jg", 1, 0);
233 TEST_JCC("jg", 1, -1);
235 TEST_JCC("jb", 1, 1);
236 TEST_JCC("jb", 1, 0);
237 TEST_JCC("jb", 1, -1);
239 TEST_JCC("jbe", 1, 1);
240 TEST_JCC("jbe", 1, 0);
241 TEST_JCC("jbe", 1, -1);
243 TEST_JCC("jae", 1, 1);
244 TEST_JCC("jae", 1, 0);
245 TEST_JCC("jae", 1, -1);
247 TEST_JCC("ja", 1, 1);
248 TEST_JCC("ja", 1, 0);
249 TEST_JCC("ja", 1, -1);
252 TEST_JCC("jp", 1, 1);
253 TEST_JCC("jp", 1, 0);
255 TEST_JCC("jnp", 1, 1);
256 TEST_JCC("jnp", 1, 0);
258 TEST_JCC("jo", 0x7fffffff, 0);
259 TEST_JCC("jo", 0x7fffffff, -1);
261 TEST_JCC("jno", 0x7fffffff, 0);
262 TEST_JCC("jno", 0x7fffffff, -1);
264 TEST_JCC("js", 0, 1);
265 TEST_JCC("js", 0, -1);
266 TEST_JCC("js", 0, 0);
268 TEST_JCC("jns", 0, 1);
269 TEST_JCC("jns", 0, -1);
270 TEST_JCC("jns", 0, 0);
274 #define CC_MASK (CC_O | CC_C)
277 #include "test-i386-muldiv.h"
280 #include "test-i386-muldiv.h"
286 #include "test-i386-muldiv.h"
289 #include "test-i386-muldiv.h"
291 void test_imulw2(int op0, int op1)
293 int res, s1, s0, flags;
303 : "=q" (res), "=g" (flags)
304 : "q" (s1), "0" (res), "1" (flags));
305 printf("%-10s A=%08x B=%08x R=%08x CC=%04x\n",
306 "imulw", s0, s1, res, flags & CC_MASK);
309 void test_imull2(int op0, int op1)
311 int res, s1, s0, flags;
321 : "=q" (res), "=g" (flags)
322 : "q" (s1), "0" (res), "1" (flags));
323 printf("%-10s A=%08x B=%08x R=%08x CC=%04x\n",
324 "imull", s0, s1, res, flags & CC_MASK);
329 test_imulb(0x1234561d, 4);
331 test_imulb(0x80, 0x80);
332 test_imulb(0x10, 0x10);
334 test_imulw(0, 0x1234001d, 45);
335 test_imulw(0, 23, -45);
336 test_imulw(0, 0x8000, 0x8000);
337 test_imulw(0, 0x100, 0x100);
339 test_imull(0, 0x1234001d, 45);
340 test_imull(0, 23, -45);
341 test_imull(0, 0x80000000, 0x80000000);
342 test_imull(0, 0x10000, 0x10000);
344 test_mulb(0x1234561d, 4);
346 test_mulb(0x80, 0x80);
347 test_mulb(0x10, 0x10);
349 test_mulw(0, 0x1234001d, 45);
350 test_mulw(0, 23, -45);
351 test_mulw(0, 0x8000, 0x8000);
352 test_mulw(0, 0x100, 0x100);
354 test_mull(0, 0x1234001d, 45);
355 test_mull(0, 23, -45);
356 test_mull(0, 0x80000000, 0x80000000);
357 test_mull(0, 0x10000, 0x10000);
359 test_imulw2(0x1234001d, 45);
360 test_imulw2(23, -45);
361 test_imulw2(0x8000, 0x8000);
362 test_imulw2(0x100, 0x100);
364 test_imull2(0x1234001d, 45);
365 test_imull2(23, -45);
366 test_imull2(0x80000000, 0x80000000);
367 test_imull2(0x10000, 0x10000);
369 test_idivb(0x12341678, 0x127e);
370 test_idivb(0x43210123, -5);
371 test_idivb(0x12340004, -1);
373 test_idivw(0, 0x12345678, 12347);
374 test_idivw(0, -23223, -45);
375 test_idivw(0, 0x12348000, -1);
376 test_idivw(0x12343, 0x12345678, 0x81238567);
378 test_idivl(0, 0x12345678, 12347);
379 test_idivl(0, -233223, -45);
380 test_idivl(0, 0x80000000, -1);
381 test_idivl(0x12343, 0x12345678, 0x81234567);
383 test_divb(0x12341678, 0x127e);
384 test_divb(0x43210123, -5);
385 test_divb(0x12340004, -1);
387 test_divw(0, 0x12345678, 12347);
388 test_divw(0, -23223, -45);
389 test_divw(0, 0x12348000, -1);
390 test_divw(0x12343, 0x12345678, 0x81238567);
392 test_divl(0, 0x12345678, 12347);
393 test_divl(0, -233223, -45);
394 test_divl(0, 0x80000000, -1);
395 test_divl(0x12343, 0x12345678, 0x81234567);
399 static void *call_end __init_call = NULL;
401 int main(int argc, char **argv)
408 ptr = &call_start + 1;
409 while (*ptr != NULL) {