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 #endif 41 42 #if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) 43 44 /* Definitions provided directly by GCC and Clang. */ 45 #define _LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ 46 #define _BIG_ENDIAN __ORDER_BIG_ENDIAN__ 47 #define _PDP_ENDIAN __ORDER_PDP_ENDIAN__ 48 #define _BYTE_ORDER __BYTE_ORDER__ 49 50 #elif defined(__GLIBC__) 51 52 #include <features.h> 53 #include <endian.h> 54 #define _LITTLE_ENDIAN __LITTLE_ENDIAN 55 #define _BIG_ENDIAN __BIG_ENDIAN 56 #define _PDP_ENDIAN __PDP_ENDIAN 57 #define _BYTE_ORDER __BYTE_ORDER 58 59 #elif defined(__APPLE__) 60 61 #include <machine/endian.h> 62 #define _LITTLE_ENDIAN LITTLE_ENDIAN 63 #define _BIG_ENDIAN BIG_ENDIAN 64 #define _PDP_ENDIAN PDP_ENDIAN 65 #define _BYTE_ORDER BYTE_ORDER 66 67 #elif defined(__FreeBSD__) 68 69 #include <machine/endian.h> 70 71 #elif defined(_WIN32) 72 73 #define _LITTLE_ENDIAN 1234 74 #define _BIG_ENDIAN 4321 75 #define _PDP_ENDIAN 3412 76 #define _BYTE_ORDER _LITTLE_ENDIAN 77 #define _FLOAT_WORD_ORDER _LITTLE_ENDIAN 78 #define LITTLE_ENDIAN _LITTLE_ENDIAN 79 #define BIG_ENDIAN _BIG_ENDIAN 80 #define PDP_ENDIAN _PDP_ENDIAN 81 #define BYTE_ORDER _BYTE_ORDER 82 83 #endif 84 85 #ifndef _IEEE_WORD_ORDER 86 #define _IEEE_WORD_ORDER _BYTE_ORDER 87 #endif 88 89 union IEEEf2bits { 90 float f; 91 struct { 92 #if _BYTE_ORDER == _LITTLE_ENDIAN 93 unsigned int man :23; 94 unsigned int exp :8; 95 unsigned int sign :1; 96 #else /* _BIG_ENDIAN */ 97 unsigned int sign :1; 98 unsigned int exp :8; 99 unsigned int man :23; 100 #endif 101 } bits; 102 }; 103 104 #define DBL_MANH_SIZE 20 105 #define DBL_MANL_SIZE 32 106 107 union IEEEd2bits { 108 double d; 109 struct { 110 #if _BYTE_ORDER == _LITTLE_ENDIAN 111 #if _IEEE_WORD_ORDER == _LITTLE_ENDIAN 112 unsigned int manl :32; 113 #endif 114 unsigned int manh :20; 115 unsigned int exp :11; 116 unsigned int sign :1; 117 #if _IEEE_WORD_ORDER == _BIG_ENDIAN 118 unsigned int manl :32; 119 #endif 120 #else /* _BIG_ENDIAN */ 121 unsigned int sign :1; 122 unsigned int exp :11; 123 unsigned int manh :20; 124 unsigned int manl :32; 125 #endif 126 } bits; 127 }; 128 129 #endif 130