root / target-ppc / op_helper.c @ a7037b29
History | View | Annotate | Download (58.8 kB)
1 | 9a64fbe4 | bellard | /*
|
---|---|---|---|
2 | 3fc6c082 | bellard | * PowerPC emulation helpers for qemu.
|
3 | 9a64fbe4 | bellard | *
|
4 | 76a66253 | j_mayer | * Copyright (c) 2003-2007 Jocelyn Mayer
|
5 | 9a64fbe4 | bellard | *
|
6 | 9a64fbe4 | bellard | * This library is free software; you can redistribute it and/or
|
7 | 9a64fbe4 | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | 9a64fbe4 | bellard | * License as published by the Free Software Foundation; either
|
9 | 9a64fbe4 | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | 9a64fbe4 | bellard | *
|
11 | 9a64fbe4 | bellard | * This library is distributed in the hope that it will be useful,
|
12 | 9a64fbe4 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 9a64fbe4 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 9a64fbe4 | bellard | * Lesser General Public License for more details.
|
15 | 9a64fbe4 | bellard | *
|
16 | 9a64fbe4 | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | 9a64fbe4 | bellard | * License along with this library; if not, write to the Free Software
|
18 | 9a64fbe4 | bellard | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 | 9a64fbe4 | bellard | */
|
20 | 9a64fbe4 | bellard | #include "exec.h" |
21 | 9a64fbe4 | bellard | |
22 | 0487d6a8 | j_mayer | #include "op_helper.h" |
23 | 0487d6a8 | j_mayer | |
24 | 9a64fbe4 | bellard | #define MEMSUFFIX _raw
|
25 | 0487d6a8 | j_mayer | #include "op_helper.h" |
26 | 9a64fbe4 | bellard | #include "op_helper_mem.h" |
27 | a541f297 | bellard | #if !defined(CONFIG_USER_ONLY)
|
28 | 9a64fbe4 | bellard | #define MEMSUFFIX _user
|
29 | 0487d6a8 | j_mayer | #include "op_helper.h" |
30 | 9a64fbe4 | bellard | #include "op_helper_mem.h" |
31 | 9a64fbe4 | bellard | #define MEMSUFFIX _kernel
|
32 | 0487d6a8 | j_mayer | #include "op_helper.h" |
33 | 9a64fbe4 | bellard | #include "op_helper_mem.h" |
34 | 9a64fbe4 | bellard | #endif
|
35 | 9a64fbe4 | bellard | |
36 | fdabc366 | bellard | //#define DEBUG_OP
|
37 | fdabc366 | bellard | //#define DEBUG_EXCEPTIONS
|
38 | 76a66253 | j_mayer | //#define DEBUG_SOFTWARE_TLB
|
39 | fdabc366 | bellard | //#define FLUSH_ALL_TLBS
|
40 | fdabc366 | bellard | |
41 | 9a64fbe4 | bellard | /*****************************************************************************/
|
42 | 9a64fbe4 | bellard | /* Exceptions processing helpers */
|
43 | 76a66253 | j_mayer | void cpu_loop_exit (void) |
44 | 9a64fbe4 | bellard | { |
45 | 9fddaa0c | bellard | longjmp(env->jmp_env, 1);
|
46 | 9a64fbe4 | bellard | } |
47 | 9a64fbe4 | bellard | |
48 | 9fddaa0c | bellard | void do_raise_exception_err (uint32_t exception, int error_code) |
49 | 9a64fbe4 | bellard | { |
50 | 9fddaa0c | bellard | #if 0
|
51 | 9fddaa0c | bellard | printf("Raise exception %3x code : %d\n", exception, error_code);
|
52 | 9fddaa0c | bellard | #endif
|
53 | 9fddaa0c | bellard | switch (exception) {
|
54 | 9fddaa0c | bellard | case EXCP_PROGRAM:
|
55 | 76a66253 | j_mayer | if (error_code == EXCP_FP && msr_fe0 == 0 && msr_fe1 == 0) |
56 | 76a66253 | j_mayer | return;
|
57 | 76a66253 | j_mayer | break;
|
58 | 9fddaa0c | bellard | default:
|
59 | 76a66253 | j_mayer | break;
|
60 | 76a66253 | j_mayer | } |
61 | 9fddaa0c | bellard | env->exception_index = exception; |
62 | 9fddaa0c | bellard | env->error_code = error_code; |
63 | 76a66253 | j_mayer | cpu_loop_exit(); |
64 | 76a66253 | j_mayer | } |
65 | 9fddaa0c | bellard | |
66 | 9fddaa0c | bellard | void do_raise_exception (uint32_t exception)
|
67 | 9fddaa0c | bellard | { |
68 | 9fddaa0c | bellard | do_raise_exception_err(exception, 0);
|
69 | 9a64fbe4 | bellard | } |
70 | 9a64fbe4 | bellard | |
71 | a496775f | j_mayer | void cpu_dump_EA (target_ulong EA);
|
72 | a496775f | j_mayer | void do_print_mem_EA (target_ulong EA)
|
73 | a496775f | j_mayer | { |
74 | a496775f | j_mayer | cpu_dump_EA(EA); |
75 | a496775f | j_mayer | } |
76 | a496775f | j_mayer | |
77 | 9a64fbe4 | bellard | /*****************************************************************************/
|
78 | 76a66253 | j_mayer | /* Registers load and stores */
|
79 | 76a66253 | j_mayer | void do_load_cr (void) |
80 | 76a66253 | j_mayer | { |
81 | 76a66253 | j_mayer | T0 = (env->crf[0] << 28) | |
82 | 76a66253 | j_mayer | (env->crf[1] << 24) | |
83 | 76a66253 | j_mayer | (env->crf[2] << 20) | |
84 | 76a66253 | j_mayer | (env->crf[3] << 16) | |
85 | 76a66253 | j_mayer | (env->crf[4] << 12) | |
86 | 76a66253 | j_mayer | (env->crf[5] << 8) | |
87 | 76a66253 | j_mayer | (env->crf[6] << 4) | |
88 | 76a66253 | j_mayer | (env->crf[7] << 0); |
89 | 76a66253 | j_mayer | } |
90 | 76a66253 | j_mayer | |
91 | 76a66253 | j_mayer | void do_store_cr (uint32_t mask)
|
92 | 76a66253 | j_mayer | { |
93 | 76a66253 | j_mayer | int i, sh;
|
94 | 76a66253 | j_mayer | |
95 | 76a66253 | j_mayer | for (i = 0, sh = 7; i < 8; i++, sh --) { |
96 | 76a66253 | j_mayer | if (mask & (1 << sh)) |
97 | 76a66253 | j_mayer | env->crf[i] = (T0 >> (sh * 4)) & 0xFUL; |
98 | 76a66253 | j_mayer | } |
99 | 76a66253 | j_mayer | } |
100 | 76a66253 | j_mayer | |
101 | 76a66253 | j_mayer | void do_load_xer (void) |
102 | 76a66253 | j_mayer | { |
103 | 76a66253 | j_mayer | T0 = (xer_so << XER_SO) | |
104 | 76a66253 | j_mayer | (xer_ov << XER_OV) | |
105 | 76a66253 | j_mayer | (xer_ca << XER_CA) | |
106 | 76a66253 | j_mayer | (xer_bc << XER_BC) | |
107 | 76a66253 | j_mayer | (xer_cmp << XER_CMP); |
108 | 76a66253 | j_mayer | } |
109 | 76a66253 | j_mayer | |
110 | 76a66253 | j_mayer | void do_store_xer (void) |
111 | 76a66253 | j_mayer | { |
112 | 76a66253 | j_mayer | xer_so = (T0 >> XER_SO) & 0x01;
|
113 | 76a66253 | j_mayer | xer_ov = (T0 >> XER_OV) & 0x01;
|
114 | 76a66253 | j_mayer | xer_ca = (T0 >> XER_CA) & 0x01;
|
115 | 76a66253 | j_mayer | xer_cmp = (T0 >> XER_CMP) & 0xFF;
|
116 | d9bce9d9 | j_mayer | xer_bc = (T0 >> XER_BC) & 0x7F;
|
117 | 76a66253 | j_mayer | } |
118 | 76a66253 | j_mayer | |
119 | 76a66253 | j_mayer | void do_load_fpscr (void) |
120 | 76a66253 | j_mayer | { |
121 | 76a66253 | j_mayer | /* The 32 MSB of the target fpr are undefined.
|
122 | 76a66253 | j_mayer | * They'll be zero...
|
123 | 76a66253 | j_mayer | */
|
124 | 76a66253 | j_mayer | union {
|
125 | 76a66253 | j_mayer | float64 d; |
126 | 76a66253 | j_mayer | struct {
|
127 | 76a66253 | j_mayer | uint32_t u[2];
|
128 | 76a66253 | j_mayer | } s; |
129 | 76a66253 | j_mayer | } u; |
130 | 76a66253 | j_mayer | int i;
|
131 | 76a66253 | j_mayer | |
132 | d9bce9d9 | j_mayer | #if defined(WORDS_BIGENDIAN)
|
133 | 76a66253 | j_mayer | #define WORD0 0 |
134 | 76a66253 | j_mayer | #define WORD1 1 |
135 | 76a66253 | j_mayer | #else
|
136 | 76a66253 | j_mayer | #define WORD0 1 |
137 | 76a66253 | j_mayer | #define WORD1 0 |
138 | 76a66253 | j_mayer | #endif
|
139 | 76a66253 | j_mayer | u.s.u[WORD0] = 0;
|
140 | 76a66253 | j_mayer | u.s.u[WORD1] = 0;
|
141 | 76a66253 | j_mayer | for (i = 0; i < 8; i++) |
142 | 76a66253 | j_mayer | u.s.u[WORD1] |= env->fpscr[i] << (4 * i);
|
143 | 76a66253 | j_mayer | FT0 = u.d; |
144 | 76a66253 | j_mayer | } |
145 | 76a66253 | j_mayer | |
146 | 76a66253 | j_mayer | void do_store_fpscr (uint32_t mask)
|
147 | 76a66253 | j_mayer | { |
148 | 76a66253 | j_mayer | /*
|
149 | 76a66253 | j_mayer | * We use only the 32 LSB of the incoming fpr
|
150 | 76a66253 | j_mayer | */
|
151 | 76a66253 | j_mayer | union {
|
152 | 76a66253 | j_mayer | double d;
|
153 | 76a66253 | j_mayer | struct {
|
154 | 76a66253 | j_mayer | uint32_t u[2];
|
155 | 76a66253 | j_mayer | } s; |
156 | 76a66253 | j_mayer | } u; |
157 | 76a66253 | j_mayer | int i, rnd_type;
|
158 | 76a66253 | j_mayer | |
159 | 76a66253 | j_mayer | u.d = FT0; |
160 | 76a66253 | j_mayer | if (mask & 0x80) |
161 | 76a66253 | j_mayer | env->fpscr[0] = (env->fpscr[0] & 0x9) | ((u.s.u[WORD1] >> 28) & ~0x9); |
162 | 76a66253 | j_mayer | for (i = 1; i < 7; i++) { |
163 | 76a66253 | j_mayer | if (mask & (1 << (7 - i))) |
164 | 76a66253 | j_mayer | env->fpscr[i] = (u.s.u[WORD1] >> (4 * (7 - i))) & 0xF; |
165 | 76a66253 | j_mayer | } |
166 | 76a66253 | j_mayer | /* TODO: update FEX & VX */
|
167 | 76a66253 | j_mayer | /* Set rounding mode */
|
168 | 76a66253 | j_mayer | switch (env->fpscr[0] & 0x3) { |
169 | 76a66253 | j_mayer | case 0: |
170 | 76a66253 | j_mayer | /* Best approximation (round to nearest) */
|
171 | 76a66253 | j_mayer | rnd_type = float_round_nearest_even; |
172 | 76a66253 | j_mayer | break;
|
173 | 76a66253 | j_mayer | case 1: |
174 | 76a66253 | j_mayer | /* Smaller magnitude (round toward zero) */
|
175 | 76a66253 | j_mayer | rnd_type = float_round_to_zero; |
176 | 76a66253 | j_mayer | break;
|
177 | 76a66253 | j_mayer | case 2: |
178 | 76a66253 | j_mayer | /* Round toward +infinite */
|
179 | 76a66253 | j_mayer | rnd_type = float_round_up; |
180 | 76a66253 | j_mayer | break;
|
181 | 76a66253 | j_mayer | default:
|
182 | 76a66253 | j_mayer | case 3: |
183 | 76a66253 | j_mayer | /* Round toward -infinite */
|
184 | 76a66253 | j_mayer | rnd_type = float_round_down; |
185 | 76a66253 | j_mayer | break;
|
186 | 76a66253 | j_mayer | } |
187 | 76a66253 | j_mayer | set_float_rounding_mode(rnd_type, &env->fp_status); |
188 | 76a66253 | j_mayer | } |
189 | 76a66253 | j_mayer | |
190 | a496775f | j_mayer | target_ulong ppc_load_dump_spr (int sprn)
|
191 | a496775f | j_mayer | { |
192 | 6b80055d | j_mayer | if (loglevel != 0) { |
193 | a496775f | j_mayer | fprintf(logfile, "Read SPR %d %03x => " ADDRX "\n", |
194 | a496775f | j_mayer | sprn, sprn, env->spr[sprn]); |
195 | a496775f | j_mayer | } |
196 | a496775f | j_mayer | |
197 | a496775f | j_mayer | return env->spr[sprn];
|
198 | a496775f | j_mayer | } |
199 | a496775f | j_mayer | |
200 | a496775f | j_mayer | void ppc_store_dump_spr (int sprn, target_ulong val) |
201 | a496775f | j_mayer | { |
202 | 6b80055d | j_mayer | if (loglevel != 0) { |
203 | a496775f | j_mayer | fprintf(logfile, "Write SPR %d %03x => " ADDRX " <= " ADDRX "\n", |
204 | a496775f | j_mayer | sprn, sprn, env->spr[sprn], val); |
205 | a496775f | j_mayer | } |
206 | a496775f | j_mayer | env->spr[sprn] = val; |
207 | a496775f | j_mayer | } |
208 | a496775f | j_mayer | |
209 | 76a66253 | j_mayer | /*****************************************************************************/
|
210 | fdabc366 | bellard | /* Fixed point operations helpers */
|
211 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
212 | d9bce9d9 | j_mayer | static void add128 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b) |
213 | fdabc366 | bellard | { |
214 | d9bce9d9 | j_mayer | *plow += a; |
215 | d9bce9d9 | j_mayer | /* carry test */
|
216 | d9bce9d9 | j_mayer | if (*plow < a)
|
217 | d9bce9d9 | j_mayer | (*phigh)++; |
218 | d9bce9d9 | j_mayer | *phigh += b; |
219 | fdabc366 | bellard | } |
220 | fdabc366 | bellard | |
221 | d9bce9d9 | j_mayer | static void neg128 (uint64_t *plow, uint64_t *phigh) |
222 | fdabc366 | bellard | { |
223 | d9bce9d9 | j_mayer | *plow = ~ *plow; |
224 | d9bce9d9 | j_mayer | *phigh = ~ *phigh; |
225 | d9bce9d9 | j_mayer | add128(plow, phigh, 1, 0); |
226 | d9bce9d9 | j_mayer | } |
227 | d9bce9d9 | j_mayer | |
228 | d9bce9d9 | j_mayer | static void mul64 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b) |
229 | d9bce9d9 | j_mayer | { |
230 | d9bce9d9 | j_mayer | uint32_t a0, a1, b0, b1; |
231 | d9bce9d9 | j_mayer | uint64_t v; |
232 | d9bce9d9 | j_mayer | |
233 | d9bce9d9 | j_mayer | a0 = a; |
234 | d9bce9d9 | j_mayer | a1 = a >> 32;
|
235 | d9bce9d9 | j_mayer | |
236 | d9bce9d9 | j_mayer | b0 = b; |
237 | d9bce9d9 | j_mayer | b1 = b >> 32;
|
238 | d9bce9d9 | j_mayer | |
239 | d9bce9d9 | j_mayer | v = (uint64_t)a0 * (uint64_t)b0; |
240 | d9bce9d9 | j_mayer | *plow = v; |
241 | d9bce9d9 | j_mayer | *phigh = 0;
|
242 | d9bce9d9 | j_mayer | |
243 | d9bce9d9 | j_mayer | v = (uint64_t)a0 * (uint64_t)b1; |
244 | d9bce9d9 | j_mayer | add128(plow, phigh, v << 32, v >> 32); |
245 | d9bce9d9 | j_mayer | |
246 | d9bce9d9 | j_mayer | v = (uint64_t)a1 * (uint64_t)b0; |
247 | d9bce9d9 | j_mayer | add128(plow, phigh, v << 32, v >> 32); |
248 | d9bce9d9 | j_mayer | |
249 | d9bce9d9 | j_mayer | v = (uint64_t)a1 * (uint64_t)b1; |
250 | d9bce9d9 | j_mayer | *phigh += v; |
251 | d9bce9d9 | j_mayer | #if defined(DEBUG_MULDIV)
|
252 | d9bce9d9 | j_mayer | printf("mul: 0x%016llx * 0x%016llx = 0x%016llx%016llx\n",
|
253 | d9bce9d9 | j_mayer | a, b, *phigh, *plow); |
254 | d9bce9d9 | j_mayer | #endif
|
255 | d9bce9d9 | j_mayer | } |
256 | d9bce9d9 | j_mayer | |
257 | d9bce9d9 | j_mayer | void do_mul64 (uint64_t *plow, uint64_t *phigh)
|
258 | d9bce9d9 | j_mayer | { |
259 | d9bce9d9 | j_mayer | mul64(plow, phigh, T0, T1); |
260 | d9bce9d9 | j_mayer | } |
261 | d9bce9d9 | j_mayer | |
262 | 0487d6a8 | j_mayer | static void imul64 (uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b) |
263 | d9bce9d9 | j_mayer | { |
264 | d9bce9d9 | j_mayer | int sa, sb;
|
265 | d9bce9d9 | j_mayer | sa = (a < 0);
|
266 | d9bce9d9 | j_mayer | if (sa)
|
267 | d9bce9d9 | j_mayer | a = -a; |
268 | d9bce9d9 | j_mayer | sb = (b < 0);
|
269 | d9bce9d9 | j_mayer | if (sb)
|
270 | d9bce9d9 | j_mayer | b = -b; |
271 | d9bce9d9 | j_mayer | mul64(plow, phigh, a, b); |
272 | d9bce9d9 | j_mayer | if (sa ^ sb) {
|
273 | d9bce9d9 | j_mayer | neg128(plow, phigh); |
274 | fdabc366 | bellard | } |
275 | fdabc366 | bellard | } |
276 | fdabc366 | bellard | |
277 | d9bce9d9 | j_mayer | void do_imul64 (uint64_t *plow, uint64_t *phigh)
|
278 | d9bce9d9 | j_mayer | { |
279 | d9bce9d9 | j_mayer | imul64(plow, phigh, T0, T1); |
280 | d9bce9d9 | j_mayer | } |
281 | d9bce9d9 | j_mayer | #endif
|
282 | d9bce9d9 | j_mayer | |
283 | fdabc366 | bellard | void do_adde (void) |
284 | fdabc366 | bellard | { |
285 | fdabc366 | bellard | T2 = T0; |
286 | fdabc366 | bellard | T0 += T1 + xer_ca; |
287 | d9bce9d9 | j_mayer | if (likely(!((uint32_t)T0 < (uint32_t)T2 ||
|
288 | d9bce9d9 | j_mayer | (xer_ca == 1 && (uint32_t)T0 == (uint32_t)T2)))) {
|
289 | fdabc366 | bellard | xer_ca = 0;
|
290 | fdabc366 | bellard | } else {
|
291 | fdabc366 | bellard | xer_ca = 1;
|
292 | fdabc366 | bellard | } |
293 | fdabc366 | bellard | } |
294 | fdabc366 | bellard | |
295 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
296 | d9bce9d9 | j_mayer | void do_adde_64 (void) |
297 | fdabc366 | bellard | { |
298 | fdabc366 | bellard | T2 = T0; |
299 | fdabc366 | bellard | T0 += T1 + xer_ca; |
300 | d9bce9d9 | j_mayer | if (likely(!((uint64_t)T0 < (uint64_t)T2 ||
|
301 | d9bce9d9 | j_mayer | (xer_ca == 1 && (uint64_t)T0 == (uint64_t)T2)))) {
|
302 | fdabc366 | bellard | xer_ca = 0;
|
303 | fdabc366 | bellard | } else {
|
304 | fdabc366 | bellard | xer_ca = 1;
|
305 | fdabc366 | bellard | } |
306 | fdabc366 | bellard | } |
307 | d9bce9d9 | j_mayer | #endif
|
308 | fdabc366 | bellard | |
309 | fdabc366 | bellard | void do_addmeo (void) |
310 | fdabc366 | bellard | { |
311 | fdabc366 | bellard | T1 = T0; |
312 | fdabc366 | bellard | T0 += xer_ca + (-1);
|
313 | d9bce9d9 | j_mayer | if (likely(!((uint32_t)T1 &
|
314 | d9bce9d9 | j_mayer | ((uint32_t)T1 ^ (uint32_t)T0) & (1UL << 31)))) { |
315 | fdabc366 | bellard | xer_ov = 0;
|
316 | fdabc366 | bellard | } else {
|
317 | fdabc366 | bellard | xer_so = 1;
|
318 | fdabc366 | bellard | xer_ov = 1;
|
319 | fdabc366 | bellard | } |
320 | fdabc366 | bellard | if (likely(T1 != 0)) |
321 | fdabc366 | bellard | xer_ca = 1;
|
322 | fdabc366 | bellard | } |
323 | fdabc366 | bellard | |
324 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
325 | d9bce9d9 | j_mayer | void do_addmeo_64 (void) |
326 | fdabc366 | bellard | { |
327 | fdabc366 | bellard | T1 = T0; |
328 | d9bce9d9 | j_mayer | T0 += xer_ca + (-1);
|
329 | d9bce9d9 | j_mayer | if (likely(!((uint64_t)T1 &
|
330 | d9bce9d9 | j_mayer | ((uint64_t)T1 ^ (uint64_t)T0) & (1ULL << 63)))) { |
331 | fdabc366 | bellard | xer_ov = 0;
|
332 | fdabc366 | bellard | } else {
|
333 | fdabc366 | bellard | xer_so = 1;
|
334 | fdabc366 | bellard | xer_ov = 1;
|
335 | fdabc366 | bellard | } |
336 | d9bce9d9 | j_mayer | if (likely(T1 != 0)) |
337 | fdabc366 | bellard | xer_ca = 1;
|
338 | fdabc366 | bellard | } |
339 | d9bce9d9 | j_mayer | #endif
|
340 | fdabc366 | bellard | |
341 | fdabc366 | bellard | void do_divwo (void) |
342 | fdabc366 | bellard | { |
343 | d9bce9d9 | j_mayer | if (likely(!(((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || |
344 | d9bce9d9 | j_mayer | (int32_t)T1 == 0))) {
|
345 | fdabc366 | bellard | xer_ov = 0;
|
346 | d9bce9d9 | j_mayer | T0 = (int32_t)T0 / (int32_t)T1; |
347 | fdabc366 | bellard | } else {
|
348 | fdabc366 | bellard | xer_so = 1;
|
349 | fdabc366 | bellard | xer_ov = 1;
|
350 | fdabc366 | bellard | T0 = (-1) * ((uint32_t)T0 >> 31); |
351 | fdabc366 | bellard | } |
352 | fdabc366 | bellard | } |
353 | fdabc366 | bellard | |
354 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
355 | d9bce9d9 | j_mayer | void do_divdo (void) |
356 | d9bce9d9 | j_mayer | { |
357 | d9bce9d9 | j_mayer | if (likely(!(((int64_t)T0 == INT64_MIN && (int64_t)T1 == -1ULL) || |
358 | d9bce9d9 | j_mayer | (int64_t)T1 == 0))) {
|
359 | d9bce9d9 | j_mayer | xer_ov = 0;
|
360 | d9bce9d9 | j_mayer | T0 = (int64_t)T0 / (int64_t)T1; |
361 | d9bce9d9 | j_mayer | } else {
|
362 | d9bce9d9 | j_mayer | xer_so = 1;
|
363 | d9bce9d9 | j_mayer | xer_ov = 1;
|
364 | d9bce9d9 | j_mayer | T0 = (-1ULL) * ((uint64_t)T0 >> 63); |
365 | d9bce9d9 | j_mayer | } |
366 | d9bce9d9 | j_mayer | } |
367 | d9bce9d9 | j_mayer | #endif
|
368 | d9bce9d9 | j_mayer | |
369 | fdabc366 | bellard | void do_divwuo (void) |
370 | fdabc366 | bellard | { |
371 | fdabc366 | bellard | if (likely((uint32_t)T1 != 0)) { |
372 | fdabc366 | bellard | xer_ov = 0;
|
373 | fdabc366 | bellard | T0 = (uint32_t)T0 / (uint32_t)T1; |
374 | fdabc366 | bellard | } else {
|
375 | fdabc366 | bellard | xer_so = 1;
|
376 | fdabc366 | bellard | xer_ov = 1;
|
377 | fdabc366 | bellard | T0 = 0;
|
378 | fdabc366 | bellard | } |
379 | fdabc366 | bellard | } |
380 | fdabc366 | bellard | |
381 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
382 | d9bce9d9 | j_mayer | void do_divduo (void) |
383 | d9bce9d9 | j_mayer | { |
384 | d9bce9d9 | j_mayer | if (likely((uint64_t)T1 != 0)) { |
385 | d9bce9d9 | j_mayer | xer_ov = 0;
|
386 | d9bce9d9 | j_mayer | T0 = (uint64_t)T0 / (uint64_t)T1; |
387 | d9bce9d9 | j_mayer | } else {
|
388 | d9bce9d9 | j_mayer | xer_so = 1;
|
389 | d9bce9d9 | j_mayer | xer_ov = 1;
|
390 | d9bce9d9 | j_mayer | T0 = 0;
|
391 | d9bce9d9 | j_mayer | } |
392 | d9bce9d9 | j_mayer | } |
393 | d9bce9d9 | j_mayer | #endif
|
394 | d9bce9d9 | j_mayer | |
395 | fdabc366 | bellard | void do_mullwo (void) |
396 | fdabc366 | bellard | { |
397 | d9bce9d9 | j_mayer | int64_t res = (int64_t)T0 * (int64_t)T1; |
398 | fdabc366 | bellard | |
399 | fdabc366 | bellard | if (likely((int32_t)res == res)) {
|
400 | fdabc366 | bellard | xer_ov = 0;
|
401 | fdabc366 | bellard | } else {
|
402 | fdabc366 | bellard | xer_ov = 1;
|
403 | fdabc366 | bellard | xer_so = 1;
|
404 | fdabc366 | bellard | } |
405 | fdabc366 | bellard | T0 = (int32_t)res; |
406 | fdabc366 | bellard | } |
407 | fdabc366 | bellard | |
408 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
409 | d9bce9d9 | j_mayer | void do_mulldo (void) |
410 | fdabc366 | bellard | { |
411 | d9bce9d9 | j_mayer | int64_t th; |
412 | d9bce9d9 | j_mayer | uint64_t tl; |
413 | d9bce9d9 | j_mayer | |
414 | d9bce9d9 | j_mayer | do_imul64(&tl, &th); |
415 | d9bce9d9 | j_mayer | if (likely(th == 0)) { |
416 | fdabc366 | bellard | xer_ov = 0;
|
417 | fdabc366 | bellard | } else {
|
418 | fdabc366 | bellard | xer_ov = 1;
|
419 | fdabc366 | bellard | xer_so = 1;
|
420 | fdabc366 | bellard | } |
421 | d9bce9d9 | j_mayer | T0 = (int64_t)tl; |
422 | fdabc366 | bellard | } |
423 | d9bce9d9 | j_mayer | #endif
|
424 | fdabc366 | bellard | |
425 | d9bce9d9 | j_mayer | void do_nego (void) |
426 | fdabc366 | bellard | { |
427 | d9bce9d9 | j_mayer | if (likely((int32_t)T0 != INT32_MIN)) {
|
428 | fdabc366 | bellard | xer_ov = 0;
|
429 | d9bce9d9 | j_mayer | T0 = -(int32_t)T0; |
430 | fdabc366 | bellard | } else {
|
431 | fdabc366 | bellard | xer_ov = 1;
|
432 | d9bce9d9 | j_mayer | xer_so = 1;
|
433 | fdabc366 | bellard | } |
434 | fdabc366 | bellard | } |
435 | fdabc366 | bellard | |
436 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
437 | d9bce9d9 | j_mayer | void do_nego_64 (void) |
438 | fdabc366 | bellard | { |
439 | d9bce9d9 | j_mayer | if (likely((int64_t)T0 != INT64_MIN)) {
|
440 | fdabc366 | bellard | xer_ov = 0;
|
441 | d9bce9d9 | j_mayer | T0 = -(int64_t)T0; |
442 | fdabc366 | bellard | } else {
|
443 | fdabc366 | bellard | xer_ov = 1;
|
444 | d9bce9d9 | j_mayer | xer_so = 1;
|
445 | fdabc366 | bellard | } |
446 | fdabc366 | bellard | } |
447 | d9bce9d9 | j_mayer | #endif
|
448 | fdabc366 | bellard | |
449 | fdabc366 | bellard | void do_subfe (void) |
450 | fdabc366 | bellard | { |
451 | fdabc366 | bellard | T0 = T1 + ~T0 + xer_ca; |
452 | d9bce9d9 | j_mayer | if (likely((uint32_t)T0 >= (uint32_t)T1 &&
|
453 | d9bce9d9 | j_mayer | (xer_ca == 0 || (uint32_t)T0 != (uint32_t)T1))) {
|
454 | fdabc366 | bellard | xer_ca = 0;
|
455 | fdabc366 | bellard | } else {
|
456 | fdabc366 | bellard | xer_ca = 1;
|
457 | fdabc366 | bellard | } |
458 | fdabc366 | bellard | } |
459 | fdabc366 | bellard | |
460 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
461 | d9bce9d9 | j_mayer | void do_subfe_64 (void) |
462 | fdabc366 | bellard | { |
463 | fdabc366 | bellard | T0 = T1 + ~T0 + xer_ca; |
464 | d9bce9d9 | j_mayer | if (likely((uint64_t)T0 >= (uint64_t)T1 &&
|
465 | d9bce9d9 | j_mayer | (xer_ca == 0 || (uint64_t)T0 != (uint64_t)T1))) {
|
466 | d9bce9d9 | j_mayer | xer_ca = 0;
|
467 | d9bce9d9 | j_mayer | } else {
|
468 | d9bce9d9 | j_mayer | xer_ca = 1;
|
469 | d9bce9d9 | j_mayer | } |
470 | d9bce9d9 | j_mayer | } |
471 | d9bce9d9 | j_mayer | #endif
|
472 | d9bce9d9 | j_mayer | |
473 | d9bce9d9 | j_mayer | void do_subfmeo (void) |
474 | d9bce9d9 | j_mayer | { |
475 | d9bce9d9 | j_mayer | T1 = T0; |
476 | d9bce9d9 | j_mayer | T0 = ~T0 + xer_ca - 1;
|
477 | d9bce9d9 | j_mayer | if (likely(!((uint32_t)~T1 & ((uint32_t)~T1 ^ (uint32_t)T0) &
|
478 | d9bce9d9 | j_mayer | (1UL << 31)))) { |
479 | fdabc366 | bellard | xer_ov = 0;
|
480 | fdabc366 | bellard | } else {
|
481 | fdabc366 | bellard | xer_so = 1;
|
482 | fdabc366 | bellard | xer_ov = 1;
|
483 | fdabc366 | bellard | } |
484 | d9bce9d9 | j_mayer | if (likely((uint32_t)T1 != UINT32_MAX))
|
485 | fdabc366 | bellard | xer_ca = 1;
|
486 | fdabc366 | bellard | } |
487 | fdabc366 | bellard | |
488 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
489 | d9bce9d9 | j_mayer | void do_subfmeo_64 (void) |
490 | fdabc366 | bellard | { |
491 | fdabc366 | bellard | T1 = T0; |
492 | fdabc366 | bellard | T0 = ~T0 + xer_ca - 1;
|
493 | d9bce9d9 | j_mayer | if (likely(!((uint64_t)~T1 & ((uint64_t)~T1 ^ (uint64_t)T0) &
|
494 | d9bce9d9 | j_mayer | (1ULL << 63)))) { |
495 | fdabc366 | bellard | xer_ov = 0;
|
496 | fdabc366 | bellard | } else {
|
497 | fdabc366 | bellard | xer_so = 1;
|
498 | fdabc366 | bellard | xer_ov = 1;
|
499 | fdabc366 | bellard | } |
500 | d9bce9d9 | j_mayer | if (likely((uint64_t)T1 != UINT64_MAX))
|
501 | fdabc366 | bellard | xer_ca = 1;
|
502 | fdabc366 | bellard | } |
503 | d9bce9d9 | j_mayer | #endif
|
504 | fdabc366 | bellard | |
505 | fdabc366 | bellard | void do_subfzeo (void) |
506 | fdabc366 | bellard | { |
507 | fdabc366 | bellard | T1 = T0; |
508 | fdabc366 | bellard | T0 = ~T0 + xer_ca; |
509 | d9bce9d9 | j_mayer | if (likely(!(((uint32_t)~T1 ^ UINT32_MAX) &
|
510 | d9bce9d9 | j_mayer | ((uint32_t)(~T1) ^ (uint32_t)T0) & (1UL << 31)))) { |
511 | fdabc366 | bellard | xer_ov = 0;
|
512 | fdabc366 | bellard | } else {
|
513 | fdabc366 | bellard | xer_ov = 1;
|
514 | fdabc366 | bellard | xer_so = 1;
|
515 | fdabc366 | bellard | } |
516 | d9bce9d9 | j_mayer | if (likely((uint32_t)T0 >= (uint32_t)~T1)) {
|
517 | fdabc366 | bellard | xer_ca = 0;
|
518 | fdabc366 | bellard | } else {
|
519 | fdabc366 | bellard | xer_ca = 1;
|
520 | fdabc366 | bellard | } |
521 | fdabc366 | bellard | } |
522 | fdabc366 | bellard | |
523 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
524 | d9bce9d9 | j_mayer | void do_subfzeo_64 (void) |
525 | d9bce9d9 | j_mayer | { |
526 | d9bce9d9 | j_mayer | T1 = T0; |
527 | d9bce9d9 | j_mayer | T0 = ~T0 + xer_ca; |
528 | d9bce9d9 | j_mayer | if (likely(!(((uint64_t)~T1 ^ UINT64_MAX) &
|
529 | d9bce9d9 | j_mayer | ((uint64_t)(~T1) ^ (uint64_t)T0) & (1ULL << 63)))) { |
530 | d9bce9d9 | j_mayer | xer_ov = 0;
|
531 | d9bce9d9 | j_mayer | } else {
|
532 | d9bce9d9 | j_mayer | xer_ov = 1;
|
533 | d9bce9d9 | j_mayer | xer_so = 1;
|
534 | d9bce9d9 | j_mayer | } |
535 | d9bce9d9 | j_mayer | if (likely((uint64_t)T0 >= (uint64_t)~T1)) {
|
536 | d9bce9d9 | j_mayer | xer_ca = 0;
|
537 | d9bce9d9 | j_mayer | } else {
|
538 | d9bce9d9 | j_mayer | xer_ca = 1;
|
539 | d9bce9d9 | j_mayer | } |
540 | d9bce9d9 | j_mayer | } |
541 | d9bce9d9 | j_mayer | #endif
|
542 | d9bce9d9 | j_mayer | |
543 | 9a64fbe4 | bellard | /* shift right arithmetic helper */
|
544 | 9a64fbe4 | bellard | void do_sraw (void) |
545 | 9a64fbe4 | bellard | { |
546 | 9a64fbe4 | bellard | int32_t ret; |
547 | 9a64fbe4 | bellard | |
548 | fdabc366 | bellard | if (likely(!(T1 & 0x20UL))) { |
549 | d9bce9d9 | j_mayer | if (likely((uint32_t)T1 != 0)) { |
550 | fdabc366 | bellard | ret = (int32_t)T0 >> (T1 & 0x1fUL);
|
551 | fdabc366 | bellard | if (likely(ret >= 0 || ((int32_t)T0 & ((1 << T1) - 1)) == 0)) { |
552 | 76a66253 | j_mayer | xer_ca = 0;
|
553 | fdabc366 | bellard | } else {
|
554 | 76a66253 | j_mayer | xer_ca = 1;
|
555 | fdabc366 | bellard | } |
556 | fdabc366 | bellard | } else {
|
557 | 76a66253 | j_mayer | ret = T0; |
558 | fdabc366 | bellard | xer_ca = 0;
|
559 | fdabc366 | bellard | } |
560 | fdabc366 | bellard | } else {
|
561 | fdabc366 | bellard | ret = (-1) * ((uint32_t)T0 >> 31); |
562 | fdabc366 | bellard | if (likely(ret >= 0 || ((uint32_t)T0 & ~0x80000000UL) == 0)) { |
563 | fdabc366 | bellard | xer_ca = 0;
|
564 | 76a66253 | j_mayer | } else {
|
565 | 9a64fbe4 | bellard | xer_ca = 1;
|
566 | 76a66253 | j_mayer | } |
567 | fdabc366 | bellard | } |
568 | 4b3686fa | bellard | T0 = ret; |
569 | 9a64fbe4 | bellard | } |
570 | 9a64fbe4 | bellard | |
571 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
572 | d9bce9d9 | j_mayer | void do_srad (void) |
573 | d9bce9d9 | j_mayer | { |
574 | d9bce9d9 | j_mayer | int64_t ret; |
575 | d9bce9d9 | j_mayer | |
576 | d9bce9d9 | j_mayer | if (likely(!(T1 & 0x40UL))) { |
577 | d9bce9d9 | j_mayer | if (likely((uint64_t)T1 != 0)) { |
578 | d9bce9d9 | j_mayer | ret = (int64_t)T0 >> (T1 & 0x3FUL);
|
579 | d9bce9d9 | j_mayer | if (likely(ret >= 0 || ((int64_t)T0 & ((1 << T1) - 1)) == 0)) { |
580 | d9bce9d9 | j_mayer | xer_ca = 0;
|
581 | d9bce9d9 | j_mayer | } else {
|
582 | d9bce9d9 | j_mayer | xer_ca = 1;
|
583 | d9bce9d9 | j_mayer | } |
584 | d9bce9d9 | j_mayer | } else {
|
585 | d9bce9d9 | j_mayer | ret = T0; |
586 | d9bce9d9 | j_mayer | xer_ca = 0;
|
587 | d9bce9d9 | j_mayer | } |
588 | d9bce9d9 | j_mayer | } else {
|
589 | d9bce9d9 | j_mayer | ret = (-1) * ((uint64_t)T0 >> 63); |
590 | d9bce9d9 | j_mayer | if (likely(ret >= 0 || ((uint64_t)T0 & ~0x8000000000000000ULL) == 0)) { |
591 | d9bce9d9 | j_mayer | xer_ca = 0;
|
592 | d9bce9d9 | j_mayer | } else {
|
593 | d9bce9d9 | j_mayer | xer_ca = 1;
|
594 | d9bce9d9 | j_mayer | } |
595 | d9bce9d9 | j_mayer | } |
596 | d9bce9d9 | j_mayer | T0 = ret; |
597 | d9bce9d9 | j_mayer | } |
598 | d9bce9d9 | j_mayer | #endif
|
599 | d9bce9d9 | j_mayer | |
600 | d9bce9d9 | j_mayer | static inline int popcnt (uint32_t val) |
601 | d9bce9d9 | j_mayer | { |
602 | d9bce9d9 | j_mayer | int i;
|
603 | d9bce9d9 | j_mayer | |
604 | d9bce9d9 | j_mayer | for (i = 0; val != 0;) |
605 | d9bce9d9 | j_mayer | val = val ^ (val - 1);
|
606 | d9bce9d9 | j_mayer | |
607 | d9bce9d9 | j_mayer | return i;
|
608 | d9bce9d9 | j_mayer | } |
609 | d9bce9d9 | j_mayer | |
610 | d9bce9d9 | j_mayer | void do_popcntb (void) |
611 | d9bce9d9 | j_mayer | { |
612 | d9bce9d9 | j_mayer | uint32_t ret; |
613 | d9bce9d9 | j_mayer | int i;
|
614 | d9bce9d9 | j_mayer | |
615 | d9bce9d9 | j_mayer | ret = 0;
|
616 | d9bce9d9 | j_mayer | for (i = 0; i < 32; i += 8) |
617 | d9bce9d9 | j_mayer | ret |= popcnt((T0 >> i) & 0xFF) << i;
|
618 | d9bce9d9 | j_mayer | T0 = ret; |
619 | d9bce9d9 | j_mayer | } |
620 | d9bce9d9 | j_mayer | |
621 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
622 | d9bce9d9 | j_mayer | void do_popcntb_64 (void) |
623 | d9bce9d9 | j_mayer | { |
624 | d9bce9d9 | j_mayer | uint64_t ret; |
625 | d9bce9d9 | j_mayer | int i;
|
626 | d9bce9d9 | j_mayer | |
627 | d9bce9d9 | j_mayer | ret = 0;
|
628 | d9bce9d9 | j_mayer | for (i = 0; i < 64; i += 8) |
629 | d9bce9d9 | j_mayer | ret |= popcnt((T0 >> i) & 0xFF) << i;
|
630 | d9bce9d9 | j_mayer | T0 = ret; |
631 | d9bce9d9 | j_mayer | } |
632 | d9bce9d9 | j_mayer | #endif
|
633 | d9bce9d9 | j_mayer | |
634 | fdabc366 | bellard | /*****************************************************************************/
|
635 | 9a64fbe4 | bellard | /* Floating point operations helpers */
|
636 | 9a64fbe4 | bellard | void do_fctiw (void) |
637 | 9a64fbe4 | bellard | { |
638 | 9a64fbe4 | bellard | union {
|
639 | 9a64fbe4 | bellard | double d;
|
640 | 9a64fbe4 | bellard | uint64_t i; |
641 | 4ecc3190 | bellard | } p; |
642 | 9a64fbe4 | bellard | |
643 | e864cabd | j_mayer | p.i = float64_to_int32(FT0, &env->fp_status); |
644 | e864cabd | j_mayer | #if USE_PRECISE_EMULATION
|
645 | 4ecc3190 | bellard | /* XXX: higher bits are not supposed to be significant.
|
646 | 76a66253 | j_mayer | * to make tests easier, return the same as a real PowerPC 750 (aka G3)
|
647 | 4ecc3190 | bellard | */
|
648 | 4ecc3190 | bellard | p.i |= 0xFFF80000ULL << 32; |
649 | e864cabd | j_mayer | #endif
|
650 | 4ecc3190 | bellard | FT0 = p.d; |
651 | 9a64fbe4 | bellard | } |
652 | 9a64fbe4 | bellard | |
653 | 9a64fbe4 | bellard | void do_fctiwz (void) |
654 | 9a64fbe4 | bellard | { |
655 | 9a64fbe4 | bellard | union {
|
656 | 9a64fbe4 | bellard | double d;
|
657 | 9a64fbe4 | bellard | uint64_t i; |
658 | 4ecc3190 | bellard | } p; |
659 | 4ecc3190 | bellard | |
660 | e864cabd | j_mayer | p.i = float64_to_int32_round_to_zero(FT0, &env->fp_status); |
661 | e864cabd | j_mayer | #if USE_PRECISE_EMULATION
|
662 | 4ecc3190 | bellard | /* XXX: higher bits are not supposed to be significant.
|
663 | d9bce9d9 | j_mayer | * to make tests easier, return the same as a real PowerPC 750 (aka G3)
|
664 | 4ecc3190 | bellard | */
|
665 | 4ecc3190 | bellard | p.i |= 0xFFF80000ULL << 32; |
666 | e864cabd | j_mayer | #endif
|
667 | 4ecc3190 | bellard | FT0 = p.d; |
668 | 9a64fbe4 | bellard | } |
669 | 9a64fbe4 | bellard | |
670 | 426613db | j_mayer | #if defined(TARGET_PPC64)
|
671 | 426613db | j_mayer | void do_fcfid (void) |
672 | 426613db | j_mayer | { |
673 | 426613db | j_mayer | union {
|
674 | 426613db | j_mayer | double d;
|
675 | 426613db | j_mayer | uint64_t i; |
676 | 426613db | j_mayer | } p; |
677 | 426613db | j_mayer | |
678 | 426613db | j_mayer | p.d = FT0; |
679 | 426613db | j_mayer | FT0 = int64_to_float64(p.i, &env->fp_status); |
680 | 426613db | j_mayer | } |
681 | 426613db | j_mayer | |
682 | 426613db | j_mayer | void do_fctid (void) |
683 | 426613db | j_mayer | { |
684 | 426613db | j_mayer | union {
|
685 | 426613db | j_mayer | double d;
|
686 | 426613db | j_mayer | uint64_t i; |
687 | 426613db | j_mayer | } p; |
688 | 426613db | j_mayer | |
689 | 426613db | j_mayer | p.i = float64_to_int64(FT0, &env->fp_status); |
690 | 426613db | j_mayer | FT0 = p.d; |
691 | 426613db | j_mayer | } |
692 | 426613db | j_mayer | |
693 | 426613db | j_mayer | void do_fctidz (void) |
694 | 426613db | j_mayer | { |
695 | 426613db | j_mayer | union {
|
696 | 426613db | j_mayer | double d;
|
697 | 426613db | j_mayer | uint64_t i; |
698 | 426613db | j_mayer | } p; |
699 | 426613db | j_mayer | |
700 | 426613db | j_mayer | p.i = float64_to_int64_round_to_zero(FT0, &env->fp_status); |
701 | 426613db | j_mayer | FT0 = p.d; |
702 | 426613db | j_mayer | } |
703 | 426613db | j_mayer | |
704 | 426613db | j_mayer | #endif
|
705 | 426613db | j_mayer | |
706 | e864cabd | j_mayer | #if USE_PRECISE_EMULATION
|
707 | e864cabd | j_mayer | void do_fmadd (void) |
708 | e864cabd | j_mayer | { |
709 | e864cabd | j_mayer | #ifdef FLOAT128
|
710 | e864cabd | j_mayer | float128 ft0_128, ft1_128; |
711 | e864cabd | j_mayer | |
712 | e864cabd | j_mayer | ft0_128 = float64_to_float128(FT0, &env->fp_status); |
713 | e864cabd | j_mayer | ft1_128 = float64_to_float128(FT1, &env->fp_status); |
714 | e864cabd | j_mayer | ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status); |
715 | e864cabd | j_mayer | ft1_128 = float64_to_float128(FT2, &env->fp_status); |
716 | e864cabd | j_mayer | ft0_128 = float128_add(ft0_128, ft1_128, &env->fp_status); |
717 | e864cabd | j_mayer | FT0 = float128_to_float64(ft0_128, &env->fp_status); |
718 | e864cabd | j_mayer | #else
|
719 | e864cabd | j_mayer | /* This is OK on x86 hosts */
|
720 | e864cabd | j_mayer | FT0 = (FT0 * FT1) + FT2; |
721 | e864cabd | j_mayer | #endif
|
722 | e864cabd | j_mayer | } |
723 | e864cabd | j_mayer | |
724 | e864cabd | j_mayer | void do_fmsub (void) |
725 | e864cabd | j_mayer | { |
726 | e864cabd | j_mayer | #ifdef FLOAT128
|
727 | e864cabd | j_mayer | float128 ft0_128, ft1_128; |
728 | e864cabd | j_mayer | |
729 | e864cabd | j_mayer | ft0_128 = float64_to_float128(FT0, &env->fp_status); |
730 | e864cabd | j_mayer | ft1_128 = float64_to_float128(FT1, &env->fp_status); |
731 | e864cabd | j_mayer | ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status); |
732 | e864cabd | j_mayer | ft1_128 = float64_to_float128(FT2, &env->fp_status); |
733 | e864cabd | j_mayer | ft0_128 = float128_sub(ft0_128, ft1_128, &env->fp_status); |
734 | e864cabd | j_mayer | FT0 = float128_to_float64(ft0_128, &env->fp_status); |
735 | e864cabd | j_mayer | #else
|
736 | e864cabd | j_mayer | /* This is OK on x86 hosts */
|
737 | e864cabd | j_mayer | FT0 = (FT0 * FT1) - FT2; |
738 | e864cabd | j_mayer | #endif
|
739 | e864cabd | j_mayer | } |
740 | e864cabd | j_mayer | #endif /* USE_PRECISE_EMULATION */ |
741 | e864cabd | j_mayer | |
742 | 4b3686fa | bellard | void do_fnmadd (void) |
743 | 4b3686fa | bellard | { |
744 | e864cabd | j_mayer | #if USE_PRECISE_EMULATION
|
745 | e864cabd | j_mayer | #ifdef FLOAT128
|
746 | e864cabd | j_mayer | float128 ft0_128, ft1_128; |
747 | e864cabd | j_mayer | |
748 | e864cabd | j_mayer | ft0_128 = float64_to_float128(FT0, &env->fp_status); |
749 | e864cabd | j_mayer | ft1_128 = float64_to_float128(FT1, &env->fp_status); |
750 | e864cabd | j_mayer | ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status); |
751 | e864cabd | j_mayer | ft1_128 = float64_to_float128(FT2, &env->fp_status); |
752 | e864cabd | j_mayer | ft0_128 = float128_add(ft0_128, ft1_128, &env->fp_status); |
753 | e864cabd | j_mayer | FT0 = float128_to_float64(ft0_128, &env->fp_status); |
754 | e864cabd | j_mayer | #else
|
755 | e864cabd | j_mayer | /* This is OK on x86 hosts */
|
756 | e864cabd | j_mayer | FT0 = (FT0 * FT1) + FT2; |
757 | e864cabd | j_mayer | #endif
|
758 | e864cabd | j_mayer | #else
|
759 | fdabc366 | bellard | FT0 = float64_mul(FT0, FT1, &env->fp_status); |
760 | fdabc366 | bellard | FT0 = float64_add(FT0, FT2, &env->fp_status); |
761 | e864cabd | j_mayer | #endif
|
762 | fdabc366 | bellard | if (likely(!isnan(FT0)))
|
763 | fdabc366 | bellard | FT0 = float64_chs(FT0); |
764 | 4b3686fa | bellard | } |
765 | 4b3686fa | bellard | |
766 | 4b3686fa | bellard | void do_fnmsub (void) |
767 | 4b3686fa | bellard | { |
768 | e864cabd | j_mayer | #if USE_PRECISE_EMULATION
|
769 | e864cabd | j_mayer | #ifdef FLOAT128
|
770 | e864cabd | j_mayer | float128 ft0_128, ft1_128; |
771 | e864cabd | j_mayer | |
772 | e864cabd | j_mayer | ft0_128 = float64_to_float128(FT0, &env->fp_status); |
773 | e864cabd | j_mayer | ft1_128 = float64_to_float128(FT1, &env->fp_status); |
774 | e864cabd | j_mayer | ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status); |
775 | e864cabd | j_mayer | ft1_128 = float64_to_float128(FT2, &env->fp_status); |
776 | e864cabd | j_mayer | ft0_128 = float128_sub(ft0_128, ft1_128, &env->fp_status); |
777 | e864cabd | j_mayer | FT0 = float128_to_float64(ft0_128, &env->fp_status); |
778 | e864cabd | j_mayer | #else
|
779 | e864cabd | j_mayer | /* This is OK on x86 hosts */
|
780 | e864cabd | j_mayer | FT0 = (FT0 * FT1) - FT2; |
781 | e864cabd | j_mayer | #endif
|
782 | e864cabd | j_mayer | #else
|
783 | fdabc366 | bellard | FT0 = float64_mul(FT0, FT1, &env->fp_status); |
784 | fdabc366 | bellard | FT0 = float64_sub(FT0, FT2, &env->fp_status); |
785 | e864cabd | j_mayer | #endif
|
786 | fdabc366 | bellard | if (likely(!isnan(FT0)))
|
787 | fdabc366 | bellard | FT0 = float64_chs(FT0); |
788 | 1ef59d0a | bellard | } |
789 | 1ef59d0a | bellard | |
790 | 9a64fbe4 | bellard | void do_fsqrt (void) |
791 | 9a64fbe4 | bellard | { |
792 | fdabc366 | bellard | FT0 = float64_sqrt(FT0, &env->fp_status); |
793 | 9a64fbe4 | bellard | } |
794 | 9a64fbe4 | bellard | |
795 | 9a64fbe4 | bellard | void do_fres (void) |
796 | 9a64fbe4 | bellard | { |
797 | 4ecc3190 | bellard | union {
|
798 | 4ecc3190 | bellard | double d;
|
799 | 4ecc3190 | bellard | uint64_t i; |
800 | 4ecc3190 | bellard | } p; |
801 | 4ecc3190 | bellard | |
802 | fdabc366 | bellard | if (likely(isnormal(FT0))) {
|
803 | e864cabd | j_mayer | #if USE_PRECISE_EMULATION
|
804 | e864cabd | j_mayer | FT0 = float64_div(1.0, FT0, &env->fp_status); |
805 | e864cabd | j_mayer | FT0 = float64_to_float32(FT0, &env->fp_status); |
806 | e864cabd | j_mayer | #else
|
807 | 76a66253 | j_mayer | FT0 = float32_div(1.0, FT0, &env->fp_status); |
808 | e864cabd | j_mayer | #endif
|
809 | 4ecc3190 | bellard | } else {
|
810 | 4ecc3190 | bellard | p.d = FT0; |
811 | 4ecc3190 | bellard | if (p.i == 0x8000000000000000ULL) { |
812 | 4ecc3190 | bellard | p.i = 0xFFF0000000000000ULL;
|
813 | 4ecc3190 | bellard | } else if (p.i == 0x0000000000000000ULL) { |
814 | 4ecc3190 | bellard | p.i = 0x7FF0000000000000ULL;
|
815 | 4ecc3190 | bellard | } else if (isnan(FT0)) { |
816 | 4ecc3190 | bellard | p.i = 0x7FF8000000000000ULL;
|
817 | 4ecc3190 | bellard | } else if (FT0 < 0.0) { |
818 | 4ecc3190 | bellard | p.i = 0x8000000000000000ULL;
|
819 | 4ecc3190 | bellard | } else {
|
820 | 4ecc3190 | bellard | p.i = 0x0000000000000000ULL;
|
821 | 4ecc3190 | bellard | } |
822 | 4ecc3190 | bellard | FT0 = p.d; |
823 | 4ecc3190 | bellard | } |
824 | 9a64fbe4 | bellard | } |
825 | 9a64fbe4 | bellard | |
826 | 4ecc3190 | bellard | void do_frsqrte (void) |
827 | 9a64fbe4 | bellard | { |
828 | 4ecc3190 | bellard | union {
|
829 | 4ecc3190 | bellard | double d;
|
830 | 4ecc3190 | bellard | uint64_t i; |
831 | 4ecc3190 | bellard | } p; |
832 | 4ecc3190 | bellard | |
833 | fdabc366 | bellard | if (likely(isnormal(FT0) && FT0 > 0.0)) { |
834 | fdabc366 | bellard | FT0 = float64_sqrt(FT0, &env->fp_status); |
835 | fdabc366 | bellard | FT0 = float32_div(1.0, FT0, &env->fp_status); |
836 | 4ecc3190 | bellard | } else {
|
837 | 4ecc3190 | bellard | p.d = FT0; |
838 | 4ecc3190 | bellard | if (p.i == 0x8000000000000000ULL) { |
839 | 4ecc3190 | bellard | p.i = 0xFFF0000000000000ULL;
|
840 | 4ecc3190 | bellard | } else if (p.i == 0x0000000000000000ULL) { |
841 | 4ecc3190 | bellard | p.i = 0x7FF0000000000000ULL;
|
842 | 4ecc3190 | bellard | } else if (isnan(FT0)) { |
843 | 4ecc3190 | bellard | if (!(p.i & 0x0008000000000000ULL)) |
844 | 4ecc3190 | bellard | p.i |= 0x000FFFFFFFFFFFFFULL;
|
845 | 4ecc3190 | bellard | } else if (FT0 < 0) { |
846 | 4ecc3190 | bellard | p.i = 0x7FF8000000000000ULL;
|
847 | 4ecc3190 | bellard | } else {
|
848 | 4ecc3190 | bellard | p.i = 0x0000000000000000ULL;
|
849 | 4ecc3190 | bellard | } |
850 | 4ecc3190 | bellard | FT0 = p.d; |
851 | 4ecc3190 | bellard | } |
852 | 9a64fbe4 | bellard | } |
853 | 9a64fbe4 | bellard | |
854 | 9a64fbe4 | bellard | void do_fsel (void) |
855 | 9a64fbe4 | bellard | { |
856 | 9a64fbe4 | bellard | if (FT0 >= 0) |
857 | 9a64fbe4 | bellard | FT0 = FT1; |
858 | 4ecc3190 | bellard | else
|
859 | 4ecc3190 | bellard | FT0 = FT2; |
860 | 9a64fbe4 | bellard | } |
861 | 9a64fbe4 | bellard | |
862 | 9a64fbe4 | bellard | void do_fcmpu (void) |
863 | 9a64fbe4 | bellard | { |
864 | fdabc366 | bellard | if (likely(!isnan(FT0) && !isnan(FT1))) {
|
865 | fdabc366 | bellard | if (float64_lt(FT0, FT1, &env->fp_status)) {
|
866 | fdabc366 | bellard | T0 = 0x08UL;
|
867 | fdabc366 | bellard | } else if (!float64_le(FT0, FT1, &env->fp_status)) { |
868 | fdabc366 | bellard | T0 = 0x04UL;
|
869 | fdabc366 | bellard | } else {
|
870 | fdabc366 | bellard | T0 = 0x02UL;
|
871 | fdabc366 | bellard | } |
872 | fdabc366 | bellard | } else {
|
873 | fdabc366 | bellard | T0 = 0x01UL;
|
874 | 9a64fbe4 | bellard | env->fpscr[4] |= 0x1; |
875 | 9a64fbe4 | bellard | env->fpscr[6] |= 0x1; |
876 | 9a64fbe4 | bellard | } |
877 | 4b3686fa | bellard | env->fpscr[3] = T0;
|
878 | 9a64fbe4 | bellard | } |
879 | 9a64fbe4 | bellard | |
880 | 9a64fbe4 | bellard | void do_fcmpo (void) |
881 | 9a64fbe4 | bellard | { |
882 | 9a64fbe4 | bellard | env->fpscr[4] &= ~0x1; |
883 | fdabc366 | bellard | if (likely(!isnan(FT0) && !isnan(FT1))) {
|
884 | fdabc366 | bellard | if (float64_lt(FT0, FT1, &env->fp_status)) {
|
885 | fdabc366 | bellard | T0 = 0x08UL;
|
886 | fdabc366 | bellard | } else if (!float64_le(FT0, FT1, &env->fp_status)) { |
887 | fdabc366 | bellard | T0 = 0x04UL;
|
888 | fdabc366 | bellard | } else {
|
889 | fdabc366 | bellard | T0 = 0x02UL;
|
890 | fdabc366 | bellard | } |
891 | fdabc366 | bellard | } else {
|
892 | fdabc366 | bellard | T0 = 0x01UL;
|
893 | 9a64fbe4 | bellard | env->fpscr[4] |= 0x1; |
894 | 76a66253 | j_mayer | if (!float64_is_signaling_nan(FT0) || !float64_is_signaling_nan(FT1)) {
|
895 | 76a66253 | j_mayer | /* Quiet NaN case */
|
896 | 9a64fbe4 | bellard | env->fpscr[6] |= 0x1; |
897 | 9a64fbe4 | bellard | if (!(env->fpscr[1] & 0x8)) |
898 | 9a64fbe4 | bellard | env->fpscr[4] |= 0x8; |
899 | 9a64fbe4 | bellard | } else {
|
900 | 9a64fbe4 | bellard | env->fpscr[4] |= 0x8; |
901 | 9a64fbe4 | bellard | } |
902 | 9a64fbe4 | bellard | } |
903 | 4b3686fa | bellard | env->fpscr[3] = T0;
|
904 | 9a64fbe4 | bellard | } |
905 | 9a64fbe4 | bellard | |
906 | 76a66253 | j_mayer | #if !defined (CONFIG_USER_ONLY)
|
907 | 6b80055d | j_mayer | void cpu_dump_rfi (target_ulong RA, target_ulong msr);
|
908 | fdabc366 | bellard | void do_rfi (void) |
909 | 9a64fbe4 | bellard | { |
910 | 426613db | j_mayer | #if defined(TARGET_PPC64)
|
911 | a42bd6cc | j_mayer | if (env->spr[SPR_SRR1] & (1ULL << MSR_SF)) { |
912 | a42bd6cc | j_mayer | env->nip = (uint64_t)(env->spr[SPR_SRR0] & ~0x00000003);
|
913 | a42bd6cc | j_mayer | do_store_msr(env, (uint64_t)(env->spr[SPR_SRR1] & ~0xFFFF0000UL));
|
914 | a42bd6cc | j_mayer | } else {
|
915 | a42bd6cc | j_mayer | env->nip = (uint32_t)(env->spr[SPR_SRR0] & ~0x00000003);
|
916 | a42bd6cc | j_mayer | ppc_store_msr_32(env, (uint32_t)(env->spr[SPR_SRR1] & ~0xFFFF0000UL));
|
917 | a42bd6cc | j_mayer | } |
918 | 426613db | j_mayer | #else
|
919 | a42bd6cc | j_mayer | env->nip = (uint32_t)(env->spr[SPR_SRR0] & ~0x00000003);
|
920 | a42bd6cc | j_mayer | do_store_msr(env, (uint32_t)(env->spr[SPR_SRR1] & ~0xFFFF0000UL));
|
921 | 426613db | j_mayer | #endif
|
922 | fdabc366 | bellard | #if defined (DEBUG_OP)
|
923 | 6b80055d | j_mayer | cpu_dump_rfi(env->nip, do_load_msr(env)); |
924 | fdabc366 | bellard | #endif
|
925 | fdabc366 | bellard | env->interrupt_request |= CPU_INTERRUPT_EXITTB; |
926 | 9a64fbe4 | bellard | } |
927 | d9bce9d9 | j_mayer | |
928 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
929 | 426613db | j_mayer | void do_rfid (void) |
930 | 426613db | j_mayer | { |
931 | a42bd6cc | j_mayer | if (env->spr[SPR_SRR1] & (1ULL << MSR_SF)) { |
932 | a42bd6cc | j_mayer | env->nip = (uint64_t)(env->spr[SPR_SRR0] & ~0x00000003);
|
933 | a42bd6cc | j_mayer | do_store_msr(env, (uint64_t)(env->spr[SPR_SRR1] & ~0xFFFF0000UL));
|
934 | a42bd6cc | j_mayer | } else {
|
935 | a42bd6cc | j_mayer | env->nip = (uint32_t)(env->spr[SPR_SRR0] & ~0x00000003);
|
936 | a42bd6cc | j_mayer | do_store_msr(env, (uint32_t)(env->spr[SPR_SRR1] & ~0xFFFF0000UL));
|
937 | a42bd6cc | j_mayer | } |
938 | d9bce9d9 | j_mayer | #if defined (DEBUG_OP)
|
939 | 6b80055d | j_mayer | cpu_dump_rfi(env->nip, do_load_msr(env)); |
940 | d9bce9d9 | j_mayer | #endif
|
941 | d9bce9d9 | j_mayer | env->interrupt_request |= CPU_INTERRUPT_EXITTB; |
942 | d9bce9d9 | j_mayer | } |
943 | d9bce9d9 | j_mayer | #endif
|
944 | 76a66253 | j_mayer | #endif
|
945 | 9a64fbe4 | bellard | |
946 | 76a66253 | j_mayer | void do_tw (int flags) |
947 | 9a64fbe4 | bellard | { |
948 | d9bce9d9 | j_mayer | if (!likely(!(((int32_t)T0 < (int32_t)T1 && (flags & 0x10)) || |
949 | d9bce9d9 | j_mayer | ((int32_t)T0 > (int32_t)T1 && (flags & 0x08)) ||
|
950 | d9bce9d9 | j_mayer | ((int32_t)T0 == (int32_t)T1 && (flags & 0x04)) ||
|
951 | d9bce9d9 | j_mayer | ((uint32_t)T0 < (uint32_t)T1 && (flags & 0x02)) ||
|
952 | a42bd6cc | j_mayer | ((uint32_t)T0 > (uint32_t)T1 && (flags & 0x01))))) {
|
953 | fdabc366 | bellard | do_raise_exception_err(EXCP_PROGRAM, EXCP_TRAP); |
954 | a42bd6cc | j_mayer | } |
955 | 9a64fbe4 | bellard | } |
956 | 9a64fbe4 | bellard | |
957 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
958 | d9bce9d9 | j_mayer | void do_td (int flags) |
959 | d9bce9d9 | j_mayer | { |
960 | d9bce9d9 | j_mayer | if (!likely(!(((int64_t)T0 < (int64_t)T1 && (flags & 0x10)) || |
961 | d9bce9d9 | j_mayer | ((int64_t)T0 > (int64_t)T1 && (flags & 0x08)) ||
|
962 | d9bce9d9 | j_mayer | ((int64_t)T0 == (int64_t)T1 && (flags & 0x04)) ||
|
963 | d9bce9d9 | j_mayer | ((uint64_t)T0 < (uint64_t)T1 && (flags & 0x02)) ||
|
964 | d9bce9d9 | j_mayer | ((uint64_t)T0 > (uint64_t)T1 && (flags & 0x01)))))
|
965 | d9bce9d9 | j_mayer | do_raise_exception_err(EXCP_PROGRAM, EXCP_TRAP); |
966 | d9bce9d9 | j_mayer | } |
967 | d9bce9d9 | j_mayer | #endif
|
968 | d9bce9d9 | j_mayer | |
969 | fdabc366 | bellard | /*****************************************************************************/
|
970 | 76a66253 | j_mayer | /* PowerPC 601 specific instructions (POWER bridge) */
|
971 | 76a66253 | j_mayer | void do_POWER_abso (void) |
972 | 9a64fbe4 | bellard | { |
973 | d9bce9d9 | j_mayer | if ((uint32_t)T0 == INT32_MIN) {
|
974 | 76a66253 | j_mayer | T0 = INT32_MAX; |
975 | 76a66253 | j_mayer | xer_ov = 1;
|
976 | 76a66253 | j_mayer | xer_so = 1;
|
977 | 76a66253 | j_mayer | } else {
|
978 | 76a66253 | j_mayer | T0 = -T0; |
979 | 76a66253 | j_mayer | xer_ov = 0;
|
980 | 76a66253 | j_mayer | } |
981 | 9a64fbe4 | bellard | } |
982 | 9a64fbe4 | bellard | |
983 | 76a66253 | j_mayer | void do_POWER_clcs (void) |
984 | 9a64fbe4 | bellard | { |
985 | 76a66253 | j_mayer | switch (T0) {
|
986 | 76a66253 | j_mayer | case 0x0CUL: |
987 | 76a66253 | j_mayer | /* Instruction cache line size */
|
988 | 76a66253 | j_mayer | T0 = ICACHE_LINE_SIZE; |
989 | 76a66253 | j_mayer | break;
|
990 | 76a66253 | j_mayer | case 0x0DUL: |
991 | 76a66253 | j_mayer | /* Data cache line size */
|
992 | 76a66253 | j_mayer | T0 = DCACHE_LINE_SIZE; |
993 | 76a66253 | j_mayer | break;
|
994 | 76a66253 | j_mayer | case 0x0EUL: |
995 | 76a66253 | j_mayer | /* Minimum cache line size */
|
996 | 76a66253 | j_mayer | T0 = ICACHE_LINE_SIZE < DCACHE_LINE_SIZE ? |
997 | 76a66253 | j_mayer | ICACHE_LINE_SIZE : DCACHE_LINE_SIZE; |
998 | 76a66253 | j_mayer | break;
|
999 | 76a66253 | j_mayer | case 0x0FUL: |
1000 | 76a66253 | j_mayer | /* Maximum cache line size */
|
1001 | 76a66253 | j_mayer | T0 = ICACHE_LINE_SIZE > DCACHE_LINE_SIZE ? |
1002 | 76a66253 | j_mayer | ICACHE_LINE_SIZE : DCACHE_LINE_SIZE; |
1003 | 76a66253 | j_mayer | break;
|
1004 | 76a66253 | j_mayer | default:
|
1005 | 76a66253 | j_mayer | /* Undefined */
|
1006 | 76a66253 | j_mayer | break;
|
1007 | 76a66253 | j_mayer | } |
1008 | 76a66253 | j_mayer | } |
1009 | 76a66253 | j_mayer | |
1010 | 76a66253 | j_mayer | void do_POWER_div (void) |
1011 | 76a66253 | j_mayer | { |
1012 | 76a66253 | j_mayer | uint64_t tmp; |
1013 | 76a66253 | j_mayer | |
1014 | d9bce9d9 | j_mayer | if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) { |
1015 | 76a66253 | j_mayer | T0 = (long)((-1) * (T0 >> 31)); |
1016 | 76a66253 | j_mayer | env->spr[SPR_MQ] = 0;
|
1017 | 76a66253 | j_mayer | } else {
|
1018 | 76a66253 | j_mayer | tmp = ((uint64_t)T0 << 32) | env->spr[SPR_MQ];
|
1019 | 76a66253 | j_mayer | env->spr[SPR_MQ] = tmp % T1; |
1020 | d9bce9d9 | j_mayer | T0 = tmp / (int32_t)T1; |
1021 | 76a66253 | j_mayer | } |
1022 | 76a66253 | j_mayer | } |
1023 | 76a66253 | j_mayer | |
1024 | 76a66253 | j_mayer | void do_POWER_divo (void) |
1025 | 76a66253 | j_mayer | { |
1026 | 76a66253 | j_mayer | int64_t tmp; |
1027 | 76a66253 | j_mayer | |
1028 | d9bce9d9 | j_mayer | if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) { |
1029 | 76a66253 | j_mayer | T0 = (long)((-1) * (T0 >> 31)); |
1030 | 76a66253 | j_mayer | env->spr[SPR_MQ] = 0;
|
1031 | 76a66253 | j_mayer | xer_ov = 1;
|
1032 | 76a66253 | j_mayer | xer_so = 1;
|
1033 | 76a66253 | j_mayer | } else {
|
1034 | 76a66253 | j_mayer | tmp = ((uint64_t)T0 << 32) | env->spr[SPR_MQ];
|
1035 | 76a66253 | j_mayer | env->spr[SPR_MQ] = tmp % T1; |
1036 | d9bce9d9 | j_mayer | tmp /= (int32_t)T1; |
1037 | 76a66253 | j_mayer | if (tmp > (int64_t)INT32_MAX || tmp < (int64_t)INT32_MIN) {
|
1038 | 76a66253 | j_mayer | xer_ov = 1;
|
1039 | 76a66253 | j_mayer | xer_so = 1;
|
1040 | 76a66253 | j_mayer | } else {
|
1041 | 76a66253 | j_mayer | xer_ov = 0;
|
1042 | 76a66253 | j_mayer | } |
1043 | 76a66253 | j_mayer | T0 = tmp; |
1044 | 76a66253 | j_mayer | } |
1045 | 76a66253 | j_mayer | } |
1046 | 76a66253 | j_mayer | |
1047 | 76a66253 | j_mayer | void do_POWER_divs (void) |
1048 | 76a66253 | j_mayer | { |
1049 | d9bce9d9 | j_mayer | if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) { |
1050 | 76a66253 | j_mayer | T0 = (long)((-1) * (T0 >> 31)); |
1051 | 76a66253 | j_mayer | env->spr[SPR_MQ] = 0;
|
1052 | 76a66253 | j_mayer | } else {
|
1053 | 76a66253 | j_mayer | env->spr[SPR_MQ] = T0 % T1; |
1054 | d9bce9d9 | j_mayer | T0 = (int32_t)T0 / (int32_t)T1; |
1055 | 76a66253 | j_mayer | } |
1056 | 76a66253 | j_mayer | } |
1057 | 76a66253 | j_mayer | |
1058 | 76a66253 | j_mayer | void do_POWER_divso (void) |
1059 | 76a66253 | j_mayer | { |
1060 | d9bce9d9 | j_mayer | if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) { |
1061 | 76a66253 | j_mayer | T0 = (long)((-1) * (T0 >> 31)); |
1062 | 76a66253 | j_mayer | env->spr[SPR_MQ] = 0;
|
1063 | 76a66253 | j_mayer | xer_ov = 1;
|
1064 | 76a66253 | j_mayer | xer_so = 1;
|
1065 | 76a66253 | j_mayer | } else {
|
1066 | d9bce9d9 | j_mayer | T0 = (int32_t)T0 / (int32_t)T1; |
1067 | d9bce9d9 | j_mayer | env->spr[SPR_MQ] = (int32_t)T0 % (int32_t)T1; |
1068 | 76a66253 | j_mayer | xer_ov = 0;
|
1069 | 76a66253 | j_mayer | } |
1070 | 76a66253 | j_mayer | } |
1071 | 76a66253 | j_mayer | |
1072 | 76a66253 | j_mayer | void do_POWER_dozo (void) |
1073 | 76a66253 | j_mayer | { |
1074 | d9bce9d9 | j_mayer | if ((int32_t)T1 > (int32_t)T0) {
|
1075 | 76a66253 | j_mayer | T2 = T0; |
1076 | 76a66253 | j_mayer | T0 = T1 - T0; |
1077 | d9bce9d9 | j_mayer | if (((uint32_t)(~T2) ^ (uint32_t)T1 ^ UINT32_MAX) &
|
1078 | d9bce9d9 | j_mayer | ((uint32_t)(~T2) ^ (uint32_t)T0) & (1UL << 31)) { |
1079 | 76a66253 | j_mayer | xer_so = 1;
|
1080 | 76a66253 | j_mayer | xer_ov = 1;
|
1081 | 76a66253 | j_mayer | } else {
|
1082 | 76a66253 | j_mayer | xer_ov = 0;
|
1083 | 76a66253 | j_mayer | } |
1084 | 76a66253 | j_mayer | } else {
|
1085 | 76a66253 | j_mayer | T0 = 0;
|
1086 | 76a66253 | j_mayer | xer_ov = 0;
|
1087 | 76a66253 | j_mayer | } |
1088 | 76a66253 | j_mayer | } |
1089 | 76a66253 | j_mayer | |
1090 | 76a66253 | j_mayer | void do_POWER_maskg (void) |
1091 | 76a66253 | j_mayer | { |
1092 | 76a66253 | j_mayer | uint32_t ret; |
1093 | 76a66253 | j_mayer | |
1094 | d9bce9d9 | j_mayer | if ((uint32_t)T0 == (uint32_t)(T1 + 1)) { |
1095 | 76a66253 | j_mayer | ret = -1;
|
1096 | 76a66253 | j_mayer | } else {
|
1097 | d9bce9d9 | j_mayer | ret = (((uint32_t)(-1)) >> ((uint32_t)T0)) ^
|
1098 | d9bce9d9 | j_mayer | (((uint32_t)(-1) >> ((uint32_t)T1)) >> 1); |
1099 | d9bce9d9 | j_mayer | if ((uint32_t)T0 > (uint32_t)T1)
|
1100 | 76a66253 | j_mayer | ret = ~ret; |
1101 | 76a66253 | j_mayer | } |
1102 | 76a66253 | j_mayer | T0 = ret; |
1103 | 76a66253 | j_mayer | } |
1104 | 76a66253 | j_mayer | |
1105 | 76a66253 | j_mayer | void do_POWER_mulo (void) |
1106 | 76a66253 | j_mayer | { |
1107 | 76a66253 | j_mayer | uint64_t tmp; |
1108 | 76a66253 | j_mayer | |
1109 | 76a66253 | j_mayer | tmp = (uint64_t)T0 * (uint64_t)T1; |
1110 | 76a66253 | j_mayer | env->spr[SPR_MQ] = tmp >> 32;
|
1111 | 76a66253 | j_mayer | T0 = tmp; |
1112 | 76a66253 | j_mayer | if (tmp >> 32 != ((uint64_t)T0 >> 16) * ((uint64_t)T1 >> 16)) { |
1113 | 76a66253 | j_mayer | xer_ov = 1;
|
1114 | 76a66253 | j_mayer | xer_so = 1;
|
1115 | 76a66253 | j_mayer | } else {
|
1116 | 76a66253 | j_mayer | xer_ov = 0;
|
1117 | 76a66253 | j_mayer | } |
1118 | 76a66253 | j_mayer | } |
1119 | 76a66253 | j_mayer | |
1120 | 76a66253 | j_mayer | #if !defined (CONFIG_USER_ONLY)
|
1121 | 76a66253 | j_mayer | void do_POWER_rac (void) |
1122 | 76a66253 | j_mayer | { |
1123 | 76a66253 | j_mayer | #if 0
|
1124 | 76a66253 | j_mayer | mmu_ctx_t ctx;
|
1125 | 76a66253 | j_mayer | |
1126 | 76a66253 | j_mayer | /* We don't have to generate many instances of this instruction,
|
1127 | 76a66253 | j_mayer | * as rac is supervisor only.
|
1128 | 76a66253 | j_mayer | */
|
1129 | 76a66253 | j_mayer | if (get_physical_address(env, &ctx, T0, 0, ACCESS_INT, 1) == 0)
|
1130 | 76a66253 | j_mayer | T0 = ctx.raddr;
|
1131 | 76a66253 | j_mayer | #endif
|
1132 | 76a66253 | j_mayer | } |
1133 | 76a66253 | j_mayer | |
1134 | 76a66253 | j_mayer | void do_POWER_rfsvc (void) |
1135 | 76a66253 | j_mayer | { |
1136 | 76a66253 | j_mayer | env->nip = env->lr & ~0x00000003UL;
|
1137 | 76a66253 | j_mayer | T0 = env->ctr & 0x0000FFFFUL;
|
1138 | 76a66253 | j_mayer | do_store_msr(env, T0); |
1139 | 76a66253 | j_mayer | #if defined (DEBUG_OP)
|
1140 | 6b80055d | j_mayer | cpu_dump_rfi(env->nip, do_load_msr(env)); |
1141 | 76a66253 | j_mayer | #endif
|
1142 | 76a66253 | j_mayer | env->interrupt_request |= CPU_INTERRUPT_EXITTB; |
1143 | 76a66253 | j_mayer | } |
1144 | 76a66253 | j_mayer | |
1145 | 76a66253 | j_mayer | /* PowerPC 601 BAT management helper */
|
1146 | 76a66253 | j_mayer | void do_store_601_batu (int nr) |
1147 | 76a66253 | j_mayer | { |
1148 | d9bce9d9 | j_mayer | do_store_ibatu(env, nr, (uint32_t)T0); |
1149 | 76a66253 | j_mayer | env->DBAT[0][nr] = env->IBAT[0][nr]; |
1150 | 76a66253 | j_mayer | env->DBAT[1][nr] = env->IBAT[1][nr]; |
1151 | 76a66253 | j_mayer | } |
1152 | 76a66253 | j_mayer | #endif
|
1153 | 76a66253 | j_mayer | |
1154 | 76a66253 | j_mayer | /*****************************************************************************/
|
1155 | 76a66253 | j_mayer | /* 602 specific instructions */
|
1156 | 76a66253 | j_mayer | /* mfrom is the most crazy instruction ever seen, imho ! */
|
1157 | 76a66253 | j_mayer | /* Real implementation uses a ROM table. Do the same */
|
1158 | 76a66253 | j_mayer | #define USE_MFROM_ROM_TABLE
|
1159 | 76a66253 | j_mayer | void do_op_602_mfrom (void) |
1160 | 76a66253 | j_mayer | { |
1161 | 76a66253 | j_mayer | if (likely(T0 < 602)) { |
1162 | d9bce9d9 | j_mayer | #if defined(USE_MFROM_ROM_TABLE)
|
1163 | 76a66253 | j_mayer | #include "mfrom_table.c" |
1164 | 76a66253 | j_mayer | T0 = mfrom_ROM_table[T0]; |
1165 | fdabc366 | bellard | #else
|
1166 | 76a66253 | j_mayer | double d;
|
1167 | 76a66253 | j_mayer | /* Extremly decomposed:
|
1168 | 76a66253 | j_mayer | * -T0 / 256
|
1169 | 76a66253 | j_mayer | * T0 = 256 * log10(10 + 1.0) + 0.5
|
1170 | 76a66253 | j_mayer | */
|
1171 | 76a66253 | j_mayer | d = T0; |
1172 | 76a66253 | j_mayer | d = float64_div(d, 256, &env->fp_status);
|
1173 | 76a66253 | j_mayer | d = float64_chs(d); |
1174 | 76a66253 | j_mayer | d = exp10(d); // XXX: use float emulation function
|
1175 | 76a66253 | j_mayer | d = float64_add(d, 1.0, &env->fp_status); |
1176 | 76a66253 | j_mayer | d = log10(d); // XXX: use float emulation function
|
1177 | 76a66253 | j_mayer | d = float64_mul(d, 256, &env->fp_status);
|
1178 | 76a66253 | j_mayer | d = float64_add(d, 0.5, &env->fp_status); |
1179 | 76a66253 | j_mayer | T0 = float64_round_to_int(d, &env->fp_status); |
1180 | fdabc366 | bellard | #endif
|
1181 | 76a66253 | j_mayer | } else {
|
1182 | 76a66253 | j_mayer | T0 = 0;
|
1183 | 76a66253 | j_mayer | } |
1184 | 76a66253 | j_mayer | } |
1185 | 76a66253 | j_mayer | |
1186 | 76a66253 | j_mayer | /*****************************************************************************/
|
1187 | 76a66253 | j_mayer | /* Embedded PowerPC specific helpers */
|
1188 | 76a66253 | j_mayer | void do_405_check_ov (void) |
1189 | 76a66253 | j_mayer | { |
1190 | d9bce9d9 | j_mayer | if (likely((((uint32_t)T1 ^ (uint32_t)T2) >> 31) || |
1191 | d9bce9d9 | j_mayer | !(((uint32_t)T0 ^ (uint32_t)T2) >> 31))) {
|
1192 | 76a66253 | j_mayer | xer_ov = 0;
|
1193 | 76a66253 | j_mayer | } else {
|
1194 | 76a66253 | j_mayer | xer_ov = 1;
|
1195 | 76a66253 | j_mayer | xer_so = 1;
|
1196 | 76a66253 | j_mayer | } |
1197 | 76a66253 | j_mayer | } |
1198 | 76a66253 | j_mayer | |
1199 | 76a66253 | j_mayer | void do_405_check_sat (void) |
1200 | 76a66253 | j_mayer | { |
1201 | d9bce9d9 | j_mayer | if (!likely((((uint32_t)T1 ^ (uint32_t)T2) >> 31) || |
1202 | d9bce9d9 | j_mayer | !(((uint32_t)T0 ^ (uint32_t)T2) >> 31))) {
|
1203 | 76a66253 | j_mayer | /* Saturate result */
|
1204 | 76a66253 | j_mayer | if (T2 >> 31) { |
1205 | 76a66253 | j_mayer | T0 = INT32_MIN; |
1206 | 76a66253 | j_mayer | } else {
|
1207 | 76a66253 | j_mayer | T0 = INT32_MAX; |
1208 | 76a66253 | j_mayer | } |
1209 | 76a66253 | j_mayer | } |
1210 | 76a66253 | j_mayer | } |
1211 | 76a66253 | j_mayer | |
1212 | 76a66253 | j_mayer | #if !defined(CONFIG_USER_ONLY)
|
1213 | a42bd6cc | j_mayer | void do_40x_rfci (void) |
1214 | 76a66253 | j_mayer | { |
1215 | 76a66253 | j_mayer | env->nip = env->spr[SPR_40x_SRR2]; |
1216 | a42bd6cc | j_mayer | do_store_msr(env, env->spr[SPR_40x_SRR3] & ~0xFFFF0000);
|
1217 | a42bd6cc | j_mayer | #if defined (DEBUG_OP)
|
1218 | 6b80055d | j_mayer | cpu_dump_rfi(env->nip, do_load_msr(env)); |
1219 | a42bd6cc | j_mayer | #endif
|
1220 | a42bd6cc | j_mayer | env->interrupt_request = CPU_INTERRUPT_EXITTB; |
1221 | a42bd6cc | j_mayer | } |
1222 | a42bd6cc | j_mayer | |
1223 | a42bd6cc | j_mayer | void do_rfci (void) |
1224 | a42bd6cc | j_mayer | { |
1225 | a42bd6cc | j_mayer | #if defined(TARGET_PPC64)
|
1226 | a42bd6cc | j_mayer | if (env->spr[SPR_BOOKE_CSRR1] & (1 << MSR_CM)) { |
1227 | a42bd6cc | j_mayer | env->nip = (uint64_t)env->spr[SPR_BOOKE_CSRR0]; |
1228 | a42bd6cc | j_mayer | } else
|
1229 | a42bd6cc | j_mayer | #endif
|
1230 | a42bd6cc | j_mayer | { |
1231 | a42bd6cc | j_mayer | env->nip = (uint32_t)env->spr[SPR_BOOKE_CSRR0]; |
1232 | a42bd6cc | j_mayer | } |
1233 | a42bd6cc | j_mayer | do_store_msr(env, (uint32_t)env->spr[SPR_BOOKE_CSRR1] & ~0x3FFF0000);
|
1234 | a42bd6cc | j_mayer | #if defined (DEBUG_OP)
|
1235 | 6b80055d | j_mayer | cpu_dump_rfi(env->nip, do_load_msr(env)); |
1236 | a42bd6cc | j_mayer | #endif
|
1237 | a42bd6cc | j_mayer | env->interrupt_request = CPU_INTERRUPT_EXITTB; |
1238 | a42bd6cc | j_mayer | } |
1239 | a42bd6cc | j_mayer | |
1240 | a42bd6cc | j_mayer | void do_rfdi (void) |
1241 | a42bd6cc | j_mayer | { |
1242 | a42bd6cc | j_mayer | #if defined(TARGET_PPC64)
|
1243 | a42bd6cc | j_mayer | if (env->spr[SPR_BOOKE_DSRR1] & (1 << MSR_CM)) { |
1244 | a42bd6cc | j_mayer | env->nip = (uint64_t)env->spr[SPR_BOOKE_DSRR0]; |
1245 | a42bd6cc | j_mayer | } else
|
1246 | a42bd6cc | j_mayer | #endif
|
1247 | a42bd6cc | j_mayer | { |
1248 | a42bd6cc | j_mayer | env->nip = (uint32_t)env->spr[SPR_BOOKE_DSRR0]; |
1249 | a42bd6cc | j_mayer | } |
1250 | a42bd6cc | j_mayer | do_store_msr(env, (uint32_t)env->spr[SPR_BOOKE_DSRR1] & ~0x3FFF0000);
|
1251 | a42bd6cc | j_mayer | #if defined (DEBUG_OP)
|
1252 | 6b80055d | j_mayer | cpu_dump_rfi(env->nip, do_load_msr(env)); |
1253 | a42bd6cc | j_mayer | #endif
|
1254 | a42bd6cc | j_mayer | env->interrupt_request = CPU_INTERRUPT_EXITTB; |
1255 | a42bd6cc | j_mayer | } |
1256 | a42bd6cc | j_mayer | |
1257 | a42bd6cc | j_mayer | void do_rfmci (void) |
1258 | a42bd6cc | j_mayer | { |
1259 | a42bd6cc | j_mayer | #if defined(TARGET_PPC64)
|
1260 | a42bd6cc | j_mayer | if (env->spr[SPR_BOOKE_MCSRR1] & (1 << MSR_CM)) { |
1261 | a42bd6cc | j_mayer | env->nip = (uint64_t)env->spr[SPR_BOOKE_MCSRR0]; |
1262 | a42bd6cc | j_mayer | } else
|
1263 | a42bd6cc | j_mayer | #endif
|
1264 | a42bd6cc | j_mayer | { |
1265 | a42bd6cc | j_mayer | env->nip = (uint32_t)env->spr[SPR_BOOKE_MCSRR0]; |
1266 | a42bd6cc | j_mayer | } |
1267 | a42bd6cc | j_mayer | do_store_msr(env, (uint32_t)env->spr[SPR_BOOKE_MCSRR1] & ~0x3FFF0000);
|
1268 | 76a66253 | j_mayer | #if defined (DEBUG_OP)
|
1269 | 6b80055d | j_mayer | cpu_dump_rfi(env->nip, do_load_msr(env)); |
1270 | 76a66253 | j_mayer | #endif
|
1271 | 76a66253 | j_mayer | env->interrupt_request = CPU_INTERRUPT_EXITTB; |
1272 | 76a66253 | j_mayer | } |
1273 | 76a66253 | j_mayer | |
1274 | a42bd6cc | j_mayer | void do_load_dcr (void) |
1275 | 76a66253 | j_mayer | { |
1276 | 76a66253 | j_mayer | target_ulong val; |
1277 | 76a66253 | j_mayer | |
1278 | 2e719ba3 | j_mayer | if (unlikely(env->dcr_env == NULL)) { |
1279 | 6b80055d | j_mayer | if (loglevel != 0) { |
1280 | a496775f | j_mayer | fprintf(logfile, "No DCR environment\n");
|
1281 | a496775f | j_mayer | } |
1282 | 76a66253 | j_mayer | do_raise_exception_err(EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_INVAL); |
1283 | 2e719ba3 | j_mayer | } else if (unlikely(ppc_dcr_read(env->dcr_env, T0, &val) != 0)) { |
1284 | 6b80055d | j_mayer | if (loglevel != 0) { |
1285 | a496775f | j_mayer | fprintf(logfile, "DCR read error %d %03x\n", (int)T0, (int)T0); |
1286 | a496775f | j_mayer | } |
1287 | 76a66253 | j_mayer | do_raise_exception_err(EXCP_PROGRAM, EXCP_INVAL | EXCP_PRIV_REG); |
1288 | 2e719ba3 | j_mayer | } else {
|
1289 | 76a66253 | j_mayer | T0 = val; |
1290 | 2e719ba3 | j_mayer | } |
1291 | 76a66253 | j_mayer | } |
1292 | 76a66253 | j_mayer | |
1293 | a42bd6cc | j_mayer | void do_store_dcr (void) |
1294 | 76a66253 | j_mayer | { |
1295 | 2e719ba3 | j_mayer | if (unlikely(env->dcr_env == NULL)) { |
1296 | 6b80055d | j_mayer | if (loglevel != 0) { |
1297 | a496775f | j_mayer | fprintf(logfile, "No DCR environment\n");
|
1298 | a496775f | j_mayer | } |
1299 | 76a66253 | j_mayer | do_raise_exception_err(EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_INVAL); |
1300 | 2e719ba3 | j_mayer | } else if (unlikely(ppc_dcr_write(env->dcr_env, T0, T1) != 0)) { |
1301 | 6b80055d | j_mayer | if (loglevel != 0) { |
1302 | a496775f | j_mayer | fprintf(logfile, "DCR write error %d %03x\n", (int)T0, (int)T0); |
1303 | a496775f | j_mayer | } |
1304 | 76a66253 | j_mayer | do_raise_exception_err(EXCP_PROGRAM, EXCP_INVAL | EXCP_PRIV_REG); |
1305 | 2e719ba3 | j_mayer | } |
1306 | 76a66253 | j_mayer | } |
1307 | 76a66253 | j_mayer | |
1308 | 76a66253 | j_mayer | void do_load_403_pb (int num) |
1309 | 76a66253 | j_mayer | { |
1310 | 76a66253 | j_mayer | T0 = env->pb[num]; |
1311 | 76a66253 | j_mayer | } |
1312 | 76a66253 | j_mayer | |
1313 | 76a66253 | j_mayer | void do_store_403_pb (int num) |
1314 | 76a66253 | j_mayer | { |
1315 | 76a66253 | j_mayer | if (likely(env->pb[num] != T0)) {
|
1316 | 76a66253 | j_mayer | env->pb[num] = T0; |
1317 | 76a66253 | j_mayer | /* Should be optimized */
|
1318 | 76a66253 | j_mayer | tlb_flush(env, 1);
|
1319 | 76a66253 | j_mayer | } |
1320 | 76a66253 | j_mayer | } |
1321 | 76a66253 | j_mayer | #endif
|
1322 | 76a66253 | j_mayer | |
1323 | 76a66253 | j_mayer | /* 440 specific */
|
1324 | 76a66253 | j_mayer | void do_440_dlmzb (void) |
1325 | 76a66253 | j_mayer | { |
1326 | 76a66253 | j_mayer | target_ulong mask; |
1327 | 76a66253 | j_mayer | int i;
|
1328 | 76a66253 | j_mayer | |
1329 | 76a66253 | j_mayer | i = 1;
|
1330 | 76a66253 | j_mayer | for (mask = 0xFF000000; mask != 0; mask = mask >> 8) { |
1331 | 76a66253 | j_mayer | if ((T0 & mask) == 0) |
1332 | 76a66253 | j_mayer | goto done;
|
1333 | 76a66253 | j_mayer | i++; |
1334 | 76a66253 | j_mayer | } |
1335 | 76a66253 | j_mayer | for (mask = 0xFF000000; mask != 0; mask = mask >> 8) { |
1336 | 76a66253 | j_mayer | if ((T1 & mask) == 0) |
1337 | 76a66253 | j_mayer | break;
|
1338 | 76a66253 | j_mayer | i++; |
1339 | 76a66253 | j_mayer | } |
1340 | 76a66253 | j_mayer | done:
|
1341 | 76a66253 | j_mayer | T0 = i; |
1342 | fdabc366 | bellard | } |
1343 | fdabc366 | bellard | |
1344 | 35cdaad6 | j_mayer | #if defined(TARGET_PPCEMB)
|
1345 | 0487d6a8 | j_mayer | /* SPE extension helpers */
|
1346 | 0487d6a8 | j_mayer | /* Use a table to make this quicker */
|
1347 | 0487d6a8 | j_mayer | static uint8_t hbrev[16] = { |
1348 | 0487d6a8 | j_mayer | 0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE, |
1349 | 0487d6a8 | j_mayer | 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF, |
1350 | 0487d6a8 | j_mayer | }; |
1351 | 0487d6a8 | j_mayer | |
1352 | 0487d6a8 | j_mayer | static inline uint8_t byte_reverse (uint8_t val) |
1353 | 0487d6a8 | j_mayer | { |
1354 | 0487d6a8 | j_mayer | return hbrev[val >> 4] | (hbrev[val & 0xF] << 4); |
1355 | 0487d6a8 | j_mayer | } |
1356 | 0487d6a8 | j_mayer | |
1357 | 0487d6a8 | j_mayer | static inline uint32_t word_reverse (uint32_t val) |
1358 | 0487d6a8 | j_mayer | { |
1359 | 0487d6a8 | j_mayer | return byte_reverse(val >> 24) | (byte_reverse(val >> 16) << 8) | |
1360 | 0487d6a8 | j_mayer | (byte_reverse(val >> 8) << 16) | (byte_reverse(val) << 24); |
1361 | 0487d6a8 | j_mayer | } |
1362 | 0487d6a8 | j_mayer | |
1363 | 0487d6a8 | j_mayer | #define MASKBITS 16 // Random value - to be fixed |
1364 | 0487d6a8 | j_mayer | void do_brinc (void) |
1365 | 0487d6a8 | j_mayer | { |
1366 | 0487d6a8 | j_mayer | uint32_t a, b, d, mask; |
1367 | 0487d6a8 | j_mayer | |
1368 | 0487d6a8 | j_mayer | mask = (uint32_t)(-1UL) >> MASKBITS;
|
1369 | 0487d6a8 | j_mayer | b = T1_64 & mask; |
1370 | 0487d6a8 | j_mayer | a = T0_64 & mask; |
1371 | 0487d6a8 | j_mayer | d = word_reverse(1 + word_reverse(a | ~mask));
|
1372 | 0487d6a8 | j_mayer | T0_64 = (T0_64 & ~mask) | (d & mask); |
1373 | 0487d6a8 | j_mayer | } |
1374 | 0487d6a8 | j_mayer | |
1375 | 0487d6a8 | j_mayer | #define DO_SPE_OP2(name) \
|
1376 | 0487d6a8 | j_mayer | void do_ev##name (void) \ |
1377 | 0487d6a8 | j_mayer | { \ |
1378 | 0487d6a8 | j_mayer | T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32, T1_64 >> 32) << 32) | \ |
1379 | 0487d6a8 | j_mayer | (uint64_t)_do_e##name(T0_64, T1_64); \ |
1380 | 0487d6a8 | j_mayer | } |
1381 | 0487d6a8 | j_mayer | |
1382 | 0487d6a8 | j_mayer | #define DO_SPE_OP1(name) \
|
1383 | 0487d6a8 | j_mayer | void do_ev##name (void) \ |
1384 | 0487d6a8 | j_mayer | { \ |
1385 | 0487d6a8 | j_mayer | T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32) << 32) | \ |
1386 | 0487d6a8 | j_mayer | (uint64_t)_do_e##name(T0_64); \ |
1387 | 0487d6a8 | j_mayer | } |
1388 | 0487d6a8 | j_mayer | |
1389 | 0487d6a8 | j_mayer | /* Fixed-point vector arithmetic */
|
1390 | 0487d6a8 | j_mayer | static inline uint32_t _do_eabs (uint32_t val) |
1391 | 0487d6a8 | j_mayer | { |
1392 | 0487d6a8 | j_mayer | if (val != 0x80000000) |
1393 | 0487d6a8 | j_mayer | val &= ~0x80000000;
|
1394 | 0487d6a8 | j_mayer | |
1395 | 0487d6a8 | j_mayer | return val;
|
1396 | 0487d6a8 | j_mayer | } |
1397 | 0487d6a8 | j_mayer | |
1398 | 0487d6a8 | j_mayer | static inline uint32_t _do_eaddw (uint32_t op1, uint32_t op2) |
1399 | 0487d6a8 | j_mayer | { |
1400 | 0487d6a8 | j_mayer | return op1 + op2;
|
1401 | 0487d6a8 | j_mayer | } |
1402 | 0487d6a8 | j_mayer | |
1403 | 0487d6a8 | j_mayer | static inline int _do_ecntlsw (uint32_t val) |
1404 | 0487d6a8 | j_mayer | { |
1405 | 0487d6a8 | j_mayer | if (val & 0x80000000) |
1406 | 0487d6a8 | j_mayer | return _do_cntlzw(~val);
|
1407 | 0487d6a8 | j_mayer | else
|
1408 | 0487d6a8 | j_mayer | return _do_cntlzw(val);
|
1409 | 0487d6a8 | j_mayer | } |
1410 | 0487d6a8 | j_mayer | |
1411 | 0487d6a8 | j_mayer | static inline int _do_ecntlzw (uint32_t val) |
1412 | 0487d6a8 | j_mayer | { |
1413 | 0487d6a8 | j_mayer | return _do_cntlzw(val);
|
1414 | 0487d6a8 | j_mayer | } |
1415 | 0487d6a8 | j_mayer | |
1416 | 0487d6a8 | j_mayer | static inline uint32_t _do_eneg (uint32_t val) |
1417 | 0487d6a8 | j_mayer | { |
1418 | 0487d6a8 | j_mayer | if (val != 0x80000000) |
1419 | 0487d6a8 | j_mayer | val ^= 0x80000000;
|
1420 | 0487d6a8 | j_mayer | |
1421 | 0487d6a8 | j_mayer | return val;
|
1422 | 0487d6a8 | j_mayer | } |
1423 | 0487d6a8 | j_mayer | |
1424 | 0487d6a8 | j_mayer | static inline uint32_t _do_erlw (uint32_t op1, uint32_t op2) |
1425 | 0487d6a8 | j_mayer | { |
1426 | 0487d6a8 | j_mayer | return rotl32(op1, op2);
|
1427 | 0487d6a8 | j_mayer | } |
1428 | 0487d6a8 | j_mayer | |
1429 | 0487d6a8 | j_mayer | static inline uint32_t _do_erndw (uint32_t val) |
1430 | 0487d6a8 | j_mayer | { |
1431 | 0487d6a8 | j_mayer | return (val + 0x000080000000) & 0xFFFF0000; |
1432 | 0487d6a8 | j_mayer | } |
1433 | 0487d6a8 | j_mayer | |
1434 | 0487d6a8 | j_mayer | static inline uint32_t _do_eslw (uint32_t op1, uint32_t op2) |
1435 | 0487d6a8 | j_mayer | { |
1436 | 0487d6a8 | j_mayer | /* No error here: 6 bits are used */
|
1437 | 0487d6a8 | j_mayer | return op1 << (op2 & 0x3F); |
1438 | 0487d6a8 | j_mayer | } |
1439 | 0487d6a8 | j_mayer | |
1440 | 0487d6a8 | j_mayer | static inline int32_t _do_esrws (int32_t op1, uint32_t op2) |
1441 | 0487d6a8 | j_mayer | { |
1442 | 0487d6a8 | j_mayer | /* No error here: 6 bits are used */
|
1443 | 0487d6a8 | j_mayer | return op1 >> (op2 & 0x3F); |
1444 | 0487d6a8 | j_mayer | } |
1445 | 0487d6a8 | j_mayer | |
1446 | 0487d6a8 | j_mayer | static inline uint32_t _do_esrwu (uint32_t op1, uint32_t op2) |
1447 | 0487d6a8 | j_mayer | { |
1448 | 0487d6a8 | j_mayer | /* No error here: 6 bits are used */
|
1449 | 0487d6a8 | j_mayer | return op1 >> (op2 & 0x3F); |
1450 | 0487d6a8 | j_mayer | } |
1451 | 0487d6a8 | j_mayer | |
1452 | 0487d6a8 | j_mayer | static inline uint32_t _do_esubfw (uint32_t op1, uint32_t op2) |
1453 | 0487d6a8 | j_mayer | { |
1454 | 0487d6a8 | j_mayer | return op2 - op1;
|
1455 | 0487d6a8 | j_mayer | } |
1456 | 0487d6a8 | j_mayer | |
1457 | 0487d6a8 | j_mayer | /* evabs */
|
1458 | 0487d6a8 | j_mayer | DO_SPE_OP1(abs); |
1459 | 0487d6a8 | j_mayer | /* evaddw */
|
1460 | 0487d6a8 | j_mayer | DO_SPE_OP2(addw); |
1461 | 0487d6a8 | j_mayer | /* evcntlsw */
|
1462 | 0487d6a8 | j_mayer | DO_SPE_OP1(cntlsw); |
1463 | 0487d6a8 | j_mayer | /* evcntlzw */
|
1464 | 0487d6a8 | j_mayer | DO_SPE_OP1(cntlzw); |
1465 | 0487d6a8 | j_mayer | /* evneg */
|
1466 | 0487d6a8 | j_mayer | DO_SPE_OP1(neg); |
1467 | 0487d6a8 | j_mayer | /* evrlw */
|
1468 | 0487d6a8 | j_mayer | DO_SPE_OP2(rlw); |
1469 | 0487d6a8 | j_mayer | /* evrnd */
|
1470 | 0487d6a8 | j_mayer | DO_SPE_OP1(rndw); |
1471 | 0487d6a8 | j_mayer | /* evslw */
|
1472 | 0487d6a8 | j_mayer | DO_SPE_OP2(slw); |
1473 | 0487d6a8 | j_mayer | /* evsrws */
|
1474 | 0487d6a8 | j_mayer | DO_SPE_OP2(srws); |
1475 | 0487d6a8 | j_mayer | /* evsrwu */
|
1476 | 0487d6a8 | j_mayer | DO_SPE_OP2(srwu); |
1477 | 0487d6a8 | j_mayer | /* evsubfw */
|
1478 | 0487d6a8 | j_mayer | DO_SPE_OP2(subfw); |
1479 | 0487d6a8 | j_mayer | |
1480 | 0487d6a8 | j_mayer | /* evsel is a little bit more complicated... */
|
1481 | 0487d6a8 | j_mayer | static inline uint32_t _do_esel (uint32_t op1, uint32_t op2, int n) |
1482 | 0487d6a8 | j_mayer | { |
1483 | 0487d6a8 | j_mayer | if (n)
|
1484 | 0487d6a8 | j_mayer | return op1;
|
1485 | 0487d6a8 | j_mayer | else
|
1486 | 0487d6a8 | j_mayer | return op2;
|
1487 | 0487d6a8 | j_mayer | } |
1488 | 0487d6a8 | j_mayer | |
1489 | 0487d6a8 | j_mayer | void do_evsel (void) |
1490 | 0487d6a8 | j_mayer | { |
1491 | 0487d6a8 | j_mayer | T0_64 = ((uint64_t)_do_esel(T0_64 >> 32, T1_64 >> 32, T0 >> 3) << 32) | |
1492 | 0487d6a8 | j_mayer | (uint64_t)_do_esel(T0_64, T1_64, (T0 >> 2) & 1); |
1493 | 0487d6a8 | j_mayer | } |
1494 | 0487d6a8 | j_mayer | |
1495 | 0487d6a8 | j_mayer | /* Fixed-point vector comparisons */
|
1496 | 0487d6a8 | j_mayer | #define DO_SPE_CMP(name) \
|
1497 | 0487d6a8 | j_mayer | void do_ev##name (void) \ |
1498 | 0487d6a8 | j_mayer | { \ |
1499 | 0487d6a8 | j_mayer | T0 = _do_evcmp_merge((uint64_t)_do_e##name(T0_64 >> 32, \ |
1500 | 0487d6a8 | j_mayer | T1_64 >> 32) << 32, \ |
1501 | 0487d6a8 | j_mayer | _do_e##name(T0_64, T1_64)); \ |
1502 | 0487d6a8 | j_mayer | } |
1503 | 0487d6a8 | j_mayer | |
1504 | 0487d6a8 | j_mayer | static inline uint32_t _do_evcmp_merge (int t0, int t1) |
1505 | 0487d6a8 | j_mayer | { |
1506 | 0487d6a8 | j_mayer | return (t0 << 3) | (t1 << 2) | ((t0 | t1) << 1) | (t0 & t1); |
1507 | 0487d6a8 | j_mayer | } |
1508 | 0487d6a8 | j_mayer | static inline int _do_ecmpeq (uint32_t op1, uint32_t op2) |
1509 | 0487d6a8 | j_mayer | { |
1510 | 0487d6a8 | j_mayer | return op1 == op2 ? 1 : 0; |
1511 | 0487d6a8 | j_mayer | } |
1512 | 0487d6a8 | j_mayer | |
1513 | 0487d6a8 | j_mayer | static inline int _do_ecmpgts (int32_t op1, int32_t op2) |
1514 | 0487d6a8 | j_mayer | { |
1515 | 0487d6a8 | j_mayer | return op1 > op2 ? 1 : 0; |
1516 | 0487d6a8 | j_mayer | } |
1517 | 0487d6a8 | j_mayer | |
1518 | 0487d6a8 | j_mayer | static inline int _do_ecmpgtu (uint32_t op1, uint32_t op2) |
1519 | 0487d6a8 | j_mayer | { |
1520 | 0487d6a8 | j_mayer | return op1 > op2 ? 1 : 0; |
1521 | 0487d6a8 | j_mayer | } |
1522 | 0487d6a8 | j_mayer | |
1523 | 0487d6a8 | j_mayer | static inline int _do_ecmplts (int32_t op1, int32_t op2) |
1524 | 0487d6a8 | j_mayer | { |
1525 | 0487d6a8 | j_mayer | return op1 < op2 ? 1 : 0; |
1526 | 0487d6a8 | j_mayer | } |
1527 | 0487d6a8 | j_mayer | |
1528 | 0487d6a8 | j_mayer | static inline int _do_ecmpltu (uint32_t op1, uint32_t op2) |
1529 | 0487d6a8 | j_mayer | { |
1530 | 0487d6a8 | j_mayer | return op1 < op2 ? 1 : 0; |
1531 | 0487d6a8 | j_mayer | } |
1532 | 0487d6a8 | j_mayer | |
1533 | 0487d6a8 | j_mayer | /* evcmpeq */
|
1534 | 0487d6a8 | j_mayer | DO_SPE_CMP(cmpeq); |
1535 | 0487d6a8 | j_mayer | /* evcmpgts */
|
1536 | 0487d6a8 | j_mayer | DO_SPE_CMP(cmpgts); |
1537 | 0487d6a8 | j_mayer | /* evcmpgtu */
|
1538 | 0487d6a8 | j_mayer | DO_SPE_CMP(cmpgtu); |
1539 | 0487d6a8 | j_mayer | /* evcmplts */
|
1540 | 0487d6a8 | j_mayer | DO_SPE_CMP(cmplts); |
1541 | 0487d6a8 | j_mayer | /* evcmpltu */
|
1542 | 0487d6a8 | j_mayer | DO_SPE_CMP(cmpltu); |
1543 | 0487d6a8 | j_mayer | |
1544 | 0487d6a8 | j_mayer | /* Single precision floating-point conversions from/to integer */
|
1545 | 0487d6a8 | j_mayer | static inline uint32_t _do_efscfsi (int32_t val) |
1546 | 0487d6a8 | j_mayer | { |
1547 | 0487d6a8 | j_mayer | union {
|
1548 | 0487d6a8 | j_mayer | uint32_t u; |
1549 | 0487d6a8 | j_mayer | float32 f; |
1550 | 0487d6a8 | j_mayer | } u; |
1551 | 0487d6a8 | j_mayer | |
1552 | 0487d6a8 | j_mayer | u.f = int32_to_float32(val, &env->spe_status); |
1553 | 0487d6a8 | j_mayer | |
1554 | 0487d6a8 | j_mayer | return u.u;
|
1555 | 0487d6a8 | j_mayer | } |
1556 | 0487d6a8 | j_mayer | |
1557 | 0487d6a8 | j_mayer | static inline uint32_t _do_efscfui (uint32_t val) |
1558 | 0487d6a8 | j_mayer | { |
1559 | 0487d6a8 | j_mayer | union {
|
1560 | 0487d6a8 | j_mayer | uint32_t u; |
1561 | 0487d6a8 | j_mayer | float32 f; |
1562 | 0487d6a8 | j_mayer | } u; |
1563 | 0487d6a8 | j_mayer | |
1564 | 0487d6a8 | j_mayer | u.f = uint32_to_float32(val, &env->spe_status); |
1565 | 0487d6a8 | j_mayer | |
1566 | 0487d6a8 | j_mayer | return u.u;
|
1567 | 0487d6a8 | j_mayer | } |
1568 | 0487d6a8 | j_mayer | |
1569 | 0487d6a8 | j_mayer | static inline int32_t _do_efsctsi (uint32_t val) |
1570 | 0487d6a8 | j_mayer | { |
1571 | 0487d6a8 | j_mayer | union {
|
1572 | 0487d6a8 | j_mayer | int32_t u; |
1573 | 0487d6a8 | j_mayer | float32 f; |
1574 | 0487d6a8 | j_mayer | } u; |
1575 | 0487d6a8 | j_mayer | |
1576 | 0487d6a8 | j_mayer | u.u = val; |
1577 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
1578 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
1579 | 0487d6a8 | j_mayer | return 0; |
1580 | 0487d6a8 | j_mayer | |
1581 | 0487d6a8 | j_mayer | return float32_to_int32(u.f, &env->spe_status);
|
1582 | 0487d6a8 | j_mayer | } |
1583 | 0487d6a8 | j_mayer | |
1584 | 0487d6a8 | j_mayer | static inline uint32_t _do_efsctui (uint32_t val) |
1585 | 0487d6a8 | j_mayer | { |
1586 | 0487d6a8 | j_mayer | union {
|
1587 | 0487d6a8 | j_mayer | int32_t u; |
1588 | 0487d6a8 | j_mayer | float32 f; |
1589 | 0487d6a8 | j_mayer | } u; |
1590 | 0487d6a8 | j_mayer | |
1591 | 0487d6a8 | j_mayer | u.u = val; |
1592 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
1593 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
1594 | 0487d6a8 | j_mayer | return 0; |
1595 | 0487d6a8 | j_mayer | |
1596 | 0487d6a8 | j_mayer | return float32_to_uint32(u.f, &env->spe_status);
|
1597 | 0487d6a8 | j_mayer | } |
1598 | 0487d6a8 | j_mayer | |
1599 | 0487d6a8 | j_mayer | static inline int32_t _do_efsctsiz (uint32_t val) |
1600 | 0487d6a8 | j_mayer | { |
1601 | 0487d6a8 | j_mayer | union {
|
1602 | 0487d6a8 | j_mayer | int32_t u; |
1603 | 0487d6a8 | j_mayer | float32 f; |
1604 | 0487d6a8 | j_mayer | } u; |
1605 | 0487d6a8 | j_mayer | |
1606 | 0487d6a8 | j_mayer | u.u = val; |
1607 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
1608 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
1609 | 0487d6a8 | j_mayer | return 0; |
1610 | 0487d6a8 | j_mayer | |
1611 | 0487d6a8 | j_mayer | return float32_to_int32_round_to_zero(u.f, &env->spe_status);
|
1612 | 0487d6a8 | j_mayer | } |
1613 | 0487d6a8 | j_mayer | |
1614 | 0487d6a8 | j_mayer | static inline uint32_t _do_efsctuiz (uint32_t val) |
1615 | 0487d6a8 | j_mayer | { |
1616 | 0487d6a8 | j_mayer | union {
|
1617 | 0487d6a8 | j_mayer | int32_t u; |
1618 | 0487d6a8 | j_mayer | float32 f; |
1619 | 0487d6a8 | j_mayer | } u; |
1620 | 0487d6a8 | j_mayer | |
1621 | 0487d6a8 | j_mayer | u.u = val; |
1622 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
1623 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
1624 | 0487d6a8 | j_mayer | return 0; |
1625 | 0487d6a8 | j_mayer | |
1626 | 0487d6a8 | j_mayer | return float32_to_uint32_round_to_zero(u.f, &env->spe_status);
|
1627 | 0487d6a8 | j_mayer | } |
1628 | 0487d6a8 | j_mayer | |
1629 | 0487d6a8 | j_mayer | void do_efscfsi (void) |
1630 | 0487d6a8 | j_mayer | { |
1631 | 0487d6a8 | j_mayer | T0_64 = _do_efscfsi(T0_64); |
1632 | 0487d6a8 | j_mayer | } |
1633 | 0487d6a8 | j_mayer | |
1634 | 0487d6a8 | j_mayer | void do_efscfui (void) |
1635 | 0487d6a8 | j_mayer | { |
1636 | 0487d6a8 | j_mayer | T0_64 = _do_efscfui(T0_64); |
1637 | 0487d6a8 | j_mayer | } |
1638 | 0487d6a8 | j_mayer | |
1639 | 0487d6a8 | j_mayer | void do_efsctsi (void) |
1640 | 0487d6a8 | j_mayer | { |
1641 | 0487d6a8 | j_mayer | T0_64 = _do_efsctsi(T0_64); |
1642 | 0487d6a8 | j_mayer | } |
1643 | 0487d6a8 | j_mayer | |
1644 | 0487d6a8 | j_mayer | void do_efsctui (void) |
1645 | 0487d6a8 | j_mayer | { |
1646 | 0487d6a8 | j_mayer | T0_64 = _do_efsctui(T0_64); |
1647 | 0487d6a8 | j_mayer | } |
1648 | 0487d6a8 | j_mayer | |
1649 | 0487d6a8 | j_mayer | void do_efsctsiz (void) |
1650 | 0487d6a8 | j_mayer | { |
1651 | 0487d6a8 | j_mayer | T0_64 = _do_efsctsiz(T0_64); |
1652 | 0487d6a8 | j_mayer | } |
1653 | 0487d6a8 | j_mayer | |
1654 | 0487d6a8 | j_mayer | void do_efsctuiz (void) |
1655 | 0487d6a8 | j_mayer | { |
1656 | 0487d6a8 | j_mayer | T0_64 = _do_efsctuiz(T0_64); |
1657 | 0487d6a8 | j_mayer | } |
1658 | 0487d6a8 | j_mayer | |
1659 | 0487d6a8 | j_mayer | /* Single precision floating-point conversion to/from fractional */
|
1660 | 0487d6a8 | j_mayer | static inline uint32_t _do_efscfsf (uint32_t val) |
1661 | 0487d6a8 | j_mayer | { |
1662 | 0487d6a8 | j_mayer | union {
|
1663 | 0487d6a8 | j_mayer | uint32_t u; |
1664 | 0487d6a8 | j_mayer | float32 f; |
1665 | 0487d6a8 | j_mayer | } u; |
1666 | 0487d6a8 | j_mayer | float32 tmp; |
1667 | 0487d6a8 | j_mayer | |
1668 | 0487d6a8 | j_mayer | u.f = int32_to_float32(val, &env->spe_status); |
1669 | 0487d6a8 | j_mayer | tmp = int64_to_float32(1ULL << 32, &env->spe_status); |
1670 | 0487d6a8 | j_mayer | u.f = float32_div(u.f, tmp, &env->spe_status); |
1671 | 0487d6a8 | j_mayer | |
1672 | 0487d6a8 | j_mayer | return u.u;
|
1673 | 0487d6a8 | j_mayer | } |
1674 | 0487d6a8 | j_mayer | |
1675 | 0487d6a8 | j_mayer | static inline uint32_t _do_efscfuf (uint32_t val) |
1676 | 0487d6a8 | j_mayer | { |
1677 | 0487d6a8 | j_mayer | union {
|
1678 | 0487d6a8 | j_mayer | uint32_t u; |
1679 | 0487d6a8 | j_mayer | float32 f; |
1680 | 0487d6a8 | j_mayer | } u; |
1681 | 0487d6a8 | j_mayer | float32 tmp; |
1682 | 0487d6a8 | j_mayer | |
1683 | 0487d6a8 | j_mayer | u.f = uint32_to_float32(val, &env->spe_status); |
1684 | 0487d6a8 | j_mayer | tmp = uint64_to_float32(1ULL << 32, &env->spe_status); |
1685 | 0487d6a8 | j_mayer | u.f = float32_div(u.f, tmp, &env->spe_status); |
1686 | 0487d6a8 | j_mayer | |
1687 | 0487d6a8 | j_mayer | return u.u;
|
1688 | 0487d6a8 | j_mayer | } |
1689 | 0487d6a8 | j_mayer | |
1690 | 0487d6a8 | j_mayer | static inline int32_t _do_efsctsf (uint32_t val) |
1691 | 0487d6a8 | j_mayer | { |
1692 | 0487d6a8 | j_mayer | union {
|
1693 | 0487d6a8 | j_mayer | int32_t u; |
1694 | 0487d6a8 | j_mayer | float32 f; |
1695 | 0487d6a8 | j_mayer | } u; |
1696 | 0487d6a8 | j_mayer | float32 tmp; |
1697 | 0487d6a8 | j_mayer | |
1698 | 0487d6a8 | j_mayer | u.u = val; |
1699 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
1700 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
1701 | 0487d6a8 | j_mayer | return 0; |
1702 | 0487d6a8 | j_mayer | tmp = uint64_to_float32(1ULL << 32, &env->spe_status); |
1703 | 0487d6a8 | j_mayer | u.f = float32_mul(u.f, tmp, &env->spe_status); |
1704 | 0487d6a8 | j_mayer | |
1705 | 0487d6a8 | j_mayer | return float32_to_int32(u.f, &env->spe_status);
|
1706 | 0487d6a8 | j_mayer | } |
1707 | 0487d6a8 | j_mayer | |
1708 | 0487d6a8 | j_mayer | static inline uint32_t _do_efsctuf (uint32_t val) |
1709 | 0487d6a8 | j_mayer | { |
1710 | 0487d6a8 | j_mayer | union {
|
1711 | 0487d6a8 | j_mayer | int32_t u; |
1712 | 0487d6a8 | j_mayer | float32 f; |
1713 | 0487d6a8 | j_mayer | } u; |
1714 | 0487d6a8 | j_mayer | float32 tmp; |
1715 | 0487d6a8 | j_mayer | |
1716 | 0487d6a8 | j_mayer | u.u = val; |
1717 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
1718 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
1719 | 0487d6a8 | j_mayer | return 0; |
1720 | 0487d6a8 | j_mayer | tmp = uint64_to_float32(1ULL << 32, &env->spe_status); |
1721 | 0487d6a8 | j_mayer | u.f = float32_mul(u.f, tmp, &env->spe_status); |
1722 | 0487d6a8 | j_mayer | |
1723 | 0487d6a8 | j_mayer | return float32_to_uint32(u.f, &env->spe_status);
|
1724 | 0487d6a8 | j_mayer | } |
1725 | 0487d6a8 | j_mayer | |
1726 | 0487d6a8 | j_mayer | static inline int32_t _do_efsctsfz (uint32_t val) |
1727 | 0487d6a8 | j_mayer | { |
1728 | 0487d6a8 | j_mayer | union {
|
1729 | 0487d6a8 | j_mayer | int32_t u; |
1730 | 0487d6a8 | j_mayer | float32 f; |
1731 | 0487d6a8 | j_mayer | } u; |
1732 | 0487d6a8 | j_mayer | float32 tmp; |
1733 | 0487d6a8 | j_mayer | |
1734 | 0487d6a8 | j_mayer | u.u = val; |
1735 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
1736 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
1737 | 0487d6a8 | j_mayer | return 0; |
1738 | 0487d6a8 | j_mayer | tmp = uint64_to_float32(1ULL << 32, &env->spe_status); |
1739 | 0487d6a8 | j_mayer | u.f = float32_mul(u.f, tmp, &env->spe_status); |
1740 | 0487d6a8 | j_mayer | |
1741 | 0487d6a8 | j_mayer | return float32_to_int32_round_to_zero(u.f, &env->spe_status);
|
1742 | 0487d6a8 | j_mayer | } |
1743 | 0487d6a8 | j_mayer | |
1744 | 0487d6a8 | j_mayer | static inline uint32_t _do_efsctufz (uint32_t val) |
1745 | 0487d6a8 | j_mayer | { |
1746 | 0487d6a8 | j_mayer | union {
|
1747 | 0487d6a8 | j_mayer | int32_t u; |
1748 | 0487d6a8 | j_mayer | float32 f; |
1749 | 0487d6a8 | j_mayer | } u; |
1750 | 0487d6a8 | j_mayer | float32 tmp; |
1751 | 0487d6a8 | j_mayer | |
1752 | 0487d6a8 | j_mayer | u.u = val; |
1753 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
1754 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
1755 | 0487d6a8 | j_mayer | return 0; |
1756 | 0487d6a8 | j_mayer | tmp = uint64_to_float32(1ULL << 32, &env->spe_status); |
1757 | 0487d6a8 | j_mayer | u.f = float32_mul(u.f, tmp, &env->spe_status); |
1758 | 0487d6a8 | j_mayer | |
1759 | 0487d6a8 | j_mayer | return float32_to_uint32_round_to_zero(u.f, &env->spe_status);
|
1760 | 0487d6a8 | j_mayer | } |
1761 | 0487d6a8 | j_mayer | |
1762 | 0487d6a8 | j_mayer | void do_efscfsf (void) |
1763 | 0487d6a8 | j_mayer | { |
1764 | 0487d6a8 | j_mayer | T0_64 = _do_efscfsf(T0_64); |
1765 | 0487d6a8 | j_mayer | } |
1766 | 0487d6a8 | j_mayer | |
1767 | 0487d6a8 | j_mayer | void do_efscfuf (void) |
1768 | 0487d6a8 | j_mayer | { |
1769 | 0487d6a8 | j_mayer | T0_64 = _do_efscfuf(T0_64); |
1770 | 0487d6a8 | j_mayer | } |
1771 | 0487d6a8 | j_mayer | |
1772 | 0487d6a8 | j_mayer | void do_efsctsf (void) |
1773 | 0487d6a8 | j_mayer | { |
1774 | 0487d6a8 | j_mayer | T0_64 = _do_efsctsf(T0_64); |
1775 | 0487d6a8 | j_mayer | } |
1776 | 0487d6a8 | j_mayer | |
1777 | 0487d6a8 | j_mayer | void do_efsctuf (void) |
1778 | 0487d6a8 | j_mayer | { |
1779 | 0487d6a8 | j_mayer | T0_64 = _do_efsctuf(T0_64); |
1780 | 0487d6a8 | j_mayer | } |
1781 | 0487d6a8 | j_mayer | |
1782 | 0487d6a8 | j_mayer | void do_efsctsfz (void) |
1783 | 0487d6a8 | j_mayer | { |
1784 | 0487d6a8 | j_mayer | T0_64 = _do_efsctsfz(T0_64); |
1785 | 0487d6a8 | j_mayer | } |
1786 | 0487d6a8 | j_mayer | |
1787 | 0487d6a8 | j_mayer | void do_efsctufz (void) |
1788 | 0487d6a8 | j_mayer | { |
1789 | 0487d6a8 | j_mayer | T0_64 = _do_efsctufz(T0_64); |
1790 | 0487d6a8 | j_mayer | } |
1791 | 0487d6a8 | j_mayer | |
1792 | 0487d6a8 | j_mayer | /* Double precision floating point helpers */
|
1793 | 0487d6a8 | j_mayer | static inline int _do_efdcmplt (uint64_t op1, uint64_t op2) |
1794 | 0487d6a8 | j_mayer | { |
1795 | 0487d6a8 | j_mayer | /* XXX: TODO: test special values (NaN, infinites, ...) */
|
1796 | 0487d6a8 | j_mayer | return _do_efdtstlt(op1, op2);
|
1797 | 0487d6a8 | j_mayer | } |
1798 | 0487d6a8 | j_mayer | |
1799 | 0487d6a8 | j_mayer | static inline int _do_efdcmpgt (uint64_t op1, uint64_t op2) |
1800 | 0487d6a8 | j_mayer | { |
1801 | 0487d6a8 | j_mayer | /* XXX: TODO: test special values (NaN, infinites, ...) */
|
1802 | 0487d6a8 | j_mayer | return _do_efdtstgt(op1, op2);
|
1803 | 0487d6a8 | j_mayer | } |
1804 | 0487d6a8 | j_mayer | |
1805 | 0487d6a8 | j_mayer | static inline int _do_efdcmpeq (uint64_t op1, uint64_t op2) |
1806 | 0487d6a8 | j_mayer | { |
1807 | 0487d6a8 | j_mayer | /* XXX: TODO: test special values (NaN, infinites, ...) */
|
1808 | 0487d6a8 | j_mayer | return _do_efdtsteq(op1, op2);
|
1809 | 0487d6a8 | j_mayer | } |
1810 | 0487d6a8 | j_mayer | |
1811 | 0487d6a8 | j_mayer | void do_efdcmplt (void) |
1812 | 0487d6a8 | j_mayer | { |
1813 | 0487d6a8 | j_mayer | T0 = _do_efdcmplt(T0_64, T1_64); |
1814 | 0487d6a8 | j_mayer | } |
1815 | 0487d6a8 | j_mayer | |
1816 | 0487d6a8 | j_mayer | void do_efdcmpgt (void) |
1817 | 0487d6a8 | j_mayer | { |
1818 | 0487d6a8 | j_mayer | T0 = _do_efdcmpgt(T0_64, T1_64); |
1819 | 0487d6a8 | j_mayer | } |
1820 | 0487d6a8 | j_mayer | |
1821 | 0487d6a8 | j_mayer | void do_efdcmpeq (void) |
1822 | 0487d6a8 | j_mayer | { |
1823 | 0487d6a8 | j_mayer | T0 = _do_efdcmpeq(T0_64, T1_64); |
1824 | 0487d6a8 | j_mayer | } |
1825 | 0487d6a8 | j_mayer | |
1826 | 0487d6a8 | j_mayer | /* Double precision floating-point conversion to/from integer */
|
1827 | 0487d6a8 | j_mayer | static inline uint64_t _do_efdcfsi (int64_t val) |
1828 | 0487d6a8 | j_mayer | { |
1829 | 0487d6a8 | j_mayer | union {
|
1830 | 0487d6a8 | j_mayer | uint64_t u; |
1831 | 0487d6a8 | j_mayer | float64 f; |
1832 | 0487d6a8 | j_mayer | } u; |
1833 | 0487d6a8 | j_mayer | |
1834 | 0487d6a8 | j_mayer | u.f = int64_to_float64(val, &env->spe_status); |
1835 | 0487d6a8 | j_mayer | |
1836 | 0487d6a8 | j_mayer | return u.u;
|
1837 | 0487d6a8 | j_mayer | } |
1838 | 0487d6a8 | j_mayer | |
1839 | 0487d6a8 | j_mayer | static inline uint64_t _do_efdcfui (uint64_t val) |
1840 | 0487d6a8 | j_mayer | { |
1841 | 0487d6a8 | j_mayer | union {
|
1842 | 0487d6a8 | j_mayer | uint64_t u; |
1843 | 0487d6a8 | j_mayer | float64 f; |
1844 | 0487d6a8 | j_mayer | } u; |
1845 | 0487d6a8 | j_mayer | |
1846 | 0487d6a8 | j_mayer | u.f = uint64_to_float64(val, &env->spe_status); |
1847 | 0487d6a8 | j_mayer | |
1848 | 0487d6a8 | j_mayer | return u.u;
|
1849 | 0487d6a8 | j_mayer | } |
1850 | 0487d6a8 | j_mayer | |
1851 | 0487d6a8 | j_mayer | static inline int64_t _do_efdctsi (uint64_t val) |
1852 | 0487d6a8 | j_mayer | { |
1853 | 0487d6a8 | j_mayer | union {
|
1854 | 0487d6a8 | j_mayer | int64_t u; |
1855 | 0487d6a8 | j_mayer | float64 f; |
1856 | 0487d6a8 | j_mayer | } u; |
1857 | 0487d6a8 | j_mayer | |
1858 | 0487d6a8 | j_mayer | u.u = val; |
1859 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
1860 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
1861 | 0487d6a8 | j_mayer | return 0; |
1862 | 0487d6a8 | j_mayer | |
1863 | 0487d6a8 | j_mayer | return float64_to_int64(u.f, &env->spe_status);
|
1864 | 0487d6a8 | j_mayer | } |
1865 | 0487d6a8 | j_mayer | |
1866 | 0487d6a8 | j_mayer | static inline uint64_t _do_efdctui (uint64_t val) |
1867 | 0487d6a8 | j_mayer | { |
1868 | 0487d6a8 | j_mayer | union {
|
1869 | 0487d6a8 | j_mayer | int64_t u; |
1870 | 0487d6a8 | j_mayer | float64 f; |
1871 | 0487d6a8 | j_mayer | } u; |
1872 | 0487d6a8 | j_mayer | |
1873 | 0487d6a8 | j_mayer | u.u = val; |
1874 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
1875 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
1876 | 0487d6a8 | j_mayer | return 0; |
1877 | 0487d6a8 | j_mayer | |
1878 | 0487d6a8 | j_mayer | return float64_to_uint64(u.f, &env->spe_status);
|
1879 | 0487d6a8 | j_mayer | } |
1880 | 0487d6a8 | j_mayer | |
1881 | 0487d6a8 | j_mayer | static inline int64_t _do_efdctsiz (uint64_t val) |
1882 | 0487d6a8 | j_mayer | { |
1883 | 0487d6a8 | j_mayer | union {
|
1884 | 0487d6a8 | j_mayer | int64_t u; |
1885 | 0487d6a8 | j_mayer | float64 f; |
1886 | 0487d6a8 | j_mayer | } u; |
1887 | 0487d6a8 | j_mayer | |
1888 | 0487d6a8 | j_mayer | u.u = val; |
1889 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
1890 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
1891 | 0487d6a8 | j_mayer | return 0; |
1892 | 0487d6a8 | j_mayer | |
1893 | 0487d6a8 | j_mayer | return float64_to_int64_round_to_zero(u.f, &env->spe_status);
|
1894 | 0487d6a8 | j_mayer | } |
1895 | 0487d6a8 | j_mayer | |
1896 | 0487d6a8 | j_mayer | static inline uint64_t _do_efdctuiz (uint64_t val) |
1897 | 0487d6a8 | j_mayer | { |
1898 | 0487d6a8 | j_mayer | union {
|
1899 | 0487d6a8 | j_mayer | int64_t u; |
1900 | 0487d6a8 | j_mayer | float64 f; |
1901 | 0487d6a8 | j_mayer | } u; |
1902 | 0487d6a8 | j_mayer | |
1903 | 0487d6a8 | j_mayer | u.u = val; |
1904 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
1905 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
1906 | 0487d6a8 | j_mayer | return 0; |
1907 | 0487d6a8 | j_mayer | |
1908 | 0487d6a8 | j_mayer | return float64_to_uint64_round_to_zero(u.f, &env->spe_status);
|
1909 | 0487d6a8 | j_mayer | } |
1910 | 0487d6a8 | j_mayer | |
1911 | 0487d6a8 | j_mayer | void do_efdcfsi (void) |
1912 | 0487d6a8 | j_mayer | { |
1913 | 0487d6a8 | j_mayer | T0_64 = _do_efdcfsi(T0_64); |
1914 | 0487d6a8 | j_mayer | } |
1915 | 0487d6a8 | j_mayer | |
1916 | 0487d6a8 | j_mayer | void do_efdcfui (void) |
1917 | 0487d6a8 | j_mayer | { |
1918 | 0487d6a8 | j_mayer | T0_64 = _do_efdcfui(T0_64); |
1919 | 0487d6a8 | j_mayer | } |
1920 | 0487d6a8 | j_mayer | |
1921 | 0487d6a8 | j_mayer | void do_efdctsi (void) |
1922 | 0487d6a8 | j_mayer | { |
1923 | 0487d6a8 | j_mayer | T0_64 = _do_efdctsi(T0_64); |
1924 | 0487d6a8 | j_mayer | } |
1925 | 0487d6a8 | j_mayer | |
1926 | 0487d6a8 | j_mayer | void do_efdctui (void) |
1927 | 0487d6a8 | j_mayer | { |
1928 | 0487d6a8 | j_mayer | T0_64 = _do_efdctui(T0_64); |
1929 | 0487d6a8 | j_mayer | } |
1930 | 0487d6a8 | j_mayer | |
1931 | 0487d6a8 | j_mayer | void do_efdctsiz (void) |
1932 | 0487d6a8 | j_mayer | { |
1933 | 0487d6a8 | j_mayer | T0_64 = _do_efdctsiz(T0_64); |
1934 | 0487d6a8 | j_mayer | } |
1935 | 0487d6a8 | j_mayer | |
1936 | 0487d6a8 | j_mayer | void do_efdctuiz (void) |
1937 | 0487d6a8 | j_mayer | { |
1938 | 0487d6a8 | j_mayer | T0_64 = _do_efdctuiz(T0_64); |
1939 | 0487d6a8 | j_mayer | } |
1940 | 0487d6a8 | j_mayer | |
1941 | 0487d6a8 | j_mayer | /* Double precision floating-point conversion to/from fractional */
|
1942 | 0487d6a8 | j_mayer | static inline uint64_t _do_efdcfsf (int64_t val) |
1943 | 0487d6a8 | j_mayer | { |
1944 | 0487d6a8 | j_mayer | union {
|
1945 | 0487d6a8 | j_mayer | uint64_t u; |
1946 | 0487d6a8 | j_mayer | float64 f; |
1947 | 0487d6a8 | j_mayer | } u; |
1948 | 0487d6a8 | j_mayer | float64 tmp; |
1949 | 0487d6a8 | j_mayer | |
1950 | 0487d6a8 | j_mayer | u.f = int32_to_float64(val, &env->spe_status); |
1951 | 0487d6a8 | j_mayer | tmp = int64_to_float64(1ULL << 32, &env->spe_status); |
1952 | 0487d6a8 | j_mayer | u.f = float64_div(u.f, tmp, &env->spe_status); |
1953 | 0487d6a8 | j_mayer | |
1954 | 0487d6a8 | j_mayer | return u.u;
|
1955 | 0487d6a8 | j_mayer | } |
1956 | 0487d6a8 | j_mayer | |
1957 | 0487d6a8 | j_mayer | static inline uint64_t _do_efdcfuf (uint64_t val) |
1958 | 0487d6a8 | j_mayer | { |
1959 | 0487d6a8 | j_mayer | union {
|
1960 | 0487d6a8 | j_mayer | uint64_t u; |
1961 | 0487d6a8 | j_mayer | float64 f; |
1962 | 0487d6a8 | j_mayer | } u; |
1963 | 0487d6a8 | j_mayer | float64 tmp; |
1964 | 0487d6a8 | j_mayer | |
1965 | 0487d6a8 | j_mayer | u.f = uint32_to_float64(val, &env->spe_status); |
1966 | 0487d6a8 | j_mayer | tmp = int64_to_float64(1ULL << 32, &env->spe_status); |
1967 | 0487d6a8 | j_mayer | u.f = float64_div(u.f, tmp, &env->spe_status); |
1968 | 0487d6a8 | j_mayer | |
1969 | 0487d6a8 | j_mayer | return u.u;
|
1970 | 0487d6a8 | j_mayer | } |
1971 | 0487d6a8 | j_mayer | |
1972 | 0487d6a8 | j_mayer | static inline int64_t _do_efdctsf (uint64_t val) |
1973 | 0487d6a8 | j_mayer | { |
1974 | 0487d6a8 | j_mayer | union {
|
1975 | 0487d6a8 | j_mayer | int64_t u; |
1976 | 0487d6a8 | j_mayer | float64 f; |
1977 | 0487d6a8 | j_mayer | } u; |
1978 | 0487d6a8 | j_mayer | float64 tmp; |
1979 | 0487d6a8 | j_mayer | |
1980 | 0487d6a8 | j_mayer | u.u = val; |
1981 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
1982 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
1983 | 0487d6a8 | j_mayer | return 0; |
1984 | 0487d6a8 | j_mayer | tmp = uint64_to_float64(1ULL << 32, &env->spe_status); |
1985 | 0487d6a8 | j_mayer | u.f = float64_mul(u.f, tmp, &env->spe_status); |
1986 | 0487d6a8 | j_mayer | |
1987 | 0487d6a8 | j_mayer | return float64_to_int32(u.f, &env->spe_status);
|
1988 | 0487d6a8 | j_mayer | } |
1989 | 0487d6a8 | j_mayer | |
1990 | 0487d6a8 | j_mayer | static inline uint64_t _do_efdctuf (uint64_t val) |
1991 | 0487d6a8 | j_mayer | { |
1992 | 0487d6a8 | j_mayer | union {
|
1993 | 0487d6a8 | j_mayer | int64_t u; |
1994 | 0487d6a8 | j_mayer | float64 f; |
1995 | 0487d6a8 | j_mayer | } u; |
1996 | 0487d6a8 | j_mayer | float64 tmp; |
1997 | 0487d6a8 | j_mayer | |
1998 | 0487d6a8 | j_mayer | u.u = val; |
1999 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2000 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2001 | 0487d6a8 | j_mayer | return 0; |
2002 | 0487d6a8 | j_mayer | tmp = uint64_to_float64(1ULL << 32, &env->spe_status); |
2003 | 0487d6a8 | j_mayer | u.f = float64_mul(u.f, tmp, &env->spe_status); |
2004 | 0487d6a8 | j_mayer | |
2005 | 0487d6a8 | j_mayer | return float64_to_uint32(u.f, &env->spe_status);
|
2006 | 0487d6a8 | j_mayer | } |
2007 | 0487d6a8 | j_mayer | |
2008 | 0487d6a8 | j_mayer | static inline int64_t _do_efdctsfz (uint64_t val) |
2009 | 0487d6a8 | j_mayer | { |
2010 | 0487d6a8 | j_mayer | union {
|
2011 | 0487d6a8 | j_mayer | int64_t u; |
2012 | 0487d6a8 | j_mayer | float64 f; |
2013 | 0487d6a8 | j_mayer | } u; |
2014 | 0487d6a8 | j_mayer | float64 tmp; |
2015 | 0487d6a8 | j_mayer | |
2016 | 0487d6a8 | j_mayer | u.u = val; |
2017 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2018 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2019 | 0487d6a8 | j_mayer | return 0; |
2020 | 0487d6a8 | j_mayer | tmp = uint64_to_float64(1ULL << 32, &env->spe_status); |
2021 | 0487d6a8 | j_mayer | u.f = float64_mul(u.f, tmp, &env->spe_status); |
2022 | 0487d6a8 | j_mayer | |
2023 | 0487d6a8 | j_mayer | return float64_to_int32_round_to_zero(u.f, &env->spe_status);
|
2024 | 0487d6a8 | j_mayer | } |
2025 | 0487d6a8 | j_mayer | |
2026 | 0487d6a8 | j_mayer | static inline uint64_t _do_efdctufz (uint64_t val) |
2027 | 0487d6a8 | j_mayer | { |
2028 | 0487d6a8 | j_mayer | union {
|
2029 | 0487d6a8 | j_mayer | int64_t u; |
2030 | 0487d6a8 | j_mayer | float64 f; |
2031 | 0487d6a8 | j_mayer | } u; |
2032 | 0487d6a8 | j_mayer | float64 tmp; |
2033 | 0487d6a8 | j_mayer | |
2034 | 0487d6a8 | j_mayer | u.u = val; |
2035 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2036 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2037 | 0487d6a8 | j_mayer | return 0; |
2038 | 0487d6a8 | j_mayer | tmp = uint64_to_float64(1ULL << 32, &env->spe_status); |
2039 | 0487d6a8 | j_mayer | u.f = float64_mul(u.f, tmp, &env->spe_status); |
2040 | 0487d6a8 | j_mayer | |
2041 | 0487d6a8 | j_mayer | return float64_to_uint32_round_to_zero(u.f, &env->spe_status);
|
2042 | 0487d6a8 | j_mayer | } |
2043 | 0487d6a8 | j_mayer | |
2044 | 0487d6a8 | j_mayer | void do_efdcfsf (void) |
2045 | 0487d6a8 | j_mayer | { |
2046 | 0487d6a8 | j_mayer | T0_64 = _do_efdcfsf(T0_64); |
2047 | 0487d6a8 | j_mayer | } |
2048 | 0487d6a8 | j_mayer | |
2049 | 0487d6a8 | j_mayer | void do_efdcfuf (void) |
2050 | 0487d6a8 | j_mayer | { |
2051 | 0487d6a8 | j_mayer | T0_64 = _do_efdcfuf(T0_64); |
2052 | 0487d6a8 | j_mayer | } |
2053 | 0487d6a8 | j_mayer | |
2054 | 0487d6a8 | j_mayer | void do_efdctsf (void) |
2055 | 0487d6a8 | j_mayer | { |
2056 | 0487d6a8 | j_mayer | T0_64 = _do_efdctsf(T0_64); |
2057 | 0487d6a8 | j_mayer | } |
2058 | 0487d6a8 | j_mayer | |
2059 | 0487d6a8 | j_mayer | void do_efdctuf (void) |
2060 | 0487d6a8 | j_mayer | { |
2061 | 0487d6a8 | j_mayer | T0_64 = _do_efdctuf(T0_64); |
2062 | 0487d6a8 | j_mayer | } |
2063 | 0487d6a8 | j_mayer | |
2064 | 0487d6a8 | j_mayer | void do_efdctsfz (void) |
2065 | 0487d6a8 | j_mayer | { |
2066 | 0487d6a8 | j_mayer | T0_64 = _do_efdctsfz(T0_64); |
2067 | 0487d6a8 | j_mayer | } |
2068 | 0487d6a8 | j_mayer | |
2069 | 0487d6a8 | j_mayer | void do_efdctufz (void) |
2070 | 0487d6a8 | j_mayer | { |
2071 | 0487d6a8 | j_mayer | T0_64 = _do_efdctufz(T0_64); |
2072 | 0487d6a8 | j_mayer | } |
2073 | 0487d6a8 | j_mayer | |
2074 | 0487d6a8 | j_mayer | /* Floating point conversion between single and double precision */
|
2075 | 0487d6a8 | j_mayer | static inline uint32_t _do_efscfd (uint64_t val) |
2076 | 0487d6a8 | j_mayer | { |
2077 | 0487d6a8 | j_mayer | union {
|
2078 | 0487d6a8 | j_mayer | uint64_t u; |
2079 | 0487d6a8 | j_mayer | float64 f; |
2080 | 0487d6a8 | j_mayer | } u1; |
2081 | 0487d6a8 | j_mayer | union {
|
2082 | 0487d6a8 | j_mayer | uint32_t u; |
2083 | 0487d6a8 | j_mayer | float32 f; |
2084 | 0487d6a8 | j_mayer | } u2; |
2085 | 0487d6a8 | j_mayer | |
2086 | 0487d6a8 | j_mayer | u1.u = val; |
2087 | 0487d6a8 | j_mayer | u2.f = float64_to_float32(u1.f, &env->spe_status); |
2088 | 0487d6a8 | j_mayer | |
2089 | 0487d6a8 | j_mayer | return u2.u;
|
2090 | 0487d6a8 | j_mayer | } |
2091 | 0487d6a8 | j_mayer | |
2092 | 0487d6a8 | j_mayer | static inline uint64_t _do_efdcfs (uint32_t val) |
2093 | 0487d6a8 | j_mayer | { |
2094 | 0487d6a8 | j_mayer | union {
|
2095 | 0487d6a8 | j_mayer | uint64_t u; |
2096 | 0487d6a8 | j_mayer | float64 f; |
2097 | 0487d6a8 | j_mayer | } u2; |
2098 | 0487d6a8 | j_mayer | union {
|
2099 | 0487d6a8 | j_mayer | uint32_t u; |
2100 | 0487d6a8 | j_mayer | float32 f; |
2101 | 0487d6a8 | j_mayer | } u1; |
2102 | 0487d6a8 | j_mayer | |
2103 | 0487d6a8 | j_mayer | u1.u = val; |
2104 | 0487d6a8 | j_mayer | u2.f = float32_to_float64(u1.f, &env->spe_status); |
2105 | 0487d6a8 | j_mayer | |
2106 | 0487d6a8 | j_mayer | return u2.u;
|
2107 | 0487d6a8 | j_mayer | } |
2108 | 0487d6a8 | j_mayer | |
2109 | 0487d6a8 | j_mayer | void do_efscfd (void) |
2110 | 0487d6a8 | j_mayer | { |
2111 | 0487d6a8 | j_mayer | T0_64 = _do_efscfd(T0_64); |
2112 | 0487d6a8 | j_mayer | } |
2113 | 0487d6a8 | j_mayer | |
2114 | 0487d6a8 | j_mayer | void do_efdcfs (void) |
2115 | 0487d6a8 | j_mayer | { |
2116 | 0487d6a8 | j_mayer | T0_64 = _do_efdcfs(T0_64); |
2117 | 0487d6a8 | j_mayer | } |
2118 | 0487d6a8 | j_mayer | |
2119 | 0487d6a8 | j_mayer | /* Single precision fixed-point vector arithmetic */
|
2120 | 0487d6a8 | j_mayer | /* evfsabs */
|
2121 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsabs); |
2122 | 0487d6a8 | j_mayer | /* evfsnabs */
|
2123 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsnabs); |
2124 | 0487d6a8 | j_mayer | /* evfsneg */
|
2125 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsneg); |
2126 | 0487d6a8 | j_mayer | /* evfsadd */
|
2127 | 0487d6a8 | j_mayer | DO_SPE_OP2(fsadd); |
2128 | 0487d6a8 | j_mayer | /* evfssub */
|
2129 | 0487d6a8 | j_mayer | DO_SPE_OP2(fssub); |
2130 | 0487d6a8 | j_mayer | /* evfsmul */
|
2131 | 0487d6a8 | j_mayer | DO_SPE_OP2(fsmul); |
2132 | 0487d6a8 | j_mayer | /* evfsdiv */
|
2133 | 0487d6a8 | j_mayer | DO_SPE_OP2(fsdiv); |
2134 | 0487d6a8 | j_mayer | |
2135 | 0487d6a8 | j_mayer | /* Single-precision floating-point comparisons */
|
2136 | 0487d6a8 | j_mayer | static inline int _do_efscmplt (uint32_t op1, uint32_t op2) |
2137 | 0487d6a8 | j_mayer | { |
2138 | 0487d6a8 | j_mayer | /* XXX: TODO: test special values (NaN, infinites, ...) */
|
2139 | 0487d6a8 | j_mayer | return _do_efststlt(op1, op2);
|
2140 | 0487d6a8 | j_mayer | } |
2141 | 0487d6a8 | j_mayer | |
2142 | 0487d6a8 | j_mayer | static inline int _do_efscmpgt (uint32_t op1, uint32_t op2) |
2143 | 0487d6a8 | j_mayer | { |
2144 | 0487d6a8 | j_mayer | /* XXX: TODO: test special values (NaN, infinites, ...) */
|
2145 | 0487d6a8 | j_mayer | return _do_efststgt(op1, op2);
|
2146 | 0487d6a8 | j_mayer | } |
2147 | 0487d6a8 | j_mayer | |
2148 | 0487d6a8 | j_mayer | static inline int _do_efscmpeq (uint32_t op1, uint32_t op2) |
2149 | 0487d6a8 | j_mayer | { |
2150 | 0487d6a8 | j_mayer | /* XXX: TODO: test special values (NaN, infinites, ...) */
|
2151 | 0487d6a8 | j_mayer | return _do_efststeq(op1, op2);
|
2152 | 0487d6a8 | j_mayer | } |
2153 | 0487d6a8 | j_mayer | |
2154 | 0487d6a8 | j_mayer | void do_efscmplt (void) |
2155 | 0487d6a8 | j_mayer | { |
2156 | 0487d6a8 | j_mayer | T0 = _do_efscmplt(T0_64, T1_64); |
2157 | 0487d6a8 | j_mayer | } |
2158 | 0487d6a8 | j_mayer | |
2159 | 0487d6a8 | j_mayer | void do_efscmpgt (void) |
2160 | 0487d6a8 | j_mayer | { |
2161 | 0487d6a8 | j_mayer | T0 = _do_efscmpgt(T0_64, T1_64); |
2162 | 0487d6a8 | j_mayer | } |
2163 | 0487d6a8 | j_mayer | |
2164 | 0487d6a8 | j_mayer | void do_efscmpeq (void) |
2165 | 0487d6a8 | j_mayer | { |
2166 | 0487d6a8 | j_mayer | T0 = _do_efscmpeq(T0_64, T1_64); |
2167 | 0487d6a8 | j_mayer | } |
2168 | 0487d6a8 | j_mayer | |
2169 | 0487d6a8 | j_mayer | /* Single-precision floating-point vector comparisons */
|
2170 | 0487d6a8 | j_mayer | /* evfscmplt */
|
2171 | 0487d6a8 | j_mayer | DO_SPE_CMP(fscmplt); |
2172 | 0487d6a8 | j_mayer | /* evfscmpgt */
|
2173 | 0487d6a8 | j_mayer | DO_SPE_CMP(fscmpgt); |
2174 | 0487d6a8 | j_mayer | /* evfscmpeq */
|
2175 | 0487d6a8 | j_mayer | DO_SPE_CMP(fscmpeq); |
2176 | 0487d6a8 | j_mayer | /* evfststlt */
|
2177 | 0487d6a8 | j_mayer | DO_SPE_CMP(fststlt); |
2178 | 0487d6a8 | j_mayer | /* evfststgt */
|
2179 | 0487d6a8 | j_mayer | DO_SPE_CMP(fststgt); |
2180 | 0487d6a8 | j_mayer | /* evfststeq */
|
2181 | 0487d6a8 | j_mayer | DO_SPE_CMP(fststeq); |
2182 | 0487d6a8 | j_mayer | |
2183 | 0487d6a8 | j_mayer | /* Single-precision floating-point vector conversions */
|
2184 | 0487d6a8 | j_mayer | /* evfscfsi */
|
2185 | 0487d6a8 | j_mayer | DO_SPE_OP1(fscfsi); |
2186 | 0487d6a8 | j_mayer | /* evfscfui */
|
2187 | 0487d6a8 | j_mayer | DO_SPE_OP1(fscfui); |
2188 | 0487d6a8 | j_mayer | /* evfscfuf */
|
2189 | 0487d6a8 | j_mayer | DO_SPE_OP1(fscfuf); |
2190 | 0487d6a8 | j_mayer | /* evfscfsf */
|
2191 | 0487d6a8 | j_mayer | DO_SPE_OP1(fscfsf); |
2192 | 0487d6a8 | j_mayer | /* evfsctsi */
|
2193 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsctsi); |
2194 | 0487d6a8 | j_mayer | /* evfsctui */
|
2195 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsctui); |
2196 | 0487d6a8 | j_mayer | /* evfsctsiz */
|
2197 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsctsiz); |
2198 | 0487d6a8 | j_mayer | /* evfsctuiz */
|
2199 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsctuiz); |
2200 | 0487d6a8 | j_mayer | /* evfsctsf */
|
2201 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsctsf); |
2202 | 0487d6a8 | j_mayer | /* evfsctuf */
|
2203 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsctuf); |
2204 | 35cdaad6 | j_mayer | #endif /* defined(TARGET_PPCEMB) */ |
2205 | 0487d6a8 | j_mayer | |
2206 | fdabc366 | bellard | /*****************************************************************************/
|
2207 | fdabc366 | bellard | /* Softmmu support */
|
2208 | fdabc366 | bellard | #if !defined (CONFIG_USER_ONLY)
|
2209 | fdabc366 | bellard | |
2210 | fdabc366 | bellard | #define MMUSUFFIX _mmu
|
2211 | fdabc366 | bellard | #define GETPC() (__builtin_return_address(0)) |
2212 | fdabc366 | bellard | |
2213 | fdabc366 | bellard | #define SHIFT 0 |
2214 | fdabc366 | bellard | #include "softmmu_template.h" |
2215 | fdabc366 | bellard | |
2216 | fdabc366 | bellard | #define SHIFT 1 |
2217 | fdabc366 | bellard | #include "softmmu_template.h" |
2218 | fdabc366 | bellard | |
2219 | fdabc366 | bellard | #define SHIFT 2 |
2220 | fdabc366 | bellard | #include "softmmu_template.h" |
2221 | fdabc366 | bellard | |
2222 | fdabc366 | bellard | #define SHIFT 3 |
2223 | fdabc366 | bellard | #include "softmmu_template.h" |
2224 | fdabc366 | bellard | |
2225 | fdabc366 | bellard | /* try to fill the TLB and return an exception if error. If retaddr is
|
2226 | fdabc366 | bellard | NULL, it means that the function was called in C code (i.e. not
|
2227 | fdabc366 | bellard | from generated code or from helper.c) */
|
2228 | fdabc366 | bellard | /* XXX: fix it to restore all registers */
|
2229 | fdabc366 | bellard | void tlb_fill (target_ulong addr, int is_write, int is_user, void *retaddr) |
2230 | fdabc366 | bellard | { |
2231 | fdabc366 | bellard | TranslationBlock *tb; |
2232 | fdabc366 | bellard | CPUState *saved_env; |
2233 | fdabc366 | bellard | target_phys_addr_t pc; |
2234 | fdabc366 | bellard | int ret;
|
2235 | fdabc366 | bellard | |
2236 | fdabc366 | bellard | /* XXX: hack to restore env in all cases, even if not called from
|
2237 | fdabc366 | bellard | generated code */
|
2238 | fdabc366 | bellard | saved_env = env; |
2239 | fdabc366 | bellard | env = cpu_single_env; |
2240 | fdabc366 | bellard | ret = cpu_ppc_handle_mmu_fault(env, addr, is_write, is_user, 1);
|
2241 | 76a66253 | j_mayer | if (unlikely(ret != 0)) { |
2242 | fdabc366 | bellard | if (likely(retaddr)) {
|
2243 | fdabc366 | bellard | /* now we have a real cpu fault */
|
2244 | fdabc366 | bellard | pc = (target_phys_addr_t)retaddr; |
2245 | fdabc366 | bellard | tb = tb_find_pc(pc); |
2246 | fdabc366 | bellard | if (likely(tb)) {
|
2247 | fdabc366 | bellard | /* the PC is inside the translated code. It means that we have
|
2248 | fdabc366 | bellard | a virtual CPU fault */
|
2249 | fdabc366 | bellard | cpu_restore_state(tb, env, pc, NULL);
|
2250 | 76a66253 | j_mayer | } |
2251 | fdabc366 | bellard | } |
2252 | fdabc366 | bellard | do_raise_exception_err(env->exception_index, env->error_code); |
2253 | fdabc366 | bellard | } |
2254 | fdabc366 | bellard | env = saved_env; |
2255 | 9a64fbe4 | bellard | } |
2256 | 9a64fbe4 | bellard | |
2257 | 76a66253 | j_mayer | /* TLB invalidation helpers */
|
2258 | 76a66253 | j_mayer | void do_tlbia (void) |
2259 | 76a66253 | j_mayer | { |
2260 | 0a032cbe | j_mayer | ppc_tlb_invalidate_all(env); |
2261 | 76a66253 | j_mayer | } |
2262 | 76a66253 | j_mayer | |
2263 | 76a66253 | j_mayer | void do_tlbie (void) |
2264 | 76a66253 | j_mayer | { |
2265 | d9bce9d9 | j_mayer | T0 = (uint32_t)T0; |
2266 | 76a66253 | j_mayer | #if !defined(FLUSH_ALL_TLBS)
|
2267 | 76a66253 | j_mayer | if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_6xx)) {
|
2268 | 76a66253 | j_mayer | ppc6xx_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK, 0);
|
2269 | 76a66253 | j_mayer | if (env->id_tlbs == 1) |
2270 | 76a66253 | j_mayer | ppc6xx_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK, 1);
|
2271 | 76a66253 | j_mayer | } else if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_4xx)) { |
2272 | 76a66253 | j_mayer | /* XXX: TODO */
|
2273 | 76a66253 | j_mayer | #if 0
|
2274 | 76a66253 | j_mayer | ppcbooke_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK,
|
2275 | 76a66253 | j_mayer | env->spr[SPR_BOOKE_PID]);
|
2276 | 76a66253 | j_mayer | #endif
|
2277 | 76a66253 | j_mayer | } else {
|
2278 | 76a66253 | j_mayer | /* tlbie invalidate TLBs for all segments */
|
2279 | 76a66253 | j_mayer | T0 &= TARGET_PAGE_MASK; |
2280 | 76a66253 | j_mayer | T0 &= ~((target_ulong)-1 << 28); |
2281 | 76a66253 | j_mayer | /* XXX: this case should be optimized,
|
2282 | 76a66253 | j_mayer | * giving a mask to tlb_flush_page
|
2283 | 76a66253 | j_mayer | */
|
2284 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0x0 << 28)); |
2285 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0x1 << 28)); |
2286 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0x2 << 28)); |
2287 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0x3 << 28)); |
2288 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0x4 << 28)); |
2289 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0x5 << 28)); |
2290 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0x6 << 28)); |
2291 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0x7 << 28)); |
2292 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0x8 << 28)); |
2293 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0x9 << 28)); |
2294 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0xA << 28)); |
2295 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0xB << 28)); |
2296 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0xC << 28)); |
2297 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0xD << 28)); |
2298 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0xE << 28)); |
2299 | 76a66253 | j_mayer | tlb_flush_page(env, T0 | (0xF << 28)); |
2300 | 76a66253 | j_mayer | } |
2301 | 76a66253 | j_mayer | #else
|
2302 | 76a66253 | j_mayer | do_tlbia(); |
2303 | 76a66253 | j_mayer | #endif
|
2304 | 76a66253 | j_mayer | } |
2305 | 76a66253 | j_mayer | |
2306 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
2307 | d9bce9d9 | j_mayer | void do_tlbie_64 (void) |
2308 | d9bce9d9 | j_mayer | { |
2309 | d9bce9d9 | j_mayer | T0 = (uint64_t)T0; |
2310 | d9bce9d9 | j_mayer | #if !defined(FLUSH_ALL_TLBS)
|
2311 | d9bce9d9 | j_mayer | if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_6xx)) {
|
2312 | d9bce9d9 | j_mayer | ppc6xx_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK, 0);
|
2313 | d9bce9d9 | j_mayer | if (env->id_tlbs == 1) |
2314 | d9bce9d9 | j_mayer | ppc6xx_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK, 1);
|
2315 | d9bce9d9 | j_mayer | } else if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_4xx)) { |
2316 | d9bce9d9 | j_mayer | /* XXX: TODO */
|
2317 | d9bce9d9 | j_mayer | #if 0
|
2318 | d9bce9d9 | j_mayer | ppcbooke_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK,
|
2319 | d9bce9d9 | j_mayer | env->spr[SPR_BOOKE_PID]);
|
2320 | d9bce9d9 | j_mayer | #endif
|
2321 | d9bce9d9 | j_mayer | } else {
|
2322 | d9bce9d9 | j_mayer | /* tlbie invalidate TLBs for all segments
|
2323 | d9bce9d9 | j_mayer | * As we have 2^36 segments, invalidate all qemu TLBs
|
2324 | d9bce9d9 | j_mayer | */
|
2325 | d9bce9d9 | j_mayer | #if 0
|
2326 | d9bce9d9 | j_mayer | T0 &= TARGET_PAGE_MASK;
|
2327 | d9bce9d9 | j_mayer | T0 &= ~((target_ulong)-1 << 28);
|
2328 | d9bce9d9 | j_mayer | /* XXX: this case should be optimized,
|
2329 | d9bce9d9 | j_mayer | * giving a mask to tlb_flush_page
|
2330 | d9bce9d9 | j_mayer | */
|
2331 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0x0 << 28));
|
2332 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0x1 << 28));
|
2333 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0x2 << 28));
|
2334 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0x3 << 28));
|
2335 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0x4 << 28));
|
2336 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0x5 << 28));
|
2337 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0x6 << 28));
|
2338 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0x7 << 28));
|
2339 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0x8 << 28));
|
2340 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0x9 << 28));
|
2341 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0xA << 28));
|
2342 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0xB << 28));
|
2343 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0xC << 28));
|
2344 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0xD << 28));
|
2345 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0xE << 28));
|
2346 | d9bce9d9 | j_mayer | tlb_flush_page(env, T0 | (0xF << 28));
|
2347 | d9bce9d9 | j_mayer | #else
|
2348 | d9bce9d9 | j_mayer | tlb_flush(env, 1);
|
2349 | d9bce9d9 | j_mayer | #endif
|
2350 | d9bce9d9 | j_mayer | } |
2351 | d9bce9d9 | j_mayer | #else
|
2352 | d9bce9d9 | j_mayer | do_tlbia(); |
2353 | d9bce9d9 | j_mayer | #endif
|
2354 | d9bce9d9 | j_mayer | } |
2355 | d9bce9d9 | j_mayer | #endif
|
2356 | d9bce9d9 | j_mayer | |
2357 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
2358 | d9bce9d9 | j_mayer | void do_slbia (void) |
2359 | d9bce9d9 | j_mayer | { |
2360 | d9bce9d9 | j_mayer | /* XXX: TODO */
|
2361 | d9bce9d9 | j_mayer | tlb_flush(env, 1);
|
2362 | d9bce9d9 | j_mayer | } |
2363 | d9bce9d9 | j_mayer | |
2364 | d9bce9d9 | j_mayer | void do_slbie (void) |
2365 | d9bce9d9 | j_mayer | { |
2366 | d9bce9d9 | j_mayer | /* XXX: TODO */
|
2367 | d9bce9d9 | j_mayer | tlb_flush(env, 1);
|
2368 | d9bce9d9 | j_mayer | } |
2369 | d9bce9d9 | j_mayer | #endif
|
2370 | d9bce9d9 | j_mayer | |
2371 | 76a66253 | j_mayer | /* Software driven TLBs management */
|
2372 | 76a66253 | j_mayer | /* PowerPC 602/603 software TLB load instructions helpers */
|
2373 | 76a66253 | j_mayer | void do_load_6xx_tlb (int is_code) |
2374 | 76a66253 | j_mayer | { |
2375 | 76a66253 | j_mayer | target_ulong RPN, CMP, EPN; |
2376 | 76a66253 | j_mayer | int way;
|
2377 | d9bce9d9 | j_mayer | |
2378 | 76a66253 | j_mayer | RPN = env->spr[SPR_RPA]; |
2379 | 76a66253 | j_mayer | if (is_code) {
|
2380 | 76a66253 | j_mayer | CMP = env->spr[SPR_ICMP]; |
2381 | 76a66253 | j_mayer | EPN = env->spr[SPR_IMISS]; |
2382 | 76a66253 | j_mayer | } else {
|
2383 | 76a66253 | j_mayer | CMP = env->spr[SPR_DCMP]; |
2384 | 76a66253 | j_mayer | EPN = env->spr[SPR_DMISS]; |
2385 | 76a66253 | j_mayer | } |
2386 | 76a66253 | j_mayer | way = (env->spr[SPR_SRR1] >> 17) & 1; |
2387 | 76a66253 | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
2388 | 76a66253 | j_mayer | if (loglevel != 0) { |
2389 | 76a66253 | j_mayer | fprintf(logfile, "%s: EPN %08lx %08lx PTE0 %08lx PTE1 %08lx way %d\n",
|
2390 | 76a66253 | j_mayer | __func__, (unsigned long)T0, (unsigned long)EPN, |
2391 | 76a66253 | j_mayer | (unsigned long)CMP, (unsigned long)RPN, way); |
2392 | 76a66253 | j_mayer | } |
2393 | 76a66253 | j_mayer | #endif
|
2394 | 76a66253 | j_mayer | /* Store this TLB */
|
2395 | d9bce9d9 | j_mayer | ppc6xx_tlb_store(env, (uint32_t)(T0 & TARGET_PAGE_MASK), |
2396 | d9bce9d9 | j_mayer | way, is_code, CMP, RPN); |
2397 | 76a66253 | j_mayer | } |
2398 | 76a66253 | j_mayer | |
2399 | a8dea12f | j_mayer | static target_ulong booke_tlb_to_page_size (int size) |
2400 | a8dea12f | j_mayer | { |
2401 | a8dea12f | j_mayer | return 1024 << (2 * size); |
2402 | a8dea12f | j_mayer | } |
2403 | a8dea12f | j_mayer | |
2404 | a8dea12f | j_mayer | static int booke_page_size_to_tlb (target_ulong page_size) |
2405 | a8dea12f | j_mayer | { |
2406 | a8dea12f | j_mayer | int size;
|
2407 | a8dea12f | j_mayer | |
2408 | a8dea12f | j_mayer | switch (page_size) {
|
2409 | a8dea12f | j_mayer | case 0x00000400UL: |
2410 | a8dea12f | j_mayer | size = 0x0;
|
2411 | a8dea12f | j_mayer | break;
|
2412 | a8dea12f | j_mayer | case 0x00001000UL: |
2413 | a8dea12f | j_mayer | size = 0x1;
|
2414 | a8dea12f | j_mayer | break;
|
2415 | a8dea12f | j_mayer | case 0x00004000UL: |
2416 | a8dea12f | j_mayer | size = 0x2;
|
2417 | a8dea12f | j_mayer | break;
|
2418 | a8dea12f | j_mayer | case 0x00010000UL: |
2419 | a8dea12f | j_mayer | size = 0x3;
|
2420 | a8dea12f | j_mayer | break;
|
2421 | a8dea12f | j_mayer | case 0x00040000UL: |
2422 | a8dea12f | j_mayer | size = 0x4;
|
2423 | a8dea12f | j_mayer | break;
|
2424 | a8dea12f | j_mayer | case 0x00100000UL: |
2425 | a8dea12f | j_mayer | size = 0x5;
|
2426 | a8dea12f | j_mayer | break;
|
2427 | a8dea12f | j_mayer | case 0x00400000UL: |
2428 | a8dea12f | j_mayer | size = 0x6;
|
2429 | a8dea12f | j_mayer | break;
|
2430 | a8dea12f | j_mayer | case 0x01000000UL: |
2431 | a8dea12f | j_mayer | size = 0x7;
|
2432 | a8dea12f | j_mayer | break;
|
2433 | a8dea12f | j_mayer | case 0x04000000UL: |
2434 | a8dea12f | j_mayer | size = 0x8;
|
2435 | a8dea12f | j_mayer | break;
|
2436 | a8dea12f | j_mayer | case 0x10000000UL: |
2437 | a8dea12f | j_mayer | size = 0x9;
|
2438 | a8dea12f | j_mayer | break;
|
2439 | a8dea12f | j_mayer | case 0x40000000UL: |
2440 | a8dea12f | j_mayer | size = 0xA;
|
2441 | a8dea12f | j_mayer | break;
|
2442 | a8dea12f | j_mayer | #if defined (TARGET_PPC64)
|
2443 | a8dea12f | j_mayer | case 0x000100000000ULL: |
2444 | a8dea12f | j_mayer | size = 0xB;
|
2445 | a8dea12f | j_mayer | break;
|
2446 | a8dea12f | j_mayer | case 0x000400000000ULL: |
2447 | a8dea12f | j_mayer | size = 0xC;
|
2448 | a8dea12f | j_mayer | break;
|
2449 | a8dea12f | j_mayer | case 0x001000000000ULL: |
2450 | a8dea12f | j_mayer | size = 0xD;
|
2451 | a8dea12f | j_mayer | break;
|
2452 | a8dea12f | j_mayer | case 0x004000000000ULL: |
2453 | a8dea12f | j_mayer | size = 0xE;
|
2454 | a8dea12f | j_mayer | break;
|
2455 | a8dea12f | j_mayer | case 0x010000000000ULL: |
2456 | a8dea12f | j_mayer | size = 0xF;
|
2457 | a8dea12f | j_mayer | break;
|
2458 | a8dea12f | j_mayer | #endif
|
2459 | a8dea12f | j_mayer | default:
|
2460 | a8dea12f | j_mayer | size = -1;
|
2461 | a8dea12f | j_mayer | break;
|
2462 | a8dea12f | j_mayer | } |
2463 | a8dea12f | j_mayer | |
2464 | a8dea12f | j_mayer | return size;
|
2465 | a8dea12f | j_mayer | } |
2466 | a8dea12f | j_mayer | |
2467 | 76a66253 | j_mayer | /* Helpers for 4xx TLB management */
|
2468 | 76a66253 | j_mayer | void do_4xx_tlbre_lo (void) |
2469 | 76a66253 | j_mayer | { |
2470 | a8dea12f | j_mayer | ppcemb_tlb_t *tlb; |
2471 | a8dea12f | j_mayer | int size;
|
2472 | 76a66253 | j_mayer | |
2473 | 76a66253 | j_mayer | T0 &= 0x3F;
|
2474 | a8dea12f | j_mayer | tlb = &env->tlb[T0].tlbe; |
2475 | a8dea12f | j_mayer | T0 = tlb->EPN; |
2476 | a8dea12f | j_mayer | if (tlb->prot & PAGE_VALID)
|
2477 | a8dea12f | j_mayer | T0 |= 0x400;
|
2478 | a8dea12f | j_mayer | size = booke_page_size_to_tlb(tlb->size); |
2479 | a8dea12f | j_mayer | if (size < 0 || size > 0x7) |
2480 | a8dea12f | j_mayer | size = 1;
|
2481 | a8dea12f | j_mayer | T0 |= size << 7;
|
2482 | a8dea12f | j_mayer | env->spr[SPR_40x_PID] = tlb->PID; |
2483 | 76a66253 | j_mayer | } |
2484 | 76a66253 | j_mayer | |
2485 | 76a66253 | j_mayer | void do_4xx_tlbre_hi (void) |
2486 | 76a66253 | j_mayer | { |
2487 | a8dea12f | j_mayer | ppcemb_tlb_t *tlb; |
2488 | 76a66253 | j_mayer | |
2489 | 76a66253 | j_mayer | T0 &= 0x3F;
|
2490 | a8dea12f | j_mayer | tlb = &env->tlb[T0].tlbe; |
2491 | a8dea12f | j_mayer | T0 = tlb->RPN; |
2492 | a8dea12f | j_mayer | if (tlb->prot & PAGE_EXEC)
|
2493 | a8dea12f | j_mayer | T0 |= 0x200;
|
2494 | a8dea12f | j_mayer | if (tlb->prot & PAGE_WRITE)
|
2495 | a8dea12f | j_mayer | T0 |= 0x100;
|
2496 | 76a66253 | j_mayer | } |
2497 | 76a66253 | j_mayer | |
2498 | 76a66253 | j_mayer | void do_4xx_tlbsx (void) |
2499 | 76a66253 | j_mayer | { |
2500 | c294fc58 | j_mayer | T0 = ppcemb_tlb_search(env, T0); |
2501 | 76a66253 | j_mayer | } |
2502 | 76a66253 | j_mayer | |
2503 | 76a66253 | j_mayer | void do_4xx_tlbsx_ (void) |
2504 | 76a66253 | j_mayer | { |
2505 | 76a66253 | j_mayer | int tmp = xer_ov;
|
2506 | 76a66253 | j_mayer | |
2507 | c294fc58 | j_mayer | T0 = ppcemb_tlb_search(env, T0); |
2508 | 76a66253 | j_mayer | if (T0 != -1) |
2509 | 76a66253 | j_mayer | tmp |= 0x02;
|
2510 | 76a66253 | j_mayer | env->crf[0] = tmp;
|
2511 | 76a66253 | j_mayer | } |
2512 | 76a66253 | j_mayer | |
2513 | c55e9aef | j_mayer | void do_4xx_tlbwe_hi (void) |
2514 | 76a66253 | j_mayer | { |
2515 | a8dea12f | j_mayer | ppcemb_tlb_t *tlb; |
2516 | 76a66253 | j_mayer | target_ulong page, end; |
2517 | 76a66253 | j_mayer | |
2518 | c55e9aef | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
2519 | 6b80055d | j_mayer | if (loglevel != 0) { |
2520 | c55e9aef | j_mayer | fprintf(logfile, "%s T0 " REGX " T1 " REGX "\n", __func__, T0, T1); |
2521 | c55e9aef | j_mayer | } |
2522 | c55e9aef | j_mayer | #endif
|
2523 | 76a66253 | j_mayer | T0 &= 0x3F;
|
2524 | a8dea12f | j_mayer | tlb = &env->tlb[T0].tlbe; |
2525 | 76a66253 | j_mayer | /* Invalidate previous TLB (if it's valid) */
|
2526 | 76a66253 | j_mayer | if (tlb->prot & PAGE_VALID) {
|
2527 | 76a66253 | j_mayer | end = tlb->EPN + tlb->size; |
2528 | c55e9aef | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
2529 | 6b80055d | j_mayer | if (loglevel != 0) { |
2530 | c55e9aef | j_mayer | fprintf(logfile, "%s: invalidate old TLB %d start " ADDRX
|
2531 | c55e9aef | j_mayer | " end " ADDRX "\n", __func__, (int)T0, tlb->EPN, end); |
2532 | c55e9aef | j_mayer | } |
2533 | c55e9aef | j_mayer | #endif
|
2534 | 76a66253 | j_mayer | for (page = tlb->EPN; page < end; page += TARGET_PAGE_SIZE)
|
2535 | 76a66253 | j_mayer | tlb_flush_page(env, page); |
2536 | 76a66253 | j_mayer | } |
2537 | a8dea12f | j_mayer | tlb->size = booke_tlb_to_page_size((T1 >> 7) & 0x7); |
2538 | c294fc58 | j_mayer | /* We cannot handle TLB size < TARGET_PAGE_SIZE.
|
2539 | c294fc58 | j_mayer | * If this ever occurs, one should use the ppcemb target instead
|
2540 | c294fc58 | j_mayer | * of the ppc or ppc64 one
|
2541 | c294fc58 | j_mayer | */
|
2542 | c294fc58 | j_mayer | if ((T1 & 0x40) && tlb->size < TARGET_PAGE_SIZE) { |
2543 | c294fc58 | j_mayer | cpu_abort(env, "TLB size %u < %u are not supported (%d)\n",
|
2544 | c294fc58 | j_mayer | tlb->size, TARGET_PAGE_SIZE, (int)((T1 >> 7) & 0x7)); |
2545 | c294fc58 | j_mayer | } |
2546 | 76a66253 | j_mayer | tlb->EPN = (T1 & 0xFFFFFC00) & ~(tlb->size - 1); |
2547 | c55e9aef | j_mayer | if (T1 & 0x40) |
2548 | 76a66253 | j_mayer | tlb->prot |= PAGE_VALID; |
2549 | 76a66253 | j_mayer | else
|
2550 | 76a66253 | j_mayer | tlb->prot &= ~PAGE_VALID; |
2551 | c294fc58 | j_mayer | if (T1 & 0x20) { |
2552 | c294fc58 | j_mayer | /* XXX: TO BE FIXED */
|
2553 | c294fc58 | j_mayer | cpu_abort(env, "Little-endian TLB entries are not supported by now\n");
|
2554 | c294fc58 | j_mayer | } |
2555 | c55e9aef | j_mayer | tlb->PID = env->spr[SPR_40x_PID]; /* PID */
|
2556 | a8dea12f | j_mayer | tlb->attr = T1 & 0xFF;
|
2557 | c55e9aef | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
2558 | c294fc58 | j_mayer | if (loglevel != 0) { |
2559 | c294fc58 | j_mayer | fprintf(logfile, "%s: set up TLB %d RPN " PADDRX " EPN " ADDRX |
2560 | c55e9aef | j_mayer | " size " ADDRX " prot %c%c%c%c PID %d\n", __func__, |
2561 | c55e9aef | j_mayer | (int)T0, tlb->RPN, tlb->EPN, tlb->size,
|
2562 | c55e9aef | j_mayer | tlb->prot & PAGE_READ ? 'r' : '-', |
2563 | c55e9aef | j_mayer | tlb->prot & PAGE_WRITE ? 'w' : '-', |
2564 | c55e9aef | j_mayer | tlb->prot & PAGE_EXEC ? 'x' : '-', |
2565 | c55e9aef | j_mayer | tlb->prot & PAGE_VALID ? 'v' : '-', (int)tlb->PID); |
2566 | c55e9aef | j_mayer | } |
2567 | c55e9aef | j_mayer | #endif
|
2568 | 76a66253 | j_mayer | /* Invalidate new TLB (if valid) */
|
2569 | 76a66253 | j_mayer | if (tlb->prot & PAGE_VALID) {
|
2570 | 76a66253 | j_mayer | end = tlb->EPN + tlb->size; |
2571 | c55e9aef | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
2572 | 6b80055d | j_mayer | if (loglevel != 0) { |
2573 | c55e9aef | j_mayer | fprintf(logfile, "%s: invalidate TLB %d start " ADDRX
|
2574 | c55e9aef | j_mayer | " end " ADDRX "\n", __func__, (int)T0, tlb->EPN, end); |
2575 | c55e9aef | j_mayer | } |
2576 | c55e9aef | j_mayer | #endif
|
2577 | 76a66253 | j_mayer | for (page = tlb->EPN; page < end; page += TARGET_PAGE_SIZE)
|
2578 | 76a66253 | j_mayer | tlb_flush_page(env, page); |
2579 | 76a66253 | j_mayer | } |
2580 | 76a66253 | j_mayer | } |
2581 | 76a66253 | j_mayer | |
2582 | c55e9aef | j_mayer | void do_4xx_tlbwe_lo (void) |
2583 | 76a66253 | j_mayer | { |
2584 | a8dea12f | j_mayer | ppcemb_tlb_t *tlb; |
2585 | 76a66253 | j_mayer | |
2586 | c55e9aef | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
2587 | 6b80055d | j_mayer | if (loglevel != 0) { |
2588 | c55e9aef | j_mayer | fprintf(logfile, "%s T0 " REGX " T1 " REGX "\n", __func__, T0, T1); |
2589 | c55e9aef | j_mayer | } |
2590 | c55e9aef | j_mayer | #endif
|
2591 | 76a66253 | j_mayer | T0 &= 0x3F;
|
2592 | a8dea12f | j_mayer | tlb = &env->tlb[T0].tlbe; |
2593 | 76a66253 | j_mayer | tlb->RPN = T1 & 0xFFFFFC00;
|
2594 | 76a66253 | j_mayer | tlb->prot = PAGE_READ; |
2595 | 76a66253 | j_mayer | if (T1 & 0x200) |
2596 | 76a66253 | j_mayer | tlb->prot |= PAGE_EXEC; |
2597 | 76a66253 | j_mayer | if (T1 & 0x100) |
2598 | 76a66253 | j_mayer | tlb->prot |= PAGE_WRITE; |
2599 | c55e9aef | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
2600 | 6b80055d | j_mayer | if (loglevel != 0) { |
2601 | 6b80055d | j_mayer | fprintf(logfile, "%s: set up TLB %d RPN " PADDRX " EPN " ADDRX |
2602 | c55e9aef | j_mayer | " size " ADDRX " prot %c%c%c%c PID %d\n", __func__, |
2603 | c55e9aef | j_mayer | (int)T0, tlb->RPN, tlb->EPN, tlb->size,
|
2604 | c55e9aef | j_mayer | tlb->prot & PAGE_READ ? 'r' : '-', |
2605 | c55e9aef | j_mayer | tlb->prot & PAGE_WRITE ? 'w' : '-', |
2606 | c55e9aef | j_mayer | tlb->prot & PAGE_EXEC ? 'x' : '-', |
2607 | c55e9aef | j_mayer | tlb->prot & PAGE_VALID ? 'v' : '-', (int)tlb->PID); |
2608 | c55e9aef | j_mayer | } |
2609 | c55e9aef | j_mayer | #endif
|
2610 | 76a66253 | j_mayer | } |
2611 | 76a66253 | j_mayer | #endif /* !CONFIG_USER_ONLY */ |