Statistics
| Branch: | Revision:

root / target-mips / op_helper.c @ 647de6ca

History | View | Annotate | Download (42.6 kB)

1 6af0bf9c bellard
/*
2 6af0bf9c bellard
 *  MIPS emulation helpers for qemu.
3 5fafdf24 ths
 *
4 6af0bf9c bellard
 *  Copyright (c) 2004-2005 Jocelyn Mayer
5 6af0bf9c bellard
 *
6 6af0bf9c bellard
 * This library is free software; you can redistribute it and/or
7 6af0bf9c bellard
 * modify it under the terms of the GNU Lesser General Public
8 6af0bf9c bellard
 * License as published by the Free Software Foundation; either
9 6af0bf9c bellard
 * version 2 of the License, or (at your option) any later version.
10 6af0bf9c bellard
 *
11 6af0bf9c bellard
 * This library is distributed in the hope that it will be useful,
12 6af0bf9c bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 6af0bf9c bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 6af0bf9c bellard
 * Lesser General Public License for more details.
15 6af0bf9c bellard
 *
16 6af0bf9c bellard
 * You should have received a copy of the GNU Lesser General Public
17 6af0bf9c bellard
 * License along with this library; if not, write to the Free Software
18 6af0bf9c bellard
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 6af0bf9c bellard
 */
20 2d0e944d ths
#include <stdlib.h>
21 6af0bf9c bellard
#include "exec.h"
22 6af0bf9c bellard
23 4ad40f36 bellard
#define GETPC() (__builtin_return_address(0))
24 4ad40f36 bellard
25 6af0bf9c bellard
/*****************************************************************************/
26 6af0bf9c bellard
/* Exceptions processing helpers */
27 6af0bf9c bellard
28 6af0bf9c bellard
void do_raise_exception_err (uint32_t exception, int error_code)
29 6af0bf9c bellard
{
30 6af0bf9c bellard
#if 1
31 6af0bf9c bellard
    if (logfile && exception < 0x100)
32 6af0bf9c bellard
        fprintf(logfile, "%s: %d %d\n", __func__, exception, error_code);
33 6af0bf9c bellard
#endif
34 6af0bf9c bellard
    env->exception_index = exception;
35 6af0bf9c bellard
    env->error_code = error_code;
36 6af0bf9c bellard
    T0 = 0;
37 6af0bf9c bellard
    cpu_loop_exit();
38 6af0bf9c bellard
}
39 6af0bf9c bellard
40 6af0bf9c bellard
void do_raise_exception (uint32_t exception)
41 6af0bf9c bellard
{
42 6af0bf9c bellard
    do_raise_exception_err(exception, 0);
43 6af0bf9c bellard
}
44 6af0bf9c bellard
45 4ad40f36 bellard
void do_restore_state (void *pc_ptr)
46 4ad40f36 bellard
{
47 4ad40f36 bellard
  TranslationBlock *tb;
48 4ad40f36 bellard
  unsigned long pc = (unsigned long) pc_ptr;
49 4ad40f36 bellard
50 4ad40f36 bellard
  tb = tb_find_pc (pc);
51 4ad40f36 bellard
  cpu_restore_state (tb, env, pc, NULL);
52 4ad40f36 bellard
}
53 4ad40f36 bellard
54 e397ee33 ths
void do_raise_exception_direct_err (uint32_t exception, int error_code)
55 4ad40f36 bellard
{
56 4ad40f36 bellard
    do_restore_state (GETPC ());
57 e397ee33 ths
    do_raise_exception_err (exception, error_code);
58 e397ee33 ths
}
59 e397ee33 ths
60 e397ee33 ths
void do_raise_exception_direct (uint32_t exception)
61 e397ee33 ths
{
62 e397ee33 ths
    do_raise_exception_direct_err (exception, 0);
63 4ad40f36 bellard
}
64 4ad40f36 bellard
65 540635ba ths
#if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
66 c570fd16 ths
#if TARGET_LONG_BITS > HOST_LONG_BITS
67 c570fd16 ths
/* Those might call libgcc functions.  */
68 c570fd16 ths
void do_dsll (void)
69 c570fd16 ths
{
70 c570fd16 ths
    T0 = T0 << T1;
71 c570fd16 ths
}
72 c570fd16 ths
73 c570fd16 ths
void do_dsll32 (void)
74 c570fd16 ths
{
75 c570fd16 ths
    T0 = T0 << (T1 + 32);
76 c570fd16 ths
}
77 c570fd16 ths
78 c570fd16 ths
void do_dsra (void)
79 c570fd16 ths
{
80 c570fd16 ths
    T0 = (int64_t)T0 >> T1;
81 c570fd16 ths
}
82 c570fd16 ths
83 c570fd16 ths
void do_dsra32 (void)
84 c570fd16 ths
{
85 c570fd16 ths
    T0 = (int64_t)T0 >> (T1 + 32);
86 c570fd16 ths
}
87 c570fd16 ths
88 c570fd16 ths
void do_dsrl (void)
89 c570fd16 ths
{
90 c570fd16 ths
    T0 = T0 >> T1;
91 c570fd16 ths
}
92 c570fd16 ths
93 c570fd16 ths
void do_dsrl32 (void)
94 c570fd16 ths
{
95 c570fd16 ths
    T0 = T0 >> (T1 + 32);
96 c570fd16 ths
}
97 c570fd16 ths
98 c570fd16 ths
void do_drotr (void)
99 c570fd16 ths
{
100 c570fd16 ths
    target_ulong tmp;
101 c570fd16 ths
102 c570fd16 ths
    if (T1) {
103 c570fd16 ths
       tmp = T0 << (0x40 - T1);
104 c570fd16 ths
       T0 = (T0 >> T1) | tmp;
105 5a63bcb2 ths
    }
106 c570fd16 ths
}
107 c570fd16 ths
108 c570fd16 ths
void do_drotr32 (void)
109 c570fd16 ths
{
110 c570fd16 ths
    target_ulong tmp;
111 c570fd16 ths
112 c570fd16 ths
    if (T1) {
113 c570fd16 ths
       tmp = T0 << (0x40 - (32 + T1));
114 c570fd16 ths
       T0 = (T0 >> (32 + T1)) | tmp;
115 5a63bcb2 ths
    }
116 c570fd16 ths
}
117 c570fd16 ths
118 c570fd16 ths
void do_dsllv (void)
119 c570fd16 ths
{
120 c570fd16 ths
    T0 = T1 << (T0 & 0x3F);
121 c570fd16 ths
}
122 c570fd16 ths
123 c570fd16 ths
void do_dsrav (void)
124 c570fd16 ths
{
125 c570fd16 ths
    T0 = (int64_t)T1 >> (T0 & 0x3F);
126 c570fd16 ths
}
127 c570fd16 ths
128 c570fd16 ths
void do_dsrlv (void)
129 c570fd16 ths
{
130 c570fd16 ths
    T0 = T1 >> (T0 & 0x3F);
131 c570fd16 ths
}
132 c570fd16 ths
133 c570fd16 ths
void do_drotrv (void)
134 c570fd16 ths
{
135 c570fd16 ths
    target_ulong tmp;
136 c570fd16 ths
137 c570fd16 ths
    T0 &= 0x3F;
138 c570fd16 ths
    if (T0) {
139 c570fd16 ths
       tmp = T1 << (0x40 - T0);
140 c570fd16 ths
       T0 = (T1 >> T0) | tmp;
141 c570fd16 ths
    } else
142 c570fd16 ths
       T0 = T1;
143 c570fd16 ths
}
144 c570fd16 ths
#endif /* TARGET_LONG_BITS > HOST_LONG_BITS */
145 540635ba ths
#endif /* TARGET_MIPSN32 || TARGET_MIPS64 */
146 c570fd16 ths
147 6af0bf9c bellard
/* 64 bits arithmetic for 32 bits hosts */
148 c570fd16 ths
#if TARGET_LONG_BITS > HOST_LONG_BITS
149 aa343735 ths
static always_inline uint64_t get_HILO (void)
150 6af0bf9c bellard
{
151 ead9360e ths
    return (env->HI[0][env->current_tc] << 32) | (uint32_t)env->LO[0][env->current_tc];
152 6af0bf9c bellard
}
153 6af0bf9c bellard
154 aa343735 ths
static always_inline void set_HILO (uint64_t HILO)
155 6af0bf9c bellard
{
156 ead9360e ths
    env->LO[0][env->current_tc] = (int32_t)HILO;
157 ead9360e ths
    env->HI[0][env->current_tc] = (int32_t)(HILO >> 32);
158 6af0bf9c bellard
}
159 6af0bf9c bellard
160 6af0bf9c bellard
void do_mult (void)
161 6af0bf9c bellard
{
162 4ad40f36 bellard
    set_HILO((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
163 6af0bf9c bellard
}
164 6af0bf9c bellard
165 6af0bf9c bellard
void do_multu (void)
166 6af0bf9c bellard
{
167 c570fd16 ths
    set_HILO((uint64_t)(uint32_t)T0 * (uint64_t)(uint32_t)T1);
168 6af0bf9c bellard
}
169 6af0bf9c bellard
170 6af0bf9c bellard
void do_madd (void)
171 6af0bf9c bellard
{
172 6af0bf9c bellard
    int64_t tmp;
173 6af0bf9c bellard
174 4ad40f36 bellard
    tmp = ((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
175 6af0bf9c bellard
    set_HILO((int64_t)get_HILO() + tmp);
176 6af0bf9c bellard
}
177 6af0bf9c bellard
178 6af0bf9c bellard
void do_maddu (void)
179 6af0bf9c bellard
{
180 6af0bf9c bellard
    uint64_t tmp;
181 6af0bf9c bellard
182 c570fd16 ths
    tmp = ((uint64_t)(uint32_t)T0 * (uint64_t)(uint32_t)T1);
183 6af0bf9c bellard
    set_HILO(get_HILO() + tmp);
184 6af0bf9c bellard
}
185 6af0bf9c bellard
186 6af0bf9c bellard
void do_msub (void)
187 6af0bf9c bellard
{
188 6af0bf9c bellard
    int64_t tmp;
189 6af0bf9c bellard
190 4ad40f36 bellard
    tmp = ((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
191 6af0bf9c bellard
    set_HILO((int64_t)get_HILO() - tmp);
192 6af0bf9c bellard
}
193 6af0bf9c bellard
194 6af0bf9c bellard
void do_msubu (void)
195 6af0bf9c bellard
{
196 6af0bf9c bellard
    uint64_t tmp;
197 6af0bf9c bellard
198 c570fd16 ths
    tmp = ((uint64_t)(uint32_t)T0 * (uint64_t)(uint32_t)T1);
199 6af0bf9c bellard
    set_HILO(get_HILO() - tmp);
200 6af0bf9c bellard
}
201 6af0bf9c bellard
#endif
202 6af0bf9c bellard
203 80c27194 ths
#if HOST_LONG_BITS < 64
204 80c27194 ths
void do_div (void)
205 80c27194 ths
{
206 80c27194 ths
    /* 64bit datatypes because we may see overflow/underflow. */
207 80c27194 ths
    if (T1 != 0) {
208 ead9360e ths
        env->LO[0][env->current_tc] = (int32_t)((int64_t)(int32_t)T0 / (int32_t)T1);
209 ead9360e ths
        env->HI[0][env->current_tc] = (int32_t)((int64_t)(int32_t)T0 % (int32_t)T1);
210 80c27194 ths
    }
211 80c27194 ths
}
212 80c27194 ths
#endif
213 80c27194 ths
214 540635ba ths
#if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
215 c570fd16 ths
void do_ddiv (void)
216 c570fd16 ths
{
217 c570fd16 ths
    if (T1 != 0) {
218 2d0e944d ths
        lldiv_t res = lldiv((int64_t)T0, (int64_t)T1);
219 ead9360e ths
        env->LO[0][env->current_tc] = res.quot;
220 ead9360e ths
        env->HI[0][env->current_tc] = res.rem;
221 c570fd16 ths
    }
222 c570fd16 ths
}
223 c570fd16 ths
224 12a4b2aa ths
#if TARGET_LONG_BITS > HOST_LONG_BITS
225 c570fd16 ths
void do_ddivu (void)
226 c570fd16 ths
{
227 c570fd16 ths
    if (T1 != 0) {
228 ead9360e ths
        env->LO[0][env->current_tc] = T0 / T1;
229 ead9360e ths
        env->HI[0][env->current_tc] = T0 % T1;
230 c570fd16 ths
    }
231 c570fd16 ths
}
232 c570fd16 ths
#endif
233 540635ba ths
#endif /* TARGET_MIPSN32 || TARGET_MIPS64 */
234 c570fd16 ths
235 5fafdf24 ths
#if defined(CONFIG_USER_ONLY)
236 873eb012 ths
void do_mfc0_random (void)
237 048f6b4d bellard
{
238 873eb012 ths
    cpu_abort(env, "mfc0 random\n");
239 048f6b4d bellard
}
240 873eb012 ths
241 873eb012 ths
void do_mfc0_count (void)
242 873eb012 ths
{
243 873eb012 ths
    cpu_abort(env, "mfc0 count\n");
244 873eb012 ths
}
245 873eb012 ths
246 8c0fdd85 ths
void cpu_mips_store_count(CPUState *env, uint32_t value)
247 048f6b4d bellard
{
248 8c0fdd85 ths
    cpu_abort(env, "mtc0 count\n");
249 8c0fdd85 ths
}
250 8c0fdd85 ths
251 8c0fdd85 ths
void cpu_mips_store_compare(CPUState *env, uint32_t value)
252 8c0fdd85 ths
{
253 8c0fdd85 ths
    cpu_abort(env, "mtc0 compare\n");
254 8c0fdd85 ths
}
255 8c0fdd85 ths
256 42532189 ths
void cpu_mips_start_count(CPUState *env)
257 42532189 ths
{
258 42532189 ths
    cpu_abort(env, "start count\n");
259 42532189 ths
}
260 42532189 ths
261 42532189 ths
void cpu_mips_stop_count(CPUState *env)
262 42532189 ths
{
263 42532189 ths
    cpu_abort(env, "stop count\n");
264 42532189 ths
}
265 42532189 ths
266 4de9b249 ths
void cpu_mips_update_irq(CPUState *env)
267 4de9b249 ths
{
268 4de9b249 ths
    cpu_abort(env, "mtc0 status / mtc0 cause\n");
269 4de9b249 ths
}
270 4de9b249 ths
271 8c0fdd85 ths
void do_mtc0_status_debug(uint32_t old, uint32_t val)
272 8c0fdd85 ths
{
273 7a387fff ths
    cpu_abort(env, "mtc0 status debug\n");
274 8c0fdd85 ths
}
275 8c0fdd85 ths
276 7a387fff ths
void do_mtc0_status_irqraise_debug (void)
277 8c0fdd85 ths
{
278 7a387fff ths
    cpu_abort(env, "mtc0 status irqraise debug\n");
279 048f6b4d bellard
}
280 048f6b4d bellard
281 8c0fdd85 ths
void cpu_mips_tlb_flush (CPUState *env, int flush_global)
282 8c0fdd85 ths
{
283 8c0fdd85 ths
    cpu_abort(env, "mips_tlb_flush\n");
284 8c0fdd85 ths
}
285 8c0fdd85 ths
286 048f6b4d bellard
#else
287 048f6b4d bellard
288 6af0bf9c bellard
/* CP0 helpers */
289 873eb012 ths
void do_mfc0_random (void)
290 6af0bf9c bellard
{
291 5dc4b744 ths
    T0 = (int32_t)cpu_mips_get_random(env);
292 873eb012 ths
}
293 6af0bf9c bellard
294 873eb012 ths
void do_mfc0_count (void)
295 873eb012 ths
{
296 5dc4b744 ths
    T0 = (int32_t)cpu_mips_get_count(env);
297 6af0bf9c bellard
}
298 6af0bf9c bellard
299 8c0fdd85 ths
void do_mtc0_status_debug(uint32_t old, uint32_t val)
300 6af0bf9c bellard
{
301 f41c52f1 ths
    fprintf(logfile, "Status %08x (%08x) => %08x (%08x) Cause %08x",
302 f41c52f1 ths
            old, old & env->CP0_Cause & CP0Ca_IP_mask,
303 f41c52f1 ths
            val, val & env->CP0_Cause & CP0Ca_IP_mask,
304 f41c52f1 ths
            env->CP0_Cause);
305 f41c52f1 ths
    (env->hflags & MIPS_HFLAG_UM) ? fputs(", UM\n", logfile)
306 f41c52f1 ths
                                  : fputs("\n", logfile);
307 8c0fdd85 ths
}
308 8c0fdd85 ths
309 8c0fdd85 ths
void do_mtc0_status_irqraise_debug(void)
310 8c0fdd85 ths
{
311 8c0fdd85 ths
    fprintf(logfile, "Raise pending IRQs\n");
312 6af0bf9c bellard
}
313 6af0bf9c bellard
314 6ea83fed bellard
void fpu_handle_exception(void)
315 6ea83fed bellard
{
316 6ea83fed bellard
#ifdef CONFIG_SOFTFLOAT
317 ead9360e ths
    int flags = get_float_exception_flags(&env->fpu->fp_status);
318 6ea83fed bellard
    unsigned int cpuflags = 0, enable, cause = 0;
319 6ea83fed bellard
320 ead9360e ths
    enable = GET_FP_ENABLE(env->fpu->fcr31);
321 6ea83fed bellard
322 3b46e624 ths
    /* determine current flags */
323 6ea83fed bellard
    if (flags & float_flag_invalid) {
324 6ea83fed bellard
        cpuflags |= FP_INVALID;
325 6ea83fed bellard
        cause |= FP_INVALID & enable;
326 6ea83fed bellard
    }
327 6ea83fed bellard
    if (flags & float_flag_divbyzero) {
328 3b46e624 ths
        cpuflags |= FP_DIV0;
329 6ea83fed bellard
        cause |= FP_DIV0 & enable;
330 6ea83fed bellard
    }
331 6ea83fed bellard
    if (flags & float_flag_overflow) {
332 3b46e624 ths
        cpuflags |= FP_OVERFLOW;
333 6ea83fed bellard
        cause |= FP_OVERFLOW & enable;
334 6ea83fed bellard
    }
335 6ea83fed bellard
    if (flags & float_flag_underflow) {
336 3b46e624 ths
        cpuflags |= FP_UNDERFLOW;
337 6ea83fed bellard
        cause |= FP_UNDERFLOW & enable;
338 6ea83fed bellard
    }
339 6ea83fed bellard
    if (flags & float_flag_inexact) {
340 5fafdf24 ths
        cpuflags |= FP_INEXACT;
341 6ea83fed bellard
        cause |= FP_INEXACT & enable;
342 6ea83fed bellard
    }
343 ead9360e ths
    SET_FP_FLAGS(env->fpu->fcr31, cpuflags);
344 ead9360e ths
    SET_FP_CAUSE(env->fpu->fcr31, cause);
345 6ea83fed bellard
#else
346 ead9360e ths
    SET_FP_FLAGS(env->fpu->fcr31, 0);
347 ead9360e ths
    SET_FP_CAUSE(env->fpu->fcr31, 0);
348 6ea83fed bellard
#endif
349 6ea83fed bellard
}
350 6ea83fed bellard
351 6af0bf9c bellard
/* TLB management */
352 814b9a47 ths
void cpu_mips_tlb_flush (CPUState *env, int flush_global)
353 814b9a47 ths
{
354 814b9a47 ths
    /* Flush qemu's TLB and discard all shadowed entries.  */
355 814b9a47 ths
    tlb_flush (env, flush_global);
356 ead9360e ths
    env->tlb->tlb_in_use = env->tlb->nb_tlb;
357 814b9a47 ths
}
358 814b9a47 ths
359 29929e34 ths
static void r4k_mips_tlb_flush_extra (CPUState *env, int first)
360 814b9a47 ths
{
361 814b9a47 ths
    /* Discard entries from env->tlb[first] onwards.  */
362 ead9360e ths
    while (env->tlb->tlb_in_use > first) {
363 ead9360e ths
        r4k_invalidate_tlb(env, --env->tlb->tlb_in_use, 0);
364 814b9a47 ths
    }
365 814b9a47 ths
}
366 814b9a47 ths
367 29929e34 ths
static void r4k_fill_tlb (int idx)
368 6af0bf9c bellard
{
369 29929e34 ths
    r4k_tlb_t *tlb;
370 6af0bf9c bellard
371 6af0bf9c bellard
    /* XXX: detect conflicting TLBs and raise a MCHECK exception when needed */
372 ead9360e ths
    tlb = &env->tlb->mmu.r4k.tlb[idx];
373 f2e9ebef ths
    tlb->VPN = env->CP0_EntryHi & (TARGET_PAGE_MASK << 1);
374 540635ba ths
#if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
375 e034e2c3 ths
    tlb->VPN &= env->SEGMask;
376 100ce988 ths
#endif
377 98c1b82b pbrook
    tlb->ASID = env->CP0_EntryHi & 0xFF;
378 3b1c8be4 ths
    tlb->PageMask = env->CP0_PageMask;
379 6af0bf9c bellard
    tlb->G = env->CP0_EntryLo0 & env->CP0_EntryLo1 & 1;
380 98c1b82b pbrook
    tlb->V0 = (env->CP0_EntryLo0 & 2) != 0;
381 98c1b82b pbrook
    tlb->D0 = (env->CP0_EntryLo0 & 4) != 0;
382 98c1b82b pbrook
    tlb->C0 = (env->CP0_EntryLo0 >> 3) & 0x7;
383 6af0bf9c bellard
    tlb->PFN[0] = (env->CP0_EntryLo0 >> 6) << 12;
384 98c1b82b pbrook
    tlb->V1 = (env->CP0_EntryLo1 & 2) != 0;
385 98c1b82b pbrook
    tlb->D1 = (env->CP0_EntryLo1 & 4) != 0;
386 98c1b82b pbrook
    tlb->C1 = (env->CP0_EntryLo1 >> 3) & 0x7;
387 6af0bf9c bellard
    tlb->PFN[1] = (env->CP0_EntryLo1 >> 6) << 12;
388 6af0bf9c bellard
}
389 6af0bf9c bellard
390 29929e34 ths
void r4k_do_tlbwi (void)
391 6af0bf9c bellard
{
392 814b9a47 ths
    /* Discard cached TLB entries.  We could avoid doing this if the
393 814b9a47 ths
       tlbwi is just upgrading access permissions on the current entry;
394 814b9a47 ths
       that might be a further win.  */
395 ead9360e ths
    r4k_mips_tlb_flush_extra (env, env->tlb->nb_tlb);
396 814b9a47 ths
397 ead9360e ths
    r4k_invalidate_tlb(env, env->CP0_Index % env->tlb->nb_tlb, 0);
398 ead9360e ths
    r4k_fill_tlb(env->CP0_Index % env->tlb->nb_tlb);
399 6af0bf9c bellard
}
400 6af0bf9c bellard
401 29929e34 ths
void r4k_do_tlbwr (void)
402 6af0bf9c bellard
{
403 6af0bf9c bellard
    int r = cpu_mips_get_random(env);
404 6af0bf9c bellard
405 29929e34 ths
    r4k_invalidate_tlb(env, r, 1);
406 29929e34 ths
    r4k_fill_tlb(r);
407 6af0bf9c bellard
}
408 6af0bf9c bellard
409 29929e34 ths
void r4k_do_tlbp (void)
410 6af0bf9c bellard
{
411 29929e34 ths
    r4k_tlb_t *tlb;
412 f2e9ebef ths
    target_ulong mask;
413 6af0bf9c bellard
    target_ulong tag;
414 f2e9ebef ths
    target_ulong VPN;
415 6af0bf9c bellard
    uint8_t ASID;
416 6af0bf9c bellard
    int i;
417 6af0bf9c bellard
418 3d9fb9fe bellard
    ASID = env->CP0_EntryHi & 0xFF;
419 ead9360e ths
    for (i = 0; i < env->tlb->nb_tlb; i++) {
420 ead9360e ths
        tlb = &env->tlb->mmu.r4k.tlb[i];
421 f2e9ebef ths
        /* 1k pages are not supported. */
422 f2e9ebef ths
        mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1);
423 f2e9ebef ths
        tag = env->CP0_EntryHi & ~mask;
424 f2e9ebef ths
        VPN = tlb->VPN & ~mask;
425 6af0bf9c bellard
        /* Check ASID, virtual page number & size */
426 f2e9ebef ths
        if ((tlb->G == 1 || tlb->ASID == ASID) && VPN == tag) {
427 6af0bf9c bellard
            /* TLB match */
428 9c2149c8 ths
            env->CP0_Index = i;
429 6af0bf9c bellard
            break;
430 6af0bf9c bellard
        }
431 6af0bf9c bellard
    }
432 ead9360e ths
    if (i == env->tlb->nb_tlb) {
433 814b9a47 ths
        /* No match.  Discard any shadow entries, if any of them match.  */
434 ead9360e ths
        for (i = env->tlb->nb_tlb; i < env->tlb->tlb_in_use; i++) {
435 ead9360e ths
            tlb = &env->tlb->mmu.r4k.tlb[i];
436 f2e9ebef ths
            /* 1k pages are not supported. */
437 f2e9ebef ths
            mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1);
438 f2e9ebef ths
            tag = env->CP0_EntryHi & ~mask;
439 f2e9ebef ths
            VPN = tlb->VPN & ~mask;
440 814b9a47 ths
            /* Check ASID, virtual page number & size */
441 f2e9ebef ths
            if ((tlb->G == 1 || tlb->ASID == ASID) && VPN == tag) {
442 29929e34 ths
                r4k_mips_tlb_flush_extra (env, i);
443 814b9a47 ths
                break;
444 814b9a47 ths
            }
445 814b9a47 ths
        }
446 814b9a47 ths
447 9c2149c8 ths
        env->CP0_Index |= 0x80000000;
448 6af0bf9c bellard
    }
449 6af0bf9c bellard
}
450 6af0bf9c bellard
451 29929e34 ths
void r4k_do_tlbr (void)
452 6af0bf9c bellard
{
453 29929e34 ths
    r4k_tlb_t *tlb;
454 09c56b84 pbrook
    uint8_t ASID;
455 6af0bf9c bellard
456 09c56b84 pbrook
    ASID = env->CP0_EntryHi & 0xFF;
457 ead9360e ths
    tlb = &env->tlb->mmu.r4k.tlb[env->CP0_Index % env->tlb->nb_tlb];
458 4ad40f36 bellard
459 4ad40f36 bellard
    /* If this will change the current ASID, flush qemu's TLB.  */
460 814b9a47 ths
    if (ASID != tlb->ASID)
461 814b9a47 ths
        cpu_mips_tlb_flush (env, 1);
462 814b9a47 ths
463 ead9360e ths
    r4k_mips_tlb_flush_extra(env, env->tlb->nb_tlb);
464 4ad40f36 bellard
465 6af0bf9c bellard
    env->CP0_EntryHi = tlb->VPN | tlb->ASID;
466 3b1c8be4 ths
    env->CP0_PageMask = tlb->PageMask;
467 7495fd0f ths
    env->CP0_EntryLo0 = tlb->G | (tlb->V0 << 1) | (tlb->D0 << 2) |
468 7495fd0f ths
                        (tlb->C0 << 3) | (tlb->PFN[0] >> 6);
469 7495fd0f ths
    env->CP0_EntryLo1 = tlb->G | (tlb->V1 << 1) | (tlb->D1 << 2) |
470 7495fd0f ths
                        (tlb->C1 << 3) | (tlb->PFN[1] >> 6);
471 6af0bf9c bellard
}
472 6af0bf9c bellard
473 048f6b4d bellard
#endif /* !CONFIG_USER_ONLY */
474 048f6b4d bellard
475 c570fd16 ths
void dump_ldst (const unsigned char *func)
476 6af0bf9c bellard
{
477 6af0bf9c bellard
    if (loglevel)
478 3594c774 ths
        fprintf(logfile, "%s => " TARGET_FMT_lx " " TARGET_FMT_lx "\n", __func__, T0, T1);
479 6af0bf9c bellard
}
480 6af0bf9c bellard
481 6af0bf9c bellard
void dump_sc (void)
482 6af0bf9c bellard
{
483 6af0bf9c bellard
    if (loglevel) {
484 3594c774 ths
        fprintf(logfile, "%s " TARGET_FMT_lx " at " TARGET_FMT_lx " (" TARGET_FMT_lx ")\n", __func__,
485 6af0bf9c bellard
                T1, T0, env->CP0_LLAddr);
486 6af0bf9c bellard
    }
487 6af0bf9c bellard
}
488 6af0bf9c bellard
489 f41c52f1 ths
void debug_pre_eret (void)
490 6af0bf9c bellard
{
491 f41c52f1 ths
    fprintf(logfile, "ERET: PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx,
492 ead9360e ths
            env->PC[env->current_tc], env->CP0_EPC);
493 f41c52f1 ths
    if (env->CP0_Status & (1 << CP0St_ERL))
494 f41c52f1 ths
        fprintf(logfile, " ErrorEPC " TARGET_FMT_lx, env->CP0_ErrorEPC);
495 f41c52f1 ths
    if (env->hflags & MIPS_HFLAG_DM)
496 f41c52f1 ths
        fprintf(logfile, " DEPC " TARGET_FMT_lx, env->CP0_DEPC);
497 f41c52f1 ths
    fputs("\n", logfile);
498 f41c52f1 ths
}
499 f41c52f1 ths
500 f41c52f1 ths
void debug_post_eret (void)
501 f41c52f1 ths
{
502 744e0915 ths
    fprintf(logfile, "  =>  PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx,
503 ead9360e ths
            env->PC[env->current_tc], env->CP0_EPC);
504 f41c52f1 ths
    if (env->CP0_Status & (1 << CP0St_ERL))
505 f41c52f1 ths
        fprintf(logfile, " ErrorEPC " TARGET_FMT_lx, env->CP0_ErrorEPC);
506 f41c52f1 ths
    if (env->hflags & MIPS_HFLAG_DM)
507 f41c52f1 ths
        fprintf(logfile, " DEPC " TARGET_FMT_lx, env->CP0_DEPC);
508 f41c52f1 ths
    if (env->hflags & MIPS_HFLAG_UM)
509 f41c52f1 ths
        fputs(", UM\n", logfile);
510 f41c52f1 ths
    else
511 24c7b0e3 ths
        fputs("\n", logfile);
512 6af0bf9c bellard
}
513 6af0bf9c bellard
514 6af0bf9c bellard
void do_pmon (int function)
515 6af0bf9c bellard
{
516 6af0bf9c bellard
    function /= 2;
517 6af0bf9c bellard
    switch (function) {
518 6af0bf9c bellard
    case 2: /* TODO: char inbyte(int waitflag); */
519 ead9360e ths
        if (env->gpr[4][env->current_tc] == 0)
520 ead9360e ths
            env->gpr[2][env->current_tc] = -1;
521 6af0bf9c bellard
        /* Fall through */
522 6af0bf9c bellard
    case 11: /* TODO: char inbyte (void); */
523 ead9360e ths
        env->gpr[2][env->current_tc] = -1;
524 6af0bf9c bellard
        break;
525 6af0bf9c bellard
    case 3:
526 6af0bf9c bellard
    case 12:
527 ead9360e ths
        printf("%c", (char)(env->gpr[4][env->current_tc] & 0xFF));
528 6af0bf9c bellard
        break;
529 6af0bf9c bellard
    case 17:
530 6af0bf9c bellard
        break;
531 6af0bf9c bellard
    case 158:
532 6af0bf9c bellard
        {
533 ead9360e ths
            unsigned char *fmt = (void *)(unsigned long)env->gpr[4][env->current_tc];
534 6af0bf9c bellard
            printf("%s", fmt);
535 6af0bf9c bellard
        }
536 6af0bf9c bellard
        break;
537 6af0bf9c bellard
    }
538 6af0bf9c bellard
}
539 e37e863f bellard
540 5fafdf24 ths
#if !defined(CONFIG_USER_ONLY)
541 e37e863f bellard
542 4ad40f36 bellard
static void do_unaligned_access (target_ulong addr, int is_write, int is_user, void *retaddr);
543 4ad40f36 bellard
544 e37e863f bellard
#define MMUSUFFIX _mmu
545 4ad40f36 bellard
#define ALIGNED_ONLY
546 e37e863f bellard
547 e37e863f bellard
#define SHIFT 0
548 e37e863f bellard
#include "softmmu_template.h"
549 e37e863f bellard
550 e37e863f bellard
#define SHIFT 1
551 e37e863f bellard
#include "softmmu_template.h"
552 e37e863f bellard
553 e37e863f bellard
#define SHIFT 2
554 e37e863f bellard
#include "softmmu_template.h"
555 e37e863f bellard
556 e37e863f bellard
#define SHIFT 3
557 e37e863f bellard
#include "softmmu_template.h"
558 e37e863f bellard
559 4ad40f36 bellard
static void do_unaligned_access (target_ulong addr, int is_write, int is_user, void *retaddr)
560 4ad40f36 bellard
{
561 4ad40f36 bellard
    env->CP0_BadVAddr = addr;
562 4ad40f36 bellard
    do_restore_state (retaddr);
563 4ad40f36 bellard
    do_raise_exception ((is_write == 1) ? EXCP_AdES : EXCP_AdEL);
564 4ad40f36 bellard
}
565 4ad40f36 bellard
566 6ebbf390 j_mayer
void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
567 e37e863f bellard
{
568 e37e863f bellard
    TranslationBlock *tb;
569 e37e863f bellard
    CPUState *saved_env;
570 e37e863f bellard
    unsigned long pc;
571 e37e863f bellard
    int ret;
572 e37e863f bellard
573 e37e863f bellard
    /* XXX: hack to restore env in all cases, even if not called from
574 e37e863f bellard
       generated code */
575 e37e863f bellard
    saved_env = env;
576 e37e863f bellard
    env = cpu_single_env;
577 6ebbf390 j_mayer
    ret = cpu_mips_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
578 e37e863f bellard
    if (ret) {
579 e37e863f bellard
        if (retaddr) {
580 e37e863f bellard
            /* now we have a real cpu fault */
581 e37e863f bellard
            pc = (unsigned long)retaddr;
582 e37e863f bellard
            tb = tb_find_pc(pc);
583 e37e863f bellard
            if (tb) {
584 e37e863f bellard
                /* the PC is inside the translated code. It means that we have
585 e37e863f bellard
                   a virtual CPU fault */
586 e37e863f bellard
                cpu_restore_state(tb, env, pc, NULL);
587 e37e863f bellard
            }
588 e37e863f bellard
        }
589 e37e863f bellard
        do_raise_exception_err(env->exception_index, env->error_code);
590 e37e863f bellard
    }
591 e37e863f bellard
    env = saved_env;
592 e37e863f bellard
}
593 e37e863f bellard
594 647de6ca ths
void do_unassigned_access(target_phys_addr_t addr, int is_write, int is_exec,
595 647de6ca ths
                          int unused)
596 647de6ca ths
{
597 647de6ca ths
    if (is_exec)
598 647de6ca ths
        do_raise_exception(EXCP_IBE);
599 647de6ca ths
    else
600 647de6ca ths
        do_raise_exception(EXCP_DBE);
601 647de6ca ths
}
602 e37e863f bellard
#endif
603 fd4a04eb ths
604 fd4a04eb ths
/* Complex FPU operations which may need stack space. */
605 fd4a04eb ths
606 8dfdb87c ths
#define FLOAT_SIGN32 (1 << 31)
607 8dfdb87c ths
#define FLOAT_SIGN64 (1ULL << 63)
608 8dfdb87c ths
#define FLOAT_ONE32 (0x3f8 << 20)
609 8dfdb87c ths
#define FLOAT_ONE64 (0x3ffULL << 52)
610 8dfdb87c ths
#define FLOAT_TWO32 (1 << 30)
611 8dfdb87c ths
#define FLOAT_TWO64 (1ULL << 62)
612 54454097 ths
#define FLOAT_QNAN32 0x7fbfffff
613 54454097 ths
#define FLOAT_QNAN64 0x7ff7ffffffffffffULL
614 54454097 ths
#define FLOAT_SNAN32 0x7fffffff
615 54454097 ths
#define FLOAT_SNAN64 0x7fffffffffffffffULL
616 8dfdb87c ths
617 fd4a04eb ths
/* convert MIPS rounding mode in FCR31 to IEEE library */
618 fd4a04eb ths
unsigned int ieee_rm[] = {
619 fd4a04eb ths
    float_round_nearest_even,
620 fd4a04eb ths
    float_round_to_zero,
621 fd4a04eb ths
    float_round_up,
622 fd4a04eb ths
    float_round_down
623 fd4a04eb ths
};
624 fd4a04eb ths
625 fd4a04eb ths
#define RESTORE_ROUNDING_MODE \
626 ead9360e ths
    set_float_rounding_mode(ieee_rm[env->fpu->fcr31 & 3], &env->fpu->fp_status)
627 fd4a04eb ths
628 ead9360e ths
void do_cfc1 (int reg)
629 fd4a04eb ths
{
630 ead9360e ths
    switch (reg) {
631 ead9360e ths
    case 0:
632 ead9360e ths
        T0 = (int32_t)env->fpu->fcr0;
633 ead9360e ths
        break;
634 ead9360e ths
    case 25:
635 ead9360e ths
        T0 = ((env->fpu->fcr31 >> 24) & 0xfe) | ((env->fpu->fcr31 >> 23) & 0x1);
636 ead9360e ths
        break;
637 ead9360e ths
    case 26:
638 ead9360e ths
        T0 = env->fpu->fcr31 & 0x0003f07c;
639 ead9360e ths
        break;
640 ead9360e ths
    case 28:
641 ead9360e ths
        T0 = (env->fpu->fcr31 & 0x00000f83) | ((env->fpu->fcr31 >> 22) & 0x4);
642 ead9360e ths
        break;
643 ead9360e ths
    default:
644 ead9360e ths
        T0 = (int32_t)env->fpu->fcr31;
645 ead9360e ths
        break;
646 ead9360e ths
    }
647 ead9360e ths
}
648 ead9360e ths
649 ead9360e ths
void do_ctc1 (int reg)
650 ead9360e ths
{
651 ead9360e ths
    switch(reg) {
652 fd4a04eb ths
    case 25:
653 fd4a04eb ths
        if (T0 & 0xffffff00)
654 fd4a04eb ths
            return;
655 ead9360e ths
        env->fpu->fcr31 = (env->fpu->fcr31 & 0x017fffff) | ((T0 & 0xfe) << 24) |
656 fd4a04eb ths
                     ((T0 & 0x1) << 23);
657 fd4a04eb ths
        break;
658 fd4a04eb ths
    case 26:
659 fd4a04eb ths
        if (T0 & 0x007c0000)
660 fd4a04eb ths
            return;
661 ead9360e ths
        env->fpu->fcr31 = (env->fpu->fcr31 & 0xfffc0f83) | (T0 & 0x0003f07c);
662 fd4a04eb ths
        break;
663 fd4a04eb ths
    case 28:
664 fd4a04eb ths
        if (T0 & 0x007c0000)
665 fd4a04eb ths
            return;
666 ead9360e ths
        env->fpu->fcr31 = (env->fpu->fcr31 & 0xfefff07c) | (T0 & 0x00000f83) |
667 fd4a04eb ths
                     ((T0 & 0x4) << 22);
668 fd4a04eb ths
        break;
669 fd4a04eb ths
    case 31:
670 fd4a04eb ths
        if (T0 & 0x007c0000)
671 fd4a04eb ths
            return;
672 ead9360e ths
        env->fpu->fcr31 = T0;
673 fd4a04eb ths
        break;
674 fd4a04eb ths
    default:
675 fd4a04eb ths
        return;
676 fd4a04eb ths
    }
677 fd4a04eb ths
    /* set rounding mode */
678 fd4a04eb ths
    RESTORE_ROUNDING_MODE;
679 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
680 ead9360e ths
    if ((GET_FP_ENABLE(env->fpu->fcr31) | 0x20) & GET_FP_CAUSE(env->fpu->fcr31))
681 fd4a04eb ths
        do_raise_exception(EXCP_FPE);
682 fd4a04eb ths
}
683 fd4a04eb ths
684 aa343735 ths
static always_inline char ieee_ex_to_mips(char xcpt)
685 fd4a04eb ths
{
686 fd4a04eb ths
    return (xcpt & float_flag_inexact) >> 5 |
687 fd4a04eb ths
           (xcpt & float_flag_underflow) >> 3 |
688 fd4a04eb ths
           (xcpt & float_flag_overflow) >> 1 |
689 fd4a04eb ths
           (xcpt & float_flag_divbyzero) << 1 |
690 fd4a04eb ths
           (xcpt & float_flag_invalid) << 4;
691 fd4a04eb ths
}
692 fd4a04eb ths
693 aa343735 ths
static always_inline char mips_ex_to_ieee(char xcpt)
694 fd4a04eb ths
{
695 fd4a04eb ths
    return (xcpt & FP_INEXACT) << 5 |
696 fd4a04eb ths
           (xcpt & FP_UNDERFLOW) << 3 |
697 fd4a04eb ths
           (xcpt & FP_OVERFLOW) << 1 |
698 fd4a04eb ths
           (xcpt & FP_DIV0) >> 1 |
699 fd4a04eb ths
           (xcpt & FP_INVALID) >> 4;
700 fd4a04eb ths
}
701 fd4a04eb ths
702 aa343735 ths
static always_inline void update_fcr31(void)
703 fd4a04eb ths
{
704 ead9360e ths
    int tmp = ieee_ex_to_mips(get_float_exception_flags(&env->fpu->fp_status));
705 fd4a04eb ths
706 ead9360e ths
    SET_FP_CAUSE(env->fpu->fcr31, tmp);
707 ead9360e ths
    if (GET_FP_ENABLE(env->fpu->fcr31) & tmp)
708 fd4a04eb ths
        do_raise_exception(EXCP_FPE);
709 fd4a04eb ths
    else
710 ead9360e ths
        UPDATE_FP_FLAGS(env->fpu->fcr31, tmp);
711 fd4a04eb ths
}
712 fd4a04eb ths
713 fd4a04eb ths
#define FLOAT_OP(name, p) void do_float_##name##_##p(void)
714 fd4a04eb ths
715 fd4a04eb ths
FLOAT_OP(cvtd, s)
716 fd4a04eb ths
{
717 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
718 ead9360e ths
    FDT2 = float32_to_float64(FST0, &env->fpu->fp_status);
719 fd4a04eb ths
    update_fcr31();
720 fd4a04eb ths
}
721 fd4a04eb ths
FLOAT_OP(cvtd, w)
722 fd4a04eb ths
{
723 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
724 ead9360e ths
    FDT2 = int32_to_float64(WT0, &env->fpu->fp_status);
725 fd4a04eb ths
    update_fcr31();
726 fd4a04eb ths
}
727 fd4a04eb ths
FLOAT_OP(cvtd, l)
728 fd4a04eb ths
{
729 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
730 ead9360e ths
    FDT2 = int64_to_float64(DT0, &env->fpu->fp_status);
731 fd4a04eb ths
    update_fcr31();
732 fd4a04eb ths
}
733 fd4a04eb ths
FLOAT_OP(cvtl, d)
734 fd4a04eb ths
{
735 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
736 ead9360e ths
    DT2 = float64_to_int64(FDT0, &env->fpu->fp_status);
737 fd4a04eb ths
    update_fcr31();
738 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
739 54454097 ths
        DT2 = FLOAT_SNAN64;
740 fd4a04eb ths
}
741 fd4a04eb ths
FLOAT_OP(cvtl, s)
742 fd4a04eb ths
{
743 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
744 ead9360e ths
    DT2 = float32_to_int64(FST0, &env->fpu->fp_status);
745 fd4a04eb ths
    update_fcr31();
746 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
747 54454097 ths
        DT2 = FLOAT_SNAN64;
748 fd4a04eb ths
}
749 fd4a04eb ths
750 fd4a04eb ths
FLOAT_OP(cvtps, pw)
751 fd4a04eb ths
{
752 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
753 ead9360e ths
    FST2 = int32_to_float32(WT0, &env->fpu->fp_status);
754 ead9360e ths
    FSTH2 = int32_to_float32(WTH0, &env->fpu->fp_status);
755 fd4a04eb ths
    update_fcr31();
756 fd4a04eb ths
}
757 fd4a04eb ths
FLOAT_OP(cvtpw, ps)
758 fd4a04eb ths
{
759 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
760 ead9360e ths
    WT2 = float32_to_int32(FST0, &env->fpu->fp_status);
761 ead9360e ths
    WTH2 = float32_to_int32(FSTH0, &env->fpu->fp_status);
762 fd4a04eb ths
    update_fcr31();
763 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
764 54454097 ths
        WT2 = FLOAT_SNAN32;
765 fd4a04eb ths
}
766 fd4a04eb ths
FLOAT_OP(cvts, d)
767 fd4a04eb ths
{
768 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
769 ead9360e ths
    FST2 = float64_to_float32(FDT0, &env->fpu->fp_status);
770 fd4a04eb ths
    update_fcr31();
771 fd4a04eb ths
}
772 fd4a04eb ths
FLOAT_OP(cvts, w)
773 fd4a04eb ths
{
774 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
775 ead9360e ths
    FST2 = int32_to_float32(WT0, &env->fpu->fp_status);
776 fd4a04eb ths
    update_fcr31();
777 fd4a04eb ths
}
778 fd4a04eb ths
FLOAT_OP(cvts, l)
779 fd4a04eb ths
{
780 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
781 ead9360e ths
    FST2 = int64_to_float32(DT0, &env->fpu->fp_status);
782 fd4a04eb ths
    update_fcr31();
783 fd4a04eb ths
}
784 fd4a04eb ths
FLOAT_OP(cvts, pl)
785 fd4a04eb ths
{
786 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
787 fd4a04eb ths
    WT2 = WT0;
788 fd4a04eb ths
    update_fcr31();
789 fd4a04eb ths
}
790 fd4a04eb ths
FLOAT_OP(cvts, pu)
791 fd4a04eb ths
{
792 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
793 fd4a04eb ths
    WT2 = WTH0;
794 fd4a04eb ths
    update_fcr31();
795 fd4a04eb ths
}
796 fd4a04eb ths
FLOAT_OP(cvtw, s)
797 fd4a04eb ths
{
798 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
799 ead9360e ths
    WT2 = float32_to_int32(FST0, &env->fpu->fp_status);
800 fd4a04eb ths
    update_fcr31();
801 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
802 54454097 ths
        WT2 = FLOAT_SNAN32;
803 fd4a04eb ths
}
804 fd4a04eb ths
FLOAT_OP(cvtw, d)
805 fd4a04eb ths
{
806 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
807 ead9360e ths
    WT2 = float64_to_int32(FDT0, &env->fpu->fp_status);
808 fd4a04eb ths
    update_fcr31();
809 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
810 54454097 ths
        WT2 = FLOAT_SNAN32;
811 fd4a04eb ths
}
812 fd4a04eb ths
813 fd4a04eb ths
FLOAT_OP(roundl, d)
814 fd4a04eb ths
{
815 ead9360e ths
    set_float_rounding_mode(float_round_nearest_even, &env->fpu->fp_status);
816 ead9360e ths
    DT2 = float64_to_int64(FDT0, &env->fpu->fp_status);
817 fd4a04eb ths
    RESTORE_ROUNDING_MODE;
818 fd4a04eb ths
    update_fcr31();
819 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
820 54454097 ths
        DT2 = FLOAT_SNAN64;
821 fd4a04eb ths
}
822 fd4a04eb ths
FLOAT_OP(roundl, s)
823 fd4a04eb ths
{
824 ead9360e ths
    set_float_rounding_mode(float_round_nearest_even, &env->fpu->fp_status);
825 ead9360e ths
    DT2 = float32_to_int64(FST0, &env->fpu->fp_status);
826 fd4a04eb ths
    RESTORE_ROUNDING_MODE;
827 fd4a04eb ths
    update_fcr31();
828 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
829 54454097 ths
        DT2 = FLOAT_SNAN64;
830 fd4a04eb ths
}
831 fd4a04eb ths
FLOAT_OP(roundw, d)
832 fd4a04eb ths
{
833 ead9360e ths
    set_float_rounding_mode(float_round_nearest_even, &env->fpu->fp_status);
834 ead9360e ths
    WT2 = float64_to_int32(FDT0, &env->fpu->fp_status);
835 fd4a04eb ths
    RESTORE_ROUNDING_MODE;
836 fd4a04eb ths
    update_fcr31();
837 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
838 54454097 ths
        WT2 = FLOAT_SNAN32;
839 fd4a04eb ths
}
840 fd4a04eb ths
FLOAT_OP(roundw, s)
841 fd4a04eb ths
{
842 ead9360e ths
    set_float_rounding_mode(float_round_nearest_even, &env->fpu->fp_status);
843 ead9360e ths
    WT2 = float32_to_int32(FST0, &env->fpu->fp_status);
844 fd4a04eb ths
    RESTORE_ROUNDING_MODE;
845 fd4a04eb ths
    update_fcr31();
846 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
847 54454097 ths
        WT2 = FLOAT_SNAN32;
848 fd4a04eb ths
}
849 fd4a04eb ths
850 fd4a04eb ths
FLOAT_OP(truncl, d)
851 fd4a04eb ths
{
852 ead9360e ths
    DT2 = float64_to_int64_round_to_zero(FDT0, &env->fpu->fp_status);
853 fd4a04eb ths
    update_fcr31();
854 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
855 54454097 ths
        DT2 = FLOAT_SNAN64;
856 fd4a04eb ths
}
857 fd4a04eb ths
FLOAT_OP(truncl, s)
858 fd4a04eb ths
{
859 ead9360e ths
    DT2 = float32_to_int64_round_to_zero(FST0, &env->fpu->fp_status);
860 fd4a04eb ths
    update_fcr31();
861 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
862 54454097 ths
        DT2 = FLOAT_SNAN64;
863 fd4a04eb ths
}
864 fd4a04eb ths
FLOAT_OP(truncw, d)
865 fd4a04eb ths
{
866 ead9360e ths
    WT2 = float64_to_int32_round_to_zero(FDT0, &env->fpu->fp_status);
867 fd4a04eb ths
    update_fcr31();
868 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
869 54454097 ths
        WT2 = FLOAT_SNAN32;
870 fd4a04eb ths
}
871 fd4a04eb ths
FLOAT_OP(truncw, s)
872 fd4a04eb ths
{
873 ead9360e ths
    WT2 = float32_to_int32_round_to_zero(FST0, &env->fpu->fp_status);
874 fd4a04eb ths
    update_fcr31();
875 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
876 54454097 ths
        WT2 = FLOAT_SNAN32;
877 fd4a04eb ths
}
878 fd4a04eb ths
879 fd4a04eb ths
FLOAT_OP(ceill, d)
880 fd4a04eb ths
{
881 ead9360e ths
    set_float_rounding_mode(float_round_up, &env->fpu->fp_status);
882 ead9360e ths
    DT2 = float64_to_int64(FDT0, &env->fpu->fp_status);
883 fd4a04eb ths
    RESTORE_ROUNDING_MODE;
884 fd4a04eb ths
    update_fcr31();
885 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
886 54454097 ths
        DT2 = FLOAT_SNAN64;
887 fd4a04eb ths
}
888 fd4a04eb ths
FLOAT_OP(ceill, s)
889 fd4a04eb ths
{
890 ead9360e ths
    set_float_rounding_mode(float_round_up, &env->fpu->fp_status);
891 ead9360e ths
    DT2 = float32_to_int64(FST0, &env->fpu->fp_status);
892 fd4a04eb ths
    RESTORE_ROUNDING_MODE;
893 fd4a04eb ths
    update_fcr31();
894 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
895 54454097 ths
        DT2 = FLOAT_SNAN64;
896 fd4a04eb ths
}
897 fd4a04eb ths
FLOAT_OP(ceilw, d)
898 fd4a04eb ths
{
899 ead9360e ths
    set_float_rounding_mode(float_round_up, &env->fpu->fp_status);
900 ead9360e ths
    WT2 = float64_to_int32(FDT0, &env->fpu->fp_status);
901 fd4a04eb ths
    RESTORE_ROUNDING_MODE;
902 fd4a04eb ths
    update_fcr31();
903 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
904 54454097 ths
        WT2 = FLOAT_SNAN32;
905 fd4a04eb ths
}
906 fd4a04eb ths
FLOAT_OP(ceilw, s)
907 fd4a04eb ths
{
908 ead9360e ths
    set_float_rounding_mode(float_round_up, &env->fpu->fp_status);
909 ead9360e ths
    WT2 = float32_to_int32(FST0, &env->fpu->fp_status);
910 fd4a04eb ths
    RESTORE_ROUNDING_MODE;
911 fd4a04eb ths
    update_fcr31();
912 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
913 54454097 ths
        WT2 = FLOAT_SNAN32;
914 fd4a04eb ths
}
915 fd4a04eb ths
916 fd4a04eb ths
FLOAT_OP(floorl, d)
917 fd4a04eb ths
{
918 ead9360e ths
    set_float_rounding_mode(float_round_down, &env->fpu->fp_status);
919 ead9360e ths
    DT2 = float64_to_int64(FDT0, &env->fpu->fp_status);
920 fd4a04eb ths
    RESTORE_ROUNDING_MODE;
921 fd4a04eb ths
    update_fcr31();
922 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
923 54454097 ths
        DT2 = FLOAT_SNAN64;
924 fd4a04eb ths
}
925 fd4a04eb ths
FLOAT_OP(floorl, s)
926 fd4a04eb ths
{
927 ead9360e ths
    set_float_rounding_mode(float_round_down, &env->fpu->fp_status);
928 ead9360e ths
    DT2 = float32_to_int64(FST0, &env->fpu->fp_status);
929 fd4a04eb ths
    RESTORE_ROUNDING_MODE;
930 fd4a04eb ths
    update_fcr31();
931 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
932 54454097 ths
        DT2 = FLOAT_SNAN64;
933 fd4a04eb ths
}
934 fd4a04eb ths
FLOAT_OP(floorw, d)
935 fd4a04eb ths
{
936 ead9360e ths
    set_float_rounding_mode(float_round_down, &env->fpu->fp_status);
937 ead9360e ths
    WT2 = float64_to_int32(FDT0, &env->fpu->fp_status);
938 fd4a04eb ths
    RESTORE_ROUNDING_MODE;
939 fd4a04eb ths
    update_fcr31();
940 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
941 54454097 ths
        WT2 = FLOAT_SNAN32;
942 fd4a04eb ths
}
943 fd4a04eb ths
FLOAT_OP(floorw, s)
944 fd4a04eb ths
{
945 ead9360e ths
    set_float_rounding_mode(float_round_down, &env->fpu->fp_status);
946 ead9360e ths
    WT2 = float32_to_int32(FST0, &env->fpu->fp_status);
947 fd4a04eb ths
    RESTORE_ROUNDING_MODE;
948 fd4a04eb ths
    update_fcr31();
949 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & (FP_OVERFLOW | FP_INVALID))
950 54454097 ths
        WT2 = FLOAT_SNAN32;
951 fd4a04eb ths
}
952 fd4a04eb ths
953 8dfdb87c ths
/* MIPS specific unary operations */
954 8dfdb87c ths
FLOAT_OP(recip, d)
955 8dfdb87c ths
{
956 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
957 ead9360e ths
    FDT2 = float64_div(FLOAT_ONE64, FDT0, &env->fpu->fp_status);
958 8dfdb87c ths
    update_fcr31();
959 8dfdb87c ths
}
960 8dfdb87c ths
FLOAT_OP(recip, s)
961 8dfdb87c ths
{
962 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
963 ead9360e ths
    FST2 = float32_div(FLOAT_ONE32, FST0, &env->fpu->fp_status);
964 8dfdb87c ths
    update_fcr31();
965 57fa1fb3 ths
}
966 57fa1fb3 ths
967 8dfdb87c ths
FLOAT_OP(rsqrt, d)
968 8dfdb87c ths
{
969 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
970 ead9360e ths
    FDT2 = float64_sqrt(FDT0, &env->fpu->fp_status);
971 ead9360e ths
    FDT2 = float64_div(FLOAT_ONE64, FDT2, &env->fpu->fp_status);
972 8dfdb87c ths
    update_fcr31();
973 8dfdb87c ths
}
974 8dfdb87c ths
FLOAT_OP(rsqrt, s)
975 8dfdb87c ths
{
976 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
977 ead9360e ths
    FST2 = float32_sqrt(FST0, &env->fpu->fp_status);
978 ead9360e ths
    FST2 = float32_div(FLOAT_ONE32, FST2, &env->fpu->fp_status);
979 8dfdb87c ths
    update_fcr31();
980 8dfdb87c ths
}
981 8dfdb87c ths
982 8dfdb87c ths
FLOAT_OP(recip1, d)
983 8dfdb87c ths
{
984 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
985 ead9360e ths
    FDT2 = float64_div(FLOAT_ONE64, FDT0, &env->fpu->fp_status);
986 8dfdb87c ths
    update_fcr31();
987 8dfdb87c ths
}
988 8dfdb87c ths
FLOAT_OP(recip1, s)
989 8dfdb87c ths
{
990 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
991 ead9360e ths
    FST2 = float32_div(FLOAT_ONE32, FST0, &env->fpu->fp_status);
992 8dfdb87c ths
    update_fcr31();
993 8dfdb87c ths
}
994 8dfdb87c ths
FLOAT_OP(recip1, ps)
995 8dfdb87c ths
{
996 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
997 ead9360e ths
    FST2 = float32_div(FLOAT_ONE32, FST0, &env->fpu->fp_status);
998 ead9360e ths
    FSTH2 = float32_div(FLOAT_ONE32, FSTH0, &env->fpu->fp_status);
999 8dfdb87c ths
    update_fcr31();
1000 8dfdb87c ths
}
1001 8dfdb87c ths
1002 8dfdb87c ths
FLOAT_OP(rsqrt1, d)
1003 8dfdb87c ths
{
1004 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
1005 ead9360e ths
    FDT2 = float64_sqrt(FDT0, &env->fpu->fp_status);
1006 ead9360e ths
    FDT2 = float64_div(FLOAT_ONE64, FDT2, &env->fpu->fp_status);
1007 8dfdb87c ths
    update_fcr31();
1008 8dfdb87c ths
}
1009 8dfdb87c ths
FLOAT_OP(rsqrt1, s)
1010 8dfdb87c ths
{
1011 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
1012 ead9360e ths
    FST2 = float32_sqrt(FST0, &env->fpu->fp_status);
1013 ead9360e ths
    FST2 = float32_div(FLOAT_ONE32, FST2, &env->fpu->fp_status);
1014 8dfdb87c ths
    update_fcr31();
1015 8dfdb87c ths
}
1016 8dfdb87c ths
FLOAT_OP(rsqrt1, ps)
1017 8dfdb87c ths
{
1018 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
1019 ead9360e ths
    FST2 = float32_sqrt(FST0, &env->fpu->fp_status);
1020 ead9360e ths
    FSTH2 = float32_sqrt(FSTH0, &env->fpu->fp_status);
1021 ead9360e ths
    FST2 = float32_div(FLOAT_ONE32, FST2, &env->fpu->fp_status);
1022 ead9360e ths
    FSTH2 = float32_div(FLOAT_ONE32, FSTH2, &env->fpu->fp_status);
1023 8dfdb87c ths
    update_fcr31();
1024 57fa1fb3 ths
}
1025 57fa1fb3 ths
1026 fd4a04eb ths
/* binary operations */
1027 fd4a04eb ths
#define FLOAT_BINOP(name) \
1028 fd4a04eb ths
FLOAT_OP(name, d)         \
1029 fd4a04eb ths
{                         \
1030 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);            \
1031 ead9360e ths
    FDT2 = float64_ ## name (FDT0, FDT1, &env->fpu->fp_status);    \
1032 ead9360e ths
    update_fcr31();                                                \
1033 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & FP_INVALID)                \
1034 54454097 ths
        FDT2 = FLOAT_QNAN64;                                       \
1035 fd4a04eb ths
}                         \
1036 fd4a04eb ths
FLOAT_OP(name, s)         \
1037 fd4a04eb ths
{                         \
1038 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);            \
1039 ead9360e ths
    FST2 = float32_ ## name (FST0, FST1, &env->fpu->fp_status);    \
1040 ead9360e ths
    update_fcr31();                                                \
1041 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & FP_INVALID)                \
1042 54454097 ths
        FST2 = FLOAT_QNAN32;                                       \
