| 1 | // Copyright 2018 Brian Smith. |
| 2 | // |
| 3 | // Permission to use, copy, modify, and/or distribute this software for any |
| 4 | // purpose with or without fee is hereby granted, provided that the above |
| 5 | // copyright notice and this permission notice appear in all copies. |
| 6 | // |
| 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES |
| 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY |
| 10 | // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 | // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 | |
| 15 | #[cfg (target_arch = "x86" )] |
| 16 | pub fn shift_full_blocks<const BLOCK_LEN: usize>( |
| 17 | in_out: super::overlapping::Overlapping<'_, u8>, |
| 18 | mut transform: impl FnMut(&[u8; BLOCK_LEN]) -> [u8; BLOCK_LEN], |
| 19 | ) { |
| 20 | let (in_out, src) = in_out.into_slice_src_mut(); |
| 21 | let in_out_len = in_out[src.clone()].len(); |
| 22 | |
| 23 | for i in (0..in_out_len).step_by(BLOCK_LEN) { |
| 24 | let block = { |
| 25 | let input = |
| 26 | <&[u8; BLOCK_LEN]>::try_from(&in_out[(src.start + i)..][..BLOCK_LEN]).unwrap(); |
| 27 | transform(input) |
| 28 | }; |
| 29 | let output = <&mut [u8; BLOCK_LEN]>::try_from(&mut in_out[i..][..BLOCK_LEN]).unwrap(); |
| 30 | *output = block; |
| 31 | } |
| 32 | } |
| 33 | |