|
37 | 37 |
|
38 | 38 | /* enable it to check the multiplication result */ |
39 | 39 | //#define USE_MUL_CHECK |
| 40 | +#ifdef CONFIG_BIGNUM |
40 | 41 | /* enable it to use FFT/NTT multiplication */ |
41 | 42 | #define USE_FFT_MUL |
42 | 43 | /* enable decimal floating point support */ |
43 | 44 | #define USE_BF_DEC |
| 45 | +#endif |
44 | 46 |
|
45 | 47 | //#define inline __attribute__((always_inline)) |
46 | 48 |
|
@@ -164,6 +166,21 @@ static inline slimb_t sat_add(slimb_t a, slimb_t b) |
164 | 166 | return r; |
165 | 167 | } |
166 | 168 |
|
| 169 | +static inline __maybe_unused limb_t shrd(limb_t low, limb_t high, long shift) |
| 170 | +{ |
| 171 | + if (shift != 0) |
| 172 | + low = (low >> shift) | (high << (LIMB_BITS - shift)); |
| 173 | + return low; |
| 174 | +} |
| 175 | + |
| 176 | +static inline __maybe_unused limb_t shld(limb_t a1, limb_t a0, long shift) |
| 177 | +{ |
| 178 | + if (shift != 0) |
| 179 | + return (a1 << shift) | (a0 >> (LIMB_BITS - shift)); |
| 180 | + else |
| 181 | + return a1; |
| 182 | +} |
| 183 | + |
167 | 184 | #define malloc(s) malloc_is_forbidden(s) |
168 | 185 | #define free(p) free_is_forbidden(p) |
169 | 186 | #define realloc(p, s) realloc_is_forbidden(p, s) |
@@ -236,7 +253,7 @@ int bf_set_ui(bf_t *r, uint64_t a) |
236 | 253 | a1 = a >> 32; |
237 | 254 | shift = clz(a1); |
238 | 255 | r->tab[0] = a0 << shift; |
239 | | - r->tab[1] = (a1 << shift) | (a0 >> (LIMB_BITS - shift)); |
| 256 | + r->tab[1] = shld(a1, a0, shift); |
240 | 257 | r->expn = 2 * LIMB_BITS - shift; |
241 | 258 | } |
242 | 259 | #endif |
@@ -1585,7 +1602,9 @@ int bf_mul(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, |
1585 | 1602 | r = &tmp; |
1586 | 1603 | } |
1587 | 1604 | if (bf_resize(r, a_len + b_len)) { |
| 1605 | +#ifdef USE_FFT_MUL |
1588 | 1606 | fail: |
| 1607 | +#endif |
1589 | 1608 | bf_set_nan(r); |
1590 | 1609 | ret = BF_ST_MEM_ERROR; |
1591 | 1610 | goto done; |
@@ -2282,11 +2301,14 @@ static int bf_pow_ui_ui(bf_t *r, limb_t a1, limb_t b, |
2282 | 2301 | bf_t a; |
2283 | 2302 | int ret; |
2284 | 2303 |
|
| 2304 | +#ifdef USE_BF_DEC |
2285 | 2305 | if (a1 == 10 && b <= LIMB_DIGITS) { |
2286 | 2306 | /* use precomputed powers. We do not round at this point |
2287 | 2307 | because we expect the caller to do it */ |
2288 | 2308 | ret = bf_set_ui(r, mp_pow_dec[b]); |
2289 | | - } else { |
| 2309 | + } else |
| 2310 | +#endif |
| 2311 | + { |
2290 | 2312 | bf_init(r->ctx, &a); |
2291 | 2313 | ret = bf_set_ui(&a, a1); |
2292 | 2314 | ret |= bf_pow_ui(r, &a, b, prec, flags); |
@@ -5392,21 +5414,6 @@ int bf_acos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags) |
5392 | 5414 |
|
5393 | 5415 | #endif /* LIMB_BITS != 64 */ |
5394 | 5416 |
|
5395 | | -static inline __maybe_unused limb_t shrd(limb_t low, limb_t high, long shift) |
5396 | | -{ |
5397 | | - if (shift != 0) |
5398 | | - low = (low >> shift) | (high << (LIMB_BITS - shift)); |
5399 | | - return low; |
5400 | | -} |
5401 | | - |
5402 | | -static inline __maybe_unused limb_t shld(limb_t a1, limb_t a0, long shift) |
5403 | | -{ |
5404 | | - if (shift != 0) |
5405 | | - return (a1 << shift) | (a0 >> (LIMB_BITS - shift)); |
5406 | | - else |
5407 | | - return a1; |
5408 | | -} |
5409 | | - |
5410 | 5417 | #if LIMB_DIGITS == 19 |
5411 | 5418 |
|
5412 | 5419 | /* WARNING: hardcoded for b = 1e19. It is assumed that: |
|
0 commit comments