From 1d81dc75ffed69e252726d8028365b6a97e6f5d8 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Fri, 31 Oct 2008 20:43:08 +0000 Subject: [PATCH] fixed: RclMoveAllWords() and RcrMoveAllWords() sometimes didn't return the proper carry, (when 'bits' was greater than or equal to 'value_size') this had impact on Rcl() and Rcr(), they also returned the wrong carry git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@85 e52654a7-88a9-db11-a3e9-0013d4bc506e --- ttmath/ttmathuint.h | 68 ++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/ttmath/ttmathuint.h b/ttmath/ttmathuint.h index 6a8bc17..f12d87a 100644 --- a/ttmath/ttmathuint.h +++ b/ttmath/ttmathuint.h @@ -762,7 +762,6 @@ public: private: - public: ///// !!!!!! #ifdef TTMATH_PLATFORM32 @@ -1195,34 +1194,37 @@ private: this method moves only words */ - void RclMoveAllWords( sint & all_words, uint & rest_bits, uint & last_c, - uint bits, uint c) - { - rest_bits = sint(bits % TTMATH_BITS_PER_UINT); - all_words = sint(bits / TTMATH_BITS_PER_UINT); + void RclMoveAllWords(uint & rest_bits, uint & last_c, uint bits, uint c) + { + rest_bits = sint(bits % TTMATH_BITS_PER_UINT); + sint all_words = sint(bits / TTMATH_BITS_PER_UINT); + uint mask = ( c ) ? TTMATH_UINT_MAX_VALUE : 0; + if( all_words >= sint(value_size) ) { - if( all_words==value_size && rest_bits==0 ) + if( all_words == value_size && rest_bits == 0 ) last_c = table[0] & 1; - all_words = value_size; // not value_size - 1 + // clearing + for(uint i = 0 ; i 0 ) + else + if( all_words > 0 ) { - sint first; - sint second; - + // 0 < all_words < value_size + + sint first, second; last_c = table[value_size - all_words] & 1; // all_words is greater than 0 // copying the first part of the value for(first = value_size-1, second=first-all_words ; second>=0 ; --first, --second) table[first] = table[second]; - // sets the rest bits of value into 'c' - uint mask = c ? TTMATH_UINT_MAX_VALUE : 0; + // setting the rest to 'c' for( ; first>=0 ; --first ) table[first] = mask; } @@ -1242,15 +1244,14 @@ public: */ uint Rcl(uint bits, uint c=0) { - uint last_c = 0; - sint all_words = 0; + uint last_c = 0; uint rest_bits = bits; if( bits == 0 ) return 0; if( bits >= TTMATH_BITS_PER_UINT ) - RclMoveAllWords(all_words, rest_bits, last_c, bits, c); + RclMoveAllWords(rest_bits, last_c, bits, c); if( rest_bits == 0 ) return last_c; @@ -1282,35 +1283,36 @@ private: this method moves only words */ - void RcrMoveAllWords( sint & all_words, uint & rest_bits, uint & last_c, - uint bits, uint c) + void RcrMoveAllWords(uint & rest_bits, uint & last_c, uint bits, uint c) { - rest_bits = sint(bits % TTMATH_BITS_PER_UINT); - all_words = sint(bits / TTMATH_BITS_PER_UINT); + rest_bits = sint(bits % TTMATH_BITS_PER_UINT); + sint all_words = sint(bits / TTMATH_BITS_PER_UINT); + uint mask = c ? TTMATH_UINT_MAX_VALUE : 0; + if( all_words >= sint(value_size) ) { - if( all_words==value_size && rest_bits==0 ) + if( all_words == value_size && rest_bits == 0 ) last_c = (table[value_size-1] & TTMATH_UINT_HIGHEST_BIT) ? 1 : 0; - all_words = value_size; // not value_size - 1 + // clearing + for(uint i = 0 ; i 0 ) + else if( all_words > 0 ) { - uint first; - uint second; + // 0 < all_words < value_size + uint first, second; last_c = (table[all_words - 1] & TTMATH_UINT_HIGHEST_BIT) ? 1 : 0; // all_words is > 0 // copying the first part of the value for(first=0, second=all_words ; second= TTMATH_BITS_PER_UINT ) - RcrMoveAllWords(all_words, rest_bits, last_c, bits, c); + RcrMoveAllWords(rest_bits, last_c, bits, c); if( rest_bits == 0 ) return last_c; @@ -3574,7 +3575,6 @@ public: #ifdef TTMATH_PLATFORM64 private: -public: uint Rcl2_one(uint c); uint Rcr2_one(uint c); uint Rcl2(uint bits, uint c);