Home | History | Annotate | Line # | Download | only in loongarch
sfp-machine.h revision 1.1
      1 /* softfp machine description for LoongArch.
      2    Copyright (C) 2021-2022 Free Software Foundation, Inc.
      3 
      4 This file is part of GCC.
      5 
      6 GCC is free software; you can redistribute it and/or modify it under
      7 the terms of the GNU General Public License as published by the Free
      8 Software Foundation; either version 3, or (at your option) any later
      9 version.
     10 
     11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
     12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14 for more details.
     15 
     16 Under Section 7 of GPL version 3, you are granted additional
     17 permissions described in the GCC Runtime Library Exception, version
     18 3.1, as published by the Free Software Foundation.
     19 
     20 You should have received a copy of the GNU General Public License and
     21 a copy of the GCC Runtime Library Exception along with this program;
     22 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     23 <http://www.gnu.org/licenses/>.  */
     24 
     25 #ifdef __loongarch64
     26 #define _FP_W_TYPE_SIZE 64
     27 #define _FP_W_TYPE unsigned long long
     28 #define _FP_WS_TYPE signed long long
     29 #define _FP_I_TYPE long long
     30 
     31 typedef int TItype __attribute__ ((mode (TI)));
     32 typedef unsigned int UTItype __attribute__ ((mode (TI)));
     33 #define TI_BITS (__CHAR_BIT__ * (int) sizeof (TItype))
     34 
     35 #define _FP_MUL_MEAT_S(R, X, Y) \
     36   _FP_MUL_MEAT_1_wide (_FP_WFRACBITS_S, R, X, Y, umul_ppmm)
     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_wide (_FP_WFRACBITS_Q, R, X, Y, umul_ppmm)
     41 
     42 #define _FP_DIV_MEAT_S(R, X, Y) _FP_DIV_MEAT_1_udiv_norm (S, R, X, Y)
     43 #define _FP_DIV_MEAT_D(R, X, Y) _FP_DIV_MEAT_1_udiv_norm (D, R, X, Y)
     44 #define _FP_DIV_MEAT_Q(R, X, Y) _FP_DIV_MEAT_2_udiv (Q, R, X, Y)
     45 
     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 #else
     50 #define _FP_W_TYPE_SIZE 32
     51 #define _FP_W_TYPE unsigned int
     52 #define _FP_WS_TYPE signed int
     53 #define _FP_I_TYPE int
     54 
     55 #define _FP_MUL_MEAT_S(R, X, Y) \
     56   _FP_MUL_MEAT_1_wide (_FP_WFRACBITS_S, R, X, Y, umul_ppmm)
     57 #define _FP_MUL_MEAT_D(R, X, Y) \
     58   _FP_MUL_MEAT_2_wide (_FP_WFRACBITS_D, R, X, Y, umul_ppmm)
     59 #define _FP_MUL_MEAT_Q(R, X, Y) \
     60   _FP_MUL_MEAT_4_wide (_FP_WFRACBITS_Q, R, X, Y, umul_ppmm)
     61 
     62 #define _FP_DIV_MEAT_S(R, X, Y) _FP_DIV_MEAT_1_udiv_norm (S, R, X, Y)
     63 #define _FP_DIV_MEAT_D(R, X, Y) _FP_DIV_MEAT_2_udiv (D, R, X, Y)
     64 #define _FP_DIV_MEAT_Q(R, X, Y) _FP_DIV_MEAT_4_udiv (Q, R, X, Y)
     65 
     66 #define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1)
     67 #define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1), -1
     68 #define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1, -1, -1
     69 #endif
     70 
     71 /* The type of the result of a floating point comparison.  This must
     72    match __libgcc_cmp_return__ in GCC for the target.  */
     73 typedef int __gcc_CMPtype __attribute__ ((mode (__libgcc_cmp_return__)));
     74 #define CMPtype __gcc_CMPtype
     75 
     76 #define _FP_NANSIGN_S 0
     77 #define _FP_NANSIGN_D 0
     78 #define _FP_NANSIGN_Q 0
     79 
     80 #define _FP_KEEPNANFRACP 1
     81 #define _FP_QNANNEGATEDP 0
     82 
     83 /* NaN payloads should be preserved for NAN2008.  */
     84 #define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
     85   do \
     86     { \
     87       R##_s = X##_s; \
     88       _FP_FRAC_COPY_##wc (R, X); \
     89       R##_c = FP_CLS_NAN; \
     90     } \
     91   while (0)
     92 
     93 #ifdef __loongarch_hard_float
     94 #define FP_EX_INVALID 0x100000
     95 #define FP_EX_DIVZERO 0x080000
     96 #define FP_EX_OVERFLOW 0x040000
     97 #define FP_EX_UNDERFLOW 0x020000
     98 #define FP_EX_INEXACT 0x010000
     99 #define FP_EX_ALL \
    100   (FP_EX_INVALID | FP_EX_DIVZERO | FP_EX_OVERFLOW | FP_EX_UNDERFLOW \
    101    | FP_EX_INEXACT)
    102 
    103 #define FP_EX_ENABLE_SHIFT 16
    104 #define FP_EX_CAUSE_SHIFT 8
    105 
    106 #define FP_RND_NEAREST 0x000
    107 #define FP_RND_ZERO 0x100
    108 #define FP_RND_PINF 0x200
    109 #define FP_RND_MINF 0x300
    110 #define FP_RND_MASK 0x300
    111 
    112 #define _FP_DECL_EX \
    113   unsigned long int _fcsr __attribute__ ((unused)) = FP_RND_NEAREST
    114 
    115 #define FP_INIT_ROUNDMODE \
    116   do \
    117     { \
    118       _fcsr = __builtin_loongarch_movfcsr2gr (0); \
    119     } \
    120   while (0)
    121 
    122 #define FP_ROUNDMODE (_fcsr & FP_RND_MASK)
    123 
    124 #define FP_TRAPPING_EXCEPTIONS ((_fcsr << FP_EX_ENABLE_SHIFT) & FP_EX_ALL)
    125 
    126 #define FP_HANDLE_EXCEPTIONS \
    127   do \
    128     { \
    129       _fcsr &= ~(FP_EX_ALL << FP_EX_CAUSE_SHIFT); \
    130       _fcsr |= _fex | (_fex << FP_EX_CAUSE_SHIFT); \
    131       __builtin_loongarch_movgr2fcsr (0, _fcsr); \
    132     } \
    133   while (0)
    134 
    135 #else
    136 #define FP_EX_INVALID (1 << 4)
    137 #define FP_EX_DIVZERO (1 << 3)
    138 #define FP_EX_OVERFLOW (1 << 2)
    139 #define FP_EX_UNDERFLOW (1 << 1)
    140 #define FP_EX_INEXACT (1 << 0)
    141 #endif
    142 
    143 #define _FP_TININESS_AFTER_ROUNDING 1
    144 
    145 #define __LITTLE_ENDIAN 1234
    146 
    147 #define __BYTE_ORDER __LITTLE_ENDIAN
    148 
    149 /* Define ALIASNAME as a strong alias for NAME.  */
    150 #define strong_alias(name, aliasname) _strong_alias (name, aliasname)
    151 #define _strong_alias(name, aliasname) \
    152   extern __typeof (name) aliasname __attribute__ ((alias (#name)));
    153