Skip to content

Commit fa757d9

Browse files
committed
optimize poly_finalize
LLVM isn't smart enough to change the array version to a cmovcc and instead spills to memory
1 parent 1dceeb1 commit fa757d9

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

hs1-siv/src/hash.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ const fn poly_step(a: u64, b: u64, k: u64) -> u64 {
175175
#[inline(always)]
176176
const fn poly_finalize(a: u64) -> u64 {
177177
let a = (a & mask(61)).wrapping_add(a >> 61);
178-
[a, 0][(a == mask(61)) as usize]
178+
let c = (a != mask(61)) as u64 * u64::MAX;
179+
a & c
179180
}
180181

181182
#[inline(always)]
@@ -189,3 +190,14 @@ where
189190
v.iter_mut().zip(it).for_each(|(w, r)| *w = r);
190191
v
191192
}
193+
194+
#[cfg(test)]
195+
mod test {
196+
#[test]
197+
fn poly_finalize_mod_2_61() {
198+
assert_eq!(super::poly_finalize(0), 0);
199+
assert_eq!(super::poly_finalize((1 << 61) - 2), (1 << 61) - 2);
200+
assert_eq!(super::poly_finalize((1 << 61) - 1), 0);
201+
assert_eq!(super::poly_finalize(1 << 61), 1);
202+
}
203+
}

0 commit comments

Comments
 (0)