[libcxx-commits] [libcxx] [libc++] Optimize num_get integral functions (PR #121795)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 26 07:58:01 PST 2025


================
@@ -403,6 +405,27 @@ struct __num_get : protected __num_get_base {
 
   [[__deprecated__("This exists only for ABI compatibility")]] static string
   __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep);
+
+  _LIBCPP_HIDE_FROM_ABI static ptrdiff_t __atoms_offset(const _CharT* __atoms, _CharT __val) {
+#    if _LIBCPP_HAS_ALGORITHM_VECTOR_UTILS
+    _LIBCPP_DIAGNOSTIC_PUSH
+    _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wpsabi")
+    if constexpr (is_same<_CharT, char>::value) {
+      using __vec   = __simd_vector<char, 32>;
+      __vec __chars = std::__broadcast<__vec>(__val);
+      __vec __cmp   = std::__partial_load<__vec, __int_chr_cnt>(__atoms);
+      auto __res    = __chars == __cmp;
+      if (std::__none_of(__res))
+        return __int_chr_cnt;
+      return std::min(__int_chr_cnt, std::__find_first_set(__res));
+    } else
+      _LIBCPP_DIAGNOSTIC_POP
+#    endif
+      {
+        return std::find(__atoms, __atoms + __int_chr_cnt, __val) - __atoms;
+      }
----------------
ldionne wrote:

This `if-else` interleaving is confusing because of the preprocessor `#if`. I think you can just have a dangling `std::find` without an `else` instead. Should look like this

```
#if HAS_VECTOR
if constexpr (char type) {
#push
  SIMD stuff
#pop
}
#endif

return std::find(...);
```

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


More information about the libcxx-commits mailing list