| 1 |
/* Software floating-point emulation. |
| 2 |
Convert IEEE quad to signed or unsigned _BitInt. |
| 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 |
|
| 33 |
#ifndef TI_BITS |
| 34 |
/* As mantissa is 112 bits + 1 implicit bit, we need 128-bit |
| 35 |
type, but on most 32-bit architectures TImode isn't supported. |
| 36 |
Use _BitInt(128) instead. */ |
| 37 |
typedef _BitInt(128) TItype; |
| 38 |
typedef unsigned _BitInt(128) UTItype; |
| 39 |
#define TI_BITS 128 |
| 40 |
#endif |
| 41 |
|
| 42 |
void |
| 43 |
__fixtfbitint (UBILtype *r, SItype rprec, TFtype a) |
| 44 |
{ |
| 45 |
FP_DECL_EX; |
| 46 |
FP_DECL_Q (A); |
| 47 |
USItype arprec = rprec < 0 ? -rprec : rprec; |
| 48 |
USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE; |
| 49 |
UTItype rv; |
| 50 |
USItype rsize = arprec > TI_BITS ? TI_BITS : arprec; |
| 51 |
USItype rsigned = rprec < 0; |
| 52 |
USItype ovf = 0; |
| 53 |
USItype shift = 0; |
| 54 |
|
| 55 |
FP_INIT_EXCEPTIONS; |
| 56 |
FP_UNPACK_RAW_Q (A, a); |
| 57 |
if (arprec > TI_BITS) |
| 58 |
{ |
| 59 |
if (A_e < _FP_EXPBIAS_Q || (A_s && !rsigned)) |
| 60 |
ovf = 1; |
| 61 |
else if (A_e >= (_FP_EXPMAX_Q < _FP_EXPBIAS_Q + arprec |
| 62 |
? _FP_EXPMAX_Q |
| 63 |
: _FP_EXPBIAS_Q + arprec - rsigned)) |
| 64 |
{ |
| 65 |
ovf = 1; |
| 66 |
if (A_s |
| 67 |
&& A_e == _FP_EXPBIAS_Q + arprec - 1 |
| 68 |
&& A_e < _FP_EXPMAX_Q) |
| 69 |
A_e -= arprec - TI_BITS; |
| 70 |
} |
| 71 |
else if (A_e >= _FP_EXPBIAS_Q + TI_BITS - rsigned) |
| 72 |
{ |
| 73 |
shift = A_e - (_FP_EXPBIAS_Q + TI_BITS - rsigned - 1); |
| 74 |
A_e -= shift; |
| 75 |
} |
| 76 |
} |
| 77 |
FP_TO_INT_Q (rv, A, rsize, rsigned); |
| 78 |
FP_HANDLE_EXCEPTIONS; |
| 79 |
FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, TI); |
| 80 |
} |
| 81 |
#endif |