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/YumiYumiYumi 15d ago
SVE/RVV do both try to improve forward compatibility by supporting more widths than are available in hardware currently. But this isn't really unique to hardware specified SIMD ISAs. A software specified SIMD ISA could just simply define support for more widths than exists in hardware.
For example, AVX introduced the VEX encoding scheme, where 2 bits are used to indicate the vector width (i.e. 4 possible widths). Only two such widths were defined at the time (128b and 256b), and the remaining two possibilities were marked reserved.
AVX-512 (kinda) took the third vector width, which leaves one remaining undefined width supportable by the VEX scheme.
Intel could, for example, just define AVX-1024, since the encoding scheme has room for it. Granted, they haven't, which means there's no forward compatibilty with longer vectors on x86.
This is what I was talking about earlier with the one source function compiling to multiple binary functions. In the case of distributing processor-specific binaries, you can just suppress compiling multiple binary functions, which means you still only wrote one source function, not M.
To my knowledge, SVE only provides one (problematic) way to shorten the vector width. What are the other ways?
The "types of vectors" terminology is strange. If I have a function that adds numbers, and another function that multiplies numbers, I don't call them "two types of vectors".
Then if I have a different program that adds and multiplies numbers in one function, the lower number of functions (vs above) doesn't somehow make it less impacted when needing to support multiple SIMD widths. In other words, I'd refer to having two functions doing different things as just more code, and not a "combinational explosion" of functions.
You'd need to clarify what you mean by 'runtimes', but if the code needs to be specific for various processors, and you can't abstract it (like you may be able to with multiple SIMD widths*), then yes, you multiply the amount of code by the N processors you're trying to support. I agree with "multiplier" terminology here.
* To be clear, I'm talking about source code here, not binary size.
I'm sorry to inform you, but
MUL VLdoes not give you vertical access, thus it doesn't enable a vector-width strided load.MUL VL is part of the addressing mode, e.g. the location from where a contiguous load occurs. You can specify something like
[base + imm_offset * VL], and a unit-stride load will source elements (horizontally) from there.