riscv: Allocate enough space to strcpy() string
[official-gcc.git] / libgcc / soft-fp / fixsfbitint.c
blobf6917225601f28fba4ccc5df104ba23026cbaad8
1 /* Software floating-point emulation.
2 Convert IEEE single to signed or unsigned _BitInt.
4 Copyright (C) 2023 Free Software Foundation, Inc.
6 This file is part of GCC.
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.
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.
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.
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/>. */
27 #include "soft-fp.h"
28 #include "single.h"
29 #include "bitint.h"
31 #ifdef __BITINT_MAXWIDTH__
32 void
33 __fixsfbitint (UBILtype *r, SItype rprec, SFtype a)
35 FP_DECL_EX;
36 FP_DECL_S (A);
37 USItype arprec = rprec < 0 ? -rprec : rprec;
38 USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
39 USItype rv;
40 USItype rsize = arprec > SI_BITS ? SI_BITS : arprec;
41 USItype rsigned = rprec < 0;
42 USItype ovf = 0;
43 USItype shift = 0;
45 FP_INIT_EXCEPTIONS;
46 FP_UNPACK_RAW_S (A, a);
47 if (arprec > SI_BITS)
49 if (A_e < _FP_EXPBIAS_S || (A_s && !rsigned))
50 ovf = 1;
51 else if (A_e >= (_FP_EXPMAX_S < _FP_EXPBIAS_S + arprec
52 ? _FP_EXPMAX_S
53 : _FP_EXPBIAS_S + arprec - rsigned))
55 ovf = 1;
56 if (A_s
57 && A_e == _FP_EXPBIAS_S + arprec - 1
58 && A_e < _FP_EXPMAX_S)
59 A_e -= arprec - SI_BITS;
61 else if (A_e >= _FP_EXPBIAS_S + SI_BITS - rsigned)
63 shift = A_e - (_FP_EXPBIAS_S + SI_BITS - rsigned - 1);
64 A_e -= shift;
67 FP_TO_INT_S (rv, A, rsize, rsigned);
68 FP_HANDLE_EXCEPTIONS;
69 FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, SI);
71 #endif