Hey there!
I am using packed_simd_2 0.3.7 and latest version of rand
.
I have this program,
use packed_simd::f64x4;
use rand::Rng;
fn main() {
let mut rng = rand::thread_rng();
// This works fine!
println!("{:?}", f64x4::from_slice_aligned(&rng.gen::<[f64; 4]>()));
// This crashes the program
println!("{:?}", gen_random(&mut rng));
}
#[derive(Debug)]
pub struct Vec3(f64x4);
fn gen_random<R: Rng + ?Sized>(rng: &mut R) -> Vec3 {
Vec3(f64x4::from_slice_aligned(&rng.gen::<[f64; 4]>()))
}
Running this program crashes with,
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `2`,
right: `0`', /home/ishan/.cargo/registry/src/github.com-1ecc6299db9ec823/packed_simd_2-0.3.7/src/v256.rs:66:1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I had this code in my raytracer and it was working fine until maybe an year ago. I tried to run it again today and now it just crashes with this error. Changing from f64x4::from_slice_aligned
to f64x4::from_slice_unaligned
also "fixes" the problem.
There is this at the specified line in the stack trace,
impl_f!([f64; 4]: f64x4, m64x4 | f64 | test_v256 | x0, x1, x2, x3 |
From: i8x4, u8x4, i16x4, u16x4, i32x4, u32x4, f32x4 |
/// A 256-bit vector with 4 `f64` lanes.
);
This is the from_slice_aligned
function.
#[inline]
pub fn from_slice_aligned(slice: &[f64]) -> Self {
unsafe {
if !(slice.len() >= 4) {
::core::panicking::panic("assertion failed: slice.len() >= 4")
};
let target_ptr = slice.get_unchecked(0) as *const f64;
{
match (&target_ptr.align_offset(crate::mem::align_of::<Self>()), &0) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(
kind,
&*left_val,
&*right_val,
::core::option::Option::None,
);
}
}
}
};
Self::from_slice_aligned_unchecked(slice)
}
}
So, This is where it checks that things are aligned properly and is likely the assert that's failing here. I am not sure why/how it was working fine a year ago and only now has started acting up ? Does any one know how do I fix this problem?