4 ms·
A better option here would be to use `_mm_movemask_epi8`, for the vector: ``` { false, false, false, false, true, false, false, true } ``` It will give an int
by ayende 3y ago
A better option here would be to use `_mm_movemask_epi8`, for the vector:
```
{ false, false, false, false, true, false, false, true }
```
It will give an int with the bits: `0b0000_1001`
You can then do `@clz` to get the index of the first set bit.
That would save you the `@reduce` and `@splat`. I don't see how to access move mask from Zig, however.
Note that the standard library has `std.zig.firstIndexOfValue`, which does what you have in the post, basically. And there is `std.zig.firstTrue`, which does the the same thing as `@clz` in this case, but I don't know what kind of assembly it will generate.
- e4m2 3y ago> I don't see how to access move mask from Zig, however. Bools in a vector each only occupy one bit. You can @bitCast an N element bool vector directly to a uN integer and it will generate movemask on x86.
- anonymoushn 3y agoThis must be new. Last year the compiler believed vectors of bools were both N bytes wide and N bits wide for different purposes and we ended up needing @ptrCast(*const u64, &my_bool_vec).*