Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1694250rdb; Sat, 2 Dec 2023 06:04:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGbMQs+/fB4Bb75Iiqh0pevZ4DDmPTjrWTdVirY1JJzB75L7Ff8Z72F/Cz2/o99jkprF5zu X-Received: by 2002:a05:6e02:968:b0:35d:59a2:a33f with SMTP id q8-20020a056e02096800b0035d59a2a33fmr634355ilt.65.1701525892464; Sat, 02 Dec 2023 06:04:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701525892; cv=none; d=google.com; s=arc-20160816; b=vzj06b3MwM4dxhq3X9TJxQm7aavT2cyE6VR9JfChTxJcIr6wIxDBssCE4djtyQdMuE PENN0j+DQ8XSXwpJ+hOKvnjUIeqjAYZcLB2iQZ8/xEH1oqjHuTiXMcsauiVLGk8nm2ew BqbkIMwh9NLhHtetPvZtfTtSffFUiHsNyAMxYB2FMzE6byc5306ZdhzUTk11oWFcjz6E Eq6dazsM0n6PuUmTfPZOEBDW+FOWsrdz+BuCisZGmSlMAAOpHTsngDZoDfOeEpshWZLt 7SVfMwhlGSlQHmHq/dA7grQM8U2q2QJs2NkPXJ3rvRbLe01JMXYNsaUtkaeDdA90AgoJ Hn+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=csGJEunuBR3yoi+1/MfrfmKcCnH12dlvCn3r096CDf0=; fh=DlmJuR6wwQKMZDEHlp504aEHD07s8CYIONf2sauIDG0=; b=L4H8krIeZ9C/HlX/pCV6PoXXDeKM81Bhr9c01AO8F/HrY3jaLSNS0AErFoSewBD2bM 0edw7WXQR8u+w3O0PYev8gHXghUsLbRFMus9W2Kmfh/EVE7D8WM0jj0MyIrpBQnTYaiD aQnLuy2W6CzQV7gCNqIg93pfEB6sb+W8dGhmz2ztxLjBWzQAqVUiP3aedHaNwWVQL357 hgVH/r+xduiAzbR9jP7kG7lHsTuxbSxWymJ6TBZeUy8TLwsapHd0GzIx16aIC0QI29V4 ZngVz6ugwo6xoCR2QqRupcYMILwjRF8sZ9zsQ2fQsd+nqJ0c3VKnT0eE1pTTEVW+JMM1 VN1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PJyPXWna; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id y185-20020a6364c2000000b005c660acad7asi914396pgb.4.2023.12.02.06.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 06:04:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PJyPXWna; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id DB562808D299; Sat, 2 Dec 2023 06:04:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229852AbjLBOEY (ORCPT + 99 others); Sat, 2 Dec 2023 09:04:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjLBOEX (ORCPT ); Sat, 2 Dec 2023 09:04:23 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 804C311C for ; Sat, 2 Dec 2023 06:04:29 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA462C433C9; Sat, 2 Dec 2023 14:04:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701525869; bh=AV5SjHrRFe5hjdLFAKlI3xJUbybDuDNPP1TvLDaRINs=; h=From:To:Cc:Subject:Date:From; b=PJyPXWnas2YQ4+MeVwOs6h99j9+jSJBaewQgFLM0EjWj2woE82icYVpFy1mOkiKGS T3skUbOlQQC4EivCgBtVdPEIBdbrCg10wZOHHleHuhQYHeLPckVXiQhT5W8nF+faXw zGVOG4WFYtfkGdJinzCdLiy+LbYVK3JQJTwrf69l6OeuSwBGvF6exbLPQSsnvUzZWq sQoLbGg/7fny0rt0f38Qi6pEmk1lz/nRGaNs2CNBuYfofhynZIFz6pYrZ57nhD+pLD 4GqyvjBrnUMed5YDKzYdpahARVX8Dcxeicqagckk/Bv6JfsfbkKtLu+zyPKDKJhGls OmBMRYzXvM0JQ== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Samuel Holland Subject: [PATCH v2] riscv: select ARCH_HAS_FAST_MULTIPLIER Date: Sat, 2 Dec 2023 21:52:02 +0800 Message-Id: <20231202135202.4071-1-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Sat, 02 Dec 2023 06:04:50 -0800 (PST) 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 --- 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 95a2a06acc6a..e4834fa76417 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 -- 2.42.0