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.
This commit is contained in:
Nico Weber 2023-03-25 21:18:38 +01:00 committed by Linus Groh
parent ee6843a13c
commit 0452a8ed4b
Notes: sideshowbarker 2024-07-17 04:34:25 +09:00

View file

@ -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;