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 46E663857703 for ; Mon, 17 Apr 2023 18:42:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 46E663857703 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=1681756920; h=from:from: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; bh=51wiuarf8bnj1Dtj+q+T970dYiRDT4o9G6wQzg6a0bk=; b=Py8X16f3KuSlQsoKYZ0fXqhvDFA4kj5wQ/WJtV1kBKiV+CevBvFVoIHvwEItdpChTFnREY zlz3M7K1p+j4PMcpqMCgb93BJP8KK7YHqV6H6ykIsUWIqLmG2iQJZ6axV1K2yVZC7utPOW YKJbmfjv9QOqt1kWkO7zvSoK5MAx/1o= 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-240-v7BxYDYUP3CH2KhZmU20Yg-1; Mon, 17 Apr 2023 14:41:58 -0400 X-MC-Unique: v7BxYDYUP3CH2KhZmU20Yg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2D915811E7C for ; Mon, 17 Apr 2023 18:41:58 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BA38E40C6E6E; Mon, 17 Apr 2023 18:41:57 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 33HIftXH216285 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 17 Apr 2023 20:41:55 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 33HIftdW216284; Mon, 17 Apr 2023 20:41:55 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [PATCH] Abstract out calculation of max HWIs per wide int. Date: Mon, 17 Apr 2023 20:39:18 +0200 Message-Id: <20230417183917.216257-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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: I'm about to add one more use of the same snippet of code, for a total of 4 identical calculations in the code base. This seems safe enough even before the release, since this file hardly changes and I'm pretty much the only one who's touched it this year. OK for trunk? gcc/ChangeLog: * wide-int.h (WIDE_INT_MAX_HWIS): New. (class fixed_wide_int_storage): Use it. (trailing_wide_ints ::set_precision): Use it. (trailing_wide_ints ::extra_size): Use it. --- gcc/wide-int.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gcc/wide-int.h b/gcc/wide-int.h index a450a744c9f..6be343c0eb5 100644 --- a/gcc/wide-int.h +++ b/gcc/wide-int.h @@ -264,6 +264,10 @@ along with GCC; see the file COPYING3. If not see /* The number of HWIs needed to store an offset_int. */ #define OFFSET_INT_ELTS (ADDR_MAX_PRECISION / HOST_BITS_PER_WIDE_INT) +/* The max number of HWIs needed to store a wide_int of PRECISION. */ +#define WIDE_INT_MAX_HWIS(PRECISION) \ + ((PRECISION + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT) + /* The type of result produced by a binary operation on types T1 and T2. Defined purely for brevity. */ #define WI_BINARY_RESULT(T1, T2) \ @@ -1214,7 +1218,7 @@ template class GTY(()) fixed_wide_int_storage { private: - HOST_WIDE_INT val[(N + HOST_BITS_PER_WIDE_INT + 1) / HOST_BITS_PER_WIDE_INT]; + HOST_WIDE_INT val[WIDE_INT_MAX_HWIS (N)]; unsigned int len; public: @@ -1475,8 +1479,7 @@ trailing_wide_ints ::set_precision (unsigned int precision, gcc_checking_assert (num_elements <= N); m_num_elements = num_elements; m_precision = precision; - m_max_len = ((precision + HOST_BITS_PER_WIDE_INT - 1) - / HOST_BITS_PER_WIDE_INT); + m_max_len = WIDE_INT_MAX_HWIS (precision); } /* Return a reference to element INDEX. */ @@ -1505,8 +1508,7 @@ inline size_t trailing_wide_ints ::extra_size (unsigned int precision, unsigned int num_elements) { - unsigned int max_len = ((precision + HOST_BITS_PER_WIDE_INT - 1) - / HOST_BITS_PER_WIDE_INT); + unsigned int max_len = WIDE_INT_MAX_HWIS (precision); gcc_checking_assert (num_elements <= N); return (num_elements * max_len - 1) * sizeof (HOST_WIDE_INT); } -- 2.39.2