1*c37dd69bSchristos /* $NetBSD: ieee.h,v 1.13 2024/01/02 19:28:25 christos Exp $ */ 28375b2d9Sfvdl 38375b2d9Sfvdl /* 48375b2d9Sfvdl * Copyright (c) 1992, 1993 58375b2d9Sfvdl * The Regents of the University of California. All rights reserved. 68375b2d9Sfvdl * 78375b2d9Sfvdl * This software was developed by the Computer Systems Engineering group 88375b2d9Sfvdl * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 98375b2d9Sfvdl * contributed to Berkeley. 108375b2d9Sfvdl * 118375b2d9Sfvdl * All advertising materials mentioning features or use of this software 128375b2d9Sfvdl * must display the following acknowledgement: 138375b2d9Sfvdl * This product includes software developed by the University of 148375b2d9Sfvdl * California, Lawrence Berkeley Laboratory. 158375b2d9Sfvdl * 168375b2d9Sfvdl * Redistribution and use in source and binary forms, with or without 178375b2d9Sfvdl * modification, are permitted provided that the following conditions 188375b2d9Sfvdl * are met: 198375b2d9Sfvdl * 1. Redistributions of source code must retain the above copyright 208375b2d9Sfvdl * notice, this list of conditions and the following disclaimer. 218375b2d9Sfvdl * 2. Redistributions in binary form must reproduce the above copyright 228375b2d9Sfvdl * notice, this list of conditions and the following disclaimer in the 238375b2d9Sfvdl * documentation and/or other materials provided with the distribution. 24aad01611Sagc * 3. Neither the name of the University nor the names of its contributors 258375b2d9Sfvdl * may be used to endorse or promote products derived from this software 268375b2d9Sfvdl * without specific prior written permission. 278375b2d9Sfvdl * 288375b2d9Sfvdl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 298375b2d9Sfvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 308375b2d9Sfvdl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 318375b2d9Sfvdl * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 328375b2d9Sfvdl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 338375b2d9Sfvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 348375b2d9Sfvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 358375b2d9Sfvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 368375b2d9Sfvdl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 378375b2d9Sfvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 388375b2d9Sfvdl * SUCH DAMAGE. 398375b2d9Sfvdl * 408375b2d9Sfvdl * @(#)ieee.h 8.1 (Berkeley) 6/11/93 418375b2d9Sfvdl */ 4256524372Schristos #ifndef _X86_IEEE_H_ 4356524372Schristos #define _X86_IEEE_H_ 448375b2d9Sfvdl 458375b2d9Sfvdl /* 468375b2d9Sfvdl * ieee.h defines the machine-dependent layout of the machine's IEEE 478375b2d9Sfvdl * floating point. It does *not* define (yet?) any of the rounding 488375b2d9Sfvdl * mode bits, exceptions, and so forth. 498375b2d9Sfvdl */ 508375b2d9Sfvdl 51a3fabb9eSkleink #include <sys/ieee754.h> 528375b2d9Sfvdl 538375b2d9Sfvdl #define EXT_EXPBITS 15 54b5b1a9d5Schristos #define EXT_FRACHBITS 32 55b5b1a9d5Schristos #define EXT_FRACLBITS 32 56b5b1a9d5Schristos #define EXT_FRACBITS (EXT_FRACLBITS + EXT_FRACHBITS) 57b5b1a9d5Schristos 58b5b1a9d5Schristos #define EXT_TO_ARRAY32(u, a) do { \ 59b5b1a9d5Schristos (a)[0] = (uint32_t)(u).extu_ext.ext_fracl; \ 60b5b1a9d5Schristos (a)[1] = (uint32_t)(u).extu_ext.ext_frach; \ 61b5b1a9d5Schristos } while(/*CONSTCOND*/0) 628375b2d9Sfvdl 6356062be2Skleink /* 64a3fabb9eSkleink * struct ieee_ext is the raw storage layout of the 80-bit 6556062be2Skleink * extended-precision type as implemented by the FPU. Per the 6656062be2Skleink * respective ABI specifications, it is followed by a tail padding of 6756062be2Skleink * 6856062be2Skleink * amd64: 48 bits, 6956062be2Skleink * i386: 16 bits. 7056062be2Skleink */ 718375b2d9Sfvdl struct ieee_ext { 72*c37dd69bSchristos uint32_t ext_fracl:EXT_FRACLBITS; 73*c37dd69bSchristos uint32_t ext_frach:EXT_FRACHBITS; 74b5b1a9d5Schristos #if 0 75*c37dd69bSchristos uint32_t ext_int:1; 76b5b1a9d5Schristos #endif 77*c37dd69bSchristos uint32_t ext_exp:EXT_EXPBITS; 78*c37dd69bSchristos uint32_t ext_sign:1; 798375b2d9Sfvdl }; 808375b2d9Sfvdl 818375b2d9Sfvdl /* 828375b2d9Sfvdl * Floats whose exponent is in [1..INFNAN) (of whatever type) are 838375b2d9Sfvdl * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. 848375b2d9Sfvdl * Floats whose exponent is zero are either zero (iff all fraction 858375b2d9Sfvdl * bits are zero) or subnormal values. 868375b2d9Sfvdl * 878375b2d9Sfvdl * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its 888375b2d9Sfvdl * high fraction; if the bit is set, it is a `quiet NaN'. 898375b2d9Sfvdl */ 90e2a86dd3Schristos #define EXT_EXP_INFNAN 0x7fff 91e2a86dd3Schristos #define EXT_EXP_INF 0x7fff 92e2a86dd3Schristos #define EXT_EXP_NAN 0x7fff 938375b2d9Sfvdl 948375b2d9Sfvdl #if 0 95b2cb7fcdSkleink #define SNG_QUIETNAN (1 << 22) 96b2cb7fcdSkleink #define DBL_QUIETNAN (1 << 19) 9795971b87Skleink #define EXT_QUIETNAN (1 << 30) 988375b2d9Sfvdl #endif 998375b2d9Sfvdl 1008375b2d9Sfvdl /* 1018375b2d9Sfvdl * Exponent biases. 1028375b2d9Sfvdl */ 1038375b2d9Sfvdl #define EXT_EXP_BIAS 16383 104b37192f0Skleink 105b37192f0Skleink /* 106b37192f0Skleink * Convenience data structures. 107b37192f0Skleink */ 108b37192f0Skleink union ieee_ext_u { 109b37192f0Skleink long double extu_ld; 110964d6747Skleink struct ieee_ext extu_ext; 111b37192f0Skleink }; 112e2a86dd3Schristos 113e2a86dd3Schristos #define extu_exp extu_ext.ext_exp 114e2a86dd3Schristos #define extu_sign extu_ext.ext_sign 115e2a86dd3Schristos #define extu_fracl extu_ext.ext_fracl 116e2a86dd3Schristos #define extu_frach extu_ext.ext_frach 117e2a86dd3Schristos 118e2a86dd3Schristos #define LDBL_NBIT 0x80000000 119e2a86dd3Schristos #define mask_nbit_l(u) ((u).extu_frach &= ~LDBL_NBIT) 12056524372Schristos 12156524372Schristos #endif /* _X86_IEEE_H_ */ 122