]>
git.proxmox.com Git - qemu.git/blob - tests/test-i386.c
b43ca59d9896732bb6ba5709d8859af9e1ff76a5
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"
98 #include "test-i386-shift.h"
103 #include "test-i386-shift.h"
105 /* XXX: should be more precise ? */
107 #define CC_MASK (CC_C)
111 #include "test-i386-shift.h"
115 #include "test-i386-shift.h"
119 #include "test-i386-shift.h"
123 #include "test-i386-shift.h"
125 /* lea test (modrm support) */
126 #define TEST_LEA(STR)\
128 asm("leal " STR ", %0"\
130 : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi), "D" (edi));\
131 printf("lea %s = %08x\n", STR, res);\
134 #define TEST_LEA16(STR)\
136 asm(".code16 ; .byte 0x67 ; leal " STR ", %0 ; .code32"\
138 : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi), "D" (edi));\
139 printf("lea %s = %08x\n", STR, res);\
145 int eax
, ebx
, ecx
, edx
, esi
, edi
, res
;
162 TEST_LEA("0x40(%%eax)");
163 TEST_LEA("0x40(%%ebx)");
164 TEST_LEA("0x40(%%ecx)");
165 TEST_LEA("0x40(%%edx)");
166 TEST_LEA("0x40(%%esi)");
167 TEST_LEA("0x40(%%edi)");
169 TEST_LEA("0x4000(%%eax)");
170 TEST_LEA("0x4000(%%ebx)");
171 TEST_LEA("0x4000(%%ecx)");
172 TEST_LEA("0x4000(%%edx)");
173 TEST_LEA("0x4000(%%esi)");
174 TEST_LEA("0x4000(%%edi)");
176 TEST_LEA("(%%eax, %%ecx)");
177 TEST_LEA("(%%ebx, %%edx)");
178 TEST_LEA("(%%ecx, %%ecx)");
179 TEST_LEA("(%%edx, %%ecx)");
180 TEST_LEA("(%%esi, %%ecx)");
181 TEST_LEA("(%%edi, %%ecx)");
183 TEST_LEA("0x40(%%eax, %%ecx)");
184 TEST_LEA("0x4000(%%ebx, %%edx)");
186 TEST_LEA("(%%ecx, %%ecx, 2)");
187 TEST_LEA("(%%edx, %%ecx, 4)");
188 TEST_LEA("(%%esi, %%ecx, 8)");
190 TEST_LEA("(,%%eax, 2)");
191 TEST_LEA("(,%%ebx, 4)");
192 TEST_LEA("(,%%ecx, 8)");
194 TEST_LEA("0x40(,%%eax, 2)");
195 TEST_LEA("0x40(,%%ebx, 4)");
196 TEST_LEA("0x40(,%%ecx, 8)");
199 TEST_LEA("-10(%%ecx, %%ecx, 2)");
200 TEST_LEA("-10(%%edx, %%ecx, 4)");
201 TEST_LEA("-10(%%esi, %%ecx, 8)");
203 TEST_LEA("0x4000(%%ecx, %%ecx, 2)");
204 TEST_LEA("0x4000(%%edx, %%ecx, 4)");
205 TEST_LEA("0x4000(%%esi, %%ecx, 8)");
207 /* limited 16 bit addressing test */
208 TEST_LEA16("0x4000");
209 TEST_LEA16("(%%bx)");
210 TEST_LEA16("(%%si)");
211 TEST_LEA16("(%%di)");
212 TEST_LEA16("0x40(%%bx)");
213 TEST_LEA16("0x40(%%si)");
214 TEST_LEA16("0x40(%%di)");
215 TEST_LEA16("0x4000(%%bx)");
216 TEST_LEA16("0x4000(%%si)");
217 TEST_LEA16("(%%bx,%%si)");
218 TEST_LEA16("(%%bx,%%di)");
219 TEST_LEA16("0x40(%%bx,%%si)");
220 TEST_LEA16("0x40(%%bx,%%di)");
221 TEST_LEA16("0x4000(%%bx,%%si)");
222 TEST_LEA16("0x4000(%%bx,%%di)");
225 #define TEST_JCC(JCC, v1, v2)\
227 asm("movl $1, %0\n\t"\
233 : "r" (v1), "r" (v2));\
234 printf("%-10s %d\n", JCC, res);\
237 /* various jump tests */
242 TEST_JCC("jne", 1, 1);
243 TEST_JCC("jne", 1, 0);
245 TEST_JCC("je", 1, 1);
246 TEST_JCC("je", 1, 0);
248 TEST_JCC("jl", 1, 1);
249 TEST_JCC("jl", 1, 0);
250 TEST_JCC("jl", 1, -1);
252 TEST_JCC("jle", 1, 1);
253 TEST_JCC("jle", 1, 0);
254 TEST_JCC("jle", 1, -1);
256 TEST_JCC("jge", 1, 1);
257 TEST_JCC("jge", 1, 0);
258 TEST_JCC("jge", -1, 1);
260 TEST_JCC("jg", 1, 1);
261 TEST_JCC("jg", 1, 0);
262 TEST_JCC("jg", 1, -1);
264 TEST_JCC("jb", 1, 1);
265 TEST_JCC("jb", 1, 0);
266 TEST_JCC("jb", 1, -1);
268 TEST_JCC("jbe", 1, 1);
269 TEST_JCC("jbe", 1, 0);
270 TEST_JCC("jbe", 1, -1);
272 TEST_JCC("jae", 1, 1);
273 TEST_JCC("jae", 1, 0);
274 TEST_JCC("jae", 1, -1);
276 TEST_JCC("ja", 1, 1);
277 TEST_JCC("ja", 1, 0);
278 TEST_JCC("ja", 1, -1);
281 TEST_JCC("jp", 1, 1);
282 TEST_JCC("jp", 1, 0);
284 TEST_JCC("jnp", 1, 1);
285 TEST_JCC("jnp", 1, 0);
287 TEST_JCC("jo", 0x7fffffff, 0);
288 TEST_JCC("jo", 0x7fffffff, -1);
290 TEST_JCC("jno", 0x7fffffff, 0);
291 TEST_JCC("jno", 0x7fffffff, -1);
293 TEST_JCC("js", 0, 1);
294 TEST_JCC("js", 0, -1);
295 TEST_JCC("js", 0, 0);
297 TEST_JCC("jns", 0, 1);
298 TEST_JCC("jns", 0, -1);
299 TEST_JCC("jns", 0, 0);
303 #define CC_MASK (CC_O | CC_C)
306 #include "test-i386-muldiv.h"
309 #include "test-i386-muldiv.h"
315 #include "test-i386-muldiv.h"
318 #include "test-i386-muldiv.h"
320 void test_imulw2(int op0
, int op1
)
322 int res
, s1
, s0
, flags
;
332 : "=q" (res
), "=g" (flags
)
333 : "q" (s1
), "0" (res
), "1" (flags
));
334 printf("%-10s A=%08x B=%08x R=%08x CC=%04x\n",
335 "imulw", s0
, s1
, res
, flags
& CC_MASK
);
338 void test_imull2(int op0
, int op1
)
340 int res
, s1
, s0
, flags
;
350 : "=q" (res
), "=g" (flags
)
351 : "q" (s1
), "0" (res
), "1" (flags
));
352 printf("%-10s A=%08x B=%08x R=%08x CC=%04x\n",
353 "imull", s0
, s1
, res
, flags
& CC_MASK
);
358 test_imulb(0x1234561d, 4);
360 test_imulb(0x80, 0x80);
361 test_imulb(0x10, 0x10);
363 test_imulw(0, 0x1234001d, 45);
364 test_imulw(0, 23, -45);
365 test_imulw(0, 0x8000, 0x8000);
366 test_imulw(0, 0x100, 0x100);
368 test_imull(0, 0x1234001d, 45);
369 test_imull(0, 23, -45);
370 test_imull(0, 0x80000000, 0x80000000);
371 test_imull(0, 0x10000, 0x10000);
373 test_mulb(0x1234561d, 4);
375 test_mulb(0x80, 0x80);
376 test_mulb(0x10, 0x10);
378 test_mulw(0, 0x1234001d, 45);
379 test_mulw(0, 23, -45);
380 test_mulw(0, 0x8000, 0x8000);
381 test_mulw(0, 0x100, 0x100);
383 test_mull(0, 0x1234001d, 45);
384 test_mull(0, 23, -45);
385 test_mull(0, 0x80000000, 0x80000000);
386 test_mull(0, 0x10000, 0x10000);
388 test_imulw2(0x1234001d, 45);
389 test_imulw2(23, -45);
390 test_imulw2(0x8000, 0x8000);
391 test_imulw2(0x100, 0x100);
393 test_imull2(0x1234001d, 45);
394 test_imull2(23, -45);
395 test_imull2(0x80000000, 0x80000000);
396 test_imull2(0x10000, 0x10000);
398 test_idivb(0x12341678, 0x127e);
399 test_idivb(0x43210123, -5);
400 test_idivb(0x12340004, -1);
402 test_idivw(0, 0x12345678, 12347);
403 test_idivw(0, -23223, -45);
404 test_idivw(0, 0x12348000, -1);
405 test_idivw(0x12343, 0x12345678, 0x81238567);
407 test_idivl(0, 0x12345678, 12347);
408 test_idivl(0, -233223, -45);
409 test_idivl(0, 0x80000000, -1);
410 test_idivl(0x12343, 0x12345678, 0x81234567);
412 test_divb(0x12341678, 0x127e);
413 test_divb(0x43210123, -5);
414 test_divb(0x12340004, -1);
416 test_divw(0, 0x12345678, 12347);
417 test_divw(0, -23223, -45);
418 test_divw(0, 0x12348000, -1);
419 test_divw(0x12343, 0x12345678, 0x81238567);
421 test_divl(0, 0x12345678, 12347);
422 test_divl(0, -233223, -45);
423 test_divl(0, 0x80000000, -1);
424 test_divl(0x12343, 0x12345678, 0x81234567);
427 #define TEST_BSX(op, size, op0)\
431 asm("xorl %1, %1 ; " #op " %" size "2, %" size "0 ; setz %b1" \
432 : "=r" (res), "=q" (resz)\
434 printf("%-10s A=%08x R=%08x %d\n", #op, val, resz ? 0 : res, resz);\
439 TEST_BSX(bsrw
, "w", 0);
440 TEST_BSX(bsrw
, "w", 0x12340128);
441 TEST_BSX(bsrl
, "", 0);
442 TEST_BSX(bsrl
, "", 0x00340128);
443 TEST_BSX(bsfw
, "w", 0);
444 TEST_BSX(bsfw
, "w", 0x12340128);
445 TEST_BSX(bsfl
, "", 0);
446 TEST_BSX(bsfl
, "", 0x00340128);
449 /**********************************************/
451 void test_fops(double a
, double b
)
453 printf("a=%f b=%f a+b=%f\n", a
, b
, a
+ b
);
454 printf("a=%f b=%f a-b=%f\n", a
, b
, a
- b
);
455 printf("a=%f b=%f a*b=%f\n", a
, b
, a
* b
);
456 printf("a=%f b=%f a/b=%f\n", a
, b
, a
/ b
);
457 printf("a=%f b=%f fmod(a, b)=%f\n", a
, b
, fmod(a
, b
));
458 printf("a=%f sqrt(a)=%f\n", a
, sqrt(a
));
459 printf("a=%f sin(a)=%f\n", a
, sin(a
));
460 printf("a=%f cos(a)=%f\n", a
, cos(a
));
461 printf("a=%f tan(a)=%f\n", a
, tan(a
));
462 printf("a=%f log(a)=%f\n", a
, log(a
));
463 printf("a=%f exp(a)=%f\n", a
, exp(a
));
464 printf("a=%f b=%f atan2(a, b)=%f\n", a
, b
, atan2(a
, b
));
465 /* just to test some op combining */
466 printf("a=%f asin(sin(a))=%f\n", a
, asin(sin(a
)));
467 printf("a=%f acos(cos(a))=%f\n", a
, acos(cos(a
)));
468 printf("a=%f atan(tan(a))=%f\n", a
, atan(tan(a
)));
472 void test_fcmp(double a
, double b
)
474 printf("(%f<%f)=%d\n",
476 printf("(%f<=%f)=%d\n",
478 printf("(%f==%f)=%d\n",
480 printf("(%f>%f)=%d\n",
482 printf("(%f<=%f)=%d\n",
486 void test_fcvt(double a
)
493 printf("(float)%f = %f\n", a
, fa
);
494 printf("(long double)%f = %Lf\n", a
, la
);
495 printf("a=%016Lx\n", *(long long *)&a
);
496 printf("la=%016Lx %04x\n", *(long long *)&la
,
497 *(unsigned short *)((char *)(&la
) + 8));
498 printf("a=%f floor(a)=%f\n", a
, floor(a
));
499 printf("a=%f ceil(a)=%f\n", a
, ceil(a
));
500 printf("a=%f rint(a)=%f\n", a
, rint(a
));
504 asm("fld" #N : "=t" (a)); \
505 printf("fld" #N "= %f\n", a);
507 void test_fconst(void)
519 void test_fbcd(double a
)
521 unsigned short bcd
[5];
524 asm("fbstp %0" : "=m" (bcd
[0]) : "t" (a
) : "st");
525 asm("fbld %1" : "=t" (b
) : "m" (bcd
[0]));
526 printf("a=%f bcd=%04x%04x%04x%04x%04x b=%f\n",
527 a
, bcd
[4], bcd
[3], bcd
[2], bcd
[1], bcd
[0], b
);
530 void test_floats(void)
541 test_fbcd(1234567890123456);
542 test_fbcd(-123451234567890);
545 /**********************************************/
547 #define TEST_BCD(op, op0, cc_in, cc_mask)\
557 : "=a" (res), "=g" (flags)\
558 : "0" (res), "1" (flags));\
559 printf("%-10s A=%08x R=%08x CCIN=%04x CC=%04x\n",\
560 #op, op0, res, cc_in, flags & cc_mask);\
565 TEST_BCD(daa
, 0x12340503, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
566 TEST_BCD(daa
, 0x12340506, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
567 TEST_BCD(daa
, 0x12340507, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
568 TEST_BCD(daa
, 0x12340559, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
569 TEST_BCD(daa
, 0x12340560, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
570 TEST_BCD(daa
, 0x1234059f, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
571 TEST_BCD(daa
, 0x123405a0, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
572 TEST_BCD(daa
, 0x12340503, 0, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
573 TEST_BCD(daa
, 0x12340506, 0, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
574 TEST_BCD(daa
, 0x12340503, CC_C
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
575 TEST_BCD(daa
, 0x12340506, CC_C
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
576 TEST_BCD(daa
, 0x12340503, CC_C
| CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
577 TEST_BCD(daa
, 0x12340506, CC_C
| CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
579 TEST_BCD(das
, 0x12340503, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
580 TEST_BCD(das
, 0x12340506, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
581 TEST_BCD(das
, 0x12340507, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
582 TEST_BCD(das
, 0x12340559, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
583 TEST_BCD(das
, 0x12340560, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
584 TEST_BCD(das
, 0x1234059f, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
585 TEST_BCD(das
, 0x123405a0, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
586 TEST_BCD(das
, 0x12340503, 0, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
587 TEST_BCD(das
, 0x12340506, 0, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
588 TEST_BCD(das
, 0x12340503, CC_C
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
589 TEST_BCD(das
, 0x12340506, CC_C
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
590 TEST_BCD(das
, 0x12340503, CC_C
| CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
591 TEST_BCD(das
, 0x12340506, CC_C
| CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_A
));
593 TEST_BCD(aaa
, 0x12340205, CC_A
, (CC_C
| CC_A
));
594 TEST_BCD(aaa
, 0x12340306, CC_A
, (CC_C
| CC_A
));
595 TEST_BCD(aaa
, 0x1234040a, CC_A
, (CC_C
| CC_A
));
596 TEST_BCD(aaa
, 0x123405fa, CC_A
, (CC_C
| CC_A
));
597 TEST_BCD(aaa
, 0x12340205, 0, (CC_C
| CC_A
));
598 TEST_BCD(aaa
, 0x12340306, 0, (CC_C
| CC_A
));
599 TEST_BCD(aaa
, 0x1234040a, 0, (CC_C
| CC_A
));
600 TEST_BCD(aaa
, 0x123405fa, 0, (CC_C
| CC_A
));
602 TEST_BCD(aas
, 0x12340205, CC_A
, (CC_C
| CC_A
));
603 TEST_BCD(aas
, 0x12340306, CC_A
, (CC_C
| CC_A
));
604 TEST_BCD(aas
, 0x1234040a, CC_A
, (CC_C
| CC_A
));
605 TEST_BCD(aas
, 0x123405fa, CC_A
, (CC_C
| CC_A
));
606 TEST_BCD(aas
, 0x12340205, 0, (CC_C
| CC_A
));
607 TEST_BCD(aas
, 0x12340306, 0, (CC_C
| CC_A
));
608 TEST_BCD(aas
, 0x1234040a, 0, (CC_C
| CC_A
));
609 TEST_BCD(aas
, 0x123405fa, 0, (CC_C
| CC_A
));
611 TEST_BCD(aam
, 0x12340547, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_O
| CC_A
));
612 TEST_BCD(aad
, 0x12340407, CC_A
, (CC_C
| CC_P
| CC_Z
| CC_S
| CC_O
| CC_A
));
616 static void *call_end __init_call
= NULL
;
618 int main(int argc
, char **argv
)
623 ptr
= &call_start
+ 1;
624 while (*ptr
!= NULL
) {