1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:47:45 +00:00

LibCrypto: Use 8-byte crc32 instruction on arm too

Takes

    % time Build/lagom/gunzip -c \
        /Users/thakis/Downloads/trace_bug.json.gz > /dev/null

from 3.9s to 3.87s.
This commit is contained in:
Nico Weber 2023-03-25 21:31:23 +01:00 committed by Linus Groh
parent 0452a8ed4b
commit 29796f8f5e

View file

@ -13,14 +13,33 @@ namespace Crypto::Checksum {
#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
void CRC32::update(ReadonlyBytes data)
void CRC32::update(ReadonlyBytes span)
{
// 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));
u8 const* data = span.data();
size_t size = span.size();
while (size > 0 && (reinterpret_cast<FlatPtr>(data) & 7) != 0) {
m_state = __builtin_arm_crc32b(m_state, *data);
++data;
--size;
}
auto* data64 = reinterpret_cast<u64 const*>(data);
while (size >= 8) {
m_state = __builtin_arm_crc32d(m_state, *data64);
++data64;
size -= 8;
}
data = reinterpret_cast<u8 const*>(data64);
while (size > 0) {
m_state = __builtin_arm_crc32b(m_state, *data);
++data;
--size;
}
};
// FIXME: On Intel, use _mm_crc32_u8 / _mm_crc32_u64 if available (SSE 4.2).