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.133.124]) by sourceware.org (Postfix) with ESMTPS id B1F3F3857706 for ; Thu, 12 Oct 2023 11:10:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B1F3F3857706 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=1697109018; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=O1blKNFOlHiPtEtfgLvMKy3kum39j5BA2HbWhFZfbIc=; b=V45k+BN6VF6gW0sR2h5b2zh4fibEd/FBki9B5PKNItypS8xKXJ7eauWaPeZGQHyvt5b3zY WBlmqwioDchkVlZID97AuK+86qhARN3nWsXTV0Es8Do4QJIc55NX59BN3e7R7Z8zNeanx2 bKQzEhzuLIfmEC8s2/b/WoTgGFejBss= 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-274-ZgPHG9PvMmmOKWOkeaCP3Q-1; Thu, 12 Oct 2023 07:10:16 -0400 X-MC-Unique: ZgPHG9PvMmmOKWOkeaCP3Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 8AE2E862F1C; Thu, 12 Oct 2023 11:10:16 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.202]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 451E225C0; Thu, 12 Oct 2023 11:10:16 +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 39CBADws226576 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 13:10:13 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 39CBACkT226575; Thu, 12 Oct 2023 13:10:12 +0200 Date: Thu, 12 Oct 2023 13:10:11 +0200 From: Jakub Jelinek To: Richard Biener , gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Re: [PATCH] wide-int: Allow up to 16320 bits wide_int and change widest_int precision to 32640 bits [PR102989] Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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_H3,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: On Thu, Oct 12, 2023 at 11:54:14AM +0100, Richard Sandiford wrote: > Jakub Jelinek writes: > > @@ -2036,11 +2075,20 @@ wi::lrshift_large (HOST_WIDE_INT *val, c > > unsigned int xlen, unsigned int xprecision, > > unsigned int precision, unsigned int shift) > > { > > - unsigned int len = rshift_large_common (val, xval, xlen, xprecision, shift); > > + /* Work out how many blocks are needed to store the significant bits > > + (excluding the upper zeros or signs). */ > > + unsigned int blocks_needed = BLOCKS_NEEDED (xprecision - shift); > > + unsigned int len = blocks_needed; > > + if (UNLIKELY (len > WIDE_INT_MAX_INL_ELTS) > > + && len > xlen > > + && xval[xlen - 1] >= 0) > > + len = xlen; > > I think here too it would be worth dropping the: > > UNLIKELY (len > WIDE_INT_MAX_INL_ELTS) > > part of the condition, since presumably the change should be safe > regardless of that. If so, there is also one spot in lshift_large as well. So incrementally: --- gcc/wide-int.cc 2023-10-11 14:41:23.719132402 +0200 +++ gcc/wide-int.cc 2023-10-11 14:41:23.719132402 +0200 @@ -2013,8 +2013,7 @@ /* The whole-block shift fills with zeros. */ unsigned int len = BLOCKS_NEEDED (precision); - if (UNLIKELY (len > WIDE_INT_MAX_INL_ELTS)) - len = xlen + skip + 1; + len = MIN (xlen + skip + 1, len); for (unsigned int i = 0; i < skip; ++i) val[i] = 0; @@ -2079,9 +2078,7 @@ (excluding the upper zeros or signs). */ unsigned int blocks_needed = BLOCKS_NEEDED (xprecision - shift); unsigned int len = blocks_needed; - if (UNLIKELY (len > WIDE_INT_MAX_INL_ELTS) - && len > xlen - && xval[xlen - 1] >= 0) + if (len > xlen && xval[xlen - 1] >= 0) len = xlen; rshift_large_common (val, xval, xlen, shift, len); @@ -2114,9 +2111,7 @@ /* Work out how many blocks are needed to store the significant bits (excluding the upper zeros or signs). */ unsigned int blocks_needed = BLOCKS_NEEDED (xprecision - shift); - unsigned int len = blocks_needed; - if (UNLIKELY (len > WIDE_INT_MAX_INL_ELTS) && len > xlen) - len = xlen; + unsigned int len = MIN (xlen, blocks_needed); rshift_large_common (val, xval, xlen, shift, len); which I'll test soon. > OK for thw wide-int parts with those changes. Thanks. What do you think about that --- gcc/wide-int.h.jj 2023-10-11 12:05:47.718059477 +0200 +++ gcc/wide-int.h 2023-10-11 13:51:56.081552500 +0200 @@ -1635,6 +1635,8 @@ widest_int_storage ::write_val (unsig u.valp = XNEWVEC (HOST_WIDE_INT, l); return u.valp; } + else if (CHECKING_P && l < WIDE_INT_MAX_INL_ELTS) + u.val[l] = HOST_WIDE_INT_UC (0xbaaaaaaddeadbeef); return u.val; } @@ -1650,6 +1652,9 @@ widest_int_storage ::set_len (unsigne memcpy (u.val, valp, l * sizeof (u.val[0])); XDELETEVEC (valp); } + else if (len && len < WIDE_INT_MAX_INL_ELTS) + gcc_checking_assert ((unsigned HOST_WIDE_INT) u.val[len] + == HOST_WIDE_INT_UC (0xbaaaaaaddeadbeef)); len = l; /* There are no excess bits in val[len - 1]. */ STATIC_ASSERT (N % HOST_BITS_PER_WIDE_INT == 0); part, shall that go into trunk as well or is that too much slowdown for checking builds? Jakub