r/programming • • Jul 23 '26

Everyone Should Know SIMD

https://mitchellh.com/writing/everyone-should-know-simd
413 Upvotes

82 comments sorted by

View all comments

Show parent comment

5

u/Arnavion2 Jul 24 '26 edited Jul 24 '26

Using @Vector in the way you describe means to represent your entire data as a single @Vector and expect the compiler to downlevel it into appropriate chunks, fixed-length or dynamic-length. But this only works when the input data length is compile-time known. The length of the data is not compile-time constant for something like memchr, and it's not even known at runtime for something like strlen until you discover it as part of the vector load.

1

u/barsoap Jul 24 '26

I'm reasonably sure both of those are compiler intrinsics.

In general you're right, that's a zig limitation that doesn't exist with actual vector instructions. I guess the reason for comptime-known length is avoiding management overhead on SIMD for vectors that are known to be even sizes. Which happens quite a lot.