2016-04-26 17:20:05 +02:00
|
|
|
/*
|
2014-03-07 16:37:09 +01:00
|
|
|
Copyright (C) 2013, 2014 Fredrik Johansson
|
|
|
|
|
2016-04-26 17:20:05 +02:00
|
|
|
This file is part of Arb.
|
|
|
|
|
|
|
|
Arb is free software: you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
|
|
|
by the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2014-03-07 16:37:09 +01:00
|
|
|
|
|
|
|
#include "fmpr.h"
|
|
|
|
|
|
|
|
#define MUL_STACK_ALLOC 40
|
|
|
|
#define MUL_TLS_ALLOC 1000
|
|
|
|
|
|
|
|
TLS_PREFIX mp_ptr __mul_tmp = NULL;
|
2015-11-05 18:03:08 +00:00
|
|
|
TLS_PREFIX slong __mul_alloc = 0;
|
2014-03-07 16:37:09 +01:00
|
|
|
|
|
|
|
void _mul_tmp_cleanup(void)
|
|
|
|
{
|
|
|
|
flint_free(__mul_tmp);
|
|
|
|
__mul_tmp = NULL;
|
|
|
|
__mul_alloc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MUL_TMP_ALLOC \
|
|
|
|
if (alloc <= MUL_STACK_ALLOC) \
|
|
|
|
{ \
|
|
|
|
tmp = tmp_stack; \
|
|
|
|
} \
|
|
|
|
else if (alloc <= MUL_TLS_ALLOC) \
|
|
|
|
{ \
|
|
|
|
if (__mul_alloc < alloc) \
|
|
|
|
{ \
|
|
|
|
if (__mul_alloc == 0) \
|
|
|
|
{ \
|
|
|
|
flint_register_cleanup_function(_mul_tmp_cleanup); \
|
|
|
|
} \
|
|
|
|
__mul_tmp = flint_realloc(__mul_tmp, sizeof(mp_limb_t) * alloc); \
|
|
|
|
__mul_alloc = alloc; \
|
|
|
|
} \
|
|
|
|
tmp = __mul_tmp; \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
tmp = flint_malloc(sizeof(mp_limb_t) * alloc); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MUL_TMP_FREE \
|
|
|
|
if (alloc > MUL_TLS_ALLOC) \
|
|
|
|
flint_free(tmp);
|
|
|
|
|
2015-11-10 13:41:43 +00:00
|
|
|
slong
|
2014-03-08 17:52:25 +01:00
|
|
|
_fmpr_mul_mpn(fmpr_t z,
|
2014-03-07 16:37:09 +01:00
|
|
|
mp_srcptr xman, mp_size_t xn, const fmpz_t xexp,
|
|
|
|
mp_srcptr yman, mp_size_t yn, const fmpz_t yexp,
|
2015-11-05 18:03:08 +00:00
|
|
|
int negative, slong prec, fmpr_rnd_t rnd)
|
2014-03-07 16:37:09 +01:00
|
|
|
{
|
2015-11-05 18:03:08 +00:00
|
|
|
slong zn, alloc, ret, shift;
|
2014-03-07 16:37:09 +01:00
|
|
|
mp_limb_t tmp_stack[MUL_STACK_ALLOC];
|
|
|
|
mp_ptr tmp;
|
|
|
|
|
|
|
|
zn = xn + yn;
|
|
|
|
alloc = zn;
|
|
|
|
|
|
|
|
MUL_TMP_ALLOC
|
|
|
|
|
|
|
|
if (yn == 1)
|
|
|
|
{
|
|
|
|
mp_limb_t cy = mpn_mul_1(tmp, xman, xn, yman[0]);
|
|
|
|
tmp[zn - 1] = cy;
|
|
|
|
zn = zn - (cy == 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mpn_mul(tmp, xman, xn, yman, yn);
|
|
|
|
zn = zn - (tmp[zn - 1] == 0);
|
|
|
|
}
|
|
|
|
|
2014-03-08 17:52:25 +01:00
|
|
|
ret = _fmpr_set_round_mpn(&shift, fmpr_manref(z), tmp, zn, negative, prec, rnd);
|
|
|
|
fmpz_add2_fmpz_si_inline(fmpr_expref(z), xexp, yexp, shift);
|
2014-03-07 16:37:09 +01:00
|
|
|
|
|
|
|
MUL_TMP_FREE
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|