xref: /minix3/sys/arch/x86/include/ieee.h (revision f6aac1c3b5ca21b829888677e8ee6bc9cda07e52)
1*f6aac1c3SLionel Sambuc /*	$NetBSD: ieee.h,v 1.11 2010/09/15 16:11:28 christos Exp $ */
2*f6aac1c3SLionel Sambuc 
3*f6aac1c3SLionel Sambuc /*
4*f6aac1c3SLionel Sambuc  * Copyright (c) 1992, 1993
5*f6aac1c3SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
6*f6aac1c3SLionel Sambuc  *
7*f6aac1c3SLionel Sambuc  * This software was developed by the Computer Systems Engineering group
8*f6aac1c3SLionel Sambuc  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9*f6aac1c3SLionel Sambuc  * contributed to Berkeley.
10*f6aac1c3SLionel Sambuc  *
11*f6aac1c3SLionel Sambuc  * All advertising materials mentioning features or use of this software
12*f6aac1c3SLionel Sambuc  * must display the following acknowledgement:
13*f6aac1c3SLionel Sambuc  *	This product includes software developed by the University of
14*f6aac1c3SLionel Sambuc  *	California, Lawrence Berkeley Laboratory.
15*f6aac1c3SLionel Sambuc  *
16*f6aac1c3SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
17*f6aac1c3SLionel Sambuc  * modification, are permitted provided that the following conditions
18*f6aac1c3SLionel Sambuc  * are met:
19*f6aac1c3SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
20*f6aac1c3SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
21*f6aac1c3SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
22*f6aac1c3SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
23*f6aac1c3SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
24*f6aac1c3SLionel Sambuc  * 3. Neither the name of the University nor the names of its contributors
25*f6aac1c3SLionel Sambuc  *    may be used to endorse or promote products derived from this software
26*f6aac1c3SLionel Sambuc  *    without specific prior written permission.
27*f6aac1c3SLionel Sambuc  *
28*f6aac1c3SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29*f6aac1c3SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30*f6aac1c3SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31*f6aac1c3SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32*f6aac1c3SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33*f6aac1c3SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34*f6aac1c3SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35*f6aac1c3SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36*f6aac1c3SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37*f6aac1c3SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38*f6aac1c3SLionel Sambuc  * SUCH DAMAGE.
39*f6aac1c3SLionel Sambuc  *
40*f6aac1c3SLionel Sambuc  *	@(#)ieee.h	8.1 (Berkeley) 6/11/93
41*f6aac1c3SLionel Sambuc  */
42*f6aac1c3SLionel Sambuc 
43*f6aac1c3SLionel Sambuc /*
44*f6aac1c3SLionel Sambuc  * ieee.h defines the machine-dependent layout of the machine's IEEE
45*f6aac1c3SLionel Sambuc  * floating point.  It does *not* define (yet?) any of the rounding
46*f6aac1c3SLionel Sambuc  * mode bits, exceptions, and so forth.
47*f6aac1c3SLionel Sambuc  */
48*f6aac1c3SLionel Sambuc 
49*f6aac1c3SLionel Sambuc #include <sys/ieee754.h>
50*f6aac1c3SLionel Sambuc 
51*f6aac1c3SLionel Sambuc #define	EXT_EXPBITS	15
52*f6aac1c3SLionel Sambuc #define EXT_FRACHBITS	32
53*f6aac1c3SLionel Sambuc #define	EXT_FRACLBITS	32
54*f6aac1c3SLionel Sambuc #define	EXT_FRACBITS	(EXT_FRACLBITS + EXT_FRACHBITS)
55*f6aac1c3SLionel Sambuc 
56*f6aac1c3SLionel Sambuc #define	EXT_TO_ARRAY32(u, a) do {			\
57*f6aac1c3SLionel Sambuc 	(a)[0] = (uint32_t)(u).extu_ext.ext_fracl;	\
58*f6aac1c3SLionel Sambuc 	(a)[1] = (uint32_t)(u).extu_ext.ext_frach;	\
59*f6aac1c3SLionel Sambuc } while(/*CONSTCOND*/0)
60*f6aac1c3SLionel Sambuc 
61*f6aac1c3SLionel Sambuc /*
62*f6aac1c3SLionel Sambuc  * struct ieee_ext is the raw storage layout of the 80-bit
63*f6aac1c3SLionel Sambuc  * extended-precision type as implemented by the FPU.  Per the
64*f6aac1c3SLionel Sambuc  * respective ABI specifications, it is followed by a tail padding of
65*f6aac1c3SLionel Sambuc  *
66*f6aac1c3SLionel Sambuc  *   amd64: 48 bits,
67*f6aac1c3SLionel Sambuc  *   i386:  16 bits.
68*f6aac1c3SLionel Sambuc  */
69*f6aac1c3SLionel Sambuc struct ieee_ext {
70*f6aac1c3SLionel Sambuc 	u_int	ext_fracl:EXT_FRACLBITS;
71*f6aac1c3SLionel Sambuc 	u_int	ext_frach:EXT_FRACHBITS;
72*f6aac1c3SLionel Sambuc #if 0
73*f6aac1c3SLionel Sambuc 	u_int	ext_int:1;
74*f6aac1c3SLionel Sambuc #endif
75*f6aac1c3SLionel Sambuc 	u_int	ext_exp:EXT_EXPBITS;
76*f6aac1c3SLionel Sambuc 	u_int	ext_sign:1;
77*f6aac1c3SLionel Sambuc };
78*f6aac1c3SLionel Sambuc 
79*f6aac1c3SLionel Sambuc /*
80*f6aac1c3SLionel Sambuc  * Floats whose exponent is in [1..INFNAN) (of whatever type) are
81*f6aac1c3SLionel Sambuc  * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.
82*f6aac1c3SLionel Sambuc  * Floats whose exponent is zero are either zero (iff all fraction
83*f6aac1c3SLionel Sambuc  * bits are zero) or subnormal values.
84*f6aac1c3SLionel Sambuc  *
85*f6aac1c3SLionel Sambuc  * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
86*f6aac1c3SLionel Sambuc  * high fraction; if the bit is set, it is a `quiet NaN'.
87*f6aac1c3SLionel Sambuc  */
88*f6aac1c3SLionel Sambuc #define	EXT_EXP_INFNAN	0x7fff
89*f6aac1c3SLionel Sambuc #define	EXT_EXP_INF	0x7fff
90*f6aac1c3SLionel Sambuc #define	EXT_EXP_NAN	0x7fff
91*f6aac1c3SLionel Sambuc 
92*f6aac1c3SLionel Sambuc #if 0
93*f6aac1c3SLionel Sambuc #define	SNG_QUIETNAN	(1 << 22)
94*f6aac1c3SLionel Sambuc #define	DBL_QUIETNAN	(1 << 19)
95*f6aac1c3SLionel Sambuc #define	EXT_QUIETNAN	(1 << 30)
96*f6aac1c3SLionel Sambuc #endif
97*f6aac1c3SLionel Sambuc 
98*f6aac1c3SLionel Sambuc /*
99*f6aac1c3SLionel Sambuc  * Exponent biases.
100*f6aac1c3SLionel Sambuc  */
101*f6aac1c3SLionel Sambuc #define	EXT_EXP_BIAS	16383
102*f6aac1c3SLionel Sambuc 
103*f6aac1c3SLionel Sambuc /*
104*f6aac1c3SLionel Sambuc  * Convenience data structures.
105*f6aac1c3SLionel Sambuc  */
106*f6aac1c3SLionel Sambuc union ieee_ext_u {
107*f6aac1c3SLionel Sambuc 	long double		extu_ld;
108*f6aac1c3SLionel Sambuc 	struct ieee_ext		extu_ext;
109*f6aac1c3SLionel Sambuc };
110*f6aac1c3SLionel Sambuc 
111*f6aac1c3SLionel Sambuc #define extu_exp	extu_ext.ext_exp
112*f6aac1c3SLionel Sambuc #define extu_sign	extu_ext.ext_sign
113*f6aac1c3SLionel Sambuc #define extu_fracl	extu_ext.ext_fracl
114*f6aac1c3SLionel Sambuc #define extu_frach	extu_ext.ext_frach
115*f6aac1c3SLionel Sambuc 
116*f6aac1c3SLionel Sambuc #define LDBL_NBIT	0x80000000
117*f6aac1c3SLionel Sambuc #define mask_nbit_l(u)	((u).extu_frach &= ~LDBL_NBIT)
118