[libc-commits] [libc] 2ab0676 - [libc] Add simd_bitmask type

via libc-commits libc-commits at lists.llvm.org
Thu Nov 19 17:48:06 PST 2026


Author: Aiden Grossman
Date: 2026-11-19T17:48:01-08:00
New Revision: 2ab0676e1b28568c400a643334884324c228d69d

URL: https://github.com/llvm/llvm-project/commit/2ab0676e1b28568c400a643334884324c228d69d
DIFF: https://github.com/llvm/llvm-project/commit/2ab0676e1b28568c400a643334884324c228d69d.diff

LOG: [libc] Add simd_bitmask type

Just a thin wrapper around internal::get_as_integer_type. This is nicer
than using an internal type outside of the library implementation in
inline_strlen.h. Putting this up given I plan on using it more for an
optimized memchr implementation.

Assisted-By: LLM

Reviewers: jhuber6, michaelrj-google

Pull Request: https://github.com/llvm/llvm-project/pull/244467

Added: 
    

Modified: 
    libc/src/__support/CPP/simd.h
    libc/src/string/memory_utils/generic/inline_strlen.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/CPP/simd.h b/libc/src/__support/CPP/simd.h
index 0a7f1eefbd438a..8895db0dde7849 100644
--- a/libc/src/__support/CPP/simd.h
+++ b/libc/src/__support/CPP/simd.h
@@ -49,6 +49,9 @@ LIBC_INLINE_VAR constexpr size_t native_vector_size = 16 / sizeof(T);
 template <typename T> LIBC_INLINE constexpr size_t native_vector_size = 1;
 #endif
 
+template <typename T>
+using get_as_integer_type_t = unsigned _BitInt(sizeof(T) * CHAR_BIT);
+
 } // namespace internal
 
 // Type aliases.
@@ -58,6 +61,8 @@ template <typename T, size_t N = internal::native_vector_size<T>>
 using simd = T [[clang::ext_vector_type(N)]];
 template <typename T>
 using simd_mask = simd<bool, internal::native_vector_size<T>>;
+template <typename T, size_t N = internal::native_vector_size<T>>
+using simd_bitmask = internal::get_as_integer_type_t<simd<bool, N>>;
 
 // Type trait helpers.
 template <typename T>
@@ -84,9 +89,6 @@ template <typename T>
 using simd_element_type_t = typename simd_element_type<T>::type;
 namespace internal {
 
-template <typename T>
-using get_as_integer_type_t = unsigned _BitInt(sizeof(T) * CHAR_BIT);
-
 template <typename T> LIBC_INLINE constexpr T poison() {
   return __builtin_nondeterministic_value(T());
 }

diff  --git a/libc/src/string/memory_utils/generic/inline_strlen.h b/libc/src/string/memory_utils/generic/inline_strlen.h
index 1fc0cd5c66a27a..9df55b16ba940c 100644
--- a/libc/src/string/memory_utils/generic/inline_strlen.h
+++ b/libc/src/string/memory_utils/generic/inline_strlen.h
@@ -20,7 +20,7 @@ namespace clang_vector {
 template <typename byte_ty>
 LIBC_INLINE constexpr cpp::simd_mask<byte_ty> shift_mask(cpp::simd_mask<char> m,
                                                          size_t shift) {
-  using bitmask_ty = cpp::internal::get_as_integer_type_t<cpp::simd_mask<char>>;
+  using bitmask_ty = cpp::simd_bitmask<char>;
   bitmask_ty r = cpp::bit_cast<bitmask_ty>(m) >> shift;
   return cpp::bit_cast<cpp::simd_mask<byte_ty>>(r);
 }


        


More information about the libc-commits mailing list