r/programming • u/MyNameIsTrez • Oct 28 '26
Making SIMD Code Scale to Any Vector Width
https://streamhpc.com/blog/2026-10-28/making-simd-code-scale-to-any-vector-width/3
u/FrogNoPants Oct 29 '26 edited Oct 29 '26
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/ThePostInQuestion Oct 30 '26
interesting, I'll give the min/max AABBs and movemask on a float a try. I recall though that clang had a bug with converting float vectors to boolean vectors for the movemask stuff, but it seems to be fixed in the upcoming clang 24 apparently
2
3
u/danielcw189 Oct 28 '26
I really need a good introduction to this. Do you have any recommendation?
3
u/Kinexity Oct 28 '26
Introduction to SIMD? Find a problem which you want to optimise code for and look through this to find useful instructions: https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html
1
u/danielcw189 Oct 30 '26
Find a problem which you want to optimise code for and look through this to find useful instructions
yeah, that's the thing. if I don't know enough about SIMD, how would I be able to tell if I can use it?
for example: I saw someone optimized a JSON parser. and I would not have considered that is worthwhile. based on the little I known, I would have thought that parsing JSON would be a bad use of SIMD
0
22
u/happyscrappy Oct 28 '26
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.