Skip to content

Make constructors const fn where possible #906

Description

@bitshifter

I have a library which wraps SIMD types and it would be a nice feature if users were able to create const values with my wrapper types. There's currently no way of doing this in stable Rust.

It would be convenient if some constructor functions could be made const fn so we can create SIMD constants.

For example this is not currently possible:

const ONES : __m128 = unsafe { _mm_set1_ps(1.0) };

Internally functions like _mm_set1_ps are quite straight forward:

pub unsafe fn _mm_set1_ps(a: f32) -> __m128 {
  __m128(a, a, a, a)
}

__m128 is a repr(simd) tuple struct.

I would propose making all of the _mm_set* functions const fn and any other construction functions in stdarch for that matter.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions