Statistics
| Branch: | Revision:

root / target-ppc / op_helper.c @ 3a607854

History | View | Annotate | Download (58.7 kB)

1 9a64fbe4 bellard
/*
2 3fc6c082 bellard
 *  PowerPC emulation helpers for qemu.
3 9a64fbe4 bellard
 * 
4 76a66253 j_mayer
 *  Copyright (c) 2003-2007 Jocelyn Mayer
5 9a64fbe4 bellard
 *
6 9a64fbe4 bellard
 * This library is free software; you can redistribute it and/or
7 9a64fbe4 bellard
 * modify it under the terms of the GNU Lesser General Public
8 9a64fbe4 bellard
 * License as published by the Free Software Foundation; either
9 9a64fbe4 bellard
 * version 2 of the License, or (at your option) any later version.
10 9a64fbe4 bellard
 *
11 9a64fbe4 bellard
 * This library is distributed in the hope that it will be useful,
12 9a64fbe4 bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 9a64fbe4 bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 9a64fbe4 bellard
 * Lesser General Public License for more details.
15 9a64fbe4 bellard
 *
16 9a64fbe4 bellard
 * You should have received a copy of the GNU Lesser General Public
17 9a64fbe4 bellard
 * License along with this library; if not, write to the Free Software
18 9a64fbe4 bellard
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 9a64fbe4 bellard
 */
20 9a64fbe4 bellard
#include "exec.h"
21 9a64fbe4 bellard
22 0487d6a8 j_mayer
#include "op_helper.h"
23 0487d6a8 j_mayer
24 9a64fbe4 bellard
#define MEMSUFFIX _raw
25 0487d6a8 j_mayer
#include "op_helper.h"
26 9a64fbe4 bellard
#include "op_helper_mem.h"
27 a541f297 bellard
#if !defined(CONFIG_USER_ONLY)
28 9a64fbe4 bellard
#define MEMSUFFIX _user
29 0487d6a8 j_mayer
#include "op_helper.h"
30 9a64fbe4 bellard
#include "op_helper_mem.h"
31 9a64fbe4 bellard
#define MEMSUFFIX _kernel
32 0487d6a8 j_mayer
#include "op_helper.h"
33 9a64fbe4 bellard
#include "op_helper_mem.h"
34 9a64fbe4 bellard
#endif
35 9a64fbe4 bellard
36 fdabc366 bellard
//#define DEBUG_OP
37 fdabc366 bellard
//#define DEBUG_EXCEPTIONS
38 76a66253 j_mayer
//#define DEBUG_SOFTWARE_TLB
39 fdabc366 bellard
//#define FLUSH_ALL_TLBS
40 fdabc366 bellard
41 9a64fbe4 bellard
/*****************************************************************************/
42 9a64fbe4 bellard
/* Exceptions processing helpers */
43 76a66253 j_mayer
void cpu_loop_exit (void)
44 9a64fbe4 bellard
{
45 9fddaa0c bellard
    longjmp(env->jmp_env, 1);
46 9a64fbe4 bellard
}
47 9a64fbe4 bellard
48 9fddaa0c bellard
void do_raise_exception_err (uint32_t exception, int error_code)
49 9a64fbe4 bellard
{
50 9fddaa0c bellard
#if 0
51 9fddaa0c bellard
    printf("Raise exception %3x code : %d\n", exception, error_code);
52 9fddaa0c bellard
#endif
53 9fddaa0c bellard
    switch (exception) {
54 9fddaa0c bellard
    case EXCP_PROGRAM:
55 76a66253 j_mayer
        if (error_code == EXCP_FP && msr_fe0 == 0 && msr_fe1 == 0)
56 76a66253 j_mayer
            return;
57 76a66253 j_mayer
        break;
58 9fddaa0c bellard
    default:
59 76a66253 j_mayer
        break;
60 76a66253 j_mayer
    }
61 9fddaa0c bellard
    env->exception_index = exception;
62 9fddaa0c bellard
    env->error_code = error_code;
63 76a66253 j_mayer
    cpu_loop_exit();
64 76a66253 j_mayer
}
65 9fddaa0c bellard
66 9fddaa0c bellard
void do_raise_exception (uint32_t exception)
67 9fddaa0c bellard
{
68 9fddaa0c bellard
    do_raise_exception_err(exception, 0);
69 9a64fbe4 bellard
}
70 9a64fbe4 bellard
71 a496775f j_mayer
void cpu_dump_EA (target_ulong EA);
72 a496775f j_mayer
void do_print_mem_EA (target_ulong EA)
73 a496775f j_mayer
{
74 a496775f j_mayer
    cpu_dump_EA(EA);
75 a496775f j_mayer
}
76 a496775f j_mayer
77 9a64fbe4 bellard
/*****************************************************************************/
78 76a66253 j_mayer
/* Registers load and stores */
79 76a66253 j_mayer
void do_load_cr (void)
80 76a66253 j_mayer
{
81 76a66253 j_mayer
    T0 = (env->crf[0] << 28) |
82 76a66253 j_mayer
        (env->crf[1] << 24) |
83 76a66253 j_mayer
        (env->crf[2] << 20) |
84 76a66253 j_mayer
        (env->crf[3] << 16) |
85 76a66253 j_mayer
        (env->crf[4] << 12) |
86 76a66253 j_mayer
        (env->crf[5] << 8) |
87 76a66253 j_mayer
        (env->crf[6] << 4) |
88 76a66253 j_mayer
        (env->crf[7] << 0);
89 76a66253 j_mayer
}
90 76a66253 j_mayer
91 76a66253 j_mayer
void do_store_cr (uint32_t mask)
92 76a66253 j_mayer
{
93 76a66253 j_mayer
    int i, sh;
94 76a66253 j_mayer
95 76a66253 j_mayer
    for (i = 0, sh = 7; i < 8; i++, sh --) {
96 76a66253 j_mayer
        if (mask & (1 << sh))
97 76a66253 j_mayer
            env->crf[i] = (T0 >> (sh * 4)) & 0xFUL;
98 76a66253 j_mayer
    }
99 76a66253 j_mayer
}
100 76a66253 j_mayer
101 76a66253 j_mayer
void do_load_xer (void)
102 76a66253 j_mayer
{
103 76a66253 j_mayer
    T0 = (xer_so << XER_SO) |
104 76a66253 j_mayer
        (xer_ov << XER_OV) |
105 76a66253 j_mayer
        (xer_ca << XER_CA) |
106 76a66253 j_mayer
        (xer_bc << XER_BC) |
107 76a66253 j_mayer
        (xer_cmp << XER_CMP);
108 76a66253 j_mayer
}
109 76a66253 j_mayer
110 76a66253 j_mayer
void do_store_xer (void)
111 76a66253 j_mayer
{
112 76a66253 j_mayer
    xer_so = (T0 >> XER_SO) & 0x01;
113 76a66253 j_mayer
    xer_ov = (T0 >> XER_OV) & 0x01;
114 76a66253 j_mayer
    xer_ca = (T0 >> XER_CA) & 0x01;
115 76a66253 j_mayer
    xer_cmp = (T0 >> XER_CMP) & 0xFF;
116 d9bce9d9 j_mayer
    xer_bc = (T0 >> XER_BC) & 0x7F;
117 76a66253 j_mayer
}
118 76a66253 j_mayer
119 76a66253 j_mayer
void do_load_fpscr (void)
120 76a66253 j_mayer
{
121 76a66253 j_mayer
    /* The 32 MSB of the target fpr are undefined.
122 76a66253 j_mayer
     * They'll be zero...
123 76a66253 j_mayer
     */
124 76a66253 j_mayer
    union {
125 76a66253 j_mayer
        float64 d;
126 76a66253 j_mayer
        struct {
127 76a66253 j_mayer
            uint32_t u[2];
128 76a66253 j_mayer
        } s;
129 76a66253 j_mayer
    } u;
130 76a66253 j_mayer
    int i;
131 76a66253 j_mayer
132 d9bce9d9 j_mayer
#if defined(WORDS_BIGENDIAN)
133 76a66253 j_mayer
#define WORD0 0
134 76a66253 j_mayer
#define WORD1 1
135 76a66253 j_mayer
#else
136 76a66253 j_mayer
#define WORD0 1
137 76a66253 j_mayer
#define WORD1 0
138 76a66253 j_mayer
#endif
139 76a66253 j_mayer
    u.s.u[WORD0] = 0;
140 76a66253 j_mayer
    u.s.u[WORD1] = 0;
141 76a66253 j_mayer
    for (i = 0; i < 8; i++)
142 76a66253 j_mayer
        u.s.u[WORD1] |= env->fpscr[i] << (4 * i);
143 76a66253 j_mayer
    FT0 = u.d;
144 76a66253 j_mayer
}
145 76a66253 j_mayer
146 76a66253 j_mayer
void do_store_fpscr (uint32_t mask)
147 76a66253 j_mayer
{
148 76a66253 j_mayer
    /*
149 76a66253 j_mayer
     * We use only the 32 LSB of the incoming fpr
150 76a66253 j_mayer
     */
151 76a66253 j_mayer
    union {
152 76a66253 j_mayer
        double d;
153 76a66253 j_mayer
        struct {
154 76a66253 j_mayer
            uint32_t u[2];
155 76a66253 j_mayer
        } s;
156 76a66253 j_mayer
    } u;
157 76a66253 j_mayer
    int i, rnd_type;
158 76a66253 j_mayer
159 76a66253 j_mayer
    u.d = FT0;
160 76a66253 j_mayer
    if (mask & 0x80)
161 76a66253 j_mayer
        env->fpscr[0] = (env->fpscr[0] & 0x9) | ((u.s.u[WORD1] >> 28) & ~0x9);
162 76a66253 j_mayer
    for (i = 1; i < 7; i++) {
163 76a66253 j_mayer
        if (mask & (1 << (7 - i)))
164 76a66253 j_mayer
            env->fpscr[i] = (u.s.u[WORD1] >> (4 * (7 - i))) & 0xF;
165 76a66253 j_mayer
    }
166 76a66253 j_mayer
    /* TODO: update FEX & VX */
167 76a66253 j_mayer
    /* Set rounding mode */
168 76a66253 j_mayer
    switch (env->fpscr[0] & 0x3) {
169 76a66253 j_mayer
    case 0:
170 76a66253 j_mayer
        /* Best approximation (round to nearest) */
171 76a66253 j_mayer
        rnd_type = float_round_nearest_even;
172 76a66253 j_mayer
        break;
173 76a66253 j_mayer
    case 1:
174 76a66253 j_mayer
        /* Smaller magnitude (round toward zero) */
175 76a66253 j_mayer
        rnd_type = float_round_to_zero;
176 76a66253 j_mayer
        break;
177 76a66253 j_mayer
    case 2:
178 76a66253 j_mayer
        /* Round toward +infinite */
179 76a66253 j_mayer
        rnd_type = float_round_up;
180 76a66253 j_mayer
        break;
181 76a66253 j_mayer
    default:
182 76a66253 j_mayer
    case 3:
183 76a66253 j_mayer
        /* Round toward -infinite */
184 76a66253 j_mayer
        rnd_type = float_round_down;
185 76a66253 j_mayer
        break;
186 76a66253 j_mayer
    }
187 76a66253 j_mayer
    set_float_rounding_mode(rnd_type, &env->fp_status);
188 76a66253 j_mayer
}
189 76a66253 j_mayer
190 a496775f j_mayer
target_ulong ppc_load_dump_spr (int sprn)
191 a496775f j_mayer
{
192 a496775f j_mayer
    if (loglevel) {
193 a496775f j_mayer
        fprintf(logfile, "Read SPR %d %03x => " ADDRX "\n",
194 a496775f j_mayer
                sprn, sprn, env->spr[sprn]);
195 a496775f j_mayer
    }
196 a496775f j_mayer
197 a496775f j_mayer
    return env->spr[sprn];
198 a496775f j_mayer
}
199 a496775f j_mayer
200 a496775f j_mayer
void ppc_store_dump_spr (int sprn, target_ulong val)
201 a496775f j_mayer
{
202 a496775f j_mayer
    if (loglevel) {
203 a496775f j_mayer
        fprintf(logfile, "Write SPR %d %03x => " ADDRX " <= " ADDRX "\n",
204 a496775f j_mayer
                sprn, sprn, env->spr[sprn], val);
205 a496775f j_mayer
    }
206 a496775f j_mayer
    env->spr[sprn] = val;
207 a496775f j_mayer
}
208 a496775f j_mayer
209 76a66253 j_mayer
/*****************************************************************************/
210 fdabc366 bellard
/* Fixed point operations helpers */
211 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
212 d9bce9d9 j_mayer
static void add128 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
213 fdabc366 bellard
{
214 d9bce9d9 j_mayer
    *plow += a;
215 d9bce9d9 j_mayer
    /* carry test */
216 d9bce9d9 j_mayer
    if (*plow < a)
217 d9bce9d9 j_mayer
        (*phigh)++;
218 d9bce9d9 j_mayer
    *phigh += b;
219 fdabc366 bellard
}
220 fdabc366 bellard
221 d9bce9d9 j_mayer
static void neg128 (uint64_t *plow, uint64_t *phigh)
222 fdabc366 bellard
{
223 d9bce9d9 j_mayer
    *plow = ~ *plow;
224 d9bce9d9 j_mayer
    *phigh = ~ *phigh;
225 d9bce9d9 j_mayer
    add128(plow, phigh, 1, 0);
226 d9bce9d9 j_mayer
}
227 d9bce9d9 j_mayer
228 d9bce9d9 j_mayer
static void mul64 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
229 d9bce9d9 j_mayer
{
230 d9bce9d9 j_mayer
    uint32_t a0, a1, b0, b1;
231 d9bce9d9 j_mayer
    uint64_t v;
232 d9bce9d9 j_mayer
233 d9bce9d9 j_mayer
    a0 = a;
234 d9bce9d9 j_mayer
    a1 = a >> 32;
235 d9bce9d9 j_mayer
236 d9bce9d9 j_mayer
    b0 = b;
237 d9bce9d9 j_mayer
    b1 = b >> 32;
238 d9bce9d9 j_mayer
    
239 d9bce9d9 j_mayer
    v = (uint64_t)a0 * (uint64_t)b0;
240 d9bce9d9 j_mayer
    *plow = v;
241 d9bce9d9 j_mayer
    *phigh = 0;
242 d9bce9d9 j_mayer
243 d9bce9d9 j_mayer
    v = (uint64_t)a0 * (uint64_t)b1;
244 d9bce9d9 j_mayer
    add128(plow, phigh, v << 32, v >> 32);
245 d9bce9d9 j_mayer
246 d9bce9d9 j_mayer
    v = (uint64_t)a1 * (uint64_t)b0;
247 d9bce9d9 j_mayer
    add128(plow, phigh, v << 32, v >> 32);
248 d9bce9d9 j_mayer
249 d9bce9d9 j_mayer
    v = (uint64_t)a1 * (uint64_t)b1;
250 d9bce9d9 j_mayer
    *phigh += v;
251 d9bce9d9 j_mayer
#if defined(DEBUG_MULDIV)
252 d9bce9d9 j_mayer
    printf("mul: 0x%016llx * 0x%016llx = 0x%016llx%016llx\n",
253 d9bce9d9 j_mayer
           a, b, *phigh, *plow);
254 d9bce9d9 j_mayer
#endif
255 d9bce9d9 j_mayer
}
256 d9bce9d9 j_mayer
257 d9bce9d9 j_mayer
void do_mul64 (uint64_t *plow, uint64_t *phigh)
258 d9bce9d9 j_mayer
{
259 d9bce9d9 j_mayer
    mul64(plow, phigh, T0, T1);
260 d9bce9d9 j_mayer
}
261 d9bce9d9 j_mayer
262 0487d6a8 j_mayer
static void imul64 (uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b)
263 d9bce9d9 j_mayer
{
264 d9bce9d9 j_mayer
    int sa, sb;
265 d9bce9d9 j_mayer
    sa = (a < 0);
266 d9bce9d9 j_mayer
    if (sa)
267 d9bce9d9 j_mayer
        a = -a;
268 d9bce9d9 j_mayer
    sb = (b < 0);
269 d9bce9d9 j_mayer
    if (sb)
270 d9bce9d9 j_mayer
        b = -b;
271 d9bce9d9 j_mayer
    mul64(plow, phigh, a, b);
272 d9bce9d9 j_mayer
    if (sa ^ sb) {
273 d9bce9d9 j_mayer
        neg128(plow, phigh);
274 fdabc366 bellard
    }
275 fdabc366 bellard
}
276 fdabc366 bellard
277 d9bce9d9 j_mayer
void do_imul64 (uint64_t *plow, uint64_t *phigh)
278 d9bce9d9 j_mayer
{
279 d9bce9d9 j_mayer
    imul64(plow, phigh, T0, T1);
280 d9bce9d9 j_mayer
}
281 d9bce9d9 j_mayer
#endif
282 d9bce9d9 j_mayer
283 fdabc366 bellard
void do_adde (void)
284 fdabc366 bellard
{
285 fdabc366 bellard
    T2 = T0;
286 fdabc366 bellard
    T0 += T1 + xer_ca;
287 d9bce9d9 j_mayer
    if (likely(!((uint32_t)T0 < (uint32_t)T2 ||
288 d9bce9d9 j_mayer
                 (xer_ca == 1 && (uint32_t)T0 == (uint32_t)T2)))) {
289 fdabc366 bellard
        xer_ca = 0;
290 fdabc366 bellard
    } else {
291 fdabc366 bellard
        xer_ca = 1;
292 fdabc366 bellard
    }
293 fdabc366 bellard
}
294 fdabc366 bellard
295 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
296 d9bce9d9 j_mayer
void do_adde_64 (void)
297 fdabc366 bellard
{
298 fdabc366 bellard
    T2 = T0;
299 fdabc366 bellard
    T0 += T1 + xer_ca;
300 d9bce9d9 j_mayer
    if (likely(!((uint64_t)T0 < (uint64_t)T2 ||
301 d9bce9d9 j_mayer
                 (xer_ca == 1 && (uint64_t)T0 == (uint64_t)T2)))) {
302 fdabc366 bellard
        xer_ca = 0;
303 fdabc366 bellard
    } else {
304 fdabc366 bellard
        xer_ca = 1;
305 fdabc366 bellard
    }
306 fdabc366 bellard
}
307 d9bce9d9 j_mayer
#endif
308 fdabc366 bellard
309 fdabc366 bellard
void do_addmeo (void)
310 fdabc366 bellard
{
311 fdabc366 bellard
    T1 = T0;
312 fdabc366 bellard
    T0 += xer_ca + (-1);
313 d9bce9d9 j_mayer
    if (likely(!((uint32_t)T1 &
314 d9bce9d9 j_mayer
                 ((uint32_t)T1 ^ (uint32_t)T0) & (1UL << 31)))) {
315 fdabc366 bellard
        xer_ov = 0;
316 fdabc366 bellard
    } else {
317 fdabc366 bellard
        xer_so = 1;
318 fdabc366 bellard
        xer_ov = 1;
319 fdabc366 bellard
    }
320 fdabc366 bellard
    if (likely(T1 != 0))
321 fdabc366 bellard
        xer_ca = 1;
322 fdabc366 bellard
}
323 fdabc366 bellard
324 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
325 d9bce9d9 j_mayer
void do_addmeo_64 (void)
326 fdabc366 bellard
{
327 fdabc366 bellard
    T1 = T0;
328 d9bce9d9 j_mayer
    T0 += xer_ca + (-1);
329 d9bce9d9 j_mayer
    if (likely(!((uint64_t)T1 &
330 d9bce9d9 j_mayer
                 ((uint64_t)T1 ^ (uint64_t)T0) & (1ULL << 63)))) {
331 fdabc366 bellard
        xer_ov = 0;
332 fdabc366 bellard
    } else {
333 fdabc366 bellard
        xer_so = 1;
334 fdabc366 bellard
        xer_ov = 1;
335 fdabc366 bellard
    }
336 d9bce9d9 j_mayer
    if (likely(T1 != 0))
337 fdabc366 bellard
        xer_ca = 1;
338 fdabc366 bellard
}
339 d9bce9d9 j_mayer
#endif
340 fdabc366 bellard
341 fdabc366 bellard
void do_divwo (void)
342 fdabc366 bellard
{
343 d9bce9d9 j_mayer
    if (likely(!(((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) ||
344 d9bce9d9 j_mayer
                 (int32_t)T1 == 0))) {
345 fdabc366 bellard
        xer_ov = 0;
346 d9bce9d9 j_mayer
        T0 = (int32_t)T0 / (int32_t)T1;
347 fdabc366 bellard
    } else {
348 fdabc366 bellard
        xer_so = 1;
349 fdabc366 bellard
        xer_ov = 1;
350 fdabc366 bellard
        T0 = (-1) * ((uint32_t)T0 >> 31);
351 fdabc366 bellard
    }
352 fdabc366 bellard
}
353 fdabc366 bellard
354 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
355 d9bce9d9 j_mayer
void do_divdo (void)
356 d9bce9d9 j_mayer
{
357 d9bce9d9 j_mayer
    if (likely(!(((int64_t)T0 == INT64_MIN && (int64_t)T1 == -1ULL) ||
358 d9bce9d9 j_mayer
                 (int64_t)T1 == 0))) {
359 d9bce9d9 j_mayer
        xer_ov = 0;
360 d9bce9d9 j_mayer
        T0 = (int64_t)T0 / (int64_t)T1;
361 d9bce9d9 j_mayer
    } else {
362 d9bce9d9 j_mayer
        xer_so = 1;
363 d9bce9d9 j_mayer
        xer_ov = 1;
364 d9bce9d9 j_mayer
        T0 = (-1ULL) * ((uint64_t)T0 >> 63);
365 d9bce9d9 j_mayer
    }
366 d9bce9d9 j_mayer
}
367 d9bce9d9 j_mayer
#endif
368 d9bce9d9 j_mayer
369 fdabc366 bellard
void do_divwuo (void)
370 fdabc366 bellard
{
371 fdabc366 bellard
    if (likely((uint32_t)T1 != 0)) {
372 fdabc366 bellard
        xer_ov = 0;
373 fdabc366 bellard
        T0 = (uint32_t)T0 / (uint32_t)T1;
374 fdabc366 bellard
    } else {
375 fdabc366 bellard
        xer_so = 1;
376 fdabc366 bellard
        xer_ov = 1;
377 fdabc366 bellard
        T0 = 0;
378 fdabc366 bellard
    }
379 fdabc366 bellard
}
380 fdabc366 bellard
381 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
382 d9bce9d9 j_mayer
void do_divduo (void)
383 d9bce9d9 j_mayer
{
384 d9bce9d9 j_mayer
    if (likely((uint64_t)T1 != 0)) {
385 d9bce9d9 j_mayer
        xer_ov = 0;
386 d9bce9d9 j_mayer
        T0 = (uint64_t)T0 / (uint64_t)T1;
387 d9bce9d9 j_mayer
    } else {
388 d9bce9d9 j_mayer
        xer_so = 1;
389 d9bce9d9 j_mayer
        xer_ov = 1;
390 d9bce9d9 j_mayer
        T0 = 0;
391 d9bce9d9 j_mayer
    }
392 d9bce9d9 j_mayer
}
393 d9bce9d9 j_mayer
#endif
394 d9bce9d9 j_mayer
395 fdabc366 bellard
void do_mullwo (void)
396 fdabc366 bellard
{
397 d9bce9d9 j_mayer
    int64_t res = (int64_t)T0 * (int64_t)T1;
398 fdabc366 bellard
399 fdabc366 bellard
    if (likely((int32_t)res == res)) {
400 fdabc366 bellard
        xer_ov = 0;
401 fdabc366 bellard
    } else {
402 fdabc366 bellard
        xer_ov = 1;
403 fdabc366 bellard
        xer_so = 1;
404 fdabc366 bellard
    }
405 fdabc366 bellard
    T0 = (int32_t)res;
406 fdabc366 bellard
}
407 fdabc366 bellard
408 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
409 d9bce9d9 j_mayer
void do_mulldo (void)
410 fdabc366 bellard
{
411 d9bce9d9 j_mayer
    int64_t th;
412 d9bce9d9 j_mayer
    uint64_t tl;
413 d9bce9d9 j_mayer
414 d9bce9d9 j_mayer
    do_imul64(&tl, &th);
415 d9bce9d9 j_mayer
    if (likely(th == 0)) {
416 fdabc366 bellard
        xer_ov = 0;
417 fdabc366 bellard
    } else {
418 fdabc366 bellard
        xer_ov = 1;
419 fdabc366 bellard
        xer_so = 1;
420 fdabc366 bellard
    }
421 d9bce9d9 j_mayer
    T0 = (int64_t)tl;
422 fdabc366 bellard
}
423 d9bce9d9 j_mayer
#endif
424 fdabc366 bellard
425 d9bce9d9 j_mayer
void do_nego (void)
426 fdabc366 bellard
{
427 d9bce9d9 j_mayer
    if (likely((int32_t)T0 != INT32_MIN)) {
428 fdabc366 bellard
        xer_ov = 0;
429 d9bce9d9 j_mayer
        T0 = -(int32_t)T0;
430 fdabc366 bellard
    } else {
431 fdabc366 bellard
        xer_ov = 1;
432 d9bce9d9 j_mayer
        xer_so = 1;
433 fdabc366 bellard
    }
434 fdabc366 bellard
}
435 fdabc366 bellard
436 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
437 d9bce9d9 j_mayer
void do_nego_64 (void)
438 fdabc366 bellard
{
439 d9bce9d9 j_mayer
    if (likely((int64_t)T0 != INT64_MIN)) {
440 fdabc366 bellard
        xer_ov = 0;
441 d9bce9d9 j_mayer
        T0 = -(int64_t)T0;
442 fdabc366 bellard
    } else {
443 fdabc366 bellard
        xer_ov = 1;
444 d9bce9d9 j_mayer
        xer_so = 1;
445 fdabc366 bellard
    }
446 fdabc366 bellard
}
447 d9bce9d9 j_mayer
#endif
448 fdabc366 bellard
449 fdabc366 bellard
void do_subfe (void)
450 fdabc366 bellard
{
451 fdabc366 bellard
    T0 = T1 + ~T0 + xer_ca;
452 d9bce9d9 j_mayer
    if (likely((uint32_t)T0 >= (uint32_t)T1 &&
453 d9bce9d9 j_mayer
               (xer_ca == 0 || (uint32_t)T0 != (uint32_t)T1))) {
454 fdabc366 bellard
        xer_ca = 0;
455 fdabc366 bellard
    } else {
456 fdabc366 bellard
        xer_ca = 1;
457 fdabc366 bellard
    }
458 fdabc366 bellard
}
459 fdabc366 bellard
460 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
461 d9bce9d9 j_mayer
void do_subfe_64 (void)
462 fdabc366 bellard
{
463 fdabc366 bellard
    T0 = T1 + ~T0 + xer_ca;
464 d9bce9d9 j_mayer
    if (likely((uint64_t)T0 >= (uint64_t)T1 &&
465 d9bce9d9 j_mayer
               (xer_ca == 0 || (uint64_t)T0 != (uint64_t)T1))) {
466 d9bce9d9 j_mayer
        xer_ca = 0;
467 d9bce9d9 j_mayer
    } else {
468 d9bce9d9 j_mayer
        xer_ca = 1;
469 d9bce9d9 j_mayer
    }
470 d9bce9d9 j_mayer
}
471 d9bce9d9 j_mayer
#endif
472 d9bce9d9 j_mayer
473 d9bce9d9 j_mayer
void do_subfmeo (void)
474 d9bce9d9 j_mayer
{
475 d9bce9d9 j_mayer
    T1 = T0;
476 d9bce9d9 j_mayer
    T0 = ~T0 + xer_ca - 1;
477 d9bce9d9 j_mayer
    if (likely(!((uint32_t)~T1 & ((uint32_t)~T1 ^ (uint32_t)T0) &
478 d9bce9d9 j_mayer
                 (1UL << 31)))) {
479 fdabc366 bellard
        xer_ov = 0;
480 fdabc366 bellard
    } else {
481 fdabc366 bellard
        xer_so = 1;
482 fdabc366 bellard
        xer_ov = 1;
483 fdabc366 bellard
    }
484 d9bce9d9 j_mayer
    if (likely((uint32_t)T1 != UINT32_MAX))
485 fdabc366 bellard
        xer_ca = 1;
486 fdabc366 bellard
}
487 fdabc366 bellard
488 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
489 d9bce9d9 j_mayer
void do_subfmeo_64 (void)
490 fdabc366 bellard
{
491 fdabc366 bellard
    T1 = T0;
492 fdabc366 bellard
    T0 = ~T0 + xer_ca - 1;
493 d9bce9d9 j_mayer
    if (likely(!((uint64_t)~T1 & ((uint64_t)~T1 ^ (uint64_t)T0) &
494 d9bce9d9 j_mayer
                 (1ULL << 63)))) {
495 fdabc366 bellard
        xer_ov = 0;
496 fdabc366 bellard
    } else {
497 fdabc366 bellard
        xer_so = 1;
498 fdabc366 bellard
        xer_ov = 1;
499 fdabc366 bellard
    }
500 d9bce9d9 j_mayer
    if (likely((uint64_t)T1 != UINT64_MAX))
501 fdabc366 bellard
        xer_ca = 1;
502 fdabc366 bellard
}
503 d9bce9d9 j_mayer
#endif
504 fdabc366 bellard
505 fdabc366 bellard
void do_subfzeo (void)
506 fdabc366 bellard
{
507 fdabc366 bellard
    T1 = T0;
508 fdabc366 bellard
    T0 = ~T0 + xer_ca;
509 d9bce9d9 j_mayer
    if (likely(!(((uint32_t)~T1 ^ UINT32_MAX) &
510 d9bce9d9 j_mayer
                 ((uint32_t)(~T1) ^ (uint32_t)T0) & (1UL << 31)))) {
511 fdabc366 bellard
        xer_ov = 0;
512 fdabc366 bellard
    } else {
513 fdabc366 bellard
        xer_ov = 1;
514 fdabc366 bellard
        xer_so = 1;
515 fdabc366 bellard
    }
516 d9bce9d9 j_mayer
    if (likely((uint32_t)T0 >= (uint32_t)~T1)) {
517 fdabc366 bellard
        xer_ca = 0;
518 fdabc366 bellard
    } else {
519 fdabc366 bellard
        xer_ca = 1;
520 fdabc366 bellard
    }
521 fdabc366 bellard
}
522 fdabc366 bellard
523 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
524 d9bce9d9 j_mayer
void do_subfzeo_64 (void)
525 d9bce9d9 j_mayer
{
526 d9bce9d9 j_mayer
    T1 = T0;
527 d9bce9d9 j_mayer
    T0 = ~T0 + xer_ca;
528 d9bce9d9 j_mayer
    if (likely(!(((uint64_t)~T1 ^ UINT64_MAX) &
529 d9bce9d9 j_mayer
                 ((uint64_t)(~T1) ^ (uint64_t)T0) & (1ULL << 63)))) {
530 d9bce9d9 j_mayer
        xer_ov = 0;
531 d9bce9d9 j_mayer
    } else {
532 d9bce9d9 j_mayer
        xer_ov = 1;
533 d9bce9d9 j_mayer
        xer_so = 1;
534 d9bce9d9 j_mayer
    }
535 d9bce9d9 j_mayer
    if (likely((uint64_t)T0 >= (uint64_t)~T1)) {
536 d9bce9d9 j_mayer
        xer_ca = 0;
537 d9bce9d9 j_mayer
    } else {
538 d9bce9d9 j_mayer
        xer_ca = 1;
539 d9bce9d9 j_mayer
    }
540 d9bce9d9 j_mayer
}
541 d9bce9d9 j_mayer
#endif
542 d9bce9d9 j_mayer
543 9a64fbe4 bellard
/* shift right arithmetic helper */
544 9a64fbe4 bellard
void do_sraw (void)
545 9a64fbe4 bellard
{
546 9a64fbe4 bellard
    int32_t ret;
547 9a64fbe4 bellard
548 fdabc366 bellard
    if (likely(!(T1 & 0x20UL))) {
549 d9bce9d9 j_mayer
        if (likely((uint32_t)T1 != 0)) {
550 fdabc366 bellard
            ret = (int32_t)T0 >> (T1 & 0x1fUL);
551 fdabc366 bellard
            if (likely(ret >= 0 || ((int32_t)T0 & ((1 << T1) - 1)) == 0)) {
552 76a66253 j_mayer
                xer_ca = 0;
553 fdabc366 bellard
            } else {
554 76a66253 j_mayer
                xer_ca = 1;
555 fdabc366 bellard
            }
556 fdabc366 bellard
        } else {
557 76a66253 j_mayer
            ret = T0;
558 fdabc366 bellard
            xer_ca = 0;
559 fdabc366 bellard
        }
560 fdabc366 bellard
    } else {
561 fdabc366 bellard
        ret = (-1) * ((uint32_t)T0 >> 31);
562 fdabc366 bellard
        if (likely(ret >= 0 || ((uint32_t)T0 & ~0x80000000UL) == 0)) {
563 fdabc366 bellard
            xer_ca = 0;
564 76a66253 j_mayer
        } else {
565 9a64fbe4 bellard
            xer_ca = 1;
566 76a66253 j_mayer
        }
567 fdabc366 bellard
    }
568 4b3686fa bellard
    T0 = ret;
569 9a64fbe4 bellard
}
570 9a64fbe4 bellard
571 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
572 d9bce9d9 j_mayer
void do_srad (void)
573 d9bce9d9 j_mayer
{
574 d9bce9d9 j_mayer
    int64_t ret;
575 d9bce9d9 j_mayer
576 d9bce9d9 j_mayer
    if (likely(!(T1 & 0x40UL))) {
577 d9bce9d9 j_mayer
        if (likely((uint64_t)T1 != 0)) {
578 d9bce9d9 j_mayer
            ret = (int64_t)T0 >> (T1 & 0x3FUL);
579 d9bce9d9 j_mayer
            if (likely(ret >= 0 || ((int64_t)T0 & ((1 << T1) - 1)) == 0)) {
580 d9bce9d9 j_mayer
                xer_ca = 0;
581 d9bce9d9 j_mayer
            } else {
582 d9bce9d9 j_mayer
                xer_ca = 1;
583 d9bce9d9 j_mayer
            }
584 d9bce9d9 j_mayer
        } else {
585 d9bce9d9 j_mayer
            ret = T0;
586 d9bce9d9 j_mayer
            xer_ca = 0;
587 d9bce9d9 j_mayer
        }
588 d9bce9d9 j_mayer
    } else {
589 d9bce9d9 j_mayer
        ret = (-1) * ((uint64_t)T0 >> 63);
590 d9bce9d9 j_mayer
        if (likely(ret >= 0 || ((uint64_t)T0 & ~0x8000000000000000ULL) == 0)) {
591 d9bce9d9 j_mayer
            xer_ca = 0;
592 d9bce9d9 j_mayer
        } else {
593 d9bce9d9 j_mayer
            xer_ca = 1;
594 d9bce9d9 j_mayer
        }
595 d9bce9d9 j_mayer
    }
596 d9bce9d9 j_mayer
    T0 = ret;
597 d9bce9d9 j_mayer
}
598 d9bce9d9 j_mayer
#endif
599 d9bce9d9 j_mayer
600 d9bce9d9 j_mayer
static inline int popcnt (uint32_t val)
601 d9bce9d9 j_mayer
{
602 d9bce9d9 j_mayer
    int i;
603 d9bce9d9 j_mayer
604 d9bce9d9 j_mayer
    for (i = 0; val != 0;)
605 d9bce9d9 j_mayer
        val = val ^ (val - 1);
606 d9bce9d9 j_mayer
607 d9bce9d9 j_mayer
    return i;
608 d9bce9d9 j_mayer
}
609 d9bce9d9 j_mayer
610 d9bce9d9 j_mayer
void do_popcntb (void)
611 d9bce9d9 j_mayer
{
612 d9bce9d9 j_mayer
    uint32_t ret;
613 d9bce9d9 j_mayer
    int i;
614 d9bce9d9 j_mayer
615 d9bce9d9 j_mayer
    ret = 0;
616 d9bce9d9 j_mayer
    for (i = 0; i < 32; i += 8)
617 d9bce9d9 j_mayer
        ret |= popcnt((T0 >> i) & 0xFF) << i;
618 d9bce9d9 j_mayer
    T0 = ret;
619 d9bce9d9 j_mayer
}
620 d9bce9d9 j_mayer
621 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
622 d9bce9d9 j_mayer
void do_popcntb_64 (void)
623 d9bce9d9 j_mayer
{
624 d9bce9d9 j_mayer
    uint64_t ret;
625 d9bce9d9 j_mayer
    int i;
626 d9bce9d9 j_mayer
627 d9bce9d9 j_mayer
    ret = 0;
628 d9bce9d9 j_mayer
    for (i = 0; i < 64; i += 8)
629 d9bce9d9 j_mayer
        ret |= popcnt((T0 >> i) & 0xFF) << i;
630 d9bce9d9 j_mayer
    T0 = ret;
631 d9bce9d9 j_mayer
}
632 d9bce9d9 j_mayer
#endif
633 d9bce9d9 j_mayer
634 fdabc366 bellard
/*****************************************************************************/
635 9a64fbe4 bellard
/* Floating point operations helpers */
636 9a64fbe4 bellard
void do_fctiw (void)
637 9a64fbe4 bellard
{
638 9a64fbe4 bellard
    union {
639 9a64fbe4 bellard
        double d;
640 9a64fbe4 bellard
        uint64_t i;
641 4ecc3190 bellard
    } p;
642 9a64fbe4 bellard
643 e864cabd j_mayer
    p.i = float64_to_int32(FT0, &env->fp_status);
644 e864cabd j_mayer
#if USE_PRECISE_EMULATION
645 4ecc3190 bellard
    /* XXX: higher bits are not supposed to be significant.
646 76a66253 j_mayer
     *     to make tests easier, return the same as a real PowerPC 750 (aka G3)
647 4ecc3190 bellard
     */
648 4ecc3190 bellard
    p.i |= 0xFFF80000ULL << 32;
649 e864cabd j_mayer
#endif
650 4ecc3190 bellard
    FT0 = p.d;
651 9a64fbe4 bellard
}
652 9a64fbe4 bellard
653 9a64fbe4 bellard
void do_fctiwz (void)
654 9a64fbe4 bellard
{
655 9a64fbe4 bellard
    union {
656 9a64fbe4 bellard
        double d;
657 9a64fbe4 bellard
        uint64_t i;
658 4ecc3190 bellard
    } p;
659 4ecc3190 bellard
660 e864cabd j_mayer
    p.i = float64_to_int32_round_to_zero(FT0, &env->fp_status);
661 e864cabd j_mayer
#if USE_PRECISE_EMULATION
662 4ecc3190 bellard
    /* XXX: higher bits are not supposed to be significant.
663 d9bce9d9 j_mayer
     *     to make tests easier, return the same as a real PowerPC 750 (aka G3)
664 4ecc3190 bellard
     */
665 4ecc3190 bellard
    p.i |= 0xFFF80000ULL << 32;
666 e864cabd j_mayer
#endif
667 4ecc3190 bellard
    FT0 = p.d;
668 9a64fbe4 bellard
}
669 9a64fbe4 bellard
670 426613db j_mayer
#if defined(TARGET_PPC64)
671 426613db j_mayer
void do_fcfid (void)
672 426613db j_mayer
{
673 426613db j_mayer
    union {
674 426613db j_mayer
        double d;
675 426613db j_mayer
        uint64_t i;
676 426613db j_mayer
    } p;
677 426613db j_mayer
678 426613db j_mayer
    p.d = FT0;
679 426613db j_mayer
    FT0 = int64_to_float64(p.i, &env->fp_status);
680 426613db j_mayer
}
681 426613db j_mayer
682 426613db j_mayer
void do_fctid (void)
683 426613db j_mayer
{
684 426613db j_mayer
    union {
685 426613db j_mayer
        double d;
686 426613db j_mayer
        uint64_t i;
687 426613db j_mayer
    } p;
688 426613db j_mayer
689 426613db j_mayer
    p.i = float64_to_int64(FT0, &env->fp_status);
690 426613db j_mayer
    FT0 = p.d;
691 426613db j_mayer
}
692 426613db j_mayer
693 426613db j_mayer
void do_fctidz (void)
694 426613db j_mayer
{
695 426613db j_mayer
    union {
696 426613db j_mayer
        double d;
697 426613db j_mayer
        uint64_t i;
698 426613db j_mayer
    } p;
699 426613db j_mayer
700 426613db j_mayer
    p.i = float64_to_int64_round_to_zero(FT0, &env->fp_status);
701 426613db j_mayer
    FT0 = p.d;
702 426613db j_mayer
}
703 426613db j_mayer
704 426613db j_mayer
#endif
705 426613db j_mayer
706 e864cabd j_mayer
#if USE_PRECISE_EMULATION
707 e864cabd j_mayer
void do_fmadd (void)
708 e864cabd j_mayer
{
709 e864cabd j_mayer
#ifdef FLOAT128
710 e864cabd j_mayer
    float128 ft0_128, ft1_128;
711 e864cabd j_mayer
712 e864cabd j_mayer
    ft0_128 = float64_to_float128(FT0, &env->fp_status);
713 e864cabd j_mayer
    ft1_128 = float64_to_float128(FT1, &env->fp_status);
714 e864cabd j_mayer
    ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status);
715 e864cabd j_mayer
    ft1_128 = float64_to_float128(FT2, &env->fp_status);
716 e864cabd j_mayer
    ft0_128 = float128_add(ft0_128, ft1_128, &env->fp_status);
717 e864cabd j_mayer
    FT0 = float128_to_float64(ft0_128, &env->fp_status);
718 e864cabd j_mayer
#else
719 e864cabd j_mayer
    /* This is OK on x86 hosts */
720 e864cabd j_mayer
    FT0 = (FT0 * FT1) + FT2;
721 e864cabd j_mayer
#endif
722 e864cabd j_mayer
}
723 e864cabd j_mayer
724 e864cabd j_mayer
void do_fmsub (void)
725 e864cabd j_mayer
{
726 e864cabd j_mayer
#ifdef FLOAT128
727 e864cabd j_mayer
    float128 ft0_128, ft1_128;
728 e864cabd j_mayer
729 e864cabd j_mayer
    ft0_128 = float64_to_float128(FT0, &env->fp_status);
730 e864cabd j_mayer
    ft1_128 = float64_to_float128(FT1, &env->fp_status);
731 e864cabd j_mayer
    ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status);
732 e864cabd j_mayer
    ft1_128 = float64_to_float128(FT2, &env->fp_status);
733 e864cabd j_mayer
    ft0_128 = float128_sub(ft0_128, ft1_128, &env->fp_status);
734 e864cabd j_mayer
    FT0 = float128_to_float64(ft0_128, &env->fp_status);
735 e864cabd j_mayer
#else
736 e864cabd j_mayer
    /* This is OK on x86 hosts */
737 e864cabd j_mayer
    FT0 = (FT0 * FT1) - FT2;
738 e864cabd j_mayer
#endif
739 e864cabd j_mayer
}
740 e864cabd j_mayer
#endif /* USE_PRECISE_EMULATION */
741 e864cabd j_mayer
742 4b3686fa bellard
void do_fnmadd (void)
743 4b3686fa bellard
{
744 e864cabd j_mayer
#if USE_PRECISE_EMULATION
745 e864cabd j_mayer
#ifdef FLOAT128
746 e864cabd j_mayer
    float128 ft0_128, ft1_128;
747 e864cabd j_mayer
748 e864cabd j_mayer
    ft0_128 = float64_to_float128(FT0, &env->fp_status);
749 e864cabd j_mayer
    ft1_128 = float64_to_float128(FT1, &env->fp_status);
750 e864cabd j_mayer
    ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status);
751 e864cabd j_mayer
    ft1_128 = float64_to_float128(FT2, &env->fp_status);
752 e864cabd j_mayer
    ft0_128 = float128_add(ft0_128, ft1_128, &env->fp_status);
753 e864cabd j_mayer
    FT0 = float128_to_float64(ft0_128, &env->fp_status);
754 e864cabd j_mayer
#else
755 e864cabd j_mayer
    /* This is OK on x86 hosts */
756 e864cabd j_mayer
    FT0 = (FT0 * FT1) + FT2;
757 e864cabd j_mayer
#endif
758 e864cabd j_mayer
#else
759 fdabc366 bellard
    FT0 = float64_mul(FT0, FT1, &env->fp_status);
760 fdabc366 bellard
    FT0 = float64_add(FT0, FT2, &env->fp_status);
761 e864cabd j_mayer
#endif
762 fdabc366 bellard
    if (likely(!isnan(FT0)))
763 fdabc366 bellard
        FT0 = float64_chs(FT0);
764 4b3686fa bellard
}
765 4b3686fa bellard
766 4b3686fa bellard
void do_fnmsub (void)
767 4b3686fa bellard
{
768 e864cabd j_mayer
#if USE_PRECISE_EMULATION
769 e864cabd j_mayer
#ifdef FLOAT128
770 e864cabd j_mayer
    float128 ft0_128, ft1_128;
771 e864cabd j_mayer
772 e864cabd j_mayer
    ft0_128 = float64_to_float128(FT0, &env->fp_status);
773 e864cabd j_mayer
    ft1_128 = float64_to_float128(FT1, &env->fp_status);
774 e864cabd j_mayer
    ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status);
775 e864cabd j_mayer
    ft1_128 = float64_to_float128(FT2, &env->fp_status);
776 e864cabd j_mayer
    ft0_128 = float128_sub(ft0_128, ft1_128, &env->fp_status);
777 e864cabd j_mayer
    FT0 = float128_to_float64(ft0_128, &env->fp_status);
778 e864cabd j_mayer
#else
779 e864cabd j_mayer
    /* This is OK on x86 hosts */
780 e864cabd j_mayer
    FT0 = (FT0 * FT1) - FT2;
781 e864cabd j_mayer
#endif
782 e864cabd j_mayer
#else
783 fdabc366 bellard
    FT0 = float64_mul(FT0, FT1, &env->fp_status);
784 fdabc366 bellard
    FT0 = float64_sub(FT0, FT2, &env->fp_status);
785 e864cabd j_mayer
#endif
786 fdabc366 bellard
    if (likely(!isnan(FT0)))
787 fdabc366 bellard
        FT0 = float64_chs(FT0);
788 1ef59d0a bellard
}
789 1ef59d0a bellard
790 9a64fbe4 bellard
void do_fsqrt (void)
791 9a64fbe4 bellard
{
792 fdabc366 bellard
    FT0 = float64_sqrt(FT0, &env->fp_status);
793 9a64fbe4 bellard
}
794 9a64fbe4 bellard
795 9a64fbe4 bellard
void do_fres (void)
796 9a64fbe4 bellard
{
797 4ecc3190 bellard
    union {
798 4ecc3190 bellard
        double d;
799 4ecc3190 bellard
        uint64_t i;
800 4ecc3190 bellard
    } p;
801 4ecc3190 bellard
802 fdabc366 bellard
    if (likely(isnormal(FT0))) {
803 e864cabd j_mayer
#if USE_PRECISE_EMULATION
804 e864cabd j_mayer
        FT0 = float64_div(1.0, FT0, &env->fp_status);
805 e864cabd j_mayer
        FT0 = float64_to_float32(FT0, &env->fp_status);
806 e864cabd j_mayer
#else
807 76a66253 j_mayer
        FT0 = float32_div(1.0, FT0, &env->fp_status);
808 e864cabd j_mayer
#endif
809 4ecc3190 bellard
    } else {
810 4ecc3190 bellard
        p.d = FT0;
811 4ecc3190 bellard
        if (p.i == 0x8000000000000000ULL) {
812 4ecc3190 bellard
            p.i = 0xFFF0000000000000ULL;
813 4ecc3190 bellard
        } else if (p.i == 0x0000000000000000ULL) {
814 4ecc3190 bellard
            p.i = 0x7FF0000000000000ULL;
815 4ecc3190 bellard
        } else if (isnan(FT0)) {
816 4ecc3190 bellard
            p.i = 0x7FF8000000000000ULL;
817 4ecc3190 bellard
        } else if (FT0 < 0.0) {
818 4ecc3190 bellard
            p.i = 0x8000000000000000ULL;
819 4ecc3190 bellard
        } else {
820 4ecc3190 bellard
            p.i = 0x0000000000000000ULL;
821 4ecc3190 bellard
        }
822 4ecc3190 bellard
        FT0 = p.d;
823 4ecc3190 bellard
    }
824 9a64fbe4 bellard
}
825 9a64fbe4 bellard
826 4ecc3190 bellard
void do_frsqrte (void)
827 9a64fbe4 bellard
{
828 4ecc3190 bellard
    union {
829 4ecc3190 bellard
        double d;
830 4ecc3190 bellard
        uint64_t i;
831 4ecc3190 bellard
    } p;
832 4ecc3190 bellard
833 fdabc366 bellard
    if (likely(isnormal(FT0) && FT0 > 0.0)) {
834 fdabc366 bellard
        FT0 = float64_sqrt(FT0, &env->fp_status);
835 fdabc366 bellard
        FT0 = float32_div(1.0, FT0, &env->fp_status);
836 4ecc3190 bellard
    } else {
837 4ecc3190 bellard
        p.d = FT0;
838 4ecc3190 bellard
        if (p.i == 0x8000000000000000ULL) {
839 4ecc3190 bellard
            p.i = 0xFFF0000000000000ULL;
840 4ecc3190 bellard
        } else if (p.i == 0x0000000000000000ULL) {
841 4ecc3190 bellard
            p.i = 0x7FF0000000000000ULL;
842 4ecc3190 bellard
        } else if (isnan(FT0)) {
843 4ecc3190 bellard
            if (!(p.i & 0x0008000000000000ULL))
844 4ecc3190 bellard
                p.i |= 0x000FFFFFFFFFFFFFULL;
845 4ecc3190 bellard
        } else if (FT0 < 0) {
846 4ecc3190 bellard
            p.i = 0x7FF8000000000000ULL;
847 4ecc3190 bellard
        } else {
848 4ecc3190 bellard
            p.i = 0x0000000000000000ULL;
849 4ecc3190 bellard
        }
850 4ecc3190 bellard
        FT0 = p.d;
851 4ecc3190 bellard
    }
852 9a64fbe4 bellard
}
853 9a64fbe4 bellard
854 9a64fbe4 bellard
void do_fsel (void)
855 9a64fbe4 bellard
{
856 9a64fbe4 bellard
    if (FT0 >= 0)
857 9a64fbe4 bellard
        FT0 = FT1;
858 4ecc3190 bellard
    else
859 4ecc3190 bellard
        FT0 = FT2;
860 9a64fbe4 bellard
}
861 9a64fbe4 bellard
862 9a64fbe4 bellard
void do_fcmpu (void)
863 9a64fbe4 bellard
{
864 fdabc366 bellard
    if (likely(!isnan(FT0) && !isnan(FT1))) {
865 fdabc366 bellard
        if (float64_lt(FT0, FT1, &env->fp_status)) {
866 fdabc366 bellard
            T0 = 0x08UL;
867 fdabc366 bellard
        } else if (!float64_le(FT0, FT1, &env->fp_status)) {
868 fdabc366 bellard
            T0 = 0x04UL;
869 fdabc366 bellard
        } else {
870 fdabc366 bellard
            T0 = 0x02UL;
871 fdabc366 bellard
        }
872 fdabc366 bellard
    } else {
873 fdabc366 bellard
        T0 = 0x01UL;
874 9a64fbe4 bellard
        env->fpscr[4] |= 0x1;
875 9a64fbe4 bellard
        env->fpscr[6] |= 0x1;
876 9a64fbe4 bellard
    }
877 4b3686fa bellard
    env->fpscr[3] = T0;
878 9a64fbe4 bellard
}
879 9a64fbe4 bellard
880 9a64fbe4 bellard
void do_fcmpo (void)
881 9a64fbe4 bellard
{
882 9a64fbe4 bellard
    env->fpscr[4] &= ~0x1;
883 fdabc366 bellard
    if (likely(!isnan(FT0) && !isnan(FT1))) {
884 fdabc366 bellard
        if (float64_lt(FT0, FT1, &env->fp_status)) {
885 fdabc366 bellard
            T0 = 0x08UL;
886 fdabc366 bellard
        } else if (!float64_le(FT0, FT1, &env->fp_status)) {
887 fdabc366 bellard
            T0 = 0x04UL;
888 fdabc366 bellard
        } else {
889 fdabc366 bellard
            T0 = 0x02UL;
890 fdabc366 bellard
        }
891 fdabc366 bellard
    } else {
892 fdabc366 bellard
        T0 = 0x01UL;
893 9a64fbe4 bellard
        env->fpscr[4] |= 0x1;
894 76a66253 j_mayer
        if (!float64_is_signaling_nan(FT0) || !float64_is_signaling_nan(FT1)) {
895 76a66253 j_mayer
            /* Quiet NaN case */
896 9a64fbe4 bellard
            env->fpscr[6] |= 0x1;
897 9a64fbe4 bellard
            if (!(env->fpscr[1] & 0x8))
898 9a64fbe4 bellard
                env->fpscr[4] |= 0x8;
899 9a64fbe4 bellard
        } else {
900 9a64fbe4 bellard
            env->fpscr[4] |= 0x8;
901 9a64fbe4 bellard
        }
902 9a64fbe4 bellard
    }
903 4b3686fa bellard
    env->fpscr[3] = T0;
904 9a64fbe4 bellard
}
905 9a64fbe4 bellard
906 76a66253 j_mayer
#if !defined (CONFIG_USER_ONLY)
907 fdabc366 bellard
void do_rfi (void)
908 9a64fbe4 bellard
{
909 426613db j_mayer
#if defined(TARGET_PPC64)
910 a42bd6cc j_mayer
    if (env->spr[SPR_SRR1] & (1ULL << MSR_SF)) {
911 a42bd6cc j_mayer
        env->nip = (uint64_t)(env->spr[SPR_SRR0] & ~0x00000003);
912 a42bd6cc j_mayer
        do_store_msr(env, (uint64_t)(env->spr[SPR_SRR1] & ~0xFFFF0000UL));
913 a42bd6cc j_mayer
    } else {
914 a42bd6cc j_mayer
        env->nip = (uint32_t)(env->spr[SPR_SRR0] & ~0x00000003);
915 a42bd6cc j_mayer
        ppc_store_msr_32(env, (uint32_t)(env->spr[SPR_SRR1] & ~0xFFFF0000UL));
916 a42bd6cc j_mayer
    }
917 426613db j_mayer
#else
918 a42bd6cc j_mayer
    env->nip = (uint32_t)(env->spr[SPR_SRR0] & ~0x00000003);
919 a42bd6cc j_mayer
    do_store_msr(env, (uint32_t)(env->spr[SPR_SRR1] & ~0xFFFF0000UL));
920 426613db j_mayer
#endif
921 fdabc366 bellard
#if defined (DEBUG_OP)
922 fdabc366 bellard
    dump_rfi();
923 fdabc366 bellard
#endif
924 fdabc366 bellard
    env->interrupt_request |= CPU_INTERRUPT_EXITTB;
925 9a64fbe4 bellard
}
926 d9bce9d9 j_mayer
927 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
928 426613db j_mayer
void do_rfid (void)
929 426613db j_mayer
{
930 a42bd6cc j_mayer
    if (env->spr[SPR_SRR1] & (1ULL << MSR_SF)) {
931 a42bd6cc j_mayer
        env->nip = (uint64_t)(env->spr[SPR_SRR0] & ~0x00000003);
932 a42bd6cc j_mayer
        do_store_msr(env, (uint64_t)(env->spr[SPR_SRR1] & ~0xFFFF0000UL));
933 a42bd6cc j_mayer
    } else {
934 a42bd6cc j_mayer
        env->nip = (uint32_t)(env->spr[SPR_SRR0] & ~0x00000003);
935 a42bd6cc j_mayer
        do_store_msr(env, (uint32_t)(env->spr[SPR_SRR1] & ~0xFFFF0000UL));
936 a42bd6cc j_mayer
    }
937 d9bce9d9 j_mayer
#if defined (DEBUG_OP)
938 d9bce9d9 j_mayer
    dump_rfi();
939 d9bce9d9 j_mayer
#endif
940 d9bce9d9 j_mayer
    env->interrupt_request |= CPU_INTERRUPT_EXITTB;
941 d9bce9d9 j_mayer
}
942 d9bce9d9 j_mayer
#endif
943 76a66253 j_mayer
#endif
944 9a64fbe4 bellard
945 76a66253 j_mayer
void do_tw (int flags)
946 9a64fbe4 bellard
{
947 d9bce9d9 j_mayer
    if (!likely(!(((int32_t)T0 < (int32_t)T1 && (flags & 0x10)) ||
948 d9bce9d9 j_mayer
                  ((int32_t)T0 > (int32_t)T1 && (flags & 0x08)) ||
949 d9bce9d9 j_mayer
                  ((int32_t)T0 == (int32_t)T1 && (flags & 0x04)) ||
950 d9bce9d9 j_mayer
                  ((uint32_t)T0 < (uint32_t)T1 && (flags & 0x02)) ||
951 a42bd6cc j_mayer
                  ((uint32_t)T0 > (uint32_t)T1 && (flags & 0x01))))) {
952 fdabc366 bellard
        do_raise_exception_err(EXCP_PROGRAM, EXCP_TRAP);
953 a42bd6cc j_mayer
    }
954 9a64fbe4 bellard
}
955 9a64fbe4 bellard
956 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
957 d9bce9d9 j_mayer
void do_td (int flags)
958 d9bce9d9 j_mayer
{
959 d9bce9d9 j_mayer
    if (!likely(!(((int64_t)T0 < (int64_t)T1 && (flags & 0x10)) ||
960 d9bce9d9 j_mayer
                  ((int64_t)T0 > (int64_t)T1 && (flags & 0x08)) ||
961 d9bce9d9 j_mayer
                  ((int64_t)T0 == (int64_t)T1 && (flags & 0x04)) ||
962 d9bce9d9 j_mayer
                  ((uint64_t)T0 < (uint64_t)T1 && (flags & 0x02)) ||
963 d9bce9d9 j_mayer
                  ((uint64_t)T0 > (uint64_t)T1 && (flags & 0x01)))))
964 d9bce9d9 j_mayer
        do_raise_exception_err(EXCP_PROGRAM, EXCP_TRAP);
965 d9bce9d9 j_mayer
}
966 d9bce9d9 j_mayer
#endif
967 d9bce9d9 j_mayer
968 fdabc366 bellard
/*****************************************************************************/
969 76a66253 j_mayer
/* PowerPC 601 specific instructions (POWER bridge) */
970 76a66253 j_mayer
void do_POWER_abso (void)
971 9a64fbe4 bellard
{
972 d9bce9d9 j_mayer
    if ((uint32_t)T0 == INT32_MIN) {
973 76a66253 j_mayer
        T0 = INT32_MAX;
974 76a66253 j_mayer
        xer_ov = 1;
975 76a66253 j_mayer
        xer_so = 1;
976 76a66253 j_mayer
    } else {
977 76a66253 j_mayer
        T0 = -T0;
978 76a66253 j_mayer
        xer_ov = 0;
979 76a66253 j_mayer
    }
980 9a64fbe4 bellard
}
981 9a64fbe4 bellard
982 76a66253 j_mayer
void do_POWER_clcs (void)
983 9a64fbe4 bellard
{
984 76a66253 j_mayer
    switch (T0) {
985 76a66253 j_mayer
    case 0x0CUL:
986 76a66253 j_mayer
        /* Instruction cache line size */
987 76a66253 j_mayer
        T0 = ICACHE_LINE_SIZE;
988 76a66253 j_mayer
        break;
989 76a66253 j_mayer
    case 0x0DUL:
990 76a66253 j_mayer
        /* Data cache line size */
991 76a66253 j_mayer
        T0 = DCACHE_LINE_SIZE;
992 76a66253 j_mayer
        break;
993 76a66253 j_mayer
    case 0x0EUL:
994 76a66253 j_mayer
        /* Minimum cache line size */
995 76a66253 j_mayer
        T0 = ICACHE_LINE_SIZE < DCACHE_LINE_SIZE ?
996 76a66253 j_mayer
            ICACHE_LINE_SIZE : DCACHE_LINE_SIZE;
997 76a66253 j_mayer
        break;
998 76a66253 j_mayer
    case 0x0FUL:
999 76a66253 j_mayer
        /* Maximum cache line size */
1000 76a66253 j_mayer
        T0 = ICACHE_LINE_SIZE > DCACHE_LINE_SIZE ?
1001 76a66253 j_mayer
            ICACHE_LINE_SIZE : DCACHE_LINE_SIZE;
1002 76a66253 j_mayer
        break;
1003 76a66253 j_mayer
    default:
1004 76a66253 j_mayer
        /* Undefined */
1005 76a66253 j_mayer
        break;
1006 76a66253 j_mayer
    }
1007 76a66253 j_mayer
}
1008 76a66253 j_mayer
1009 76a66253 j_mayer
void do_POWER_div (void)
1010 76a66253 j_mayer
{
1011 76a66253 j_mayer
    uint64_t tmp;
1012 76a66253 j_mayer
1013 d9bce9d9 j_mayer
    if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) {
1014 76a66253 j_mayer
        T0 = (long)((-1) * (T0 >> 31));
1015 76a66253 j_mayer
        env->spr[SPR_MQ] = 0;
1016 76a66253 j_mayer
    } else {
1017 76a66253 j_mayer
        tmp = ((uint64_t)T0 << 32) | env->spr[SPR_MQ];
1018 76a66253 j_mayer
        env->spr[SPR_MQ] = tmp % T1;
1019 d9bce9d9 j_mayer
        T0 = tmp / (int32_t)T1;
1020 76a66253 j_mayer
    }
1021 76a66253 j_mayer
}
1022 76a66253 j_mayer
1023 76a66253 j_mayer
void do_POWER_divo (void)
1024 76a66253 j_mayer
{
1025 76a66253 j_mayer
    int64_t tmp;
1026 76a66253 j_mayer
1027 d9bce9d9 j_mayer
    if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) {
1028 76a66253 j_mayer
        T0 = (long)((-1) * (T0 >> 31));
1029 76a66253 j_mayer
        env->spr[SPR_MQ] = 0;
1030 76a66253 j_mayer
        xer_ov = 1;
1031 76a66253 j_mayer
        xer_so = 1;
1032 76a66253 j_mayer
    } else {
1033 76a66253 j_mayer
        tmp = ((uint64_t)T0 << 32) | env->spr[SPR_MQ];
1034 76a66253 j_mayer
        env->spr[SPR_MQ] = tmp % T1;
1035 d9bce9d9 j_mayer
        tmp /= (int32_t)T1;
1036 76a66253 j_mayer
        if (tmp > (int64_t)INT32_MAX || tmp < (int64_t)INT32_MIN) {
1037 76a66253 j_mayer
            xer_ov = 1;
1038 76a66253 j_mayer
            xer_so = 1;
1039 76a66253 j_mayer
        } else {
1040 76a66253 j_mayer
            xer_ov = 0;
1041 76a66253 j_mayer
        }
1042 76a66253 j_mayer
        T0 = tmp;
1043 76a66253 j_mayer
    }
1044 76a66253 j_mayer
}
1045 76a66253 j_mayer
1046 76a66253 j_mayer
void do_POWER_divs (void)
1047 76a66253 j_mayer
{
1048 d9bce9d9 j_mayer
    if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) {
1049 76a66253 j_mayer
        T0 = (long)((-1) * (T0 >> 31));
1050 76a66253 j_mayer
        env->spr[SPR_MQ] = 0;
1051 76a66253 j_mayer
    } else {
1052 76a66253 j_mayer
        env->spr[SPR_MQ] = T0 % T1;
1053 d9bce9d9 j_mayer
        T0 = (int32_t)T0 / (int32_t)T1;
1054 76a66253 j_mayer
    }
1055 76a66253 j_mayer
}
1056 76a66253 j_mayer
1057 76a66253 j_mayer
void do_POWER_divso (void)
1058 76a66253 j_mayer
{
1059 d9bce9d9 j_mayer
    if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) {
1060 76a66253 j_mayer
        T0 = (long)((-1) * (T0 >> 31));
1061 76a66253 j_mayer
        env->spr[SPR_MQ] = 0;
1062 76a66253 j_mayer
        xer_ov = 1;
1063 76a66253 j_mayer
        xer_so = 1;
1064 76a66253 j_mayer
    } else {
1065 d9bce9d9 j_mayer
        T0 = (int32_t)T0 / (int32_t)T1;
1066 d9bce9d9 j_mayer
        env->spr[SPR_MQ] = (int32_t)T0 % (int32_t)T1;
1067 76a66253 j_mayer
        xer_ov = 0;
1068 76a66253 j_mayer
    }
1069 76a66253 j_mayer
}
1070 76a66253 j_mayer
1071 76a66253 j_mayer
void do_POWER_dozo (void)
1072 76a66253 j_mayer
{
1073 d9bce9d9 j_mayer
    if ((int32_t)T1 > (int32_t)T0) {
1074 76a66253 j_mayer
        T2 = T0;
1075 76a66253 j_mayer
        T0 = T1 - T0;
1076 d9bce9d9 j_mayer
        if (((uint32_t)(~T2) ^ (uint32_t)T1 ^ UINT32_MAX) &
1077 d9bce9d9 j_mayer
            ((uint32_t)(~T2) ^ (uint32_t)T0) & (1UL << 31)) {
1078 76a66253 j_mayer
            xer_so = 1;
1079 76a66253 j_mayer
            xer_ov = 1;
1080 76a66253 j_mayer
        } else {
1081 76a66253 j_mayer
            xer_ov = 0;
1082 76a66253 j_mayer
        }
1083 76a66253 j_mayer
    } else {
1084 76a66253 j_mayer
        T0 = 0;
1085 76a66253 j_mayer
        xer_ov = 0;
1086 76a66253 j_mayer
    }
1087 76a66253 j_mayer
}
1088 76a66253 j_mayer
1089 76a66253 j_mayer
void do_POWER_maskg (void)
1090 76a66253 j_mayer
{
1091 76a66253 j_mayer
    uint32_t ret;
1092 76a66253 j_mayer
1093 d9bce9d9 j_mayer
    if ((uint32_t)T0 == (uint32_t)(T1 + 1)) {
1094 76a66253 j_mayer
        ret = -1;
1095 76a66253 j_mayer
    } else {
1096 d9bce9d9 j_mayer
        ret = (((uint32_t)(-1)) >> ((uint32_t)T0)) ^
1097 d9bce9d9 j_mayer
            (((uint32_t)(-1) >> ((uint32_t)T1)) >> 1);
1098 d9bce9d9 j_mayer
        if ((uint32_t)T0 > (uint32_t)T1)
1099 76a66253 j_mayer
            ret = ~ret;
1100 76a66253 j_mayer
    }
1101 76a66253 j_mayer
    T0 = ret;
1102 76a66253 j_mayer
}
1103 76a66253 j_mayer
1104 76a66253 j_mayer
void do_POWER_mulo (void)
1105 76a66253 j_mayer
{
1106 76a66253 j_mayer
    uint64_t tmp;
1107 76a66253 j_mayer
1108 76a66253 j_mayer
    tmp = (uint64_t)T0 * (uint64_t)T1;
1109 76a66253 j_mayer
    env->spr[SPR_MQ] = tmp >> 32;
1110 76a66253 j_mayer
    T0 = tmp;
1111 76a66253 j_mayer
    if (tmp >> 32 != ((uint64_t)T0 >> 16) * ((uint64_t)T1 >> 16)) {
1112 76a66253 j_mayer
        xer_ov = 1;
1113 76a66253 j_mayer
        xer_so = 1;
1114 76a66253 j_mayer
    } else {
1115 76a66253 j_mayer
        xer_ov = 0;
1116 76a66253 j_mayer
    }
1117 76a66253 j_mayer
}
1118 76a66253 j_mayer
1119 76a66253 j_mayer
#if !defined (CONFIG_USER_ONLY)
1120 76a66253 j_mayer
void do_POWER_rac (void)
1121 76a66253 j_mayer
{
1122 76a66253 j_mayer
#if 0
1123 76a66253 j_mayer
    mmu_ctx_t ctx;
1124 76a66253 j_mayer

1125 76a66253 j_mayer
    /* We don't have to generate many instances of this instruction,
1126 76a66253 j_mayer
     * as rac is supervisor only.
1127 76a66253 j_mayer
     */
1128 76a66253 j_mayer
    if (get_physical_address(env, &ctx, T0, 0, ACCESS_INT, 1) == 0)
1129 76a66253 j_mayer
        T0 = ctx.raddr;
1130 76a66253 j_mayer
#endif
1131 76a66253 j_mayer
}
1132 76a66253 j_mayer
1133 76a66253 j_mayer
void do_POWER_rfsvc (void)
1134 76a66253 j_mayer
{
1135 76a66253 j_mayer
    env->nip = env->lr & ~0x00000003UL;
1136 76a66253 j_mayer
    T0 = env->ctr & 0x0000FFFFUL;
1137 76a66253 j_mayer
    do_store_msr(env, T0);
1138 76a66253 j_mayer
#if defined (DEBUG_OP)
1139 76a66253 j_mayer
    dump_rfi();
1140 76a66253 j_mayer
#endif
1141 76a66253 j_mayer
    env->interrupt_request |= CPU_INTERRUPT_EXITTB;
1142 76a66253 j_mayer
}
1143 76a66253 j_mayer
1144 76a66253 j_mayer
/* PowerPC 601 BAT management helper */
1145 76a66253 j_mayer
void do_store_601_batu (int nr)
1146 76a66253 j_mayer
{
1147 d9bce9d9 j_mayer
    do_store_ibatu(env, nr, (uint32_t)T0);
1148 76a66253 j_mayer
    env->DBAT[0][nr] = env->IBAT[0][nr];
1149 76a66253 j_mayer
    env->DBAT[1][nr] = env->IBAT[1][nr];
1150 76a66253 j_mayer
}
1151 76a66253 j_mayer
#endif
1152 76a66253 j_mayer
1153 76a66253 j_mayer
/*****************************************************************************/
1154 76a66253 j_mayer
/* 602 specific instructions */
1155 76a66253 j_mayer
/* mfrom is the most crazy instruction ever seen, imho ! */
1156 76a66253 j_mayer
/* Real implementation uses a ROM table. Do the same */
1157 76a66253 j_mayer
#define USE_MFROM_ROM_TABLE
1158 76a66253 j_mayer
void do_op_602_mfrom (void)
1159 76a66253 j_mayer
{
1160 76a66253 j_mayer
    if (likely(T0 < 602)) {
1161 d9bce9d9 j_mayer
#if defined(USE_MFROM_ROM_TABLE)
1162 76a66253 j_mayer
#include "mfrom_table.c"
1163 76a66253 j_mayer
        T0 = mfrom_ROM_table[T0];
1164 fdabc366 bellard
#else
1165 76a66253 j_mayer
        double d;
1166 76a66253 j_mayer
        /* Extremly decomposed:
1167 76a66253 j_mayer
         *                    -T0 / 256
1168 76a66253 j_mayer
         * T0 = 256 * log10(10          + 1.0) + 0.5
1169 76a66253 j_mayer
         */
1170 76a66253 j_mayer
        d = T0;
1171 76a66253 j_mayer
        d = float64_div(d, 256, &env->fp_status);
1172 76a66253 j_mayer
        d = float64_chs(d);
1173 76a66253 j_mayer
        d = exp10(d); // XXX: use float emulation function
1174 76a66253 j_mayer
        d = float64_add(d, 1.0, &env->fp_status);
1175 76a66253 j_mayer
        d = log10(d); // XXX: use float emulation function
1176 76a66253 j_mayer
        d = float64_mul(d, 256, &env->fp_status);
1177 76a66253 j_mayer
        d = float64_add(d, 0.5, &env->fp_status);
1178 76a66253 j_mayer
        T0 = float64_round_to_int(d, &env->fp_status);
1179 fdabc366 bellard
#endif
1180 76a66253 j_mayer
    } else {
1181 76a66253 j_mayer
        T0 = 0;
1182 76a66253 j_mayer
    }
1183 76a66253 j_mayer
}
1184 76a66253 j_mayer
1185 76a66253 j_mayer
/*****************************************************************************/
1186 76a66253 j_mayer
/* Embedded PowerPC specific helpers */
1187 76a66253 j_mayer
void do_405_check_ov (void)
1188 76a66253 j_mayer
{
1189 d9bce9d9 j_mayer
    if (likely((((uint32_t)T1 ^ (uint32_t)T2) >> 31) ||
1190 d9bce9d9 j_mayer
               !(((uint32_t)T0 ^ (uint32_t)T2) >> 31))) {
1191 76a66253 j_mayer
        xer_ov = 0;
1192 76a66253 j_mayer
    } else {
1193 76a66253 j_mayer
        xer_ov = 1;
1194 76a66253 j_mayer
        xer_so = 1;
1195 76a66253 j_mayer
    }
1196 76a66253 j_mayer
}
1197 76a66253 j_mayer
1198 76a66253 j_mayer
void do_405_check_sat (void)
1199 76a66253 j_mayer
{
1200 d9bce9d9 j_mayer
    if (!likely((((uint32_t)T1 ^ (uint32_t)T2) >> 31) ||
1201 d9bce9d9 j_mayer
                !(((uint32_t)T0 ^ (uint32_t)T2) >> 31))) {
1202 76a66253 j_mayer
        /* Saturate result */
1203 76a66253 j_mayer
        if (T2 >> 31) {
1204 76a66253 j_mayer
            T0 = INT32_MIN;
1205 76a66253 j_mayer
        } else {
1206 76a66253 j_mayer
            T0 = INT32_MAX;
1207 76a66253 j_mayer
        }
1208 76a66253 j_mayer
    }
1209 76a66253 j_mayer
}
1210 76a66253 j_mayer
1211 76a66253 j_mayer
#if !defined(CONFIG_USER_ONLY)
1212 a42bd6cc j_mayer
void do_40x_rfci (void)
1213 76a66253 j_mayer
{
1214 76a66253 j_mayer
    env->nip = env->spr[SPR_40x_SRR2];
1215 a42bd6cc j_mayer
    do_store_msr(env, env->spr[SPR_40x_SRR3] & ~0xFFFF0000);
1216 a42bd6cc j_mayer
#if defined (DEBUG_OP)
1217 a42bd6cc j_mayer
    dump_rfi();
1218 a42bd6cc j_mayer
#endif
1219 a42bd6cc j_mayer
    env->interrupt_request = CPU_INTERRUPT_EXITTB;
1220 a42bd6cc j_mayer
}
1221 a42bd6cc j_mayer
1222 a42bd6cc j_mayer
void do_rfci (void)
1223 a42bd6cc j_mayer
{
1224 a42bd6cc j_mayer
#if defined(TARGET_PPC64)
1225 a42bd6cc j_mayer
    if (env->spr[SPR_BOOKE_CSRR1] & (1 << MSR_CM)) {
1226 a42bd6cc j_mayer
        env->nip = (uint64_t)env->spr[SPR_BOOKE_CSRR0];
1227 a42bd6cc j_mayer
    } else
1228 a42bd6cc j_mayer
#endif
1229 a42bd6cc j_mayer
    {
1230 a42bd6cc j_mayer
        env->nip = (uint32_t)env->spr[SPR_BOOKE_CSRR0];
1231 a42bd6cc j_mayer
    }
1232 a42bd6cc j_mayer
    do_store_msr(env, (uint32_t)env->spr[SPR_BOOKE_CSRR1] & ~0x3FFF0000);
1233 a42bd6cc j_mayer
#if defined (DEBUG_OP)
1234 a42bd6cc j_mayer
    dump_rfi();
1235 a42bd6cc j_mayer
#endif
1236 a42bd6cc j_mayer
    env->interrupt_request = CPU_INTERRUPT_EXITTB;
1237 a42bd6cc j_mayer
}
1238 a42bd6cc j_mayer
1239 a42bd6cc j_mayer
void do_rfdi (void)
1240 a42bd6cc j_mayer
{
1241 a42bd6cc j_mayer
#if defined(TARGET_PPC64)
1242 a42bd6cc j_mayer
    if (env->spr[SPR_BOOKE_DSRR1] & (1 << MSR_CM)) {
1243 a42bd6cc j_mayer
        env->nip = (uint64_t)env->spr[SPR_BOOKE_DSRR0];
1244 a42bd6cc j_mayer
    } else
1245 a42bd6cc j_mayer
#endif
1246 a42bd6cc j_mayer
    {
1247 a42bd6cc j_mayer
        env->nip = (uint32_t)env->spr[SPR_BOOKE_DSRR0];
1248 a42bd6cc j_mayer
    }
1249 a42bd6cc j_mayer
    do_store_msr(env, (uint32_t)env->spr[SPR_BOOKE_DSRR1] & ~0x3FFF0000);
1250 a42bd6cc j_mayer
#if defined (DEBUG_OP)
1251 a42bd6cc j_mayer
    dump_rfi();
1252 a42bd6cc j_mayer
#endif
1253 a42bd6cc j_mayer
    env->interrupt_request = CPU_INTERRUPT_EXITTB;
1254 a42bd6cc j_mayer
}
1255 a42bd6cc j_mayer
1256 a42bd6cc j_mayer
void do_rfmci (void)
1257 a42bd6cc j_mayer
{
1258 a42bd6cc j_mayer
#if defined(TARGET_PPC64)
1259 a42bd6cc j_mayer
    if (env->spr[SPR_BOOKE_MCSRR1] & (1 << MSR_CM)) {
1260 a42bd6cc j_mayer
        env->nip = (uint64_t)env->spr[SPR_BOOKE_MCSRR0];
1261 a42bd6cc j_mayer
    } else
1262 a42bd6cc j_mayer
#endif
1263 a42bd6cc j_mayer
    {
1264 a42bd6cc j_mayer
        env->nip = (uint32_t)env->spr[SPR_BOOKE_MCSRR0];
1265 a42bd6cc j_mayer
    }
1266 a42bd6cc j_mayer
    do_store_msr(env, (uint32_t)env->spr[SPR_BOOKE_MCSRR1] & ~0x3FFF0000);
1267 76a66253 j_mayer
#if defined (DEBUG_OP)
1268 76a66253 j_mayer
    dump_rfi();
1269 76a66253 j_mayer
#endif
1270 76a66253 j_mayer
    env->interrupt_request = CPU_INTERRUPT_EXITTB;
1271 76a66253 j_mayer
}
1272 76a66253 j_mayer
1273 a42bd6cc j_mayer
void do_load_dcr (void)
1274 76a66253 j_mayer
{
1275 76a66253 j_mayer
    target_ulong val;
1276 76a66253 j_mayer
    
1277 2e719ba3 j_mayer
    if (unlikely(env->dcr_env == NULL)) {
1278 a496775f j_mayer
        if (loglevel) {
1279 a496775f j_mayer
            fprintf(logfile, "No DCR environment\n");
1280 a496775f j_mayer
        }
1281 76a66253 j_mayer
        do_raise_exception_err(EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_INVAL);
1282 2e719ba3 j_mayer
    } else if (unlikely(ppc_dcr_read(env->dcr_env, T0, &val) != 0)) {
1283 a496775f j_mayer
        if (loglevel) {
1284 a496775f j_mayer
            fprintf(logfile, "DCR read error %d %03x\n", (int)T0, (int)T0);
1285 a496775f j_mayer
        }
1286 76a66253 j_mayer
        do_raise_exception_err(EXCP_PROGRAM, EXCP_INVAL | EXCP_PRIV_REG);
1287 2e719ba3 j_mayer
    } else {
1288 76a66253 j_mayer
        T0 = val;
1289 2e719ba3 j_mayer
    }
1290 76a66253 j_mayer
}
1291 76a66253 j_mayer
1292 a42bd6cc j_mayer
void do_store_dcr (void)
1293 76a66253 j_mayer
{
1294 2e719ba3 j_mayer
    if (unlikely(env->dcr_env == NULL)) {
1295 a496775f j_mayer
        if (loglevel) {
1296 a496775f j_mayer
            fprintf(logfile, "No DCR environment\n");
1297 a496775f j_mayer
        }
1298 76a66253 j_mayer
        do_raise_exception_err(EXCP_PROGRAM, EXCP_INVAL | EXCP_INVAL_INVAL);
1299 2e719ba3 j_mayer
    } else if (unlikely(ppc_dcr_write(env->dcr_env, T0, T1) != 0)) {
1300 a496775f j_mayer
        if (loglevel) {
1301 a496775f j_mayer
            fprintf(logfile, "DCR write error %d %03x\n", (int)T0, (int)T0);
1302 a496775f j_mayer
        }
1303 76a66253 j_mayer
        do_raise_exception_err(EXCP_PROGRAM, EXCP_INVAL | EXCP_PRIV_REG);
1304 2e719ba3 j_mayer
    }
1305 76a66253 j_mayer
}
1306 76a66253 j_mayer
1307 76a66253 j_mayer
void do_load_403_pb (int num)
1308 76a66253 j_mayer
{
1309 76a66253 j_mayer
    T0 = env->pb[num];
1310 76a66253 j_mayer
}
1311 76a66253 j_mayer
1312 76a66253 j_mayer
void do_store_403_pb (int num)
1313 76a66253 j_mayer
{
1314 76a66253 j_mayer
    if (likely(env->pb[num] != T0)) {
1315 76a66253 j_mayer
        env->pb[num] = T0;
1316 76a66253 j_mayer
        /* Should be optimized */
1317 76a66253 j_mayer
        tlb_flush(env, 1);
1318 76a66253 j_mayer
    }
1319 76a66253 j_mayer
}
1320 76a66253 j_mayer
#endif
1321 76a66253 j_mayer
1322 76a66253 j_mayer
/* 440 specific */
1323 76a66253 j_mayer
void do_440_dlmzb (void)
1324 76a66253 j_mayer
{
1325 76a66253 j_mayer
    target_ulong mask;
1326 76a66253 j_mayer
    int i;
1327 76a66253 j_mayer
1328 76a66253 j_mayer
    i = 1;
1329 76a66253 j_mayer
    for (mask = 0xFF000000; mask != 0; mask = mask >> 8) {
1330 76a66253 j_mayer
        if ((T0 & mask) == 0)
1331 76a66253 j_mayer
            goto done;
1332 76a66253 j_mayer
        i++;
1333 76a66253 j_mayer
    }
1334 76a66253 j_mayer
    for (mask = 0xFF000000; mask != 0; mask = mask >> 8) {
1335 76a66253 j_mayer
        if ((T1 & mask) == 0)
1336 76a66253 j_mayer
            break;
1337 76a66253 j_mayer
        i++;
1338 76a66253 j_mayer
    }
1339 76a66253 j_mayer
 done:
1340 76a66253 j_mayer
    T0 = i;
1341 fdabc366 bellard
}
1342 fdabc366 bellard
1343 0487d6a8 j_mayer
#if defined(TARGET_PPCSPE)
1344 0487d6a8 j_mayer
/* SPE extension helpers */
1345 0487d6a8 j_mayer
/* Use a table to make this quicker */
1346 0487d6a8 j_mayer
static uint8_t hbrev[16] = {
1347 0487d6a8 j_mayer
    0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE,
1348 0487d6a8 j_mayer
    0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF,
1349 0487d6a8 j_mayer
};
1350 0487d6a8 j_mayer
1351 0487d6a8 j_mayer
static inline uint8_t byte_reverse (uint8_t val)
1352 0487d6a8 j_mayer
{
1353 0487d6a8 j_mayer
    return hbrev[val >> 4] | (hbrev[val & 0xF] << 4);
1354 0487d6a8 j_mayer
}
1355 0487d6a8 j_mayer
1356 0487d6a8 j_mayer
static inline uint32_t word_reverse (uint32_t val)
1357 0487d6a8 j_mayer
{
1358 0487d6a8 j_mayer
    return byte_reverse(val >> 24) | (byte_reverse(val >> 16) << 8) |
1359 0487d6a8 j_mayer
        (byte_reverse(val >> 8) << 16) | (byte_reverse(val) << 24);
1360 0487d6a8 j_mayer
}
1361 0487d6a8 j_mayer
1362 0487d6a8 j_mayer
#define MASKBITS 16 // Random value - to be fixed
1363 0487d6a8 j_mayer
void do_brinc (void)
1364 0487d6a8 j_mayer
{
1365 0487d6a8 j_mayer
    uint32_t a, b, d, mask;
1366 0487d6a8 j_mayer
1367 0487d6a8 j_mayer
    mask = (uint32_t)(-1UL) >> MASKBITS;
1368 0487d6a8 j_mayer
    b = T1_64 & mask;
1369 0487d6a8 j_mayer
    a = T0_64 & mask;
1370 0487d6a8 j_mayer
    d = word_reverse(1 + word_reverse(a | ~mask));
1371 0487d6a8 j_mayer
    T0_64 = (T0_64 & ~mask) | (d & mask);
1372 0487d6a8 j_mayer
}
1373 0487d6a8 j_mayer
1374 0487d6a8 j_mayer
#define DO_SPE_OP2(name)                                                      \
1375 0487d6a8 j_mayer
void do_ev##name (void)                                                       \
1376 0487d6a8 j_mayer
{                                                                             \
1377 0487d6a8 j_mayer
    T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32, T1_64 >> 32) << 32) |         \
1378 0487d6a8 j_mayer
        (uint64_t)_do_e##name(T0_64, T1_64);                                  \
1379 0487d6a8 j_mayer
}
1380 0487d6a8 j_mayer
1381 0487d6a8 j_mayer
#define DO_SPE_OP1(name)                                                      \
1382 0487d6a8 j_mayer
void do_ev##name (void)                                                       \
1383 0487d6a8 j_mayer
{                                                                             \
1384 0487d6a8 j_mayer
    T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32) << 32) |                      \
1385 0487d6a8 j_mayer
        (uint64_t)_do_e##name(T0_64);                                         \
1386 0487d6a8 j_mayer
}
1387 0487d6a8 j_mayer
1388 0487d6a8 j_mayer
/* Fixed-point vector arithmetic */
1389 0487d6a8 j_mayer
static inline uint32_t _do_eabs (uint32_t val)
1390 0487d6a8 j_mayer
{
1391 0487d6a8 j_mayer
    if (val != 0x80000000)
1392 0487d6a8 j_mayer
        val &= ~0x80000000;
1393 0487d6a8 j_mayer
1394 0487d6a8 j_mayer
    return val;
1395 0487d6a8 j_mayer
}
1396 0487d6a8 j_mayer
1397 0487d6a8 j_mayer
static inline uint32_t _do_eaddw (uint32_t op1, uint32_t op2)
1398 0487d6a8 j_mayer
{
1399 0487d6a8 j_mayer
    return op1 + op2;
1400 0487d6a8 j_mayer
}
1401 0487d6a8 j_mayer
1402 0487d6a8 j_mayer
static inline int _do_ecntlsw (uint32_t val)
1403 0487d6a8 j_mayer
{
1404 0487d6a8 j_mayer
    if (val & 0x80000000)
1405 0487d6a8 j_mayer
        return _do_cntlzw(~val);
1406 0487d6a8 j_mayer
    else
1407 0487d6a8 j_mayer
        return _do_cntlzw(val);
1408 0487d6a8 j_mayer
}
1409 0487d6a8 j_mayer
1410 0487d6a8 j_mayer
static inline int _do_ecntlzw (uint32_t val)
1411 0487d6a8 j_mayer
{
1412 0487d6a8 j_mayer
    return _do_cntlzw(val);
1413 0487d6a8 j_mayer
}
1414 0487d6a8 j_mayer
1415 0487d6a8 j_mayer
static inline uint32_t _do_eneg (uint32_t val)
1416 0487d6a8 j_mayer
{
1417 0487d6a8 j_mayer
    if (val != 0x80000000)
1418 0487d6a8 j_mayer
        val ^= 0x80000000;
1419 0487d6a8 j_mayer
1420 0487d6a8 j_mayer
    return val;
1421 0487d6a8 j_mayer
}
1422 0487d6a8 j_mayer
1423 0487d6a8 j_mayer
static inline uint32_t _do_erlw (uint32_t op1, uint32_t op2)
1424 0487d6a8 j_mayer
{
1425 0487d6a8 j_mayer
    return rotl32(op1, op2);
1426 0487d6a8 j_mayer
}
1427 0487d6a8 j_mayer
1428 0487d6a8 j_mayer
static inline uint32_t _do_erndw (uint32_t val)
1429 0487d6a8 j_mayer
{
1430 0487d6a8 j_mayer
    return (val + 0x000080000000) & 0xFFFF0000;
1431 0487d6a8 j_mayer
}
1432 0487d6a8 j_mayer
1433 0487d6a8 j_mayer
static inline uint32_t _do_eslw (uint32_t op1, uint32_t op2)
1434 0487d6a8 j_mayer
{
1435 0487d6a8 j_mayer
    /* No error here: 6 bits are used */
1436 0487d6a8 j_mayer
    return op1 << (op2 & 0x3F);
1437 0487d6a8 j_mayer
}
1438 0487d6a8 j_mayer
1439 0487d6a8 j_mayer
static inline int32_t _do_esrws (int32_t op1, uint32_t op2)
1440 0487d6a8 j_mayer
{
1441 0487d6a8 j_mayer
    /* No error here: 6 bits are used */
1442 0487d6a8 j_mayer
    return op1 >> (op2 & 0x3F);
1443 0487d6a8 j_mayer
}
1444 0487d6a8 j_mayer
1445 0487d6a8 j_mayer
static inline uint32_t _do_esrwu (uint32_t op1, uint32_t op2)
1446 0487d6a8 j_mayer
{
1447 0487d6a8 j_mayer
    /* No error here: 6 bits are used */
1448 0487d6a8 j_mayer
    return op1 >> (op2 & 0x3F);
1449 0487d6a8 j_mayer
}
1450 0487d6a8 j_mayer
1451 0487d6a8 j_mayer
static inline uint32_t _do_esubfw (uint32_t op1, uint32_t op2)
1452 0487d6a8 j_mayer
{
1453 0487d6a8 j_mayer
    return op2 - op1;
1454 0487d6a8 j_mayer
}
1455 0487d6a8 j_mayer
1456 0487d6a8 j_mayer
/* evabs */
1457 0487d6a8 j_mayer
DO_SPE_OP1(abs);
1458 0487d6a8 j_mayer
/* evaddw */
1459 0487d6a8 j_mayer
DO_SPE_OP2(addw);
1460 0487d6a8 j_mayer
/* evcntlsw */
1461 0487d6a8 j_mayer
DO_SPE_OP1(cntlsw);
1462 0487d6a8 j_mayer
/* evcntlzw */
1463 0487d6a8 j_mayer
DO_SPE_OP1(cntlzw);
1464 0487d6a8 j_mayer
/* evneg */
1465 0487d6a8 j_mayer
DO_SPE_OP1(neg);
1466 0487d6a8 j_mayer
/* evrlw */
1467 0487d6a8 j_mayer
DO_SPE_OP2(rlw);
1468 0487d6a8 j_mayer
/* evrnd */
1469 0487d6a8 j_mayer
DO_SPE_OP1(rndw);
1470 0487d6a8 j_mayer
/* evslw */
1471 0487d6a8 j_mayer
DO_SPE_OP2(slw);
1472 0487d6a8 j_mayer
/* evsrws */
1473 0487d6a8 j_mayer
DO_SPE_OP2(srws);
1474 0487d6a8 j_mayer
/* evsrwu */
1475 0487d6a8 j_mayer
DO_SPE_OP2(srwu);
1476 0487d6a8 j_mayer
/* evsubfw */
1477 0487d6a8 j_mayer
DO_SPE_OP2(subfw);
1478 0487d6a8 j_mayer
1479 0487d6a8 j_mayer
/* evsel is a little bit more complicated... */
1480 0487d6a8 j_mayer
static inline uint32_t _do_esel (uint32_t op1, uint32_t op2, int n)
1481 0487d6a8 j_mayer
{
1482 0487d6a8 j_mayer
    if (n)
1483 0487d6a8 j_mayer
        return op1;
1484 0487d6a8 j_mayer
    else
1485 0487d6a8 j_mayer
        return op2;
1486 0487d6a8 j_mayer
}
1487 0487d6a8 j_mayer
1488 0487d6a8 j_mayer
void do_evsel (void)
1489 0487d6a8 j_mayer
{
1490 0487d6a8 j_mayer
    T0_64 = ((uint64_t)_do_esel(T0_64 >> 32, T1_64 >> 32, T0 >> 3) << 32) |
1491 0487d6a8 j_mayer
        (uint64_t)_do_esel(T0_64, T1_64, (T0 >> 2) & 1);
1492 0487d6a8 j_mayer
}
1493 0487d6a8 j_mayer
1494 0487d6a8 j_mayer
/* Fixed-point vector comparisons */
1495 0487d6a8 j_mayer
#define DO_SPE_CMP(name)                                                      \
1496 0487d6a8 j_mayer
void do_ev##name (void)                                                       \
1497 0487d6a8 j_mayer
{                                                                             \
1498 0487d6a8 j_mayer
    T0 = _do_evcmp_merge((uint64_t)_do_e##name(T0_64 >> 32,                   \
1499 0487d6a8 j_mayer
                                               T1_64 >> 32) << 32,            \
1500 0487d6a8 j_mayer
                         _do_e##name(T0_64, T1_64));                          \
1501 0487d6a8 j_mayer
}
1502 0487d6a8 j_mayer
1503 0487d6a8 j_mayer
static inline uint32_t _do_evcmp_merge (int t0, int t1)
1504 0487d6a8 j_mayer
{
1505 0487d6a8 j_mayer
    return (t0 << 3) | (t1 << 2) | ((t0 | t1) << 1) | (t0 & t1);
1506 0487d6a8 j_mayer
}
1507 0487d6a8 j_mayer
static inline int _do_ecmpeq (uint32_t op1, uint32_t op2)
1508 0487d6a8 j_mayer
{
1509 0487d6a8 j_mayer
    return op1 == op2 ? 1 : 0;
1510 0487d6a8 j_mayer
}
1511 0487d6a8 j_mayer
1512 0487d6a8 j_mayer
static inline int _do_ecmpgts (int32_t op1, int32_t op2)
1513 0487d6a8 j_mayer
{
1514 0487d6a8 j_mayer
    return op1 > op2 ? 1 : 0;
1515 0487d6a8 j_mayer
}
1516 0487d6a8 j_mayer
1517 0487d6a8 j_mayer
static inline int _do_ecmpgtu (uint32_t op1, uint32_t op2)
1518 0487d6a8 j_mayer
{
1519 0487d6a8 j_mayer
    return op1 > op2 ? 1 : 0;
1520 0487d6a8 j_mayer
}
1521 0487d6a8 j_mayer
1522 0487d6a8 j_mayer
static inline int _do_ecmplts (int32_t op1, int32_t op2)
1523 0487d6a8 j_mayer
{
1524 0487d6a8 j_mayer
    return op1 < op2 ? 1 : 0;
1525 0487d6a8 j_mayer
}
1526 0487d6a8 j_mayer
1527 0487d6a8 j_mayer
static inline int _do_ecmpltu (uint32_t op1, uint32_t op2)
1528 0487d6a8 j_mayer
{
1529 0487d6a8 j_mayer
    return op1 < op2 ? 1 : 0;
1530 0487d6a8 j_mayer
}
1531 0487d6a8 j_mayer
1532 0487d6a8 j_mayer
/* evcmpeq */
1533 0487d6a8 j_mayer
DO_SPE_CMP(cmpeq);
1534 0487d6a8 j_mayer
/* evcmpgts */
1535 0487d6a8 j_mayer
DO_SPE_CMP(cmpgts);
1536 0487d6a8 j_mayer
/* evcmpgtu */
1537 0487d6a8 j_mayer
DO_SPE_CMP(cmpgtu);
1538 0487d6a8 j_mayer
/* evcmplts */
1539 0487d6a8 j_mayer
DO_SPE_CMP(cmplts);
1540 0487d6a8 j_mayer
/* evcmpltu */
1541 0487d6a8 j_mayer
DO_SPE_CMP(cmpltu);
1542 0487d6a8 j_mayer
1543 0487d6a8 j_mayer
/* Single precision floating-point conversions from/to integer */
1544 0487d6a8 j_mayer
static inline uint32_t _do_efscfsi (int32_t val)
1545 0487d6a8 j_mayer
{
1546 0487d6a8 j_mayer
    union {
1547 0487d6a8 j_mayer
        uint32_t u;
1548 0487d6a8 j_mayer
        float32 f;
1549 0487d6a8 j_mayer
    } u;
1550 0487d6a8 j_mayer
1551 0487d6a8 j_mayer
    u.f = int32_to_float32(val, &env->spe_status);
1552 0487d6a8 j_mayer
1553 0487d6a8 j_mayer
    return u.u;
1554 0487d6a8 j_mayer
}
1555 0487d6a8 j_mayer
1556 0487d6a8 j_mayer
static inline uint32_t _do_efscfui (uint32_t val)
1557 0487d6a8 j_mayer
{
1558 0487d6a8 j_mayer
    union {
1559 0487d6a8 j_mayer
        uint32_t u;
1560 0487d6a8 j_mayer
        float32 f;
1561 0487d6a8 j_mayer
    } u;
1562 0487d6a8 j_mayer
1563 0487d6a8 j_mayer
    u.f = uint32_to_float32(val, &env->spe_status);
1564 0487d6a8 j_mayer
1565 0487d6a8 j_mayer
    return u.u;
1566 0487d6a8 j_mayer
}
1567 0487d6a8 j_mayer
1568 0487d6a8 j_mayer
static inline int32_t _do_efsctsi (uint32_t val)
1569 0487d6a8 j_mayer
{
1570 0487d6a8 j_mayer
    union {
1571 0487d6a8 j_mayer
        int32_t u;
1572 0487d6a8 j_mayer
        float32 f;
1573 0487d6a8 j_mayer
    } u;
1574 0487d6a8 j_mayer
1575 0487d6a8 j_mayer
    u.u = val;
1576 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
1577 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
1578 0487d6a8 j_mayer
        return 0;
1579 0487d6a8 j_mayer
1580 0487d6a8 j_mayer
    return float32_to_int32(u.f, &env->spe_status);
1581 0487d6a8 j_mayer
}
1582 0487d6a8 j_mayer
1583 0487d6a8 j_mayer
static inline uint32_t _do_efsctui (uint32_t val)
1584 0487d6a8 j_mayer
{
1585 0487d6a8 j_mayer
    union {
1586 0487d6a8 j_mayer
        int32_t u;
1587 0487d6a8 j_mayer
        float32 f;
1588 0487d6a8 j_mayer
    } u;
1589 0487d6a8 j_mayer
1590 0487d6a8 j_mayer
    u.u = val;
1591 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
1592 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
1593 0487d6a8 j_mayer
        return 0;
1594 0487d6a8 j_mayer
1595 0487d6a8 j_mayer
    return float32_to_uint32(u.f, &env->spe_status);
1596 0487d6a8 j_mayer
}
1597 0487d6a8 j_mayer
1598 0487d6a8 j_mayer
static inline int32_t _do_efsctsiz (uint32_t val)
1599 0487d6a8 j_mayer
{
1600 0487d6a8 j_mayer
    union {
1601 0487d6a8 j_mayer
        int32_t u;
1602 0487d6a8 j_mayer
        float32 f;
1603 0487d6a8 j_mayer
    } u;
1604 0487d6a8 j_mayer
1605 0487d6a8 j_mayer
    u.u = val;
1606 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
1607 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
1608 0487d6a8 j_mayer
        return 0;
1609 0487d6a8 j_mayer
1610 0487d6a8 j_mayer
    return float32_to_int32_round_to_zero(u.f, &env->spe_status);
1611 0487d6a8 j_mayer
}
1612 0487d6a8 j_mayer
1613 0487d6a8 j_mayer
static inline uint32_t _do_efsctuiz (uint32_t val)
1614 0487d6a8 j_mayer
{
1615 0487d6a8 j_mayer
    union {
1616 0487d6a8 j_mayer
        int32_t u;
1617 0487d6a8 j_mayer
        float32 f;
1618 0487d6a8 j_mayer
    } u;
1619 0487d6a8 j_mayer
1620 0487d6a8 j_mayer
    u.u = val;
1621 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
1622 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
1623 0487d6a8 j_mayer
        return 0;
1624 0487d6a8 j_mayer
1625 0487d6a8 j_mayer
    return float32_to_uint32_round_to_zero(u.f, &env->spe_status);
1626 0487d6a8 j_mayer
}
1627 0487d6a8 j_mayer
1628 0487d6a8 j_mayer
void do_efscfsi (void)
1629 0487d6a8 j_mayer
{
1630 0487d6a8 j_mayer
    T0_64 = _do_efscfsi(T0_64);
1631 0487d6a8 j_mayer
}
1632 0487d6a8 j_mayer
1633 0487d6a8 j_mayer
void do_efscfui (void)
1634 0487d6a8 j_mayer
{
1635 0487d6a8 j_mayer
    T0_64 = _do_efscfui(T0_64);
1636 0487d6a8 j_mayer
}
1637 0487d6a8 j_mayer
1638 0487d6a8 j_mayer
void do_efsctsi (void)
1639 0487d6a8 j_mayer
{
1640 0487d6a8 j_mayer
    T0_64 = _do_efsctsi(T0_64);
1641 0487d6a8 j_mayer
}
1642 0487d6a8 j_mayer
1643 0487d6a8 j_mayer
void do_efsctui (void)
1644 0487d6a8 j_mayer
{
1645 0487d6a8 j_mayer
    T0_64 = _do_efsctui(T0_64);
1646 0487d6a8 j_mayer
}
1647 0487d6a8 j_mayer
1648 0487d6a8 j_mayer
void do_efsctsiz (void)
1649 0487d6a8 j_mayer
{
1650 0487d6a8 j_mayer
    T0_64 = _do_efsctsiz(T0_64);
1651 0487d6a8 j_mayer
}
1652 0487d6a8 j_mayer
1653 0487d6a8 j_mayer
void do_efsctuiz (void)
1654 0487d6a8 j_mayer
{
1655 0487d6a8 j_mayer
    T0_64 = _do_efsctuiz(T0_64);
1656 0487d6a8 j_mayer
}
1657 0487d6a8 j_mayer
1658 0487d6a8 j_mayer
/* Single precision floating-point conversion to/from fractional */
1659 0487d6a8 j_mayer
static inline uint32_t _do_efscfsf (uint32_t val)
1660 0487d6a8 j_mayer
{
1661 0487d6a8 j_mayer
    union {
1662 0487d6a8 j_mayer
        uint32_t u;
1663 0487d6a8 j_mayer
        float32 f;
1664 0487d6a8 j_mayer
    } u;
1665 0487d6a8 j_mayer
    float32 tmp;
1666 0487d6a8 j_mayer
1667 0487d6a8 j_mayer
    u.f = int32_to_float32(val, &env->spe_status);
1668 0487d6a8 j_mayer
    tmp = int64_to_float32(1ULL << 32, &env->spe_status);
1669 0487d6a8 j_mayer
    u.f = float32_div(u.f, tmp, &env->spe_status);
1670 0487d6a8 j_mayer
1671 0487d6a8 j_mayer
    return u.u;
1672 0487d6a8 j_mayer
}
1673 0487d6a8 j_mayer
1674 0487d6a8 j_mayer
static inline uint32_t _do_efscfuf (uint32_t val)
1675 0487d6a8 j_mayer
{
1676 0487d6a8 j_mayer
    union {
1677 0487d6a8 j_mayer
        uint32_t u;
1678 0487d6a8 j_mayer
        float32 f;
1679 0487d6a8 j_mayer
    } u;
1680 0487d6a8 j_mayer
    float32 tmp;
1681 0487d6a8 j_mayer
1682 0487d6a8 j_mayer
    u.f = uint32_to_float32(val, &env->spe_status);
1683 0487d6a8 j_mayer
    tmp = uint64_to_float32(1ULL << 32, &env->spe_status);
1684 0487d6a8 j_mayer
    u.f = float32_div(u.f, tmp, &env->spe_status);
1685 0487d6a8 j_mayer
1686 0487d6a8 j_mayer
    return u.u;
1687 0487d6a8 j_mayer
}
1688 0487d6a8 j_mayer
1689 0487d6a8 j_mayer
static inline int32_t _do_efsctsf (uint32_t val)
1690 0487d6a8 j_mayer
{
1691 0487d6a8 j_mayer
    union {
1692 0487d6a8 j_mayer
        int32_t u;
1693 0487d6a8 j_mayer
        float32 f;
1694 0487d6a8 j_mayer
    } u;
1695 0487d6a8 j_mayer
    float32 tmp;
1696 0487d6a8 j_mayer
1697 0487d6a8 j_mayer
    u.u = val;
1698 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
1699 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
1700 0487d6a8 j_mayer
        return 0;
1701 0487d6a8 j_mayer
    tmp = uint64_to_float32(1ULL << 32, &env->spe_status);
1702 0487d6a8 j_mayer
    u.f = float32_mul(u.f, tmp, &env->spe_status);
1703 0487d6a8 j_mayer
1704 0487d6a8 j_mayer
    return float32_to_int32(u.f, &env->spe_status);
1705 0487d6a8 j_mayer
}
1706 0487d6a8 j_mayer
1707 0487d6a8 j_mayer
static inline uint32_t _do_efsctuf (uint32_t val)
1708 0487d6a8 j_mayer
{
1709 0487d6a8 j_mayer
    union {
1710 0487d6a8 j_mayer
        int32_t u;
1711 0487d6a8 j_mayer
        float32 f;
1712 0487d6a8 j_mayer
    } u;
1713 0487d6a8 j_mayer
    float32 tmp;
1714 0487d6a8 j_mayer
1715 0487d6a8 j_mayer
    u.u = val;
1716 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
1717 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
1718 0487d6a8 j_mayer
        return 0;
1719 0487d6a8 j_mayer
    tmp = uint64_to_float32(1ULL << 32, &env->spe_status);
1720 0487d6a8 j_mayer
    u.f = float32_mul(u.f, tmp, &env->spe_status);
1721 0487d6a8 j_mayer
1722 0487d6a8 j_mayer
    return float32_to_uint32(u.f, &env->spe_status);
1723 0487d6a8 j_mayer
}
1724 0487d6a8 j_mayer
1725 0487d6a8 j_mayer
static inline int32_t _do_efsctsfz (uint32_t val)
1726 0487d6a8 j_mayer
{
1727 0487d6a8 j_mayer
    union {
1728 0487d6a8 j_mayer
        int32_t u;
1729 0487d6a8 j_mayer
        float32 f;
1730 0487d6a8 j_mayer
    } u;
1731 0487d6a8 j_mayer
    float32 tmp;
1732 0487d6a8 j_mayer
1733 0487d6a8 j_mayer
    u.u = val;
1734 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
1735 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
1736 0487d6a8 j_mayer
        return 0;
1737 0487d6a8 j_mayer
    tmp = uint64_to_float32(1ULL << 32, &env->spe_status);
1738 0487d6a8 j_mayer
    u.f = float32_mul(u.f, tmp, &env->spe_status);
1739 0487d6a8 j_mayer
1740 0487d6a8 j_mayer
    return float32_to_int32_round_to_zero(u.f, &env->spe_status);
1741 0487d6a8 j_mayer
}
1742 0487d6a8 j_mayer
1743 0487d6a8 j_mayer
static inline uint32_t _do_efsctufz (uint32_t val)
1744 0487d6a8 j_mayer
{
1745 0487d6a8 j_mayer
    union {
1746 0487d6a8 j_mayer
        int32_t u;
1747 0487d6a8 j_mayer
        float32 f;
1748 0487d6a8 j_mayer
    } u;
1749 0487d6a8 j_mayer
    float32 tmp;
1750 0487d6a8 j_mayer
1751 0487d6a8 j_mayer
    u.u = val;
1752 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
1753 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
1754 0487d6a8 j_mayer
        return 0;
1755 0487d6a8 j_mayer
    tmp = uint64_to_float32(1ULL << 32, &env->spe_status);
1756 0487d6a8 j_mayer
    u.f = float32_mul(u.f, tmp, &env->spe_status);
1757 0487d6a8 j_mayer
1758 0487d6a8 j_mayer
    return float32_to_uint32_round_to_zero(u.f, &env->spe_status);
1759 0487d6a8 j_mayer
}
1760 0487d6a8 j_mayer
1761 0487d6a8 j_mayer
void do_efscfsf (void)
1762 0487d6a8 j_mayer
{
1763 0487d6a8 j_mayer
    T0_64 = _do_efscfsf(T0_64);
1764 0487d6a8 j_mayer
}
1765 0487d6a8 j_mayer
1766 0487d6a8 j_mayer
void do_efscfuf (void)
1767 0487d6a8 j_mayer
{
1768 0487d6a8 j_mayer
    T0_64 = _do_efscfuf(T0_64);
1769 0487d6a8 j_mayer
}
1770 0487d6a8 j_mayer
1771 0487d6a8 j_mayer
void do_efsctsf (void)
1772 0487d6a8 j_mayer
{
1773 0487d6a8 j_mayer
    T0_64 = _do_efsctsf(T0_64);
1774 0487d6a8 j_mayer
}
1775 0487d6a8 j_mayer
1776 0487d6a8 j_mayer
void do_efsctuf (void)
1777 0487d6a8 j_mayer
{
1778 0487d6a8 j_mayer
    T0_64 = _do_efsctuf(T0_64);
1779 0487d6a8 j_mayer
}
1780 0487d6a8 j_mayer
1781 0487d6a8 j_mayer
void do_efsctsfz (void)
1782 0487d6a8 j_mayer
{
1783 0487d6a8 j_mayer
    T0_64 = _do_efsctsfz(T0_64);
1784 0487d6a8 j_mayer
}
1785 0487d6a8 j_mayer
1786 0487d6a8 j_mayer
void do_efsctufz (void)
1787 0487d6a8 j_mayer
{
1788 0487d6a8 j_mayer
    T0_64 = _do_efsctufz(T0_64);
1789 0487d6a8 j_mayer
}
1790 0487d6a8 j_mayer
1791 0487d6a8 j_mayer
/* Double precision floating point helpers */
1792 0487d6a8 j_mayer
static inline int _do_efdcmplt (uint64_t op1, uint64_t op2)
1793 0487d6a8 j_mayer
{
1794 0487d6a8 j_mayer
    /* XXX: TODO: test special values (NaN, infinites, ...) */
1795 0487d6a8 j_mayer
    return _do_efdtstlt(op1, op2);
1796 0487d6a8 j_mayer
}
1797 0487d6a8 j_mayer
1798 0487d6a8 j_mayer
static inline int _do_efdcmpgt (uint64_t op1, uint64_t op2)
1799 0487d6a8 j_mayer
{
1800 0487d6a8 j_mayer
    /* XXX: TODO: test special values (NaN, infinites, ...) */
1801 0487d6a8 j_mayer
    return _do_efdtstgt(op1, op2);
1802 0487d6a8 j_mayer
}
1803 0487d6a8 j_mayer
1804 0487d6a8 j_mayer
static inline int _do_efdcmpeq (uint64_t op1, uint64_t op2)
1805 0487d6a8 j_mayer
{
1806 0487d6a8 j_mayer
    /* XXX: TODO: test special values (NaN, infinites, ...) */
1807 0487d6a8 j_mayer
    return _do_efdtsteq(op1, op2);
1808 0487d6a8 j_mayer
}
1809 0487d6a8 j_mayer
1810 0487d6a8 j_mayer
void do_efdcmplt (void)
1811 0487d6a8 j_mayer
{
1812 0487d6a8 j_mayer
    T0 = _do_efdcmplt(T0_64, T1_64);
1813 0487d6a8 j_mayer
}
1814 0487d6a8 j_mayer
1815 0487d6a8 j_mayer
void do_efdcmpgt (void)
1816 0487d6a8 j_mayer
{
1817 0487d6a8 j_mayer
    T0 = _do_efdcmpgt(T0_64, T1_64);
1818 0487d6a8 j_mayer
}
1819 0487d6a8 j_mayer
1820 0487d6a8 j_mayer
void do_efdcmpeq (void)
1821 0487d6a8 j_mayer
{
1822 0487d6a8 j_mayer
    T0 = _do_efdcmpeq(T0_64, T1_64);
1823 0487d6a8 j_mayer
}
1824 0487d6a8 j_mayer
1825 0487d6a8 j_mayer
/* Double precision floating-point conversion to/from integer */
1826 0487d6a8 j_mayer
static inline uint64_t _do_efdcfsi (int64_t val)
1827 0487d6a8 j_mayer
{
1828 0487d6a8 j_mayer
    union {
1829 0487d6a8 j_mayer
        uint64_t u;
1830 0487d6a8 j_mayer
        float64 f;
1831 0487d6a8 j_mayer
    } u;
1832 0487d6a8 j_mayer
1833 0487d6a8 j_mayer
    u.f = int64_to_float64(val, &env->spe_status);
1834 0487d6a8 j_mayer
1835 0487d6a8 j_mayer
    return u.u;
1836 0487d6a8 j_mayer
}
1837 0487d6a8 j_mayer
1838 0487d6a8 j_mayer
static inline uint64_t _do_efdcfui (uint64_t val)
1839 0487d6a8 j_mayer
{
1840 0487d6a8 j_mayer
    union {
1841 0487d6a8 j_mayer
        uint64_t u;
1842 0487d6a8 j_mayer
        float64 f;
1843 0487d6a8 j_mayer
    } u;
1844 0487d6a8 j_mayer
1845 0487d6a8 j_mayer
    u.f = uint64_to_float64(val, &env->spe_status);
1846 0487d6a8 j_mayer
1847 0487d6a8 j_mayer
    return u.u;
1848 0487d6a8 j_mayer
}
1849 0487d6a8 j_mayer
1850 0487d6a8 j_mayer
static inline int64_t _do_efdctsi (uint64_t val)
1851 0487d6a8 j_mayer
{
1852 0487d6a8 j_mayer
    union {
1853 0487d6a8 j_mayer
        int64_t u;
1854 0487d6a8 j_mayer
        float64 f;
1855 0487d6a8 j_mayer
    } u;
1856 0487d6a8 j_mayer
1857 0487d6a8 j_mayer
    u.u = val;
1858 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
1859 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
1860 0487d6a8 j_mayer
        return 0;
1861 0487d6a8 j_mayer
1862 0487d6a8 j_mayer
    return float64_to_int64(u.f, &env->spe_status);
1863 0487d6a8 j_mayer
}
1864 0487d6a8 j_mayer
1865 0487d6a8 j_mayer
static inline uint64_t _do_efdctui (uint64_t val)
1866 0487d6a8 j_mayer
{
1867 0487d6a8 j_mayer
    union {
1868 0487d6a8 j_mayer
        int64_t u;
1869 0487d6a8 j_mayer
        float64 f;
1870 0487d6a8 j_mayer
    } u;
1871 0487d6a8 j_mayer
1872 0487d6a8 j_mayer
    u.u = val;
1873 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
1874 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
1875 0487d6a8 j_mayer
        return 0;
1876 0487d6a8 j_mayer
1877 0487d6a8 j_mayer
    return float64_to_uint64(u.f, &env->spe_status);
1878 0487d6a8 j_mayer
}
1879 0487d6a8 j_mayer
1880 0487d6a8 j_mayer
static inline int64_t _do_efdctsiz (uint64_t val)
1881 0487d6a8 j_mayer
{
1882 0487d6a8 j_mayer
    union {
1883 0487d6a8 j_mayer
        int64_t u;
1884 0487d6a8 j_mayer
        float64 f;
1885 0487d6a8 j_mayer
    } u;
1886 0487d6a8 j_mayer
1887 0487d6a8 j_mayer
    u.u = val;
1888 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
1889 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
1890 0487d6a8 j_mayer
        return 0;
1891 0487d6a8 j_mayer
1892 0487d6a8 j_mayer
    return float64_to_int64_round_to_zero(u.f, &env->spe_status);
1893 0487d6a8 j_mayer
}
1894 0487d6a8 j_mayer
1895 0487d6a8 j_mayer
static inline uint64_t _do_efdctuiz (uint64_t val)
1896 0487d6a8 j_mayer
{
1897 0487d6a8 j_mayer
    union {
1898 0487d6a8 j_mayer
        int64_t u;
1899 0487d6a8 j_mayer
        float64 f;
1900 0487d6a8 j_mayer
    } u;
1901 0487d6a8 j_mayer
1902 0487d6a8 j_mayer
    u.u = val;
1903 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
1904 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
1905 0487d6a8 j_mayer
        return 0;
1906 0487d6a8 j_mayer
1907 0487d6a8 j_mayer
    return float64_to_uint64_round_to_zero(u.f, &env->spe_status);
1908 0487d6a8 j_mayer
}
1909 0487d6a8 j_mayer
1910 0487d6a8 j_mayer
void do_efdcfsi (void)
1911 0487d6a8 j_mayer
{
1912 0487d6a8 j_mayer
    T0_64 = _do_efdcfsi(T0_64);
1913 0487d6a8 j_mayer
}
1914 0487d6a8 j_mayer
1915 0487d6a8 j_mayer
void do_efdcfui (void)
1916 0487d6a8 j_mayer
{
1917 0487d6a8 j_mayer
    T0_64 = _do_efdcfui(T0_64);
1918 0487d6a8 j_mayer
}
1919 0487d6a8 j_mayer
1920 0487d6a8 j_mayer
void do_efdctsi (void)
1921 0487d6a8 j_mayer
{
1922 0487d6a8 j_mayer
    T0_64 = _do_efdctsi(T0_64);
1923 0487d6a8 j_mayer
}
1924 0487d6a8 j_mayer
1925 0487d6a8 j_mayer
void do_efdctui (void)
1926 0487d6a8 j_mayer
{
1927 0487d6a8 j_mayer
    T0_64 = _do_efdctui(T0_64);
1928 0487d6a8 j_mayer
}
1929 0487d6a8 j_mayer
1930 0487d6a8 j_mayer
void do_efdctsiz (void)
1931 0487d6a8 j_mayer
{
1932 0487d6a8 j_mayer
    T0_64 = _do_efdctsiz(T0_64);
1933 0487d6a8 j_mayer
}
1934 0487d6a8 j_mayer
1935 0487d6a8 j_mayer
void do_efdctuiz (void)
1936 0487d6a8 j_mayer
{
1937 0487d6a8 j_mayer
    T0_64 = _do_efdctuiz(T0_64);
1938 0487d6a8 j_mayer
}
1939 0487d6a8 j_mayer
1940 0487d6a8 j_mayer
/* Double precision floating-point conversion to/from fractional */
1941 0487d6a8 j_mayer
static inline uint64_t _do_efdcfsf (int64_t val)
1942 0487d6a8 j_mayer
{
1943 0487d6a8 j_mayer
    union {
1944 0487d6a8 j_mayer
        uint64_t u;
1945 0487d6a8 j_mayer
        float64 f;
1946 0487d6a8 j_mayer
    } u;
1947 0487d6a8 j_mayer
    float64 tmp;
1948 0487d6a8 j_mayer
1949 0487d6a8 j_mayer
    u.f = int32_to_float64(val, &env->spe_status);
1950 0487d6a8 j_mayer
    tmp = int64_to_float64(1ULL << 32, &env->spe_status);
1951 0487d6a8 j_mayer
    u.f = float64_div(u.f, tmp, &env->spe_status);
1952 0487d6a8 j_mayer
1953 0487d6a8 j_mayer
    return u.u;
1954 0487d6a8 j_mayer
}
1955 0487d6a8 j_mayer
1956 0487d6a8 j_mayer
static inline uint64_t _do_efdcfuf (uint64_t val)
1957 0487d6a8 j_mayer
{
1958 0487d6a8 j_mayer
    union {
1959 0487d6a8 j_mayer
        uint64_t u;
1960 0487d6a8 j_mayer
        float64 f;
1961 0487d6a8 j_mayer
    } u;
1962 0487d6a8 j_mayer
    float64 tmp;
1963 0487d6a8 j_mayer
1964 0487d6a8 j_mayer
    u.f = uint32_to_float64(val, &env->spe_status);
1965 0487d6a8 j_mayer
    tmp = int64_to_float64(1ULL << 32, &env->spe_status);
1966 0487d6a8 j_mayer
    u.f = float64_div(u.f, tmp, &env->spe_status);
1967 0487d6a8 j_mayer
1968 0487d6a8 j_mayer
    return u.u;
1969 0487d6a8 j_mayer
}
1970 0487d6a8 j_mayer
1971 0487d6a8 j_mayer
static inline int64_t _do_efdctsf (uint64_t val)
1972 0487d6a8 j_mayer
{
1973 0487d6a8 j_mayer
    union {
1974 0487d6a8 j_mayer
        int64_t u;
1975 0487d6a8 j_mayer
        float64 f;
1976 0487d6a8 j_mayer
    } u;
1977 0487d6a8 j_mayer
    float64 tmp;
1978 0487d6a8 j_mayer
1979 0487d6a8 j_mayer
    u.u = val;
1980 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
1981 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
1982 0487d6a8 j_mayer
        return 0;
1983 0487d6a8 j_mayer
    tmp = uint64_to_float64(1ULL << 32, &env->spe_status);
1984 0487d6a8 j_mayer
    u.f = float64_mul(u.f, tmp, &env->spe_status);
1985 0487d6a8 j_mayer
1986 0487d6a8 j_mayer
    return float64_to_int32(u.f, &env->spe_status);
1987 0487d6a8 j_mayer
}
1988 0487d6a8 j_mayer
1989 0487d6a8 j_mayer
static inline uint64_t _do_efdctuf (uint64_t val)
1990 0487d6a8 j_mayer
{
1991 0487d6a8 j_mayer
    union {
1992 0487d6a8 j_mayer
        int64_t u;
1993 0487d6a8 j_mayer
        float64 f;
1994 0487d6a8 j_mayer
    } u;
1995 0487d6a8 j_mayer
    float64 tmp;
1996 0487d6a8 j_mayer
1997 0487d6a8 j_mayer
    u.u = val;
1998 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
1999 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
2000 0487d6a8 j_mayer
        return 0;
2001 0487d6a8 j_mayer
    tmp = uint64_to_float64(1ULL << 32, &env->spe_status);
2002 0487d6a8 j_mayer
    u.f = float64_mul(u.f, tmp, &env->spe_status);
2003 0487d6a8 j_mayer
2004 0487d6a8 j_mayer
    return float64_to_uint32(u.f, &env->spe_status);
2005 0487d6a8 j_mayer
}
2006 0487d6a8 j_mayer
2007 0487d6a8 j_mayer
static inline int64_t _do_efdctsfz (uint64_t val)
2008 0487d6a8 j_mayer
{
2009 0487d6a8 j_mayer
    union {
2010 0487d6a8 j_mayer
        int64_t u;
2011 0487d6a8 j_mayer
        float64 f;
2012 0487d6a8 j_mayer
    } u;
2013 0487d6a8 j_mayer
    float64 tmp;
2014 0487d6a8 j_mayer
2015 0487d6a8 j_mayer
    u.u = val;
2016 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
2017 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
2018 0487d6a8 j_mayer
        return 0;
2019 0487d6a8 j_mayer
    tmp = uint64_to_float64(1ULL << 32, &env->spe_status);
2020 0487d6a8 j_mayer
    u.f = float64_mul(u.f, tmp, &env->spe_status);
2021 0487d6a8 j_mayer
2022 0487d6a8 j_mayer
    return float64_to_int32_round_to_zero(u.f, &env->spe_status);
2023 0487d6a8 j_mayer
}
2024 0487d6a8 j_mayer
2025 0487d6a8 j_mayer
static inline uint64_t _do_efdctufz (uint64_t val)
2026 0487d6a8 j_mayer
{
2027 0487d6a8 j_mayer
    union {
2028 0487d6a8 j_mayer
        int64_t u;
2029 0487d6a8 j_mayer
        float64 f;
2030 0487d6a8 j_mayer
    } u;
2031 0487d6a8 j_mayer
    float64 tmp;
2032 0487d6a8 j_mayer
2033 0487d6a8 j_mayer
    u.u = val;
2034 0487d6a8 j_mayer
    /* NaN are not treated the same way IEEE 754 does */
2035 0487d6a8 j_mayer
    if (unlikely(isnan(u.f)))
2036 0487d6a8 j_mayer
        return 0;
2037 0487d6a8 j_mayer
    tmp = uint64_to_float64(1ULL << 32, &env->spe_status);
2038 0487d6a8 j_mayer
    u.f = float64_mul(u.f, tmp, &env->spe_status);
2039 0487d6a8 j_mayer
2040 0487d6a8 j_mayer
    return float64_to_uint32_round_to_zero(u.f, &env->spe_status);
2041 0487d6a8 j_mayer
}
2042 0487d6a8 j_mayer
2043 0487d6a8 j_mayer
void do_efdcfsf (void)
2044 0487d6a8 j_mayer
{
2045 0487d6a8 j_mayer
    T0_64 = _do_efdcfsf(T0_64);
2046 0487d6a8 j_mayer
}
2047 0487d6a8 j_mayer
2048 0487d6a8 j_mayer
void do_efdcfuf (void)
2049 0487d6a8 j_mayer
{
2050 0487d6a8 j_mayer
    T0_64 = _do_efdcfuf(T0_64);
2051 0487d6a8 j_mayer
}
2052 0487d6a8 j_mayer
2053 0487d6a8 j_mayer
void do_efdctsf (void)
2054 0487d6a8 j_mayer
{
2055 0487d6a8 j_mayer
    T0_64 = _do_efdctsf(T0_64);
2056 0487d6a8 j_mayer
}
2057 0487d6a8 j_mayer
2058 0487d6a8 j_mayer
void do_efdctuf (void)
2059 0487d6a8 j_mayer
{
2060 0487d6a8 j_mayer
    T0_64 = _do_efdctuf(T0_64);
2061 0487d6a8 j_mayer
}
2062 0487d6a8 j_mayer
2063 0487d6a8 j_mayer
void do_efdctsfz (void)
2064 0487d6a8 j_mayer
{
2065 0487d6a8 j_mayer
    T0_64 = _do_efdctsfz(T0_64);
2066 0487d6a8 j_mayer
}
2067 0487d6a8 j_mayer
2068 0487d6a8 j_mayer
void do_efdctufz (void)
2069 0487d6a8 j_mayer
{
2070 0487d6a8 j_mayer
    T0_64 = _do_efdctufz(T0_64);
2071 0487d6a8 j_mayer
}
2072 0487d6a8 j_mayer
2073 0487d6a8 j_mayer
/* Floating point conversion between single and double precision */
2074 0487d6a8 j_mayer
static inline uint32_t _do_efscfd (uint64_t val)
2075 0487d6a8 j_mayer
{
2076 0487d6a8 j_mayer
    union {
2077 0487d6a8 j_mayer
        uint64_t u;
2078 0487d6a8 j_mayer
        float64 f;
2079 0487d6a8 j_mayer
    } u1;
2080 0487d6a8 j_mayer
    union {
2081 0487d6a8 j_mayer
        uint32_t u;
2082 0487d6a8 j_mayer
        float32 f;
2083 0487d6a8 j_mayer
    } u2;
2084 0487d6a8 j_mayer
2085 0487d6a8 j_mayer
    u1.u = val;
2086 0487d6a8 j_mayer
    u2.f = float64_to_float32(u1.f, &env->spe_status);
2087 0487d6a8 j_mayer
2088 0487d6a8 j_mayer
    return u2.u;
2089 0487d6a8 j_mayer
}
2090 0487d6a8 j_mayer
2091 0487d6a8 j_mayer
static inline uint64_t _do_efdcfs (uint32_t val)
2092 0487d6a8 j_mayer
{
2093 0487d6a8 j_mayer
    union {
2094 0487d6a8 j_mayer
        uint64_t u;
2095 0487d6a8 j_mayer
        float64 f;
2096 0487d6a8 j_mayer
    } u2;
2097 0487d6a8 j_mayer
    union {
2098 0487d6a8 j_mayer
        uint32_t u;
2099 0487d6a8 j_mayer
        float32 f;
2100 0487d6a8 j_mayer
    } u1;
2101 0487d6a8 j_mayer
2102 0487d6a8 j_mayer
    u1.u = val;
2103 0487d6a8 j_mayer
    u2.f = float32_to_float64(u1.f, &env->spe_status);
2104 0487d6a8 j_mayer
2105 0487d6a8 j_mayer
    return u2.u;
2106 0487d6a8 j_mayer
}
2107 0487d6a8 j_mayer
2108 0487d6a8 j_mayer
void do_efscfd (void)
2109 0487d6a8 j_mayer
{
2110 0487d6a8 j_mayer
    T0_64 = _do_efscfd(T0_64);
2111 0487d6a8 j_mayer
}
2112 0487d6a8 j_mayer
2113 0487d6a8 j_mayer
void do_efdcfs (void)
2114 0487d6a8 j_mayer
{
2115 0487d6a8 j_mayer
    T0_64 = _do_efdcfs(T0_64);
2116 0487d6a8 j_mayer
}
2117 0487d6a8 j_mayer
2118 0487d6a8 j_mayer
/* Single precision fixed-point vector arithmetic */
2119 0487d6a8 j_mayer
/* evfsabs */
2120 0487d6a8 j_mayer
DO_SPE_OP1(fsabs);
2121 0487d6a8 j_mayer
/* evfsnabs */
2122 0487d6a8 j_mayer
DO_SPE_OP1(fsnabs);
2123 0487d6a8 j_mayer
/* evfsneg */
2124 0487d6a8 j_mayer
DO_SPE_OP1(fsneg);
2125 0487d6a8 j_mayer
/* evfsadd */
2126 0487d6a8 j_mayer
DO_SPE_OP2(fsadd);
2127 0487d6a8 j_mayer
/* evfssub */
2128 0487d6a8 j_mayer
DO_SPE_OP2(fssub);
2129 0487d6a8 j_mayer
/* evfsmul */
2130 0487d6a8 j_mayer
DO_SPE_OP2(fsmul);
2131 0487d6a8 j_mayer
/* evfsdiv */
2132 0487d6a8 j_mayer
DO_SPE_OP2(fsdiv);
2133 0487d6a8 j_mayer
2134 0487d6a8 j_mayer
/* Single-precision floating-point comparisons */
2135 0487d6a8 j_mayer
static inline int _do_efscmplt (uint32_t op1, uint32_t op2)
2136 0487d6a8 j_mayer
{
2137 0487d6a8 j_mayer
    /* XXX: TODO: test special values (NaN, infinites, ...) */
2138 0487d6a8 j_mayer
    return _do_efststlt(op1, op2);
2139 0487d6a8 j_mayer
}
2140 0487d6a8 j_mayer
2141 0487d6a8 j_mayer
static inline int _do_efscmpgt (uint32_t op1, uint32_t op2)
2142 0487d6a8 j_mayer
{
2143 0487d6a8 j_mayer
    /* XXX: TODO: test special values (NaN, infinites, ...) */
2144 0487d6a8 j_mayer
    return _do_efststgt(op1, op2);
2145 0487d6a8 j_mayer
}
2146 0487d6a8 j_mayer
2147 0487d6a8 j_mayer
static inline int _do_efscmpeq (uint32_t op1, uint32_t op2)
2148 0487d6a8 j_mayer
{
2149 0487d6a8 j_mayer
    /* XXX: TODO: test special values (NaN, infinites, ...) */
2150 0487d6a8 j_mayer
    return _do_efststeq(op1, op2);
2151 0487d6a8 j_mayer
}
2152 0487d6a8 j_mayer
2153 0487d6a8 j_mayer
void do_efscmplt (void)
2154 0487d6a8 j_mayer
{
2155 0487d6a8 j_mayer
    T0 = _do_efscmplt(T0_64, T1_64);
2156 0487d6a8 j_mayer
}
2157 0487d6a8 j_mayer
2158 0487d6a8 j_mayer
void do_efscmpgt (void)
2159 0487d6a8 j_mayer
{
2160 0487d6a8 j_mayer
    T0 = _do_efscmpgt(T0_64, T1_64);
2161 0487d6a8 j_mayer
}
2162 0487d6a8 j_mayer
2163 0487d6a8 j_mayer
void do_efscmpeq (void)
2164 0487d6a8 j_mayer
{
2165 0487d6a8 j_mayer
    T0 = _do_efscmpeq(T0_64, T1_64);
2166 0487d6a8 j_mayer
}
2167 0487d6a8 j_mayer
2168 0487d6a8 j_mayer
/* Single-precision floating-point vector comparisons */
2169 0487d6a8 j_mayer
/* evfscmplt */
2170 0487d6a8 j_mayer
DO_SPE_CMP(fscmplt);
2171 0487d6a8 j_mayer
/* evfscmpgt */
2172 0487d6a8 j_mayer
DO_SPE_CMP(fscmpgt);
2173 0487d6a8 j_mayer
/* evfscmpeq */
2174 0487d6a8 j_mayer
DO_SPE_CMP(fscmpeq);
2175 0487d6a8 j_mayer
/* evfststlt */
2176 0487d6a8 j_mayer
DO_SPE_CMP(fststlt);
2177 0487d6a8 j_mayer
/* evfststgt */
2178 0487d6a8 j_mayer
DO_SPE_CMP(fststgt);
2179 0487d6a8 j_mayer
/* evfststeq */
2180 0487d6a8 j_mayer
DO_SPE_CMP(fststeq);
2181 0487d6a8 j_mayer
2182 0487d6a8 j_mayer
/* Single-precision floating-point vector conversions */
2183 0487d6a8 j_mayer
/* evfscfsi */
2184 0487d6a8 j_mayer
DO_SPE_OP1(fscfsi);
2185 0487d6a8 j_mayer
/* evfscfui */
2186 0487d6a8 j_mayer
DO_SPE_OP1(fscfui);
2187 0487d6a8 j_mayer
/* evfscfuf */
2188 0487d6a8 j_mayer
DO_SPE_OP1(fscfuf);
2189 0487d6a8 j_mayer
/* evfscfsf */
2190 0487d6a8 j_mayer
DO_SPE_OP1(fscfsf);
2191 0487d6a8 j_mayer
/* evfsctsi */
2192 0487d6a8 j_mayer
DO_SPE_OP1(fsctsi);
2193 0487d6a8 j_mayer
/* evfsctui */
2194 0487d6a8 j_mayer
DO_SPE_OP1(fsctui);
2195 0487d6a8 j_mayer
/* evfsctsiz */
2196 0487d6a8 j_mayer
DO_SPE_OP1(fsctsiz);
2197 0487d6a8 j_mayer
/* evfsctuiz */
2198 0487d6a8 j_mayer
DO_SPE_OP1(fsctuiz);
2199 0487d6a8 j_mayer
/* evfsctsf */
2200 0487d6a8 j_mayer
DO_SPE_OP1(fsctsf);
2201 0487d6a8 j_mayer
/* evfsctuf */
2202 0487d6a8 j_mayer
DO_SPE_OP1(fsctuf);
2203 0487d6a8 j_mayer
#endif /* defined(TARGET_PPCSPE) */
2204 0487d6a8 j_mayer
2205 fdabc366 bellard
/*****************************************************************************/
2206 fdabc366 bellard
/* Softmmu support */
2207 fdabc366 bellard
#if !defined (CONFIG_USER_ONLY)
2208 fdabc366 bellard
2209 fdabc366 bellard
#define MMUSUFFIX _mmu
2210 fdabc366 bellard
#define GETPC() (__builtin_return_address(0))
2211 fdabc366 bellard
2212 fdabc366 bellard
#define SHIFT 0
2213 fdabc366 bellard
#include "softmmu_template.h"
2214 fdabc366 bellard
2215 fdabc366 bellard
#define SHIFT 1
2216 fdabc366 bellard
#include "softmmu_template.h"
2217 fdabc366 bellard
2218 fdabc366 bellard
#define SHIFT 2
2219 fdabc366 bellard
#include "softmmu_template.h"
2220 fdabc366 bellard
2221 fdabc366 bellard
#define SHIFT 3
2222 fdabc366 bellard
#include "softmmu_template.h"
2223 fdabc366 bellard
2224 fdabc366 bellard
/* try to fill the TLB and return an exception if error. If retaddr is
2225 fdabc366 bellard
   NULL, it means that the function was called in C code (i.e. not
2226 fdabc366 bellard
   from generated code or from helper.c) */
2227 fdabc366 bellard
/* XXX: fix it to restore all registers */
2228 fdabc366 bellard
void tlb_fill (target_ulong addr, int is_write, int is_user, void *retaddr)
2229 fdabc366 bellard
{
2230 fdabc366 bellard
    TranslationBlock *tb;
2231 fdabc366 bellard
    CPUState *saved_env;
2232 fdabc366 bellard
    target_phys_addr_t pc;
2233 fdabc366 bellard
    int ret;
2234 fdabc366 bellard
2235 fdabc366 bellard
    /* XXX: hack to restore env in all cases, even if not called from
2236 fdabc366 bellard
       generated code */
2237 fdabc366 bellard
    saved_env = env;
2238 fdabc366 bellard
    env = cpu_single_env;
2239 fdabc366 bellard
    ret = cpu_ppc_handle_mmu_fault(env, addr, is_write, is_user, 1);
2240 76a66253 j_mayer
    if (unlikely(ret != 0)) {
2241 fdabc366 bellard
        if (likely(retaddr)) {
2242 fdabc366 bellard
            /* now we have a real cpu fault */
2243 fdabc366 bellard
            pc = (target_phys_addr_t)retaddr;
2244 fdabc366 bellard
            tb = tb_find_pc(pc);
2245 fdabc366 bellard
            if (likely(tb)) {
2246 fdabc366 bellard
                /* the PC is inside the translated code. It means that we have
2247 fdabc366 bellard
                   a virtual CPU fault */
2248 fdabc366 bellard
                cpu_restore_state(tb, env, pc, NULL);
2249 76a66253 j_mayer
            }
2250 fdabc366 bellard
        }
2251 fdabc366 bellard
        do_raise_exception_err(env->exception_index, env->error_code);
2252 fdabc366 bellard
    }
2253 fdabc366 bellard
    env = saved_env;
2254 9a64fbe4 bellard
}
2255 9a64fbe4 bellard
2256 76a66253 j_mayer
/* TLB invalidation helpers */
2257 76a66253 j_mayer
void do_tlbia (void)
2258 76a66253 j_mayer
{
2259 0a032cbe j_mayer
    ppc_tlb_invalidate_all(env);
2260 76a66253 j_mayer
}
2261 76a66253 j_mayer
2262 76a66253 j_mayer
void do_tlbie (void)
2263 76a66253 j_mayer
{
2264 d9bce9d9 j_mayer
    T0 = (uint32_t)T0;
2265 76a66253 j_mayer
#if !defined(FLUSH_ALL_TLBS)
2266 76a66253 j_mayer
    if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_6xx)) {
2267 76a66253 j_mayer
        ppc6xx_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK, 0);
