Hi all,
I'm writing an emulator, and I'm wondering if there's any way to get a raw pointer to a static item at compile time. The code below errors:
pub static mut registers: [u32; 16] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
pub const reg32: *mut u32 = &mut registers as *mut _ as *mut u32;
I've tried const fn's, and it still doesn't work.
And before you ask, yes, this does have a noticeable impact on performance. Having a pointer that evaluates to a constant value at runtime makes things 20-30% faster, at least in my benchmarks. Using a raw pointer also avoids the overhead bounds checking -- all indexes into this array are masked (i.e. reg & 7) at some point.