diff --git a/ttmath/ttmathconfig.h b/ttmath/ttmathconfig.h index 13c0f8c..3121715 100644 --- a/ttmath/ttmathconfig.h +++ b/ttmath/ttmathconfig.h @@ -27,37 +27,36 @@ distribution. */ -#ifndef headerfilettmathmathttconfig -#define headerfilettmathmathttconfig +#ifndef headerfilettmathconfig +#define headerfilettmathconfig #pragma once #include namespace ttmath { - -#if defined(_MSC_VER) - #include - #if defined(_UNICODE) + #if defined(TTMATH_USE_WCHAR) typedef wchar_t tchar_t; typedef std::wstring tstr_t; typedef std::wostringstream tostrstrm_t; typedef std::wostream tostrm_t; typedef std::wistream tistrm_t; + + #define __TTMATH_TEXT(quote) L ## quote #else typedef char tchar_t; typedef std::string tstr_t; typedef std::ostringstream tostrstrm_t; typedef std::ostream tostrm_t; typedef std::istream tistrm_t; + + #define __TTMATH_TEXT(quote) quote #endif + + #define TTMATH_TEXT(quote) __TTMATH_TEXT(quote) - #if defined(_UNICODE) - #define __TEXT(quote) L ## quote - #else - #define __TEXT(quote) quote - #endif - #define TTMATH_TEXT(quote) __TEXT(quote) +#if defined(WIN32) + #include #if defined(_MT) class clsCrit @@ -116,19 +115,16 @@ namespace ttmath } #define TTMATH_USE_THREADSAFE_OBJ(c) clsCritObj lock(c) #endif -#else // not MS compiler - typedef char tchar_t; - typedef std::string tstr_t; - typedef std::ostringstream tostrstrm_t; - typedef std::ostream tostrm_t; - typedef std::istream tistrm_t; +#else // defined(WIN32) + // not Windows world: no threading synchronization for now #endif #if !defined(TTMATH_IMPLEMENT_THREADSAFE_OBJ) + // if we don't know about serialization, make it a no-op #define TTMATH_IMPLEMENT_THREADSAFE_OBJ /* */ #define TTMATH_USE_THREADSAFE_OBJ(c) /* */ #endif } // namespace -#endif // headerfilettmathmathttconfig +#endif // headerfilettmathconfig diff --git a/ttmath/ttmathuint_x86_64.h b/ttmath/ttmathuint_x86_64.h index ddfa461..a2eaa81 100644 --- a/ttmath/ttmathuint_x86_64.h +++ b/ttmath/ttmathuint_x86_64.h @@ -858,6 +858,7 @@ namespace ttmath * */ + #ifndef __GNUC__ /*! this method calculates 64bits word a:b / 32bits c (a higher, b lower word) @@ -911,131 +912,132 @@ namespace ttmath *rest = rest_; } - template - uint UInt::AddTwoWords(uint a, uint b, uint carry, uint * result) - { - uint temp; - - if( carry == 0 ) - { - temp = a + b; - - if( temp < a ) - carry = 1; - } - else - { - carry = 1; - temp = a + b + carry; - - if( temp > a ) // !(temp<=a) - carry = 0; - } - - *result = temp; - - return carry; - } - - template - uint UInt::SubTwoWords(uint a, uint b, uint carry, uint * result) - { - if( carry == 0 ) - { - *result = a - b; - - if( a < b ) - carry = 1; - } - else - { - carry = 1; - *result = a - b - carry; - - if( a > b ) // !(a <= b ) - carry = 0; - } - - return carry; - } - - /*! - this static method addes one vector to the other - 'ss1' is larger in size or equal to 'ss2' - - ss1 points to the first (larger) vector - ss2 points to the second vector - ss1_size - size of the ss1 (and size of the result too) - ss2_size - size of the ss2 - result - is the result vector (which has size the same as ss1: ss1_size) - - Example: ss1_size is 5, ss2_size is 3 - ss1: ss2: result (output): - 5 1 5+1 - 4 3 4+3 - 2 7 2+7 - 6 6 - 9 9 - of course the carry is propagated and will be returned from the last item - (this method is used by the Karatsuba multiplication algorithm) - */ - template - uint UInt::AddVector(const uint * ss1, const uint * ss2, uint ss1_size, uint ss2_size, uint * result) - { - uint i, c = 0; - - TTMATH_ASSERT( ss1_size >= ss2_size ) - - for(i=0 ; i - uint UInt::SubVector(const uint * ss1, const uint * ss2, uint ss1_size, uint ss2_size, uint * result) - { - uint i, c = 0; - - TTMATH_ASSERT( ss1_size >= ss2_size ) - - for(i=0 ; i + uint UInt::AddTwoWords(uint a, uint b, uint carry, uint * result) + { + uint temp; + + if( carry == 0 ) + { + temp = a + b; + + if( temp < a ) + carry = 1; + } + else + { + carry = 1; + temp = a + b + carry; + + if( temp > a ) // !(temp<=a) + carry = 0; + } + + *result = temp; + + return carry; + } + + template + uint UInt::SubTwoWords(uint a, uint b, uint carry, uint * result) + { + if( carry == 0 ) + { + *result = a - b; + + if( a < b ) + carry = 1; + } + else + { + carry = 1; + *result = a - b - carry; + + if( a > b ) // !(a <= b ) + carry = 0; + } + + return carry; + } + + /*! + this static method addes one vector to the other + 'ss1' is larger in size or equal to 'ss2' + + ss1 points to the first (larger) vector + ss2 points to the second vector + ss1_size - size of the ss1 (and size of the result too) + ss2_size - size of the ss2 + result - is the result vector (which has size the same as ss1: ss1_size) + + Example: ss1_size is 5, ss2_size is 3 + ss1: ss2: result (output): + 5 1 5+1 + 4 3 4+3 + 2 7 2+7 + 6 6 + 9 9 + of course the carry is propagated and will be returned from the last item + (this method is used by the Karatsuba multiplication algorithm) + */ + template + uint UInt::AddVector(const uint * ss1, const uint * ss2, uint ss1_size, uint ss2_size, uint * result) + { + uint i, c = 0; + + TTMATH_ASSERT( ss1_size >= ss2_size ) + + for(i=0 ; i + uint UInt::SubVector(const uint * ss1, const uint * ss2, uint ss1_size, uint ss2_size, uint * result) + { + uint i, c = 0; + + TTMATH_ASSERT( ss1_size >= ss2_size ) + + for(i=0 ; i