17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
5428cee1jfrank * Common Development and Distribution License (the "License").
6428cee1jfrank * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
217c478bdstevel@tonic-gate/*
228159a90Sree Vemuri * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bdstevel@tonic-gate * Use is subject to license terms.
247c478bdstevel@tonic-gate */
257c478bdstevel@tonic-gate
267c478bdstevel@tonic-gate/* VIS floating point instruction simulator for Sparc FPU simulator. */
277c478bdstevel@tonic-gate
287c478bdstevel@tonic-gate#include <sys/types.h>
297c478bdstevel@tonic-gate#include <sys/systm.h>
307c478bdstevel@tonic-gate#include <sys/fpu/fpusystm.h>
317c478bdstevel@tonic-gate#include <sys/fpu/fpu_simulator.h>
327c478bdstevel@tonic-gate#include <sys/vis_simulator.h>
337c478bdstevel@tonic-gate#include <sys/fpu/globals.h>
347c478bdstevel@tonic-gate#include <sys/privregs.h>
357c478bdstevel@tonic-gate#include <sys/sun4asi.h>
367c478bdstevel@tonic-gate#include <sys/machasi.h>
377c478bdstevel@tonic-gate#include <sys/debug.h>
387c478bdstevel@tonic-gate#include <sys/cpu_module.h>
397c478bdstevel@tonic-gate#include <sys/systm.h>
407c478bdstevel@tonic-gate
417c478bdstevel@tonic-gate#define	FPU_REG_FIELD uint32_reg	/* Coordinate with FPU_REGS_TYPE. */
427c478bdstevel@tonic-gate#define	FPU_DREG_FIELD uint64_reg	/* Coordinate with FPU_DREGS_TYPE. */
437c478bdstevel@tonic-gate#define	FPU_FSR_FIELD uint64_reg	/* Coordinate with V9_FPU_FSR_TYPE. */
447c478bdstevel@tonic-gate
45bfb7f38kalaiextern	uint_t	get_subcc_ccr(uint64_t, uint64_t);
46bfb7f38kalai
477c478bdstevel@tonic-gatestatic enum ftt_type vis_array(fp_simd_type *, vis_inst_type, struct regs *,
487c478bdstevel@tonic-gate				void *);
497c478bdstevel@tonic-gatestatic enum ftt_type vis_alignaddr(fp_simd_type *, vis_inst_type,
507c478bdstevel@tonic-gate				struct regs *, void *, kfpu_t *);
517c478bdstevel@tonic-gatestatic enum ftt_type vis_edge(fp_simd_type *, vis_inst_type, struct regs *,
527c478bdstevel@tonic-gate				void *);
537c478bdstevel@tonic-gatestatic enum ftt_type vis_faligndata(fp_simd_type *, fp_inst_type,
547c478bdstevel@tonic-gate				kfpu_t *);
557c478bdstevel@tonic-gatestatic enum ftt_type vis_bmask(fp_simd_type *, vis_inst_type, struct regs *,
567c478bdstevel@tonic-gate				void *, kfpu_t *);
577c478bdstevel@tonic-gatestatic enum ftt_type vis_bshuffle(fp_simd_type *, fp_inst_type,
587c478bdstevel@tonic-gate				kfpu_t *);
597c478bdstevel@tonic-gatestatic enum ftt_type vis_siam(fp_simd_type *, vis_inst_type, kfpu_t *);
607c478bdstevel@tonic-gatestatic enum ftt_type vis_fcmp(fp_simd_type *, vis_inst_type, struct regs *,
617c478bdstevel@tonic-gate				void *);
627c478bdstevel@tonic-gatestatic enum ftt_type vis_fmul(fp_simd_type *, vis_inst_type);
637c478bdstevel@tonic-gatestatic enum ftt_type vis_fpixel(fp_simd_type *, vis_inst_type, kfpu_t *);
647c478bdstevel@tonic-gatestatic enum ftt_type vis_fpaddsub(fp_simd_type *, vis_inst_type);
658159a90Sree Vemuristatic enum ftt_type vis_pdist(fp_simd_type *, fp_inst_type, struct regs *,
668159a90Sree Vemuri				void *, uint_t);
677c478bdstevel@tonic-gatestatic enum ftt_type vis_prtl_fst(fp_simd_type *, vis_inst_type, struct regs *,
687c478bdstevel@tonic-gate				void *, uint_t);
697c478bdstevel@tonic-gatestatic enum ftt_type vis_short_fls(fp_simd_type *, vis_inst_type,
707c478bdstevel@tonic-gate				struct regs *, void *, uint_t);
717c478bdstevel@tonic-gatestatic enum ftt_type vis_blk_fldst(fp_simd_type *, vis_inst_type,
727c478bdstevel@tonic-gate				struct regs *, void *, uint_t);
737c478bdstevel@tonic-gate
747c478bdstevel@tonic-gate/*
757c478bdstevel@tonic-gate * Simulator for VIS instructions with op3 == 0x36 that get fp_disabled
767c478bdstevel@tonic-gate * traps.
777c478bdstevel@tonic-gate */
787c478bdstevel@tonic-gateenum ftt_type
797c478bdstevel@tonic-gatevis_fpu_simulator(
807c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
817c478bdstevel@tonic-gate	fp_inst_type	pinst,	/* FPU instruction to simulate. */
827c478bdstevel@tonic-gate	struct regs	*pregs,	/* Pointer to PCB image of registers. */
837c478bdstevel@tonic-gate	void		*prw,	/* Pointer to locals and ins. */
847c478bdstevel@tonic-gate	kfpu_t		*fp)	/* Need to fp to access gsr reg */
857c478bdstevel@tonic-gate{
867c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
877c478bdstevel@tonic-gate	uint_t	us1, us2, usr;
887c478bdstevel@tonic-gate	uint64_t lus1, lus2, lusr;
897c478bdstevel@tonic-gate	enum ftt_type ftt = ftt_none;
907c478bdstevel@tonic-gate	union {
917c478bdstevel@tonic-gate		vis_inst_type	inst;
927c478bdstevel@tonic-gate		fp_inst_type	pinst;
937c478bdstevel@tonic-gate	} f;
947c478bdstevel@tonic-gate
957c478bdstevel@tonic-gate	ASSERT(USERMODE(pregs->r_tstate));
967c478bdstevel@tonic-gate	nrs1 = pinst.rs1;
977c478bdstevel@tonic-gate	nrs2 = pinst.rs2;
987c478bdstevel@tonic-gate	nrd = pinst.rd;
997c478bdstevel@tonic-gate	f.pinst = pinst;
1007c478bdstevel@tonic-gate	if ((f.inst.opf & 1) == 0) {		/* double precision */
1017c478bdstevel@tonic-gate		if ((nrs1 & 1) == 1) 		/* fix register encoding */
1027c478bdstevel@tonic-gate			nrs1 = (nrs1 & 0x1e) | 0x20;
1037c478bdstevel@tonic-gate		if ((nrs2 & 1) == 1)
1047c478bdstevel@tonic-gate			nrs2 = (nrs2 & 0x1e) | 0x20;
1057c478bdstevel@tonic-gate		if ((nrd & 1) == 1)
1067c478bdstevel@tonic-gate			nrd = (nrd & 0x1e) | 0x20;
1077c478bdstevel@tonic-gate	}
1087c478bdstevel@tonic-gate
1097c478bdstevel@tonic-gate	switch (f.inst.opf) {
1107c478bdstevel@tonic-gate		/* these instr's do not use fp regs */
1117c478bdstevel@tonic-gate	case edge8:
1127c478bdstevel@tonic-gate	case edge8l:
1137c478bdstevel@tonic-gate	case edge8n:
1147c478bdstevel@tonic-gate	case edge8ln:
1157c478bdstevel@tonic-gate	case edge16:
1167c478bdstevel@tonic-gate	case edge16l:
1177c478bdstevel@tonic-gate	case edge16n:
1187c478bdstevel@tonic-gate	case edge16ln:
1197c478bdstevel@tonic-gate	case edge32:
1207c478bdstevel@tonic-gate	case edge32l:
1217c478bdstevel@tonic-gate	case edge32n:
1227c478bdstevel@tonic-gate	case edge32ln:
1237c478bdstevel@tonic-gate		ftt = vis_edge(pfpsd, f.inst, pregs, prw);
1247c478bdstevel@tonic-gate		break;
1257c478bdstevel@tonic-gate	case array8:
1267c478bdstevel@tonic-gate	case array16:
1277c478bdstevel@tonic-gate	case array32:
1287c478bdstevel@tonic-gate		ftt = vis_array(pfpsd, f.inst, pregs, prw);
1297c478bdstevel@tonic-gate		break;
1307c478bdstevel@tonic-gate	case alignaddr:
1317c478bdstevel@tonic-gate	case alignaddrl:
1327c478bdstevel@tonic-gate		ftt = vis_alignaddr(pfpsd, f.inst, pregs, prw, fp);
1337c478bdstevel@tonic-gate		break;
1347c478bdstevel@tonic-gate	case bmask:
1357c478bdstevel@tonic-gate		ftt = vis_bmask(pfpsd, f.inst, pregs, prw, fp);
1367c478bdstevel@tonic-gate		break;
1377c478bdstevel@tonic-gate	case fcmple16:
1387c478bdstevel@tonic-gate	case fcmpne16:
1397c478bdstevel@tonic-gate	case fcmpgt16:
1407c478bdstevel@tonic-gate	case fcmpeq16:
1417c478bdstevel@tonic-gate	case fcmple32:
1427c478bdstevel@tonic-gate	case fcmpne32:
1437c478bdstevel@tonic-gate	case fcmpgt32:
1447c478bdstevel@tonic-gate	case fcmpeq32:
1457c478bdstevel@tonic-gate		ftt = vis_fcmp(pfpsd, f.inst, pregs, prw);
1467c478bdstevel@tonic-gate		break;
1477c478bdstevel@tonic-gate	case fmul8x16:
1487c478bdstevel@tonic-gate	case fmul8x16au:
1497c478bdstevel@tonic-gate	case fmul8x16al:
1507c478bdstevel@tonic-gate	case fmul8sux16:
1517c478bdstevel@tonic-gate	case fmul8ulx16:
1527c478bdstevel@tonic-gate	case fmuld8sux16:
1537c478bdstevel@tonic-gate	case fmuld8ulx16:
1547c478bdstevel@tonic-gate		ftt = vis_fmul(pfpsd, f.inst);
1557c478bdstevel@tonic-gate		break;
1567c478bdstevel@tonic-gate	case fpack16:
1577c478bdstevel@tonic-gate	case fpack32:
1587c478bdstevel@tonic-gate	case fpackfix:
1597c478bdstevel@tonic-gate	case fexpand:
1607c478bdstevel@tonic-gate	case fpmerge:
1617c478bdstevel@tonic-gate		ftt = vis_fpixel(pfpsd, f.inst, fp);
1627c478bdstevel@tonic-gate		break;
1637c478bdstevel@tonic-gate	case pdist:
1648159a90Sree Vemuri	case pdistn:
1658159a90Sree Vemuri		ftt = vis_pdist(pfpsd, pinst, pregs, prw, f.inst.opf);
1667c478bdstevel@tonic-gate		break;
1677c478bdstevel@tonic-gate	case faligndata:
1687c478bdstevel@tonic-gate		ftt = vis_faligndata(pfpsd, pinst, fp);
1697c478bdstevel@tonic-gate		break;
1707c478bdstevel@tonic-gate	case bshuffle:
1717c478bdstevel@tonic-gate		ftt = vis_bshuffle(pfpsd, pinst, fp);
1727c478bdstevel@tonic-gate		break;
1737c478bdstevel@tonic-gate	case fpadd16:
1747c478bdstevel@tonic-gate	case fpadd16s:
1757c478bdstevel@tonic-gate	case fpadd32:
1767c478bdstevel@tonic-gate	case fpadd32s:
1777c478bdstevel@tonic-gate	case fpsub16:
1787c478bdstevel@tonic-gate	case fpsub16s:
1797c478bdstevel@tonic-gate	case fpsub32:
1807c478bdstevel@tonic-gate	case fpsub32s:
1817c478bdstevel@tonic-gate		ftt = vis_fpaddsub(pfpsd, f.inst);
1827c478bdstevel@tonic-gate		break;
1837c478bdstevel@tonic-gate	case fzero:
1847c478bdstevel@tonic-gate		lusr = 0;
1857c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
1867c478bdstevel@tonic-gate		break;
1877c478bdstevel@tonic-gate	case fzeros:
1887c478bdstevel@tonic-gate		usr = 0;
1897c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
1907c478bdstevel@tonic-gate		break;
1917c478bdstevel@tonic-gate	case fnor:
1927c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus1, nrs1);
1937c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus2, nrs2);
1947c478bdstevel@tonic-gate		lusr = ~(lus1 | lus2);
1957c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
1967c478bdstevel@tonic-gate		break;
1977c478bdstevel@tonic-gate	case fnors:
1987c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us1, nrs1);
1997c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us2, nrs2);
2007c478bdstevel@tonic-gate		usr = ~(us1 | us2);
2017c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
2027c478bdstevel@tonic-gate		break;
2037c478bdstevel@tonic-gate	case fandnot2:
2047c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2057c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2067c478bdstevel@tonic-gate		lusr = (lus1 & ~lus2);
2077c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
2087c478bdstevel@tonic-gate		break;
2097c478bdstevel@tonic-gate	case fandnot2s:
2107c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us1, nrs1);
2117c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us2, nrs2);
2127c478bdstevel@tonic-gate		usr = (us1 & ~us2);
2137c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
2147c478bdstevel@tonic-gate		break;
2157c478bdstevel@tonic-gate	case fnot2:
2167c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2177c478bdstevel@tonic-gate		lusr = ~lus2;
2187c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
2197c478bdstevel@tonic-gate		break;
2207c478bdstevel@tonic-gate	case fnot2s:
2217c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us2, nrs2);
2227c478bdstevel@tonic-gate		usr = ~us2;
2237c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
2247c478bdstevel@tonic-gate		break;
2257c478bdstevel@tonic-gate	case fandnot1:
2267c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2277c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2287c478bdstevel@tonic-gate		lusr = (~lus1 & lus2);
2297c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
2307c478bdstevel@tonic-gate		break;
2317c478bdstevel@tonic-gate	case fandnot1s:
2327c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us1, nrs1);
2337c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us2, nrs2);
2347c478bdstevel@tonic-gate		usr = (~us1 & us2);
2357c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
2367c478bdstevel@tonic-gate		break;
2377c478bdstevel@tonic-gate	case fnot1:
2387c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2397c478bdstevel@tonic-gate		lusr = ~lus1;
2407c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
2417c478bdstevel@tonic-gate		break;
2427c478bdstevel@tonic-gate	case fnot1s:
2437c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us1, nrs1);
2447c478bdstevel@tonic-gate		usr = ~us1;
2457c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
2467c478bdstevel@tonic-gate		break;
2477c478bdstevel@tonic-gate	case fxor:
2487c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2497c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2507c478bdstevel@tonic-gate		lusr = (lus1 ^ lus2);
2517c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
2527c478bdstevel@tonic-gate		break;
2537c478bdstevel@tonic-gate	case fxors:
2547c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us1, nrs1);
2557c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us2, nrs2);
2567c478bdstevel@tonic-gate		usr = (us1 ^ us2);
2577c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
2587c478bdstevel@tonic-gate		break;
2597c478bdstevel@tonic-gate	case fnand:
2607c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2617c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2627c478bdstevel@tonic-gate		lusr = ~(lus1 & lus2);
2637c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
2647c478bdstevel@tonic-gate		break;
2657c478bdstevel@tonic-gate	case fnands:
2667c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us1, nrs1);
2677c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us2, nrs2);
2687c478bdstevel@tonic-gate		usr = ~(us1 & us2);
2697c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
2707c478bdstevel@tonic-gate		break;
2717c478bdstevel@tonic-gate	case fand:
2727c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2737c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2747c478bdstevel@tonic-gate		lusr = (lus1 & lus2);
2757c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
2767c478bdstevel@tonic-gate		break;
2777c478bdstevel@tonic-gate	case fands:
2787c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us1, nrs1);
2797c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us2, nrs2);
2807c478bdstevel@tonic-gate		usr = (us1 & us2);
2817c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
2827c478bdstevel@tonic-gate		break;
2837c478bdstevel@tonic-gate	case fxnor:
2847c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2857c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2867c478bdstevel@tonic-gate		lusr = ~(lus1 ^ lus2);
2877c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
2887c478bdstevel@tonic-gate		break;
2897c478bdstevel@tonic-gate	case fxnors:
2907c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us1, nrs1);
2917c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us2, nrs2);
2927c478bdstevel@tonic-gate		usr = ~(us1 ^ us2);
2937c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
2947c478bdstevel@tonic-gate		break;
2957c478bdstevel@tonic-gate	case fsrc1:
2967c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lusr, nrs1);
2977c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
2987c478bdstevel@tonic-gate		break;
2997c478bdstevel@tonic-gate	case fsrc1s:
3007c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &usr, nrs1);
3017c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
3027c478bdstevel@tonic-gate		break;
3037c478bdstevel@tonic-gate	case fornot2:
3047c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus1, nrs1);
3057c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus2, nrs2);
3067c478bdstevel@tonic-gate		lusr = (lus1 | ~lus2);
3077c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
3087c478bdstevel@tonic-gate		break;
3097c478bdstevel@tonic-gate	case fornot2s:
3107c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us1, nrs1);
3117c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us2, nrs2);
3127c478bdstevel@tonic-gate		usr = (us1 | ~us2);
3137c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
3147c478bdstevel@tonic-gate		break;
3157c478bdstevel@tonic-gate	case fsrc2:
3167c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lusr, nrs2);
3177c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
3187c478bdstevel@tonic-gate		break;
3197c478bdstevel@tonic-gate	case fsrc2s:
3207c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &usr, nrs2);
3217c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
3227c478bdstevel@tonic-gate		break;
3237c478bdstevel@tonic-gate	case fornot1:
3247c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus1, nrs1);
3257c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus2, nrs2);
3267c478bdstevel@tonic-gate		lusr = (~lus1 | lus2);
3277c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
3287c478bdstevel@tonic-gate		break;
3297c478bdstevel@tonic-gate	case fornot1s:
3307c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us1, nrs1);
3317c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us2, nrs2);
3327c478bdstevel@tonic-gate		usr = (~us1 | us2);
3337c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
3347c478bdstevel@tonic-gate		break;
3357c478bdstevel@tonic-gate	case for_op:
3367c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus1, nrs1);
3377c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lus2, nrs2);
3387c478bdstevel@tonic-gate		lusr = (lus1 | lus2);
3397c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
3407c478bdstevel@tonic-gate		break;
3417c478bdstevel@tonic-gate	case fors_op:
3427c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us1, nrs1);
3437c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &us2, nrs2);
3447c478bdstevel@tonic-gate		usr = (us1 | us2);
3457c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
3467c478bdstevel@tonic-gate		break;
3477c478bdstevel@tonic-gate	case fone:
3487c478bdstevel@tonic-gate		lusr = 0xffffffffffffffff;
3497c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lusr, nrd);
3507c478bdstevel@tonic-gate		break;
3517c478bdstevel@tonic-gate	case fones:
3527c478bdstevel@tonic-gate		usr = 0xffffffffUL;
3537c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &usr, nrd);
3547c478bdstevel@tonic-gate		break;
3557c478bdstevel@tonic-gate	case siam:
3567c478bdstevel@tonic-gate		ftt = vis_siam(pfpsd, f.inst, fp);
3577c478bdstevel@tonic-gate		break;
3587c478bdstevel@tonic-gate	default:
3597c478bdstevel@tonic-gate		return (ftt_unimplemented);
3607c478bdstevel@tonic-gate	}
3617c478bdstevel@tonic-gate
3627c478bdstevel@tonic-gate	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
3637c478bdstevel@tonic-gate	pregs->r_npc += 4;
3647c478bdstevel@tonic-gate	return (ftt);
3657c478bdstevel@tonic-gate}
3667c478bdstevel@tonic-gate
3677c478bdstevel@tonic-gate/*
3687c478bdstevel@tonic-gate * Simulator for edge instructions
3697c478bdstevel@tonic-gate */
3707c478bdstevel@tonic-gatestatic enum ftt_type
3717c478bdstevel@tonic-gatevis_edge(
3727c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
3737c478bdstevel@tonic-gate	vis_inst_type	inst,	/* FPU instruction to simulate. */
3747c478bdstevel@tonic-gate	struct regs	*pregs,	/* Pointer to PCB image of registers. */
3757c478bdstevel@tonic-gate	void		*prw)	/* Pointer to locals and ins. */
3767c478bdstevel@tonic-gate
3777c478bdstevel@tonic-gate{
3787c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
3797c478bdstevel@tonic-gate	enum ftt_type ftt;
3807c478bdstevel@tonic-gate	uint64_t addrl, addrr, mask;
3817c478bdstevel@tonic-gate	uint64_t ah61l, ah61r;		/* Higher 61 bits of address */
3827c478bdstevel@tonic-gate	int al3l, al3r;			/* Lower 3 bits of address */
383bfb7f38kalai	uint_t	ccr;
3847c478bdstevel@tonic-gate
3857c478bdstevel@tonic-gate	nrs1 = inst.rs1;
3867c478bdstevel@tonic-gate	nrs2 = inst.rs2;
3877c478bdstevel@tonic-gate	nrd = inst.rd;
3887c478bdstevel@tonic-gate
3897c478bdstevel@tonic-gate	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &addrl);
3907c478bdstevel@tonic-gate	if (ftt != ftt_none)
3917c478bdstevel@tonic-gate		return (ftt);
3927c478bdstevel@tonic-gate	ftt = read_iureg(pfpsd, nrs2, pregs, prw, &addrr);
3937c478bdstevel@tonic-gate	if (ftt != ftt_none)
3947c478bdstevel@tonic-gate		return (ftt);
3957c478bdstevel@tonic-gate
396b1b05f9arutz	/* Test PSTATE.AM to determine 32-bit vs 64-bit addressing */
397b1b05f9arutz	if ((pregs->r_tstate & TSTATE_AM) != 0) {
398b1b05f9arutz		ah61l = addrl & 0xfffffff8;
399b1b05f9arutz		ah61r = addrr & 0xfffffff8;
4007c478bdstevel@tonic-gate	} else {
4017c478bdstevel@tonic-gate		ah61l = addrl & ~0x7;
4027c478bdstevel@tonic-gate		ah61r = addrr & ~0x7;
4037c478bdstevel@tonic-gate	}
4047c478bdstevel@tonic-gate
4057c478bdstevel@tonic-gate
4067c478bdstevel@tonic-gate	switch (inst.opf) {
4077c478bdstevel@tonic-gate	case edge8:
4087c478bdstevel@tonic-gate	case edge8n:
4097c478bdstevel@tonic-gate	case edge8l:
4107c478bdstevel@tonic-gate	case edge8ln:
4117c478bdstevel@tonic-gate		al3l = addrl & 0x7;
4127c478bdstevel@tonic-gate		switch (inst.opf) {
4137c478bdstevel@tonic-gate		case edge8:
4147c478bdstevel@tonic-gate		case edge8n:
4157c478bdstevel@tonic-gate			if (inst.opf == edge8) {
4167c478bdstevel@tonic-gate				VISINFO_KSTAT(vis_edge8);
4177c478bdstevel@tonic-gate			} else {
4187c478bdstevel@tonic-gate				VISINFO_KSTAT(vis_edge8n);
4197c478bdstevel@tonic-gate			}
4205892374df			mask = 0xff >> al3l;
4217c478bdstevel@tonic-gate			if (ah61l == ah61r) {
4227c478bdstevel@tonic-gate				al3r = addrr & 0x7;
4235892374df				mask &= (0xff << (0x7 - al3r)) & 0xff;
4247c478bdstevel@tonic-gate			}
4257c478bdstevel@tonic-gate			break;
4267c478bdstevel@tonic-gate		case edge8l:
4277c478bdstevel@tonic-gate		case edge8ln:
4287c478bdstevel@tonic-gate			if (inst.opf == edge8l) {
4297c478bdstevel@tonic-gate				VISINFO_KSTAT(vis_edge8l);
4307c478bdstevel@tonic-gate			} else {
4317c478bdstevel@tonic-gate				VISINFO_KSTAT(vis_edge8ln);
4327c478bdstevel@tonic-gate			}
4335892374df			mask = (0xff << al3l) & 0xff;
4347c478bdstevel@tonic-gate			if (ah61l == ah61r) {
4357c478bdstevel@tonic-gate				al3r = addrr & 0x7;
4365892374df				mask &= 0xff >> (0x7 - al3r);
4377c478bdstevel@tonic-gate			}
4387c478bdstevel@tonic-gate			break;
4397c478bdstevel@tonic-gate		}
4407c478bdstevel@tonic-gate		break;
4417c478bdstevel@tonic-gate	case edge16:
4427c478bdstevel@tonic-gate	case edge16l:
4437c478bdstevel@tonic-gate	case edge16n:
4447c478bdstevel@tonic-gate	case edge16ln:
4457c478bdstevel@tonic-gate		al3l = addrl & 0x6;
4465892374df		al3l >>= 0x1;
4477c478bdstevel@tonic-gate		switch (inst.opf) {
4487c478bdstevel@tonic-gate		case edge16:
4497c478bdstevel@tonic-gate		case edge16n:
4507c478bdstevel@tonic-gate			if (inst.opf == edge16) {
4517c478bdstevel@tonic-gate				VISINFO_KSTAT(vis_edge16);
4527c478bdstevel@tonic-gate
4537c478bdstevel@tonic-gate			} else {
4547c478bdstevel@tonic-gate				VISINFO_KSTAT(vis_edge16n);
4557c478bdstevel@tonic-gate			}
4565892374df			mask = 0xf >> al3l;
4577c478bdstevel@tonic-gate			if (ah61l == ah61r) {
4587c478bdstevel@tonic-gate				al3r = addrr & 0x6;
4595892374df				al3r >>= 0x1;
4605892374df				mask &= (0xf << (0x3 - al3r)) & 0xf;
4617c478bdstevel@tonic-gate			}
4627c478bdstevel@tonic-gate			break;
4637c478bdstevel@tonic-gate		case edge16l:
4647c478bdstevel@tonic-gate		case edge16ln:
4657c478bdstevel@tonic-gate			if (inst.opf == edge16l) {
4667c478bdstevel@tonic-gate				VISINFO_KSTAT(vis_edge16l);
4677c478bdstevel@tonic-gate
4687c478bdstevel@tonic-gate			} else {
4697c478bdstevel@tonic-gate				VISINFO_KSTAT(vis_edge16ln);
4707c478bdstevel@tonic-gate			}
4715892374df
4725892374df			mask = (0xf << al3l) & 0xf;
4737c478bdstevel@tonic-gate			if (ah61l == ah61r) {
4747c478bdstevel@tonic-gate				al3r = addrr & 0x6;
4755892374df				al3r >>= 0x1;
4765892374df				mask &= 0xf >> (0x3 - al3r);
4777c478bdstevel@tonic-gate			}
4787c478bdstevel@tonic-gate			break;
4797c478bdstevel@tonic-gate		}
4807c478bdstevel@tonic-gate		break;
4817c478bdstevel@tonic-gate	case edge32:
4827c478bdstevel@tonic-gate	case edge32l:
4837c478bdstevel@tonic-gate	case edge32n:
4847c478bdstevel@tonic-gate	case edge32ln:
4857c478bdstevel@tonic-gate		al3l = addrl & 0x4;
4865892374df		al3l >>= 0x2;
4875892374df
4887c478bdstevel@tonic-gate		switch (inst.opf) {
4897c478bdstevel@tonic-gate		case edge32:
4907c478bdstevel@tonic-gate		case edge32n:
4917c478bdstevel@tonic-gate			if (inst.opf == edge32) {
4927c478bdstevel@tonic-gate				VISINFO_KSTAT(vis_edge32);
4937c478bdstevel@tonic-gate
4947c478bdstevel@tonic-gate			} else {
4957c478bdstevel@tonic-gate				VISINFO_KSTAT(vis_edge32n);
4967c478bdstevel@tonic-gate			}
4975892374df			mask = 0x3 >> al3l;
4987c478bdstevel@tonic-gate			if (ah61l == ah61r) {
4997c478bdstevel@tonic-gate				al3r = addrr & 0x4;
5005892374df				al3r >>= 0x2;
5015892374df				mask &= (0x3 << (0x1 - al3r)) & 0x3;
5027c478bdstevel@tonic-gate			}
5037c478bdstevel@tonic-gate			break;
5047c478bdstevel@tonic-gate		case edge32l:
5057c478bdstevel@tonic-gate		case edge32ln:
5067c478bdstevel@tonic-gate			if (inst.opf == edge32l) {
5077c478bdstevel@tonic-gate				VISINFO_KSTAT(vis_edge32l);
5087c478bdstevel@tonic-gate
5097c478bdstevel@tonic-gate			} else {
5107c478bdstevel@tonic-gate				VISINFO_KSTAT(vis_edge32ln);
5117c478bdstevel@tonic-gate			}
5125892374df			mask = (0x3 << al3l) & 0x3;
5137c478bdstevel@tonic-gate			if (ah61l == ah61r) {
5147c478bdstevel@tonic-gate				al3r = addrr & 0x4;
5155892374df				al3r >>= 0x2;
5165892374df				mask &= 0x3 >> (0x1 - al3r);
5177c478bdstevel@tonic-gate			}
5187c478bdstevel@tonic-gate			break;
5197c478bdstevel@tonic-gate		}
5207c478bdstevel@tonic-gate		break;
5217c478bdstevel@tonic-gate	}
5225892374df
5237c478bdstevel@tonic-gate	ftt = write_iureg(pfpsd, nrd, pregs, prw, &mask);
5247c478bdstevel@tonic-gate
5257c478bdstevel@tonic-gate	switch (inst.opf) {
5267c478bdstevel@tonic-gate	case edge8:
5277c478bdstevel@tonic-gate	case edge8l:
5287c478bdstevel@tonic-gate	case edge16:
5297c478bdstevel@tonic-gate	case edge16l:
5307c478bdstevel@tonic-gate	case edge32:
5317c478bdstevel@tonic-gate	case edge32l:
5327c478bdstevel@tonic-gate
533bfb7f38kalai		/* Update flags per SUBcc outcome */
534bfb7f38kalai		pregs->r_tstate &= ~((uint64_t)TSTATE_CCR_MASK
535bfb7f38kalai					<< TSTATE_CCR_SHIFT);
536bfb7f38kalai		ccr = get_subcc_ccr(addrl, addrr);  /* get subcc cond. codes */
537bfb7f38kalai		pregs->r_tstate |= ((uint64_t)ccr << TSTATE_CCR_SHIFT);
538bfb7f38kalai
5397c478bdstevel@tonic-gate		break;
5407c478bdstevel@tonic-gate	}
5417c478bdstevel@tonic-gate	return (ftt);
542bfb7f38kalai}
543bfb7f38kalai
5447c478bdstevel@tonic-gate/*
5457c478bdstevel@tonic-gate * Simulator for three dimentional array addressing instructions.
5467c478bdstevel@tonic-gate */
5477c478bdstevel@tonic-gatestatic enum ftt_type
5487c478bdstevel@tonic-gatevis_array(
5497c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
5507c478bdstevel@tonic-gate	vis_inst_type	inst,	/* FPU instruction to simulate. */
5517c478bdstevel@tonic-gate	struct regs	*pregs,	/* Pointer to PCB image of registers. */
5527c478bdstevel@tonic-gate	void		*prw)	/* Pointer to locals and ins. */
5537c478bdstevel@tonic-gate
5547c478bdstevel@tonic-gate{
5557c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
5567c478bdstevel@tonic-gate	enum ftt_type ftt;
5577c478bdstevel@tonic-gate	uint64_t laddr, bsize, baddr;
5587c478bdstevel@tonic-gate	uint64_t nbit;
5597c478bdstevel@tonic-gate	int oy, oz;
5607c478bdstevel@tonic-gate
5617c478bdstevel@tonic-gate	nrs1 = inst.rs1;
5627c478bdstevel@tonic-gate	nrs2 = inst.rs2;
5637c478bdstevel@tonic-gate	nrd = inst.rd;
5647c478bdstevel@tonic-gate
5657c478bdstevel@tonic-gate	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &laddr);
5667c478bdstevel@tonic-gate	if (ftt != ftt_none)
5677c478bdstevel@tonic-gate		return (ftt);
5687c478bdstevel@tonic-gate	ftt = read_iureg(pfpsd, nrs2, pregs, prw, &bsize);
5697c478bdstevel@tonic-gate	if (ftt != ftt_none)
5707c478bdstevel@tonic-gate		return (ftt);
5717c478bdstevel@tonic-gate
5727c478bdstevel@tonic-gate	if (bsize > 5) {
5737c478bdstevel@tonic-gate		bsize = 5;
5747c478bdstevel@tonic-gate	}
5757c478bdstevel@tonic-gate	nbit = (1 << bsize) - 1;	/* Number of bits for XY<6+n-1:6> */
5767c478bdstevel@tonic-gate	oy = 17 + bsize;		/* Offset of Y<6+n-1:6> */
5777c478bdstevel@tonic-gate	oz = 17 + 2 * bsize;		/* Offset of Z<8:5> */
5787c478bdstevel@tonic-gate
5797c478bdstevel@tonic-gate	baddr = 0;
5807c478bdstevel@tonic-gate	baddr |= (laddr >> (11 -  0)) & (0x03 <<  0);	/* X_integer<1:0> */
5817c478bdstevel@tonic-gate	baddr |= (laddr >> (33 -  2)) & (0x03 <<  2);	/* Y_integer<1:0> */
5827c478bdstevel@tonic-gate	baddr |= (laddr >> (55 -  4)) & (0x01 <<  4);	/* Z_integer<0>   */
5837c478bdstevel@tonic-gate	baddr |= (laddr >> (13 -  5)) & (0x0f <<  5);	/* X_integer<5:2> */
5847c478bdstevel@tonic-gate	baddr |= (laddr >> (35 -  9)) & (0x0f <<  9);	/* Y_integer<5:2> */
5857c478bdstevel@tonic-gate	baddr |= (laddr >> (56 - 13)) & (0x0f << 13);	/* Z_integer<4:1> */
5867c478bdstevel@tonic-gate	baddr |= (laddr >> (17 - 17)) & (nbit << 17);	/* X_integer<6+n-1:6> */
5877c478bdstevel@tonic-gate	baddr |= (laddr >> (39 - oy)) & (nbit << oy);	/* Y_integer<6+n-1:6> */
5887c478bdstevel@tonic-gate	baddr |= (laddr >> (60 - oz)) & (0x0f << oz);	/* Z_integer<8:5> */
5897c478bdstevel@tonic-gate
5907c478bdstevel@tonic-gate	switch (inst.opf) {
5917c478bdstevel@tonic-gate	case array8:
5927c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_array8);
5937c478bdstevel@tonic-gate		break;
5947c478bdstevel@tonic-gate	case array16:
5957c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_array16);
5967c478bdstevel@tonic-gate		baddr <<= 1;
5977c478bdstevel@tonic-gate		break;
5987c478bdstevel@tonic-gate	case array32:
5997c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_array32);
6007c478bdstevel@tonic-gate		baddr <<= 2;
6017c478bdstevel@tonic-gate		break;
6027c478bdstevel@tonic-gate	}
6037c478bdstevel@tonic-gate
6047c478bdstevel@tonic-gate	ftt = write_iureg(pfpsd, nrd, pregs, prw, &baddr);
6057c478bdstevel@tonic-gate
6067c478bdstevel@tonic-gate	return (ftt);
6077c478bdstevel@tonic-gate}
6087c478bdstevel@tonic-gate
6097c478bdstevel@tonic-gate/*
6107c478bdstevel@tonic-gate * Simulator for alignaddr and alignaddrl instructions.
6117c478bdstevel@tonic-gate */
6127c478bdstevel@tonic-gatestatic enum ftt_type
6137c478bdstevel@tonic-gatevis_alignaddr(
6147c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
6157c478bdstevel@tonic-gate	vis_inst_type	inst,	/* FPU instruction to simulate. */
6167c478bdstevel@tonic-gate	struct regs	*pregs,	/* Pointer to PCB image of registers. */
6177c478bdstevel@tonic-gate	void		*prw,	/* Pointer to locals and ins. */
6187c478bdstevel@tonic-gate	kfpu_t		*fp)	/* Need to fp to access gsr reg */
6197c478bdstevel@tonic-gate{
6207c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
6217c478bdstevel@tonic-gate	enum ftt_type ftt;
6227c478bdstevel@tonic-gate	uint64_t ea, tea, g, r;
6237c478bdstevel@tonic-gate	short s;
6247c478bdstevel@tonic-gate
6257c478bdstevel@tonic-gate	nrs1 = inst.rs1;
6267c478bdstevel@tonic-gate	nrs2 = inst.rs2;
6277c478bdstevel@tonic-gate	nrd = inst.rd;
6287c478bdstevel@tonic-gate
6297c478bdstevel@tonic-gate	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
6307c478bdstevel@tonic-gate	if (ftt != ftt_none)
6317c478bdstevel@tonic-gate		return (ftt);
6327c478bdstevel@tonic-gate	ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tea);
6337c478bdstevel@tonic-gate	if (ftt != ftt_none)
6347c478bdstevel@tonic-gate		return (ftt);
6357c478bdstevel@tonic-gate	ea += tea;
6367c478bdstevel@tonic-gate	r = ea & ~0x7;	/* zero least 3 significant bits */
6377c478bdstevel@tonic-gate	ftt = write_iureg(pfpsd, nrd, pregs, prw, &r);
6387c478bdstevel@tonic-gate
6397c478bdstevel@tonic-gate
6405892374df	g = pfpsd->fp_current_read_gsr(fp);
6417c478bdstevel@tonic-gate	g &= ~(GSR_ALIGN_MASK);		/* zero the align offset */
6427c478bdstevel@tonic-gate	r = ea & 0x7;
6437c478bdstevel@tonic-gate	if (inst.opf == alignaddrl) {
6447c478bdstevel@tonic-gate		s = (short)(~r);	/* 2's complement for alignaddrl */
6457c478bdstevel@tonic-gate		if (s < 0)
6467c478bdstevel@tonic-gate			r = (uint64_t)((s + 1) & 0x7);
6477c478bdstevel@tonic-gate		else
6487c478bdstevel@tonic-gate			r = (uint64_t)(s & 0x7);
6497c478bdstevel@tonic-gate	}
6507c478bdstevel@tonic-gate	g |= (r << GSR_ALIGN_SHIFT) & GSR_ALIGN_MASK;
6515892374df	pfpsd->fp_current_write_gsr(g, fp);
6527c478bdstevel@tonic-gate
6537c478bdstevel@tonic-gate	return (ftt);
6547c478bdstevel@tonic-gate}
6557c478bdstevel@tonic-gate
6567c478bdstevel@tonic-gate/*
6577c478bdstevel@tonic-gate * Simulator for bmask instruction.
6587c478bdstevel@tonic-gate */
6597c478bdstevel@tonic-gatestatic enum ftt_type
6607c478bdstevel@tonic-gatevis_bmask(
6617c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
6627c478bdstevel@tonic-gate	vis_inst_type	inst,	/* FPU instruction to simulate. */
6637c478bdstevel@tonic-gate	struct regs	*pregs,	/* Pointer to PCB image of registers. */
6647c478bdstevel@tonic-gate	void		*prw,	/* Pointer to locals and ins. */
6657c478bdstevel@tonic-gate	kfpu_t		*fp)	/* Need to fp to access gsr reg */
6667c478bdstevel@tonic-gate{
6677c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
6687c478bdstevel@tonic-gate	enum ftt_type ftt;
6697c478bdstevel@tonic-gate	uint64_t ea, tea, g;
6707c478bdstevel@tonic-gate
6717c478bdstevel@tonic-gate	VISINFO_KSTAT(vis_bmask);
6727c478bdstevel@tonic-gate	nrs1 = inst.rs1;
6737c478bdstevel@tonic-gate	nrs2 = inst.rs2;
6747c478bdstevel@tonic-gate	nrd = inst.rd;
6757c478bdstevel@tonic-gate
6767c478bdstevel@tonic-gate	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
6777c478bdstevel@tonic-gate	if (ftt != ftt_none)
6787c478bdstevel@tonic-gate		return (ftt);
6797c478bdstevel@tonic-gate	ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tea);
6807c478bdstevel@tonic-gate	if (ftt != ftt_none)
6817c478bdstevel@tonic-gate		return (ftt);
6827c478bdstevel@tonic-gate	ea += tea;
6837c478bdstevel@tonic-gate	ftt = write_iureg(pfpsd, nrd, pregs, prw, &ea);
6847c478bdstevel@tonic-gate
6855892374df	g = pfpsd->fp_current_read_gsr(fp);
6867c478bdstevel@tonic-gate	g &= ~(GSR_MASK_MASK);		/* zero the mask offset */
6877c478bdstevel@tonic-gate
6887c478bdstevel@tonic-gate	/* Put the least significant 32 bits of ea in GSR.mask */
6897c478bdstevel@tonic-gate	g |= (ea << GSR_MASK_SHIFT) & GSR_MASK_MASK;
6905892374df	pfpsd->fp_current_write_gsr(g, fp);
6917c478bdstevel@tonic-gate	return (ftt);
6927c478bdstevel@tonic-gate}
6937c478bdstevel@tonic-gate
6947c478bdstevel@tonic-gate/*
6957c478bdstevel@tonic-gate * Simulator for fp[add|sub]* instruction.
6967c478bdstevel@tonic-gate */
6977c478bdstevel@tonic-gatestatic enum ftt_type
6987c478bdstevel@tonic-gatevis_fpaddsub(
6997c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
7007c478bdstevel@tonic-gate	vis_inst_type	inst)	/* FPU instruction to simulate. */
7017c478bdstevel@tonic-gate{
7027c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
7037c478bdstevel@tonic-gate	union {
7047c478bdstevel@tonic-gate		uint64_t	ll;
7057c478bdstevel@tonic-gate		uint32_t	i[2];
7067c478bdstevel@tonic-gate		uint16_t	s[4];
7077c478bdstevel@tonic-gate	} lrs1, lrs2, lrd;
7087c478bdstevel@tonic-gate	union {
7097c478bdstevel@tonic-gate		uint32_t	i;
7107c478bdstevel@tonic-gate		uint16_t	s[2];
7117c478bdstevel@tonic-gate	} krs1, krs2, krd;
7127c478bdstevel@tonic-gate	int i;
7137c478bdstevel@tonic-gate
7147c478bdstevel@tonic-gate	nrs1 = inst.rs1;
7157c478bdstevel@tonic-gate	nrs2 = inst.rs2;
7167c478bdstevel@tonic-gate	nrd = inst.rd;
7177c478bdstevel@tonic-gate	if ((inst.opf & 1) == 0) {	/* double precision */
7187c478bdstevel@tonic-gate		if ((nrs1 & 1) == 1) 	/* fix register encoding */
7197c478bdstevel@tonic-gate			nrs1 = (nrs1 & 0x1e) | 0x20;
7207c478bdstevel@tonic-gate		if ((nrs2 & 1) == 1)
7217c478bdstevel@tonic-gate			nrs2 = (nrs2 & 0x1e) | 0x20;
7227c478bdstevel@tonic-gate		if ((nrd & 1) == 1)
7237c478bdstevel@tonic-gate			nrd = (nrd & 0x1e) | 0x20;
7247c478bdstevel@tonic-gate	}
7257c478bdstevel@tonic-gate	switch (inst.opf) {
7267c478bdstevel@tonic-gate	case fpadd16:
7277c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
7287c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
7297c478bdstevel@tonic-gate		for (i = 0; i <= 3; i++) {
7307c478bdstevel@tonic-gate			lrd.s[i] = lrs1.s[i] + lrs2.s[i];
7317c478bdstevel@tonic-gate		}
7327c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
7337c478bdstevel@tonic-gate		break;
7347c478bdstevel@tonic-gate	case fpadd16s:
7357c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
7367c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
7377c478bdstevel@tonic-gate		for (i = 0; i <= 1; i++) {
7387c478bdstevel@tonic-gate			krd.s[i] = krs1.s[i] + krs2.s[i];
7397c478bdstevel@tonic-gate		}
7407c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &krd.i, nrd);
7417c478bdstevel@tonic-gate		break;
7427c478bdstevel@tonic-gate	case fpadd32:
7437c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
7447c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
7457c478bdstevel@tonic-gate		for (i = 0; i <= 1; i++) {
7467c478bdstevel@tonic-gate			lrd.i[i] = lrs1.i[i] + lrs2.i[i];
7477c478bdstevel@tonic-gate		}
7487c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
7497c478bdstevel@tonic-gate		break;
7507c478bdstevel@tonic-gate	case fpadd32s:
7517c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
7527c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
7537c478bdstevel@tonic-gate		krd.i = krs1.i + krs2.i;
7547c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &krd.i, nrd);
7557c478bdstevel@tonic-gate		break;
7567c478bdstevel@tonic-gate	case fpsub16:
7577c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
7587c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
7597c478bdstevel@tonic-gate		for (i = 0; i <= 3; i++) {
7607c478bdstevel@tonic-gate			lrd.s[i] = lrs1.s[i] - lrs2.s[i];
7617c478bdstevel@tonic-gate		}
7627c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
7637c478bdstevel@tonic-gate		break;
7647c478bdstevel@tonic-gate	case fpsub16s:
7657c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
7667c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
7677c478bdstevel@tonic-gate		for (i = 0; i <= 1; i++) {
7687c478bdstevel@tonic-gate			krd.s[i] = krs1.s[i] - krs2.s[i];
7697c478bdstevel@tonic-gate		}
7707c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &krd.i, nrd);
7717c478bdstevel@tonic-gate		break;
7727c478bdstevel@tonic-gate	case fpsub32:
7737c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
7747c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
7757c478bdstevel@tonic-gate		for (i = 0; i <= 1; i++) {
7767c478bdstevel@tonic-gate			lrd.i[i] = lrs1.i[i] - lrs2.i[i];
7777c478bdstevel@tonic-gate		}
7787c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
7797c478bdstevel@tonic-gate		break;
7807c478bdstevel@tonic-gate	case fpsub32s:
7817c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
7827c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
7837c478bdstevel@tonic-gate		krd.i = krs1.i - krs2.i;
7847c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &krd.i, nrd);
7857c478bdstevel@tonic-gate		break;
7867c478bdstevel@tonic-gate	}
7877c478bdstevel@tonic-gate	return (ftt_none);
7887c478bdstevel@tonic-gate}
7897c478bdstevel@tonic-gate
7907c478bdstevel@tonic-gate/*
7917c478bdstevel@tonic-gate * Simulator for fcmp* instruction.
7927c478bdstevel@tonic-gate */
7937c478bdstevel@tonic-gatestatic enum ftt_type
7947c478bdstevel@tonic-gatevis_fcmp(
7957c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
7967c478bdstevel@tonic-gate	vis_inst_type	inst,	/* FPU instruction to simulate. */
7977c478bdstevel@tonic-gate	struct regs	*pregs,	/* Pointer to PCB image of registers. */
7987c478bdstevel@tonic-gate	void		*prw)	/* Pointer to locals and ins. */
7997c478bdstevel@tonic-gate{
8007c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
8017c478bdstevel@tonic-gate	union {
8027c478bdstevel@tonic-gate		uint64_t	ll;
8037c478bdstevel@tonic-gate		uint32_t	i[2];
8047c478bdstevel@tonic-gate		uint16_t	s[4];
8057c478bdstevel@tonic-gate	} krs1, krs2, krd;
8067c478bdstevel@tonic-gate	enum ftt_type ftt;
8077c478bdstevel@tonic-gate	short sr1, sr2;
8087c478bdstevel@tonic-gate	int i, ir1, ir2;
8097c478bdstevel@tonic-gate
8107c478bdstevel@tonic-gate	nrs1 = inst.rs1;
8117c478bdstevel@tonic-gate	nrs2 = inst.rs2;
8127c478bdstevel@tonic-gate	nrd = inst.rd;
8137c478bdstevel@tonic-gate	krd.ll = 0;
8147c478bdstevel@tonic-gate	if ((nrs1 & 1) == 1) 	/* fix register encoding */
8157c478bdstevel@tonic-gate		nrs1 = (nrs1 & 0x1e) | 0x20;
8167c478bdstevel@tonic-gate	if ((nrs2 & 1) == 1)
8177c478bdstevel@tonic-gate		nrs2 = (nrs2 & 0x1e) | 0x20;
8187c478bdstevel@tonic-gate
8197c478bdstevel@tonic-gate	_fp_unpack_extword(pfpsd, &krs1.ll, nrs1);
8207c478bdstevel@tonic-gate	_fp_unpack_extword(pfpsd, &krs2.ll, nrs2);
8217c478bdstevel@tonic-gate	switch (inst.opf) {
8227c478bdstevel@tonic-gate	case fcmple16:
8237c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fcmple16);
8247c478bdstevel@tonic-gate		for (i = 0; i <= 3; i++) {
8257c478bdstevel@tonic-gate			sr1 = (short)krs1.s[i];
8267c478bdstevel@tonic-gate			sr2 = (short)krs2.s[i];
8277c478bdstevel@tonic-gate			if (sr1 <= sr2)
8287c478bdstevel@tonic-gate				krd.ll += (0x8 >> i);
8297c478bdstevel@tonic-gate		}
8307c478bdstevel@tonic-gate		break;
8317c478bdstevel@tonic-gate	case fcmpne16:
8327c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fcmpne16);
8337c478bdstevel@tonic-gate		for (i = 0; i <= 3; i++) {
8347c478bdstevel@tonic-gate			sr1 = (short)krs1.s[i];
8357c478bdstevel@tonic-gate			sr2 = (short)krs2.s[i];
8367c478bdstevel@tonic-gate			if (sr1 != sr2)
8377c478bdstevel@tonic-gate				krd.ll += (0x8 >> i);
8387c478bdstevel@tonic-gate		}
8397c478bdstevel@tonic-gate		break;
8407c478bdstevel@tonic-gate	case fcmpgt16:
8417c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fcmpgt16);
8427c478bdstevel@tonic-gate		for (i = 0; i <= 3; i++) {
8437c478bdstevel@tonic-gate			sr1 = (short)krs1.s[i];
8447c478bdstevel@tonic-gate			sr2 = (short)krs2.s[i];
8457c478bdstevel@tonic-gate			if (sr1 > sr2)
8467c478bdstevel@tonic-gate				krd.ll += (0x8 >> i);
8477c478bdstevel@tonic-gate		}
8487c478bdstevel@tonic-gate		break;
8497c478bdstevel@tonic-gate	case fcmpeq16:
8507c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fcmpeq16);
8517c478bdstevel@tonic-gate		for (i = 0; i <= 3; i++) {
8527c478bdstevel@tonic-gate			sr1 = (short)krs1.s[i];
8537c478bdstevel@tonic-gate			sr2 = (short)krs2.s[i];
8547c478bdstevel@tonic-gate			if (sr1 == sr2)
8557c478bdstevel@tonic-gate				krd.ll += (0x8 >> i);
8567c478bdstevel@tonic-gate		}
8577c478bdstevel@tonic-gate		break;
8587c478bdstevel@tonic-gate	case fcmple32:
8597c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fcmple32);
8607c478bdstevel@tonic-gate		for (i = 0; i <= 1; i++) {
8617c478bdstevel@tonic-gate			ir1 = (int)krs1.i[i];
8627c478bdstevel@tonic-gate			ir2 = (int)krs2.i[i];
8637c478bdstevel@tonic-gate			if (ir1 <= ir2)
8647c478bdstevel@tonic-gate				krd.ll += (0x2 >> i);
8657c478bdstevel@tonic-gate		}
8667c478bdstevel@tonic-gate		break;
8677c478bdstevel@tonic-gate	case fcmpne32:
8687c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fcmpne32);
8697c478bdstevel@tonic-gate		for (i = 0; i <= 1; i++) {
8707c478bdstevel@tonic-gate			ir1 = (int)krs1.i[i];
8717c478bdstevel@tonic-gate			ir2 = (int)krs2.i[i];
8727c478bdstevel@tonic-gate			if (ir1 != ir2)
8737c478bdstevel@tonic-gate				krd.ll += (0x2 >> i);
8747c478bdstevel@tonic-gate		}
8757c478bdstevel@tonic-gate		break;
8767c478bdstevel@tonic-gate	case fcmpgt32:
8777c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fcmpgt32);
8787c478bdstevel@tonic-gate		for (i = 0; i <= 1; i++) {
8797c478bdstevel@tonic-gate			ir1 = (int)krs1.i[i];
8807c478bdstevel@tonic-gate			ir2 = (int)krs2.i[i];
8817c478bdstevel@tonic-gate			if (ir1 > ir2)
8827c478bdstevel@tonic-gate				krd.ll += (0x2 >> i);
8837c478bdstevel@tonic-gate		}
8847c478bdstevel@tonic-gate		break;
8857c478bdstevel@tonic-gate	case fcmpeq32:
8867c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fcmpeq32);
8877c478bdstevel@tonic-gate		for (i = 0; i <= 1; i++) {
8887c478bdstevel@tonic-gate			ir1 = (int)krs1.i[i];
8897c478bdstevel@tonic-gate			ir2 = (int)krs2.i[i];
8907c478bdstevel@tonic-gate			if (ir1 == ir2)
8917c478bdstevel@tonic-gate				krd.ll += (0x2 >> i);
8927c478bdstevel@tonic-gate		}
8937c478bdstevel@tonic-gate		break;
8947c478bdstevel@tonic-gate	}
8957c478bdstevel@tonic-gate	ftt = write_iureg(pfpsd, nrd, pregs, prw, &krd.ll);
8967c478bdstevel@tonic-gate	return (ftt);
8977c478bdstevel@tonic-gate}
8987c478bdstevel@tonic-gate
8997c478bdstevel@tonic-gate/*
9007c478bdstevel@tonic-gate * Simulator for fmul* instruction.
9017c478bdstevel@tonic-gate */
9027c478bdstevel@tonic-gatestatic enum ftt_type
9037c478bdstevel@tonic-gatevis_fmul(
9047c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
9057c478bdstevel@tonic-gate	vis_inst_type	inst)	/* FPU instruction to simulate. */
9067c478bdstevel@tonic-gate{
9077c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
9087c478bdstevel@tonic-gate	union {
9097c478bdstevel@tonic-gate		uint64_t	ll;
9107c478bdstevel@tonic-gate		uint32_t	i[2];
9117c478bdstevel@tonic-gate		uint16_t	s[4];
9127c478bdstevel@tonic-gate		uint8_t		c[8];
9137c478bdstevel@tonic-gate	} lrs1, lrs2, lrd;
9147c478bdstevel@tonic-gate	union {
9157c478bdstevel@tonic-gate		uint32_t	i;
9167c478bdstevel@tonic-gate		uint16_t	s[2];
9177c478bdstevel@tonic-gate		uint8_t		c[4];
9187c478bdstevel@tonic-gate	} krs1, krs2, kres;
9197c478bdstevel@tonic-gate	short s1, s2, sres;
9207c478bdstevel@tonic-gate	ushort_t us1;
9217c478bdstevel@tonic-gate	char c1;
9227c478bdstevel@tonic-gate	int i;
9237c478bdstevel@tonic-gate
9247c478bdstevel@tonic-gate	nrs1 = inst.rs1;
9257c478bdstevel@tonic-gate	nrs2 = inst.rs2;
9267c478bdstevel@tonic-gate	nrd = inst.rd;
9277c478bdstevel@tonic-gate	if ((inst.opf & 1) == 0) {	/* double precision */
9287c478bdstevel@tonic-gate		if ((nrd & 1) == 1) 	/* fix register encoding */
9297c478bdstevel@tonic-gate			nrd = (nrd & 0x1e) | 0x20;
9307c478bdstevel@tonic-gate	}
9317c478bdstevel@tonic-gate
9327c478bdstevel@tonic-gate	switch (inst.opf) {
9337c478bdstevel@tonic-gate	case fmul8x16:
9347c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fmul8x16);
9357c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
9367c478bdstevel@tonic-gate		if ((nrs2 & 1) == 1)
9377c478bdstevel@tonic-gate			nrs2 = (nrs2 & 0x1e) | 0x20;
9387c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
9397c478bdstevel@tonic-gate		for (i = 0; i <= 3; i++) {
9407c478bdstevel@tonic-gate			us1 = (ushort_t)krs1.c[i];
9417c478bdstevel@tonic-gate			s2 = (short)lrs2.s[i];
9427c478bdstevel@tonic-gate			kres.i = us1 * s2;
9437c478bdstevel@tonic-gate			sres = (short)((kres.c[1] << 8) | kres.c[2]);
9447c478bdstevel@tonic-gate			if (kres.c[3] >= 0x80)
9457c478bdstevel@tonic-gate				sres++;
9467c478bdstevel@tonic-gate			lrd.s[i] = sres;
9477c478bdstevel@tonic-gate		}
9487c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
9497c478bdstevel@tonic-gate		break;
9507c478bdstevel@tonic-gate	case fmul8x16au:
9517c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fmul8x16au);
9527c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
9537c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
9547c478bdstevel@tonic-gate		for (i = 0; i <= 3; i++) {
9557c478bdstevel@tonic-gate			us1 = (ushort_t)krs1.c[i];
9567c478bdstevel@tonic-gate			s2 = (short)krs2.s[0];
9577c478bdstevel@tonic-gate			kres.i = us1 * s2;
9587c478bdstevel@tonic-gate			sres = (short)((kres.c[1] << 8) | kres.c[2]);
9597c478bdstevel@tonic-gate			if (kres.c[3] >= 0x80)
9607c478bdstevel@tonic-gate				sres++;
9617c478bdstevel@tonic-gate			lrd.s[i] = sres;
9627c478bdstevel@tonic-gate		}
9637c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
9647c478bdstevel@tonic-gate		break;
9657c478bdstevel@tonic-gate	case fmul8x16al:
9667c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fmul8x16al);
9677c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
9687c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
9697c478bdstevel@tonic-gate		for (i = 0; i <= 3; i++) {
9707c478bdstevel@tonic-gate			us1 = (ushort_t)krs1.c[i];
9717c478bdstevel@tonic-gate			s2 = (short)krs2.s[1];
9727c478bdstevel@tonic-gate			kres.i = us1 * s2;
9737c478bdstevel@tonic-gate			sres = (short)((kres.c[1] << 8) | kres.c[2]);
9747c478bdstevel@tonic-gate			if (kres.c[3] >= 0x80)
9757c478bdstevel@tonic-gate				sres++;
9767c478bdstevel@tonic-gate			lrd.s[i] = sres;
9777c478bdstevel@tonic-gate		}
9787c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
9797c478bdstevel@tonic-gate		break;
9807c478bdstevel@tonic-gate	case fmul8sux16:
9817c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fmul8sux16);
9827c478bdstevel@tonic-gate		if ((nrs1 & 1) == 1) 	/* fix register encoding */
9837c478bdstevel@tonic-gate			nrs1 = (nrs1 & 0x1e) | 0x20;
9847c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
9857c478bdstevel@tonic-gate		if ((nrs2 & 1) == 1)
9867c478bdstevel@tonic-gate			nrs2 = (nrs2 & 0x1e) | 0x20;
9877c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
9887c478bdstevel@tonic-gate		for (i = 0; i <= 3; i++) {
9897c478bdstevel@tonic-gate			c1 = lrs1.c[(i*2)];
9907c478bdstevel@tonic-gate			s1 = (short)c1;		/* keeps the sign alive */
9917c478bdstevel@tonic-gate			s2 = (short)lrs2.s[i];
9927c478bdstevel@tonic-gate			kres.i = s1 * s2;
9937c478bdstevel@tonic-gate			sres = (short)((kres.c[1] << 8) | kres.c[2]);
9947c478bdstevel@tonic-gate			if (kres.c[3] >= 0x80)
9957c478bdstevel@tonic-gate				sres++;
9967c478bdstevel@tonic-gate			if (sres < 0)
9977c478bdstevel@tonic-gate				lrd.s[i] = (sres & 0xFFFF);
9987c478bdstevel@tonic-gate			else
9997c478bdstevel@tonic-gate				lrd.s[i] = sres;
10007c478bdstevel@tonic-gate		}
10017c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
10027c478bdstevel@tonic-gate		break;
10037c478bdstevel@tonic-gate	case fmul8ulx16:
10047c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fmul8ulx16);
10057c478bdstevel@tonic-gate		if ((nrs1 & 1) == 1) 	/* fix register encoding */
10067c478bdstevel@tonic-gate			nrs1 = (nrs1 & 0x1e) | 0x20;
10077c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
10087c478bdstevel@tonic-gate		if ((nrs2 & 1) == 1)
10097c478bdstevel@tonic-gate			nrs2 = (nrs2 & 0x1e) | 0x20;
10107c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
10117c478bdstevel@tonic-gate		for (i = 0; i <= 3; i++) {
10127c478bdstevel@tonic-gate			us1 = (ushort_t)lrs1.c[(i*2)+1];
10137c478bdstevel@tonic-gate			s2 = (short)lrs2.s[i];
10147c478bdstevel@tonic-gate			kres.i = us1 * s2;
10157c478bdstevel@tonic-gate			sres = (short)kres.s[0];
10167c478bdstevel@tonic-gate			if (kres.s[1] >= 0x8000)
10177c478bdstevel@tonic-gate				sres++;
10187c478bdstevel@tonic-gate			lrd.s[i] = sres;
10197c478bdstevel@tonic-gate		}
10207c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
10217c478bdstevel@tonic-gate		break;
10227c478bdstevel@tonic-gate	case fmuld8sux16:
10237c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fmuld8sux16);
10247c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
10257c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
10267c478bdstevel@tonic-gate		for (i = 0; i <= 1; i++) {
10277c478bdstevel@tonic-gate			c1 = krs1.c[(i*2)];
10287c478bdstevel@tonic-gate			s1 = (short)c1;		/* keeps the sign alive */
10297c478bdstevel@tonic-gate			s2 = (short)krs2.s[i];
10307c478bdstevel@tonic-gate			kres.i = s1 * s2;
10317c478bdstevel@tonic-gate			lrd.i[i] = kres.i << 8;
10327c478bdstevel@tonic-gate		}
10337c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
10347c478bdstevel@tonic-gate		break;
10357c478bdstevel@tonic-gate	case fmuld8ulx16:
10367c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fmuld8ulx16);
10377c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
10387c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
10397c478bdstevel@tonic-gate		for (i = 0; i <= 1; i++) {
10407c478bdstevel@tonic-gate			us1 = (ushort_t)krs1.c[(i*2)+1];
10417c478bdstevel@tonic-gate			s2 = (short)krs2.s[i];
10427c478bdstevel@tonic-gate			lrd.i[i] = us1 * s2;
10437c478bdstevel@tonic-gate		}
10447c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
10457c478bdstevel@tonic-gate		break;
10467c478bdstevel@tonic-gate	}
10477c478bdstevel@tonic-gate	return (ftt_none);
10487c478bdstevel@tonic-gate}
10497c478bdstevel@tonic-gate
10507c478bdstevel@tonic-gate/*
10517c478bdstevel@tonic-gate * Simulator for fpixel formatting instructions.
10527c478bdstevel@tonic-gate */
10537c478bdstevel@tonic-gatestatic enum ftt_type
10547c478bdstevel@tonic-gatevis_fpixel(
10557c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
10567c478bdstevel@tonic-gate	vis_inst_type	inst,	/* FPU instruction to simulate. */
10577c478bdstevel@tonic-gate	kfpu_t		*fp)	/* Need to fp to access gsr reg */
10587c478bdstevel@tonic-gate{
10597c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
10607c478bdstevel@tonic-gate	int	i, j, k, sf;
10617c478bdstevel@tonic-gate	union {
10627c478bdstevel@tonic-gate		uint64_t	ll;
10637c478bdstevel@tonic-gate		uint32_t	i[2];
10647c478bdstevel@tonic-gate		uint16_t	s[4];
10657c478bdstevel@tonic-gate		uint8_t		c[8];
10667c478bdstevel@tonic-gate	} lrs1, lrs2, lrd;
10677c478bdstevel@tonic-gate	union {
10687c478bdstevel@tonic-gate		uint32_t	i;
10697c478bdstevel@tonic-gate		uint16_t	s[2];
10707c478bdstevel@tonic-gate		uint8_t		c[4];
10717c478bdstevel@tonic-gate	} krs1, krs2, krd;
10727c478bdstevel@tonic-gate	uint64_t r;
10737c478bdstevel@tonic-gate	int64_t l, m;
10747c478bdstevel@tonic-gate	short s;
10757c478bdstevel@tonic-gate	uchar_t uc;
10767c478bdstevel@tonic-gate
10777c478bdstevel@tonic-gate	nrs1 = inst.rs1;
10787c478bdstevel@tonic-gate	nrs2 = inst.rs2;
10797c478bdstevel@tonic-gate	nrd = inst.rd;
10807c478bdstevel@tonic-gate	if ((inst.opf != fpack16) && (inst.opf != fpackfix)) {
10817c478bdstevel@tonic-gate		if ((nrd & 1) == 1) 	/* fix register encoding */
10827c478bdstevel@tonic-gate			nrd = (nrd & 0x1e) | 0x20;
10837c478bdstevel@tonic-gate	}
10847c478bdstevel@tonic-gate
10857c478bdstevel@tonic-gate	switch (inst.opf) {
10867c478bdstevel@tonic-gate	case fpack16:
10877c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fpack16);
10887c478bdstevel@tonic-gate		if ((nrs2 & 1) == 1) 	/* fix register encoding */
10897c478bdstevel@tonic-gate			nrs2 = (nrs2 & 0x1e) | 0x20;
10907c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
10915892374df		r = pfpsd->fp_current_read_gsr(fp);
10927c478bdstevel@tonic-gate		/* fpack16 ignores GSR.scale msb */
10937c478bdstevel@tonic-gate		sf = (int)(GSR_SCALE(r) & 0xf);
10947c478bdstevel@tonic-gate		for (i = 0; i <= 3; i++) {
10957c478bdstevel@tonic-gate			s = (short)lrs2.s[i];	/* preserve the sign */
10967c478bdstevel@tonic-gate			j = ((int)s << sf);
10977c478bdstevel@tonic-gate			k = j >> 7;
10987c478bdstevel@tonic-gate			if (k < 0) {
10997c478bdstevel@tonic-gate				uc = 0;
11007c478bdstevel@tonic-gate			} else if (k > 255) {
11017c478bdstevel@tonic-gate				uc = 255;
11027c478bdstevel@tonic-gate			} else {
11037c478bdstevel@tonic-gate				uc = (uchar_t)k;
11047c478bdstevel@tonic-gate			}
11057c478bdstevel@tonic-gate			krd.c[i] = uc;
11067c478bdstevel@tonic-gate		}
11077c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &krd.i, nrd);
11087c478bdstevel@tonic-gate		break;
11097c478bdstevel@tonic-gate	case fpack32:
11107c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fpack32);
11117c478bdstevel@tonic-gate		if ((nrs1 & 1) == 1) 	/* fix register encoding */
11127c478bdstevel@tonic-gate			nrs1 = (nrs1 & 0x1e) | 0x20;
11137c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
11147c478bdstevel@tonic-gate		if ((nrs2 & 1) == 1)
11157c478bdstevel@tonic-gate			nrs2 = (nrs2 & 0x1e) | 0x20;
11167c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
11177c478bdstevel@tonic-gate
11185892374df		r = pfpsd->fp_current_read_gsr(fp);
11197c478bdstevel@tonic-gate		sf = (int)GSR_SCALE(r);
11207c478bdstevel@tonic-gate		lrd.ll = lrs1.ll << 8;
11217c478bdstevel@tonic-gate		for (i = 0, k = 3; i <= 1; i++, k += 4) {
11227c478bdstevel@tonic-gate			j = (int)lrs2.i[i];	/* preserve the sign */
11237c478bdstevel@tonic-gate			l = ((int64_t)j << sf);
11247c478bdstevel@tonic-gate			m = l >> 23;
11257c478bdstevel@tonic-gate			if (m < 0) {
11267c478bdstevel@tonic-gate				uc = 0;
11277c478bdstevel@tonic-gate			} else if (m > 255) {
11287c478bdstevel@tonic-gate				uc = 255;
11297c478bdstevel@tonic-gate			} else {
11307c478bdstevel@tonic-gate				uc = (uchar_t)m;
11317c478bdstevel@tonic-gate			}
11327c478bdstevel@tonic-gate			lrd.c[k] = uc;
11337c478bdstevel@tonic-gate		}
11347c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
11357c478bdstevel@tonic-gate		break;
11367c478bdstevel@tonic-gate	case fpackfix:
11377c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fpackfix);
11387c478bdstevel@tonic-gate		if ((nrs2 & 1) == 1)
11397c478bdstevel@tonic-gate			nrs2 = (nrs2 & 0x1e) | 0x20;
11407c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
11417c478bdstevel@tonic-gate
11425892374df		r = pfpsd->fp_current_read_gsr(fp);
11437c478bdstevel@tonic-gate		sf = (int)GSR_SCALE(r);
11447c478bdstevel@tonic-gate		for (i = 0; i <= 1; i++) {
11457c478bdstevel@tonic-gate			j = (int)lrs2.i[i];	/* preserve the sign */
11467c478bdstevel@tonic-gate			l = ((int64_t)j << sf);
11477c478bdstevel@tonic-gate			m = l >> 16;
11487c478bdstevel@tonic-gate			if (m < -32768) {
11497c478bdstevel@tonic-gate				s = -32768;
11507c478bdstevel@tonic-gate			} else if (m > 32767) {
11517c478bdstevel@tonic-gate				s = 32767;
11527c478bdstevel@tonic-gate			} else {
11537c478bdstevel@tonic-gate				s = (short)m;
11547c478bdstevel@tonic-gate			}
11557c478bdstevel@tonic-gate			krd.s[i] = s;
11567c478bdstevel@tonic-gate		}
11577c478bdstevel@tonic-gate		_fp_pack_word(pfpsd, &krd.i, nrd);
11587c478bdstevel@tonic-gate		break;
11597c478bdstevel@tonic-gate	case fexpand:
11607c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fexpand);
11617c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
11627c478bdstevel@tonic-gate		for (i = 0; i <= 3; i++) {
11637c478bdstevel@tonic-gate			uc = krs2.c[i];
11647c478bdstevel@tonic-gate			lrd.s[i] = (ushort_t)(uc << 4);
11657c478bdstevel@tonic-gate		}
11667c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
11677c478bdstevel@tonic-gate		break;
11687c478bdstevel@tonic-gate	case fpmerge:
11697c478bdstevel@tonic-gate		VISINFO_KSTAT(vis_fpmerge);
11707c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
11717c478bdstevel@tonic-gate		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
11727c478bdstevel@tonic-gate		for (i = 0, j = 0; i <= 3; i++, j += 2) {
11737c478bdstevel@tonic-gate			lrd.c[j] = krs1.c[i];
11747c478bdstevel@tonic-gate			lrd.c[j+1] = krs2.c[i];
11757c478bdstevel@tonic-gate		}
11767c478bdstevel@tonic-gate		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
11777c478bdstevel@tonic-gate		break;
11787c478bdstevel@tonic-gate	}
11797c478bdstevel@tonic-gate	return (ftt_none);
11807c478bdstevel@tonic-gate}
11817c478bdstevel@tonic-gate
11827c478bdstevel@tonic-gate/*
11837c478bdstevel@tonic-gate * Simulator for pdist instruction.
11847c478bdstevel@tonic-gate */
11857c478bdstevel@tonic-gateenum ftt_type
11867c478bdstevel@tonic-gatevis_pdist(
11877c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
11888159a90Sree Vemuri	fp_inst_type	pinst,	/* FPU instruction to simulate. */
11898159a90Sree Vemuri	struct regs	*pregs,	/* Pointer to PCB image of registers. */
11908159a90Sree Vemuri	void		*prw,	/* Pointer to locals and ins. */
11918159a90Sree Vemuri	uint_t		op)	/* Opcode pdist or pdistn */
11927c478bdstevel@tonic-gate{
11937c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
11947c478bdstevel@tonic-gate	int	i;
11957c478bdstevel@tonic-gate	short	s;
11967c478bdstevel@tonic-gate	union {
11977c478bdstevel@tonic-gate		uint64_t	ll;
11987c478bdstevel@tonic-gate		uint8_t		c[8];
11997c478bdstevel@tonic-gate	} lrs1, lrs2, lrd;
12007c478bdstevel@tonic-gate
12017c478bdstevel@tonic-gate	nrs1 = pinst.rs1;
12027c478bdstevel@tonic-gate	nrs2 = pinst.rs2;
12037c478bdstevel@tonic-gate	nrd = pinst.rd;
12048159a90Sree Vemuri
12057c478bdstevel@tonic-gate	if ((nrs1 & 1) == 1) 		/* fix register encoding */
12067c478bdstevel@tonic-gate		nrs1 = (nrs1 & 0x1e) | 0x20;
12077c478bdstevel@tonic-gate	if ((nrs2 & 1) == 1)
12087c478bdstevel@tonic-gate		nrs2 = (nrs2 & 0x1e) | 0x20;
12097c478bdstevel@tonic-gate	if ((nrd & 1) == 1)
12107c478bdstevel@tonic-gate		nrd = (nrd & 0x1e) | 0x20;
12117c478bdstevel@tonic-gate
12127c478bdstevel@tonic-gate	_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
12137c478bdstevel@tonic-gate	_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
12148159a90Sree Vemuri
12158159a90Sree Vemuri	if (op == pdist) {
12168159a90Sree Vemuri		VISINFO_KSTAT(vis_pdist);
12178159a90Sree Vemuri		_fp_unpack_extword(pfpsd, &lrd.ll, nrd);
12188159a90Sree Vemuri	} else {
12198159a90Sree Vemuri		/* pdistn */
12208159a90Sree Vemuri		VISINFO_KSTAT(vis_pdistn);
12218159a90Sree Vemuri		lrd.ll = 0;
12228159a90Sree Vemuri	}
12237c478bdstevel@tonic-gate
12247c478bdstevel@tonic-gate	for (i = 0; i <= 7; i++) {
12257c478bdstevel@tonic-gate		s = (short)(lrs1.c[i] - lrs2.c[i]);
12267c478bdstevel@tonic-gate		if (s < 0)
12277c478bdstevel@tonic-gate			s = ~s + 1;
12287c478bdstevel@tonic-gate		lrd.ll += s;
12297c478bdstevel@tonic-gate	}
12307c478bdstevel@tonic-gate
12318159a90Sree Vemuri	if (op == pdist)
12328159a90Sree Vemuri		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
12338159a90Sree Vemuri	else
12348159a90Sree Vemuri		/* pdistn */
12358159a90Sree Vemuri		(void) write_iureg(pfpsd, nrd, pregs, prw, &lrd.ll);
12367c478bdstevel@tonic-gate	return (ftt_none);
12377c478bdstevel@tonic-gate}
12387c478bdstevel@tonic-gate
12397c478bdstevel@tonic-gate/*
12407c478bdstevel@tonic-gate * Simulator for faligndata instruction.
12417c478bdstevel@tonic-gate */
12427c478bdstevel@tonic-gatestatic enum ftt_type
12437c478bdstevel@tonic-gatevis_faligndata(
12447c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
12457c478bdstevel@tonic-gate	fp_inst_type	pinst,	/* FPU instruction to simulate. */
12467c478bdstevel@tonic-gate	kfpu_t		*fp)	/* Need to fp to access gsr reg */
12477c478bdstevel@tonic-gate{
12487c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
12497c478bdstevel@tonic-gate	int	i, j, k, ao;
12507c478bdstevel@tonic-gate	union {
12517c478bdstevel@tonic-gate		uint64_t	ll;
12527c478bdstevel@tonic-gate		uint8_t		c[8];
12537c478bdstevel@tonic-gate	} lrs1, lrs2, lrd;
12547c478bdstevel@tonic-gate	uint64_t r;
12557c478bdstevel@tonic-gate
12567c478bdstevel@tonic-gate	nrs1 = pinst.rs1;
12577c478bdstevel@tonic-gate	nrs2 = pinst.rs2;
12587c478bdstevel@tonic-gate	nrd = pinst.rd;
12597c478bdstevel@tonic-gate	if ((nrs1 & 1) == 1) 		/* fix register encoding */
12607c478bdstevel@tonic-gate		nrs1 = (nrs1 & 0x1e) | 0x20;
12617c478bdstevel@tonic-gate	if ((nrs2 & 1) == 1)
12627c478bdstevel@tonic-gate		nrs2 = (nrs2 & 0x1e) | 0x20;
12637c478bdstevel@tonic-gate	if ((nrd & 1) == 1)
12647c478bdstevel@tonic-gate		nrd = (nrd & 0x1e) | 0x20;
12657c478bdstevel@tonic-gate
12667c478bdstevel@tonic-gate	_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
12677c478bdstevel@tonic-gate	_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
12687c478bdstevel@tonic-gate
12695892374df	r = pfpsd->fp_current_read_gsr(fp);
12707c478bdstevel@tonic-gate	ao = (int)GSR_ALIGN(r);
12717c478bdstevel@tonic-gate
12727c478bdstevel@tonic-gate	for (i = 0, j = ao, k = 0; i <= 7; i++)
12737c478bdstevel@tonic-gate		if (j <= 7) {
12747c478bdstevel@tonic-gate			lrd.c[i] = lrs1.c[j++];
12757c478bdstevel@tonic-gate		} else {
12767c478bdstevel@tonic-gate			lrd.c[i] = lrs2.c[k++];
12777c478bdstevel@tonic-gate		}
12787c478bdstevel@tonic-gate	_fp_pack_extword(pfpsd, &lrd.ll, nrd);
12797c478bdstevel@tonic-gate
12807c478bdstevel@tonic-gate	return (ftt_none);
12817c478bdstevel@tonic-gate}
12827c478bdstevel@tonic-gate
12837c478bdstevel@tonic-gate/*
12847c478bdstevel@tonic-gate * Simulator for bshuffle instruction.
12857c478bdstevel@tonic-gate */
12867c478bdstevel@tonic-gatestatic enum ftt_type
12877c478bdstevel@tonic-gatevis_bshuffle(
12887c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
12897c478bdstevel@tonic-gate	fp_inst_type	pinst,	/* FPU instruction to simulate. */
12907c478bdstevel@tonic-gate	kfpu_t		*fp)	/* Need to fp to access gsr reg */
12917c478bdstevel@tonic-gate{
12927c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
12937c478bdstevel@tonic-gate	int	i, j, ao;
12947c478bdstevel@tonic-gate	union {
12957c478bdstevel@tonic-gate		uint64_t	ll;
12967c478bdstevel@tonic-gate		uint8_t		c[8];
12977c478bdstevel@tonic-gate	} lrs1, lrs2, lrd;
12987c478bdstevel@tonic-gate	uint64_t r;
12997c478bdstevel@tonic-gate
13007c478bdstevel@tonic-gate	VISINFO_KSTAT(vis_bshuffle);
13017c478bdstevel@tonic-gate	nrs1 = pinst.rs1;
13027c478bdstevel@tonic-gate	nrs2 = pinst.rs2;
13037c478bdstevel@tonic-gate	nrd = pinst.rd;
13047c478bdstevel@tonic-gate	if ((nrs1 & 1) == 1) 		/* fix register encoding */
13057c478bdstevel@tonic-gate		nrs1 = (nrs1 & 0x1e) | 0x20;
13067c478bdstevel@tonic-gate	if ((nrs2 & 1) == 1)
13077c478bdstevel@tonic-gate		nrs2 = (nrs2 & 0x1e) | 0x20;
13087c478bdstevel@tonic-gate	if ((nrd & 1) == 1)
13097c478bdstevel@tonic-gate		nrd = (nrd & 0x1e) | 0x20;
13107c478bdstevel@tonic-gate
13117c478bdstevel@tonic-gate	_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
13127c478bdstevel@tonic-gate	_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
13137c478bdstevel@tonic-gate
13145892374df	r = pfpsd->fp_current_read_gsr(fp);
13157c478bdstevel@tonic-gate	ao = (int)GSR_MASK(r);
13167c478bdstevel@tonic-gate
13177c478bdstevel@tonic-gate	/*
13187c478bdstevel@tonic-gate	 * BSHUFFLE Destination Byte Selection
13197c478bdstevel@tonic-gate	 * rd Byte	Source
13207c478bdstevel@tonic-gate	 * 0		rs byte[GSR.mask<31..28>]
13217c478bdstevel@tonic-gate	 * 1		rs byte[GSR.mask<27..24>]
13227c478bdstevel@tonic-gate	 * 2		rs byte[GSR.mask<23..20>]
13237c478bdstevel@tonic-gate	 * 3		rs byte[GSR.mask<19..16>]
13247c478bdstevel@tonic-gate	 * 4		rs byte[GSR.mask<15..12>]
13257c478bdstevel@tonic-gate	 * 5		rs byte[GSR.mask<11..8>]
13267c478bdstevel@tonic-gate	 * 6		rs byte[GSR.mask<7..4>]
13277c478bdstevel@tonic-gate	 * 7		rs byte[GSR.mask<3..0>]
13287c478bdstevel@tonic-gate	 * P.S. rs1 is the upper half and rs2 is the lower half
13297c478bdstevel@tonic-gate	 * Bytes in the source value are numbered from most to
13307c478bdstevel@tonic-gate	 * least significant
13317c478bdstevel@tonic-gate	 */
13327c478bdstevel@tonic-gate	for (i = 7; i >= 0; i--, ao = (ao >> 4)) {
13337c478bdstevel@tonic-gate		j = ao & 0xf;		/* get byte number */
13347c478bdstevel@tonic-gate		if (j < 8) {
13357c478bdstevel@tonic-gate			lrd.c[i] = lrs1.c[j];
13367c478bdstevel@tonic-gate		} else {
13377c478bdstevel@tonic-gate			lrd.c[i] = lrs2.c[j - 8];
13387c478bdstevel@tonic-gate		}
13397c478bdstevel@tonic-gate	}
13407c478bdstevel@tonic-gate	_fp_pack_extword(pfpsd, &lrd.ll, nrd);
13417c478bdstevel@tonic-gate
13427c478bdstevel@tonic-gate	return (ftt_none);
13437c478bdstevel@tonic-gate}
13447c478bdstevel@tonic-gate
13457c478bdstevel@tonic-gate/*
13467c478bdstevel@tonic-gate * Simulator for siam instruction.
13477c478bdstevel@tonic-gate */
13487c478bdstevel@tonic-gatestatic enum ftt_type
13497c478bdstevel@tonic-gatevis_siam(
13507c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
13517c478bdstevel@tonic-gate	vis_inst_type	inst,	/* FPU instruction to simulate. */
13527c478bdstevel@tonic-gate	kfpu_t		*fp)	/* Need to fp to access gsr reg */
13537c478bdstevel@tonic-gate{
13547c478bdstevel@tonic-gate	uint_t	nrs2;			/* Register number fields. */
13557c478bdstevel@tonic-gate	uint64_t g, r;
13567c478bdstevel@tonic-gate	nrs2 = inst.rs2;
13577c478bdstevel@tonic-gate
13585892374df	g = pfpsd->fp_current_read_gsr(fp);
13597c478bdstevel@tonic-gate	g &= ~(GSR_IM_IRND_MASK);	/* zero the IM and IRND fields */
13607c478bdstevel@tonic-gate	r = nrs2 & 0x7;			/* get mode(3 bit) */
13617c478bdstevel@tonic-gate	g |= (r << GSR_IRND_SHIFT);
13625892374df	pfpsd->fp_current_write_gsr(g, fp);
13637c478bdstevel@tonic-gate	return (ftt_none);
13647c478bdstevel@tonic-gate}
13657c478bdstevel@tonic-gate
13667c478bdstevel@tonic-gate/*
13677c478bdstevel@tonic-gate * Simulator for VIS loads and stores between floating-point unit and memory.
13687c478bdstevel@tonic-gate */
13697c478bdstevel@tonic-gateenum ftt_type
13707c478bdstevel@tonic-gatevis_fldst(
13717c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
13727c478bdstevel@tonic-gate	fp_inst_type	pinst,	/* FPU instruction to simulate. */
13737c478bdstevel@tonic-gate	struct regs	*pregs,	/* Pointer to PCB image of registers. */
13747c478bdstevel@tonic-gate	void		*prw,	/* Pointer to locals and ins. */
13757c478bdstevel@tonic-gate	uint_t		asi)	/* asi to emulate! */
13767c478bdstevel@tonic-gate{
13777c478bdstevel@tonic-gate	union {
13787c478bdstevel@tonic-gate		vis_inst_type	inst;
13797c478bdstevel@tonic-gate		fp_inst_type	pinst;
13807c478bdstevel@tonic-gate	} i;
13817c478bdstevel@tonic-gate
13827c478bdstevel@tonic-gate	ASSERT(USERMODE(pregs->r_tstate));
13837c478bdstevel@tonic-gate	i.pinst = pinst;
13847c478bdstevel@tonic-gate	switch (asi) {
13857c478bdstevel@tonic-gate		case ASI_PST8_P:
13867c478bdstevel@tonic-gate		case ASI_PST8_S:
13877c478bdstevel@tonic-gate		case ASI_PST16_P:
13887c478bdstevel@tonic-gate		case ASI_PST16_S:
13897c478bdstevel@tonic-gate		case ASI_PST32_P:
13907c478bdstevel@tonic-gate		case ASI_PST32_S:
13917c478bdstevel@tonic-gate		case ASI_PST8_PL:
13927c478bdstevel@tonic-gate		case ASI_PST8_SL:
13937c478bdstevel@tonic-gate		case ASI_PST16_PL:
13947c478bdstevel@tonic-gate		case ASI_PST16_SL:
13957c478bdstevel@tonic-gate		case ASI_PST32_PL:
13967c478bdstevel@tonic-gate		case ASI_PST32_SL:
13977c478bdstevel@tonic-gate			return (vis_prtl_fst(pfpsd, i.inst, pregs,
1398b1b05f9arutz			    prw, asi));
13997c478bdstevel@tonic-gate		case ASI_FL8_P:
14007c478bdstevel@tonic-gate		case ASI_FL8_S:
14017c478bdstevel@tonic-gate		case ASI_FL8_PL:
14027c478bdstevel@tonic-gate		case ASI_FL8_SL:
14037c478bdstevel@tonic-gate		case ASI_FL16_P:
14047c478bdstevel@tonic-gate		case ASI_FL16_S:
14057c478bdstevel@tonic-gate		case ASI_FL16_PL:
14067c478bdstevel@tonic-gate		case ASI_FL16_SL:
14077c478bdstevel@tonic-gate			return (vis_short_fls(pfpsd, i.inst, pregs,
1408b1b05f9arutz			    prw, asi));
14097c478bdstevel@tonic-gate		case ASI_BLK_AIUP:
14107c478bdstevel@tonic-gate		case ASI_BLK_AIUS:
14117c478bdstevel@tonic-gate		case ASI_BLK_AIUPL:
14127c478bdstevel@tonic-gate		case ASI_BLK_AIUSL:
14137c478bdstevel@tonic-gate		case ASI_BLK_P:
14147c478bdstevel@tonic-gate		case ASI_BLK_S:
14157c478bdstevel@tonic-gate		case ASI_BLK_PL:
14167c478bdstevel@tonic-gate		case ASI_BLK_SL:
14177c478bdstevel@tonic-gate		case ASI_BLK_COMMIT_P:
14187c478bdstevel@tonic-gate		case ASI_BLK_COMMIT_S:
14197c478bdstevel@tonic-gate			return (vis_blk_fldst(pfpsd, i.inst, pregs,
1420b1b05f9arutz			    prw, asi));
14217c478bdstevel@tonic-gate		default:
14227c478bdstevel@tonic-gate			return (ftt_unimplemented);
14237c478bdstevel@tonic-gate	}
14247c478bdstevel@tonic-gate}
14257c478bdstevel@tonic-gate
14267c478bdstevel@tonic-gate/*
14277c478bdstevel@tonic-gate * Simulator for partial stores between floating-point unit and memory.
14287c478bdstevel@tonic-gate */
14297c478bdstevel@tonic-gatestatic enum ftt_type
14307c478bdstevel@tonic-gatevis_prtl_fst(
14317c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
14327c478bdstevel@tonic-gate	vis_inst_type	inst,	/* ISE instruction to simulate. */
14337c478bdstevel@tonic-gate	struct regs	*pregs,	/* Pointer to PCB image of registers. */
14347c478bdstevel@tonic-gate	void		*prw,	/* Pointer to locals and ins. */
14357c478bdstevel@tonic-gate	uint_t		asi)	/* asi to emulate! */
14367c478bdstevel@tonic-gate{
14377c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
14387c478bdstevel@tonic-gate	uint_t	opf, msk;
14397c478bdstevel@tonic-gate	int	h, i, j;
14407c478bdstevel@tonic-gate	uint64_t ea, tmsk;
14417c478bdstevel@tonic-gate	union {
14427c478bdstevel@tonic-gate		freg_type	f;
14437c478bdstevel@tonic-gate		uint64_t	ll;
14447c478bdstevel@tonic-gate		uint32_t	i[2];
14457c478bdstevel@tonic-gate		uint16_t	s[4];
14467c478bdstevel@tonic-gate		uint8_t		c[8];
14477c478bdstevel@tonic-gate	} k, l, res;
14487c478bdstevel@tonic-gate	enum ftt_type   ftt;
14497c478bdstevel@tonic-gate
14507c478bdstevel@tonic-gate	nrs1 = inst.rs1;
14517c478bdstevel@tonic-gate	nrs2 = inst.rs2;
14527c478bdstevel@tonic-gate	nrd = inst.rd;
14537c478bdstevel@tonic-gate	if ((nrd & 1) == 1) 		/* fix register encoding */
14547c478bdstevel@tonic-gate		nrd = (nrd & 0x1e) | 0x20;
14557c478bdstevel@tonic-gate	opf = inst.opf;
14567c478bdstevel@tonic-gate	res.ll = 0;
14577c478bdstevel@tonic-gate	if ((opf & 0x100) == 0) {	/* effective address = rs1  */
14587c478bdstevel@tonic-gate		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
14597c478bdstevel@tonic-gate		if (ftt != ftt_none)
14607c478bdstevel@tonic-gate			return (ftt);
14617c478bdstevel@tonic-gate		ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tmsk);
14627c478bdstevel@tonic-gate		if (ftt != ftt_none)
14637c478bdstevel@tonic-gate			return (ftt);
14647c478bdstevel@tonic-gate		msk = (uint_t)tmsk;
14657c478bdstevel@tonic-gate	} else {
14667c478bdstevel@tonic-gate		pfpsd->fp_trapaddr = (caddr_t)pregs->r_pc;
14677c478bdstevel@tonic-gate		return (ftt_unimplemented);
14687c478bdstevel@tonic-gate	}
14697c478bdstevel@tonic-gate
14707c478bdstevel@tonic-gate	pfpsd->fp_trapaddr = (caddr_t)ea; /* setup bad addr in case we trap */
14717c478bdstevel@tonic-gate	if ((ea & 0x3) != 0)
14727c478bdstevel@tonic-gate		return (ftt_alignment);	/* Require 32 bit-alignment. */
14737c478bdstevel@tonic-gate
14747c478bdstevel@tonic-gate	switch (asi) {
14757c478bdstevel@tonic-gate	case ASI_PST8_P:
14767c478bdstevel@tonic-gate	case ASI_PST8_S:
14777c478bdstevel@tonic-gate		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
14787c478bdstevel@tonic-gate		if (ftt != ftt_none)
14797c478bdstevel@tonic-gate			return (ftt);
14807c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
14817c478bdstevel@tonic-gate		for (i = 0, j = 0x80; i <= 7; i++, j >>= 1) {
14827c478bdstevel@tonic-gate			if ((msk & j) == j)
14837c478bdstevel@tonic-gate				res.c[i] = k.c[i];
14847c478bdstevel@tonic-gate			else
14857c478bdstevel@tonic-gate				res.c[i] = l.c[i];
14867c478bdstevel@tonic-gate		}
14877c478bdstevel@tonic-gate		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
14887c478bdstevel@tonic-gate		if (ftt != ftt_none)
14897c478bdstevel@tonic-gate			return (ftt);
14907c478bdstevel@tonic-gate		break;
14917c478bdstevel@tonic-gate	case ASI_PST8_PL:	/* little-endian */
14927c478bdstevel@tonic-gate	case ASI_PST8_SL:
14937c478bdstevel@tonic-gate		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
14947c478bdstevel@tonic-gate		if (ftt != ftt_none)
14957c478bdstevel@tonic-gate			return (ftt);
14967c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
1497428cee1jfrank		for (h = 7, i = 0, j = 1; i <= 7; h--, i++, j <<= 1) {
14987c478bdstevel@tonic-gate			if ((msk & j) == j)
1499428cee1jfrank				res.c[i] = k.c[h];
15007c478bdstevel@tonic-gate			else
1501428cee1jfrank				res.c[i] = l.c[i];
15027c478bdstevel@tonic-gate		}
15037c478bdstevel@tonic-gate		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
15047c478bdstevel@tonic-gate		if (ftt != ftt_none)
15057c478bdstevel@tonic-gate			return (ftt);
15067c478bdstevel@tonic-gate		break;
15077c478bdstevel@tonic-gate	case ASI_PST16_P:
15087c478bdstevel@tonic-gate	case ASI_PST16_S:
15097c478bdstevel@tonic-gate		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
15107c478bdstevel@tonic-gate		if (ftt != ftt_none)
15117c478bdstevel@tonic-gate			return (ftt);
15127c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
15137c478bdstevel@tonic-gate		for (i = 0, j = 0x8; i <= 3; i++, j >>= 1) {
15147c478bdstevel@tonic-gate			if ((msk & j) == j)
15157c478bdstevel@tonic-gate				res.s[i] = k.s[i];
15167c478bdstevel@tonic-gate			else
15177c478bdstevel@tonic-gate				res.s[i] = l.s[i];
15187c478bdstevel@tonic-gate		}
15197c478bdstevel@tonic-gate		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
15207c478bdstevel@tonic-gate		if (ftt != ftt_none)
15217c478bdstevel@tonic-gate			return (ftt);
15227c478bdstevel@tonic-gate		break;
15237c478bdstevel@tonic-gate	case ASI_PST16_PL:
15247c478bdstevel@tonic-gate	case ASI_PST16_SL:
15257c478bdstevel@tonic-gate		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
15267c478bdstevel@tonic-gate		if (ftt != ftt_none)
15277c478bdstevel@tonic-gate			return (ftt);
15287c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
1529428cee1jfrank		for (h = 7, i = 0, j = 1; i <= 6; h -= 2, i += 2, j <<= 1) {
15307c478bdstevel@tonic-gate			if ((msk & j) == j) {
1531428cee1jfrank				res.c[i] = k.c[h];
1532428cee1jfrank				res.c[i+1] = k.c[h-1];
15337c478bdstevel@tonic-gate			} else {
1534428cee1jfrank				res.c[i] = l.c[i];
1535428cee1jfrank				res.c[i+1] = l.c[i+1];
15367c478bdstevel@tonic-gate			}
15377c478bdstevel@tonic-gate		}
15387c478bdstevel@tonic-gate		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
15397c478bdstevel@tonic-gate		if (ftt != ftt_none)
15407c478bdstevel@tonic-gate			return (ftt);
15417c478bdstevel@tonic-gate		break;
15427c478bdstevel@tonic-gate	case ASI_PST32_P:
15437c478bdstevel@tonic-gate	case ASI_PST32_S:
15447c478bdstevel@tonic-gate		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
15457c478bdstevel@tonic-gate		if (ftt != ftt_none)
15467c478bdstevel@tonic-gate			return (ftt);
15477c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
15487c478bdstevel@tonic-gate		for (i = 0, j = 0x2; i <= 1; i++, j >>= 1) {
15497c478bdstevel@tonic-gate			if ((msk & j) == j)
15507c478bdstevel@tonic-gate				res.i[i] = k.i[i];
15517c478bdstevel@tonic-gate			else
15527c478bdstevel@tonic-gate				res.i[i] = l.i[i];
15537c478bdstevel@tonic-gate		}
15547c478bdstevel@tonic-gate		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
15557c478bdstevel@tonic-gate		if (ftt != ftt_none)
15567c478bdstevel@tonic-gate			return (ftt);
15577c478bdstevel@tonic-gate		break;
15587c478bdstevel@tonic-gate	case ASI_PST32_PL:
15597c478bdstevel@tonic-gate	case ASI_PST32_SL:
15607c478bdstevel@tonic-gate		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
15617c478bdstevel@tonic-gate		if (ftt != ftt_none)
15627c478bdstevel@tonic-gate			return (ftt);
15637c478bdstevel@tonic-gate		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
1564428cee1jfrank		for (h = 7, i = 0, j = 1; i <= 4; h -= 4, i += 4, j <<= 1) {
15657c478bdstevel@tonic-gate			if ((msk & j) == j) {
1566428cee1jfrank				res.c[i] = k.c[h];
1567428cee1jfrank				res.c[i+1] = k.c[h-1];
1568428cee1jfrank				res.c[i+2] = k.c[h-2];
1569428cee1jfrank				res.c[i+3] = k.c[h-3];
15707c478bdstevel@tonic-gate			} else {
1571428cee1jfrank				res.c[i] = l.c[i];
1572428cee1jfrank				res.c[i+1] = l.c[i+1];
1573428cee1jfrank				res.c[i+2] = l.c[i+2];
1574428cee1jfrank				res.c[i+3] = l.c[i+3];
15757c478bdstevel@tonic-gate			}
15767c478bdstevel@tonic-gate		}
15777c478bdstevel@tonic-gate		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
15787c478bdstevel@tonic-gate		if (ftt != ftt_none)
15797c478bdstevel@tonic-gate			return (ftt);
15807c478bdstevel@tonic-gate		break;
15817c478bdstevel@tonic-gate	}
15827c478bdstevel@tonic-gate
15837c478bdstevel@tonic-gate	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
15847c478bdstevel@tonic-gate	pregs->r_npc += 4;
15857c478bdstevel@tonic-gate	return (ftt_none);
15867c478bdstevel@tonic-gate}
15877c478bdstevel@tonic-gate
15887c478bdstevel@tonic-gate/*
15897c478bdstevel@tonic-gate * Simulator for short load/stores between floating-point unit and memory.
15907c478bdstevel@tonic-gate */
15917c478bdstevel@tonic-gatestatic enum ftt_type
15927c478bdstevel@tonic-gatevis_short_fls(
15937c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
15947c478bdstevel@tonic-gate	vis_inst_type	inst,	/* ISE instruction to simulate. */
15957c478bdstevel@tonic-gate	struct regs	*pregs,	/* Pointer to PCB image of registers. */
15967c478bdstevel@tonic-gate	void		*prw,	/* Pointer to locals and ins. */
15977c478bdstevel@tonic-gate	uint_t		asi)	/* asi to emulate! */
15987c478bdstevel@tonic-gate{
15997c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
16007c478bdstevel@tonic-gate	uint_t	opf;
16017c478bdstevel@tonic-gate	uint64_t ea, tea;
16027c478bdstevel@tonic-gate	union {
16037c478bdstevel@tonic-gate		freg_type	f;
16047c478bdstevel@tonic-gate		uint64_t	ll;
16057c478bdstevel@tonic-gate		uint32_t	i[2];
16067c478bdstevel@tonic-gate		uint16_t	s[4];
16077c478bdstevel@tonic-gate		uint8_t		c[8];
16087c478bdstevel@tonic-gate	} k;
16097c478bdstevel@tonic-gate	union {
16107c478bdstevel@tonic-gate		vis_inst_type	inst;
16117c478bdstevel@tonic-gate		int		i;
16127c478bdstevel@tonic-gate	} fp;
16137c478bdstevel@tonic-gate	enum ftt_type   ftt = ftt_none;
16147c478bdstevel@tonic-gate	ushort_t us;
16157c478bdstevel@tonic-gate	uchar_t uc;
16167c478bdstevel@tonic-gate
16177c478bdstevel@tonic-gate	nrs1 = inst.rs1;
16187c478bdstevel@tonic-gate	nrs2 = inst.rs2;
16197c478bdstevel@tonic-gate	nrd = inst.rd;
16207c478bdstevel@tonic-gate	if ((nrd & 1) == 1) 		/* fix register encoding */
16217c478bdstevel@tonic-gate		nrd = (nrd & 0x1e) | 0x20;
16227c478bdstevel@tonic-gate	opf = inst.opf;
16237c478bdstevel@tonic-gate	fp.inst = inst;
16247c478bdstevel@tonic-gate	if ((opf & 0x100) == 0) { /* effective address = rs1 + rs2 */
16257c478bdstevel@tonic-gate		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
16267c478bdstevel@tonic-gate		if (ftt != ftt_none)
16277c478bdstevel@tonic-gate			return (ftt);
16287c478bdstevel@tonic-gate		ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tea);
16297c478bdstevel@tonic-gate		if (ftt != ftt_none)
16307c478bdstevel@tonic-gate			return (ftt);
16317c478bdstevel@tonic-gate		ea += tea;
16327c478bdstevel@tonic-gate	} else {	/* effective address = rs1 + imm13 */
16337c478bdstevel@tonic-gate		fp.inst = inst;
16347c478bdstevel@tonic-gate		ea = (fp.i << 19) >> 19;	/* Extract simm13 field. */
16357c478bdstevel@tonic-gate		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &tea);
16367c478bdstevel@tonic-gate		if (ftt != ftt_none)
16377c478bdstevel@tonic-gate			return (ftt);
16387c478bdstevel@tonic-gate		ea += tea;
16397c478bdstevel@tonic-gate	}
16407c478bdstevel@tonic-gate	if (get_udatamodel() == DATAMODEL_ILP32)
16417c478bdstevel@tonic-gate		ea = (uint64_t)(caddr32_t)ea;
16427c478bdstevel@tonic-gate
16437c478bdstevel@tonic-gate	pfpsd->fp_trapaddr = (caddr_t)ea; /* setup bad addr in case we trap */
16447c478bdstevel@tonic-gate	switch (asi) {
16457c478bdstevel@tonic-gate	case ASI_FL8_P:
16467c478bdstevel@tonic-gate	case ASI_FL8_S:
16477c478bdstevel@tonic-gate	case ASI_FL8_PL:		/* little-endian */
16487c478bdstevel@tonic-gate	case ASI_FL8_SL:
16497c478bdstevel@tonic-gate		if ((inst.op3 & 7) == 3) {	/* load byte */
16507c478bdstevel@tonic-gate			if (fuword8((void *)ea, &uc) == -1)
16517c478bdstevel@tonic-gate				return (ftt_fault);
16527c478bdstevel@tonic-gate			k.ll = 0;
16537c478bdstevel@tonic-gate			k.c[7] = uc;
16547c478bdstevel@tonic-gate			_fp_pack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16557c478bdstevel@tonic-gate		} else {			/* store byte */
16567c478bdstevel@tonic-gate			_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16577c478bdstevel@tonic-gate			uc = k.c[7];
16587c478bdstevel@tonic-gate			if (subyte((caddr_t)ea, uc) == -1)
16597c478bdstevel@tonic-gate				return (ftt_fault);
16607c478bdstevel@tonic-gate		}
16617c478bdstevel@tonic-gate		break;
16627c478bdstevel@tonic-gate	case ASI_FL16_P:
16637c478bdstevel@tonic-gate	case ASI_FL16_S:
16647c478bdstevel@tonic-gate		if ((ea & 1) == 1)
16657c478bdstevel@tonic-gate			return (ftt_alignment);
16667c478bdstevel@tonic-gate		if ((inst.op3 & 7) == 3) {	/* load short */
16677c478bdstevel@tonic-gate			if (fuword16((void *)ea, &us) == -1)
16687c478bdstevel@tonic-gate				return (ftt_fault);
16697c478bdstevel@tonic-gate			k.ll = 0;
16707c478bdstevel@tonic-gate			k.s[3] = us;
16717c478bdstevel@tonic-gate			_fp_pack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16727c478bdstevel@tonic-gate		} else {			/* store short */
16737c478bdstevel@tonic-gate			_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16747c478bdstevel@tonic-gate			us = k.s[3];
16757c478bdstevel@tonic-gate			if (suword16((caddr_t)ea, us) == -1)
16767c478bdstevel@tonic-gate				return (ftt_fault);
16777c478bdstevel@tonic-gate		}
16787c478bdstevel@tonic-gate		break;
16797c478bdstevel@tonic-gate	case ASI_FL16_PL:		/* little-endian */
16807c478bdstevel@tonic-gate	case ASI_FL16_SL:
16817c478bdstevel@tonic-gate		if ((ea & 1) == 1)
16827c478bdstevel@tonic-gate			return (ftt_alignment);
16837c478bdstevel@tonic-gate		if ((inst.op3 & 7) == 3) {	/* load short */
16847c478bdstevel@tonic-gate			if (fuword16((void *)ea, &us) == -1)
16857c478bdstevel@tonic-gate				return (ftt_fault);
16867c478bdstevel@tonic-gate			k.ll = 0;
16877c478bdstevel@tonic-gate			k.c[6] = (uchar_t)us;
16887c478bdstevel@tonic-gate			k.c[7] = (uchar_t)((us & 0xff00) >> 8);
16897c478bdstevel@tonic-gate			_fp_pack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16907c478bdstevel@tonic-gate		} else {			/* store short */
16917c478bdstevel@tonic-gate			_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16927c478bdstevel@tonic-gate			uc = k.c[7];
16937c478bdstevel@tonic-gate			us = (ushort_t)((uc << 8) | k.c[6]);
16947c478bdstevel@tonic-gate			if (suword16((void *)ea, us) == -1)
16957c478bdstevel@tonic-gate				return (ftt_fault);
16967c478bdstevel@tonic-gate		}
16977c478bdstevel@tonic-gate		break;
16987c478bdstevel@tonic-gate	}
16997c478bdstevel@tonic-gate
17007c478bdstevel@tonic-gate	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
17017c478bdstevel@tonic-gate	pregs->r_npc += 4;
17027c478bdstevel@tonic-gate	return (ftt_none);
17037c478bdstevel@tonic-gate}
17047c478bdstevel@tonic-gate
17057c478bdstevel@tonic-gate/*
17067c478bdstevel@tonic-gate * Simulator for block loads and stores between floating-point unit and memory.
17075ccb2ffwh * We pass the addrees of ea to sync_data_memory() to flush the Ecache.
17085ccb2ffwh * Sync_data_memory() calls platform dependent code to flush the Ecache.
17097c478bdstevel@tonic-gate */
17107c478bdstevel@tonic-gatestatic enum ftt_type
17117c478bdstevel@tonic-gatevis_blk_fldst(
17127c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
17137c478bdstevel@tonic-gate	vis_inst_type	inst,	/* ISE instruction to simulate. */
17147c478bdstevel@tonic-gate	struct regs	*pregs,	/* Pointer to PCB image of registers. */
17157c478bdstevel@tonic-gate	void		*prw,	/* Pointer to locals and ins. */
17167c478bdstevel@tonic-gate	uint_t		asi)	/* asi to emulate! */
17177c478bdstevel@tonic-gate{
17187c478bdstevel@tonic-gate	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
17197c478bdstevel@tonic-gate	uint_t	opf, h, i, j;
17207c478bdstevel@tonic-gate	uint64_t ea, tea;
17217c478bdstevel@tonic-gate	union {
17227c478bdstevel@tonic-gate		freg_type	f;
17237c478bdstevel@tonic-gate		uint64_t	ll;
17247c478bdstevel@tonic-gate		uint8_t		c[8];
17257c478bdstevel@tonic-gate	} k, l;
17267c478bdstevel@tonic-gate	union {
17277c478bdstevel@tonic-gate		vis_inst_type	inst;
17287c478bdstevel@tonic-gate		int32_t		i;
17297c478bdstevel@tonic-gate	} fp;
17307c478bdstevel@tonic-gate	enum ftt_type   ftt;
17317c478bdstevel@tonic-gate	boolean_t little_endian = B_FALSE;
17327c478bdstevel@tonic-gate
17337c478bdstevel@tonic-gate	nrs1 = inst.rs1;
17347c478bdstevel@tonic-gate	nrs2 = inst.rs2;
17357c478bdstevel@tonic-gate	nrd = inst.rd;
17367c478bdstevel@tonic-gate	if ((nrd & 1) == 1) 		/* fix register encoding */
17377c478bdstevel@tonic-gate		nrd = (nrd & 0x1e) | 0x20;
17387c478bdstevel@tonic-gate
17397c478bdstevel@tonic-gate	/* ensure register is 8-double precision aligned */
17407c478bdstevel@tonic-gate	if ((nrd & 0xf) != 0)
17417c478bdstevel@tonic-gate		return (ftt_unimplemented);
17427c478bdstevel@tonic-gate
17437c478bdstevel@tonic-gate	opf = inst.opf;
17447c478bdstevel@tonic-gate	if ((opf & 0x100) == 0) { 	/* effective address = rs1 + rs2 */
17457c478bdstevel@tonic-gate		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
17467c478bdstevel@tonic-gate		if (ftt != ftt_none)
17477c478bdstevel@tonic-gate			return (ftt);
17487c478bdstevel@tonic-gate		ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tea);
17497c478bdstevel@tonic-gate		if (ftt != ftt_none)
17507c478bdstevel@tonic-gate			return (ftt);
17517c478bdstevel@tonic-gate		ea += tea;
17527c478bdstevel@tonic-gate	} else {			/* effective address = rs1 + imm13 */
17537c478bdstevel@tonic-gate		fp.inst = inst;
17547c478bdstevel@tonic-gate		ea = (fp.i << 19) >> 19;	/* Extract simm13 field. */
17557c478bdstevel@tonic-gate		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &tea);
17567c478bdstevel@tonic-gate		if (ftt != ftt_none)
17577c478bdstevel@tonic-gate			return (ftt);
17587c478bdstevel@tonic-gate		ea += tea;
17597c478bdstevel@tonic-gate	}
17607c478bdstevel@tonic-gate	if ((ea & 0x3F) != 0)		/* Require 64 byte-alignment. */
17617c478bdstevel@tonic-gate		return (ftt_alignment);
17627c478bdstevel@tonic-gate
17637c478bdstevel@tonic-gate	pfpsd->fp_trapaddr = (caddr_t)ea; /* setup bad addr in case we trap */
17647c478bdstevel@tonic-gate	switch (asi) {
17657c478bdstevel@tonic-gate	case ASI_BLK_AIUPL:
17667c478bdstevel@tonic-gate	case ASI_BLK_AIUSL:
17677c478bdstevel@tonic-gate	case ASI_BLK_PL:
17687c478bdstevel@tonic-gate	case ASI_BLK_SL:
17697c478bdstevel@tonic-gate		little_endian = B_TRUE;
17707c478bdstevel@tonic-gate		/* FALLTHROUGH */
17717c478bdstevel@tonic-gate	case ASI_BLK_AIUP:
17727c478bdstevel@tonic-gate	case ASI_BLK_AIUS:
17737c478bdstevel@tonic-gate	case ASI_BLK_P:
17747c478bdstevel@tonic-gate	case ASI_BLK_S:
17757c478bdstevel@tonic-gate	case ASI_BLK_COMMIT_P:
17767c478bdstevel@tonic-gate	case ASI_BLK_COMMIT_S:
17777c478bdstevel@tonic-gate		if ((inst.op3 & 7) == 3) {	/* lddf */
1778b1b05f9arutz			for (i = 0; i < 8; i++, nrd += 2) {
1779b1b05f9arutz				ftt = _fp_read_extword((uint64_t *)ea, &k.ll,
1780b1b05f9arutz				    pfpsd);
1781b1b05f9arutz				if (ftt != ftt_none)
1782b1b05f9arutz					return (ftt);
1783b1b05f9arutz				if (little_endian) {
1784b1b05f9arutz					for (j = 0, h = 7; j < 8; j++, h--)
1785b1b05f9arutz						l.c[h] = k.c[j];
1786b1b05f9arutz					k.ll = l.ll;
1787b1b05f9arutz				}
1788b1b05f9arutz				_fp_pack_extword(pfpsd, &k.f.FPU_DREG_FIELD,
1789b1b05f9arutz				    nrd);
1790b1b05f9arutz				ea += 8;
17917c478bdstevel@tonic-gate			}
17927c478bdstevel@tonic-gate		} else {			/* stdf */
1793b1b05f9arutz			for (i = 0; i < 8; i++, nrd += 2) {
1794b1b05f9arutz				_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD,
1795b1b05f9arutz				    nrd);
1796b1b05f9arutz				if (little_endian) {
1797b1b05f9arutz					for (j = 0, h = 7; j < 8; j++, h--)
1798b1b05f9arutz						l.c[h] = k.c[j];
1799b1b05f9arutz					k.ll = l.ll;
1800b1b05f9arutz				}
1801b1b05f9arutz				ftt = _fp_write_extword((uint64_t *)ea, k.ll,
1802b1b05f9arutz				    pfpsd);
1803b1b05f9arutz				if (ftt != ftt_none)
1804b1b05f9arutz					return (ftt);
1805b1b05f9arutz				ea += 8;
18067c478bdstevel@tonic-gate			}
18077c478bdstevel@tonic-gate		}
18087c478bdstevel@tonic-gate		if ((asi == ASI_BLK_COMMIT_P) || (asi == ASI_BLK_COMMIT_S))
18095ccb2ffwh			sync_data_memory((caddr_t)(ea - 64), 64);
18107c478bdstevel@tonic-gate		break;
18117c478bdstevel@tonic-gate	default:
18127c478bdstevel@tonic-gate		/* addr of unimp inst */
18137c478bdstevel@tonic-gate		pfpsd->fp_trapaddr = (caddr_t)pregs->r_pc;
18147c478bdstevel@tonic-gate		return (ftt_unimplemented);
18157c478bdstevel@tonic-gate	}
18167c478bdstevel@tonic-gate
18177c478bdstevel@tonic-gate	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
18187c478bdstevel@tonic-gate	pregs->r_npc += 4;
18197c478bdstevel@tonic-gate	return (ftt_none);
18207c478bdstevel@tonic-gate}
18217c478bdstevel@tonic-gate
18227c478bdstevel@tonic-gate/*
18237c478bdstevel@tonic-gate * Simulator for rd %gsr instruction.
18247c478bdstevel@tonic-gate */
18257c478bdstevel@tonic-gateenum ftt_type
18267c478bdstevel@tonic-gatevis_rdgsr(
18277c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
18287c478bdstevel@tonic-gate	fp_inst_type	pinst,	/* FPU instruction to simulate. */
18297c478bdstevel@tonic-gate	struct regs	*pregs,	/* Pointer to PCB image of registers. */
18307c478bdstevel@tonic-gate	void		*prw,	/* Pointer to locals and ins. */
18317c478bdstevel@tonic-gate	kfpu_t		*fp)	/* Need to fp to access gsr reg */
18327c478bdstevel@tonic-gate{
18337c478bdstevel@tonic-gate	uint_t nrd;
18347c478bdstevel@tonic-gate	uint64_t r;
18357c478bdstevel@tonic-gate	enum ftt_type ftt = ftt_none;
18367c478bdstevel@tonic-gate
18377c478bdstevel@tonic-gate	nrd = pinst.rd;
18387c478bdstevel@tonic-gate
18395892374df	r = pfpsd->fp_current_read_gsr(fp);
18407c478bdstevel@tonic-gate	ftt = write_iureg(pfpsd, nrd, pregs, prw, &r);
18417c478bdstevel@tonic-gate	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
18427c478bdstevel@tonic-gate	pregs->r_npc += 4;
18437c478bdstevel@tonic-gate	return (ftt);
18447c478bdstevel@tonic-gate}
18457c478bdstevel@tonic-gate
18467c478bdstevel@tonic-gate/*
18477c478bdstevel@tonic-gate * Simulator for wr %gsr instruction.
18487c478bdstevel@tonic-gate */
18497c478bdstevel@tonic-gateenum ftt_type
18507c478bdstevel@tonic-gatevis_wrgsr(
18517c478bdstevel@tonic-gate	fp_simd_type	*pfpsd,	/* FPU simulator data. */
18527c478bdstevel@tonic-gate	fp_inst_type	pinst,	/* FPU instruction to simulate. */
18537c478bdstevel@tonic-gate	struct regs	*pregs,	/* Pointer to PCB image of registers. */
18547c478bdstevel@tonic-gate	void		*prw,	/* Pointer to locals and ins. */
18557c478bdstevel@tonic-gate	kfpu_t		*fp)	/* Need to fp to access gsr reg */
18567c478bdstevel@tonic-gate{
18577c478bdstevel@tonic-gate	uint_t nrs1;
18587c478bdstevel@tonic-gate	uint64_t r, r1, r2;
18597c478bdstevel@tonic-gate	enum ftt_type ftt = ftt_none;
18607c478bdstevel@tonic-gate
18617c478bdstevel@tonic-gate	nrs1 = pinst.rs1;
18627c478bdstevel@tonic-gate	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &r1);
18637c478bdstevel@tonic-gate	if (ftt != ftt_none)
18647c478bdstevel@tonic-gate		return (ftt);
18657c478bdstevel@tonic-gate	if (pinst.ibit == 0) {	/* copy the value in r[rs2] */
18667c478bdstevel@tonic-gate		uint_t nrs2;
18677c478bdstevel@tonic-gate
18687c478bdstevel@tonic-gate		nrs2 = pinst.rs2;
18697c478bdstevel@tonic-gate		ftt = read_iureg(pfpsd, nrs2, pregs, prw, &r2);
18707c478bdstevel@tonic-gate		if (ftt != ftt_none)
18717c478bdstevel@tonic-gate			return (ftt);
18727c478bdstevel@tonic-gate	} else {	/* use sign_ext(simm13) */
18737c478bdstevel@tonic-gate		union {
18747c478bdstevel@tonic-gate			fp_inst_type	inst;
18757c478bdstevel@tonic-gate			uint32_t	i;
18767c478bdstevel@tonic-gate		} fp;
18777c478bdstevel@tonic-gate
18787c478bdstevel@tonic-gate		fp.inst = pinst;		/* Extract simm13 field */
18797c478bdstevel@tonic-gate		r2 = (fp.i << 19) >> 19;
18807c478bdstevel@tonic-gate	}
18817c478bdstevel@tonic-gate	r = r1 ^ r2;
18825892374df	pfpsd->fp_current_write_gsr(r, fp);
18837c478bdstevel@tonic-gate	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
18847c478bdstevel@tonic-gate	pregs->r_npc += 4;
18857c478bdstevel@tonic-gate	return (ftt);
18867c478bdstevel@tonic-gate}
18877c478bdstevel@tonic-gate
18887c478bdstevel@tonic-gate/*
18897c478bdstevel@tonic-gate * This is the loadable module wrapper.
18907c478bdstevel@tonic-gate */
18917c478bdstevel@tonic-gate#include <sys/errno.h>
18927c478bdstevel@tonic-gate#include <sys/modctl.h>
18937c478bdstevel@tonic-gate
18947c478bdstevel@tonic-gate/*
18957c478bdstevel@tonic-gate * Module linkage information for the kernel.
18967c478bdstevel@tonic-gate */
18977c478bdstevel@tonic-gateextern struct mod_ops mod_miscops;
18987c478bdstevel@tonic-gate
18997c478bdstevel@tonic-gatestatic struct modlmisc modlmisc = {
19007c478bdstevel@tonic-gate	&mod_miscops,
19017c478bdstevel@tonic-gate	"vis fp simulation",
19027c478bdstevel@tonic-gate};
19037c478bdstevel@tonic-gate
19047c478bdstevel@tonic-gatestatic struct modlinkage modlinkage = {
19057c478bdstevel@tonic-gate	MODREV_1, (void *)&modlmisc, NULL
19067c478bdstevel@tonic-gate};
19077c478bdstevel@tonic-gate
19087c478bdstevel@tonic-gateint
19097c478bdstevel@tonic-gate_init(void)
19107c478bdstevel@tonic-gate{
19117c478bdstevel@tonic-gate	return (mod_install(&modlinkage));
19127c478bdstevel@tonic-gate}
19137c478bdstevel@tonic-gate
19147c478bdstevel@tonic-gateint
19157c478bdstevel@tonic-gate_info(struct modinfo *modinfop)
19167c478bdstevel@tonic-gate{
19177c478bdstevel@tonic-gate	return (mod_info(&modlinkage, modinfop));
19187c478bdstevel@tonic-gate}
1919