How to convert between SIMD mask types?

maybe i’m just missing something but i don’t see any APIs on SIMDMask that allow for converting between different mask types. for example, if I want to store the results of a SIMD3<Float> comparison as an SIMD3<Int8> integer vector (with 1 in the set lanes, and 0 in the clear lanes), how would i do this?

Interested to see if there is a simple way to do that as well. (Looping is always a possibility.) What I have always done is match the widths. In your case, it would be SIMD3<Float> and SIMD3<Int32>. This comes naturally when you do floatValues .> SIMD3<Float>.zero, for example. The reason I thought the API was doing this was to prevent inefficient conversions that might occur when converting to arbitrary widths.

well, i’m actually using it in a generic context, so i’m not sure how to get an integer SIMD vector from an arbitrary SIMD3<T> where T:BinaryFloatingPoint

I see. That has bothered me too. My workaround was to avoid generics and use a set of local typealiases like this:

    typealias SIMDX = SIMD8
    typealias ScalarFloat = Float64
    typealias ScalarInt = Int64

The idea being that I could gate the widths statically based on the platform with #if but it sure isn't idiomatic Swift.

pinging @scanon in case he knows of a good way to handle this

Terms of Service

Privacy Policy

Cookie Policy