[llvm] [llvm] Improve implementation of StringRef::find_last_of and cie (PR #71865)

via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 1 11:56:08 PDT 2024


================
@@ -268,17 +268,70 @@ 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 & 0x7F7F7F7F7F7F7F7FULL) + 0x7F7F7F7F7F7F7F7FULL) | v) |
+           0x7F7F7F7F7F7F7F7FULL);
+}
+static inline uint64_t hasvalue(uint64_t x, char n) {
+  return haszero((x) ^ (~0ULL / 255 * (n)));
----------------
Ralender wrote:

Maybe its just me but I think `haszero((x) ^ ((uint64_t)n * 0x0101010101010101))` makes it more clear that `n` is just repeated over the entire `uint64_t`

https://github.com/llvm/llvm-project/pull/71865


More information about the llvm-commits mailing list