QMessageAutenticationCode: add some Q_ASSUME()s to xored()
... telling the compiler all there is to know about block.size(), so it hopefully vectorizes the function well. Pick-to: 6.5 Change-Id: Icb3d5c983402e52a65c72af15f806f3a3fe6411f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
c1e2ec16db
commit
bcc6015a3a
@ -12,6 +12,8 @@
|
|||||||
#include <private/qlocking_p.h>
|
#include <private/qlocking_p.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <climits>
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
#include "../../3rdparty/sha1/sha1.cpp"
|
#include "../../3rdparty/sha1/sha1.cpp"
|
||||||
|
|
||||||
@ -1099,10 +1101,34 @@ constexpr int maxHashBlockSize()
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[maybe_unused]]
|
||||||
|
constexpr int minHashBlockSize()
|
||||||
|
{
|
||||||
|
int result = INT_MAX;
|
||||||
|
using A = QCryptographicHash::Algorithm;
|
||||||
|
for (int i = 0; i < A::NumAlgorithms ; ++i)
|
||||||
|
result = std::min(result, qt_hash_block_size(A(i)));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[maybe_unused]]
|
||||||
|
constexpr int gcdHashBlockSize()
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
using A = QCryptographicHash::Algorithm;
|
||||||
|
for (int i = 0; i < A::NumAlgorithms ; ++i)
|
||||||
|
result = std::gcd(result, qt_hash_block_size(A(i)));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
using HashBlock = QSmallByteArray<maxHashBlockSize()>;
|
using HashBlock = QSmallByteArray<maxHashBlockSize()>;
|
||||||
|
|
||||||
static HashBlock xored(const HashBlock &block, quint8 val) noexcept
|
static HashBlock xored(const HashBlock &block, quint8 val) noexcept
|
||||||
{
|
{
|
||||||
|
// some hints for the optimizer:
|
||||||
|
Q_ASSUME(block.size() >= minHashBlockSize());
|
||||||
|
Q_ASSUME(block.size() <= maxHashBlockSize());
|
||||||
|
Q_ASSUME(block.size() % gcdHashBlockSize() == 0);
|
||||||
HashBlock result;
|
HashBlock result;
|
||||||
result.resizeForOverwrite(block.size());
|
result.resizeForOverwrite(block.size());
|
||||||
for (qsizetype i = 0; i < block.size(); ++i)
|
for (qsizetype i = 0; i < block.size(); ++i)
|
||||||
|
Loading…
Reference in New Issue
Block a user