]> git.proxmox.com Git - qemu.git/blob - tests/test-i386-shift.h
af892f6c7d8527c7f134a590bf91ef6f879ae5ca
[qemu.git] / tests / test-i386-shift.h
1
2 #define exec_op glue(exec_, OP)
3 #define exec_opl glue(glue(exec_, OP), l)
4 #define exec_opw glue(glue(exec_, OP), w)
5 #define exec_opb glue(glue(exec_, OP), b)
6
7 #define EXECSHIFT(size, res, s1, flags) \
8 asm ("push %4\n\t"\
9 "popf\n\t"\
10 stringify(OP) size " %%cl, %" size "0\n\t" \
11 "pushf\n\t"\
12 "popl %1\n\t"\
13 : "=q" (res), "=g" (flags)\
14 : "c" (s1), "0" (res), "1" (flags));
15
16 void exec_opl(int s0, int s1, int iflags)
17 {
18 int res, flags;
19 res = s0;
20 flags = iflags;
21 EXECSHIFT("", res, s1, flags);
22 /* overflow is undefined if count != 1 */
23 if (s1 != 1)
24 flags &= ~CC_O;
25 printf("%-10s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
26 stringify(OP) "l", s0, s1, res, iflags, flags & CC_MASK);
27 }
28
29 void exec_opw(int s0, int s1, int iflags)
30 {
31 int res, flags;
32 res = s0;
33 flags = iflags;
34 EXECSHIFT("w", res, s1, flags);
35 /* overflow is undefined if count != 1 */
36 if (s1 != 1)
37 flags &= ~CC_O;
38 printf("%-10s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
39 stringify(OP) "w", s0, s1, res, iflags, flags & CC_MASK);
40 }
41
42 void exec_opb(int s0, int s1, int iflags)
43 {
44 int res, flags;
45 res = s0;
46 flags = iflags;
47 EXECSHIFT("b", res, s1, flags);
48 /* overflow is undefined if count != 1 */
49 if (s1 != 1)
50 flags &= ~CC_O;
51 printf("%-10s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
52 stringify(OP) "b", s0, s1, res, iflags, flags & CC_MASK);
53 }
54
55 void exec_op(int s0, int s1)
56 {
57 exec_opl(s0, s1, 0);
58 exec_opw(s0, s1, 0);
59 exec_opb(s0, s1, 0);
60 #ifdef OP_CC
61 exec_opl(s0, s1, CC_C);
62 exec_opw(s0, s1, CC_C);
63 exec_opb(s0, s1, CC_C);
64 #endif
65 }
66
67 void glue(test_, OP)(void)
68 {
69 int i;
70 for(i = 0; i < 32; i++)
71 exec_op(0x12345678, i);
72 for(i = 0; i < 32; i++)
73 exec_op(0x82345678, i);
74 }
75
76 void *glue(_test_, OP) __init_call = glue(test_, OP);
77
78 #undef OP
79 #undef OP_CC