diff options
author | Nico Weber <thakis@chromium.org> | 2023-03-25 21:18:38 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-25 21:42:50 +0000 |
commit | 0452a8ed4bf529699047218fcf624ead56b6e168 (patch) | |
tree | 022e73a7754b73ccaa8d6e40d23d7290cf95dd10 /Userland | |
parent | ee6843a13c22edd64b8e113cb3784021051c2f90 (diff) | |
download | serenity-0452a8ed4bf529699047218fcf624ead56b6e168.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibCrypto/Checksum/CRC32.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
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<u32, 256> data {}; @@ -39,6 +55,8 @@ void CRC32::update(ReadonlyBytes data) } }; +#endif + u32 CRC32::digest() { return ~m_state; |