1 /* OpenCP Module Player
2  * copyright (c) '04-'10 Stian Skjelstad <stian@nixia.no>
3  *
4  * Unit test for asm_emu/x86*.h
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20 
21 #include "config.h"
22 #include <math.h>
23 #include <stdio.h>
24 #include "types.h"
25 #include "x86.h"
26 
27 static struct assembler_state_t state;
28 static int failed = 0;
29 
writecallback(uint_fast16_t selector,uint_fast32_t addr,int size,uint_fast32_t data)30 static void writecallback(uint_fast16_t selector, uint_fast32_t addr, int size, uint_fast32_t data)
31 {
32 }
readcallback(uint_fast16_t selector,uint_fast32_t addr,int size)33 static uint_fast32_t readcallback(uint_fast16_t selector, uint_fast32_t addr, int size)
34 {
35 	return 0;
36 }
37 
adcb(void)38 static void adcb(void)
39 {
40 	int i;
41 	int j;
42 
43 	fprintf(stderr, "adcb x, y:\n");
44 	for (i=0;i<=255;i++)
45 	for (j=0;j<=255;j++)
46 	{
47 		write_cf(state.eflags, 0);
48 		state.al=i;
49 		state.bl=j;
50 		asm_adcb(&state, state.al, &state.bl);
51 		if ((i+j != state.bl) ^ read_cf(state.eflags))
52 		{
53 			failed++;
54 			fprintf(stderr, "  unsigned adcb failed: %d+%d+0=%d CF=%d\n", j, i, state.bl, read_cf(state.eflags));
55 		}
56 		if (((signed int)((signed char)i)+(signed int)((signed char)j) != (signed char)state.bl) ^ read_of(state.eflags))
57 		{
58 			failed++;
59 			fprintf(stderr, "  signed adcb failed: %d+%d+0=%d OF=%d\n", (signed char)j, (signed char)i, (signed char)state.bl, read_of(state.eflags));
60 		}
61 
62 		write_cf(state.eflags, 1);
63 		state.al=i;
64 		state.bl=j;
65 		asm_adcb(&state, state.al, &state.bl);
66 		if ((i+j+1 != state.bl) ^ read_cf(state.eflags))
67 		{
68 			failed++;
69 			fprintf(stderr, "  unsigned adcb failed: %d+%d+1=%d CF=%d\n", j, i, state.bl, read_cf(state.eflags));
70 		}
71 		if (((signed int)((signed char)i)+(signed int)((signed char)j)+1 != (signed char)state.bl) ^ read_of(state.eflags))
72 		{
73 			failed++;
74 			fprintf(stderr, "  signed adcb failed: %d+%d+1=%d OF=%d\n", (signed char)j, (signed char)i, (signed char)state.bl, read_of(state.eflags));
75 		}
76 
77 	}
78 }
79 
addb(void)80 static void addb(void)
81 {
82 	int i;
83 	int j;
84 
85 	fprintf(stderr, "addb x, y:\n");
86 	for (i=0;i<=255;i++)
87 	for (j=0;j<=255;j++)
88 	{
89 		state.al=i;
90 		state.bl=j;
91 		asm_addb(&state, state.al, &state.bl);
92 		if ((i+j != state.bl) ^ read_cf(state.eflags))
93 		{
94 			failed++;
95 			fprintf(stderr, "  unsigned addb failed: %d+%d=%d CF=%d\n", j, i, state.bl, read_cf(state.eflags));
96 		}
97 		if (((signed int)((signed char)i)+(signed int)((signed char)j) != (signed char)state.bl) ^ read_of(state.eflags))
98 		{
99 			failed++;
100 			fprintf(stderr, "  signed addb failed: %d+%d=%d OF=%d\n", (signed char)j, (signed char)i, (signed char)state.bl, read_of(state.eflags));
101 		}
102 	}
103 }
104 
divl(void)105 static void divl(void)
106 {
107 	uint64_t i; int donei=0; int oldi;
108 	uint_fast32_t j; int donej=0; int oldj;
109 	uint32_t tmp;
110 
111 	fprintf(stderr, "divl y:\n");
112 	for (i=0;!donei;)
113 	{
114 		donej=0;
115 		for (j=0;!donej;)
116 		{
117 			state.edx=i>>32;
118 			state.eax=i;
119 			if (state.edx<j)
120 			{
121 				state.ebx = j;
122 				asm_divl(&state, state.ebx);
123 				tmp = i/j;
124 				if (state.eax != tmp)
125 				{
126 					failed++;
127 					fprintf(stderr, "  divl failed: %lld/%d=%d EXPECTED %d\n", i, j, state.eax, tmp);
128 				}
129 			}
130 			oldj = j;
131 			if (j & 1)
132 				j+=0x7fffff;
133 			else
134 				j++;
135 			donej = j < oldj;
136 		}
137 		oldi = i;
138 		if (i & 1)
139 			i+=0x7fffffffffffLL;
140 		else
141 			i++;
142 		donei = i < oldi;
143 	}
144 }
145 
imul_1_b(void)146 static void imul_1_b(void)
147 {
148 	int i;
149 	int j;
150 	int tmp;
151 	int tmp2;
152 
153 	fprintf(stderr, "imul_1_b x:\n");
154 	for (i=0;i<=255;i++)
155 	for (j=0;j<=255;j++)
156 	{
157 		state.al=i;
158 		asm_imul_1_b(&state, j);
159 		tmp = (int8_t)i*(int8_t)j;
160 		tmp2 = (tmp<-256)||(tmp>255); /* x86 specs seems a bit wierd here at this point, since overflow/carry flag reflect the sign of the result*/
161 		if (((int16_t)state.ax != tmp) || (read_cf(state.eflags) != tmp2) || (read_of(state.eflags) != tmp2))
162 		{
163 			failed++;
164 			fprintf(stderr, "  imul_1_b failed: %d*%d=%d OF=%d CF=%d EXPECTED %d*%d=%d OF=%d CF=%d\n", (signed char)i, (signed char)j, (int16_t)state.ax, read_of(state.eflags), read_cf(state.eflags), (signed char)i, (signed char)j, tmp, tmp2, tmp2);
165 		}
166 	}
167 }
168 
imul_1_w(void)169 static void imul_1_w(void)
170 {
171 	int i;
172 	int j;
173 	int_fast32_t tmp;
174 	int tmp2;
175 	uint16_t tmp3, tmp4;
176 
177 	fprintf(stderr, "imul_1_w x:\n");
178 	for (i=0;i<=65536;)
179 	{
180 		for (j=0;j<=65536;)
181 		{
182 			state.ax=i;
183 			asm_imul_1_w(&state, j);
184 			tmp = ((int_fast32_t)(int16_t)i)*(int16_t)j;
185 			tmp3 = (unsigned)tmp&0xffff;
186 			tmp4 = (unsigned)tmp>>16;
187 			tmp2 = (tmp<-65536)||(tmp>65535); /* x86 specs seems a bit wierd here at this point, since overflow/carry flag reflect the sign of the result*/
188 			if ((state.ax != tmp3) || (state.dx != tmp4) || (read_cf(state.eflags) != tmp2) || (read_of(state.eflags) != tmp2))
189 			{
190 				failed++;
191 				fprintf(stderr, "  imul_1_w failed: %d*%d=%d OF=%d CF=%d EXPECTED %d*%d=%d OF=%d CF=%d\n", (int16_t)i, (int16_t)j, (((int)state.ax<<16) | state.dx), read_of(state.eflags), read_cf(state.eflags), (int16_t)i, (int16_t)j, tmp, tmp2, tmp2);
192 			}
193 
194 			if (j & 1)
195 				j+=127;
196 			else
197 				j++;
198 
199 		}
200 		if (i & 1)
201 			i+=127;
202 		else
203 			i++;
204 	}
205 }
206 
imul_1_l(void)207 static void imul_1_l(void)
208 {
209 	int i; int donei=0; int oldi;
210 	int j; int donej=0; int oldj;
211 	int_fast64_t tmp;
212 	int tmp2;
213 	uint32_t tmp3, tmp4;
214 
215 	fprintf(stderr, "imul_1_l x:\n");
216 	for (i=0;!donei;)
217 	{
218 		donej=0;
219 		for (j=0;!donej;)
220 		{
221 			state.eax=i;
222 			asm_imul_1_l(&state, j);
223 			tmp = ((int_fast64_t)(int32_t)i)*(int32_t)j;
224 			tmp3 = (uint_fast64_t)tmp&0xffffffff;
225 			tmp4 = (uint_fast64_t)tmp>>32;
226 			if ((tmp & 0xffffffff00000000LL) == 0x0000000000000000LL)
227 				tmp2 = 0;
228 			else if ((tmp & 0xffffffff00000000LL) == 0xffffffff00000000LL)
229 				tmp2 = 0;
230 			else
231 				tmp2 = 1;
232 			if ((state.eax != tmp3) || (state.edx != tmp4) || (read_cf(state.eflags) != tmp2) || (read_of(state.eflags) != tmp2))
233 			{
234 				failed++;
235 				fprintf(stderr, "  imul_1_l failed: %d*%d=%lld OF=%d CF=%d EXPECTED %d*%d=%lld OF=%d CF=%d\n", (int32_t)i, (int32_t)j, (((uint64_t)state.ax<<32) | state.edx), read_of(state.eflags), read_cf(state.eflags), (int32_t)i, (int32_t)j, tmp, tmp2, tmp2);
236 			}
237 			oldj = j;
238 			if (j & 1)
239 				j+=0x7fffff;
240 			else
241 				j++;
242 			donej = j < oldj;
243 		}
244 		oldi = i;
245 		if (i & 1)
246 			i+=32767;
247 		else
248 			i++;
249 		donei = i < oldi;
250 	}
251 }
252 
imul_2_l(void)253 static void imul_2_l(void)
254 {
255 	int i; int donei=0; int oldi;
256 	int j; int donej=0; int oldj;
257 	int_fast64_t tmp;
258 /*
259 	int tmp2;*/
260 	uint32_t tmp3, tmp4;
261 
262 	fprintf(stderr, "imul_2_l x,y:\n");
263 	for (i=0x80000000;!donei;)
264 	{
265 		donej=0;
266 		for (j=0x80000000;!donej;)
267 		{
268 			state.eax=i;
269 			asm_imul_2_l(&state, j, &state.eax);
270 			tmp = ((int_fast64_t)(int32_t)i)*(int32_t)j;
271 			tmp3 = (uint_fast64_t)tmp&0xffffffff;
272 			tmp4 = (uint_fast64_t)tmp>>32;
273 			if ((tmp4 == 0x00000000) || (tmp4 == 0xffffffff)) /* we ignore overruns for now */
274 			{
275 /*
276 			if ((tmp & 0xffffffff00000000LL) == 0x0000000000000000LL)
277 				tmp2 = 0;
278 			else if ((tmp & 0xffffffff00000000LL) == 0xffffffff00000000LL)
279 				tmp2 = 0;
280 			else
281 				tmp2 = 1;*/
282 				if ((state.eax != tmp3)/* || (state.edx != tmp4) || (read_cf(state.eflags) != tmp2) || (read_of(state.eflags) != tmp2)*/)
283 				{
284 					failed++;
285 					fprintf(stderr, "  imul_2_l failed: %d*%d=%d EXPECTED %d*%d=%d\n", (int32_t)i, (int32_t)j, state.eax, (int32_t)i, (int32_t)j, (int32_t)tmp);
286 				}
287 			}
288 			oldj = j;
289 			if (j & 1)
290 				j+=0x7fffff;
291 			else
292 				j++;
293 			donej = j < oldj;
294 		}
295 		oldi = i;
296 		if (i & 1)
297 			i+=32767;
298 		else
299 			i++;
300 		donei = i < oldi;
301 	}
302 }
303 
sarl(void)304 static void sarl(void)
305 {
306 	int i;
307 	fprintf(stderr, "sarl x, y:\n");
308 	for (i=0;i<=32;i++)
309 	{
310 		uint32_t tmp;
311 		state.eax = 0x10000000;
312 		if (i==0)
313 			tmp = state.eax;
314 		else if (i==32)
315 			tmp = state.eax; /* wrap... this is kind of undefined on the x86 platform */
316 		else
317 			tmp = (state.eax >> i);
318 		asm_sarl(&state, i, &state.eax);
319 		if (tmp != state.eax)
320 		{
321 			fprintf(stderr, " shll %d, 0x00000001 failed, expected 0x%08x, got 0x%08x\n", i, (int)tmp, (int)state.ebx);
322 			failed++;
323 		}
324 	}
325 }
326 
sbbb(void)327 static void sbbb(void)
328 {
329 	int i;
330 	int j;
331 
332 	fprintf(stderr, "sbbb x, y:\n");
333 	for (i=0;i<=255;i++)
334 	for (j=0;j<=255;j++)
335 	{
336 		write_cf(state.eflags, 0);
337 		state.al=i;
338 		state.bl=j;
339 		asm_sbbb(&state, state.al, &state.bl);
340 		if ((j-i != state.bl) ^ read_cf(state.eflags))
341 		{
342 			failed++;
343 			fprintf(stderr, "  unsigned sbbb failed: %d-%d-0=%d CF=%d\n", j, i, state.bl, read_cf(state.eflags));
344 		}
345 		if (((signed int)((signed char)j)-(signed int)((signed char)i) != (signed char)state.bl) ^ read_of(state.eflags))
346 		{
347 			failed++;
348 			fprintf(stderr, "  signed sbbb failed: %d-%d-0=%d OF=%d\n", (signed char)j, (signed char)i, (signed char)state.bl, read_of(state.eflags));
349 		}
350 
351 		write_cf(state.eflags, 1);
352 		state.al=i;
353 		state.bl=j;
354 		asm_sbbb(&state, state.al, &state.bl);
355 		if ((j-i-1 != state.bl) ^ read_cf(state.eflags))
356 		{
357 			failed++;
358 			fprintf(stderr, "  unsigned sbbb failed: %d-%d-1=%d CF=%d\n", j, i, state.bl, read_cf(state.eflags));
359 		}
360 		if (((signed int)((signed char)j)-(signed int)((signed char)i)-1 != (signed char)state.bl) ^ read_of(state.eflags))
361 		{
362 			failed++;
363 			fprintf(stderr, "  signed sbbb failed: %d-%d-1=%d OF=%d\n", (signed char)j, (signed char)i, (signed char)state.bl, read_of(state.eflags));
364 		}
365 	}
366 }
367 
shll(void)368 static void shll(void)
369 {
370 	int i;
371 	fprintf(stderr, "shll x, y:\n");
372 	for (i=0;i<=32;i++)
373 	{
374 		uint32_t tmp;
375 		state.eax = 0x00000001;
376 		if (i==0)
377 			tmp = state.eax;
378 		else if (i==32)
379 			tmp = state.eax; /* wrap... this is kind of undefined on the x86 platform */
380 		else
381 			tmp = (state.eax << i);
382 		asm_shll(&state, i, &state.eax);
383 		if (tmp != state.eax)
384 		{
385 			fprintf(stderr, " shll %d, 0x00000001 failed, expected 0x%08x, got 0x%08x\n", i, (int)tmp, (int)state.ebx);
386 			failed++;
387 		}
388 	}
389 }
390 
shldl(void)391 static void shldl(void)
392 {
393 	int i;
394 	fprintf(stderr, "shldl x, y, z:\n");
395 	for (i=0;i<=32;i++)
396 	{
397 		uint32_t tmp;
398 		state.eax = 0x80000000;
399 		state.ebx = 0x00001000;
400 		if (i==0)
401 			tmp = state.ebx;
402 		else if (i==32)
403 			tmp = state.ebx; /* wrap... this is kind of undefined on the x86 platform */
404 		else
405 			tmp = (state.ebx << i)|(state.eax>>(32-i));
406 		asm_shldl(&state, i, state.eax, &state.ebx);
407 		if (tmp != state.ebx)
408 		{
409 			fprintf(stderr, " shldl %d, 0x%08x, 0x%08x failed, expected 0x%08x, got 0x%08x\n", i, 0x80000000, 0x00001000, (int)tmp, (int)state.ebx);
410 			failed++;
411 		}
412 	}
413 }
414 
subb(void)415 static void subb(void)
416 {
417 	int i;
418 	int j;
419 
420 	fprintf(stderr, "subb x, y:\n");
421 	for (i=0;i<=255;i++)
422 	for (j=0;j<=255;j++)
423 	{
424 		state.al=i;
425 		state.bl=j;
426 		asm_subb(&state, state.al, &state.bl);
427 		if ((j-i != state.bl) ^ read_cf(state.eflags))
428 		{
429 			failed++;
430 			fprintf(stderr, "  unsigned subb failed: %d-%d=%d CF=%d\n", j, i, state.bl, read_cf(state.eflags));
431 		}
432 		if (((signed int)((signed char)j)-(signed int)((signed char)i) != (signed char)state.bl) ^ read_of(state.eflags))
433 		{
434 			failed++;
435 			fprintf(stderr, "  signed subb failed: %d-%d=%d OF=%d\n", (signed char)j, (signed char)i, (signed char)state.bl, read_of(state.eflags));
436 		}
437 	}
438 }
439 
main(int argc,char * argv[])440 int main(int argc, char *argv[])
441 {
442 	init_assembler_state(&state, writecallback, readcallback);
443 
444 	asm_flds(&state, -123.4567);
445 	asm_flds(&state, -223.4567);
446 	asm_flds(&state, -323.4567);
447 
448 	fprintf(stderr, "[FPU reset state]\n");
449 	fprintf(stderr, "Status Busy [B] = %d\n", read_fpu_status_busy(state.FPUStatusWord));
450 	fprintf(stderr, "Status Conditioncode3 [C3] = %d\n", read_fpu_status_conditioncode3(state.FPUStatusWord));
451 	fprintf(stderr, "Status Conditioncode2 [C2] = %d\n", read_fpu_status_conditioncode2(state.FPUStatusWord));
452 	fprintf(stderr, "Status Conditioncode1 [C1] = %d\n", read_fpu_status_conditioncode1(state.FPUStatusWord));
453 	fprintf(stderr, "Status Conditioncode0 [C0] = %d\n", read_fpu_status_conditioncode0(state.FPUStatusWord));
454 	fprintf(stderr, "Status Top [TOP] = %d\n", read_fpu_status_top(state.FPUStatusWord));
455 	fprintf(stderr, "Status Error Summary [ES] = %d\n", read_fpu_status_error_summary(state.FPUStatusWord));
456 	fprintf(stderr, "Status Stack Fault [SF] = %d\n", read_fpu_status_stack_fault(state.FPUStatusWord));
457 	fprintf(stderr, "Status Exception Precision [PE] = %d\n", read_fpu_status_exception_precision(state.FPUStatusWord));
458 	fprintf(stderr, "Status Exception Underflow [UE] = %d\n", read_fpu_status_exception_underflow(state.FPUStatusWord));
459 	fprintf(stderr, "Status Exception Overflow [OE] = %d\n", read_fpu_status_exception_overflow(state.FPUStatusWord));
460 	fprintf(stderr, "Status Exception Zero [ZE] = %d\n", read_fpu_status_exception_zero_divide(state.FPUStatusWord));
461 	fprintf(stderr, "Status Exception Denormalized Operand [DE] = %d\n", read_fpu_status_exception_denormalized_operand(state.FPUStatusWord));
462 	fprintf(stderr, "Status Exception Invalid Operand [EI] = %d\n", read_fpu_status_exception_invalid_operand(state.FPUStatusWord));
463 	fprintf(stderr, "Control Infinity [X] = %d\n",  read_fpu_control_infinty(state.FPUControlWord));
464 	fprintf(stderr, "Control Rounding [RC] = %d ",  read_fpu_control_rounding(state.FPUControlWord));
465 	switch (read_fpu_control_rounding(state.FPUControlWord))
466 	{
467 		case RC_ROUND_TO_NEAREST:
468 			fprintf(stderr, "Round to nearest (even)\n");
469 			break;
470 		case RC_ROUND_DOWN:
471 			fprintf(stderr, "Round down (toward negative inifinty)\n");
472 			break;
473 		case RC_ROUND_UP:
474 			fprintf(stderr, "Round up (toward positive infinity)\n");
475 			break;
476 		case RC_ROUND_ZERO:
477 			fprintf(stderr, "Round toward zero (truncate)\n");
478 			break;
479 	}
480 	fprintf(stderr, "Control Precision [PC] = %d ", read_fpu_control_precision(state.FPUControlWord));
481 	switch (read_fpu_control_precision(state.FPUControlWord))
482 	{
483 		case PC_SINGLE_PRECISION:
484 			fprintf(stderr, "Single (24bits)\n");
485 			break;
486 		case PC_RESERVED:
487 			fprintf(stderr, "Reserved\n");
488 			break;
489 		case PC_DOUBLE_PRECISION:
490 			fprintf(stderr, "Double (53bits)\n");
491 			break;
492 		case PC_DOUBLE_EXTENDED_PRECISION:
493 			fprintf(stderr, "Double Extended (64bits)\n");
494 			break;
495 	}
496 	fprintf(stderr, "Control Exception Mask Precision [PM] = %d\n", read_fpu_control_exception_mask_precision(state.FPUControlWord));
497 	fprintf(stderr, "Control Exception Mask Underflow [UM] = %d\n", read_fpu_control_exception_mask_underflow(state.FPUControlWord));
498 	fprintf(stderr, "Control Exception Mask Overflow [OM] = %d\n", read_fpu_control_exception_mask_overflow(state.FPUControlWord));
499 	fprintf(stderr, "Control Exception Mask Zero Divide [ZM] = %d\n", read_fpu_control_exception_mask_zero_divide(state.FPUControlWord));
500 	fprintf(stderr, "Control Exception Mask Denormal Operand [DM] = %d\n", read_fpu_control_exception_mask_denormal_operand(state.FPUControlWord));
501 	fprintf(stderr, "Control Exception Mask Invalid Operation [IM] = %d\n", read_fpu_control_exception_mask_invalid_operation(state.FPUControlWord));
502 	fprintf(stderr, "Tag Word = 0x%04x:\n", state.FPUTagWord);
503 	{
504 		int i;
505 		for (i=0;i<8;i++)
506 		{
507 			int tag = read_fpu_sub_tag(state.FPUTagWord, i);
508 			fprintf(stderr, "TAG(%d) = %d ", i, tag);
509 			switch (tag)
510 			{
511 				case FPU_TAG_VALID:
512 					fprintf(stderr, "VALID\n");
513 					fprintf(stderr, "ST%d = " FPU_TYPE_FORMAT "\n", i, read_fpu_st(&state, i));
514 					break;
515 				case FPU_TAG_ZERO:
516 					fprintf(stderr, "ZERO\n");
517 					fprintf(stderr, "ST%d = " FPU_TYPE_FORMAT "\n", i, read_fpu_st(&state, i));
518 					break;
519 				case FPU_TAG_SPECIAL:
520 					fprintf(stderr, "SPECIAL ");
521 					{
522 						FPU_TYPE data = read_fpu_st(&state, i);
523 						if (signbit(data))
524 							fprintf(stderr, "- ");
525 						else
526 							fprintf(stderr, "+ ");
527 						if (isnan(data))
528 							fprintf(stderr, "NaN ");
529 						if (isfinite(data))
530 							fprintf(stderr, "Inf ");
531 						if (!isnormal(data))
532 							fprintf(stderr, "!Normal ");
533 						fprintf(stderr, "\n");
534 					}
535 					break;
536 				case FPU_TAG_EMPTY:
537 					fprintf(stderr, "EMPTY\n");
538 					break;
539 			}
540 		}
541 	}
542 	fprintf(stderr, "\n");
543 	asm_movl(&state, 0x12345678, &state.eax);
544 	asm_movl(&state, 0x01234567, &state.ebx);
545 	asm_cmpl(&state, state.eax, state.ebx);
546 	asm_jb(&state, jb_exit);
547 	fprintf(stderr, "cmpl 0x12345678, 0x01234567  does not branch jb\n");
548 	goto jb_done;
549 jb_exit:
550 	fprintf(stderr, "cmpl 0x12345678, 0x01234567  does branch jb\n");
551 jb_done:
552 
553 
554 
555 	if (state.eax != 0x12345678)
556 	{
557 		fprintf(stderr, "movl failed... expected 0x12345678, got 0x%08x\n", (int)state.eax);
558 		failed++;
559 	}
560 	if (state.ax != 0x5678)
561 	{
562 		fprintf(stderr, "endian failed, expected 0x5678, got 0x%04x\n", (int)state.ax);
563 		failed++;
564 	}
565 	if (state.al != 0x78)
566 	{
567 		fprintf(stderr, "endian failed, expected 0x78, got 0x%02x\n", (int)state.al);
568 		failed++;
569 	}
570 	if (state.ah != 0x56)
571 	{
572 		fprintf(stderr, "endian failed, expected 0x56, got 0x%02x\n", (int)state.ah);
573 		failed++;
574 	}
575 
576 /*
577 	asm_subl(&state, 0x12345679, &state.eax);
578 
579 	fprintf(stderr, "eflags=0x%08x\n", state.eflags);
580 #ifdef X86_AF
581 	fprintf(stderr, "    af=%d\n", read_af(state.eflags));
582 #endif
583 	fprintf(stderr, "    cf=%d\n", read_cf(state.eflags));
584 	fprintf(stderr, "    of=%d\n", read_of(state.eflags));
585 #ifdef X86_PF
586 	fprintf(stderr, "    pf=%d\n", read_pf(state.eflags));
587 #endif
588 	fprintf(stderr, "    sf=%d\n", read_sf(state.eflags));
589 	fprintf(stderr, "    zf=%d\n", read_zf(state.eflags));
590 */
591 	adcb();
592 	addb();
593 	divl();
594 	imul_1_b();
595 	imul_1_w();
596 	imul_1_l();
597 	imul_2_l();
598 	sarl();
599 	sbbb();
600 	shldl();
601 	shll();
602 	subb();
603 
604 	return !!failed;
605 
606 }
607