root / tests / test-i386-shift.h @ 0443eaf6
History | View | Annotate | Download (3.5 kB)
1 | 379ca80d | bellard | |
---|---|---|---|
2 | 379ca80d | bellard | #define exec_op glue(exec_, OP)
|
3 | 379ca80d | bellard | #define exec_opl glue(glue(exec_, OP), l)
|
4 | 379ca80d | bellard | #define exec_opw glue(glue(exec_, OP), w)
|
5 | 379ca80d | bellard | #define exec_opb glue(glue(exec_, OP), b)
|
6 | 379ca80d | bellard | |
7 | d57c4e01 | bellard | #ifndef OP_SHIFTD
|
8 | d57c4e01 | bellard | |
9 | d57c4e01 | bellard | #ifdef OP_NOBYTE
|
10 | d57c4e01 | bellard | #define EXECSHIFT(size, res, s1, s2, flags) \
|
11 | d57c4e01 | bellard | asm ("push %4\n\t"\ |
12 | d57c4e01 | bellard | "popf\n\t"\
|
13 | d57c4e01 | bellard | stringify(OP) size " %" size "2, %" size "0\n\t" \ |
14 | d57c4e01 | bellard | "pushf\n\t"\
|
15 | d57c4e01 | bellard | "popl %1\n\t"\
|
16 | d57c4e01 | bellard | : "=g" (res), "=g" (flags)\ |
17 | d57c4e01 | bellard | : "r" (s1), "0" (res), "1" (flags)); |
18 | d57c4e01 | bellard | #else
|
19 | d57c4e01 | bellard | #define EXECSHIFT(size, res, s1, s2, flags) \
|
20 | 379ca80d | bellard | asm ("push %4\n\t"\ |
21 | 379ca80d | bellard | "popf\n\t"\
|
22 | 379ca80d | bellard | stringify(OP) size " %%cl, %" size "0\n\t" \ |
23 | 379ca80d | bellard | "pushf\n\t"\
|
24 | 379ca80d | bellard | "popl %1\n\t"\
|
25 | 379ca80d | bellard | : "=q" (res), "=g" (flags)\ |
26 | 379ca80d | bellard | : "c" (s1), "0" (res), "1" (flags)); |
27 | d57c4e01 | bellard | #endif
|
28 | 379ca80d | bellard | |
29 | d57c4e01 | bellard | void exec_opl(int s2, int s0, int s1, int iflags) |
30 | 379ca80d | bellard | { |
31 | 379ca80d | bellard | int res, flags;
|
32 | 379ca80d | bellard | res = s0; |
33 | 379ca80d | bellard | flags = iflags; |
34 | d57c4e01 | bellard | EXECSHIFT("", res, s1, s2, flags);
|
35 | 379ca80d | bellard | /* overflow is undefined if count != 1 */
|
36 | 379ca80d | bellard | if (s1 != 1) |
37 | 379ca80d | bellard | flags &= ~CC_O; |
38 | 379ca80d | bellard | printf("%-10s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
|
39 | 379ca80d | bellard | stringify(OP) "l", s0, s1, res, iflags, flags & CC_MASK);
|
40 | 379ca80d | bellard | } |
41 | 379ca80d | bellard | |
42 | d57c4e01 | bellard | void exec_opw(int s2, int s0, int s1, int iflags) |
43 | 379ca80d | bellard | { |
44 | 379ca80d | bellard | int res, flags;
|
45 | 379ca80d | bellard | res = s0; |
46 | 379ca80d | bellard | flags = iflags; |
47 | d57c4e01 | bellard | EXECSHIFT("w", res, s1, s2, flags);
|
48 | 379ca80d | bellard | /* overflow is undefined if count != 1 */
|
49 | 379ca80d | bellard | if (s1 != 1) |
50 | 379ca80d | bellard | flags &= ~CC_O; |
51 | 379ca80d | bellard | printf("%-10s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
|
52 | 379ca80d | bellard | stringify(OP) "w", s0, s1, res, iflags, flags & CC_MASK);
|
53 | 379ca80d | bellard | } |
54 | 379ca80d | bellard | |
55 | d57c4e01 | bellard | #else
|
56 | d57c4e01 | bellard | #define EXECSHIFT(size, res, s1, s2, flags) \
|
57 | d57c4e01 | bellard | asm ("push %4\n\t"\ |
58 | d57c4e01 | bellard | "popf\n\t"\
|
59 | d57c4e01 | bellard | stringify(OP) size " %%cl, %" size "5, %" size "0\n\t" \ |
60 | d57c4e01 | bellard | "pushf\n\t"\
|
61 | d57c4e01 | bellard | "popl %1\n\t"\
|
62 | d57c4e01 | bellard | : "=g" (res), "=g" (flags)\ |
63 | d57c4e01 | bellard | : "c" (s1), "0" (res), "1" (flags), "r" (s2)); |
64 | d57c4e01 | bellard | |
65 | d57c4e01 | bellard | void exec_opl(int s2, int s0, int s1, int iflags) |
66 | d57c4e01 | bellard | { |
67 | d57c4e01 | bellard | int res, flags;
|
68 | d57c4e01 | bellard | res = s0; |
69 | d57c4e01 | bellard | flags = iflags; |
70 | d57c4e01 | bellard | EXECSHIFT("", res, s1, s2, flags);
|
71 | d57c4e01 | bellard | /* overflow is undefined if count != 1 */
|
72 | d57c4e01 | bellard | if (s1 != 1) |
73 | d57c4e01 | bellard | flags &= ~CC_O; |
74 | d57c4e01 | bellard | printf("%-10s A=%08x B=%08x C=%08x R=%08x CCIN=%04x CC=%04x\n",
|
75 | d57c4e01 | bellard | stringify(OP) "l", s0, s2, s1, res, iflags, flags & CC_MASK);
|
76 | d57c4e01 | bellard | } |
77 | d57c4e01 | bellard | |
78 | d57c4e01 | bellard | void exec_opw(int s2, int s0, int s1, int iflags) |
79 | d57c4e01 | bellard | { |
80 | d57c4e01 | bellard | int res, flags;
|
81 | d57c4e01 | bellard | res = s0; |
82 | d57c4e01 | bellard | flags = iflags; |
83 | d57c4e01 | bellard | EXECSHIFT("w", res, s1, s2, flags);
|
84 | d57c4e01 | bellard | /* overflow is undefined if count != 1 */
|
85 | d57c4e01 | bellard | if (s1 != 1) |
86 | d57c4e01 | bellard | flags &= ~CC_O; |
87 | d57c4e01 | bellard | printf("%-10s A=%08x B=%08x C=%08x R=%08x CCIN=%04x CC=%04x\n",
|
88 | d57c4e01 | bellard | stringify(OP) "w", s0, s2, s1, res, iflags, flags & CC_MASK);
|
89 | d57c4e01 | bellard | } |
90 | d57c4e01 | bellard | |
91 | d57c4e01 | bellard | #endif
|
92 | d57c4e01 | bellard | |
93 | d57c4e01 | bellard | #ifndef OP_NOBYTE
|
94 | 379ca80d | bellard | void exec_opb(int s0, int s1, int iflags) |
95 | 379ca80d | bellard | { |
96 | 379ca80d | bellard | int res, flags;
|
97 | 379ca80d | bellard | res = s0; |
98 | 379ca80d | bellard | flags = iflags; |
99 | d57c4e01 | bellard | EXECSHIFT("b", res, s1, 0, flags); |
100 | 379ca80d | bellard | /* overflow is undefined if count != 1 */
|
101 | 379ca80d | bellard | if (s1 != 1) |
102 | 379ca80d | bellard | flags &= ~CC_O; |
103 | 379ca80d | bellard | printf("%-10s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
|
104 | 379ca80d | bellard | stringify(OP) "b", s0, s1, res, iflags, flags & CC_MASK);
|
105 | 379ca80d | bellard | } |
106 | d57c4e01 | bellard | #endif
|
107 | 379ca80d | bellard | |
108 | d57c4e01 | bellard | void exec_op(int s2, int s0, int s1) |
109 | 379ca80d | bellard | { |
110 | d57c4e01 | bellard | exec_opl(s2, s0, s1, 0);
|
111 | afeb6ee3 | bellard | #ifdef OP_SHIFTD
|
112 | afeb6ee3 | bellard | if (s1 <= 15) |
113 | afeb6ee3 | bellard | exec_opw(s2, s0, s1, 0);
|
114 | afeb6ee3 | bellard | #else
|
115 | d57c4e01 | bellard | exec_opw(s2, s0, s1, 0);
|
116 | afeb6ee3 | bellard | #endif
|
117 | d57c4e01 | bellard | #ifndef OP_NOBYTE
|
118 | 379ca80d | bellard | exec_opb(s0, s1, 0);
|
119 | d57c4e01 | bellard | #endif
|
120 | 379ca80d | bellard | #ifdef OP_CC
|
121 | d57c4e01 | bellard | exec_opl(s2, s0, s1, CC_C); |
122 | d57c4e01 | bellard | exec_opw(s2, s0, s1, CC_C); |
123 | 379ca80d | bellard | exec_opb(s0, s1, CC_C); |
124 | 379ca80d | bellard | #endif
|
125 | 379ca80d | bellard | } |
126 | 379ca80d | bellard | |
127 | 379ca80d | bellard | void glue(test_, OP)(void) |
128 | 379ca80d | bellard | { |
129 | 379ca80d | bellard | int i;
|
130 | 379ca80d | bellard | for(i = 0; i < 32; i++) |
131 | d57c4e01 | bellard | exec_op(0x21ad3d34, 0x12345678, i); |
132 | 379ca80d | bellard | for(i = 0; i < 32; i++) |
133 | d57c4e01 | bellard | exec_op(0x813f3421, 0x82345678, i); |
134 | 379ca80d | bellard | } |
135 | 379ca80d | bellard | |
136 | 379ca80d | bellard | void *glue(_test_, OP) __init_call = glue(test_, OP);
|
137 | 379ca80d | bellard | |
138 | 379ca80d | bellard | #undef OP
|
139 | 379ca80d | bellard | #undef OP_CC
|
140 | d57c4e01 | bellard | #undef OP_SHIFTD
|
141 | d57c4e01 | bellard | #undef OP_NOBYTE
|
142 | d57c4e01 | bellard | #undef EXECSHIFT
|