1 /* $NetBSD: fpu_emu.c,v 1.14 2005/12/11 12:18:42 christos Exp $ */
4 * SPDX-License-Identifier: BSD-4-Clause
6 * Copyright 2001 Wasabi Systems, Inc.
9 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed for the NetBSD Project by
22 * Wasabi Systems, Inc.
23 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
24 * or promote products derived from this software without specific prior
27 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
41 * Copyright (c) 1992, 1993
42 * The Regents of the University of California. All rights reserved.
44 * This software was developed by the Computer Systems Engineering group
45 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
46 * contributed to Berkeley.
48 * All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by the University of
51 * California, Lawrence Berkeley Laboratory.
53 * Redistribution and use in source and binary forms, with or without
54 * modification, are permitted provided that the following conditions
56 * 1. Redistributions of source code must retain the above copyright
57 * notice, this list of conditions and the following disclaimer.
58 * 2. Redistributions in binary form must reproduce the above copyright
59 * notice, this list of conditions and the following disclaimer in the
60 * documentation and/or other materials provided with the distribution.
61 * 3. Neither the name of the University nor the names of its contributors
62 * may be used to endorse or promote products derived from this software
63 * without specific prior written permission.
65 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
66 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
67 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
68 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
69 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
70 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
71 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
72 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
73 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
74 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
77 * @(#)fpu.c 8.1 (Berkeley) 6/11/93
80 #include <sys/cdefs.h>
81 __FBSDID("$FreeBSD$");
85 #include <sys/param.h>
86 #include <sys/systm.h>
88 #include <sys/kernel.h>
90 #include <sys/sysctl.h>
91 #include <sys/signal.h>
92 #include <sys/syslog.h>
93 #include <sys/signalvar.h>
95 #include <machine/fpu.h>
96 #include <machine/reg.h>
98 #include <powerpc/fpu/fpu_emu.h>
99 #include <powerpc/fpu/fpu_extern.h>
100 #include <powerpc/fpu/fpu_instr.h>
102 static SYSCTL_NODE(_hw, OID_AUTO, fpu_emu, CTLFLAG_RW, 0, "FPU emulator");
104 #define FPU_EMU_EVCNT_DECL(name) \
105 static u_int fpu_emu_evcnt_##name; \
106 SYSCTL_INT(_hw_fpu_emu, OID_AUTO, evcnt_##name, CTLFLAG_RD, \
107 &fpu_emu_evcnt_##name, 0, "")
109 #define FPU_EMU_EVCNT_INCR(name) fpu_emu_evcnt_##name++
111 FPU_EMU_EVCNT_DECL(stfiwx);
112 FPU_EMU_EVCNT_DECL(fpstore);
113 FPU_EMU_EVCNT_DECL(fpload);
114 FPU_EMU_EVCNT_DECL(fcmpu);
115 FPU_EMU_EVCNT_DECL(frsp);
116 FPU_EMU_EVCNT_DECL(fctiw);
117 FPU_EMU_EVCNT_DECL(fcmpo);
118 FPU_EMU_EVCNT_DECL(mtfsb1);
119 FPU_EMU_EVCNT_DECL(fnegabs);
120 FPU_EMU_EVCNT_DECL(mcrfs);
121 FPU_EMU_EVCNT_DECL(mtfsb0);
122 FPU_EMU_EVCNT_DECL(fmr);
123 FPU_EMU_EVCNT_DECL(mtfsfi);
124 FPU_EMU_EVCNT_DECL(fnabs);
125 FPU_EMU_EVCNT_DECL(fabs);
126 FPU_EMU_EVCNT_DECL(mffs);
127 FPU_EMU_EVCNT_DECL(mtfsf);
128 FPU_EMU_EVCNT_DECL(fctid);
129 FPU_EMU_EVCNT_DECL(fcfid);
130 FPU_EMU_EVCNT_DECL(fdiv);
131 FPU_EMU_EVCNT_DECL(fsub);
132 FPU_EMU_EVCNT_DECL(fadd);
133 FPU_EMU_EVCNT_DECL(fsqrt);
134 FPU_EMU_EVCNT_DECL(fsel);
135 FPU_EMU_EVCNT_DECL(fpres);
136 FPU_EMU_EVCNT_DECL(fmul);
137 FPU_EMU_EVCNT_DECL(frsqrte);
138 FPU_EMU_EVCNT_DECL(fmulsub);
139 FPU_EMU_EVCNT_DECL(fmuladd);
140 FPU_EMU_EVCNT_DECL(fnmsub);
141 FPU_EMU_EVCNT_DECL(fnmadd);
143 /* FPSR exception masks */
144 #define FPSR_EX_MSK (FPSCR_VX|FPSCR_OX|FPSCR_UX|FPSCR_ZX| \
145 FPSCR_XX|FPSCR_VXSNAN|FPSCR_VXISI|FPSCR_VXIDI| \
146 FPSCR_VXZDZ|FPSCR_VXIMZ|FPSCR_VXVC|FPSCR_VXSOFT|\
147 FPSCR_VXSQRT|FPSCR_VXCVI)
148 #define FPSR_EX (FPSCR_VE|FPSCR_OE|FPSCR_UE|FPSCR_ZE|FPSCR_XE)
149 #define FPSR_EXOP (FPSR_EX_MSK&(~FPSR_EX))
154 vm_offset_t opc_disasm(vm_offset_t, int);
157 * Dump a `fpn' structure.
160 fpu_dumpfpn(struct fpn *fp)
162 static const char *class[] = {
163 "SNAN", "QNAN", "ZERO", "NUM", "INF"
166 printf("%s %c.%x %x %x %xE%d", class[fp->fp_class + 2],
167 fp->fp_sign ? '-' : ' ',
168 fp->fp_mant[0], fp->fp_mant[1],
169 fp->fp_mant[2], fp->fp_mant[3],
175 * fpu_execute returns the following error numbers (0 = no error):
177 #define FPE 1 /* take a floating point exception */
178 #define NOTFPU 2 /* not an FPU instruction */
183 * Emulate a floating-point instruction.
184 * Return zero for success, else signal number.
185 * (Typically: zero, SIGFPE, SIGILL, SIGSEGV)
188 fpu_emulate(struct trapframe *frame, struct fpu *fpf)
194 /* initialize insn.is_datasize to tell it is *not* initialized */
198 /* always set this (to avoid a warning) */
200 if (copyin((void *) (frame->srr0), &insn.i_int, sizeof (insn.i_int))) {
202 printf("fpu_emulate: fault reading opcode\n");
207 DPRINTF(FPE_EX, ("fpu_emulate: emulating insn %x at %p\n",
208 insn.i_int, (void *)frame->srr0));
211 if ((insn.i_any.i_opcd == OPC_TWI) ||
212 ((insn.i_any.i_opcd == OPC_integer_31) &&
213 (insn.i_x.i_xo == OPC31_TW))) {
214 /* Check for the two trap insns. */
215 DPRINTF(FPE_EX, ("fpu_emulate: SIGTRAP\n"));
219 switch (fpu_execute(frame, &fe, &insn)) {
221 DPRINTF(FPE_EX, ("fpu_emulate: success\n"));
226 DPRINTF(FPE_EX, ("fpu_emulate: SIGFPE\n"));
231 DPRINTF(FPE_EX, ("fpu_emulate: SIGSEGV\n"));
237 DPRINTF(FPE_EX, ("fpu_emulate: SIGILL\n"));
239 if (fpe_debug & FPE_EX) {
240 printf("fpu_emulate: illegal insn %x at %p:",
241 insn.i_int, (void *) (frame->srr0));
242 opc_disasm(frame->srr0, insn.i_int);
247 if (fpe_debug & FPE_EX)
248 kdb_enter(KDB_WHY_UNSET, "illegal instruction");
257 * Execute an FPU instruction (one that runs entirely in the FPU; not
258 * FBfcc or STF, for instance). On return, fe->fe_fs->fs_fsr will be
259 * modified to reflect the setting the hardware would have left.
261 * Note that we do not catch all illegal opcodes, so you can, for instance,
262 * multiply two integers this way.
265 fpu_execute(struct trapframe *tf, struct fpemu *fe, union instr *insn)
268 union instr instr = *insn;
271 int ra, rb, rc, rt, type, mask, fsr, cx, bf, setcr;
278 fe->fe_fpscr = ((int *)&fs->fpscr)[1];
281 * On PowerPC all floating point values are stored in registers
282 * as doubles, even when used for single precision operations.
285 cond = instr.i_any.i_rc;
287 bf = 0; /* XXX gcc */
289 #if defined(DDB) && defined(DEBUG)
290 if (fpe_debug & FPE_EX) {
291 vm_offset_t loc = tf->srr0;
293 printf("Trying to emulate: %p ", (void *)loc);
294 opc_disasm(loc, instr.i_int);
299 * `Decode' and execute instruction.
302 if ((instr.i_any.i_opcd >= OPC_LFS && instr.i_any.i_opcd <= OPC_STFDU) ||
303 instr.i_any.i_opcd == OPC_integer_31) {
305 * Handle load/store insns:
307 * Convert to/from single if needed, calculate addr,
308 * and update index reg if needed.
311 size_t size = sizeof(float);
314 cond = 0; /* ld/st never set condition codes */
317 if (instr.i_any.i_opcd == OPC_integer_31) {
318 if (instr.i_x.i_xo == OPC31_STFIWX) {
319 FPU_EMU_EVCNT_INCR(stfiwx);
321 /* Store as integer */
325 ("reg %d has %jx reg %d has %jx\n",
326 ra, (uintmax_t)tf->fixreg[ra], rb,
327 (uintmax_t)tf->fixreg[rb]));
329 addr = tf->fixreg[rb];
331 addr += tf->fixreg[ra];
333 a = (int *)&fs->fpr[rt].fpr;
335 ("fpu_execute: Store INT %x at %p\n",
336 a[1], (void *)addr));
337 if (copyout(&a[1], (void *)addr, sizeof(int)))
342 if ((instr.i_x.i_xo & OPC31_FPMASK) != OPC31_FPOP)
343 /* Not an indexed FP load/store op */
346 store = (instr.i_x.i_xo & 0x80);
347 if (instr.i_x.i_xo & 0x40)
348 size = sizeof(double);
351 update = (instr.i_x.i_xo & 0x20);
353 /* calculate EA of load/store */
356 DPRINTF(FPE_INSN, ("reg %d has %jx reg %d has %jx\n",
357 ra, (uintmax_t)tf->fixreg[ra], rb,
358 (uintmax_t)tf->fixreg[rb]));
359 addr = tf->fixreg[rb];
361 addr += tf->fixreg[ra];
364 store = instr.i_d.i_opcd & 0x4;
365 if (instr.i_d.i_opcd & 0x2)
366 size = sizeof(double);
369 update = instr.i_d.i_opcd & 0x1;
371 /* calculate EA of load/store */
373 addr = instr.i_d.i_d;
374 DPRINTF(FPE_INSN, ("reg %d has %jx displ %jx\n",
375 ra, (uintmax_t)tf->fixreg[ra],
378 addr += tf->fixreg[ra];
382 if (update && ra == 0)
387 FPU_EMU_EVCNT_INCR(fpstore);
388 if (type != FTYPE_DBL) {
390 ("fpu_execute: Store SNG at %p\n",
392 fpu_explode(fe, fp = &fe->fe_f1, FTYPE_DBL, rt);
393 fpu_implode(fe, fp, type, (void *)&buf);
394 if (copyout(&buf, (void *)addr, size))
398 ("fpu_execute: Store DBL at %p\n",
400 if (copyout(&fs->fpr[rt].fpr, (void *)addr,
406 FPU_EMU_EVCNT_INCR(fpload);
407 DPRINTF(FPE_INSN, ("fpu_execute: Load from %p\n",
409 if (copyin((const void *)addr, &fs->fpr[rt].fpr,
412 if (type != FTYPE_DBL) {
413 fpu_explode(fe, fp = &fe->fe_f1, type, rt);
414 fpu_implode(fe, fp, FTYPE_DBL,
415 (u_int *)&fs->fpr[rt].fpr);
419 tf->fixreg[ra] = addr;
423 } else if (instr.i_any.i_opcd == OPC_load_st_62) {
424 /* These are 64-bit extensions */
427 } else if (instr.i_any.i_opcd == OPC_sp_fp_59 ||
428 instr.i_any.i_opcd == OPC_dp_fp_63) {
431 if (instr.i_any.i_opcd == OPC_dp_fp_63 &&
432 !(instr.i_a.i_xo & OPC63M_MASK)) {
439 /* One of the special opcodes.... */
440 switch (instr.i_x.i_xo) {
442 FPU_EMU_EVCNT_INCR(fcmpu);
443 DPRINTF(FPE_INSN, ("fpu_execute: FCMPU\n"));
445 fpu_explode(fe, &fe->fe_f1, type, ra);
446 fpu_explode(fe, &fe->fe_f2, type, rb);
448 /* Make sure we do the condition regs. */
450 /* N.B.: i_rs is already left shifted by two. */
451 bf = instr.i_x.i_rs & 0xfc;
459 * PowerPC uses this to round a double
460 * precision value to single precision,
461 * but values in registers are always
462 * stored in double precision format.
464 FPU_EMU_EVCNT_INCR(frsp);
465 DPRINTF(FPE_INSN, ("fpu_execute: FRSP\n"));
466 fpu_explode(fe, fp = &fe->fe_f1, FTYPE_DBL, rb);
467 fpu_implode(fe, fp, FTYPE_SNG,
468 (u_int *)&fs->fpr[rt].fpr);
469 fpu_explode(fe, fp = &fe->fe_f1, FTYPE_SNG, rt);
474 FPU_EMU_EVCNT_INCR(fctiw);
475 DPRINTF(FPE_INSN, ("fpu_execute: FCTIW\n"));
476 fpu_explode(fe, fp = &fe->fe_f1, type, rb);
480 FPU_EMU_EVCNT_INCR(fcmpo);
481 DPRINTF(FPE_INSN, ("fpu_execute: FCMPO\n"));
483 fpu_explode(fe, &fe->fe_f1, type, ra);
484 fpu_explode(fe, &fe->fe_f2, type, rb);
486 /* Make sure we do the condition regs. */
488 /* N.B.: i_rs is already left shifted by two. */
489 bf = instr.i_x.i_rs & 0xfc;
493 FPU_EMU_EVCNT_INCR(mtfsb1);
494 DPRINTF(FPE_INSN, ("fpu_execute: MTFSB1\n"));
496 (~(FPSCR_VX|FPSR_EX) & (1<<(31-rt)));
499 FPU_EMU_EVCNT_INCR(fnegabs);
500 DPRINTF(FPE_INSN, ("fpu_execute: FNEGABS\n"));
501 memcpy(&fs->fpr[rt].fpr, &fs->fpr[rb].fpr,
503 a = (int *)&fs->fpr[rt].fpr;
507 FPU_EMU_EVCNT_INCR(mcrfs);
508 DPRINTF(FPE_INSN, ("fpu_execute: MCRFS\n"));
512 /* Extract the bits we want */
513 mask = (fe->fe_fpscr >> (28 - ra)) & 0xf;
514 /* Clear the bits we copied. */
516 (FPSR_EX_MSK | (0xf << (28 - ra)));
517 fe->fe_fpscr &= fe->fe_cx;
518 /* Now shove them in the right part of cr */
519 tf->cr &= ~(0xf << (28 - rt));
520 tf->cr |= (mask << (28 - rt));
523 FPU_EMU_EVCNT_INCR(mtfsb0);
524 DPRINTF(FPE_INSN, ("fpu_execute: MTFSB0\n"));
526 ((FPSCR_VX|FPSR_EX) & ~(1<<(31-rt)));
529 FPU_EMU_EVCNT_INCR(fmr);
530 DPRINTF(FPE_INSN, ("fpu_execute: FMR\n"));
531 memcpy(&fs->fpr[rt].fpr, &fs->fpr[rb].fpr,
535 FPU_EMU_EVCNT_INCR(mtfsfi);
536 DPRINTF(FPE_INSN, ("fpu_execute: MTFSFI\n"));
538 rt &= 0x1c; /* Already left-shifted 4 */
539 fe->fe_cx = rb << (28 - rt);
540 mask = 0xf<<(28 - rt);
541 fe->fe_fpscr = (fe->fe_fpscr & ~mask) |
543 /* XXX weird stuff about OX, FX, FEX, and VX should be handled */
546 FPU_EMU_EVCNT_INCR(fnabs);
547 DPRINTF(FPE_INSN, ("fpu_execute: FABS\n"));
548 memcpy(&fs->fpr[rt].fpr, &fs->fpr[rb].fpr,
550 a = (int *)&fs->fpr[rt].fpr;
554 FPU_EMU_EVCNT_INCR(fabs);
555 DPRINTF(FPE_INSN, ("fpu_execute: FABS\n"));
556 memcpy(&fs->fpr[rt].fpr, &fs->fpr[rb].fpr,
558 a = (int *)&fs->fpr[rt].fpr;
562 FPU_EMU_EVCNT_INCR(mffs);
563 DPRINTF(FPE_INSN, ("fpu_execute: MFFS\n"));
564 memcpy(&fs->fpr[rt].fpr, &fs->fpscr,
568 FPU_EMU_EVCNT_INCR(mtfsf);
569 DPRINTF(FPE_INSN, ("fpu_execute: MTFSF\n"));
570 if ((rt = instr.i_xfl.i_flm) == -1)
574 /* Convert 1 bit -> 4 bits */
575 for (ra = 0; ra < 8; ra ++)
577 mask |= (0xf<<(4*ra));
579 a = (int *)&fs->fpr[rt].fpr;
580 fe->fe_cx = mask & a[1];
581 fe->fe_fpscr = (fe->fe_fpscr&~mask) |
583 /* XXX weird stuff about OX, FX, FEX, and VX should be handled */
587 FPU_EMU_EVCNT_INCR(fctid);
588 DPRINTF(FPE_INSN, ("fpu_execute: FCTID\n"));
589 fpu_explode(fe, fp = &fe->fe_f1, type, rb);
593 FPU_EMU_EVCNT_INCR(fcfid);
594 DPRINTF(FPE_INSN, ("fpu_execute: FCFID\n"));
596 fpu_explode(fe, fp = &fe->fe_f1, type, rb);
605 rt = instr.i_a.i_frt;
606 ra = instr.i_a.i_fra;
607 rb = instr.i_a.i_frb;
608 rc = instr.i_a.i_frc;
611 * All arithmetic operations work on registers, which
612 * are stored as doubles.
615 switch ((unsigned int)instr.i_a.i_xo) {
617 FPU_EMU_EVCNT_INCR(fdiv);
618 DPRINTF(FPE_INSN, ("fpu_execute: FDIV\n"));
619 fpu_explode(fe, &fe->fe_f1, type, ra);
620 fpu_explode(fe, &fe->fe_f2, type, rb);
624 FPU_EMU_EVCNT_INCR(fsub);
625 DPRINTF(FPE_INSN, ("fpu_execute: FSUB\n"));
626 fpu_explode(fe, &fe->fe_f1, type, ra);
627 fpu_explode(fe, &fe->fe_f2, type, rb);
631 FPU_EMU_EVCNT_INCR(fadd);
632 DPRINTF(FPE_INSN, ("fpu_execute: FADD\n"));
633 fpu_explode(fe, &fe->fe_f1, type, ra);
634 fpu_explode(fe, &fe->fe_f2, type, rb);
638 FPU_EMU_EVCNT_INCR(fsqrt);
639 DPRINTF(FPE_INSN, ("fpu_execute: FSQRT\n"));
640 fpu_explode(fe, &fe->fe_f1, type, rb);
644 FPU_EMU_EVCNT_INCR(fsel);
645 DPRINTF(FPE_INSN, ("fpu_execute: FSEL\n"));
646 a = (int *)&fe->fe_fpstate->fpr[ra].fpr;
647 if ((*a & 0x80000000) && (*a & 0x7fffffff))
650 DPRINTF(FPE_INSN, ("f%d => f%d\n", rc, rt));
651 memcpy(&fs->fpr[rt].fpr, &fs->fpr[rc].fpr,
655 FPU_EMU_EVCNT_INCR(fpres);
656 DPRINTF(FPE_INSN, ("fpu_execute: FPRES\n"));
657 fpu_explode(fe, &fe->fe_f1, type, rb);
659 /* now we've gotta overwrite the dest reg */
660 *((int *)&fe->fe_fpstate->fpr[rt].fpr) = 1;
661 fpu_explode(fe, &fe->fe_f1, FTYPE_INT, rt);
665 FPU_EMU_EVCNT_INCR(fmul);
666 DPRINTF(FPE_INSN, ("fpu_execute: FMUL\n"));
667 fpu_explode(fe, &fe->fe_f1, type, ra);
668 fpu_explode(fe, &fe->fe_f2, type, rc);
672 /* Reciprocal sqrt() estimate */
673 FPU_EMU_EVCNT_INCR(frsqrte);
674 DPRINTF(FPE_INSN, ("fpu_execute: FRSQRTE\n"));
675 fpu_explode(fe, &fe->fe_f1, type, rb);
678 /* now we've gotta overwrite the dest reg */
679 *((int *)&fe->fe_fpstate->fpr[rt].fpr) = 1;
680 fpu_explode(fe, &fe->fe_f1, FTYPE_INT, rt);
684 FPU_EMU_EVCNT_INCR(fmulsub);
685 DPRINTF(FPE_INSN, ("fpu_execute: FMULSUB\n"));
686 fpu_explode(fe, &fe->fe_f1, type, ra);
687 fpu_explode(fe, &fe->fe_f2, type, rc);
690 fpu_explode(fe, &fe->fe_f2, type, rb);
694 FPU_EMU_EVCNT_INCR(fmuladd);
695 DPRINTF(FPE_INSN, ("fpu_execute: FMULADD\n"));
696 fpu_explode(fe, &fe->fe_f1, type, ra);
697 fpu_explode(fe, &fe->fe_f2, type, rc);
700 fpu_explode(fe, &fe->fe_f2, type, rb);
704 FPU_EMU_EVCNT_INCR(fnmsub);
705 DPRINTF(FPE_INSN, ("fpu_execute: FNMSUB\n"));
706 fpu_explode(fe, &fe->fe_f1, type, ra);
707 fpu_explode(fe, &fe->fe_f2, type, rc);
710 fpu_explode(fe, &fe->fe_f2, type, rb);
716 FPU_EMU_EVCNT_INCR(fnmadd);
717 DPRINTF(FPE_INSN, ("fpu_execute: FNMADD\n"));
718 fpu_explode(fe, &fe->fe_f1, type, ra);
719 fpu_explode(fe, &fe->fe_f2, type, rc);
722 fpu_explode(fe, &fe->fe_f2, type, rb);
732 /* If the instruction was single precision, round */
733 if (!(instr.i_any.i_opcd & 0x4)) {
734 fpu_implode(fe, fp, FTYPE_SNG,
735 (u_int *)&fs->fpr[rt].fpr);
736 fpu_explode(fe, fp = &fe->fe_f1, FTYPE_SNG, rt);
744 * ALU operation is complete. Collapse the result and then check
745 * for exceptions. If we got any, and they are enabled, do not
746 * alter the destination register, just stop with an exception.
747 * Otherwise set new current exceptions and accrue.
750 fpu_implode(fe, fp, type, (u_int *)&fs->fpr[rt].fpr);
755 if ((cx^fsr)&FPSR_EX_MSK)
757 mask = fsr & FPSR_EX;
761 if (cx & FPSCR_FPRF) {
762 /* Need to replace CC */
765 if (cx & (FPSR_EXOP))
768 DPRINTF(FPE_INSN, ("fpu_execute: cx %x, fsr %x\n", cx, fsr));
772 cond = fsr & 0xf0000000;
773 /* Isolate condition codes */
775 /* Move fpu condition codes to cr[1] */
776 tf->cr &= (0x0f000000);
777 tf->cr |= (cond<<24);
778 DPRINTF(FPE_INSN, ("fpu_execute: cr[1] <= %x\n", cond));
782 cond = fsr & FPSCR_FPCC;
783 /* Isolate condition codes */
785 /* Move fpu condition codes to cr[1] */
786 tf->cr &= ~(0xf0000000>>bf);
787 tf->cr |= (cond>>bf);
788 DPRINTF(FPE_INSN, ("fpu_execute: cr[%d] (cr=%jx) <= %x\n",
789 bf/4, (uintmax_t)tf->cr, cond));
792 ((int *)&fs->fpscr)[1] = fsr;
795 return (0); /* success */