[libc] [llvm] [libc][NFC] Remove __support/bit.h and use __support/CPP/bit.h instead (PR #73939)

Guillaume Chatelet via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 5 02:05:33 PST 2023


================
@@ -152,8 +153,9 @@ class HashState {
     }
   }
   LIBC_INLINE uint64_t finish() {
-    int rot = buffer & 63;
-    uint64_t folded = folded_multiply(buffer, pad);
+    const uint64_t folded = folded_multiply(buffer, pad);
+    // Only keep the bottom bits of buffer that fits in an int.
+    const int rot = buffer & cpp::numeric_limits<int>::digits;
----------------
gchatelet wrote:

OK -my bad- I misunderstood the code in the first place... 🙄
The original code was
```
    uint64_t rot = buffer & 63;
    uint64_t folded = folded_multiply(buffer, pad);
    return rotate_left(folded, rot);
```
So `rot` is an unsigned value from `0` to `63` which totally fits in an `int` ([guaranteed to be 16 bits at least](https://en.cppreference.com/w/cpp/language/types)).

So changing the `rot` type from `uint64_t` to `int` is totally fine. I think my brain read `1 << 63` instead of `63`...

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


More information about the llvm-commits mailing list