Skip to content

Commit 94b44fd

Browse files
committed
genksyms: Support arm64 CRC32 hardware acceleration
maillist inclusion category: performance Use hardware 'crc32b' to build genksyms when support, it shows 2x speed up than crctab32 way. Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent caaba8d commit 94b44fd

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

scripts/genksyms/genksyms.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,40 @@ static const uint32_t crctab32[] = {
116116
0x2d02ef8dU
117117
};
118118

119+
/*
120+
* Architecture-specific CRC32 hardware acceleration.
121+
*/
122+
static int crc32_hw_available;
123+
124+
#ifdef __aarch64__
125+
#include <sys/auxv.h>
126+
#include <asm/hwcap.h>
127+
128+
static void crc32_check_hw(void)
129+
{
130+
crc32_hw_available = (getauxval(AT_HWCAP) & HWCAP_CRC32) != 0;
131+
}
132+
133+
static inline uint32_t crc32_hw_byte(uint8_t c, uint32_t crc)
134+
{
135+
asm volatile(".arch_extension crc\n\t"
136+
"crc32b %w0, %w0, %w1" : "+r"(crc) : "r"(c));
137+
return crc;
138+
}
139+
140+
#else
141+
static void crc32_check_hw(void)
142+
{
143+
crc32_hw_available = 0;
144+
}
145+
#endif
146+
119147
static uint32_t partial_crc32_one(uint8_t c, uint32_t crc)
120148
{
149+
#if defined(__aarch64__)
150+
if (__builtin_expect(crc32_hw_available, 0))
151+
return crc32_hw_byte(c, crc);
152+
#endif
121153
return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
122154
}
123155

@@ -740,6 +772,8 @@ int main(int argc, char **argv)
740772
FILE *dumpfile = NULL, *ref_file = NULL;
741773
int o;
742774

775+
crc32_check_hw();
776+
743777
struct option long_opts[] = {
744778
{"debug", 0, 0, 'd'},
745779
{"warnings", 0, 0, 'w'},

0 commit comments

Comments
 (0)