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