Handling of THRESHOLDs
Torbjorn Granlund
tg at gmplib.org
Sun Nov 22 16:20:06 CET 2009
We choose algorithm in GMP with constructs like
if (BELOW_THRESHOLD (MUL_TOOM22_THRESHOLD))
{
mul_basecase (...);
}
else if (BELOW_THRESHOLD (MUL_TOOM33_THRESHOLD))
{
mul_toom22 (...);
}
else
{
mul_toom33 (...);
}
If for some reason, mul_toom22 is never better than mul_basecase and
mul_toom33, we use a trick:
#if MUL_TOOM22_THRESHOLD >= MUL_TOOM33_THRESHOLD
#define MUL_TOOM22_THRESHOLD MUL_TOOM33_THRESHOLD
#define MUL_TOOM33_THRESHOLD 0
#endif
When this happens, MUL_TOOM22_THRESHOLD is actually the threshold beteen
mul_basecase and mul_toom33... A bit confusing. (MUL_TOOM33_THRESHOLD
is made into a dummy threshold that allows the compiler to remove the
test and the call to mul_toom22.)
I am contemplating if we should rename these thresholds to make things
slightly more readable. Now FOO_THRESHOLD-1 is the largest operands for
which algorithm foo is used. The change would be to let FOO_THRESHOLD
be the smallest operands for which foo is used.
The code above would become
if (BELOW_THRESHOLD (MUL_BASECASE_THRESHOLD))
{
mul_basecase (...);
}
else if (BELOW_THRESHOLD (MUL_TOOM22_THRESHOLD))
{
mul_toom22 (...);
}
else
{
mul_toom33 (...);
}
When we want to switch off mul_toom22, it is MUL_TOOM22_THRESHOLD we
need to knock to 0. I also think moving the threshold name closer to
the routine name makes things more readable.
Opinions? Surely there is some drawback...?
--
Torbjörn
More information about the gmp-devel
mailing list