Skip to content

Commit

Permalink
Use compiler intrinsics where supported
Browse files Browse the repository at this point in the history
This improves the performance of certain functions that use it.
  • Loading branch information
AZero13 committed Dec 19, 2023
1 parent 8241b9c commit 0712677
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions xmss_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,17 +467,18 @@ static void bds_round(bds_state *state, const unsigned long leaf_idx, const unsi
memcpy(node_addr, addr, 12);
setType(node_addr, 2);

for (i = 0; i < h; i++) {
if (! ((leaf_idx >> i) & 1)) {
tau = i;
break;
if (tau > 0) {
if (leaf_idx != ~0) {
tau = __builtin_ctzl(~leaf_idx);
if (tau > h)
tau = h;
}
}

if (tau > 0) {
memcpy(buf, state->auth + (tau-1) * n, n);
// we need to do this before refreshing state->keep to prevent overwriting
memcpy(buf + n, state->keep + ((tau-1) >> 1) * n, n);
if (tau > 0) {
memcpy(buf, state->auth + (tau - 1) * n, n);
// we need to do this before refreshing state->keep to prevent overwriting
memcpy(buf + n, state->keep + ((tau - 1) >> 1) * n, n);
}
}
if (!((leaf_idx >> (tau + 1)) & 1) && (tau < h - 1)) {
memcpy(state->keep + (tau >> 1)*n, state->auth + tau*n, n);
Expand Down

0 comments on commit 0712677

Please sign in to comment.