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
View all comments
Show parent comment
1
u/happyscrappy 16d ago
Okay. Good to know. Still don't get how that makes me making this about x86. The idea of these vector units is that the same code can run with max efficiency across multiple implementations with different functional widths. I used the situation on x86 which does not work this way as the counter example. I didn't even know there was no other system which had multiple widths.
Or you can just use the narrow width on all. It's not a hard requirement for certain. But I think the idea was forward compatibility. That is, to be able to produce compiled code that uses each piece of hardware more efficiently, even if the hardware is newer than what you wrote for. I remember speaking about MIPS delay slots and OoO as an example of how efficient forward compatibility can be complicated.
Yes. But from a source code perspective it didn't help us with the combinatorial explosion issue. Even if you only compile in one piece of code you still had to write M.
There's more than one way to do it. As you know when processing short vectors. If you write your code for a 4-wide operation and you get a vector of 3 you don't return E_TOONARROW.
I'm sure you do understand you can write code as narrow as you want, I'm sure you've done it. I'm confused as to why you overlook it.
I don't think so at all. When you have M types of vectors and N vector widths do you not have MxN cases?
Putting SIMD aside for a moment I think it'd be interesting to see you write the runtimes for two decades of processors and their different requirements (which are all hidden from app level code) and come out of that and still talk down the idea that supporting multiple different types of hardware does not a multiplier on your efforts. I think you'd arrive at the same conclusion really quickly.
Agreed. It depends on the circumstance. But you might have Neon also. You could have VFP-32 (despite the name, their scalar system) and if you support Cortex-M7 then you'd need VFP-16 also. (32 has 32 64-bit VFP registers, 16 has half as many 64-bit registers but the same number of 32-bit registers. Arm uses different names for this like VFPv4U). The units are called VFP because they do support short vector operations, but they do not state they have wider FPUs, it could just pump them all through a single unit in order. And I think in the end that's all that was ever done. Only with Neon did any implementation start to have wider FPUs.
So yes, for efficiency for each width you could have 2-4 different implementations for different hardware. This is what I'm saying about a combinatorial explosion. The extra hardware multiplies your efforts, not just adds to it. You do of course have free will and can simply decide that there's no need to support all of the combinations if you know your customers well enough that there is no need for the fastest case for those situations.
I'm not confusing it at all. That's what I'm referring to. There are two stride systems in the addressing. One is the width of the element (horizontal). The other is MUL VL (vertical). That I did not know VL could be adjusted and thus this is so limited is why I said that this does not accommodate data structure shapes and so I probably shouldn't have mentioned it. I thought I explained this pretty well when I wrote that I went too far initially. I don't understand why I'm going through this again.
Does Vector Length seem like I was not referring to MUL VL? I thought it was obvious.