1043 fd4a04eb ths
}                         \
1044 fd4a04eb ths
FLOAT_OP(name, ps)        \
1045 fd4a04eb ths
{                         \
1046 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);            \
1047 ead9360e ths
    FST2 = float32_ ## name (FST0, FST1, &env->fpu->fp_status);    \
1048 ead9360e ths
    FSTH2 = float32_ ## name (FSTH0, FSTH1, &env->fpu->fp_status); \
1049 fd4a04eb ths
    update_fcr31();       \
1050 ead9360e ths
    if (GET_FP_CAUSE(env->fpu->fcr31) & FP_INVALID) {              \
1051 54454097 ths
        FST2 = FLOAT_QNAN32;                                       \
1052 54454097 ths
        FSTH2 = FLOAT_QNAN32;                                      \
1053 3a5b360d ths
    }                     \
1054 fd4a04eb ths
}
1055 fd4a04eb ths
FLOAT_BINOP(add)
1056 fd4a04eb ths
FLOAT_BINOP(sub)
1057 fd4a04eb ths
FLOAT_BINOP(mul)
1058 fd4a04eb ths
FLOAT_BINOP(div)
1059 fd4a04eb ths
#undef FLOAT_BINOP
1060 fd4a04eb ths
1061 8dfdb87c ths
/* MIPS specific binary operations */
1062 8dfdb87c ths
FLOAT_OP(recip2, d)
1063 8dfdb87c ths
{
1064 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
1065 ead9360e ths
    FDT2 = float64_mul(FDT0, FDT2, &env->fpu->fp_status);
1066 ead9360e ths
    FDT2 = float64_sub(FDT2, FLOAT_ONE64, &env->fpu->fp_status) ^ FLOAT_SIGN64;
1067 8dfdb87c ths
    update_fcr31();
1068 8dfdb87c ths
}
1069 8dfdb87c ths
FLOAT_OP(recip2, s)
1070 8dfdb87c ths
{
1071 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
1072 ead9360e ths
    FST2 = float32_mul(FST0, FST2, &env->fpu->fp_status);
1073 ead9360e ths
    FST2 = float32_sub(FST2, FLOAT_ONE32, &env->fpu->fp_status) ^ FLOAT_SIGN32;
1074 8dfdb87c ths
    update_fcr31();
1075 8dfdb87c ths
}
1076 8dfdb87c ths
FLOAT_OP(recip2, ps)
1077 8dfdb87c ths
{
1078 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
1079 ead9360e ths
    FST2 = float32_mul(FST0, FST2, &env->fpu->fp_status);
1080 ead9360e ths
    FSTH2 = float32_mul(FSTH0, FSTH2, &env->fpu->fp_status);
1081 ead9360e ths
    FST2 = float32_sub(FST2, FLOAT_ONE32, &env->fpu->fp_status) ^ FLOAT_SIGN32;
1082 ead9360e ths
    FSTH2 = float32_sub(FSTH2, FLOAT_ONE32, &env->fpu->fp_status) ^ FLOAT_SIGN32;
1083 8dfdb87c ths
    update_fcr31();
1084 8dfdb87c ths
}
1085 8dfdb87c ths
1086 8dfdb87c ths
FLOAT_OP(rsqrt2, d)
1087 8dfdb87c ths
{
1088 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
1089 ead9360e ths
    FDT2 = float64_mul(FDT0, FDT2, &env->fpu->fp_status);
1090 ead9360e ths
    FDT2 = float64_sub(FDT2, FLOAT_ONE64, &env->fpu->fp_status);
1091 ead9360e ths
    FDT2 = float64_div(FDT2, FLOAT_TWO64, &env->fpu->fp_status) ^ FLOAT_SIGN64;
1092 8dfdb87c ths
    update_fcr31();
1093 8dfdb87c ths
}
1094 8dfdb87c ths
FLOAT_OP(rsqrt2, s)
1095 8dfdb87c ths
{
1096 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
1097 ead9360e ths
    FST2 = float32_mul(FST0, FST2, &env->fpu->fp_status);
1098 ead9360e ths
    FST2 = float32_sub(FST2, FLOAT_ONE32, &env->fpu->fp_status);
1099 ead9360e ths
    FST2 = float32_div(FST2, FLOAT_TWO32, &env->fpu->fp_status) ^ FLOAT_SIGN32;
1100 8dfdb87c ths
    update_fcr31();
1101 8dfdb87c ths
}
1102 8dfdb87c ths
FLOAT_OP(rsqrt2, ps)
1103 8dfdb87c ths
{
1104 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
1105 ead9360e ths
    FST2 = float32_mul(FST0, FST2, &env->fpu->fp_status);
1106 ead9360e ths
    FSTH2 = float32_mul(FSTH0, FSTH2, &env->fpu->fp_status);
1107 ead9360e ths
    FST2 = float32_sub(FST2, FLOAT_ONE32, &env->fpu->fp_status);
1108 ead9360e ths
    FSTH2 = float32_sub(FSTH2, FLOAT_ONE32, &env->fpu->fp_status);
1109 ead9360e ths
    FST2 = float32_div(FST2, FLOAT_TWO32, &env->fpu->fp_status) ^ FLOAT_SIGN32;
1110 ead9360e ths
    FSTH2 = float32_div(FSTH2, FLOAT_TWO32, &env->fpu->fp_status) ^ FLOAT_SIGN32;
1111 8dfdb87c ths
    update_fcr31();
1112 57fa1fb3 ths
}
1113 57fa1fb3 ths
1114 fd4a04eb ths
FLOAT_OP(addr, ps)
1115 fd4a04eb ths
{
1116 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
1117 ead9360e ths
    FST2 = float32_add (FST0, FSTH0, &env->fpu->fp_status);
1118 ead9360e ths
    FSTH2 = float32_add (FST1, FSTH1, &env->fpu->fp_status);
1119 fd4a04eb ths
    update_fcr31();
1120 fd4a04eb ths
}
1121 fd4a04eb ths
1122 57fa1fb3 ths
FLOAT_OP(mulr, ps)
1123 57fa1fb3 ths
{
1124 ead9360e ths
    set_float_exception_flags(0, &env->fpu->fp_status);
1125 ead9360e ths
    FST2 = float32_mul (FST0, FSTH0, &env->fpu->fp_status);
1126 ead9360e ths
    FSTH2 = float32_mul (FST1, FSTH1, &env->fpu->fp_status);
1127 57fa1fb3 ths
    update_fcr31();
1128 57fa1fb3 ths
}
1129 57fa1fb3 ths
1130 8dfdb87c ths
/* compare operations */
1131 fd4a04eb ths
#define FOP_COND_D(op, cond)                   \
1132 fd4a04eb ths
void do_cmp_d_ ## op (long cc)                 \
1133 fd4a04eb ths
{                                              \
1134 fd4a04eb ths
    int c = cond;                              \
1135 fd4a04eb ths
    update_fcr31();                            \
1136 fd4a04eb ths
    if (c)                                     \
1137 ead9360e ths
        SET_FP_COND(cc, env->fpu);             \
1138 fd4a04eb ths
    else                                       \
1139 ead9360e ths
        CLEAR_FP_COND(cc, env->fpu);           \
1140 fd4a04eb ths
}                                              \
1141 fd4a04eb ths
void do_cmpabs_d_ ## op (long cc)              \
1142 fd4a04eb ths
{                                              \
1143 fd4a04eb ths
    int c;                                     \
1144 8dfdb87c ths
    FDT0 &= ~FLOAT_SIGN64;                     \
1145 8dfdb87c ths
    FDT1 &= ~FLOAT_SIGN64;                     \
1146 fd4a04eb ths
    c = cond;                                  \
1147 fd4a04eb ths
    update_fcr31();                            \
1148 fd4a04eb ths
    if (c)                                     \
1149 ead9360e ths
        SET_FP_COND(cc, env->fpu);             \
1150 fd4a04eb ths
    else                                       \
1151 ead9360e ths
        CLEAR_FP_COND(cc, env->fpu);           \
1152 fd4a04eb ths
}
1153 fd4a04eb ths
1154 fd4a04eb ths
int float64_is_unordered(int sig, float64 a, float64 b STATUS_PARAM)
1155 fd4a04eb ths
{
1156 fd4a04eb ths
    if (float64_is_signaling_nan(a) ||
1157 fd4a04eb ths
        float64_is_signaling_nan(b) ||
1158 fd4a04eb ths
        (sig && (float64_is_nan(a) || float64_is_nan(b)))) {
1159 fd4a04eb ths
        float_raise(float_flag_invalid, status);
1160 fd4a04eb ths
        return 1;
1161 fd4a04eb ths
    } else if (float64_is_nan(a) || float64_is_nan(b)) {
1162 fd4a04eb ths
        return 1;
1163 fd4a04eb ths
    } else {
1164 fd4a04eb ths
        return 0;
1165 fd4a04eb ths
    }
1166 fd4a04eb ths
}
1167 fd4a04eb ths
1168 fd4a04eb ths
/* NOTE: the comma operator will make "cond" to eval to false,
1169 fd4a04eb ths
 * but float*_is_unordered() is still called. */
1170 ead9360e ths
FOP_COND_D(f,   (float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status), 0))
1171 ead9360e ths
FOP_COND_D(un,  float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status))
1172 ead9360e ths
FOP_COND_D(eq,  !float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status) && float64_eq(FDT0, FDT1, &env->fpu->fp_status))
1173 ead9360e ths
FOP_COND_D(ueq, float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status)  || float64_eq(FDT0, FDT1, &env->fpu->fp_status))
1174 ead9360e ths
FOP_COND_D(olt, !float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status) && float64_lt(FDT0, FDT1, &env->fpu->fp_status))
1175 ead9360e ths
FOP_COND_D(ult, float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status)  || float64_lt(FDT0, FDT1, &env->fpu->fp_status))
1176 ead9360e ths
FOP_COND_D(ole, !float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status) && float64_le(FDT0, FDT1, &env->fpu->fp_status))
1177 ead9360e ths
FOP_COND_D(ule, float64_is_unordered(0, FDT1, FDT0, &env->fpu->fp_status)  || float64_le(FDT0, FDT1, &env->fpu->fp_status))
1178 fd4a04eb ths
/* NOTE: the comma operator will make "cond" to eval to false,
1179 fd4a04eb ths
 * but float*_is_unordered() is still called. */
1180 ead9360e ths
FOP_COND_D(sf,  (float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status), 0))
1181 ead9360e ths
FOP_COND_D(ngle,float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status))
1182 ead9360e ths
FOP_COND_D(seq, !float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status) && float64_eq(FDT0, FDT1, &env->fpu->fp_status))
1183 ead9360e ths
FOP_COND_D(ngl, float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status)  || float64_eq(FDT0, FDT1, &env->fpu->fp_status))
1184 ead9360e ths
FOP_COND_D(lt,  !float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status) && float64_lt(FDT0, FDT1, &env->fpu->fp_status))
1185 ead9360e ths
FOP_COND_D(nge, float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status)  || float64_lt(FDT0, FDT1, &env->fpu->fp_status))
1186 ead9360e ths
FOP_COND_D(le,  !float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status) && float64_le(FDT0, FDT1, &env->fpu->fp_status))
1187 ead9360e ths
FOP_COND_D(ngt, float64_is_unordered(1, FDT1, FDT0, &env->fpu->fp_status)  || float64_le(FDT0, FDT1, &env->fpu->fp_status))
1188 fd4a04eb ths
1189 fd4a04eb ths
#define FOP_COND_S(op, cond)                   \
1190 fd4a04eb ths
void do_cmp_s_ ## op (long cc)                 \
1191 fd4a04eb ths
{                                              \
1192 fd4a04eb ths
    int c = cond;                              \
1193 fd4a04eb ths
    update_fcr31();                            \
1194 fd4a04eb ths
    if (c)                                     \
1195 ead9360e ths
        SET_FP_COND(cc, env->fpu);             \
1196 fd4a04eb ths
    else                                       \
1197 ead9360e ths
        CLEAR_FP_COND(cc, env->fpu);           \
1198 fd4a04eb ths
}                                              \
1199 fd4a04eb ths
void do_cmpabs_s_ ## op (long cc)              \
1200 fd4a04eb ths
{                                              \
1201 fd4a04eb ths
    int c;                                     \
1202 8dfdb87c ths
    FST0 &= ~FLOAT_SIGN32;                     \
1203 8dfdb87c ths
    FST1 &= ~FLOAT_SIGN32;                     \
1204 fd4a04eb ths
    c = cond;                                  \
1205 fd4a04eb ths
    update_fcr31();                            \
1206 fd4a04eb ths
    if (c)                                     \
1207 ead9360e ths
        SET_FP_COND(cc, env->fpu);             \
1208 fd4a04eb ths
    else                                       \
1209 ead9360e ths
        CLEAR_FP_COND(cc, env->fpu);           \
1210 fd4a04eb ths
}
1211 fd4a04eb ths
1212 fd4a04eb ths
flag float32_is_unordered(int sig, float32 a, float32 b STATUS_PARAM)
1213 fd4a04eb ths
{
1214 fd4a04eb ths
    if (float32_is_signaling_nan(a) ||
1215 fd4a04eb ths
        float32_is_signaling_nan(b) ||
1216 fd4a04eb ths
        (sig && (float32_is_nan(a) || float32_is_nan(b)))) {
1217 fd4a04eb ths
        float_raise(float_flag_invalid, status);
1218 fd4a04eb ths
        return 1;
1219 fd4a04eb ths
    } else if (float32_is_nan(a) || float32_is_nan(b)) {
1220 fd4a04eb ths
        return 1;
1221 fd4a04eb ths
    } else {
1222 fd4a04eb ths
        return 0;
1223 fd4a04eb ths
    }
1224 fd4a04eb ths
}
1225 fd4a04eb ths
1226 fd4a04eb ths
/* NOTE: the comma operator will make "cond" to eval to false,
1227 fd4a04eb ths
 * but float*_is_unordered() is still called. */
1228 ead9360e ths
FOP_COND_S(f,   (float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status), 0))
1229 ead9360e ths
FOP_COND_S(un,  float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status))
1230 ead9360e ths
FOP_COND_S(eq,  !float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) && float32_eq(FST0, FST1, &env->fpu->fp_status))
1231 ead9360e ths
FOP_COND_S(ueq, float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status)  || float32_eq(FST0, FST1, &env->fpu->fp_status))
1232 ead9360e ths
FOP_COND_S(olt, !float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) && float32_lt(FST0, FST1, &env->fpu->fp_status))
1233 ead9360e ths
FOP_COND_S(ult, float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status)  || float32_lt(FST0, FST1, &env->fpu->fp_status))
1234 ead9360e ths
FOP_COND_S(ole, !float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status) && float32_le(FST0, FST1, &env->fpu->fp_status))
1235 ead9360e ths
FOP_COND_S(ule, float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status)  || float32_le(FST0, FST1, &env->fpu->fp_status))
1236 fd4a04eb ths
/* NOTE: the comma operator will make "cond" to eval to false,
1237 fd4a04eb ths
 * but float*_is_unordered() is still called. */
1238 ead9360e ths
FOP_COND_S(sf,  (float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status), 0))
1239 ead9360e ths
FOP_COND_S(ngle,float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status))
1240 ead9360e ths
FOP_COND_S(seq, !float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) && float32_eq(FST0, FST1, &env->fpu->fp_status))
1241 ead9360e ths
FOP_COND_S(ngl, float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status)  || float32_eq(FST0, FST1, &env->fpu->fp_status))
1242 ead9360e ths
FOP_COND_S(lt,  !float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) && float32_lt(FST0, FST1, &env->fpu->fp_status))
1243 ead9360e ths
FOP_COND_S(nge, float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status)  || float32_lt(FST0, FST1, &env->fpu->fp_status))
1244 ead9360e ths
FOP_COND_S(le,  !float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status) && float32_le(FST0, FST1, &env->fpu->fp_status))
1245 ead9360e ths
FOP_COND_S(ngt, float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status)  || float32_le(FST0, FST1, &env->fpu->fp_status))
1246 fd4a04eb ths
1247 fd4a04eb ths
#define FOP_COND_PS(op, condl, condh)          \
1248 fd4a04eb ths
void do_cmp_ps_ ## op (long cc)                \
1249 fd4a04eb ths
{                                              \
1250 fd4a04eb ths
    int cl = condl;                            \
1251 fd4a04eb ths
    int ch = condh;                            \
1252 fd4a04eb ths
    update_fcr31();                            \
1253 fd4a04eb ths
    if (cl)                                    \
1254 ead9360e ths
        SET_FP_COND(cc, env->fpu);             \
1255 fd4a04eb ths
    else                                       \
1256 ead9360e ths
        CLEAR_FP_COND(cc, env->fpu);           \
1257 fd4a04eb ths
    if (ch)                                    \
1258 ead9360e ths
        SET_FP_COND(cc + 1, env->fpu);         \
1259 fd4a04eb ths
    else                                       \
1260 ead9360e ths
        CLEAR_FP_COND(cc + 1, env->fpu);       \
1261 fd4a04eb ths
}                                              \
1262 fd4a04eb ths
void do_cmpabs_ps_ ## op (long cc)             \
1263 fd4a04eb ths
{                                              \
1264 fd4a04eb ths
    int cl, ch;                                \
1265 8dfdb87c ths
    FST0 &= ~FLOAT_SIGN32;                     \
1266 8dfdb87c ths
    FSTH0 &= ~FLOAT_SIGN32;                    \
1267 8dfdb87c ths
    FST1 &= ~FLOAT_SIGN32;                     \
1268 8dfdb87c ths
    FSTH1 &= ~FLOAT_SIGN32;                    \
1269 fd4a04eb ths
    cl = condl;                                \
1270 fd4a04eb ths
    ch = condh;                                \
1271 fd4a04eb ths
    update_fcr31();                            \
1272 fd4a04eb ths
    if (cl)                                    \
1273 ead9360e ths
        SET_FP_COND(cc, env->fpu);             \
1274 fd4a04eb ths
    else                                       \
1275 ead9360e ths
        CLEAR_FP_COND(cc, env->fpu);           \
1276 fd4a04eb ths
    if (ch)                                    \
1277 ead9360e ths
        SET_FP_COND(cc + 1, env->fpu);         \
1278 fd4a04eb ths
    else                                       \
1279 ead9360e ths
        CLEAR_FP_COND(cc + 1, env->fpu);       \
1280 fd4a04eb ths
}
1281 fd4a04eb ths
1282 fd4a04eb ths
/* NOTE: the comma operator will make "cond" to eval to false,
1283 fd4a04eb ths
 * but float*_is_unordered() is still called. */
