crc32: Add crc32 implementation using __builtin_aarch64_crc32b
Subsystems (2)
PATCH 1/1 crc32: Add crc32 implementation using __builtin_aarch64_crc32b
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.
--- arch/arm/Kconfig | 9 +++++++++ arch/arm/Makefile | 4 ++++ lib/crc32.c | 7 +++++++ 3 files changed, 20 insertions(+)
arch/arm/Kconfig +9 -0
@@ -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
arch/arm/Makefile +4 -0
@@ -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
lib/crc32.c +7 -0
@@ -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
Signature · 1 line
2.33.0
Quoted 8 lines · Marek Vasut
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
0x500000000x2000000
time: 0.126 seconds # crc32 instruction
time: 0.213 seconds # software crc32
Quoted 7 lines
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 <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>
Applied to u-boot/next, thanks!
Signature · 1 line
Tom