From patchwork Thu Jan 25 14:57:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 192124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp40298dyb; Thu, 25 Jan 2024 07:10:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFHE2VmYvYAGAOSCvkxT6vojAIzlmKGQuqBShq7wqQBNALWaKnOoOs4HoV3FrAAV0Rb/3m X-Received: by 2002:a17:907:b01f:b0:a23:36f7:4918 with SMTP id fu31-20020a170907b01f00b00a2336f74918mr796867ejc.72.1706195433719; Thu, 25 Jan 2024 07:10:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706195433; cv=pass; d=google.com; s=arc-20160816; b=l4t41alolGt5oRzTg9ImviisBgtjBvET2kqVixP1cdm6+pF7babHDrJXgfPdN3r9o8 i0ITrfPVqINuSZIRF2Srq24JVUTq7lV7j+d/A0gLWowJ1ycU276GZGvqyckXU9edBUZh 38l4xOMN34EnLDofvHD7epd8DwcFqJHLjrfvgDoXgdm5uTPCGRkXPACkYujl4XKV7PJZ X/i3dKo6PoUjFDa7Fl2k6g/iz0FOUERDXEcqaFS1G5HfucEEotoi8qgE0oAlNtGPEwXq gMmzteXfw2SYnmurXH3esocVyTI0bUHBJDn+dT5eFCs46qxStim9bPETcbPe6TmFf+7U YSeg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=EO+l7ZFLJQqSA7Ulg59d6kw71xgezrnH2EaPLE90p3c=; fh=+p6A4q0z6aoZsBvdCbtzzLH5AwY313zmODNLLoBWAdA=; b=gnBdcvFCtJA1lv9OWWhoM+mqWvnbcM1shKU4wojdEJgZeZE710yj4OnlDPuwBJWmCn c6F+cRWGryif4liveieeGmQ2QmDm6Q2r9znF8SYunx8Efv5eY+3TbnyUdxmHqgXf+8p3 F2+celGmop+TQ5E3OaplNX9CauiSjTUnxVPdfotl6AyH3fUSu7xw90VcDXRWsngnisCx kGMiP7BS/HWbqK19Ci3dhpIMGhZhkcDy2oS24qf1zVZ9I9XkvrxbnJxP3tgOPAioaTYv 94/GoBY09o7QxS7lj48aM9CWSFwq0E+i4VCwUDN8C55IfRC1hbjC7zg8N9YX9uZXtOv0 cBDQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uI9AdYXo; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-38797-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38797-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u9-20020a17090657c900b00a3185d3926asi540310ejr.202.2024.01.25.07.10.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 07:10:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38797-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uI9AdYXo; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-38797-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38797-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 55F401F232CC for ; Thu, 25 Jan 2024 15:10:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9FC0D73178; Thu, 25 Jan 2024 15:10:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uI9AdYXo" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08A776E2D1 for ; Thu, 25 Jan 2024 15:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706195398; cv=none; b=Z/apkBS/yVLj8X/3HIb9mLq4/UttUPoBOS/SKTDu0j7ivE7mF5ZD1kuSghm3UdjOizAqahW/mXSg1hSpM3ROOvjSiyKiXwskQzV2YjJxbrxrU6/OZdD6t016oJxvDBy0KjeGZJubO8BeWWBcmrAOADbI/Po6UwpnrM00PBHJ9lY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706195398; c=relaxed/simple; bh=jGTeEqT3oFqBR8XDClyO1GAGfuARRlp1VqsQY6R1rZE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Mi4/shoWrHerSAXu2VL2ykYhhI+601YyeymaNFFJl+C+aVo0xxPDjeJUnzBPO71w+zRZjWpZ4wKftsmp1jWAt31Sx3dV5vfnYC8sn7vZwd/9qitVW5g+1GGqhaVW0e3DeNGKZYEG9bW75a8gGSj+xFA6D/nwp5Km/aa0Rug5a5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uI9AdYXo; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D064AC433F1; Thu, 25 Jan 2024 15:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706195397; bh=jGTeEqT3oFqBR8XDClyO1GAGfuARRlp1VqsQY6R1rZE=; h=From:To:Cc:Subject:Date:From; b=uI9AdYXoCYAn5DBxuyyvDJKzDd81svW6+pDf8TyqdpmXSirs3iM9UeAu1/KDakzpV IsqSQZZyeebMygPcY5g00qnnK1S0gz/6X6kmK1YWDzmCMrCqpY7j22STrwxn7SsMpi QDEINiE6NdWlX0MeVJS4Yd3YR19GMSiS4ny5m9hMlWkUnaUAFIpg+3HTCgksRBRK8F Bhj9/CB/yxx+Rie9jLZn0MhbBGmsz1F/GRzXkvTd+X4K+jvpQGDQbzl6vDgahv6Dhs TpmiRDUvSyW/6S9BJ8kHywTlbsnN/ws880XQbUxLr8V8e5f2QVuFvCvDfuRSFVT8bg cEhhhy2eSrB3A== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Samuel Holland , Alexandre Ghiti Subject: [PATCH v3] riscv: select ARCH_HAS_FAST_MULTIPLIER Date: Thu, 25 Jan 2024 22:57:03 +0800 Message-ID: <20240125145703.913-1-jszhang@kernel.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789075583212631282 X-GMAIL-MSGID: 1789075583212631282 Currently, riscv linux requires at least IMA, so all platforms have a multiplier. And I assume the 'mul' efficiency is comparable or better than a sequence of five or so register-dependent arithmetic instructions. Select ARCH_HAS_FAST_MULTIPLIER to get slightly nicer codegen. Refer to commit f9b4192923fa ("[PATCH] bitops: hweight() speedup") for more details. In a simple benchmark test calling hweight64() in a loop, it got: about 14% performance improvement on JH7110, tested on Milkv Mars. about 23% performance improvement on TH1520 and SG2042, tested on Sipeed LPI4A and SG2042 platform. a slight performance drop on CV1800B, tested on milkv duo. Among all riscv platforms in my hands, this is the only one which sees a slight performance drop. It means the 'mul' isn't quick enough. However, the situation exists on x86 too, for example, P4 doesn't have fast integer multiplies as said in the above commit, x86 also selects ARCH_HAS_FAST_MULTIPLIER. So let's select ARCH_HAS_FAST_MULTIPLIER which can benefit almost riscv platforms. Samuel also provided some performance numbers: On Unmatched: 20% speedup for __sw_hweight32 and 30% speedup for __sw_hweight64. On D1: 8% speedup for __sw_hweight32 and 8% slowdown for __sw_hweight64. Signed-off-by: Jisheng Zhang Reviewed-by: Samuel Holland Tested-by: Samuel Holland Reviewed-by: Alexandre Ghiti --- since v2: - rebase on v6.8-rc1 - collect Reviewed-by and Tested-by tag since v1: - fix typo in commit msg - add some performance numbers provided by Samuel - collect Reviewed-by and Tested-by tag arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index bffbd869a068..fdd1a595ebd8 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -23,6 +23,7 @@ config RISCV select ARCH_HAS_DEBUG_VIRTUAL if MMU select ARCH_HAS_DEBUG_VM_PGTABLE select ARCH_HAS_DEBUG_WX + select ARCH_HAS_FAST_MULTIPLIER select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE