hmm, how bad would it be if i just wrote something equivalent in plain swift like this:
func find(_ key:UInt8, in vector:SIMD16<UInt8>, _ body:(Int) -> ())
{
// (key: 5, vector: (1, 5, 1, 1, 5, 5, 1, 1, 1, 1, 1, 1, 5, 1, 1, 5))
let places:SIMD16<UInt8> =
.init(128, 64, 32, 16, 8, 4, 2, 1, 128, 64, 32, 16, 8, 4, 2, 1),
match:SIMD16<UInt8> = places.replacing(with: 0, where: vector .!= key)
// match: ( 0, 64, 0, 0, 8, 4, 0, 0, 0, 0, 0, 0, 8, 0, 0, 1)
let r8:SIMD8<UInt8> = match.evenHalf | match.oddHalf,
r4:SIMD4<UInt8> = r8.evenHalf | r8.oddHalf,
r2:SIMD2<UInt8> = r4.evenHalf | r4.oddHalf
let r:UInt16 = .init(r2.x) << 8 | .init(r2.y)
// r: 0b0100_1100_0000_1001
var i:Int = r.leadingZeroBitCount
while i < 16
{
body(i)
i += 1 + ((r << i) << 1).leadingZeroBitCount
}
}
the assembly doesn’t look very concise, but i wonder if you have any ideas for how to improve it?