[llvm] [llvm] Improve implementation of StringRef::find_last_of and cie (PR #71865)
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 20 15:44:49 PST 2023
================
@@ -268,17 +268,47 @@ StringRef::size_type StringRef::find_first_not_of(StringRef Chars,
return npos;
}
+// See https://graphics.stanford.edu/~seander/bithacks.html#ValueInWord
+static inline uint64_t haszero(uint64_t v) {
+ return ((v)-0x0101010101010101UL) & ~(v) & 0x8080808080808080UL;
+}
+static inline uint64_t hasvalue(uint64_t x, char n) {
+ return haszero((x) ^ (~0UL / 255 * (n)));
----------------
aganea wrote:
You'll need `~0ULL` here otherwise things won't work as expected. `x` is a 64-bit value and the goal of the algorithm to spread out `n` to all bytes. The initial algorithm in the [link](https://graphics.stanford.edu/~seander/bithacks.html#ValueInWord) you've provided was written for 32-bit values. With just `~0UL` only the lowest 32-bit values of the 64-bit value will be filled out.
https://github.com/llvm/llvm-project/pull/71865
More information about the llvm-commits
mailing list