1284 ead9360e ths
FOP_COND_PS(f,   (float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status), 0),
1285 ead9360e ths
                 (float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status), 0))
1286 ead9360e ths
FOP_COND_PS(un,  float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status),
1287 ead9360e ths
                 float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status))
1288 ead9360e ths
FOP_COND_PS(eq,  !float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status)   && float32_eq(FST0, FST1, &env->fpu->fp_status),
1289 ead9360e ths
                 !float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status) && float32_eq(FSTH0, FSTH1, &env->fpu->fp_status))
1290 ead9360e ths
FOP_COND_PS(ueq, float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status)    || float32_eq(FST0, FST1, &env->fpu->fp_status),
1291 ead9360e ths
                 float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status)  || float32_eq(FSTH0, FSTH1, &env->fpu->fp_status))
1292 ead9360e ths
FOP_COND_PS(olt, !float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status)   && float32_lt(FST0, FST1, &env->fpu->fp_status),
1293 ead9360e ths
                 !float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status) && float32_lt(FSTH0, FSTH1, &env->fpu->fp_status))
1294 ead9360e ths
FOP_COND_PS(ult, float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status)    || float32_lt(FST0, FST1, &env->fpu->fp_status),
1295 ead9360e ths
                 float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status)  || float32_lt(FSTH0, FSTH1, &env->fpu->fp_status))
