fixed: UInt::AddInt() in no-asm code has incorrect assertion

changed: UInt::SubInt() in no-asm code is a little faster now
changed: small cosmetic changes in commentaries
deleted: some debug #ifdef's from UInt::Div() (in no-asm code)



git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@136 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2009-05-08 18:14:00 +00:00
parent a7a7eb7808
commit 277dd72fb6
8 changed files with 36 additions and 69 deletions

View File

@ -1,4 +1,4 @@
Version 0.8.4 prerelease (2009.05.05):
Version 0.8.4 prerelease (2009.05.08):
* fixed: UInt::DivInt() didn't check whether the divisor is zero
there was a hardware interruption when the divisor was zero
(now the method returns one)
@ -25,7 +25,6 @@ Version 0.8.4 prerelease (2009.05.05):
(it's used when macro TTMATH_NOASM is defined)
The third form can be used on x86 and x86_64 as well and
on other platforms with a little effort.
(Temporarily I left there some '#ifdef's for debugging.)
Version 0.8.3 (2009.04.06):

4
README
View File

@ -21,6 +21,6 @@ This means only C++ developers can use this library and one thing they have
to do is to use 'include' directive of the preprocessor. How big the
values can be is set directly in the source code by the programmer.
Author: Tomasz Sowa <t.sowa@slimaczek.pl>
Project pages: http://ttmath.slimaczek.pl
Author: Tomasz Sowa <t.sowa@ttmath.org>
Project pages: http://www.ttmath.org
http://sourceforge.net/projects/ttmath

View File

@ -423,7 +423,7 @@ namespace ttmath
if( c )
// Sin is from <-1,1> and cannot make an overflow
// but the carry can be from the Taylor series
// (then we only breaks our calculations)
// (then we only break our calculations)
break;
if( addition )

View File

@ -1874,7 +1874,7 @@ public:
// error but I leave it at the moment as is
TTMATH_ASSERT( sizeof(double) == 8 )
// I am not sure what will be on a plaltform which has
// I am not sure what will be on a platform which has
// a different endianness... but we use this library only
// on x86 and amd (intel) 64 bits (as there's a lot of assembler code)
union

View File

@ -2903,7 +2903,6 @@ public:
private:
public: // !!! chwilowo public
uint Rcl2_one(uint c);
uint Rcr2_one(uint c);
uint Rcl2(uint bits, uint c);

View File

@ -116,7 +116,7 @@ namespace ttmath
table[1] = 30 + 2;
table[2] = 5;
of course if there was a carry from table[3] it would be returned
of course if there was a carry from table[2] it would be returned
*/
template<uint value_size>
uint UInt<value_size>::AddInt(uint value, uint index)
@ -175,7 +175,7 @@ namespace ttmath
{
uint i, c;
TTMATH_ASSERT( index < value_size )
TTMATH_ASSERT( index < value_size - 1 )
c = AddTwoWords(table[index], x1, 0, &table[index]);
@ -255,7 +255,7 @@ namespace ttmath
table[1] = 30 - 2;
table[2] = 5;
of course if there was a carry from table[3] it would be returned
of course if there was a carry from table[2] it would be returned
*/
template<uint value_size>
uint UInt<value_size>::SubInt(uint value, uint index)
@ -473,8 +473,8 @@ namespace ttmath
uint mask = 1;
while( bit-- > 0 )
mask = mask << 1;
if( bit > 1 )
mask = mask << bit;
uint last = value & mask;
value = value | mask;
@ -601,7 +601,6 @@ namespace ttmath
*/
// !! maybe returns something? a carry? or when c is zero?
/*!
this method calculates 64bits word a:b / 32bits c (a higher, b lower word)
r = a:b / c and rest - remainder
@ -648,10 +647,6 @@ namespace ttmath
{
*r = b / c;
*rest = b % c;
#ifdef TTMATH_WARTOWNIK
++tester_wartownik1; // !!!!! skasowac
#endif
}
else
if( c_.u_.high == 0 )
@ -674,10 +669,6 @@ namespace ttmath
*rest = temp2.u % c;
*r = res_.u;
#ifdef TTMATH_WARTOWNIK
++tester_wartownik2; // !!!!! skasowac
#endif
}
else
{
@ -690,6 +681,13 @@ namespace ttmath
#ifdef TTMATH_PLATFORM64
/*!
this method is available only on 64bit platforms
the same algorithm like the third division algorithm in ttmathuint.h
but now with the radix=2^32
*/
template<uint value_size>
void UInt<value_size>::DivTwoWords2(uint a, uint b, uint c, uint * r, uint * rest)
{
@ -704,7 +702,6 @@ namespace ttmath
c_.u = c;
// normalizing
// a0 will actually not be used
uint d = DivTwoWordsNormalize(a_, b_, c_);
// loop from j=1 to j=0
@ -748,12 +745,7 @@ namespace ttmath
a_.u = a_.u << 1; // carry bits from 'a' are simply skipped
if( bc )
{
a_.u = a_.u | 1;
#ifdef TTMATH_WARTOWNIK
++tester_wartownik3; // !!!!! skasowac
#endif
}
}
return d;
@ -802,23 +794,11 @@ namespace ttmath
if( decrease )
{
#ifdef TTMATH_WARTOWNIK
++tester_wartownik4; // !!!!! skasowac
#endif
--qp_.u;
rp_.u += v_.u_.high;
if( rp_.u_.high == 0 )
{
next_test = true;
#ifdef TTMATH_WARTOWNIK
++tester_wartownik5; // !!!!! skasowac
#endif
}
}
}
while( next_test );
@ -849,20 +829,12 @@ namespace ttmath
temp_.u_.low = u_.u_.high;
c = SubTwoWords(temp_.u, res_high, c, &sub_res_high_.u);
#ifdef TTMATH_WARTOWNIK
++tester_wartownik6; // !!!!! skasowac
#endif
if( c )
{
--q;
c = AddTwoWords(sub_res_low_.u, v_.u, 0, &sub_res_low_.u);
AddTwoWords(sub_res_high_.u, 0, c, &sub_res_high_.u);
#ifdef TTMATH_WARTOWNIK
++tester_wartownik7; // !!!!! skasowac
#endif
}
u_.u_.high = sub_res_high_.u_.low;

View File

@ -463,7 +463,6 @@ namespace ttmath
#ifdef __GNUC__
__asm__ __volatile__(
"push %%ecx \n"
"xorl %%eax, %%eax \n"
@ -515,7 +514,7 @@ namespace ttmath
table[1] = 30 - 2;
table[2] = 5;
of course if there was a carry from table[3] it would be returned
of course if there was a carry from table[2] it would be returned
*/
template<uint value_size>
uint UInt<value_size>::SubInt(uint value, uint index)
@ -1138,16 +1137,15 @@ namespace ttmath
/*!
multiplication: result2:result1 = a * b
result2 - higher word
result1 - lower word of the result
multiplication: result_high:result_low = a * b
result_high - higher word of the result
result_low - lower word of the result
this method never returns a carry
it is an auxiliary method for second version of the multiplication algorithm
this methos never returns a carry
this method is used in the second version of the multiplication algorithms
*/
template<uint value_size>
void UInt<value_size>::MulTwoWords(uint a, uint b, uint * result2, uint * result1)
void UInt<value_size>::MulTwoWords(uint a, uint b, uint * result_high, uint * result_low)
{
/*
we must use these temporary variables in order to inform the compilator
@ -1192,8 +1190,8 @@ namespace ttmath
#endif
*result1 = result1_;
*result2 = result2_;
*result_low = result1_;
*result_high = result2_;
}

View File

@ -137,7 +137,7 @@ namespace ttmath
table[1] = 30 + 2;
table[2] = 5;
of course if there was a carry from table[3] it would be returned
of course if there was a carry from table[2] it would be returned
*/
template<uint value_size>
uint UInt<value_size>::AddInt(uint value, uint index)
@ -339,7 +339,7 @@ namespace ttmath
table[1] = 30 - 2;
table[2] = 5;
of course if there was a carry from table[3] it would be returned
of course if there was a carry from table[2] it would be returned
*/
template<uint value_size>
uint UInt<value_size>::SubInt(uint value, uint index)
@ -635,7 +635,7 @@ namespace ttmath
/*
this method returns the number of the highest set bit in one 32-bit word
this method returns the number of the highest set bit in one 64-bit word
if the 'x' is zero this method returns '-1'
***this method is created only on a 64bit platform***
@ -723,18 +723,17 @@ namespace ttmath
/*!
multiplication: result2:result1 = a * b
result2 - higher word
result1 - lower word of the result
multiplication: result_high:result_low = a * b
result_high - higher word of the result
result_low - lower word of the result
this methos never returns a carry
this method is used in the second version of the multiplication algorithms
***this method is created only on a 64bit platform***
it is an auxiliary method for version two of the multiplication algorithm
*/
template<uint value_size>
void UInt<value_size>::MulTwoWords(uint a, uint b, uint * result2, uint * result1)
void UInt<value_size>::MulTwoWords(uint a, uint b, uint * result_high, uint * result_low)
{
/*
we must use these temporary variables in order to inform the compilator
@ -763,8 +762,8 @@ namespace ttmath
#endif
*result1 = result1_;
*result2 = result2_;
*result_low = result1_;
*result_high = result2_;
}