libc: refactor psimd's __strong_alias logic a bit This makes exporting partial TUs easier. Specifically, I'm trying to add `wcslen` to ARM64. It _could_ be better to swap to "headers where everything's implemented, and `.cpp` files that force that have one-line implementations," but this seems to work fine for now. Bug: 452714218 Test: mma Change-Id: I307158e26266ca2073285b54cb5b85c35ae99b76
diff --git a/libc/portable-simd/memchr.cpp b/libc/portable-simd/memchr.cpp index 154a2c4..96589a3 100644 --- a/libc/portable-simd/memchr.cpp +++ b/libc/portable-simd/memchr.cpp
@@ -419,3 +419,9 @@ static_cast<const wchar_t*>(portable_simd::memchr_vectorized<WmemchrTraits>( reinterpret_cast<const WmemchrTraits::CharType*>(ptr), ch, count))); } + +#if defined(__x86_64__) +PSIMD_MAYBE_STRONG_ALIAS(memchr); +PSIMD_MAYBE_STRONG_ALIAS(memrchr); +PSIMD_MAYBE_STRONG_ALIAS(wmemchr); +#endif
diff --git a/libc/portable-simd/portable_simd_detail.h b/libc/portable-simd/portable_simd_detail.h index 294f977..41f2eb6 100644 --- a/libc/portable-simd/portable_simd_detail.h +++ b/libc/portable-simd/portable_simd_detail.h
@@ -89,14 +89,23 @@ // should be put on `PSIMD_LIBC_FUNCTION`. #define PSIMD_FLATTEN __attribute__((__flatten__)) +// Given e.g., `strlen`, gives back the portable_simd name for the current +// compilation, e.g., `portable_simd_strlen_avx2`. +#define PSIMD_CONCAT1(x, y) x##y +#define PSIMD_CONCAT(x, y) PSIMD_CONCAT1(x, y) +#define PSIMD_LIBC_FUNCTION_NAME(libc_name) \ + PSIMD_CONCAT(PSIMD_CONCAT(portable_simd_, libc_name), PSIMD_EXPORT_SUFFIX) + // If PSIMD_ADD_LIBC_ALIASES is defined, we'll emit strong aliases for each // function to its corresponding libc function. For example, if this TU defines // a portable-simd version of `strlen` for SSE, `-DPSIMD_ADD_LIBC_ALIASES` will // emit a definition of `strlen` as well as `portable_simd_strlen_sse`. #if defined(PSIMD_ADD_LIBC_ALIASES) -#define PSIMD_MAYBE_STRONG_ALIAS(libc_name, impl_func) __strong_alias(libc_name, impl_func) +#define PSIMD_MAYBE_STRONG_ALIAS1(libc_name, impl_name) __strong_alias(libc_name, impl_name) +#define PSIMD_MAYBE_STRONG_ALIAS(libc_name) \ + PSIMD_MAYBE_STRONG_ALIAS1(libc_name, PSIMD_LIBC_FUNCTION_NAME(libc_name)) #else -#define PSIMD_MAYBE_STRONG_ALIAS(libc_name, impl_func) +#define PSIMD_MAYBE_STRONG_ALIAS(libc_name) #endif // Attributes to place on functions that we 'export', AKA are designed to be @@ -112,15 +121,10 @@ // `avx2` depends on the SIMD instructions we're targeting). If // `PSIMD_ADD_LIBC_ALIASES` is enabled, it also adds a strong alias for // `strlen = portable_simd_strlen_avx2`. -#define PSIMD_CONCAT1(x, y) x##y -#define PSIMD_CONCAT(x, y) PSIMD_CONCAT1(x, y) #define PSIMD_LIBC_FUNCTION_IMPL(ret_ty, libc_name, full_name, ...) \ - PSIMD_MAYBE_STRONG_ALIAS(libc_name, full_name) \ PSIMD_FLATTEN __attribute__((__hot__)) ret_ty full_name(__VA_ARGS__) #define PSIMD_LIBC_FUNCTION(ret_ty, libc_name, ...) \ - PSIMD_LIBC_FUNCTION_IMPL( \ - ret_ty, libc_name, \ - PSIMD_CONCAT(PSIMD_CONCAT(portable_simd_, libc_name), PSIMD_EXPORT_SUFFIX), __VA_ARGS__) + PSIMD_LIBC_FUNCTION_IMPL(ret_ty, libc_name, PSIMD_LIBC_FUNCTION_NAME(libc_name), __VA_ARGS__) namespace portable_simd {
diff --git a/libc/portable-simd/strlen.cpp b/libc/portable-simd/strlen.cpp index 14f9a99..486bad5 100644 --- a/libc/portable-simd/strlen.cpp +++ b/libc/portable-simd/strlen.cpp
@@ -239,3 +239,8 @@ return portable_simd::strlen_vectorized<WcslenTraits>( reinterpret_cast<const WcslenTraits::CharType*>(s)); } + +#if defined(__x86_64__) +PSIMD_MAYBE_STRONG_ALIAS(strlen); +PSIMD_MAYBE_STRONG_ALIAS(wcslen); +#endif