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

13

u/paulstelian97 Jul 23 '26

The fact that the size of the vector can be runtime dynamic is quite nuts to me!

1

u/tanner-gooding Jul 27 '26

Its not really runtime dynamic, no operating system supports that and rather enforce it to be fixed per process instead.

Linux technically provides APIs to allow actual dynamic changing, but warns you that doing so can/will lead to UB.

It's also not really truly "variable length", you don't even really write your SIMD code that differently. You just rather have some APIs that trivially let you get the leading/trailing masks and deal with the remainder.

Predicated instructions are in fact more expensive than their unpredicated counterparts, so you don't write the entire loop predicated unless you can't help it

1

u/Arnavion2 Jul 28 '26

Masks and predication apply to SVE but not to RISC-V, where the active vector length is controlled by a special register.