sfp-machine.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* RISC-V softfloat definitions
  2. Copyright (C) 2017-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <fenv.h>
  16. #include <fpu_control.h>
  17. #if __riscv_xlen == 32
  18. # define _FP_W_TYPE_SIZE 32
  19. # define _FP_W_TYPE unsigned long
  20. # define _FP_WS_TYPE signed long
  21. # define _FP_I_TYPE long
  22. # define _FP_MUL_MEAT_S(R, X, Y) \
  23. _FP_MUL_MEAT_1_wide (_FP_WFRACBITS_S, R, X, Y, umul_ppmm)
  24. # define _FP_MUL_MEAT_D(R, X, Y) \
  25. _FP_MUL_MEAT_2_wide (_FP_WFRACBITS_D, R, X, Y, umul_ppmm)
  26. # define _FP_MUL_MEAT_Q(R, X, Y) \
  27. _FP_MUL_MEAT_4_wide (_FP_WFRACBITS_Q, R, X, Y, umul_ppmm)
  28. # define _FP_MUL_MEAT_DW_S(R, X, Y) \
  29. _FP_MUL_MEAT_DW_1_wide (_FP_WFRACBITS_S, R, X, Y, umul_ppmm)
  30. # define _FP_MUL_MEAT_DW_D(R, X, Y) \
  31. _FP_MUL_MEAT_DW_2_wide (_FP_WFRACBITS_D, R, X, Y, umul_ppmm)
  32. # define _FP_MUL_MEAT_DW_Q(R, X, Y) \
  33. _FP_MUL_MEAT_DW_4_wide (_FP_WFRACBITS_Q, R, X, Y, umul_ppmm)
  34. # define _FP_DIV_MEAT_S(R, X, Y) _FP_DIV_MEAT_1_udiv_norm (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
  38. # define _FP_NANFRAC_D _FP_QNANBIT_D, 0
  39. # define _FP_NANFRAC_Q _FP_QNANBIT_Q, 0, 0, 0
  40. #else
  41. # define _FP_W_TYPE_SIZE 64
  42. # define _FP_W_TYPE unsigned long
  43. # define _FP_WS_TYPE signed long
  44. # define _FP_I_TYPE long
  45. # define _FP_MUL_MEAT_S(R, X, Y) \
  46. _FP_MUL_MEAT_1_imm (_FP_WFRACBITS_S, R, X, Y)
  47. # define _FP_MUL_MEAT_D(R, X, Y) \
  48. _FP_MUL_MEAT_1_wide (_FP_WFRACBITS_D, R, X, Y, umul_ppmm)
  49. # define _FP_MUL_MEAT_Q(R, X, Y) \
  50. _FP_MUL_MEAT_2_wide_3mul (_FP_WFRACBITS_Q, R, X, Y, umul_ppmm)
  51. # define _FP_MUL_MEAT_DW_S(R, X, Y) \
  52. _FP_MUL_MEAT_DW_1_imm (_FP_WFRACBITS_S, R, X, Y)
  53. # define _FP_MUL_MEAT_DW_D(R, X, Y) \
  54. _FP_MUL_MEAT_DW_1_wide (_FP_WFRACBITS_D, R, X, Y, umul_ppmm)
  55. # define _FP_MUL_MEAT_DW_Q(R, X, Y) \
  56. _FP_MUL_MEAT_DW_2_wide_3mul (_FP_WFRACBITS_Q, R, X, Y, umul_ppmm)
  57. # define _FP_DIV_MEAT_S(R, X, Y) _FP_DIV_MEAT_1_imm (S, R, X, Y, _FP_DIV_HELP_imm)
  58. # define _FP_DIV_MEAT_D(R, X, Y) _FP_DIV_MEAT_1_udiv_norm (D, R, X, Y)
  59. # define _FP_DIV_MEAT_Q(R, X, Y) _FP_DIV_MEAT_2_udiv (Q, R, X, Y)
  60. # define _FP_NANFRAC_S _FP_QNANBIT_S
  61. # define _FP_NANFRAC_D _FP_QNANBIT_D
  62. # define _FP_NANFRAC_Q _FP_QNANBIT_Q, 0
  63. #endif
  64. #define _FP_NANSIGN_S 0
  65. #define _FP_NANSIGN_D 0
  66. #define _FP_NANSIGN_Q 0
  67. #define _FP_KEEPNANFRACP 0
  68. #define _FP_QNANNEGATEDP 0
  69. #define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
  70. do { \
  71. R##_s = _FP_NANSIGN_##fs; \
  72. _FP_FRAC_SET_##wc (R, _FP_NANFRAC_##fs); \
  73. R##_c = FP_CLS_NAN; \
  74. } while (0)
  75. #define _FP_DECL_EX int _frm __attribute__ ((unused));
  76. #define FP_ROUNDMODE _frm
  77. #define FP_RND_NEAREST FE_TONEAREST
  78. #define FP_RND_ZERO FE_TOWARDZERO
  79. #define FP_RND_PINF FE_UPWARD
  80. #define FP_RND_MINF FE_DOWNWARD
  81. #define FP_EX_INVALID FE_INVALID
  82. #define FP_EX_OVERFLOW FE_OVERFLOW
  83. #define FP_EX_UNDERFLOW FE_UNDERFLOW
  84. #define FP_EX_DIVZERO FE_DIVBYZERO
  85. #define FP_EX_INEXACT FE_INEXACT
  86. #define _FP_TININESS_AFTER_ROUNDING 1
  87. #ifdef __riscv_flen
  88. # define FP_INIT_ROUNDMODE \
  89. do { \
  90. __asm__ volatile ("frrm %0" : "=r" (_frm)); \
  91. } while (0)
  92. # define FP_HANDLE_EXCEPTIONS \
  93. do { \
  94. if (__builtin_expect (_fex, 0)) \
  95. __asm__ volatile ("csrs fflags, %0" : : "rK" (_fex)); \
  96. } while (0)
  97. #else
  98. # define FP_INIT_ROUNDMODE _frm = FP_RND_NEAREST
  99. #endif