changed: small optimization in Big::ExpSurrounding0() and Big::LnSurrounding1()
the remainder from a division '%' was changed with a bitwise And operation '&' ((i % 5) == 0) was changed to: ((i & 3) == 0) - it means ((i % 4) == 0) now the test if performed after 4 iterations (early were after 5 iterations) we can do that when the divisor is a power of 2 changed: optimization in Factorial() we're testing WasStopSignal() only after a few iterations it's faster now about 4 times on GCC 4.3.3 (when stop object is provided to the factorial) git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@161 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
74553109a5
commit
019a902fed
|
@ -1902,13 +1902,16 @@ namespace ttmath
|
||||||
|
|
||||||
while( !carry && multipler<maxvalue )
|
while( !carry && multipler<maxvalue )
|
||||||
{
|
{
|
||||||
// !! the test here we don't have to make in all iterations (performance)
|
if( stop && (multipler & 127)==0 ) // it means 'stop && (multipler % 128)==0'
|
||||||
if( stop && stop->WasStopSignal() )
|
|
||||||
{
|
{
|
||||||
if( err )
|
// after each 128 iterations we make a test
|
||||||
*err = err_interrupt;
|
if( stop->WasStopSignal() )
|
||||||
|
{
|
||||||
|
if( err )
|
||||||
|
*err = err_interrupt;
|
||||||
|
|
||||||
return 2;
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
++multipler;
|
++multipler;
|
||||||
|
@ -1932,20 +1935,25 @@ namespace ttmath
|
||||||
|
|
||||||
one.SetOne();
|
one.SetOne();
|
||||||
uint carry = 0;
|
uint carry = 0;
|
||||||
|
uint iter = 1; // only for testing the stop object
|
||||||
|
|
||||||
while( !carry && multipler < x )
|
while( !carry && multipler < x )
|
||||||
{
|
{
|
||||||
// !! the test here we don't have to make in all iterations (performance)
|
if( stop && (iter & 31)==0 ) // it means 'stop && (iter % 32)==0'
|
||||||
if( stop && stop->WasStopSignal() )
|
|
||||||
{
|
{
|
||||||
if( err )
|
// after each 32 iterations we make a test
|
||||||
*err = err_interrupt;
|
if( stop->WasStopSignal() )
|
||||||
|
{
|
||||||
|
if( err )
|
||||||
|
*err = err_interrupt;
|
||||||
|
|
||||||
return 2;
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
carry += multipler.Add(one);
|
carry += multipler.Add(one);
|
||||||
carry += result.Mul(multipler);
|
carry += result.Mul(multipler);
|
||||||
|
++iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( err )
|
if( err )
|
||||||
|
|
|
@ -1399,19 +1399,17 @@ public:
|
||||||
denominator.SetOne();
|
denominator.SetOne();
|
||||||
denominator_i.SetOne();
|
denominator_i.SetOne();
|
||||||
|
|
||||||
// every 'step_test' times we make a test
|
|
||||||
const uint step_test = 5;
|
|
||||||
uint i;
|
uint i;
|
||||||
old_value = *this;
|
old_value = *this;
|
||||||
|
|
||||||
// we begin from 1 in order to not testing at the beginning
|
// we begin from 1 in order to not test at the beginning
|
||||||
#ifdef TTMATH_CONSTANTSGENERATOR
|
#ifdef TTMATH_CONSTANTSGENERATOR
|
||||||
for(i=1 ; true ; ++i)
|
for(i=1 ; true ; ++i)
|
||||||
#else
|
#else
|
||||||
for(i=1 ; i<=TTMATH_ARITHMETIC_MAX_LOOP ; ++i)
|
for(i=1 ; i<=TTMATH_ARITHMETIC_MAX_LOOP ; ++i)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
bool testing = ((i % step_test) == 0);
|
bool testing = ((i & 3) == 0); // it means '(i % 4) == 0'
|
||||||
|
|
||||||
next_part = numerator;
|
next_part = numerator;
|
||||||
|
|
||||||
|
@ -1567,20 +1565,17 @@ public:
|
||||||
SetZero();
|
SetZero();
|
||||||
|
|
||||||
old_value = *this;
|
old_value = *this;
|
||||||
|
|
||||||
// every 'step_test' times we make a test
|
|
||||||
const uint step_test = 5;
|
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
|
|
||||||
#ifdef TTMATH_CONSTANTSGENERATOR
|
#ifdef TTMATH_CONSTANTSGENERATOR
|
||||||
for(i=1 ; true ; ++i)
|
for(i=1 ; true ; ++i)
|
||||||
#else
|
#else
|
||||||
// we begin from 1 in order to not testing at the beginning
|
// we begin from 1 in order to not test at the beginning
|
||||||
for(i=1 ; i<=TTMATH_ARITHMETIC_MAX_LOOP ; ++i)
|
for(i=1 ; i<=TTMATH_ARITHMETIC_MAX_LOOP ; ++i)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
bool testing = ((i % step_test) == 0);
|
bool testing = ((i & 3) == 0); // it means '(i % 4) == 0'
|
||||||
|
|
||||||
next_part = x1;
|
next_part = x1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue