VolumeVerifier: enable fast hash functions by default

sets defaults based on cpu support.
This commit is contained in:
Shawn Hoffman
2022-07-28 10:31:16 -07:00
parent 7d2d5d914b
commit d71797154a
7 changed files with 61 additions and 18 deletions

View File

@ -18,6 +18,7 @@
#include "Common/Align.h"
#include "Common/Assert.h"
#include "Common/CPUDetect.h"
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
#include "Common/Crypto/SHA1.h"
@ -374,6 +375,24 @@ VolumeVerifier::~VolumeVerifier()
WaitForAsyncOperations();
}
Hashes<bool> VolumeVerifier::GetDefaultHashesToCalculate()
{
Hashes<bool> hashes_to_calculate{.crc32 = true, .md5 = true, .sha1 = true};
// If the system can compute certain hashes faster than others, only default-enable the fast ones.
const bool sha1_hw_accel = Common::SHA1::CreateContext()->HwAccelerated();
// For crc32, we assume zlib-ng will be fast if cpu supports crc32
const bool crc32_hw_accel = cpu_info.bCRC32;
if (crc32_hw_accel || sha1_hw_accel)
{
hashes_to_calculate.crc32 = crc32_hw_accel;
// md5 has no accelerated implementation at the moment, always default to off
hashes_to_calculate.md5 = false;
// Always enable SHA1, to avoid situation where only crc32 is computed
hashes_to_calculate.sha1 = true;
}
return hashes_to_calculate;
}
void VolumeVerifier::Start()
{
ASSERT(!m_started);