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: 85067 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3119696vqo; Tue, 18 Apr 2023 13:52:01 -0700 (PDT) X-Google-Smtp-Source: AKy350YwhLWgn45LzK5imstHUh/DObWTlKWJN5/ofyMl5t2mQtmRppZAl0hAHdfW1/v5D0HH/KA2 X-Received: by 2002:aa7:ce10:0:b0:4af:6c5e:225c with SMTP id d16-20020aa7ce10000000b004af6c5e225cmr2961312edv.33.1681851120945; Tue, 18 Apr 2023 13:52:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681851120; cv=none; d=google.com; s=arc-20160816; b=I9SfGLimtcgRk+FGiA00O+L4VbE/k9wPgJUR0Olu0sI+dxGHYhZ+Nha76mBb+mEjG4 6V/mxTUdEwYNm4In9HyvgtE0/u63yhpkPm+s5oz5ZbyZ/Ho4YzsDWxG4s/XmxJuvq4Sy 7yFtN9QOZJJMNFhjzS6ka3WAFyW8DJ6Ykgp+J6bXEEsgSG314KpmrBX2r0BuPruhDm0Q DHhzoKvW12u5qlqofddYcDIxQ+LiRw+Leh6PwNmpoQ31K5GUrMPd/X4CKB1rPoNaotIq iAjY26KhFg20x8CYB68poDETGa8upRg/cbHSIDUpdot2/K9zl2T9Fz3ei9pOK90LmEJo z4yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=mcERfxR9Ho8Jvg/3GdjoZOpXRbRKM6/KEW8w43klyR8=; b=OkWm7hAkjRh4igLwob9/y6VylUox/ZHy/dj3w4nhoMO3MJP2XJENtKQb5MdnkNRfTb RSQkcF8S+w41fHUvIfKBU6jiI3dXwS44QHpmWPHabpJup45tnQN/SttsNqgKHF2yMORq kGBhWpFfOqivU6tVr3+o6yAJx9YEpF1xHZldhDUp+DwHV2KHeyNxePbmqRoXUymQKiEy 8qIgknxBwdbZV8absbKd/XgfQzkkYAvtky8mwpu//IphbC/fvYzArY7+a6sJDhOo3J3b 6/EO8vxmzQ8f+OJv1cIFzaDfpiD3Mmbvk6maCJN6hzPAT5IKXlSVZ35FJE+HuYkg7O56 4W+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=LM6ctbgA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fb10-20020a1709073a0a00b0094f79f74ecfsi5067891ejc.1012.2023.04.18.13.52.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 13:52:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=LM6ctbgA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 582CD385696D for ; Tue, 18 Apr 2023 20:48:42 +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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763539056121207802?= X-GMAIL-MSGID: =?utf-8?q?1763548721138343338?= 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