Skip to content

Commit f8b2eab

Browse files
authored
blake2: add Cargo feature to optimize for code size. (#440)
1 parent 13dcab4 commit f8b2eab

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

blake2/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ reset = [] # Enable reset functionality
2525
simd = []
2626
simd_opt = ["simd"]
2727
simd_asm = ["simd_opt"]
28+
size_opt = [] # Optimize for code size. Removes some `inline(always)`

blake2/src/macros.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,29 +107,29 @@ macro_rules! blake2_impl {
107107
fn compress(&mut self, block: &Block<Self>, f0: $word, f1: $word) {
108108
use $crate::consts::SIGMA;
109109

110-
#[inline(always)]
110+
#[cfg_attr(not(feature = "size_opt"), inline(always))]
111111
fn quarter_round(v: &mut [$vec; 4], rd: u32, rb: u32, m: $vec) {
112112
v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le());
113113
v[3] = (v[3] ^ v[0]).rotate_right_const(rd);
114114
v[2] = v[2].wrapping_add(v[3]);
115115
v[1] = (v[1] ^ v[2]).rotate_right_const(rb);
116116
}
117117

118-
#[inline(always)]
118+
#[cfg_attr(not(feature = "size_opt"), inline(always))]
119119
fn shuffle(v: &mut [$vec; 4]) {
120120
v[1] = v[1].shuffle_left_1();
121121
v[2] = v[2].shuffle_left_2();
122122
v[3] = v[3].shuffle_left_3();
123123
}
124124

125-
#[inline(always)]
125+
#[cfg_attr(not(feature = "size_opt"), inline(always))]
126126
fn unshuffle(v: &mut [$vec; 4]) {
127127
v[1] = v[1].shuffle_right_1();
128128
v[2] = v[2].shuffle_right_2();
129129
v[3] = v[3].shuffle_right_3();
130130
}
131131

132-
#[inline(always)]
132+
#[cfg_attr(not(feature = "size_opt"), inline(always))]
133133
fn round(v: &mut [$vec; 4], m: &[$word; 16], s: &[usize; 16]) {
134134
quarter_round(v, $R1, $R2, $vec::gather(m, s[0], s[2], s[4], s[6]));
135135
quarter_round(v, $R3, $R4, $vec::gather(m, s[1], s[3], s[5], s[7]));

0 commit comments

Comments
 (0)