Statistics
| Branch: | Revision:

root / target-mips / op_helper.c @ e034e2c3

History | View | Annotate | Download (39.5 kB)

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