xref: /openbsd-src/sys/arch/mips64/include/ieee.h (revision 972edd4aff9a28151783e54940e12ef1a6f83cda)
1*972edd4aSmiod /*	$OpenBSD: ieee.h,v 1.4 2010/01/23 19:11:21 miod Exp $	*/
2f58c7388Spefo 
3f58c7388Spefo /*
4f58c7388Spefo  * Copyright (c) 1992, 1993
5f58c7388Spefo  *	The Regents of the University of California.  All rights reserved.
6f58c7388Spefo  *
7f58c7388Spefo  * This software was developed by the Computer Systems Engineering group
8f58c7388Spefo  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9f58c7388Spefo  * contributed to Berkeley.
10f58c7388Spefo  *
11f58c7388Spefo  * All advertising materials mentioning features or use of this software
12f58c7388Spefo  * must display the following acknowledgement:
13f58c7388Spefo  *	This product includes software developed by the University of
14f58c7388Spefo  *	California, Lawrence Berkeley Laboratory.
15f58c7388Spefo  *
16f58c7388Spefo  * Redistribution and use in source and binary forms, with or without
17f58c7388Spefo  * modification, are permitted provided that the following conditions
18f58c7388Spefo  * are met:
19f58c7388Spefo  * 1. Redistributions of source code must retain the above copyright
20f58c7388Spefo  *    notice, this list of conditions and the following disclaimer.
21f58c7388Spefo  * 2. Redistributions in binary form must reproduce the above copyright
22f58c7388Spefo  *    notice, this list of conditions and the following disclaimer in the
23f58c7388Spefo  *    documentation and/or other materials provided with the distribution.
2453aa784aSmiod  * 3. Neither the name of the University nor the names of its contributors
25f58c7388Spefo  *    may be used to endorse or promote products derived from this software
26f58c7388Spefo  *    without specific prior written permission.
27f58c7388Spefo  *
28f58c7388Spefo  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29f58c7388Spefo  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30f58c7388Spefo  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31f58c7388Spefo  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32f58c7388Spefo  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33f58c7388Spefo  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34f58c7388Spefo  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35f58c7388Spefo  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36f58c7388Spefo  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37f58c7388Spefo  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38f58c7388Spefo  * SUCH DAMAGE.
39f58c7388Spefo  *
40f58c7388Spefo  *	@(#)ieee.h	8.1 (Berkeley) 6/11/93
41f58c7388Spefo  */
42f58c7388Spefo 
43f58c7388Spefo /*
44f58c7388Spefo  * ieee.h defines the machine-dependent layout of the machine's IEEE
45f58c7388Spefo  * floating point.  It does *not* define (yet?) any of the rounding
46f58c7388Spefo  * mode bits, exceptions, and so forth.
47f58c7388Spefo  */
48f58c7388Spefo 
49f58c7388Spefo /*
50f58c7388Spefo  * Define the number of bits in each fraction and exponent.
51f58c7388Spefo  *
52f58c7388Spefo  *		     k	         k+1
53f58c7388Spefo  * Note that  1.0 x 2  == 0.1 x 2      and that denorms are represented
54f58c7388Spefo  *
55f58c7388Spefo  *					  (-exp_bias+1)
56f58c7388Spefo  * as fractions that look like 0.fffff x 2             .  This means that
57f58c7388Spefo  *
58f58c7388Spefo  *			 -126
59f58c7388Spefo  * the number 0.10000 x 2    , for instance, is the same as the normalized
60f58c7388Spefo  *
61f58c7388Spefo  *		-127			   -128
62f58c7388Spefo  * float 1.0 x 2    .  Thus, to represent 2    , we need one leading zero
63f58c7388Spefo  *
64f58c7388Spefo  *				  -129
65f58c7388Spefo  * in the fraction; to represent 2    , we need two, and so on.  This
66f58c7388Spefo  *
67f58c7388Spefo  *						     (-exp_bias-fracbits+1)
68f58c7388Spefo  * implies that the smallest denormalized number is 2
69f58c7388Spefo  *
70f58c7388Spefo  * for whichever format we are talking about: for single precision, for
71f58c7388Spefo  *
72f58c7388Spefo  *						-126		-149
73f58c7388Spefo  * instance, we get .00000000000000000000001 x 2    , or 1.0 x 2    , and
74f58c7388Spefo  *
75f58c7388Spefo  * -149 == -127 - 23 + 1.
76f58c7388Spefo  */
77f58c7388Spefo #define	SNG_EXPBITS	8
78f58c7388Spefo #define	SNG_FRACBITS	23
79f58c7388Spefo 
80f58c7388Spefo #define	DBL_EXPBITS	11
817b36286aSmartynas #define	DBL_FRACHBITS	20
827b36286aSmartynas #define	DBL_FRACLBITS	32
83f58c7388Spefo #define	DBL_FRACBITS	52
84f58c7388Spefo 
85f58c7388Spefo #define	EXT_EXPBITS	15
867b36286aSmartynas #define	EXT_FRACHBITS	16
877b36286aSmartynas #define	EXT_FRACHMBITS	32
887b36286aSmartynas #define	EXT_FRACLMBITS	32
897b36286aSmartynas #define	EXT_FRACLBITS	32
90f58c7388Spefo #define	EXT_FRACBITS	112
91f58c7388Spefo 
927b36286aSmartynas #define	EXT_IMPLICIT_NBIT
937b36286aSmartynas 
947b36286aSmartynas #define	EXT_TO_ARRAY32(p, a) do {		\
957b36286aSmartynas 	(a)[0] = (uint32_t)(p)->ext_fracl;	\
967b36286aSmartynas 	(a)[1] = (uint32_t)(p)->ext_fraclm;	\
977b36286aSmartynas 	(a)[2] = (uint32_t)(p)->ext_frachm;	\
987b36286aSmartynas 	(a)[3] = (uint32_t)(p)->ext_frach;	\
997b36286aSmartynas } while(0)
1007b36286aSmartynas 
101f58c7388Spefo struct ieee_single {
102*972edd4aSmiod #ifdef __MIPSEB__
103f58c7388Spefo 	u_int	sng_sign:1;
104f58c7388Spefo 	u_int	sng_exp:8;
105f58c7388Spefo 	u_int	sng_frac:23;
106*972edd4aSmiod #else
107*972edd4aSmiod 	u_int	sng_frac:23;
108*972edd4aSmiod 	u_int	sng_exp:8;
109*972edd4aSmiod 	u_int	sng_sign:1;
110*972edd4aSmiod #endif
111f58c7388Spefo };
112f58c7388Spefo 
113f58c7388Spefo struct ieee_double {
114*972edd4aSmiod #ifdef __MIPSEB__
115f58c7388Spefo 	u_int	dbl_sign:1;
116f58c7388Spefo 	u_int	dbl_exp:11;
117f58c7388Spefo 	u_int	dbl_frach:20;
118f58c7388Spefo 	u_int	dbl_fracl;
119*972edd4aSmiod #else
120*972edd4aSmiod 	u_int	dbl_fracl;
121*972edd4aSmiod 	u_int	dbl_frach:20;
122*972edd4aSmiod 	u_int	dbl_exp:11;
123*972edd4aSmiod 	u_int	dbl_sign:1;
124*972edd4aSmiod #endif
125f58c7388Spefo };
126f58c7388Spefo 
127f58c7388Spefo struct ieee_ext {
128*972edd4aSmiod #ifdef __MIPSEB__
129f58c7388Spefo 	u_int	ext_sign:1;
130f58c7388Spefo 	u_int	ext_exp:15;
131f58c7388Spefo 	u_int	ext_frach:16;
132f58c7388Spefo 	u_int	ext_frachm;
133f58c7388Spefo 	u_int	ext_fraclm;
134f58c7388Spefo 	u_int	ext_fracl;
135*972edd4aSmiod #else
136*972edd4aSmiod 	u_int	ext_fracl;
137*972edd4aSmiod 	u_int	ext_fraclm;
138*972edd4aSmiod 	u_int	ext_frachm;
139*972edd4aSmiod 	u_int	ext_frach:16;
140*972edd4aSmiod 	u_int	ext_exp:15;
141*972edd4aSmiod 	u_int	ext_sign:1;
142*972edd4aSmiod #endif
143f58c7388Spefo };
144f58c7388Spefo 
145f58c7388Spefo /*
146f58c7388Spefo  * Floats whose exponent is in [1..INFNAN) (of whatever type) are
147f58c7388Spefo  * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.
148f58c7388Spefo  * Floats whose exponent is zero are either zero (iff all fraction
149f58c7388Spefo  * bits are zero) or subnormal values.
150f58c7388Spefo  *
151f58c7388Spefo  * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
152f58c7388Spefo  * high fraction; if the bit is set, it is a `quiet NaN'.
153f58c7388Spefo  */
154f58c7388Spefo #define	SNG_EXP_INFNAN	255
155f58c7388Spefo #define	DBL_EXP_INFNAN	2047
156f58c7388Spefo #define	EXT_EXP_INFNAN	32767
157f58c7388Spefo 
158f58c7388Spefo #if 0
159f58c7388Spefo #define	SNG_QUIETNAN	(1 << 22)
160f58c7388Spefo #define	DBL_QUIETNAN	(1 << 19)
161f58c7388Spefo #define	EXT_QUIETNAN	(1 << 15)
162f58c7388Spefo #endif
163f58c7388Spefo 
164f58c7388Spefo /*
165f58c7388Spefo  * Exponent biases.
166f58c7388Spefo  */
167f58c7388Spefo #define	SNG_EXP_BIAS	127
168f58c7388Spefo #define	DBL_EXP_BIAS	1023
169f58c7388Spefo #define	EXT_EXP_BIAS	16383
170