3 ms·
This is an interesting article. I don't really work with low level enough languages for this to matter (unless - does this ever show up in Javascript somehow?).
by losvedir 3mo ago
This is an interesting article. I don't really work with low level enough languages for this to matter (unless - does this ever show up in Javascript somehow?).
I guess I don't understand the "reduce" step. It seems like you have to be careful not to "undo" all the benefit from SIMD. Sure, it can compare 8 values in parallel, but then if you have to look at each of the 8 answers in turn you're back to where you began. Is the `@reduce()` function in the example a special Vector one that tells you if all the values are true or not in one "step"?
- wrs 3mo agoYes. "`@reduce(.And, ...)` combines every boolean using `and` and returns a single boolean." If it's true (the common case here) then you proceed to look at the next 8 bytes. If it's false, you apply a @bitcast (turn the booleans into bits) and @ctz (find the first 0) to get the index of where it was false.
- saagarjha 3mo agoIt can show up in JavaScript if you write your code in a way that lets the browser engine lower it to SIMD under the hood
- exDM69 3mo ago> Is the `@reduce()` function in the example a special... Yes, it is. In SIMD you can do a reduce for a commutative function in O(log N) steps. Sum, product, min, max, all, any, etc. Although in this case it might be better if you just take the mask (vector of booleans), convert it to a bitmask and check if it is (non-) zero. If the language provides it, you might also use .all() or .any() for a mask.