Skip to content

There's seemingly no way to construct a __m128i in a const fn #403

@shepmaster

Description

@shepmaster

My ideal case would be to take a &[u8] and "fill up" a __m128:

let needle: __m128i = bytes.collect(); // Takes the first 16 bytes, zero-initialized otherwise

// or

let mut needle = __m128i::default(); // zero-initialize
needle.extend(bytes); // Takes the first 16 bytes

However, none of the "nice" traits are implemented for these types, and I've gotten the feeling that is no accident. Basically, I can use an intrinsic function to set it (e.g. _mm_setzero_si128), or I can convert from u8x16 and friends.

The intrinsics are not const, so they cannot be used in a const fn context.

The closest I could find was

u8x16::new(
    x0, x1, x2, x3, x4, x5, x6, x7,
    x8, x9, x10, x11, x12, x13, x14, x15,
).into_bits()

but into_bits is likewise not const.

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