public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 9/12] libgcc _BitInt support [PR102989]
@ 2023-08-09 18:23 Jakub Jelinek
  2023-09-01 21:48 ` Joseph Myers
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2023-08-09 18:23 UTC (permalink / raw)
  To: Joseph S. Myers, Ian Lance Taylor; +Cc: gcc-patches

Hi!

This patch adds the library helpers for multiplication, division + modulo
and casts from and to floating point (both binary and decimal).
As described in the intro, the first step is try to reduce further the
passed in precision by skipping over most significant limbs with just zeros
or sign bit copies.  For multiplication and division I've implemented
a simple algorithm, using something smarter like Karatsuba or Toom N-Way
might be faster for very large _BitInts (which we don't support right now
anyway), but could mean more code in libgcc, which maybe isn't what people
are willing to accept.
For the to/from floating point conversions the patch uses soft-fp, because
it already has tons of handy macros which can be used for that.  In theory
it could be implemented using {,unsigned} long long or {,unsigned} __int128
to/from floating point conversions with some frexp before/after, but at that
point we already need to force it into integer registers and analyze it
anyway.  Plus, for 32-bit arches there is no __int128 that could be used
for XF/TF mode stuff.
I know that soft-fp is owned by glibc and I think the op-common.h change
should be propagated there, but the bitint stuff is really GCC specific
and IMHO doesn't belong into the glibc copy.

2023-08-09  Jakub Jelinek  <jakub@redhat.com>

	PR c/102989
libgcc/
	* config/aarch64/t-softfp (softfp_extras): Use += rather than :=.
	* config/i386/64/t-softfp (softfp_extras): Likewise.
	* config/i386/libgcc-glibc.ver (GCC_14.0.0): Export _BitInt support
	routines.
	* config/i386/t-softfp (softfp_extras): Add fixxfbitint and
	bf, hf and xf mode floatbitint.
	(CFLAGS-floatbitintbf.c, CFLAGS-floatbitinthf.c): Add -msse2.
	* config/riscv/t-softfp32 (softfp_extras): Use += rather than :=.
	* config/rs6000/t-e500v1-fp (softfp_extras): Likewise.
	* config/rs6000/t-e500v2-fp (softfp_extras): Likewise.
	* config/t-softfp (softfp_floatbitint_funcs): New.
	(softfp_bid_list): New.
	(softfp_func_list): Add sf and df mode from and to _BitInt libcalls.
	(softfp_bid_file_list): New.
	(LIB2ADD_ST): Add $(softfp_bid_file_list).
	* config/t-softfp-sfdftf (softfp_extras): Add fixtfbitint and
	floatbitinttf.
	* config/t-softfp-tf (softfp_extras): Likewise.
	* libgcc2.c (bitint_reduce_prec): New inline function.
	(BITINT_INC, BITINT_END): Define.
	(bitint_mul_1, bitint_addmul_1): New helper functions.
	(__mulbitint3): New function.
	(bitint_negate, bitint_submul_1): New helper functions.
	(__divmodbitint4): New function.
	* libgcc2.h (LIBGCC2_UNITS_PER_WORD): When building _BitInt support
	libcalls, redefine depending on __LIBGCC_BITINT_LIMB_WIDTH__.
	(__mulbitint3, __divmodbitint4): Declare.
	* libgcc-std.ver.in (GCC_14.0.0): Export _BitInt support routines.
	* Makefile.in (lib2funcs): Add _mulbitint3.
	(LIB2_DIVMOD_FUNCS): Add _divmodbitint4.
	* soft-fp/bitint.h: New file.
	* soft-fp/fixdfbitint.c: New file.
	* soft-fp/fixsfbitint.c: New file.
	* soft-fp/fixtfbitint.c: New file.
	* soft-fp/fixxfbitint.c: New file.
	* soft-fp/floatbitintbf.c: New file.
	* soft-fp/floatbitintdf.c: New file.
	* soft-fp/floatbitinthf.c: New file.
	* soft-fp/floatbitintsf.c: New file.
	* soft-fp/floatbitinttf.c: New file.
	* soft-fp/floatbitintxf.c: New file.
	* soft-fp/op-common.h (_FP_FROM_INT): Add support for rsize up to
	4 * _FP_W_TYPE_SIZE rather than just 2 * _FP_W_TYPE_SIZE.
	* soft-fp/bitintpow10.c: New file.
	* soft-fp/fixsdbitint.c: New file.
	* soft-fp/fixddbitint.c: New file.
	* soft-fp/fixtdbitint.c: New file.
	* soft-fp/floatbitintsd.c: New file.
	* soft-fp/floatbitintdd.c: New file.
	* soft-fp/floatbitinttd.c: New file.

--- libgcc/config/aarch64/t-softfp.jj	2023-08-08 15:54:35.737595343 +0200
+++ libgcc/config/aarch64/t-softfp	2023-08-08 16:12:02.346939560 +0200
@@ -3,7 +3,7 @@ softfp_int_modes := si di ti
 softfp_extensions := sftf dftf hftf bfsf
 softfp_truncations := tfsf tfdf tfhf tfbf dfbf sfbf hfbf
 softfp_exclude_libgcc2 := n
-softfp_extras := fixhfti fixunshfti floattihf floatuntihf \
+softfp_extras += fixhfti fixunshfti floattihf floatuntihf \
 		 floatdibf floatundibf floattibf floatuntibf
 
 TARGET_LIBGCC2_CFLAGS += -Wno-missing-prototypes
--- libgcc/config/i386/64/t-softfp.jj	2023-08-08 15:54:35.766594936 +0200
+++ libgcc/config/i386/64/t-softfp	2023-08-08 16:12:02.346939560 +0200
@@ -1,4 +1,4 @@
-softfp_extras := fixhfti fixunshfti floattihf floatuntihf \
+softfp_extras += fixhfti fixunshfti floattihf floatuntihf \
 		 floattibf floatuntibf
 
 CFLAGS-fixhfti.c += -msse2
--- libgcc/config/i386/libgcc-glibc.ver.jj	2023-08-08 15:54:35.831594026 +0200
+++ libgcc/config/i386/libgcc-glibc.ver	2023-08-08 16:12:02.347939546 +0200
@@ -226,3 +226,13 @@ GCC_13.0.0 {
   __truncxfbf2
   __trunchfbf2
 }
+
+%inherit GCC_14.0.0 GCC_13.0.0
+GCC_14.0.0 {
+  __PFX__fixxfbitint
+  __PFX__fixtfbitint
+  __PFX__floatbitintbf
+  __PFX__floatbitinthf
+  __PFX__floatbitintxf
+  __PFX__floatbitinttf
+}
--- libgcc/config/i386/t-softfp.jj	2023-08-08 15:55:09.819118062 +0200
+++ libgcc/config/i386/t-softfp	2023-08-08 16:12:02.347939546 +0200
@@ -10,7 +10,7 @@ softfp_extensions := hfsf hfdf hftf hfxf
 softfp_truncations := tfhf xfhf dfhf sfhf tfsf dfsf tfdf tfxf \
 		      tfbf xfbf dfbf sfbf hfbf
 
-softfp_extras += eqhf2
+softfp_extras += eqhf2 fixxfbitint $(foreach m,hf bf xf,floatbitint$(m))
 
 CFLAGS-extendhfsf2.c += -msse2
 CFLAGS-extendhfdf2.c += -msse2
@@ -28,6 +28,9 @@ CFLAGS-truncxfbf2.c += -msse2
 CFLAGS-trunctfbf2.c += -msse2
 CFLAGS-trunchfbf2.c += -msse2
 
+CFLAGS-floatbitintbf.c += -msse2
+CFLAGS-floatbitinthf.c += -msse2
+
 CFLAGS-eqhf2.c += -msse2
 CFLAGS-_divhc3.c += -msse2
 CFLAGS-_mulhc3.c += -msse2
--- libgcc/config/riscv/t-softfp32.jj	2023-08-08 15:54:35.920592780 +0200
+++ libgcc/config/riscv/t-softfp32	2023-08-08 16:12:02.347939546 +0200
@@ -13,7 +13,7 @@ softfp_extensions := sftf dftf
 softfp_truncations := tfsf tfdf
 
 # Enable divide routines to make -mno-fdiv work.
-softfp_extras := divsf3 divdf3
+softfp_extras += divsf3 divdf3
 
 else
 # !ABI_DOUBLE
@@ -28,7 +28,7 @@ else
 # ABI_SINGLE
 
 # Enable divide routines to make -mno-fdiv work.
-softfp_extras := divsf3
+softfp_extras += divsf3
 
 endif
 
@@ -38,7 +38,7 @@ else
 # ABI_QUAD
 
 # Enable divide routines to make -mno-fdiv work.
-softfp_extras := divsf3 divdf3 divtf3
+softfp_extras += divsf3 divdf3 divtf3
 
 endif
 
--- libgcc/config/rs6000/t-e500v1-fp.jj	2023-08-08 15:54:35.965592150 +0200
+++ libgcc/config/rs6000/t-e500v1-fp	2023-08-08 16:12:02.347939546 +0200
@@ -29,4 +29,4 @@ softfp_int_modes := si di
 softfp_extensions := sfdf
 softfp_truncations := dfsf
 softfp_exclude_libgcc2 := n
-softfp_extras := unordsf2
+softfp_extras += unordsf2
--- libgcc/config/rs6000/t-e500v2-fp.jj	2023-08-08 15:54:35.965592150 +0200
+++ libgcc/config/rs6000/t-e500v2-fp	2023-08-08 16:12:02.347939546 +0200
@@ -23,4 +23,4 @@ softfp_int_modes :=
 softfp_extensions :=
 softfp_truncations :=
 softfp_exclude_libgcc2 := n
-softfp_extras := unordsf2 unorddf2
+softfp_extras += unordsf2 unorddf2
--- libgcc/config/t-softfp.jj	2023-08-08 15:54:35.992591772 +0200
+++ libgcc/config/t-softfp	2023-08-08 16:22:09.404440148 +0200
@@ -64,12 +64,21 @@ softfp_float_funcs = add$(m)3 div$(m)3 e
   neg$(m)2 sub$(m)3 unord$(m)2
 softfp_floatint_funcs = fix$(m)$(i) fixuns$(m)$(i) \
   float$(i)$(m) floatun$(i)$(m)
+softfp_floatbitint_funcs = fix$(m)bitint floatbitint$(m)
+softfp_bid_list := 
+ifeq ($(decimal_float),yes)
+ifeq ($(enable_decimal_float),bid)
+softfp_bid_list += bitintpow10 \
+		   $(foreach m,sd dd td,fix$(m)bitint floatbitint$(m))
+endif
+endif
 
 softfp_func_list := \
   $(foreach m,$(softfp_float_modes), \
               $(softfp_float_funcs) \
               $(foreach i,$(softfp_int_modes), \
                           $(softfp_floatint_funcs))) \
+  $(foreach m,sf df,$(softfp_floatbitint_funcs)) \
   $(foreach e,$(softfp_extensions),extend$(e)2) \
   $(foreach t,$(softfp_truncations),trunc$(t)2) \
   $(softfp_extras)
@@ -116,6 +125,8 @@ softfp_file_list := \
   $(addsuffix .c,$(addprefix $(srcdir)/soft-fp/,$(softfp_func_list)))
 endif
 endif
+softfp_bid_file_list := \
+  $(addsuffix .c,$(addprefix $(srcdir)/soft-fp/,$(softfp_bid_list)))
 
 # Disable missing prototype and type limit warnings.  The prototypes
 # for the functions in the soft-fp files have not been brought across
@@ -129,6 +140,7 @@ soft-fp-objects = $(addsuffix $(objext),
 $(soft-fp-objects) : INTERNAL_CFLAGS += -Wno-missing-prototypes -Wno-type-limits
 
 LIB2ADD += $(softfp_file_list)
+LIB2ADD_ST += $(softfp_bid_file_list)
 
 ifneq ($(softfp_exclude_libgcc2),y)
 # Functions in libgcc2.c are excluded for each soft-float mode (a
--- libgcc/config/t-softfp-sfdftf.jj	2023-08-08 15:54:35.992591772 +0200
+++ libgcc/config/t-softfp-sfdftf	2023-08-08 16:12:02.347939546 +0200
@@ -2,4 +2,5 @@ softfp_float_modes := sf df tf
 softfp_int_modes := si di
 softfp_extensions := sfdf sftf dftf xftf
 softfp_truncations := dfsf tfsf tfdf tfxf
+softfp_extras += fixtfbitint floatbitinttf
 softfp_exclude_libgcc2 := n
--- libgcc/config/t-softfp-tf.jj	2023-08-08 15:54:36.011591506 +0200
+++ libgcc/config/t-softfp-tf	2023-08-08 16:12:02.347939546 +0200
@@ -2,4 +2,5 @@ softfp_float_modes := tf
 softfp_int_modes := si di ti
 softfp_extensions := sftf dftf xftf
 softfp_truncations := tfsf tfdf tfxf
+softfp_extras += fixtfbitint floatbitinttf
 softfp_exclude_libgcc2 := n
--- libgcc/libgcc2.c.jj	2023-08-08 15:54:36.059590834 +0200
+++ libgcc/libgcc2.c	2023-08-08 16:12:02.348939532 +0200
@@ -1301,6 +1301,687 @@ __udivdi3 (UDWtype n, UDWtype d)
 }
 #endif
 \f
+#if (defined(__BITINT_MAXWIDTH__) \
+     && (defined(L_mulbitint3) || defined(L_divmodbitint4)))
+/* _BitInt support.  */
+
+/* If *P is zero or sign extended (the latter only for PREC < 0) from
+   some narrower _BitInt value, reduce precision.  */
+
+static inline __attribute__((__always_inline__)) SItype
+bitint_reduce_prec (const UWtype **p, SItype prec)
+{
+  UWtype mslimb;
+  SItype i;
+  if (prec < 0)
+    {
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      i = 0;
+#else
+      i = ((USItype) -1 - prec) / W_TYPE_SIZE;
+#endif
+      mslimb = (*p)[i];
+      if (mslimb & ((UWtype) 1 << (((USItype) -1 - prec) % W_TYPE_SIZE)))
+	{
+	  SItype n = ((USItype) -prec) % W_TYPE_SIZE;
+	  if (n)
+	    {
+	      mslimb |= ((UWtype) -1 << (((USItype) -1 - prec) % W_TYPE_SIZE));
+	      if (mslimb == (UWtype) -1)
+		{
+		  prec += n;
+		  if (prec >= -1)
+		    return -2;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+		  ++p;
+#else
+		  --i;
+#endif
+		  mslimb = (*p)[i];
+		  n = 0;
+		}
+	    }
+	  while (mslimb == (UWtype) -1)
+	    {
+	      prec += W_TYPE_SIZE;
+	      if (prec >= -1)
+		return -2;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+	      ++p;
+#else
+	      --i;
+#endif
+	      mslimb = (*p)[i];
+	    }
+	  if (n == 0)
+	    {
+	      if ((Wtype) mslimb >= 0)
+		{
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+		  --p;
+#endif
+		  return prec - 1;
+		}
+	    }
+	  return prec;
+	}
+      else
+	prec = -prec;
+    }
+  else
+    {
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      i = 0;
+#else
+      i = ((USItype) prec - 1) / W_TYPE_SIZE;
+#endif
+      mslimb = (*p)[i];
+    }
+  SItype n = ((USItype) prec) % W_TYPE_SIZE;
+  if (n)
+    {
+      mslimb &= ((UWtype) 1 << (((USItype) prec) % W_TYPE_SIZE)) - 1;
+      if (mslimb == 0)
+	{
+	  prec -= n;
+	  if (prec == 0)
+	    return 1;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+	  ++p;
+#else
+	  --i;
+#endif
+	  mslimb = (*p)[i];
+	}
+    }
+  while (mslimb == 0)
+    {
+      prec -= W_TYPE_SIZE;
+      if (prec == 0)
+	return 1;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      ++p;
+#else
+      --i;
+#endif
+      mslimb = (*p)[i];
+    }
+  return prec;
+}
+
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+# define BITINT_INC -1
+# define BITINT_END(be, le) (be)
+#else
+# define BITINT_INC 1
+# define BITINT_END(be, le) (le)
+#endif
+
+#ifdef L_mulbitint3
+/* D = S * L.  */
+
+static UWtype
+bitint_mul_1 (UWtype *d, const UWtype *s, UWtype l, SItype n)
+{
+  UWtype sv, hi, lo, c = 0;
+  do
+    {
+      sv = *s;
+      s += BITINT_INC;
+      umul_ppmm (hi, lo, sv, l);
+      c = __builtin_add_overflow (lo, c, &lo) + hi;
+      *d = lo;
+      d += BITINT_INC;
+    }
+  while (--n);
+  return c;
+}
+
+/* D += S * L.  */
+
+static UWtype
+bitint_addmul_1 (UWtype *d, const UWtype *s, UWtype l, SItype n)
+{
+  UWtype sv, hi, lo, c = 0;
+  do
+    {
+      sv = *s;
+      s += BITINT_INC;
+      umul_ppmm (hi, lo, sv, l);
+      hi += __builtin_add_overflow (lo, *d, &lo);
+      c = __builtin_add_overflow (lo, c, &lo) + hi;
+      *d = lo;
+      d += BITINT_INC;
+    }
+  while (--n);
+  return c;
+}
+
+/* If XPREC is positive, it is precision in bits
+   of an unsigned _BitInt operand (which has XPREC/W_TYPE_SIZE
+   full limbs and if Xprec%W_TYPE_SIZE one partial limb.
+   If Xprec is negative, -XPREC is precision in bits
+   of a signed _BitInt operand.  RETPREC should be always
+   positive.  */
+
+void
+__mulbitint3 (UWtype *ret, SItype retprec,
+	      const UWtype *u, SItype uprec,
+	      const UWtype *v, SItype vprec)
+{
+  uprec = bitint_reduce_prec (&u, uprec);
+  vprec = bitint_reduce_prec (&v, vprec);
+  USItype auprec = uprec < 0 ? -uprec : uprec;
+  USItype avprec = vprec < 0 ? -vprec : vprec;
+
+  /* Prefer non-negative U.
+     Otherwise make sure V doesn't have higher precision than U.  */
+  if ((uprec < 0 && vprec >= 0)
+      || (avprec > auprec && !(uprec >= 0 && vprec < 0)))
+    {
+      SItype p;
+      const UWtype *t;
+      p = uprec; uprec = vprec; vprec = p;
+      p = auprec; auprec = avprec; avprec = p;
+      t = u; u = v; v = t;
+    }
+
+  USItype un = auprec / W_TYPE_SIZE;
+  USItype un2 = (auprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
+  USItype vn = avprec / W_TYPE_SIZE;
+  USItype vn2 = (avprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
+  USItype retn = ((USItype) retprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
+  USItype retidx, uidx, vidx;
+  UWtype vv;
+  /* Indexes of least significant limb.  */
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+  retidx = retn - 1;
+  uidx = un2 - 1;
+  vidx = vn2 - 1;
+#else
+  retidx = 0;
+  uidx = 0;
+  vidx = 0;
+#endif
+  if (__builtin_expect (auprec <= W_TYPE_SIZE, 0) && vprec < 0)
+    {
+      UWtype uu = u[uidx];
+      if (__builtin_expect (auprec < W_TYPE_SIZE, 0))
+	uu &= ((UWtype) 1 << (auprec % W_TYPE_SIZE)) - 1;
+      if (uu == 0)
+	{
+	  /* 0 * negative would be otherwise mishandled below, so
+	     handle it specially.  */
+	  __builtin_memset (ret, 0, retn * sizeof (UWtype));
+	  return;
+	}
+    }
+  vv = v[vidx];
+  if (__builtin_expect (avprec < W_TYPE_SIZE, 0))
+    {
+      if (vprec > 0)
+	vv &= ((UWtype) 1 << (avprec % W_TYPE_SIZE)) - 1;
+      else
+	vv |= (UWtype) -1 << (avprec % W_TYPE_SIZE);
+    }
+
+  USItype n = un > retn ? retn : un;
+  USItype n2 = n;
+  USItype retidx2 = retidx + n * BITINT_INC;
+  UWtype c = 0, uv = 0;
+  if (n)
+    c = bitint_mul_1 (ret + retidx, u + uidx, vv, n);
+  if (retn > un && un2 != un)
+    {
+      UWtype hi, lo;
+      uv = u[uidx + n * BITINT_INC];
+      if (uprec > 0)
+	uv &= ((UWtype) 1 << (auprec % W_TYPE_SIZE)) - 1;
+      else
+	uv |= (UWtype) -1 << (auprec % W_TYPE_SIZE);
+      umul_ppmm (hi, lo, uv, vv);
+      c = __builtin_add_overflow (lo, c, &lo) + hi;
+      ret[retidx2] = lo;
+      retidx2 += BITINT_INC;
+      ++n2;
+    }
+  if (retn > un2)
+    {
+      if (uprec < 0)
+	{
+	  while (n2 < retn)
+	    {
+	      if (n2 >= un2 + vn2)
+		break;
+	      UWtype hi, lo;
+	      umul_ppmm (hi, lo, (UWtype) -1, vv);
+	      c = __builtin_add_overflow (lo, c, &lo) + hi;
+	      ret[retidx2] = lo;
+	      retidx2 += BITINT_INC;
+	      ++n2;
+	    }
+	}
+      else
+	{
+	  ret[retidx2] = c;
+	  retidx2 += BITINT_INC;
+	  ++n2;
+	}
+      /* If RET has more limbs than U after precision reduction,
+	 fill in the remaining limbs.  */
+      while (n2 < retn)
+	{
+	  if (n2 < un2 + vn2 || (uprec ^ vprec) >= 0)
+	    c = 0;
+	  else
+	    c = (UWtype) -1;
+	  ret[retidx2] = c;
+	  retidx2 += BITINT_INC;
+	  ++n2;
+	}
+    }
+  /* N is now number of possibly non-zero limbs in RET (ignoring
+     limbs above UN2 + VN2 which if any have been finalized already).  */
+  USItype end = vprec < 0 ? un2 + vn2 : vn2;
+  if (retn > un2 + vn2) retn = un2 + vn2;
+  if (end > retn) end = retn;
+  for (USItype m = 1; m < end; ++m)
+    {
+      retidx += BITINT_INC;
+      vidx += BITINT_INC;
+      if (m < vn2)
+	{
+	  vv = v[vidx];
+	  if (__builtin_expect (m == vn, 0))
+	    {
+	      if (vprec > 0)
+		vv &= ((UWtype) 1 << (avprec % W_TYPE_SIZE)) - 1;
+	      else
+		vv |= (UWtype) -1 << (avprec % W_TYPE_SIZE);
+	    }
+	}
+      else
+	vv = (UWtype) -1;
+      if (m + n > retn)
+	n = retn - m;
+      c = 0;
+      if (n)
+	c = bitint_addmul_1 (ret + retidx, u + uidx, vv, n);
+      n2 = m + n;
+      retidx2 = retidx + n * BITINT_INC;
+      if (n2 < retn && un2 != un)
+	{
+	  UWtype hi, lo;
+	  umul_ppmm (hi, lo, uv, vv);
+	  hi += __builtin_add_overflow (lo, ret[retidx2], &lo);
+	  c = __builtin_add_overflow (lo, c, &lo) + hi;
+	  ret[retidx2] = lo;
+	  retidx2 += BITINT_INC;
+	  ++n2;
+	}
+      if (uprec < 0)
+	while (n2 < retn)
+	  {
+	    UWtype hi, lo;
+	    umul_ppmm (hi, lo, (UWtype) -1, vv);
+	    hi += __builtin_add_overflow (lo, ret[retidx2], &lo);
+	    c = __builtin_add_overflow (lo, c, &lo) + hi;
+	    ret[retidx2] = lo;
+	    retidx2 += BITINT_INC;
+	    ++n2;
+	  }
+      else if (n2 < retn)
+	{
+	  ret[retidx2] = c;
+	  retidx2 += BITINT_INC;
+	}
+    }
+}
+#endif
+
+#ifdef L_divmodbitint4
+static void
+bitint_negate (UWtype *d, const UWtype *s, SItype n)
+{
+  UWtype c = 1;
+  do
+    {
+      UWtype sv = *s, lo;
+      s += BITINT_INC;
+      c = __builtin_add_overflow (~sv, c, &lo);
+      *d = lo;
+      d += BITINT_INC;
+    }
+  while (--n);
+}
+
+/* D -= S * L.  */
+
+static UWtype
+bitint_submul_1 (UWtype *d, const UWtype *s, UWtype l, SItype n)
+{
+  UWtype sv, hi, lo, c = 0;
+  do
+    {
+      sv = *s;
+      s += BITINT_INC;
+      umul_ppmm (hi, lo, sv, l);
+      hi += __builtin_sub_overflow (*d, lo, &lo);
+      c = __builtin_sub_overflow (lo, c, &lo) + hi;
+      *d = lo;
+      d += BITINT_INC;
+    }
+  while (--n);
+  return c;
+}
+
+/* If XPREC is positive, it is precision in bits
+   of an unsigned _BitInt operand (which has XPREC/W_TYPE_SIZE
+   full limbs and if Xprec%W_TYPE_SIZE one partial limb.
+   If Xprec is negative, -XPREC is precision in bits
+   of a signed _BitInt operand.  QPREC and RPREC should be
+   always non-negative.  If either Q or R is NULL (at least
+   one should be non-NULL), then corresponding QPREC or RPREC
+   should be 0.  */
+
+void
+__divmodbitint4 (UWtype *q, SItype qprec,
+		 UWtype *r, SItype rprec,
+		 const UWtype *u, SItype uprec,
+		 const UWtype *v, SItype vprec)
+{
+  uprec = bitint_reduce_prec (&u, uprec);
+  vprec = bitint_reduce_prec (&v, vprec);
+  USItype auprec = uprec < 0 ? -uprec : uprec;
+  USItype avprec = vprec < 0 ? -vprec : vprec;
+  USItype un = (auprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
+  USItype vn = (avprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
+  USItype qn = ((USItype) qprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
+  USItype rn = ((USItype) rprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
+  USItype up = auprec % W_TYPE_SIZE;
+  USItype vp = avprec % W_TYPE_SIZE;
+  if (__builtin_expect (un < vn, 0))
+    {
+      /* If abs(v) > abs(u), then q is 0 and r is u.  */
+      if (q)
+	__builtin_memset (q, 0, qn * sizeof (UWtype));
+      if (r == NULL)
+	return;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      r += rn - 1;
+      u += un - 1;
+#endif
+      if (up)
+	--un;
+      if (rn < un)
+	un = rn;
+      for (rn -= un; un; --un)
+	{
+	  *r = *u;
+	  r += BITINT_INC;
+	  u += BITINT_INC;
+	}
+      if (!rn)
+	return;
+      if (up)
+	{
+	  if (uprec > 0)
+	    *r = *u & (((UWtype) 1 << up) - 1);
+	  else
+	    *r = *u | ((UWtype) -1 << up);
+	  r += BITINT_INC;
+	  if (!--rn)
+	    return;
+	}
+      UWtype c = uprec < 0 ? (UWtype) -1 : (UWtype) 0;
+      for (; rn; --rn)
+	{
+	  *r = c;
+	  r += BITINT_INC;
+	}
+      return;
+    }
+  USItype qn2 = un - vn + 1;
+  if (qn >= qn2)
+    qn2 = 0;
+  USItype sz = un + 1 + vn + qn2;
+  UWtype *buf = __builtin_alloca (sz * sizeof (UWtype));
+  USItype uidx, vidx;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+  uidx = un - 1;
+  vidx = vn - 1;
+#else
+  uidx = 0;
+  vidx = 0;
+#endif
+  if (uprec < 0)
+    bitint_negate (buf + BITINT_END (uidx + 1, 0), u + uidx, un);
+  else
+    __builtin_memcpy (buf + BITINT_END (1, 0), u, un * sizeof (UWtype));
+  if (up)
+    buf[BITINT_END (1, un - 1)] &= (((UWtype) 1 << up) - 1);
+  if (vprec < 0)
+    bitint_negate (buf + un + 1 + vidx, v + vidx, vn);
+  else
+    __builtin_memcpy (buf + un + 1, v, vn * sizeof (UWtype));
+  if (vp)
+    buf[un + 1 + BITINT_END (0, vn - 1)] &= (((UWtype) 1 << vp) - 1);
+  UWtype *u2 = buf;
+  UWtype *v2 = u2 + un + 1;
+  UWtype *q2 = v2 + vn;
+  if (!qn2)
+    q2 = q + BITINT_END (qn - (un - vn + 1), 0);
+
+  /* Knuth's algorithm.  See also ../gcc/wide-int.cc (divmod_internal_2).  */
+
+#ifndef UDIV_NEEDS_NORMALIZATION
+  /* Handle single limb divisor first.  */
+  if (vn == 1)
+    {
+      UWtype vv = v2[0];
+      if (vv == 0)
+	vv = 1 / vv; /* Divide intentionally by zero.  */
+      UWtype k = 0;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      for (SItype i = 0; i <= un - 1; ++i)
+#else
+      for (SItype i = un - 1; i >= 0; --i)
+#endif
+	udiv_qrnnd (q2[i], k, k, u2[BITINT_END (i + 1, i)], vv);
+      if (r != NULL)
+	r[BITINT_END (rn - 1, 0)] = k;
+    }
+  else
+#endif
+    {
+      SItype s;
+#ifdef UDIV_NEEDS_NORMALIZATION
+      if (vn == 1 && v2[0] == 0)
+	s = 0;
+      else
+#endif
+      if (sizeof (0U) == sizeof (UWtype))
+	s = __builtin_clz (v2[BITINT_END (0, vn - 1)]);
+      else if (sizeof (0UL) == sizeof (UWtype))
+	s = __builtin_clzl (v2[BITINT_END (0, vn - 1)]);
+      else
+	s = __builtin_clzll (v2[BITINT_END (0, vn - 1)]);
+      if (s)
+	{
+	  /* Normalize by shifting v2 left so that it has msb set.  */
+	  const SItype n = sizeof (UWtype) * __CHAR_BIT__;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+	  for (SItype i = 0; i < vn - 1; ++i)
+#else
+	  for (SItype i = vn - 1; i > 0; --i)
+#endif
+	    v2[i] = (v2[i] << s) | (v2[i - BITINT_INC] >> (n - s));
+	  v2[vidx] = v2[vidx] << s;
+	  /* And shift u2 left by the same amount.  */
+	  u2[BITINT_END (0, un)] = u2[BITINT_END (1, un - 1)] >> (n - s);
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+	  for (SItype i = 1; i < un; ++i)
+#else
+	  for (SItype i = un - 1; i > 0; --i)
+#endif
+	    u2[i] = (u2[i] << s) | (u2[i - BITINT_INC] >> (n - s));
+	  u2[BITINT_END (un, 0)] = u2[BITINT_END (un, 0)] << s;
+	}
+      else
+	u2[BITINT_END (0, un)] = 0;
+#ifdef UDIV_NEEDS_NORMALIZATION
+      /* Handle single limb divisor first.  */
+      if (vn == 1)
+	{
+	  UWtype vv = v2[0];
+	  if (vv == 0)
+	    vv = 1 / vv; /* Divide intentionally by zero.  */
+	  UWtype k = u2[BITINT_END (0, un)];
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+	  for (SItype i = 0; i <= un - 1; ++i)
+#else
+	  for (SItype i = un - 1; i >= 0; --i)
+#endif
+	    udiv_qrnnd (q2[i], k, k, u2[BITINT_END (i + 1, i)], vv);
+	  if (r != NULL)
+	    r[BITINT_END (rn - 1, 0)] = k >> s;
+	}
+      else
+#endif
+	{
+	  UWtype vv1 = v2[BITINT_END (0, vn - 1)];
+	  UWtype vv0 = v2[BITINT_END (1, vn - 2)];
+	  /* Main loop.  */
+	  for (SItype j = un - vn; j >= 0; --j)
+	    {
+	      /* Compute estimate in qhat.  */
+	      UWtype uv1 = u2[BITINT_END (un - j - vn, j + vn)];
+	      UWtype uv0 = u2[BITINT_END (un - j - vn + 1, j + vn - 1)];
+	      UWtype qhat, rhat, hi, lo, c;
+	      if (uv1 >= vv1)
+		{
+		  /* udiv_qrnnd doesn't support quotients which don't
+		     fit into UWtype, so subtract from uv1:uv0 vv1
+		     first.  */
+		  uv1 -= vv1 + __builtin_sub_overflow (uv0, vv1, &uv0);
+		  udiv_qrnnd (qhat, rhat, uv1, uv0, vv1);
+		  if (!__builtin_add_overflow (rhat, vv1, &rhat))
+		    goto again;
+		}
+	      else
+		{
+		  udiv_qrnnd (qhat, rhat, uv1, uv0, vv1);
+		again:
+		  umul_ppmm (hi, lo, qhat, vv0);
+		  if (hi > rhat
+		      || (hi == rhat
+			  && lo > u2[BITINT_END (un - j - vn + 2,
+						 j + vn - 2)]))
+		    {
+		      --qhat;
+		      if (!__builtin_add_overflow (rhat, vv1, &rhat))
+			goto again;
+		    }
+		}
+
+	      c = bitint_submul_1 (u2 + BITINT_END (un - j, j),
+				   v2 + BITINT_END (vn - 1, 0), qhat, vn);
+	      u2[BITINT_END (un - j - vn, j + vn)] -= c;
+	      /* If we've subtracted too much, decrease qhat and
+		 and add back.  */
+	      if ((Wtype) u2[BITINT_END (un - j - vn, j + vn)] < 0)
+		{
+		  --qhat;
+		  c = 0;
+		  for (USItype i = 0; i < vn; ++i)
+		    {
+		      UWtype s = v2[BITINT_END (vn - 1 - i, i)];
+		      UWtype d = u2[BITINT_END (un - i - j, i + j)];
+		      UWtype c1 = __builtin_add_overflow (d, s, &d);
+		      UWtype c2 = __builtin_add_overflow (d, c, &d);
+		      c = c1 + c2;
+		      u2[BITINT_END (un - i - j, i + j)] = d;
+		    }
+		  u2[BITINT_END (un - j - vn, j + vn)] += c;
+		}
+	      q2[BITINT_END (un - vn - j, j)] = qhat;
+	    }
+	  if (r != NULL)
+	    {
+	      if (s)
+		{
+		  const SItype n = sizeof (UWtype) * __CHAR_BIT__;
+		  /* Unnormalize remainder.  */
+		  USItype i;
+		  for (i = 0; i < vn && i < rn; ++i)
+		    r[BITINT_END (rn - 1 - i, i)]
+		      = ((u2[BITINT_END (un - i, i)] >> s)
+			 | (u2[BITINT_END (un - i - 1, i + 1)] << (n - s)));
+		  if (i < rn)
+		    r[BITINT_END (rn - vn, vn - 1)]
+		      = u2[BITINT_END (un - vn + 1, vn - 1)] >> s;
+		}
+	      else if (rn > vn)
+		__builtin_memcpy (&r[BITINT_END (rn - vn, 0)],
+				  &u2[BITINT_END (un + 1 - vn, 0)],
+				  vn * sizeof (UWtype));
+	      else
+		__builtin_memcpy (&r[0], &u2[BITINT_END (un + 1 - rn, 0)],
+				  rn * sizeof (UWtype));
+	    }
+	}
+    }
+  if (q != NULL)
+    {
+      if ((uprec < 0) ^ (vprec < 0))
+	{
+	  /* Negative quotient.  */
+	  USItype n;
+	  if (un - vn + 1 > qn)
+	    n = qn;
+	  else
+	    n = un - vn + 1;
+	  bitint_negate (q + BITINT_END (qn - 1, 0),
+			 q2 + BITINT_END (un - vn, 0), n);
+	  if (qn > n)
+	    __builtin_memset (q + BITINT_END (0, n), -1,
+			      (qn - n) * sizeof (UWtype));
+	}
+      else
+	{
+	  /* Positive quotient.  */
+	  if (qn2)
+	    __builtin_memcpy (q, q2 + BITINT_END (un - vn + 1 - qn, 0),
+			      qn * sizeof (UWtype));
+	  else if (qn > un - vn + 1)
+	    __builtin_memset (q + BITINT_END (0, un - vn + 1), 0,
+			      (qn - (un - vn + 1)) * sizeof (UWtype));
+	}
+    }
+  if (r != NULL)
+    {
+      if (uprec < 0)
+	{
+	  /* Negative remainder.  */
+	  bitint_negate (r + BITINT_END (rn - 1, 0),
+			 r + BITINT_END (rn - 1, 0),
+			 rn > vn ? vn : rn);
+	  if (rn > vn)
+	    __builtin_memset (r + BITINT_END (0, vn), -1,
+			      (rn - vn) * sizeof (UWtype));
+	}
+      else
+	{
+	  /* Positive remainder.  */
+	  if (rn > vn)
+	    __builtin_memset (r + BITINT_END (0, vn), 0,
+			      (rn - vn) * sizeof (UWtype));
+	}
+    }
+}
+#endif
+#endif
+\f
 #ifdef L_cmpdi2
 cmp_return_type
 __cmpdi2 (DWtype a, DWtype b)
--- libgcc/libgcc2.h.jj	2023-08-08 15:54:36.075590609 +0200
+++ libgcc/libgcc2.h	2023-08-08 16:12:02.348939532 +0200
@@ -181,6 +181,12 @@ typedef int shift_count_type __attribute
 #define float bogus_type
 #define double bogus_type
 
+#if (defined(__BITINT_MAXWIDTH__) \
+     && (defined(L_mulbitint3) || defined(L_divmodbitint4)))
+#undef LIBGCC2_UNITS_PER_WORD
+#define LIBGCC2_UNITS_PER_WORD (__LIBGCC_BITINT_LIMB_WIDTH__ / __CHAR_BIT__)
+#endif
+
 /* Versions prior to 3.4.4 were not taking into account the word size for
    the 5 trapping arithmetic functions absv, addv, subv, mulv and negv.  As
    a consequence, the si and di variants were always and the only ones emitted.
@@ -390,6 +396,15 @@ extern DWtype __divmoddi4 (DWtype, DWtyp
 extern UDWtype __udivmoddi4 (UDWtype, UDWtype, UDWtype *);
 #endif
 
+#if (defined(__BITINT_MAXWIDTH__) \
+     && (defined(L_mulbitint3) || defined(L_divmodbitint4)))
+/* _BitInt support.  */
+extern void __mulbitint3 (UWtype *, SItype, const UWtype *, SItype,
+			  const UWtype *, SItype);
+extern void __divmodbitint4 (UWtype *, SItype, UWtype *, SItype,
+			     const UWtype *, SItype, const UWtype *, SItype);
+#endif
+
 /* __negdi2 is static inline when building other libgcc2 portions.  */
 #if !defined(L_divdi3) && !defined(L_moddi3)
 extern DWtype __negdi2 (DWtype);
--- libgcc/libgcc-std.ver.in.jj	2023-08-08 15:54:36.029591253 +0200
+++ libgcc/libgcc-std.ver.in	2023-08-08 16:12:02.348939532 +0200
@@ -1944,3 +1944,13 @@ GCC_7.0.0 {
   __PFX__divmoddi4
   __PFX__divmodti4
 }
+
+%inherit GCC_14.0.0 GCC_7.0.0
+GCC_14.0.0 {
+  __PFX__mulbitint3
+  __PFX__divmodbitint4
+  __PFX__fixsfbitint
+  __PFX__fixdfbitint
+  __PFX__floatbitintsf
+  __PFX__floatbitintdf
+}
--- libgcc/Makefile.in.jj	2023-08-08 15:54:35.711595707 +0200
+++ libgcc/Makefile.in	2023-08-08 16:12:02.348939532 +0200
@@ -446,7 +446,7 @@ lib2funcs = _muldi3 _negdi2 _lshrdi3 _as
 	    _paritysi2 _paritydi2 _powisf2 _powidf2 _powixf2 _powitf2	   \
 	    _mulhc3 _mulsc3 _muldc3 _mulxc3 _multc3 _divhc3 _divsc3	   \
 	    _divdc3 _divxc3 _divtc3 _bswapsi2 _bswapdi2 _clrsbsi2	   \
-	    _clrsbdi2
+	    _clrsbdi2 _mulbitint3
 
 # The floating-point conversion routines that involve a single-word integer.
 # XX stands for the integer mode.
@@ -466,7 +466,8 @@ endif
 # These might cause a divide overflow trap and so are compiled with
 # unwinder info.
 LIB2_DIVMOD_FUNCS = _divdi3 _moddi3 _divmoddi4 \
-		    _udivdi3 _umoddi3 _udivmoddi4 _udiv_w_sdiv
+		    _udivdi3 _umoddi3 _udivmoddi4 _udiv_w_sdiv \
+		    _divmodbitint4
 
 # Remove any objects from lib2funcs and LIB2_DIVMOD_FUNCS that are
 # defined as optimized assembly code in LIB1ASMFUNCS or as C code
--- libgcc/soft-fp/bitint.h.jj	2023-08-08 16:12:02.348939532 +0200
+++ libgcc/soft-fp/bitint.h	2023-08-08 16:21:45.953768373 +0200
@@ -0,0 +1,329 @@
+/* Software floating-point emulation.
+   Definitions for _BitInt implementation details.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#ifndef GCC_SOFT_FP_BITINT_H
+#define GCC_SOFT_FP_BITINT_H
+
+#ifdef __BITINT_MAXWIDTH__
+#define BIL_UNITS_PER_WORD (__LIBGCC_BITINT_LIMB_WIDTH__ / __CHAR_BIT__)
+
+#if BIL_UNITS_PER_WORD == 8
+#define BIL_TYPE_SIZE (8 * __CHAR_BIT__)
+#define BILtype		DItype
+#define UBILtype	UDItype
+#elif BIL_UNITS_PER_WORD == 4
+#define BIL_TYPE_SIZE (4 * __CHAR_BIT__)
+#define BILtype		SItype
+#define UBILtype	USItype
+#elif BIL_UNITS_PER_WORD == 2
+#define BIL_TYPE_SIZE (2 * __CHAR_BIT__)
+#define BILtype		HItype
+#define UBILtype	UHItype
+#else
+#define BIL_TYPE_SIZE __CHAR_BIT__
+#define BILtype		QItype
+#define UBILtype	UQItype
+#endif
+
+/* If *P is zero or sign extended (the latter only for PREC < 0) from
+   some narrower _BitInt value, reduce precision.  */
+
+static inline __attribute__((__always_inline__)) SItype
+bitint_reduce_prec (const UBILtype **p, SItype prec)
+{
+  UBILtype mslimb;
+  SItype i;
+  if (prec < 0)
+    {
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      i = 0;
+#else
+      i = ((USItype) -1 - prec) / BIL_TYPE_SIZE;
+#endif
+      mslimb = (*p)[i];
+      if (mslimb & ((UBILtype) 1 << (((USItype) -1 - prec) % BIL_TYPE_SIZE)))
+	{
+	  SItype n = ((USItype) -prec) % BIL_TYPE_SIZE;
+	  if (n)
+	    {
+	      mslimb |= ((UBILtype) -1 << (((USItype) -1 - prec) % BIL_TYPE_SIZE));
+	      if (mslimb == (UBILtype) -1)
+		{
+		  prec += n;
+		  if (prec >= -1)
+		    return -2;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+		  ++p;
+#else
+		  --i;
+#endif
+		  mslimb = (*p)[i];
+		  n = 0;
+		}
+	    }
+	  while (mslimb == (UBILtype) -1)
+	    {
+	      prec += BIL_TYPE_SIZE;
+	      if (prec >= -1)
+		return -2;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+	      ++p;
+#else
+	      --i;
+#endif
+	      mslimb = (*p)[i];
+	    }
+	  if (n == 0)
+	    {
+	      if ((BILtype) mslimb >= 0)
+		{
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+		  --p;
+#endif
+		  return prec - 1;
+		}
+	    }
+	  return prec;
+	}
+      else
+	prec = -prec;
+    }
+  else
+    {
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      i = 0;
+#else
+      i = ((USItype) prec - 1) / BIL_TYPE_SIZE;
+#endif
+      mslimb = (*p)[i];
+    }
+  SItype n = ((USItype) prec) % BIL_TYPE_SIZE;
+  if (n)
+    {
+      mslimb &= ((UBILtype) 1 << (((USItype) prec) % BIL_TYPE_SIZE)) - 1;
+      if (mslimb == 0)
+	{
+	  prec -= n;
+	  if (prec == 0)
+	    return 1;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+	  ++p;
+#else
+	  --i;
+#endif
+	  mslimb = (*p)[i];
+	}
+    }
+  while (mslimb == 0)
+    {
+      prec -= BIL_TYPE_SIZE;
+      if (prec == 0)
+	return 1;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      ++p;
+#else
+      --i;
+#endif
+      mslimb = (*p)[i];
+    }
+  return prec;
+}
+
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+# define BITINT_INC -1
+# define BITINT_END(be, le) (be)
+#else
+# define BITINT_INC 1
+# define BITINT_END(be, le) (le)
+#endif
+
+static inline __attribute__((__always_inline__)) void
+bitint_negate (UBILtype *d, const UBILtype *s, SItype n)
+{
+  UBILtype c = 1;
+  do
+    {
+      UBILtype sv = *s, lo;
+      s += BITINT_INC;
+      c = __builtin_add_overflow (~sv, c, &lo);
+      *d = lo;
+      d += BITINT_INC;
+    }
+  while (--n);
+}
+
+#define FP_TO_BITINT(r, rn, arprec, shift, rv, rsize, rsigned, ovf, DI) \
+  if (ovf)								\
+    {									\
+      if ((rv & 1) != 0)						\
+	__builtin_memset (r, -1, rn * sizeof (UBILtype));		\
+      else								\
+	__builtin_memset (r, 0, rn * sizeof (UBILtype));		\
+      if (rv & (((U##DI##type) 1) << (rsize - 1)))			\
+	r[BITINT_END (0, rn - 1)]					\
+	  |= (UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE);		\
+      else								\
+	r[BITINT_END (0, rn - 1)]					\
+	  &= ~((UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE));	\
+    }									\
+  else									\
+    {									\
+      USItype shiftl = shift / BIL_TYPE_SIZE;				\
+      rsize = DI##_BITS;						\
+      if (rsigned && (DI##type) rv >= 0)				\
+	rsigned = 0;							\
+      if (shift + DI##_BITS > arprec)					\
+	rsize = arprec - shift;						\
+      USItype shiftr = shift % BIL_TYPE_SIZE;				\
+      if (shiftl)							\
+	__builtin_memset (r + BITINT_END (rn - shiftl, 0), 0,		\
+			  shiftl * sizeof (UBILtype));			\
+      USItype idx = BITINT_END (rn - shiftl - 1, shiftl);		\
+      DI##type rvs = rv;						\
+      if (shiftr)							\
+	{								\
+	  r[idx] = (rsigned ? (UBILtype) rvs : (UBILtype) rv) << shiftr;\
+	  idx += BITINT_INC;						\
+	  if (rsize > BIL_TYPE_SIZE - shiftr)				\
+	    {								\
+	      rv >>= BIL_TYPE_SIZE - shiftr;				\
+	      rvs >>= BIL_TYPE_SIZE - shiftr;				\
+	      rsize -= BIL_TYPE_SIZE - shiftr;				\
+	    }								\
+	  else								\
+	    rsize = 0;							\
+	}								\
+      while (rsize)							\
+	{								\
+	  r[idx] = rsigned ? (UBILtype) rvs : (UBILtype) rv;		\
+	  idx += BITINT_INC;						\
+	  if (rsize <= BIL_TYPE_SIZE)					\
+	    break;							\
+	  rv >>= (DI##_BITS > BIL_TYPE_SIZE ? BIL_TYPE_SIZE : 0);	\
+	  rvs >>= (DI##_BITS > BIL_TYPE_SIZE ? BIL_TYPE_SIZE : 0);	\
+	  rsize -= BIL_TYPE_SIZE;					\
+	}								\
+      if (idx < rn)							\
+	__builtin_memset (r + BITINT_END (0, idx), rsigned ? -1 : 0,	\
+			  BITINT_END (idx + 1, rn - idx)		\
+			  * sizeof (UBILtype));				\
+    }
+
+#define FP_FROM_BITINT(i, iprec, iv, shift, DI)				\
+  do									\
+    {									\
+      iprec = bitint_reduce_prec (&i, iprec);				\
+      USItype aiprec = iprec < 0 ? -iprec : iprec;			\
+      USItype in = (aiprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;	\
+      USItype idx = BITINT_END (0, in - 1);				\
+      UBILtype msb = i[idx];						\
+      SItype n = 0;							\
+      if (aiprec % BIL_TYPE_SIZE)					\
+	{								\
+	  if (iprec > 0)						\
+	    msb &= ((UBILtype) 1 << (aiprec % BIL_TYPE_SIZE)) - 1;	\
+	  else								\
+	    msb |= (UBILtype) -1 << (aiprec % BIL_TYPE_SIZE);		\
+	}								\
+      if (iprec < 0)							\
+	{								\
+	  n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb);\
+	  if (BIL_TYPE_SIZE > DI##_BITS && n > DI##_BITS)		\
+	    {								\
+	      iv = msb >> (n - DI##_BITS);				\
+	      shift = n - DI##_BITS;					\
+	      n = 0;							\
+	    }								\
+	  else								\
+	    {								\
+	      iv = (BILtype) msb;					\
+	      n = DI##_BITS - n;					\
+	    }								\
+	}								\
+      /* bitint_reduce_prec guarantees that if msb is 0, then whole	\
+	 i must be zero, otherwise it would have reduced the		\
+	 precision.  */							\
+      else if (msb == 0)						\
+	iv = 0;								\
+      else								\
+	{								\
+	  n = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (msb);	\
+	  if (BIL_TYPE_SIZE >= DI##_BITS && n >= DI##_BITS)		\
+	    {								\
+	      iv = msb >> (n - DI##_BITS + 1);				\
+	      shift = n - DI##_BITS + 1;				\
+	      n = 0;							\
+	    }								\
+	  else								\
+	    {								\
+	      iv = msb;							\
+	      n = DI##_BITS - 1 - n;					\
+	    }								\
+	}								\
+      while (n && BITINT_END (idx < in - 1, idx))			\
+	{								\
+	  idx -= BITINT_INC;						\
+	  msb = i[idx];							\
+	  if (BIL_TYPE_SIZE < DI##_BITS && n >= BIL_TYPE_SIZE)		\
+	    {								\
+	      iv = (U##DI##type) iv << (BIL_TYPE_SIZE < DI##_BITS	\
+					? BIL_TYPE_SIZE : 0);		\
+	      iv |= msb;						\
+	      n -= BIL_TYPE_SIZE;					\
+	    }								\
+	  else								\
+	    {								\
+	      iv = (U##DI##type) iv << n;				\
+	      iv |= msb >> (BIL_TYPE_SIZE - n);				\
+	      shift = BIL_TYPE_SIZE - n;				\
+	      break;							\
+	    }								\
+	}								\
+									\
+      UBILtype low_bits = 0;						\
+      if (shift)							\
+	low_bits = msb & (((UBILtype) 1 << shift) - 1);			\
+      shift += BITINT_END (in - 1 - idx, idx) * BIL_TYPE_SIZE;		\
+      while (!low_bits && BITINT_END (idx < in - 1, idx))		\
+	{								\
+	  idx -= BITINT_INC;						\
+	  low_bits |= i[idx];						\
+	}								\
+      iv |= (low_bits != 0);						\
+    }									\
+  while (0)
+
+extern void __mulbitint3 (UBILtype *, SItype, const UBILtype *, SItype,
+			  const UBILtype *, SItype);
+extern void __divmodbitint4 (UBILtype *, SItype, UBILtype *, SItype,
+			     const UBILtype *, SItype,
+			     const UBILtype *, SItype);
+
+extern USItype __bid_pow10bitint (UBILtype *, SItype, USItype);
+
+#endif /* __BITINT_MAXWIDTH__ */
+
+#endif /* GCC_SOFT_FP_BITINT_H */
--- libgcc/soft-fp/fixdfbitint.c.jj	2023-08-08 16:12:02.348939532 +0200
+++ libgcc/soft-fp/fixdfbitint.c	2023-08-08 16:12:02.348939532 +0200
@@ -0,0 +1,71 @@
+/* Software floating-point emulation.
+   Convert IEEE double to signed or unsigned _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "double.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+void
+__fixdfbitint (UBILtype *r, SItype rprec, DFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_D (A);
+  USItype arprec = rprec < 0 ? -rprec : rprec;
+  USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  UDItype rv;
+  USItype rsize = arprec > DI_BITS ? DI_BITS : arprec;
+  USItype rsigned = rprec < 0;
+  USItype ovf = 0;
+  USItype shift = 0;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_D (A, a);
+  if (arprec > DI_BITS)
+    {
+      if (A_e < _FP_EXPBIAS_D || (A_s && !rsigned))
+	ovf = 1;
+      else if (A_e >= (_FP_EXPMAX_D < _FP_EXPBIAS_D + arprec
+		       ? _FP_EXPMAX_D
+		       : _FP_EXPBIAS_D + arprec - rsigned))
+	{
+	  ovf = 1;
+	  if (A_s
+	      && A_e == _FP_EXPBIAS_D + arprec - 1
+	      && A_e < _FP_EXPMAX_D)
+	    A_e -= arprec - DI_BITS;
+	}
+      else if (A_e >= _FP_EXPBIAS_D + DI_BITS - rsigned)
+	{
+	  shift = A_e - (_FP_EXPBIAS_D + DI_BITS - rsigned - 1);
+	  A_e -= shift;
+	}
+    }
+  FP_TO_INT_D (rv, A, rsize, rsigned);
+  FP_HANDLE_EXCEPTIONS;
+  FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, DI);
+}
+#endif
--- libgcc/soft-fp/fixsfbitint.c.jj	2023-08-08 16:12:02.348939532 +0200
+++ libgcc/soft-fp/fixsfbitint.c	2023-08-08 16:12:02.348939532 +0200
@@ -0,0 +1,71 @@
+/* Software floating-point emulation.
+   Convert IEEE single to signed or unsigned _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "single.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+void
+__fixsfbitint (UBILtype *r, SItype rprec, SFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_S (A);
+  USItype arprec = rprec < 0 ? -rprec : rprec;
+  USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  USItype rv;
+  USItype rsize = arprec > SI_BITS ? SI_BITS : arprec;
+  USItype rsigned = rprec < 0;
+  USItype ovf = 0;
+  USItype shift = 0;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_S (A, a);
+  if (arprec > SI_BITS)
+    {
+      if (A_e < _FP_EXPBIAS_S || (A_s && !rsigned))
+	ovf = 1;
+      else if (A_e >= (_FP_EXPMAX_S < _FP_EXPBIAS_S + arprec
+		       ? _FP_EXPMAX_S
+		       : _FP_EXPBIAS_S + arprec - rsigned))
+	{
+	  ovf = 1;
+	  if (A_s
+	      && A_e == _FP_EXPBIAS_S + arprec - 1
+	      && A_e < _FP_EXPMAX_S)
+	    A_e -= arprec - SI_BITS;
+	}
+      else if (A_e >= _FP_EXPBIAS_S + SI_BITS - rsigned)
+	{
+	  shift = A_e - (_FP_EXPBIAS_S + SI_BITS - rsigned - 1);
+	  A_e -= shift;
+	}
+    }
+  FP_TO_INT_S (rv, A, rsize, rsigned);
+  FP_HANDLE_EXCEPTIONS;
+  FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, SI);
+}
+#endif
--- libgcc/soft-fp/fixtfbitint.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/fixtfbitint.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,81 @@
+/* Software floating-point emulation.
+   Convert IEEE quad to signed or unsigned _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "quad.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+
+#ifndef TI_BITS
+/* As mantissa is 112 bits + 1 implicit bit, we need 128-bit
+   type, but on most 32-bit architectures TImode isn't supported.
+   Use _BitInt(128) instead.  */
+typedef _BitInt(128) TItype;
+typedef unsigned _BitInt(128) UTItype;
+#define TI_BITS 128
+#endif
+
+void
+__fixtfbitint (UBILtype *r, SItype rprec, TFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_Q (A);
+  USItype arprec = rprec < 0 ? -rprec : rprec;
+  USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  UTItype rv;
+  USItype rsize = arprec > TI_BITS ? TI_BITS : arprec;
+  USItype rsigned = rprec < 0;
+  USItype ovf = 0;
+  USItype shift = 0;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_Q (A, a);
+  if (arprec > TI_BITS)
+    {
+      if (A_e < _FP_EXPBIAS_Q || (A_s && !rsigned))
+	ovf = 1;
+      else if (A_e >= (_FP_EXPMAX_Q < _FP_EXPBIAS_Q + arprec
+		       ? _FP_EXPMAX_Q
+		       : _FP_EXPBIAS_Q + arprec - rsigned))
+	{
+	  ovf = 1;
+	  if (A_s
+	      && A_e == _FP_EXPBIAS_Q + arprec - 1
+	      && A_e < _FP_EXPMAX_Q)
+	    A_e -= arprec - TI_BITS;
+	}
+      else if (A_e >= _FP_EXPBIAS_Q + TI_BITS - rsigned)
+	{
+	  shift = A_e - (_FP_EXPBIAS_Q + TI_BITS - rsigned - 1);
+	  A_e -= shift;
+	}
+    }
+  FP_TO_INT_Q (rv, A, rsize, rsigned);
+  FP_HANDLE_EXCEPTIONS;
+  FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, TI);
+}
+#endif
--- libgcc/soft-fp/fixxfbitint.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/fixxfbitint.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,82 @@
+/* Software floating-point emulation.
+   Convert IEEE extended to signed or unsigned _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "extended.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+
+#ifndef TI_BITS
+/* While mantissa is 64 bits including 1 explicit bit, extended.h uses
+   op-2.h for W_TYPE_SIZE 64 and op-4.h for W_TYPE_SIZE 32, so we have
+   to use 128-bit type here.  On most 32-bit architectures TImode isn't
+   supported, so use _BitInt(128) instead.  */
+typedef _BitInt(128) TItype;
+typedef unsigned _BitInt(128) UTItype;
+#define TI_BITS 128
+#endif
+
+void
+__fixxfbitint (UBILtype *r, SItype rprec, XFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_E (A);
+  USItype arprec = rprec < 0 ? -rprec : rprec;
+  USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  UTItype rv;
+  USItype rsize = arprec > TI_BITS ? TI_BITS : arprec;
+  USItype rsigned = rprec < 0;
+  USItype ovf = 0;
+  USItype shift = 0;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_E (A, a);
+  if (arprec > TI_BITS)
+    {
+      if (A_e < _FP_EXPBIAS_E || (A_s && !rsigned))
+	ovf = 1;
+      else if (A_e >= (_FP_EXPMAX_E < _FP_EXPBIAS_E + arprec
+		       ? _FP_EXPMAX_E
+		       : _FP_EXPBIAS_E + arprec - rsigned))
+	{
+	  ovf = 1;
+	  if (A_s
+	      && A_e == _FP_EXPBIAS_E + arprec - 1
+	      && A_e < _FP_EXPMAX_E)
+	    A_e -= arprec - TI_BITS;
+	}
+      else if (A_e >= _FP_EXPBIAS_E + TI_BITS - rsigned)
+	{
+	  shift = A_e - (_FP_EXPBIAS_E + TI_BITS - rsigned - 1);
+	  A_e -= shift;
+	}
+    }
+  FP_TO_INT_E (rv, A, rsize, rsigned);
+  FP_HANDLE_EXCEPTIONS;
+  FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, TI);
+}
+#endif
--- libgcc/soft-fp/floatbitintbf.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/floatbitintbf.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,59 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to bfloat16.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "brain.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+BFtype
+__floatbitintbf (const UBILtype *i, SItype iprec)
+{
+  SItype iv;
+  USItype shift = 0;
+  FP_DECL_EX;
+  FP_DECL_B (A);
+  BFtype a;
+
+  FP_FROM_BITINT (i, iprec, iv, shift, SI);
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_B (A, iv, SI_BITS, USItype);
+  if (shift)
+    {
+      A_e += shift;
+      if (A_e >= _FP_EXPMAX_B)
+	{
+	  /* Exponent too big; overflow to infinity.  */
+	  _FP_OVERFLOW_SEMIRAW (B, 1, A);
+	  _FP_PACK_SEMIRAW (B, 1, A);
+	}
+    }
+  FP_PACK_RAW_B (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
+#endif
--- libgcc/soft-fp/floatbitintdf.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/floatbitintdf.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,64 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to IEEE double.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "double.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+DFtype
+__floatbitintdf (const UBILtype *i, SItype iprec)
+{
+  DItype iv;
+  USItype shift = 0;
+  FP_DECL_EX;
+  FP_DECL_D (A);
+  DFtype a;
+
+  FP_FROM_BITINT (i, iprec, iv, shift, DI);
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_D (A, iv, DI_BITS, UDItype);
+  if (shift)
+    {
+      A_e += shift;
+      if (A_e >= _FP_EXPMAX_D)
+	{
+	  /* Exponent too big; overflow to infinity.  */
+#if _FP_W_TYPE_SIZE < 64
+	  _FP_OVERFLOW_SEMIRAW (D, 2, A);
+	  _FP_PACK_SEMIRAW (D, 2, A);
+#else
+	  _FP_OVERFLOW_SEMIRAW (D, 1, A);
+	  _FP_PACK_SEMIRAW (D, 1, A);
+#endif
+	}
+    }
+  FP_PACK_RAW_D (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
+#endif
--- libgcc/soft-fp/floatbitinthf.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/floatbitinthf.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,59 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to IEEE half.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "half.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+HFtype
+__floatbitinthf (const UBILtype *i, SItype iprec)
+{
+  SItype iv;
+  USItype shift = 0;
+  FP_DECL_EX;
+  FP_DECL_H (A);
+  HFtype a;
+
+  FP_FROM_BITINT (i, iprec, iv, shift, SI);
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_H (A, iv, SI_BITS, USItype);
+  if (shift)
+    {
+      A_e += shift;
+      if (A_e >= _FP_EXPMAX_H)
+	{
+	  /* Exponent too big; overflow to infinity.  */
+	  _FP_OVERFLOW_SEMIRAW (H, 1, A);
+	  _FP_PACK_SEMIRAW (H, 1, A);
+	}
+    }
+  FP_PACK_RAW_H (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
+#endif
--- libgcc/soft-fp/floatbitintsf.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/floatbitintsf.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,59 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to IEEE single.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "single.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+SFtype
+__floatbitintsf (const UBILtype *i, SItype iprec)
+{
+  SItype iv;
+  USItype shift = 0;
+  FP_DECL_EX;
+  FP_DECL_S (A);
+  SFtype a;
+
+  FP_FROM_BITINT (i, iprec, iv, shift, SI);
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_S (A, iv, SI_BITS, USItype);
+  if (shift)
+    {
+      A_e += shift;
+      if (A_e >= _FP_EXPMAX_S)
+	{
+	  /* Exponent too big; overflow to infinity.  */
+	  _FP_OVERFLOW_SEMIRAW (S, 1, A);
+	  _FP_PACK_SEMIRAW (S, 1, A);
+	}
+    }
+  FP_PACK_RAW_S (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
+#endif
--- libgcc/soft-fp/floatbitinttf.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/floatbitinttf.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,73 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to IEEE quad.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "quad.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+#ifndef TI_BITS
+/* As mantissa is 112 bits + 1 implicit bit, we need 128-bit
+   type, but on most 32-bit architectures TImode isn't supported.
+   Use _BitInt(128) instead.  */
+typedef _BitInt(128) TItype;
+typedef unsigned _BitInt(128) UTItype;
+#define TI_BITS 128
+#endif
+
+TFtype
+__floatbitinttf (const UBILtype *i, SItype iprec)
+{
+  TItype iv;
+  USItype shift = 0;
+  FP_DECL_EX;
+  FP_DECL_Q (A);
+  TFtype a;
+
+  FP_FROM_BITINT (i, iprec, iv, shift, TI);
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_Q (A, iv, TI_BITS, UTItype);
+  if (shift)
+    {
+      A_e += shift;
+      if (A_e >= _FP_EXPMAX_Q)
+	{
+	  /* Exponent too big; overflow to infinity.  */
+#if _FP_W_TYPE_SIZE < 64
+	  _FP_OVERFLOW_SEMIRAW (Q, 4, A);
+	  _FP_PACK_SEMIRAW (Q, 4, A);
+#else
+	  _FP_OVERFLOW_SEMIRAW (Q, 2, A);
+	  _FP_PACK_SEMIRAW (Q, 2, A);
+#endif
+	}
+    }
+  FP_PACK_RAW_Q (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
+#endif
--- libgcc/soft-fp/floatbitintxf.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/floatbitintxf.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,74 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to IEEE extended.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "extended.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+#ifndef TI_BITS
+/* While mantissa is 64 bits including 1 explicit bit, extended.h uses
+   op-2.h for W_TYPE_SIZE 64 and op-4.h for W_TYPE_SIZE 32, so we have
+   to use 128-bit type here.  On most 32-bit architectures TImode isn't
+   supported, so use _BitInt(128) instead.  */
+typedef _BitInt(128) TItype;
+typedef unsigned _BitInt(128) UTItype;
+#define TI_BITS 128
+#endif
+
+XFtype
+__floatbitintxf (const UBILtype *i, SItype iprec)
+{
+  TItype iv;
+  USItype shift = 0;
+  FP_DECL_EX;
+  FP_DECL_E (A);
+  XFtype a;
+
+  FP_FROM_BITINT (i, iprec, iv, shift, TI);
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_E (A, iv, TI_BITS, UTItype);
+  if (shift)
+    {
+      A_e += shift;
+      if (A_e >= _FP_EXPMAX_E)
+	{
+	  /* Exponent too big; overflow to infinity.  */
+#if _FP_W_TYPE_SIZE < 64
+	  _FP_OVERFLOW_SEMIRAW (E, 4, A);
+	  _FP_PACK_SEMIRAW (E, 4, A);
+#else
+	  _FP_OVERFLOW_SEMIRAW (E, 2, A);
+	  _FP_PACK_SEMIRAW (E, 2, A);
+#endif
+	}
+    }
+  FP_PACK_RAW_E (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
+#endif
--- libgcc/soft-fp/op-common.h.jj	2023-08-08 15:54:36.110590119 +0200
+++ libgcc/soft-fp/op-common.h	2023-08-08 16:12:02.349939518 +0200
@@ -1800,7 +1800,7 @@
 	  if ((X##_s = ((r) < 0)))					\
 	    _FP_FROM_INT_ur = -_FP_FROM_INT_ur;				\
 									\
-	  _FP_STATIC_ASSERT ((rsize) <= 2 * _FP_W_TYPE_SIZE,		\
+	  _FP_STATIC_ASSERT ((rsize) <= 4 * _FP_W_TYPE_SIZE,		\
 			     "rsize too large");			\
 	  (void) (((rsize) <= _FP_W_TYPE_SIZE)				\
 		  ? ({							\
@@ -1810,13 +1810,38 @@
 		      X##_e = (_FP_EXPBIAS_##fs + _FP_W_TYPE_SIZE - 1	\
 			       - _FP_FROM_INT_lz);			\
 		    })							\
-		  : ({						\
+		  : ((rsize) <= 2 * _FP_W_TYPE_SIZE)			\
+		  ? ({							\
 		      int _FP_FROM_INT_lz;				\
 		      __FP_CLZ_2 (_FP_FROM_INT_lz,			\
 				  (_FP_W_TYPE) (_FP_FROM_INT_ur		\
 						>> _FP_W_TYPE_SIZE),	\
 				  (_FP_W_TYPE) _FP_FROM_INT_ur);	\
-		      X##_e = (_FP_EXPBIAS_##fs + 2 * _FP_W_TYPE_SIZE - 1 \
+		      X##_e = (_FP_EXPBIAS_##fs				\
+			       + 2 * _FP_W_TYPE_SIZE - 1		\
+			       - _FP_FROM_INT_lz);			\
+		    })							\
+		  : ({							\
+		      int _FP_FROM_INT_lz;				\
+		      if (_FP_FROM_INT_ur >> (2 * _FP_W_TYPE_SIZE))	\
+			{						\
+			  rtype _FP_FROM_INT_uru			\
+			    = _FP_FROM_INT_ur >> (2 * _FP_W_TYPE_SIZE);	\
+			  __FP_CLZ_2 (_FP_FROM_INT_lz,			\
+				      (_FP_W_TYPE) (_FP_FROM_INT_uru	\
+						    >> _FP_W_TYPE_SIZE),\
+				      (_FP_W_TYPE) _FP_FROM_INT_uru);	\
+			}						\
+		      else						\
+			{						\
+			  __FP_CLZ_2 (_FP_FROM_INT_lz,			\
+				      (_FP_W_TYPE) (_FP_FROM_INT_ur	\
+						    >> _FP_W_TYPE_SIZE),\
+				      (_FP_W_TYPE) _FP_FROM_INT_ur);	\
+			  _FP_FROM_INT_lz += 2 * _FP_W_TYPE_SIZE;	\
+			}						\
+		      X##_e = (_FP_EXPBIAS_##fs				\
+			       + 4 * _FP_W_TYPE_SIZE - 1		\
 			       - _FP_FROM_INT_lz);			\
 		    }));						\
 									\
--- libgcc/soft-fp/bitintpow10.c.jj	2023-08-08 16:21:45.956768331 +0200
+++ libgcc/soft-fp/bitintpow10.c	2023-08-09 15:22:45.519805895 +0200
@@ -0,0 +1,132 @@
+/* Software floating-point emulation.
+   Compute powers of 10 into _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+# define BIL_VAL(x) ((UBILtype) (x))
+# if BIL_TYPE_SIZE == 64
+#  define BIL_PAIR(x, y) ((BIL_VAL (x) << 32) | BIL_VAL (y))
+#  define BIL_OFF(x, y) (x)
+# elif BIL_TYPE_SIZE == 32
+#  if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+#   define BIL_PAIR(x, y) BIL_VAL (x), BIL_VAL (y)
+#  else
+#   define BIL_PAIR(x, y) BIL_VAL (y), BIL_VAL (x)
+#  endif
+#  define BIL_OFF(x, y) (y)
+# else
+#  error Unsupported _BitInt limb size
+# endif
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+# define BIL_SET2(a, b) a, b
+# define BIL_SET3(a, b, c) a, b, c
+# define BIL_SET4(a, b, c, d) a, b, c, d
+# define BIL_SET5(a, b, c, d, e) a, b, c, d, e
+# define BIL_SET6(a, b, c, d, e, f) a, b, c, d, e, f
+# define BIL_SET7(a, b, c, d, e, f, g) a, b, c, d, e, f, g
+# define BIL_SET8(a, b, c, d, e, f, g, h) a, b, c, d, e, f, g, h
+# define BIL_SET9(a, b, c, d, e, f, g, h, i) a, b, c, d, e, f, g, h, i
+# define BIL_SET10(a, b, c, d, e, f, g, h, i, j) a, b, c, d, e, f, g, h, i, j
+# define BIL_SET11(a, b, c, d, e, f, g, h, i, j, k) \
+  a, b, c, d, e, f, g, h, i, j, k
+# define BIL_SET12(a, b, c, d, e, f, g, h, i, j, k, l) \
+  a, b, c, d, e, f, g, h, i, j, k, l
+# define BIL_SET13(a, b, c, d, e, f, g, h, i, j, k, l, m) \
+  a, b, c, d, e, f, g, h, i, j, k, l, m
+# define BIL_SET14(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
+  a, b, c, d, e, f, g, h, i, j, k, l, m, n
+# define BIL_SET15(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
+  a, b, c, d, e, f, g, h, i, j, k, l, m, n, o
+#else
+# define BIL_SET2(a, b) b, a
+# define BIL_SET3(a, b, c) c, b, a
+# define BIL_SET4(a, b, c, d) d, c, b, a
+# define BIL_SET5(a, b, c, d, e) e, d, c, b, a
+# define BIL_SET6(a, b, c, d, e, f) f, e, d, c, b, a
+# define BIL_SET7(a, b, c, d, e, f, g) g, f, e, d, c, b, a
+# define BIL_SET8(a, b, c, d, e, f, g, h) h, g, f, e, d, c, b, a
+# define BIL_SET9(a, b, c, d, e, f, g, h, i) i, h, g, f, e, d, c, b, a
+# define BIL_SET10(a, b, c, d, e, f, g, h, i, j) j, i, h, g, f, e, d, c, b, a
+# define BIL_SET11(a, b, c, d, e, f, g, h, i, j, k) \
+  k, j, i, h, g, f, e, d, c, b, a
+# define BIL_SET12(a, b, c, d, e, f, g, h, i, j, k, l) \
+  l, k, j, i, h, g, f, e, d, c, b, a
+# define BIL_SET13(a, b, c, d, e, f, g, h, i, j, k, l, m) \
+  m, l, k, j, i, h, g, f, e, d, c, b, a
+# define BIL_SET14(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
+  n, m, l, k, j, i, h, g, f, e, d, c, b, a
+# define BIL_SET15(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
+  o, n, m, l, k, j, i, h, g, f, e, d, c, b, a
+#endif
+
+#include "bitintpow10.h"
+
+/* Set r (_BitInt limbs with rprec bits) to pow10 (n),
+   where n is in [0, 6111].  Returns number of least significant
+   limbs with just 0s in it.  */
+
+USItype
+__bid_pow10bitint (UBILtype *r, SItype rprec, USItype n)
+{
+  USItype rn = ((USItype) rprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  if (n <= 256)
+    {
+      /* No need to multiply anything, just copy it from pow10_limbs
+	 array.  */
+      USItype low_zeros = (n / 64) * (64 / BIL_TYPE_SIZE);
+      UBILtype *p = &pow10_limbs[pow10_offs[n]];
+      USItype cnt = pow10_offs[n + 1] - pow10_offs[n];
+      if (low_zeros)
+	__builtin_memset (r + BITINT_END (rn - low_zeros, 0), '\0',
+			  low_zeros * sizeof (UBILtype));
+      __builtin_memcpy (r + BITINT_END (rn - low_zeros - cnt, low_zeros),
+			p, cnt * sizeof (UBILtype));
+      if (rn > low_zeros + cnt)
+	__builtin_memset (r + BITINT_END (0, low_zeros + cnt), '\0',
+			  (rn - low_zeros - cnt) * sizeof (UBILtype));
+      return low_zeros;
+    }
+  else
+    {
+      USItype m = n / 256;
+      n &= 255;
+      USItype low_zeros = ((n / 64) + (m * 4)) * (64 / BIL_TYPE_SIZE);
+      UBILtype *pm = &pow10_limbs[pow10_offs[m + 255]];
+      USItype cntm = pow10_offs[m + 256] - pow10_offs[m + 255];
+      UBILtype *pn = &pow10_limbs[pow10_offs[n]];
+      USItype cntn = pow10_offs[n + 1] - pow10_offs[n];
+      if (low_zeros)
+	__builtin_memset (r + BITINT_END (rn - low_zeros, 0), '\0',
+			  low_zeros * sizeof (UBILtype));
+      __mulbitint3 (r + BITINT_END (0, low_zeros),
+		    rprec - low_zeros * BIL_TYPE_SIZE,
+		    pm, cntm * BIL_TYPE_SIZE, pn, cntn * BIL_TYPE_SIZE);
+      return low_zeros;
+    }
+}
+#endif
--- libgcc/soft-fp/fixsdbitint.c.jj	2023-08-08 16:21:45.953768373 +0200
+++ libgcc/soft-fp/fixsdbitint.c	2023-08-08 16:21:45.953768373 +0200
@@ -0,0 +1,196 @@
+/* Software floating-point emulation.
+   Convert _Decimal32 to signed or unsigned _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+extern void __bid_fixsdbitint (UBILtype *, SItype, _Decimal32);
+
+void
+__bid_fixsdbitint (UBILtype *r, SItype rprec, _Decimal32 a)
+{
+  FP_DECL_EX;
+  USItype arprec = rprec < 0 ? -rprec : rprec;
+  USItype rn = (arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  union { _Decimal32 d; USItype u; } u;
+  USItype mantissa, t;
+  SItype sgn;
+  SItype exponent;
+  USItype exp_bits, mant_bits;
+  UBILtype *pow10v, *resv;
+  USItype pow10_limbs, res_limbs, min_limbs, mant_limbs, low_zeros;
+
+  FP_INIT_EXCEPTIONS;
+  u.d = a;
+  t = u.u >> 21;
+  sgn = (SItype) u.u < 0;
+  if ((t & (3 << 8)) != (3 << 8))
+    {
+      mantissa = u.u & ((((USItype) 1) << 23) - 1);
+      exponent = (t >> 2) & 0xff;
+    }
+  else if ((t & (3 << 6)) != (3 << 6))
+    {
+      mantissa = u.u & ((((USItype) 1) << 21) - 1);
+      mantissa |= ((USItype) 1) << 23;
+      exponent = t & 0xff;
+      if (mantissa > (USItype) 9999999)
+	mantissa = 0;
+    }
+  else
+    {
+      FP_SET_EXCEPTION (FP_EX_INVALID
+			| FP_EX_INVALID_CVI
+			| ((FP_EX_INVALID_SNAN
+			    && ((t & 0x20)) != 0)
+			   ? FP_EX_INVALID_SNAN : 0));
+    ovf:
+      if (!sgn)
+	__builtin_memset (r, -1, rn * sizeof (UBILtype));
+      else
+	__builtin_memset (r, 0, rn * sizeof (UBILtype));
+      if (sgn ^ (rprec >= 0))
+	r[BITINT_END (0, rn - 1)]
+	  |= (UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE);
+      else
+	r[BITINT_END (0, rn - 1)]
+	  &= ~((UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE));
+      goto done;
+    }
+  exponent -= 101;
+
+  if (mantissa == 0)
+    {
+      /* Zero (with any exponent).  */
+    zero:
+      __builtin_memset (r, 0, rn * sizeof (UBILtype));
+      goto done;
+    }
+  if (exponent <= -7)
+    {
+      FP_SET_EXCEPTION (FP_EX_INEXACT);
+      goto zero;
+    }
+  else if (exponent < 0)
+    {
+      UBILtype limbs[64 / BIL_TYPE_SIZE];
+      USItype rem;
+      UDItype d;
+      __bid_pow10bitint (limbs, 64, -exponent);
+#if BIL_TYPE_SIZE == 64
+      d = limbs[0];
+#elif BIL_TYPE_SIZE == 32
+      d = (limbs[BITINT_END (0, 1)] << 32) | limbs[BITINT_END (1, 0)];
+#else
+# error Unsupported BIL_TYPE_SIZE
+#endif
+      rem = mantissa % (USItype) d;
+      mantissa /= (USItype) d;
+      if (rem)
+	FP_SET_EXCEPTION (FP_EX_INEXACT);
+      if (mantissa == 0)
+	goto zero;
+      exponent = 0;
+    }
+
+  if (rprec >= 0 && sgn)
+    {
+    ovf_ex:
+      FP_SET_EXCEPTION (FP_EX_INVALID | FP_EX_INVALID_CVI);
+      goto ovf;
+    }
+
+  /* Lower estimate for number of bits needed for pow10 (exponent).  */
+  exp_bits = exponent / 3;
+  exp_bits = exp_bits * 10 - exp_bits / 29;
+  mant_bits = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (mantissa);
+  if (exp_bits + mant_bits > arprec + 1)
+    goto ovf_ex;
+  /* Upper estimate for number of bits needed for pow10 (exponent).  */
+  exp_bits = (exponent + 2) / 3;
+  exp_bits = exp_bits * 10 - exp_bits / 30;
+  if (exp_bits == 0)
+    exp_bits = 1;
+  pow10_limbs = (exp_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  pow10v = __builtin_alloca (pow10_limbs * sizeof (UBILtype));
+  low_zeros = __bid_pow10bitint (pow10v, exp_bits, exponent);
+
+  res_limbs = ((exp_bits + mant_bits + BIL_TYPE_SIZE - 1)
+	       / BIL_TYPE_SIZE) - low_zeros;
+  mant_limbs = 1;
+  resv = __builtin_alloca ((res_limbs + mant_limbs) * sizeof (UBILtype));
+  resv[res_limbs] = mantissa;
+  __mulbitint3 (resv, exp_bits + mant_bits - low_zeros * BIL_TYPE_SIZE,
+		resv + res_limbs, mant_bits,
+		pow10v + BITINT_END (0, low_zeros),
+		exp_bits - low_zeros * BIL_TYPE_SIZE);
+  if (res_limbs + low_zeros >= rn)
+    {
+      if (res_limbs + low_zeros > rn && resv[BITINT_END (0, res_limbs - 1)])
+	goto ovf_ex;
+      if ((arprec % BIL_TYPE_SIZE) != 0
+	  && (resv[BITINT_END (rn - res_limbs, rn - 1) - low_zeros]
+	      & ((UBILtype) -1 << (arprec % BIL_TYPE_SIZE))) != 0)
+	goto ovf_ex;
+      min_limbs = rn - low_zeros;
+    }
+  else
+    min_limbs = res_limbs;
+  if (low_zeros)
+    __builtin_memset (r + BITINT_END (rn - low_zeros, 0), '\0',
+		      low_zeros * sizeof (UBILtype));
+  if (sgn)
+    bitint_negate (r + BITINT_END (rn - low_zeros - 1, low_zeros),
+		   resv + BITINT_END (res_limbs - 1, 0), min_limbs);
+  else
+    __builtin_memcpy (r + BITINT_END (rn - low_zeros - min_limbs, low_zeros),
+		      resv + BITINT_END (res_limbs - min_limbs, 0),
+		      min_limbs * sizeof (UBILtype));
+  if (res_limbs + low_zeros < rn)
+    {
+      if (sgn)
+	__builtin_memset (r + BITINT_END (0, res_limbs + low_zeros), -1,
+			  (rn - res_limbs - low_zeros) * sizeof (UBILtype));
+      else
+	__builtin_memset (r + BITINT_END (0, res_limbs + low_zeros), '\0',
+			  (rn - res_limbs - low_zeros) * sizeof (UBILtype));
+    }
+  else if (sgn)
+    {
+      if ((r[BITINT_END (0, rn - 1)]
+	   & ((UBILtype) 1 << ((arprec - 1) % BIL_TYPE_SIZE))) == 0)
+	goto ovf_ex;
+    }
+  else if (rprec < 0
+	   && (r[BITINT_END (0, rn - 1)]
+	       & ((UBILtype) 1 << ((arprec - 1) % BIL_TYPE_SIZE))) != 0)
+    goto ovf_ex;
+
+done:
+  FP_HANDLE_EXCEPTIONS;
+}
+#endif
--- libgcc/soft-fp/fixddbitint.c.jj	2023-08-08 16:21:45.953768373 +0200
+++ libgcc/soft-fp/fixddbitint.c	2023-08-08 16:21:45.953768373 +0200
@@ -0,0 +1,205 @@
+/* Software floating-point emulation.
+   Convert _Decimal64 to signed or unsigned _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+extern void __bid_fixddbitint (UBILtype *, SItype, _Decimal64);
+
+void
+__bid_fixddbitint (UBILtype *r, SItype rprec, _Decimal64 a)
+{
+  FP_DECL_EX;
+  USItype arprec = rprec < 0 ? -rprec : rprec;
+  USItype rn = (arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  union { _Decimal64 d; UDItype u; } u;
+  UDItype mantissa, t;
+  SItype sgn;
+  SItype exponent;
+  USItype exp_bits, mant_bits;
+  UBILtype *pow10v, *resv;
+  USItype pow10_limbs, res_limbs, min_limbs, mant_limbs, low_zeros;
+
+  FP_INIT_EXCEPTIONS;
+  u.d = a;
+  t = u.u >> 51;
+  sgn = (DItype) u.u < 0;
+  if ((t & (3 << 10)) != (3 << 10))
+    {
+      mantissa = u.u & ((((UDItype) 1) << 53) - 1);
+      exponent = (t >> 2) & 0x3ff;
+    }
+  else if ((t & (3 << 8)) != (3 << 8))
+    {
+      mantissa = u.u & ((((UDItype) 1) << 51) - 1);
+      mantissa |= ((UDItype) 1) << 53;
+      exponent = t & 0x3ff;
+      if (mantissa > (UDItype) 9999999999999999)
+	mantissa = 0;
+    }
+  else
+    {
+      FP_SET_EXCEPTION (FP_EX_INVALID
+			| FP_EX_INVALID_CVI
+			| ((FP_EX_INVALID_SNAN
+			    && ((t & 0x80)) != 0)
+			   ? FP_EX_INVALID_SNAN : 0));
+    ovf:
+      if (!sgn)
+	__builtin_memset (r, -1, rn * sizeof (UBILtype));
+      else
+	__builtin_memset (r, 0, rn * sizeof (UBILtype));
+      if (sgn ^ (rprec >= 0))
+	r[BITINT_END (0, rn - 1)]
+	  |= (UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE);
+      else
+	r[BITINT_END (0, rn - 1)]
+	  &= ~((UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE));
+      goto done;
+    }
+  exponent -= 398;
+
+  if (mantissa == 0)
+    {
+      /* Zero (with any exponent).  */
+    zero:
+      __builtin_memset (r, 0, rn * sizeof (UBILtype));
+      goto done;
+    }
+  if (exponent <= -16)
+    {
+      FP_SET_EXCEPTION (FP_EX_INEXACT);
+      goto zero;
+    }
+  else if (exponent < 0)
+    {
+      UBILtype limbs[64 / BIL_TYPE_SIZE];
+      UDItype d, rem;
+      __bid_pow10bitint (limbs, 64, -exponent);
+#if BIL_TYPE_SIZE == 64
+      d = limbs[0];
+#elif BIL_TYPE_SIZE == 32
+      d = (limbs[BITINT_END (0, 1)] << 32) | limbs[BITINT_END (1, 0)];
+#else
+# error Unsupported BIL_TYPE_SIZE
+#endif
+      rem = mantissa % d;
+      mantissa /= d;
+      if (rem)
+	FP_SET_EXCEPTION (FP_EX_INEXACT);
+      if (mantissa == 0)
+	goto zero;
+      exponent = 0;
+    }
+
+  if (rprec >= 0 && sgn)
+    {
+    ovf_ex:
+      FP_SET_EXCEPTION (FP_EX_INVALID | FP_EX_INVALID_CVI);
+      goto ovf;
+    }
+
+  /* Lower estimate for number of bits needed for pow10 (exponent).  */
+  exp_bits = exponent / 3;
+  exp_bits = exp_bits * 10 - exp_bits / 29;
+  mant_bits = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (mantissa);
+  if (exp_bits + mant_bits > arprec + 1)
+    goto ovf_ex;
+  /* Upper estimate for number of bits needed for pow10 (exponent).  */
+  exp_bits = (exponent + 2) / 3;
+  exp_bits = exp_bits * 10 - exp_bits / 30;
+  if (exp_bits == 0)
+    exp_bits = 1;
+  pow10_limbs = (exp_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  pow10v = __builtin_alloca (pow10_limbs * sizeof (UBILtype));
+  low_zeros = __bid_pow10bitint (pow10v, exp_bits, exponent);
+
+  res_limbs = ((exp_bits + mant_bits + BIL_TYPE_SIZE - 1)
+	       / BIL_TYPE_SIZE) - low_zeros;
+  mant_limbs = (mant_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  resv = __builtin_alloca ((res_limbs + mant_limbs) * sizeof (UBILtype));
+#if BIL_TYPE_SIZE >= 64
+  resv[res_limbs] = mantissa;
+#else
+  if (mant_limbs == 1)
+    resv[res_limbs] = mantissa;
+  else
+    {
+      resv[res_limbs + BITINT_END (1, 0)] = mantissa;
+      resv[res_limbs + BITINT_END (0, 1)] = mantissa >> 32;
+    }
+#endif
+  __mulbitint3 (resv, exp_bits + mant_bits - low_zeros * BIL_TYPE_SIZE,
+		resv + res_limbs, mant_bits,
+		pow10v + BITINT_END (0, low_zeros),
+		exp_bits - low_zeros * BIL_TYPE_SIZE);
+  if (res_limbs + low_zeros >= rn)
+    {
+      if (res_limbs + low_zeros > rn && resv[BITINT_END (0, res_limbs - 1)])
+	goto ovf_ex;
+      if ((arprec % BIL_TYPE_SIZE) != 0
+	  && (resv[BITINT_END (rn - res_limbs, rn - 1) - low_zeros]
+	      & ((UBILtype) -1 << (arprec % BIL_TYPE_SIZE))) != 0)
+	goto ovf_ex;
+      min_limbs = rn - low_zeros;
+    }
+  else
+    min_limbs = res_limbs;
+  if (low_zeros)
+    __builtin_memset (r + BITINT_END (rn - low_zeros, 0), '\0',
+		      low_zeros * sizeof (UBILtype));
+  if (sgn)
+    bitint_negate (r + BITINT_END (rn - low_zeros - 1, low_zeros),
+		   resv + BITINT_END (res_limbs - 1, 0), min_limbs);
+  else
+    __builtin_memcpy (r + BITINT_END (rn - low_zeros - min_limbs, low_zeros),
+		      resv + BITINT_END (res_limbs - min_limbs, 0),
+		      min_limbs * sizeof (UBILtype));
+  if (res_limbs + low_zeros < rn)
+    {
+      if (sgn)
+	__builtin_memset (r + BITINT_END (0, res_limbs + low_zeros), -1,
+			  (rn - res_limbs - low_zeros) * sizeof (UBILtype));
+      else
+	__builtin_memset (r + BITINT_END (0, res_limbs + low_zeros), '\0',
+			  (rn - res_limbs - low_zeros) * sizeof (UBILtype));
+    }
+  else if (sgn)
+    {
+      if ((r[BITINT_END (0, rn - 1)]
+	   & ((UBILtype) 1 << ((arprec - 1) % BIL_TYPE_SIZE))) == 0)
+	goto ovf_ex;
+    }
+  else if (rprec < 0
+	   && (r[BITINT_END (0, rn - 1)]
+	       & ((UBILtype) 1 << ((arprec - 1) % BIL_TYPE_SIZE))) != 0)
+    goto ovf_ex;
+
+done:
+  FP_HANDLE_EXCEPTIONS;
+}
+#endif
--- libgcc/soft-fp/fixtdbitint.c.jj	2023-08-08 16:21:45.953768373 +0200
+++ libgcc/soft-fp/fixtdbitint.c	2023-08-08 16:21:45.953768373 +0200
@@ -0,0 +1,242 @@
+/* Software floating-point emulation.
+   Convert _Decimal128 to signed or unsigned _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+extern void __bid_fixtdbitint (UBILtype *, SItype, _Decimal128);
+
+void
+__bid_fixtdbitint (UBILtype *r, SItype rprec, _Decimal128 a)
+{
+  FP_DECL_EX;
+  USItype arprec = rprec < 0 ? -rprec : rprec;
+  USItype rn = (arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  union { _Decimal128 d; UDItype u[2]; } u;
+  UDItype mantissahi, mantissalo, t;
+  SItype sgn;
+  SItype exponent;
+  USItype exp_bits, mant_bits;
+  UBILtype *pow10v, *resv;
+  USItype pow10_limbs, res_limbs, min_limbs, mant_limbs, low_zeros;
+
+  FP_INIT_EXCEPTIONS;
+  u.d = a;
+  mantissahi = u.u[__FLOAT_WORD_ORDER__ != __ORDER_BIG_ENDIAN__];
+  mantissalo = u.u[__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__];
+  t = mantissahi >> 47;
+  sgn = (DItype) mantissahi < 0;
+  if ((t & (3 << 14)) != (3 << 14))
+    {
+      mantissahi &= ((((UDItype) 1) << 49) - 1);
+      exponent = (t >> 2) & 0x3fff;
+    }
+  else if ((t & (3 << 12)) != (3 << 12))
+    {
+      mantissahi &= ((((UDItype) 1) << 47) - 1);
+      mantissahi |= ((UDItype) 1) << 49;
+      exponent = t & 0x3fff;
+      if (mantissahi > (UDItype) 0x1ed09bead87c0
+	  || (mantissahi == (UDItype) 0x1ed09bead87c0
+	      && mantissalo > 0x378d8e63ffffffff))
+	{
+	  mantissahi = 0;
+	  mantissalo = 0;
+	}
+    }
+  else
+    {
+      FP_SET_EXCEPTION (FP_EX_INVALID
+			| FP_EX_INVALID_CVI
+			| ((FP_EX_INVALID_SNAN
+			    && ((t & 0x800)) != 0)
+			   ? FP_EX_INVALID_SNAN : 0));
+    ovf:
+      if (!sgn)
+	__builtin_memset (r, -1, rn * sizeof (UBILtype));
+      else
+	__builtin_memset (r, 0, rn * sizeof (UBILtype));
+      if (sgn ^ (rprec >= 0))
+	r[BITINT_END (0, rn - 1)]
+	  |= (UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE);
+      else
+	r[BITINT_END (0, rn - 1)]
+	  &= ~((UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE));
+      goto done;
+    }
+  exponent -= 6176;
+
+  if (mantissahi == 0 && mantissalo == 0)
+    {
+      /* Zero (with any exponent).  */
+    zero:
+      __builtin_memset (r, 0, rn * sizeof (UBILtype));
+      goto done;
+    }
+  if (exponent <= -34)
+    {
+      FP_SET_EXCEPTION (FP_EX_INEXACT);
+      goto zero;
+    }
+  if (exponent < 0)
+    {
+      UBILtype limbs[4 * 128 / BIL_TYPE_SIZE];
+#if BIL_TYPE_SIZE == 64
+      limbs[BITINT_END (0, 1)] = mantissahi;
+      limbs[BITINT_END (1, 0)] = mantissalo;
+#elif BIL_TYPE_SIZE == 32
+      limbs[BITINT_END (0, 3)] = mantissahi >> 32;
+      limbs[BITINT_END (1, 2)] = mantissahi;
+      limbs[BITINT_END (2, 1)] = mantissalo >> 32;
+      limbs[BITINT_END (3, 0)] = mantissalo;
+#elif
+# error Unhandled BIL_TYPE_SIZE
+#endif
+      __bid_pow10bitint (&limbs[128 / BIL_TYPE_SIZE], 128, -exponent);
+      __divmodbitint4 (&limbs[2 * 128 / BIL_TYPE_SIZE], 128,
+		       &limbs[3 * 128 / BIL_TYPE_SIZE], 128,
+		       &limbs[0], 128, &limbs[128 / BIL_TYPE_SIZE], 128);
+      UDItype rem;
+#if BIL_TYPE_SIZE == 64
+      mantissahi = limbs[BITINT_END (4, 5)];
+      mantissalo = limbs[BITINT_END (5, 4)];
+      rem = limbs[6] | limbs[7];
+#elif BIL_TYPE_SIZE == 32
+      mantissahi = limbs[BITINT_END (8, 11)] << 32;
+      mantissahi |= limbs[BITINT_END (9, 10)];
+      mantissalo = limbs[BITINT_END (10, 9)] << 32;
+      mantissalo |= limbs[BITINT_END (11, 8)];
+      rem = limbs[12] | limbs[13] | limbs[14] | limbs[15];
+#endif
+      if (rem)
+	FP_SET_EXCEPTION (FP_EX_INEXACT);
+      if (mantissahi == 0 && mantissalo == 0)
+	goto zero;
+      exponent = 0;
+    }
+
+  if (rprec >= 0 && sgn)
+    {
+    ovf_ex:
+      FP_SET_EXCEPTION (FP_EX_INVALID | FP_EX_INVALID_CVI);
+      goto ovf;
+    }
+
+  /* Lower estimate for number of bits needed for pow10 (exponent).  */
+  exp_bits = exponent / 3;
+  exp_bits = exp_bits * 10 - exp_bits / 29;
+  if (mantissahi)
+    mant_bits = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (mantissahi)
+		+ 64;
+  else
+    mant_bits = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (mantissalo);
+  if (exp_bits + mant_bits > arprec + 1)
+    goto ovf_ex;
+  /* Upper estimate for number of bits needed for pow10 (exponent).  */
+  exp_bits = (exponent + 2) / 3;
+  exp_bits = exp_bits * 10 - exp_bits / 30;
+  if (exp_bits == 0)
+    exp_bits = 1;
+  pow10_limbs = (exp_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  pow10v = __builtin_alloca (pow10_limbs * sizeof (UBILtype));
+  low_zeros = __bid_pow10bitint (pow10v, exp_bits, exponent);
+
+  res_limbs = ((exp_bits + mant_bits + BIL_TYPE_SIZE - 1)
+	       / BIL_TYPE_SIZE) - low_zeros;
+  mant_limbs = (mant_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  resv = __builtin_alloca ((res_limbs + mant_limbs) * sizeof (UBILtype));
+#if BIL_TYPE_SIZE >= 64
+  if (mant_limbs == 1)
+    resv[res_limbs] = mantissalo;
+  else
+    {
+      resv[res_limbs + BITINT_END (1, 0)] = mantissalo;
+      resv[res_limbs + BITINT_END (0, 1)] = mantissahi;
+    }
+#else
+  resv[res_limbs + BITINT_END (mant_limbs - 1, 0)] = mantissalo;
+  if (mant_limbs >= 2)
+    {
+      resv[res_limbs + BITINT_END (mant_limbs - 2, 1)] = mantissalo >> 32;
+      if (mant_limbs >= 3)
+	{
+	  resv[res_limbs + BITINT_END (mant_limbs - 3, 2)] = mantissahi;
+	  if (mant_limbs == 4)
+	    resv[res_limbs + BITINT_END (0, 3)] = mantissahi >> 32;
+	}
+    }
+#endif
+  __mulbitint3 (resv, exp_bits + mant_bits - low_zeros * BIL_TYPE_SIZE,
+		resv + res_limbs, mant_bits,
+		pow10v + BITINT_END (0, low_zeros),
+		exp_bits - low_zeros * BIL_TYPE_SIZE);
+  if (res_limbs + low_zeros >= rn)
+    {
+      if (res_limbs + low_zeros > rn && resv[BITINT_END (0, res_limbs - 1)])
+	goto ovf_ex;
+      if ((arprec % BIL_TYPE_SIZE) != 0
+	  && (resv[BITINT_END (rn - res_limbs, rn - 1) - low_zeros]
+	      & ((UBILtype) -1 << (arprec % BIL_TYPE_SIZE))) != 0)
+	goto ovf_ex;
+      min_limbs = rn - low_zeros;
+    }
+  else
+    min_limbs = res_limbs;
+  if (low_zeros)
+    __builtin_memset (r + BITINT_END (rn - low_zeros, 0), '\0',
+		      low_zeros * sizeof (UBILtype));
+  if (sgn)
+    bitint_negate (r + BITINT_END (rn - low_zeros - 1, low_zeros),
+		   resv + BITINT_END (res_limbs - 1, 0), min_limbs);
+  else
+    __builtin_memcpy (r + BITINT_END (rn - low_zeros - min_limbs, low_zeros),
+		      resv + BITINT_END (res_limbs - min_limbs, 0),
+		      min_limbs * sizeof (UBILtype));
+  if (res_limbs + low_zeros < rn)
+    {
+      if (sgn)
+	__builtin_memset (r + BITINT_END (0, res_limbs + low_zeros), -1,
+			  (rn - res_limbs - low_zeros) * sizeof (UBILtype));
+      else
+	__builtin_memset (r + BITINT_END (0, res_limbs + low_zeros), '\0',
+			  (rn - res_limbs - low_zeros) * sizeof (UBILtype));
+    }
+  else if (sgn)
+    {
+      if ((r[BITINT_END (0, rn - 1)]
+	   & ((UBILtype) 1 << ((arprec - 1) % BIL_TYPE_SIZE))) == 0)
+	goto ovf_ex;
+    }
+  else if (rprec < 0
+	   && (r[BITINT_END (0, rn - 1)]
+	       & ((UBILtype) 1 << ((arprec - 1) % BIL_TYPE_SIZE))) != 0)
+    goto ovf_ex;
+
+done:
+  FP_HANDLE_EXCEPTIONS;
+}
+#endif
--- libgcc/soft-fp/floatbitintsd.c.jj	2023-08-08 16:22:09.405440134 +0200
+++ libgcc/soft-fp/floatbitintsd.c	2023-08-08 16:22:09.405440134 +0200
@@ -0,0 +1,235 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to _Decimal32.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+extern _Decimal32 __bid_floatbitintsd (const UBILtype *, SItype);
+
+_Decimal32
+__bid_floatbitintsd (const UBILtype *i, SItype iprec)
+{
+  iprec = bitint_reduce_prec (&i, iprec);
+  USItype aiprec = iprec < 0 ? -iprec : iprec;
+  USItype in = (aiprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  USItype idx = BITINT_END (0, in - 1);
+  UBILtype msb = i[idx];
+  USItype mantissa;
+  SItype exponent = 0;
+  UBILtype inexact = 0;
+  union { _Decimal32 d; USItype u; } u, ui;
+  if (aiprec % BIL_TYPE_SIZE)
+    {
+      if (iprec > 0)
+	msb &= ((UBILtype) 1 << (aiprec % BIL_TYPE_SIZE)) - 1;
+      else
+	msb |= (UBILtype) -1 << (aiprec % BIL_TYPE_SIZE);
+    }
+  if (iprec < 0)
+    {
+      SItype n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb);
+      aiprec = (in - 1) * BIL_TYPE_SIZE + n;
+    }
+  else if (msb == 0)
+    aiprec = 1;
+  else
+    {
+      SItype n = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (msb);
+      aiprec = (in - 1) * BIL_TYPE_SIZE + n;
+    }
+  /* Number of bits in (_BitInt(2048)) 9999999e+90DF.  */
+  if (aiprec > 323 + (iprec < 0))
+    {
+    ovf:
+      if (iprec < 0)
+	u.d = -9000000e+90DF;
+      else
+	u.d = 9000000e+90DF;
+      __asm ("" : "+g" (u.d));
+      u.d += u.d;
+      __asm ("" : "+g" (u.d));
+      goto done;
+    }
+  /* Bit precision of 9999999uwb.  */
+  if (aiprec >= 24)
+    {
+      USItype pow10_limbs, q_limbs, q2_limbs, j;
+      USItype exp_bits = 0, e;
+      UDItype m;
+      UBILtype *buf;
+      /* First do a possibly large divide smaller enough such that
+	 we only need to check remainder for 0 or non-0 and then
+	 we'll do further division.  */
+      if (aiprec >= 24 + 4 + 10)
+	{
+	  exp_bits = (aiprec - 24 - 4) / 10;
+	  exponent = exp_bits * 3;
+	  /* Upper estimate for pow10 (exponent) bits.  */
+	  exp_bits = exp_bits * 10 - exp_bits / 30;
+	}
+      pow10_limbs = (exp_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+      /* 38 is the highest number of quotient bits needed on
+	 aiprec range of [38, 323].  E.g. if aiprec is 317,
+	 exponent will be 84 and exp_bits 280.  317 - 280 + 1
+	 is 38.  */
+      q_limbs = (38 + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+      q2_limbs = (32 + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+      buf = __builtin_alloca ((q_limbs + pow10_limbs * 2 + q2_limbs + 2)
+			      * sizeof (UBILtype));
+      if (exponent)
+	{
+	  __bid_pow10bitint (buf + q_limbs, exp_bits, exponent);
+	  __divmodbitint4 (buf, q_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs,
+			   pow10_limbs * BIL_TYPE_SIZE,
+			   i, iprec < 0 ? -aiprec : aiprec,
+			   buf + q_limbs, exp_bits);
+	  if (iprec < 0)
+	    bitint_negate (buf + BITINT_END (q_limbs - 1, 0),
+			   buf + BITINT_END (q_limbs - 1, 0), q_limbs);
+	  inexact = buf[q_limbs + pow10_limbs];
+	  for (j = 1; j < pow10_limbs; ++j)
+	    inexact |= buf[q_limbs + pow10_limbs + 1];
+	}
+      else
+	{
+	  __builtin_memcpy (buf + BITINT_END (q_limbs - in + 1, 0), i,
+			    (in - 1) * sizeof (UBILtype));
+	  buf[BITINT_END (q_limbs - in, in - 1)] = msb;
+	  if (iprec < 0)
+	    bitint_negate (buf + BITINT_END (q_limbs - 1, 0),
+			   buf + BITINT_END (q_limbs - 1, 0), in);
+	  if (q_limbs > in)
+	    __builtin_memset (buf + BITINT_END (0, in), '\0',
+			      (q_limbs - in) * sizeof (UBILtype));
+	}
+      e = 0;
+#if BIL_TYPE_SIZE == 64
+      m = buf[0];
+#elif BIL_TYPE_SIZE == 32
+      m = ((UDItype) buf[BITINT_END (0, 1)] << 32) | buf[BITINT_END (1, 0)];
+#else
+# error Unsupported BIL_TYPE_SIZE
+#endif
+      if (m >= (UDItype) 10000000000)
+	{
+	  if (m >= (UDItype) 100000000000)
+	    e = 5;
+	  else
+	    e = 4;
+	}
+      else if (m >= (UDItype) 100000000)
+	{
+	  if (m >= (UDItype) 1000000000)
+	    e = 3;
+	  else
+	    e = 2;
+	}
+      else if (m >= (UDItype) 10000000)
+	e = 1;
+      exponent += e;
+      if (exponent > 90)
+	goto ovf;
+      if (e)
+	{
+	  UBILtype rem, half;
+	  __bid_pow10bitint (buf + q_limbs + pow10_limbs * 2,
+			     BIL_TYPE_SIZE, e);
+	  __divmodbitint4 (buf + q_limbs + pow10_limbs * 2 + 1,
+			   q2_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs * 2 + 1 + q2_limbs,
+			   BIL_TYPE_SIZE,
+			   buf, q_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs * 2, BIL_TYPE_SIZE);
+	  half = buf[q_limbs + pow10_limbs * 2] / 2;
+	  rem = buf[q_limbs + pow10_limbs * 2 + 1 + q2_limbs];
+	  if (inexact)
+	    {
+	      /* If first division discovered some non-0 digits
+		 and this second division is by 10, e.g.
+		 for XXXXXX5499999999999 or XXXXXX5000000000001
+		 if first division is by 10^12 and second by 10^1,
+		 doing rem |= 1 wouldn't change the 5.  Similarly
+		 for rem 4 doing rem |= 1 would change it to 5,
+		 but we don't want to change it in that case.  */
+	      if (e == 1)
+		{
+		  if (rem == 5)
+		    rem = 6;
+		  else if (rem != 4)
+		    rem |= 1;
+		}
+	      else
+		rem |= 1;
+	    }
+	  /* Set inexact to 0, 1, 2, 3 depending on if remainder
+	     of the divisions is exact 0, smaller than 10^exponent / 2,
+	     exactly 10^exponent / 2 or greater than that.  */
+	  if (rem >= half)
+	    inexact = 2 + (rem > half);
+	  else
+	    inexact = (rem != 0);
+	  mantissa = buf[q_limbs + pow10_limbs * 2 + 1];
+	}
+      else
+#if BIL_TYPE_SIZE == 64
+	mantissa = buf[0];
+#else
+	mantissa = buf[BITINT_END (1, 0)];
+#endif
+    }
+  else
+    {
+      mantissa = msb;
+      if (iprec < 0)
+	mantissa = -mantissa;
+    }
+
+  exponent += 101;
+  if (mantissa >= (USItype) 0x800000)
+    u.u = (((((iprec < 0) << 2) | (USItype) 3) << 29)
+	   | (((USItype) exponent) << 21)
+	   | (mantissa ^ (USItype) 0x800000));
+  else
+    u.u = ((((USItype) (iprec < 0)) << 31)
+	   | (((USItype) exponent) << 23)
+	   | mantissa);
+  if (inexact)
+    {
+      ui.u = ((((USItype) (iprec < 0)) << 31)
+	      | (((USItype) (exponent - 1)) << 23)
+	      | (inexact + 3));
+      __asm ("" : "+g" (u.d));
+      __asm ("" : "+g" (ui.d));
+      u.d += ui.d;
+      __asm ("" : "+g" (u.d));
+    }
+
+done:
+  return u.d;
+}
+#endif
--- libgcc/soft-fp/floatbitintdd.c.jj	2023-08-08 16:22:09.405440134 +0200
+++ libgcc/soft-fp/floatbitintdd.c	2023-08-08 16:22:09.405440134 +0200
@@ -0,0 +1,264 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to _Decimal64.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+extern _Decimal64 __bid_floatbitintdd (const UBILtype *, SItype);
+
+_Decimal64
+__bid_floatbitintdd (const UBILtype *i, SItype iprec)
+{
+  iprec = bitint_reduce_prec (&i, iprec);
+  USItype aiprec = iprec < 0 ? -iprec : iprec;
+  USItype in = (aiprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  USItype idx = BITINT_END (0, in - 1);
+  UBILtype msb = i[idx];
+  UDItype mantissa;
+  SItype exponent = 0;
+  UBILtype inexact = 0;
+  union { _Decimal64 d; UDItype u; } u, ui;
+  if (aiprec % BIL_TYPE_SIZE)
+    {
+      if (iprec > 0)
+	msb &= ((UBILtype) 1 << (aiprec % BIL_TYPE_SIZE)) - 1;
+      else
+	msb |= (UBILtype) -1 << (aiprec % BIL_TYPE_SIZE);
+    }
+  if (iprec < 0)
+    {
+      SItype n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb);
+      aiprec = (in - 1) * BIL_TYPE_SIZE + n;
+    }
+  else if (msb == 0)
+    aiprec = 1;
+  else
+    {
+      SItype n = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (msb);
+      aiprec = (in - 1) * BIL_TYPE_SIZE + n;
+    }
+  /* Number of bits in (_BitInt(2048)) 9999999999999999e+369DD.  */
+  if (aiprec > 1279 + (iprec < 0))
+    {
+    ovf:
+      if (iprec < 0)
+	u.d = -9000000000000000e+369DD;
+      else
+	u.d = 9000000000000000e+369DD;
+      __asm ("" : "+g" (u.d));
+      u.d += u.d;
+      __asm ("" : "+g" (u.d));
+      goto done;
+    }
+  /* Bit precision of 9999999999999999uwb.  */
+  if (aiprec >= 54)
+    {
+      USItype pow10_limbs, q_limbs, q2_limbs, j;
+      USItype exp_bits = 0, e;
+      UDItype m;
+      UBILtype *buf;
+      /* First do a possibly large divide smaller enough such that
+	 we only need to check remainder for 0 or non-0 and then
+	 we'll do further division.  */
+      if (aiprec >= 54 + 4 + 10)
+	{
+	  exp_bits = (aiprec - 54 - 4) / 10;
+	  exponent = exp_bits * 3;
+	  /* Upper estimate for pow10 (exponent) bits.  */
+	  exp_bits = exp_bits * 10 - exp_bits / 30;
+	}
+      pow10_limbs = (exp_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+      /* 72 is the highest number of quotient bits needed on
+	 aiprec range of [68, 1279].  E.g. if aiprec is 1277,
+	 exponent will be 363 and exp_bits 1206.  1277 - 1206 + 1
+	 is 72.  Unfortunately that means the result doesn't fit into
+	 UDItype...  */
+      q_limbs = (72 + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+      q2_limbs = 64 / BIL_TYPE_SIZE;
+      buf = __builtin_alloca ((q_limbs + pow10_limbs * 2 + q2_limbs + 2)
+			      * sizeof (UBILtype));
+      if (exponent)
+	{
+	  __bid_pow10bitint (buf + q_limbs, exp_bits, exponent);
+	  __divmodbitint4 (buf, q_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs,
+			   pow10_limbs * BIL_TYPE_SIZE,
+			   i, iprec < 0 ? -aiprec : aiprec,
+			   buf + q_limbs, exp_bits);
+	  if (iprec < 0)
+	    bitint_negate (buf + BITINT_END (q_limbs - 1, 0),
+			   buf + BITINT_END (q_limbs - 1, 0), q_limbs);
+	  inexact = buf[q_limbs + pow10_limbs];
+	  for (j = 1; j < pow10_limbs; ++j)
+	    inexact |= buf[q_limbs + pow10_limbs + 1];
+	}
+      else
+	{
+	  __builtin_memcpy (buf + BITINT_END (q_limbs - in + 1, 0), i,
+			    (in - 1) * sizeof (UBILtype));
+	  buf[BITINT_END (q_limbs - in, in - 1)] = msb;
+	  if (iprec < 0)
+	    bitint_negate (buf + BITINT_END (q_limbs - 1, 0),
+			   buf + BITINT_END (q_limbs - 1, 0), in);
+	  if (q_limbs > in)
+	    __builtin_memset (buf + BITINT_END (0, in), '\0',
+			      (q_limbs - in) * sizeof (UBILtype));
+	}
+      e = 0;
+#if BIL_TYPE_SIZE == 64
+      m = buf[BITINT_END (1, 0)];
+#elif BIL_TYPE_SIZE == 32
+      m = ((UDItype) buf[1] << 32) | buf[BITINT_END (2, 0)];
+#else
+# error Unsupported BIL_TYPE_SIZE
+#endif
+      if (buf[BITINT_END (0, q_limbs - 1)])
+	{
+	  if (buf[BITINT_END (0, q_limbs - 1)] > 0x5)
+	    {
+	      /* 1000000000000000000000wb */
+	      if (buf[BITINT_END (0, q_limbs - 1)] > 0x36
+		  || (buf[BITINT_END (0, q_limbs - 1)] == 0x36
+		      && m >= (UDItype) 0x35c9adc5dea00000))
+		e = 6;
+	      else
+		e = 5;
+	    }
+	  /* 100000000000000000000wb */
+	  else if (buf[BITINT_END (0, q_limbs - 1)] == 0x5
+		   && m >= (UDItype) 0x6bc75e2d63100000)
+	    e = 5;
+	  else
+	    e = 4;
+	}
+      else if (m >= (UDItype) 1000000000000000000)
+	{
+	  if (m >= (UDItype) 10000000000000000000ULL)
+	    e = 4;
+	  else
+	    e = 3;
+	}
+      else if (m >= (UDItype) 100000000000000000)
+	e = 2;
+      else if (m >= (UDItype) 10000000000000000)
+	e = 1;
+      exponent += e;
+      if (exponent > 369)
+	goto ovf;
+      if (e)
+	{
+	  UBILtype rem, half;
+	  __bid_pow10bitint (buf + q_limbs + pow10_limbs * 2,
+			     BIL_TYPE_SIZE, e);
+	  __divmodbitint4 (buf + q_limbs + pow10_limbs * 2 + 1,
+			   q2_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs * 2 + 1 + q2_limbs,
+			   BIL_TYPE_SIZE,
+			   buf, q_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs * 2, BIL_TYPE_SIZE);
+	  half = buf[q_limbs + pow10_limbs * 2] / 2;
+	  rem = buf[q_limbs + pow10_limbs * 2 + 1 + q2_limbs];
+	  if (inexact)
+	    {
+	      /* If first division discovered some non-0 digits
+		 and this second division is by 10, e.g.
+		 for XXXXXX5499999999999 or XXXXXX5000000000001
+		 if first division is by 10^12 and second by 10^1,
+		 doing rem |= 1 wouldn't change the 5.  Similarly
+		 for rem 4 doing rem |= 1 would change it to 5,
+		 but we don't want to change it in that case.  */
+	      if (e == 1)
+		{
+		  if (rem == 5)
+		    rem = 6;
+		  else if (rem != 4)
+		    rem |= 1;
+		}
+	      else
+		rem |= 1;
+	    }
+	  /* Set inexact to 0, 1, 2, 3 depending on if remainder
+	     of the divisions is exact 0, smaller than 10^exponent / 2,
+	     exactly 10^exponent / 2 or greater than that.  */
+	  if (rem >= half)
+	    inexact = 2 + (rem > half);
+	  else
+	    inexact = (rem != 0);
+#if BIL_TYPE_SIZE == 64
+	  mantissa = buf[q_limbs + pow10_limbs * 2 + 1];
+#else
+	  mantissa
+	    = ((buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (0, 1)] << 32)
+	       | buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (1, 0)]);
+#endif
+	}
+      else
+#if BIL_TYPE_SIZE == 64
+	mantissa = buf[BITINT_END (1, 0)];
+#else
+	mantissa
+	  = ((buf[1] << 32) | buf[BITINT_END (2, 0)]);
+#endif
+    }
+  else
+    {
+#if BIL_TYPE_SIZE == 64
+      mantissa = msb;
+#else
+      if (in == 1)
+	mantissa = iprec < 0 ? (UDItype) (BILtype) msb : (UDItype) msb;
+      else
+	mantissa = ((msb << 32) | i[BITINT_END (1, 0)]);
+#endif
+      if (iprec < 0)
+	mantissa = -mantissa;
+    }
+
+  exponent += 398;
+  if (mantissa >= (UDItype) 0x20000000000000)
+    u.u = (((((iprec < 0) << 2) | (UDItype) 3) << 61)
+	   | (((UDItype) exponent) << 51)
+	   | (mantissa ^ (UDItype) 0x20000000000000));
+  else
+    u.u = ((((UDItype) (iprec < 0)) << 63)
+	   | (((UDItype) exponent) << 53)
+	   | mantissa);
+  if (inexact)
+    {
+      ui.u = ((((UDItype) (iprec < 0)) << 63)
+	      | (((UDItype) (exponent - 1)) << 53)
+	      | (inexact + 3));
+      __asm ("" : "+g" (u.d));
+      __asm ("" : "+g" (ui.d));
+      u.d += ui.d;
+      __asm ("" : "+g" (u.d));
+    }
+
+done:
+  return u.d;
+}
+#endif
--- libgcc/soft-fp/floatbitinttd.c.jj	2023-08-08 16:22:09.405440134 +0200
+++ libgcc/soft-fp/floatbitinttd.c	2023-08-08 16:22:09.405440134 +0200
@@ -0,0 +1,271 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to _Decimal128.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+extern _Decimal128 __bid_floatbitinttd (const UBILtype *, SItype);
+
+_Decimal128
+__bid_floatbitinttd (const UBILtype *i, SItype iprec)
+{
+  iprec = bitint_reduce_prec (&i, iprec);
+  USItype aiprec = iprec < 0 ? -iprec : iprec;
+  USItype in = (aiprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  USItype idx = BITINT_END (0, in - 1);
+  UBILtype msb = i[idx];
+  UDItype mantissahi, mantissalo;
+  SItype exponent = 0;
+  UBILtype inexact = 0;
+  union { _Decimal128 d; UDItype u[2]; } u, ui;
+  if (aiprec % BIL_TYPE_SIZE)
+    {
+      if (iprec > 0)
+	msb &= ((UBILtype) 1 << (aiprec % BIL_TYPE_SIZE)) - 1;
+      else
+	msb |= (UBILtype) -1 << (aiprec % BIL_TYPE_SIZE);
+    }
+  if (iprec < 0)
+    {
+      SItype n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb);
+      aiprec = (in - 1) * BIL_TYPE_SIZE + n;
+    }
+  else if (msb == 0)
+    aiprec = 1;
+  else
+    {
+      SItype n = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (msb);
+      aiprec = (in - 1) * BIL_TYPE_SIZE + n;
+    }
+  /* Number of bits in
+     (_BitInt(32768)) 9999999999999999999999999999999999e+6111DL.  */
+  if (aiprec > 20414 + (iprec < 0))
+    {
+    ovf:
+      if (iprec < 0)
+	u.d = -9000000000000000000000000000000000e+6111DL;
+      else
+	u.d = 9000000000000000000000000000000000e+6111DL;
+      __asm ("" : "+g" (u.d));
+      u.d += u.d;
+      __asm ("" : "+g" (u.d));
+      goto done;
+    }
+  /* Bit precision of 9999999999999999999999999999999999uwb.  */
+  if (aiprec >= 113)
+    {
+      USItype pow10_limbs, q_limbs, q2_limbs, j, k;
+      USItype exp_bits = 0, e;
+      UBILtype *buf;
+      /* First do a possibly large divide smaller enough such that
+	 we only need to check remainder for 0 or non-0 and then
+	 we'll do further division.  */
+      if (aiprec >= 113 + 4 + 10)
+	{
+	  exp_bits = ((aiprec - 113 - 4) * (UDItype) 30) / 299;
+	  exponent = exp_bits * 3;
+	  /* Upper estimate for pow10 (exponent) bits.  */
+	  exp_bits = exp_bits * 10 - exp_bits / 30;
+	}
+      pow10_limbs = (exp_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+      /* 127 is the highest number of quotient bits needed on
+	 aiprec range of [127, 20414].  E.g. if aiprec is 20409,
+	 exponent will be 6105 and exp_bits 20283.  20409 - 20283 + 1
+	 is 127.  */
+      q_limbs = (127 + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+      q2_limbs = 128 / BIL_TYPE_SIZE;
+      buf = __builtin_alloca ((q_limbs + pow10_limbs * 2 + q2_limbs + 2)
+			      * sizeof (UBILtype));
+      if (exponent)
+	{
+	  __bid_pow10bitint (buf + q_limbs, exp_bits, exponent);
+	  __divmodbitint4 (buf, q_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs,
+			   pow10_limbs * BIL_TYPE_SIZE,
+			   i, iprec < 0 ? -aiprec : aiprec,
+			   buf + q_limbs, exp_bits);
+	  if (iprec < 0)
+	    bitint_negate (buf + BITINT_END (q_limbs - 1, 0),
+			   buf + BITINT_END (q_limbs - 1, 0), q_limbs);
+	  inexact = buf[q_limbs + pow10_limbs];
+	  for (j = 1; j < pow10_limbs; ++j)
+	    inexact |= buf[q_limbs + pow10_limbs + 1];
+	}
+      else
+	{
+	  __builtin_memcpy (buf + BITINT_END (q_limbs - in + 1, 0), i,
+			    (in - 1) * sizeof (UBILtype));
+	  buf[BITINT_END (q_limbs - in, in - 1)] = msb;
+	  if (iprec < 0)
+	    bitint_negate (buf + BITINT_END (q_limbs - 1, 0),
+			   buf + BITINT_END (q_limbs - 1, 0), in);
+	  if (q_limbs > in)
+	    __builtin_memset (buf + BITINT_END (0, in), '\0',
+			      (q_limbs - in) * sizeof (UBILtype));
+	}
+      e = 0;
+      for (j = 3; j; )
+	{
+	  USItype eprev = e;
+	  __bid_pow10bitint (buf + q_limbs + pow10_limbs * 2 + 1,
+			     128, 33 + e + j);
+	  for (k = BITINT_END (0, q_limbs - 1);
+	       k != BITINT_END (q_limbs, (USItype) -1); k -= BITINT_INC)
+	    if (buf[k] > buf[q_limbs + pow10_limbs * 2 + 1 + k])
+	      {
+		e += j;
+		break;
+	      }
+	    else if (buf[k] < buf[q_limbs + pow10_limbs * 2 + 1 + k])
+	      break;
+	  if (k == BITINT_END (q_limbs, (USItype) -1))
+	    e += j;
+	  if (j == 2 && e != eprev)
+	    break;
+	  else
+	    --j;
+	}
+      exponent += e;
+      if (exponent > 6111)
+	goto ovf;
+      if (e)
+	{
+	  UBILtype rem, half;
+	  __bid_pow10bitint (buf + q_limbs + pow10_limbs * 2,
+			     BIL_TYPE_SIZE, e);
+	  __divmodbitint4 (buf + q_limbs + pow10_limbs * 2 + 1,
+			   q2_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs * 2 + 1 + q2_limbs,
+			   BIL_TYPE_SIZE,
+			   buf, q_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs * 2, BIL_TYPE_SIZE);
+	  half = buf[q_limbs + pow10_limbs * 2] / 2;
+	  rem = buf[q_limbs + pow10_limbs * 2 + 1 + q2_limbs];
+	  if (inexact)
+	    {
+	      /* If first division discovered some non-0 digits
+		 and this second division is by 10, e.g.
+		 for XXXXXX5499999999999 or XXXXXX5000000000001
+		 if first division is by 10^12 and second by 10^1,
+		 doing rem |= 1 wouldn't change the 5.  Similarly
+		 for rem 4 doing rem |= 1 would change it to 5,
+		 but we don't want to change it in that case.  */
+	      if (e == 1)
+		{
+		  if (rem == 5)
+		    rem = 6;
+		  else if (rem != 4)
+		    rem |= 1;
+		}
+	      else
+		rem |= 1;
+	    }
+	  /* Set inexact to 0, 1, 2, 3 depending on if remainder
+	     of the divisions is exact 0, smaller than 10^exponent / 2,
+	     exactly 10^exponent / 2 or greater than that.  */
+	  if (rem >= half)
+	    inexact = 2 + (rem > half);
+	  else
+	    inexact = (rem != 0);
+#if BIL_TYPE_SIZE == 64
+	  mantissahi = buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (0, 1)];
+	  mantissalo = buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (1, 0)];
+#else
+	  mantissahi
+	    = ((buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (0, 3)] << 32)
+	       | buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (1, 2)]);
+	  mantissalo
+	    = ((buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (2, 1)] << 32)
+	       | buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (3, 0)]);
+#endif
+	}
+      else
+	{
+#if BIL_TYPE_SIZE == 64
+	  mantissahi = buf[BITINT_END (0, 1)];
+	  mantissalo = buf[BITINT_END (1, 0)];
+#else
+	  mantissahi = (buf[BITINT_END (0, 3)] << 32) | buf[BITINT_END (1, 2)];
+	  mantissalo = (buf[BITINT_END (2, 1)] << 32) | buf[BITINT_END (3, 0)];
+#endif
+	}
+    }
+  else
+    {
+      mantissahi = iprec < 0 ? -1 : 0;
+#if BIL_TYPE_SIZE == 64
+      if (in == 1)
+	mantissalo = msb;
+      else
+	{
+	  mantissahi = msb;
+	  mantissalo = i[BITINT_END (1, 0)];
+	}
+#else
+      if (in <= 2)
+	{
+	  if (in == 1)
+	    mantissalo = iprec < 0 ? (UDItype) (BILtype) msb : (UDItype) msb;
+	  else
+	    mantissalo = (msb << 32) | i[BITINT_END (1, 0)];
+	}
+      else
+	{
+	  if (in == 3)
+	    mantissahi = iprec < 0 ? (UDItype) (BILtype) msb : (UDItype) msb;
+	  else
+	    mantissahi = (msb << 32) | i[BITINT_END (1, 2)];
+	  mantissalo = ((i[BITINT_END (in - 2, 1)] << 32)
+			| i[BITINT_END (in - 1, 0)]);
+	}
+#endif
+      if (iprec < 0)
+	mantissahi
+	  = ~mantissahi + __builtin_add_overflow (~mantissalo, 1, &mantissalo);
+    }
+
+  exponent += 6176;
+  u.u[__FLOAT_WORD_ORDER__ != __ORDER_BIG_ENDIAN__]
+    = ((((UDItype) (iprec < 0)) << 63)
+       | (((UDItype) exponent) << 49)
+       | mantissahi);
+  u.u[__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__] = mantissalo;
+  if (inexact)
+    {
+      ui.u[__FLOAT_WORD_ORDER__ != __ORDER_BIG_ENDIAN__]
+	= (((UDItype) (iprec < 0)) << 63) | (((UDItype) exponent - 1) << 49);
+      ui.u[__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__] = inexact + 3;
+      __asm ("" : "+g" (u.d));
+      __asm ("" : "+g" (ui.d));
+      u.d += ui.d;
+      __asm ("" : "+g" (u.d));
+    }
+
+done:
+  return u.d;
+}
+#endif

	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 9/12] libgcc _BitInt support [PR102989]
  2023-08-09 18:23 [PATCH 9/12] libgcc _BitInt support [PR102989] Jakub Jelinek
@ 2023-09-01 21:48 ` Joseph Myers
  2023-09-02 11:42   ` Jakub Jelinek
  2023-09-04 19:42   ` [PATCH 15/12] Add further _BitInt <-> floating point tests [PR102989] Jakub Jelinek
  0 siblings, 2 replies; 4+ messages in thread
From: Joseph Myers @ 2023-09-01 21:48 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Ian Lance Taylor, gcc-patches

On Wed, 9 Aug 2023, Jakub Jelinek via Gcc-patches wrote:

> I know that soft-fp is owned by glibc and I think the op-common.h change
> should be propagated there, but the bitint stuff is really GCC specific
> and IMHO doesn't belong into the glibc copy.

The op-common.h change is OK for glibc.

Some additional tests I think should be added to the testsuite for 
floating-point functionality in this patch, that I didn't spot in the 
testsuite patches - if any of these aren't included initially, there 
should at least be bugs filed in Bugzilla for the omissions:

1. Test overflowing conversions to integers (including from inf or NaN) 
raise FE_INVALID.  (Note: it's not specified in the standard whether 
inexact conversions to integers raise FE_INEXACT or not, so testing that 
seems less important.)

2. Test conversions from integers to floating point raise FE_INEXACT when 
inexact, together with FE_OVERFLOW when overflowing (while exact 
conversions don't raise exceptions).

3. Test conversions from integers to floating point respect the rounding 
mode.

4. Test converting floating-point values in the range (-1.0, 0.0] to both 
unsigned and signed _BitInt; I didn't see such tests for binary floating 
types, only for decimal types, and the decimal tests didn't include tests 
of negative zero itself as the value converted to _BitInt.

5. Test conversions of noncanonical BID zero to integers (these tests 
would be specific to BID).  See below for a bug in this area.

For points 2 and 3 above, it's probably appropriate to test only for 
binary floating point, to avoid any issues with the separate DFP rounding 
mode and with DFP arithmetic operations not necessarily working correctly 
with exceptions - but then a bug should be filed in Bugzilla noting the 
omission of such tests for DFP.

For points 1, 2 and 3 above, if the conversions for types such as 
_BitInt(32) might end up using the same conversions as for types such as 
int, then tests for such types should probably be omitted (again with a 
bug filed) given the range of known bugs about exceptions from such 
operations with types such as int.

> +__bid_fixtdbitint (UBILtype *r, SItype rprec, _Decimal128 a)
> +{
> +  FP_DECL_EX;
> +  USItype arprec = rprec < 0 ? -rprec : rprec;
> +  USItype rn = (arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
> +  union { _Decimal128 d; UDItype u[2]; } u;
> +  UDItype mantissahi, mantissalo, t;
> +  SItype sgn;
> +  SItype exponent;
> +  USItype exp_bits, mant_bits;
> +  UBILtype *pow10v, *resv;
> +  USItype pow10_limbs, res_limbs, min_limbs, mant_limbs, low_zeros;
> +
> +  FP_INIT_EXCEPTIONS;
> +  u.d = a;
> +  mantissahi = u.u[__FLOAT_WORD_ORDER__ != __ORDER_BIG_ENDIAN__];
> +  mantissalo = u.u[__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__];
> +  t = mantissahi >> 47;
> +  sgn = (DItype) mantissahi < 0;
> +  if ((t & (3 << 14)) != (3 << 14))
> +    {
> +      mantissahi &= ((((UDItype) 1) << 49) - 1);
> +      exponent = (t >> 2) & 0x3fff;

Overflow (thus producing a noncanonical zero) is possible in this case for 
TDmode.  An appropriate test of a noncanonical zero that goes through this 
case should thus be added to the testsuite.

> +    }
> +  else if ((t & (3 << 12)) != (3 << 12))
> +    {
> +      mantissahi &= ((((UDItype) 1) << 47) - 1);
> +      mantissahi |= ((UDItype) 1) << 49;
> +      exponent = t & 0x3fff;
> +      if (mantissahi > (UDItype) 0x1ed09bead87c0
> +	  || (mantissahi == (UDItype) 0x1ed09bead87c0
> +	      && mantissalo > 0x378d8e63ffffffff))
> +	{
> +	  mantissahi = 0;
> +	  mantissalo = 0;
> +	}

And in this case, overflow is guaranteed; the check for the overflow 
threshold should thus move to the previous case.

This patch is OK with these fixes.

Note for powerpc architecture maintainers: adding _BitInt support on that 
architecture will mean, as well as adding support for the conversions 
to/from DPD (if S/390 doesn't get there first), also adding support for 
conversions to/from IBM long double.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 9/12] libgcc _BitInt support [PR102989]
  2023-09-01 21:48 ` Joseph Myers
@ 2023-09-02 11:42   ` Jakub Jelinek
  2023-09-04 19:42   ` [PATCH 15/12] Add further _BitInt <-> floating point tests [PR102989] Jakub Jelinek
  1 sibling, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2023-09-02 11:42 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Ian Lance Taylor, gcc-patches

On Fri, Sep 01, 2023 at 09:48:22PM +0000, Joseph Myers wrote:
> This patch is OK with these fixes.

Thanks, here is an updated patch, thanks for catching the _Decimal128
bug.  Will post testsuite additions/adjustment patch as follow-up on Monday.

2023-09-02  Jakub Jelinek  <jakub@redhat.com>

	PR c/102989
libgcc/
	* config/aarch64/t-softfp (softfp_extras): Use += rather than :=.
	* config/i386/64/t-softfp (softfp_extras): Likewise.
	* config/i386/libgcc-glibc.ver (GCC_14.0.0): Export _BitInt support
	routines.
	* config/i386/t-softfp (softfp_extras): Add fixxfbitint and
	bf, hf and xf mode floatbitint.
	(CFLAGS-floatbitintbf.c, CFLAGS-floatbitinthf.c): Add -msse2.
	* config/riscv/t-softfp32 (softfp_extras): Use += rather than :=.
	* config/rs6000/t-e500v1-fp (softfp_extras): Likewise.
	* config/rs6000/t-e500v2-fp (softfp_extras): Likewise.
	* config/t-softfp (softfp_floatbitint_funcs): New.
	(softfp_bid_list): New.
	(softfp_func_list): Add sf and df mode from and to _BitInt libcalls.
	(softfp_bid_file_list): New.
	(LIB2ADD_ST): Add $(softfp_bid_file_list).
	* config/t-softfp-sfdftf (softfp_extras): Add fixtfbitint and
	floatbitinttf.
	* config/t-softfp-tf (softfp_extras): Likewise.
	* libgcc2.c (bitint_reduce_prec): New inline function.
	(BITINT_INC, BITINT_END): Define.
	(bitint_mul_1, bitint_addmul_1): New helper functions.
	(__mulbitint3): New function.
	(bitint_negate, bitint_submul_1): New helper functions.
	(__divmodbitint4): New function.
	* libgcc2.h (LIBGCC2_UNITS_PER_WORD): When building _BitInt support
	libcalls, redefine depending on __LIBGCC_BITINT_LIMB_WIDTH__.
	(__mulbitint3, __divmodbitint4): Declare.
	* libgcc-std.ver.in (GCC_14.0.0): Export _BitInt support routines.
	* Makefile.in (lib2funcs): Add _mulbitint3.
	(LIB2_DIVMOD_FUNCS): Add _divmodbitint4.
	* soft-fp/bitint.h: New file.
	* soft-fp/fixdfbitint.c: New file.
	* soft-fp/fixsfbitint.c: New file.
	* soft-fp/fixtfbitint.c: New file.
	* soft-fp/fixxfbitint.c: New file.
	* soft-fp/floatbitintbf.c: New file.
	* soft-fp/floatbitintdf.c: New file.
	* soft-fp/floatbitinthf.c: New file.
	* soft-fp/floatbitintsf.c: New file.
	* soft-fp/floatbitinttf.c: New file.
	* soft-fp/floatbitintxf.c: New file.
	* soft-fp/op-common.h (_FP_FROM_INT): Add support for rsize up to
	4 * _FP_W_TYPE_SIZE rather than just 2 * _FP_W_TYPE_SIZE.
	* soft-fp/bitintpow10.c: New file.
	* soft-fp/fixsdbitint.c: New file.
	* soft-fp/fixddbitint.c: New file.
	* soft-fp/fixtdbitint.c: New file.
	* soft-fp/floatbitintsd.c: New file.
	* soft-fp/floatbitintdd.c: New file.
	* soft-fp/floatbitinttd.c: New file.

--- libgcc/config/aarch64/t-softfp.jj	2023-08-08 15:54:35.737595343 +0200
+++ libgcc/config/aarch64/t-softfp	2023-08-08 16:12:02.346939560 +0200
@@ -3,7 +3,7 @@ softfp_int_modes := si di ti
 softfp_extensions := sftf dftf hftf bfsf
 softfp_truncations := tfsf tfdf tfhf tfbf dfbf sfbf hfbf
 softfp_exclude_libgcc2 := n
-softfp_extras := fixhfti fixunshfti floattihf floatuntihf \
+softfp_extras += fixhfti fixunshfti floattihf floatuntihf \
 		 floatdibf floatundibf floattibf floatuntibf
 
 TARGET_LIBGCC2_CFLAGS += -Wno-missing-prototypes
--- libgcc/config/i386/64/t-softfp.jj	2023-08-08 15:54:35.766594936 +0200
+++ libgcc/config/i386/64/t-softfp	2023-08-08 16:12:02.346939560 +0200
@@ -1,4 +1,4 @@
-softfp_extras := fixhfti fixunshfti floattihf floatuntihf \
+softfp_extras += fixhfti fixunshfti floattihf floatuntihf \
 		 floattibf floatuntibf
 
 CFLAGS-fixhfti.c += -msse2
--- libgcc/config/i386/libgcc-glibc.ver.jj	2023-08-08 15:54:35.831594026 +0200
+++ libgcc/config/i386/libgcc-glibc.ver	2023-08-08 16:12:02.347939546 +0200
@@ -226,3 +226,13 @@ GCC_13.0.0 {
   __truncxfbf2
   __trunchfbf2
 }
+
+%inherit GCC_14.0.0 GCC_13.0.0
+GCC_14.0.0 {
+  __PFX__fixxfbitint
+  __PFX__fixtfbitint
+  __PFX__floatbitintbf
+  __PFX__floatbitinthf
+  __PFX__floatbitintxf
+  __PFX__floatbitinttf
+}
--- libgcc/config/i386/t-softfp.jj	2023-08-08 15:55:09.819118062 +0200
+++ libgcc/config/i386/t-softfp	2023-08-08 16:12:02.347939546 +0200
@@ -10,7 +10,7 @@ softfp_extensions := hfsf hfdf hftf hfxf
 softfp_truncations := tfhf xfhf dfhf sfhf tfsf dfsf tfdf tfxf \
 		      tfbf xfbf dfbf sfbf hfbf
 
-softfp_extras += eqhf2
+softfp_extras += eqhf2 fixxfbitint $(foreach m,hf bf xf,floatbitint$(m))
 
 CFLAGS-extendhfsf2.c += -msse2
 CFLAGS-extendhfdf2.c += -msse2
@@ -28,6 +28,9 @@ CFLAGS-truncxfbf2.c += -msse2
 CFLAGS-trunctfbf2.c += -msse2
 CFLAGS-trunchfbf2.c += -msse2
 
+CFLAGS-floatbitintbf.c += -msse2
+CFLAGS-floatbitinthf.c += -msse2
+
 CFLAGS-eqhf2.c += -msse2
 CFLAGS-_divhc3.c += -msse2
 CFLAGS-_mulhc3.c += -msse2
--- libgcc/config/riscv/t-softfp32.jj	2023-08-08 15:54:35.920592780 +0200
+++ libgcc/config/riscv/t-softfp32	2023-08-08 16:12:02.347939546 +0200
@@ -13,7 +13,7 @@ softfp_extensions := sftf dftf
 softfp_truncations := tfsf tfdf
 
 # Enable divide routines to make -mno-fdiv work.
-softfp_extras := divsf3 divdf3
+softfp_extras += divsf3 divdf3
 
 else
 # !ABI_DOUBLE
@@ -28,7 +28,7 @@ else
 # ABI_SINGLE
 
 # Enable divide routines to make -mno-fdiv work.
-softfp_extras := divsf3
+softfp_extras += divsf3
 
 endif
 
@@ -38,7 +38,7 @@ else
 # ABI_QUAD
 
 # Enable divide routines to make -mno-fdiv work.
-softfp_extras := divsf3 divdf3 divtf3
+softfp_extras += divsf3 divdf3 divtf3
 
 endif
 
--- libgcc/config/rs6000/t-e500v1-fp.jj	2023-08-08 15:54:35.965592150 +0200
+++ libgcc/config/rs6000/t-e500v1-fp	2023-08-08 16:12:02.347939546 +0200
@@ -29,4 +29,4 @@ softfp_int_modes := si di
 softfp_extensions := sfdf
 softfp_truncations := dfsf
 softfp_exclude_libgcc2 := n
-softfp_extras := unordsf2
+softfp_extras += unordsf2
--- libgcc/config/rs6000/t-e500v2-fp.jj	2023-08-08 15:54:35.965592150 +0200
+++ libgcc/config/rs6000/t-e500v2-fp	2023-08-08 16:12:02.347939546 +0200
@@ -23,4 +23,4 @@ softfp_int_modes :=
 softfp_extensions :=
 softfp_truncations :=
 softfp_exclude_libgcc2 := n
-softfp_extras := unordsf2 unorddf2
+softfp_extras += unordsf2 unorddf2
--- libgcc/config/t-softfp.jj	2023-08-08 15:54:35.992591772 +0200
+++ libgcc/config/t-softfp	2023-08-08 16:22:09.404440148 +0200
@@ -64,12 +64,21 @@ softfp_float_funcs = add$(m)3 div$(m)3 e
   neg$(m)2 sub$(m)3 unord$(m)2
 softfp_floatint_funcs = fix$(m)$(i) fixuns$(m)$(i) \
   float$(i)$(m) floatun$(i)$(m)
+softfp_floatbitint_funcs = fix$(m)bitint floatbitint$(m)
+softfp_bid_list := 
+ifeq ($(decimal_float),yes)
+ifeq ($(enable_decimal_float),bid)
+softfp_bid_list += bitintpow10 \
+		   $(foreach m,sd dd td,fix$(m)bitint floatbitint$(m))
+endif
+endif
 
 softfp_func_list := \
   $(foreach m,$(softfp_float_modes), \
               $(softfp_float_funcs) \
               $(foreach i,$(softfp_int_modes), \
                           $(softfp_floatint_funcs))) \
+  $(foreach m,sf df,$(softfp_floatbitint_funcs)) \
   $(foreach e,$(softfp_extensions),extend$(e)2) \
   $(foreach t,$(softfp_truncations),trunc$(t)2) \
   $(softfp_extras)
@@ -116,6 +125,8 @@ softfp_file_list := \
   $(addsuffix .c,$(addprefix $(srcdir)/soft-fp/,$(softfp_func_list)))
 endif
 endif
+softfp_bid_file_list := \
+  $(addsuffix .c,$(addprefix $(srcdir)/soft-fp/,$(softfp_bid_list)))
 
 # Disable missing prototype and type limit warnings.  The prototypes
 # for the functions in the soft-fp files have not been brought across
@@ -129,6 +140,7 @@ soft-fp-objects = $(addsuffix $(objext),
 $(soft-fp-objects) : INTERNAL_CFLAGS += -Wno-missing-prototypes -Wno-type-limits
 
 LIB2ADD += $(softfp_file_list)
+LIB2ADD_ST += $(softfp_bid_file_list)
 
 ifneq ($(softfp_exclude_libgcc2),y)
 # Functions in libgcc2.c are excluded for each soft-float mode (a
--- libgcc/config/t-softfp-sfdftf.jj	2023-08-08 15:54:35.992591772 +0200
+++ libgcc/config/t-softfp-sfdftf	2023-08-08 16:12:02.347939546 +0200
@@ -2,4 +2,5 @@ softfp_float_modes := sf df tf
 softfp_int_modes := si di
 softfp_extensions := sfdf sftf dftf xftf
 softfp_truncations := dfsf tfsf tfdf tfxf
+softfp_extras += fixtfbitint floatbitinttf
 softfp_exclude_libgcc2 := n
--- libgcc/config/t-softfp-tf.jj	2023-08-08 15:54:36.011591506 +0200
+++ libgcc/config/t-softfp-tf	2023-08-08 16:12:02.347939546 +0200
@@ -2,4 +2,5 @@ softfp_float_modes := tf
 softfp_int_modes := si di ti
 softfp_extensions := sftf dftf xftf
 softfp_truncations := tfsf tfdf tfxf
+softfp_extras += fixtfbitint floatbitinttf
 softfp_exclude_libgcc2 := n
--- libgcc/libgcc2.c.jj	2023-08-08 15:54:36.059590834 +0200
+++ libgcc/libgcc2.c	2023-08-08 16:12:02.348939532 +0200
@@ -1301,6 +1301,687 @@ __udivdi3 (UDWtype n, UDWtype d)
 }
 #endif
 \f
+#if (defined(__BITINT_MAXWIDTH__) \
+     && (defined(L_mulbitint3) || defined(L_divmodbitint4)))
+/* _BitInt support.  */
+
+/* If *P is zero or sign extended (the latter only for PREC < 0) from
+   some narrower _BitInt value, reduce precision.  */
+
+static inline __attribute__((__always_inline__)) SItype
+bitint_reduce_prec (const UWtype **p, SItype prec)
+{
+  UWtype mslimb;
+  SItype i;
+  if (prec < 0)
+    {
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      i = 0;
+#else
+      i = ((USItype) -1 - prec) / W_TYPE_SIZE;
+#endif
+      mslimb = (*p)[i];
+      if (mslimb & ((UWtype) 1 << (((USItype) -1 - prec) % W_TYPE_SIZE)))
+	{
+	  SItype n = ((USItype) -prec) % W_TYPE_SIZE;
+	  if (n)
+	    {
+	      mslimb |= ((UWtype) -1 << (((USItype) -1 - prec) % W_TYPE_SIZE));
+	      if (mslimb == (UWtype) -1)
+		{
+		  prec += n;
+		  if (prec >= -1)
+		    return -2;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+		  ++p;
+#else
+		  --i;
+#endif
+		  mslimb = (*p)[i];
+		  n = 0;
+		}
+	    }
+	  while (mslimb == (UWtype) -1)
+	    {
+	      prec += W_TYPE_SIZE;
+	      if (prec >= -1)
+		return -2;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+	      ++p;
+#else
+	      --i;
+#endif
+	      mslimb = (*p)[i];
+	    }
+	  if (n == 0)
+	    {
+	      if ((Wtype) mslimb >= 0)
+		{
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+		  --p;
+#endif
+		  return prec - 1;
+		}
+	    }
+	  return prec;
+	}
+      else
+	prec = -prec;
+    }
+  else
+    {
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      i = 0;
+#else
+      i = ((USItype) prec - 1) / W_TYPE_SIZE;
+#endif
+      mslimb = (*p)[i];
+    }
+  SItype n = ((USItype) prec) % W_TYPE_SIZE;
+  if (n)
+    {
+      mslimb &= ((UWtype) 1 << (((USItype) prec) % W_TYPE_SIZE)) - 1;
+      if (mslimb == 0)
+	{
+	  prec -= n;
+	  if (prec == 0)
+	    return 1;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+	  ++p;
+#else
+	  --i;
+#endif
+	  mslimb = (*p)[i];
+	}
+    }
+  while (mslimb == 0)
+    {
+      prec -= W_TYPE_SIZE;
+      if (prec == 0)
+	return 1;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      ++p;
+#else
+      --i;
+#endif
+      mslimb = (*p)[i];
+    }
+  return prec;
+}
+
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+# define BITINT_INC -1
+# define BITINT_END(be, le) (be)
+#else
+# define BITINT_INC 1
+# define BITINT_END(be, le) (le)
+#endif
+
+#ifdef L_mulbitint3
+/* D = S * L.  */
+
+static UWtype
+bitint_mul_1 (UWtype *d, const UWtype *s, UWtype l, SItype n)
+{
+  UWtype sv, hi, lo, c = 0;
+  do
+    {
+      sv = *s;
+      s += BITINT_INC;
+      umul_ppmm (hi, lo, sv, l);
+      c = __builtin_add_overflow (lo, c, &lo) + hi;
+      *d = lo;
+      d += BITINT_INC;
+    }
+  while (--n);
+  return c;
+}
+
+/* D += S * L.  */
+
+static UWtype
+bitint_addmul_1 (UWtype *d, const UWtype *s, UWtype l, SItype n)
+{
+  UWtype sv, hi, lo, c = 0;
+  do
+    {
+      sv = *s;
+      s += BITINT_INC;
+      umul_ppmm (hi, lo, sv, l);
+      hi += __builtin_add_overflow (lo, *d, &lo);
+      c = __builtin_add_overflow (lo, c, &lo) + hi;
+      *d = lo;
+      d += BITINT_INC;
+    }
+  while (--n);
+  return c;
+}
+
+/* If XPREC is positive, it is precision in bits
+   of an unsigned _BitInt operand (which has XPREC/W_TYPE_SIZE
+   full limbs and if Xprec%W_TYPE_SIZE one partial limb.
+   If Xprec is negative, -XPREC is precision in bits
+   of a signed _BitInt operand.  RETPREC should be always
+   positive.  */
+
+void
+__mulbitint3 (UWtype *ret, SItype retprec,
+	      const UWtype *u, SItype uprec,
+	      const UWtype *v, SItype vprec)
+{
+  uprec = bitint_reduce_prec (&u, uprec);
+  vprec = bitint_reduce_prec (&v, vprec);
+  USItype auprec = uprec < 0 ? -uprec : uprec;
+  USItype avprec = vprec < 0 ? -vprec : vprec;
+
+  /* Prefer non-negative U.
+     Otherwise make sure V doesn't have higher precision than U.  */
+  if ((uprec < 0 && vprec >= 0)
+      || (avprec > auprec && !(uprec >= 0 && vprec < 0)))
+    {
+      SItype p;
+      const UWtype *t;
+      p = uprec; uprec = vprec; vprec = p;
+      p = auprec; auprec = avprec; avprec = p;
+      t = u; u = v; v = t;
+    }
+
+  USItype un = auprec / W_TYPE_SIZE;
+  USItype un2 = (auprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
+  USItype vn = avprec / W_TYPE_SIZE;
+  USItype vn2 = (avprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
+  USItype retn = ((USItype) retprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
+  USItype retidx, uidx, vidx;
+  UWtype vv;
+  /* Indexes of least significant limb.  */
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+  retidx = retn - 1;
+  uidx = un2 - 1;
+  vidx = vn2 - 1;
+#else
+  retidx = 0;
+  uidx = 0;
+  vidx = 0;
+#endif
+  if (__builtin_expect (auprec <= W_TYPE_SIZE, 0) && vprec < 0)
+    {
+      UWtype uu = u[uidx];
+      if (__builtin_expect (auprec < W_TYPE_SIZE, 0))
+	uu &= ((UWtype) 1 << (auprec % W_TYPE_SIZE)) - 1;
+      if (uu == 0)
+	{
+	  /* 0 * negative would be otherwise mishandled below, so
+	     handle it specially.  */
+	  __builtin_memset (ret, 0, retn * sizeof (UWtype));
+	  return;
+	}
+    }
+  vv = v[vidx];
+  if (__builtin_expect (avprec < W_TYPE_SIZE, 0))
+    {
+      if (vprec > 0)
+	vv &= ((UWtype) 1 << (avprec % W_TYPE_SIZE)) - 1;
+      else
+	vv |= (UWtype) -1 << (avprec % W_TYPE_SIZE);
+    }
+
+  USItype n = un > retn ? retn : un;
+  USItype n2 = n;
+  USItype retidx2 = retidx + n * BITINT_INC;
+  UWtype c = 0, uv = 0;
+  if (n)
+    c = bitint_mul_1 (ret + retidx, u + uidx, vv, n);
+  if (retn > un && un2 != un)
+    {
+      UWtype hi, lo;
+      uv = u[uidx + n * BITINT_INC];
+      if (uprec > 0)
+	uv &= ((UWtype) 1 << (auprec % W_TYPE_SIZE)) - 1;
+      else
+	uv |= (UWtype) -1 << (auprec % W_TYPE_SIZE);
+      umul_ppmm (hi, lo, uv, vv);
+      c = __builtin_add_overflow (lo, c, &lo) + hi;
+      ret[retidx2] = lo;
+      retidx2 += BITINT_INC;
+      ++n2;
+    }
+  if (retn > un2)
+    {
+      if (uprec < 0)
+	{
+	  while (n2 < retn)
+	    {
+	      if (n2 >= un2 + vn2)
+		break;
+	      UWtype hi, lo;
+	      umul_ppmm (hi, lo, (UWtype) -1, vv);
+	      c = __builtin_add_overflow (lo, c, &lo) + hi;
+	      ret[retidx2] = lo;
+	      retidx2 += BITINT_INC;
+	      ++n2;
+	    }
+	}
+      else
+	{
+	  ret[retidx2] = c;
+	  retidx2 += BITINT_INC;
+	  ++n2;
+	}
+      /* If RET has more limbs than U after precision reduction,
+	 fill in the remaining limbs.  */
+      while (n2 < retn)
+	{
+	  if (n2 < un2 + vn2 || (uprec ^ vprec) >= 0)
+	    c = 0;
+	  else
+	    c = (UWtype) -1;
+	  ret[retidx2] = c;
+	  retidx2 += BITINT_INC;
+	  ++n2;
+	}
+    }
+  /* N is now number of possibly non-zero limbs in RET (ignoring
+     limbs above UN2 + VN2 which if any have been finalized already).  */
+  USItype end = vprec < 0 ? un2 + vn2 : vn2;
+  if (retn > un2 + vn2) retn = un2 + vn2;
+  if (end > retn) end = retn;
+  for (USItype m = 1; m < end; ++m)
+    {
+      retidx += BITINT_INC;
+      vidx += BITINT_INC;
+      if (m < vn2)
+	{
+	  vv = v[vidx];
+	  if (__builtin_expect (m == vn, 0))
+	    {
+	      if (vprec > 0)
+		vv &= ((UWtype) 1 << (avprec % W_TYPE_SIZE)) - 1;
+	      else
+		vv |= (UWtype) -1 << (avprec % W_TYPE_SIZE);
+	    }
+	}
+      else
+	vv = (UWtype) -1;
+      if (m + n > retn)
+	n = retn - m;
+      c = 0;
+      if (n)
+	c = bitint_addmul_1 (ret + retidx, u + uidx, vv, n);
+      n2 = m + n;
+      retidx2 = retidx + n * BITINT_INC;
+      if (n2 < retn && un2 != un)
+	{
+	  UWtype hi, lo;
+	  umul_ppmm (hi, lo, uv, vv);
+	  hi += __builtin_add_overflow (lo, ret[retidx2], &lo);
+	  c = __builtin_add_overflow (lo, c, &lo) + hi;
+	  ret[retidx2] = lo;
+	  retidx2 += BITINT_INC;
+	  ++n2;
+	}
+      if (uprec < 0)
+	while (n2 < retn)
+	  {
+	    UWtype hi, lo;
+	    umul_ppmm (hi, lo, (UWtype) -1, vv);
+	    hi += __builtin_add_overflow (lo, ret[retidx2], &lo);
+	    c = __builtin_add_overflow (lo, c, &lo) + hi;
+	    ret[retidx2] = lo;
+	    retidx2 += BITINT_INC;
+	    ++n2;
+	  }
+      else if (n2 < retn)
+	{
+	  ret[retidx2] = c;
+	  retidx2 += BITINT_INC;
+	}
+    }
+}
+#endif
+
+#ifdef L_divmodbitint4
+static void
+bitint_negate (UWtype *d, const UWtype *s, SItype n)
+{
+  UWtype c = 1;
+  do
+    {
+      UWtype sv = *s, lo;
+      s += BITINT_INC;
+      c = __builtin_add_overflow (~sv, c, &lo);
+      *d = lo;
+      d += BITINT_INC;
+    }
+  while (--n);
+}
+
+/* D -= S * L.  */
+
+static UWtype
+bitint_submul_1 (UWtype *d, const UWtype *s, UWtype l, SItype n)
+{
+  UWtype sv, hi, lo, c = 0;
+  do
+    {
+      sv = *s;
+      s += BITINT_INC;
+      umul_ppmm (hi, lo, sv, l);
+      hi += __builtin_sub_overflow (*d, lo, &lo);
+      c = __builtin_sub_overflow (lo, c, &lo) + hi;
+      *d = lo;
+      d += BITINT_INC;
+    }
+  while (--n);
+  return c;
+}
+
+/* If XPREC is positive, it is precision in bits
+   of an unsigned _BitInt operand (which has XPREC/W_TYPE_SIZE
+   full limbs and if Xprec%W_TYPE_SIZE one partial limb.
+   If Xprec is negative, -XPREC is precision in bits
+   of a signed _BitInt operand.  QPREC and RPREC should be
+   always non-negative.  If either Q or R is NULL (at least
+   one should be non-NULL), then corresponding QPREC or RPREC
+   should be 0.  */
+
+void
+__divmodbitint4 (UWtype *q, SItype qprec,
+		 UWtype *r, SItype rprec,
+		 const UWtype *u, SItype uprec,
+		 const UWtype *v, SItype vprec)
+{
+  uprec = bitint_reduce_prec (&u, uprec);
+  vprec = bitint_reduce_prec (&v, vprec);
+  USItype auprec = uprec < 0 ? -uprec : uprec;
+  USItype avprec = vprec < 0 ? -vprec : vprec;
+  USItype un = (auprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
+  USItype vn = (avprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
+  USItype qn = ((USItype) qprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
+  USItype rn = ((USItype) rprec + W_TYPE_SIZE - 1) / W_TYPE_SIZE;
+  USItype up = auprec % W_TYPE_SIZE;
+  USItype vp = avprec % W_TYPE_SIZE;
+  if (__builtin_expect (un < vn, 0))
+    {
+      /* If abs(v) > abs(u), then q is 0 and r is u.  */
+      if (q)
+	__builtin_memset (q, 0, qn * sizeof (UWtype));
+      if (r == NULL)
+	return;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      r += rn - 1;
+      u += un - 1;
+#endif
+      if (up)
+	--un;
+      if (rn < un)
+	un = rn;
+      for (rn -= un; un; --un)
+	{
+	  *r = *u;
+	  r += BITINT_INC;
+	  u += BITINT_INC;
+	}
+      if (!rn)
+	return;
+      if (up)
+	{
+	  if (uprec > 0)
+	    *r = *u & (((UWtype) 1 << up) - 1);
+	  else
+	    *r = *u | ((UWtype) -1 << up);
+	  r += BITINT_INC;
+	  if (!--rn)
+	    return;
+	}
+      UWtype c = uprec < 0 ? (UWtype) -1 : (UWtype) 0;
+      for (; rn; --rn)
+	{
+	  *r = c;
+	  r += BITINT_INC;
+	}
+      return;
+    }
+  USItype qn2 = un - vn + 1;
+  if (qn >= qn2)
+    qn2 = 0;
+  USItype sz = un + 1 + vn + qn2;
+  UWtype *buf = __builtin_alloca (sz * sizeof (UWtype));
+  USItype uidx, vidx;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+  uidx = un - 1;
+  vidx = vn - 1;
+#else
+  uidx = 0;
+  vidx = 0;
+#endif
+  if (uprec < 0)
+    bitint_negate (buf + BITINT_END (uidx + 1, 0), u + uidx, un);
+  else
+    __builtin_memcpy (buf + BITINT_END (1, 0), u, un * sizeof (UWtype));
+  if (up)
+    buf[BITINT_END (1, un - 1)] &= (((UWtype) 1 << up) - 1);
+  if (vprec < 0)
+    bitint_negate (buf + un + 1 + vidx, v + vidx, vn);
+  else
+    __builtin_memcpy (buf + un + 1, v, vn * sizeof (UWtype));
+  if (vp)
+    buf[un + 1 + BITINT_END (0, vn - 1)] &= (((UWtype) 1 << vp) - 1);
+  UWtype *u2 = buf;
+  UWtype *v2 = u2 + un + 1;
+  UWtype *q2 = v2 + vn;
+  if (!qn2)
+    q2 = q + BITINT_END (qn - (un - vn + 1), 0);
+
+  /* Knuth's algorithm.  See also ../gcc/wide-int.cc (divmod_internal_2).  */
+
+#ifndef UDIV_NEEDS_NORMALIZATION
+  /* Handle single limb divisor first.  */
+  if (vn == 1)
+    {
+      UWtype vv = v2[0];
+      if (vv == 0)
+	vv = 1 / vv; /* Divide intentionally by zero.  */
+      UWtype k = 0;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      for (SItype i = 0; i <= un - 1; ++i)
+#else
+      for (SItype i = un - 1; i >= 0; --i)
+#endif
+	udiv_qrnnd (q2[i], k, k, u2[BITINT_END (i + 1, i)], vv);
+      if (r != NULL)
+	r[BITINT_END (rn - 1, 0)] = k;
+    }
+  else
+#endif
+    {
+      SItype s;
+#ifdef UDIV_NEEDS_NORMALIZATION
+      if (vn == 1 && v2[0] == 0)
+	s = 0;
+      else
+#endif
+      if (sizeof (0U) == sizeof (UWtype))
+	s = __builtin_clz (v2[BITINT_END (0, vn - 1)]);
+      else if (sizeof (0UL) == sizeof (UWtype))
+	s = __builtin_clzl (v2[BITINT_END (0, vn - 1)]);
+      else
+	s = __builtin_clzll (v2[BITINT_END (0, vn - 1)]);
+      if (s)
+	{
+	  /* Normalize by shifting v2 left so that it has msb set.  */
+	  const SItype n = sizeof (UWtype) * __CHAR_BIT__;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+	  for (SItype i = 0; i < vn - 1; ++i)
+#else
+	  for (SItype i = vn - 1; i > 0; --i)
+#endif
+	    v2[i] = (v2[i] << s) | (v2[i - BITINT_INC] >> (n - s));
+	  v2[vidx] = v2[vidx] << s;
+	  /* And shift u2 left by the same amount.  */
+	  u2[BITINT_END (0, un)] = u2[BITINT_END (1, un - 1)] >> (n - s);
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+	  for (SItype i = 1; i < un; ++i)
+#else
+	  for (SItype i = un - 1; i > 0; --i)
+#endif
+	    u2[i] = (u2[i] << s) | (u2[i - BITINT_INC] >> (n - s));
+	  u2[BITINT_END (un, 0)] = u2[BITINT_END (un, 0)] << s;
+	}
+      else
+	u2[BITINT_END (0, un)] = 0;
+#ifdef UDIV_NEEDS_NORMALIZATION
+      /* Handle single limb divisor first.  */
+      if (vn == 1)
+	{
+	  UWtype vv = v2[0];
+	  if (vv == 0)
+	    vv = 1 / vv; /* Divide intentionally by zero.  */
+	  UWtype k = u2[BITINT_END (0, un)];
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+	  for (SItype i = 0; i <= un - 1; ++i)
+#else
+	  for (SItype i = un - 1; i >= 0; --i)
+#endif
+	    udiv_qrnnd (q2[i], k, k, u2[BITINT_END (i + 1, i)], vv);
+	  if (r != NULL)
+	    r[BITINT_END (rn - 1, 0)] = k >> s;
+	}
+      else
+#endif
+	{
+	  UWtype vv1 = v2[BITINT_END (0, vn - 1)];
+	  UWtype vv0 = v2[BITINT_END (1, vn - 2)];
+	  /* Main loop.  */
+	  for (SItype j = un - vn; j >= 0; --j)
+	    {
+	      /* Compute estimate in qhat.  */
+	      UWtype uv1 = u2[BITINT_END (un - j - vn, j + vn)];
+	      UWtype uv0 = u2[BITINT_END (un - j - vn + 1, j + vn - 1)];
+	      UWtype qhat, rhat, hi, lo, c;
+	      if (uv1 >= vv1)
+		{
+		  /* udiv_qrnnd doesn't support quotients which don't
+		     fit into UWtype, so subtract from uv1:uv0 vv1
+		     first.  */
+		  uv1 -= vv1 + __builtin_sub_overflow (uv0, vv1, &uv0);
+		  udiv_qrnnd (qhat, rhat, uv1, uv0, vv1);
+		  if (!__builtin_add_overflow (rhat, vv1, &rhat))
+		    goto again;
+		}
+	      else
+		{
+		  udiv_qrnnd (qhat, rhat, uv1, uv0, vv1);
+		again:
+		  umul_ppmm (hi, lo, qhat, vv0);
+		  if (hi > rhat
+		      || (hi == rhat
+			  && lo > u2[BITINT_END (un - j - vn + 2,
+						 j + vn - 2)]))
+		    {
+		      --qhat;
+		      if (!__builtin_add_overflow (rhat, vv1, &rhat))
+			goto again;
+		    }
+		}
+
+	      c = bitint_submul_1 (u2 + BITINT_END (un - j, j),
+				   v2 + BITINT_END (vn - 1, 0), qhat, vn);
+	      u2[BITINT_END (un - j - vn, j + vn)] -= c;
+	      /* If we've subtracted too much, decrease qhat and
+		 and add back.  */
+	      if ((Wtype) u2[BITINT_END (un - j - vn, j + vn)] < 0)
+		{
+		  --qhat;
+		  c = 0;
+		  for (USItype i = 0; i < vn; ++i)
+		    {
+		      UWtype s = v2[BITINT_END (vn - 1 - i, i)];
+		      UWtype d = u2[BITINT_END (un - i - j, i + j)];
+		      UWtype c1 = __builtin_add_overflow (d, s, &d);
+		      UWtype c2 = __builtin_add_overflow (d, c, &d);
+		      c = c1 + c2;
+		      u2[BITINT_END (un - i - j, i + j)] = d;
+		    }
+		  u2[BITINT_END (un - j - vn, j + vn)] += c;
+		}
+	      q2[BITINT_END (un - vn - j, j)] = qhat;
+	    }
+	  if (r != NULL)
+	    {
+	      if (s)
+		{
+		  const SItype n = sizeof (UWtype) * __CHAR_BIT__;
+		  /* Unnormalize remainder.  */
+		  USItype i;
+		  for (i = 0; i < vn && i < rn; ++i)
+		    r[BITINT_END (rn - 1 - i, i)]
+		      = ((u2[BITINT_END (un - i, i)] >> s)
+			 | (u2[BITINT_END (un - i - 1, i + 1)] << (n - s)));
+		  if (i < rn)
+		    r[BITINT_END (rn - vn, vn - 1)]
+		      = u2[BITINT_END (un - vn + 1, vn - 1)] >> s;
+		}
+	      else if (rn > vn)
+		__builtin_memcpy (&r[BITINT_END (rn - vn, 0)],
+				  &u2[BITINT_END (un + 1 - vn, 0)],
+				  vn * sizeof (UWtype));
+	      else
+		__builtin_memcpy (&r[0], &u2[BITINT_END (un + 1 - rn, 0)],
+				  rn * sizeof (UWtype));
+	    }
+	}
+    }
+  if (q != NULL)
+    {
+      if ((uprec < 0) ^ (vprec < 0))
+	{
+	  /* Negative quotient.  */
+	  USItype n;
+	  if (un - vn + 1 > qn)
+	    n = qn;
+	  else
+	    n = un - vn + 1;
+	  bitint_negate (q + BITINT_END (qn - 1, 0),
+			 q2 + BITINT_END (un - vn, 0), n);
+	  if (qn > n)
+	    __builtin_memset (q + BITINT_END (0, n), -1,
+			      (qn - n) * sizeof (UWtype));
+	}
+      else
+	{
+	  /* Positive quotient.  */
+	  if (qn2)
+	    __builtin_memcpy (q, q2 + BITINT_END (un - vn + 1 - qn, 0),
+			      qn * sizeof (UWtype));
+	  else if (qn > un - vn + 1)
+	    __builtin_memset (q + BITINT_END (0, un - vn + 1), 0,
+			      (qn - (un - vn + 1)) * sizeof (UWtype));
+	}
+    }
+  if (r != NULL)
+    {
+      if (uprec < 0)
+	{
+	  /* Negative remainder.  */
+	  bitint_negate (r + BITINT_END (rn - 1, 0),
+			 r + BITINT_END (rn - 1, 0),
+			 rn > vn ? vn : rn);
+	  if (rn > vn)
+	    __builtin_memset (r + BITINT_END (0, vn), -1,
+			      (rn - vn) * sizeof (UWtype));
+	}
+      else
+	{
+	  /* Positive remainder.  */
+	  if (rn > vn)
+	    __builtin_memset (r + BITINT_END (0, vn), 0,
+			      (rn - vn) * sizeof (UWtype));
+	}
+    }
+}
+#endif
+#endif
+\f
 #ifdef L_cmpdi2
 cmp_return_type
 __cmpdi2 (DWtype a, DWtype b)
--- libgcc/libgcc2.h.jj	2023-08-08 15:54:36.075590609 +0200
+++ libgcc/libgcc2.h	2023-08-08 16:12:02.348939532 +0200
@@ -181,6 +181,12 @@ typedef int shift_count_type __attribute
 #define float bogus_type
 #define double bogus_type
 
+#if (defined(__BITINT_MAXWIDTH__) \
+     && (defined(L_mulbitint3) || defined(L_divmodbitint4)))
+#undef LIBGCC2_UNITS_PER_WORD
+#define LIBGCC2_UNITS_PER_WORD (__LIBGCC_BITINT_LIMB_WIDTH__ / __CHAR_BIT__)
+#endif
+
 /* Versions prior to 3.4.4 were not taking into account the word size for
    the 5 trapping arithmetic functions absv, addv, subv, mulv and negv.  As
    a consequence, the si and di variants were always and the only ones emitted.
@@ -390,6 +396,15 @@ extern DWtype __divmoddi4 (DWtype, DWtyp
 extern UDWtype __udivmoddi4 (UDWtype, UDWtype, UDWtype *);
 #endif
 
+#if (defined(__BITINT_MAXWIDTH__) \
+     && (defined(L_mulbitint3) || defined(L_divmodbitint4)))
+/* _BitInt support.  */
+extern void __mulbitint3 (UWtype *, SItype, const UWtype *, SItype,
+			  const UWtype *, SItype);
+extern void __divmodbitint4 (UWtype *, SItype, UWtype *, SItype,
+			     const UWtype *, SItype, const UWtype *, SItype);
+#endif
+
 /* __negdi2 is static inline when building other libgcc2 portions.  */
 #if !defined(L_divdi3) && !defined(L_moddi3)
 extern DWtype __negdi2 (DWtype);
--- libgcc/libgcc-std.ver.in.jj	2023-08-08 15:54:36.029591253 +0200
+++ libgcc/libgcc-std.ver.in	2023-08-08 16:12:02.348939532 +0200
@@ -1944,3 +1944,13 @@ GCC_7.0.0 {
   __PFX__divmoddi4
   __PFX__divmodti4
 }
+
+%inherit GCC_14.0.0 GCC_7.0.0
+GCC_14.0.0 {
+  __PFX__mulbitint3
+  __PFX__divmodbitint4
+  __PFX__fixsfbitint
+  __PFX__fixdfbitint
+  __PFX__floatbitintsf
+  __PFX__floatbitintdf
+}
--- libgcc/Makefile.in.jj	2023-08-08 15:54:35.711595707 +0200
+++ libgcc/Makefile.in	2023-08-08 16:12:02.348939532 +0200
@@ -446,7 +446,7 @@ lib2funcs = _muldi3 _negdi2 _lshrdi3 _as
 	    _paritysi2 _paritydi2 _powisf2 _powidf2 _powixf2 _powitf2	   \
 	    _mulhc3 _mulsc3 _muldc3 _mulxc3 _multc3 _divhc3 _divsc3	   \
 	    _divdc3 _divxc3 _divtc3 _bswapsi2 _bswapdi2 _clrsbsi2	   \
-	    _clrsbdi2
+	    _clrsbdi2 _mulbitint3
 
 # The floating-point conversion routines that involve a single-word integer.
 # XX stands for the integer mode.
@@ -466,7 +466,8 @@ endif
 # These might cause a divide overflow trap and so are compiled with
 # unwinder info.
 LIB2_DIVMOD_FUNCS = _divdi3 _moddi3 _divmoddi4 \
-		    _udivdi3 _umoddi3 _udivmoddi4 _udiv_w_sdiv
+		    _udivdi3 _umoddi3 _udivmoddi4 _udiv_w_sdiv \
+		    _divmodbitint4
 
 # Remove any objects from lib2funcs and LIB2_DIVMOD_FUNCS that are
 # defined as optimized assembly code in LIB1ASMFUNCS or as C code
--- libgcc/soft-fp/bitint.h.jj	2023-08-08 16:12:02.348939532 +0200
+++ libgcc/soft-fp/bitint.h	2023-08-08 16:21:45.953768373 +0200
@@ -0,0 +1,329 @@
+/* Software floating-point emulation.
+   Definitions for _BitInt implementation details.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#ifndef GCC_SOFT_FP_BITINT_H
+#define GCC_SOFT_FP_BITINT_H
+
+#ifdef __BITINT_MAXWIDTH__
+#define BIL_UNITS_PER_WORD (__LIBGCC_BITINT_LIMB_WIDTH__ / __CHAR_BIT__)
+
+#if BIL_UNITS_PER_WORD == 8
+#define BIL_TYPE_SIZE (8 * __CHAR_BIT__)
+#define BILtype		DItype
+#define UBILtype	UDItype
+#elif BIL_UNITS_PER_WORD == 4
+#define BIL_TYPE_SIZE (4 * __CHAR_BIT__)
+#define BILtype		SItype
+#define UBILtype	USItype
+#elif BIL_UNITS_PER_WORD == 2
+#define BIL_TYPE_SIZE (2 * __CHAR_BIT__)
+#define BILtype		HItype
+#define UBILtype	UHItype
+#else
+#define BIL_TYPE_SIZE __CHAR_BIT__
+#define BILtype		QItype
+#define UBILtype	UQItype
+#endif
+
+/* If *P is zero or sign extended (the latter only for PREC < 0) from
+   some narrower _BitInt value, reduce precision.  */
+
+static inline __attribute__((__always_inline__)) SItype
+bitint_reduce_prec (const UBILtype **p, SItype prec)
+{
+  UBILtype mslimb;
+  SItype i;
+  if (prec < 0)
+    {
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      i = 0;
+#else
+      i = ((USItype) -1 - prec) / BIL_TYPE_SIZE;
+#endif
+      mslimb = (*p)[i];
+      if (mslimb & ((UBILtype) 1 << (((USItype) -1 - prec) % BIL_TYPE_SIZE)))
+	{
+	  SItype n = ((USItype) -prec) % BIL_TYPE_SIZE;
+	  if (n)
+	    {
+	      mslimb |= ((UBILtype) -1 << (((USItype) -1 - prec) % BIL_TYPE_SIZE));
+	      if (mslimb == (UBILtype) -1)
+		{
+		  prec += n;
+		  if (prec >= -1)
+		    return -2;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+		  ++p;
+#else
+		  --i;
+#endif
+		  mslimb = (*p)[i];
+		  n = 0;
+		}
+	    }
+	  while (mslimb == (UBILtype) -1)
+	    {
+	      prec += BIL_TYPE_SIZE;
+	      if (prec >= -1)
+		return -2;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+	      ++p;
+#else
+	      --i;
+#endif
+	      mslimb = (*p)[i];
+	    }
+	  if (n == 0)
+	    {
+	      if ((BILtype) mslimb >= 0)
+		{
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+		  --p;
+#endif
+		  return prec - 1;
+		}
+	    }
+	  return prec;
+	}
+      else
+	prec = -prec;
+    }
+  else
+    {
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      i = 0;
+#else
+      i = ((USItype) prec - 1) / BIL_TYPE_SIZE;
+#endif
+      mslimb = (*p)[i];
+    }
+  SItype n = ((USItype) prec) % BIL_TYPE_SIZE;
+  if (n)
+    {
+      mslimb &= ((UBILtype) 1 << (((USItype) prec) % BIL_TYPE_SIZE)) - 1;
+      if (mslimb == 0)
+	{
+	  prec -= n;
+	  if (prec == 0)
+	    return 1;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+	  ++p;
+#else
+	  --i;
+#endif
+	  mslimb = (*p)[i];
+	}
+    }
+  while (mslimb == 0)
+    {
+      prec -= BIL_TYPE_SIZE;
+      if (prec == 0)
+	return 1;
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+      ++p;
+#else
+      --i;
+#endif
+      mslimb = (*p)[i];
+    }
+  return prec;
+}
+
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+# define BITINT_INC -1
+# define BITINT_END(be, le) (be)
+#else
+# define BITINT_INC 1
+# define BITINT_END(be, le) (le)
+#endif
+
+static inline __attribute__((__always_inline__)) void
+bitint_negate (UBILtype *d, const UBILtype *s, SItype n)
+{
+  UBILtype c = 1;
+  do
+    {
+      UBILtype sv = *s, lo;
+      s += BITINT_INC;
+      c = __builtin_add_overflow (~sv, c, &lo);
+      *d = lo;
+      d += BITINT_INC;
+    }
+  while (--n);
+}
+
+#define FP_TO_BITINT(r, rn, arprec, shift, rv, rsize, rsigned, ovf, DI) \
+  if (ovf)								\
+    {									\
+      if ((rv & 1) != 0)						\
+	__builtin_memset (r, -1, rn * sizeof (UBILtype));		\
+      else								\
+	__builtin_memset (r, 0, rn * sizeof (UBILtype));		\
+      if (rv & (((U##DI##type) 1) << (rsize - 1)))			\
+	r[BITINT_END (0, rn - 1)]					\
+	  |= (UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE);		\
+      else								\
+	r[BITINT_END (0, rn - 1)]					\
+	  &= ~((UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE));	\
+    }									\
+  else									\
+    {									\
+      USItype shiftl = shift / BIL_TYPE_SIZE;				\
+      rsize = DI##_BITS;						\
+      if (rsigned && (DI##type) rv >= 0)				\
+	rsigned = 0;							\
+      if (shift + DI##_BITS > arprec)					\
+	rsize = arprec - shift;						\
+      USItype shiftr = shift % BIL_TYPE_SIZE;				\
+      if (shiftl)							\
+	__builtin_memset (r + BITINT_END (rn - shiftl, 0), 0,		\
+			  shiftl * sizeof (UBILtype));			\
+      USItype idx = BITINT_END (rn - shiftl - 1, shiftl);		\
+      DI##type rvs = rv;						\
+      if (shiftr)							\
+	{								\
+	  r[idx] = (rsigned ? (UBILtype) rvs : (UBILtype) rv) << shiftr;\
+	  idx += BITINT_INC;						\
+	  if (rsize > BIL_TYPE_SIZE - shiftr)				\
+	    {								\
+	      rv >>= BIL_TYPE_SIZE - shiftr;				\
+	      rvs >>= BIL_TYPE_SIZE - shiftr;				\
+	      rsize -= BIL_TYPE_SIZE - shiftr;				\
+	    }								\
+	  else								\
+	    rsize = 0;							\
+	}								\
+      while (rsize)							\
+	{								\
+	  r[idx] = rsigned ? (UBILtype) rvs : (UBILtype) rv;		\
+	  idx += BITINT_INC;						\
+	  if (rsize <= BIL_TYPE_SIZE)					\
+	    break;							\
+	  rv >>= (DI##_BITS > BIL_TYPE_SIZE ? BIL_TYPE_SIZE : 0);	\
+	  rvs >>= (DI##_BITS > BIL_TYPE_SIZE ? BIL_TYPE_SIZE : 0);	\
+	  rsize -= BIL_TYPE_SIZE;					\
+	}								\
+      if (idx < rn)							\
+	__builtin_memset (r + BITINT_END (0, idx), rsigned ? -1 : 0,	\
+			  BITINT_END (idx + 1, rn - idx)		\
+			  * sizeof (UBILtype));				\
+    }
+
+#define FP_FROM_BITINT(i, iprec, iv, shift, DI)				\
+  do									\
+    {									\
+      iprec = bitint_reduce_prec (&i, iprec);				\
+      USItype aiprec = iprec < 0 ? -iprec : iprec;			\
+      USItype in = (aiprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;	\
+      USItype idx = BITINT_END (0, in - 1);				\
+      UBILtype msb = i[idx];						\
+      SItype n = 0;							\
+      if (aiprec % BIL_TYPE_SIZE)					\
+	{								\
+	  if (iprec > 0)						\
+	    msb &= ((UBILtype) 1 << (aiprec % BIL_TYPE_SIZE)) - 1;	\
+	  else								\
+	    msb |= (UBILtype) -1 << (aiprec % BIL_TYPE_SIZE);		\
+	}								\
+      if (iprec < 0)							\
+	{								\
+	  n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb);\
+	  if (BIL_TYPE_SIZE > DI##_BITS && n > DI##_BITS)		\
+	    {								\
+	      iv = msb >> (n - DI##_BITS);				\
+	      shift = n - DI##_BITS;					\
+	      n = 0;							\
+	    }								\
+	  else								\
+	    {								\
+	      iv = (BILtype) msb;					\
+	      n = DI##_BITS - n;					\
+	    }								\
+	}								\
+      /* bitint_reduce_prec guarantees that if msb is 0, then whole	\
+	 i must be zero, otherwise it would have reduced the		\
+	 precision.  */							\
+      else if (msb == 0)						\
+	iv = 0;								\
+      else								\
+	{								\
+	  n = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (msb);	\
+	  if (BIL_TYPE_SIZE >= DI##_BITS && n >= DI##_BITS)		\
+	    {								\
+	      iv = msb >> (n - DI##_BITS + 1);				\
+	      shift = n - DI##_BITS + 1;				\
+	      n = 0;							\
+	    }								\
+	  else								\
+	    {								\
+	      iv = msb;							\
+	      n = DI##_BITS - 1 - n;					\
+	    }								\
+	}								\
+      while (n && BITINT_END (idx < in - 1, idx))			\
+	{								\
+	  idx -= BITINT_INC;						\
+	  msb = i[idx];							\
+	  if (BIL_TYPE_SIZE < DI##_BITS && n >= BIL_TYPE_SIZE)		\
+	    {								\
+	      iv = (U##DI##type) iv << (BIL_TYPE_SIZE < DI##_BITS	\
+					? BIL_TYPE_SIZE : 0);		\
+	      iv |= msb;						\
+	      n -= BIL_TYPE_SIZE;					\
+	    }								\
+	  else								\
+	    {								\
+	      iv = (U##DI##type) iv << n;				\
+	      iv |= msb >> (BIL_TYPE_SIZE - n);				\
+	      shift = BIL_TYPE_SIZE - n;				\
+	      break;							\
+	    }								\
+	}								\
+									\
+      UBILtype low_bits = 0;						\
+      if (shift)							\
+	low_bits = msb & (((UBILtype) 1 << shift) - 1);			\
+      shift += BITINT_END (in - 1 - idx, idx) * BIL_TYPE_SIZE;		\
+      while (!low_bits && BITINT_END (idx < in - 1, idx))		\
+	{								\
+	  idx -= BITINT_INC;						\
+	  low_bits |= i[idx];						\
+	}								\
+      iv |= (low_bits != 0);						\
+    }									\
+  while (0)
+
+extern void __mulbitint3 (UBILtype *, SItype, const UBILtype *, SItype,
+			  const UBILtype *, SItype);
+extern void __divmodbitint4 (UBILtype *, SItype, UBILtype *, SItype,
+			     const UBILtype *, SItype,
+			     const UBILtype *, SItype);
+
+extern USItype __bid_pow10bitint (UBILtype *, SItype, USItype);
+
+#endif /* __BITINT_MAXWIDTH__ */
+
+#endif /* GCC_SOFT_FP_BITINT_H */
--- libgcc/soft-fp/fixdfbitint.c.jj	2023-08-08 16:12:02.348939532 +0200
+++ libgcc/soft-fp/fixdfbitint.c	2023-08-08 16:12:02.348939532 +0200
@@ -0,0 +1,71 @@
+/* Software floating-point emulation.
+   Convert IEEE double to signed or unsigned _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "double.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+void
+__fixdfbitint (UBILtype *r, SItype rprec, DFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_D (A);
+  USItype arprec = rprec < 0 ? -rprec : rprec;
+  USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  UDItype rv;
+  USItype rsize = arprec > DI_BITS ? DI_BITS : arprec;
+  USItype rsigned = rprec < 0;
+  USItype ovf = 0;
+  USItype shift = 0;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_D (A, a);
+  if (arprec > DI_BITS)
+    {
+      if (A_e < _FP_EXPBIAS_D || (A_s && !rsigned))
+	ovf = 1;
+      else if (A_e >= (_FP_EXPMAX_D < _FP_EXPBIAS_D + arprec
+		       ? _FP_EXPMAX_D
+		       : _FP_EXPBIAS_D + arprec - rsigned))
+	{
+	  ovf = 1;
+	  if (A_s
+	      && A_e == _FP_EXPBIAS_D + arprec - 1
+	      && A_e < _FP_EXPMAX_D)
+	    A_e -= arprec - DI_BITS;
+	}
+      else if (A_e >= _FP_EXPBIAS_D + DI_BITS - rsigned)
+	{
+	  shift = A_e - (_FP_EXPBIAS_D + DI_BITS - rsigned - 1);
+	  A_e -= shift;
+	}
+    }
+  FP_TO_INT_D (rv, A, rsize, rsigned);
+  FP_HANDLE_EXCEPTIONS;
+  FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, DI);
+}
+#endif
--- libgcc/soft-fp/fixsfbitint.c.jj	2023-08-08 16:12:02.348939532 +0200
+++ libgcc/soft-fp/fixsfbitint.c	2023-08-08 16:12:02.348939532 +0200
@@ -0,0 +1,71 @@
+/* Software floating-point emulation.
+   Convert IEEE single to signed or unsigned _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "single.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+void
+__fixsfbitint (UBILtype *r, SItype rprec, SFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_S (A);
+  USItype arprec = rprec < 0 ? -rprec : rprec;
+  USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  USItype rv;
+  USItype rsize = arprec > SI_BITS ? SI_BITS : arprec;
+  USItype rsigned = rprec < 0;
+  USItype ovf = 0;
+  USItype shift = 0;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_S (A, a);
+  if (arprec > SI_BITS)
+    {
+      if (A_e < _FP_EXPBIAS_S || (A_s && !rsigned))
+	ovf = 1;
+      else if (A_e >= (_FP_EXPMAX_S < _FP_EXPBIAS_S + arprec
+		       ? _FP_EXPMAX_S
+		       : _FP_EXPBIAS_S + arprec - rsigned))
+	{
+	  ovf = 1;
+	  if (A_s
+	      && A_e == _FP_EXPBIAS_S + arprec - 1
+	      && A_e < _FP_EXPMAX_S)
+	    A_e -= arprec - SI_BITS;
+	}
+      else if (A_e >= _FP_EXPBIAS_S + SI_BITS - rsigned)
+	{
+	  shift = A_e - (_FP_EXPBIAS_S + SI_BITS - rsigned - 1);
+	  A_e -= shift;
+	}
+    }
+  FP_TO_INT_S (rv, A, rsize, rsigned);
+  FP_HANDLE_EXCEPTIONS;
+  FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, SI);
+}
+#endif
--- libgcc/soft-fp/fixtfbitint.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/fixtfbitint.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,81 @@
+/* Software floating-point emulation.
+   Convert IEEE quad to signed or unsigned _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "quad.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+
+#ifndef TI_BITS
+/* As mantissa is 112 bits + 1 implicit bit, we need 128-bit
+   type, but on most 32-bit architectures TImode isn't supported.
+   Use _BitInt(128) instead.  */
+typedef _BitInt(128) TItype;
+typedef unsigned _BitInt(128) UTItype;
+#define TI_BITS 128
+#endif
+
+void
+__fixtfbitint (UBILtype *r, SItype rprec, TFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_Q (A);
+  USItype arprec = rprec < 0 ? -rprec : rprec;
+  USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  UTItype rv;
+  USItype rsize = arprec > TI_BITS ? TI_BITS : arprec;
+  USItype rsigned = rprec < 0;
+  USItype ovf = 0;
+  USItype shift = 0;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_Q (A, a);
+  if (arprec > TI_BITS)
+    {
+      if (A_e < _FP_EXPBIAS_Q || (A_s && !rsigned))
+	ovf = 1;
+      else if (A_e >= (_FP_EXPMAX_Q < _FP_EXPBIAS_Q + arprec
+		       ? _FP_EXPMAX_Q
+		       : _FP_EXPBIAS_Q + arprec - rsigned))
+	{
+	  ovf = 1;
+	  if (A_s
+	      && A_e == _FP_EXPBIAS_Q + arprec - 1
+	      && A_e < _FP_EXPMAX_Q)
+	    A_e -= arprec - TI_BITS;
+	}
+      else if (A_e >= _FP_EXPBIAS_Q + TI_BITS - rsigned)
+	{
+	  shift = A_e - (_FP_EXPBIAS_Q + TI_BITS - rsigned - 1);
+	  A_e -= shift;
+	}
+    }
+  FP_TO_INT_Q (rv, A, rsize, rsigned);
+  FP_HANDLE_EXCEPTIONS;
+  FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, TI);
+}
+#endif
--- libgcc/soft-fp/fixxfbitint.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/fixxfbitint.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,82 @@
+/* Software floating-point emulation.
+   Convert IEEE extended to signed or unsigned _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "extended.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+
+#ifndef TI_BITS
+/* While mantissa is 64 bits including 1 explicit bit, extended.h uses
+   op-2.h for W_TYPE_SIZE 64 and op-4.h for W_TYPE_SIZE 32, so we have
+   to use 128-bit type here.  On most 32-bit architectures TImode isn't
+   supported, so use _BitInt(128) instead.  */
+typedef _BitInt(128) TItype;
+typedef unsigned _BitInt(128) UTItype;
+#define TI_BITS 128
+#endif
+
+void
+__fixxfbitint (UBILtype *r, SItype rprec, XFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_E (A);
+  USItype arprec = rprec < 0 ? -rprec : rprec;
+  USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  UTItype rv;
+  USItype rsize = arprec > TI_BITS ? TI_BITS : arprec;
+  USItype rsigned = rprec < 0;
+  USItype ovf = 0;
+  USItype shift = 0;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_E (A, a);
+  if (arprec > TI_BITS)
+    {
+      if (A_e < _FP_EXPBIAS_E || (A_s && !rsigned))
+	ovf = 1;
+      else if (A_e >= (_FP_EXPMAX_E < _FP_EXPBIAS_E + arprec
+		       ? _FP_EXPMAX_E
+		       : _FP_EXPBIAS_E + arprec - rsigned))
+	{
+	  ovf = 1;
+	  if (A_s
+	      && A_e == _FP_EXPBIAS_E + arprec - 1
+	      && A_e < _FP_EXPMAX_E)
+	    A_e -= arprec - TI_BITS;
+	}
+      else if (A_e >= _FP_EXPBIAS_E + TI_BITS - rsigned)
+	{
+	  shift = A_e - (_FP_EXPBIAS_E + TI_BITS - rsigned - 1);
+	  A_e -= shift;
+	}
+    }
+  FP_TO_INT_E (rv, A, rsize, rsigned);
+  FP_HANDLE_EXCEPTIONS;
+  FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, TI);
+}
+#endif
--- libgcc/soft-fp/floatbitintbf.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/floatbitintbf.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,59 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to bfloat16.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "brain.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+BFtype
+__floatbitintbf (const UBILtype *i, SItype iprec)
+{
+  SItype iv;
+  USItype shift = 0;
+  FP_DECL_EX;
+  FP_DECL_B (A);
+  BFtype a;
+
+  FP_FROM_BITINT (i, iprec, iv, shift, SI);
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_B (A, iv, SI_BITS, USItype);
+  if (shift)
+    {
+      A_e += shift;
+      if (A_e >= _FP_EXPMAX_B)
+	{
+	  /* Exponent too big; overflow to infinity.  */
+	  _FP_OVERFLOW_SEMIRAW (B, 1, A);
+	  _FP_PACK_SEMIRAW (B, 1, A);
+	}
+    }
+  FP_PACK_RAW_B (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
+#endif
--- libgcc/soft-fp/floatbitintdf.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/floatbitintdf.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,64 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to IEEE double.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "double.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+DFtype
+__floatbitintdf (const UBILtype *i, SItype iprec)
+{
+  DItype iv;
+  USItype shift = 0;
+  FP_DECL_EX;
+  FP_DECL_D (A);
+  DFtype a;
+
+  FP_FROM_BITINT (i, iprec, iv, shift, DI);
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_D (A, iv, DI_BITS, UDItype);
+  if (shift)
+    {
+      A_e += shift;
+      if (A_e >= _FP_EXPMAX_D)
+	{
+	  /* Exponent too big; overflow to infinity.  */
+#if _FP_W_TYPE_SIZE < 64
+	  _FP_OVERFLOW_SEMIRAW (D, 2, A);
+	  _FP_PACK_SEMIRAW (D, 2, A);
+#else
+	  _FP_OVERFLOW_SEMIRAW (D, 1, A);
+	  _FP_PACK_SEMIRAW (D, 1, A);
+#endif
+	}
+    }
+  FP_PACK_RAW_D (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
+#endif
--- libgcc/soft-fp/floatbitinthf.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/floatbitinthf.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,59 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to IEEE half.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "half.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+HFtype
+__floatbitinthf (const UBILtype *i, SItype iprec)
+{
+  SItype iv;
+  USItype shift = 0;
+  FP_DECL_EX;
+  FP_DECL_H (A);
+  HFtype a;
+
+  FP_FROM_BITINT (i, iprec, iv, shift, SI);
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_H (A, iv, SI_BITS, USItype);
+  if (shift)
+    {
+      A_e += shift;
+      if (A_e >= _FP_EXPMAX_H)
+	{
+	  /* Exponent too big; overflow to infinity.  */
+	  _FP_OVERFLOW_SEMIRAW (H, 1, A);
+	  _FP_PACK_SEMIRAW (H, 1, A);
+	}
+    }
+  FP_PACK_RAW_H (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
+#endif
--- libgcc/soft-fp/floatbitintsf.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/floatbitintsf.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,59 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to IEEE single.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "single.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+SFtype
+__floatbitintsf (const UBILtype *i, SItype iprec)
+{
+  SItype iv;
+  USItype shift = 0;
+  FP_DECL_EX;
+  FP_DECL_S (A);
+  SFtype a;
+
+  FP_FROM_BITINT (i, iprec, iv, shift, SI);
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_S (A, iv, SI_BITS, USItype);
+  if (shift)
+    {
+      A_e += shift;
+      if (A_e >= _FP_EXPMAX_S)
+	{
+	  /* Exponent too big; overflow to infinity.  */
+	  _FP_OVERFLOW_SEMIRAW (S, 1, A);
+	  _FP_PACK_SEMIRAW (S, 1, A);
+	}
+    }
+  FP_PACK_RAW_S (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
+#endif
--- libgcc/soft-fp/floatbitinttf.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/floatbitinttf.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,73 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to IEEE quad.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "quad.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+#ifndef TI_BITS
+/* As mantissa is 112 bits + 1 implicit bit, we need 128-bit
+   type, but on most 32-bit architectures TImode isn't supported.
+   Use _BitInt(128) instead.  */
+typedef _BitInt(128) TItype;
+typedef unsigned _BitInt(128) UTItype;
+#define TI_BITS 128
+#endif
+
+TFtype
+__floatbitinttf (const UBILtype *i, SItype iprec)
+{
+  TItype iv;
+  USItype shift = 0;
+  FP_DECL_EX;
+  FP_DECL_Q (A);
+  TFtype a;
+
+  FP_FROM_BITINT (i, iprec, iv, shift, TI);
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_Q (A, iv, TI_BITS, UTItype);
+  if (shift)
+    {
+      A_e += shift;
+      if (A_e >= _FP_EXPMAX_Q)
+	{
+	  /* Exponent too big; overflow to infinity.  */
+#if _FP_W_TYPE_SIZE < 64
+	  _FP_OVERFLOW_SEMIRAW (Q, 4, A);
+	  _FP_PACK_SEMIRAW (Q, 4, A);
+#else
+	  _FP_OVERFLOW_SEMIRAW (Q, 2, A);
+	  _FP_PACK_SEMIRAW (Q, 2, A);
+#endif
+	}
+    }
+  FP_PACK_RAW_Q (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
+#endif
--- libgcc/soft-fp/floatbitintxf.c.jj	2023-08-08 16:12:02.349939518 +0200
+++ libgcc/soft-fp/floatbitintxf.c	2023-08-08 16:12:02.349939518 +0200
@@ -0,0 +1,74 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to IEEE extended.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "extended.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+#ifndef TI_BITS
+/* While mantissa is 64 bits including 1 explicit bit, extended.h uses
+   op-2.h for W_TYPE_SIZE 64 and op-4.h for W_TYPE_SIZE 32, so we have
+   to use 128-bit type here.  On most 32-bit architectures TImode isn't
+   supported, so use _BitInt(128) instead.  */
+typedef _BitInt(128) TItype;
+typedef unsigned _BitInt(128) UTItype;
+#define TI_BITS 128
+#endif
+
+XFtype
+__floatbitintxf (const UBILtype *i, SItype iprec)
+{
+  TItype iv;
+  USItype shift = 0;
+  FP_DECL_EX;
+  FP_DECL_E (A);
+  XFtype a;
+
+  FP_FROM_BITINT (i, iprec, iv, shift, TI);
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_E (A, iv, TI_BITS, UTItype);
+  if (shift)
+    {
+      A_e += shift;
+      if (A_e >= _FP_EXPMAX_E)
+	{
+	  /* Exponent too big; overflow to infinity.  */
+#if _FP_W_TYPE_SIZE < 64
+	  _FP_OVERFLOW_SEMIRAW (E, 4, A);
+	  _FP_PACK_SEMIRAW (E, 4, A);
+#else
+	  _FP_OVERFLOW_SEMIRAW (E, 2, A);
+	  _FP_PACK_SEMIRAW (E, 2, A);
+#endif
+	}
+    }
+  FP_PACK_RAW_E (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
+#endif
--- libgcc/soft-fp/op-common.h.jj	2023-08-08 15:54:36.110590119 +0200
+++ libgcc/soft-fp/op-common.h	2023-08-08 16:12:02.349939518 +0200
@@ -1800,7 +1800,7 @@
 	  if ((X##_s = ((r) < 0)))					\
 	    _FP_FROM_INT_ur = -_FP_FROM_INT_ur;				\
 									\
-	  _FP_STATIC_ASSERT ((rsize) <= 2 * _FP_W_TYPE_SIZE,		\
+	  _FP_STATIC_ASSERT ((rsize) <= 4 * _FP_W_TYPE_SIZE,		\
 			     "rsize too large");			\
 	  (void) (((rsize) <= _FP_W_TYPE_SIZE)				\
 		  ? ({							\
@@ -1810,13 +1810,38 @@
 		      X##_e = (_FP_EXPBIAS_##fs + _FP_W_TYPE_SIZE - 1	\
 			       - _FP_FROM_INT_lz);			\
 		    })							\
-		  : ({						\
+		  : ((rsize) <= 2 * _FP_W_TYPE_SIZE)			\
+		  ? ({							\
 		      int _FP_FROM_INT_lz;				\
 		      __FP_CLZ_2 (_FP_FROM_INT_lz,			\
 				  (_FP_W_TYPE) (_FP_FROM_INT_ur		\
 						>> _FP_W_TYPE_SIZE),	\
 				  (_FP_W_TYPE) _FP_FROM_INT_ur);	\
-		      X##_e = (_FP_EXPBIAS_##fs + 2 * _FP_W_TYPE_SIZE - 1 \
+		      X##_e = (_FP_EXPBIAS_##fs				\
+			       + 2 * _FP_W_TYPE_SIZE - 1		\
+			       - _FP_FROM_INT_lz);			\
+		    })							\
+		  : ({							\
+		      int _FP_FROM_INT_lz;				\
+		      if (_FP_FROM_INT_ur >> (2 * _FP_W_TYPE_SIZE))	\
+			{						\
+			  rtype _FP_FROM_INT_uru			\
+			    = _FP_FROM_INT_ur >> (2 * _FP_W_TYPE_SIZE);	\
+			  __FP_CLZ_2 (_FP_FROM_INT_lz,			\
+				      (_FP_W_TYPE) (_FP_FROM_INT_uru	\
+						    >> _FP_W_TYPE_SIZE),\
+				      (_FP_W_TYPE) _FP_FROM_INT_uru);	\
+			}						\
+		      else						\
+			{						\
+			  __FP_CLZ_2 (_FP_FROM_INT_lz,			\
+				      (_FP_W_TYPE) (_FP_FROM_INT_ur	\
+						    >> _FP_W_TYPE_SIZE),\
+				      (_FP_W_TYPE) _FP_FROM_INT_ur);	\
+			  _FP_FROM_INT_lz += 2 * _FP_W_TYPE_SIZE;	\
+			}						\
+		      X##_e = (_FP_EXPBIAS_##fs				\
+			       + 4 * _FP_W_TYPE_SIZE - 1		\
 			       - _FP_FROM_INT_lz);			\
 		    }));						\
 									\
--- libgcc/soft-fp/bitintpow10.c.jj	2023-08-08 16:21:45.956768331 +0200
+++ libgcc/soft-fp/bitintpow10.c	2023-08-09 15:22:45.519805895 +0200
@@ -0,0 +1,132 @@
+/* Software floating-point emulation.
+   Compute powers of 10 into _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+# define BIL_VAL(x) ((UBILtype) (x))
+# if BIL_TYPE_SIZE == 64
+#  define BIL_PAIR(x, y) ((BIL_VAL (x) << 32) | BIL_VAL (y))
+#  define BIL_OFF(x, y) (x)
+# elif BIL_TYPE_SIZE == 32
+#  if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+#   define BIL_PAIR(x, y) BIL_VAL (x), BIL_VAL (y)
+#  else
+#   define BIL_PAIR(x, y) BIL_VAL (y), BIL_VAL (x)
+#  endif
+#  define BIL_OFF(x, y) (y)
+# else
+#  error Unsupported _BitInt limb size
+# endif
+#if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
+# define BIL_SET2(a, b) a, b
+# define BIL_SET3(a, b, c) a, b, c
+# define BIL_SET4(a, b, c, d) a, b, c, d
+# define BIL_SET5(a, b, c, d, e) a, b, c, d, e
+# define BIL_SET6(a, b, c, d, e, f) a, b, c, d, e, f
+# define BIL_SET7(a, b, c, d, e, f, g) a, b, c, d, e, f, g
+# define BIL_SET8(a, b, c, d, e, f, g, h) a, b, c, d, e, f, g, h
+# define BIL_SET9(a, b, c, d, e, f, g, h, i) a, b, c, d, e, f, g, h, i
+# define BIL_SET10(a, b, c, d, e, f, g, h, i, j) a, b, c, d, e, f, g, h, i, j
+# define BIL_SET11(a, b, c, d, e, f, g, h, i, j, k) \
+  a, b, c, d, e, f, g, h, i, j, k
+# define BIL_SET12(a, b, c, d, e, f, g, h, i, j, k, l) \
+  a, b, c, d, e, f, g, h, i, j, k, l
+# define BIL_SET13(a, b, c, d, e, f, g, h, i, j, k, l, m) \
+  a, b, c, d, e, f, g, h, i, j, k, l, m
+# define BIL_SET14(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
+  a, b, c, d, e, f, g, h, i, j, k, l, m, n
+# define BIL_SET15(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
+  a, b, c, d, e, f, g, h, i, j, k, l, m, n, o
+#else
+# define BIL_SET2(a, b) b, a
+# define BIL_SET3(a, b, c) c, b, a
+# define BIL_SET4(a, b, c, d) d, c, b, a
+# define BIL_SET5(a, b, c, d, e) e, d, c, b, a
+# define BIL_SET6(a, b, c, d, e, f) f, e, d, c, b, a
+# define BIL_SET7(a, b, c, d, e, f, g) g, f, e, d, c, b, a
+# define BIL_SET8(a, b, c, d, e, f, g, h) h, g, f, e, d, c, b, a
+# define BIL_SET9(a, b, c, d, e, f, g, h, i) i, h, g, f, e, d, c, b, a
+# define BIL_SET10(a, b, c, d, e, f, g, h, i, j) j, i, h, g, f, e, d, c, b, a
+# define BIL_SET11(a, b, c, d, e, f, g, h, i, j, k) \
+  k, j, i, h, g, f, e, d, c, b, a
+# define BIL_SET12(a, b, c, d, e, f, g, h, i, j, k, l) \
+  l, k, j, i, h, g, f, e, d, c, b, a
+# define BIL_SET13(a, b, c, d, e, f, g, h, i, j, k, l, m) \
+  m, l, k, j, i, h, g, f, e, d, c, b, a
+# define BIL_SET14(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \
+  n, m, l, k, j, i, h, g, f, e, d, c, b, a
+# define BIL_SET15(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) \
+  o, n, m, l, k, j, i, h, g, f, e, d, c, b, a
+#endif
+
+#include "bitintpow10.h"
+
+/* Set r (_BitInt limbs with rprec bits) to pow10 (n),
+   where n is in [0, 6111].  Returns number of least significant
+   limbs with just 0s in it.  */
+
+USItype
+__bid_pow10bitint (UBILtype *r, SItype rprec, USItype n)
+{
+  USItype rn = ((USItype) rprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  if (n <= 256)
+    {
+      /* No need to multiply anything, just copy it from pow10_limbs
+	 array.  */
+      USItype low_zeros = (n / 64) * (64 / BIL_TYPE_SIZE);
+      UBILtype *p = &pow10_limbs[pow10_offs[n]];
+      USItype cnt = pow10_offs[n + 1] - pow10_offs[n];
+      if (low_zeros)
+	__builtin_memset (r + BITINT_END (rn - low_zeros, 0), '\0',
+			  low_zeros * sizeof (UBILtype));
+      __builtin_memcpy (r + BITINT_END (rn - low_zeros - cnt, low_zeros),
+			p, cnt * sizeof (UBILtype));
+      if (rn > low_zeros + cnt)
+	__builtin_memset (r + BITINT_END (0, low_zeros + cnt), '\0',
+			  (rn - low_zeros - cnt) * sizeof (UBILtype));
+      return low_zeros;
+    }
+  else
+    {
+      USItype m = n / 256;
+      n &= 255;
+      USItype low_zeros = ((n / 64) + (m * 4)) * (64 / BIL_TYPE_SIZE);
+      UBILtype *pm = &pow10_limbs[pow10_offs[m + 255]];
+      USItype cntm = pow10_offs[m + 256] - pow10_offs[m + 255];
+      UBILtype *pn = &pow10_limbs[pow10_offs[n]];
+      USItype cntn = pow10_offs[n + 1] - pow10_offs[n];
+      if (low_zeros)
+	__builtin_memset (r + BITINT_END (rn - low_zeros, 0), '\0',
+			  low_zeros * sizeof (UBILtype));
+      __mulbitint3 (r + BITINT_END (0, low_zeros),
+		    rprec - low_zeros * BIL_TYPE_SIZE,
+		    pm, cntm * BIL_TYPE_SIZE, pn, cntn * BIL_TYPE_SIZE);
+      return low_zeros;
+    }
+}
+#endif
--- libgcc/soft-fp/fixsdbitint.c.jj	2023-08-08 16:21:45.953768373 +0200
+++ libgcc/soft-fp/fixsdbitint.c	2023-08-08 16:21:45.953768373 +0200
@@ -0,0 +1,196 @@
+/* Software floating-point emulation.
+   Convert _Decimal32 to signed or unsigned _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+extern void __bid_fixsdbitint (UBILtype *, SItype, _Decimal32);
+
+void
+__bid_fixsdbitint (UBILtype *r, SItype rprec, _Decimal32 a)
+{
+  FP_DECL_EX;
+  USItype arprec = rprec < 0 ? -rprec : rprec;
+  USItype rn = (arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  union { _Decimal32 d; USItype u; } u;
+  USItype mantissa, t;
+  SItype sgn;
+  SItype exponent;
+  USItype exp_bits, mant_bits;
+  UBILtype *pow10v, *resv;
+  USItype pow10_limbs, res_limbs, min_limbs, mant_limbs, low_zeros;
+
+  FP_INIT_EXCEPTIONS;
+  u.d = a;
+  t = u.u >> 21;
+  sgn = (SItype) u.u < 0;
+  if ((t & (3 << 8)) != (3 << 8))
+    {
+      mantissa = u.u & ((((USItype) 1) << 23) - 1);
+      exponent = (t >> 2) & 0xff;
+    }
+  else if ((t & (3 << 6)) != (3 << 6))
+    {
+      mantissa = u.u & ((((USItype) 1) << 21) - 1);
+      mantissa |= ((USItype) 1) << 23;
+      exponent = t & 0xff;
+      if (mantissa > (USItype) 9999999)
+	mantissa = 0;
+    }
+  else
+    {
+      FP_SET_EXCEPTION (FP_EX_INVALID
+			| FP_EX_INVALID_CVI
+			| ((FP_EX_INVALID_SNAN
+			    && ((t & 0x20)) != 0)
+			   ? FP_EX_INVALID_SNAN : 0));
+    ovf:
+      if (!sgn)
+	__builtin_memset (r, -1, rn * sizeof (UBILtype));
+      else
+	__builtin_memset (r, 0, rn * sizeof (UBILtype));
+      if (sgn ^ (rprec >= 0))
+	r[BITINT_END (0, rn - 1)]
+	  |= (UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE);
+      else
+	r[BITINT_END (0, rn - 1)]
+	  &= ~((UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE));
+      goto done;
+    }
+  exponent -= 101;
+
+  if (mantissa == 0)
+    {
+      /* Zero (with any exponent).  */
+    zero:
+      __builtin_memset (r, 0, rn * sizeof (UBILtype));
+      goto done;
+    }
+  if (exponent <= -7)
+    {
+      FP_SET_EXCEPTION (FP_EX_INEXACT);
+      goto zero;
+    }
+  else if (exponent < 0)
+    {
+      UBILtype limbs[64 / BIL_TYPE_SIZE];
+      USItype rem;
+      UDItype d;
+      __bid_pow10bitint (limbs, 64, -exponent);
+#if BIL_TYPE_SIZE == 64
+      d = limbs[0];
+#elif BIL_TYPE_SIZE == 32
+      d = (limbs[BITINT_END (0, 1)] << 32) | limbs[BITINT_END (1, 0)];
+#else
+# error Unsupported BIL_TYPE_SIZE
+#endif
+      rem = mantissa % (USItype) d;
+      mantissa /= (USItype) d;
+      if (rem)
+	FP_SET_EXCEPTION (FP_EX_INEXACT);
+      if (mantissa == 0)
+	goto zero;
+      exponent = 0;
+    }
+
+  if (rprec >= 0 && sgn)
+    {
+    ovf_ex:
+      FP_SET_EXCEPTION (FP_EX_INVALID | FP_EX_INVALID_CVI);
+      goto ovf;
+    }
+
+  /* Lower estimate for number of bits needed for pow10 (exponent).  */
+  exp_bits = exponent / 3;
+  exp_bits = exp_bits * 10 - exp_bits / 29;
+  mant_bits = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (mantissa);
+  if (exp_bits + mant_bits > arprec + 1)
+    goto ovf_ex;
+  /* Upper estimate for number of bits needed for pow10 (exponent).  */
+  exp_bits = (exponent + 2) / 3;
+  exp_bits = exp_bits * 10 - exp_bits / 30;
+  if (exp_bits == 0)
+    exp_bits = 1;
+  pow10_limbs = (exp_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  pow10v = __builtin_alloca (pow10_limbs * sizeof (UBILtype));
+  low_zeros = __bid_pow10bitint (pow10v, exp_bits, exponent);
+
+  res_limbs = ((exp_bits + mant_bits + BIL_TYPE_SIZE - 1)
+	       / BIL_TYPE_SIZE) - low_zeros;
+  mant_limbs = 1;
+  resv = __builtin_alloca ((res_limbs + mant_limbs) * sizeof (UBILtype));
+  resv[res_limbs] = mantissa;
+  __mulbitint3 (resv, exp_bits + mant_bits - low_zeros * BIL_TYPE_SIZE,
+		resv + res_limbs, mant_bits,
+		pow10v + BITINT_END (0, low_zeros),
+		exp_bits - low_zeros * BIL_TYPE_SIZE);
+  if (res_limbs + low_zeros >= rn)
+    {
+      if (res_limbs + low_zeros > rn && resv[BITINT_END (0, res_limbs - 1)])
+	goto ovf_ex;
+      if ((arprec % BIL_TYPE_SIZE) != 0
+	  && (resv[BITINT_END (rn - res_limbs, rn - 1) - low_zeros]
+	      & ((UBILtype) -1 << (arprec % BIL_TYPE_SIZE))) != 0)
+	goto ovf_ex;
+      min_limbs = rn - low_zeros;
+    }
+  else
+    min_limbs = res_limbs;
+  if (low_zeros)
+    __builtin_memset (r + BITINT_END (rn - low_zeros, 0), '\0',
+		      low_zeros * sizeof (UBILtype));
+  if (sgn)
+    bitint_negate (r + BITINT_END (rn - low_zeros - 1, low_zeros),
+		   resv + BITINT_END (res_limbs - 1, 0), min_limbs);
+  else
+    __builtin_memcpy (r + BITINT_END (rn - low_zeros - min_limbs, low_zeros),
+		      resv + BITINT_END (res_limbs - min_limbs, 0),
+		      min_limbs * sizeof (UBILtype));
+  if (res_limbs + low_zeros < rn)
+    {
+      if (sgn)
+	__builtin_memset (r + BITINT_END (0, res_limbs + low_zeros), -1,
+			  (rn - res_limbs - low_zeros) * sizeof (UBILtype));
+      else
+	__builtin_memset (r + BITINT_END (0, res_limbs + low_zeros), '\0',
+			  (rn - res_limbs - low_zeros) * sizeof (UBILtype));
+    }
+  else if (sgn)
+    {
+      if ((r[BITINT_END (0, rn - 1)]
+	   & ((UBILtype) 1 << ((arprec - 1) % BIL_TYPE_SIZE))) == 0)
+	goto ovf_ex;
+    }
+  else if (rprec < 0
+	   && (r[BITINT_END (0, rn - 1)]
+	       & ((UBILtype) 1 << ((arprec - 1) % BIL_TYPE_SIZE))) != 0)
+    goto ovf_ex;
+
+done:
+  FP_HANDLE_EXCEPTIONS;
+}
+#endif
--- libgcc/soft-fp/fixddbitint.c.jj	2023-08-08 16:21:45.953768373 +0200
+++ libgcc/soft-fp/fixddbitint.c	2023-08-08 16:21:45.953768373 +0200
@@ -0,0 +1,205 @@
+/* Software floating-point emulation.
+   Convert _Decimal64 to signed or unsigned _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+extern void __bid_fixddbitint (UBILtype *, SItype, _Decimal64);
+
+void
+__bid_fixddbitint (UBILtype *r, SItype rprec, _Decimal64 a)
+{
+  FP_DECL_EX;
+  USItype arprec = rprec < 0 ? -rprec : rprec;
+  USItype rn = (arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  union { _Decimal64 d; UDItype u; } u;
+  UDItype mantissa, t;
+  SItype sgn;
+  SItype exponent;
+  USItype exp_bits, mant_bits;
+  UBILtype *pow10v, *resv;
+  USItype pow10_limbs, res_limbs, min_limbs, mant_limbs, low_zeros;
+
+  FP_INIT_EXCEPTIONS;
+  u.d = a;
+  t = u.u >> 51;
+  sgn = (DItype) u.u < 0;
+  if ((t & (3 << 10)) != (3 << 10))
+    {
+      mantissa = u.u & ((((UDItype) 1) << 53) - 1);
+      exponent = (t >> 2) & 0x3ff;
+    }
+  else if ((t & (3 << 8)) != (3 << 8))
+    {
+      mantissa = u.u & ((((UDItype) 1) << 51) - 1);
+      mantissa |= ((UDItype) 1) << 53;
+      exponent = t & 0x3ff;
+      if (mantissa > (UDItype) 9999999999999999)
+	mantissa = 0;
+    }
+  else
+    {
+      FP_SET_EXCEPTION (FP_EX_INVALID
+			| FP_EX_INVALID_CVI
+			| ((FP_EX_INVALID_SNAN
+			    && ((t & 0x80)) != 0)
+			   ? FP_EX_INVALID_SNAN : 0));
+    ovf:
+      if (!sgn)
+	__builtin_memset (r, -1, rn * sizeof (UBILtype));
+      else
+	__builtin_memset (r, 0, rn * sizeof (UBILtype));
+      if (sgn ^ (rprec >= 0))
+	r[BITINT_END (0, rn - 1)]
+	  |= (UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE);
+      else
+	r[BITINT_END (0, rn - 1)]
+	  &= ~((UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE));
+      goto done;
+    }
+  exponent -= 398;
+
+  if (mantissa == 0)
+    {
+      /* Zero (with any exponent).  */
+    zero:
+      __builtin_memset (r, 0, rn * sizeof (UBILtype));
+      goto done;
+    }
+  if (exponent <= -16)
+    {
+      FP_SET_EXCEPTION (FP_EX_INEXACT);
+      goto zero;
+    }
+  else if (exponent < 0)
+    {
+      UBILtype limbs[64 / BIL_TYPE_SIZE];
+      UDItype d, rem;
+      __bid_pow10bitint (limbs, 64, -exponent);
+#if BIL_TYPE_SIZE == 64
+      d = limbs[0];
+#elif BIL_TYPE_SIZE == 32
+      d = (limbs[BITINT_END (0, 1)] << 32) | limbs[BITINT_END (1, 0)];
+#else
+# error Unsupported BIL_TYPE_SIZE
+#endif
+      rem = mantissa % d;
+      mantissa /= d;
+      if (rem)
+	FP_SET_EXCEPTION (FP_EX_INEXACT);
+      if (mantissa == 0)
+	goto zero;
+      exponent = 0;
+    }
+
+  if (rprec >= 0 && sgn)
+    {
+    ovf_ex:
+      FP_SET_EXCEPTION (FP_EX_INVALID | FP_EX_INVALID_CVI);
+      goto ovf;
+    }
+
+  /* Lower estimate for number of bits needed for pow10 (exponent).  */
+  exp_bits = exponent / 3;
+  exp_bits = exp_bits * 10 - exp_bits / 29;
+  mant_bits = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (mantissa);
+  if (exp_bits + mant_bits > arprec + 1)
+    goto ovf_ex;
+  /* Upper estimate for number of bits needed for pow10 (exponent).  */
+  exp_bits = (exponent + 2) / 3;
+  exp_bits = exp_bits * 10 - exp_bits / 30;
+  if (exp_bits == 0)
+    exp_bits = 1;
+  pow10_limbs = (exp_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  pow10v = __builtin_alloca (pow10_limbs * sizeof (UBILtype));
+  low_zeros = __bid_pow10bitint (pow10v, exp_bits, exponent);
+
+  res_limbs = ((exp_bits + mant_bits + BIL_TYPE_SIZE - 1)
+	       / BIL_TYPE_SIZE) - low_zeros;
+  mant_limbs = (mant_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  resv = __builtin_alloca ((res_limbs + mant_limbs) * sizeof (UBILtype));
+#if BIL_TYPE_SIZE >= 64
+  resv[res_limbs] = mantissa;
+#else
+  if (mant_limbs == 1)
+    resv[res_limbs] = mantissa;
+  else
+    {
+      resv[res_limbs + BITINT_END (1, 0)] = mantissa;
+      resv[res_limbs + BITINT_END (0, 1)] = mantissa >> 32;
+    }
+#endif
+  __mulbitint3 (resv, exp_bits + mant_bits - low_zeros * BIL_TYPE_SIZE,
+		resv + res_limbs, mant_bits,
+		pow10v + BITINT_END (0, low_zeros),
+		exp_bits - low_zeros * BIL_TYPE_SIZE);
+  if (res_limbs + low_zeros >= rn)
+    {
+      if (res_limbs + low_zeros > rn && resv[BITINT_END (0, res_limbs - 1)])
+	goto ovf_ex;
+      if ((arprec % BIL_TYPE_SIZE) != 0
+	  && (resv[BITINT_END (rn - res_limbs, rn - 1) - low_zeros]
+	      & ((UBILtype) -1 << (arprec % BIL_TYPE_SIZE))) != 0)
+	goto ovf_ex;
+      min_limbs = rn - low_zeros;
+    }
+  else
+    min_limbs = res_limbs;
+  if (low_zeros)
+    __builtin_memset (r + BITINT_END (rn - low_zeros, 0), '\0',
+		      low_zeros * sizeof (UBILtype));
+  if (sgn)
+    bitint_negate (r + BITINT_END (rn - low_zeros - 1, low_zeros),
+		   resv + BITINT_END (res_limbs - 1, 0), min_limbs);
+  else
+    __builtin_memcpy (r + BITINT_END (rn - low_zeros - min_limbs, low_zeros),
+		      resv + BITINT_END (res_limbs - min_limbs, 0),
+		      min_limbs * sizeof (UBILtype));
+  if (res_limbs + low_zeros < rn)
+    {
+      if (sgn)
+	__builtin_memset (r + BITINT_END (0, res_limbs + low_zeros), -1,
+			  (rn - res_limbs - low_zeros) * sizeof (UBILtype));
+      else
+	__builtin_memset (r + BITINT_END (0, res_limbs + low_zeros), '\0',
+			  (rn - res_limbs - low_zeros) * sizeof (UBILtype));
+    }
+  else if (sgn)
+    {
+      if ((r[BITINT_END (0, rn - 1)]
+	   & ((UBILtype) 1 << ((arprec - 1) % BIL_TYPE_SIZE))) == 0)
+	goto ovf_ex;
+    }
+  else if (rprec < 0
+	   && (r[BITINT_END (0, rn - 1)]
+	       & ((UBILtype) 1 << ((arprec - 1) % BIL_TYPE_SIZE))) != 0)
+    goto ovf_ex;
+
+done:
+  FP_HANDLE_EXCEPTIONS;
+}
+#endif
--- libgcc/soft-fp/fixtdbitint.c.jj	2023-08-08 16:21:45.953768373 +0200
+++ libgcc/soft-fp/fixtdbitint.c	2023-08-08 16:21:45.953768373 +0200
@@ -0,0 +1,242 @@
+/* Software floating-point emulation.
+   Convert _Decimal128 to signed or unsigned _BitInt.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+extern void __bid_fixtdbitint (UBILtype *, SItype, _Decimal128);
+
+void
+__bid_fixtdbitint (UBILtype *r, SItype rprec, _Decimal128 a)
+{
+  FP_DECL_EX;
+  USItype arprec = rprec < 0 ? -rprec : rprec;
+  USItype rn = (arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  union { _Decimal128 d; UDItype u[2]; } u;
+  UDItype mantissahi, mantissalo, t;
+  SItype sgn;
+  SItype exponent;
+  USItype exp_bits, mant_bits;
+  UBILtype *pow10v, *resv;
+  USItype pow10_limbs, res_limbs, min_limbs, mant_limbs, low_zeros;
+
+  FP_INIT_EXCEPTIONS;
+  u.d = a;
+  mantissahi = u.u[__FLOAT_WORD_ORDER__ != __ORDER_BIG_ENDIAN__];
+  mantissalo = u.u[__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__];
+  t = mantissahi >> 47;
+  sgn = (DItype) mantissahi < 0;
+  if ((t & (3 << 14)) != (3 << 14))
+    {
+      mantissahi &= ((((UDItype) 1) << 49) - 1);
+      exponent = (t >> 2) & 0x3fff;
+      if (mantissahi > (UDItype) 0x1ed09bead87c0
+	  || (mantissahi == (UDItype) 0x1ed09bead87c0
+	      && mantissalo > 0x378d8e63ffffffff))
+	{
+	  mantissahi = 0;
+	  mantissalo = 0;
+	}
+    }
+  else if ((t & (3 << 12)) != (3 << 12))
+    {
+      mantissahi = 0;
+      mantissalo = 0;
+      exponent = t & 0x3fff;
+    }
+  else
+    {
+      FP_SET_EXCEPTION (FP_EX_INVALID
+			| FP_EX_INVALID_CVI
+			| ((FP_EX_INVALID_SNAN
+			    && ((t & 0x800)) != 0)
+			   ? FP_EX_INVALID_SNAN : 0));
+    ovf:
+      if (!sgn)
+	__builtin_memset (r, -1, rn * sizeof (UBILtype));
+      else
+	__builtin_memset (r, 0, rn * sizeof (UBILtype));
+      if (sgn ^ (rprec >= 0))
+	r[BITINT_END (0, rn - 1)]
+	  |= (UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE);
+      else
+	r[BITINT_END (0, rn - 1)]
+	  &= ~((UBILtype) -1 << ((arprec - 1) % BIL_TYPE_SIZE));
+      goto done;
+    }
+  exponent -= 6176;
+
+  if (mantissahi == 0 && mantissalo == 0)
+    {
+      /* Zero (with any exponent).  */
+    zero:
+      __builtin_memset (r, 0, rn * sizeof (UBILtype));
+      goto done;
+    }
+  if (exponent <= -34)
+    {
+      FP_SET_EXCEPTION (FP_EX_INEXACT);
+      goto zero;
+    }
+  if (exponent < 0)
+    {
+      UBILtype limbs[4 * 128 / BIL_TYPE_SIZE];
+#if BIL_TYPE_SIZE == 64
+      limbs[BITINT_END (0, 1)] = mantissahi;
+      limbs[BITINT_END (1, 0)] = mantissalo;
+#elif BIL_TYPE_SIZE == 32
+      limbs[BITINT_END (0, 3)] = mantissahi >> 32;
+      limbs[BITINT_END (1, 2)] = mantissahi;
+      limbs[BITINT_END (2, 1)] = mantissalo >> 32;
+      limbs[BITINT_END (3, 0)] = mantissalo;
+#elif
+# error Unhandled BIL_TYPE_SIZE
+#endif
+      __bid_pow10bitint (&limbs[128 / BIL_TYPE_SIZE], 128, -exponent);
+      __divmodbitint4 (&limbs[2 * 128 / BIL_TYPE_SIZE], 128,
+		       &limbs[3 * 128 / BIL_TYPE_SIZE], 128,
+		       &limbs[0], 128, &limbs[128 / BIL_TYPE_SIZE], 128);
+      UDItype rem;
+#if BIL_TYPE_SIZE == 64
+      mantissahi = limbs[BITINT_END (4, 5)];
+      mantissalo = limbs[BITINT_END (5, 4)];
+      rem = limbs[6] | limbs[7];
+#elif BIL_TYPE_SIZE == 32
+      mantissahi = limbs[BITINT_END (8, 11)] << 32;
+      mantissahi |= limbs[BITINT_END (9, 10)];
+      mantissalo = limbs[BITINT_END (10, 9)] << 32;
+      mantissalo |= limbs[BITINT_END (11, 8)];
+      rem = limbs[12] | limbs[13] | limbs[14] | limbs[15];
+#endif
+      if (rem)
+	FP_SET_EXCEPTION (FP_EX_INEXACT);
+      if (mantissahi == 0 && mantissalo == 0)
+	goto zero;
+      exponent = 0;
+    }
+
+  if (rprec >= 0 && sgn)
+    {
+    ovf_ex:
+      FP_SET_EXCEPTION (FP_EX_INVALID | FP_EX_INVALID_CVI);
+      goto ovf;
+    }
+
+  /* Lower estimate for number of bits needed for pow10 (exponent).  */
+  exp_bits = exponent / 3;
+  exp_bits = exp_bits * 10 - exp_bits / 29;
+  if (mantissahi)
+    mant_bits = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (mantissahi)
+		+ 64;
+  else
+    mant_bits = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (mantissalo);
+  if (exp_bits + mant_bits > arprec + 1)
+    goto ovf_ex;
+  /* Upper estimate for number of bits needed for pow10 (exponent).  */
+  exp_bits = (exponent + 2) / 3;
+  exp_bits = exp_bits * 10 - exp_bits / 30;
+  if (exp_bits == 0)
+    exp_bits = 1;
+  pow10_limbs = (exp_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  pow10v = __builtin_alloca (pow10_limbs * sizeof (UBILtype));
+  low_zeros = __bid_pow10bitint (pow10v, exp_bits, exponent);
+
+  res_limbs = ((exp_bits + mant_bits + BIL_TYPE_SIZE - 1)
+	       / BIL_TYPE_SIZE) - low_zeros;
+  mant_limbs = (mant_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  resv = __builtin_alloca ((res_limbs + mant_limbs) * sizeof (UBILtype));
+#if BIL_TYPE_SIZE >= 64
+  if (mant_limbs == 1)
+    resv[res_limbs] = mantissalo;
+  else
+    {
+      resv[res_limbs + BITINT_END (1, 0)] = mantissalo;
+      resv[res_limbs + BITINT_END (0, 1)] = mantissahi;
+    }
+#else
+  resv[res_limbs + BITINT_END (mant_limbs - 1, 0)] = mantissalo;
+  if (mant_limbs >= 2)
+    {
+      resv[res_limbs + BITINT_END (mant_limbs - 2, 1)] = mantissalo >> 32;
+      if (mant_limbs >= 3)
+	{
+	  resv[res_limbs + BITINT_END (mant_limbs - 3, 2)] = mantissahi;
+	  if (mant_limbs == 4)
+	    resv[res_limbs + BITINT_END (0, 3)] = mantissahi >> 32;
+	}
+    }
+#endif
+  __mulbitint3 (resv, exp_bits + mant_bits - low_zeros * BIL_TYPE_SIZE,
+		resv + res_limbs, mant_bits,
+		pow10v + BITINT_END (0, low_zeros),
+		exp_bits - low_zeros * BIL_TYPE_SIZE);
+  if (res_limbs + low_zeros >= rn)
+    {
+      if (res_limbs + low_zeros > rn && resv[BITINT_END (0, res_limbs - 1)])
+	goto ovf_ex;
+      if ((arprec % BIL_TYPE_SIZE) != 0
+	  && (resv[BITINT_END (rn - res_limbs, rn - 1) - low_zeros]
+	      & ((UBILtype) -1 << (arprec % BIL_TYPE_SIZE))) != 0)
+	goto ovf_ex;
+      min_limbs = rn - low_zeros;
+    }
+  else
+    min_limbs = res_limbs;
+  if (low_zeros)
+    __builtin_memset (r + BITINT_END (rn - low_zeros, 0), '\0',
+		      low_zeros * sizeof (UBILtype));
+  if (sgn)
+    bitint_negate (r + BITINT_END (rn - low_zeros - 1, low_zeros),
+		   resv + BITINT_END (res_limbs - 1, 0), min_limbs);
+  else
+    __builtin_memcpy (r + BITINT_END (rn - low_zeros - min_limbs, low_zeros),
+		      resv + BITINT_END (res_limbs - min_limbs, 0),
+		      min_limbs * sizeof (UBILtype));
+  if (res_limbs + low_zeros < rn)
+    {
+      if (sgn)
+	__builtin_memset (r + BITINT_END (0, res_limbs + low_zeros), -1,
+			  (rn - res_limbs - low_zeros) * sizeof (UBILtype));
+      else
+	__builtin_memset (r + BITINT_END (0, res_limbs + low_zeros), '\0',
+			  (rn - res_limbs - low_zeros) * sizeof (UBILtype));
+    }
+  else if (sgn)
+    {
+      if ((r[BITINT_END (0, rn - 1)]
+	   & ((UBILtype) 1 << ((arprec - 1) % BIL_TYPE_SIZE))) == 0)
+	goto ovf_ex;
+    }
+  else if (rprec < 0
+	   && (r[BITINT_END (0, rn - 1)]
+	       & ((UBILtype) 1 << ((arprec - 1) % BIL_TYPE_SIZE))) != 0)
+    goto ovf_ex;
+
+done:
+  FP_HANDLE_EXCEPTIONS;
+}
+#endif
--- libgcc/soft-fp/floatbitintsd.c.jj	2023-08-08 16:22:09.405440134 +0200
+++ libgcc/soft-fp/floatbitintsd.c	2023-08-08 16:22:09.405440134 +0200
@@ -0,0 +1,235 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to _Decimal32.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+extern _Decimal32 __bid_floatbitintsd (const UBILtype *, SItype);
+
+_Decimal32
+__bid_floatbitintsd (const UBILtype *i, SItype iprec)
+{
+  iprec = bitint_reduce_prec (&i, iprec);
+  USItype aiprec = iprec < 0 ? -iprec : iprec;
+  USItype in = (aiprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  USItype idx = BITINT_END (0, in - 1);
+  UBILtype msb = i[idx];
+  USItype mantissa;
+  SItype exponent = 0;
+  UBILtype inexact = 0;
+  union { _Decimal32 d; USItype u; } u, ui;
+  if (aiprec % BIL_TYPE_SIZE)
+    {
+      if (iprec > 0)
+	msb &= ((UBILtype) 1 << (aiprec % BIL_TYPE_SIZE)) - 1;
+      else
+	msb |= (UBILtype) -1 << (aiprec % BIL_TYPE_SIZE);
+    }
+  if (iprec < 0)
+    {
+      SItype n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb);
+      aiprec = (in - 1) * BIL_TYPE_SIZE + n;
+    }
+  else if (msb == 0)
+    aiprec = 1;
+  else
+    {
+      SItype n = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (msb);
+      aiprec = (in - 1) * BIL_TYPE_SIZE + n;
+    }
+  /* Number of bits in (_BitInt(2048)) 9999999e+90DF.  */
+  if (aiprec > 323 + (iprec < 0))
+    {
+    ovf:
+      if (iprec < 0)
+	u.d = -9000000e+90DF;
+      else
+	u.d = 9000000e+90DF;
+      __asm ("" : "+g" (u.d));
+      u.d += u.d;
+      __asm ("" : "+g" (u.d));
+      goto done;
+    }
+  /* Bit precision of 9999999uwb.  */
+  if (aiprec >= 24)
+    {
+      USItype pow10_limbs, q_limbs, q2_limbs, j;
+      USItype exp_bits = 0, e;
+      UDItype m;
+      UBILtype *buf;
+      /* First do a possibly large divide smaller enough such that
+	 we only need to check remainder for 0 or non-0 and then
+	 we'll do further division.  */
+      if (aiprec >= 24 + 4 + 10)
+	{
+	  exp_bits = (aiprec - 24 - 4) / 10;
+	  exponent = exp_bits * 3;
+	  /* Upper estimate for pow10 (exponent) bits.  */
+	  exp_bits = exp_bits * 10 - exp_bits / 30;
+	}
+      pow10_limbs = (exp_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+      /* 38 is the highest number of quotient bits needed on
+	 aiprec range of [38, 323].  E.g. if aiprec is 317,
+	 exponent will be 84 and exp_bits 280.  317 - 280 + 1
+	 is 38.  */
+      q_limbs = (38 + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+      q2_limbs = (32 + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+      buf = __builtin_alloca ((q_limbs + pow10_limbs * 2 + q2_limbs + 2)
+			      * sizeof (UBILtype));
+      if (exponent)
+	{
+	  __bid_pow10bitint (buf + q_limbs, exp_bits, exponent);
+	  __divmodbitint4 (buf, q_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs,
+			   pow10_limbs * BIL_TYPE_SIZE,
+			   i, iprec < 0 ? -aiprec : aiprec,
+			   buf + q_limbs, exp_bits);
+	  if (iprec < 0)
+	    bitint_negate (buf + BITINT_END (q_limbs - 1, 0),
+			   buf + BITINT_END (q_limbs - 1, 0), q_limbs);
+	  inexact = buf[q_limbs + pow10_limbs];
+	  for (j = 1; j < pow10_limbs; ++j)
+	    inexact |= buf[q_limbs + pow10_limbs + 1];
+	}
+      else
+	{
+	  __builtin_memcpy (buf + BITINT_END (q_limbs - in + 1, 0), i,
+			    (in - 1) * sizeof (UBILtype));
+	  buf[BITINT_END (q_limbs - in, in - 1)] = msb;
+	  if (iprec < 0)
+	    bitint_negate (buf + BITINT_END (q_limbs - 1, 0),
+			   buf + BITINT_END (q_limbs - 1, 0), in);
+	  if (q_limbs > in)
+	    __builtin_memset (buf + BITINT_END (0, in), '\0',
+			      (q_limbs - in) * sizeof (UBILtype));
+	}
+      e = 0;
+#if BIL_TYPE_SIZE == 64
+      m = buf[0];
+#elif BIL_TYPE_SIZE == 32
+      m = ((UDItype) buf[BITINT_END (0, 1)] << 32) | buf[BITINT_END (1, 0)];
+#else
+# error Unsupported BIL_TYPE_SIZE
+#endif
+      if (m >= (UDItype) 10000000000)
+	{
+	  if (m >= (UDItype) 100000000000)
+	    e = 5;
+	  else
+	    e = 4;
+	}
+      else if (m >= (UDItype) 100000000)
+	{
+	  if (m >= (UDItype) 1000000000)
+	    e = 3;
+	  else
+	    e = 2;
+	}
+      else if (m >= (UDItype) 10000000)
+	e = 1;
+      exponent += e;
+      if (exponent > 90)
+	goto ovf;
+      if (e)
+	{
+	  UBILtype rem, half;
+	  __bid_pow10bitint (buf + q_limbs + pow10_limbs * 2,
+			     BIL_TYPE_SIZE, e);
+	  __divmodbitint4 (buf + q_limbs + pow10_limbs * 2 + 1,
+			   q2_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs * 2 + 1 + q2_limbs,
+			   BIL_TYPE_SIZE,
+			   buf, q_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs * 2, BIL_TYPE_SIZE);
+	  half = buf[q_limbs + pow10_limbs * 2] / 2;
+	  rem = buf[q_limbs + pow10_limbs * 2 + 1 + q2_limbs];
+	  if (inexact)
+	    {
+	      /* If first division discovered some non-0 digits
+		 and this second division is by 10, e.g.
+		 for XXXXXX5499999999999 or XXXXXX5000000000001
+		 if first division is by 10^12 and second by 10^1,
+		 doing rem |= 1 wouldn't change the 5.  Similarly
+		 for rem 4 doing rem |= 1 would change it to 5,
+		 but we don't want to change it in that case.  */
+	      if (e == 1)
+		{
+		  if (rem == 5)
+		    rem = 6;
+		  else if (rem != 4)
+		    rem |= 1;
+		}
+	      else
+		rem |= 1;
+	    }
+	  /* Set inexact to 0, 1, 2, 3 depending on if remainder
+	     of the divisions is exact 0, smaller than 10^exponent / 2,
+	     exactly 10^exponent / 2 or greater than that.  */
+	  if (rem >= half)
+	    inexact = 2 + (rem > half);
+	  else
+	    inexact = (rem != 0);
+	  mantissa = buf[q_limbs + pow10_limbs * 2 + 1];
+	}
+      else
+#if BIL_TYPE_SIZE == 64
+	mantissa = buf[0];
+#else
+	mantissa = buf[BITINT_END (1, 0)];
+#endif
+    }
+  else
+    {
+      mantissa = msb;
+      if (iprec < 0)
+	mantissa = -mantissa;
+    }
+
+  exponent += 101;
+  if (mantissa >= (USItype) 0x800000)
+    u.u = (((((iprec < 0) << 2) | (USItype) 3) << 29)
+	   | (((USItype) exponent) << 21)
+	   | (mantissa ^ (USItype) 0x800000));
+  else
+    u.u = ((((USItype) (iprec < 0)) << 31)
+	   | (((USItype) exponent) << 23)
+	   | mantissa);
+  if (inexact)
+    {
+      ui.u = ((((USItype) (iprec < 0)) << 31)
+	      | (((USItype) (exponent - 1)) << 23)
+	      | (inexact + 3));
+      __asm ("" : "+g" (u.d));
+      __asm ("" : "+g" (ui.d));
+      u.d += ui.d;
+      __asm ("" : "+g" (u.d));
+    }
+
+done:
+  return u.d;
+}
+#endif
--- libgcc/soft-fp/floatbitintdd.c.jj	2023-08-08 16:22:09.405440134 +0200
+++ libgcc/soft-fp/floatbitintdd.c	2023-08-08 16:22:09.405440134 +0200
@@ -0,0 +1,264 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to _Decimal64.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+extern _Decimal64 __bid_floatbitintdd (const UBILtype *, SItype);
+
+_Decimal64
+__bid_floatbitintdd (const UBILtype *i, SItype iprec)
+{
+  iprec = bitint_reduce_prec (&i, iprec);
+  USItype aiprec = iprec < 0 ? -iprec : iprec;
+  USItype in = (aiprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  USItype idx = BITINT_END (0, in - 1);
+  UBILtype msb = i[idx];
+  UDItype mantissa;
+  SItype exponent = 0;
+  UBILtype inexact = 0;
+  union { _Decimal64 d; UDItype u; } u, ui;
+  if (aiprec % BIL_TYPE_SIZE)
+    {
+      if (iprec > 0)
+	msb &= ((UBILtype) 1 << (aiprec % BIL_TYPE_SIZE)) - 1;
+      else
+	msb |= (UBILtype) -1 << (aiprec % BIL_TYPE_SIZE);
+    }
+  if (iprec < 0)
+    {
+      SItype n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb);
+      aiprec = (in - 1) * BIL_TYPE_SIZE + n;
+    }
+  else if (msb == 0)
+    aiprec = 1;
+  else
+    {
+      SItype n = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (msb);
+      aiprec = (in - 1) * BIL_TYPE_SIZE + n;
+    }
+  /* Number of bits in (_BitInt(2048)) 9999999999999999e+369DD.  */
+  if (aiprec > 1279 + (iprec < 0))
+    {
+    ovf:
+      if (iprec < 0)
+	u.d = -9000000000000000e+369DD;
+      else
+	u.d = 9000000000000000e+369DD;
+      __asm ("" : "+g" (u.d));
+      u.d += u.d;
+      __asm ("" : "+g" (u.d));
+      goto done;
+    }
+  /* Bit precision of 9999999999999999uwb.  */
+  if (aiprec >= 54)
+    {
+      USItype pow10_limbs, q_limbs, q2_limbs, j;
+      USItype exp_bits = 0, e;
+      UDItype m;
+      UBILtype *buf;
+      /* First do a possibly large divide smaller enough such that
+	 we only need to check remainder for 0 or non-0 and then
+	 we'll do further division.  */
+      if (aiprec >= 54 + 4 + 10)
+	{
+	  exp_bits = (aiprec - 54 - 4) / 10;
+	  exponent = exp_bits * 3;
+	  /* Upper estimate for pow10 (exponent) bits.  */
+	  exp_bits = exp_bits * 10 - exp_bits / 30;
+	}
+      pow10_limbs = (exp_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+      /* 72 is the highest number of quotient bits needed on
+	 aiprec range of [68, 1279].  E.g. if aiprec is 1277,
+	 exponent will be 363 and exp_bits 1206.  1277 - 1206 + 1
+	 is 72.  Unfortunately that means the result doesn't fit into
+	 UDItype...  */
+      q_limbs = (72 + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+      q2_limbs = 64 / BIL_TYPE_SIZE;
+      buf = __builtin_alloca ((q_limbs + pow10_limbs * 2 + q2_limbs + 2)
+			      * sizeof (UBILtype));
+      if (exponent)
+	{
+	  __bid_pow10bitint (buf + q_limbs, exp_bits, exponent);
+	  __divmodbitint4 (buf, q_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs,
+			   pow10_limbs * BIL_TYPE_SIZE,
+			   i, iprec < 0 ? -aiprec : aiprec,
+			   buf + q_limbs, exp_bits);
+	  if (iprec < 0)
+	    bitint_negate (buf + BITINT_END (q_limbs - 1, 0),
+			   buf + BITINT_END (q_limbs - 1, 0), q_limbs);
+	  inexact = buf[q_limbs + pow10_limbs];
+	  for (j = 1; j < pow10_limbs; ++j)
+	    inexact |= buf[q_limbs + pow10_limbs + 1];
+	}
+      else
+	{
+	  __builtin_memcpy (buf + BITINT_END (q_limbs - in + 1, 0), i,
+			    (in - 1) * sizeof (UBILtype));
+	  buf[BITINT_END (q_limbs - in, in - 1)] = msb;
+	  if (iprec < 0)
+	    bitint_negate (buf + BITINT_END (q_limbs - 1, 0),
+			   buf + BITINT_END (q_limbs - 1, 0), in);
+	  if (q_limbs > in)
+	    __builtin_memset (buf + BITINT_END (0, in), '\0',
+			      (q_limbs - in) * sizeof (UBILtype));
+	}
+      e = 0;
+#if BIL_TYPE_SIZE == 64
+      m = buf[BITINT_END (1, 0)];
+#elif BIL_TYPE_SIZE == 32
+      m = ((UDItype) buf[1] << 32) | buf[BITINT_END (2, 0)];
+#else
+# error Unsupported BIL_TYPE_SIZE
+#endif
+      if (buf[BITINT_END (0, q_limbs - 1)])
+	{
+	  if (buf[BITINT_END (0, q_limbs - 1)] > 0x5)
+	    {
+	      /* 1000000000000000000000wb */
+	      if (buf[BITINT_END (0, q_limbs - 1)] > 0x36
+		  || (buf[BITINT_END (0, q_limbs - 1)] == 0x36
+		      && m >= (UDItype) 0x35c9adc5dea00000))
+		e = 6;
+	      else
+		e = 5;
+	    }
+	  /* 100000000000000000000wb */
+	  else if (buf[BITINT_END (0, q_limbs - 1)] == 0x5
+		   && m >= (UDItype) 0x6bc75e2d63100000)
+	    e = 5;
+	  else
+	    e = 4;
+	}
+      else if (m >= (UDItype) 1000000000000000000)
+	{
+	  if (m >= (UDItype) 10000000000000000000ULL)
+	    e = 4;
+	  else
+	    e = 3;
+	}
+      else if (m >= (UDItype) 100000000000000000)
+	e = 2;
+      else if (m >= (UDItype) 10000000000000000)
+	e = 1;
+      exponent += e;
+      if (exponent > 369)
+	goto ovf;
+      if (e)
+	{
+	  UBILtype rem, half;
+	  __bid_pow10bitint (buf + q_limbs + pow10_limbs * 2,
+			     BIL_TYPE_SIZE, e);
+	  __divmodbitint4 (buf + q_limbs + pow10_limbs * 2 + 1,
+			   q2_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs * 2 + 1 + q2_limbs,
+			   BIL_TYPE_SIZE,
+			   buf, q_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs * 2, BIL_TYPE_SIZE);
+	  half = buf[q_limbs + pow10_limbs * 2] / 2;
+	  rem = buf[q_limbs + pow10_limbs * 2 + 1 + q2_limbs];
+	  if (inexact)
+	    {
+	      /* If first division discovered some non-0 digits
+		 and this second division is by 10, e.g.
+		 for XXXXXX5499999999999 or XXXXXX5000000000001
+		 if first division is by 10^12 and second by 10^1,
+		 doing rem |= 1 wouldn't change the 5.  Similarly
+		 for rem 4 doing rem |= 1 would change it to 5,
+		 but we don't want to change it in that case.  */
+	      if (e == 1)
+		{
+		  if (rem == 5)
+		    rem = 6;
+		  else if (rem != 4)
+		    rem |= 1;
+		}
+	      else
+		rem |= 1;
+	    }
+	  /* Set inexact to 0, 1, 2, 3 depending on if remainder
+	     of the divisions is exact 0, smaller than 10^exponent / 2,
+	     exactly 10^exponent / 2 or greater than that.  */
+	  if (rem >= half)
+	    inexact = 2 + (rem > half);
+	  else
+	    inexact = (rem != 0);
+#if BIL_TYPE_SIZE == 64
+	  mantissa = buf[q_limbs + pow10_limbs * 2 + 1];
+#else
+	  mantissa
+	    = ((buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (0, 1)] << 32)
+	       | buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (1, 0)]);
+#endif
+	}
+      else
+#if BIL_TYPE_SIZE == 64
+	mantissa = buf[BITINT_END (1, 0)];
+#else
+	mantissa
+	  = ((buf[1] << 32) | buf[BITINT_END (2, 0)]);
+#endif
+    }
+  else
+    {
+#if BIL_TYPE_SIZE == 64
+      mantissa = msb;
+#else
+      if (in == 1)
+	mantissa = iprec < 0 ? (UDItype) (BILtype) msb : (UDItype) msb;
+      else
+	mantissa = ((msb << 32) | i[BITINT_END (1, 0)]);
+#endif
+      if (iprec < 0)
+	mantissa = -mantissa;
+    }
+
+  exponent += 398;
+  if (mantissa >= (UDItype) 0x20000000000000)
+    u.u = (((((iprec < 0) << 2) | (UDItype) 3) << 61)
+	   | (((UDItype) exponent) << 51)
+	   | (mantissa ^ (UDItype) 0x20000000000000));
+  else
+    u.u = ((((UDItype) (iprec < 0)) << 63)
+	   | (((UDItype) exponent) << 53)
+	   | mantissa);
+  if (inexact)
+    {
+      ui.u = ((((UDItype) (iprec < 0)) << 63)
+	      | (((UDItype) (exponent - 1)) << 53)
+	      | (inexact + 3));
+      __asm ("" : "+g" (u.d));
+      __asm ("" : "+g" (ui.d));
+      u.d += ui.d;
+      __asm ("" : "+g" (u.d));
+    }
+
+done:
+  return u.d;
+}
+#endif
--- libgcc/soft-fp/floatbitinttd.c.jj	2023-08-08 16:22:09.405440134 +0200
+++ libgcc/soft-fp/floatbitinttd.c	2023-08-08 16:22:09.405440134 +0200
@@ -0,0 +1,271 @@
+/* Software floating-point emulation.
+   Convert a _BitInt to _Decimal128.
+
+   Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "bitint.h"
+
+#ifdef __BITINT_MAXWIDTH__
+extern _Decimal128 __bid_floatbitinttd (const UBILtype *, SItype);
+
+_Decimal128
+__bid_floatbitinttd (const UBILtype *i, SItype iprec)
+{
+  iprec = bitint_reduce_prec (&i, iprec);
+  USItype aiprec = iprec < 0 ? -iprec : iprec;
+  USItype in = (aiprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+  USItype idx = BITINT_END (0, in - 1);
+  UBILtype msb = i[idx];
+  UDItype mantissahi, mantissalo;
+  SItype exponent = 0;
+  UBILtype inexact = 0;
+  union { _Decimal128 d; UDItype u[2]; } u, ui;
+  if (aiprec % BIL_TYPE_SIZE)
+    {
+      if (iprec > 0)
+	msb &= ((UBILtype) 1 << (aiprec % BIL_TYPE_SIZE)) - 1;
+      else
+	msb |= (UBILtype) -1 << (aiprec % BIL_TYPE_SIZE);
+    }
+  if (iprec < 0)
+    {
+      SItype n = sizeof (0ULL) * __CHAR_BIT__ + 1 - __builtin_clzll (~msb);
+      aiprec = (in - 1) * BIL_TYPE_SIZE + n;
+    }
+  else if (msb == 0)
+    aiprec = 1;
+  else
+    {
+      SItype n = sizeof (0ULL) * __CHAR_BIT__ - __builtin_clzll (msb);
+      aiprec = (in - 1) * BIL_TYPE_SIZE + n;
+    }
+  /* Number of bits in
+     (_BitInt(32768)) 9999999999999999999999999999999999e+6111DL.  */
+  if (aiprec > 20414 + (iprec < 0))
+    {
+    ovf:
+      if (iprec < 0)
+	u.d = -9000000000000000000000000000000000e+6111DL;
+      else
+	u.d = 9000000000000000000000000000000000e+6111DL;
+      __asm ("" : "+g" (u.d));
+      u.d += u.d;
+      __asm ("" : "+g" (u.d));
+      goto done;
+    }
+  /* Bit precision of 9999999999999999999999999999999999uwb.  */
+  if (aiprec >= 113)
+    {
+      USItype pow10_limbs, q_limbs, q2_limbs, j, k;
+      USItype exp_bits = 0, e;
+      UBILtype *buf;
+      /* First do a possibly large divide smaller enough such that
+	 we only need to check remainder for 0 or non-0 and then
+	 we'll do further division.  */
+      if (aiprec >= 113 + 4 + 10)
+	{
+	  exp_bits = ((aiprec - 113 - 4) * (UDItype) 30) / 299;
+	  exponent = exp_bits * 3;
+	  /* Upper estimate for pow10 (exponent) bits.  */
+	  exp_bits = exp_bits * 10 - exp_bits / 30;
+	}
+      pow10_limbs = (exp_bits + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+      /* 127 is the highest number of quotient bits needed on
+	 aiprec range of [127, 20414].  E.g. if aiprec is 20409,
+	 exponent will be 6105 and exp_bits 20283.  20409 - 20283 + 1
+	 is 127.  */
+      q_limbs = (127 + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE;
+      q2_limbs = 128 / BIL_TYPE_SIZE;
+      buf = __builtin_alloca ((q_limbs + pow10_limbs * 2 + q2_limbs + 2)
+			      * sizeof (UBILtype));
+      if (exponent)
+	{
+	  __bid_pow10bitint (buf + q_limbs, exp_bits, exponent);
+	  __divmodbitint4 (buf, q_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs,
+			   pow10_limbs * BIL_TYPE_SIZE,
+			   i, iprec < 0 ? -aiprec : aiprec,
+			   buf + q_limbs, exp_bits);
+	  if (iprec < 0)
+	    bitint_negate (buf + BITINT_END (q_limbs - 1, 0),
+			   buf + BITINT_END (q_limbs - 1, 0), q_limbs);
+	  inexact = buf[q_limbs + pow10_limbs];
+	  for (j = 1; j < pow10_limbs; ++j)
+	    inexact |= buf[q_limbs + pow10_limbs + 1];
+	}
+      else
+	{
+	  __builtin_memcpy (buf + BITINT_END (q_limbs - in + 1, 0), i,
+			    (in - 1) * sizeof (UBILtype));
+	  buf[BITINT_END (q_limbs - in, in - 1)] = msb;
+	  if (iprec < 0)
+	    bitint_negate (buf + BITINT_END (q_limbs - 1, 0),
+			   buf + BITINT_END (q_limbs - 1, 0), in);
+	  if (q_limbs > in)
+	    __builtin_memset (buf + BITINT_END (0, in), '\0',
+			      (q_limbs - in) * sizeof (UBILtype));
+	}
+      e = 0;
+      for (j = 3; j; )
+	{
+	  USItype eprev = e;
+	  __bid_pow10bitint (buf + q_limbs + pow10_limbs * 2 + 1,
+			     128, 33 + e + j);
+	  for (k = BITINT_END (0, q_limbs - 1);
+	       k != BITINT_END (q_limbs, (USItype) -1); k -= BITINT_INC)
+	    if (buf[k] > buf[q_limbs + pow10_limbs * 2 + 1 + k])
+	      {
+		e += j;
+		break;
+	      }
+	    else if (buf[k] < buf[q_limbs + pow10_limbs * 2 + 1 + k])
+	      break;
+	  if (k == BITINT_END (q_limbs, (USItype) -1))
+	    e += j;
+	  if (j == 2 && e != eprev)
+	    break;
+	  else
+	    --j;
+	}
+      exponent += e;
+      if (exponent > 6111)
+	goto ovf;
+      if (e)
+	{
+	  UBILtype rem, half;
+	  __bid_pow10bitint (buf + q_limbs + pow10_limbs * 2,
+			     BIL_TYPE_SIZE, e);
+	  __divmodbitint4 (buf + q_limbs + pow10_limbs * 2 + 1,
+			   q2_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs * 2 + 1 + q2_limbs,
+			   BIL_TYPE_SIZE,
+			   buf, q_limbs * BIL_TYPE_SIZE,
+			   buf + q_limbs + pow10_limbs * 2, BIL_TYPE_SIZE);
+	  half = buf[q_limbs + pow10_limbs * 2] / 2;
+	  rem = buf[q_limbs + pow10_limbs * 2 + 1 + q2_limbs];
+	  if (inexact)
+	    {
+	      /* If first division discovered some non-0 digits
+		 and this second division is by 10, e.g.
+		 for XXXXXX5499999999999 or XXXXXX5000000000001
+		 if first division is by 10^12 and second by 10^1,
+		 doing rem |= 1 wouldn't change the 5.  Similarly
+		 for rem 4 doing rem |= 1 would change it to 5,
+		 but we don't want to change it in that case.  */
+	      if (e == 1)
+		{
+		  if (rem == 5)
+		    rem = 6;
+		  else if (rem != 4)
+		    rem |= 1;
+		}
+	      else
+		rem |= 1;
+	    }
+	  /* Set inexact to 0, 1, 2, 3 depending on if remainder
+	     of the divisions is exact 0, smaller than 10^exponent / 2,
+	     exactly 10^exponent / 2 or greater than that.  */
+	  if (rem >= half)
+	    inexact = 2 + (rem > half);
+	  else
+	    inexact = (rem != 0);
+#if BIL_TYPE_SIZE == 64
+	  mantissahi = buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (0, 1)];
+	  mantissalo = buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (1, 0)];
+#else
+	  mantissahi
+	    = ((buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (0, 3)] << 32)
+	       | buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (1, 2)]);
+	  mantissalo
+	    = ((buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (2, 1)] << 32)
+	       | buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (3, 0)]);
+#endif
+	}
+      else
+	{
+#if BIL_TYPE_SIZE == 64
+	  mantissahi = buf[BITINT_END (0, 1)];
+	  mantissalo = buf[BITINT_END (1, 0)];
+#else
+	  mantissahi = (buf[BITINT_END (0, 3)] << 32) | buf[BITINT_END (1, 2)];
+	  mantissalo = (buf[BITINT_END (2, 1)] << 32) | buf[BITINT_END (3, 0)];
+#endif
+	}
+    }
+  else
+    {
+      mantissahi = iprec < 0 ? -1 : 0;
+#if BIL_TYPE_SIZE == 64
+      if (in == 1)
+	mantissalo = msb;
+      else
+	{
+	  mantissahi = msb;
+	  mantissalo = i[BITINT_END (1, 0)];
+	}
+#else
+      if (in <= 2)
+	{
+	  if (in == 1)
+	    mantissalo = iprec < 0 ? (UDItype) (BILtype) msb : (UDItype) msb;
+	  else
+	    mantissalo = (msb << 32) | i[BITINT_END (1, 0)];
+	}
+      else
+	{
+	  if (in == 3)
+	    mantissahi = iprec < 0 ? (UDItype) (BILtype) msb : (UDItype) msb;
+	  else
+	    mantissahi = (msb << 32) | i[BITINT_END (1, 2)];
+	  mantissalo = ((i[BITINT_END (in - 2, 1)] << 32)
+			| i[BITINT_END (in - 1, 0)]);
+	}
+#endif
+      if (iprec < 0)
+	mantissahi
+	  = ~mantissahi + __builtin_add_overflow (~mantissalo, 1, &mantissalo);
+    }
+
+  exponent += 6176;
+  u.u[__FLOAT_WORD_ORDER__ != __ORDER_BIG_ENDIAN__]
+    = ((((UDItype) (iprec < 0)) << 63)
+       | (((UDItype) exponent) << 49)
+       | mantissahi);
+  u.u[__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__] = mantissalo;
+  if (inexact)
+    {
+      ui.u[__FLOAT_WORD_ORDER__ != __ORDER_BIG_ENDIAN__]
+	= (((UDItype) (iprec < 0)) << 63) | (((UDItype) exponent - 1) << 49);
+      ui.u[__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__] = inexact + 3;
+      __asm ("" : "+g" (u.d));
+      __asm ("" : "+g" (ui.d));
+      u.d += ui.d;
+      __asm ("" : "+g" (u.d));
+    }
+
+done:
+  return u.d;
+}
+#endif


	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 15/12] Add further _BitInt <-> floating point tests [PR102989]
  2023-09-01 21:48 ` Joseph Myers
  2023-09-02 11:42   ` Jakub Jelinek
@ 2023-09-04 19:42   ` Jakub Jelinek
  1 sibling, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2023-09-04 19:42 UTC (permalink / raw)
  To: Joseph Myers; +Cc: gcc-patches

Hi!

I've posted the adjusted patches already on Saturday, here is just
the testsuite additions.

On Fri, Sep 01, 2023 at 09:48:22PM +0000, Joseph Myers wrote:
> 1. Test overflowing conversions to integers (including from inf or NaN) 
> raise FE_INVALID.  (Note: it's not specified in the standard whether 
> inexact conversions to integers raise FE_INEXACT or not, so testing that 
> seems less important.)

This is in gcc.dg/bitint-28.c (FE_INVALID) and gcc.dg/bitint-29.c
(FE_INEXACT) for binary and dfp/bitint-8.c new tests.

> 2. Test conversions from integers to floating point raise FE_INEXACT when 
> inexact, together with FE_OVERFLOW when overflowing (while exact 
> conversions don't raise exceptions).

This is in gcc.dg/bitint-30.c new test.

> 3. Test conversions from integers to floating point respect the rounding 
> mode.

This is in gcc.dg/bitint-31.c new test.

> 4. Test converting floating-point values in the range (-1.0, 0.0] to both 
> unsigned and signed _BitInt; I didn't see such tests for binary floating 
> types, only for decimal types, and the decimal tests didn't include tests 
> of negative zero itself as the value converted to _BitInt.

This is done as incremental changes to existing tests.

> 5. Test conversions of noncanonical BID zero to integers (these tests 
> would be specific to BID).  See below for a bug in this area.

This is done in dfp/bitint-7.c test.

Tested on x86_64-linux.

2023-09-04  Jakub Jelinek  <jakub@redhat.com>

	PR c/102989
	* gcc.dg/torture/bitint-21.c (main): Add tests for -1 for signed only,
	-1 + epsilon, another (-1, 0) range value and -0.
	* gcc.dg/torture/bitint-22.c (main): Likewise.
	* gcc.dg/bitint-28.c: New test.
	* gcc.dg/bitint-29.c: New test.
	* gcc.dg/bitint-30.c: New test.
	* gcc.dg/bitint-31.c: New test.
	* gcc.dg/dfp/bitint-1.c (main): Add tests for -1 for signed only,
	-1 + epsilon and -0.
	* gcc.dg/dfp/bitint-2.c (main): Likewise.
	* gcc.dg/dfp/bitint-3.c (main): Likewise.
	* gcc.dg/dfp/bitint-7.c: New test.
	* gcc.dg/dfp/bitint-8.c: New test.

--- gcc/testsuite/gcc.dg/torture/bitint-21.c.jj	2023-09-04 09:45:47.071866931 +0200
+++ gcc/testsuite/gcc.dg/torture/bitint-21.c	2023-09-04 10:15:25.741715123 +0200
@@ -98,91 +98,91 @@ main ()
 #if __FLT_MANT_DIG__ == 24
 #if __BITINT_MAXWIDTH__ >= 135
   static float flt_135[] = {
-    0.25f, 0.0f, 1.0f, -42.0f, 16777215.25f,
+    -1.0f, -0.96875f, -0.5f, -0.0f, 0.25f, 0.0f, 1.0f, -42.0f, 16777215.25f,
     -50855501824.5f, 39580962846540824576.0f,
     -122147759335346835551823516808712814592.0f,
     -85070591730234615865843651857942052864.0f
   };
   static _BitInt(135) fltr_135[] = {
-    0wb, 0wb, 1wb, -42wb, 16777215wb,
+    -1wb, 0wb, 0wb, 0wb, 0wb, 0wb, 1wb, -42wb, 16777215wb,
     -50855501824wb, 39580962846540824576wb,
     -122147759335346835551823516808712814592wb,
     -85070591730234615865843651857942052864wb
   };
-  for (int i = 0; i < 9; ++i)
+  for (int i = 0; i < 13; ++i)
     if (testflt_135 (flt_135[i]) != fltr_135[i])
       __builtin_abort ();
   static float fltu_135[] = {
-    0.125f, 0.0f, 1.0f, 42.59375f, 16777215.75f,
+    -0.9375f, -0.25f, -0.0f, 0.125f, 0.0f, 1.0f, 42.59375f, 16777215.75f,
     397530272.5f, 1557145973265213792232550652968960.0f,
     69722182498815269047577928656018735104.0f
   };
   static unsigned _BitInt(135) fltur_135[] = {
-    0uwb, 0uwb, 1uwb, 42uwb, 16777216uwb,
+    0uwb, 0uwb, 0uwb, 0uwb, 0uwb, 1uwb, 42uwb, 16777216uwb,
     397530272uwb, 1557145973265213792232550652968960uwb,
     69722182498815269047577928656018735104uwb
   };
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 11; ++i)
     if (testfltu_135 (fltu_135[i]) != fltur_135[i])
       __builtin_abort ();
 #endif
 #if __BITINT_MAXWIDTH__ >= 192
   static float flt_192[] = {
-    0.625f, 0.0f, 1.0f, -42.0f, 16777215.25f,
+    -0.984375f, -0.75f, -0.0f, 0.625f, 0.0f, 1.0f, -42.0f, 16777215.25f,
     -166724322197504.5f, 7557890186859550768856301568.0f,
     6614377725485260848635133905887821824.0f,
     -85070591730234615865843651857942052864.0f
   };
   static _BitInt(192) fltr_192[] = {
-    0wb, 0wb, 1wb, -42wb, 16777215wb,
+    0wb, 0wb, 0wb, 0wb, 0wb, 1wb, -42wb, 16777215wb,
     -166724322197504wb, 7557890186859550768856301568wb,
     6614377725485260848635133905887821824wb,
     -85070591730234615865843651857942052864wb
   };
-  for (int i = 0; i < 9; ++i)
+  for (int i = 0; i < 12; ++i)
     if (testflt_192 (flt_192[i]) != fltr_192[i])
       __builtin_abort ();
   static float fltu_192[] = {
-    __FLT_MIN__, 0.0f, 1.0f, 42.125f, 16777216.75f,
-    2197600337920.75f, 4591683053408742366929307227985543168.0f,
+    -0.9921875f, -0.125f, -0.0f, __FLT_MIN__, 0.0f, 1.0f, 42.125f,
+    16777216.75f, 2197600337920.75f, 4591683053408742366929307227985543168.0f,
     89668786387864080590151097276117811200.0f
   };
   static unsigned _BitInt(192) fltur_192[] = {
-    0uwb, 0uwb, 1uwb, 42uwb, 16777216uwb,
+    0uwb, 0uwb, 0uwb, 0uwb, 0uwb, 1uwb, 42uwb, 16777216uwb,
     2197600337920uwb, 4591683053408742366929307227985543168uwb,
     89668786387864080590151097276117811200uwb
   };
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 11; ++i)
     if (testfltu_192 (fltu_192[i]) != fltur_192[i])
       __builtin_abort ();
 #endif
 #if __BITINT_MAXWIDTH__ >= 575
   static float flt_575[] = {
-    0.0001f, 0.0f, 1.0f, -28.0f, 16777214.75f,
+    -0.99609375f, -0.0625f, -0.0f, 0.0001f, 0.0f, 1.0f, -28.0f, 16777214.75f,
     -1321998852554752.5f, 3447217350995641328695097279119360.0f,
     -153684583933125564944797950598195445760.0f,
     -6614377725485260848635133905887821824.0f
   };
   static _BitInt(575) fltr_575[] = {
-    0wb, 0wb, 1wb, -28wb, 16777215wb,
+    0wb, 0wb, 0wb, 0wb, 0wb, 1wb, -28wb, 16777215wb,
     -1321998852554752wb, 3447217350995641328695097279119360wb,
     -153684583933125564944797950598195445760wb,
     -6614377725485260848635133905887821824wb
   };
-  for (int i = 0; i < 9; ++i)
+  for (int i = 0; i < 12; ++i)
     if (testflt_575 (flt_575[i]) != fltr_575[i])
       __builtin_abort ();
   static float fltu_575[] = {
-    4.0f * __FLT_MIN__, 0.0f, 1.0f, 38.125f, 16777210.75f,
-    450604433408.75f, 49420393052787309452540595771398946816.0f,
+    -0.9921875f, -0.125f, -0.0f, 4.0f * __FLT_MIN__, 0.0f, 1.0f, 38.125f,
+    16777210.75f, 450604433408.75f, 49420393052787309452540595771398946816.0f,
     144076816645080570490809349637635309568.0f
   };
   static unsigned _BitInt(575) fltur_575[] = {
-    0uwb, 0uwb, 1uwb, 38uwb, 16777211uwb,
+    0uwb, 0uwb, 0uwb, 0uwb, 0uwb, 1uwb, 38uwb, 16777211uwb,
     450604433408uwb, 49420393052787309452540595771398946816uwb,
     144076816645080570490809349637635309568uwb
   };
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 11; ++i)
     if (testfltu_575 (fltu_575[i]) != fltur_575[i])
       __builtin_abort ();
 #endif
@@ -190,91 +190,91 @@ main ()
 #if __DBL_MANT_DIG__ == 53
 #if __BITINT_MAXWIDTH__ >= 135
   static double dbl_135[] = {
-    0.25, 0.0, 1.0, -42.0, 4294967295.25,
+    -0.998046875, -0.5, -0.0, 0.25, 0.0, 1.0, -42.0, 4294967295.25,
     -600381955574889.5, 31830517255028909053694705664.0,
     -18738990071541038357046558935673124945920.0,
     -21778071482940061661655974875633165533184.0
   };
   static _BitInt(135) dblr_135[] = {
-    0wb, 0wb, 1wb, -42wb, 4294967295wb,
+    0wb, 0wb, 0wb, 0wb, 0wb, 1wb, -42wb, 4294967295wb,
     -600381955574889wb, 31830517255028909053694705664wb,
     -18738990071541038357046558935673124945920wb,
     -21778071482940061661655974875633165533183wb - 1wb
   };
-  for (int i = 0; i < 9; ++i)
+  for (int i = 0; i < 12; ++i)
     if (testdbl_135 (dbl_135[i]) != dblr_135[i])
       __builtin_abort ();
   static double dblu_135[] = {
-    0.125, 0.0, 1.0, 42.59375, 4294967295.75,
+    -0.9990234375, -0.25, -0.0, 0.125, 0.0, 1.0, 42.59375, 4294967295.75,
     1379919377114330.5, 1887176628826898072984354816.0,
     28122698032432725461429202074509590396928.0
   };
   static unsigned _BitInt(135) dblur_135[] = {
-    0uwb, 0uwb, 1uwb, 42uwb, 4294967295uwb,
+    0uwb, 0uwb, 0uwb, 0uwb, 0uwb, 1uwb, 42uwb, 4294967295uwb,
     1379919377114330uwb, 1887176628826898072984354816uwb,
     28122698032432725461429202074509590396928uwb
   };
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 11; ++i)
     if (testdblu_135 (dblu_135[i]) != dblur_135[i])
       __builtin_abort ();
 #endif
 #if __BITINT_MAXWIDTH__ >= 192
   static double dbl_192[] = {
-    0.625, 0.0, 1.0, -42.0, 4294967295.25,
+    -0.99951171875, -0.75, -0.0, 0.625, 0.0, 1.0, -42.0, 4294967295.25,
     -334692618508390720.5, 7241713824636372052614321786924022698463985664.0,
     1051470826442514757151114043324296190023320100185399361536.0,
     -3138550867693340381917894711603833208051177722232017256448.0
   };
   static _BitInt(192) dblr_192[] = {
-    0wb, 0wb, 1wb, -42wb, 4294967295wb,
+    0wb, 0wb, 0wb, 0wb, 0wb, 1wb, -42wb, 4294967295wb,
     -334692618508390720wb, 7241713824636372052614321786924022698463985664wb,
     1051470826442514757151114043324296190023320100185399361536wb,
     -3138550867693340381917894711603833208051177722232017256447wb - 1wb
   };
-  for (int i = 0; i < 9; ++i)
+  for (int i = 0; i < 12; ++i)
     if (testdbl_192 (dbl_192[i]) != dblr_192[i])
       __builtin_abort ();
   static double dblu_192[] = {
-    __DBL_MIN__, 0.0, 1.0, 42.125, 4294967296.75,
+    -0.999755859375, -0.25, -0.0, __DBL_MIN__, 0.0, 1.0, 42.125, 4294967296.75,
     85543274084479312.75, 1452517026416706854711122198528.0,
     4878159368183578289135952951143197426988727705359645409280.0
   };
   static unsigned _BitInt(192) dblur_192[] = {
-    0uwb, 0uwb, 1uwb, 42uwb, 4294967296uwb,
+    0uwb, 0uwb, 0uwb, 0uwb, 0uwb, 1uwb, 42uwb, 4294967296uwb,
     85543274084479312uwb, 1452517026416706854711122198528uwb,
     4878159368183578289135952951143197426988727705359645409280uwb
   };
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 11; ++i)
     if (testdblu_192 (dblu_192[i]) != dblur_192[i])
       __builtin_abort ();
 #endif
 #if __BITINT_MAXWIDTH__ >= 575
   static double dbl_575[] = {
-    0.0001, 0.0, 1.0, -28.0, 4294967294.75,
+    -1.0, -0.9998779296875, -0.125, -0.0, 0.0001, 0.0, 1.0, -28.0, 4294967294.75,
     -37518052491018912.5, 103740344328578397848785318842252129922803939603530145015162908477052192630505472.0,
     -60264112735379285992549557294906950572505306720710356591257742566415478531569283626542380634430345616295459560427283714375540825055746407845009719778430303250931745441185792.0,
     -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174784.0
   };
   static _BitInt(575) dblr_575[] = {
-    0wb, 0wb, 1wb, -28wb, 4294967294wb,
+    -1wb, 0wb, 0wb, 0wb, 0wb, 0wb, 1wb, -28wb, 4294967294wb,
     -37518052491018912wb, 103740344328578397848785318842252129922803939603530145015162908477052192630505472wb,
     -60264112735379285992549557294906950572505306720710356591257742566415478531569283626542380634430345616295459560427283714375540825055746407845009719778430303250931745441185792wb,
     -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb
   };
-  for (int i = 0; i < 9; ++i)
+  for (int i = 0; i < 13; ++i)
     if (testdbl_575 (dbl_575[i]) != dblr_575[i])
       __builtin_abort ();
   static double dblu_575[] = {
-    4.0 * __DBL_MIN__, 0.0, 1.0, 38.125, 4294967297.75,
+    -0.99993896484375, -0.0625, -0.0, 4.0 * __DBL_MIN__, 0.0, 1.0, 38.125, 4294967297.75,
     138240328005104064.75, 1588129215384992270224118343146332410113351482118715170651778867930903010675691494429363974899842924150784.0,
     106390366882040443685518677989907085524608028099417390750037507495093586319031581000179209552004867195248003952212636389496136628539779816025838629984567658036669448510767104.0
   };
   static unsigned _BitInt(575) dblur_575[] = {
-    0uwb, 0uwb, 1uwb, 38uwb, 4294967297uwb,
+    0uwb, 0uwb, 0uwb, 0uwb, 0uwb, 1uwb, 38uwb, 4294967297uwb,
     138240328005104064uwb, 1588129215384992270224118343146332410113351482118715170651778867930903010675691494429363974899842924150784uwb,
     106390366882040443685518677989907085524608028099417390750037507495093586319031581000179209552004867195248003952212636389496136628539779816025838629984567658036669448510767104uwb
   };
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 11; ++i)
     if (testdblu_575 (dblu_575[i]) != dblur_575[i])
       __builtin_abort ();
 #endif
--- gcc/testsuite/gcc.dg/torture/bitint-22.c.jj	2023-09-04 09:45:47.072866916 +0200
+++ gcc/testsuite/gcc.dg/torture/bitint-22.c	2023-09-04 10:36:59.467479044 +0200
@@ -98,91 +98,91 @@ main ()
 #if __LDBL_MANT_DIG__ == 64
 #if __BITINT_MAXWIDTH__ >= 135
   static long double ldbl_135[] = {
-    0.25L, 0.0L, 1.0L, -42.0L, 4294967295.25L,
+    -0.96875L, -0.25L, -0.0L, 0.25L, 0.0L, 1.0L, -42.0L, 4294967295.25L,
     -8790480341948727187.25L, 27274375615880435204096.0L,
     -14925443517338257613013233930892304449536.0L,
     -21778071482940061661655974875633165533184.0L
   };
   static _BitInt(135) ldblr_135[] = {
-    0wb, 0wb, 1wb, -42wb, 4294967295wb,
+    0wb, 0wb, 0wb, 0wb, 0wb, 1wb, -42wb, 4294967295wb,
     -8790480341948727187wb, 27274375615880435204096wb,
     -14925443517338257613013233930892304449536wb,
     -21778071482940061661655974875633165533183wb - 1wb
   };
-  for (int i = 0; i < 9; ++i)
+  for (int i = 0; i < 12; ++i)
     if (testldbl_135 (ldbl_135[i]) != ldblr_135[i])
       __builtin_abort ();
   static long double ldblu_135[] = {
-    0.125L, 0.0L, 1.0L, 42.59375L, 4294967295.75L,
+    -0.9921875L, -0.75L, -0.0L, 0.125L, 0.0L, 1.0L, 42.59375L, 4294967295.75L,
     176563931524327024.5L, 33864941055480177570480471932928.0L,
     25454535165593017203571842988709209178112.0L
   };
   static unsigned _BitInt(135) ldblur_135[] = {
-    0uwb, 0uwb, 1uwb, 42uwb, 4294967295uwb,
+    0uwb, 0uwb, 0uwb, 0uwb, 0uwb, 1uwb, 42uwb, 4294967295uwb,
     176563931524327024uwb, 33864941055480177570480471932928uwb,
     25454535165593017203571842988709209178112uwb
   };
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 11; ++i)
     if (testldblu_135 (ldblu_135[i]) != ldblur_135[i])
       __builtin_abort ();
 #endif
 #if __BITINT_MAXWIDTH__ >= 192
   static long double ldbl_192[] = {
-    0.625L, 0.0L, 1.0L, -42.0L, 4294967295.25L,
+    -1.0L, -0.998046875L, -0.5L, -0.0L, 0.625L, 0.0L, 1.0L, -42.0L, 4294967295.25L,
     -5824742198306330891.5L, 440458331210868742661519441920.0L,
     1835666805014205039814897225189119947560942436848001613824.0L,
     -3138550867693340381917894711603833208051177722232017256448.0L
   };
   static _BitInt(192) ldblr_192[] = {
-    0wb, 0wb, 1wb, -42wb, 4294967295wb,
+    -1wb, 0wb, 0wb, 0wb, 0wb, 0wb, 1wb, -42wb, 4294967295wb,
     -5824742198306330891wb, 440458331210868742661519441920wb,
     1835666805014205039814897225189119947560942436848001613824wb,
     -3138550867693340381917894711603833208051177722232017256447wb - 1wb
   };
-  for (int i = 0; i < 9; ++i)
+  for (int i = 0; i < 13; ++i)
     if (testldbl_192 (ldbl_192[i]) != ldblr_192[i])
       __builtin_abort ();
   static long double ldblu_192[] = {
-    __LDBL_MIN__, 0.0L, 1.0L, 42.125L, 4294967296.75L,
+    -0.99951171875L, -0.125L, -0.0L, __LDBL_MIN__, 0.0L, 1.0L, 42.125L, 4294967296.75L,
     2076918887405157419.75L, 20675944534182826922963677915852149395069559898112.0L,
     5501434424609388038261967254007295028886638351806353113088.0L
   };
   static unsigned _BitInt(192) ldblur_192[] = {
-    0uwb, 0uwb, 1uwb, 42uwb, 4294967296uwb,
+    0uwb, 0uwb, 0uwb, 0uwb, 0uwb, 1uwb, 42uwb, 4294967296uwb,
     2076918887405157419uwb, 20675944534182826922963677915852149395069559898112uwb,
     5501434424609388038261967254007295028886638351806353113088uwb
   };
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 11; ++i)
     if (testldblu_192 (ldblu_192[i]) != ldblur_192[i])
       __builtin_abort ();
 #endif
 #if __BITINT_MAXWIDTH__ >= 575
   static long double ldbl_575[] = {
-    0.0001L, 0.0L, 1.0L, -28.0L, 4294967294.75L,
+    -1.00048828125L, -0.999755859375L, -0.0625L, -0.0L, 0.0001L, 0.0L, 1.0L, -28.0L, 4294967294.75L,
     -3665832965020207456.5L, 163698889538251840454153874702336.0L,
     32915174451748642699300864037265677114762093753017270154115822402734463611341115095984060833654391570465670441530007982951775959694729040694137686724336684263404019031998464.0L,
     -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174784.0L
   };
   static _BitInt(575) ldblr_575[] = {
-    0wb, 0wb, 1wb, -28wb, 4294967294wb,
+    -1wb, 0wb, 0wb, 0wb, 0wb, 0wb, 1wb, -28wb, 4294967294wb,
     -3665832965020207456wb, 163698889538251840454153874702336wb,
     32915174451748642699300864037265677114762093753017270154115822402734463611341115095984060833654391570465670441530007982951775959694729040694137686724336684263404019031998464wb,
     -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb
   };
-  for (int i = 0; i < 9; ++i)
+  for (int i = 0; i < 13; ++i)
     if (testldbl_575 (ldbl_575[i]) != ldblr_575[i])
       __builtin_abort ();
   static long double ldblu_575[] = {
-    4.0L * __LDBL_MIN__, 0.0L, 1.0L, 38.125L, 4294967297.75L,
+    -0.9998779296875L, -0.5L, -0.0L, 4.0L * __LDBL_MIN__, 0.0L, 1.0L, 38.125L, 4294967297.75L,
     1378703406647015633.75L, 611519358004879551476944320883148018860550235384446976.0L,
     115943866857281393364910134541262519802574312323472821552898049002204954780753923929784955305825114286696121504922573067409422635510048274769753298552619702526028834918105088.0L
   };
   static unsigned _BitInt(575) ldblur_575[] = {
-    0uwb, 0uwb, 1uwb, 38uwb, 4294967297uwb,
+    0uwb, 0uwb, 0uwb, 0uwb, 0uwb, 1uwb, 38uwb, 4294967297uwb,
     1378703406647015633uwb, 611519358004879551476944320883148018860550235384446976uwb,
     115943866857281393364910134541262519802574312323472821552898049002204954780753923929784955305825114286696121504922573067409422635510048274769753298552619702526028834918105088uwb
   };
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 11; ++i)
     if (testldblu_575 (ldblu_575[i]) != ldblur_575[i])
       __builtin_abort ();
 #endif
@@ -190,91 +190,93 @@ main ()
 #if __FLT128_MANT_DIG__ == 113
 #if __BITINT_MAXWIDTH__ >= 135
   static _Float128 flt128_135[] = {
-    0.25F128, 0.0F128, 1.0F128, -42.0F128, 4294967295.25F128,
+    -1.0F128, -0.999969482421875F128, -0.5F128, -0.0F128, 0.25F128, 0.0F128,
+    1.0F128, -42.0F128, 4294967295.25F128,
     -622114258022893415468272077014949.5F128, 6846686534183872435237780851340978176.0F128,
     -18109992041001989671440396535501724581888.0F128,
     -21778071482940061661655974875633165533184.0F128
   };
   static _BitInt(135) flt128r_135[] = {
-    0wb, 0wb, 1wb, -42wb, 4294967295wb,
+    -1wb, 0wb, 0wb, 0wb, 0wb, 0wb, 1wb, -42wb, 4294967295wb,
     -622114258022893415468272077014949wb, 6846686534183872435237780851340978176wb,
     -18109992041001989671440396535501724581888wb,
     -21778071482940061661655974875633165533183wb - 1wb
   };
-  for (int i = 0; i < 9; ++i)
+  for (int i = 0; i < 13; ++i)
     if (testflt128_135 (flt128_135[i]) != flt128r_135[i])
       __builtin_abort ();
   static _Float128 flt128u_135[] = {
-    0.125F128, 0.0F128, 1.0F128, 42.59375F128, 4294967295.75F128,
+    -0.9999847412109375F128, -0.25F128, -0.0F128, 0.125F128, 0.0F128, 1.0F128,
+    42.59375F128, 4294967295.75F128,
     3866883549893778868343627501393297.5F128, 1884508847679496004639718578196282112.0F128,
     40418154190724512480670668005754087145472.0F128
   };
   static unsigned _BitInt(135) flt128ur_135[] = {
-    0uwb, 0uwb, 1uwb, 42uwb, 4294967295uwb,
+    0uwb, 0uwb, 0uwb, 0uwb, 0uwb, 1uwb, 42uwb, 4294967295uwb,
     3866883549893778868343627501393297uwb, 1884508847679496004639718578196282112uwb,
     40418154190724512480670668005754087145472uwb
   };
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 11; ++i)
     if (testflt128u_135 (flt128u_135[i]) != flt128ur_135[i])
       __builtin_abort ();
 #endif
 #if __BITINT_MAXWIDTH__ >= 192
   static _Float128 flt128_192[] = {
-    0.625F128, 0.0F128, 1.0F128, -42.0F128, 4294967295.25F128,
+    -0.99999237060546875F128, -0.75F128, -0.0F128, 0.625F128, 0.0F128, 1.0F128, -42.0F128, 4294967295.25F128,
     -2985198467222342042164811285508981.5F128, 431282768955649236431442335280406747022360576.0F128,
     1589969577168452878096502186670522088231011726426596442112.0F128,
     -3138550867693340381917894711603833208051177722232017256448.0F128
   };
   static _BitInt(192) flt128r_192[] = {
-    0wb, 0wb, 1wb, -42wb, 4294967295wb,
+    0wb, 0wb, 0wb, 0wb, 0wb, 1wb, -42wb, 4294967295wb,
     -2985198467222342042164811285508981wb, 431282768955649236431442335280406747022360576wb,
     1589969577168452878096502186670522088231011726426596442112wb,
     -3138550867693340381917894711603833208051177722232017256447wb - 1wb
   };
-  for (int i = 0; i < 9; ++i)
+  for (int i = 0; i < 12; ++i)
     if (testflt128_192 (flt128_192[i]) != flt128r_192[i])
       __builtin_abort ();
   static _Float128 flt128u_192[] = {
-    __FLT128_MIN__, 0.0F128, 1.0F128, 42.125F128, 4294967296.75F128,
+    -0.999996185302734375F128, -0.0625F128, -0.0F128, __FLT128_MIN__, 0.0F128, 1.0F128, 42.125F128, 4294967296.75F128,
     1198221816583045676753413578483973.75F128, 321058543109670204450967161534914741927936.0F128,
     4124250833671183507048495617931376186682553019928355536896.0F128
   };
   static unsigned _BitInt(192) flt128ur_192[] = {
-    0uwb, 0uwb, 1uwb, 42uwb, 4294967296uwb,
+    0uwb, 0uwb, 0uwb, 0uwb, 0uwb, 1uwb, 42uwb, 4294967296uwb,
     1198221816583045676753413578483973uwb, 321058543109670204450967161534914741927936uwb,
     4124250833671183507048495617931376186682553019928355536896uwb
   };
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 11; ++i)
     if (testflt128u_192 (flt128u_192[i]) != flt128ur_192[i])
       __builtin_abort ();
 #endif
 #if __BITINT_MAXWIDTH__ >= 575
   static _Float128 flt128_575[] = {
-    0.0001F128, 0.0F128, 1.0F128, -28.0F128, 4294967294.75F128,
+    -1.0000019073486328125F128, -0.9999980926513671875F128, -0.125F128, -0.0F128, 0.0001F128, 0.0F128, 1.0F128, -28.0F128, 4294967294.75F128,
     -4434536963340205213805292449887836.5F128, 7798956314177801818163892326325236647148010864640.0F128,
     -48379475169482975928082617475070980956970510451882414558095669485086407691242420689411465910847147042640064381848760072045866350077715681395831023828798188292450661613699072.0F128,
     -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174784.0F128
   };
   static _BitInt(575) flt128r_575[] = {
-    0wb, 0wb, 1wb, -28wb, 4294967294wb,
+    -1wb, 0wb, 0wb, 0wb, 0wb, 0wb, 1wb, -28wb, 4294967294wb,
     -4434536963340205213805292449887836wb, 7798956314177801818163892326325236647148010864640wb,
     -48379475169482975928082617475070980956970510451882414558095669485086407691242420689411465910847147042640064381848760072045866350077715681395831023828798188292450661613699072wb,
     -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb
   };
-  for (int i = 0; i < 9; ++i)
+  for (int i = 0; i < 13; ++i)
     if (testflt128_575 (flt128_575[i]) != flt128r_575[i])
       __builtin_abort ();
   static _Float128 flt128u_575[] = {
-    4.0F128 * __FLT128_MIN__, 0.0F128, 1.0F128, 38.125F128, 4294967297.75F128,
+    -0.99999904632568359375F128, -0.75F128, -0.0F128, 4.0F128 * __FLT128_MIN__, 0.0F128, 1.0F128, 38.125F128, 4294967297.75F128,
     1286565442597535616086070715374552.75F128, 2888274376848382435313359223769917404575136171432777745913780227423600640.0F128,
     101012352069182509789055890148950528106809264092697629422634347377509770791198015780931797016594366657511165718215124632216959526129296364564413818230848005073384975475146752.0F128
   };
   static unsigned _BitInt(575) flt128ur_575[] = {
-    0uwb, 0uwb, 1uwb, 38uwb, 4294967297uwb,
+    0uwb, 0uwb, 0uwb, 0uwb, 0uwb, 1uwb, 38uwb, 4294967297uwb,
     1286565442597535616086070715374552uwb, 2888274376848382435313359223769917404575136171432777745913780227423600640uwb,
     101012352069182509789055890148950528106809264092697629422634347377509770791198015780931797016594366657511165718215124632216959526129296364564413818230848005073384975475146752uwb
   };
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 11; ++i)
     if (testflt128u_575 (flt128u_575[i]) != flt128ur_575[i])
       __builtin_abort ();
 #endif
--- gcc/testsuite/gcc.dg/bitint-28.c.jj	2023-09-04 12:52:07.607635862 +0200
+++ gcc/testsuite/gcc.dg/bitint-28.c	2023-09-04 14:44:43.240152428 +0200
@@ -0,0 +1,401 @@
+/* PR c/102989 */
+/* { dg-do run } */
+/* { dg-require-effective-target fenv_exceptions } */
+/* { dg-options "-std=c2x" } */
+/* { dg-add-options ieee } */
+
+#include <fenv.h>
+
+#if __FLT_MANT_DIG__ == 24
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) _BitInt(135)
+testflt_135 (float d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(135)
+testfltu_135 (float d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) _BitInt(192)
+testflt_192 (float d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(192)
+testfltu_192 (float d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) _BitInt(575)
+testflt_575 (float d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(575)
+testfltu_575 (float d)
+{
+  return d;
+}
+#endif
+#endif
+
+#if __DBL_MANT_DIG__ == 53
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) _BitInt(135)
+testdbl_135 (double d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(135)
+testdblu_135 (double d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) _BitInt(192)
+testdbl_192 (double d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(192)
+testdblu_192 (double d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) _BitInt(575)
+testdbl_575 (double d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(575)
+testdblu_575 (double d)
+{
+  return d;
+}
+#endif
+#endif
+
+#if __LDBL_MANT_DIG__ == 64
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) _BitInt(135)
+testldbl_135 (long double d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(135)
+testldblu_135 (long double d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) _BitInt(192)
+testldbl_192 (long double d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(192)
+testldblu_192 (long double d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) _BitInt(575)
+testldbl_575 (long double d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(575)
+testldblu_575 (long double d)
+{
+  return d;
+}
+#endif
+#endif
+
+#if __FLT128_MANT_DIG__ == 113
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) _BitInt(135)
+testflt128_135 (_Float128 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(135)
+testflt128u_135 (_Float128 d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) _BitInt(192)
+testflt128_192 (_Float128 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(192)
+testflt128u_192 (_Float128 d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) _BitInt(575)
+testflt128_575 (_Float128 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(575)
+testflt128u_575 (_Float128 d)
+{
+  return d;
+}
+#endif
+#endif
+
+__attribute__((noipa)) void
+check_invalid (int test, int inv)
+{
+  if (!test)
+    __builtin_abort ();
+  if ((!fetestexcept (FE_INVALID)) != (!inv))
+    __builtin_abort ();
+  feclearexcept (FE_INVALID);
+}
+
+int
+main ()
+{
+#if __FLT_MANT_DIG__ == 24
+#if __BITINT_MAXWIDTH__ >= 135
+  check_invalid (testflt_135 (-85070591730234615865843651857942052864.0f) == -85070591730234615865843651857942052864wb, 0);
+  check_invalid (testflt_135 (__builtin_inff ()) == 21778071482940061661655974875633165533183wb, 1);
+  check_invalid (testflt_135 (-__builtin_inff ()) == -21778071482940061661655974875633165533183wb - 1wb, 1);
+  check_invalid (testflt_135 (__builtin_nanf ("")) == 21778071482940061661655974875633165533183wb, 1);
+  check_invalid (testflt_135 (0xffffffp+104f) == 340282346638528859811704183484516925440wb, 0);
+  check_invalid (testflt_135 (-0xffffffp+104f) == -340282346638528859811704183484516925440wb, 0);
+  check_invalid (testfltu_135 (-0.9990234375f) == 0uwb, 0);
+  check_invalid (testfltu_135 (-1.f) == 0uwb, 1);
+  check_invalid (testfltu_135 (__builtin_inff ()) == 43556142965880123323311949751266331066367uwb, 1);
+  check_invalid (testfltu_135 (-__builtin_inff ()) == 0uwb, 1);
+  check_invalid (testfltu_135 (__builtin_nanf ("")) == 43556142965880123323311949751266331066367uwb, 1);
+  check_invalid (testfltu_135 (0xffffffp+104f) == 340282346638528859811704183484516925440uwb, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_invalid (testflt_192 (-85070591730234615865843651857942052864.0f) == -85070591730234615865843651857942052864wb, 0);
+  check_invalid (testflt_192 (__builtin_inff ()) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (testflt_192 (-__builtin_inff ()) == -3138550867693340381917894711603833208051177722232017256447wb - 1wb, 1);
+  check_invalid (testflt_192 (__builtin_nanf ("")) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (testflt_192 (0xffffffp+104f) == 340282346638528859811704183484516925440wb, 0);
+  check_invalid (testflt_192 (-0xffffffp+104f) == -340282346638528859811704183484516925440wb, 0);
+  check_invalid (testfltu_192 (-0.9990234375f) == 0uwb, 0);
+  check_invalid (testfltu_192 (-1.f) == 0uwb, 1);
+  check_invalid (testfltu_192 (__builtin_inff ()) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (testfltu_192 (-__builtin_inff ()) == 0uwb, 1);
+  check_invalid (testfltu_192 (__builtin_nanf ("")) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (testfltu_192 (0xffffffp+104f) == 340282346638528859811704183484516925440uwb, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_invalid (testflt_575 (-85070591730234615865843651857942052864.0f) == -85070591730234615865843651857942052864wb, 0);
+  check_invalid (testflt_575 (__builtin_inff ()) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (testflt_575 (-__builtin_inff ()) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb, 1);
+  check_invalid (testflt_575 (__builtin_nanf ("")) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (testflt_575 (0xffffffp+104f) == 340282346638528859811704183484516925440wb, 0);
+  check_invalid (testflt_575 (-0xffffffp+104f) == -340282346638528859811704183484516925440wb, 0);
+  check_invalid (testfltu_575 (-0.9990234375f) == 0uwb, 0);
+  check_invalid (testfltu_575 (-1.f) == 0uwb, 1);
+  check_invalid (testfltu_575 (__builtin_inff ()) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (testfltu_575 (-__builtin_inff ()) == 0uwb, 1);
+  check_invalid (testfltu_575 (__builtin_nanf ("")) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (testfltu_575 (0xffffffp+104f) == 340282346638528859811704183484516925440uwb, 0);
+#endif
+#endif
+#if __DBL_MANT_DIG__ == 53
+#if __BITINT_MAXWIDTH__ >= 135
+  check_invalid (testdbl_135 (-85070591730234615865843651857942052864.0) == -85070591730234615865843651857942052864wb, 0);
+  check_invalid (testdbl_135 (__builtin_inf ()) == 21778071482940061661655974875633165533183wb, 1);
+  check_invalid (testdbl_135 (-__builtin_inf ()) == -21778071482940061661655974875633165533183wb - 1wb, 1);
+  check_invalid (testdbl_135 (__builtin_nan ("")) == 21778071482940061661655974875633165533183wb, 1);
+  check_invalid (testdbl_135 (0x1fffffffffffffp+81) == 21778071482940059243804335646374816120832wb, 0);
+  check_invalid (testdbl_135 (0x20000000000000p+81) == 21778071482940061661655974875633165533183wb, 1);
+  check_invalid (testdbl_135 (-0x20000000000000p+81) == -21778071482940061661655974875633165533183wb - 1, 0);
+  check_invalid (testdbl_135 (-0x20000000000002p+81) == -21778071482940061661655974875633165533183wb - 1, 1);
+  check_invalid (testdblu_135 (-0.9990234375) == 0uwb, 0);
+  check_invalid (testdblu_135 (-1.) == 0uwb, 1);
+  check_invalid (testdblu_135 (__builtin_inf ()) == 43556142965880123323311949751266331066367uwb, 1);
+  check_invalid (testdblu_135 (-__builtin_inf ()) == 0uwb, 1);
+  check_invalid (testdblu_135 (__builtin_nan ("")) == 43556142965880123323311949751266331066367uwb, 1);
+  check_invalid (testdblu_135 (0x1fffffffffffffp+82) == 43556142965880118487608671292749632241664uwb, 0);
+  check_invalid (testdblu_135 (0x20000000000000p+82) == 43556142965880123323311949751266331066367uwb, 1);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_invalid (testdbl_192 (-85070591730234615865843651857942052864.0) == -85070591730234615865843651857942052864wb, 0);
+  check_invalid (testdbl_192 (__builtin_inf ()) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (testdbl_192 (-__builtin_inf ()) == -3138550867693340381917894711603833208051177722232017256447wb - 1wb, 1);
+  check_invalid (testdbl_192 (__builtin_nan ("")) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (testdbl_192 (0x1fffffffffffffp+138) == 3138550867693340033468750984562846621555579712101368725504wb, 0);
+  check_invalid (testdbl_192 (0x20000000000000p+138) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (testdbl_192 (-0x20000000000000p+138) == -3138550867693340381917894711603833208051177722232017256447wb - 1, 0);
+  check_invalid (testdbl_192 (-0x20000000000002p+138) == -3138550867693340381917894711603833208051177722232017256447wb - 1, 1);
+  check_invalid (testdblu_192 (-0.9990234375) == 0uwb, 0);
+  check_invalid (testdblu_192 (-1.) == 0uwb, 1);
+  check_invalid (testdblu_192 (__builtin_inf ()) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (testdblu_192 (-__builtin_inf ()) == 0uwb, 1);
+  check_invalid (testdblu_192 (__builtin_nan ("")) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (testdblu_192 (0x1fffffffffffffp+139) == 6277101735386680066937501969125693243111159424202737451008uwb, 0);
+  check_invalid (testdblu_192 (0x20000000000000p+139) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_invalid (testdbl_575 (-85070591730234615865843651857942052864.0) == -85070591730234615865843651857942052864wb, 0);
+  check_invalid (testdbl_575 (__builtin_inf ()) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (testdbl_575 (-__builtin_inf ()) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb, 1);
+  check_invalid (testdbl_575 (__builtin_nan ("")) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (testdbl_575 (0x1fffffffffffffp+521) == 61832600368276126650327970124302082526882038193909742709080463879918896882169507607035916867654709124839777195049479857541529867095829765369898539058829479405123401922117632wb, 0);
+  check_invalid (testdbl_575 (0x20000000000000p+521) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (testdbl_575 (-0x20000000000000p+521) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, 0);
+  check_invalid (testdbl_575 (-0x20000000000002p+521) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, 1);
+  check_invalid (testdblu_575 (-0.9990234375) == 0uwb, 0);
+  check_invalid (testdblu_575 (-1.) == 0uwb, 1);
+  check_invalid (testdblu_575 (__builtin_inf ()) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (testdblu_575 (-__builtin_inf ()) == 0uwb, 1);
+  check_invalid (testdblu_575 (__builtin_nan ("")) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (testdblu_575 (0x1fffffffffffffp+522) == 123665200736552253300655940248604165053764076387819485418160927759837793764339015214071833735309418249679554390098959715083059734191659530739797078117658958810246803844235264uwb, 0);
+  check_invalid (testdblu_575 (0x20000000000000p+522) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+#endif
+#endif
+#if __LDBL_MANT_DIG__ == 64
+#if __BITINT_MAXWIDTH__ >= 135
+  check_invalid (testldbl_135 (-85070591730234615865843651857942052864.0L) == -85070591730234615865843651857942052864wb, 0);
+  check_invalid (testldbl_135 (__builtin_infl ()) == 21778071482940061661655974875633165533183wb, 1);
+  check_invalid (testldbl_135 (-__builtin_infl ()) == -21778071482940061661655974875633165533183wb - 1wb, 1);
+  check_invalid (testldbl_135 (__builtin_nanl ("")) == 21778071482940061661655974875633165533183wb, 1);
+  check_invalid (testldbl_135 (0xffffffffffffffffp+70L) == 21778071482940061660475383254915754229760wb, 0);
+  check_invalid (testldbl_135 (0x10000000000000000p+70L) == 21778071482940061661655974875633165533183wb, 1);
+  check_invalid (testldbl_135 (-0x10000000000000000p+70L) == -21778071482940061661655974875633165533183wb - 1, 0);
+  check_invalid (testldbl_135 (-0x10000000000000002p+70L) == -21778071482940061661655974875633165533183wb - 1, 1);
+  check_invalid (testldblu_135 (-0.9990234375L) == 0uwb, 0);
+  check_invalid (testldblu_135 (-1.L) == 0uwb, 1);
+  check_invalid (testldblu_135 (__builtin_infl ()) == 43556142965880123323311949751266331066367uwb, 1);
+  check_invalid (testldblu_135 (-__builtin_infl ()) == 0uwb, 1);
+  check_invalid (testldblu_135 (__builtin_nanl ("")) == 43556142965880123323311949751266331066367uwb, 1);
+  check_invalid (testldblu_135 (0xffffffffffffffffp+71L) == 43556142965880123320950766509831508459520uwb, 0);
+  check_invalid (testldblu_135 (0x10000000000000000p+71L) == 43556142965880123323311949751266331066367uwb, 1);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_invalid (testldbl_192 (-85070591730234615865843651857942052864.0L) == -85070591730234615865843651857942052864wb, 0);
+  check_invalid (testldbl_192 (__builtin_infl ()) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (testldbl_192 (-__builtin_infl ()) == -3138550867693340381917894711603833208051177722232017256447wb - 1wb, 1);
+  check_invalid (testldbl_192 (__builtin_nanl ("")) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (testldbl_192 (0xffffffffffffffffp+127L) == 3138550867693340381747753528143363976319490418516133150720wb, 0);
+  check_invalid (testldbl_192 (0x10000000000000000p+127L) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (testldbl_192 (-0x10000000000000000p+127L) == -3138550867693340381917894711603833208051177722232017256447wb - 1, 0);
+  check_invalid (testldbl_192 (-0x10000000000000002p+127L) == -3138550867693340381917894711603833208051177722232017256447wb - 1, 1);
+  check_invalid (testldblu_192 (-0.9990234375L) == 0uwb, 0);
+  check_invalid (testldblu_192 (-1.L) == 0uwb, 1);
+  check_invalid (testldblu_192 (__builtin_infl ()) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (testldblu_192 (-__builtin_infl ()) == 0uwb, 1);
+  check_invalid (testldblu_192 (__builtin_nanl ("")) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (testldblu_192 (0xffffffffffffffffp+128L) == 6277101735386680763495507056286727952638980837032266301440uwb, 0);
+  check_invalid (testldblu_192 (0x10000000000000000p+128L) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_invalid (testldbl_575 (-85070591730234615865843651857942052864.0L) == -85070591730234615865843651857942052864wb, 0);
+  check_invalid (testldbl_575 (__builtin_infl ()) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (testldbl_575 (-__builtin_infl ()) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb, 1);
+  check_invalid (testldbl_575 (__builtin_nanl ("")) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (testldbl_575 (0xffffffffffffffffp+510L) == 61832600368276133511773678272426148233889331025751498446645922568076207932202076431648659257792374503198949281962308977915333294030066289778448068072486649492543280785653760wb, 0);
+  check_invalid (testldbl_575 (0x10000000000000000p+510L) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (testldbl_575 (-0x10000000000000000p+510L) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, 0);
+  check_invalid (testldbl_575 (-0x10000000000000002p+510L) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, 1);
+  check_invalid (testldblu_575 (-0.9990234375L) == 0uwb, 0);
+  check_invalid (testldblu_575 (-1.L) == 0uwb, 1);
+  check_invalid (testldblu_575 (__builtin_infl ()) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (testldblu_575 (-__builtin_infl ()) == 0uwb, 1);
+  check_invalid (testldblu_575 (__builtin_nanl ("")) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (testldblu_575 (0xffffffffffffffffp+511L) == 123665200736552267023547356544852296467778662051502996893291845136152415864404152863297318515584749006397898563924617955830666588060132579556896136144973298985086561571307520uwb, 0);
+  check_invalid (testldblu_575 (0x10000000000000000p+511L) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+#endif
+#endif
+#if __FLT128_MANT_DIG__ == 113
+#if __BITINT_MAXWIDTH__ >= 135
+  check_invalid (testflt128_135 (-85070591730234615865843651857942052864.0F128) == -85070591730234615865843651857942052864wb, 0);
+  check_invalid (testflt128_135 (__builtin_inff128 ()) == 21778071482940061661655974875633165533183wb, 1);
+  check_invalid (testflt128_135 (-__builtin_inff128 ()) == -21778071482940061661655974875633165533183wb - 1wb, 1);
+  check_invalid (testflt128_135 (__builtin_nanf128 ("")) == 21778071482940061661655974875633165533183wb, 1);
+  check_invalid (testflt128_135 (0x1ffffffffffffffffffffffffffffp+21F128) == 21778071482940061661655974875633163436032wb, 0);
+  check_invalid (testflt128_135 (0x20000000000000000000000000000p+21F128) == 21778071482940061661655974875633165533183wb, 1);
+  check_invalid (testflt128_135 (-0x20000000000000000000000000000p+21F128) == -21778071482940061661655974875633165533183wb - 1, 0);
+  check_invalid (testflt128_135 (-0x20000000000000000000000000002p+21F128) == -21778071482940061661655974875633165533183wb - 1, 1);
+  check_invalid (testflt128u_135 (-0.9990234375F128) == 0uwb, 0);
+  check_invalid (testflt128u_135 (-1.F128) == 0uwb, 1);
+  check_invalid (testflt128u_135 (__builtin_inff128 ()) == 43556142965880123323311949751266331066367uwb, 1);
+  check_invalid (testflt128u_135 (-__builtin_inff128 ()) == 0uwb, 1);
+  check_invalid (testflt128u_135 (__builtin_nanf128 ("")) == 43556142965880123323311949751266331066367uwb, 1);
+  check_invalid (testflt128u_135 (0x1ffffffffffffffffffffffffffffp+22F128) == 43556142965880123323311949751266326872064uwb, 0);
+  check_invalid (testflt128u_135 (0x20000000000000000000000000000p+22F128) == 43556142965880123323311949751266331066367uwb, 1);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_invalid (testflt128_192 (-85070591730234615865843651857942052864.0F128) == -85070591730234615865843651857942052864wb, 0);
+  check_invalid (testflt128_192 (__builtin_inff128 ()) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (testflt128_192 (-__builtin_inff128 ()) == -3138550867693340381917894711603833208051177722232017256447wb - 1wb, 1);
+  check_invalid (testflt128_192 (__builtin_nanf128 ("")) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (testflt128_192 (0x1ffffffffffffffffffffffffffffp+78F128) == 3138550867693340381917894711603832905819722818574723579904wb, 0);
+  check_invalid (testflt128_192 (0x20000000000000000000000000000p+78F128) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (testflt128_192 (-0x20000000000000000000000000000p+78F128) == -3138550867693340381917894711603833208051177722232017256447wb - 1, 0);
+  check_invalid (testflt128_192 (-0x20000000000000000000000000002p+78F128) == -3138550867693340381917894711603833208051177722232017256447wb - 1, 1);
+  check_invalid (testflt128u_192 (-0.9990234375F128) == 0uwb, 0);
+  check_invalid (testflt128u_192 (-1.F128) == 0uwb, 1);
+  check_invalid (testflt128u_192 (__builtin_inff128 ()) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (testflt128u_192 (-__builtin_inff128 ()) == 0uwb, 1);
+  check_invalid (testflt128u_192 (__builtin_nanf128 ("")) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (testflt128u_192 (0x1ffffffffffffffffffffffffffffp+79F128) == 6277101735386680763835789423207665811639445637149447159808uwb, 0);
+  check_invalid (testflt128u_192 (0x20000000000000000000000000000p+79F128) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_invalid (testflt128_575 (-85070591730234615865843651857942052864.0F128) == -85070591730234615865843651857942052864wb, 0);
+  check_invalid (testflt128_575 (__builtin_inff128 ()) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (testflt128_575 (-__builtin_inff128 ()) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb, 1);
+  check_invalid (testflt128_575 (__builtin_nanf128 ("")) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (testflt128_575 (0x1ffffffffffffffffffffffffffffp+461F128) == 61832600368276133515125630254911791554520007845691312598455129804691160851602940042069550439343049559602369631548246946680753811425558728725309540242943660463695151425912832wb, 0);
+  check_invalid (testflt128_575 (0x20000000000000000000000000000p+461F128) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (testflt128_575 (-0x20000000000000000000000000000p+461F128) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, 0);
+  check_invalid (testflt128_575 (-0x20000000000000000000000000002p+461F128) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, 1);
+  check_invalid (testflt128u_575 (-0.9990234375F128) == 0uwb, 0);
+  check_invalid (testflt128u_575 (-1.F128) == 0uwb, 1);
+  check_invalid (testflt128u_575 (__builtin_inff128 ()) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (testflt128u_575 (-__builtin_inff128 ()) == 0uwb, 1);
+  check_invalid (testflt128u_575 (__builtin_nanf128 ("")) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (testflt128u_575 (0x1ffffffffffffffffffffffffffffp+462F128) == 123665200736552267030251260509823583109040015691382625196910259609382321703205880084139100878686099119204739263096493893361507622851117457450619080485887320927390302851825664uwb, 0);
+  check_invalid (testflt128u_575 (0x20000000000000000000000000000p+462F128) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+#endif
+#endif
+}
--- gcc/testsuite/gcc.dg/bitint-29.c.jj	2023-09-04 14:54:08.440333215 +0200
+++ gcc/testsuite/gcc.dg/bitint-29.c	2023-09-04 15:33:55.882523605 +0200
@@ -0,0 +1,351 @@
+/* PR c/102989 */
+/* { dg-do run } */
+/* { dg-require-effective-target fenv_exceptions } */
+/* { dg-options "-std=c2x" } */
+/* { dg-add-options ieee } */
+
+#include <fenv.h>
+
+#if __FLT_MANT_DIG__ == 24
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) _BitInt(135)
+testflt_135 (float d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(135)
+testfltu_135 (float d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) _BitInt(192)
+testflt_192 (float d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(192)
+testfltu_192 (float d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) _BitInt(575)
+testflt_575 (float d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(575)
+testfltu_575 (float d)
+{
+  return d;
+}
+#endif
+#endif
+
+#if __DBL_MANT_DIG__ == 53
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) _BitInt(135)
+testdbl_135 (double d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(135)
+testdblu_135 (double d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) _BitInt(192)
+testdbl_192 (double d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(192)
+testdblu_192 (double d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) _BitInt(575)
+testdbl_575 (double d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(575)
+testdblu_575 (double d)
+{
+  return d;
+}
+#endif
+#endif
+
+#if __LDBL_MANT_DIG__ == 64
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) _BitInt(135)
+testldbl_135 (long double d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(135)
+testldblu_135 (long double d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) _BitInt(192)
+testldbl_192 (long double d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(192)
+testldblu_192 (long double d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) _BitInt(575)
+testldbl_575 (long double d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(575)
+testldblu_575 (long double d)
+{
+  return d;
+}
+#endif
+#endif
+
+#if __FLT128_MANT_DIG__ == 113
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) _BitInt(135)
+testflt128_135 (_Float128 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(135)
+testflt128u_135 (_Float128 d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) _BitInt(192)
+testflt128_192 (_Float128 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(192)
+testflt128u_192 (_Float128 d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) _BitInt(575)
+testflt128_575 (_Float128 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(575)
+testflt128u_575 (_Float128 d)
+{
+  return d;
+}
+#endif
+#endif
+
+__attribute__((noipa)) void
+check_inexact (int test, int inex)
+{
+  if (!test)
+    __builtin_abort ();
+  if ((!fetestexcept (FE_INEXACT)) != (!inex))
+    __builtin_abort ();
+  feclearexcept (FE_INEXACT);
+}
+
+int
+main ()
+{
+#if __FLT_MANT_DIG__ == 24
+#if __BITINT_MAXWIDTH__ >= 135
+  check_inexact (testflt_135 (-85070591730234615865843651857942052864.0f) == -85070591730234615865843651857942052864wb, 0);
+  check_inexact (testflt_135 (0xffffffp+104f) == 340282346638528859811704183484516925440wb, 0);
+  check_inexact (testflt_135 (-0xffffffp+104f) == -340282346638528859811704183484516925440wb, 0);
+  check_inexact (testflt_135 (-0xffffffp-1f) == -8388607wb, 1);
+  check_inexact (testflt_135 (-0.f) == 0wb, 0);
+  check_inexact (testflt_135 (-0.f) == 0wb, 0);
+  check_inexact (testflt_135 (-0.9990234375f) == 0wb, 1);
+  check_inexact (testfltu_135 (0.f) == 0uwb, 0);
+  check_inexact (testfltu_135 (-0.9990234375f) == 0uwb, 1);
+  check_inexact (testfltu_135 (0xffffffp-1f) == 8388607uwb, 1);
+  check_inexact (testfltu_135 (0xffffffp+104f) == 340282346638528859811704183484516925440uwb, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_inexact (testflt_192 (-85070591730234615865843651857942052864.0f) == -85070591730234615865843651857942052864wb, 0);
+  check_inexact (testflt_192 (0xffffffp+104f) == 340282346638528859811704183484516925440wb, 0);
+  check_inexact (testflt_192 (-0xffffffp+104f) == -340282346638528859811704183484516925440wb, 0);
+  check_inexact (testflt_192 (-0xffffffp-3f) == -2097151wb, 1);
+  check_inexact (testflt_192 (-0.f) == 0wb, 0);
+  check_inexact (testflt_192 (-0.9990234375f) == 0wb, 1);
+  check_inexact (testfltu_192 (0.f) == 0uwb, 0);
+  check_inexact (testfltu_192 (-0.9990234375f) == 0uwb, 1);
+  check_inexact (testfltu_192 (0xffffffp-3f) == 2097151uwb, 1);
+  check_inexact (testfltu_192 (0xffffffp+104f) == 340282346638528859811704183484516925440uwb, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_inexact (testflt_575 (-85070591730234615865843651857942052864.0f) == -85070591730234615865843651857942052864wb, 0);
+  check_inexact (testflt_575 (0xffffffp+104f) == 340282346638528859811704183484516925440wb, 0);
+  check_inexact (testflt_575 (-0xffffffp+104f) == -340282346638528859811704183484516925440wb, 0);
+  check_inexact (testflt_575 (-0xffffffp-5f) == -524287wb, 1);
+  check_inexact (testflt_575 (0.f) == 0wb, 0);
+  check_inexact (testflt_575 (-0.9990234375f) == 0wb, 1);
+  check_inexact (testfltu_575 (-0.f) == 0uwb, 0);
+  check_inexact (testfltu_575 (-0.9990234375f) == 0uwb, 1);
+  check_inexact (testfltu_575 (0xffffffp-5f) == 524287uwb, 1);
+  check_inexact (testfltu_575 (0xffffffp+104f) == 340282346638528859811704183484516925440uwb, 0);
+#endif
+#endif
+#if __DBL_MANT_DIG__ == 53
+#if __BITINT_MAXWIDTH__ >= 135
+  check_inexact (testdbl_135 (-85070591730234615865843651857942052864.0) == -85070591730234615865843651857942052864wb, 0);
+  check_inexact (testdbl_135 (0x1fffffffffffffp+81) == 21778071482940059243804335646374816120832wb, 0);
+  check_inexact (testdbl_135 (-0x20000000000000p+81) == -21778071482940061661655974875633165533183wb - 1, 0);
+  check_inexact (testdbl_135 (-0x1fffffffffffffp-1) == -4503599627370495wb, 1);
+  check_inexact (testdbl_135 (-0.) == 0wb, 0);
+  check_inexact (testdbl_135 (-0.9990234375) == 0wb, 1);
+  check_inexact (testdblu_135 (0.) == 0uwb, 0);
+  check_inexact (testdblu_135 (-0.9990234375) == 0uwb, 1);
+  check_inexact (testdblu_135 (0x1fffffffffffffp-1) == 4503599627370495uwb, 1);
+  check_inexact (testdblu_135 (0x1fffffffffffffp+82) == 43556142965880118487608671292749632241664uwb, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_inexact (testdbl_192 (-85070591730234615865843651857942052864.0) == -85070591730234615865843651857942052864wb, 0);
+  check_inexact (testdbl_192 (0x1fffffffffffffp+138) == 3138550867693340033468750984562846621555579712101368725504wb, 0);
+  check_inexact (testdbl_192 (-0x20000000000000p+138) == -3138550867693340381917894711603833208051177722232017256447wb - 1, 0);
+  check_inexact (testdbl_192 (-0x1fffffffffffffp-3) == -1125899906842623wb, 1);
+  check_inexact (testdbl_192 (0.) == 0wb, 0);
+  check_inexact (testdbl_192 (-0.9990234375) == 0wb, 1);
+  check_inexact (testdblu_192 (-0.) == 0uwb, 0);
+  check_inexact (testdblu_192 (-0.9990234375) == 0uwb, 1);
+  check_inexact (testdblu_192 (0x1fffffffffffffp-3) == 1125899906842623uwb, 1);
+  check_inexact (testdblu_192 (0x1fffffffffffffp+139) == 6277101735386680066937501969125693243111159424202737451008uwb, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_inexact (testdbl_575 (-85070591730234615865843651857942052864.0) == -85070591730234615865843651857942052864wb, 0);
+  check_inexact (testdbl_575 (0x1fffffffffffffp+521) == 61832600368276126650327970124302082526882038193909742709080463879918896882169507607035916867654709124839777195049479857541529867095829765369898539058829479405123401922117632wb, 0);
+  check_inexact (testdbl_575 (-0x20000000000000p+521) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, 0);
+  check_inexact (testdbl_575 (-0x1fffffffffffffp-5) == -281474976710655wb, 1);
+  check_inexact (testdbl_575 (-0.) == 0wb, 0);
+  check_inexact (testdbl_575 (-0.9990234375) == 0wb, 1);
+  check_inexact (testdblu_575 (0.) == 0uwb, 0);
+  check_inexact (testdblu_575 (-0.9990234375) == 0uwb, 1);
+  check_inexact (testdblu_575 (0x1fffffffffffffp-5) == 281474976710655uwb, 1);
+  check_inexact (testdblu_575 (0x1fffffffffffffp+522) == 123665200736552253300655940248604165053764076387819485418160927759837793764339015214071833735309418249679554390098959715083059734191659530739797078117658958810246803844235264uwb, 0);
+#endif
+#endif
+#if __LDBL_MANT_DIG__ == 64
+#if __BITINT_MAXWIDTH__ >= 135
+  check_inexact (testldbl_135 (-85070591730234615865843651857942052864.0L) == -85070591730234615865843651857942052864wb, 0);
+  check_inexact (testldbl_135 (0xffffffffffffffffp+70L) == 21778071482940061660475383254915754229760wb, 0);
+  check_inexact (testldbl_135 (-0x10000000000000000p+70L) == -21778071482940061661655974875633165533183wb - 1, 0);
+  check_inexact (testldbl_135 (-0xffffffffffffffffp-1L) == -9223372036854775807wb, 1);
+  check_inexact (testldbl_135 (-0.L) == 0wb, 0);
+  check_inexact (testldbl_135 (-0.9990234375L) == 0wb, 1);
+  check_inexact (testldblu_135 (0.L) == 0uwb, 0);
+  check_inexact (testldblu_135 (-0.9990234375L) == 0uwb, 1);
+  check_inexact (testldblu_135 (0xffffffffffffffffp-1L) == 9223372036854775807uwb, 1);
+  check_inexact (testldblu_135 (0xffffffffffffffffp+71L) == 43556142965880123320950766509831508459520uwb, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_inexact (testldbl_192 (-85070591730234615865843651857942052864.0L) == -85070591730234615865843651857942052864wb, 0);
+  check_inexact (testldbl_192 (0xffffffffffffffffp+127L) == 3138550867693340381747753528143363976319490418516133150720wb, 0);
+  check_inexact (testldbl_192 (-0x10000000000000000p+127L) == -3138550867693340381917894711603833208051177722232017256447wb - 1, 0);
+  check_inexact (testldbl_192 (-0xffffffffffffffffp-2L) == -4611686018427387903wb, 1);
+  check_inexact (testldbl_192 (0.L) == 0wb, 0);
+  check_inexact (testldbl_192 (-0.9990234375L) == 0wb, 1);
+  check_inexact (testldblu_192 (-0.L) == 0uwb, 0);
+  check_inexact (testldblu_192 (-0.9990234375L) == 0uwb, 1);
+  check_inexact (testldblu_192 (0xffffffffffffffffp-2L) == 4611686018427387903uwb, 1);
+  check_inexact (testldblu_192 (0xffffffffffffffffp+128L) == 6277101735386680763495507056286727952638980837032266301440uwb, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_inexact (testldbl_575 (-85070591730234615865843651857942052864.0L) == -85070591730234615865843651857942052864wb, 0);
+  check_inexact (testldbl_575 (0xffffffffffffffffp+510L) == 61832600368276133511773678272426148233889331025751498446645922568076207932202076431648659257792374503198949281962308977915333294030066289778448068072486649492543280785653760wb, 0);
+  check_inexact (testldbl_575 (-0x10000000000000000p+510L) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, 0);
+  check_inexact (testldbl_575 (-0xffffffffffffffffp-4L) == -1152921504606846975wb, 1);
+  check_inexact (testldbl_575 (0.L) == 0wb, 0);
+  check_inexact (testldbl_575 (-0.9990234375L) == 0wb, 1);
+  check_inexact (testldblu_575 (-0.L) == 0uwb, 0);
+  check_inexact (testldblu_575 (-0.9990234375L) == 0uwb, 1);
+  check_inexact (testldblu_575 (0xffffffffffffffffp-4L) == 1152921504606846975uwb, 1);
+  check_inexact (testldblu_575 (0xffffffffffffffffp+511L) == 123665200736552267023547356544852296467778662051502996893291845136152415864404152863297318515584749006397898563924617955830666588060132579556896136144973298985086561571307520uwb, 0);
+#endif
+#endif
+#if __FLT128_MANT_DIG__ == 113
+#if __BITINT_MAXWIDTH__ >= 135
+  check_inexact (testflt128_135 (-85070591730234615865843651857942052864.0F128) == -85070591730234615865843651857942052864wb, 0);
+  check_inexact (testflt128_135 (0x1ffffffffffffffffffffffffffffp+21F128) == 21778071482940061661655974875633163436032wb, 0);
+  check_inexact (testflt128_135 (-0x20000000000000000000000000000p+21F128) == -21778071482940061661655974875633165533183wb - 1, 0);
+  check_inexact (testflt128_135 (-0x1ffffffffffffffffffffffffffffp-1F128) == -5192296858534827628530496329220095wb, 1);
+  check_inexact (testflt128_135 (-0.F128) == 0wb, 0);
+  check_inexact (testflt128_135 (-0.9990234375F128) == 0wb, 1);
+  check_inexact (testflt128u_135 (0.F128) == 0uwb, 0);
+  check_inexact (testflt128u_135 (-0.9990234375F128) == 0uwb, 1);
+  check_inexact (testflt128u_135 (0x1ffffffffffffffffffffffffffffp-1F128) == 5192296858534827628530496329220095uwb, 1);
+  check_inexact (testflt128u_135 (0x1ffffffffffffffffffffffffffffp+22F128) == 43556142965880123323311949751266326872064uwb, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_inexact (testflt128_192 (-85070591730234615865843651857942052864.0F128) == -85070591730234615865843651857942052864wb, 0);
+  check_inexact (testflt128_192 (0x1ffffffffffffffffffffffffffffp+78F128) == 3138550867693340381917894711603832905819722818574723579904wb, 0);
+  check_inexact (testflt128_192 (-0x20000000000000000000000000000p+78F128) == -3138550867693340381917894711603833208051177722232017256447wb - 1, 0);
+  check_inexact (testflt128_192 (-0x1ffffffffffffffffffffffffffffp-4F128) == -649037107316853453566312041152511wb, 1);
+  check_inexact (testflt128_192 (-0.F128) == 0wb, 0);
+  check_inexact (testflt128_192 (-0.9990234375F128) == 0wb, 1);
+  check_inexact (testflt128u_192 (0.F128) == 0uwb, 0);
+  check_inexact (testflt128u_192 (-0.9990234375F128) == 0uwb, 1);
+  check_inexact (testflt128u_192 (0x1ffffffffffffffffffffffffffffp-4F128) == 649037107316853453566312041152511uwb, 1);
+  check_inexact (testflt128u_192 (0x1ffffffffffffffffffffffffffffp+79F128) == 6277101735386680763835789423207665811639445637149447159808uwb, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_inexact (testflt128_575 (-85070591730234615865843651857942052864.0F128) == -85070591730234615865843651857942052864wb, 0);
+  check_inexact (testflt128_575 (0x1ffffffffffffffffffffffffffffp+461F128) == 61832600368276133515125630254911791554520007845691312598455129804691160851602940042069550439343049559602369631548246946680753811425558728725309540242943660463695151425912832wb, 0);
+  check_inexact (testflt128_575 (-0x20000000000000000000000000000p+461F128) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, 0);
+  check_inexact (testflt128_575 (-0x1ffffffffffffffffffffffffffffp-8F128) == -40564819207303340847894502572031wb, 1);
+  check_inexact (testflt128_575 (0.F128) == 0wb, 0);
+  check_inexact (testflt128_575 (-0.9990234375F128) == 0wb, 1);
+  check_inexact (testflt128u_575 (-0.F128) == 0uwb, 0);
+  check_inexact (testflt128u_575 (-0.9990234375F128) == 0uwb, 1);
+  check_inexact (testflt128u_575 (0x1ffffffffffffffffffffffffffffp-8F128) == 40564819207303340847894502572031uwb, 1);
+  check_inexact (testflt128u_575 (0x1ffffffffffffffffffffffffffffp+462F128) == 123665200736552267030251260509823583109040015691382625196910259609382321703205880084139100878686099119204739263096493893361507622851117457450619080485887320927390302851825664uwb, 0);
+#endif
+#endif
+}
--- gcc/testsuite/gcc.dg/bitint-30.c.jj	2023-09-04 16:57:40.503703479 +0200
+++ gcc/testsuite/gcc.dg/bitint-30.c	2023-09-04 19:21:32.680004331 +0200
@@ -0,0 +1,470 @@
+/* PR c/102989 */
+/* { dg-do run } */
+/* { dg-require-effective-target fenv_exceptions } */
+/* { dg-options "-std=c2x" } */
+/* { dg-add-options ieee } */
+
+#include <fenv.h>
+
+#if __FLT_MANT_DIG__ == 24
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) float
+testflt_135 (_BitInt(135) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) float
+testfltu_135 (unsigned _BitInt(135) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) float
+testflt_192 (_BitInt(192) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) float
+testfltu_192 (unsigned _BitInt(192) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) float
+testflt_575 (_BitInt(575) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) float
+testfltu_575 (unsigned _BitInt(575) b)
+{
+  return b;
+}
+#endif
+#endif
+
+#if __DBL_MANT_DIG__ == 53
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) double
+testdbl_135 (_BitInt(135) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) double
+testdblu_135 (unsigned _BitInt(135) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) double
+testdbl_192 (_BitInt(192) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) double
+testdblu_192 (unsigned _BitInt(192) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) double
+testdbl_575 (_BitInt(575) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) double
+testdblu_575 (unsigned _BitInt(575) b)
+{
+  return b;
+}
+#endif
+#endif
+
+#if __LDBL_MANT_DIG__ == 64
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) long double
+testldbl_135 (_BitInt(135) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) long double
+testldblu_135 (unsigned _BitInt(135) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) long double
+testldbl_192 (_BitInt(192) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) long double
+testldblu_192 (unsigned _BitInt(192) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) long double
+testldbl_575 (_BitInt(575) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) long double
+testldblu_575 (unsigned _BitInt(575) b)
+{
+  return b;
+}
+#endif
+#endif
+
+#if __FLT128_MANT_DIG__ == 113
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) _Float128
+testflt128_135 (_BitInt(135) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) _Float128
+testflt128u_135 (unsigned _BitInt(135) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) _Float128
+testflt128_192 (_BitInt(192) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) _Float128
+testflt128u_192 (unsigned _BitInt(192) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) _Float128
+testflt128_575 (_BitInt(575) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) _Float128
+testflt128u_575 (unsigned _BitInt(575) b)
+{
+  return b;
+}
+#endif
+#endif
+
+__attribute__((noipa)) void
+check_except (int test, int inex, int ovf)
+{
+  if (!test)
+    __builtin_abort ();
+  if ((!fetestexcept (FE_INEXACT)) != (!inex))
+    __builtin_abort ();
+  if ((!fetestexcept (FE_OVERFLOW)) != (!ovf))
+    __builtin_abort ();
+  feclearexcept (FE_INEXACT | FE_OVERFLOW);
+}
+
+int
+main ()
+{
+#if __FLT_MANT_DIG__ == 24
+#if __BITINT_MAXWIDTH__ >= 135
+  check_except (testflt_135 (151115713941029764726783wb) == 0xfffffep+53f, 1, 0);
+  check_except (testflt_135 (151115713941029764726784wb) == 0xfffffep+53f, 1, 0);
+  check_except (testflt_135 (151115713941029764726785wb) == 0xffffffp+53f, 1, 0);
+  check_except (testflt_135 (151115718444629392097280wb) == 0xffffffp+53f, 0, 0);
+  check_except (testflt_135 (151115722948229019467775wb) == 0xffffffp+53f, 1, 0);
+  check_except (testflt_135 (151115722948229019467776wb) == 0x1000000p+53f, 1, 0);
+  check_except (testflt_135 (151115722948229019467777wb) == 0x1000000p+53f, 1, 0);
+  check_except (testflt_135 (-340282346638528859811704183484516925440wb) == -0xffffffp+104f, 0, 0);
+  check_except (testflt_135 (-340282356779733661637539395458142568447wb) == -0xffffffp+104f, 1, 0);
+  check_except (testflt_135 (-340282356779733661637539395458142568448wb) == -__builtin_inff (), 1, 1);
+  check_except (testflt_135 (-21778071482940061661655974875633165533183wb - 1) == -__builtin_inff (), 1, 1);
+  check_except (testfltu_135 (151115713941029764726783uwb) == 0xfffffep+53f, 1, 0);
+  check_except (testfltu_135 (151115713941029764726784uwb) == 0xfffffep+53f, 1, 0);
+  check_except (testfltu_135 (151115713941029764726785uwb) == 0xffffffp+53f, 1, 0);
+  check_except (testfltu_135 (151115718444629392097280uwb) == 0xffffffp+53f, 0, 0);
+  check_except (testfltu_135 (151115722948229019467775uwb) == 0xffffffp+53f, 1, 0);
+  check_except (testfltu_135 (151115722948229019467776uwb) == 0x1000000p+53f, 1, 0);
+  check_except (testfltu_135 (151115722948229019467777uwb) == 0x1000000p+53f, 1, 0);
+  check_except (testfltu_135 (340282346638528859811704183484516925440uwb) == 0xffffffp+104f, 0, 0);
+  check_except (testfltu_135 (340282356779733661637539395458142568447uwb) == 0xffffffp+104f, 1, 0);
+  check_except (testfltu_135 (340282356779733661637539395458142568448uwb) == __builtin_inff (), 1, 1);
+  check_except (testfltu_135 (43556142965880123323311949751266331066367uwb) == __builtin_inff (), 1, 1);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_except (testflt_192 (-10141203895131470501001744613375wb) == -0xfffffep+79f, 1, 0);
+  check_except (testflt_192 (-10141203895131470501001744613376wb) == -0xfffffep+79f, 1, 0);
+  check_except (testflt_192 (-10141203895131470501001744613377wb) == -0xffffffp+79f, 1, 0);
+  check_except (testflt_192 (-10141204197362925404659038289920wb) == -0xffffffp+79f, 0, 0);
+  check_except (testflt_192 (-10141204499594380308316331966463wb) == -0xffffffp+79f, 1, 0);
+  check_except (testflt_192 (-10141204499594380308316331966464wb) == -0x1000000p+79f, 1, 0);
+  check_except (testflt_192 (-10141204499594380308316331966465wb) == -0x1000000p+79f, 1, 0);
+  check_except (testflt_192 (340282346638528859811704183484516925440wb) == 0xffffffp+104f, 0, 0);
+  check_except (testflt_192 (340282356779733661637539395458142568447wb) == 0xffffffp+104f, 1, 0);
+  check_except (testflt_192 (340282356779733661637539395458142568448wb) == __builtin_inff (), 1, 1);
+  check_except (testflt_192 (3138550867693340381917894711603833208051177722232017256447wb) == __builtin_inff (), 1, 1);
+  check_except (testfltu_192 (10141203895131470501001744613375uwb) == 0xfffffep+79f, 1, 0);
+  check_except (testfltu_192 (10141203895131470501001744613376uwb) == 0xfffffep+79f, 1, 0);
+  check_except (testfltu_192 (10141203895131470501001744613377uwb) == 0xffffffp+79f, 1, 0);
+  check_except (testfltu_192 (10141204197362925404659038289920uwb) == 0xffffffp+79f, 0, 0);
+  check_except (testfltu_192 (10141204499594380308316331966463uwb) == 0xffffffp+79f, 1, 0);
+  check_except (testfltu_192 (10141204499594380308316331966464uwb) == 0x1000000p+79f, 1, 0);
+  check_except (testfltu_192 (10141204499594380308316331966465uwb) == 0x1000000p+79f, 1, 0);
+  check_except (testfltu_192 (340282346638528859811704183484516925440uwb) == 0xffffffp+104f, 0, 0);
+  check_except (testfltu_192 (340282356779733661637539395458142568447uwb) == 0xffffffp+104f, 1, 0);
+  check_except (testfltu_192 (340282356779733661637539395458142568448uwb) == __builtin_inff (), 1, 1);
+  check_except (testfltu_192 (6277101735386680763835789423207666416102355444464034512895uwb) == __builtin_inff (), 1, 1);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_except (testflt_575 (10633823015541376812058405359715352575wb) == 0xfffffep+99f, 1, 0);
+  check_except (testflt_575 (10633823015541376812058405359715352576wb) == 0xfffffep+99f, 1, 0);
+  check_except (testflt_575 (10633823015541376812058405359715352577wb) == 0xffffffp+99f, 1, 0);
+  check_except (testflt_575 (10633823332454026869115755733891153920wb) == 0xffffffp+99f, 0, 0);
+  check_except (testflt_575 (10633823649366676926173106108066955263wb) == 0xffffffp+99f, 1, 0);
+  check_except (testflt_575 (10633823649366676926173106108066955264wb) == 0x1000000p+99f, 1, 0);
+  check_except (testflt_575 (10633823649366676926173106108066955265wb) == 0x1000000p+99f, 1, 0);
+  check_except (testflt_575 (-340282346638528859811704183484516925440wb) == -0xffffffp+104f, 0, 0);
+  check_except (testflt_575 (-340282356779733661637539395458142568447wb) == -0xffffffp+104f, 1, 0);
+  check_except (testflt_575 (-340282356779733661637539395458142568448wb) == -__builtin_inff (), 1, 1);
+  check_except (testflt_575 (-61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1) == -__builtin_inff (), 1, 1);
+  check_except (testfltu_575 (10633823015541376812058405359715352575uwb) == 0xfffffep+99f, 1, 0);
+  check_except (testfltu_575 (10633823015541376812058405359715352576uwb) == 0xfffffep+99f, 1, 0);
+  check_except (testfltu_575 (10633823015541376812058405359715352577uwb) == 0xffffffp+99f, 1, 0);
+  check_except (testfltu_575 (10633823332454026869115755733891153920uwb) == 0xffffffp+99f, 0, 0);
+  check_except (testfltu_575 (10633823649366676926173106108066955263uwb) == 0xffffffp+99f, 1, 0);
+  check_except (testfltu_575 (10633823649366676926173106108066955264uwb) == 0x1000000p+99f, 1, 0);
+  check_except (testfltu_575 (10633823649366676926173106108066955265uwb) == 0x1000000p+99f, 1, 0);
+  check_except (testfltu_575 (340282346638528859811704183484516925440uwb) == 0xffffffp+104f, 0, 0);
+  check_except (testfltu_575 (340282356779733661637539395458142568447uwb) == 0xffffffp+104f, 1, 0);
+  check_except (testfltu_575 (340282356779733661637539395458142568448uwb) == __builtin_inff (), 1, 1);
+  check_except (testfltu_575 (123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb) == __builtin_inff (), 1, 1);
+#endif
+#endif
+#if __DBL_MANT_DIG__ == 53
+#if __BITINT_MAXWIDTH__ >= 135
+  check_except (testdbl_135 (-21267647932558650424686050812251602943wb) == -0x1ffffffffffffep+71, 1, 0);
+  check_except (testdbl_135 (-21267647932558650424686050812251602944wb) == -0x1ffffffffffffep+71, 1, 0);
+  check_except (testdbl_135 (-21267647932558650424686050812251602945wb) == -0x1fffffffffffffp+71, 1, 0);
+  check_except (testdbl_135 (-21267647932558651605277671529662906368wb) == -0x1fffffffffffffp+71, 0, 0);
+  check_except (testdbl_135 (-21267647932558652785869292247074209791wb) == -0x1fffffffffffffp+71, 1, 0);
+  check_except (testdbl_135 (-21267647932558652785869292247074209792wb) == -0x20000000000000p+71, 1, 0);
+  check_except (testdbl_135 (-21267647932558652785869292247074209793wb) == -0x20000000000000p+71, 1, 0);
+  check_except (testdbl_135 (21778071482940059243804335646374816120832wb) == 0x1fffffffffffffp+81, 0, 0);
+  check_except (testdbl_135 (21778071482940060452730155261003990827007wb) == 0x1fffffffffffffp+81, 1, 0);
+  check_except (testdbl_135 (21778071482940060452730155261003990827008wb) == 0x20000000000000p+81, 1, 0);
+  check_except (testdbl_135 (21778071482940060452730155261003990827009wb) == 0x20000000000000p+81, 1, 0);
+  check_except (testdbl_135 (21778071482940061661655974875633165533183wb) == 0x20000000000000p+81, 1, 0);
+  check_except (testdblu_135 (21267647932558650424686050812251602943uwb) == 0x1ffffffffffffep+71, 1, 0);
+  check_except (testdblu_135 (21267647932558650424686050812251602944uwb) == 0x1ffffffffffffep+71, 1, 0);
+  check_except (testdblu_135 (21267647932558650424686050812251602945uwb) == 0x1fffffffffffffp+71, 1, 0);
+  check_except (testdblu_135 (21267647932558651605277671529662906368uwb) == 0x1fffffffffffffp+71, 0, 0);
+  check_except (testdblu_135 (21267647932558652785869292247074209791uwb) == 0x1fffffffffffffp+71, 1, 0);
+  check_except (testdblu_135 (21267647932558652785869292247074209792uwb) == 0x20000000000000p+71, 1, 0);
+  check_except (testdblu_135 (21267647932558652785869292247074209793uwb) == 0x20000000000000p+71, 1, 0);
+  check_except (testdblu_135 (43556142965880118487608671292749632241664uwb) == 0x1fffffffffffffp+82, 0, 0);
+  check_except (testdblu_135 (43556142965880120905460310522007981654015uwb) == 0x1fffffffffffffp+82, 1, 0);
+  check_except (testdblu_135 (43556142965880120905460310522007981654016uwb) == 0x20000000000000p+82, 1, 0);
+  check_except (testdblu_135 (43556142965880120905460310522007981654017uwb) == 0x20000000000000p+82, 1, 0);
+  check_except (testdblu_135 (43556142965880123323311949751266331066367uwb) == 0x20000000000000p+82, 1, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_except (testdbl_192 (89202980794122477710862401666030147234430975wb) == 0x1ffffffffffffep+93, 1, 0);
+  check_except (testdbl_192 (89202980794122477710862401666030147234430976wb) == 0x1ffffffffffffep+93, 1, 0);
+  check_except (testdbl_192 (89202980794122477710862401666030147234430977wb) == 0x1fffffffffffffp+93, 1, 0);
+  check_except (testdbl_192 (89202980794122482662622558807551246830927872wb) == 0x1fffffffffffffp+93, 0, 0);
+  check_except (testdbl_192 (89202980794122487614382715949072346427424767wb) == 0x1fffffffffffffp+93, 1, 0);
+  check_except (testdbl_192 (89202980794122487614382715949072346427424768wb) == 0x20000000000000p+93, 1, 0);
+  check_except (testdbl_192 (89202980794122487614382715949072346427424769wb) == 0x20000000000000p+93, 1, 0);
+  check_except (testdbl_192 (-3138550867693340033468750984562846621555579712101368725504wb) == -0x1fffffffffffffp+138, 0, 0);
+  check_except (testdbl_192 (-3138550867693340207693322848083339914803378717166692990975wb) == -0x1fffffffffffffp+138, 1, 0);
+  check_except (testdbl_192 (-3138550867693340207693322848083339914803378717166692990976wb) == -0x20000000000000p+138, 1, 0);
+  check_except (testdbl_192 (-3138550867693340207693322848083339914803378717166692990977wb) == -0x20000000000000p+138, 1, 0);
+  check_except (testdbl_192 (-3138550867693340381917894711603833208051177722232017256447wb - 1) == -0x20000000000000p+138, 0, 0);
+  check_except (testdblu_192 (89202980794122477710862401666030147234430975uwb) == 0x1ffffffffffffep+93, 1, 0);
+  check_except (testdblu_192 (89202980794122477710862401666030147234430976uwb) == 0x1ffffffffffffep+93, 1, 0);
+  check_except (testdblu_192 (89202980794122477710862401666030147234430977uwb) == 0x1fffffffffffffp+93, 1, 0);
+  check_except (testdblu_192 (89202980794122482662622558807551246830927872uwb) == 0x1fffffffffffffp+93, 0, 0);
+  check_except (testdblu_192 (89202980794122487614382715949072346427424767uwb) == 0x1fffffffffffffp+93, 1, 0);
+  check_except (testdblu_192 (89202980794122487614382715949072346427424768uwb) == 0x20000000000000p+93, 1, 0);
+  check_except (testdblu_192 (89202980794122487614382715949072346427424769uwb) == 0x20000000000000p+93, 1, 0);
+  check_except (testdblu_192 (6277101735386680066937501969125693243111159424202737451008uwb) == 0x1fffffffffffffp+139, 0, 0);
+  check_except (testdblu_192 (6277101735386680415386645696166679829606757434333385981951uwb) == 0x1fffffffffffffp+139, 1, 0);
+  check_except (testdblu_192 (6277101735386680415386645696166679829606757434333385981952uwb) == 0x20000000000000p+139, 1, 0);
+  check_except (testdblu_192 (6277101735386680415386645696166679829606757434333385981953uwb) == 0x20000000000000p+139, 1, 0);
+  check_except (testdblu_192 (6277101735386680763835789423207666416102355444464034512895uwb) == 0x20000000000000p+139, 1, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_except (testdbl_575 (-615656346818663635164482277361060010743329029962521103256875011322006445221646740336801072761830405785423389392895wb) == -0x1ffffffffffffep+325, 1, 0);
+  check_except (testdbl_575 (-615656346818663635164482277361060010743329029962521103256875011322006445221646740336801072761830405785423389392896wb) == -0x1ffffffffffffep+325, 1, 0);
+  check_except (testdbl_575 (-615656346818663635164482277361060010743329029962521103256875011322006445221646740336801072761830405785423389392897wb) == -0x1fffffffffffffp+325, 1, 0);
+  check_except (testdbl_575 (-615656346818663669340274852095621329063676328675354936900147369028450764374312465492316685252079206152816780378112wb) == -0x1fffffffffffffp+325, 0, 0);
+  check_except (testdbl_575 (-615656346818663703516067426830182647384023627388188770543419726734895083526978190647832297742328006520210171363327wb) == -0x1fffffffffffffp+325, 1, 0);
+  check_except (testdbl_575 (-615656346818663703516067426830182647384023627388188770543419726734895083526978190647832297742328006520210171363328wb) == -0x20000000000000p+325, 1, 0);
+  check_except (testdbl_575 (-615656346818663703516067426830182647384023627388188770543419726734895083526978190647832297742328006520210171363329wb) == -0x20000000000000p+325, 1, 0);
+  check_except (testdbl_575 (61832600368276126650327970124302082526882038193909742709080463879918896882169507607035916867654709124839777195049479857541529867095829765369898539058829479405123401922117632wb) == 0x1fffffffffffffp+521, 0, 0);
+  check_except (testdbl_575 (61832600368276130082726800189606940017832437734606351343798113951571601579401237199807508566482735186119597525776757346189685562836258783930892538917151385692137547479646207wb) == 0x1fffffffffffffp+521, 1, 0);
+  check_except (testdbl_575 (61832600368276130082726800189606940017832437734606351343798113951571601579401237199807508566482735186119597525776757346189685562836258783930892538917151385692137547479646208wb) == 0x20000000000000p+521, 1, 0);
+  check_except (testdbl_575 (61832600368276130082726800189606940017832437734606351343798113951571601579401237199807508566482735186119597525776757346189685562836258783930892538917151385692137547479646209wb) == 0x20000000000000p+521, 1, 0);
+  check_except (testdbl_575 (61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb) == 0x20000000000000p+521, 1, 0);
+  check_except (testdblu_575 (615656346818663635164482277361060010743329029962521103256875011322006445221646740336801072761830405785423389392895uwb) == 0x1ffffffffffffep+325, 1, 0);
+  check_except (testdblu_575 (615656346818663635164482277361060010743329029962521103256875011322006445221646740336801072761830405785423389392896uwb) == 0x1ffffffffffffep+325, 1, 0);
+  check_except (testdblu_575 (615656346818663635164482277361060010743329029962521103256875011322006445221646740336801072761830405785423389392897uwb) == 0x1fffffffffffffp+325, 1, 0);
+  check_except (testdblu_575 (615656346818663669340274852095621329063676328675354936900147369028450764374312465492316685252079206152816780378112uwb) == 0x1fffffffffffffp+325, 0, 0);
+  check_except (testdblu_575 (615656346818663703516067426830182647384023627388188770543419726734895083526978190647832297742328006520210171363327uwb) == 0x1fffffffffffffp+325, 1, 0);
+  check_except (testdblu_575 (615656346818663703516067426830182647384023627388188770543419726734895083526978190647832297742328006520210171363328uwb) == 0x20000000000000p+325, 1, 0);
+  check_except (testdblu_575 (615656346818663703516067426830182647384023627388188770543419726734895083526978190647832297742328006520210171363329uwb) == 0x20000000000000p+325, 1, 0);
+  check_except (testdblu_575 (123665200736552253300655940248604165053764076387819485418160927759837793764339015214071833735309418249679554390098959715083059734191659530739797078117658958810246803844235264uwb) == 0x1fffffffffffffp+522, 0, 0);
+  check_except (testdblu_575 (123665200736552260165453600379213880035664875469212702687596227903143203158802474399615017132965470372239195051553514692379371125672517567861785077834302771384275094959292415uwb) == 0x1fffffffffffffp+522, 1, 0);
+  check_except (testdblu_575 (123665200736552260165453600379213880035664875469212702687596227903143203158802474399615017132965470372239195051553514692379371125672517567861785077834302771384275094959292416uwb) == 0x20000000000000p+522, 1, 0);
+  check_except (testdblu_575 (123665200736552260165453600379213880035664875469212702687596227903143203158802474399615017132965470372239195051553514692379371125672517567861785077834302771384275094959292417uwb) == 0x20000000000000p+522, 1, 0);
+  check_except (testdblu_575 (123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb) == 0x20000000000000p+522, 1, 0);
+#endif
+#endif
+#if __LDBL_MANT_DIG__ == 64
+#if __BITINT_MAXWIDTH__ >= 135
+  check_except (testldbl_135 (-27577662721237071616947187835994111wb) == -0xa9f5e144d113e1c4p+51L, 1, 0);
+  check_except (testldbl_135 (-27577662721237071616947187835994112wb) == -0xa9f5e144d113e1c4p+51L, 1, 0);
+  check_except (testldbl_135 (-27577662721237071616947187835994113wb) == -0xa9f5e144d113e1c5p+51L, 1, 0);
+  check_except (testldbl_135 (-27577662721237071618073087742836736wb) == -0xa9f5e144d113e1c5p+51L, 0, 0);
+  check_except (testldbl_135 (-27577662721237071619198987649679359wb) == -0xa9f5e144d113e1c5p+51L, 1, 0);
+  check_except (testldbl_135 (-27577662721237071619198987649679360wb) == -0xa9f5e144d113e1c6p+51L, 1, 0);
+  check_except (testldbl_135 (-27577662721237071619198987649679361wb) == -0xa9f5e144d113e1c6p+51L, 1, 0);
+  check_except (testldbl_135 (-21778071482940061660475383254915754229760wb) == -0xffffffffffffffffp+70L, 0, 0);
+  check_except (testldbl_135 (-21778071482940061661065679065274459881471wb) == -0xffffffffffffffffp+70L, 1, 0);
+  check_except (testldbl_135 (-21778071482940061661065679065274459881472wb) == -0x10000000000000000p+70L, 1, 0);
+  check_except (testldbl_135 (-21778071482940061661065679065274459881473wb) == -0x10000000000000000p+70L, 1, 0);
+  check_except (testldbl_135 (-21778071482940061661655974875633165533183wb - 1) == -0x10000000000000000p+70L, 0, 0);
+  check_except (testldblu_135 (27577662721237071616947187835994111uwb) == 0xa9f5e144d113e1c4p+51L, 1, 0);
+  check_except (testldblu_135 (27577662721237071616947187835994112uwb) == 0xa9f5e144d113e1c4p+51L, 1, 0);
+  check_except (testldblu_135 (27577662721237071616947187835994113uwb) == 0xa9f5e144d113e1c5p+51L, 1, 0);
+  check_except (testldblu_135 (27577662721237071618073087742836736uwb) == 0xa9f5e144d113e1c5p+51L, 0, 0);
+  check_except (testldblu_135 (27577662721237071619198987649679359uwb) == 0xa9f5e144d113e1c5p+51L, 1, 0);
+  check_except (testldblu_135 (27577662721237071619198987649679360uwb) == 0xa9f5e144d113e1c6p+51L, 1, 0);
+  check_except (testldblu_135 (27577662721237071619198987649679361uwb) == 0xa9f5e144d113e1c6p+51L, 1, 0);
+  check_except (testldblu_135 (43556142965880123320950766509831508459520uwb) == 0xffffffffffffffffp+71L, 0, 0);
+  check_except (testldblu_135 (43556142965880123322131358130548919762943uwb) == 0xffffffffffffffffp+71L, 1, 0);
+  check_except (testldblu_135 (43556142965880123322131358130548919762944uwb) == 0x10000000000000000p+71L, 1, 0);
+  check_except (testldblu_135 (43556142965880123322131358130548919762945uwb) == 0x10000000000000000p+71L, 1, 0);
+  check_except (testldblu_135 (43556142965880123323311949751266331066367uwb) == 0x10000000000000000p+71L, 1, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_except (testldbl_192 (96388802158769743653878219701497927252918090596351wb) == 0x83e75ebf94ce024ep+103L, 1, 0);
+  check_except (testldbl_192 (96388802158769743653878219701497927252918090596352wb) == 0x83e75ebf94ce024ep+103L, 1, 0);
+  check_except (testldbl_192 (96388802158769743653878219701497927252918090596353wb) == 0x83e75ebf94ce024fp+103L, 1, 0);
+  check_except (testldbl_192 (96388802158769743658948822102410844858904903417856wb) == 0x83e75ebf94ce024fp+103L, 0, 0);
+  check_except (testldbl_192 (96388802158769743664019424503323762464891716239359wb) == 0x83e75ebf94ce024fp+103L, 1, 0);
+  check_except (testldbl_192 (96388802158769743664019424503323762464891716239360wb) == 0x83e75ebf94ce0250p+103L, 1, 0);
+  check_except (testldbl_192 (96388802158769743664019424503323762464891716239361wb) == 0x83e75ebf94ce0250p+103L, 1, 0);
+  check_except (testldbl_192 (-3138550867693340381747753528143363976319490418516133150720wb) == -0xffffffffffffffffp+127L, 0, 0);
+  check_except (testldbl_192 (-3138550867693340381832824119873598592185334070374075203583wb) == -0xffffffffffffffffp+127L, 1, 0);
+  check_except (testldbl_192 (-3138550867693340381832824119873598592185334070374075203584wb) == -0x10000000000000000p+127L, 1, 0);
+  check_except (testldbl_192 (-3138550867693340381832824119873598592185334070374075203585wb) == -0x10000000000000000p+127L, 1, 0);
+  check_except (testldbl_192 (-3138550867693340381917894711603833208051177722232017256447wb - 1wb) == -0x10000000000000000p+127L, 0, 0);
+  check_except (testldblu_192 (96388802158769743653878219701497927252918090596351uwb) == 0x83e75ebf94ce024ep+103L, 1, 0);
+  check_except (testldblu_192 (96388802158769743653878219701497927252918090596352uwb) == 0x83e75ebf94ce024ep+103L, 1, 0);
+  check_except (testldblu_192 (96388802158769743653878219701497927252918090596353uwb) == 0x83e75ebf94ce024fp+103L, 1, 0);
+  check_except (testldblu_192 (96388802158769743658948822102410844858904903417856uwb) == 0x83e75ebf94ce024fp+103L, 0, 0);
+  check_except (testldblu_192 (96388802158769743664019424503323762464891716239359uwb) == 0x83e75ebf94ce024fp+103L, 1, 0);
+  check_except (testldblu_192 (96388802158769743664019424503323762464891716239360uwb) == 0x83e75ebf94ce0250p+103L, 1, 0);
+  check_except (testldblu_192 (96388802158769743664019424503323762464891716239361uwb) == 0x83e75ebf94ce0250p+103L, 1, 0);
+  check_except (testldblu_192 (6277101735386680763495507056286727952638980837032266301440uwb) == 0xffffffffffffffffp+128L, 0, 0);
+  check_except (testldblu_192 (6277101735386680763665648239747197184370668140748150407167uwb) == 0xffffffffffffffffp+128L, 1, 0);
+  check_except (testldblu_192 (6277101735386680763665648239747197184370668140748150407168uwb) == 0x10000000000000000p+128L, 1, 0);
+  check_except (testldblu_192 (6277101735386680763665648239747197184370668140748150407169uwb) == 0x10000000000000000p+128L, 1, 0);
+  check_except (testldblu_192 (6277101735386680763835789423207666416102355444464034512895uwb) == 0x10000000000000000p+128L, 1, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_except (testldbl_575 (-61832600368276133511773678272426148233889331025751498446645922568076207932202076431648659257792374503198949281962308977915333294030066289778448068072486649492543280785653760wb) == -0xffffffffffffffffp+510L, 0, 0);
+  check_except (testldbl_575 (-61832600368276133513449654263668972871336084150527229212580843295650257104417521612113879761551567875299183569233171906376587276303377046135167303423979970735847486911414271wb) == -0xffffffffffffffffp+510L, 1, 0);
+  check_except (testldbl_575 (-61832600368276133513449654263668972871336084150527229212580843295650257104417521612113879761551567875299183569233171906376587276303377046135167303423979970735847486911414272wb) == -0x10000000000000000p+510L, 1, 0);
+  check_except (testldbl_575 (-61832600368276133513449654263668972871336084150527229212580843295650257104417521612113879761551567875299183569233171906376587276303377046135167303423979970735847486911414273wb) == -0x10000000000000000p+510L, 1, 0);
+  check_except (testldbl_575 (-61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1) == -0x10000000000000000p+510L, 0, 0);
+  check_except (testldblu_575 (123665200736552267023547356544852296467778662051502996893291845136152415864404152863297318515584749006397898563924617955830666588060132579556896136144973298985086561571307520uwb) == 0xffffffffffffffffp+511L, 0, 0);
+  check_except (testldblu_575 (123665200736552267026899308527337945742672168301054458425161686591300514208835043224227759523103135750598367138466343812753174552606754092270334606847959941471694973822828543uwb) == 0xffffffffffffffffp+511L, 1, 0);
+  check_except (testldblu_575 (123665200736552267026899308527337945742672168301054458425161686591300514208835043224227759523103135750598367138466343812753174552606754092270334606847959941471694973822828544uwb) == 0x10000000000000000p+511L, 1, 0);
+  check_except (testldblu_575 (123665200736552267026899308527337945742672168301054458425161686591300514208835043224227759523103135750598367138466343812753174552606754092270334606847959941471694973822828545uwb) == 0x10000000000000000p+511L, 1, 0);
+  check_except (testldblu_575 (123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb) == 0x10000000000000000p+511L, 1, 0);
+#endif
+#endif
+#if __FLT128_MANT_DIG__ == 113
+#if __BITINT_MAXWIDTH__ >= 135
+  check_except (testflt128_135 (-21646332438261169091754659013488783917055wb) == -0x1fce71fdcfb1797b42dede66ac9ecp+21F128, 1, 0);
+  check_except (testflt128_135 (-21646332438261169091754659013488783917056wb) == -0x1fce71fdcfb1797b42dede66ac9ecp+21F128, 1, 0);
+  check_except (testflt128_135 (-21646332438261169091754659013488783917057wb) == -0x1fce71fdcfb1797b42dede66ac9edp+21F128, 1, 0);
+  check_except (testflt128_135 (-21646332438261169091754659013488784965632wb) == -0x1fce71fdcfb1797b42dede66ac9edp+21F128, 0, 0);
+  check_except (testflt128_135 (-21646332438261169091754659013488786014207wb) == -0x1fce71fdcfb1797b42dede66ac9edp+21F128, 1, 0);
+  check_except (testflt128_135 (-21646332438261169091754659013488786014208wb) == -0x1fce71fdcfb1797b42dede66ac9eep+21F128, 1, 0);
+  check_except (testflt128_135 (-21646332438261169091754659013488786014209wb) == -0x1fce71fdcfb1797b42dede66ac9eep+21F128, 1, 0);
+  check_except (testflt128u_135 (21646332438261169091754659013488783917055uwb) == 0x1fce71fdcfb1797b42dede66ac9ecp+21F128, 1, 0);
+  check_except (testflt128u_135 (21646332438261169091754659013488783917056uwb) == 0x1fce71fdcfb1797b42dede66ac9ecp+21F128, 1, 0);
+  check_except (testflt128u_135 (21646332438261169091754659013488783917057uwb) == 0x1fce71fdcfb1797b42dede66ac9edp+21F128, 1, 0);
+  check_except (testflt128u_135 (21646332438261169091754659013488784965632uwb) == 0x1fce71fdcfb1797b42dede66ac9edp+21F128, 0, 0);
+  check_except (testflt128u_135 (21646332438261169091754659013488786014207uwb) == 0x1fce71fdcfb1797b42dede66ac9edp+21F128, 1, 0);
+  check_except (testflt128u_135 (21646332438261169091754659013488786014208uwb) == 0x1fce71fdcfb1797b42dede66ac9eep+21F128, 1, 0);
+  check_except (testflt128u_135 (21646332438261169091754659013488786014209uwb) == 0x1fce71fdcfb1797b42dede66ac9eep+21F128, 1, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_except (testflt128_192 (3138550867693340381917894711603832905819722818574723579904wb) == 0x1ffffffffffffffffffffffffffffp+78F128, 0, 0);
+  check_except (testflt128_192 (3138550867693340381917894711603833056935450270403370418175wb) == 0x1ffffffffffffffffffffffffffffp+78F128, 1, 0);
+  check_except (testflt128_192 (3138550867693340381917894711603833056935450270403370418176wb) == 0x20000000000000000000000000000p+78F128, 1, 0);
+  check_except (testflt128_192 (3138550867693340381917894711603833056935450270403370418177wb) == 0x20000000000000000000000000000p+78F128, 1, 0);
+  check_except (testflt128_192 (3138550867693340381917894711603833208051177722232017256447wb) == 0x20000000000000000000000000000p+78F128, 1, 0);
+  check_except (testflt128u_192 (6277101735386680763835789423207665811639445637149447159808uwb) == 0x1ffffffffffffffffffffffffffffp+79F128, 0, 0);
+  check_except (testflt128u_192 (6277101735386680763835789423207666113870900540806740836351uwb) == 0x1ffffffffffffffffffffffffffffp+79F128, 1, 0);
+  check_except (testflt128u_192 (6277101735386680763835789423207666113870900540806740836352uwb) == 0x20000000000000000000000000000p+79F128, 1, 0);
+  check_except (testflt128u_192 (6277101735386680763835789423207666113870900540806740836353uwb) == 0x20000000000000000000000000000p+79F128, 1, 0);
+  check_except (testflt128u_192 (6277101735386680763835789423207666416102355444464034512895uwb) == 0x20000000000000000000000000000p+79F128, 1, 0);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_except (testflt128_575 (-39695651458311907436978914487787846289740055435765388813682045155135192382154626611682813571487190641804615256990296246545713518740501887218789991403746059512699763279527936wb) == -0x148b25ce53790ddc343a80e5af6bap+461F128, 0, 0);
+  check_except (testflt128_575 (-39695651458311907436978914487787849266871470150571212503712362264401765094669639986937588484471046485703139369468190190624257242316066424102078490670010875270428034085158911wb) == -0x148b25ce53790ddc343a80e5af6bap+461F128, 1, 0);
+  check_except (testflt128_575 (-39695651458311907436978914487787849266871470150571212503712362264401765094669639986937588484471046485703139369468190190624257242316066424102078490670010875270428034085158912wb) == -0x148b25ce53790ddc343a80e5af6bap+461F128, 1, 0);
+  check_except (testflt128_575 (-39695651458311907436978914487787849266871470150571212503712362264401765094669639986937588484471046485703139369468190190624257242316066424102078490670010875270428034085158913wb) == -0x148b25ce53790ddc343a80e5af6bbp+461F128, 1, 0);
+  check_except (testflt128_575 (-39695651458311907436978914487787852244002884865377036193742679373668337807184653362192363397454902329601663481946084134702800965891630960985366989936275691028156304890789888wb) == -0x148b25ce53790ddc343a80e5af6bbp+461F128, 0, 0);
+  check_except (testflt128_575 (-39695651458311907436978914487787855221134299580182859883772996482934910519699666737447138310438758173500187594423978078781344689467195497868655489202540506785884575696420863wb) == -0x148b25ce53790ddc343a80e5af6bbp+461F128, 1, 0);
+  check_except (testflt128_575 (-39695651458311907436978914487787855221134299580182859883772996482934910519699666737447138310438758173500187594423978078781344689467195497868655489202540506785884575696420864wb) == -0x148b25ce53790ddc343a80e5af6bcp+461F128, 1, 0);
+  check_except (testflt128_575 (-39695651458311907436978914487787855221134299580182859883772996482934910519699666737447138310438758173500187594423978078781344689467195497868655489202540506785884575696420865wb) == -0x148b25ce53790ddc343a80e5af6bcp+461F128, 1, 0);
+  check_except (testflt128_575 (-61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1) == -0x20000000000000000000000000000p+461F128, 0, 0);
+  check_except (testflt128u_575 (79391302916623814873957828975575692579480110871530777627364090310270384764309253223365627142974381283609230513980592493091427037481003774437579982807492119025399526559055872uwb) == 0x148b25ce53790ddc343a80e5af6bap+462F128, 0, 0);
+  check_except (testflt128u_575 (79391302916623814873957828975575698533742940301142425007424724528803530189339279973875176968942092971406278738936380381248514484632132848204156981340021750540856068170317823uwb) == 0x148b25ce53790ddc343a80e5af6bap+462F128, 1, 0);
+  check_except (testflt128u_575 (79391302916623814873957828975575698533742940301142425007424724528803530189339279973875176968942092971406278738936380381248514484632132848204156981340021750540856068170317824uwb) == 0x148b25ce53790ddc343a80e5af6bap+462F128, 1, 0);
+  check_except (testflt128u_575 (79391302916623814873957828975575698533742940301142425007424724528803530189339279973875176968942092971406278738936380381248514484632132848204156981340021750540856068170317825uwb) == 0x148b25ce53790ddc343a80e5af6bbp+462F128, 1, 0);
+  check_except (testflt128u_575 (79391302916623814873957828975575704488005769730754072387485358747336675614369306724384726794909804659203326963892168269405601931783261921970733979872551382056312609781579776uwb) == 0x148b25ce53790ddc343a80e5af6bbp+462F128, 0, 0);
+  check_except (testflt128u_575 (79391302916623814873957828975575710442268599160365719767545992965869821039399333474894276620877516347000375188847956157562689378934390995737310978405081013571769151392841727uwb) == 0x148b25ce53790ddc343a80e5af6bbp+462F128, 1, 0);
+  check_except (testflt128u_575 (79391302916623814873957828975575710442268599160365719767545992965869821039399333474894276620877516347000375188847956157562689378934390995737310978405081013571769151392841728uwb) == 0x148b25ce53790ddc343a80e5af6bcp+462F128, 1, 0);
+  check_except (testflt128u_575 (79391302916623814873957828975575710442268599160365719767545992965869821039399333474894276620877516347000375188847956157562689378934390995737310978405081013571769151392841729uwb) == 0x148b25ce53790ddc343a80e5af6bcp+462F128, 1, 0);
+  check_except (testflt128u_575 (123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb) == 0x20000000000000000000000000000p+462F128, 1, 0);
+#endif
+#endif
+}
--- gcc/testsuite/gcc.dg/bitint-31.c.jj	2023-09-04 19:22:08.042521693 +0200
+++ gcc/testsuite/gcc.dg/bitint-31.c	2023-09-04 20:47:57.162160285 +0200
@@ -0,0 +1,480 @@
+/* PR c/102989 */
+/* { dg-do run } */
+/* { dg-require-effective-target fenv } */
+/* { dg-options "-std=c2x" } */
+/* { dg-add-options ieee } */
+
+#include <fenv.h>
+
+#if __FLT_MANT_DIG__ == 24
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) float
+testflt_135 (_BitInt(135) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) float
+testfltu_135 (unsigned _BitInt(135) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) float
+testflt_192 (_BitInt(192) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) float
+testfltu_192 (unsigned _BitInt(192) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) float
+testflt_575 (_BitInt(575) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) float
+testfltu_575 (unsigned _BitInt(575) b)
+{
+  return b;
+}
+#endif
+#endif
+
+#if __DBL_MANT_DIG__ == 53
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) double
+testdbl_135 (_BitInt(135) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) double
+testdblu_135 (unsigned _BitInt(135) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) double
+testdbl_192 (_BitInt(192) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) double
+testdblu_192 (unsigned _BitInt(192) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) double
+testdbl_575 (_BitInt(575) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) double
+testdblu_575 (unsigned _BitInt(575) b)
+{
+  return b;
+}
+#endif
+#endif
+
+#if __LDBL_MANT_DIG__ == 64
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) long double
+testldbl_135 (_BitInt(135) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) long double
+testldblu_135 (unsigned _BitInt(135) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) long double
+testldbl_192 (_BitInt(192) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) long double
+testldblu_192 (unsigned _BitInt(192) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) long double
+testldbl_575 (_BitInt(575) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) long double
+testldblu_575 (unsigned _BitInt(575) b)
+{
+  return b;
+}
+#endif
+#endif
+
+#if __FLT128_MANT_DIG__ == 113
+#if __BITINT_MAXWIDTH__ >= 135
+__attribute__((noipa)) _Float128
+testflt128_135 (_BitInt(135) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) _Float128
+testflt128u_135 (unsigned _BitInt(135) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) _Float128
+testflt128_192 (_BitInt(192) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) _Float128
+testflt128u_192 (unsigned _BitInt(192) b)
+{
+  return b;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) _Float128
+testflt128_575 (_BitInt(575) b)
+{
+  return b;
+}
+
+__attribute__((noipa)) _Float128
+testflt128u_575 (unsigned _BitInt(575) b)
+{
+  return b;
+}
+#endif
+#endif
+
+#define check_round(expr, vn, vd, vu, vz) \
+  do						\
+    {						\
+      fesetround (FE_TONEAREST);		\
+      if (expr != vn)				\
+	__builtin_abort ();			\
+      fesetround (FE_DOWNWARD);			\
+      if (expr != vd)				\
+	__builtin_abort ();			\
+      fesetround (FE_UPWARD);			\
+      if (expr != vu)				\
+	__builtin_abort ();			\
+      fesetround (FE_TOWARDZERO);		\
+      if (expr != vz)				\
+	__builtin_abort ();			\
+    }						\
+  while (0)
+
+#define check_round_same(expr, vn) check_round (expr, vn, vn, vn, vn)
+
+int
+main ()
+{
+#if defined(FE_TONEAREST) && defined(FE_DOWNWARD) && defined(FE_UPWARD) && defined (FE_TOWARDZERO)
+#if __FLT_MANT_DIG__ == 24
+#if __BITINT_MAXWIDTH__ >= 135
+  check_round (testflt_135 (151115713941029764726783wb), 0xfffffep+53f, 0xfffffep+53f, 0xffffffp+53f, 0xfffffep+53f);
+  check_round (testflt_135 (151115713941029764726784wb), 0xfffffep+53f, 0xfffffep+53f, 0xffffffp+53f, 0xfffffep+53f);
+  check_round (testflt_135 (151115713941029764726785wb), 0xffffffp+53f, 0xfffffep+53f, 0xffffffp+53f, 0xfffffep+53f);
+  check_round_same (testflt_135 (151115718444629392097280wb), 0xffffffp+53f);
+  check_round (testflt_135 (151115722948229019467775wb), 0xffffffp+53f, 0xffffffp+53f, 0x1000000p+53f, 0xffffffp+53f);
+  check_round (testflt_135 (151115722948229019467776wb), 0x1000000p+53f, 0xffffffp+53f, 0x1000000p+53f, 0xffffffp+53f);
+  check_round (testflt_135 (151115722948229019467777wb), 0x1000000p+53f, 0xffffffp+53f, 0x1000000p+53f, 0xffffffp+53f);
+  check_round_same (testflt_135 (-340282346638528859811704183484516925440wb), -0xffffffp+104f);
+  check_round (testflt_135 (-340282356779733661637539395458142568447wb), -0xffffffp+104f, -__builtin_inff (), -0xffffffp+104f, -0xffffffp+104f);
+  check_round (testflt_135 (-340282356779733661637539395458142568448wb), -__builtin_inff (), -__builtin_inff (), -0xffffffp+104f, -0xffffffp+104f);
+  check_round (testflt_135 (-21778071482940061661655974875633165533183wb - 1), -__builtin_inff (), -__builtin_inff (), -0xffffffp+104f, -0xffffffp+104f);
+  check_round (testfltu_135 (151115713941029764726783uwb), 0xfffffep+53f, 0xfffffep+53f, 0xffffffp+53f, 0xfffffep+53f);
+  check_round (testfltu_135 (151115713941029764726784uwb), 0xfffffep+53f, 0xfffffep+53f, 0xffffffp+53f, 0xfffffep+53f);
+  check_round (testfltu_135 (151115713941029764726785uwb), 0xffffffp+53f, 0xfffffep+53f, 0xffffffp+53f, 0xfffffep+53f);
+  check_round_same (testfltu_135 (151115718444629392097280uwb), 0xffffffp+53f);
+  check_round (testfltu_135 (151115722948229019467775uwb), 0xffffffp+53f, 0xffffffp+53f, 0x1000000p+53f, 0xffffffp+53f);
+  check_round (testfltu_135 (151115722948229019467776uwb), 0x1000000p+53f, 0xffffffp+53f, 0x1000000p+53f, 0xffffffp+53f);
+  check_round (testfltu_135 (151115722948229019467777uwb), 0x1000000p+53f, 0xffffffp+53f, 0x1000000p+53f, 0xffffffp+53f);
+  check_round_same (testfltu_135 (340282346638528859811704183484516925440uwb), 0xffffffp+104f);
+  check_round (testfltu_135 (340282356779733661637539395458142568447uwb), 0xffffffp+104f, 0xffffffp+104f, __builtin_inff (), 0xffffffp+104f);
+  check_round (testfltu_135 (340282356779733661637539395458142568448uwb), __builtin_inff (), 0xffffffp+104f, __builtin_inff (), 0xffffffp+104f);
+  check_round (testfltu_135 (43556142965880123323311949751266331066367uwb), __builtin_inff (), 0xffffffp+104f, __builtin_inff (), 0xffffffp+104f);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_round (testflt_192 (-10141203895131470501001744613375wb), -0xfffffep+79f, -0xffffffp+79f, -0xfffffep+79f, -0xfffffep+79f);
+  check_round (testflt_192 (-10141203895131470501001744613376wb), -0xfffffep+79f, -0xffffffp+79f, -0xfffffep+79f, -0xfffffep+79f);
+  check_round (testflt_192 (-10141203895131470501001744613377wb), -0xffffffp+79f, -0xffffffp+79f, -0xfffffep+79f, -0xfffffep+79f);
+  check_round_same (testflt_192 (-10141204197362925404659038289920wb), -0xffffffp+79f);
+  check_round (testflt_192 (-10141204499594380308316331966463wb), -0xffffffp+79f, -0x1000000p+79f, -0xffffffp+79f, -0xffffffp+79f);
+  check_round (testflt_192 (-10141204499594380308316331966464wb), -0x1000000p+79f, -0x1000000p+79f, -0xffffffp+79f, -0xffffffp+79f);
+  check_round (testflt_192 (-10141204499594380308316331966465wb), -0x1000000p+79f, -0x1000000p+79f, -0xffffffp+79f, -0xffffffp+79f);
+  check_round_same (testflt_192 (340282346638528859811704183484516925440wb), 0xffffffp+104f);
+  check_round (testflt_192 (340282356779733661637539395458142568447wb), 0xffffffp+104f, 0xffffffp+104f, __builtin_inff (), 0xffffffp+104f);
+  check_round (testflt_192 (340282356779733661637539395458142568448wb), __builtin_inff (), 0xffffffp+104f, __builtin_inff (), 0xffffffp+104f);
+  check_round (testflt_192 (3138550867693340381917894711603833208051177722232017256447wb), __builtin_inff (), 0xffffffp+104f, __builtin_inff (), 0xffffffp+104f);
+  check_round (testfltu_192 (10141203895131470501001744613375uwb), 0xfffffep+79f, 0xfffffep+79f, 0xffffffp+79f, 0xfffffep+79f);
+  check_round (testfltu_192 (10141203895131470501001744613376uwb), 0xfffffep+79f, 0xfffffep+79f, 0xffffffp+79f, 0xfffffep+79f);
+  check_round (testfltu_192 (10141203895131470501001744613377uwb), 0xffffffp+79f, 0xfffffep+79f, 0xffffffp+79f, 0xfffffep+79f);
+  check_round_same (testfltu_192 (10141204197362925404659038289920uwb), 0xffffffp+79f);
+  check_round (testfltu_192 (10141204499594380308316331966463uwb), 0xffffffp+79f, 0xffffffp+79f, 0x1000000p+79f, 0xffffffp+79f);
+  check_round (testfltu_192 (10141204499594380308316331966464uwb), 0x1000000p+79f, 0xffffffp+79f, 0x1000000p+79f, 0xffffffp+79f);
+  check_round (testfltu_192 (10141204499594380308316331966465uwb), 0x1000000p+79f, 0xffffffp+79f, 0x1000000p+79f, 0xffffffp+79f);
+  check_round_same (testfltu_192 (340282346638528859811704183484516925440uwb), 0xffffffp+104f);
+  check_round (testfltu_192 (340282356779733661637539395458142568447uwb), 0xffffffp+104f, 0xffffffp+104f, __builtin_inff (), 0xffffffp+104f);
+  check_round (testfltu_192 (340282356779733661637539395458142568448uwb), __builtin_inff (), 0xffffffp+104f, __builtin_inff (), 0xffffffp+104f);
+  check_round (testfltu_192 (6277101735386680763835789423207666416102355444464034512895uwb), __builtin_inff (), 0xffffffp+104f, __builtin_inff (), 0xffffffp+104f);
+#endif
+#if 0 && __BITINT_MAXWIDTH__ >= 575
+  check_round (testflt_575 (10633823015541376812058405359715352575wb), 0xfffffep+99f, 0xfffffep+99f, 0xffffffp+99f, 0xfffffep+99f);
+  check_round (testflt_575 (10633823015541376812058405359715352576wb), 0xfffffep+99f, 0xfffffep+99f, 0xffffffp+99f, 0xfffffep+99f);
+  check_round (testflt_575 (10633823015541376812058405359715352577wb), 0xffffffp+99f, 0xfffffep+99f, 0xffffffp+99f, 0xfffffep+99f);
+  check_round_same (testflt_575 (10633823332454026869115755733891153920wb), 0xffffffp+99f);
+  check_round (testflt_575 (10633823649366676926173106108066955263wb), 0xffffffp+99f, 0xffffffp+99f, 0x1000000p+99f, 0xffffffp+99f);
+  check_round (testflt_575 (10633823649366676926173106108066955264wb), 0x1000000p+99f, 0xffffffp+99f, 0x1000000p+99f, 0xffffffp+99f);
+  check_round (testflt_575 (10633823649366676926173106108066955265wb), 0x1000000p+99f, 0xffffffp+99f, 0x1000000p+99f, 0xffffffp+99f);
+  check_round_same (testflt_575 (-340282346638528859811704183484516925440wb), -0xffffffp+104f);
+  check_round (testflt_575 (-340282356779733661637539395458142568447wb), -0xffffffp+104f, -__builtin_inff (), -0xffffffp+104f, -0xffffffp+104f);
+  check_round (testflt_575 (-340282356779733661637539395458142568448wb), -__builtin_inff (), -__builtin_inff (), -0xffffffp+104f, -0xffffffp+104f);
+  check_round (testflt_575 (-61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1), -__builtin_inff (), -__builtin_inff (), -0xffffffp+104f, -0xffffffp+104f);
+  check_round (testfltu_575 (10633823015541376812058405359715352575uwb), 0xfffffep+99f, 0xfffffep+99f, 0xffffffp+99f, 0xfffffep+99f);
+  check_round (testfltu_575 (10633823015541376812058405359715352576uwb), 0xfffffep+99f, 0xfffffep+99f, 0xffffffp+99f, 0xfffffep+99f);
+  check_round (testfltu_575 (10633823015541376812058405359715352577uwb), 0xffffffp+99f, 0xfffffep+99f, 0xffffffp+99f, 0xfffffep+99f);
+  check_round_same (testfltu_575 (10633823332454026869115755733891153920uwb), 0xffffffp+99f);
+  check_round (testfltu_575 (10633823649366676926173106108066955263uwb), 0xffffffp+99f, 0xffffffp+99f, 0x1000000p+99f, 0xffffffp+99f);
+  check_round (testfltu_575 (10633823649366676926173106108066955264uwb), 0x1000000p+99f, 0xffffffp+99f, 0x1000000p+99f, 0xffffffp+99f);
+  check_round (testfltu_575 (10633823649366676926173106108066955265uwb), 0x1000000p+99f, 0xffffffp+99f, 0x1000000p+99f, 0xffffffp+99f);
+  check_round_same (testfltu_575 (340282346638528859811704183484516925440uwb), 0xffffffp+104f);
+  check_round (testfltu_575 (340282356779733661637539395458142568447uwb), 0xffffffp+104f, 0xffffffp+104f, __builtin_inff (), 0xffffffp+104f);
+  check_round (testfltu_575 (340282356779733661637539395458142568448uwb), __builtin_inff (), 0xffffffp+104f, __builtin_inff (), 0xffffffp+104f);
+  check_round (testfltu_575 (123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb), __builtin_inff (), 0xffffffp+104f, __builtin_inff (), 0xffffffp+104f);
+#endif
+#endif
+#if __DBL_MANT_DIG__, 53
+#if __BITINT_MAXWIDTH__ >= 135
+  check_round (testdbl_135 (-21267647932558650424686050812251602943wb), -0x1ffffffffffffep+71, -0x1fffffffffffffp+71, -0x1ffffffffffffep+71, -0x1ffffffffffffep+71);
+  check_round (testdbl_135 (-21267647932558650424686050812251602944wb), -0x1ffffffffffffep+71, -0x1fffffffffffffp+71, -0x1ffffffffffffep+71, -0x1ffffffffffffep+71);
+  check_round (testdbl_135 (-21267647932558650424686050812251602945wb), -0x1fffffffffffffp+71, -0x1fffffffffffffp+71, -0x1ffffffffffffep+71, -0x1ffffffffffffep+71);
+  check_round_same (testdbl_135 (-21267647932558651605277671529662906368wb), -0x1fffffffffffffp+71);
+  check_round (testdbl_135 (-21267647932558652785869292247074209791wb), -0x1fffffffffffffp+71, -0x20000000000000p+71, -0x1fffffffffffffp+71, -0x1fffffffffffffp+71);
+  check_round (testdbl_135 (-21267647932558652785869292247074209792wb), -0x20000000000000p+71, -0x20000000000000p+71, -0x1fffffffffffffp+71, -0x1fffffffffffffp+71);
+  check_round (testdbl_135 (-21267647932558652785869292247074209793wb), -0x20000000000000p+71, -0x20000000000000p+71, -0x1fffffffffffffp+71, -0x1fffffffffffffp+71);
+  check_round_same (testdbl_135 (21778071482940059243804335646374816120832wb), 0x1fffffffffffffp+81);
+  check_round (testdbl_135 (21778071482940060452730155261003990827007wb), 0x1fffffffffffffp+81, 0x1fffffffffffffp+81, 0x20000000000000p+81, 0x1fffffffffffffp+81);
+  check_round (testdbl_135 (21778071482940060452730155261003990827008wb), 0x20000000000000p+81, 0x1fffffffffffffp+81, 0x20000000000000p+81, 0x1fffffffffffffp+81);
+  check_round (testdbl_135 (21778071482940060452730155261003990827009wb), 0x20000000000000p+81, 0x1fffffffffffffp+81, 0x20000000000000p+81, 0x1fffffffffffffp+81);
+  check_round (testdbl_135 (21778071482940061661655974875633165533183wb), 0x20000000000000p+81, 0x1fffffffffffffp+81, 0x20000000000000p+81, 0x1fffffffffffffp+81);
+  check_round (testdblu_135 (21267647932558650424686050812251602943uwb), 0x1ffffffffffffep+71, 0x1ffffffffffffep+71, 0x1fffffffffffffp+71, 0x1ffffffffffffep+71);
+  check_round (testdblu_135 (21267647932558650424686050812251602944uwb), 0x1ffffffffffffep+71, 0x1ffffffffffffep+71, 0x1fffffffffffffp+71, 0x1ffffffffffffep+71);
+  check_round (testdblu_135 (21267647932558650424686050812251602945uwb), 0x1fffffffffffffp+71, 0x1ffffffffffffep+71, 0x1fffffffffffffp+71, 0x1ffffffffffffep+71);
+  check_round_same (testdblu_135 (21267647932558651605277671529662906368uwb), 0x1fffffffffffffp+71);
+  check_round (testdblu_135 (21267647932558652785869292247074209791uwb), 0x1fffffffffffffp+71, 0x1fffffffffffffp+71, 0x20000000000000p+71, 0x1fffffffffffffp+71);
+  check_round (testdblu_135 (21267647932558652785869292247074209792uwb), 0x20000000000000p+71, 0x1fffffffffffffp+71, 0x20000000000000p+71, 0x1fffffffffffffp+71);
+  check_round (testdblu_135 (21267647932558652785869292247074209793uwb), 0x20000000000000p+71, 0x1fffffffffffffp+71, 0x20000000000000p+71, 0x1fffffffffffffp+71);
+  check_round_same (testdblu_135 (43556142965880118487608671292749632241664uwb), 0x1fffffffffffffp+82);
+  check_round (testdblu_135 (43556142965880120905460310522007981654015uwb), 0x1fffffffffffffp+82, 0x1fffffffffffffp+82, 0x20000000000000p+82, 0x1fffffffffffffp+82);
+  check_round (testdblu_135 (43556142965880120905460310522007981654016uwb), 0x20000000000000p+82, 0x1fffffffffffffp+82, 0x20000000000000p+82, 0x1fffffffffffffp+82);
+  check_round (testdblu_135 (43556142965880120905460310522007981654017uwb), 0x20000000000000p+82, 0x1fffffffffffffp+82, 0x20000000000000p+82, 0x1fffffffffffffp+82);
+  check_round (testdblu_135 (43556142965880123323311949751266331066367uwb), 0x20000000000000p+82, 0x1fffffffffffffp+82, 0x20000000000000p+82, 0x1fffffffffffffp+82);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_round (testdbl_192 (89202980794122477710862401666030147234430975wb), 0x1ffffffffffffep+93, 0x1ffffffffffffep+93, 0x1fffffffffffffp+93, 0x1ffffffffffffep+93);
+  check_round (testdbl_192 (89202980794122477710862401666030147234430976wb), 0x1ffffffffffffep+93, 0x1ffffffffffffep+93, 0x1fffffffffffffp+93, 0x1ffffffffffffep+93);
+  check_round (testdbl_192 (89202980794122477710862401666030147234430977wb), 0x1fffffffffffffp+93, 0x1ffffffffffffep+93, 0x1fffffffffffffp+93, 0x1ffffffffffffep+93);
+  check_round_same (testdbl_192 (89202980794122482662622558807551246830927872wb), 0x1fffffffffffffp+93);
+  check_round (testdbl_192 (89202980794122487614382715949072346427424767wb), 0x1fffffffffffffp+93, 0x1fffffffffffffp+93, 0x20000000000000p+93, 0x1fffffffffffffp+93);
+  check_round (testdbl_192 (89202980794122487614382715949072346427424768wb), 0x20000000000000p+93, 0x1fffffffffffffp+93, 0x20000000000000p+93, 0x1fffffffffffffp+93);
+  check_round (testdbl_192 (89202980794122487614382715949072346427424769wb), 0x20000000000000p+93, 0x1fffffffffffffp+93, 0x20000000000000p+93, 0x1fffffffffffffp+93);
+  check_round_same (testdbl_192 (-3138550867693340033468750984562846621555579712101368725504wb), -0x1fffffffffffffp+138);
+  check_round (testdbl_192 (-3138550867693340207693322848083339914803378717166692990975wb), -0x1fffffffffffffp+138, -0x20000000000000p+138, -0x1fffffffffffffp+138, -0x1fffffffffffffp+138);
+  check_round (testdbl_192 (-3138550867693340207693322848083339914803378717166692990976wb), -0x20000000000000p+138, -0x20000000000000p+138, -0x1fffffffffffffp+138, -0x1fffffffffffffp+138);
+  check_round (testdbl_192 (-3138550867693340207693322848083339914803378717166692990977wb), -0x20000000000000p+138, -0x20000000000000p+138, -0x1fffffffffffffp+138, -0x1fffffffffffffp+138);
+  check_round_same (testdbl_192 (-3138550867693340381917894711603833208051177722232017256447wb - 1), -0x20000000000000p+138);
+  check_round (testdblu_192 (89202980794122477710862401666030147234430975uwb), 0x1ffffffffffffep+93, 0x1ffffffffffffep+93, 0x1fffffffffffffp+93, 0x1ffffffffffffep+93);
+  check_round (testdblu_192 (89202980794122477710862401666030147234430976uwb), 0x1ffffffffffffep+93, 0x1ffffffffffffep+93, 0x1fffffffffffffp+93, 0x1ffffffffffffep+93);
+  check_round (testdblu_192 (89202980794122477710862401666030147234430977uwb), 0x1fffffffffffffp+93, 0x1ffffffffffffep+93, 0x1fffffffffffffp+93, 0x1ffffffffffffep+93);
+  check_round_same (testdblu_192 (89202980794122482662622558807551246830927872uwb), 0x1fffffffffffffp+93);
+  check_round (testdblu_192 (89202980794122487614382715949072346427424767uwb), 0x1fffffffffffffp+93, 0x1fffffffffffffp+93, 0x20000000000000p+93, 0x1fffffffffffffp+93);
+  check_round (testdblu_192 (89202980794122487614382715949072346427424768uwb), 0x20000000000000p+93, 0x1fffffffffffffp+93, 0x20000000000000p+93, 0x1fffffffffffffp+93);
+  check_round (testdblu_192 (89202980794122487614382715949072346427424769uwb), 0x20000000000000p+93, 0x1fffffffffffffp+93, 0x20000000000000p+93, 0x1fffffffffffffp+93);
+  check_round_same (testdblu_192 (6277101735386680066937501969125693243111159424202737451008uwb), 0x1fffffffffffffp+139);
+  check_round (testdblu_192 (6277101735386680415386645696166679829606757434333385981951uwb), 0x1fffffffffffffp+139, 0x1fffffffffffffp+139, 0x20000000000000p+139, 0x1fffffffffffffp+139);
+  check_round (testdblu_192 (6277101735386680415386645696166679829606757434333385981952uwb), 0x20000000000000p+139, 0x1fffffffffffffp+139, 0x20000000000000p+139, 0x1fffffffffffffp+139);
+  check_round (testdblu_192 (6277101735386680415386645696166679829606757434333385981953uwb), 0x20000000000000p+139, 0x1fffffffffffffp+139, 0x20000000000000p+139, 0x1fffffffffffffp+139);
+  check_round (testdblu_192 (6277101735386680763835789423207666416102355444464034512895uwb), 0x20000000000000p+139, 0x1fffffffffffffp+139, 0x20000000000000p+139, 0x1fffffffffffffp+139);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_round (testdbl_575 (-615656346818663635164482277361060010743329029962521103256875011322006445221646740336801072761830405785423389392895wb), -0x1ffffffffffffep+325, -0x1fffffffffffffp+325, -0x1ffffffffffffep+325, -0x1ffffffffffffep+325);
+  check_round (testdbl_575 (-615656346818663635164482277361060010743329029962521103256875011322006445221646740336801072761830405785423389392896wb), -0x1ffffffffffffep+325, -0x1fffffffffffffp+325, -0x1ffffffffffffep+325, -0x1ffffffffffffep+325);
+  check_round (testdbl_575 (-615656346818663635164482277361060010743329029962521103256875011322006445221646740336801072761830405785423389392897wb), -0x1fffffffffffffp+325, -0x1fffffffffffffp+325, -0x1ffffffffffffep+325, -0x1ffffffffffffep+325);
+  check_round_same (testdbl_575 (-615656346818663669340274852095621329063676328675354936900147369028450764374312465492316685252079206152816780378112wb), -0x1fffffffffffffp+325);
+  check_round (testdbl_575 (-615656346818663703516067426830182647384023627388188770543419726734895083526978190647832297742328006520210171363327wb), -0x1fffffffffffffp+325, -0x20000000000000p+325, -0x1fffffffffffffp+325, -0x1fffffffffffffp+325);
+  check_round (testdbl_575 (-615656346818663703516067426830182647384023627388188770543419726734895083526978190647832297742328006520210171363328wb), -0x20000000000000p+325, -0x20000000000000p+325, -0x1fffffffffffffp+325, -0x1fffffffffffffp+325);
+  check_round (testdbl_575 (-615656346818663703516067426830182647384023627388188770543419726734895083526978190647832297742328006520210171363329wb), -0x20000000000000p+325, -0x20000000000000p+325, -0x1fffffffffffffp+325, -0x1fffffffffffffp+325);
+  check_round_same (testdbl_575 (61832600368276126650327970124302082526882038193909742709080463879918896882169507607035916867654709124839777195049479857541529867095829765369898539058829479405123401922117632wb), 0x1fffffffffffffp+521);
+  check_round (testdbl_575 (61832600368276130082726800189606940017832437734606351343798113951571601579401237199807508566482735186119597525776757346189685562836258783930892538917151385692137547479646207wb), 0x1fffffffffffffp+521, 0x1fffffffffffffp+521, 0x20000000000000p+521, 0x1fffffffffffffp+521);
+  check_round (testdbl_575 (61832600368276130082726800189606940017832437734606351343798113951571601579401237199807508566482735186119597525776757346189685562836258783930892538917151385692137547479646208wb), 0x20000000000000p+521, 0x1fffffffffffffp+521, 0x20000000000000p+521, 0x1fffffffffffffp+521);
+  check_round (testdbl_575 (61832600368276130082726800189606940017832437734606351343798113951571601579401237199807508566482735186119597525776757346189685562836258783930892538917151385692137547479646209wb), 0x20000000000000p+521, 0x1fffffffffffffp+521, 0x20000000000000p+521, 0x1fffffffffffffp+521);
+  check_round (testdbl_575 (61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb), 0x20000000000000p+521, 0x1fffffffffffffp+521, 0x20000000000000p+521, 0x1fffffffffffffp+521);
+  check_round (testdblu_575 (615656346818663635164482277361060010743329029962521103256875011322006445221646740336801072761830405785423389392895uwb), 0x1ffffffffffffep+325, 0x1ffffffffffffep+325, 0x1fffffffffffffp+325, 0x1ffffffffffffep+325);
+  check_round (testdblu_575 (615656346818663635164482277361060010743329029962521103256875011322006445221646740336801072761830405785423389392896uwb), 0x1ffffffffffffep+325, 0x1ffffffffffffep+325, 0x1fffffffffffffp+325, 0x1ffffffffffffep+325);
+  check_round (testdblu_575 (615656346818663635164482277361060010743329029962521103256875011322006445221646740336801072761830405785423389392897uwb), 0x1fffffffffffffp+325, 0x1ffffffffffffep+325, 0x1fffffffffffffp+325, 0x1ffffffffffffep+325);
+  check_round_same (testdblu_575 (615656346818663669340274852095621329063676328675354936900147369028450764374312465492316685252079206152816780378112uwb), 0x1fffffffffffffp+325);
+  check_round (testdblu_575 (615656346818663703516067426830182647384023627388188770543419726734895083526978190647832297742328006520210171363327uwb), 0x1fffffffffffffp+325, 0x1fffffffffffffp+325, 0x20000000000000p+325, 0x1fffffffffffffp+325);
+  check_round (testdblu_575 (615656346818663703516067426830182647384023627388188770543419726734895083526978190647832297742328006520210171363328uwb), 0x20000000000000p+325, 0x1fffffffffffffp+325, 0x20000000000000p+325, 0x1fffffffffffffp+325);
+  check_round (testdblu_575 (615656346818663703516067426830182647384023627388188770543419726734895083526978190647832297742328006520210171363329uwb), 0x20000000000000p+325, 0x1fffffffffffffp+325, 0x20000000000000p+325, 0x1fffffffffffffp+325);
+  check_round_same (testdblu_575 (123665200736552253300655940248604165053764076387819485418160927759837793764339015214071833735309418249679554390098959715083059734191659530739797078117658958810246803844235264uwb), 0x1fffffffffffffp+522);
+  check_round (testdblu_575 (123665200736552260165453600379213880035664875469212702687596227903143203158802474399615017132965470372239195051553514692379371125672517567861785077834302771384275094959292415uwb), 0x1fffffffffffffp+522, 0x1fffffffffffffp+522, 0x20000000000000p+522, 0x1fffffffffffffp+522);
+  check_round (testdblu_575 (123665200736552260165453600379213880035664875469212702687596227903143203158802474399615017132965470372239195051553514692379371125672517567861785077834302771384275094959292416uwb), 0x20000000000000p+522, 0x1fffffffffffffp+522, 0x20000000000000p+522, 0x1fffffffffffffp+522);
+  check_round (testdblu_575 (123665200736552260165453600379213880035664875469212702687596227903143203158802474399615017132965470372239195051553514692379371125672517567861785077834302771384275094959292417uwb), 0x20000000000000p+522, 0x1fffffffffffffp+522, 0x20000000000000p+522, 0x1fffffffffffffp+522);
+  check_round (testdblu_575 (123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb), 0x20000000000000p+522, 0x1fffffffffffffp+522, 0x20000000000000p+522, 0x1fffffffffffffp+522);
+#endif
+#endif
+#if __LDBL_MANT_DIG__, 64
+#if __BITINT_MAXWIDTH__ >= 135
+  check_round (testldbl_135 (-27577662721237071616947187835994111wb), -0xa9f5e144d113e1c4p+51L, -0xa9f5e144d113e1c5p+51L, -0xa9f5e144d113e1c4p+51L, -0xa9f5e144d113e1c4p+51L);
+  check_round (testldbl_135 (-27577662721237071616947187835994112wb), -0xa9f5e144d113e1c4p+51L, -0xa9f5e144d113e1c5p+51L, -0xa9f5e144d113e1c4p+51L, -0xa9f5e144d113e1c4p+51L);
+  check_round (testldbl_135 (-27577662721237071616947187835994113wb), -0xa9f5e144d113e1c5p+51L, -0xa9f5e144d113e1c5p+51L, -0xa9f5e144d113e1c4p+51L, -0xa9f5e144d113e1c4p+51L);
+  check_round_same (testldbl_135 (-27577662721237071618073087742836736wb), -0xa9f5e144d113e1c5p+51L);
+  check_round (testldbl_135 (-27577662721237071619198987649679359wb), -0xa9f5e144d113e1c5p+51L, -0xa9f5e144d113e1c6p+51L, -0xa9f5e144d113e1c5p+51L, -0xa9f5e144d113e1c5p+51L);
+  check_round (testldbl_135 (-27577662721237071619198987649679360wb), -0xa9f5e144d113e1c6p+51L, -0xa9f5e144d113e1c6p+51L, -0xa9f5e144d113e1c5p+51L, -0xa9f5e144d113e1c5p+51L);
+  check_round (testldbl_135 (-27577662721237071619198987649679361wb), -0xa9f5e144d113e1c6p+51L, -0xa9f5e144d113e1c6p+51L, -0xa9f5e144d113e1c5p+51L, -0xa9f5e144d113e1c5p+51L);
+  check_round_same (testldbl_135 (-21778071482940061660475383254915754229760wb), -0xffffffffffffffffp+70L);
+  check_round (testldbl_135 (-21778071482940061661065679065274459881471wb), -0xffffffffffffffffp+70L, -0x10000000000000000p+70L, -0xffffffffffffffffp+70L, -0xffffffffffffffffp+70L);
+  check_round (testldbl_135 (-21778071482940061661065679065274459881472wb), -0x10000000000000000p+70L, -0x10000000000000000p+70L, -0xffffffffffffffffp+70L, -0xffffffffffffffffp+70L);
+  check_round (testldbl_135 (-21778071482940061661065679065274459881473wb), -0x10000000000000000p+70L, -0x10000000000000000p+70L, -0xffffffffffffffffp+70L, -0xffffffffffffffffp+70L);
+  check_round_same (testldbl_135 (-21778071482940061661655974875633165533183wb - 1), -0x10000000000000000p+70L);
+  check_round (testldblu_135 (27577662721237071616947187835994111uwb), 0xa9f5e144d113e1c4p+51L, 0xa9f5e144d113e1c4p+51L, 0xa9f5e144d113e1c5p+51L, 0xa9f5e144d113e1c4p+51L);
+  check_round (testldblu_135 (27577662721237071616947187835994112uwb), 0xa9f5e144d113e1c4p+51L, 0xa9f5e144d113e1c4p+51L, 0xa9f5e144d113e1c5p+51L, 0xa9f5e144d113e1c4p+51L);
+  check_round (testldblu_135 (27577662721237071616947187835994113uwb), 0xa9f5e144d113e1c5p+51L, 0xa9f5e144d113e1c4p+51L, 0xa9f5e144d113e1c5p+51L, 0xa9f5e144d113e1c4p+51L);
+  check_round_same (testldblu_135 (27577662721237071618073087742836736uwb), 0xa9f5e144d113e1c5p+51L);
+  check_round (testldblu_135 (27577662721237071619198987649679359uwb), 0xa9f5e144d113e1c5p+51L, 0xa9f5e144d113e1c5p+51L, 0xa9f5e144d113e1c6p+51L, 0xa9f5e144d113e1c5p+51L);
+  check_round (testldblu_135 (27577662721237071619198987649679360uwb), 0xa9f5e144d113e1c6p+51L, 0xa9f5e144d113e1c5p+51L, 0xa9f5e144d113e1c6p+51L, 0xa9f5e144d113e1c5p+51L);
+  check_round (testldblu_135 (27577662721237071619198987649679361uwb), 0xa9f5e144d113e1c6p+51L, 0xa9f5e144d113e1c5p+51L, 0xa9f5e144d113e1c6p+51L, 0xa9f5e144d113e1c5p+51L);
+  check_round_same (testldblu_135 (43556142965880123320950766509831508459520uwb), 0xffffffffffffffffp+71L);
+  check_round (testldblu_135 (43556142965880123322131358130548919762943uwb), 0xffffffffffffffffp+71L, 0xffffffffffffffffp+71L, 0x10000000000000000p+71L, 0xffffffffffffffffp+71L);
+  check_round (testldblu_135 (43556142965880123322131358130548919762944uwb), 0x10000000000000000p+71L, 0xffffffffffffffffp+71L, 0x10000000000000000p+71L, 0xffffffffffffffffp+71L);
+  check_round (testldblu_135 (43556142965880123322131358130548919762945uwb), 0x10000000000000000p+71L, 0xffffffffffffffffp+71L, 0x10000000000000000p+71L, 0xffffffffffffffffp+71L);
+  check_round (testldblu_135 (43556142965880123323311949751266331066367uwb), 0x10000000000000000p+71L, 0xffffffffffffffffp+71L, 0x10000000000000000p+71L, 0xffffffffffffffffp+71L);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_round (testldbl_192 (96388802158769743653878219701497927252918090596351wb), 0x83e75ebf94ce024ep+103L, 0x83e75ebf94ce024ep+103L, 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce024ep+103L);
+  check_round (testldbl_192 (96388802158769743653878219701497927252918090596352wb), 0x83e75ebf94ce024ep+103L, 0x83e75ebf94ce024ep+103L, 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce024ep+103L);
+  check_round (testldbl_192 (96388802158769743653878219701497927252918090596353wb), 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce024ep+103L, 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce024ep+103L);
+  check_round_same (testldbl_192 (96388802158769743658948822102410844858904903417856wb), 0x83e75ebf94ce024fp+103L);
+  check_round (testldbl_192 (96388802158769743664019424503323762464891716239359wb), 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce0250p+103L, 0x83e75ebf94ce024fp+103L);
+  check_round (testldbl_192 (96388802158769743664019424503323762464891716239360wb), 0x83e75ebf94ce0250p+103L, 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce0250p+103L, 0x83e75ebf94ce024fp+103L);
+  check_round (testldbl_192 (96388802158769743664019424503323762464891716239361wb), 0x83e75ebf94ce0250p+103L, 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce0250p+103L, 0x83e75ebf94ce024fp+103L);
+  check_round_same (testldbl_192 (-3138550867693340381747753528143363976319490418516133150720wb), -0xffffffffffffffffp+127L);
+  check_round (testldbl_192 (-3138550867693340381832824119873598592185334070374075203583wb), -0xffffffffffffffffp+127L, -0x10000000000000000p+127L, -0xffffffffffffffffp+127L, -0xffffffffffffffffp+127L);
+  check_round (testldbl_192 (-3138550867693340381832824119873598592185334070374075203584wb), -0x10000000000000000p+127L, -0x10000000000000000p+127L, -0xffffffffffffffffp+127L, -0xffffffffffffffffp+127L);
+  check_round (testldbl_192 (-3138550867693340381832824119873598592185334070374075203585wb), -0x10000000000000000p+127L, -0x10000000000000000p+127L, -0xffffffffffffffffp+127L, -0xffffffffffffffffp+127L);
+  check_round_same (testldbl_192 (-3138550867693340381917894711603833208051177722232017256447wb - 1wb), -0x10000000000000000p+127L);
+  check_round (testldblu_192 (96388802158769743653878219701497927252918090596351uwb), 0x83e75ebf94ce024ep+103L, 0x83e75ebf94ce024ep+103L, 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce024ep+103L);
+  check_round (testldblu_192 (96388802158769743653878219701497927252918090596352uwb), 0x83e75ebf94ce024ep+103L, 0x83e75ebf94ce024ep+103L, 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce024ep+103L);
+  check_round (testldblu_192 (96388802158769743653878219701497927252918090596353uwb), 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce024ep+103L, 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce024ep+103L);
+  check_round_same (testldblu_192 (96388802158769743658948822102410844858904903417856uwb), 0x83e75ebf94ce024fp+103L);
+  check_round (testldblu_192 (96388802158769743664019424503323762464891716239359uwb), 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce0250p+103L, 0x83e75ebf94ce024fp+103L);
+  check_round (testldblu_192 (96388802158769743664019424503323762464891716239360uwb), 0x83e75ebf94ce0250p+103L, 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce0250p+103L, 0x83e75ebf94ce024fp+103L);
+  check_round (testldblu_192 (96388802158769743664019424503323762464891716239361uwb), 0x83e75ebf94ce0250p+103L, 0x83e75ebf94ce024fp+103L, 0x83e75ebf94ce0250p+103L, 0x83e75ebf94ce024fp+103L);
+  check_round_same (testldblu_192 (6277101735386680763495507056286727952638980837032266301440uwb), 0xffffffffffffffffp+128L);
+  check_round (testldblu_192 (6277101735386680763665648239747197184370668140748150407167uwb), 0xffffffffffffffffp+128L, 0xffffffffffffffffp+128L, 0x10000000000000000p+128L, 0xffffffffffffffffp+128L);
+  check_round (testldblu_192 (6277101735386680763665648239747197184370668140748150407168uwb), 0x10000000000000000p+128L, 0xffffffffffffffffp+128L, 0x10000000000000000p+128L, 0xffffffffffffffffp+128L);
+  check_round (testldblu_192 (6277101735386680763665648239747197184370668140748150407169uwb), 0x10000000000000000p+128L, 0xffffffffffffffffp+128L, 0x10000000000000000p+128L, 0xffffffffffffffffp+128L);
+  check_round (testldblu_192 (6277101735386680763835789423207666416102355444464034512895uwb), 0x10000000000000000p+128L, 0xffffffffffffffffp+128L, 0x10000000000000000p+128L, 0xffffffffffffffffp+128L);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_round_same (testldbl_575 (-61832600368276133511773678272426148233889331025751498446645922568076207932202076431648659257792374503198949281962308977915333294030066289778448068072486649492543280785653760wb), -0xffffffffffffffffp+510L);
+  check_round (testldbl_575 (-61832600368276133513449654263668972871336084150527229212580843295650257104417521612113879761551567875299183569233171906376587276303377046135167303423979970735847486911414271wb), -0xffffffffffffffffp+510L, -0x10000000000000000p+510L, -0xffffffffffffffffp+510L, -0xffffffffffffffffp+510L);
+  check_round (testldbl_575 (-61832600368276133513449654263668972871336084150527229212580843295650257104417521612113879761551567875299183569233171906376587276303377046135167303423979970735847486911414272wb), -0x10000000000000000p+510L, -0x10000000000000000p+510L, -0xffffffffffffffffp+510L, -0xffffffffffffffffp+510L);
+  check_round (testldbl_575 (-61832600368276133513449654263668972871336084150527229212580843295650257104417521612113879761551567875299183569233171906376587276303377046135167303423979970735847486911414273wb), -0x10000000000000000p+510L, -0x10000000000000000p+510L, -0xffffffffffffffffp+510L, -0xffffffffffffffffp+510L);
+  check_round_same (testldbl_575 (-61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1), -0x10000000000000000p+510L);
+  check_round_same (testldblu_575 (123665200736552267023547356544852296467778662051502996893291845136152415864404152863297318515584749006397898563924617955830666588060132579556896136144973298985086561571307520uwb), 0xffffffffffffffffp+511L);
+  check_round (testldblu_575 (123665200736552267026899308527337945742672168301054458425161686591300514208835043224227759523103135750598367138466343812753174552606754092270334606847959941471694973822828543uwb), 0xffffffffffffffffp+511L, 0xffffffffffffffffp+511L, 0x10000000000000000p+511L, 0xffffffffffffffffp+511L);
+  check_round (testldblu_575 (123665200736552267026899308527337945742672168301054458425161686591300514208835043224227759523103135750598367138466343812753174552606754092270334606847959941471694973822828544uwb), 0x10000000000000000p+511L, 0xffffffffffffffffp+511L, 0x10000000000000000p+511L, 0xffffffffffffffffp+511L);
+  check_round (testldblu_575 (123665200736552267026899308527337945742672168301054458425161686591300514208835043224227759523103135750598367138466343812753174552606754092270334606847959941471694973822828545uwb), 0x10000000000000000p+511L, 0xffffffffffffffffp+511L, 0x10000000000000000p+511L, 0xffffffffffffffffp+511L);
+  check_round (testldblu_575 (123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb), 0x10000000000000000p+511L, 0xffffffffffffffffp+511L, 0x10000000000000000p+511L, 0xffffffffffffffffp+511L);
+#endif
+#endif
+#if __FLT128_MANT_DIG__, 113
+#if __BITINT_MAXWIDTH__ >= 135
+  check_round (testflt128_135 (-21646332438261169091754659013488783917055wb), -0x1fce71fdcfb1797b42dede66ac9ecp+21F128, -0x1fce71fdcfb1797b42dede66ac9edp+21F128, -0x1fce71fdcfb1797b42dede66ac9ecp+21F128, -0x1fce71fdcfb1797b42dede66ac9ecp+21F128);
+  check_round (testflt128_135 (-21646332438261169091754659013488783917056wb), -0x1fce71fdcfb1797b42dede66ac9ecp+21F128, -0x1fce71fdcfb1797b42dede66ac9edp+21F128, -0x1fce71fdcfb1797b42dede66ac9ecp+21F128, -0x1fce71fdcfb1797b42dede66ac9ecp+21F128);
+  check_round (testflt128_135 (-21646332438261169091754659013488783917057wb), -0x1fce71fdcfb1797b42dede66ac9edp+21F128, -0x1fce71fdcfb1797b42dede66ac9edp+21F128, -0x1fce71fdcfb1797b42dede66ac9ecp+21F128, -0x1fce71fdcfb1797b42dede66ac9ecp+21F128);
+  check_round_same (testflt128_135 (-21646332438261169091754659013488784965632wb), -0x1fce71fdcfb1797b42dede66ac9edp+21F128);
+  check_round (testflt128_135 (-21646332438261169091754659013488786014207wb), -0x1fce71fdcfb1797b42dede66ac9edp+21F128, -0x1fce71fdcfb1797b42dede66ac9eep+21F128, -0x1fce71fdcfb1797b42dede66ac9edp+21F128, -0x1fce71fdcfb1797b42dede66ac9edp+21F128); 
+  check_round (testflt128_135 (-21646332438261169091754659013488786014208wb), -0x1fce71fdcfb1797b42dede66ac9eep+21F128, -0x1fce71fdcfb1797b42dede66ac9eep+21F128, -0x1fce71fdcfb1797b42dede66ac9edp+21F128, -0x1fce71fdcfb1797b42dede66ac9edp+21F128);
+  check_round (testflt128_135 (-21646332438261169091754659013488786014209wb), -0x1fce71fdcfb1797b42dede66ac9eep+21F128, -0x1fce71fdcfb1797b42dede66ac9eep+21F128, -0x1fce71fdcfb1797b42dede66ac9edp+21F128, -0x1fce71fdcfb1797b42dede66ac9edp+21F128);
+  check_round (testflt128u_135 (21646332438261169091754659013488783917055uwb), 0x1fce71fdcfb1797b42dede66ac9ecp+21F128, 0x1fce71fdcfb1797b42dede66ac9ecp+21F128, 0x1fce71fdcfb1797b42dede66ac9edp+21F128, 0x1fce71fdcfb1797b42dede66ac9ecp+21F128);
+  check_round (testflt128u_135 (21646332438261169091754659013488783917056uwb), 0x1fce71fdcfb1797b42dede66ac9ecp+21F128, 0x1fce71fdcfb1797b42dede66ac9ecp+21F128, 0x1fce71fdcfb1797b42dede66ac9edp+21F128, 0x1fce71fdcfb1797b42dede66ac9ecp+21F128);
+  check_round (testflt128u_135 (21646332438261169091754659013488783917057uwb), 0x1fce71fdcfb1797b42dede66ac9edp+21F128, 0x1fce71fdcfb1797b42dede66ac9ecp+21F128, 0x1fce71fdcfb1797b42dede66ac9edp+21F128, 0x1fce71fdcfb1797b42dede66ac9ecp+21F128);
+  check_round_same (testflt128u_135 (21646332438261169091754659013488784965632uwb), 0x1fce71fdcfb1797b42dede66ac9edp+21F128);
+  check_round (testflt128u_135 (21646332438261169091754659013488786014207uwb), 0x1fce71fdcfb1797b42dede66ac9edp+21F128, 0x1fce71fdcfb1797b42dede66ac9edp+21F128, 0x1fce71fdcfb1797b42dede66ac9eep+21F128, 0x1fce71fdcfb1797b42dede66ac9edp+21F128);
+  check_round (testflt128u_135 (21646332438261169091754659013488786014208uwb), 0x1fce71fdcfb1797b42dede66ac9eep+21F128, 0x1fce71fdcfb1797b42dede66ac9edp+21F128, 0x1fce71fdcfb1797b42dede66ac9eep+21F128, 0x1fce71fdcfb1797b42dede66ac9edp+21F128);
+  check_round (testflt128u_135 (21646332438261169091754659013488786014209uwb), 0x1fce71fdcfb1797b42dede66ac9eep+21F128, 0x1fce71fdcfb1797b42dede66ac9edp+21F128, 0x1fce71fdcfb1797b42dede66ac9eep+21F128, 0x1fce71fdcfb1797b42dede66ac9edp+21F128);
+#endif
+#if __BITINT_MAXWIDTH__ >= 192
+  check_round_same (testflt128_192 (3138550867693340381917894711603832905819722818574723579904wb), 0x1ffffffffffffffffffffffffffffp+78F128);
+  check_round (testflt128_192 (3138550867693340381917894711603833056935450270403370418175wb), 0x1ffffffffffffffffffffffffffffp+78F128, 0x1ffffffffffffffffffffffffffffp+78F128, 0x20000000000000000000000000000p+78F128, 0x1ffffffffffffffffffffffffffffp+78F128);
+  check_round (testflt128_192 (3138550867693340381917894711603833056935450270403370418176wb), 0x20000000000000000000000000000p+78F128, 0x1ffffffffffffffffffffffffffffp+78F128, 0x20000000000000000000000000000p+78F128, 0x1ffffffffffffffffffffffffffffp+78F128);
+  check_round (testflt128_192 (3138550867693340381917894711603833056935450270403370418177wb), 0x20000000000000000000000000000p+78F128, 0x1ffffffffffffffffffffffffffffp+78F128, 0x20000000000000000000000000000p+78F128, 0x1ffffffffffffffffffffffffffffp+78F128);
+  check_round (testflt128_192 (3138550867693340381917894711603833208051177722232017256447wb), 0x20000000000000000000000000000p+78F128, 0x1ffffffffffffffffffffffffffffp+78F128, 0x20000000000000000000000000000p+78F128, 0x1ffffffffffffffffffffffffffffp+78F128);
+  check_round_same (testflt128u_192 (6277101735386680763835789423207665811639445637149447159808uwb), 0x1ffffffffffffffffffffffffffffp+79F128);
+  check_round (testflt128u_192 (6277101735386680763835789423207666113870900540806740836351uwb), 0x1ffffffffffffffffffffffffffffp+79F128, 0x1ffffffffffffffffffffffffffffp+79F128, 0x20000000000000000000000000000p+79F128, 0x1ffffffffffffffffffffffffffffp+79F128);
+  check_round (testflt128u_192 (6277101735386680763835789423207666113870900540806740836352uwb), 0x20000000000000000000000000000p+79F128, 0x1ffffffffffffffffffffffffffffp+79F128, 0x20000000000000000000000000000p+79F128, 0x1ffffffffffffffffffffffffffffp+79F128);
+  check_round (testflt128u_192 (6277101735386680763835789423207666113870900540806740836353uwb), 0x20000000000000000000000000000p+79F128, 0x1ffffffffffffffffffffffffffffp+79F128, 0x20000000000000000000000000000p+79F128, 0x1ffffffffffffffffffffffffffffp+79F128);
+  check_round (testflt128u_192 (6277101735386680763835789423207666416102355444464034512895uwb), 0x20000000000000000000000000000p+79F128, 0x1ffffffffffffffffffffffffffffp+79F128, 0x20000000000000000000000000000p+79F128, 0x1ffffffffffffffffffffffffffffp+79F128);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_round_same (testflt128_575 (-39695651458311907436978914487787846289740055435765388813682045155135192382154626611682813571487190641804615256990296246545713518740501887218789991403746059512699763279527936wb), -0x148b25ce53790ddc343a80e5af6bap+461F128);
+  check_round (testflt128_575 (-39695651458311907436978914487787849266871470150571212503712362264401765094669639986937588484471046485703139369468190190624257242316066424102078490670010875270428034085158911wb), -0x148b25ce53790ddc343a80e5af6bap+461F128, -0x148b25ce53790ddc343a80e5af6bbp+461F128, -0x148b25ce53790ddc343a80e5af6bap+461F128, -0x148b25ce53790ddc343a80e5af6bap+461F128);
+  check_round (testflt128_575 (-39695651458311907436978914487787849266871470150571212503712362264401765094669639986937588484471046485703139369468190190624257242316066424102078490670010875270428034085158912wb), -0x148b25ce53790ddc343a80e5af6bap+461F128, -0x148b25ce53790ddc343a80e5af6bbp+461F128, -0x148b25ce53790ddc343a80e5af6bap+461F128, -0x148b25ce53790ddc343a80e5af6bap+461F128);
+  check_round (testflt128_575 (-39695651458311907436978914487787849266871470150571212503712362264401765094669639986937588484471046485703139369468190190624257242316066424102078490670010875270428034085158913wb), -0x148b25ce53790ddc343a80e5af6bbp+461F128, -0x148b25ce53790ddc343a80e5af6bbp+461F128, -0x148b25ce53790ddc343a80e5af6bap+461F128, -0x148b25ce53790ddc343a80e5af6bap+461F128);
+  check_round_same (testflt128_575 (-39695651458311907436978914487787852244002884865377036193742679373668337807184653362192363397454902329601663481946084134702800965891630960985366989936275691028156304890789888wb), -0x148b25ce53790ddc343a80e5af6bbp+461F128);
+  check_round (testflt128_575 (-39695651458311907436978914487787855221134299580182859883772996482934910519699666737447138310438758173500187594423978078781344689467195497868655489202540506785884575696420863wb), -0x148b25ce53790ddc343a80e5af6bbp+461F128, -0x148b25ce53790ddc343a80e5af6bcp+461F128, -0x148b25ce53790ddc343a80e5af6bbp+461F128, -0x148b25ce53790ddc343a80e5af6bbp+461F128);
+  check_round (testflt128_575 (-39695651458311907436978914487787855221134299580182859883772996482934910519699666737447138310438758173500187594423978078781344689467195497868655489202540506785884575696420864wb), -0x148b25ce53790ddc343a80e5af6bcp+461F128, -0x148b25ce53790ddc343a80e5af6bcp+461F128, -0x148b25ce53790ddc343a80e5af6bbp+461F128, -0x148b25ce53790ddc343a80e5af6bbp+461F128);
+  check_round (testflt128_575 (-39695651458311907436978914487787855221134299580182859883772996482934910519699666737447138310438758173500187594423978078781344689467195497868655489202540506785884575696420865wb), -0x148b25ce53790ddc343a80e5af6bcp+461F128, -0x148b25ce53790ddc343a80e5af6bcp+461F128, -0x148b25ce53790ddc343a80e5af6bbp+461F128, -0x148b25ce53790ddc343a80e5af6bbp+461F128);
+  check_round_same (testflt128_575 (-61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1), -0x20000000000000000000000000000p+461F128);
+  check_round_same (testflt128u_575 (79391302916623814873957828975575692579480110871530777627364090310270384764309253223365627142974381283609230513980592493091427037481003774437579982807492119025399526559055872uwb), 0x148b25ce53790ddc343a80e5af6bap+462F128);
+  check_round (testflt128u_575 (79391302916623814873957828975575698533742940301142425007424724528803530189339279973875176968942092971406278738936380381248514484632132848204156981340021750540856068170317823uwb), 0x148b25ce53790ddc343a80e5af6bap+462F128, 0x148b25ce53790ddc343a80e5af6bap+462F128, 0x148b25ce53790ddc343a80e5af6bbp+462F128, 0x148b25ce53790ddc343a80e5af6bap+462F128);
+  check_round (testflt128u_575 (79391302916623814873957828975575698533742940301142425007424724528803530189339279973875176968942092971406278738936380381248514484632132848204156981340021750540856068170317824uwb), 0x148b25ce53790ddc343a80e5af6bap+462F128, 0x148b25ce53790ddc343a80e5af6bap+462F128, 0x148b25ce53790ddc343a80e5af6bbp+462F128, 0x148b25ce53790ddc343a80e5af6bap+462F128);
+  check_round (testflt128u_575 (79391302916623814873957828975575698533742940301142425007424724528803530189339279973875176968942092971406278738936380381248514484632132848204156981340021750540856068170317825uwb), 0x148b25ce53790ddc343a80e5af6bbp+462F128, 0x148b25ce53790ddc343a80e5af6bap+462F128, 0x148b25ce53790ddc343a80e5af6bbp+462F128, 0x148b25ce53790ddc343a80e5af6bap+462F128);
+  check_round_same (testflt128u_575 (79391302916623814873957828975575704488005769730754072387485358747336675614369306724384726794909804659203326963892168269405601931783261921970733979872551382056312609781579776uwb), 0x148b25ce53790ddc343a80e5af6bbp+462F128);
+  check_round (testflt128u_575 (79391302916623814873957828975575710442268599160365719767545992965869821039399333474894276620877516347000375188847956157562689378934390995737310978405081013571769151392841727uwb), 0x148b25ce53790ddc343a80e5af6bbp+462F128, 0x148b25ce53790ddc343a80e5af6bbp+462F128, 0x148b25ce53790ddc343a80e5af6bcp+462F128, 0x148b25ce53790ddc343a80e5af6bbp+462F128);
+  check_round (testflt128u_575 (79391302916623814873957828975575710442268599160365719767545992965869821039399333474894276620877516347000375188847956157562689378934390995737310978405081013571769151392841728uwb), 0x148b25ce53790ddc343a80e5af6bcp+462F128, 0x148b25ce53790ddc343a80e5af6bbp+462F128, 0x148b25ce53790ddc343a80e5af6bcp+462F128, 0x148b25ce53790ddc343a80e5af6bbp+462F128);
+  check_round (testflt128u_575 (79391302916623814873957828975575710442268599160365719767545992965869821039399333474894276620877516347000375188847956157562689378934390995737310978405081013571769151392841729uwb), 0x148b25ce53790ddc343a80e5af6bcp+462F128, 0x148b25ce53790ddc343a80e5af6bbp+462F128, 0x148b25ce53790ddc343a80e5af6bcp+462F128, 0x148b25ce53790ddc343a80e5af6bbp+462F128);
+  check_round (testflt128u_575 (123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb), 0x20000000000000000000000000000p+462F128, 0x1ffffffffffffffffffffffffffffp+462F128, 0x20000000000000000000000000000p+462F128, 0x1ffffffffffffffffffffffffffffp+462F128);
+#endif
+#endif
+#endif
+}
--- gcc/testsuite/gcc.dg/dfp/bitint-1.c.jj	2023-09-04 09:45:47.076866859 +0200
+++ gcc/testsuite/gcc.dg/dfp/bitint-1.c	2023-09-04 10:52:48.625174662 +0200
@@ -37,6 +37,8 @@ main ()
   if (tests192 (0.DD) != 0wb
       || tests192 (0.9999999999999999DD) != 0wb
       || tests192 (7.999999999999999DD) != 7wb
+      || tests192 (-0.DD) != 0wb
+      || tests192 (-0.9999999999999999DD) != 0wb
       || tests192 (-42.5DD) != -42wb
       || tests192 (-34242319854.45429e+27DD) != -34242319854454290000000000000000000000wb
       || tests192 (-213855087769445.9e+43DD) != -2138550877694459000000000000000000000000000000000000000000wb
@@ -51,6 +53,7 @@ main ()
   if (testu192 (0.DD) != 0uwb
       || testu192 (0.9999999999999999DD) != 0uwb
       || testu192 (-0.9999999999999999DD) != 0uwb
+      || testu192 (-0.0DD) != 0uwb
       || testu192 (-0.5DD) != 0uwb
       || testu192 (42.99999999999999DD) != 42uwb
       || testu192 (42.e+21DD) != 42000000000000000000000uwb
@@ -68,6 +71,9 @@ main ()
   if (tests575 (0.DD) != 0wb
       || tests575 (0.999999DD) != 0wb
       || tests575 (12.9999999999999DD) != 12wb
+      || tests575 (-0.DD) != 0wb
+      || tests575 (-0.9999999999999999DD) != 0wb
+      || tests575 (-1.DD) != -1wb
       || tests575 (-89.5DD) != -89wb
       || tests575 (-34242319854.45429e+37DD) != -342423198544542900000000000000000000000000000000wb
       || tests575 (-518326003682761.2e+158DD) != -51832600368276120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000wb
@@ -83,6 +89,8 @@ main ()
       || testu575 (0.5555555555555555DD) != 0uwb
       || testu575 (-0.7777777777777777DD) != 0uwb
       || testu575 (-0.99DD) != 0uwb
+      || testu575 (-0.000DD) != 0uwb
+      || testu575 (-0.99999999DD) != 0uwb
       || testu575 (42.99999999999999DD) != 42uwb
       || testu575 (42.e+21DD) != 42000000000000000000000uwb
       || testu575 (94272319854.45429e+27DD) != 94272319854454290000000000000000000000uwb
--- gcc/testsuite/gcc.dg/dfp/bitint-2.c.jj	2023-09-04 09:45:47.076866859 +0200
+++ gcc/testsuite/gcc.dg/dfp/bitint-2.c	2023-09-04 10:56:05.779431014 +0200
@@ -37,6 +37,9 @@ main ()
   if (tests192 (0.DF) != 0wb
       || tests192 (0.9999999DF) != 0wb
       || tests192 (7.999999DF) != 7wb
+      || tests192 (-0.000DF) != 0wb
+      || tests192 (-0.9999999DF) != 0wb
+      || tests192 (-1.DF) != -1wb
       || tests192 (-42.5DF) != -42wb
       || tests192 (-3424.231e+27DF) != -3424231000000000000000000000000wb
       || tests192 (-213855.9e+43DF) != -2138559000000000000000000000000000000000000000000wb
@@ -52,6 +55,8 @@ main ()
       || testu192 (0.9999999DF) != 0uwb
       || testu192 (-0.9999999DF) != 0uwb
       || testu192 (-0.5DF) != 0uwb
+      || testu192 (-0.0000DF) != 0uwb
+      || testu192 (-0.99999DF) != 0uwb
       || testu192 (42.99999DF) != 42uwb
       || testu192 (42.e+21DF) != 42000000000000000000000uwb
       || testu192 (3427.231e+29DF) != 342723100000000000000000000000000uwb
@@ -68,6 +73,9 @@ main ()
   if (tests575 (0.DF) != 0wb
       || tests575 (0.999999DF) != 0wb
       || tests575 (12.9999DF) != 12wb
+      || tests575 (-0.DF) != 0wb
+      || tests575 (-0.999DF) != 0wb
+      || tests575 (-1.0000DF) != -1wb
       || tests575 (-89.5DF) != -89wb
       || tests575 (-34242.31e+37DF) != -342423100000000000000000000000000000000000wb
       || tests575 (-518326.2e+88DF) != -5183262000000000000000000000000000000000000000000000000000000000000000000000000000000000000000wb
@@ -78,6 +86,9 @@ main ()
       || testu575 (0.5555555DF) != 0uwb
       || testu575 (-0.7777777DF) != 0uwb
       || testu575 (-0.99DF) != 0uwb
+      || testu575 (-0.DF) != 0uwb
+      || testu575 (-0.7777777DF) != 0uwb
+      || testu575 (-0.9999999DF) != 0uwb
       || testu575 (42.99999DF) != 42uwb
       || testu575 (42.e+21DF) != 42000000000000000000000uwb
       || testu575 (9427.231e+27DF) != 9427231000000000000000000000000uwb
--- gcc/testsuite/gcc.dg/dfp/bitint-3.c.jj	2023-09-04 09:45:47.076866859 +0200
+++ gcc/testsuite/gcc.dg/dfp/bitint-3.c	2023-09-04 11:04:29.181425571 +0200
@@ -37,6 +37,9 @@ main ()
   if (tests192 (0.DL) != 0wb
       || tests192 (0.9999999999999999999999999999999999DL) != 0wb
       || tests192 (7.999999999999999999999999999999999DL) != 7wb
+      || tests192 (-0.DL) != 0wb
+      || tests192 (-0.9999999999999999999999999999999999DL) != 0wb
+      || tests192 (-1.DL) != -1wb
       || tests192 (-42.5DL) != -42wb
       || tests192 (-34242319854.45429439857871298745432e+27DL) != -34242319854454294398578712987454320000wb
       || tests192 (-213855087769445.9e+43DL) != -2138550877694459000000000000000000000000000000000000000000wb
@@ -51,6 +54,8 @@ main ()
   if (testu192 (0.DL) != 0uwb
       || testu192 (0.9999999999999999999999999999999999DL) != 0uwb
       || testu192 (-0.9999999999999999999999999999999999DL) != 0uwb
+      || testu192 (-0.DL) != 0uwb
+      || testu192 (-0.9999999999999999999999DL) != 0uwb
       || testu192 (-0.5DL) != 0uwb
       || testu192 (42.99999999999999999999999999999999DL) != 42uwb
       || testu192 (42.e+21DL) != 42000000000000000000000uwb
@@ -68,6 +73,9 @@ main ()
   if (tests575 (0.DL) != 0wb
       || tests575 (0.999999999999999999999DL) != 0wb
       || tests575 (12.99999999999999999999999999999DL) != 12wb
+      || tests575 (-0.0000000000DL) != 0wb
+      || tests575 (-0.9999999999999999999999999999999999DL) != 0uwb
+      || tests575 (-1.DL) != -1wb
       || tests575 (-89.5DL) != -89wb
       || tests575 (-34242319854.45429986754986758972345e+37DL) != -342423198544542998675498675897234500000000000000wb
       || tests575 (-518326003682761.2e+158DL) != -51832600368276120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000wb
@@ -83,6 +91,7 @@ main ()
       || testu575 (0.5555555555555555555555555555555555DL) != 0uwb
       || testu575 (-0.7777777777777777777777777777777777DL) != 0uwb
       || testu575 (-0.99DL) != 0uwb
+      || testu575 (-0.00000000000DL) != 0uwb
       || testu575 (42.99999999999999999999999999999999DL) != 42uwb
       || testu575 (42.e+21DL) != 42000000000000000000000uwb
       || testu575 (94272319854.45429e+27DL) != 94272319854454290000000000000000000000uwb
--- gcc/testsuite/gcc.dg/dfp/bitint-7.c.jj	2023-09-04 12:05:08.838925401 +0200
+++ gcc/testsuite/gcc.dg/dfp/bitint-7.c	2023-09-04 12:05:30.203626858 +0200
@@ -0,0 +1,110 @@
+/* PR c/102989 */
+/* Test non-canonical BID significands.  */
+/* { dg-do run { target bitint } } */
+/* { dg-require-effective-target dfp_bid } */
+/* { dg-options "-std=gnu2x -O2" } */
+
+union U32
+{
+  _Decimal32 d;
+  unsigned int u;
+};
+
+union U64
+{
+  _Decimal64 d;
+  unsigned long long int u;
+};
+
+union U128
+{
+  _Decimal128 d;
+  unsigned long long int u[2];
+};
+
+int
+main ()
+{
+  volatile union U32 u32;
+  u32.d = 0.9999999e+27DF;
+  u32.u++;
+  volatile union U64 u64;
+  u64.d = 0.9999999999999999e+90DD;
+  u64.u++;
+  volatile union U128 u128;
+  u128.d = 0.9999999999999999999999999999999999e+39DL;
+  if (u128.u[0] == 0x378d8e63ffffffffULL)
+    u128.u[0]++;
+  else if (u128.u[1] == 0x378d8e63ffffffffULL)
+    u128.u[1]++;
+  else
+    u128.d = 0.DL;
+#if __BITINT_MAXWIDTH__ >= 192
+  if ((_BitInt(192)) u32.d != 0wb
+      || (unsigned _BitInt(192)) u32.d != 0uwb
+      || (_BitInt(192)) u64.d != 0wb
+      || (unsigned _BitInt(192)) u64.d != 0uwb
+      || (_BitInt(192)) u128.d != 0wb
+      || (unsigned _BitInt(192)) u128.d != 0uwb)
+    __builtin_abort ();
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  if ((_BitInt(575)) u32.d != 0wb
+      || (unsigned _BitInt(575)) u32.d != 0uwb
+      || (_BitInt(575)) u64.d != 0wb
+      || (unsigned _BitInt(575)) u64.d != 0uwb
+      || (_BitInt(575)) u128.d != 0wb
+      || (unsigned _BitInt(575)) u128.d != 0uwb)
+    __builtin_abort ();
+#endif
+  u32.u = 0xe59fffffU;
+  u64.u = 0xe3ffffffffffffffULL;
+  if (u128.u[0] == 0x378d8e6400000000ULL)
+    {
+      u128.u[0] = -1ULL;
+      u128.u[1] = 0xe1be7fffffffffffULL;
+    }
+  else if (u128.u[1] == 0x378d8e6400000000ULL)
+    {
+      u128.u[1] = -1ULL;
+      u128.u[0] = 0xe1be7fffffffffffULL;
+    }
+#if __BITINT_MAXWIDTH__ >= 192
+  if ((_BitInt(192)) u32.d != 0wb
+      || (unsigned _BitInt(192)) u32.d != 0uwb
+      || (_BitInt(192)) u64.d != 0wb
+      || (unsigned _BitInt(192)) u64.d != 0uwb
+      || (_BitInt(192)) u128.d != 0wb
+      || (unsigned _BitInt(192)) u128.d != 0uwb)
+    __builtin_abort ();
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  if ((_BitInt(575)) u32.d != 0wb
+      || (unsigned _BitInt(575)) u32.d != 0uwb
+      || (_BitInt(575)) u64.d != 0wb
+      || (unsigned _BitInt(575)) u64.d != 0uwb
+      || (_BitInt(575)) u128.d != 0wb
+      || (unsigned _BitInt(575)) u128.d != 0uwb)
+    __builtin_abort ();
+#endif
+  if (u128.u[0] == -1ULL)
+    {
+      u128.u[0] = 0;
+      u128.u[1] = 0xe629800000000000ULL;
+    }
+  else if (u128.u[1] == -1ULL)
+    {
+      u128.u[1] = 0;
+      u128.u[0] = 0xe629800000000000ULL;
+    }
+#if __BITINT_MAXWIDTH__ >= 192
+  if ((_BitInt(192)) u128.d != 0wb
+      || (unsigned _BitInt(192)) u128.d != 0uwb)
+    __builtin_abort ();
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  if ((_BitInt(575)) u128.d != 0wb
+      || (unsigned _BitInt(575)) u128.d != 0uwb)
+    __builtin_abort ();
+#endif
+}
--- gcc/testsuite/gcc.dg/dfp/bitint-8.c.jj	2023-09-04 20:51:21.864357476 +0200
+++ gcc/testsuite/gcc.dg/dfp/bitint-8.c	2023-09-04 21:32:20.255674946 +0200
@@ -0,0 +1,182 @@
+/* PR c/102989 */
+/* { dg-do run { target bitint } } */
+/* { dg-require-effective-target fenv_exceptions } */
+/* { dg-options "-std=c2x" } */
+
+#include <fenv.h>
+
+#if __BITINT_MAXWIDTH__ >= 192
+__attribute__((noipa)) _BitInt(192)
+tests192_32 (_Decimal32 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(192)
+testu192_32 (_Decimal32 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) _BitInt(192)
+tests192_64 (_Decimal64 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(192)
+testu192_64 (_Decimal64 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) _BitInt(192)
+tests192_128 (_Decimal128 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(192)
+testu192_128 (_Decimal128 d)
+{
+  return d;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 575
+__attribute__((noipa)) _BitInt(575)
+tests575_32 (_Decimal32 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(575)
+testu575_32 (_Decimal32 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) _BitInt(575)
+tests575_64 (_Decimal64 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(575)
+testu575_64 (_Decimal64 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) _BitInt(575)
+tests575_128 (_Decimal128 d)
+{
+  return d;
+}
+
+__attribute__((noipa)) unsigned _BitInt(575)
+testu575_128 (_Decimal128 d)
+{
+  return d;
+}
+#endif
+
+__attribute__((noipa)) void
+check_invalid (int test, int inv)
+{
+  if (!test)
+    __builtin_abort ();
+  if ((!fetestexcept (FE_INVALID)) != (!inv))
+    __builtin_abort ();
+  feclearexcept (FE_INVALID);
+}
+
+int
+main ()
+{
+#if __BITINT_MAXWIDTH__ >= 192
+  check_invalid (tests192_32 (__builtin_infd32 ()) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (tests192_32 (-__builtin_infd32 ()) == -3138550867693340381917894711603833208051177722232017256447wb - 1wb, 1);
+  check_invalid (tests192_32 (__builtin_nand32 ("")) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (tests192_32 (-313855.0e+52DF) == -3138550000000000000000000000000000000000000000000000000000wb, 0);
+  check_invalid (tests192_32 (-313855.1e+52DF) == -3138550867693340381917894711603833208051177722232017256447wb - 1wb, 1);
+  check_invalid (tests192_32 (313855.0e+52DF) == 3138550000000000000000000000000000000000000000000000000000wb, 0);
+  check_invalid (tests192_32 (313855.1e+52DF) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (testu192_32 (__builtin_infd32 ()) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (testu192_32 (-__builtin_infd32 ()) == 0uwb, 1);
+  check_invalid (testu192_32 (__builtin_nand32 ("")) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (testu192_32 (-0.9999999DF) == 0uwb, 0);
+  check_invalid (testu192_32 (-1.0DF) == 0uwb, 1);
+  check_invalid (testu192_32 (6277101.0e+51DF) == 6277101000000000000000000000000000000000000000000000000000uwb, 0);
+  check_invalid (testu192_32 (6277102.0e+51DF) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (tests192_64 (__builtin_infd64 ()) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (tests192_64 (-__builtin_infd64 ()) == -3138550867693340381917894711603833208051177722232017256447wb - 1wb, 1);
+  check_invalid (tests192_64 (__builtin_nand64 ("")) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (tests192_64 (-313855086769334.0e+43DD) == -3138550867693340000000000000000000000000000000000000000000wb, 0);
+  check_invalid (tests192_64 (-313855086769334.1e+43DD) == -3138550867693340381917894711603833208051177722232017256447wb - 1wb, 1);
+  check_invalid (tests192_64 (313855086769334.0e+43DD) == 3138550867693340000000000000000000000000000000000000000000wb, 0);
+  check_invalid (tests192_64 (313855086769334.1e+43DD) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (testu192_64 (__builtin_infd64 ()) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (testu192_64 (-__builtin_infd64 ()) == 0wb, 1);
+  check_invalid (testu192_64 (__builtin_nand64 ("")) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (testu192_64 (-0.9999999999999999DD) == 0uwb, 0);
+  check_invalid (testu192_64 (-1.0DD) == 0uwb, 1);
+  check_invalid (testu192_64 (627710173538668.0e+43DD) == 6277101735386680000000000000000000000000000000000000000000uwb, 0);
+  check_invalid (testu192_64 (627710173538668.1e+43DD) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (tests192_128 (__builtin_infd128 ()) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (tests192_128 (-__builtin_infd128 ()) == -3138550867693340381917894711603833208051177722232017256447wb - 1wb, 1);
+  check_invalid (tests192_128 (__builtin_nand128 ("")) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (tests192_128 (-3138550867693340381917894711603833.0e+24DL) == -3138550867693340381917894711603833000000000000000000000000wb, 0);
+  check_invalid (tests192_128 (-3138550867693340381917894711603834.0e+24DL) == -3138550867693340381917894711603833208051177722232017256447wb - 1wb, 1);
+  check_invalid (tests192_128 (3138550867693340381917894711603833.0e+24DL) == 3138550867693340381917894711603833000000000000000000000000wb, 0);
+  check_invalid (tests192_128 (3138550867693340381917894711603834.0e+24DL) == 3138550867693340381917894711603833208051177722232017256447wb, 1);
+  check_invalid (testu192_128 (__builtin_infd128 ()) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (testu192_128 (-__builtin_infd128 ()) == 0wb, 1);
+  check_invalid (testu192_128 (__builtin_nand128 ("")) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+  check_invalid (testu192_128 (-0.9999999999999999999999999999999999DL) == 0uwb, 0);
+  check_invalid (testu192_128 (-1.0DL) == 0uwb, 1);
+  check_invalid (testu192_128 (6277101735386680763835789423207666.0e+24DL) == 6277101735386680763835789423207666000000000000000000000000uwb, 0);
+  check_invalid (testu192_128 (6277101735386680763835789423207667.0e+24DL) == 6277101735386680763835789423207666416102355444464034512895uwb, 1);
+#endif
+#if __BITINT_MAXWIDTH__ >= 575
+  check_invalid (tests575_32 (__builtin_infd32 ()) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (tests575_32 (-__builtin_infd32 ()) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb, 1);
+  check_invalid (tests575_32 (__builtin_nand32 ("")) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (tests575_32 (-9999999e+90DF) == -9999999000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000wb, 0);
+  check_invalid (tests575_32 (9999999e+90DF) == 9999999000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000wb, 0);
+  check_invalid (testu575_32 (__builtin_infd32 ()) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (testu575_32 (-__builtin_infd32 ()) == 0uwb, 1);
+  check_invalid (testu575_32 (__builtin_nand32 ("")) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (testu575_32 (-0.9999999DF) == 0uwb, 0);
+  check_invalid (testu575_32 (-1.0DF) == 0uwb, 1);
+  check_invalid (testu575_32 (9999999e+90DF) == 9999999000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000uwb, 0);
+  check_invalid (tests575_64 (__builtin_infd64 ()) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (tests575_64 (-__builtin_infd64 ()) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb, 1);
+  check_invalid (tests575_64 (__builtin_nand64 ("")) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (tests575_64 (-6183260036827613.0e+157DD) == -61832600368276130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000wb, 0);
+  check_invalid (tests575_64 (-6183260036827614.0e+157DD) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb, 1);
+  check_invalid (tests575_64 (6183260036827613.0e+157DD) == 61832600368276130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000wb, 0);
+  check_invalid (tests575_64 (6183260036827614.0e+157DD) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (testu575_64 (__builtin_infd64 ()) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (testu575_64 (-__builtin_infd64 ()) == 0wb, 1);
+  check_invalid (testu575_64 (__builtin_nand64 ("")) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (testu575_64 (-0.9999999999999999DD) == 0uwb, 0);
+  check_invalid (testu575_64 (-1.0DD) == 0uwb, 1);
+  check_invalid (testu575_64 (1236652007365522.0e+158DD) == 123665200736552200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000uwb, 0);
+  check_invalid (testu575_64 (1236652007365523.0e+158DD) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (tests575_128 (__builtin_infd128 ()) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (tests575_128 (-__builtin_infd128 ()) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb, 1);
+  check_invalid (tests575_128 (__builtin_nand128 ("")) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (tests575_128 (-6183260036827613351512563025491179.0e+139DL) == -61832600368276133515125630254911790000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000wb, 0);
+  check_invalid (tests575_128 (-618326003682761335151256302549118.0e+140DL) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1wb, 1);
+  check_invalid (tests575_128 (6183260036827613351512563025491179.0e+139DL) == 61832600368276133515125630254911790000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000wb, 0);
+  check_invalid (tests575_128 (618326003682761335151256302549118.0e+140DL) == 61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb, 1);
+  check_invalid (testu575_128 (__builtin_infd128 ()) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (testu575_128 (-__builtin_infd128 ()) == 0wb, 1);
+  check_invalid (testu575_128 (__builtin_nand128 ("")) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+  check_invalid (testu575_128 (-0.9999999999999999999999999999999999DL) == 0uwb, 0);
+  check_invalid (testu575_128 (-1.0DL) == 0uwb, 1);
+  check_invalid (testu575_128 (1236652007365522670302512605098235.0e+140DL) == 123665200736552267030251260509823500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000uwb, 0);
+  check_invalid (testu575_128 (1236652007365522670302512605098236.0e+140DL) == 123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb, 1);
+#endif
+}

	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-04 19:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-09 18:23 [PATCH 9/12] libgcc _BitInt support [PR102989] Jakub Jelinek
2023-09-01 21:48 ` Joseph Myers
2023-09-02 11:42   ` Jakub Jelinek
2023-09-04 19:42   ` [PATCH 15/12] Add further _BitInt <-> floating point tests [PR102989] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).