Created
November 11, 2020 02:45
-
-
Save delta4d/ca020c34eb146db2ca0235f3c2db236e to your computer and use it in GitHub Desktop.
NoisePage on Virtual Env
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/execution/util/vector_util.cpp b/src/execution/util/vector_util.cpp | |
index 340091ea..a1fea15b 100644 | |
--- a/src/execution/util/vector_util.cpp | |
+++ b/src/execution/util/vector_util.cpp | |
@@ -107,7 +107,11 @@ uint32_t VectorUtil::ByteVectorToSelectionVector(const uint8_t *byte_vector, con | |
auto idx = _mm_set1_epi16(0); | |
for (; i + 8 <= num_bytes; i += 8) { | |
const auto word = *reinterpret_cast<const uint64_t *>(byte_vector + i); | |
+#ifdef __BMI2__ | |
const auto mask = _pext_u64(word, 0x202020202020202); | |
+#else | |
+ const auto mask = BitUtil::pext_u64(word, 0x202020202020202); | |
+#endif | |
NOISEPAGE_ASSERT(mask < 256, "Out-of-bounds mask"); | |
const auto match_pos_scaled = _mm_loadl_epi64(reinterpret_cast<const __m128i *>(&simd::K8_BIT_MATCH_LUT[mask])); | |
const auto match_pos = _mm_cvtepi8_epi16(match_pos_scaled); | |
diff --git a/src/include/execution/util/bit_util.h b/src/include/execution/util/bit_util.h | |
index fed309ce..d0baaea4 100644 | |
--- a/src/include/execution/util/bit_util.h | |
+++ b/src/include/execution/util/bit_util.h | |
@@ -120,6 +120,34 @@ class BitUtil { | |
auto num_words = Num32BitWordsFor(num_bits); | |
std::memset(bits, 0, num_words * sizeof(uint32_t)); | |
} | |
+ | |
+ /** | |
+ * serial version of _pdep_u64 | |
+ */ | |
+ static uint64_t pdep_u64(uint64_t src, uint64_t mask) { | |
+ uint64_t dest = 0u; | |
+ for (uint64_t b2 = 1; mask; b2 <<= 1) { | |
+ if (src & b2) { | |
+ dest |= mask & -mask; | |
+ } | |
+ mask &= mask - 1; | |
+ } | |
+ return dest; | |
+ } | |
+ | |
+ /** | |
+ * serial version for pext_u64 | |
+ */ | |
+ static uint64_t pext_u64(uint64_t src, uint64_t mask) { | |
+ uint64_t dest = 0u; | |
+ for (uint64_t b2 = 1; mask; b2 <<= 1) { | |
+ if (src & mask & -mask) { | |
+ dest |= b2; | |
+ } | |
+ mask &= mask - 1; | |
+ } | |
+ return dest; | |
+ } | |
}; | |
} // namespace noisepage::execution::util | |
diff --git a/src/include/execution/util/bit_vector.h b/src/include/execution/util/bit_vector.h | |
index c78fd9a6..95d5d3e5 100644 | |
--- a/src/include/execution/util/bit_vector.h | |
+++ b/src/include/execution/util/bit_vector.h | |
@@ -354,7 +354,11 @@ class BitVector { | |
const WordType word = words_[i]; | |
const uint32_t count = BitUtil::CountPopulation(word); | |
if (n < count) { | |
+#ifdef __BMI2__ | |
const WordType mask = _pdep_u64(static_cast<WordType>(1) << n, word); | |
+#else | |
+ const WordType mask = BitUtil::pdep_u64(static_cast<WordType>(1) << n, word); | |
+#endif | |
const uint32_t pos = BitUtil::CountTrailingZeros(mask); | |
return std::min(GetNumBits(), (i * WORD_SIZE_BITS) + pos); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment