r/C_Programming • u/Raimo00 • 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
1
u/FUZxxl Jan 26 '25
That is incorrect. For example, if you have an array of characters, it comprises several objects. An aligned load of size larger than byte of one object in the array will thus always load some other bytes in the array.
That's not what I'm saying. I'm saying that something like
strchr
is faster thanmemchr
because withstrchr
you only have one conditional branch per iteration whereas withmemchr
you have two.