2268 76a66253 j_mayer
        if (env->id_tlbs == 1)
2269 76a66253 j_mayer
            ppc6xx_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK, 1);
2270 76a66253 j_mayer
    } else if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_4xx)) {
2271 76a66253 j_mayer
        /* XXX: TODO */
2272 76a66253 j_mayer
#if 0
2273 76a66253 j_mayer
        ppcbooke_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK,
2274 76a66253 j_mayer
                                     env->spr[SPR_BOOKE_PID]);
2275 76a66253 j_mayer
#endif
2276 76a66253 j_mayer
    } else {
2277 76a66253 j_mayer
        /* tlbie invalidate TLBs for all segments */
2278 76a66253 j_mayer
        T0 &= TARGET_PAGE_MASK;
2279 76a66253 j_mayer
        T0 &= ~((target_ulong)-1 << 28);
2280 76a66253 j_mayer
        /* XXX: this case should be optimized,
2281 76a66253 j_mayer
         * giving a mask to tlb_flush_page
2282 76a66253 j_mayer
         */
2283 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0x0 << 28));
2284 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0x1 << 28));
2285 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0x2 << 28));
2286 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0x3 << 28));
2287 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0x4 << 28));
2288 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0x5 << 28));
2289 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0x6 << 28));
2290 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0x7 << 28));
2291 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0x8 << 28));
2292 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0x9 << 28));
2293 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0xA << 28));
2294 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0xB << 28));
2295 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0xC << 28));
2296 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0xD << 28));
2297 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0xE << 28));
2298 76a66253 j_mayer
        tlb_flush_page(env, T0 | (0xF << 28));
2299 76a66253 j_mayer
    }
2300 76a66253 j_mayer
#else
2301 76a66253 j_mayer
    do_tlbia();
2302 76a66253 j_mayer
#endif
2303 76a66253 j_mayer
}
2304 76a66253 j_mayer
2305 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
2306 d9bce9d9 j_mayer
void do_tlbie_64 (void)
2307 d9bce9d9 j_mayer
{
2308 d9bce9d9 j_mayer
    T0 = (uint64_t)T0;
2309 d9bce9d9 j_mayer
#if !defined(FLUSH_ALL_TLBS)
2310 d9bce9d9 j_mayer
    if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_6xx)) {
2311 d9bce9d9 j_mayer
        ppc6xx_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK, 0);
2312 d9bce9d9 j_mayer
        if (env->id_tlbs == 1)
2313 d9bce9d9 j_mayer
            ppc6xx_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK, 1);
2314 d9bce9d9 j_mayer
    } else if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_4xx)) {
2315 d9bce9d9 j_mayer
        /* XXX: TODO */
2316 d9bce9d9 j_mayer
#if 0
2317 d9bce9d9 j_mayer
        ppcbooke_tlb_invalidate_virt(env, T0 & TARGET_PAGE_MASK,
2318 d9bce9d9 j_mayer
                                     env->spr[SPR_BOOKE_PID]);
2319 d9bce9d9 j_mayer
#endif
2320 d9bce9d9 j_mayer
    } else {
2321 d9bce9d9 j_mayer
        /* tlbie invalidate TLBs for all segments
2322 d9bce9d9 j_mayer
         * As we have 2^36 segments, invalidate all qemu TLBs
2323 d9bce9d9 j_mayer
         */
2324 d9bce9d9 j_mayer
#if 0
2325 d9bce9d9 j_mayer
        T0 &= TARGET_PAGE_MASK;
2326 d9bce9d9 j_mayer
        T0 &= ~((target_ulong)-1 << 28);
2327 d9bce9d9 j_mayer
        /* XXX: this case should be optimized,
2328 d9bce9d9 j_mayer
         * giving a mask to tlb_flush_page
2329 d9bce9d9 j_mayer
         */
2330 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0x0 << 28));
2331 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0x1 << 28));
2332 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0x2 << 28));
2333 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0x3 << 28));
2334 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0x4 << 28));
2335 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0x5 << 28));
2336 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0x6 << 28));
2337 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0x7 << 28));
2338 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0x8 << 28));
2339 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0x9 << 28));
2340 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0xA << 28));
2341 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0xB << 28));
2342 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0xC << 28));
2343 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0xD << 28));
2344 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0xE << 28));
2345 d9bce9d9 j_mayer
        tlb_flush_page(env, T0 | (0xF << 28));
2346 d9bce9d9 j_mayer
#else
2347 d9bce9d9 j_mayer
        tlb_flush(env, 1);
2348 d9bce9d9 j_mayer
#endif
2349 d9bce9d9 j_mayer
    }
2350 d9bce9d9 j_mayer
#else
2351 d9bce9d9 j_mayer
    do_tlbia();
2352 d9bce9d9 j_mayer
#endif
2353 d9bce9d9 j_mayer
}
2354 d9bce9d9 j_mayer
#endif
2355 d9bce9d9 j_mayer
2356 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
2357 d9bce9d9 j_mayer
void do_slbia (void)
2358 d9bce9d9 j_mayer
{
2359 d9bce9d9 j_mayer
    /* XXX: TODO */
2360 d9bce9d9 j_mayer
    tlb_flush(env, 1);
2361 d9bce9d9 j_mayer
}
2362 d9bce9d9 j_mayer
2363 d9bce9d9 j_mayer
void do_slbie (void)
2364 d9bce9d9 j_mayer
{
2365 d9bce9d9 j_mayer
    /* XXX: TODO */
2366 d9bce9d9 j_mayer
    tlb_flush(env, 1);
2367 d9bce9d9 j_mayer
}
2368 d9bce9d9 j_mayer
#endif
2369 d9bce9d9 j_mayer
2370 76a66253 j_mayer
/* Software driven TLBs management */
2371 76a66253 j_mayer
/* PowerPC 602/603 software TLB load instructions helpers */
2372 76a66253 j_mayer
void do_load_6xx_tlb (int is_code)
2373 76a66253 j_mayer
{
2374 76a66253 j_mayer
    target_ulong RPN, CMP, EPN;
2375 76a66253 j_mayer
    int way;
2376 d9bce9d9 j_mayer
2377 76a66253 j_mayer
    RPN = env->spr[SPR_RPA];
2378 76a66253 j_mayer
    if (is_code) {
2379 76a66253 j_mayer
        CMP = env->spr[SPR_ICMP];
2380 76a66253 j_mayer
        EPN = env->spr[SPR_IMISS];
2381 76a66253 j_mayer
    } else {
2382 76a66253 j_mayer
        CMP = env->spr[SPR_DCMP];
2383 76a66253 j_mayer
        EPN = env->spr[SPR_DMISS];
2384 76a66253 j_mayer
    }
2385 76a66253 j_mayer
    way = (env->spr[SPR_SRR1] >> 17) & 1;
2386 76a66253 j_mayer
#if defined (DEBUG_SOFTWARE_TLB)
2387 76a66253 j_mayer
    if (loglevel != 0) {
2388 76a66253 j_mayer
        fprintf(logfile, "%s: EPN %08lx %08lx PTE0 %08lx PTE1 %08lx way %d\n",
2389 76a66253 j_mayer
                __func__, (unsigned long)T0, (unsigned long)EPN,
2390 76a66253 j_mayer
                (unsigned long)CMP, (unsigned long)RPN, way);
2391 76a66253 j_mayer
    }
2392 76a66253 j_mayer
#endif
2393 76a66253 j_mayer
    /* Store this TLB */
2394 d9bce9d9 j_mayer
    ppc6xx_tlb_store(env, (uint32_t)(T0 & TARGET_PAGE_MASK),
2395 d9bce9d9 j_mayer
                     way, is_code, CMP, RPN);
2396 76a66253 j_mayer
}
2397 76a66253 j_mayer
2398 a8dea12f j_mayer
static target_ulong booke_tlb_to_page_size (int size)
2399 a8dea12f j_mayer
{
2400 a8dea12f j_mayer
    return 1024 << (2 * size);
2401 a8dea12f j_mayer
}
2402 a8dea12f j_mayer
2403 a8dea12f j_mayer
static int booke_page_size_to_tlb (target_ulong page_size)
2404 a8dea12f j_mayer
{
2405 a8dea12f j_mayer
    int size;
2406 a8dea12f j_mayer
2407 a8dea12f j_mayer
    switch (page_size) {
2408 a8dea12f j_mayer
    case 0x00000400UL:
2409 a8dea12f j_mayer
        size = 0x0;
2410 a8dea12f j_mayer
        break;
2411 a8dea12f j_mayer
    case 0x00001000UL:
2412 a8dea12f j_mayer
        size = 0x1;
2413 a8dea12f j_mayer
        break;
2414 a8dea12f j_mayer
    case 0x00004000UL:
2415 a8dea12f j_mayer
        size = 0x2;
2416 a8dea12f j_mayer
        break;
2417 a8dea12f j_mayer
    case 0x00010000UL:
2418 a8dea12f j_mayer
        size = 0x3;
2419 a8dea12f j_mayer
        break;
2420 a8dea12f j_mayer
    case 0x00040000UL:
2421 a8dea12f j_mayer
        size = 0x4;
2422 a8dea12f j_mayer
        break;
2423 a8dea12f j_mayer
    case 0x00100000UL:
2424 a8dea12f j_mayer
        size = 0x5;
2425 a8dea12f j_mayer
        break;
2426 a8dea12f j_mayer
    case 0x00400000UL:
2427 a8dea12f j_mayer
        size = 0x6;
2428 a8dea12f j_mayer
        break;
2429 a8dea12f j_mayer
    case 0x01000000UL:
2430 a8dea12f j_mayer
        size = 0x7;
2431 a8dea12f j_mayer
        break;
2432 a8dea12f j_mayer
    case 0x04000000UL:
2433 a8dea12f j_mayer
        size = 0x8;
2434