blob: 75106b8ce2a4c8c8936d026c00d36706aa252d1d [file] [log] [blame]
bellardd57c4e02003-03-04 01:14:13 +00001
2#define exec_op glue(exec_, OP)
bellard776f2222005-03-02 22:19:12 +00003#define exec_opq glue(glue(exec_, OP), q)
bellardd57c4e02003-03-04 01:14:13 +00004#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)
7
bellard776f2222005-03-02 22:19:12 +00008#define EXECOP2(size, rsize, res, s1, flags) \
bellardd57c4e02003-03-04 01:14:13 +00009 asm ("push %4\n\t"\
10 "popf\n\t"\
bellard776f2222005-03-02 22:19:12 +000011 stringify(OP) size " %" rsize "2, %" rsize "0\n\t" \
bellardd57c4e02003-03-04 01:14:13 +000012 "pushf\n\t"\
bellard776f2222005-03-02 22:19:12 +000013 "pop %1\n\t"\
bellardd57c4e02003-03-04 01:14:13 +000014 : "=q" (res), "=g" (flags)\
bellard776f2222005-03-02 22:19:12 +000015 : "q" (s1), "0" (res), "1" (flags)); \
16 printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n", \
17 stringify(OP) size, s0, s1, res, iflags, flags & CC_MASK);
bellardd57c4e02003-03-04 01:14:13 +000018
bellard776f2222005-03-02 22:19:12 +000019#define EXECOP1(size, rsize, res, flags) \
bellardd57c4e02003-03-04 01:14:13 +000020 asm ("push %3\n\t"\
21 "popf\n\t"\
bellard776f2222005-03-02 22:19:12 +000022 stringify(OP) size " %" rsize "0\n\t" \
bellardd57c4e02003-03-04 01:14:13 +000023 "pushf\n\t"\
bellard776f2222005-03-02 22:19:12 +000024 "pop %1\n\t"\
bellardd57c4e02003-03-04 01:14:13 +000025 : "=q" (res), "=g" (flags)\
bellard776f2222005-03-02 22:19:12 +000026 : "0" (res), "1" (flags)); \
27 printf("%-10s A=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n", \
28 stringify(OP) size, s0, res, iflags, flags & CC_MASK);
bellardd57c4e02003-03-04 01:14:13 +000029
30#ifdef OP1
bellard776f2222005-03-02 22:19:12 +000031#if defined(__x86_64__)
32void exec_opq(long s0, long s1, long iflags)
bellardd57c4e02003-03-04 01:14:13 +000033{
bellard776f2222005-03-02 22:19:12 +000034 long res, flags;
bellardd57c4e02003-03-04 01:14:13 +000035 res = s0;
36 flags = iflags;
bellard776f2222005-03-02 22:19:12 +000037 EXECOP1("q", "", res, flags);
bellardd57c4e02003-03-04 01:14:13 +000038}
39#endif
40
bellard776f2222005-03-02 22:19:12 +000041void exec_opl(long s0, long s1, long iflags)
bellardd57c4e02003-03-04 01:14:13 +000042{
bellard776f2222005-03-02 22:19:12 +000043 long res, flags;
44 res = s0;
45 flags = iflags;
46 EXECOP1("l", "k", res, flags);
47}
48
49void exec_opw(long s0, long s1, long iflags)
50{
51 long res, flags;
52 res = s0;
53 flags = iflags;
54 EXECOP1("w", "w", res, flags);
55}
56
57void exec_opb(long s0, long s1, long iflags)
58{
59 long res, flags;
60 res = s0;
61 flags = iflags;
62 EXECOP1("b", "b", res, flags);
63}
64#else
65#if defined(__x86_64__)
66void exec_opq(long s0, long s1, long iflags)
67{
68 long res, flags;
69 res = s0;
70 flags = iflags;
71 EXECOP2("q", "", res, s1, flags);
72}
73#endif
74
75void exec_opl(long s0, long s1, long iflags)
76{
77 long res, flags;
78 res = s0;
79 flags = iflags;
80 EXECOP2("l", "k", res, s1, flags);
81}
82
83void exec_opw(long s0, long s1, long iflags)
84{
85 long res, flags;
86 res = s0;
87 flags = iflags;
88 EXECOP2("w", "w", res, s1, flags);
89}
90
91void exec_opb(long s0, long s1, long iflags)
92{
93 long res, flags;
94 res = s0;
95 flags = iflags;
96 EXECOP2("b", "b", res, s1, flags);
97}
98#endif
99
100void exec_op(long s0, long s1)
101{
102 s0 = i2l(s0);
103 s1 = i2l(s1);
104#if defined(__x86_64__)
105 exec_opq(s0, s1, 0);
106#endif
bellardd57c4e02003-03-04 01:14:13 +0000107 exec_opl(s0, s1, 0);
108 exec_opw(s0, s1, 0);
109 exec_opb(s0, s1, 0);
110#ifdef OP_CC
bellard776f2222005-03-02 22:19:12 +0000111#if defined(__x86_64__)
112 exec_opq(s0, s1, CC_C);
113#endif
bellardd57c4e02003-03-04 01:14:13 +0000114 exec_opl(s0, s1, CC_C);
115 exec_opw(s0, s1, CC_C);
116 exec_opb(s0, s1, CC_C);
117#endif
118}
119
120void glue(test_, OP)(void)
121{
122 exec_op(0x12345678, 0x812FADA);
123 exec_op(0x12341, 0x12341);
124 exec_op(0x12341, -0x12341);
125 exec_op(0xffffffff, 0);
126 exec_op(0xffffffff, -1);
127 exec_op(0xffffffff, 1);
128 exec_op(0xffffffff, 2);
129 exec_op(0x7fffffff, 0);
130 exec_op(0x7fffffff, 1);
131 exec_op(0x7fffffff, -1);
132 exec_op(0x80000000, -1);
133 exec_op(0x80000000, 1);
134 exec_op(0x80000000, -2);
135 exec_op(0x12347fff, 0);
136 exec_op(0x12347fff, 1);
137 exec_op(0x12347fff, -1);
138 exec_op(0x12348000, -1);
139 exec_op(0x12348000, 1);
140 exec_op(0x12348000, -2);
141 exec_op(0x12347f7f, 0);
142 exec_op(0x12347f7f, 1);
143 exec_op(0x12347f7f, -1);
144 exec_op(0x12348080, -1);
145 exec_op(0x12348080, 1);
146 exec_op(0x12348080, -2);
147}
148
149void *glue(_test_, OP) __init_call = glue(test_, OP);
150
151#undef OP
152#undef OP_CC