Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Const-generic bounds should allow simple casts #84526

Closed
aloucks opened this issue Apr 24, 2021 · 3 comments
Closed

Const-generic bounds should allow simple casts #84526

aloucks opened this issue Apr 24, 2021 · 3 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. F-generic_const_exprs `#![feature(generic_const_exprs)]`

Comments

@aloucks
Copy link
Contributor

aloucks commented Apr 24, 2021

The as_usize wrapper function in the example below shouldn't be required.

@oli-obk
#83278 (comment)

#![feature(const_generics)]
#![feature(const_evaluatable_checked)]

use std::arch::x86_64::*;

pub const fn _MM_SHUFFLE(fp3: u32, fp2: u32, fp1: u32, fp0: u32) -> i32 {
    ((fp3 << 6) | (fp2 << 4) | (fp1 << 2) | fp0) as i32
}

pub const fn as_usize(a: i32) -> usize {
    a as usize
}

pub fn swizzle<const X: u32, const Y: u32, const Z: u32, const W: u32>(v: __m128) -> __m128
where [(); as_usize(_MM_SHUFFLE(W, Z, Y, X))]:
{
    unsafe {
        _mm_shuffle_ps(v, v, _MM_SHUFFLE(W, Z, Y, X))
    }
}
@jonas-schievink jonas-schievink added C-feature-request Category: A feature request, i.e: not implemented / a PR. F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Apr 24, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Apr 24, 2021

cc @rust-lang/project-const-generics

Casts are infallible and could be allowed. I think they are sufficiently common for us to allow them

@nikomatsakis
Copy link
Contributor

That makes sense to me

@memoryruins
Copy link
Contributor

fn as_usize is no longer needed and the where clause can be written as where [(); _MM_SHUFFLE(W, Z, Y, X) as usize]:. Presumably fixed by #86130

playground
1.55.0-nightly 2021-06-21 406d4a9cc3b9601cf98a

@oli-obk oli-obk closed this as completed Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. F-generic_const_exprs `#![feature(generic_const_exprs)]`
Projects
None yet
Development

No branches or pull requests

5 participants