From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 1F4983858D20 for ; Thu, 28 Sep 2023 14:04:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F4983858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695909850; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GOFZ6XsULsWwsGU2fxdsbC1C3f8bFNQstJS8w+yqvrI=; b=Y1XMFnw/Tr0QAyWNeKtzBy9Bg9qWmzmOBzdcvhGDFkoZoBpSmDw89D3iHMttegjsy2zEfK wQ92VQRPNrE1J1sR1kDrGdARrm4D/GsRewRmPj+bJ32EMbwhFXhmjfE5TCXfcSbeF/jMTq P1ZYAXVA41oRWjYjtSxjcm1HMlQMjpw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-153-zYoEp5xSOkWQRG79tVIpAg-1; Thu, 28 Sep 2023 10:04:07 -0400 X-MC-Unique: zYoEp5xSOkWQRG79tVIpAg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B0E6318172CC; Thu, 28 Sep 2023 14:04:00 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.202]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EDE01492C37; Thu, 28 Sep 2023 14:03:59 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 38SE3u4L2671621 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 28 Sep 2023 16:03:57 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 38SE3tWS2671620; Thu, 28 Sep 2023 16:03:55 +0200 Date: Thu, 28 Sep 2023 16:03:55 +0200 From: Jakub Jelinek To: Richard Biener , Richard Sandiford , Aldy Hernandez Cc: gcc-patches@gcc.gnu.org Subject: [RFC] > WIDE_INT_MAX_PREC support in wide_int and widest_int Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi! On Tue, Aug 29, 2023 at 05:09:52PM +0200, Jakub Jelinek via Gcc-patches wro= te: > On Tue, Aug 29, 2023 at 11:42:48AM +0100, Richard Sandiford wrote: > > > I'll note tree-ssa-loop-niter.cc also uses GMP in some cases, widest_= int > > > is really trying to be poor-mans GMP by limiting the maximum precisio= n. > >=20 > > I'd characterise widest_int as "a wide_int that is big enough to hold > > all supported integer types, without losing sign information". It's > > not big enough to do arbitrary arithmetic without losing precision > > (in the way that GMP is). > >=20 > > If the new limit on integer sizes is 65535 bits for all targets, > > then I think that means that widest_int needs to become a 65536-bit typ= e. > > (But not with all bits represented all the time, of course.) >=20 > If the widest_int storage would be dependent on the len rather than > precision for how it is stored, then I think we'd need a new method which > would be called at the start of filling the limbs where we'd tell how man= y > limbs there would be (i.e. what will set_len be called with later on), an= d > do nothing for all storages but the new widest_int_storage. So, I've spent some time on this. While wide_int is in the patch a fixed/v= ariable number of limbs (aka len) storage depending on precision (precision > WIDE_INT_MAX_PRECISION means heap allocated limb array, otherwise it is inline), widest_int has always very large precision (WIDEST_INT_MAX_PRECISION, currently defined to the INTEGER_CST imposed limitation of 255 64-bit limbs) but uses inline array for length corresponding up to WIDE_INT_MAX_PRECISION bits and for larger one uses similarly to wide_int a heap allocated array of limbs. These changes make both wide_int and widest_int obviously non-POD, not trivially default constructible, nor trivially copy constructible, triviall= y destructible, trivially copyable, so not a good fit for GC and some vec operations. One common use of wide_int in GC structures was in dwarf2out.{h,cc}; but as large _BitInt constants don't appear in RTL, we really don't need such larg= e precisions there. So, for wide_int the patch introduces rwide_int, restricted wide_int, which acts like the old wide_int (except that it is now trivially default constructible and has assertions precision isn't set above WIDE_INT_MAX_PRECISION). For widest_int, the nastiness is that because it always has huge precision of 16320 right now, a) we need to be told upfront in wide-int.h before calling the large value internal functions in wide-int.cc how many elements we'll need for the result (some reasonable upper estimate is fine) b) various of the wide-int.cc functions were lazy and assumed precision is small enough and often used up to that many elements, which is undesirable; so, it now tries to decreas that and use xi.len etc. based estimates instead if possible (sometimes only if precision is above WIDE_INT_MAX_PRECISION) c) with the higher precision, behavior changes for lrshift (-1, 2) etc. or unsigned division with dividend having most significant bit set in widest_int - while such values were considered to be above or equal to 1 << (WIDE_INT_MAX_PRECISION - 2), now they are with WIDEST_INT_MAX_PRECISION and so much larger; but lrshift on widest_int is I think only done in ccp and I'd strongly hope that we treat the values as unsigned and so usually much smaller length; so it is just when we call wi::lrshift (-1, 2) or similar that results change. I've noticed that for wide_int or widest_int references even simple operations like eq_p liked to allocate and immediately free huge buffers, which was caused by wide_int doing allocation on creation with a particular precision and e.g. get_binary_precision running into that. So, I've duplicated that to avoid the allocations when all we need is just a precision. The patch below doesn't actually build anymore since the vec.h asserts (which point to useful stuff though), so temporarily I've applied it also with --- gcc/vec.h.xx=092023-09-28 12:56:09.055786055 +0200 +++ gcc/vec.h=092023-09-28 13:15:31.760487111 +0200 @@ -1197,7 +1197,7 @@ template inline void vec::qsort (int (*cmp) (const void *, const void *)) { - static_assert (vec_detail::is_trivially_copyable_or_pair ::value, "")= ; +// static_assert (vec_detail::is_trivially_copyable_or_pair ::value, "= "); if (length () > 1) gcc_qsort (address (), length (), sizeof (T), cmp); } @@ -1422,7 +1422,7 @@ template void gt_ggc_mx (vec *v) { - static_assert (std::is_trivially_destructible ::value, ""); +// static_assert (std::is_trivially_destructible ::value, ""); extern void gt_ggc_mx (T &); for (unsigned i =3D 0; i < v->length (); i++) gt_ggc_mx ((*v)[i]); hack. The two spots that trigger are tree-ssa-loop-niter.cc doing qsort on widest_int vector (to be exact, swapping elements in the vector of widest_int or wide_int by memcpy actually would work, the reason it has non-trivial destructor and copy assignment/copy constructor is to make sure distinct objects have (if needed) distinct heap allocations and that those are freed in the end, but the bitwise memcpy swapping preserves that), and omp_general.cc using two widest_int members in a GC structure. For some reason, a more important problem isn't diagnosed, loop and nb_iter_bound structs (also GC) having widest_int members (first one 2, second one just one). And then there is e.g. another issue with slsr, which allocates structs containing widest_int in obstack, not expecting it would need to construct those (and where to destruct them). Also, ipa_bits contains 2 widest_int members in GC allocated structure. Actually the reason is quite obvious, my assert has been added just for GC vec of non-trivially destructible types, neither loop, nor ipa_bits are used in vectors. Bet we should make wide_int_storage and widest_int_storage GTY ((user)) and just declare but don't define the handlers or something similar. And, now the question is what to do about this. I guess for omp_general I could just use generic_wide_int > or something similar, after all the widest_int wasn't really great when it had maximum precision of WIDE_INT_MAX_PRECISION, different values on different targets, it has very few uses and is easy to change (thinking about this, makes me wonder what we do for offloading if offload host has different WIDE_INT_MAX_PRECISION from offload target). But the more important question is what to do about loop/niters analysis. I think for number of iteration analysis it might be ok to punt somehow (if there is a way to tell that number of iterations is unknown) if we get some bound which is too large to be expressible in some reasonably smal= l fixed precision (whether it is WIDE_INT_MAX_PRECISION, or something different is a question). We could either introduce yet another widest_int like storage which would have still WIDEST_INT_MAX_PRECISION precision, but would ICE if length is set to something above its fixed width. One problem is that the write_val estimations are often just conservatively larger and could trigger even if the value fits in the end. Or we could use generic_wide_int > (perhap= s call that rwidest_int), the drawback would be that it would be slightly har= der to use as it has different precision from widest_int, we'd need to do some from on it or the like. Plus I really don't know the niters code to know how to punt. ipa_bits is even worse, because unlike niter analysis, I think it is very much desirable to support IPA VRP of all supported _BitInt sizes. Shall we perhaps use trailing_wide_int storage in there, or conditionally rwidest_int vs. INTEGER_CSTs for stuff that doesn't fit, something else? What about slsr? This is after bitint lowering, so it shouldn't be performing opts on larger BITINT_TYPEs and so could also go with the rwidest_int. With the above vec.h hack the short (in number of lines, otherwise it is large, each 16319 bit decimal constant is huge) testcase below works, but even make check-gcc RUNTESTFLAGS=3Ddg.exp=3Dbitint* (i.e. the compile o= nly tests) show some ICEs, some of them due to widest_int in loop, others in slsr, others to be debugged. As for the qsort in niters, if we change niters to use some rwidest_int, either fixed or something new, then the sorting problem could go away. Another option would be to rename vec_detail::is_trivially_copyable_or_pair trait to say vec_detail::is_qsort_sortable and allow code to amend that trait on a type by type basis when needed after analysing it works correctl= y for some further type (like wide_int or widest_int). But am not sure it would work if widest-int.h is included before vec.h etc. Your thoughts on all of this? --- gcc/wide-int.h.jj=092023-09-27 10:37:39.456836804 +0200 +++ gcc/wide-int.h=092023-09-28 14:55:40.059632413 +0200 @@ -27,7 +27,7 @@ along with GCC; see the file COPYING3. other longer storage GCC representations (rtl and tree). =20 The actual precision of a wide_int depends on the flavor. There - are three predefined flavors: + are four predefined flavors: =20 1) wide_int (the default). This flavor does the math in the precision of its input arguments. It is assumed (and checked) @@ -53,6 +53,10 @@ along with GCC; see the file COPYING3. multiply, division, shifts, comparisons, and operations that need overflow detected), the signedness must be specified separately. =20 + For precisions up to WIDE_INT_MAX_PRECISION, it uses an inline + buffer in the type, for larger precisions up to WIDEST_INT_MAX_PRECIS= ION + it uses a pointer to heap allocated buffer. + 2) offset_int. This is a fixed-precision integer that can hold any address offset, measured in either bits or bytes, with at least one extra sign bit. At the moment the maximum address @@ -76,11 +80,15 @@ along with GCC; see the file COPYING3. wi::leu_p (a, b) as a more efficient short-hand for "a >=3D 0 && a <=3D b". ] =20 + 3) rwide_int. Restricted wide_int. This is similar to + wide_int, but maximum possible precision is WIDE_INT_MAX_PRECISION + and it always uses an inline buffer. offset_int and rwide_int are + GC-friendly, wide_int and widest_int are not. + 3) widest_int. This representation is an approximation of infinite precision math. However, it is not really infinite precision math as in the GMP library. It is really finite - precision math where the precision is 4 times the size of the - largest integer that the target port can represent. + precision math where the precision is WIDEST_INT_MAX_PRECISION. =20 Like offset_int, widest_int is wider than all the values that it needs to represent, so the integers are logically signed. @@ -242,6 +250,13 @@ along with GCC; see the file COPYING3. =20 #define WIDE_INT_MAX_PRECISION (WIDE_INT_MAX_ELTS * HOST_BITS_PER_WIDE_INT= ) =20 +/* Precision of widest_int and largest _BitInt precision + 1 we can + support. */ +#define WIDEST_INT_MAX_ELTS 255 +#define WIDEST_INT_MAX_PRECISION (WIDEST_INT_MAX_ELTS * HOST_BITS_PER_WIDE= _INT) + +STATIC_ASSERT (WIDE_INT_MAX_ELTS < WIDEST_INT_MAX_ELTS); + /* This is the max size of any pointer on any machine. It does not seem to be as easy to sniff this out of the machine description as it is for MAX_BITSIZE_MODE_ANY_INT since targets may support @@ -307,17 +322,19 @@ along with GCC; see the file COPYING3. #define WI_BINARY_RESULT_VAR(RESULT, VAL, T1, X, T2, Y) \ WI_BINARY_RESULT (T1, T2) RESULT =3D \ wi::int_traits ::get_binary_result (X, Y); = \ - HOST_WIDE_INT *VAL =3D RESULT.write_val () + HOST_WIDE_INT *VAL =3D RESULT.write_val (0) =20 /* Similar for the result of a unary operation on X, which has type T. */ #define WI_UNARY_RESULT_VAR(RESULT, VAL, T, X) \ WI_UNARY_RESULT (T) RESULT =3D \ wi::int_traits ::get_binary_result (X, X); \ - HOST_WIDE_INT *VAL =3D RESULT.write_val () + HOST_WIDE_INT *VAL =3D RESULT.write_val (0) =20 template class generic_wide_int; template class fixed_wide_int_storage; class wide_int_storage; +class rwide_int_storage; +template class widest_int_storage; =20 /* An N-bit integer. Until we can use typedef templates, use this instead= . */ #define FIXED_WIDE_INT(N) \ @@ -325,10 +342,9 @@ class wide_int_storage; =20 typedef generic_wide_int wide_int; typedef FIXED_WIDE_INT (ADDR_MAX_PRECISION) offset_int; -typedef FIXED_WIDE_INT (WIDE_INT_MAX_PRECISION) widest_int; -/* Spelled out explicitly (rather than through FIXED_WIDE_INT) - so as not to confuse gengtype. */ -typedef generic_wide_int < fixed_wide_int_storage > widest2_int; +typedef generic_wide_int rwide_int; +typedef generic_wide_int > wi= dest_int; +typedef generic_wide_int = > widest2_int; =20 /* wi::storage_ref can be a reference to a primitive type, so this is the conservatively-correct setting. */ @@ -380,7 +396,11 @@ namespace wi =20 /* The integer has a constant precision (known at GCC compile time) and is signed. */ - CONST_PRECISION + CONST_PRECISION, + + /* Like CONST_PRECISION, but with WIDEST_INT_MAX_PRECISION or larger + precision where not all elements of arrays are always present. */ + WIDEST_CONST_PRECISION }; =20 /* This class, which has no default implementation, is expected to @@ -390,9 +410,15 @@ namespace wi Classifies the type of T. =20 static const unsigned int precision; - Only defined if precision_type =3D=3D CONST_PRECISION. Specifies t= he + Only defined if precision_type =3D=3D CONST_PRECISION or + precision_type =3D=3D WIDEST_CONST_PRECISION. Specifies the precision of all integers of type T. =20 + static const unsigned int inl_precision; + Only defined if precision_type =3D=3D WIDEST_CONST_PRECISION. + Specifies precision which is represented in the inline + arrays. + static const bool host_dependent_precision; True if the precision of T depends (or can depend) on the host. =20 @@ -415,9 +441,10 @@ namespace wi struct binary_traits; =20 /* Specify the result type for each supported combination of binary - inputs. Note that CONST_PRECISION and VAR_PRECISION cannot be - mixed, in order to give stronger type checking. When both inputs - are CONST_PRECISION, they must have the same precision. */ + inputs. Note that CONST_PRECISION, WIDEST_CONST_PRECISION and + VAR_PRECISION cannot be mixed, in order to give stronger type + checking. When both inputs are CONST_PRECISION or both are + WIDEST_CONST_PRECISION, they must have the same precision. */ template struct binary_traits { @@ -447,6 +474,17 @@ namespace wi }; =20 template + struct binary_traits + { + typedef generic_wide_int < widest_int_storage +=09=09=09 ::inl_precision> > result_type; + typedef result_type operator_result; + typedef bool predicate_result; + typedef result_type signed_shift_result_type; + typedef bool signed_predicate_result; + }; + + template struct binary_traits { typedef wide_int result_type; @@ -468,6 +506,17 @@ namespace wi }; =20 template + struct binary_traits + { + typedef generic_wide_int < widest_int_storage +=09=09=09 ::inl_precision> > result_type; + typedef result_type operator_result; + typedef bool predicate_result; + typedef result_type signed_shift_result_type; + typedef bool signed_predicate_result; + }; + + template struct binary_traits { STATIC_ASSERT (int_traits ::precision =3D=3D int_traits ::prec= ision); @@ -482,6 +531,18 @@ namespace wi }; =20 template + struct binary_traits + { + STATIC_ASSERT (int_traits ::precision =3D=3D int_traits ::prec= ision); + typedef generic_wide_int < widest_int_storage +=09=09=09 ::inl_precision> > result_type; + typedef result_type operator_result; + typedef bool predicate_result; + typedef result_type signed_shift_result_type; + typedef bool signed_predicate_result; + }; + + template struct binary_traits { typedef wide_int result_type; @@ -709,8 +770,10 @@ wi::storage_ref::get_val () const Although not required by generic_wide_int itself, writable storage classes can also provide the following functions: =20 - HOST_WIDE_INT *write_val () - Get a modifiable version of get_val () + HOST_WIDE_INT *write_val (unsigned int) + Get a modifiable version of get_val (). The argument should be + upper estimation for LEN (ignored by all storages but + widest_int_storage). =20 unsigned int set_len (unsigned int len) Set the value returned by get_len () to LEN. */ @@ -777,6 +840,8 @@ public: =20 static const bool is_sign_extended =3D wi::int_traits >::is_sign_extended; + static const bool needs_write_val_arg + =3D wi::int_traits >::needs_write_val_arg; }; =20 template @@ -1049,6 +1114,7 @@ namespace wi static const enum precision_type precision_type =3D VAR_PRECISION; static const bool host_dependent_precision =3D HDP; static const bool is_sign_extended =3D SE; + static const bool needs_write_val_arg =3D false; }; } =20 @@ -1065,7 +1131,11 @@ namespace wi class GTY(()) wide_int_storage { private: - HOST_WIDE_INT val[WIDE_INT_MAX_ELTS]; + union + { + HOST_WIDE_INT val[WIDE_INT_MAX_ELTS]; + HOST_WIDE_INT *valp; + } GTY((skip)) u; unsigned int len; unsigned int precision; =20 @@ -1073,14 +1143,17 @@ public: wide_int_storage (); template wide_int_storage (const T &); + wide_int_storage (const wide_int_storage &); + ~wide_int_storage (); =20 /* The standard generic_wide_int storage methods. */ unsigned int get_precision () const; const HOST_WIDE_INT *get_val () const; unsigned int get_len () const; - HOST_WIDE_INT *write_val (); + HOST_WIDE_INT *write_val (unsigned int); void set_len (unsigned int, bool =3D false); =20 + wide_int_storage &operator =3D (const wide_int_storage &); template wide_int_storage &operator =3D (const T &); =20 @@ -1099,12 +1172,15 @@ namespace wi /* Guaranteed by a static assert in the wide_int_storage constructor. = */ static const bool host_dependent_precision =3D false; static const bool is_sign_extended =3D true; + static const bool needs_write_val_arg =3D false; template static wide_int get_binary_result (const T1 &, const T2 &); + template + static unsigned int get_binary_precision (const T1 &, const T2 &); }; } =20 -inline wide_int_storage::wide_int_storage () {} +inline wide_int_storage::wide_int_storage () : precision (0) {} =20 /* Initialize the storage from integer X, in its natural precision. Note that we do not allow integers with host-dependent precision @@ -1113,21 +1189,75 @@ inline wide_int_storage::wide_int_storag template inline wide_int_storage::wide_int_storage (const T &x) { - { STATIC_ASSERT (!wi::int_traits::host_dependent_precision); } - { STATIC_ASSERT (wi::int_traits::precision_type !=3D wi::CONST_PRECIS= ION); } + STATIC_ASSERT (!wi::int_traits::host_dependent_precision); + STATIC_ASSERT (wi::int_traits::precision_type !=3D wi::CONST_PRECISIO= N); + STATIC_ASSERT (wi::int_traits::precision_type +=09=09 !=3D wi::WIDEST_CONST_PRECISION); WIDE_INT_REF_FOR (T) xi (x); precision =3D xi.precision; + if (UNLIKELY (precision > WIDE_INT_MAX_PRECISION)) + u.valp =3D XNEWVEC (HOST_WIDE_INT, CEIL (precision, HOST_BITS_PER_WIDE= _INT)); wi::copy (*this, xi); } =20 +inline wide_int_storage::wide_int_storage (const wide_int_storage &x) +{ + len =3D x.len; + precision =3D x.precision; + if (UNLIKELY (precision > WIDE_INT_MAX_PRECISION)) + { + u.valp =3D XNEWVEC (HOST_WIDE_INT, CEIL (precision, HOST_BITS_PER_WI= DE_INT)); + memcpy (u.valp, x.u.valp, len * sizeof (HOST_WIDE_INT)); + } + else + memcpy (u.val, x.u.val, len * sizeof (HOST_WIDE_INT)); +} + +inline wide_int_storage::~wide_int_storage () +{ + if (UNLIKELY (precision > WIDE_INT_MAX_PRECISION)) + XDELETEVEC (u.valp); +} + +inline wide_int_storage& +wide_int_storage::operator =3D (const wide_int_storage &x) +{ + if (UNLIKELY (precision > WIDE_INT_MAX_PRECISION)) + { + if (this =3D=3D &x) +=09return *this; + XDELETEVEC (u.valp); + } + len =3D x.len; + precision =3D x.precision; + if (UNLIKELY (precision > WIDE_INT_MAX_PRECISION)) + { + u.valp =3D XNEWVEC (HOST_WIDE_INT, CEIL (precision, HOST_BITS_PER_WI= DE_INT)); + memcpy (u.valp, x.u.valp, len * sizeof (HOST_WIDE_INT)); + } + else + memcpy (u.val, x.u.val, len * sizeof (HOST_WIDE_INT)); + return *this; +} + template inline wide_int_storage& wide_int_storage::operator =3D (const T &x) { - { STATIC_ASSERT (!wi::int_traits::host_dependent_precision); } - { STATIC_ASSERT (wi::int_traits::precision_type !=3D wi::CONST_PRECIS= ION); } + STATIC_ASSERT (!wi::int_traits::host_dependent_precision); + STATIC_ASSERT (wi::int_traits::precision_type !=3D wi::CONST_PRECISIO= N); + STATIC_ASSERT (wi::int_traits::precision_type +=09=09 !=3D wi::WIDEST_CONST_PRECISION); WIDE_INT_REF_FOR (T) xi (x); - precision =3D xi.precision; + if (UNLIKELY (precision !=3D xi.precision)) + { + if (UNLIKELY (precision > WIDE_INT_MAX_PRECISION)) +=09XDELETEVEC (u.valp); + precision =3D xi.precision; + if (UNLIKELY (precision > WIDE_INT_MAX_PRECISION)) +=09u.valp =3D XNEWVEC (HOST_WIDE_INT, +=09=09=09 CEIL (precision, HOST_BITS_PER_WIDE_INT)); + } wi::copy (*this, xi); return *this; } @@ -1141,7 +1271,7 @@ wide_int_storage::get_precision () const inline const HOST_WIDE_INT * wide_int_storage::get_val () const { - return val; + return UNLIKELY (precision > WIDE_INT_MAX_PRECISION) ? u.valp : u.val; } =20 inline unsigned int @@ -1151,9 +1281,9 @@ wide_int_storage::get_len () const } =20 inline HOST_WIDE_INT * -wide_int_storage::write_val () +wide_int_storage::write_val (unsigned int) { - return val; + return UNLIKELY (precision > WIDE_INT_MAX_PRECISION) ? u.valp : u.val; } =20 inline void @@ -1161,8 +1291,10 @@ wide_int_storage::set_len (unsigned int { len =3D l; if (!is_sign_extended && len * HOST_BITS_PER_WIDE_INT > precision) - val[len - 1] =3D sext_hwi (val[len - 1], -=09=09=09 precision % HOST_BITS_PER_WIDE_INT); + { + HOST_WIDE_INT &v =3D write_val (len)[len - 1]; + v =3D sext_hwi (v, precision % HOST_BITS_PER_WIDE_INT); + } } =20 /* Treat X as having signedness SGN and convert it to a PRECISION-bit @@ -1172,7 +1304,7 @@ wide_int_storage::from (const wide_int_r =09=09=09signop sgn) { wide_int result =3D wide_int::create (precision); - result.set_len (wi::force_to_size (result.write_val (), x.val, x.len, + result.set_len (wi::force_to_size (result.write_val (x.len), x.val, x.le= n, =09=09=09=09 x.precision, precision, sgn)); return result; } @@ -1185,7 +1317,7 @@ wide_int_storage::from_array (const HOST =09=09=09 unsigned int precision, bool need_canon_p) { wide_int result =3D wide_int::create (precision); - result.set_len (wi::from_array (result.write_val (), val, len, precision= , + result.set_len (wi::from_array (result.write_val (len), val, len, precis= ion, =09=09=09=09 need_canon_p)); return result; } @@ -1196,6 +1328,9 @@ wide_int_storage::create (unsigned int p { wide_int x; x.precision =3D precision; + if (UNLIKELY (precision > WIDE_INT_MAX_PRECISION)) + x.u.valp =3D XNEWVEC (HOST_WIDE_INT, +=09=09=09CEIL (precision, HOST_BITS_PER_WIDE_INT)); return x; } =20 @@ -1212,6 +1347,194 @@ wi::int_traits ::get_b return wide_int::create (wi::get_precision (x)); } =20 +template +inline unsigned int +wi::int_traits ::get_binary_precision (const T1 &x, +=09=09=09=09=09=09=09 const T2 &y) +{ + /* This shouldn't be used for two flexible-precision inputs. */ + STATIC_ASSERT (wi::int_traits ::precision_type !=3D FLEXIBLE_PRECISI= ON +=09=09 || wi::int_traits ::precision_type !=3D FLEXIBLE_PRECISION); + if (wi::int_traits ::precision_type =3D=3D FLEXIBLE_PRECISION) + return wi::get_precision (y); + else + return wi::get_precision (x); +} + +/* The storage used by rwide_int. */ +class GTY(()) rwide_int_storage +{ +private: + HOST_WIDE_INT val[WIDE_INT_MAX_ELTS]; + unsigned int len; + unsigned int precision; + +public: + rwide_int_storage () =3D default; + template + rwide_int_storage (const T &); + + /* The standard generic_rwide_int storage methods. */ + unsigned int get_precision () const; + const HOST_WIDE_INT *get_val () const; + unsigned int get_len () const; + HOST_WIDE_INT *write_val (unsigned int); + void set_len (unsigned int, bool =3D false); + + template + rwide_int_storage &operator =3D (const T &); + + static rwide_int from (const wide_int_ref &, unsigned int, signop); + static rwide_int from_array (const HOST_WIDE_INT *, unsigned int, +=09=09=09 unsigned int, bool =3D true); + static rwide_int create (unsigned int); +}; + +namespace wi +{ + template <> + struct int_traits + { + static const enum precision_type precision_type =3D VAR_PRECISION; + /* Guaranteed by a static assert in the rwide_int_storage constructor.= */ + static const bool host_dependent_precision =3D false; + static const bool is_sign_extended =3D true; + static const bool needs_write_val_arg =3D false; + template + static rwide_int get_binary_result (const T1 &, const T2 &); + template + static unsigned int get_binary_precision (const T1 &, const T2 &); + }; +} + +/* Initialize the storage from integer X, in its natural precision. + Note that we do not allow integers with host-dependent precision + to become rwide_ints; rwide_ints must always be logically independent + of the host. */ +template +inline rwide_int_storage::rwide_int_storage (const T &x) +{ + STATIC_ASSERT (!wi::int_traits::host_dependent_precision); + STATIC_ASSERT (wi::int_traits::precision_type !=3D wi::CONST_PRECISIO= N); + STATIC_ASSERT (wi::int_traits::precision_type +=09=09 !=3D wi::WIDEST_CONST_PRECISION); + WIDE_INT_REF_FOR (T) xi (x); + precision =3D xi.precision; + gcc_assert (precision <=3D WIDE_INT_MAX_PRECISION); + wi::copy (*this, xi); +} + +template +inline rwide_int_storage& +rwide_int_storage::operator =3D (const T &x) +{ + STATIC_ASSERT (!wi::int_traits::host_dependent_precision); + STATIC_ASSERT (wi::int_traits::precision_type !=3D wi::CONST_PRECISIO= N); + STATIC_ASSERT (wi::int_traits::precision_type +=09=09 !=3D wi::WIDEST_CONST_PRECISION); + WIDE_INT_REF_FOR (T) xi (x); + precision =3D xi.precision; + gcc_assert (precision <=3D WIDE_INT_MAX_PRECISION); + wi::copy (*this, xi); + return *this; +} + +inline unsigned int +rwide_int_storage::get_precision () const +{ + return precision; +} + +inline const HOST_WIDE_INT * +rwide_int_storage::get_val () const +{ + return val; +} + +inline unsigned int +rwide_int_storage::get_len () const +{ + return len; +} + +inline HOST_WIDE_INT * +rwide_int_storage::write_val (unsigned int) +{ + return val; +} + +inline void +rwide_int_storage::set_len (unsigned int l, bool is_sign_extended) +{ + len =3D l; + if (!is_sign_extended && len * HOST_BITS_PER_WIDE_INT > precision) + val[len - 1] =3D sext_hwi (val[len - 1], +=09=09=09 precision % HOST_BITS_PER_WIDE_INT); +} + +/* Treat X as having signedness SGN and convert it to a PRECISION-bit + number. */ +inline rwide_int +rwide_int_storage::from (const wide_int_ref &x, unsigned int precision, +=09=09=09 signop sgn) +{ + rwide_int result =3D rwide_int::create (precision); + result.set_len (wi::force_to_size (result.write_val (x.len), x.val, x.le= n, +=09=09=09=09 x.precision, precision, sgn)); + return result; +} + +/* Create a rwide_int from the explicit block encoding given by VAL and + LEN. PRECISION is the precision of the integer. NEED_CANON_P is + true if the encoding may have redundant trailing blocks. */ +inline rwide_int +rwide_int_storage::from_array (const HOST_WIDE_INT *val, unsigned int len, +=09=09=09 unsigned int precision, bool need_canon_p) +{ + rwide_int result =3D rwide_int::create (precision); + result.set_len (wi::from_array (result.write_val (len), val, len, precis= ion, +=09=09=09=09 need_canon_p)); + return result; +} + +/* Return an uninitialized rwide_int with precision PRECISION. */ +inline rwide_int +rwide_int_storage::create (unsigned int precision) +{ + rwide_int x; + gcc_assert (precision <=3D WIDE_INT_MAX_PRECISION); + x.precision =3D precision; + return x; +} + +template +inline rwide_int +wi::int_traits ::get_binary_result (const T1 &x, +=09=09=09=09=09=09 const T2 &y) +{ + /* This shouldn't be used for two flexible-precision inputs. */ + STATIC_ASSERT (wi::int_traits ::precision_type !=3D FLEXIBLE_PRECISI= ON +=09=09 || wi::int_traits ::precision_type !=3D FLEXIBLE_PRECISION); + if (wi::int_traits ::precision_type =3D=3D FLEXIBLE_PRECISION) + return rwide_int::create (wi::get_precision (y)); + else + return rwide_int::create (wi::get_precision (x)); +} + +template +inline unsigned int +wi::int_traits ::get_binary_precision (const T1 &x, +=09=09=09=09=09=09=09 const T2 &y) +{ + /* This shouldn't be used for two flexible-precision inputs. */ + STATIC_ASSERT (wi::int_traits ::precision_type !=3D FLEXIBLE_PRECISI= ON +=09=09 || wi::int_traits ::precision_type !=3D FLEXIBLE_PRECISION); + if (wi::int_traits ::precision_type =3D=3D FLEXIBLE_PRECISION) + return wi::get_precision (y); + else + return wi::get_precision (x); +} + /* The storage used by FIXED_WIDE_INT (N). */ template class GTY(()) fixed_wide_int_storage @@ -1221,7 +1544,7 @@ private: unsigned int len; =20 public: - fixed_wide_int_storage (); + fixed_wide_int_storage () =3D default; template fixed_wide_int_storage (const T &); =20 @@ -1229,7 +1552,7 @@ public: unsigned int get_precision () const; const HOST_WIDE_INT *get_val () const; unsigned int get_len () const; - HOST_WIDE_INT *write_val (); + HOST_WIDE_INT *write_val (unsigned int); void set_len (unsigned int, bool =3D false); =20 static FIXED_WIDE_INT (N) from (const wide_int_ref &, signop); @@ -1245,15 +1568,15 @@ namespace wi static const enum precision_type precision_type =3D CONST_PRECISION; static const bool host_dependent_precision =3D false; static const bool is_sign_extended =3D true; + static const bool needs_write_val_arg =3D false; static const unsigned int precision =3D N; template static FIXED_WIDE_INT (N) get_binary_result (const T1 &, const T2 &); + template + static unsigned int get_binary_precision (const T1 &, const T2 &); }; } =20 -template -inline fixed_wide_int_storage ::fixed_wide_int_storage () {} - /* Initialize the storage from integer X, in precision N. */ template template @@ -1288,7 +1611,7 @@ fixed_wide_int_storage ::get_len () c =20 template inline HOST_WIDE_INT * -fixed_wide_int_storage ::write_val () +fixed_wide_int_storage ::write_val (unsigned int) { return val; } @@ -1308,7 +1631,7 @@ inline FIXED_WIDE_INT (N) fixed_wide_int_storage ::from (const wide_int_ref &x, signop sgn) { FIXED_WIDE_INT (N) result; - result.set_len (wi::force_to_size (result.write_val (), x.val, x.len, + result.set_len (wi::force_to_size (result.write_val (x.len), x.val, x.le= n, =09=09=09=09 x.precision, N, sgn)); return result; } @@ -1323,7 +1646,7 @@ fixed_wide_int_storage ::from_array ( =09=09=09=09=09bool need_canon_p) { FIXED_WIDE_INT (N) result; - result.set_len (wi::from_array (result.write_val (), val, len, + result.set_len (wi::from_array (result.write_val (len), val, len, =09=09=09=09 N, need_canon_p)); return result; } @@ -1337,6 +1660,244 @@ get_binary_result (const T1 &, const T2 return FIXED_WIDE_INT (N) (); } =20 +template +template +inline unsigned int +wi::int_traits < fixed_wide_int_storage >:: +get_binary_precision (const T1 &, const T2 &) +{ + return N; +} + +#define WIDEST_INT(N) generic_wide_int < widest_int_storage > + +/* The storage used by widest_int. */ +template +class GTY(()) widest_int_storage +{ +private: + union + { + HOST_WIDE_INT val[WIDE_INT_MAX_HWIS (N)]; + HOST_WIDE_INT *valp; + } GTY((skip)) u; + unsigned int len; + +public: + widest_int_storage (); + widest_int_storage (const widest_int_storage &); + template + widest_int_storage (const T &); + ~widest_int_storage (); + widest_int_storage &operator =3D (const widest_int_storage &); + template + inline widest_int_storage& operator =3D (const T &); + + /* The standard generic_wide_int storage methods. */ + unsigned int get_precision () const; + const HOST_WIDE_INT *get_val () const; + unsigned int get_len () const; + HOST_WIDE_INT *write_val (unsigned int); + void set_len (unsigned int, bool =3D false); + + static WIDEST_INT (N) from (const wide_int_ref &, signop); + static WIDEST_INT (N) from_array (const HOST_WIDE_INT *, unsigned int, +=09=09=09=09 bool =3D true); +}; + +namespace wi +{ + template + struct int_traits < widest_int_storage > + { + static const enum precision_type precision_type =3D WIDEST_CONST_PRECI= SION; + static const bool host_dependent_precision =3D false; + static const bool is_sign_extended =3D true; + static const bool needs_write_val_arg =3D true; + static const unsigned int precision + =3D N / WIDE_INT_MAX_PRECISION * WIDEST_INT_MAX_PRECISION; + static const unsigned int inl_precision =3D N; + template + static WIDEST_INT (N) get_binary_result (const T1 &, const T2 &); + template + static unsigned int get_binary_precision (const T1 &, const T2 &); + }; +} + +template +inline widest_int_storage ::widest_int_storage () : len (0) {} + +/* Initialize the storage from integer X, in precision N. */ +template +template +inline widest_int_storage ::widest_int_storage (const T &x) : len (0) +{ + /* Check for type compatibility. We don't want to initialize a + widest integer from something like a wide_int. */ + WI_BINARY_RESULT (T, WIDEST_INT (N)) *assertion ATTRIBUTE_UNUSED; + wi::copy (*this, WIDE_INT_REF_FOR (T) (x, N / WIDE_INT_MAX_PRECISION +=09=09=09=09=09 * WIDEST_INT_MAX_PRECISION)); +} + +template +inline +widest_int_storage ::widest_int_storage (const widest_int_storage &= x) +{ + len =3D x.len; + if (UNLIKELY (len > N / HOST_BITS_PER_WIDE_INT)) + { + u.valp =3D XNEWVEC (HOST_WIDE_INT, len); + memcpy (u.valp, x.u.valp, len * sizeof (HOST_WIDE_INT)); + } + else + memcpy (u.val, x.u.val, len * sizeof (HOST_WIDE_INT)); +} + +template +inline widest_int_storage ::~widest_int_storage () +{ + if (UNLIKELY (len > N / HOST_BITS_PER_WIDE_INT)) + XDELETEVEC (u.valp); +} + +template +inline widest_int_storage & +widest_int_storage ::operator =3D (const widest_int_storage &x) +{ + if (UNLIKELY (len > N / HOST_BITS_PER_WIDE_INT)) + { + if (this =3D=3D &x) +=09return *this; + XDELETEVEC (u.valp); + } + len =3D x.len; + if (UNLIKELY (len > N / HOST_BITS_PER_WIDE_INT)) + { + u.valp =3D XNEWVEC (HOST_WIDE_INT, len); + memcpy (u.valp, x.u.valp, len * sizeof (HOST_WIDE_INT)); + } + else + memcpy (u.val, x.u.val, len * sizeof (HOST_WIDE_INT)); + return *this; +} + +template +template +inline widest_int_storage & +widest_int_storage ::operator =3D (const T &x) +{ + /* Check for type compatibility. We don't want to assign a + widest integer from something like a wide_int. */ + WI_BINARY_RESULT (T, WIDEST_INT (N)) *assertion ATTRIBUTE_UNUSED; + if (UNLIKELY (len > N / HOST_BITS_PER_WIDE_INT)) + XDELETEVEC (u.valp); + len =3D 0; + wi::copy (*this, WIDE_INT_REF_FOR (T) (x, N / WIDE_INT_MAX_PRECISION +=09=09=09=09=09 * WIDEST_INT_MAX_PRECISION)); + return *this; +} + +template +inline unsigned int +widest_int_storage ::get_precision () const +{ + return N / WIDE_INT_MAX_PRECISION * WIDEST_INT_MAX_PRECISION; +} + +template +inline const HOST_WIDE_INT * +widest_int_storage ::get_val () const +{ + return UNLIKELY (len > N / HOST_BITS_PER_WIDE_INT) ? u.valp : u.val; +} + +template +inline unsigned int +widest_int_storage ::get_len () const +{ + return len; +} + +template +inline HOST_WIDE_INT * +widest_int_storage ::write_val (unsigned int l) +{ + if (UNLIKELY (len > N / HOST_BITS_PER_WIDE_INT)) + XDELETEVEC (u.valp); + len =3D l; + if (UNLIKELY (l > N / HOST_BITS_PER_WIDE_INT)) + { + u.valp =3D XNEWVEC (HOST_WIDE_INT, l); + return u.valp; + } + return u.val; +} + +template +inline void +widest_int_storage ::set_len (unsigned int l, bool) +{ + gcc_checking_assert (l <=3D len); + if (UNLIKELY (len > N / HOST_BITS_PER_WIDE_INT) + && l <=3D N / HOST_BITS_PER_WIDE_INT) + { + HOST_WIDE_INT *valp =3D u.valp; + memcpy (u.val, valp, len * sizeof (u.val[0])); + XDELETEVEC (valp); + } + len =3D l; + /* There are no excess bits in val[len - 1]. */ + STATIC_ASSERT (N % HOST_BITS_PER_WIDE_INT =3D=3D 0); +} + +/* Treat X as having signedness SGN and convert it to an N-bit number. */ +template +inline WIDEST_INT (N) +widest_int_storage ::from (const wide_int_ref &x, signop sgn) +{ + WIDEST_INT (N) result; + unsigned int exp_len =3D x.len; + unsigned int prec =3D result.get_precision (); + if (sgn =3D=3D UNSIGNED && prec > x.precision && x.val[x.len - 1] < 0) + exp_len =3D CEIL (x.precision, HOST_BITS_PER_WIDE_INT) + 1; + result.set_len (wi::force_to_size (result.write_val (exp_len), x.val, x.= len, +=09=09=09=09 x.precision, prec, sgn)); + return result; +} + +/* Create a WIDEST_INT (N) from the explicit block encoding given by + VAL and LEN. NEED_CANON_P is true if the encoding may have redundant + trailing blocks. */ +template +inline WIDEST_INT (N) +widest_int_storage ::from_array (const HOST_WIDE_INT *val, +=09=09=09=09 unsigned int len, +=09=09=09=09 bool need_canon_p) +{ + WIDEST_INT (N) result; + result.set_len (wi::from_array (result.write_val (len), val, len, +=09=09=09=09 result.get_precision (), need_canon_p)); + return result; +} + +template +template +inline WIDEST_INT (N) +wi::int_traits < widest_int_storage >:: +get_binary_result (const T1 &, const T2 &) +{ + return WIDEST_INT (N) (); +} + +template +template +inline unsigned int +wi::int_traits < widest_int_storage >:: +get_binary_precision (const T1 &, const T2 &) +{ + return N / WIDE_INT_MAX_PRECISION * WIDEST_INT_MAX_PRECISION; +} + /* A reference to one element of a trailing_wide_ints structure. */ class trailing_wide_int_storage { @@ -1359,7 +1920,7 @@ public: unsigned int get_len () const; unsigned int get_precision () const; const HOST_WIDE_INT *get_val () const; - HOST_WIDE_INT *write_val (); + HOST_WIDE_INT *write_val (unsigned int); void set_len (unsigned int, bool =3D false); =20 template @@ -1445,7 +2006,7 @@ trailing_wide_int_storage::get_val () co } =20 inline HOST_WIDE_INT * -trailing_wide_int_storage::write_val () +trailing_wide_int_storage::write_val (unsigned int) { return m_val; } @@ -1528,6 +2089,7 @@ namespace wi static const enum precision_type precision_type =3D FLEXIBLE_PRECISION= ; static const bool host_dependent_precision =3D true; static const bool is_sign_extended =3D true; + static const bool needs_write_val_arg =3D false; static unsigned int get_precision (T); static wi::storage_ref decompose (HOST_WIDE_INT *, unsigned int, T); }; @@ -1699,6 +2261,7 @@ namespace wi precision of HOST_WIDE_INT. */ static const bool host_dependent_precision =3D false; static const bool is_sign_extended =3D true; + static const bool needs_write_val_arg =3D false; static unsigned int get_precision (const wi::hwi_with_prec &); static wi::storage_ref decompose (HOST_WIDE_INT *, unsigned int, =09=09=09=09 const wi::hwi_with_prec &); @@ -1804,8 +2367,8 @@ template inline unsigned int wi::get_binary_precision (const T1 &x, const T2 &y) { - return get_precision (wi::int_traits :: -=09=09=09get_binary_result (x, y)); + return wi::int_traits ::get_binary_precision = (x, +=09=09=09=09=09=09=09=09=09 y); } =20 /* Copy the contents of Y to X, but keeping X's current precision. */ @@ -1813,9 +2376,9 @@ template inline void wi::copy (T1 &x, const T2 &y) { - HOST_WIDE_INT *xval =3D x.write_val (); - const HOST_WIDE_INT *yval =3D y.get_val (); unsigned int len =3D y.get_len (); + HOST_WIDE_INT *xval =3D x.write_val (len); + const HOST_WIDE_INT *yval =3D y.get_val (); unsigned int i =3D 0; do xval[i] =3D yval[i]; @@ -2162,6 +2725,8 @@ wi::bit_not (const T &x) { WI_UNARY_RESULT_VAR (result, val, T, x); WIDE_INT_REF_FOR (T) xi (x, get_precision (result)); + if (result.needs_write_val_arg) + val =3D result.write_val (xi.len); for (unsigned int i =3D 0; i < xi.len; ++i) val[i] =3D ~xi.val[i]; result.set_len (xi.len); @@ -2203,6 +2768,8 @@ wi::sext (const T &x, unsigned int offse unsigned int precision =3D get_precision (result); WIDE_INT_REF_FOR (T) xi (x, precision); =20 + if (result.needs_write_val_arg) + val =3D result.write_val (xi.len); if (offset <=3D HOST_BITS_PER_WIDE_INT) { val[0] =3D sext_hwi (xi.ulow (), offset); @@ -2230,6 +2797,9 @@ wi::zext (const T &x, unsigned int offse return result; } =20 + if (result.needs_write_val_arg) + val =3D result.write_val (MAX (xi.len, +=09=09=09=09 CEIL (offset, HOST_BITS_PER_WIDE_INT))); /* In these cases we know that at least the top bit will be clear, so no sign extension is necessary. */ if (offset < HOST_BITS_PER_WIDE_INT) @@ -2259,6 +2829,9 @@ wi::set_bit (const T &x, unsigned int bi WI_UNARY_RESULT_VAR (result, val, T, x); unsigned int precision =3D get_precision (result); WIDE_INT_REF_FOR (T) xi (x, precision); + if (result.needs_write_val_arg) + val =3D result.write_val (MAX (xi.len, +=09=09=09=09 bit / HOST_BITS_PER_WIDE_INT + 1)); if (precision <=3D HOST_BITS_PER_WIDE_INT) { val[0] =3D xi.ulow () | (HOST_WIDE_INT_1U << bit); @@ -2280,6 +2853,8 @@ wi::bswap (const T &x) WI_UNARY_RESULT_VAR (result, val, T, x); unsigned int precision =3D get_precision (result); WIDE_INT_REF_FOR (T) xi (x, precision); + if (result.needs_write_val_arg) + gcc_unreachable (); /* bswap on widest_int makes no sense. */ result.set_len (bswap_large (val, xi.val, xi.len, precision)); return result; } @@ -2292,6 +2867,8 @@ wi::bitreverse (const T &x) WI_UNARY_RESULT_VAR (result, val, T, x); unsigned int precision =3D get_precision (result); WIDE_INT_REF_FOR (T) xi (x, precision); + if (result.needs_write_val_arg) + gcc_unreachable (); /* bitreverse on widest_int makes no sense. */ result.set_len (bitreverse_large (val, xi.val, xi.len, precision)); return result; } @@ -2368,6 +2945,8 @@ wi::bit_and (const T1 &x, const T2 &y) WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y, precision); bool is_sign_extended =3D xi.is_sign_extended && yi.is_sign_extended; + if (result.needs_write_val_arg) + val =3D result.write_val (MAX (xi.len, yi.len)); if (LIKELY (xi.len + yi.len =3D=3D 2)) { val[0] =3D xi.ulow () & yi.ulow (); @@ -2389,6 +2968,8 @@ wi::bit_and_not (const T1 &x, const T2 & WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y, precision); bool is_sign_extended =3D xi.is_sign_extended && yi.is_sign_extended; + if (result.needs_write_val_arg) + val =3D result.write_val (MAX (xi.len, yi.len)); if (LIKELY (xi.len + yi.len =3D=3D 2)) { val[0] =3D xi.ulow () & ~yi.ulow (); @@ -2410,6 +2991,8 @@ wi::bit_or (const T1 &x, const T2 &y) WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y, precision); bool is_sign_extended =3D xi.is_sign_extended && yi.is_sign_extended; + if (result.needs_write_val_arg) + val =3D result.write_val (MAX (xi.len, yi.len)); if (LIKELY (xi.len + yi.len =3D=3D 2)) { val[0] =3D xi.ulow () | yi.ulow (); @@ -2431,6 +3014,8 @@ wi::bit_or_not (const T1 &x, const T2 &y WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y, precision); bool is_sign_extended =3D xi.is_sign_extended && yi.is_sign_extended; + if (result.needs_write_val_arg) + val =3D result.write_val (MAX (xi.len, yi.len)); if (LIKELY (xi.len + yi.len =3D=3D 2)) { val[0] =3D xi.ulow () | ~yi.ulow (); @@ -2452,6 +3037,8 @@ wi::bit_xor (const T1 &x, const T2 &y) WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y, precision); bool is_sign_extended =3D xi.is_sign_extended && yi.is_sign_extended; + if (result.needs_write_val_arg) + val =3D result.write_val (MAX (xi.len, yi.len)); if (LIKELY (xi.len + yi.len =3D=3D 2)) { val[0] =3D xi.ulow () ^ yi.ulow (); @@ -2472,6 +3059,8 @@ wi::add (const T1 &x, const T2 &y) unsigned int precision =3D get_precision (result); WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y, precision); + if (result.needs_write_val_arg) + val =3D result.write_val (MAX (xi.len, yi.len) + 1); if (precision <=3D HOST_BITS_PER_WIDE_INT) { val[0] =3D xi.ulow () + yi.ulow (); @@ -2515,6 +3104,8 @@ wi::add (const T1 &x, const T2 &y, signo unsigned int precision =3D get_precision (result); WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y, precision); + if (result.needs_write_val_arg) + val =3D result.write_val (MAX (xi.len, yi.len) + 1); if (precision <=3D HOST_BITS_PER_WIDE_INT) { unsigned HOST_WIDE_INT xl =3D xi.ulow (); @@ -2558,6 +3149,8 @@ wi::sub (const T1 &x, const T2 &y) unsigned int precision =3D get_precision (result); WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y, precision); + if (result.needs_write_val_arg) + val =3D result.write_val (MAX (xi.len, yi.len) + 1); if (precision <=3D HOST_BITS_PER_WIDE_INT) { val[0] =3D xi.ulow () - yi.ulow (); @@ -2601,6 +3194,8 @@ wi::sub (const T1 &x, const T2 &y, signo unsigned int precision =3D get_precision (result); WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y, precision); + if (result.needs_write_val_arg) + val =3D result.write_val (MAX (xi.len, yi.len) + 1); if (precision <=3D HOST_BITS_PER_WIDE_INT) { unsigned HOST_WIDE_INT xl =3D xi.ulow (); @@ -2643,6 +3238,8 @@ wi::mul (const T1 &x, const T2 &y) unsigned int precision =3D get_precision (result); WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y, precision); + if (result.needs_write_val_arg) + val =3D result.write_val (xi.len + yi.len + 2); if (precision <=3D HOST_BITS_PER_WIDE_INT) { val[0] =3D xi.ulow () * yi.ulow (); @@ -2664,6 +3261,8 @@ wi::mul (const T1 &x, const T2 &y, signo unsigned int precision =3D get_precision (result); WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y, precision); + if (result.needs_write_val_arg) + val =3D result.write_val (xi.len + yi.len + 2); result.set_len (mul_internal (val, xi.val, xi.len, =09=09=09=09yi.val, yi.len, precision, =09=09=09=09sgn, overflow, false)); @@ -2698,6 +3297,8 @@ wi::mul_high (const T1 &x, const T2 &y, unsigned int precision =3D get_precision (result); WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y, precision); + if (result.needs_write_val_arg) + gcc_unreachable (); /* mul_high on widest_int doesn't make sense. */ result.set_len (mul_internal (val, xi.val, xi.len, =09=09=09=09yi.val, yi.len, precision, =09=09=09=09sgn, 0, true)); @@ -2716,6 +3317,12 @@ wi::div_trunc (const T1 &x, const T2 &y, WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y); =20 + if (quotient.needs_write_val_arg) + quotient_val =3D quotient.write_val ((sgn =3D=3D UNSIGNED +=09=09=09=09=09&& xi.val[xi.len - 1] < 0) +=09=09=09=09 ? CEIL (precision, +=09=09=09=09=09 HOST_BITS_PER_WIDE_INT) + 1 +=09=09=09=09 : xi.len + 1); quotient.set_len (divmod_internal (quotient_val, 0, 0, xi.val, xi.len, =09=09=09=09 precision, =09=09=09=09 yi.val, yi.len, yi.precision, @@ -2753,6 +3360,15 @@ wi::div_floor (const T1 &x, const T2 &y, WIDE_INT_REF_FOR (T2) yi (y); =20 unsigned int remainder_len; + if (quotient.needs_write_val_arg) + { + quotient_val =3D quotient.write_val ((sgn =3D=3D UNSIGNED +=09=09=09=09=09 && xi.val[xi.len - 1] < 0) +=09=09=09=09=09 ? CEIL (precision, +=09=09=09=09=09=09 HOST_BITS_PER_WIDE_INT) + 1 +=09=09=09=09=09 : xi.len + 1); + remainder_val =3D remainder.write_val (yi.len); + } quotient.set_len (divmod_internal (quotient_val, =09=09=09=09 &remainder_len, remainder_val, =09=09=09=09 xi.val, xi.len, precision, @@ -2795,6 +3411,15 @@ wi::div_ceil (const T1 &x, const T2 &y, WIDE_INT_REF_FOR (T2) yi (y); =20 unsigned int remainder_len; + if (quotient.needs_write_val_arg) + { + quotient_val =3D quotient.write_val ((sgn =3D=3D UNSIGNED +=09=09=09=09=09 && xi.val[xi.len - 1] < 0) +=09=09=09=09=09 ? CEIL (precision, +=09=09=09=09=09=09 HOST_BITS_PER_WIDE_INT) + 1 +=09=09=09=09=09 : xi.len + 1); + remainder_val =3D remainder.write_val (yi.len); + } quotient.set_len (divmod_internal (quotient_val, =09=09=09=09 &remainder_len, remainder_val, =09=09=09=09 xi.val, xi.len, precision, @@ -2828,6 +3453,15 @@ wi::div_round (const T1 &x, const T2 &y, WIDE_INT_REF_FOR (T2) yi (y); =20 unsigned int remainder_len; + if (quotient.needs_write_val_arg) + { + quotient_val =3D quotient.write_val ((sgn =3D=3D UNSIGNED +=09=09=09=09=09 && xi.val[xi.len - 1] < 0) +=09=09=09=09=09 ? CEIL (precision, +=09=09=09=09=09=09 HOST_BITS_PER_WIDE_INT) + 1 +=09=09=09=09=09 : xi.len + 1); + remainder_val =3D remainder.write_val (yi.len); + } quotient.set_len (divmod_internal (quotient_val, =09=09=09=09 &remainder_len, remainder_val, =09=09=09=09 xi.val, xi.len, precision, @@ -2871,6 +3505,15 @@ wi::divmod_trunc (const T1 &x, const T2 WIDE_INT_REF_FOR (T2) yi (y); =20 unsigned int remainder_len; + if (quotient.needs_write_val_arg) + { + quotient_val =3D quotient.write_val ((sgn =3D=3D UNSIGNED +=09=09=09=09=09 && xi.val[xi.len - 1] < 0) +=09=09=09=09=09 ? CEIL (precision, +=09=09=09=09=09=09 HOST_BITS_PER_WIDE_INT) + 1 +=09=09=09=09=09 : xi.len + 1); + remainder_val =3D remainder.write_val (yi.len); + } quotient.set_len (divmod_internal (quotient_val, =09=09=09=09 &remainder_len, remainder_val, =09=09=09=09 xi.val, xi.len, precision, @@ -2915,6 +3558,8 @@ wi::mod_trunc (const T1 &x, const T2 &y, WIDE_INT_REF_FOR (T2) yi (y); =20 unsigned int remainder_len; + if (remainder.needs_write_val_arg) + remainder_val =3D remainder.write_val (yi.len); divmod_internal (0, &remainder_len, remainder_val, =09=09 xi.val, xi.len, precision, =09=09 yi.val, yi.len, yi.precision, sgn, overflow); @@ -2955,6 +3600,15 @@ wi::mod_floor (const T1 &x, const T2 &y, WIDE_INT_REF_FOR (T2) yi (y); =20 unsigned int remainder_len; + if (quotient.needs_write_val_arg) + { + quotient_val =3D quotient.write_val ((sgn =3D=3D UNSIGNED +=09=09=09=09=09 && xi.val[xi.len - 1] < 0) +=09=09=09=09=09 ? CEIL (precision, +=09=09=09=09=09=09 HOST_BITS_PER_WIDE_INT) + 1 +=09=09=09=09=09 : xi.len + 1); + remainder_val =3D remainder.write_val (yi.len); + } quotient.set_len (divmod_internal (quotient_val, =09=09=09=09 &remainder_len, remainder_val, =09=09=09=09 xi.val, xi.len, precision, @@ -2991,6 +3645,15 @@ wi::mod_ceil (const T1 &x, const T2 &y, WIDE_INT_REF_FOR (T2) yi (y); =20 unsigned int remainder_len; + if (quotient.needs_write_val_arg) + { + quotient_val =3D quotient.write_val ((sgn =3D=3D UNSIGNED +=09=09=09=09=09 && xi.val[xi.len - 1] < 0) +=09=09=09=09=09 ? CEIL (precision, +=09=09=09=09=09=09 HOST_BITS_PER_WIDE_INT) + 1 +=09=09=09=09=09 : xi.len + 1); + remainder_val =3D remainder.write_val (yi.len); + } quotient.set_len (divmod_internal (quotient_val, =09=09=09=09 &remainder_len, remainder_val, =09=09=09=09 xi.val, xi.len, precision, @@ -3017,6 +3680,15 @@ wi::mod_round (const T1 &x, const T2 &y, WIDE_INT_REF_FOR (T2) yi (y); =20 unsigned int remainder_len; + if (quotient.needs_write_val_arg) + { + quotient_val =3D quotient.write_val ((sgn =3D=3D UNSIGNED +=09=09=09=09=09 && xi.val[xi.len - 1] < 0) +=09=09=09=09=09 ? CEIL (precision, +=09=09=09=09=09=09 HOST_BITS_PER_WIDE_INT) + 1 +=09=09=09=09=09 : xi.len + 1); + remainder_val =3D remainder.write_val (yi.len); + } quotient.set_len (divmod_internal (quotient_val, =09=09=09=09 &remainder_len, remainder_val, =09=09=09=09 xi.val, xi.len, precision, @@ -3086,12 +3758,16 @@ wi::lshift (const T1 &x, const T2 &y) /* Handle the simple cases quickly. */ if (geu_p (yi, precision)) { + if (result.needs_write_val_arg) +=09val =3D result.write_val (1); val[0] =3D 0; result.set_len (1); } else { unsigned int shift =3D yi.to_uhwi (); + if (result.needs_write_val_arg) +=09val =3D result.write_val (xi.len + shift / HOST_BITS_PER_WIDE_INT + 1); /* For fixed-precision integers like offset_int and widest_int, =09 handle the case where the shift value is constant and the =09 result is a single nonnegative HWI (meaning that we don't @@ -3130,12 +3806,23 @@ wi::lrshift (const T1 &x, const T2 &y) /* Handle the simple cases quickly. */ if (geu_p (yi, xi.precision)) { + if (result.needs_write_val_arg) +=09val =3D result.write_val (1); val[0] =3D 0; result.set_len (1); } else { unsigned int shift =3D yi.to_uhwi (); + if (result.needs_write_val_arg) +=09{ +=09 unsigned int est_len =3D xi.len; +=09 if (xi.val[xi.len - 1] < 0 && shift) +=09 /* Logical right shift of sign-extended value might need a very +=09 large precision e.g. for widest_int. */ +=09 est_len =3D CEIL (xi.precision - shift, HOST_BITS_PER_WIDE_INT) + 1= ; +=09 val =3D result.write_val (est_len); +=09} /* For fixed-precision integers like offset_int and widest_int, =09 handle the case where the shift value is constant and the =09 shifted value is a single nonnegative HWI (meaning that all @@ -3171,6 +3858,8 @@ wi::arshift (const T1 &x, const T2 &y) since the result can be no larger than that. */ WIDE_INT_REF_FOR (T1) xi (x); WIDE_INT_REF_FOR (T2) yi (y); + if (result.needs_write_val_arg) + val =3D result.write_val (xi.len); /* Handle the simple cases quickly. */ if (geu_p (yi, xi.precision)) { @@ -3465,7 +4154,7 @@ inline wide_int wi::mask (unsigned int width, bool negate_p, unsigned int precision) { wide_int result =3D wide_int::create (precision); - result.set_len (mask (result.write_val (), width, negate_p, precision)); + result.set_len (mask (result.write_val (0), width, negate_p, precision))= ; return result; } =20 @@ -3477,7 +4166,7 @@ wi::shifted_mask (unsigned int start, un =09=09 unsigned int precision) { wide_int result =3D wide_int::create (precision); - result.set_len (shifted_mask (result.write_val (), start, width, negate_= p, + result.set_len (shifted_mask (result.write_val (0), start, width, negate= _p, =09=09=09=09precision)); return result; } @@ -3498,8 +4187,8 @@ wi::mask (unsigned int width, bool negat { STATIC_ASSERT (wi::int_traits::precision); T result; - result.set_len (mask (result.write_val (), width, negate_p, -=09=09=09wi::int_traits ::precision)); + result.set_len (mask (result.write_val (width / HOST_BITS_PER_WIDE_INT += 1), +=09=09=09width, negate_p, wi::int_traits ::precision)); return result; } =20 @@ -3512,9 +4201,13 @@ wi::shifted_mask (unsigned int start, un { STATIC_ASSERT (wi::int_traits::precision); T result; - result.set_len (shifted_mask (result.write_val (), start, width, -=09=09=09=09negate_p, -=09=09=09=09wi::int_traits ::precision)); + unsigned int prec =3D wi::int_traits ::precision; + unsigned int est_len + =3D result.needs_write_val_arg + ? ((start + (width > prec - start ? prec - start : width)) +=09 / HOST_BITS_PER_WIDE_INT + 1) : 0; + result.set_len (shifted_mask (result.write_val (est_len), start, width, +=09=09=09=09negate_p, prec)); return result; } =20 --- gcc/wide-int.cc.jj=092023-09-27 10:37:39.429837179 +0200 +++ gcc/wide-int.cc=092023-09-28 14:59:04.121819198 +0200 @@ -51,7 +51,7 @@ typedef unsigned int UDWtype __attribute #include "longlong.h" #endif =20 -static const HOST_WIDE_INT zeros[WIDE_INT_MAX_ELTS] =3D {}; +static const HOST_WIDE_INT zeros[1] =3D {}; =20 /* * Internal utilities. @@ -62,8 +62,7 @@ static const HOST_WIDE_INT zeros[WIDE_IN #define HALF_INT_MASK ((HOST_WIDE_INT_1 << HOST_BITS_PER_HALF_WIDE_INT) - = 1) =20 #define BLOCK_OF(TARGET) ((TARGET) / HOST_BITS_PER_WIDE_INT) -#define BLOCKS_NEEDED(PREC) \ - (PREC ? (((PREC) + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT)= : 1) +#define BLOCKS_NEEDED(PREC) (PREC ? CEIL (PREC, HOST_BITS_PER_WIDE_INT) : = 1) #define SIGN_MASK(X) ((HOST_WIDE_INT) (X) < 0 ? -1 : 0) =20 /* Return the value a VAL[I] if I < LEN, otherwise, return 0 or -1 @@ -96,7 +95,7 @@ canonize (HOST_WIDE_INT *val, unsigned i top =3D val[len - 1]; if (len * HOST_BITS_PER_WIDE_INT > precision) val[len - 1] =3D top =3D sext_hwi (top, precision % HOST_BITS_PER_WIDE= _INT); - if (top !=3D 0 && top !=3D (HOST_WIDE_INT)-1) + if (top !=3D 0 && top !=3D HOST_WIDE_INT_M1) return len; =20 /* At this point we know that the top is either 0 or -1. Find the @@ -163,7 +162,7 @@ wi::from_buffer (const unsigned char *bu /* We have to clear all the bits ourself, as we merely or in values below. */ unsigned int len =3D BLOCKS_NEEDED (precision); - HOST_WIDE_INT *val =3D result.write_val (); + HOST_WIDE_INT *val =3D result.write_val (0); for (unsigned int i =3D 0; i < len; ++i) val[i] =3D 0; =20 @@ -232,8 +231,7 @@ wi::to_mpz (const wide_int_ref &x, mpz_t } else if (excess < 0 && wi::neg_p (x)) { - int extra -=09=3D (-excess + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT; + int extra =3D CEIL (-excess, HOST_BITS_PER_WIDE_INT); HOST_WIDE_INT *t =3D XALLOCAVEC (HOST_WIDE_INT, len + extra); for (int i =3D 0; i < len; i++) =09t[i] =3D v[i]; @@ -280,8 +278,8 @@ wi::from_mpz (const_tree type, mpz_t x, extracted from the GMP manual, section "Integer Import and Export": http://gmplib.org/manual/Integer-Import-and-Export.html */ numb =3D CHAR_BIT * sizeof (HOST_WIDE_INT); - count =3D (mpz_sizeinbase (x, 2) + numb - 1) / numb; - HOST_WIDE_INT *val =3D res.write_val (); + count =3D CEIL (mpz_sizeinbase (x, 2), numb); + HOST_WIDE_INT *val =3D res.write_val (0); /* Read the absolute value. =20 Write directly to the wide_int storage if possible, otherwise leave @@ -1334,21 +1332,6 @@ wi::mul_internal (HOST_WIDE_INT *val, co unsigned HOST_WIDE_INT o0, o1, k, t; unsigned int i; unsigned int j; - unsigned int blocks_needed =3D BLOCKS_NEEDED (prec); - unsigned int half_blocks_needed =3D blocks_needed * 2; - /* The sizes here are scaled to support a 2x largest mode by 2x - largest mode yielding a 4x largest mode result. This is what is - needed by vpn. */ - - unsigned HOST_HALF_WIDE_INT - u[4 * MAX_BITSIZE_MODE_ANY_INT / HOST_BITS_PER_HALF_WIDE_INT]; - unsigned HOST_HALF_WIDE_INT - v[4 * MAX_BITSIZE_MODE_ANY_INT / HOST_BITS_PER_HALF_WIDE_INT]; - /* The '2' in 'R' is because we are internally doing a full - multiply. */ - unsigned HOST_HALF_WIDE_INT - r[2 * 4 * MAX_BITSIZE_MODE_ANY_INT / HOST_BITS_PER_HALF_WIDE_INT]; - HOST_WIDE_INT mask =3D ((HOST_WIDE_INT)1 << HOST_BITS_PER_HALF_WIDE_INT)= - 1; =20 /* If the top level routine did not really pass in an overflow, then just make sure that we never attempt to set it. */ @@ -1469,6 +1452,35 @@ wi::mul_internal (HOST_WIDE_INT *val, co return 1; } =20 + /* The sizes here are scaled to support a 2x WIDE_INT_MAX_PRECISION by 2= x + WIDE_INT_MAX_PRECISION yielding a 4x WIDE_INT_MAX_PRECISION result. = */ + + unsigned HOST_HALF_WIDE_INT + ubuf[4 * WIDE_INT_MAX_PRECISION / HOST_BITS_PER_HALF_WIDE_INT]; + unsigned HOST_HALF_WIDE_INT + vbuf[4 * WIDE_INT_MAX_PRECISION / HOST_BITS_PER_HALF_WIDE_INT]; + /* The '2' in 'R' is because we are internally doing a full + multiply. */ + unsigned HOST_HALF_WIDE_INT + rbuf[2 * 4 * WIDE_INT_MAX_PRECISION / HOST_BITS_PER_HALF_WIDE_INT]; + const HOST_WIDE_INT mask =3D ((HOST_WIDE_INT)1 << HOST_BITS_PER_HALF_WID= E_INT) - 1; + unsigned HOST_HALF_WIDE_INT *u =3D ubuf; + unsigned HOST_HALF_WIDE_INT *v =3D vbuf; + unsigned HOST_HALF_WIDE_INT *r =3D rbuf; + + if (prec > WIDE_INT_MAX_PRECISION && !high) + prec =3D (op1len + op2len + 1) * HOST_BITS_PER_WIDE_INT; + unsigned int blocks_needed =3D BLOCKS_NEEDED (prec); + unsigned int half_blocks_needed =3D blocks_needed * 2; + if (UNLIKELY (prec > WIDE_INT_MAX_PRECISION)) + { + unsigned HOST_HALF_WIDE_INT *buf +=09=3D XALLOCAVEC (unsigned HOST_HALF_WIDE_INT, 4 * 4 * blocks_needed); + u =3D buf; + v =3D u + 4 * blocks_needed; + r =3D v + 4 * blocks_needed; + } + /* We do unsigned mul and then correct it. */ wi_unpack (u, op1val, op1len, half_blocks_needed, prec, SIGNED); wi_unpack (v, op2val, op2len, half_blocks_needed, prec, SIGNED); @@ -1782,16 +1794,6 @@ wi::divmod_internal (HOST_WIDE_INT *quot =09=09 unsigned int divisor_prec, signop sgn, =09=09 wi::overflow_type *oflow) { - unsigned int dividend_blocks_needed =3D 2 * BLOCKS_NEEDED (dividend_prec= ); - unsigned int divisor_blocks_needed =3D 2 * BLOCKS_NEEDED (divisor_prec); - unsigned HOST_HALF_WIDE_INT - b_quotient[4 * MAX_BITSIZE_MODE_ANY_INT / HOST_BITS_PER_HALF_WIDE_INT]= ; - unsigned HOST_HALF_WIDE_INT - b_remainder[4 * MAX_BITSIZE_MODE_ANY_INT / HOST_BITS_PER_HALF_WIDE_INT= ]; - unsigned HOST_HALF_WIDE_INT - b_dividend[(4 * MAX_BITSIZE_MODE_ANY_INT / HOST_BITS_PER_HALF_WIDE_INT= ) + 1]; - unsigned HOST_HALF_WIDE_INT - b_divisor[4 * MAX_BITSIZE_MODE_ANY_INT / HOST_BITS_PER_HALF_WIDE_INT]; unsigned int m, n; bool dividend_neg =3D false; bool divisor_neg =3D false; @@ -1910,6 +1912,41 @@ wi::divmod_internal (HOST_WIDE_INT *quot =09} } =20 + unsigned HOST_HALF_WIDE_INT + b_quotient_buf[4 * WIDE_INT_MAX_PRECISION / HOST_BITS_PER_HALF_WIDE_IN= T]; + unsigned HOST_HALF_WIDE_INT + b_remainder_buf[4 * WIDE_INT_MAX_PRECISION / HOST_BITS_PER_HALF_WIDE_I= NT]; + unsigned HOST_HALF_WIDE_INT + b_dividend_buf[(4 * WIDE_INT_MAX_PRECISION / HOST_BITS_PER_HALF_WIDE_I= NT) +=09=09 + 1]; + unsigned HOST_HALF_WIDE_INT + b_divisor_buf[4 * WIDE_INT_MAX_PRECISION / HOST_BITS_PER_HALF_WIDE_INT= ]; + unsigned HOST_HALF_WIDE_INT *b_quotient =3D b_quotient_buf; + unsigned HOST_HALF_WIDE_INT *b_remainder =3D b_remainder_buf; + unsigned HOST_HALF_WIDE_INT *b_dividend =3D b_dividend_buf; + unsigned HOST_HALF_WIDE_INT *b_divisor =3D b_divisor_buf; + + if (dividend_prec > WIDE_INT_MAX_PRECISION + && (sgn =3D=3D SIGNED || dividend_val[dividend_len - 1] >=3D 0)) + dividend_prec =3D (dividend_len + 1) * HOST_BITS_PER_WIDE_INT; + if (divisor_prec > WIDE_INT_MAX_PRECISION) + divisor_prec =3D divisor_len * HOST_BITS_PER_WIDE_INT; + unsigned int dividend_blocks_needed =3D 2 * BLOCKS_NEEDED (dividend_prec= ); + unsigned int divisor_blocks_needed =3D 2 * BLOCKS_NEEDED (divisor_prec); + if (UNLIKELY (dividend_prec > WIDE_INT_MAX_PRECISION) + || UNLIKELY (divisor_prec > WIDE_INT_MAX_PRECISION)) + { + unsigned HOST_HALF_WIDE_INT *buf + =3D XALLOCAVEC (unsigned HOST_HALF_WIDE_INT, +=09=09 12 * dividend_blocks_needed +=09=09 + 4 * divisor_blocks_needed + 1); + b_quotient =3D buf; + b_remainder =3D b_quotient + 4 * dividend_blocks_needed; + b_dividend =3D b_remainder + 4 * dividend_blocks_needed; + b_divisor =3D b_dividend + 4 * dividend_blocks_needed + 1; + memset (b_quotient, 0, +=09 4 * dividend_blocks_needed * sizeof (HOST_HALF_WIDE_INT)); + } wi_unpack (b_dividend, dividend.get_val (), dividend.get_len (), =09 dividend_blocks_needed, dividend_prec, UNSIGNED); wi_unpack (b_divisor, divisor.get_val (), divisor.get_len (), @@ -1924,7 +1961,8 @@ wi::divmod_internal (HOST_WIDE_INT *quot while (n > 1 && b_divisor[n - 1] =3D=3D 0) n--; =20 - memset (b_quotient, 0, sizeof (b_quotient)); + if (b_quotient =3D=3D b_quotient_buf) + memset (b_quotient_buf, 0, sizeof (b_quotient_buf)); =20 divmod_internal_2 (b_quotient, b_remainder, b_dividend, b_divisor, m, n)= ; =20 @@ -1970,6 +2008,8 @@ wi::lshift_large (HOST_WIDE_INT *val, co =20 /* The whole-block shift fills with zeros. */ unsigned int len =3D BLOCKS_NEEDED (precision); + if (UNLIKELY (len > WIDE_INT_MAX_ELTS)) + len =3D xlen + skip + 1; for (unsigned int i =3D 0; i < skip; ++i) val[i] =3D 0; =20 @@ -1993,22 +2033,17 @@ wi::lshift_large (HOST_WIDE_INT *val, co return canonize (val, len, precision); } =20 -/* Right shift XVAL by SHIFT and store the result in VAL. Return the +/* Right shift XVAL by SHIFT and store the result in VAL. LEN is the number of blocks in VAL. The input has XPRECISION bits and the output has XPRECISION - SHIFT bits. */ -static unsigned int +static void rshift_large_common (HOST_WIDE_INT *val, const HOST_WIDE_INT *xval, -=09=09 unsigned int xlen, unsigned int xprecision, -=09=09 unsigned int shift) +=09=09 unsigned int xlen, unsigned int shift, unsigned int len) { /* Split the shift into a whole-block shift and a subblock shift. */ unsigned int skip =3D shift / HOST_BITS_PER_WIDE_INT; unsigned int small_shift =3D shift % HOST_BITS_PER_WIDE_INT; =20 - /* Work out how many blocks are needed to store the significant bits - (excluding the upper zeros or signs). */ - unsigned int len =3D BLOCKS_NEEDED (xprecision - shift); - /* It's easier to handle the simple block case specially. */ if (small_shift =3D=3D 0) for (unsigned int i =3D 0; i < len; ++i) @@ -2025,7 +2060,6 @@ rshift_large_common (HOST_WIDE_INT *val, =09 val[i] |=3D curr << (-small_shift % HOST_BITS_PER_WIDE_INT); =09} } - return len; } =20 /* Logically right shift XVAL by SHIFT and store the result in VAL. @@ -2036,11 +2070,18 @@ wi::lrshift_large (HOST_WIDE_INT *val, c =09=09 unsigned int xlen, unsigned int xprecision, =09=09 unsigned int precision, unsigned int shift) { - unsigned int len =3D rshift_large_common (val, xval, xlen, xprecision, s= hift); + /* Work out how many blocks are needed to store the significant bits + (excluding the upper zeros or signs). */ + unsigned int blocks_needed =3D BLOCKS_NEEDED (xprecision - shift); + unsigned int len =3D blocks_needed; + if (UNLIKELY (len > WIDE_INT_MAX_ELTS) && len > xlen && xval[xlen - 1] >= =3D 0) + len =3D xlen; + + rshift_large_common (val, xval, xlen, shift, len); =20 /* The value we just created has precision XPRECISION - SHIFT. Zero-extend it to wider precisions. */ - if (precision > xprecision - shift) + if (precision > xprecision - shift && len =3D=3D blocks_needed) { unsigned int small_prec =3D (xprecision - shift) % HOST_BITS_PER_WID= E_INT; if (small_prec) @@ -2063,11 +2104,18 @@ wi::arshift_large (HOST_WIDE_INT *val, c =09=09 unsigned int xlen, unsigned int xprecision, =09=09 unsigned int precision, unsigned int shift) { - unsigned int len =3D rshift_large_common (val, xval, xlen, xprecision, s= hift); + /* Work out how many blocks are needed to store the significant bits + (excluding the upper zeros or signs). */ + unsigned int blocks_needed =3D BLOCKS_NEEDED (xprecision - shift); + unsigned int len =3D blocks_needed; + if (UNLIKELY (len > WIDE_INT_MAX_ELTS) && len > xlen) + len =3D xlen; + + rshift_large_common (val, xval, xlen, shift, len); =20 /* The value we just created has precision XPRECISION - SHIFT. Sign-extend it to wider types. */ - if (precision > xprecision - shift) + if (precision > xprecision - shift && len =3D=3D blocks_needed) { unsigned int small_prec =3D (xprecision - shift) % HOST_BITS_PER_WID= E_INT; if (small_prec) @@ -2399,9 +2447,12 @@ from_int (int i) static void assert_deceq (const char *expected, const wide_int_ref &wi, signop sgn) { - char buf[WIDE_INT_PRINT_BUFFER_SIZE]; - print_dec (wi, buf, sgn); - ASSERT_STREQ (expected, buf); + char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p =3D buf; + unsigned len =3D wi.get_len (); + if (UNLIKELY (len > WIDE_INT_MAX_ELTS)) + p =3D XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4); + print_dec (wi, p, sgn); + ASSERT_STREQ (expected, p); } =20 /* Likewise for base 16. */ @@ -2409,9 +2460,12 @@ assert_deceq (const char *expected, cons static void assert_hexeq (const char *expected, const wide_int_ref &wi) { - char buf[WIDE_INT_PRINT_BUFFER_SIZE]; - print_hex (wi, buf); - ASSERT_STREQ (expected, buf); + char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p =3D buf; + unsigned len =3D wi.get_len (); + if (UNLIKELY (len > WIDE_INT_MAX_ELTS)) + p =3D XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4); + print_hex (wi, p); + ASSERT_STREQ (expected, p); } =20 /* Test cases. */ --- gcc/print-tree.cc.jj=092023-07-11 13:40:39.000000000 +0200 +++ gcc/print-tree.cc=092023-09-28 14:12:40.257284557 +0200 @@ -365,13 +365,13 @@ print_node (FILE *file, const char *pref fputs (code =3D=3D CALL_EXPR ? " must-tail-call" : " static", file); if (TREE_DEPRECATED (node)) fputs (" deprecated", file); - if (TREE_UNAVAILABLE (node)) - fputs (" unavailable", file); if (TREE_VISITED (node)) fputs (" visited", file); =20 if (code !=3D TREE_VEC && code !=3D INTEGER_CST && code !=3D SSA_NAME) { + if (TREE_UNAVAILABLE (node)) +=09fputs (" unavailable", file); if (TREE_LANG_FLAG_0 (node)) =09fputs (" tree_0", file); if (TREE_LANG_FLAG_1 (node)) --- gcc/dwarf2out.cc.jj=092023-09-28 12:05:50.905151340 +0200 +++ gcc/dwarf2out.cc=092023-09-28 13:06:34.492017940 +0200 @@ -397,7 +397,7 @@ dump_struct_debug (tree type, enum debug of the number. */ =20 static unsigned int -get_full_len (const wide_int &op) +get_full_len (const rwide_int &op) { int prec =3D wi::get_precision (op); return ((prec + HOST_BITS_PER_WIDE_INT - 1) @@ -3900,7 +3900,7 @@ static void add_data_member_location_att =09=09=09=09=09=09struct vlr_context *); static bool add_const_value_attribute (dw_die_ref, machine_mode, rtx); static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *); -static void insert_wide_int (const wide_int &, unsigned char *, int); +static void insert_wide_int (const rwide_int &, unsigned char *, int); static unsigned insert_float (const_rtx, unsigned char *); static rtx rtl_for_decl_location (tree); static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool)= ; @@ -4598,14 +4598,14 @@ AT_unsigned (dw_attr_node *a) =20 static inline void add_AT_wide (dw_die_ref die, enum dwarf_attribute attr_kind, -=09 const wide_int& w) +=09 const rwide_int& w) { dw_attr_node attr; =20 attr.dw_attr =3D attr_kind; attr.dw_attr_val.val_class =3D dw_val_class_wide_int; attr.dw_attr_val.val_entry =3D NULL; - attr.dw_attr_val.v.val_wide =3D ggc_alloc (); + attr.dw_attr_val.v.val_wide =3D ggc_alloc (); *attr.dw_attr_val.v.val_wide =3D w; add_dwarf_attr (die, &attr); } @@ -16714,7 +16714,7 @@ mem_loc_descriptor (rtx rtl, machine_mod =09 mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external =3D 0; =09 mem_loc_result->dw_loc_oprnd2.val_class =09 =3D dw_val_class_wide_int; -=09 mem_loc_result->dw_loc_oprnd2.v.val_wide =3D ggc_alloc (); +=09 mem_loc_result->dw_loc_oprnd2.v.val_wide =3D ggc_alloc (); =09 *mem_loc_result->dw_loc_oprnd2.v.val_wide =3D rtx_mode_t (rtl, mode); =09} break; @@ -17288,7 +17288,7 @@ loc_descriptor (rtx rtl, machine_mode mo =09 loc_result =3D new_loc_descr (DW_OP_implicit_value, =09=09=09=09 GET_MODE_SIZE (int_mode), 0); =09 loc_result->dw_loc_oprnd2.val_class =3D dw_val_class_wide_int; -=09 loc_result->dw_loc_oprnd2.v.val_wide =3D ggc_alloc (); +=09 loc_result->dw_loc_oprnd2.v.val_wide =3D ggc_alloc (); =09 *loc_result->dw_loc_oprnd2.v.val_wide =3D rtx_mode_t (rtl, int_mode); =09} break; @@ -20189,7 +20189,7 @@ extract_int (const unsigned char *src, u /* Writes wide_int values to dw_vec_const array. */ =20 static void -insert_wide_int (const wide_int &val, unsigned char *dest, int elt_size) +insert_wide_int (const rwide_int &val, unsigned char *dest, int elt_size) { int i; =20 @@ -20274,7 +20274,7 @@ add_const_value_attribute (dw_die_ref di =09 && (GET_MODE_PRECISION (int_mode) =09 & (HOST_BITS_PER_WIDE_INT - 1)) =3D=3D 0) =09{ -=09 wide_int w =3D rtx_mode_t (rtl, int_mode); +=09 rwide_int w =3D rtx_mode_t (rtl, int_mode); =09 add_AT_wide (die, DW_AT_const_value, w); =09 return true; =09} --- gcc/dwarf2out.h.jj=092023-09-27 10:37:38.536849616 +0200 +++ gcc/dwarf2out.h=092023-09-28 13:06:34.492017940 +0200 @@ -30,7 +30,7 @@ typedef struct dw_cfi_node *dw_cfi_ref; typedef struct dw_loc_descr_node *dw_loc_descr_ref; typedef struct dw_loc_list_struct *dw_loc_list_ref; typedef struct dw_discr_list_node *dw_discr_list_ref; -typedef wide_int *wide_int_ptr; +typedef rwide_int *rwide_int_ptr; =20 =20 /* Call frames are described using a sequence of Call Frame @@ -252,7 +252,7 @@ struct GTY(()) dw_val_node { unsigned HOST_WIDE_INT =09GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned; double_int GTY ((tag ("dw_val_class_const_double"))) val_double; - wide_int_ptr GTY ((tag ("dw_val_class_wide_int"))) val_wide; + rwide_int_ptr GTY ((tag ("dw_val_class_wide_int"))) val_wide; dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec; struct dw_val_die_union =09{ --- gcc/tree.h.jj=092023-09-27 10:37:39.114841566 +0200 +++ gcc/tree.h=092023-09-28 13:06:34.506017744 +0200 @@ -6258,13 +6258,17 @@ namespace wi template struct int_traits > { - static const enum precision_type precision_type =3D CONST_PRECISION; + static const enum precision_type precision_type + =3D N =3D=3D ADDR_MAX_PRECISION ? CONST_PRECISION : WIDEST_CONST_PRE= CISION; static const bool host_dependent_precision =3D false; static const bool is_sign_extended =3D true; static const unsigned int precision =3D N; + static const unsigned int inl_precision + =3D N =3D=3D ADDR_MAX_PRECISION ? 0 +=09 : N / WIDEST_INT_MAX_PRECISION * WIDE_INT_MAX_PRECISION; }; =20 - typedef extended_tree widest_extended_tree; + typedef extended_tree widest_extended_tree; typedef extended_tree offset_extended_tree; =20 typedef const generic_wide_int tree_to_widest_ref= ; @@ -6292,7 +6296,8 @@ namespace wi tree_to_poly_wide_ref to_poly_wide (const_tree); =20 template - struct ints_for >, CONST_PRECISION> + struct ints_for >, +=09=09 int_traits >::precision_type> { typedef generic_wide_int > extended; static extended zero (const extended &); @@ -6308,7 +6313,7 @@ namespace wi =20 /* Used to convert a tree to a widest2_int like this: widest2_int foo =3D widest2_int_cst (some_tree). */ -typedef generic_wide_int > +typedef generic_wide_int = > widest2_int_cst; =20 /* Refer to INTEGER_CST T as though it were a widest_int. @@ -6444,7 +6449,7 @@ wi::extended_tree ::get_len () const { if (N =3D=3D ADDR_MAX_PRECISION) return TREE_INT_CST_OFFSET_NUNITS (m_t); - else if (N >=3D WIDE_INT_MAX_PRECISION) + else if (N >=3D WIDEST_INT_MAX_PRECISION) return TREE_INT_CST_EXT_NUNITS (m_t); else /* This class is designed to be used for specific output precisions @@ -6530,7 +6535,8 @@ wi::to_poly_wide (const_tree t) template inline generic_wide_int > wi::ints_for >, -=09 wi::CONST_PRECISION>::zero (const extended &x) +=09 wi::int_traits >::precision_type +=09 >::zero (const extended &x) { return build_zero_cst (TREE_TYPE (x.get_tree ())); } --- gcc/value-range.cc.jj=092023-09-27 10:37:39.240839811 +0200 +++ gcc/value-range.cc=092023-09-28 13:06:34.512017660 +0200 @@ -245,17 +245,24 @@ vrange::dump (FILE *file) const void irange_bitmask::dump (FILE *file) const { - char buf[WIDE_INT_PRINT_BUFFER_SIZE]; + char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p; pretty_printer buffer; =20 pp_needs_newline (&buffer) =3D true; buffer.buffer->stream =3D file; pp_string (&buffer, "MASK "); - print_hex (m_mask, buf); - pp_string (&buffer, buf); + unsigned len_mask =3D m_mask.get_len (); + unsigned len_val =3D m_value.get_len (); + unsigned len =3D MAX (len_mask, len_val); + if (len > WIDE_INT_MAX_ELTS) + p =3D XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4); + else + p =3D buf; + print_hex (m_mask, p); + pp_string (&buffer, p); pp_string (&buffer, " VALUE "); - print_hex (m_value, buf); - pp_string (&buffer, buf); + print_hex (m_value, p); + pp_string (&buffer, p); pp_flush (&buffer); } =20 --- gcc/c/c-decl.cc.jj=092023-09-27 10:37:38.428851119 +0200 +++ gcc/c/c-decl.cc=092023-09-28 13:06:34.514017632 +0200 @@ -12355,11 +12355,11 @@ declspecs_add_type (location_t loc, stru =09=09=09=09spec.expr); =09=09 return specs; =09=09 } -=09=09 if (wi::to_widest (spec.expr) > WIDE_INT_MAX_PRECISION - 1) +=09=09 if (wi::to_widest (spec.expr) > WIDEST_INT_MAX_PRECISION - 1) =09=09 { =09=09 error_at (loc, "%<_BitInt%> argument %qE is larger than " =09=09=09=09 "% %qd", -=09=09=09=09spec.expr, (int) WIDE_INT_MAX_PRECISION - 1); +=09=09=09=09spec.expr, (int) WIDEST_INT_MAX_PRECISION - 1); =09=09 return specs; =09=09 } =09=09 specs->u.bitint_prec =3D tree_to_uhwi (spec.expr); --- gcc/gengtype.cc.jj=092023-09-27 10:37:38.751846621 +0200 +++ gcc/gengtype.cc=092023-09-28 13:06:34.515017618 +0200 @@ -5236,7 +5236,6 @@ main (int argc, char **argv) POS_HERE (do_scalar_typedef ("double_int", &pos)); POS_HERE (do_scalar_typedef ("poly_int64_pod", &pos)); POS_HERE (do_scalar_typedef ("offset_int", &pos)); - POS_HERE (do_scalar_typedef ("widest_int", &pos)); POS_HERE (do_scalar_typedef ("int64_t", &pos)); POS_HERE (do_scalar_typedef ("poly_int64", &pos)); POS_HERE (do_scalar_typedef ("poly_uint64", &pos)); --- gcc/tree-ssa-loop-niter.cc.jj=092023-09-27 10:37:39.072842151 +0200 +++ gcc/tree-ssa-loop-niter.cc=092023-09-28 13:06:34.515017618 +0200 @@ -3873,12 +3873,17 @@ do_warn_aggressive_loop_optimizations (c return; =20 gimple *estmt =3D last_nondebug_stmt (e->src); - char buf[WIDE_INT_PRINT_BUFFER_SIZE]; - print_dec (i_bound, buf, TYPE_UNSIGNED (TREE_TYPE (loop->nb_iterations)) + char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p; + unsigned len =3D i_bound.get_len (); + if (len > WIDE_INT_MAX_ELTS) + p =3D XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4); + else + p =3D buf; + print_dec (i_bound, p, TYPE_UNSIGNED (TREE_TYPE (loop->nb_iterations)) =09 ? UNSIGNED : SIGNED); auto_diagnostic_group d; if (warning_at (gimple_location (stmt), OPT_Waggressive_loop_optimizatio= ns, -=09=09 "iteration %s invokes undefined behavior", buf)) +=09=09 "iteration %s invokes undefined behavior", p)) inform (gimple_location (estmt), "within this loop"); loop->warned_aggressive_loop_optimizations =3D true; } --- gcc/c-family/c-warn.cc.jj=092023-09-27 10:37:38.334852428 +0200 +++ gcc/c-family/c-warn.cc=092023-09-28 13:06:34.524017491 +0200 @@ -1517,13 +1517,15 @@ match_case_to_enum_1 (tree key, tree typ return; =20 char buf[WIDE_INT_PRINT_BUFFER_SIZE]; + wide_int w =3D wi::to_wide (key); =20 + gcc_assert (w.get_len () <=3D WIDE_INT_MAX_ELTS); if (tree_fits_uhwi_p (key)) - print_dec (wi::to_wide (key), buf, UNSIGNED); + print_dec (w, buf, UNSIGNED); else if (tree_fits_shwi_p (key)) - print_dec (wi::to_wide (key), buf, SIGNED); + print_dec (w, buf, SIGNED); else - print_hex (wi::to_wide (key), buf); + print_hex (w, buf); =20 if (TYPE_NAME (type) =3D=3D NULL_TREE) warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label)), --- gcc/c-family/c-cppbuiltin.cc.jj=092023-09-27 10:37:38.226853933 +0200 +++ gcc/c-family/c-cppbuiltin.cc=092023-09-28 13:06:34.541017253 +0200 @@ -1195,10 +1195,10 @@ c_cpp_builtins (cpp_reader *pfile) struct bitint_info info; /* For now, restrict __BITINT_MAXWIDTH__ to what can be represented = in =09 wide_int and widest_int. */ - if (targetm.c.bitint_type_info (WIDE_INT_MAX_PRECISION - 1, &info)) + if (targetm.c.bitint_type_info (WIDEST_INT_MAX_PRECISION - 1, &info)= ) =09{ =09 cpp_define_formatted (pfile, "__BITINT_MAXWIDTH__=3D%d", -=09=09=09=09(int) WIDE_INT_MAX_PRECISION - 1); +=09=09=09=09(int) WIDEST_INT_MAX_PRECISION - 1); =09 if (flag_building_libgcc) =09 { =09 scalar_int_mode limb_mode --- gcc/c-family/c-lex.cc.jj=092023-09-27 10:37:38.272853292 +0200 +++ gcc/c-family/c-lex.cc=092023-09-28 13:06:34.550017127 +0200 @@ -843,7 +843,7 @@ interpret_integer (const cpp_token *toke int max_bits_per_digit =3D 4; // ceil (log2 (10)) unsigned int prefix_len =3D 0; bool hex =3D false; - const int bitint_maxwidth =3D WIDE_INT_MAX_PRECISION - 1; + const int bitint_maxwidth =3D WIDEST_INT_MAX_PRECISION - 1; if ((flags & CPP_N_RADIX) =3D=3D CPP_N_OCTAL) =09{ =09 max_bits_per_digit =3D 3; --- gcc/value-range-pretty-print.cc.jj=092023-09-27 10:37:39.170840787 +020= 0 +++ gcc/value-range-pretty-print.cc=092023-09-28 13:06:34.550017127 +0200 @@ -99,12 +99,19 @@ vrange_printer::print_irange_bitmasks (c return; =20 pp_string (pp, " MASK "); - char buf[WIDE_INT_PRINT_BUFFER_SIZE]; - print_hex (bm.mask (), buf); - pp_string (pp, buf); + char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p; + unsigned len_mask =3D bm.mask ().get_len (); + unsigned len_val =3D bm.value ().get_len (); + unsigned len =3D MAX (len_mask, len_val); + if (len > WIDE_INT_MAX_ELTS) + p =3D XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4); + else + p =3D buf; + print_hex (bm.mask (), p); + pp_string (pp, p); pp_string (pp, " VALUE "); - print_hex (bm.value (), buf); - pp_string (pp, buf); + print_hex (bm.value (), p); + pp_string (pp, p); } =20 void --- gcc/poly-int.h.jj=092023-09-27 10:37:38.874844909 +0200 +++ gcc/poly-int.h=092023-09-28 13:06:34.551017113 +0200 @@ -97,6 +97,18 @@ struct poly_coeff_traits +struct poly_coeff_traits +{ + typedef WI_UNARY_RESULT (T) result; + typedef int int_type; + /* These types are always signed. */ + static const int signedness =3D 1; + static const int precision =3D wi::int_traits::precision; + static const int inl_precision =3D wi::int_traits::inl_precision; + static const int rank =3D precision * 2 / CHAR_BIT; +}; + /* Information about a pair of coefficient types. */ template struct poly_coeff_pair_traits --- gcc/godump.cc.jj=092023-09-27 10:37:38.805845870 +0200 +++ gcc/godump.cc=092023-09-28 13:06:34.551017113 +0200 @@ -1154,7 +1154,11 @@ go_output_typedef (class godump_containe =09 snprintf (buf, sizeof buf, HOST_WIDE_INT_PRINT_UNSIGNED, =09=09 tree_to_uhwi (value)); =09 else -=09 print_hex (wi::to_wide (element), buf); +=09 { +=09 wide_int w =3D wi::to_wide (element); +=09 gcc_assert (w.get_len () <=3D WIDE_INT_MAX_ELTS); +=09 print_hex (w, buf); +=09 } =20 =09 mhval->value =3D xstrdup (buf); =09 *slot =3D mhval; --- gcc/value-range.h.jj=092023-09-27 10:37:39.268839422 +0200 +++ gcc/value-range.h=092023-09-28 13:06:34.555017057 +0200 @@ -626,7 +626,9 @@ irange::maybe_resize (int needed) { m_max_ranges =3D HARD_MAX_RANGES; wide_int *newmem =3D new wide_int[m_max_ranges * 2]; - memcpy (newmem, m_base, sizeof (wide_int) * num_pairs () * 2); + unsigned n =3D num_pairs () * 2; + for (unsigned i =3D 0; i < n; ++i) +=09newmem[i] =3D m_base[i]; m_base =3D newmem; } } --- gcc/stor-layout.cc.jj=092023-09-27 10:37:38.951843836 +0200 +++ gcc/stor-layout.cc=092023-09-28 13:06:34.560016987 +0200 @@ -2946,7 +2946,7 @@ set_min_and_max_values_for_integral_type if (precision < 1) return; =20 - gcc_assert (precision <=3D WIDE_INT_MAX_PRECISION); + gcc_assert (precision <=3D WIDEST_INT_MAX_PRECISION); =20 TYPE_MIN_VALUE (type) =3D wide_int_to_tree (type, wi::min_value (precision, sgn)); --- gcc/wide-int-print.cc.jj=092023-09-27 10:37:39.379837876 +0200 +++ gcc/wide-int-print.cc=092023-09-28 14:24:04.824794192 +0200 @@ -74,9 +74,12 @@ print_decs (const wide_int_ref &wi, char void print_decs (const wide_int_ref &wi, FILE *file) { - char buf[WIDE_INT_PRINT_BUFFER_SIZE]; - print_decs (wi, buf); - fputs (buf, file); + char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p =3D buf; + unsigned len =3D wi.get_len (); + if (UNLIKELY (len > WIDE_INT_MAX_ELTS)) + p =3D XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4); + print_decs (wi, p); + fputs (p, file); } =20 /* Try to print the unsigned self in decimal to BUF if the number fits @@ -98,9 +101,12 @@ print_decu (const wide_int_ref &wi, char void print_decu (const wide_int_ref &wi, FILE *file) { - char buf[WIDE_INT_PRINT_BUFFER_SIZE]; - print_decu (wi, buf); - fputs (buf, file); + char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p =3D buf; + unsigned len =3D wi.get_len (); + if (UNLIKELY (len > WIDE_INT_MAX_ELTS)) + p =3D XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4); + print_decu (wi, p); + fputs (p, file); } =20 void @@ -134,9 +140,12 @@ print_hex (const wide_int_ref &val, char void print_hex (const wide_int_ref &wi, FILE *file) { - char buf[WIDE_INT_PRINT_BUFFER_SIZE]; - print_hex (wi, buf); - fputs (buf, file); + char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p =3D buf; + unsigned len =3D wi.get_len (); + if (UNLIKELY (len > WIDE_INT_MAX_ELTS)) + p =3D XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4); + print_hex (wi, p); + fputs (p, file); } =20 /* Print larger precision wide_int. Not defined as inline in a header --- gcc/testsuite/gcc.dg/bitint-38.c.jj=092023-09-28 15:02:23.182069788 +02= 00 +++ gcc/testsuite/gcc.dg/bitint-38.c=092023-09-28 15:02:39.168848976 +0200 @@ -0,0 +1,17 @@ +/* PR c/102989 */ +/* { dg-do compile { target { bitint } } } */ + +#if __BITINT_MAXWIDTH__ >=3D 16319 +constexpr unsigned _BitInt(16319) a + =3D 46809856770167726127621548193677044225438364376699537824160022717939= 628343291686588133221586710648915925157749537208566348709231774324477059728= 763319900537499845533358728035749014999310181139205148376149598710826496473= 833711815515586271543891072166123033253318533558175760051184685411593263726= 196963313436586869536391457057811006447186847584134858936693364541098769997= 908014021284990908118817091046496748623135893521289709626062603305553614183= 559928449847473785848765847011514477192311482631228386303550370060014144072= 442636469963633024041427127562602129493942248325061962900595999224341866123= 012213266776978118379033875934588490382169559099157722852052372530204821544= 784157311384081159363841342505493821326296144831789857414053309000499273268= 852511500478297389324409142700039689042715222530866107895467106606923445375= 759318175390086520343903540248030641357223961046714259192080918736743807117= 010096956744004469142748795978563733838165130991678206367028604654758524083= 789230717092884948587718679328070760084086678347179914817925081838771618312= 732334619953338746336344235621880377969700575932441037647685522242087626242= 598557198281818035387041014982421454431301328519954419349662422321998640294= 484962248942200767856494617479789279508933089953562472777752533078949270357= 456411225295514777094292976154560435086940424655827475235351037015722948500= 440213104315345429039792938727637405493857897687860646721735939868427505051= 910441391428602410680811634071227305942736229370315135549833621317069889444= 840536939875718852316046029271487585787996817357832819135821597249351327129= 787563440079330192925005282225863601565085768302390070984541083848793677853= 325040788618095457604634069790858402095129504884493804786565702907285079744= 297614689529418499373699950548566574281131379540553067419984805580275990178= 637682206952934297126196311933247650406428586936204966208340578982843313215= 493324281743280941581054818065875039369227272958623284206565849097120192778= 001425881533311545969511794227355187664684482107672366404028277283451141989= 135127816901710398709480382959428635234046834661872608878149262681618865733= 135910417181982267380585631782849903908808822313725829737392904330767357009= 039694778959879992292864384353261701216481107461888177462262894353903797488= 381268913080186091509003587024406100581941813006839098647031467785360508010= 331341183790435828783740154625741324046693989352750893154106524192987230720= 387644388210619326254465229013236469167191033200612786414699140401536668356= 931724805794959607035492936115832695555160023607526843504410588016279838079= 916160798736528245866203159909692182517620270789073002369870685576293269168= 825936535896407659582457777527599118314911837204720605511846311286460406385= 389482040724983787136893494143811968060552854688725693433424607559674641029= 795445863235817142871414182091818338443568133237931754104825239171071219662= 340633870206119521372456930328540224285367138611314821153569168546183645829= 503753803437831805510824008241444120530040152673239995922834692652858685274= 338949097873478792672199985538879471183716442300771962610917900546611370645= 076526968758081982277218930108450362729738967513422822233728686764111051106= 198023124788453349244289893674342964195831413532907340649577636920815803211= 588385069101056904898394112677147799097609225239197281269166984744679850724= 410612166788542302561376925810277385553750973329580501331393740228280489721= 384722107264711160517234946456408991490649350813385538962717766342605776325= 208628632534381125475768180306827627804875799742528433471319022681846302307= 446190017695801005557243498313517114536524233927332698446518106428726464547= 083209111510064058410437557730405695196945620013848531356000927233822810363= 776386328926167325872673675340704414366407947949697258056053449480617081046= 930477300587359062628007238799966852254674798570159961397510118854385785214= 155925163405867671830800032486980962819944268156561566291262602279606441449= 610634423643128569768835770799298996656155717172997209353300747694786221592= 258320481118901555050564208247540064763952078218777682539559825742171410647= 386979764267826638075587335674781227397769160414784274115172291946473489032= 677259497902240322819107558691046420487025467429043766886117763971311276299= 639024610203099491718695782698208419415687039831233605910052156603409274069= 464261319290985064400393374512929106257634121387481551009983570872335543297= 009013967112023291074766590619136016025951219816084978419759730010622394596= 088660312713603712000086496866865145241104837289560738290749427881097147566= 394494879145861866225023837516652348484750734204006680185622232898866204957= 929960054568249041275448362105119023162319626554939196425978017807049564253= 888378950337940653127933886695515764665491340518187925418918590429832586550= 339568878631106766927360967060307658260725352708497774453318714564268623635= 016559398042857511932991192138224078050452742263065408694106024275713131318= 4709635181001199631726283364158943337968797uwb + + 99354435180574564299271266552222578172075113116713358325600655730552= 766787479906529073488397418185627579390846490733481721083971838270203779417= 259831075136362874065305263582535084372902419372769083862829043530791029045= 356756086045764861629983194277028512784082136414548372230796164016158756724= 532501484216792238294178342275181330910551802702492661616766771761496751642= 576408123442979356507296298018787580599440901688627305198172033523414583103= 638114823180832702324343293173238228189911345006016698689223960135129694778= 394564723458123123219242152418497721476874557602245592409527373190093485408= 949663635681583495013552292646467700180715905024417027872690979739798998376= 831221941031100897284256766902460911469939550379184257728400222882228329325= 425160915011494771608565644643769102932300919635731192306480266678963993527= 909826119575699789720381785195702784475407075028616785026579051927432258932= 256639948075689186448982737022854836763857176511040420021053529931765121664= 200850644524317531813658058335489226767488904124203326946090968197797656003= 452163903943072575567782237434439589839621137231935512478979954237623480921= 038936837113738971391682894202676606114099476445487150077878329592511675531= 750966391476747761179731004479032436269028923822637675913280382357085934015= 637930194181244531663864717924684210038558942065843547314893636681340779462= 035460672372356577464802968316517917903859813975584589059046413942462797827= 467360091018623668680683634119763885576979219143171793712064440853907796348= 313697233700507646788528467793694972323747806919052809923680797627473522455= 196072641541971489588969556619042149091849522899961420506048216087499004178= 451377275969031004523500675513058409982804827752098832788730718955887518114= 623425178257534938149979184184374554749924222439195499673719644234574402872= 962708556058509546859126443033540190587169167355225330653230577554798036687= 825302503819882110750346557601232502494414406843384509538232903469096898225= 276526987235028723125703052611967684774988980207930718087589033817968738686= 823788509252116293927606286852227450735441166156355579108053576235902180237= 158327163725325193728620938285457973255678036919980517851560658615668888714= 611301335220393218434390179643820300807524767093987313411730624302750031119= 549076278372084883486866669047657106569177064709243184321601554507260076680= 354945717797931292122421012932748532378508488061527744636892434266832958846= 486807902403630970152183479663991663800903706285912887123051331718696396799= 228540664930767731669701904829888280170310168915619719862796753719630209324= 693372640613177863305668393839893847609355902992879635468638481199994517395= 484051240015140330966956055807661216114406385499888959702624251332181598480= 617272171634871318064816867668437899714652479035348538379514138457866671224= 271826489891565995296474394195537851585616131140232673038699275651705077817= 823664470113408512581785341015859500814234377037784923474482304738976435057= 739573855041121824466905850338237471759669290912936932010618586701412091290= 914528612922762760129106240712411654020891616069444238262454616085949357324= 819001982408622934094423088006900195508316304798830005798846146019069617230= 113544498045767943398260569869576800909160468486734197235296943846538094003= 772185450752691487661291946370394082255156780133321880749972176678354949400= 430149178774383549026731074531642752800102510403600409373087389256894757251= 316390320119790096427135422928942190593529729331511123761973838149253632886= 709955562694478049949250867917281369066932495071150978070603658721109982107= 683360783895087241848635972859877369120730719801371625907796646750334291193= 278553078271746737492574629830542216317975270099875957324602221973676084409= 734882118984714393020513888068185216596858736723838280213298481534102049266= 077109716782685416775844216952380117843513860478691587871566346306938724280= 678649803200632934358875747458590670249884857423532785487044675442987935115= 835876597137116770657923711993294193723927203219818622698900248323489998654= 493398563392203868531626419844449349981762488217031547747940268634238466653= 611479125803101793332398493141451581038137243712771560318260702136561892184= 285511714925793677366526502405108405244792806619221493703814048636680382299= 221050646583350833149468425459780504970217952171249479595750654717498722788= 027563713908714410042326332526118257486585935406678310988740272233275415237= 428577509541196157085415141451108639250492045175740008247979008175853769614= 627545214951001988296751009580666395319581067041597172650352055971610478795= 108499005875657466032257631298774343179498421057423869658861371177986421681= 907333674141267979294346275323078554488410354337952290312755458858728768488= 466666664754658669053322930953814940967023286499207405066589305030531627779= 448214333834072831551787079709064580238271416811403729683560846170010538704= 990798843840198208755858431290828946877405339467637568469249528252513830263= 64635539377880784234770789463152435704464616uwb; +constexpr unsigned _BitInt(16319) b + =3D 20129744567093027275741005070628998262449166046517026903695683755854= 448756834360166513132405078796314602781998330705368407367482030156637206994= 877425582250124595106718397028199112773892105727478029626122540718672466812= 244172521968825004812596684190534400169291245019886664334632347203172906471= 830047918779870667296830826108769036384267604969509336398421516482677170697= 323144807237345130767733861415665037591249948490085867356183319101541167176= 586195051721766552194667530417142250556133895688441663400613014781276825394= 358975458967475147806589013506569415945496841131100738180426238464950629268= 379774013285627049621529192047736803089092751891513992605419086502588233332= 057296638567290306093910878742093500873864277174719410183640765821580587831= 967716708363976225535905317908137780497267444416760176647705834046996010820= 212494244083222254037700699529789991033448979912128507710343500466786839351= 071045788239200231971288879352062329627654083430317549832483148696514166354= 870702716570783257707960927427529476249626444239951812293100465038963807939= 297639901456086408459677292249078230581624034160083198437374539728677906306= 289960873601083706201882999243554025429957091619812945018432503309674349427= 513057767160754691227365332241845175797106713295593063635202655344273695438= 810685712451003351469460085582752740414723264094665962205140763820691773090= 780866423727990711323748512766522537850976590598658397979845215595029782750= 537140603588592215363608992433922289542233458102634259275757690440754308009= 593855238137227351798446486981151672766513716998027602215751256719370429397= 129549459120277202327118788743080998483470436192625398340057850391478909668= 185290635380423955404607217710958636050373730838469336370845039431945543326= 700579270919052885975364141422331087288874462285858637176621255141698264412= 903522678033317989170115880081516284097559300133507799471895326457336815172= 421155995525168781635131143991136416642016744949082321204689839861376266795= 485532171923826942486502913400286963940309484507484129423576156798044985198= 780159055788525538310878089397895175129162099671894337526801235280427428321= 205321530735108239848594278720839317921782831352363541199919557577597546876= 704462612904924694431903072332864341465745291866718067601041404212430941956= 177407763481845568339170224196193106463030409080073136605433869775860974939= 991008596874978506245689726966715206639438259724689301019692258116991317695= 012205036157177039536905494005833948384397446492918129185274359806145454148= 241131925838562069991934872329314452016900728948186477387223161994145551216= 156032211038319475270853818660079065895119923373317496777184177315345923787= 700803986965175033224375435249224949151191006574511519055220741174631165879= 299688118138728380219550143006894817522270338472413899079751917314505754802= 052988622174392135207139715960212346858882422543222621408433817817181595201= 086403368301839080592455115463829425708132345811270911456928961301265223101= 989524481521721969838980208647528038509328501705428950749820080720418776718= 084142086501267418284241370398868561282277848391673847937247873117719906103= 441015578245152673184719538896073697272475250261227685660058944107087333786= 104761624391816175414338999215260190162551489343436332492645887029551964578= 826432156700872459216605843463884228343167159924792752429816064841479438134= 662749621639560203443871326810129872763539114284811330805213188716333471069= 710270583945841626338361700846410927750916663908367683188084193258384935122= 236639934335284160522042065088923421928660724095726039642836343542211473282= 392554371973074108770797447448654428325845253304889062021031599531436606775= 029315849674756213988932349651640552571880780461452187094400408403309806507= 698230071584809861634596000425300485805174853406774961321055086995665513868= 382285048348264250174388793184093524675621762558537763747237314473883173686= 633576273836946507237880619627632543093619281096675643877749217588495383292= 078713230253993525326209732859301842016440189010027733234997657748351253359= 664018894197346327201303258090754079801393874104215986193719394144148559622= 409051961205332355846077533183278890738832391535561074612724819789952480872= 328880408266970201766239451001690274739141595541572957753788951050043026811= 943691163688663710637928472363177936029259448725818579129920714382357882142= 208643606823754520733994646572586821541644398149238544337745998203264678454= 665487925173493921777764033537269522992103115842823750405588538846833724101= 543165897489915300004787110814394934465518176677482202804123781727309993329= 004830726928892557850582806559007396866888620985629055058474721708813614135= 721948922060211334334572381348586196886746758900465692833094336637178459072= 850215866106799456460266354416689624866015411034238864944123721969568161372= 557215009049887790769403406590484422511214573790761107726077762451440539965= 975955360773797196902546431341823788555069435728043202455375041817472821677= 779625286961992491729576392881089462100341878uwb + / 42uwb; +constexpr unsigned _BitInt(16319) c + =3D 26277232382028447345935282100364413976442241120491848683780108318345= 774920397366452596924421335605374686659278612312801604887370376076386444511= 450318895545695570784577285598906650901929444302296033412199632594998376064= 124714220414913923213779444306833277388995703552219430575080927111195417046= 911177019070713847128826447830096432003962403463656558600431115273248877177= 875063381111477888059798858016050213420475851620413016793445517539227019973= 682699447952322388748860981947593432985730684746088183583225184347825110697= 327973294826205227564425769950503423435597165969299975681406974619941538502= 827193742760455245269483134360940023933986344217577102114800134253879530890= 064362520368475535738854741806292542624386473461274620987891355541987873664= 157022522167908591164654787501854546457737341526763516705032705254046172926= 268968997302379261582933264475402063191548343982201230445504659038868786347= 667710658240088825869575188227013335559298579845948690316856611693386990691= 782821847535492639223427223360712994033576990398197160051785889033125034223= 732954451076425681456628201904077784454089380196178912326887148822779198657= 689238010492393879170486604804437202791286852035982584159978541711417080787= 022338893101116171974852272032081114570327098305927880933671644227124990161= 298341841320653588271798586647749346370617067175316167393884414111921877638= 201303618067479025167446526964230732790261566590993315887290551248612349150= 417516918700813876388862131622594037955509016393068514645257179527317715173= 019090736514553638608004576856188118523434383702648256819068546345047653068= 719910165573154521302405552789235554333112380164692074092017083602440917300= 094238211450798274305773890594242881597233221582216100516212402569681571888= 843321851284369613879319709906369098535804168065394213774970627125064665536= 078444150533436796088491087726051879648804306086489894004214709726215682689= 504951069889191755818331155532574370572928592103344141366890552816031266922= 028893616252999452323417869066941579667306347161357254079241809644500681547= 267163742601555111699376923690500014172294337681007418735910341792131377741= 308586228268385825579773985382339854821729670313925456724869607910114957040= 810377671394779834675225181536565444830551924417794139736686594557660483813= 045525089850285373756403594900392226296617656189774567019900237644329891280= 192776067340109751100025818473155267503490628146429306493520953677660612094= 758307190480072039980575323428994009982415676875786338343681850769724258724= 712947129844865182522700509869810541147515988955709784790248266593581532414= 091983670376426534289079098742549505127694160521110700035496658932724007621= 759500091227595477831200325335242614162624218010753586306794482732500765136= 299548052958345872488446969032973871418565484570096440609125401439516349061= 951073344772753817168731533186740449206533184858409824331269879276752302819= 075938894191764603880669059804914705202932220114574769307945938446355744093= 058483466098741029671133305308451601510124097336668044362140994842230895354= 232007936193610666215236351383330719496758577095102466235782700820575938453= 736277546445932135116947993404356975890051717304128693125699951445791328843= 668647245439797933691355015781238038148597339831348341049751957204680813855= 138272253234219030458164179195368888878989362640509486440530112337687890165= 646824152338885218611665567933423652236621168833497594762922586523151554244= 316284075364923316223457798336995440229801638249044555841786652868778333857= 626201712694823945146208412572567947403078655159448178467488335673853886982= 143607843369103504905837049147006413324087204923968347162406372146304110247= 436210704329838033967549296094708909042352807942165389054391217609084676765= 464997803900415653278041220586434133698802658726748950122980183615091029049= 242919298428066745937148593879994539254240070220900694662200741796632687373= 414952817000938093930497338259168439649970963774406833411431113922194082765= 390241161715106142638681072839764035976877223152727829248475639970029777900= 589595383604989099084081251802305001465530685587689066710306032849298712531= 664047230963409638484129598076118133347670029704549206295184751171783054889= 490211218045322681317529569999778899567668829982207035948032411418382057247= 326141072264502161892285323531743728756335449414720326329614400327415751813= 608405440522389476951223717685562226240221655814783640319063683104993438443= 847695342093582440489676230855515734722099028773790309518629302472390856918= 840009781940193713784596688294176313226823907143925396584175086934911386332= 502448539920116580493698106175151294846382915609543814748269873022997601962= 804377576934064368480060369871027634248583037300264157126892396407333810094= 970488786868749240778818119777818968060847669660858189435863648299750130319= 878885182309492320093569553086644726783916663680961005542160003603514646606= 310756647257217877792590840884087816175376150368236330721380807047180835128= 240716072193739218623529235235449408073833764uwb + >> 171; +static_assert (a =3D=3D 10403542085759133691203342137159028259461894955438= 331210801665800234672962180907518788681055608925051917190662144445433835595= 489501570265148539013616306519011285861864113638610998587283343748668959870= 044400340187367869274012726759732348878437230149364081610941398977036594823= 591463255731808309715219781556045092524781748798096243155527048746090614751= 043610821560662864236720952557147844731917800712343725546175449104075627616= 077829385396994452199410766816558008090921987787438967590914249326913953731= 957899714113110918563882837045448642562338486517475793442626878243475178869= 958697311252767202125088496235928130685145568023992654921893286093433280015= 789621699281948053130963767216950901322064090115301029360256916486236324346= 980555378227825665231041206505932451054100655891377307183657244188881780309= 602697733965633806548575793711470844175477213922050584861112947113328821094= 578714380110663964395764964375008963336325761662071121014767368961020824065= 775639039724097407257977371623360602667242992626829630277589757195892131842= 788347638167481783472539736593840645020141666099662762763659119482517961624= 374850646183224354529879255694192077493038699570091875155722960929748259201= 284457182471153956119946261637096783796538046622701136421992223281799392319= 105563566498086105138357131671079600937329401554014025354725298453142629483= 842874038291307431207948198280389112036878226218928165845324560374437065373= 122000792930554833265840423016148390974876479752688661617125284208020330726= 704780298561478529279775092768807953202013307072084373090254748865483609183= 726295735240865516817482898554990450888147008484162850924835809973020042760= 450232447237837196378388135483084055028396408249214425019231777824054821326= 738728924661602608905318664721047678808734917923923121217803736039325080641= 571812479260200189082647677675380297657174607422686495562781202604884582727= 406463545308236800937463493199421020490845203940782000643133713413924683795= 888948837880891750307666957538835987772265423203470320354145742841869795472= 799186154631385288573730129094228733379855432514817031425884584962254283999= 586850250406406681047191820544352342046667950146374296364655891915135310082= 529994904874562441551527081311638121766367661807914647092917287784017613115= 795691373814041086838720316968010349263776702775009771662737124600992709418= 630470128579612748138807983617697487500079502839532266478317788699680283395= 230308668613168191852557234122469290277763000256531531071762280960597416576= 452124575885006363492171314551026369237325119844147154972582617127637240421= 323781252125819313268498872048683068789228870983086306586111793007178693570= 562554975762384431236664489360478109692520183356042112794589756922036102025= 380888246082763911915622037570736969677850621708281909652070776450422110772= 285659921383413532725137107621514770958361581240471968542997294446402584844= 918179956881219978405772785713402046471903103404871352324277109089891640558= 983922159359479964068994923538490500501798825116238188381267330618026093160= 290205596669795981834842352271011063939632623926629960113926326029952143452= 354640614061049438932665467928443113232214498101774523178129020155017228802= 221901469548072234073334681052461327832268955923701109732874360984002493130= 025470753861967432493102395766279717815113135763810886216491770265724160887= 688887515282293447287121039545323777928286876711267049135547760773655845950= 622676327972280622345486253084626121247885891757458308974259466441284967765= 824561478351421051923081842594791616249682768594796413184742007504540382141= 773556098929461233842797978566466734240436032269122908057438314319410489575= 244845739320693764798687398942275314333361838560358278583766983210126081046= 020231469705836544611252075187733112560778125560225565803349953151880800601= 890382648216375737077015744684142132303864494083237680306898134033570758401= 131735819237730280209424231954121970154195575070728876653187928423918894211= 617093567094857926079694003950142962763480728907322409338954277493711834363= 423032309296862081371923061150409402403668284066920335645815769603890931600= 189625120845560771835017710222988445713995722670892970377791415975424998772= 977793133120924108755323766471601770964843725827421304729349535336212587039= 242582503381150992918495310760366078232133800372960134691178665615437284018= 675587037783965019497398984583781291648236566997741116811234934754542646608= 973862932050896956712947890625239848619289180051302224085308716715734850608= 995498117691600907423641124622236235949675965926735290984369155077055324647= 942699875972019355174794849379024365265476001505043957802797349447782453767= 742359446787304217770032967959809288342189111153359045680464231699344620995= 535326063943372491385550455978845273436611631962336651743357242055102619760= 848116407351488643448217122169718350824452317641509534606434395208225350712= 889271762643740106849245478364448395994915755050465135468245061369394410933= 866013068008514339549345174558881983866497072827311379042433413uwb); +static_assert (b =3D=3D 47927963254983398275573821596735710148688490586945= 302151656389894891544659129428967888410488282848368101861900787393734303255= 909595611040969035422441862500296655015996183400474078033076442208281022919= 339382663505873362486125052306726201934754009977462857545931535761634915082= 457969531364063028166780758999692064992454347878021515200637154689307943805= 765515434945644517436059064850821739923175860513488184741071305928775874657= 579331194145636134729035837432777505225398881945576787038414037353432531906= 221463764944822367521370140398750351920450032158498609394040097931192233762= 919615392739593496142319079251492975289355219161278102593077980694080934774= 807348815686269838231658663255453109747406854147841668747295898035046214722= 954204337096637695161230258009467203656917423590804239279208200992286134875= 490081064276216238601176771626719652470715951261404740555830904552686923119= 865477301873427026359632829140952933264973522266815070542033531976946547220= 197973086938491321120720753739960137399906970065546372022920105333218600697= 858250092770971284041999765371634305856374505354948168051485795619245710565= 177475544471205491166573508574008824290197617246557203404659741951935583377= 220245975415117684554899445620844502922298410099631370945492174513316818179= 053941295889751044787346934407150836832047822816077953368388724034918957631= 287532906408983549478253389828549312675591697063148899645182358568234280904= 393370464356625596517001437115695750865735696271243546529127281196748236370= 851643906557876213318702947945779409043920207097980173253604088090541910037= 502992188977212850308451093143517148397901877959716663055881990934822377000= 137739027330737305203072941381961798582398137407044371548508882948736515168= 678665314156055539763283978378697347560390812910312112592558243537758659944= 336321765948248602151244471507899974214561619241705438327522143175018570171= 179348707944798029574180941726592337226502723788420039623849392735910288582= 594856812800635227346505171247207005920245031905445152238832105970200308151= 371801900107107616143235847115536995978281165233083750307528808742605565540= 002941143874829336203146501750257713925224473144855518861387693696103669523= 617994232375111611201101459297439748647388267459200813013679266349328732383= 431914791502242752803351817813918019855167200467126443959596212095412230012= 937785180621368904740496659226139300584975540396940968189138713630212621475= 457757421407899273838583419421850094135489271442461781867612967840281259964= 938951919393938448193171251996576357123654457926939171468811259400443993779= 102766652727502895609600502472189226835366234904950156893142674698374992326= 628993607966485208811438064202797698153274845831487974169502396605979807274= 335098034836109236427828852711258048141786054778320994100643663029556902570= 837898367870844766792830052796171750493189799905267492521148625102911003353= 413851945670464764491436591194854953791559798723403394543172251931597408230= 783241193488626433308391622670766594854714782494114377403163099298640358928= 143049334330420757343195444050636710200574691425877526862566305694461542707= 733031232666443103430989472012268269487427473562080231601131548241018299190= 616533588303175681201813391409086131938902379083952833720360688912943648792= 014016737028487092443886087383029664801442484437819591293255142678077981975= 752535336855805082530356241998952865342550778119356839913188367344788882869= 555211229365407308833977580823432443662765954396216494645039675972304007590= 676650615202226481515809367464962286957243012116484337925382676418395332482= 943675100503507815220367552316843116120946303449177210299631555487831100050= 075236979610968511974561546844657652354600832503906077552097096336790921653= 334305722166205970710071599011452051510942858155477347155178222397083241240= 607349989679794924719726305591105357558068555200222677799099434663185151779= 136463033055175444365657794849872636280668141970553674032426859753989628280= 355279972608055457330269595842841726967166030617385338134381402404827936273= 803947019883936570628616414755586493336436328787509713812842557390990443318= 379509867020380053354885621917457990109708412341140216044839027465621606220= 773380452267811600783048591111833813729141550004024463664622846527554661318= 545121547721492409389740865925389787233163029436137942926808211251948997928= 382653291328290814782484778151796477938082491839492432242010471783901296042= 252376674439710606346399821841652194708961984612546483314531228197199405727= 591759159127914527483728327356941190487588359081892701108376611136862387628= 866146969785698402392454111735458471072816206092874754444972907108640607282= 082670735270509846957021243000503176987077098449014754492254187858251649602= 605563421853473982976704443111427277286348462896880059204798597700568726057= 437433260876574696564797640594970930403341444263058148836225175692288351728= 756577265334618966609417525651898087863205788909104258464451037447721910608= 0358138511257658994752983022904583136418485544787844335722425uwb); +static_assert (c =3D=3D 87791074236971898375693906050841211797859249085219= 857442103255912236679245196526258183737200195092459037070061326325721733862= 550642013557351987594406882625147809841117910427395663017848973163739949221= 920509632722884340603422885119715696976800265237608112255164300526997540446= 828188926798191319956002162809660627367323847324113616574443996958838650961= 034287596228138677355472599785293194368898640136872193905676042833180111007= 999534515209684412648660318139544886280584751143487292754141431589178747095= 995562471836958538385523210889734458760880425568104799106614493746619996750= 828111038144533532941948866129614927372632772715518890386107307604784595692= 561493219983504140230663638149893111097283117129890229962472801825879214491= 853539228859378776045004007387742400087099452897916050111777396577201816014= 535122598820045644624158286527149042897272352105372777213898166876433661452= 000011777121121975156955788874837929887554354013884561458544888805370883603= 979946432160148284956624602056864485481132298410979556139584409013754162565= 328645118522986963276115172332413247990709194912864261597887926317238337174= 515380434373640171852377431824028356700876831256026403188874515966503235287= 201281881985472704629716121576034879585267050059555804094416707718493880164= 380358501945858703270134092362367309142177220256553194722311416667902879556= 857136362746535655774542758385903508061686391652646764704409303516129925189= 046646477158058659410384237683768466978175431224095175917172922387459403459= 005304585514685192457678645317421021786288543765245133679832091869745757657= 072739737753868400812388038803350957408363865272082673118089735224503911890= 557398289369373596931672405246606249458569070420412573471920869840096409845= 093226225038902560463247683416326435464557790353760020616911131212342731649= 379841717742423277699156887425640494541631583181218185827647752680912924708= 890884455751080226880692716971982831514696454008705070066637993306617027027= 474432542204783110564072207496481031234354733815835208730552187341151209786= 784404558964588524975699899667232359656087068265936071288476301376185091512= 558347426364387962855698738699677293418712135210300114273729873885726742284= 413334588575122260492832433475214578049120087810369667863747603253414920332= 978483681609032604700190675353306116459095608887974519070883897641904030079= 983051686730294469340122451388381805960985594425706961500112962181441863870= 246158853022907449053406669059217439700137798133324937711920480432972814232= 484890568414170138076703081910957324642214513769972707454684597021527968182= 227457305657212026631030431211601014598336832495586844591088625369619943085= 350399708145578212681703887459419803788389699105928956705542918117397687718= 299410438578196037512469579622360911547558939620383631206904838624230010389= 486206816112538671492964636904178280343035479227922490985224047514289607138= 750504639061341508460897057144703039182990126916002853558594129248477604970= 769784327224466025218250890974545423433548473473960450795877572106353569992= 687064654257888333111905176230618606752300109941271964590303221667515716566= 423216907874719066094734960347896437104781622556640929912514467878876353518= 529338268207197817337545781610734013626681098191139242522911257413952714743= 423055745369749182739385135974189637873089945934341918906877303024959106860= 723388364131591622810722635427582576995880898386774693974678993480652935817= 510358443898483871618474351603272760666036831317032464104091228327933767515= 126887451955640216460692459923633964681005135362116514506105233152116971257= 746388453132439730835364176920759624869188446674321443530197229596536386329= 482940499842668618701512553150233467246714304992579939580490880661608705450= 252765979751548555376202656903540410287427427550743965976319653203807825009= 445684240534200383575249171250992413349900321895264658381929721109708613800= 609868020819480443455264148571585699390058952366723063443482128058512699207= 110438913068758730163306016739732493270725035718735183667505750700910512885= 907647886301909667768540315789393826907090226674217344428417846808264941466= 205898628296127042795216377404216941950514000952780847169746246152083925855= 732001826641570668138493460583217631565239656984659013960251521596421935629= 007438127158858110572125790178604885399603344067027526885952173602194709687= 380097740679150371570274922091088013377075625712668977239114012033743084907= 932262009743533568353117563848956929098027209489681315046048554669619873147= 018464603421352019143561525916848109246883509291401201876930893242559246345= 785764270044263392994938334345029515939025514510022928396350009042532500218= 846254176287564398629643255627207095287849648686873308478944769995773265823= 323502131488612054136523374993834165315457072729079947556383396302215767079= 549642362109626938046397147546686798411349283930812842091580982026837446505= 139189201683305984323623897774718706310394884087693548630019675317294156866= 31571754649uwb); +#endif =09Jakub