sfp-machine.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* Software floating-point machine description for RISC-V.
  2. Copyright (C) 2016-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #if __riscv_xlen == 32
  20. #define _FP_W_TYPE_SIZE 32
  21. #define _FP_W_TYPE unsigned long
  22. #define _FP_WS_TYPE signed long
  23. #define _FP_I_TYPE long
  24. #define _FP_MUL_MEAT_S(R,X,Y) \
  25. _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm)
  26. #define _FP_MUL_MEAT_D(R,X,Y) \
  27. _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm)
  28. #define _FP_MUL_MEAT_Q(R,X,Y) \
  29. _FP_MUL_MEAT_4_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm)
  30. #define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_udiv_norm(S,R,X,Y)
  31. #define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_2_udiv(D,R,X,Y)
  32. #define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_4_udiv(Q,R,X,Y)
  33. #define _FP_NANFRAC_S _FP_QNANBIT_S
  34. #define _FP_NANFRAC_D _FP_QNANBIT_D, 0
  35. #define _FP_NANFRAC_Q _FP_QNANBIT_Q, 0, 0, 0
  36. #else
  37. #define _FP_W_TYPE_SIZE 64
  38. #define _FP_W_TYPE unsigned long long
  39. #define _FP_WS_TYPE signed long long
  40. #define _FP_I_TYPE long long
  41. #define _FP_MUL_MEAT_S(R,X,Y) \
  42. _FP_MUL_MEAT_1_imm(_FP_WFRACBITS_S,R,X,Y)
  43. #define _FP_MUL_MEAT_D(R,X,Y) \
  44. _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm)
  45. #define _FP_MUL_MEAT_Q(R,X,Y) \
  46. _FP_MUL_MEAT_2_wide_3mul(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm)
  47. #define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_imm(S,R,X,Y,_FP_DIV_HELP_imm)
  48. #define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_1_udiv_norm(D,R,X,Y)
  49. #define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_2_udiv(Q,R,X,Y)
  50. #define _FP_NANFRAC_S _FP_QNANBIT_S
  51. #define _FP_NANFRAC_D _FP_QNANBIT_D
  52. #define _FP_NANFRAC_Q _FP_QNANBIT_Q, 0
  53. #endif
  54. #if __riscv_xlen == 64
  55. typedef int TItype __attribute__ ((mode (TI)));
  56. typedef unsigned int UTItype __attribute__ ((mode (TI)));
  57. #define TI_BITS (__CHAR_BIT__ * (int)sizeof(TItype))
  58. #endif
  59. /* The type of the result of a floating point comparison. This must
  60. match __libgcc_cmp_return__ in GCC for the target. */
  61. typedef int __gcc_CMPtype __attribute__ ((mode (__libgcc_cmp_return__)));
  62. #define CMPtype __gcc_CMPtype
  63. #define _FP_NANSIGN_S 0
  64. #define _FP_NANSIGN_D 0
  65. #define _FP_NANSIGN_Q 0
  66. #define _FP_KEEPNANFRACP 0
  67. #define _FP_QNANNEGATEDP 0
  68. #define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
  69. do { \
  70. R##_s = _FP_NANSIGN_##fs; \
  71. _FP_FRAC_SET_##wc(R,_FP_NANFRAC_##fs); \
  72. R##_c = FP_CLS_NAN; \
  73. } while (0)
  74. #define _FP_DECL_EX int _frm __attribute__ ((unused));
  75. #define FP_ROUNDMODE _frm
  76. #define FP_RND_NEAREST 0x0
  77. #define FP_RND_ZERO 0x1
  78. #define FP_RND_PINF 0x3
  79. #define FP_RND_MINF 0x2
  80. #define FP_EX_INVALID 0x10
  81. #define FP_EX_OVERFLOW 0x04
  82. #define FP_EX_UNDERFLOW 0x02
  83. #define FP_EX_DIVZERO 0x08
  84. #define FP_EX_INEXACT 0x01
  85. #define _FP_TININESS_AFTER_ROUNDING 1
  86. #ifdef __riscv_flen
  87. #define FP_INIT_ROUNDMODE \
  88. do { \
  89. __asm__ volatile ("frrm %0" : "=r" (_frm)); \
  90. } while (0)
  91. #define FP_HANDLE_EXCEPTIONS \
  92. do { \
  93. if (__builtin_expect (_fex, 0)) \
  94. __asm__ volatile ("csrs fflags, %0" : : "rK" (_fex)); \
  95. } while (0)
  96. #else
  97. #define FP_INIT_ROUNDMODE _frm = FP_RND_NEAREST
  98. #endif
  99. #define __LITTLE_ENDIAN 1234
  100. #define __BIG_ENDIAN 4321
  101. #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  102. #define __BYTE_ORDER __BIG_ENDIAN
  103. #else
  104. #define __BYTE_ORDER __LITTLE_ENDIAN
  105. #endif
  106. /* Define ALIASNAME as a strong alias for NAME. */
  107. # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
  108. # define _strong_alias(name, aliasname) \
  109. extern __typeof (name) aliasname __attribute__ ((alias (#name)));