Skip to content

Commit

Permalink
ec_mult.h: harden booth_encode().
Browse files Browse the repository at this point in the history
This is a complement to 553ea28. The
information about 'wval >> sz' being a single bit is formally
deducible, so the compiler could emit the 'select' llvm bytecode.
It wasn't observed though, not then or now.
  • Loading branch information
dot-asm committed Jan 24, 2023
1 parent 86faad5 commit 73604c8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ec_mult.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ static limb_t get_wval_limb(const byte *d, size_t off, size_t bits)
static limb_t booth_encode(limb_t wval, size_t sz)
{
limb_t mask = 0 - (wval >> sz); /* "sign" bit -> mask */
launder(mask);

wval = (wval + 1) >> 1;
wval = (wval & ~mask) | ((0-wval) & mask);
wval = (wval ^ mask) - mask;

/* &0x1f, but <=0x10, is index in table, rest is extended "sign" bit */
return wval;
Expand Down

0 comments on commit 73604c8

Please sign in to comment.