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