tract_linalg/generic/
lut.rs

1use crate::frame::lut::LutKer;
2
3#[derive(Clone, Debug, Hash)]
4pub struct GenericLut8;
5
6impl LutKer for GenericLut8 {
7    fn name() -> &'static str {
8        "generic"
9    }
10
11    fn input_alignment_bytes() -> usize {
12        1
13    }
14
15    fn table_alignment_bytes() -> usize {
16        1
17    }
18
19    fn n() -> usize {
20        8
21    }
22
23    unsafe fn run(buf: *mut u8, len: usize, table: *const u8) {
24        debug_assert!(len % Self::n() == 0);
25        debug_assert!(buf as usize % Self::input_alignment_bytes() == 0);
26        debug_assert!(table as usize % Self::table_alignment_bytes() == 0);
27        for i in 0..((len / 8) as isize) {
28            let ptr = buf.offset(8 * i);
29            *ptr.offset(0) = *table.offset(*ptr.offset(0) as isize);
30            *ptr.offset(1) = *table.offset(*ptr.offset(1) as isize);
31            *ptr.offset(2) = *table.offset(*ptr.offset(2) as isize);
32            *ptr.offset(3) = *table.offset(*ptr.offset(3) as isize);
33            *ptr.offset(4) = *table.offset(*ptr.offset(4) as isize);
34            *ptr.offset(5) = *table.offset(*ptr.offset(5) as isize);
35            *ptr.offset(6) = *table.offset(*ptr.offset(6) as isize);
36            *ptr.offset(7) = *table.offset(*ptr.offset(7) as isize);
37        }
38    }
39}
40
41#[cfg(test)]
42#[macro_use]
43pub mod test {
44    lut_frame_tests!(true, crate::generic::GenericLut8);
45}