Make constructors `const fn` where possible
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 694
- Forks
- 336
- Avg merge
- 5d 14h
- Merged PRs (30d)
- 9
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the _mm_set* constructors and the __m128 repr(simd) tuple struct in stdarch. Check which construction functions can be declared const fn, then verify that the issue's const ONES example can create a SIMD constant on stable Rust. Done means the applicable constructors support const evaluation without changing unrelated APIs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100