Skip to content

Commit

Permalink
sha2(wasm): optimize out cast_ms in sha512
Browse files Browse the repository at this point in the history
  • Loading branch information
max-te committed Nov 1, 2024
1 parent 601ca6e commit 21b1597
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions sha2/src/sha512/wasm32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ unsafe fn rounds_0_63(current_state: &mut State, x: &mut [v128; 8], ms: &mut Msg
let y = sha512_update_x(x, k64);

{
let ms = cast_ms(ms);
sha_round(current_state, ms[2 * j]);
sha_round(current_state, ms[2 * j + 1]);
let ms = ms[j];
sha_round(current_state, u64x2_extract_lane::<0>(ms));
sha_round(current_state, u64x2_extract_lane::<1>(ms));
}

ms[j] = y;
Expand All @@ -62,9 +62,10 @@ unsafe fn rounds_0_63(current_state: &mut State, x: &mut [v128; 8], ms: &mut Msg

#[inline(always)]
fn rounds_64_79(current_state: &mut State, ms: &MsgSchedule) {
let ms = cast_ms(ms);
for i in 64..80 {
sha_round(current_state, ms[i & 0xf]);
for j in 0..8 {
let ms = ms[j];
sha_round(current_state, u64x2_extract_lane::<0>(ms));
sha_round(current_state, u64x2_extract_lane::<1>(ms));
}
}

Expand Down Expand Up @@ -162,11 +163,6 @@ unsafe fn sha512_update_x(x: &mut [v128; 8], k64: v128) -> v128 {
i64x2_add(x[7], k64)
}

#[inline(always)]
fn cast_ms(ms: &MsgSchedule) -> &[u64; SHA512_BLOCK_WORDS_NUM] {
unsafe { &*(ms.as_ptr().cast()) }
}

type State = [u64; SHA512_HASH_WORDS_NUM];
type MsgSchedule = [v128; SHA512_BLOCK_WORDS_NUM / 2];

Expand Down

0 comments on commit 21b1597

Please sign in to comment.