fpmath.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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$
  28. */
  29. #ifndef _FPMATH_H
  30. #define _FPMATH_H
  31. #if defined(__arm__)
  32. #include "arm/_fpmath.h"
  33. #elif defined(__aarch64__)
  34. #include "aarch64/_fpmath.h"
  35. #elif defined(__i386__) || defined(__x86_64__)
  36. #ifdef __LP64__
  37. #include "amd64/_fpmath.h"
  38. #else
  39. #include "i387/_fpmath.h"
  40. #endif
  41. #elif defined(__powerpc__)
  42. #include "powerpc/_fpmath.h"
  43. #else
  44. #error "Unsupported platform"
  45. #endif
  46. #ifdef __linux
  47. #include <features.h>
  48. #include <endian.h>
  49. #define _LITTLE_ENDIAN __LITTLE_ENDIAN
  50. #define _BIG_ENDIAN __BIG_ENDIAN
  51. #define _PDP_ENDIAN __PDP_ENDIAN
  52. #define _BYTE_ORDER __BYTE_ORDER
  53. #endif
  54. #ifdef __APPLE__
  55. #include <machine/endian.h>
  56. #define _LITTLE_ENDIAN LITTLE_ENDIAN
  57. #define _BIG_ENDIAN BIG_ENDIAN
  58. #define _PDP_ENDIAN PDP_ENDIAN
  59. #define _BYTE_ORDER BYTE_ORDER
  60. #endif
  61. #ifdef __FreeBSD__
  62. #include <machine/endian.h>
  63. #endif
  64. #ifdef _WIN32
  65. #define _LITTLE_ENDIAN 1234
  66. #define _BIG_ENDIAN 4321
  67. #define _PDP_ENDIAN 3412
  68. #define _BYTE_ORDER _LITTLE_ENDIAN
  69. #define _FLOAT_WORD_ORDER _LITTLE_ENDIAN
  70. #define LITTLE_ENDIAN _LITTLE_ENDIAN
  71. #define BIG_ENDIAN _BIG_ENDIAN
  72. #define PDP_ENDIAN _PDP_ENDIAN
  73. #define BYTE_ORDER _BYTE_ORDER
  74. #endif
  75. #ifndef _IEEE_WORD_ORDER
  76. #define _IEEE_WORD_ORDER _BYTE_ORDER
  77. #endif
  78. union IEEEf2bits {
  79. float f;
  80. struct {
  81. #if _BYTE_ORDER == _LITTLE_ENDIAN
  82. unsigned int man :23;
  83. unsigned int exp :8;
  84. unsigned int sign :1;
  85. #else /* _BIG_ENDIAN */
  86. unsigned int sign :1;
  87. unsigned int exp :8;
  88. unsigned int man :23;
  89. #endif
  90. } bits;
  91. };
  92. #define DBL_MANH_SIZE 20
  93. #define DBL_MANL_SIZE 32
  94. union IEEEd2bits {
  95. double d;
  96. struct {
  97. #if _BYTE_ORDER == _LITTLE_ENDIAN
  98. #if _IEEE_WORD_ORDER == _LITTLE_ENDIAN
  99. unsigned int manl :32;
  100. #endif
  101. unsigned int manh :20;
  102. unsigned int exp :11;
  103. unsigned int sign :1;
  104. #if _IEEE_WORD_ORDER == _BIG_ENDIAN
  105. unsigned int manl :32;
  106. #endif
  107. #else /* _BIG_ENDIAN */
  108. unsigned int sign :1;
  109. unsigned int exp :11;
  110. unsigned int manh :20;
  111. unsigned int manl :32;
  112. #endif
  113. } bits;
  114. };
  115. #endif /* _FPMATH_H */