| 1 |
/* Software floating-point emulation. |
| 2 |
Compute powers of 10 into _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 "bitint.h" |
| 29 |
|
| 30 |
#ifdef __BITINT_MAXWIDTH__ |
| 31 |
# define BIL_VAL(x) ((UBILtype) (x)) |
| 32 |
# if BIL_TYPE_SIZE == 64 |
| 33 |
# define BIL_PAIR(x, y) ((BIL_VAL (x) << 32) | BIL_VAL (y)) |
| 34 |
# define BIL_OFF(x, y) (x) |
| 35 |
# elif BIL_TYPE_SIZE == 32 |
| 36 |
# if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 37 |
# define BIL_PAIR(x, y) BIL_VAL (x), BIL_VAL (y) |
| 38 |
# else |
| 39 |
# define BIL_PAIR(x, y) BIL_VAL (y), BIL_VAL (x) |
| 40 |
# endif |
| 41 |
# define BIL_OFF(x, y) (y) |
| 42 |
# else |
| 43 |
# error Unsupported _BitInt limb size |
| 44 |
# endif |
| 45 |
#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 46 |
# define BIL_SET2(a, b) a, b |
| 47 |
# define BIL_SET3(a, b, c) a, b, c |
| 48 |
# define BIL_SET4(a, b, c, d) a, b, c, d |
| 49 |
# define BIL_SET5(a, b, c, d, e) a, b, c, d, e |
| 50 |
# define BIL_SET6(a, b, c, d, e, f) a, b, c, d, e, f |
| 51 |
# define BIL_SET7(a, b, c, d, e, f, g) a, b, c, d, e, f, g |
| 52 |
# define BIL_SET8(a, b, c, d, e, f, g, h) a, b, c, d, e, f, g, h |
| 53 |
# define BIL_SET9(a, b, c, d, e, f, g, h, i) a, b, c, d, e, f, g, h, i |
| 54 |
# define BIL_SET10(a, b, c, d, e, f, g, h, i, j) a, b, c, d, e, f, g, h, i, j |
| 55 |
# define BIL_SET11(a, b, c, d, e, f, g, h, i, j, k) \ |
| 56 |
a, b, c, d, e, f, g, h, i, j, k |
| 57 |
# define BIL_SET12(a, b, c, d, e, f, g, h, i, j, k, l) \ |
| 58 |
a, b, c, d, e, f, g, h, i, j, k, l |
| 59 |
# define BIL_SET13(a, b, c, d, e, f, g, h, i, j, k, l, m) \ |
| 60 |
a, b, c, d, e, f, g, h, i, j, k, l, m |
| 61 |
# define BIL_SET14(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \ |
| 62 |
a, b, c, d, e, f, g, h, i, j, k, l, m, n |
| 63 |
# define BIL_SET15(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \ |
| 64 |
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o |
| 65 |
#else |
| 66 |
# define BIL_SET2(a, b) b, a |
| 67 |
# define BIL_SET3(a, b, c) c, b, a |
| 68 |
# define BIL_SET4(a, b, c, d) d, c, b, a |
| 69 |
# define BIL_SET5(a, b, c, d, e) e, d, c, b, a |
| 70 |
# define BIL_SET6(a, b, c, d, e, f) f, e, d, c, b, a |
| 71 |
# define BIL_SET7(a, b, c, d, e, f, g) g, f, e, d, c, b, a |
| 72 |
# define BIL_SET8(a, b, c, d, e, f, g, h) h, g, f, e, d, c, b, a |
| 73 |
# define BIL_SET9(a, b, c, d, e, f, g, h, i) i, h, g, f, e, d, c, b, a |
| 74 |
# define BIL_SET10(a, b, c, d, e, f, g, h, i, j) j, i, h, g, f, e, d, c, b, a |
| 75 |
# define BIL_SET11(a, b, c, d, e, f, g, h, i, j, k) \ |
| 76 |
k, j, i, h, g, f, e, d, c, b, a |
| 77 |
# define BIL_SET12(a, b, c, d, e, f, g, h, i, j, k, l) \ |
| 78 |
l, k, j, i, h, g, f, e, d, c, b, a |
| 79 |
# define BIL_SET13(a, b, c, d, e, f, g, h, i, j, k, l, m) \ |
| 80 |
m, l, k, j, i, h, g, f, e, d, c, b, a |
| 81 |
# define BIL_SET14(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \ |
| 82 |
n, m, l, k, j, i, h, g, f, e, d, c, b, a |
| 83 |
# define BIL_SET15(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \ |
| 84 |
o, n, m, l, k, j, i, h, g, f, e, d, c, b, a |
| 85 |
#endif |
| 86 |
|
| 87 |
#include "bitintpow10.h" |
| 88 |
|
| 89 |
/* Set r (_BitInt limbs with rprec bits) to pow10 (n), |
| 90 |
where n is in [0, 6111]. Returns number of least significant |
| 91 |
limbs with just 0s in it. */ |
| 92 |
|
| 93 |
USItype |
| 94 |
__bid_pow10bitint (UBILtype *r, SItype rprec, USItype n) |
| 95 |
{ |
| 96 |
USItype rn = ((USItype) rprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE; |
| 97 |
if (n <= 256) |
| 98 |
{ |
| 99 |
/* No need to multiply anything, just copy it from pow10_limbs |
| 100 |
array. */ |
| 101 |
USItype low_zeros = (n / 64) * (64 / BIL_TYPE_SIZE); |
| 102 |
UBILtype *p = &pow10_limbs[pow10_offs[n]]; |
| 103 |
USItype cnt = pow10_offs[n + 1] - pow10_offs[n]; |
| 104 |
if (low_zeros) |
| 105 |
__builtin_memset (r + BITINT_END (rn - low_zeros, 0), '\0', |
| 106 |
low_zeros * sizeof (UBILtype)); |
| 107 |
__builtin_memcpy (r + BITINT_END (rn - low_zeros - cnt, low_zeros), |
| 108 |
p, cnt * sizeof (UBILtype)); |
| 109 |
if (rn > low_zeros + cnt) |
| 110 |
__builtin_memset (r + BITINT_END (0, low_zeros + cnt), '\0', |
| 111 |
(rn - low_zeros - cnt) * sizeof (UBILtype)); |
| 112 |
return low_zeros; |
| 113 |
} |
| 114 |
else |
| 115 |
{ |
| 116 |
USItype m = n / 256; |
| 117 |
n &= 255; |
| 118 |
USItype low_zeros = ((n / 64) + (m * 4)) * (64 / BIL_TYPE_SIZE); |
| 119 |
UBILtype *pm = &pow10_limbs[pow10_offs[m + 255]]; |
| 120 |
USItype cntm = pow10_offs[m + 256] - pow10_offs[m + 255]; |
| 121 |
UBILtype *pn = &pow10_limbs[pow10_offs[n]]; |
| 122 |
USItype cntn = pow10_offs[n + 1] - pow10_offs[n]; |
| 123 |
if (low_zeros) |
| 124 |
__builtin_memset (r + BITINT_END (rn - low_zeros, 0), '\0', |
| 125 |
low_zeros * sizeof (UBILtype)); |
| 126 |
__mulbitint3 (r + BITINT_END (0, low_zeros), |
| 127 |
rprec - low_zeros * BIL_TYPE_SIZE, |
| 128 |
pm, cntm * BIL_TYPE_SIZE, pn, cntn * BIL_TYPE_SIZE); |
| 129 |
return low_zeros; |
| 130 |
} |
| 131 |
} |
| 132 |
#endif |