root / tests / test-i386-shift.h @ f40070c3
History | View | Annotate | Download (4.7 kB)
1 | 379ca80d | bellard | |
---|---|---|---|
2 | 379ca80d | bellard | #define exec_op glue(exec_, OP)
|
3 | 776f2227 | bellard | #define exec_opq glue(glue(exec_, OP), q)
|
4 | 379ca80d | bellard | #define exec_opl glue(glue(exec_, OP), l)
|
5 | 379ca80d | bellard | #define exec_opw glue(glue(exec_, OP), w)
|
6 | 379ca80d | bellard | #define exec_opb glue(glue(exec_, OP), b)
|
7 | 379ca80d | bellard | |
8 | d57c4e01 | bellard | #ifndef OP_SHIFTD
|
9 | d57c4e01 | bellard | |
10 | d57c4e01 | bellard | #ifdef OP_NOBYTE
|
11 | 776f2227 | bellard | #define EXECSHIFT(size, rsize, res, s1, s2, flags) \
|
12 | d57c4e01 | bellard | asm ("push %4\n\t"\ |
13 | d57c4e01 | bellard | "popf\n\t"\
|
14 | 776f2227 | bellard | stringify(OP) size " %" rsize "2, %" rsize "0\n\t" \ |
15 | d57c4e01 | bellard | "pushf\n\t"\
|
16 | 776f2227 | bellard | "pop %1\n\t"\
|
17 | d57c4e01 | bellard | : "=g" (res), "=g" (flags)\ |
18 | d57c4e01 | bellard | : "r" (s1), "0" (res), "1" (flags)); |
19 | d57c4e01 | bellard | #else
|
20 | 776f2227 | bellard | #define EXECSHIFT(size, rsize, res, s1, s2, flags) \
|
21 | 379ca80d | bellard | asm ("push %4\n\t"\ |
22 | 379ca80d | bellard | "popf\n\t"\
|
23 | 776f2227 | bellard | stringify(OP) size " %%cl, %" rsize "0\n\t" \ |
24 | 379ca80d | bellard | "pushf\n\t"\
|
25 | 776f2227 | bellard | "pop %1\n\t"\
|
26 | 379ca80d | bellard | : "=q" (res), "=g" (flags)\ |
27 | 379ca80d | bellard | : "c" (s1), "0" (res), "1" (flags)); |
28 | d57c4e01 | bellard | #endif
|
29 | 379ca80d | bellard | |
30 | 776f2227 | bellard | #if defined(__x86_64__)
|
31 | 776f2227 | bellard | void exec_opq(long s2, long s0, long s1, long iflags) |
32 | 379ca80d | bellard | { |
33 | 776f2227 | bellard | long res, flags;
|
34 | 379ca80d | bellard | res = s0; |
35 | 379ca80d | bellard | flags = iflags; |
36 | 776f2227 | bellard | EXECSHIFT("q", "", res, s1, s2, flags); |
37 | 379ca80d | bellard | /* overflow is undefined if count != 1 */
|
38 | 379ca80d | bellard | if (s1 != 1) |
39 | 379ca80d | bellard | flags &= ~CC_O; |
40 | 776f2227 | bellard | printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n", |
41 | 776f2227 | bellard | stringify(OP) "q", s0, s1, res, iflags, flags & CC_MASK);
|
42 | 776f2227 | bellard | } |
43 | 776f2227 | bellard | #endif
|
44 | 776f2227 | bellard | |
45 | 776f2227 | bellard | void exec_opl(long s2, long s0, long s1, long iflags) |
46 | 776f2227 | bellard | { |
47 | 776f2227 | bellard | long res, flags;
|
48 | 776f2227 | bellard | res = s0; |
49 | 776f2227 | bellard | flags = iflags; |
50 | 776f2227 | bellard | EXECSHIFT("l", "k", res, s1, s2, flags); |
51 | 776f2227 | bellard | /* overflow is undefined if count != 1 */
|
52 | 776f2227 | bellard | if (s1 != 1) |
53 | 776f2227 | bellard | flags &= ~CC_O; |
54 | 776f2227 | bellard | printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n", |
55 | 379ca80d | bellard | stringify(OP) "l", s0, s1, res, iflags, flags & CC_MASK);
|
56 | 379ca80d | bellard | } |
57 | 379ca80d | bellard | |
58 | 776f2227 | bellard | void exec_opw(long s2, long s0, long s1, long iflags) |
59 | 379ca80d | bellard | { |
60 | 776f2227 | bellard | long res, flags;
|
61 | 379ca80d | bellard | res = s0; |
62 | 379ca80d | bellard | flags = iflags; |
63 | 776f2227 | bellard | EXECSHIFT("w", "w", res, s1, s2, flags); |
64 | 379ca80d | bellard | /* overflow is undefined if count != 1 */
|
65 | 379ca80d | bellard | if (s1 != 1) |
66 | 379ca80d | bellard | flags &= ~CC_O; |
67 | 776f2227 | bellard | printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n", |
68 | 379ca80d | bellard | stringify(OP) "w", s0, s1, res, iflags, flags & CC_MASK);
|
69 | 379ca80d | bellard | } |
70 | 379ca80d | bellard | |
71 | d57c4e01 | bellard | #else
|
72 | 776f2227 | bellard | #define EXECSHIFT(size, rsize, res, s1, s2, flags) \
|
73 | d57c4e01 | bellard | asm ("push %4\n\t"\ |
74 | d57c4e01 | bellard | "popf\n\t"\
|
75 | 776f2227 | bellard | stringify(OP) size " %%cl, %" rsize "5, %" rsize "0\n\t" \ |
76 | d57c4e01 | bellard | "pushf\n\t"\
|
77 | 776f2227 | bellard | "pop %1\n\t"\
|
78 | d57c4e01 | bellard | : "=g" (res), "=g" (flags)\ |
79 | d57c4e01 | bellard | : "c" (s1), "0" (res), "1" (flags), "r" (s2)); |
80 | d57c4e01 | bellard | |
81 | 776f2227 | bellard | #if defined(__x86_64__)
|
82 | 776f2227 | bellard | void exec_opq(long s2, long s0, long s1, long iflags) |
83 | 776f2227 | bellard | { |
84 | 776f2227 | bellard | long res, flags;
|
85 | 776f2227 | bellard | res = s0; |
86 | 776f2227 | bellard | flags = iflags; |
87 | 776f2227 | bellard | EXECSHIFT("q", "", res, s1, s2, flags); |
88 | 776f2227 | bellard | /* overflow is undefined if count != 1 */
|
89 | 776f2227 | bellard | if (s1 != 1) |
90 | 776f2227 | bellard | flags &= ~CC_O; |
91 | 776f2227 | bellard | printf("%-10s A=" FMTLX " B=" FMTLX " C=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n", |
92 | 776f2227 | bellard | stringify(OP) "q", s0, s2, s1, res, iflags, flags & CC_MASK);
|
93 | 776f2227 | bellard | } |
94 | 776f2227 | bellard | #endif
|
95 | 776f2227 | bellard | |
96 | 776f2227 | bellard | void exec_opl(long s2, long s0, long s1, long iflags) |
97 | d57c4e01 | bellard | { |
98 | 776f2227 | bellard | long res, flags;
|
99 | d57c4e01 | bellard | res = s0; |
100 | d57c4e01 | bellard | flags = iflags; |
101 | 776f2227 | bellard | EXECSHIFT("l", "k", res, s1, s2, flags); |
102 | d57c4e01 | bellard | /* overflow is undefined if count != 1 */
|
103 | d57c4e01 | bellard | if (s1 != 1) |
104 | d57c4e01 | bellard | flags &= ~CC_O; |
105 | 776f2227 | bellard | printf("%-10s A=" FMTLX " B=" FMTLX " C=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n", |
106 | d57c4e01 | bellard | stringify(OP) "l", s0, s2, s1, res, iflags, flags & CC_MASK);
|
107 | d57c4e01 | bellard | } |
108 | d57c4e01 | bellard | |
109 | 776f2227 | bellard | void exec_opw(long s2, long s0, long s1, long iflags) |
110 | d57c4e01 | bellard | { |
111 | 776f2227 | bellard | long res, flags;
|
112 | d57c4e01 | bellard | res = s0; |
113 | d57c4e01 | bellard | flags = iflags; |
114 | 776f2227 | bellard | EXECSHIFT("w", "w", res, s1, s2, flags); |
115 | d57c4e01 | bellard | /* overflow is undefined if count != 1 */
|
116 | d57c4e01 | bellard | if (s1 != 1) |
117 | d57c4e01 | bellard | flags &= ~CC_O; |
118 | 776f2227 | bellard | printf("%-10s A=" FMTLX " B=" FMTLX " C=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n", |
119 | d57c4e01 | bellard | stringify(OP) "w", s0, s2, s1, res, iflags, flags & CC_MASK);
|
120 | d57c4e01 | bellard | } |
121 | d57c4e01 | bellard | |
122 | d57c4e01 | bellard | #endif
|
123 | d57c4e01 | bellard | |
124 | d57c4e01 | bellard | #ifndef OP_NOBYTE
|
125 | 776f2227 | bellard | void exec_opb(long s0, long s1, long iflags) |
126 | 379ca80d | bellard | { |
127 | 776f2227 | bellard | long res, flags;
|
128 | 379ca80d | bellard | res = s0; |
129 | 379ca80d | bellard | flags = iflags; |
130 | 776f2227 | bellard | EXECSHIFT("b", "b", res, s1, 0, flags); |
131 | 379ca80d | bellard | /* overflow is undefined if count != 1 */
|
132 | 379ca80d | bellard | if (s1 != 1) |
133 | 379ca80d | bellard | flags &= ~CC_O; |
134 | 776f2227 | bellard | printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n", |
135 | 379ca80d | bellard | stringify(OP) "b", s0, s1, res, iflags, flags & CC_MASK);
|
136 | 379ca80d | bellard | } |
137 | d57c4e01 | bellard | #endif
|
138 | 379ca80d | bellard | |
139 | 776f2227 | bellard | void exec_op(long s2, long s0, long s1) |
140 | 379ca80d | bellard | { |
141 | 776f2227 | bellard | s2 = i2l(s2); |
142 | 776f2227 | bellard | s0 = i2l(s0); |
143 | 776f2227 | bellard | #if defined(__x86_64__)
|
144 | 776f2227 | bellard | exec_opq(s2, s0, s1, 0);
|
145 | 776f2227 | bellard | #endif
|
146 | d57c4e01 | bellard | exec_opl(s2, s0, s1, 0);
|
147 | afeb6ee3 | bellard | #ifdef OP_SHIFTD
|
148 | a5973fbf | bellard | exec_opw(s2, s0, s1, 0);
|
149 | afeb6ee3 | bellard | #else
|
150 | d57c4e01 | bellard | exec_opw(s2, s0, s1, 0);
|
151 | afeb6ee3 | bellard | #endif
|
152 | d57c4e01 | bellard | #ifndef OP_NOBYTE
|
153 | 379ca80d | bellard | exec_opb(s0, s1, 0);
|
154 | d57c4e01 | bellard | #endif
|
155 | 379ca80d | bellard | #ifdef OP_CC
|
156 | 776f2227 | bellard | #if defined(__x86_64__)
|
157 | 776f2227 | bellard | exec_opq(s2, s0, s1, CC_C); |
158 | 776f2227 | bellard | #endif
|
159 | d57c4e01 | bellard | exec_opl(s2, s0, s1, CC_C); |
160 | d57c4e01 | bellard | exec_opw(s2, s0, s1, CC_C); |
161 | 379ca80d | bellard | exec_opb(s0, s1, CC_C); |
162 | 379ca80d | bellard | #endif
|
163 | 379ca80d | bellard | } |
164 | 379ca80d | bellard | |
165 | 379ca80d | bellard | void glue(test_, OP)(void) |
166 | 379ca80d | bellard | { |
167 | 776f2227 | bellard | int i, n;
|
168 | 776f2227 | bellard | #if defined(__x86_64__)
|
169 | 776f2227 | bellard | n = 64;
|
170 | 776f2227 | bellard | #else
|
171 | 776f2227 | bellard | n = 32;
|
172 | 776f2227 | bellard | #endif
|
173 | 776f2227 | bellard | for(i = 0; i < n; i++) |
174 | d57c4e01 | bellard | exec_op(0x21ad3d34, 0x12345678, i); |
175 | 776f2227 | bellard | for(i = 0; i < n; i++) |
176 | 6c3ee14f | bellard | exec_op(0x813f3421, 0x82345679, i); |
177 | 379ca80d | bellard | } |
178 | 379ca80d | bellard | |
179 | 379ca80d | bellard | void *glue(_test_, OP) __init_call = glue(test_, OP);
|
180 | 379ca80d | bellard | |
181 | 379ca80d | bellard | #undef OP
|
182 | 379ca80d | bellard | #undef OP_CC
|
183 | d57c4e01 | bellard | #undef OP_SHIFTD
|
184 | d57c4e01 | bellard | #undef OP_NOBYTE
|
185 | d57c4e01 | bellard | #undef EXECSHIFT |