SIMD Swizzles

I'd like to propose a specific element swizzle for SIMD4, which I find myself adding to every project where I use SIMD types:

extension SIMD4 {
    
    var xyz: SIMD3<Scalar> {
        return self[SIMD3(0, 1, 2)]
    }
    
}

I know that it is preferred that we don't add every element swizzle, only the particularly useful ones, and I find this one to be particularly useful, as I constantly find myself adding it to graphics related projects.

Since I will probably be adding SwiftNumerics to any future graphics projects, it would be nice to have this particular swizzle included.

It'd hard to draw a line whether a swizzling is useful or not.
Even simd2.xyxy or simd2.xxyy, or even color.rgba vs color.argb is not that far out of reach.

I think zero-extending or truncating another SIMD vector is a special class that could reasonably be given its own affordance. I would probably want it to be more general than just SIMD3 from SIMD4, however.

2 Likes

That'd still be a lot if we're to extend it all the way to SIMD64. Though perhaps that's doable with .gyb?

That's fair, I called out this case as especially useful, but yes in general the truncating case would be useful.