- 32 bit ASM code and ASSERTS did not work as the ASM code put its result in EAX, but the ASSERT afterwards did destroy the EAX's contents, of course.
git-svn-id: svn://ttmath.org/publicrep/ttmath/branches/chk@155 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
b31d34ebdd
commit
be8913866a
|
@ -97,10 +97,13 @@ namespace ttmath
|
||||||
-2.7 = -3
|
-2.7 = -3
|
||||||
*/
|
*/
|
||||||
template<class ValueType>
|
template<class ValueType>
|
||||||
ValueType Round(const ValueType & x)
|
ValueType Round(const ValueType & x, ErrorCode * err = 0)
|
||||||
{
|
{
|
||||||
ValueType result( x );
|
ValueType result( x );
|
||||||
result.Round();
|
uint c = result.Round();
|
||||||
|
|
||||||
|
if( err )
|
||||||
|
*err = c ? err_overflow : err_ok;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -298,7 +301,7 @@ namespace ttmath
|
||||||
(you don't have to call this function)
|
(you don't have to call this function)
|
||||||
*/
|
*/
|
||||||
template<class ValueType>
|
template<class ValueType>
|
||||||
void PrepareSin(ValueType & x, bool & change_sign)
|
uint PrepareSin(ValueType & x, bool & change_sign)
|
||||||
{
|
{
|
||||||
ValueType temp;
|
ValueType temp;
|
||||||
|
|
||||||
|
@ -314,12 +317,10 @@ namespace ttmath
|
||||||
// we're reducing the period 2*PI
|
// we're reducing the period 2*PI
|
||||||
// (for big values there'll always be zero)
|
// (for big values there'll always be zero)
|
||||||
temp.Set2Pi();
|
temp.Set2Pi();
|
||||||
if( x > temp )
|
|
||||||
{
|
if( x.Mod(temp) )
|
||||||
x.Div( temp );
|
return 1;
|
||||||
x.RemainFraction();
|
|
||||||
x.Mul( temp );
|
|
||||||
}
|
|
||||||
|
|
||||||
// we're setting 'x' as being in the range of <0, 0.5PI>
|
// we're setting 'x' as being in the range of <0, 0.5PI>
|
||||||
|
|
||||||
|
@ -340,6 +341,8 @@ namespace ttmath
|
||||||
x.Sub( temp );
|
x.Sub( temp );
|
||||||
x = temp - x;
|
x = temp - x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -426,7 +429,7 @@ namespace ttmath
|
||||||
if( c )
|
if( c )
|
||||||
// Sin is from <-1,1> and cannot make an overflow
|
// Sin is from <-1,1> and cannot make an overflow
|
||||||
// but the carry can be from the Taylor series
|
// but the carry can be from the Taylor series
|
||||||
// (then we only breaks our calculations)
|
// (then we only break our calculations)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if( addition )
|
if( addition )
|
||||||
|
@ -458,15 +461,15 @@ namespace ttmath
|
||||||
this function calculates the Sine
|
this function calculates the Sine
|
||||||
*/
|
*/
|
||||||
template<class ValueType>
|
template<class ValueType>
|
||||||
ValueType Sin(ValueType x)
|
ValueType Sin(ValueType x, ErrorCode * err = 0)
|
||||||
{
|
{
|
||||||
using namespace auxiliaryfunctions;
|
using namespace auxiliaryfunctions;
|
||||||
|
|
||||||
ValueType one;
|
ValueType one, result;
|
||||||
bool change_sign;
|
bool change_sign;
|
||||||
|
|
||||||
PrepareSin( x, change_sign );
|
if( err )
|
||||||
ValueType result = Sin0pi05( x );
|
*err = err_ok;
|
||||||
|
|
||||||
if( PrepareSin( x, change_sign ) )
|
if( PrepareSin( x, change_sign ) )
|
||||||
{
|
{
|
||||||
|
@ -506,22 +509,24 @@ namespace ttmath
|
||||||
we're using the formula cos(x) = sin(x + PI/2)
|
we're using the formula cos(x) = sin(x + PI/2)
|
||||||
*/
|
*/
|
||||||
template<class ValueType>
|
template<class ValueType>
|
||||||
ValueType Cos(ValueType x)
|
ValueType Cos(ValueType x, ErrorCode * err = 0)
|
||||||
{
|
{
|
||||||
ValueType pi05;
|
ValueType pi05;
|
||||||
pi05.Set05Pi();
|
pi05.Set05Pi();
|
||||||
|
|
||||||
x.Add( pi05 );
|
uint c = x.Add( pi05 );
|
||||||
|
|
||||||
if( c )
|
if( c )
|
||||||
{
|
{
|
||||||
if( err )
|
if( err )
|
||||||
*err = err_overflow;
|
*err = err_overflow;
|
||||||
}
|
|
||||||
|
|
||||||
return ValueType(); // result is undefined (NaN is set by default)
|
return ValueType(); // result is undefined (NaN is set by default)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Sin(x, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
this function calulates the Tangent
|
this function calulates the Tangent
|
||||||
|
@ -536,7 +541,10 @@ namespace ttmath
|
||||||
template<class ValueType>
|
template<class ValueType>
|
||||||
ValueType Tan(const ValueType & x, ErrorCode * err = 0)
|
ValueType Tan(const ValueType & x, ErrorCode * err = 0)
|
||||||
{
|
{
|
||||||
ValueType result = Cos(x);
|
ValueType result = Cos(x, err);
|
||||||
|
|
||||||
|
if( err && *err != err_ok )
|
||||||
|
return result;
|
||||||
|
|
||||||
if( result.IsZero() )
|
if( result.IsZero() )
|
||||||
{
|
{
|
||||||
|
@ -548,10 +556,7 @@ namespace ttmath
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( err )
|
return Sin(x, err) / result;
|
||||||
*err = err_ok;
|
|
||||||
|
|
||||||
return Sin(x) / result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -578,7 +583,10 @@ namespace ttmath
|
||||||
template<class ValueType>
|
template<class ValueType>
|
||||||
ValueType Cot(const ValueType & x, ErrorCode * err = 0)
|
ValueType Cot(const ValueType & x, ErrorCode * err = 0)
|
||||||
{
|
{
|
||||||
ValueType result = Sin(x);
|
ValueType result = Sin(x, err);
|
||||||
|
|
||||||
|
if( err && *err != err_ok )
|
||||||
|
return result;
|
||||||
|
|
||||||
if( result.IsZero() )
|
if( result.IsZero() )
|
||||||
{
|
{
|
||||||
|
@ -590,10 +598,7 @@ namespace ttmath
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( err )
|
return Cos(x, err) / result;
|
||||||
*err = err_ok;
|
|
||||||
|
|
||||||
return Cos(x) / result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2053,14 +2058,17 @@ namespace ttmath
|
||||||
|
|
||||||
e.g.
|
e.g.
|
||||||
mod( 12.6 ; 3) = 0.6 because 12.6 = 3*4 + 0.6
|
mod( 12.6 ; 3) = 0.6 because 12.6 = 3*4 + 0.6
|
||||||
mod(-12.6 ; 3) = -0.6
|
mod(-12.6 ; 3) = -0.6 bacause -12.6 = 3*(-4) + (-0.6)
|
||||||
mod( 12.6 ; -3) = 0.6
|
mod( 12.6 ; -3) = 0.6
|
||||||
mod(-12.6 ; -3) = -0.6
|
mod(-12.6 ; -3) = -0.6
|
||||||
*/
|
*/
|
||||||
template<class ValueType>
|
template<class ValueType>
|
||||||
ValueType Mod(ValueType a, const ValueType & b)
|
ValueType Mod(ValueType a, const ValueType & b, ErrorCode * err = 0)
|
||||||
{
|
{
|
||||||
a.Mod(b);
|
uint c = a.Mod(b);
|
||||||
|
|
||||||
|
if( err )
|
||||||
|
*err = c ? err_overflow : err_ok;
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2693,7 +2693,7 @@ public:
|
||||||
tchar_t decimal_point = TTMATH_COMMA_CHARACTER_1 ) const
|
tchar_t decimal_point = TTMATH_COMMA_CHARACTER_1 ) const
|
||||||
{
|
{
|
||||||
static tchar_t error_overflow_msg[] = TTMATH_TEXT("overflow");
|
static tchar_t error_overflow_msg[] = TTMATH_TEXT("overflow");
|
||||||
static char error_nan_msg[] = "NaN";
|
static tchar_t error_nan_msg[] = TTMATH_TEXT("NaN");
|
||||||
result.erase();
|
result.erase();
|
||||||
|
|
||||||
if( IsNan() )
|
if( IsNan() )
|
||||||
|
|
|
@ -976,7 +976,7 @@ public:
|
||||||
// table[i] = result.table[i];
|
// table[i] = result.table[i];
|
||||||
|
|
||||||
// testing carry
|
// testing carry
|
||||||
for( ; i<value_size*2 ; ++i)
|
for(i = value_size ; i<value_size*2 ; ++i)
|
||||||
if( result.table[i] != 0 )
|
if( result.table[i] != 0 )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
@ -2877,7 +2877,7 @@ public:
|
||||||
ttmathuint_noasm.h
|
ttmathuint_noasm.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef TTMATH_NOASM
|
#if defined(TTMATH_NOASM)
|
||||||
static uint AddTwoWords(uint a, uint b, uint carry, uint * result);
|
static uint AddTwoWords(uint a, uint b, uint carry, uint * result);
|
||||||
static uint SubTwoWords(uint a, uint b, uint carry, uint * result);
|
static uint SubTwoWords(uint a, uint b, uint carry, uint * result);
|
||||||
|
|
||||||
|
|
|
@ -38,16 +38,17 @@
|
||||||
#ifndef headerfilettmathuint_noasm
|
#ifndef headerfilettmathuint_noasm
|
||||||
#define headerfilettmathuint_noasm
|
#define headerfilettmathuint_noasm
|
||||||
|
|
||||||
|
|
||||||
#ifdef TTMATH_NOASM
|
#ifdef TTMATH_NOASM
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\file ttmathuint_noasm.h
|
\file ttmathuint.h
|
||||||
\brief template class UInt<uint> with methods without any assembler code
|
\brief template class UInt<uint> with methods without any assembler code
|
||||||
|
|
||||||
this file is included at the end of ttmathuint.h
|
this file is included at the end of ttmathuint.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma message("TTMATH_NOASM")
|
||||||
|
|
||||||
|
|
||||||
namespace ttmath
|
namespace ttmath
|
||||||
{
|
{
|
||||||
|
@ -95,7 +96,7 @@ namespace ttmath
|
||||||
for(i=0 ; i<value_size ; ++i)
|
for(i=0 ; i<value_size ; ++i)
|
||||||
c = AddTwoWords(table[i], ss2.table[i], c, &table[i]);
|
c = AddTwoWords(table[i], ss2.table[i], c, &table[i]);
|
||||||
|
|
||||||
TTMATH_LOG("UInt_noasm::Add")
|
TTMATH_LOG("UInt::Add")
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -131,7 +132,7 @@ namespace ttmath
|
||||||
for(i=index+1 ; i<value_size && c ; ++i)
|
for(i=index+1 ; i<value_size && c ; ++i)
|
||||||
c = AddTwoWords(table[i], 0, c, &table[i]);
|
c = AddTwoWords(table[i], 0, c, &table[i]);
|
||||||
|
|
||||||
TTMATH_LOG("UInt_noasm::AddInt")
|
TTMATH_LOG("UInt::AddInt")
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -184,7 +185,7 @@ namespace ttmath
|
||||||
for(i=index+2 ; i<value_size && c ; ++i)
|
for(i=index+2 ; i<value_size && c ; ++i)
|
||||||
c = AddTwoWords(table[i], 0, c, &table[i]);
|
c = AddTwoWords(table[i], 0, c, &table[i]);
|
||||||
|
|
||||||
TTMATH_LOG("UInt64::AddTwoInts")
|
TTMATH_LOG("UInt::AddTwoInts")
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -232,7 +233,7 @@ namespace ttmath
|
||||||
for(i=0 ; i<value_size ; ++i)
|
for(i=0 ; i<value_size ; ++i)
|
||||||
c = SubTwoWords(table[i], ss2.table[i], c, &table[i]);
|
c = SubTwoWords(table[i], ss2.table[i], c, &table[i]);
|
||||||
|
|
||||||
TTMATH_LOG("UInt_noasm::Sub")
|
TTMATH_LOG("UInt::Sub")
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -270,7 +271,7 @@ namespace ttmath
|
||||||
for(i=index+1 ; i<value_size && c ; ++i)
|
for(i=index+1 ; i<value_size && c ; ++i)
|
||||||
c = SubTwoWords(table[i], 0, c, &table[i]);
|
c = SubTwoWords(table[i], 0, c, &table[i]);
|
||||||
|
|
||||||
TTMATH_LOG("UInt_noasm::SubInt")
|
TTMATH_LOG("UInt::SubInt")
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -305,7 +306,7 @@ namespace ttmath
|
||||||
c = new_c;
|
c = new_c;
|
||||||
}
|
}
|
||||||
|
|
||||||
TTMATH_LOG("UInt64::Rcl2_one")
|
TTMATH_LOG("UInt::Rcl2_one")
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -344,7 +345,7 @@ namespace ttmath
|
||||||
c = new_c;
|
c = new_c;
|
||||||
}
|
}
|
||||||
|
|
||||||
TTMATH_LOG("UInt64::Rcr2_one")
|
TTMATH_LOG("UInt::Rcr2_one")
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -421,7 +422,7 @@ namespace ttmath
|
||||||
c = new_c;
|
c = new_c;
|
||||||
}
|
}
|
||||||
|
|
||||||
TTMATH_LOG("UInt64::Rcr2")
|
TTMATH_LOG("UInt::Rcr2")
|
||||||
|
|
||||||
return (c & TTMATH_UINT_HIGHEST_BIT) ? 1 : 0;
|
return (c & TTMATH_UINT_HIGHEST_BIT) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
@ -879,7 +880,3 @@ namespace ttmath
|
||||||
|
|
||||||
#endif //ifdef TTMATH_NOASM
|
#endif //ifdef TTMATH_NOASM
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,14 +36,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef headerfilettmathuint_x86
|
#ifndef headerfilettmathuint_x86
|
||||||
#define headerfilettmathuint_x86
|
#define headerfilettmathuint_x86
|
||||||
|
|
||||||
|
|
||||||
#ifndef TTMATH_NOASM
|
#ifndef TTMATH_NOASM
|
||||||
#ifdef TTMATH_PLATFORM32
|
#ifdef TTMATH_PLATFORM32
|
||||||
|
|
||||||
|
#pragma message("TTMATH_ASM")
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\file ttmathuint_x86.h
|
\file ttmathuint_x86.h
|
||||||
|
@ -65,8 +64,7 @@ namespace ttmath
|
||||||
* basic mathematic functions
|
* basic mathematic functions
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
adding ss2 to the this and adding carry if it's defined
|
adding ss2 to the this and adding carry if it's defined
|
||||||
(this = this + ss2 + c)
|
(this = this + ss2 + c)
|
||||||
|
@ -85,7 +83,6 @@ namespace ttmath
|
||||||
// this algorithm doesn't require it
|
// this algorithm doesn't require it
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
|
|
||||||
// this part might be compiled with for example visual c
|
// this part might be compiled with for example visual c
|
||||||
|
|
||||||
__asm
|
__asm
|
||||||
|
@ -109,8 +106,8 @@ namespace ttmath
|
||||||
|
|
||||||
setc al
|
setc al
|
||||||
movzx eax, al
|
movzx eax, al
|
||||||
|
mov [c], eax
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,11 +140,11 @@ namespace ttmath
|
||||||
: "=d" (c)
|
: "=d" (c)
|
||||||
: "D" (c), "c" (b), "b" (p1), "S" (p2)
|
: "D" (c), "c" (b), "b" (p1), "S" (p2)
|
||||||
: "%eax", "cc", "memory" );
|
: "%eax", "cc", "memory" );
|
||||||
|
|
||||||
return c;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TTMATH_LOG("UInt32::Add")
|
TTMATH_LOG("UInt::Add")
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -174,13 +171,13 @@ namespace ttmath
|
||||||
template<uint value_size>
|
template<uint value_size>
|
||||||
uint UInt<value_size>::AddInt(uint value, uint index)
|
uint UInt<value_size>::AddInt(uint value, uint index)
|
||||||
{
|
{
|
||||||
register uint b = value_size;
|
uint b = value_size;
|
||||||
register uint * p1 = table;
|
uint * p1 = table;
|
||||||
|
uint c;
|
||||||
|
|
||||||
TTMATH_ASSERT( index < value_size )
|
TTMATH_ASSERT( index < value_size )
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
|
|
||||||
__asm
|
__asm
|
||||||
{
|
{
|
||||||
mov ecx, [b]
|
mov ecx, [b]
|
||||||
|
@ -204,14 +201,12 @@ namespace ttmath
|
||||||
end:
|
end:
|
||||||
setc al
|
setc al
|
||||||
movzx eax, al
|
movzx eax, al
|
||||||
|
mov [c], eax
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
register uint c;
|
|
||||||
|
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__(
|
||||||
|
|
||||||
"push %%eax \n"
|
"push %%eax \n"
|
||||||
|
@ -238,11 +233,11 @@ namespace ttmath
|
||||||
: "=d" (c)
|
: "=d" (c)
|
||||||
: "a" (value), "c" (b), "0" (index), "b" (p1)
|
: "a" (value), "c" (b), "0" (index), "b" (p1)
|
||||||
: "cc", "memory" );
|
: "cc", "memory" );
|
||||||
|
|
||||||
return c;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TTMATH_LOG("UInt32::AddInt")
|
TTMATH_LOG("UInt::AddInt")
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -281,8 +276,9 @@ namespace ttmath
|
||||||
template<uint value_size>
|
template<uint value_size>
|
||||||
uint UInt<value_size>::AddTwoInts(uint x2, uint x1, uint index)
|
uint UInt<value_size>::AddTwoInts(uint x2, uint x1, uint index)
|
||||||
{
|
{
|
||||||
register uint b = value_size;
|
uint b = value_size;
|
||||||
register uint * p1 = table;
|
uint * p1 = table;
|
||||||
|
uint c;
|
||||||
|
|
||||||
TTMATH_ASSERT( index < value_size - 1 )
|
TTMATH_ASSERT( index < value_size - 1 )
|
||||||
|
|
||||||
|
@ -313,13 +309,11 @@ namespace ttmath
|
||||||
end:
|
end:
|
||||||
setc al
|
setc al
|
||||||
movzx eax, al
|
movzx eax, al
|
||||||
|
mov [c], eax
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
register uint c;
|
|
||||||
|
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__(
|
||||||
|
|
||||||
"push %%ecx \n"
|
"push %%ecx \n"
|
||||||
|
@ -350,11 +344,11 @@ namespace ttmath
|
||||||
: "=a" (c)
|
: "=a" (c)
|
||||||
: "c" (b), "d" (index), "b" (p1), "S" (x1), "0" (x2)
|
: "c" (b), "d" (index), "b" (p1), "S" (x1), "0" (x2)
|
||||||
: "cc", "memory" );
|
: "cc", "memory" );
|
||||||
|
|
||||||
return c;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TTMATH_LOG("UInt32::AddTwoInts")
|
TTMATH_LOG("UInt::AddTwoInts")
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -380,7 +374,6 @@ namespace ttmath
|
||||||
// this algorithm doesn't require it
|
// this algorithm doesn't require it
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
|
|
||||||
__asm
|
__asm
|
||||||
{
|
{
|
||||||
mov ecx,[b]
|
mov ecx,[b]
|
||||||
|
@ -404,6 +397,7 @@ namespace ttmath
|
||||||
|
|
||||||
setc al
|
setc al
|
||||||
movzx eax, al
|
movzx eax, al
|
||||||
|
mov [c], eax
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -435,10 +429,11 @@ namespace ttmath
|
||||||
: "D" (c), "c" (b), "b" (p1), "S" (p2)
|
: "D" (c), "c" (b), "b" (p1), "S" (p2)
|
||||||
: "%eax", "cc", "memory" );
|
: "%eax", "cc", "memory" );
|
||||||
|
|
||||||
return c;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TTMATH_LOG("UInt32::Sub")
|
TTMATH_LOG("UInt::Sub")
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -466,8 +461,9 @@ namespace ttmath
|
||||||
template<uint value_size>
|
template<uint value_size>
|
||||||
uint UInt<value_size>::SubInt(uint value, uint index)
|
uint UInt<value_size>::SubInt(uint value, uint index)
|
||||||
{
|
{
|
||||||
register uint b = value_size;
|
uint b = value_size;
|
||||||
register uint * p1 = table;
|
uint * p1 = table;
|
||||||
|
uint c;
|
||||||
|
|
||||||
TTMATH_ASSERT( index < value_size )
|
TTMATH_ASSERT( index < value_size )
|
||||||
|
|
||||||
|
@ -495,13 +491,12 @@ namespace ttmath
|
||||||
end:
|
end:
|
||||||
setc al
|
setc al
|
||||||
movzx eax, al
|
movzx eax, al
|
||||||
|
mov [c], eax
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
register uint c;
|
|
||||||
|
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__(
|
||||||
|
|
||||||
"push %%eax \n"
|
"push %%eax \n"
|
||||||
|
@ -528,12 +523,11 @@ namespace ttmath
|
||||||
: "=d" (c)
|
: "=d" (c)
|
||||||
: "a" (value), "c" (b), "0" (index), "b" (p1)
|
: "a" (value), "c" (b), "0" (index), "b" (p1)
|
||||||
: "cc", "memory" );
|
: "cc", "memory" );
|
||||||
|
|
||||||
return c;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TTMATH_LOG("UInt32::SubInt")
|
TTMATH_LOG("UInt::SubInt")
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -577,6 +571,7 @@ namespace ttmath
|
||||||
|
|
||||||
setc al
|
setc al
|
||||||
movzx eax, al
|
movzx eax, al
|
||||||
|
mov [c], eax
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -606,12 +601,11 @@ namespace ttmath
|
||||||
: "=a" (c)
|
: "=a" (c)
|
||||||
: "0" (c), "c" (b), "b" (p1)
|
: "0" (c), "c" (b), "b" (p1)
|
||||||
: "cc", "memory" );
|
: "cc", "memory" );
|
||||||
|
|
||||||
return c;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TTMATH_LOG("UInt32::Rcl2_one")
|
TTMATH_LOG("UInt::Rcl2_one")
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -652,6 +646,7 @@ namespace ttmath
|
||||||
|
|
||||||
setc al
|
setc al
|
||||||
movzx eax, al
|
movzx eax, al
|
||||||
|
mov [c], eax
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -677,11 +672,11 @@ namespace ttmath
|
||||||
: "=a" (c)
|
: "=a" (c)
|
||||||
: "0" (c), "c" (b), "b" (p1)
|
: "0" (c), "c" (b), "b" (p1)
|
||||||
: "cc", "memory" );
|
: "cc", "memory" );
|
||||||
|
|
||||||
return c;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TTMATH_LOG("UInt32::Rcr2_one")
|
TTMATH_LOG("UInt::Rcr2_one")
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -743,6 +738,7 @@ namespace ttmath
|
||||||
jnz p
|
jnz p
|
||||||
|
|
||||||
and eax, 1
|
and eax, 1
|
||||||
|
mov dword ptr [c], eax
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -790,11 +786,11 @@ namespace ttmath
|
||||||
: "=a" (c)
|
: "=a" (c)
|
||||||
: "0" (c), "D" (b), "b" (p1), "c" (bits), [amask] "m" (mask)
|
: "0" (c), "D" (b), "b" (p1), "c" (bits), [amask] "m" (mask)
|
||||||
: "cc", "memory" );
|
: "cc", "memory" );
|
||||||
|
|
||||||
return c;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TTMATH_LOG("UInt32::Rcl2")
|
TTMATH_LOG("UInt::Rcl2")
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -860,6 +856,8 @@ namespace ttmath
|
||||||
|
|
||||||
rol eax, 1 // bit 31 will be bit 0
|
rol eax, 1 // bit 31 will be bit 0
|
||||||
and eax, 1
|
and eax, 1
|
||||||
|
|
||||||
|
mov dword ptr [c], eax
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -910,11 +908,11 @@ namespace ttmath
|
||||||
: "=a" (c)
|
: "=a" (c)
|
||||||
: "0" (c), "D" (b), "b" (p1), "c" (bits), [amask] "m" (mask)
|
: "0" (c), "D" (b), "b" (p1), "c" (bits), [amask] "m" (mask)
|
||||||
: "cc", "memory" );
|
: "cc", "memory" );
|
||||||
|
|
||||||
return c;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TTMATH_LOG("UInt32::Rcr2")
|
TTMATH_LOG("UInt::Rcr2")
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -926,6 +924,7 @@ namespace ttmath
|
||||||
template<uint value_size>
|
template<uint value_size>
|
||||||
sint UInt<value_size>::FindLeadingBitInWord(uint x)
|
sint UInt<value_size>::FindLeadingBitInWord(uint x)
|
||||||
{
|
{
|
||||||
|
sint result;
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
__asm
|
__asm
|
||||||
|
@ -933,13 +932,13 @@ namespace ttmath
|
||||||
mov edx,-1
|
mov edx,-1
|
||||||
bsr eax,[x]
|
bsr eax,[x]
|
||||||
cmovz eax,edx
|
cmovz eax,edx
|
||||||
|
|
||||||
|
mov [result], eax
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
register sint result;
|
|
||||||
|
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__(
|
||||||
|
|
||||||
"bsrl %1, %0 \n"
|
"bsrl %1, %0 \n"
|
||||||
|
@ -951,9 +950,9 @@ namespace ttmath
|
||||||
: "R" (x)
|
: "R" (x)
|
||||||
: "cc" );
|
: "cc" );
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -976,6 +975,7 @@ namespace ttmath
|
||||||
TTMATH_ASSERT( bit < TTMATH_BITS_PER_UINT )
|
TTMATH_ASSERT( bit < TTMATH_BITS_PER_UINT )
|
||||||
|
|
||||||
uint v = value;
|
uint v = value;
|
||||||
|
uint old_bit;
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
__asm
|
__asm
|
||||||
|
@ -987,13 +987,12 @@ namespace ttmath
|
||||||
|
|
||||||
setc bl
|
setc bl
|
||||||
movzx ebx, bl
|
movzx ebx, bl
|
||||||
mov eax, ebx
|
mov [old_bit], ebx
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
uint old_bit;
|
|
||||||
|
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__(
|
||||||
|
|
||||||
|
@ -1005,11 +1004,10 @@ namespace ttmath
|
||||||
: "=a" (v), "=b" (old_bit)
|
: "=a" (v), "=b" (old_bit)
|
||||||
: "0" (v), "1" (bit)
|
: "0" (v), "1" (bit)
|
||||||
: "cc" );
|
: "cc" );
|
||||||
|
|
||||||
return old_bit;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
value = v;
|
value = v;
|
||||||
|
return old_bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1101,7 +1099,7 @@ namespace ttmath
|
||||||
these variables have similar meaning like those in
|
these variables have similar meaning like those in
|
||||||
the multiplication algorithm MulTwoWords
|
the multiplication algorithm MulTwoWords
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TTMATH_ASSERT( c != 0 )
|
TTMATH_ASSERT( c != 0 )
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
|
|
Loading…
Reference in New Issue