blake2/simd/
simd_opt.rs

1// Copyright 2015 blake2-rfc Developers
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8#[allow(unused_macros)]
9#[cfg(feature = "simd")]
10macro_rules! transmute_shuffle {
11    ($tmp:ident, $shuffle:ident, $vec:expr, $idx_n:expr, $idx:expr) => {
12        unsafe {
13            use crate::simd::simdint::$shuffle;
14            use crate::simd::simdty::$tmp;
15            use core::mem::transmute;
16
17            const IDX: [u32; $idx_n] = $idx;
18            let tmp_i: $tmp = transmute($vec);
19            let tmp_o: $tmp = $shuffle(tmp_i, tmp_i, IDX);
20            transmute(tmp_o)
21        }
22    };
23}
24
25#[cfg(feature = "simd")]
26pub mod u32x4;
27#[cfg(feature = "simd")]
28pub mod u64x4;
29
30#[cfg(not(feature = "simd"))]
31macro_rules! simd_opt {
32    ($vec:ident) => {
33        pub mod $vec {
34            use crate::simd::simdty::$vec;
35
36            #[inline(always)]
37            pub fn rotate_right_const(vec: $vec, n: u32) -> $vec {
38                $vec::new(
39                    vec.0.rotate_right(n),
40                    vec.1.rotate_right(n),
41                    vec.2.rotate_right(n),
42                    vec.3.rotate_right(n),
43                )
44            }
45        }
46    };
47}
48
49#[cfg(not(feature = "simd"))]
50simd_opt!(u32x4);
51#[cfg(not(feature = "simd"))]
52simd_opt!(u64x4);