Home | History | Annotate | Line # | Download | only in soft-fp
      1  1.1  mrg /* Software floating-point emulation.
      2  1.1  mrg    Compute powers of 10 into _BitInt.
      3  1.1  mrg 
      4  1.1  mrg    Copyright (C) 2023 Free Software Foundation, Inc.
      5  1.1  mrg 
      6  1.1  mrg This file is part of GCC.
      7  1.1  mrg 
      8  1.1  mrg GCC is free software; you can redistribute it and/or modify it under
      9  1.1  mrg the terms of the GNU General Public License as published by the Free
     10  1.1  mrg Software Foundation; either version 3, or (at your option) any later
     11  1.1  mrg version.
     12  1.1  mrg 
     13  1.1  mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
     14  1.1  mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
     15  1.1  mrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     16  1.1  mrg for more details.
     17  1.1  mrg 
     18  1.1  mrg Under Section 7 of GPL version 3, you are granted additional
     19  1.1  mrg permissions described in the GCC Runtime Library Exception, version
     20  1.1  mrg 3.1, as published by the Free Software Foundation.
     21  1.1  mrg 
     22  1.1  mrg You should have received a copy of the GNU General Public License and
     23  1.1  mrg a copy of the GCC Runtime Library Exception along with this program;
     24  1.1  mrg see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     25  1.1  mrg <http://www.gnu.org/licenses/>.  */
     26  1.1  mrg 
     27  1.1  mrg #include "soft-fp.h"
     28  1.1  mrg #include "bitint.h"
     29  1.1  mrg 
     30  1.1  mrg #ifdef __BITINT_MAXWIDTH__
     31  1.1  mrg # define BIL_VAL(x) ((UBILtype) (x))
     32  1.1  mrg # if BIL_TYPE_SIZE == 64
     33  1.1  mrg #  define BIL_PAIR(x, y) ((BIL_VAL (x) << 32) | BIL_VAL (y))
     34  1.1  mrg #  define BIL_OFF(x, y) (x)
     35  1.1  mrg # elif BIL_TYPE_SIZE == 32
     36  1.1  mrg #  if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
     37  1.1  mrg #   define BIL_PAIR(x, y) BIL_VAL (x), BIL_VAL (y)
     38  1.1  mrg #  else
     39  1.1  mrg #   define BIL_PAIR(x, y) BIL_VAL (y), BIL_VAL (x)
     40  1.1  mrg #  endif
     41  1.1  mrg #  define BIL_OFF(x, y) (y)
     42  1.1  mrg # else
     43  1.1  mrg #  error Unsupported _BitInt limb size
     44  1.1  mrg # endif
     45  1.1  mrg #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
     46  1.1  mrg # define BIL_SET2(a, b) a, b
     47  1.1  mrg # define BIL_SET3(a, b, c) a, b, c
     48  1.1  mrg # define BIL_SET4(a, b, c, d) a, b, c, d
     49  1.1  mrg # define BIL_SET5(a, b, c, d, e) a, b, c, d, e
     50  1.1  mrg # define BIL_SET6(a, b, c, d, e, f) a, b, c, d, e, f
     51  1.1  mrg # define BIL_SET7(a, b, c, d, e, f, g) a, b, c, d, e, f, g
     52  1.1  mrg # define BIL_SET8(a, b, c, d, e, f, g, h) a, b, c, d, e, f, g, h
     53  1.1  mrg # define BIL_SET9(a, b, c, d, e, f, g, h, i) a, b, c, d, e, f, g, h, i
     54  1.1  mrg # define BIL_SET10(a, b, c, d, e, f, g, h, i, j) a, b, c, d, e, f, g, h, i, j
     55  1.1  mrg # define BIL_SET11(a, b, c, d, e, f, g, h, i, j, k) \
     56  1.1  mrg   a, b, c, d, e, f, g, h, i, j, k
     57  1.1  mrg # define BIL_SET12(a, b, c, d, e, f, g, h, i, j, k, l) \
     58  1.1  mrg   a, b, c, d, e, f, g, h, i, j, k, l
     59  1.1  mrg # define BIL_SET13(a, b, c, d, e, f, g, h, i, j, k, l, m) \
     60  1.1  mrg   a, b, c, d, e, f, g, h, i, j, k, l, m
     61  1.1  mrg # define BIL_SET14(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
     62  1.1  mrg   a, b, c, d, e, f, g, h, i, j, k, l, m, n
     63  1.1  mrg # define BIL_SET15(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
     64  1.1  mrg   a, b, c, d, e, f, g, h, i, j, k, l, m, n, o
     65  1.1  mrg #else
     66  1.1  mrg # define BIL_SET2(a, b) b, a
     67  1.1  mrg # define BIL_SET3(a, b, c) c, b, a
     68  1.1  mrg # define BIL_SET4(a, b, c, d) d, c, b, a
     69  1.1  mrg # define BIL_SET5(a, b, c, d, e) e, d, c, b, a
     70  1.1  mrg # define BIL_SET6(a, b, c, d, e, f) f, e, d, c, b, a
     71  1.1  mrg # define BIL_SET7(a, b, c, d, e, f, g) g, f, e, d, c, b, a
     72  1.1  mrg # define BIL_SET8(a, b, c, d, e, f, g, h) h, g, f, e, d, c, b, a
     73  1.1  mrg # define BIL_SET9(a, b, c, d, e, f, g, h, i) i, h, g, f, e, d, c, b, a
     74  1.1  mrg # define BIL_SET10(a, b, c, d, e, f, g, h, i, j) j, i, h, g, f, e, d, c, b, a
     75  1.1  mrg # define BIL_SET11(a, b, c, d, e, f, g, h, i, j, k) \
     76  1.1  mrg   k, j, i, h, g, f, e, d, c, b, a
     77  1.1  mrg # define BIL_SET12(a, b, c, d, e, f, g, h, i, j, k, l) \
     78  1.1  mrg   l, k, j, i, h, g, f, e, d, c, b, a
     79  1.1  mrg # define BIL_SET13(a, b, c, d, e, f, g, h, i, j, k, l, m) \
     80  1.1  mrg   m, l, k, j, i, h, g, f, e, d, c, b, a
     81  1.1  mrg # define BIL_SET14(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
     82  1.1  mrg   n, m, l, k, j, i, h, g, f, e, d, c, b, a
     83  1.1  mrg # define BIL_SET15(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
     84  1.1  mrg   o, n, m, l, k, j, i, h, g, f, e, d, c, b, a
     85  1.1  mrg #endif
     86  1.1  mrg 
     87  1.1  mrg #include "bitintpow10.h"
     88  1.1  mrg 
     89  1.1  mrg /* Set r (_BitInt limbs with rprec bits) to pow10 (n),
     90  1.1  mrg    where n is in [0, 6111].  Returns number of least significant
     91  1.1  mrg    limbs with just 0s in it.  */
     92  1.1  mrg 
     93  1.1  mrg USItype
     94  1.1  mrg __bid_pow10bitint (UBILtype *r, SItype rprec, USItype n)
     95  1.1  mrg {
     96  1.1  mrg   USItype rn = ((USItype) rprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
     97  1.1  mrg   if (n <= 256)
     98  1.1  mrg     {
     99  1.1  mrg       /* No need to multiply anything, just copy it from pow10_limbs
    100  1.1  mrg 	 array.  */
    101  1.1  mrg       USItype low_zeros = (n / 64) * (64 / BIL_TYPE_SIZE);
    102  1.1  mrg       UBILtype *p = &pow10_limbs[pow10_offs[n]];
    103  1.1  mrg       USItype cnt = pow10_offs[n + 1] - pow10_offs[n];
    104  1.1  mrg       if (low_zeros)
    105  1.1  mrg 	__builtin_memset (r + BITINT_END (rn - low_zeros, 0), '\0',
    106  1.1  mrg 			  low_zeros * sizeof (UBILtype));
    107  1.1  mrg       __builtin_memcpy (r + BITINT_END (rn - low_zeros - cnt, low_zeros),
    108  1.1  mrg 			p, cnt * sizeof (UBILtype));
    109  1.1  mrg       if (rn > low_zeros + cnt)
    110  1.1  mrg 	__builtin_memset (r + BITINT_END (0, low_zeros + cnt), '\0',
    111  1.1  mrg 			  (rn - low_zeros - cnt) * sizeof (UBILtype));
    112  1.1  mrg       return low_zeros;
    113  1.1  mrg     }
    114  1.1  mrg   else
    115  1.1  mrg     {
    116  1.1  mrg       USItype m = n / 256;
    117  1.1  mrg       n &= 255;
    118  1.1  mrg       USItype low_zeros = ((n / 64) + (m * 4)) * (64 / BIL_TYPE_SIZE);
    119  1.1  mrg       UBILtype *pm = &pow10_limbs[pow10_offs[m + 255]];
    120  1.1  mrg       USItype cntm = pow10_offs[m + 256] - pow10_offs[m + 255];
    121  1.1  mrg       UBILtype *pn = &pow10_limbs[pow10_offs[n]];
    122  1.1  mrg       USItype cntn = pow10_offs[n + 1] - pow10_offs[n];
    123  1.1  mrg       if (low_zeros)
    124  1.1  mrg 	__builtin_memset (r + BITINT_END (rn - low_zeros, 0), '\0',
    125  1.1  mrg 			  low_zeros * sizeof (UBILtype));
    126  1.1  mrg       __mulbitint3 (r + BITINT_END (0, low_zeros),
    127  1.1  mrg 		    rprec - low_zeros * BIL_TYPE_SIZE,
    128  1.1  mrg 		    pm, cntm * BIL_TYPE_SIZE, pn, cntn * BIL_TYPE_SIZE);
    129  1.1  mrg       return low_zeros;
    130  1.1  mrg     }
    131  1.1  mrg }
    132  1.1  mrg #endif
    133