sfp-machine.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* Machine-dependent software floating-point definitions.
  2. Sparc userland (_Q_*) version.
  3. Copyright (C) 1997,1998,1999, 2002, 2006 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Richard Henderson (rth@cygnus.com),
  6. Jakub Jelinek (jj@ultra.linux.cz) and
  7. David S. Miller (davem@redhat.com).
  8. The GNU C Library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public
  10. License as published by the Free Software Foundation; either
  11. version 2.1 of the License, or (at your option) any later version.
  12. The GNU C Library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Lesser General Public License for more details.
  16. You should have received a copy of the GNU Lesser General Public
  17. License along with the GNU C Library; if not, write to the Free
  18. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  19. 02111-1307 USA. */
  20. #include <fpu_control.h>
  21. #include <stdlib.h>
  22. #define _FP_W_TYPE_SIZE 32
  23. #define _FP_W_TYPE unsigned long
  24. #define _FP_WS_TYPE signed long
  25. #define _FP_I_TYPE long
  26. #define _FP_MUL_MEAT_S(R,X,Y) \
  27. _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm)
  28. #define _FP_MUL_MEAT_D(R,X,Y) \
  29. _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm)
  30. #define _FP_MUL_MEAT_Q(R,X,Y) \
  31. _FP_MUL_MEAT_4_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm)
  32. #define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_udiv(S,R,X,Y)
  33. #define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_2_udiv(D,R,X,Y)
  34. #define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_4_udiv(Q,R,X,Y)
  35. #define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1)
  36. #define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1), -1
  37. #define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1, -1, -1
  38. #define _FP_NANSIGN_S 0
  39. #define _FP_NANSIGN_D 0
  40. #define _FP_NANSIGN_Q 0
  41. #define _FP_KEEPNANFRACP 1
  42. /* If one NaN is signaling and the other is not,
  43. * we choose that one, otherwise we choose X.
  44. */
  45. /* For _Qp_* and _Q_*, this should prefer X, for
  46. * CPU instruction emulation this should prefer Y.
  47. * (see SPAMv9 B.2.2 section).
  48. */
  49. #define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
  50. do { \
  51. if ((_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs) \
  52. && !(_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs)) \
  53. { \
  54. R##_s = Y##_s; \
  55. _FP_FRAC_COPY_##wc(R,Y); \
  56. } \
  57. else \
  58. { \
  59. R##_s = X##_s; \
  60. _FP_FRAC_COPY_##wc(R,X); \
  61. } \
  62. R##_c = FP_CLS_NAN; \
  63. } while (0)
  64. /* Some assembly to speed things up. */
  65. #define __FP_FRAC_ADD_3(r2,r1,r0,x2,x1,x0,y2,y1,y0) \
  66. __asm__ ("addcc %r7,%8,%2\n\
  67. addxcc %r5,%6,%1\n\
  68. addx %r3,%4,%0" \
  69. : "=r" ((USItype)(r2)), \
  70. "=&r" ((USItype)(r1)), \
  71. "=&r" ((USItype)(r0)) \
  72. : "%rJ" ((USItype)(x2)), \
  73. "rI" ((USItype)(y2)), \
  74. "%rJ" ((USItype)(x1)), \
  75. "rI" ((USItype)(y1)), \
  76. "%rJ" ((USItype)(x0)), \
  77. "rI" ((USItype)(y0)) \
  78. : "cc")
  79. #define __FP_FRAC_SUB_3(r2,r1,r0,x2,x1,x0,y2,y1,y0) \
  80. __asm__ ("subcc %r7,%8,%2\n\
  81. subxcc %r5,%6,%1\n\
  82. subx %r3,%4,%0" \
  83. : "=r" ((USItype)(r2)), \
  84. "=&r" ((USItype)(r1)), \
  85. "=&r" ((USItype)(r0)) \
  86. : "%rJ" ((USItype)(x2)), \
  87. "rI" ((USItype)(y2)), \
  88. "%rJ" ((USItype)(x1)), \
  89. "rI" ((USItype)(y1)), \
  90. "%rJ" ((USItype)(x0)), \
  91. "rI" ((USItype)(y0)) \
  92. : "cc")
  93. #define __FP_FRAC_ADD_4(r3,r2,r1,r0,x3,x2,x1,x0,y3,y2,y1,y0) \
  94. do { \
  95. /* We need to fool gcc, as we need to pass more than 10 \
  96. input/outputs. */ \
  97. register USItype _t1 __asm__ ("g1"), _t2 __asm__ ("g2"); \
  98. __asm__ __volatile__ ("\
  99. addcc %r8,%9,%1\n\
  100. addxcc %r6,%7,%0\n\
  101. addxcc %r4,%5,%%g2\n\
  102. addx %r2,%3,%%g1" \
  103. : "=&r" ((USItype)(r1)), \
  104. "=&r" ((USItype)(r0)) \
  105. : "%rJ" ((USItype)(x3)), \
  106. "rI" ((USItype)(y3)), \
  107. "%rJ" ((USItype)(x2)), \
  108. "rI" ((USItype)(y2)), \
  109. "%rJ" ((USItype)(x1)), \
  110. "rI" ((USItype)(y1)), \
  111. "%rJ" ((USItype)(x0)), \
  112. "rI" ((USItype)(y0)) \
  113. : "cc", "g1", "g2"); \
  114. __asm__ __volatile__ ("" : "=r" (_t1), "=r" (_t2)); \
  115. r3 = _t1; r2 = _t2; \
  116. } while (0)
  117. #define __FP_FRAC_SUB_4(r3,r2,r1,r0,x3,x2,x1,x0,y3,y2,y1,y0) \
  118. do { \
  119. /* We need to fool gcc, as we need to pass more than 10 \
  120. input/outputs. */ \
  121. register USItype _t1 __asm__ ("g1"), _t2 __asm__ ("g2"); \
  122. __asm__ __volatile__ ("\
  123. subcc %r8,%9,%1\n\
  124. subxcc %r6,%7,%0\n\
  125. subxcc %r4,%5,%%g2\n\
  126. subx %r2,%3,%%g1" \
  127. : "=&r" ((USItype)(r1)), \
  128. "=&r" ((USItype)(r0)) \
  129. : "%rJ" ((USItype)(x3)), \
  130. "rI" ((USItype)(y3)), \
  131. "%rJ" ((USItype)(x2)), \
  132. "rI" ((USItype)(y2)), \
  133. "%rJ" ((USItype)(x1)), \
  134. "rI" ((USItype)(y1)), \
  135. "%rJ" ((USItype)(x0)), \
  136. "rI" ((USItype)(y0)) \
  137. : "cc", "g1", "g2"); \
  138. __asm__ __volatile__ ("" : "=r" (_t1), "=r" (_t2)); \
  139. r3 = _t1; r2 = _t2; \
  140. } while (0)
  141. #define __FP_FRAC_DEC_3(x2,x1,x0,y2,y1,y0) __FP_FRAC_SUB_3(x2,x1,x0,x2,x1,x0,y2,y1,y0)
  142. #define __FP_FRAC_DEC_4(x3,x2,x1,x0,y3,y2,y1,y0) __FP_FRAC_SUB_4(x3,x2,x1,x0,x3,x2,x1,x0,y3,y2,y1,y0)
  143. #define __FP_FRAC_ADDI_4(x3,x2,x1,x0,i) \
  144. __asm__ ("addcc %3,%4,%3\n\
  145. addxcc %2,%%g0,%2\n\
  146. addxcc %1,%%g0,%1\n\
  147. addx %0,%%g0,%0" \
  148. : "=&r" ((USItype)(x3)), \
  149. "=&r" ((USItype)(x2)), \
  150. "=&r" ((USItype)(x1)), \
  151. "=&r" ((USItype)(x0)) \
  152. : "rI" ((USItype)(i)), \
  153. "0" ((USItype)(x3)), \
  154. "1" ((USItype)(x2)), \
  155. "2" ((USItype)(x1)), \
  156. "3" ((USItype)(x0)) \
  157. : "cc")
  158. /* Obtain the current rounding mode. */
  159. #ifndef FP_ROUNDMODE
  160. #define FP_ROUNDMODE ((_fcw >> 30) & 0x3)
  161. #endif
  162. /* Exception flags. */
  163. #define FP_EX_INVALID (1 << 4)
  164. #define FP_EX_OVERFLOW (1 << 3)
  165. #define FP_EX_UNDERFLOW (1 << 2)
  166. #define FP_EX_DIVZERO (1 << 1)
  167. #define FP_EX_INEXACT (1 << 0)
  168. #define _FP_DECL_EX fpu_control_t _fcw
  169. #define FP_INIT_ROUNDMODE \
  170. do { \
  171. _FPU_GETCW(_fcw); \
  172. } while (0)
  173. /* Simulate exceptions using double arithmetics. */
  174. extern double ___Q_simulate_exceptions(int exc);
  175. #define FP_HANDLE_EXCEPTIONS \
  176. do { \
  177. if (!_fex) \
  178. { \
  179. /* This is the common case, so we do it inline. \
  180. * We need to clear cexc bits if any. \
  181. */ \
  182. extern unsigned long long ___Q_numbers[]; \
  183. __asm__ __volatile__("\
  184. ldd [%0], %%f30\n\
  185. faddd %%f30, %%f30, %%f30\
  186. " : : "r" (___Q_numbers) : "f30"); \
  187. } \
  188. else \
  189. ___Q_simulate_exceptions (_fex); \
  190. } while (0)