[libc] [llvm] Add vector-based strlen implementation for x86_64 and aarch64 (PR #152389)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 7 12:09:58 PDT 2025


jhuber6 wrote:

> > You're doing the benchmarks single source I guess?
> 
> The glibc benchmark suite is pretty nice. You just #include the .c file you want to use and tag as many function names as you want. That all breaks down if it isn't c and can't be built with gcc though.
> 
> I hacked your code using builtin vector types into something more comparable to my original implemenation, and hacked a bit more to build it with clang and insert into the benchmark at link time. So here is a graph of the results on my local machine. With the clang-based vectors, ss2 is somewhat faster than the intrinsic version. avx2 is pretty much the same, and avx512 is somewhat slower.
>

Interesting thanks for taking the time to compare them. it's probably worth checking why AVX512 is slightly slower and seeing if there's any potential for instcombine updates. 

> char_read is the blue line, and the default today. Ouch. wide_read is the most optimal version we ship today. Better, but still.
> 
> The __strlen_* implementations are glibc hand-coded implementations.
> 
> Note the logarithmic scale. You will want to display this on a large monitor. It's all about tradeoffs.
> 
> I don't know when the ext_vector_types were added to clang, but at least clang-19 as shipped by debian testing doesn't support them. So if we care about older compilers, we probably shouldn't go this route.
>

They've been supported for quite awhile, but I only fixed the modern C++ spelling in Clang-21. Use the old attribute syntax and it should work https://godbolt.org/z/Kzv5d5ojY. I was thinking about just making a helped like `HAS_VECTOR_TYPE` which checks `__has_attribute(ext_vector_type)`. We likely then just want some  templated wrapper type around the raw attribute.

> I'll wait to clean all this up and upload it the actual changes until we figure out what to do.
> <img alt="strlen-" width="2000" height="1429" src="https://private-user-images.githubusercontent.com/56981066/475731809-50e0eb2b-dc37-4992-8b0b-2c3f269c4610.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTQ1OTM1MzIsIm5iZiI6MTc1NDU5MzIzMiwicGF0aCI6Ii81Njk4MTA2Ni80NzU3MzE4MDktNTBlMGViMmItZGMzNy00OTkyLThiMGItMmMzZjI2OWM0NjEwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA4MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwODA3VDE5MDAzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTUxODg5ZWVkNTNmZjk1NGIzZjQ0ODJjZjVkNjc4Zjk3ZjgxODZjZGI2ZDA2ZmRkYTcxNzY3ZGM2NzZiM2MzY2QmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.H3iOe5V29Cqt_i4oDAwdDg21HxWGKjgJ0xe6ScB-QbA">



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


More information about the llvm-commits mailing list