mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +00:00
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:
parent
ee6843a13c
commit
0452a8ed4b
1 changed files with 18 additions and 0 deletions
|
@ -11,6 +11,22 @@
|
||||||
|
|
||||||
namespace Crypto::Checksum {
|
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()
|
static constexpr auto generate_table()
|
||||||
{
|
{
|
||||||
Array<u32, 256> data {};
|
Array<u32, 256> data {};
|
||||||
|
@ -39,6 +55,8 @@ void CRC32::update(ReadonlyBytes data)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
u32 CRC32::digest()
|
u32 CRC32::digest()
|
||||||
{
|
{
|
||||||
return ~m_state;
|
return ~m_state;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue