1 /* Software floating-point machine description for RISC-V. 2 3 Copyright (C) 2016-2018 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_S _FP_QNANBIT_S 45 #define _FP_NANFRAC_D _FP_QNANBIT_D, 0 46 #define _FP_NANFRAC_Q _FP_QNANBIT_Q, 0, 0, 0 47 48 #else 49 50 #define _FP_W_TYPE_SIZE 64 51 #define _FP_W_TYPE unsigned long long 52 #define _FP_WS_TYPE signed long long 53 #define _FP_I_TYPE long long 54 55 #define _FP_MUL_MEAT_S(R,X,Y) \ 56 _FP_MUL_MEAT_1_imm(_FP_WFRACBITS_S,R,X,Y) 57 #define _FP_MUL_MEAT_D(R,X,Y) \ 58 _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm) 59 #define _FP_MUL_MEAT_Q(R,X,Y) \ 60 _FP_MUL_MEAT_2_wide_3mul(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm) 61 62 #define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_imm(S,R,X,Y,_FP_DIV_HELP_imm) 63 #define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_1_udiv_norm(D,R,X,Y) 64 #define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_2_udiv(Q,R,X,Y) 65 66 #define _FP_NANFRAC_S _FP_QNANBIT_S 67 #define _FP_NANFRAC_D _FP_QNANBIT_D 68 #define _FP_NANFRAC_Q _FP_QNANBIT_Q, 0 69 70 #endif 71 72 #if __riscv_xlen == 64 73 typedef int TItype __attribute__ ((mode (TI))); 74 typedef unsigned int UTItype __attribute__ ((mode (TI))); 75 #define TI_BITS (__CHAR_BIT__ * (int)sizeof(TItype)) 76 #endif 77 78 /* The type of the result of a floating point comparison. This must 79 match __libgcc_cmp_return__ in GCC for the target. */ 80 typedef int __gcc_CMPtype __attribute__ ((mode (__libgcc_cmp_return__))); 81 #define CMPtype __gcc_CMPtype 82 83 #define _FP_NANSIGN_S 0 84 #define _FP_NANSIGN_D 0 85 #define _FP_NANSIGN_Q 0 86 87 #define _FP_KEEPNANFRACP 0 88 #define _FP_QNANNEGATEDP 0 89 90 #define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \ 91 do { \ 92 R##_s = _FP_NANSIGN_##fs; \ 93 _FP_FRAC_SET_##wc(R,_FP_NANFRAC_##fs); \ 94 R##_c = FP_CLS_NAN; \ 95 } while (0) 96 97 #define _FP_DECL_EX int _frm __attribute__ ((unused)); 98 #define FP_ROUNDMODE _frm 99 100 #define FP_RND_NEAREST 0x0 101 #define FP_RND_ZERO 0x1 102 #define FP_RND_PINF 0x3 103 #define FP_RND_MINF 0x2 104 105 #define FP_EX_INVALID 0x10 106 #define FP_EX_OVERFLOW 0x04 107 #define FP_EX_UNDERFLOW 0x02 108 #define FP_EX_DIVZERO 0x08 109 #define FP_EX_INEXACT 0x01 110 111 #define _FP_TININESS_AFTER_ROUNDING 1 112 113 #ifdef __riscv_flen 114 #define FP_INIT_ROUNDMODE \ 115 do { \ 116 __asm__ volatile ("frrm %0" : "=r" (_frm)); \ 117 } while (0) 118 119 #define FP_HANDLE_EXCEPTIONS \ 120 do { \ 121 if (__builtin_expect (_fex, 0)) \ 122 __asm__ volatile ("csrs fflags, %0" : : "rK" (_fex)); \ 123 } while (0) 124 #else 125 #define FP_INIT_ROUNDMODE _frm = FP_RND_NEAREST 126 #endif 127 128 #define __LITTLE_ENDIAN 1234 129 #define __BIG_ENDIAN 4321 130 131 #define __BYTE_ORDER __LITTLE_ENDIAN 132 133 134 /* Define ALIASNAME as a strong alias for NAME. */ 135 # define strong_alias(name, aliasname) _strong_alias(name, aliasname) 136 # define _strong_alias(name, aliasname) \ 137 extern __typeof (name) aliasname __attribute__ ((alias (#name))); 138