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