1 /* Software floating-point emulation. 2 Convert IEEE double 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 "double.h" 29 #include "bitint.h" 30 31 #ifdef __BITINT_MAXWIDTH__ 32 void 33 __fixdfbitint (UBILtype *r, SItype rprec, DFtype a) 34 { 35 FP_DECL_EX; 36 FP_DECL_D (A); 37 USItype arprec = rprec < 0 ? -rprec : rprec; 38 USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE; 39 UDItype rv; 40 USItype rsize = arprec > DI_BITS ? DI_BITS : arprec; 41 USItype rsigned = rprec < 0; 42 USItype ovf = 0; 43 USItype shift = 0; 44 45 FP_INIT_EXCEPTIONS; 46 FP_UNPACK_RAW_D (A, a); 47 if (arprec > DI_BITS) 48 { 49 if (A_e < _FP_EXPBIAS_D || (A_s && !rsigned)) 50 ovf = 1; 51 else if (A_e >= (_FP_EXPMAX_D < _FP_EXPBIAS_D + arprec 52 ? _FP_EXPMAX_D 53 : _FP_EXPBIAS_D + arprec - rsigned)) 54 { 55 ovf = 1; 56 if (A_s 57 && A_e == _FP_EXPBIAS_D + arprec - 1 58 && A_e < _FP_EXPMAX_D) 59 A_e -= arprec - DI_BITS; 60 } 61 else if (A_e >= _FP_EXPBIAS_D + DI_BITS - rsigned) 62 { 63 shift = A_e - (_FP_EXPBIAS_D + DI_BITS - rsigned - 1); 64 A_e -= shift; 65 } 66 } 67 FP_TO_INT_D (rv, A, rsize, rsigned); 68 FP_HANDLE_EXCEPTIONS; 69 FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, DI); 70 } 71 #endif 72