[libc-commits] [libc] [llvm] [libc] Fix forward missing `BigInt` specialization of `mask_leading_ones` / `mask_trailing_ones` (PR #84325)

via libc-commits libc-commits at lists.llvm.org
Thu Mar 7 08:27:37 PST 2024


================
@@ -1056,4 +1056,59 @@ rotr(T value, int rotate) {
 
 } // namespace LIBC_NAMESPACE::cpp
 
+namespace LIBC_NAMESPACE {
+
+// Specialization of mask_trailing_ones ('math_extras.h') for BigInt.
+template <typename T, size_t count>
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_big_int_v<T>, T>
+mask_trailing_ones() {
+  static_assert(!T::SIGNED);
+  if (count == 0)
+    return T();
+  constexpr unsigned T_BITS = CHAR_BIT * sizeof(T);
+  static_assert(count <= T_BITS && "Invalid bit index");
+  using word_type = typename T::word_type;
+  T out;
+  const int chunk_index_containing_bit = static_cast<int>(count / T::WORD_SIZE);
----------------
lntue wrote:

`constexpr`?

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


More information about the libc-commits mailing list