1296 ead9360e ths
FOP_COND_PS(ole, !float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status)   && float32_le(FST0, FST1, &env->fpu->fp_status),
1297 ead9360e ths
                 !float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status) && float32_le(FSTH0, FSTH1, &env->fpu->fp_status))
1298 ead9360e ths
FOP_COND_PS(ule, float32_is_unordered(0, FST1, FST0, &env->fpu->fp_status)    || float32_le(FST0, FST1, &env->fpu->fp_status),
1299 ead9360e ths
                 float32_is_unordered(0, FSTH1, FSTH0, &env->fpu->fp_status)  || float32_le(FSTH0, FSTH1, &env->fpu->fp_status))
1300 fd4a04eb ths
/* NOTE: the comma operator will make "cond" to eval to false,
1301 fd4a04eb ths
 * but float*_is_unordered() is still called. */
1302 ead9360e ths
FOP_COND_PS(sf,  (float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status), 0),
1303 ead9360e ths
                 (float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status), 0))
1304 ead9360e ths
FOP_COND_PS(ngle,float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status),
1305 ead9360e ths
                 float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status))
1306 ead9360e ths
FOP_COND_PS(seq, !float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status)   && float32_eq(FST0, FST1, &env->fpu->fp_status),
1307 ead9360e ths
                 !float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status) && float32_eq(FSTH0, FSTH1, &env->fpu->fp_status))
