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