From patchwork Mon Apr 17 18:39:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1769790 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=hCNlnRhc; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q0bWk2tkxz1yZk for ; Tue, 18 Apr 2023 04:42:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 11FC3385381D for ; Mon, 17 Apr 2023 18:42:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11FC3385381D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681756942; bh=51wiuarf8bnj1Dtj+q+T970dYiRDT4o9G6wQzg6a0bk=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=hCNlnRhcwrglCuGTuwPvGKfTFHKCllHUAKe5OABGn7mg23QAsxk0i45LG42Tuh8gL UL0HUZWeMS89aW4EUMcEhUC9Soce1igcz+cntV40QN0+Glcgo7/WS6vZ8Bc23wUZl4 wJD+xBj/4IchCdOkXNTwB6uSV7G45GSlL8tkM114= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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); }