1308 ead9360e ths
FOP_COND_PS(ngl, float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status)    || float32_eq(FST0, FST1, &env->fpu->fp_status),
1309 ead9360e ths
                 float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status)  || float32_eq(FSTH0, FSTH1, &env->fpu->fp_status))
1310 ead9360e ths
FOP_COND_PS(lt,  !float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status)   && float32_lt(FST0, FST1, &env->fpu->fp_status),
1311 ead9360e ths
                 !float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status) && float32_lt(FSTH0, FSTH1, &env->fpu->fp_status))
1312 ead9360e ths
FOP_COND_PS(nge, float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status)    || float32_lt(FST0, FST1, &env->fpu->fp_status),
1313 ead9360e ths
                 float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status)  || float32_lt(FSTH0, FSTH1, &env->fpu->fp_status))
1314 ead9360e ths
FOP_COND_PS(le,  !float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status)   && float32_le(FST0, FST1, &env->fpu->fp_status),
1315 ead9360e ths
                 !float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status) && float32_le(FSTH0, FSTH1, &env->fpu->fp_status))
1316 ead9360e ths
FOP_COND_PS(ngt, float32_is_unordered(1, FST1, FST0, &env->fpu->fp_status)    || float32_le(FST0, FST1, &env->fpu->fp_status),
1317 ead9360e ths
                 float32_is_unordered(1, FSTH1, FSTH0, &env->fpu->fp_status)  || float32_le(FSTH0, FSTH1, &env->fpu->fp_status))