1*803a4704SPulkoMandy /*- 2*803a4704SPulkoMandy * Copyright (c) 1992, 1993 3*803a4704SPulkoMandy * The Regents of the University of California. All rights reserved. 4*803a4704SPulkoMandy * 5*803a4704SPulkoMandy * This software was developed by the Computer Systems Engineering group 6*803a4704SPulkoMandy * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7*803a4704SPulkoMandy * contributed to Berkeley. 8*803a4704SPulkoMandy * 9*803a4704SPulkoMandy * Redistribution and use in source and binary forms, with or without 10*803a4704SPulkoMandy * modification, are permitted provided that the following conditions 11*803a4704SPulkoMandy * are met: 12*803a4704SPulkoMandy * 1. Redistributions of source code must retain the above copyright 13*803a4704SPulkoMandy * notice, this list of conditions and the following disclaimer. 14*803a4704SPulkoMandy * 2. Redistributions in binary form must reproduce the above copyright 15*803a4704SPulkoMandy * notice, this list of conditions and the following disclaimer in the 16*803a4704SPulkoMandy * documentation and/or other materials provided with the distribution. 17*803a4704SPulkoMandy * 4. Neither the name of the University nor the names of its contributors 18*803a4704SPulkoMandy * may be used to endorse or promote products derived from this software 19*803a4704SPulkoMandy * without specific prior written permission. 20*803a4704SPulkoMandy * 21*803a4704SPulkoMandy * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22*803a4704SPulkoMandy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23*803a4704SPulkoMandy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24*803a4704SPulkoMandy * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25*803a4704SPulkoMandy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26*803a4704SPulkoMandy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27*803a4704SPulkoMandy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28*803a4704SPulkoMandy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29*803a4704SPulkoMandy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30*803a4704SPulkoMandy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31*803a4704SPulkoMandy * SUCH DAMAGE. 32*803a4704SPulkoMandy * 33*803a4704SPulkoMandy * @(#)ieee.h 8.1 (Berkeley) 6/11/93 34*803a4704SPulkoMandy * from: NetBSD: ieee.h,v 1.1.1.1 1998/06/20 04:58:51 eeh Exp 35*803a4704SPulkoMandy * $FreeBSD: head/sys/sparc64/include/ieee.h 139825 2005-01-07 02:29:27Z imp $ 36*803a4704SPulkoMandy */ 37*803a4704SPulkoMandy 38*803a4704SPulkoMandy #ifndef _MACHINE_IEEE_H_ 39*803a4704SPulkoMandy #define _MACHINE_IEEE_H_ 40*803a4704SPulkoMandy 41*803a4704SPulkoMandy #include <stdint.h> 42*803a4704SPulkoMandy 43*803a4704SPulkoMandy /* 44*803a4704SPulkoMandy * ieee.h defines the machine-dependent layout of the machine's IEEE 45*803a4704SPulkoMandy * floating point. It does *not* define (yet?) any of the rounding 46*803a4704SPulkoMandy * mode bits, exceptions, and so forth. 47*803a4704SPulkoMandy */ 48*803a4704SPulkoMandy 49*803a4704SPulkoMandy /* 50*803a4704SPulkoMandy * Define the number of bits in each fraction and exponent. 51*803a4704SPulkoMandy * 52*803a4704SPulkoMandy * k k+1 53*803a4704SPulkoMandy * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented 54*803a4704SPulkoMandy * 55*803a4704SPulkoMandy * (-exp_bias+1) 56*803a4704SPulkoMandy * as fractions that look like 0.fffff x 2 . This means that 57*803a4704SPulkoMandy * 58*803a4704SPulkoMandy * -126 59*803a4704SPulkoMandy * the number 0.10000 x 2 , for instance, is the same as the normalized 60*803a4704SPulkoMandy * 61*803a4704SPulkoMandy * -127 -128 62*803a4704SPulkoMandy * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero 63*803a4704SPulkoMandy * 64*803a4704SPulkoMandy * -129 65*803a4704SPulkoMandy * in the fraction; to represent 2 , we need two, and so on. This 66*803a4704SPulkoMandy * 67*803a4704SPulkoMandy * (-exp_bias-fracbits+1) 68*803a4704SPulkoMandy * implies that the smallest denormalized number is 2 69*803a4704SPulkoMandy * 70*803a4704SPulkoMandy * for whichever format we are talking about: for single precision, for 71*803a4704SPulkoMandy * 72*803a4704SPulkoMandy * -126 -149 73*803a4704SPulkoMandy * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and 74*803a4704SPulkoMandy * 75*803a4704SPulkoMandy * -149 == -127 - 23 + 1. 76*803a4704SPulkoMandy */ 77*803a4704SPulkoMandy #define SNG_EXPBITS 8 78*803a4704SPulkoMandy #define SNG_FRACBITS 23 79*803a4704SPulkoMandy 80*803a4704SPulkoMandy #define DBL_EXPBITS 11 81*803a4704SPulkoMandy #define DBL_FRACBITS 52 82*803a4704SPulkoMandy 83*803a4704SPulkoMandy #ifdef notyet 84*803a4704SPulkoMandy #define E80_EXPBITS 15 85*803a4704SPulkoMandy #define E80_FRACBITS 64 86*803a4704SPulkoMandy #endif 87*803a4704SPulkoMandy 88*803a4704SPulkoMandy #define EXT_EXPBITS 15 89*803a4704SPulkoMandy #define EXT_FRACBITS 112 90*803a4704SPulkoMandy 91*803a4704SPulkoMandy struct ieee_single { 92*803a4704SPulkoMandy uint32_t sng_sign:1; 93*803a4704SPulkoMandy uint32_t sng_exp:8; 94*803a4704SPulkoMandy uint32_t sng_frac:23; 95*803a4704SPulkoMandy }; 96*803a4704SPulkoMandy 97*803a4704SPulkoMandy struct ieee_double { 98*803a4704SPulkoMandy uint32_t dbl_sign:1; 99*803a4704SPulkoMandy uint32_t dbl_exp:11; 100*803a4704SPulkoMandy uint32_t dbl_frach:20; 101*803a4704SPulkoMandy uint32_t dbl_fracl; 102*803a4704SPulkoMandy }; 103*803a4704SPulkoMandy 104*803a4704SPulkoMandy struct ieee_ext { 105*803a4704SPulkoMandy uint32_t ext_sign:1; 106*803a4704SPulkoMandy uint32_t ext_exp:15; 107*803a4704SPulkoMandy uint32_t ext_frach:16; 108*803a4704SPulkoMandy uint32_t ext_frachm; 109*803a4704SPulkoMandy uint32_t ext_fraclm; 110*803a4704SPulkoMandy uint32_t ext_fracl; 111*803a4704SPulkoMandy }; 112*803a4704SPulkoMandy 113*803a4704SPulkoMandy /* 114*803a4704SPulkoMandy * Floats whose exponent is in [1..INFNAN) (of whatever type) are 115*803a4704SPulkoMandy * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. 116*803a4704SPulkoMandy * Floats whose exponent is zero are either zero (iff all fraction 117*803a4704SPulkoMandy * bits are zero) or subnormal values. 118*803a4704SPulkoMandy * 119*803a4704SPulkoMandy * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its 120*803a4704SPulkoMandy * high fraction; if the bit is set, it is a `quiet NaN'. 121*803a4704SPulkoMandy */ 122*803a4704SPulkoMandy #define SNG_EXP_INFNAN 255 123*803a4704SPulkoMandy #define DBL_EXP_INFNAN 2047 124*803a4704SPulkoMandy #define EXT_EXP_INFNAN 32767 125*803a4704SPulkoMandy 126*803a4704SPulkoMandy #if 0 127*803a4704SPulkoMandy #define SNG_QUIETNAN (1 << 22) 128*803a4704SPulkoMandy #define DBL_QUIETNAN (1 << 19) 129*803a4704SPulkoMandy #define EXT_QUIETNAN (1 << 15) 130*803a4704SPulkoMandy #endif 131*803a4704SPulkoMandy 132*803a4704SPulkoMandy /* 133*803a4704SPulkoMandy * Exponent biases. 134*803a4704SPulkoMandy */ 135*803a4704SPulkoMandy #define SNG_EXP_BIAS 127 136*803a4704SPulkoMandy #define DBL_EXP_BIAS 1023 137*803a4704SPulkoMandy #define EXT_EXP_BIAS 16383 138*803a4704SPulkoMandy 139*803a4704SPulkoMandy #endif 140