The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] genksyms: Support arm64 CRC32 hardware acceleration
@ 2026-05-25  7:03 Wentao Guan
  2026-05-25  7:50 ` Petr Pavlu
  2026-05-28 10:33 ` [PATCH v2] genksyms: Support arm64 CRC32 hardware acceleration kernel test robot
  0 siblings, 2 replies; 9+ messages in thread
From: Wentao Guan @ 2026-05-25  7:03 UTC (permalink / raw)
  To: masahiroy; +Cc: petr.pavlu, linux-kernel, Wentao Guan

Use hardware 'crc32b' to partial_crc32_one() when support,
it shows 2x speed up than crctab32 way.

I think it will be scaled to more architecture.

Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
---
changelog:
1. remove change in partial_crc32(),
for partial_crc32_one() already use crc32b.

---
---
 scripts/genksyms/genksyms.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/scripts/genksyms/genksyms.c b/scripts/genksyms/genksyms.c
index 83e48670c2fcf..80b7797c842aa 100644
--- a/scripts/genksyms/genksyms.c
+++ b/scripts/genksyms/genksyms.c
@@ -116,8 +116,40 @@ static const uint32_t crctab32[] = {
 	0x2d02ef8dU
 };
 
+/*
+ * Architecture-specific CRC32 hardware acceleration.
+ */
+static int crc32_hw_available;
+
+#ifdef __aarch64__
+#include <sys/auxv.h>
+#include <asm/hwcap.h>
+
+static void crc32_check_hw(void)
+{
+	crc32_hw_available = (getauxval(AT_HWCAP) & HWCAP_CRC32) != 0;
+}
+
+static inline uint32_t crc32_hw_byte(uint8_t c, uint32_t crc)
+{
+	asm volatile(".arch_extension crc\n\t"
+				"crc32b %w0, %w0, %w1" : "+r"(crc) : "r"(c));
+	return crc;
+}
+
+#else
+static void crc32_check_hw(void)
+{
+	crc32_hw_available = 0;
+}
+#endif
+
 static uint32_t partial_crc32_one(uint8_t c, uint32_t crc)
 {
+#if defined(__aarch64__)
+	if (__builtin_expect(crc32_hw_available, 0))
+		return crc32_hw_byte(c, crc);
+#endif
 	return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
 }
 
@@ -740,6 +772,8 @@ int main(int argc, char **argv)
 	FILE *dumpfile = NULL, *ref_file = NULL;
 	int o;
 
+	crc32_check_hw();
+
 	struct option long_opts[] = {
 		{"debug", 0, 0, 'd'},
 		{"warnings", 0, 0, 'w'},
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-05-28 10:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-25  7:03 [PATCH v2] genksyms: Support arm64 CRC32 hardware acceleration Wentao Guan
2026-05-25  7:50 ` Petr Pavlu
2026-05-25  8:02   ` [PATCH v2] genksyms: Support arm64 CRC32 hardware acceleration1~ Wentao Guan
2026-05-25  9:09     ` Petr Pavlu
2026-05-25 13:41       ` Wentao Guan
2026-05-25 17:33         ` Petr Pavlu
2026-05-26 18:12           ` Wentao Guan
2026-05-26 19:13           ` Wentao Guan
2026-05-28 10:33 ` [PATCH v2] genksyms: Support arm64 CRC32 hardware acceleration kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox