# SIMD Swizzles

**URL:** <https://forums.swift.org/t/simd-swizzles/30690>\
**Category:** Swift Numerics\
**Tags:** simd\
**Created:** [November 11, 2019, 8:14pm UTC](https://forums.swift.org/t/simd-swizzles/30690 "2019-11-11T20:14:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Syre](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Syre](https://forums.swift.org/u/Syre)\
**Post date:** [November 11, 2019, 8:14pm UTC](https://forums.swift.org/t/simd-swizzles/30690/1 "2019-11-11T20:14:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Lantua](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lantua/32/8868_2.png) [@Lantua](https://forums.swift.org/u/Lantua)\
**Post date:** [November 11, 2019, 8:26pm UTC](https://forums.swift.org/t/simd-swizzles/30690/2 "2019-11-11T20:26:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![scanon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/scanon/32/2445_2.png) [@scanon](https://forums.swift.org/u/scanon)\
**Post date:** [November 11, 2019, 8:31pm UTC](https://forums.swift.org/t/simd-swizzles/30690/3 "2019-11-11T20:31:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Lantua](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lantua/32/8868_2.png) [@Lantua](https://forums.swift.org/u/Lantua)\
**Post date:** [November 11, 2019, 8:34pm UTC](https://forums.swift.org/t/simd-swizzles/30690/4 "2019-11-11T20:34:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Syre](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Syre](https://forums.swift.org/u/Syre)\
**Post date:** [November 11, 2019, 9:02pm UTC](https://forums.swift.org/t/simd-swizzles/30690/5 "2019-11-11T21:02:52Z")

</div>

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