Request: mark all integer platform intrinsics as `const`
Lokathor opened this issue · 3 comments
The platform intrinsics for floating point suffer the standard floating point problems of not being fully deterministic at all times, which is a requirement for const.
However, the platform intrinsics for integer data do not suffer these problems at all. They are plain integer math operations and you can deterministically know exactly what bit pattern you'll get out for any bit pattern you send in. This means that they are eligible for becoming const
. At compile time we could even emulate the operations if necessary.
So, we should make all of these const
.
PS: yes, obviously it's not as easy as flipping a switch, i'm not an idiot. This is a long term goal that requires quite a bit of compiler support work to be built up as part of the ongoing const project, etc etc etc
If you want the intrinsics to use them in const fns,they already do work:
#![feature(core_intrinsics)]
const fn hello()->u32{
// The intrinsic is not a const fn,yet it can be called inside a const fn
// pub fn saturating_sub<T>(a: T, b: T) -> T;
std::intrinsics::saturating_sub::<u32>(0,10)
}
const HI:u32=hello();
fn main(){
dbg!(HI);
}
I agree that they should be marked const to avoid confusion though.
I believe that's considered a bug, based on what I read in another issue.
However, either way, I was meaning the arch intrinsics, eg, SSE2 and similar.