drd/tests/Makefile.am: Use -faligned-new for C++ code if supported
[valgrind.git] / VEX / test / test-amd64.h
blob94b32feb528e3e0670d66d03d0263ea892fab24c
2 #define exec_op glue(exec_, OP)
3 #define exec_opq glue(glue(exec_, OP), q)
4 #define exec_opl glue(glue(exec_, OP), l)
5 #define exec_opw glue(glue(exec_, OP), w)
6 #define exec_opb glue(glue(exec_, OP), b)
8 #define EXECOP2(size, res, s1, flags) \
9 asm ("pushq %4\n\t"\
10 "popfq\n\t"\
11 stringify(OP) size " %" size "2, %" size "0\n\t" \
12 "pushfq\n\t"\
13 "popq %1\n\t"\
14 : "=q" (res), "=g" (flags)\
15 : "q" (s1), "0" (res), "1" (flags));
17 #define EXECOP1(size, res, flags) \
18 asm ("pushq %3\n\t"\
19 "popfq\n\t"\
20 stringify(OP) size " %" size "0\n\t" \
21 "pushfq\n\t"\
22 "popq %1\n\t"\
23 : "=q" (res), "=g" (flags)\
24 : "0" (res), "1" (flags));
26 #ifdef OP1
27 inline void exec_opq(int64 s0, int64 s1, int64 iflags)
29 int64 res, flags;
30 res = s0;
31 flags = iflags;
32 EXECOP1("", res, flags);
33 printf("%-6s A=%016llx R=%016llx CCIN=%04llx CC=%04llx\n",
34 stringify(OP) "q", s0, res, iflags, flags & CC_MASK);
36 inline void exec_opl(int64 s0, int64 s1, int64 iflags)
38 int64 res, flags;
39 res = s0;
40 flags = iflags;
41 EXECOP1("", res, flags);
42 printf("%-6s A=%016llx R=%016llx CCIN=%04llx CC=%04llx\n",
43 stringify(OP) "l", s0, res, iflags, flags & CC_MASK);
45 inline void exec_opw(int64 s0, int64 s1, int64 iflags)
47 int64 res, flags;
48 res = s0;
49 flags = iflags;
50 EXECOP1("w", res, flags);
51 printf("%-6s A=%016llx R=%016llx CCIN=%04llx CC=%04llx\n",
52 stringify(OP) "w", s0, res, iflags, flags & CC_MASK);
54 inline void exec_opb(int64 s0, int64 s1, int64 iflags)
56 int64 res, flags;
57 res = s0;
58 flags = iflags;
59 EXECOP1("b", res, flags);
60 printf("%-6s A=%016llx R=%016llx CCIN=%04llx CC=%04llx\n",
61 stringify(OP) "b", s0, res, iflags, flags & CC_MASK);
63 #else
64 inline void exec_opq(int64 s0, int64 s1, int64 iflags)
66 int64 res, flags;
67 res = s0;
68 flags = iflags;
69 EXECOP2("q", res, s1, flags);
70 printf("%-6s A=%016llx B=%016llx R=%016llx CCIN=%04llx CC=%04llx\n",
71 stringify(OP) "q", s0, s1, res, iflags, flags & CC_MASK);
74 inline void exec_opl(int64 s0, int64 s1, int64 iflags)
76 int64 res, flags;
77 res = s0;
78 flags = iflags;
79 EXECOP2("", res, s1, flags);
80 printf("%-6s A=%016llx B=%016llx R=%016llx CCIN=%04llx CC=%04llx\n",
81 stringify(OP) "l", s0, s1, res, iflags, flags & CC_MASK);
84 inline void exec_opw(int64 s0, int64 s1, int64 iflags)
86 int64 res, flags;
87 res = s0;
88 flags = iflags;
89 EXECOP2("w", res, s1, flags);
90 printf("%-6s A=%016llx B=%016llx R=%016llx CCIN=%04llx CC=%04llx\n",
91 stringify(OP) "w", s0, s1, res, iflags, flags & CC_MASK);
94 inline void exec_opb(int64 s0, int64 s1, int64 iflags)
96 int64 res, flags;
97 res = s0;
98 flags = iflags;
99 EXECOP2("b", res, s1, flags);
100 printf("%-6s A=%016llx B=%016llx R=%016llx CCIN=%04llx CC=%04llx\n",
101 stringify(OP) "b", s0, s1, res, iflags, flags & CC_MASK);
103 #endif
105 void exec_op(int64 s0, int64 s1)
107 #if 1
108 int64 o,s,z,a,c,p,flags_in;
109 for (o = 0; o < 2; o++) {
110 for (s = 0; s < 2; s++) {
111 for (z = 0; z < 2; z++) {
112 for (a = 0; a < 2; a++) {
113 for (c = 0; c < 2; c++) {
114 for (p = 0; p < 2; p++) {
116 flags_in = (o ? CC_O : 0)
117 | (s ? CC_S : 0)
118 | (z ? CC_Z : 0)
119 | (a ? CC_A : 0)
120 | (c ? CC_C : 0)
121 | (p ? CC_P : 0);
122 exec_opq(s0, s1, flags_in);
123 exec_opl(s0, s1, flags_in);
124 exec_opw(s0, s1, flags_in);
125 exec_opb(s0, s1, flags_in);
126 }}}}}}
127 #else
128 exec_opq(s0, s1, 0);
129 exec_opl(s0, s1, 0);
130 exec_opw(s0, s1, 0);
131 exec_opb(s0, s1, 0);
132 exec_opq(s0, s1, CC_C);
133 exec_opl(s0, s1, CC_C);
134 exec_opw(s0, s1, CC_C);
135 exec_opb(s0, s1, CC_C);
136 #endif
139 void glue(test_, OP)(void)
141 #define NVALS 57
142 int64 i, j;
143 static unsigned int val[NVALS]
144 = { 0x00, 0x01, 0x02, 0x03,
145 0x3F, 0x40, 0x41,
146 0x7E, 0x7F, 0x80, 0x81, 0x82,
147 0xBF, 0xC0, 0xC1,
148 0xFC, 0xFD, 0xFE, 0xFF,
150 0xFF00, 0xFF01, 0xFF02, 0xFF03,
151 0xFF3F, 0xFF40, 0xFF41,
152 0xFF7E, 0xFF7F, 0xFF80, 0xFF81, 0xFF82,
153 0xFFBF, 0xFFC0, 0xFFC1,
154 0xFFFC, 0xFFFD, 0xFFFE, 0xFFFF,
156 0xFFFFFF00, 0xFFFFFF01, 0xFFFFFF02, 0xFFFFFF03,
157 0xFFFFFF3F, 0xFFFFFF40, 0xFFFFFF41,
158 0xFFFFFF7E, 0xFFFFFF7F, 0xFFFFFF80, 0xFFFFFF81, 0xFFFFFF82,
159 0xFFFFFFBF, 0xFFFFFFC0, 0xFFFFFFC1,
160 0xFFFFFFFC, 0xFFFFFFFD, 0xFFFFFFFE, 0xFFFFFFFF
163 exec_op(0xabcd12345678, 0x4321812FADA);
164 exec_op(0x12345678, 0x812FADA);
165 exec_op(0xabcd00012341, 0xabcd00012341);
166 exec_op(0x12341, 0x12341);
167 exec_op(0x12341, -0x12341);
168 exec_op(0xffffffff, 0);
169 exec_op(0xffffffff, -1);
170 exec_op(0xffffffff, 1);
171 exec_op(0xffffffff, 2);
172 exec_op(0x7fffffff, 0);
173 exec_op(0x7fffffff, 1);
174 exec_op(0x7fffffff, -1);
175 exec_op(0x80000000, -1);
176 exec_op(0x80000000, 1);
177 exec_op(0x80000000, -2);
178 exec_op(0x12347fff, 0);
179 exec_op(0x12347fff, 1);
180 exec_op(0x12347fff, -1);
181 exec_op(0x12348000, -1);
182 exec_op(0x12348000, 1);
183 exec_op(0x12348000, -2);
184 exec_op(0x12347f7f, 0);
185 exec_op(0x12347f7f, 1);
186 exec_op(0x12347f7f, -1);
187 exec_op(0x12348080, -1);
188 exec_op(0x12348080, 1);
189 exec_op(0x12348080, -2);
191 exec_op(0xFFFFFFFFffffffff, 0);
192 exec_op(0xFFFFFFFFffffffff, -1);
193 exec_op(0xFFFFFFFFffffffff, 1);
194 exec_op(0xFFFFFFFFffffffff, 2);
195 exec_op(0x7fffffffFFFFFFFF, 0);
196 exec_op(0x7fffffffFFFFFFFF, 1);
197 exec_op(0x7fffffffFFFFFFFF, -1);
198 exec_op(0x8000000000000000, -1);
199 exec_op(0x8000000000000000, 1);
200 exec_op(0x8000000000000000, -2);
201 exec_op(0x123443217FFFFFFF, 0);
202 exec_op(0x123443217FFFFFFF, 1);
203 exec_op(0x123443217FFFFFFF, -1);
204 exec_op(0x1234432180000000, -1);
205 exec_op(0x1234432180000000, 1);
206 exec_op(0x1234432180000000, -2);
207 exec_op(0x123443217F7F7f7f, 0);
208 exec_op(0x123443217F7F7f7f, 1);
209 exec_op(0x123443217F7F7f7f, -1);
210 exec_op(0x1234432180808080, -1);
211 exec_op(0x1234432180808080, 1);
212 exec_op(0x1234432180808080, -2);
214 #if TEST_INTEGER_VERBOSE
215 if (1)
216 for (i = 0; i < NVALS; i++)
217 for (j = 0; j < NVALS; j++)
218 exec_op(val[i], val[j]);
219 #endif
221 #undef NVALS
224 void *glue(_test_, OP) __init_call = glue(test_, OP);
226 #undef OP
227 #undef OP_CC