enable msvc build

This commit is contained in:
wgh136
2024-04-18 10:44:35 +08:00
parent 2675a36960
commit 6ec3c33ed7
2 changed files with 296 additions and 305 deletions

View File

@@ -37,12 +37,10 @@
/* enable it to check the multiplication result */
//#define USE_MUL_CHECK
#ifdef CONFIG_BIGNUM
/* enable it to use FFT/NTT multiplication */
#define USE_FFT_MUL
/* enable decimal floating point support */
#define USE_BF_DEC
#endif
//#define inline __attribute__((always_inline))
@@ -136,7 +134,6 @@ static inline slimb_t ceil_div(slimb_t a, slimb_t b)
return a / b;
}
#ifdef USE_BF_DEC
/* b must be >= 1 */
static inline slimb_t floor_div(slimb_t a, slimb_t b)
{
@@ -146,7 +143,6 @@ static inline slimb_t floor_div(slimb_t a, slimb_t b)
return (a - b + 1) / b;
}
}
#endif
/* return r = a modulo b (0 <= r <= b - 1. b must be >= 1 */
static inline limb_t smod(slimb_t a, slimb_t b)
@@ -168,21 +164,6 @@ static inline slimb_t sat_add(slimb_t a, slimb_t b)
return r;
}
static inline __maybe_unused limb_t shrd(limb_t low, limb_t high, long shift)
{
if (shift != 0)
low = (low >> shift) | (high << (LIMB_BITS - shift));
return low;
}
static inline __maybe_unused limb_t shld(limb_t a1, limb_t a0, long shift)
{
if (shift != 0)
return (a1 << shift) | (a0 >> (LIMB_BITS - shift));
else
return a1;
}
#define malloc(s) malloc_is_forbidden(s)
#define free(p) free_is_forbidden(p)
#define realloc(p, s) realloc_is_forbidden(p, s)
@@ -255,7 +236,7 @@ int bf_set_ui(bf_t *r, uint64_t a)
a1 = a >> 32;
shift = clz(a1);
r->tab[0] = a0 << shift;
r->tab[1] = shld(a1, a0, shift);
r->tab[1] = (a1 << shift) | (a0 >> (LIMB_BITS - shift));
r->expn = 2 * LIMB_BITS - shift;
}
#endif
@@ -311,7 +292,7 @@ int bf_set(bf_t *r, const bf_t *a)
}
r->sign = a->sign;
r->expn = a->expn;
memcpy_no_ub(r->tab, a->tab, a->len * sizeof(limb_t));
memcpy(r->tab, a->tab, a->len * sizeof(limb_t));
return 0;
}
@@ -1604,9 +1585,7 @@ int bf_mul(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
r = &tmp;
}
if (bf_resize(r, a_len + b_len)) {
#ifdef USE_FFT_MUL
fail:
#endif
bf_set_nan(r);
ret = BF_ST_MEM_ERROR;
goto done;
@@ -2303,14 +2282,11 @@ static int bf_pow_ui_ui(bf_t *r, limb_t a1, limb_t b,
bf_t a;
int ret;
#ifdef USE_BF_DEC
if (a1 == 10 && b <= LIMB_DIGITS) {
/* use precomputed powers. We do not round at this point
because we expect the caller to do it */
ret = bf_set_ui(r, mp_pow_dec[b]);
} else
#endif
{
} else {
bf_init(r->ctx, &a);
ret = bf_set_ui(&a, a1);
ret |= bf_pow_ui(r, &a, b, prec, flags);
@@ -2899,7 +2875,7 @@ static int strcasestart(const char *str, const char *val, const char **ptr)
return 1;
}
int bf_atof_internal(bf_t *r, slimb_t *pexponent,
static int bf_atof_internal(bf_t *r, slimb_t *pexponent,
const char *str, const char **pnext, int radix,
limb_t prec, bf_flags_t flags, BOOL is_dec)
{
@@ -5416,6 +5392,21 @@ int bf_acos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
#endif /* LIMB_BITS != 64 */
static inline __maybe_unused limb_t shrd(limb_t low, limb_t high, long shift)
{
if (shift != 0)
low = (low >> shift) | (high << (LIMB_BITS - shift));
return low;
}
static inline __maybe_unused limb_t shld(limb_t a1, limb_t a0, long shift)
{
if (shift != 0)
return (a1 << shift) | (a0 >> (LIMB_BITS - shift));
else
return a1;
}
#if LIMB_DIGITS == 19
/* WARNING: hardcoded for b = 1e19. It is assumed that: