xref: /openbsd-src/sys/arch/hppa/include/ieee.h (revision 7b36286a70b46b494e2bca4a889ab49ef62ba86c)
1*7b36286aSmartynas /*	$OpenBSD: ieee.h,v 1.3 2008/09/07 20:36:06 martynas Exp $	*/
239bdc9c2Smickey 
339bdc9c2Smickey /*
439bdc9c2Smickey  * Copyright (c) 1992, 1993
539bdc9c2Smickey  *	The Regents of the University of California.  All rights reserved.
639bdc9c2Smickey  *
739bdc9c2Smickey  * This software was developed by the Computer Systems Engineering group
839bdc9c2Smickey  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
939bdc9c2Smickey  * contributed to Berkeley.
1039bdc9c2Smickey  *
1139bdc9c2Smickey  * All advertising materials mentioning features or use of this software
1239bdc9c2Smickey  * must display the following acknowledgement:
1339bdc9c2Smickey  *	This product includes software developed by the University of
1439bdc9c2Smickey  *	California, Lawrence Berkeley Laboratory.
1539bdc9c2Smickey  *
1639bdc9c2Smickey  * Redistribution and use in source and binary forms, with or without
1739bdc9c2Smickey  * modification, are permitted provided that the following conditions
1839bdc9c2Smickey  * are met:
1939bdc9c2Smickey  * 1. Redistributions of source code must retain the above copyright
2039bdc9c2Smickey  *    notice, this list of conditions and the following disclaimer.
2139bdc9c2Smickey  * 2. Redistributions in binary form must reproduce the above copyright
2239bdc9c2Smickey  *    notice, this list of conditions and the following disclaimer in the
2339bdc9c2Smickey  *    documentation and/or other materials provided with the distribution.
2429295d1cSmillert  * 3. Neither the name of the University nor the names of its contributors
2539bdc9c2Smickey  *    may be used to endorse or promote products derived from this software
2639bdc9c2Smickey  *    without specific prior written permission.
2739bdc9c2Smickey  *
2839bdc9c2Smickey  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2939bdc9c2Smickey  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3039bdc9c2Smickey  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3139bdc9c2Smickey  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3239bdc9c2Smickey  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3339bdc9c2Smickey  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3439bdc9c2Smickey  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3539bdc9c2Smickey  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3639bdc9c2Smickey  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3739bdc9c2Smickey  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3839bdc9c2Smickey  * SUCH DAMAGE.
3939bdc9c2Smickey  *
4039bdc9c2Smickey  *	@(#)ieee.h	8.1 (Berkeley) 6/11/93
4139bdc9c2Smickey  */
4239bdc9c2Smickey 
4339bdc9c2Smickey /*
4439bdc9c2Smickey  * ieee.h defines the machine-dependent layout of the machine's IEEE
4539bdc9c2Smickey  * floating point.  It does *not* define (yet?) any of the rounding
4639bdc9c2Smickey  * mode bits, exceptions, and so forth.
4739bdc9c2Smickey  */
4839bdc9c2Smickey 
4939bdc9c2Smickey /*
5039bdc9c2Smickey  * Define the number of bits in each fraction and exponent.
5139bdc9c2Smickey  *
5239bdc9c2Smickey  *		     k	         k+1
5339bdc9c2Smickey  * Note that  1.0 x 2  == 0.1 x 2      and that denorms are represented
5439bdc9c2Smickey  *
5539bdc9c2Smickey  *					  (-exp_bias+1)
5639bdc9c2Smickey  * as fractions that look like 0.fffff x 2             .  This means that
5739bdc9c2Smickey  *
5839bdc9c2Smickey  *			 -126
5939bdc9c2Smickey  * the number 0.10000 x 2    , for instance, is the same as the normalized
6039bdc9c2Smickey  *
6139bdc9c2Smickey  *		-127			   -128
6239bdc9c2Smickey  * float 1.0 x 2    .  Thus, to represent 2    , we need one leading zero
6339bdc9c2Smickey  *
6439bdc9c2Smickey  *				  -129
6539bdc9c2Smickey  * in the fraction; to represent 2    , we need two, and so on.  This
6639bdc9c2Smickey  *
6739bdc9c2Smickey  *						     (-exp_bias-fracbits+1)
6839bdc9c2Smickey  * implies that the smallest denormalized number is 2
6939bdc9c2Smickey  *
7039bdc9c2Smickey  * for whichever format we are talking about: for single precision, for
7139bdc9c2Smickey  *
7239bdc9c2Smickey  *						-126		-149
7339bdc9c2Smickey  * instance, we get .00000000000000000000001 x 2    , or 1.0 x 2    , and
7439bdc9c2Smickey  *
7539bdc9c2Smickey  * -149 == -127 - 23 + 1.
7639bdc9c2Smickey  */
7739bdc9c2Smickey #define	SNG_EXPBITS	8
7839bdc9c2Smickey #define	SNG_FRACBITS	23
7939bdc9c2Smickey 
8039bdc9c2Smickey #define	DBL_EXPBITS	11
81*7b36286aSmartynas #define	DBL_FRACHBITS	20
82*7b36286aSmartynas #define	DBL_FRACLBITS	32
8339bdc9c2Smickey #define	DBL_FRACBITS	52
8439bdc9c2Smickey 
8539bdc9c2Smickey #ifdef notyet
8639bdc9c2Smickey #define	E80_EXPBITS	15
8739bdc9c2Smickey #define	E80_FRACBITS	64
8839bdc9c2Smickey #endif
8939bdc9c2Smickey 
9039bdc9c2Smickey struct ieee_single {
9139bdc9c2Smickey 	u_int	sng_sign:1;
9239bdc9c2Smickey 	u_int	sng_exp:8;
9339bdc9c2Smickey 	u_int	sng_frac:23;
9439bdc9c2Smickey };
9539bdc9c2Smickey 
9639bdc9c2Smickey struct ieee_double {
9739bdc9c2Smickey 	u_int	dbl_sign:1;
9839bdc9c2Smickey 	u_int	dbl_exp:11;
9939bdc9c2Smickey 	u_int	dbl_frach:20;
10039bdc9c2Smickey 	u_int	dbl_fracl;
10139bdc9c2Smickey };
10239bdc9c2Smickey 
10339bdc9c2Smickey /*
10439bdc9c2Smickey  * Floats whose exponent is in [1..INFNAN) (of whatever type) are
10539bdc9c2Smickey  * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.
10639bdc9c2Smickey  * Floats whose exponent is zero are either zero (iff all fraction
10739bdc9c2Smickey  * bits are zero) or subnormal values.
10839bdc9c2Smickey  *
10939bdc9c2Smickey  * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
11039bdc9c2Smickey  * high fraction; if the bit is set, it is a `quiet NaN'.
11139bdc9c2Smickey  */
11239bdc9c2Smickey #define	SNG_EXP_INFNAN	255
11339bdc9c2Smickey #define	DBL_EXP_INFNAN	2047
11439bdc9c2Smickey 
11539bdc9c2Smickey #if 0
11639bdc9c2Smickey #define	SNG_QUIETNAN	(1 << 22)
11739bdc9c2Smickey #define	DBL_QUIETNAN	(1 << 19)
11839bdc9c2Smickey #endif
11939bdc9c2Smickey 
12039bdc9c2Smickey /*
12139bdc9c2Smickey  * Exponent biases.
12239bdc9c2Smickey  */
12339bdc9c2Smickey #define	SNG_EXP_BIAS	127
12439bdc9c2Smickey #define	DBL_EXP_BIAS	1023
125