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