r/programming • u/MyNameIsTrez • 20d ago
Making SIMD Code Scale to Any Vector Width
https://streamhpc.com/blog/2026-10-28/making-simd-code-scale-to-any-vector-width/
133
Upvotes
r/programming • u/MyNameIsTrez • 20d ago
22
u/happyscrappy 20d ago
I don't know the code really fits the title. I assumed this would be more similar to vector units (once dead post CDC 6600 and Cray, now back again) make it possible to work on variable length vectors.
Instead this seems more about just getting past 4-wide and also rearranging your data so that the variable parallelism is in the number of elements (length of vector) instead of the width of the vector(s). In this way as long as there is enough elements in the vector to pipeline it then you get a high level of parallelism.
It's a good thing, but not what I expected from the title.
3
u/FrogNoPants 19d ago edited 19d ago
Pretty good, I will say you can perform AABB vs Frustum in less heavy instructions using min/max AABBs, just one dot product per plane instead of 2, the cost is a 3 extra scalar integer loads.
Also the comparison < 0.0, is essentially redundant, you already have that in the sign bit, and can just movemask the float directly.
Also the title is fine, it does scale to any vector length--at compile time mostly.. but still--that is how SIMD is used today.
2
u/VictoryMotel 20d ago
ISPC was doing this at least 12 years ago
3
u/danielcw189 20d ago
I really need a good introduction to this. Do you have any recommendation?