1 /*- 2 * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> 3 * Copyright (c) 2002 David Schultz <das@FreeBSD.ORG> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * $FreeBSD: src/lib/libc/include/fpmath.h,v 1.4 2008/12/23 22:20:59 marcel Exp $ 28 */ 29 #ifndef _FPMATH_H_ 30 #define _FPMATH_H_ 31 32 #if defined(__aarch64__) 33 #include "aarch64_fpmath.h" 34 #elif defined(__i386__) || defined(__x86_64__) 35 #ifdef __LP64__ 36 #include "amd64_fpmath.h" 37 #else 38 #include "i386_fpmath.h" 39 #endif 40 #elif defined(__powerpc__) 41 #include "powerpc_fpmath.h" 42 #elif defined(__mips__) 43 #include "mips_fpmath.h" 44 #elif defined(__s390__) 45 #include "s390_fpmath.h" 46 #endif 47 48 /* Definitions provided directly by GCC and Clang. */ 49 #if !(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)) 50 51 #if defined(__GLIBC__) 52 53 #include <features.h> 54 #include <endian.h> 55 #define __ORDER_LITTLE_ENDIAN__ __LITTLE_ENDIAN 56 #define __ORDER_BIG_ENDIAN__ __BIG_ENDIAN 57 #define __BYTE_ORDER__ __BYTE_ORDER 58 59 #elif defined(__APPLE__) 60 61 #include <machine/endian.h> 62 #define __ORDER_LITTLE_ENDIAN__ LITTLE_ENDIAN 63 #define __ORDER_BIG_ENDIAN__ BIG_ENDIAN 64 #define __BYTE_ORDER__ BYTE_ORDER 65 66 #elif defined(_WIN32) 67 68 #define __ORDER_LITTLE_ENDIAN__ 1234 69 #define __ORDER_BIG_ENDIAN__ 4321 70 #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ 71 72 #endif 73 74 #endif /* __BYTE_ORDER__, __ORDER_LITTLE_ENDIAN__ and __ORDER_BIG_ENDIAN__ */ 75 76 #ifndef __FLOAT_WORD_ORDER__ 77 #define __FLOAT_WORD_ORDER__ __BYTE_ORDER__ 78 #endif 79 80 union IEEEf2bits { 81 float f; 82 struct { 83 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 84 unsigned int man :23; 85 unsigned int exp :8; 86 unsigned int sign :1; 87 #else /* _BIG_ENDIAN */ 88 unsigned int sign :1; 89 unsigned int exp :8; 90 unsigned int man :23; 91 #endif 92 } bits; 93 }; 94 95 #define DBL_MANH_SIZE 20 96 #define DBL_MANL_SIZE 32 97 98 union IEEEd2bits { 99 double d; 100 struct { 101 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 102 #if __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__ 103 unsigned int manl :32; 104 #endif 105 unsigned int manh :20; 106 unsigned int exp :11; 107 unsigned int sign :1; 108 #if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__ 109 unsigned int manl :32; 110 #endif 111 #else /* _BIG_ENDIAN */ 112 unsigned int sign :1; 113 unsigned int exp :11; 114 unsigned int manh :20; 115 unsigned int manl :32; 116 #endif 117 } bits; 118 }; 119 120 #endif 121