#include <gmp.h>
#include "profiler.h"
#include "ulong_extras.h"
#include "fmpz.h"
#define ntests 2000
void
fmpz_mul_ui_old(fmpz_t f, const fmpz_t g, ulong x)
{
fmpz c2 = *g;
if (!COEFF_IS_MPZ(c2))
{
ulong th, tl;
ulong uc2 = FLINT_ABS(c2);
umul_ppmm(th, tl, uc2, x);
if (c2 >= 0)
fmpz_set_uiui(f, th, tl);
else
fmpz_neg_uiui(f, th, tl);
}
else
{
if (x == 0)
fmpz_zero(f);
else
{
mpz_ptr z = _fmpz_promote(f);
mpz_mul_ui(z, COEFF_TO_PTR(c2), x);
}
}
}
void
sample_new(void * arg, ulong count)
{
fmpz_t res, a;
ulong b;
ulong ix, jx;
int bits = *((int *) arg);
FLINT_TEST_INIT(state);
fmpz_init(res);
fmpz_init(a);
for (ix = 0; ix < count; ix++)
{
fmpz_randtest(a, state, bits + 20);
b = n_randbits(state, bits);
prof_start();
for (jx = 0; jx < ntests; jx++)
fmpz_mul_ui(res, a, b);
prof_stop();
}
fmpz_clear(res);
fmpz_clear(a);
FLINT_TEST_CLEAR(state);
}
void
sample_old(void * arg, ulong count)
{
fmpz_t res, a;
ulong b;
ulong ix, jx;
int bits = *((int *) arg);
FLINT_TEST_INIT(state);
fmpz_init(res);
fmpz_init(a);
for (ix = 0; ix < count; ix++)
{
fmpz_randtest(a, state, bits + 20);
b = n_randbits(state, bits);
prof_start();
for (jx = 0; jx < ntests; jx++)
fmpz_mul_ui_old(res, a, b);
prof_stop();
}
fmpz_clear(res);
fmpz_clear(a);
FLINT_TEST_CLEAR(state);
}
int
main(void)
{
double minnew, maxnew, minold, maxold;
int bits;
for (bits = 1; bits <= 64; bits += 3)
{
prof_repeat(&minnew, &maxnew, sample_new, &bits);
prof_repeat(&minold, &maxold, sample_old, &bits);
flint_printf("%d bits: min %.2fx, max %.2fx\n",
bits, minold / minnew, maxold / maxnew);
}
return 0;
}