sfp-machine.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* Machine-dependent software floating-point definitions.
  2. Sparc64 userland (_Q_* and _Qp_*) version.
  3. Copyright (C) 1997-2017 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, see
  18. <http://www.gnu.org/licenses/>. */
  19. #include <fpu_control.h>
  20. #include <fenv.h>
  21. #include <stdlib.h>
  22. #define _FP_W_TYPE_SIZE 64
  23. #define _FP_W_TYPE unsigned long
  24. #define _FP_WS_TYPE signed long
  25. #define _FP_I_TYPE long
  26. /* Helper macros for _FP_MUL_MEAT_2_120_240_double. */
  27. #define _FP_MUL_MEAT_SET_FE_TZ \
  28. do { \
  29. static fpu_control_t _fetz = _FPU_RC_DOWN; \
  30. _FPU_SETCW(_fetz); \
  31. } while (0)
  32. #ifndef _FP_MUL_MEAT_RESET_FE
  33. #define _FP_MUL_MEAT_RESET_FE _FPU_SETCW(_fcw)
  34. #endif
  35. #define _FP_MUL_MEAT_S(R,X,Y) \
  36. _FP_MUL_MEAT_1_imm(_FP_WFRACBITS_S,R,X,Y)
  37. #define _FP_MUL_MEAT_D(R,X,Y) \
  38. _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm)
  39. #define _FP_MUL_MEAT_Q(R,X,Y) \
  40. _FP_MUL_MEAT_2_120_240_double(_FP_WFRACBITS_Q,R,X,Y, \
  41. _FP_MUL_MEAT_SET_FE_TZ, \
  42. _FP_MUL_MEAT_RESET_FE)
  43. #define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_imm(S,R,X,Y,_FP_DIV_HELP_imm)
  44. #define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_1_udiv_norm(D,R,X,Y)
  45. #define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_2_udiv(Q,R,X,Y)
  46. #define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1)
  47. #define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1)
  48. #define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1
  49. #define _FP_NANSIGN_S 0
  50. #define _FP_NANSIGN_D 0
  51. #define _FP_NANSIGN_Q 0
  52. #define _FP_KEEPNANFRACP 1
  53. #define _FP_QNANNEGATEDP 0
  54. /* If one NaN is signaling and the other is not,
  55. * we choose that one, otherwise we choose Y.
  56. */
  57. #define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
  58. do { \
  59. if ((_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs) \
  60. && !(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \
  61. { \
  62. R##_s = X##_s; \
  63. _FP_FRAC_COPY_##wc(R,X); \
  64. } \
  65. else \
  66. { \
  67. R##_s = Y##_s; \
  68. _FP_FRAC_COPY_##wc(R,Y); \
  69. } \
  70. R##_c = FP_CLS_NAN; \
  71. } while (0)
  72. /* Obtain the current rounding mode. */
  73. #ifndef FP_ROUNDMODE
  74. #define FP_ROUNDMODE ((_fcw >> 30) & 0x3)
  75. #endif
  76. /* Exception flags. */
  77. #define FP_EX_INVALID (1 << 4)
  78. #define FP_EX_OVERFLOW (1 << 3)
  79. #define FP_EX_UNDERFLOW (1 << 2)
  80. #define FP_EX_DIVZERO (1 << 1)
  81. #define FP_EX_INEXACT (1 << 0)
  82. #define _FP_TININESS_AFTER_ROUNDING 0
  83. #define _FP_DECL_EX \
  84. fpu_control_t _fcw __attribute__ ((unused)) = (FP_RND_NEAREST << 30)
  85. #define FP_INIT_ROUNDMODE \
  86. do { \
  87. _FPU_GETCW(_fcw); \
  88. } while (0)
  89. #define FP_TRAPPING_EXCEPTIONS ((_fcw >> 23) & 0x1f)
  90. #define FP_INHIBIT_RESULTS ((_fcw >> 23) & _fex)
  91. /* Simulate exceptions using double arithmetics. */
  92. extern void __Qp_handle_exceptions(int exc);
  93. #define FP_HANDLE_EXCEPTIONS \
  94. do { \
  95. if (!_fex) \
  96. { \
  97. /* This is the common case, so we do it inline. \
  98. * We need to clear cexc bits if any. \
  99. */ \
  100. __asm__ __volatile__("fzero %%f62\n\t" \
  101. "faddd %%f62, %%f62, %%f62" \
  102. : : : "f62"); \
  103. } \
  104. else \
  105. { \
  106. __Qp_handle_exceptions (_fex); \
  107. } \
  108. } while (0)
  109. #define QP_HANDLE_EXCEPTIONS(_a) \
  110. do { \
  111. if ((_fcw >> 23) & _fex) \
  112. { \
  113. _a; \
  114. } \
  115. else \
  116. { \
  117. _fcw = (_fcw & ~0x1fL) | (_fex << 5) | _fex; \
  118. _FPU_SETCW(_fcw); \
  119. } \
  120. } while (0)
  121. #define QP_NO_EXCEPTIONS \
  122. __asm ("fzero %%f62\n\t" \
  123. "faddd %%f62, %%f62, %%f62" : : : "f62")
  124. #define QP_CLOBBER "memory", "f52", "f54", "f56", "f58", "f60", "f62"
  125. #define QP_CLOBBER_CC QP_CLOBBER , "cc"