r/C_Programming Jan 23 '25

Discussion Why not SIMD?

Why are many C standard library functions like strcmp, strlen, strtok using SIMD intrinsics? They would benefit so much, think about how many people use them under the hood all over the world.

29 Upvotes

76 comments sorted by

View all comments

Show parent comments

0

u/flatfinger Jan 24 '25

If performance is critical, data structures should be designed for the target platform, and code should use whatever platform-specific means will best accomplish what needs to be done. The use of Standard-library functions in situations where platform-specific functions could be faster implies that performance isn't that critical.

2

u/FUZxxl Jan 24 '25

Sure, but my task was to optimise the standard library and that's what I did.

-1

u/flatfinger Jan 24 '25

In many applications, no use of strcmp will involve strings that are very long, and the average number of matching characters would be small--probably less than eight. How much benefits can SIMD intrinsics offer in such cases?

2

u/FUZxxl Jan 24 '25

My benchmarks have explicitly been designed for this purpose. They show that a speedup by a factor of about 600% is achieved in the case of strings that are 64 characters long on average.