fpu.h revision 4
14Srgrimes/*-
24Srgrimes * Copyright (c) 1990 The Regents of the University of California.
34Srgrimes * All rights reserved.
44Srgrimes *
54Srgrimes * This code is derived from software contributed to Berkeley by
64Srgrimes * William Jolitz.
74Srgrimes *
84Srgrimes * Redistribution and use in source and binary forms, with or without
94Srgrimes * modification, are permitted provided that the following conditions
104Srgrimes * are met:
114Srgrimes * 1. Redistributions of source code must retain the above copyright
124Srgrimes *    notice, this list of conditions and the following disclaimer.
134Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
144Srgrimes *    notice, this list of conditions and the following disclaimer in the
154Srgrimes *    documentation and/or other materials provided with the distribution.
164Srgrimes * 3. All advertising materials mentioning features or use of this software
174Srgrimes *    must display the following acknowledgement:
184Srgrimes *	This product includes software developed by the University of
194Srgrimes *	California, Berkeley and its contributors.
204Srgrimes * 4. Neither the name of the University nor the names of its contributors
214Srgrimes *    may be used to endorse or promote products derived from this software
224Srgrimes *    without specific prior written permission.
234Srgrimes *
244Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
254Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
264Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
274Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
284Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
294Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
304Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
314Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
324Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
334Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
344Srgrimes * SUCH DAMAGE.
354Srgrimes *
364Srgrimes *	@(#)npx.h	5.3 (Berkeley) 1/18/91
374Srgrimes *
384Srgrimes * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
394Srgrimes * --------------------         -----   ----------------------
404Srgrimes * CURRENT PATCH LEVEL:         1       00154
414Srgrimes * --------------------         -----   ----------------------
424Srgrimes *
434Srgrimes * 20 Apr 93	Bruce Evans		New npx-0.5 code
444Srgrimes *
454Srgrimes */
464Srgrimes
474Srgrimes/*
484Srgrimes * 287/387 NPX Coprocessor Data Structures and Constants
494Srgrimes * W. Jolitz 1/90
504Srgrimes */
514Srgrimes
524Srgrimes#ifndef	___NPX87___
534Srgrimes#define	___NPX87___
544Srgrimes
554Srgrimes/* Environment information of floating point unit */
564Srgrimesstruct	env87 {
574Srgrimes	long	en_cw;		/* control word (16bits) */
584Srgrimes	long	en_sw;		/* status word (16bits) */
594Srgrimes	long	en_tw;		/* tag word (16bits) */
604Srgrimes	long	en_fip;		/* floating point instruction pointer */
614Srgrimes	u_short	en_fcs;		/* floating code segment selector */
624Srgrimes	u_short	en_opcode;	/* opcode last executed (11 bits ) */
634Srgrimes	long	en_foo;		/* floating operand offset */
644Srgrimes	long	en_fos;		/* floating operand segment selector */
654Srgrimes};
664Srgrimes
674Srgrimes/* Contents of each floating point accumulator */
684Srgrimesstruct	fpacc87 {
694Srgrimes#ifdef dontdef /* too unportable */
704Srgrimes	u_long	fp_mantlo;	/* mantissa low (31:0) */
714Srgrimes	u_long	fp_manthi;	/* mantissa high (63:32) */
724Srgrimes	int	fp_exp:15;	/* exponent */
734Srgrimes	int	fp_sgn:1;	/* mantissa sign */
744Srgrimes#else
754Srgrimes	u_char	fp_bytes[10];
764Srgrimes#endif
774Srgrimes};
784Srgrimes
794Srgrimes/* Floating point context */
804Srgrimesstruct	save87 {
814Srgrimes	struct	env87 sv_env;		/* floating point control/status */
824Srgrimes	struct	fpacc87	sv_ac[8];	/* accumulator contents, 0-7 */
834Srgrimes#ifndef dontdef
844Srgrimes	u_long	sv_ex_sw;	/* status word for last exception (was pad) */
854Srgrimes	u_long	sv_ex_tw;	/* tag word for last exception (was pad) */
864Srgrimes	u_char	sv_pad[8 * 2 - 2 * 4];	/* bogus historical padding */
874Srgrimes#endif
884Srgrimes};
894Srgrimes
904Srgrimes/* Cyrix EMC memory - mapped coprocessor context switch information */
914Srgrimesstruct	emcsts {
924Srgrimes	long	em_msw;		/* memory mapped status register when swtched */
934Srgrimes	long	em_tar;		/* memory mapped temp A register when swtched */
944Srgrimes	long	em_dl;		/* memory mapped D low register when swtched */
954Srgrimes};
964Srgrimes
974Srgrimes/* Intel prefers long real (53 bit) precision */
984Srgrimes#define	__iBCS_NPXCW__		0x262
994Srgrimes/* wfj prefers temporary real (64 bit) precision */
1004Srgrimes#define	__386BSD_NPXCW__	0x362
1014Srgrimes/*
1024Srgrimes * bde prefers 53 bit precision and all exceptions masked.
1034Srgrimes *
1044Srgrimes * The standard control word from finit is 0x37F, giving:
1054Srgrimes *
1064Srgrimes *	round to nearest
1074Srgrimes *	64-bit precision
1084Srgrimes *	all exceptions masked.
1094Srgrimes *
1104Srgrimes * Now I want:
1114Srgrimes *
1124Srgrimes *	affine mode for 287's (if they work at all) (1 in bitfield 1<<12)
1134Srgrimes *	53-bit precision (2 in bitfield 3<<8)
1144Srgrimes *	overflow exception unmasked (0 in bitfield 1<<3)
1154Srgrimes *	zero divide exception unmasked (0 in bitfield 1<<2)
1164Srgrimes *	invalid-operand exception unmasked (0 in bitfield 1<<0).
1174Srgrimes *
1184Srgrimes * 64-bit precision often gives bad results with high level languages
1194Srgrimes * because it makes the results of calculations depend on whether
1204Srgrimes * intermediate values are stored in memory or in FPU registers.
1214Srgrimes *
1224Srgrimes * The "Intel" and wfj control words have:
1234Srgrimes *
1244Srgrimes *	underflow exception unmasked (0 in bitfield 1<<4)
1254Srgrimes *
1264Srgrimes * but that causes an unexpected exception in the test program 'paranoia'
1274Srgrimes * and makes denormals useless (DBL_MIN / 2 underflows).  It doesn't make
1284Srgrimes * a lot of sense to trap underflow without trapping denormals.
1294Srgrimes *
1304Srgrimes * Later I will want the IEEE default of all exceptions masked.  See the
1314Srgrimes * 0.0 math manpage for why this is better.  The 0.1 math manpage is empty.
1324Srgrimes */
1334Srgrimes#define	__BDE_NPXCW__		0x1272
1344Srgrimes#define	__BETTER_BDE_NPXCW__	0x127f
1354Srgrimes
1364Srgrimes#ifdef __BROKEN_NPXCW__
1374Srgrimes#ifdef __386BSD__
1384Srgrimes#define	__INITIAL_NPXCW__	__386BSD_NPXCW__
1394Srgrimes#else
1404Srgrimes#define	__INITIAL_NPXCW__	__iBCS_NPXCW__
1414Srgrimes#endif
1424Srgrimes#else
1434Srgrimes#define	__INITIAL_NPXCW__	__BDE_NPXCW__
1444Srgrimes#endif
1454Srgrimes
1464Srgrimes#endif	___NPX87___
147