sfp-machine_32.h 6.8 KB

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