polydat_core/numeric/
register.rs1use crate::ast::Bits128;
10
11pub fn gather_f32(v: &[f32], offset: u64) -> Bits128 {
13 let o = offset as usize;
14 if o + 4 > v.len() {
15 panic!(
16 "reg_gather_f32: window [{o}, {}) exceeds slice length {}",
17 o + 4,
18 v.len()
19 );
20 }
21 Bits128::from_lanes_f32([v[o], v[o + 1], v[o + 2], v[o + 3]])
22}
23
24pub fn to_reg_f32(v: &[f32]) -> Bits128 {
26 if v.len() != 4 {
27 panic!(
28 "vec_to_reg_f32: expected exactly 4 elements, got {}",
29 v.len()
30 );
31 }
32 Bits128::from_lanes_f32([v[0], v[1], v[2], v[3]])
33}
34
35pub fn lane_f32(r: Bits128, i: u64) -> f64 {
37 if i >= 4 {
38 panic!("reg_lane_f32: lane {i} out of range 0..4");
39 }
40 r.lanes_f32()[i as usize] as f64
41}
42
43pub fn with_lane_f32(r: Bits128, i: u64, v: f64) -> Bits128 {
45 if i >= 4 {
46 panic!("reg_with_lane_f32: lane {i} out of range 0..4");
47 }
48 let mut out = r.lanes_f32();
49 out[i as usize] = v as f32;
50 Bits128::from_lanes_f32(out)
51}
52
53pub fn lane_i16(r: Bits128, i: u64) -> i16 {
55 if i >= 8 {
56 panic!("reg_lane_i16: lane {i} out of range 0..8");
57 }
58 r.lanes_i16()[i as usize]
59}
60
61pub fn lane_i64(r: Bits128, i: u64) -> i64 {
63 if i >= 2 {
64 panic!("reg_lane_i64: lane {i} out of range 0..2");
65 }
66 r.lanes_i64()[i as usize]
67}
68
69pub fn mul_i8(a: Bits128, b: Bits128) -> Bits128 {
71 let (a, b) = (a.lanes_i8(), b.lanes_i8());
72 Bits128::from_lanes_i8(core::array::from_fn(|i| a[i].wrapping_mul(b[i])))
73}