summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-01-18 11:31:40 -0800
committerThiago Macieira <thiago.macieira@intel.com>2022-01-21 14:08:01 -0800
commit517821b1730695dc41403668854871c746face26 (patch)
treed70cf2d2ec29a5b630bc7b024e80a6110ddb4452 /src
parente1654aeb2e7fa282af045496c4903b06d2893e21 (diff)
QHash: improve aeshash's page detection code
We don't need to test for actually crossing a page boundary. It suffices to check if we're in the upper half or the lower half of the page. In the upper half, we load ending at the end; in the lower half, we load starting at the current position. This way, it can never crash. Pick-to: 6.2.3 6.2 6.3 Change-Id: Icad7c1bad46a449c8e8afffd16cb743e622b3405 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qhash.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index 8f7ffb79b8..0de69ad20a 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -597,10 +597,11 @@ lt16:
// including NULLs at the end because the length is in the key)
// WARNING: this may produce valgrind warnings, but it's safe
+ constexpr quintptr PageSize = 4096;
__m128i data;
- if (Q_LIKELY(quintptr(src + 1) & 0xff0)) {
- // same page, we definitely can't fault:
+ if ((quintptr(src) & (PageSize / 2)) == 0) {
+ // lower half of the page:
// load all 16 bytes and mask off the bytes past the end of the source
static const qint8 maskarray[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -610,15 +611,14 @@ lt16:
data = _mm_loadu_si128(src);
data = _mm_and_si128(data, mask);
} else {
- // too close to the end of the page, it could fault:
+ // upper half of the page:
// load 16 bytes ending at the data end, then shuffle them to the beginning
static const qint8 shufflecontrol[] = {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
__m128i control = _mm_loadu_si128(reinterpret_cast<const __m128i *>(shufflecontrol + 15 - len));
- p = reinterpret_cast<const uchar *>(src - 1);
- data = _mm_loadu_si128(reinterpret_cast<const __m128i *>(p + len));
+ data = _mm_loadu_si128(reinterpret_cast<const __m128i *>(p + len) - 1);
data = _mm_shuffle_epi8(data, control);
}