blob: e86b85f5a787367c6fff955f4b9d2e19842921ac [file] [log] [blame]
sewardj5484c142004-08-24 22:43:26 +00001
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#ifndef OP_SHIFTD
8
9#ifdef OP_NOBYTE
10#define EXECSHIFT(size, res, s1, s2, flags) \
11 asm ("push %4\n\t"\
12 "popf\n\t"\
13 stringify(OP) size " %" size "2, %" size "0\n\t" \
14 "pushf\n\t"\
15 "popl %1\n\t"\
16 : "=g" (res), "=g" (flags)\
17 : "r" (s1), "0" (res), "1" (flags));
18#else
19#define EXECSHIFT(size, res, s1, s2, flags) \
20 asm ("push %4\n\t"\
21 "popf\n\t"\
22 stringify(OP) size " %%cl, %" size "0\n\t" \
23 "pushf\n\t"\
24 "popl %1\n\t"\
25 : "=q" (res), "=g" (flags)\
26 : "c" (s1), "0" (res), "1" (flags));
27#endif
28
29void exec_opl(int s2, int s0, int s1, int iflags)
30{
31 int res, flags;
32 res = s0;
33 flags = iflags;
34 EXECSHIFT("", res, s1, s2, 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) "l", s0, s1, res, iflags, flags & CC_MASK);
40}
41
42void exec_opw(int s2, int s0, int s1, int iflags)
43{
44 int res, flags;
45 res = s0;
46 flags = iflags;
47 EXECSHIFT("w", res, s1, s2, 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) "w", s0, s1, res, iflags, flags & CC_MASK);
53}
54
55#else
56#define EXECSHIFT(size, res, s1, s2, flags) \
57 asm ("push %4\n\t"\
58 "popf\n\t"\
59 stringify(OP) size " %%cl, %" size "5, %" size "0\n\t" \
60 "pushf\n\t"\
61 "popl %1\n\t"\
62 : "=g" (res), "=g" (flags)\
63 : "c" (s1), "0" (res), "1" (flags), "r" (s2));
64
65void exec_opl(int s2, int s0, int s1, int iflags)
66{
67 int res, flags;
68 res = s0;
69 flags = iflags;
70 EXECSHIFT("", res, s1, s2, flags);
71 /* overflow is undefined if count != 1 */
72 if (s1 != 1)
73 flags &= ~CC_O;
74 printf("%-10s A=%08x B=%08x C=%08x R=%08x CCIN=%04x CC=%04x\n",
75 stringify(OP) "l", s0, s2, s1, res, iflags, flags & CC_MASK);
76}
77
78void exec_opw(int s2, int s0, int s1, int iflags)
79{
80 int res, flags;
81 res = s0;
82 flags = iflags;
83 EXECSHIFT("w", res, s1, s2, flags);
84 /* overflow is undefined if count != 1 */
85 if (s1 != 1)
86 flags &= ~CC_O;
87 printf("%-10s A=%08x B=%08x C=%08x R=%08x CCIN=%04x CC=%04x\n",
88 stringify(OP) "w", s0, s2, s1, res, iflags, flags & CC_MASK);
89}
90
91#endif
92
93#ifndef OP_NOBYTE
94void exec_opb(int s0, int s1, int iflags)
95{
96 int res, flags;
97 res = s0;
98 flags = iflags;
99 EXECSHIFT("b", res, s1, 0, flags);
100 /* overflow is undefined if count != 1 */
101 if (s1 != 1)
102 flags &= ~CC_O;
103 printf("%-10s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
104 stringify(OP) "b", s0, s1, res, iflags, flags & CC_MASK);
105}
106#endif
107
108void exec_op(int s2, int s0, int s1)
109{
sewardj2b5b7512004-08-26 11:27:21 +0000110 int o,s,z,a,c,p,flags_in;
111 for (o = 0; o < 2; o++) {
112 for (s = 0; s < 2; s++) {
113 for (z = 0; z < 2; z++) {
114 for (a = 0; a < 2; a++) {
115 for (c = 0; c < 2; c++) {
116 for (p = 0; p < 2; p++) {
117
118 flags_in = (o ? CC_O : 0)
119 | (s ? CC_S : 0)
120 | (z ? CC_Z : 0)
121 | (a ? CC_A : 0)
122 | (c ? CC_C : 0)
123 | (p ? CC_P : 0);
124
125 exec_opl(s2, s0, s1, flags_in);
sewardj5484c142004-08-24 22:43:26 +0000126#ifdef OP_SHIFTD
127 if (s1 <= 15)
sewardj2b5b7512004-08-26 11:27:21 +0000128 exec_opw(s2, s0, s1, flags_in);
sewardj5484c142004-08-24 22:43:26 +0000129#else
sewardj2b5b7512004-08-26 11:27:21 +0000130 exec_opw(s2, s0, s1, flags_in);
sewardj5484c142004-08-24 22:43:26 +0000131#endif
132#ifndef OP_NOBYTE
sewardj2b5b7512004-08-26 11:27:21 +0000133 exec_opb(s0, s1, flags_in);
sewardj5484c142004-08-24 22:43:26 +0000134#endif
135#ifdef OP_CC
sewardj2b5b7512004-08-26 11:27:21 +0000136 exec_opl(s2, s0, s1, flags_in);
137 exec_opw(s2, s0, s1, flags_in);
138 exec_opb(s0, s1, flags_in);
sewardj5484c142004-08-24 22:43:26 +0000139#endif
sewardj2b5b7512004-08-26 11:27:21 +0000140
141 }}}}}}
142
sewardj5484c142004-08-24 22:43:26 +0000143}
144
145void glue(test_, OP)(void)
146{
147 int i;
148 for(i = 0; i < 32; i++)
149 exec_op(0x21ad3d34, 0x12345678, i);
150 for(i = 0; i < 32; i++)
151 exec_op(0x813f3421, 0x82345678, i);
152}
153
154void *glue(_test_, OP) __init_call = glue(test_, OP);
155
156#undef OP
157#undef OP_CC
158#undef OP_SHIFTD
159#undef OP_NOBYTE
160#undef EXECSHIFT
161