ieee.h revision 86551
186551Sjake/*
286551Sjake * Copyright (c) 1992, 1993
386551Sjake *	The Regents of the University of California.  All rights reserved.
486551Sjake *
586551Sjake * This software was developed by the Computer Systems Engineering group
686551Sjake * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
786551Sjake * contributed to Berkeley.
886551Sjake *
986551Sjake * All advertising materials mentioning features or use of this software
1086551Sjake * must display the following acknowledgement:
1186551Sjake *	This product includes software developed by the University of
1286551Sjake *	California, Lawrence Berkeley Laboratory.
1386551Sjake *
1486551Sjake * Redistribution and use in source and binary forms, with or without
1586551Sjake * modification, are permitted provided that the following conditions
1686551Sjake * are met:
1786551Sjake * 1. Redistributions of source code must retain the above copyright
1886551Sjake *    notice, this list of conditions and the following disclaimer.
1986551Sjake * 2. Redistributions in binary form must reproduce the above copyright
2086551Sjake *    notice, this list of conditions and the following disclaimer in the
2186551Sjake *    documentation and/or other materials provided with the distribution.
2286551Sjake * 3. All advertising materials mentioning features or use of this software
2386551Sjake *    must display the following acknowledgement:
2486551Sjake *	This product includes software developed by the University of
2586551Sjake *	California, Berkeley and its contributors.
2686551Sjake * 4. Neither the name of the University nor the names of its contributors
2786551Sjake *    may be used to endorse or promote products derived from this software
2886551Sjake *    without specific prior written permission.
2986551Sjake *
3086551Sjake * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3186551Sjake * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3286551Sjake * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3386551Sjake * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3486551Sjake * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3586551Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3686551Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3786551Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3886551Sjake * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3986551Sjake * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4086551Sjake * SUCH DAMAGE.
4186551Sjake *
4286551Sjake *	@(#)ieee.h	8.1 (Berkeley) 6/11/93
4386551Sjake *	from: NetBSD: ieee.h,v 1.1.1.1 1998/06/20 04:58:51 eeh Exp
4486551Sjake * $FreeBSD: head/sys/sparc64/include/ieee.h 86551 2001-11-18 17:56:46Z jake $
4586551Sjake */
4686551Sjake
4786551Sjake#ifndef _MACHINE_IEEE_H_
4886551Sjake#define	_MACHINE_IEEE_H_
4986551Sjake
5086551Sjake/*
5186551Sjake * ieee.h defines the machine-dependent layout of the machine's IEEE
5286551Sjake * floating point.  It does *not* define (yet?) any of the rounding
5386551Sjake * mode bits, exceptions, and so forth.
5486551Sjake */
5586551Sjake
5686551Sjake/*
5786551Sjake * Define the number of bits in each fraction and exponent.
5886551Sjake *
5986551Sjake *		     k	         k+1
6086551Sjake * Note that  1.0 x 2  == 0.1 x 2      and that denorms are represented
6186551Sjake *
6286551Sjake *					  (-exp_bias+1)
6386551Sjake * as fractions that look like 0.fffff x 2             .  This means that
6486551Sjake *
6586551Sjake *			 -126
6686551Sjake * the number 0.10000 x 2    , for instance, is the same as the normalized
6786551Sjake *
6886551Sjake *		-127			   -128
6986551Sjake * float 1.0 x 2    .  Thus, to represent 2    , we need one leading zero
7086551Sjake *
7186551Sjake *				  -129
7286551Sjake * in the fraction; to represent 2    , we need two, and so on.  This
7386551Sjake *
7486551Sjake *						     (-exp_bias-fracbits+1)
7586551Sjake * implies that the smallest denormalized number is 2
7686551Sjake *
7786551Sjake * for whichever format we are talking about: for single precision, for
7886551Sjake *
7986551Sjake *						-126		-149
8086551Sjake * instance, we get .00000000000000000000001 x 2    , or 1.0 x 2    , and
8186551Sjake *
8286551Sjake * -149 == -127 - 23 + 1.
8386551Sjake */
8486551Sjake#define	SNG_EXPBITS	8
8586551Sjake#define	SNG_FRACBITS	23
8686551Sjake
8786551Sjake#define	DBL_EXPBITS	11
8886551Sjake#define	DBL_FRACBITS	52
8986551Sjake
9086551Sjake#ifdef notyet
9186551Sjake#define	E80_EXPBITS	15
9286551Sjake#define	E80_FRACBITS	64
9386551Sjake#endif
9486551Sjake
9586551Sjake#define	EXT_EXPBITS	15
9686551Sjake#define	EXT_FRACBITS	112
9786551Sjake
9886551Sjakestruct ieee_single {
9986551Sjake	u_int	sng_sign:1;
10086551Sjake	u_int	sng_exp:8;
10186551Sjake	u_int	sng_frac:23;
10286551Sjake};
10386551Sjake
10486551Sjakestruct ieee_double {
10586551Sjake	u_int	dbl_sign:1;
10686551Sjake	u_int	dbl_exp:11;
10786551Sjake	u_int	dbl_frach:20;
10886551Sjake	u_int	dbl_fracl;
10986551Sjake};
11086551Sjake
11186551Sjakestruct ieee_ext {
11286551Sjake	u_int	ext_sign:1;
11386551Sjake	u_int	ext_exp:15;
11486551Sjake	u_int	ext_frach:16;
11586551Sjake	u_int	ext_frachm;
11686551Sjake	u_int	ext_fraclm;
11786551Sjake	u_int	ext_fracl;
11886551Sjake};
11986551Sjake
12086551Sjake/*
12186551Sjake * Floats whose exponent is in [1..INFNAN) (of whatever type) are
12286551Sjake * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.
12386551Sjake * Floats whose exponent is zero are either zero (iff all fraction
12486551Sjake * bits are zero) or subnormal values.
12586551Sjake *
12686551Sjake * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
12786551Sjake * high fraction; if the bit is set, it is a `quiet NaN'.
12886551Sjake */
12986551Sjake#define	SNG_EXP_INFNAN	255
13086551Sjake#define	DBL_EXP_INFNAN	2047
13186551Sjake#define	EXT_EXP_INFNAN	32767
13286551Sjake
13386551Sjake#if 0
13486551Sjake#define	SNG_QUIETNAN	(1 << 22)
13586551Sjake#define	DBL_QUIETNAN	(1 << 19)
13686551Sjake#define	EXT_QUIETNAN	(1 << 15)
13786551Sjake#endif
13886551Sjake
13986551Sjake/*
14086551Sjake * Exponent biases.
14186551Sjake */
14286551Sjake#define	SNG_EXP_BIAS	127
14386551Sjake#define	DBL_EXP_BIAS	1023
14486551Sjake#define	EXT_EXP_BIAS	16383
14586551Sjake
14686551Sjake#endif
147