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