pub struct Table2dU8xU8 { /* private fields */ }Expand description
A 2D SIMD lookup table for u8 × u8 coordinates, supporting up to 64K entries.
This table stores data in row-major order and uses SIMD gather operations for efficient parallel lookups. Each lookup takes a row index (0..num_rows) and column index (0..num_cols), both as u8, and returns the corresponding value.
§Index Calculation
For row r and column c, the flat index is: index = r * num_cols + c
Since row and column are both u8 (max 255), and num_cols is at most 256, the maximum index is 255 * 256 + 255 = 65535, which fits in u16.
§Example
// Create a 16x16 multiplication table
let mut data = vec![0u8; 256];
for r in 0..16u8 {
for c in 0..16u8 {
data[(r as usize) * 16 + (c as usize)] = r.wrapping_mul(c);
}
}
let table = Table2dU8xU8::from_flat(&data, 16);
// Look up multiple (row, col) pairs in parallel
let rows = u8x16::from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
let cols = u8x16::splat(5); // All looking up column 5
let result = table.lookup_one(rows, cols);
// result[i] = i * 5Implementations§
Source§impl Table2dU8xU8
impl Table2dU8xU8
Sourcepub fn from_flat(data: &[u8], num_cols: usize) -> Self
pub fn from_flat(data: &[u8], num_cols: usize) -> Self
Create a 2D table from a flat slice with the given number of columns.
The data is stored in row-major order: data[row * num_cols + col].
§Arguments
data: Flat slice of values, length must benum_rows * num_colsnum_cols: Number of columns per row (1..=256)
§Panics
- Panics if
num_colsis 0 or greater than 256 - Panics if
data.len()is not a multiple ofnum_cols - Panics if
data.len() > 65536
Sourcepub fn from_2d(matrix: &[&[u8]]) -> Self
pub fn from_2d(matrix: &[&[u8]]) -> Self
Create a 2D table from a 2D matrix (Vec of rows).
All rows must have the same length.
§Panics
- Panics if the matrix is empty
- Panics if rows have different lengths
- Panics if total size exceeds 65536
Sourcepub fn lookup_one(&self, rows: u8x16, cols: u8x16) -> u8x16
pub fn lookup_one(&self, rows: u8x16, cols: u8x16) -> u8x16
Look up 16 values in parallel using (row, col) coordinates.
Computes result[i] = table[rows[i]][cols[i]] for all 16 lanes.
§Arguments
rows: Row indices (0..num_rows) for each of the 16 lanescols: Column indices (0..num_cols) for each of the 16 lanes
§Safety
In debug mode, asserts that all indices are in bounds. In release mode, out-of-bounds access is undefined behavior.
Trait Implementations§
Source§impl Clone for Table2dU8xU8
impl Clone for Table2dU8xU8
Source§fn clone(&self) -> Table2dU8xU8
fn clone(&self) -> Table2dU8xU8
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more