From patchwork Tue Apr 18 20:48:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 1770426 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 (2048-bit key; unprotected) header.d=rivosinc-com.20221208.gappssmtp.com header.i=@rivosinc-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=LM6ctbgA; 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 4Q1GGm3JJwz1ybF for ; Wed, 19 Apr 2023 06:48:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DB5C438768A2 for ; Tue, 18 Apr 2023 20:48:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 0B90B38768A0 for ; Tue, 18 Apr 2023 20:48:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B90B38768A0 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-63b5465fc13so1949600b3a.3 for ; Tue, 18 Apr 2023 13:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681850894; x=1684442894; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mcERfxR9Ho8Jvg/3GdjoZOpXRbRKM6/KEW8w43klyR8=; b=LM6ctbgA4kmMxewGBYwPPsHbj3MX1v9n77CytQ9CgCEP33e1tNktymyAJ+4YPab22l ts5AyjvPMRnXBvn9odRP2msvalKN1ypKOzA2zNqd1+W+psLY6f0SRKcDtfk7FTnKZdF/ 2xjgGXQLrvyCJoB/8AdG58QW/cGqIX5CCa9YcTWz6asPvHNNJTrMMW091/jwGNS1mpEw b8I1rElkvD9EpRA8PlWC7ncta4bUsIWXqxeJrrrt9yCWyfaT6fC1XeyWAclN7dEh4byt s1l3xmY/mOBiOnRWOhZzHItrsRZ3AuRdoKNnBYwWEYfp40gkPgrupAC8RWz/6ihuDmDo Worg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681850894; x=1684442894; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mcERfxR9Ho8Jvg/3GdjoZOpXRbRKM6/KEW8w43klyR8=; b=gqnWft8JLMg4RtmxD7rv42sDFbSu7Ah2y1y/Q+tqz1kQ396UnBuyYnCzpX+u6cZ7wz IXLydf496xrW2WI8MzeZugHLjudK1kECB8zvEPl6LPDTpgmj2H4uzH3YsTKT5LtGN1M+ sF08dygVdixsTdRa1vcjFWOtMv3TnWS0eo1VrI0zjE35p4eWtNt6eC4MQ+F/IpUeua9V 0smDiizIcaXnyDVUXfA8idekACfxU3qfmX/b29v2Q039YjIOaBgvxtNw1ZJlQJLyolEC bFxBmkkfecmhxtO+vHFrkOICGh0umwiQdTbO2uD6v2hHT95lwo5gBX+YWp/6wuzNIxb5 jSBQ== X-Gm-Message-State: AAQBX9dncp/cDDi3Enx2JLbbzG1/Ad19/tigOngzhNtxpUS85rtlcJH2 FfmO/ZJO+xahFN0m5tSlr8xoMSMswnkQMZIlKdK7Zw== X-Google-Smtp-Source: AKy350YIPmE8BnkVBaOagIYAxVQZhxHEfbk6vu9JsXeQ7FYLIc6jD3qntImIS2bQohAEp7rBW8IE+A== X-Received: by 2002:a05:6a00:2392:b0:623:5880:98cd with SMTP id f18-20020a056a00239200b00623588098cdmr1177164pfc.5.1681850893563; Tue, 18 Apr 2023 13:48:13 -0700 (PDT) Received: from vineet-framework.ba.rivosinc.com ([71.202.114.183]) by smtp.gmail.com with ESMTPSA id f14-20020aa78b0e000000b0063b6bd2216dsm7756352pfd.187.2023.04.18.13.48.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 13:48:13 -0700 (PDT) From: Vineet Gupta To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, Jeff Law , Palmer Dabbelt , Philipp Tomsich , Christoph Mullner , gnu-toolchain@rivosinc.com, Vineet Gupta Subject: [PATCH v2] expansion: make layout of x_shift*cost[][][] more efficient Date: Tue, 18 Apr 2023 13:48:09 -0700 Message-Id: <20230418204809.993242-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230418181745.987867-1-vineetg@rivosinc.com> References: <20230418181745.987867-1-vineetg@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" when debugging expmed.[ch] for PR/108987 saw that some of the cost arrays have less than ideal layout as follows: x_shift*cost[0..63][speed][modes] We would want speed to be first index since a typical compile will have that fixed, followed by mode and then the shift values. It should be non-functional from compiler semantics pov, except executing slightly faster due to better locality of shift values for given speed and mode. And also a bit more intutive when debugging. gcc/Changelog: * expmed.h (x_shift*_cost): convert to int [speed][mode][shift]. (shift*_cost_ptr ()): Access x_shift*_cost array directly. Signed-off-by: Vineet Gupta --- Changes since v1: - Post a non stale version of patch --- gcc/expmed.h | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/gcc/expmed.h b/gcc/expmed.h index c747a0da1637..22ae1d2d0743 100644 --- a/gcc/expmed.h +++ b/gcc/expmed.h @@ -161,15 +161,14 @@ struct target_expmed { struct expmed_op_cheap x_sdiv_pow2_cheap; struct expmed_op_cheap x_smod_pow2_cheap; - /* Cost of various pieces of RTL. Note that some of these are indexed by - shift count and some by mode. */ + /* Cost of various pieces of RTL. */ int x_zero_cost[2]; struct expmed_op_costs x_add_cost; struct expmed_op_costs x_neg_cost; - struct expmed_op_costs x_shift_cost[MAX_BITS_PER_WORD]; - struct expmed_op_costs x_shiftadd_cost[MAX_BITS_PER_WORD]; - struct expmed_op_costs x_shiftsub0_cost[MAX_BITS_PER_WORD]; - struct expmed_op_costs x_shiftsub1_cost[MAX_BITS_PER_WORD]; + int x_shift_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD]; + int x_shiftadd_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD]; + int x_shiftsub0_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD]; + int x_shiftsub1_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD]; struct expmed_op_costs x_mul_cost; struct expmed_op_costs x_sdiv_cost; struct expmed_op_costs x_udiv_cost; @@ -395,8 +394,8 @@ neg_cost (bool speed, machine_mode mode) inline int * shift_cost_ptr (bool speed, machine_mode mode, int bits) { - return expmed_op_cost_ptr (&this_target_expmed->x_shift_cost[bits], - speed, mode); + int midx = expmed_mode_index (mode); + return &this_target_expmed->x_shift_cost[speed][midx][bits]; } /* Set the COST of doing a shift in MODE by BITS when optimizing for SPEED. */ @@ -421,8 +420,8 @@ shift_cost (bool speed, machine_mode mode, int bits) inline int * shiftadd_cost_ptr (bool speed, machine_mode mode, int bits) { - return expmed_op_cost_ptr (&this_target_expmed->x_shiftadd_cost[bits], - speed, mode); + int midx = expmed_mode_index (mode); + return &this_target_expmed->x_shiftadd_cost[speed][midx][bits]; } /* Set the COST of doing a shift in MODE by BITS followed by an add when @@ -448,8 +447,8 @@ shiftadd_cost (bool speed, machine_mode mode, int bits) inline int * shiftsub0_cost_ptr (bool speed, machine_mode mode, int bits) { - return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub0_cost[bits], - speed, mode); + int midx = expmed_mode_index (mode); + return &this_target_expmed->x_shiftsub0_cost[speed][midx][bits]; } /* Set the COST of doing a shift in MODE by BITS and then subtracting a @@ -475,8 +474,8 @@ shiftsub0_cost (bool speed, machine_mode mode, int bits) inline int * shiftsub1_cost_ptr (bool speed, machine_mode mode, int bits) { - return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub1_cost[bits], - speed, mode); + int midx = expmed_mode_index (mode); + return &this_target_expmed->x_shiftsub1_cost[speed][midx][bits]; } /* Set the COST of subtracting a shift in MODE by BITS from a value when