cryprot_core/
transpose.rs

1//! Transpose bit-matrices fast.
2
3#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
4pub mod avx2;
5pub mod portable;
6
7#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
8cpufeatures::new!(target_feature_avx2, "avx2");
9
10/// Transpose a bit matrix.
11///
12/// # Panics
13/// If `rows % 128 != 0`
14/// If for `let cols = input.len() * 8 / rows`, `cols % 128 != 0`
15pub fn transpose_bitmatrix(input: &[u8], output: &mut [u8], rows: usize) {
16    #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
17    if target_feature_avx2::get() {
18        unsafe { avx2::transpose_bitmatrix(input, output, rows) }
19    } else {
20        portable::transpose_bitmatrix(input, output, rows);
21    }
22    #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
23    portable::transpose_bitmatrix(input, output, rows);
24}