[PATCH] D142179: [ADT] Add bit_floor, bit_ceil, and bit_width to bit.h
Simon Pilgrim via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 20 03:50:22 PST 2023
RKSimon added inline comments.
================
Comment at: llvm/include/llvm/ADT/bit.h:244
+///
+/// Ex. bit_ceil(5) == 8.
+template <typename T> T bit_ceil(T Value) {
----------------
bit_ceil can have UB behaviour for unrepresentable values - maybe at least mention this in the comment?
================
Comment at: llvm/include/llvm/ADT/bit.h:249
+ if (Value < 2) return 1;
+ return T(1) << llvm::bit_width(Value - 1u);
+}
----------------
Does this need to be bit_width<T> or llvm::bit_width((T)(Value - 1u)) ?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142179/new/
https://reviews.llvm.org/D142179
More information about the llvm-commits
mailing list