Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C1B6C432BE for ; Mon, 30 Aug 2021 13:05:44 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 64F2560E77 for ; Mon, 30 Aug 2021 13:05:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 64F2560E77 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B4D9483338; Mon, 30 Aug 2021 15:05:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1630328741; bh=nq79WduIzeh9QBJhZjJ19wO3o0GiZrrXSrlzk9jnvP8=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=ghDcYhLgxRPAoQw4YkGStIZ39eUZTchydY/sUGKandUXZ5xLwyqc/hkqvS93RFeex ezFK6i7Z5oGYgcKoDmTLhk4Bao5b91dmzlH76p+tMSLm7DuvH+UVu7ihBeuL+mJECB BGOsWgovlTwO1kaFLhUFt+wADYJaE5snW2YjxvjS/JdwSodcVi2Ir+3A+azPmOPmvv EFWQlMi8juTMNb9ufwePdYSHJylZnjNxhCq455o34/XGMw8yQygSoIOOSiLq7fpVS0 fjHzUAOlkcllWR50M5PJJrBlp2yJai4FTtbeVn/C1AEDitW+5bUf6ykv7lVb9RzXrF 9ch3VcnrT2g2A== Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 5700983334; Mon, 30 Aug 2021 15:05:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1630328739; bh=nq79WduIzeh9QBJhZjJ19wO3o0GiZrrXSrlzk9jnvP8=; h=From:To:Cc:Subject:Date:From; b=LE94yOmeMHt/u0RextBGmf6+h1md9nciMIdm/kG50TN+QmRv/HSpHk40uszARNMJE e6ZaQG7ueI60F88aZSV0eI4A4h84mIFGdrtXVMMrIbDqUIW5igyO3YnNSbvmpCU9mQ ISVi44SBK/VOAe45bWQuGfQppzE+Dtc4H0qva42ZBJCDDvjTuDkLrCxTsfGsxderrd cR7XKvFKbBfy2X3eQkOX4E1vMmNmMpgPXwpB+C9VQ060MdUp0wbh1LYzj/ulD4Od5F 2INw4q9NmD+OPvU02mC3JVYhn5JUV1ByG29QKLJ0F7qY6QYfo1CgQKsEIsVWA0ui9h keBye2vdDvBgA== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Simon Glass , Tom Rini Subject: [PATCH] crc32: Add crc32 implementation using __builtin_aarch64_crc32b Date: Mon, 30 Aug 2021 15:05:23 +0200 Message-Id: <20210830130523.11043-1-marex@denx.de> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean ARMv8.0 has optional crc32 instruction for crc32 calculation. The instruction is mandatory since ARMv8.1. The crc32 calculation is faster using the dedicated instruction, e.g. 1.4 GHz iMX8MN gives: => time crc32 0x50000000 0x2000000 time: 0.126 seconds # crc32 instruction time: 0.213 seconds # software crc32 Add implementation using the compiler builtin wrapper for the crc32 instruction and enable it by default, since we don't support any platforms which do not implement this instruction. Signed-off-by: Marek Vasut Cc: Simon Glass Cc: Tom Rini --- arch/arm/Kconfig | 9 +++++++++ arch/arm/Makefile | 4 ++++ lib/crc32.c | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 2d59562665f..134d3c6563d 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -10,6 +10,15 @@ config ARM64 select SYS_CACHE_SHIFT_6 if ARM64 +config ARM64_CRC32 + bool "Enable support for CRC32 instruction" + default y + help + ARMv8 implements dedicated crc32 instruction for crc32 calculation. + This is faster than software crc32 calculation. This instruction may + not be present on all ARMv8.0, but is always present on ARMv8.1 and + newer. + config POSITION_INDEPENDENT bool "Generate position-independent pre-relocation code" help diff --git a/arch/arm/Makefile b/arch/arm/Makefile index c68e598a675..ce977bf6323 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -18,7 +18,11 @@ arch-$(CONFIG_CPU_V7A) =$(call cc-option, -march=armv7-a, \ $(call cc-option, -march=armv7)) arch-$(CONFIG_CPU_V7M) =-march=armv7-m arch-$(CONFIG_CPU_V7R) =-march=armv7-r +ifeq ($(CONFIG_ARM64_CRC32),y) +arch-$(CONFIG_ARM64) =-march=armv8-a+crc +else arch-$(CONFIG_ARM64) =-march=armv8-a +endif # On Tegra systems we must build SPL for the armv4 core on the device # but otherwise we can use the value in CONFIG_SYS_ARM_ARCH diff --git a/lib/crc32.c b/lib/crc32.c index f2acc107fe4..a207e3d2b40 100644 --- a/lib/crc32.c +++ b/lib/crc32.c @@ -184,6 +184,12 @@ const uint32_t * ZEXPORT get_crc_table() */ uint32_t __efi_runtime crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len) { +#ifdef CONFIG_ARM64_CRC32 + crc = cpu_to_le32(crc); + while (len--) + crc = __builtin_aarch64_crc32b(crc, *buf++); + return le32_to_cpu(crc); +#else const uint32_t *tab = crc_table; const uint32_t *b =(const uint32_t *)buf; size_t rem_len; @@ -221,6 +227,7 @@ uint32_t __efi_runtime crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len) } return le32_to_cpu(crc); +#endif } #undef DO_CRC -- 2.33.0