forked from wolfSSL/wolfssl
sp_mod_word(): add unoptimized alternative if -U__GNUC__.
This commit is contained in:
@ -1477,7 +1477,6 @@ int sp_mulmod(sp_int* a, sp_int* b, sp_int* m, sp_int* r)
|
||||
*/
|
||||
static WC_INLINE int sp_mod_word(sp_int_word *w, sp_int_digit d) {
|
||||
sp_int_word x;
|
||||
int x_shift;
|
||||
if (*w == 0)
|
||||
return 0;
|
||||
if (d == 0)
|
||||
@ -1490,12 +1489,10 @@ static WC_INLINE int sp_mod_word(sp_int_word *w, sp_int_digit d) {
|
||||
* shifting so that x has one less leading zero, and then doing a
|
||||
* final comparison.
|
||||
*
|
||||
* textbook logic:
|
||||
*
|
||||
* while (x <= w/2)
|
||||
* x <<= 1;
|
||||
*/
|
||||
x_shift = ((int)__builtin_clzll(d) + (SP_WORD_SIZE - 1));
|
||||
#ifdef __GNUC__
|
||||
{
|
||||
int x_shift = ((int)__builtin_clzll(d) + (SP_WORD_SIZE - 1));
|
||||
if ((*w >> SP_WORD_SIZE) == 0)
|
||||
x_shift -=
|
||||
#if SP_WORD_SIZE == 64
|
||||
@ -1519,14 +1516,23 @@ static WC_INLINE int sp_mod_word(sp_int_word *w, sp_int_digit d) {
|
||||
if (x_shift < 0)
|
||||
x_shift = 0;
|
||||
x = (sp_int_word)d << x_shift;
|
||||
}
|
||||
if (x <= (*w>>1))
|
||||
x <<= 1;
|
||||
#else /* ! __GNUC__ */
|
||||
/* textbook logic */
|
||||
|
||||
x = (sp_int_word)d;
|
||||
while (x <= (*w>>1))
|
||||
x <<= 1;
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
while (*w >= (sp_int_word)d) {
|
||||
if (*w >= x)
|
||||
*w -= x;
|
||||
x >>= 1;
|
||||
}
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif /* WOLFSSL_SP_MOD_WORD_RP */
|
||||
|
Reference in New Issue
Block a user