Skip to content

Saturating casts for integers, like _mm_packus_epi16 and _mm_packs_epi16 #369

Open
@okaneco

Description

@okaneco

My most common use case is for saturating narrowing casts, such as from i16 to u8. It would be great to take advantage of native instructions without first having to use simd_clamp. saturating_cast would reduce code and chances of errors from clamping with incorrect values.

I'm not sure about the availability of this feature on other architectures. It might make sense to split this for narrowing and widening features based on availability. I'm not familiar with other architectures, but it looks like ARM has narrowing casts with VQMOVN/VQMOVUN.

Perhaps there could be a fallback which does simd_clamp().cast() (or other optimal construction) for architectures that don't have these instructions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: a feature request, i.e. not implemented / a PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions