From 0452a8ed4bf529699047218fcf624ead56b6e168 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sat, 25 Mar 2023 21:18:38 +0100 Subject: [PATCH] LibCrypto: Start sometimes hardware-accelerating crc32 Takes % time Build/lagom/gunzip -c \ /Users/thakis/Downloads/trace_bug.json.gz > /dev/null from 4s to 3.9s on my MBP. --- .../Libraries/LibCrypto/Checksum/CRC32.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Userland/Libraries/LibCrypto/Checksum/CRC32.cpp b/Userland/Libraries/LibCrypto/Checksum/CRC32.cpp index 0a0ed2e861..805bff2546 100644 --- a/Userland/Libraries/LibCrypto/Checksum/CRC32.cpp +++ b/Userland/Libraries/LibCrypto/Checksum/CRC32.cpp @@ -11,6 +11,22 @@ namespace Crypto::Checksum { +#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) + +void CRC32::update(ReadonlyBytes data) +{ + // FIXME: Does this require runtime checking on rpi? + // (Maybe the instruction is present on the rpi4 but not on the rpi3?) + + // FIXME: Use __builtin_arm_crc32d() for aligned middle part. + for (size_t i = 0; i < data.size(); i++) + m_state = __builtin_arm_crc32b(m_state, data.at(i)); +}; + + // FIXME: On Intel, use _mm_crc32_u8 / _mm_crc32_u64 if available (SSE 4.2). + +#else + static constexpr auto generate_table() { Array data {}; @@ -39,6 +55,8 @@ void CRC32::update(ReadonlyBytes data) } }; +#endif + u32 CRC32::digest() { return ~m_state;