xref: /openbsd-src/sys/arch/powerpc/include/ieee.h (revision 7b36286a70b46b494e2bca4a889ab49ef62ba86c)
1*7b36286aSmartynas /*	$OpenBSD: ieee.h,v 1.5 2008/09/07 20:36:07 martynas Exp $	*/
247bc79e1Srahnds 
347bc79e1Srahnds /*
447bc79e1Srahnds  * Copyright (c) 1992, 1993
547bc79e1Srahnds  *	The Regents of the University of California.  All rights reserved.
647bc79e1Srahnds  *
747bc79e1Srahnds  * This software was developed by the Computer Systems Engineering group
847bc79e1Srahnds  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
947bc79e1Srahnds  * contributed to Berkeley.
1047bc79e1Srahnds  *
1147bc79e1Srahnds  * All advertising materials mentioning features or use of this software
1247bc79e1Srahnds  * must display the following acknowledgement:
1347bc79e1Srahnds  *	This product includes software developed by the University of
1447bc79e1Srahnds  *	California, Lawrence Berkeley Laboratory.
1547bc79e1Srahnds  *
1647bc79e1Srahnds  * Redistribution and use in source and binary forms, with or without
1747bc79e1Srahnds  * modification, are permitted provided that the following conditions
1847bc79e1Srahnds  * are met:
1947bc79e1Srahnds  * 1. Redistributions of source code must retain the above copyright
2047bc79e1Srahnds  *    notice, this list of conditions and the following disclaimer.
2147bc79e1Srahnds  * 2. Redistributions in binary form must reproduce the above copyright
2247bc79e1Srahnds  *    notice, this list of conditions and the following disclaimer in the
2347bc79e1Srahnds  *    documentation and/or other materials provided with the distribution.
2429295d1cSmillert  * 3. Neither the name of the University nor the names of its contributors
2547bc79e1Srahnds  *    may be used to endorse or promote products derived from this software
2647bc79e1Srahnds  *    without specific prior written permission.
2747bc79e1Srahnds  *
2847bc79e1Srahnds  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2947bc79e1Srahnds  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3047bc79e1Srahnds  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3147bc79e1Srahnds  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3247bc79e1Srahnds  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3347bc79e1Srahnds  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3447bc79e1Srahnds  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3547bc79e1Srahnds  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3647bc79e1Srahnds  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3747bc79e1Srahnds  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3847bc79e1Srahnds  * SUCH DAMAGE.
3947bc79e1Srahnds  *
4047bc79e1Srahnds  *	@(#)ieee.h	8.1 (Berkeley) 6/11/93
4147bc79e1Srahnds  */
4247bc79e1Srahnds 
4347bc79e1Srahnds /*
4447bc79e1Srahnds  * ieee.h defines the machine-dependent layout of the machine's IEEE
4547bc79e1Srahnds  * floating point.  It does *not* define (yet?) any of the rounding
4647bc79e1Srahnds  * mode bits, exceptions, and so forth.
4747bc79e1Srahnds  */
4847bc79e1Srahnds 
4947bc79e1Srahnds /*
5047bc79e1Srahnds  * Define the number of bits in each fraction and exponent.
5147bc79e1Srahnds  *
5247bc79e1Srahnds  *		     k	         k+1
5347bc79e1Srahnds  * Note that  1.0 x 2  == 0.1 x 2      and that denorms are represented
5447bc79e1Srahnds  *
5547bc79e1Srahnds  *					  (-exp_bias+1)
5647bc79e1Srahnds  * as fractions that look like 0.fffff x 2             .  This means that
5747bc79e1Srahnds  *
5847bc79e1Srahnds  *			 -126
5947bc79e1Srahnds  * the number 0.10000 x 2    , for instance, is the same as the normalized
6047bc79e1Srahnds  *
6147bc79e1Srahnds  *		-127			   -128
6247bc79e1Srahnds  * float 1.0 x 2    .  Thus, to represent 2    , we need one leading zero
6347bc79e1Srahnds  *
6447bc79e1Srahnds  *				  -129
6547bc79e1Srahnds  * in the fraction; to represent 2    , we need two, and so on.  This
6647bc79e1Srahnds  *
6747bc79e1Srahnds  *						     (-exp_bias-fracbits+1)
6847bc79e1Srahnds  * implies that the smallest denormalized number is 2
6947bc79e1Srahnds  *
7047bc79e1Srahnds  * for whichever format we are talking about: for single precision, for
7147bc79e1Srahnds  *
7247bc79e1Srahnds  *						-126		-149
7347bc79e1Srahnds  * instance, we get .00000000000000000000001 x 2    , or 1.0 x 2    , and
7447bc79e1Srahnds  *
7547bc79e1Srahnds  * -149 == -127 - 23 + 1.
7647bc79e1Srahnds  */
7747bc79e1Srahnds #define	SNG_EXPBITS	8
7847bc79e1Srahnds #define	SNG_FRACBITS	23
7947bc79e1Srahnds 
8047bc79e1Srahnds #define	DBL_EXPBITS	11
81*7b36286aSmartynas #define	DBL_FRACHBITS	20
82*7b36286aSmartynas #define	DBL_FRACLBITS	32
8347bc79e1Srahnds #define	DBL_FRACBITS	52
8447bc79e1Srahnds 
8547bc79e1Srahnds struct ieee_single {
8647bc79e1Srahnds 	u_int	sng_sign:1;
8747bc79e1Srahnds 	u_int	sng_exp:8;
8847bc79e1Srahnds 	u_int	sng_frac:23;
8947bc79e1Srahnds };
9047bc79e1Srahnds 
9147bc79e1Srahnds struct ieee_double {
9247bc79e1Srahnds 	u_int	dbl_sign:1;
9347bc79e1Srahnds 	u_int	dbl_exp:11;
9447bc79e1Srahnds 	u_int	dbl_frach:20;
9547bc79e1Srahnds 	u_int	dbl_fracl;
9647bc79e1Srahnds };
9747bc79e1Srahnds 
9847bc79e1Srahnds /*
9947bc79e1Srahnds  * Floats whose exponent is in [1..INFNAN) (of whatever type) are
10047bc79e1Srahnds  * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.
10147bc79e1Srahnds  * Floats whose exponent is zero are either zero (iff all fraction
10247bc79e1Srahnds  * bits are zero) or subnormal values.
10347bc79e1Srahnds  *
10447bc79e1Srahnds  * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
10547bc79e1Srahnds  * high fraction; if the bit is set, it is a `quiet NaN'.
10647bc79e1Srahnds  */
10747bc79e1Srahnds #define	SNG_EXP_INFNAN	255
10847bc79e1Srahnds #define	DBL_EXP_INFNAN	2047
10947bc79e1Srahnds 
11047bc79e1Srahnds #if 0
11147bc79e1Srahnds #define	SNG_QUIETNAN	(1 << 22)
11247bc79e1Srahnds #define	DBL_QUIETNAN	(1 << 19)
11347bc79e1Srahnds #endif
11447bc79e1Srahnds 
11547bc79e1Srahnds /*
11647bc79e1Srahnds  * Exponent biases.
11747bc79e1Srahnds  */
11847bc79e1Srahnds #define	SNG_EXP_BIAS	127
11947bc79e1Srahnds #define	DBL_EXP_BIAS	1023
120