fpmath.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*-
  2. * Copyright (c) 2003 Mike Barcroft <[email protected]>
  3. * Copyright (c) 2002 David Schultz <[email protected]>
  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. #if defined(__aarch64__)
  32. #include "aarch64_fpmath.h"
  33. #elif defined(__i386__) || defined(__x86_64__)
  34. #ifdef __LP64__
  35. #include "amd64_fpmath.h"
  36. #else
  37. #include "i386_fpmath.h"
  38. #endif
  39. #elif defined(__powerpc__)
  40. #include "powerpc_fpmath.h"
  41. #elif defined(__mips__)
  42. #include "mips_fpmath.h"
  43. #elif defined(__s390__)
  44. #include "s390_fpmath.h"
  45. #endif
  46. /* Definitions provided directly by GCC and Clang. */
  47. #if !(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__))
  48. #if defined(__GLIBC__)
  49. #include <features.h>
  50. #include <endian.h>
  51. #define __ORDER_LITTLE_ENDIAN__ __LITTLE_ENDIAN
  52. #define __ORDER_BIG_ENDIAN__ __BIG_ENDIAN
  53. #define __BYTE_ORDER__ __BYTE_ORDER
  54. #elif defined(__APPLE__)
  55. #include <machine/endian.h>
  56. #define __ORDER_LITTLE_ENDIAN__ LITTLE_ENDIAN
  57. #define __ORDER_BIG_ENDIAN__ BIG_ENDIAN
  58. #define __BYTE_ORDER__ BYTE_ORDER
  59. #elif defined(_WIN32)
  60. #define __ORDER_LITTLE_ENDIAN__ 1234
  61. #define __ORDER_BIG_ENDIAN__ 4321
  62. #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
  63. #endif
  64. #endif /* __BYTE_ORDER__, __ORDER_LITTLE_ENDIAN__ and __ORDER_BIG_ENDIAN__ */
  65. #ifndef __FLOAT_WORD_ORDER__
  66. #define __FLOAT_WORD_ORDER__ __BYTE_ORDER__
  67. #endif
  68. union IEEEf2bits {
  69. float f;
  70. struct {
  71. #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  72. unsigned int man :23;
  73. unsigned int exp :8;
  74. unsigned int sign :1;
  75. #else /* _BIG_ENDIAN */
  76. unsigned int sign :1;
  77. unsigned int exp :8;
  78. unsigned int man :23;
  79. #endif
  80. } bits;
  81. };
  82. #define DBL_MANH_SIZE 20
  83. #define DBL_MANL_SIZE 32
  84. union IEEEd2bits {
  85. double d;
  86. struct {
  87. #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  88. #if __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__
  89. unsigned int manl :32;
  90. #endif
  91. unsigned int manh :20;
  92. unsigned int exp :11;
  93. unsigned int sign :1;
  94. #if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__
  95. unsigned int manl :32;
  96. #endif
  97. #else /* _BIG_ENDIAN */
  98. unsigned int sign :1;
  99. unsigned int exp :11;
  100. unsigned int manh :20;
  101. unsigned int manl :32;
  102. #endif
  103. } bits;
  104. };
  105. #endif