Home | History | Annotate | Line # | Download | only in soft-fp
floatbitinttf.c revision 1.1
      1  1.1  mrg /* Software floating-point emulation.
      2  1.1  mrg    Convert a _BitInt to IEEE quad.
      3  1.1  mrg 
      4  1.1  mrg    Copyright (C) 2023 Free Software Foundation, Inc.
      5  1.1  mrg 
      6  1.1  mrg This file is part of GCC.
      7  1.1  mrg 
      8  1.1  mrg GCC is free software; you can redistribute it and/or modify it under
      9  1.1  mrg the terms of the GNU General Public License as published by the Free
     10  1.1  mrg Software Foundation; either version 3, or (at your option) any later
     11  1.1  mrg version.
     12  1.1  mrg 
     13  1.1  mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
     14  1.1  mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
     15  1.1  mrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     16  1.1  mrg for more details.
     17  1.1  mrg 
     18  1.1  mrg Under Section 7 of GPL version 3, you are granted additional
     19  1.1  mrg permissions described in the GCC Runtime Library Exception, version
     20  1.1  mrg 3.1, as published by the Free Software Foundation.
     21  1.1  mrg 
     22  1.1  mrg You should have received a copy of the GNU General Public License and
     23  1.1  mrg a copy of the GCC Runtime Library Exception along with this program;
     24  1.1  mrg see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     25  1.1  mrg <http://www.gnu.org/licenses/>.  */
     26  1.1  mrg 
     27  1.1  mrg #include "soft-fp.h"
     28  1.1  mrg #include "quad.h"
     29  1.1  mrg #include "bitint.h"
     30  1.1  mrg 
     31  1.1  mrg #ifdef __BITINT_MAXWIDTH__
     32  1.1  mrg #ifndef TI_BITS
     33  1.1  mrg /* As mantissa is 112 bits + 1 implicit bit, we need 128-bit
     34  1.1  mrg    type, but on most 32-bit architectures TImode isn't supported.
     35  1.1  mrg    Use _BitInt(128) instead.  */
     36  1.1  mrg typedef _BitInt(128) TItype;
     37  1.1  mrg typedef unsigned _BitInt(128) UTItype;
     38  1.1  mrg #define TI_BITS 128
     39  1.1  mrg #endif
     40  1.1  mrg 
     41  1.1  mrg TFtype
     42  1.1  mrg __floatbitinttf (const UBILtype *i, SItype iprec)
     43  1.1  mrg {
     44  1.1  mrg   TItype iv;
     45  1.1  mrg   USItype shift = 0;
     46  1.1  mrg   FP_DECL_EX;
     47  1.1  mrg   FP_DECL_Q (A);
     48  1.1  mrg   TFtype a;
     49  1.1  mrg 
     50  1.1  mrg   FP_FROM_BITINT (i, iprec, iv, shift, TI);
     51  1.1  mrg   FP_INIT_ROUNDMODE;
     52  1.1  mrg   FP_FROM_INT_Q (A, iv, TI_BITS, UTItype);
     53  1.1  mrg   if (shift)
     54  1.1  mrg     {
     55  1.1  mrg       A_e += shift;
     56  1.1  mrg       if (A_e >= _FP_EXPMAX_Q)
     57  1.1  mrg 	{
     58  1.1  mrg 	  /* Exponent too big; overflow to infinity.  */
     59  1.1  mrg #if _FP_W_TYPE_SIZE < 64
     60  1.1  mrg 	  _FP_OVERFLOW_SEMIRAW (Q, 4, A);
     61  1.1  mrg 	  _FP_PACK_SEMIRAW (Q, 4, A);
     62  1.1  mrg #else
     63  1.1  mrg 	  _FP_OVERFLOW_SEMIRAW (Q, 2, A);
     64  1.1  mrg 	  _FP_PACK_SEMIRAW (Q, 2, A);
     65  1.1  mrg #endif
     66  1.1  mrg 	}
     67  1.1  mrg     }
     68  1.1  mrg   FP_PACK_RAW_Q (a, A);
     69  1.1  mrg   FP_HANDLE_EXCEPTIONS;
     70  1.1  mrg 
     71  1.1  mrg   return a;
     72  1.1  mrg }
     73  1.1  mrg #endif
     74