sfp-machine.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. #include <linux/config.h>
  24. #define _FP_W_TYPE_SIZE 32
  25. #define _FP_W_TYPE unsigned long
  26. #define _FP_WS_TYPE signed long
  27. #define _FP_I_TYPE long
  28. #define _FP_MUL_MEAT_S(R,X,Y) \
  29. _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm)
  30. #define _FP_MUL_MEAT_D(R,X,Y) \
  31. _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm)
  32. #define _FP_MUL_MEAT_Q(R,X,Y) \
  33. _FP_MUL_MEAT_4_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm)
  34. #define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_udiv(S,R,X,Y)
  35. #define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_2_udiv(D,R,X,Y)
  36. #define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_4_udiv(Q,R,X,Y)
  37. #define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1)
  38. #define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1), -1
  39. #define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1, -1, -1
  40. #define _FP_NANSIGN_S 0
  41. #define _FP_NANSIGN_D 0
  42. #define _FP_NANSIGN_Q 0
  43. #define _FP_KEEPNANFRACP 1
  44. /* If one NaN is signaling and the other is not,
  45. * we choose that one, otherwise we choose X.
  46. */
  47. /* For _Qp_* and _Q_*, this should prefer X, for
  48. * CPU instruction emulation this should prefer Y.
  49. * (see SPAMv9 B.2.2 section).
  50. */
  51. #define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
  52. do { \
  53. if ((_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs) \
  54. && !(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \
  55. { \
  56. R##_s = X##_s; \
  57. _FP_FRAC_COPY_##wc(R,X); \
  58. } \
  59. else \
  60. { \
  61. R##_s = Y##_s; \
  62. _FP_FRAC_COPY_##wc(R,Y); \
  63. } \
  64. R##_c = FP_CLS_NAN; \
  65. } while (0)
  66. /* Some assembly to speed things up. */
  67. #define __FP_FRAC_ADD_3(r2,r1,r0,x2,x1,x0,y2,y1,y0) \
  68. __asm__ ("addcc %r7,%8,%2\n\t" \
  69. "addxcc %r5,%6,%1\n\t" \
  70. "addx %r3,%4,%0\n" \
  71. : "=r" ((USItype)(r2)), \
  72. "=&r" ((USItype)(r1)), \
  73. "=&r" ((USItype)(r0)) \
  74. : "%rJ" ((USItype)(x2)), \
  75. "rI" ((USItype)(y2)), \
  76. "%rJ" ((USItype)(x1)), \
  77. "rI" ((USItype)(y1)), \
  78. "%rJ" ((USItype)(x0)), \
  79. "rI" ((USItype)(y0)) \
  80. : "cc")
  81. #define __FP_FRAC_SUB_3(r2,r1,r0,x2,x1,x0,y2,y1,y0) \
  82. __asm__ ("subcc %r7,%8,%2\n\t" \
  83. "subxcc %r5,%6,%1\n\t" \
  84. "subx %r3,%4,%0\n" \
  85. : "=r" ((USItype)(r2)), \
  86. "=&r" ((USItype)(r1)), \
  87. "=&r" ((USItype)(r0)) \
  88. : "%rJ" ((USItype)(x2)), \
  89. "rI" ((USItype)(y2)), \
  90. "%rJ" ((USItype)(x1)), \
  91. "rI" ((USItype)(y1)), \
  92. "%rJ" ((USItype)(x0)), \
  93. "rI" ((USItype)(y0)) \
  94. : "cc")
  95. #define __FP_FRAC_ADD_4(r3,r2,r1,r0,x3,x2,x1,x0,y3,y2,y1,y0) \
  96. do { \
  97. /* We need to fool gcc, as we need to pass more than 10 \
  98. input/outputs. */ \
  99. register USItype _t1 __asm__ ("g1"), _t2 __asm__ ("g2"); \
  100. __asm__ __volatile__ ( \
  101. "addcc %r8,%9,%1\n\t" \
  102. "addxcc %r6,%7,%0\n\t" \
  103. "addxcc %r4,%5,%%g2\n\t" \
  104. "addx %r2,%3,%%g1\n\t" \
  105. : "=&r" ((USItype)(r1)), \
  106. "=&r" ((USItype)(r0)) \
  107. : "%rJ" ((USItype)(x3)), \
  108. "rI" ((USItype)(y3)), \
  109. "%rJ" ((USItype)(x2)), \
  110. "rI" ((USItype)(y2)), \
  111. "%rJ" ((USItype)(x1)), \
  112. "rI" ((USItype)(y1)), \
  113. "%rJ" ((USItype)(x0)), \
  114. "rI" ((USItype)(y0)) \
  115. : "cc", "g1", "g2"); \
  116. __asm__ __volatile__ ("" : "=r" (_t1), "=r" (_t2)); \
  117. r3 = _t1; r2 = _t2; \
  118. } while (0)
  119. #define __FP_FRAC_SUB_4(r3,r2,r1,r0,x3,x2,x1,x0,y3,y2,y1,y0) \
  120. do { \
  121. /* We need to fool gcc, as we need to pass more than 10 \
  122. input/outputs. */ \
  123. register USItype _t1 __asm__ ("g1"), _t2 __asm__ ("g2"); \
  124. __asm__ __volatile__ ( \
  125. "subcc %r8,%9,%1\n\t" \
  126. "subxcc %r6,%7,%0\n\t" \
  127. "subxcc %r4,%5,%%g2\n\t" \
  128. "subx %r2,%3,%%g1\n\t" \
  129. : "=&r" ((USItype)(r1)), \
  130. "=&r" ((USItype)(r0)) \
  131. : "%rJ" ((USItype)(x3)), \
  132. "rI" ((USItype)(y3)), \
  133. "%rJ" ((USItype)(x2)), \
  134. "rI" ((USItype)(y2)), \
  135. "%rJ" ((USItype)(x1)), \
  136. "rI" ((USItype)(y1)), \
  137. "%rJ" ((USItype)(x0)), \
  138. "rI" ((USItype)(y0)) \
  139. : "cc", "g1", "g2"); \
  140. __asm__ __volatile__ ("" : "=r" (_t1), "=r" (_t2)); \
  141. r3 = _t1; r2 = _t2; \
  142. } while (0)
  143. #define __FP_FRAC_DEC_3(x2,x1,x0,y2,y1,y0) __FP_FRAC_SUB_3(x2,x1,x0,x2,x1,x0,y2,y1,y0)
  144. #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)
  145. #define __FP_FRAC_ADDI_4(x3,x2,x1,x0,i) \
  146. __asm__ ("addcc %3,%4,%3\n\t" \
  147. "addxcc %2,%%g0,%2\n\t" \
  148. "addxcc %1,%%g0,%1\n\t" \
  149. "addx %0,%%g0,%0\n\t" \
  150. : "=&r" ((USItype)(x3)), \
  151. "=&r" ((USItype)(x2)), \
  152. "=&r" ((USItype)(x1)), \
  153. "=&r" ((USItype)(x0)) \
  154. : "rI" ((USItype)(i)), \
  155. "0" ((USItype)(x3)), \
  156. "1" ((USItype)(x2)), \
  157. "2" ((USItype)(x1)), \
  158. "3" ((USItype)(x0)) \
  159. : "cc")
  160. #ifndef CONFIG_SMP
  161. extern struct task_struct *last_task_used_math;
  162. #endif
  163. /* Obtain the current rounding mode. */
  164. #ifndef FP_ROUNDMODE
  165. #ifdef CONFIG_SMP
  166. #define FP_ROUNDMODE ((current->thread.fsr >> 30) & 0x3)
  167. #else
  168. #define FP_ROUNDMODE ((last_task_used_math->thread.fsr >> 30) & 0x3)
  169. #endif
  170. #endif
  171. /* Exception flags. */
  172. #define FP_EX_INVALID (1 << 4)
  173. #define FP_EX_OVERFLOW (1 << 3)
  174. #define FP_EX_UNDERFLOW (1 << 2)
  175. #define FP_EX_DIVZERO (1 << 1)
  176. #define FP_EX_INEXACT (1 << 0)
  177. #define FP_HANDLE_EXCEPTIONS return _fex
  178. #ifdef CONFIG_SMP
  179. #define FP_INHIBIT_RESULTS ((current->thread.fsr >> 23) & _fex)
  180. #else
  181. #define FP_INHIBIT_RESULTS ((last_task_used_math->thread.fsr >> 23) & _fex)
  182. #endif
  183. #endif