diff --git a/ttmath/ttmathuint.h b/ttmath/ttmathuint.h index 8848f53..acc27f7 100644 --- a/ttmath/ttmathuint.h +++ b/ttmath/ttmathuint.h @@ -1450,9 +1450,9 @@ public: __asm__ __volatile__( "bsrl %1, %0 \n" - "jnz 1f \n" - "movl $-1, %0 \n" - "1: \n" + "jnz 1f \n" + "movl $-1, %0 \n" + "1: \n" : "=R" (result) : "R" (x) @@ -2627,23 +2627,25 @@ private: */ uint Div3_Normalize(UInt & v, uint n, uint & d) { - uint c = 0; + // v.table[n-1] is != 0 - // !!!!!!!!! change - for( d = 0 ; (v.table[n-1] & TTMATH_UINT_HIGHEST_BIT) == 0 ; ++d ) + uint bit = (uint)FindLeadingBitInWord(v.table[n-1]); + uint move = (TTMATH_BITS_PER_UINT - bit - 1); + uint res = table[value_size-1]; + d = move; + + if( move > 0 ) { - // we can move the bits only to the 'n-1' index but at the moment - // we don't have such method - // maybe it's time to write it now? - v.Rcl(1, 0); - - c <<= 1; - - if( Rcl(1, 0) ) - c += 1; + v.Rcl(move, 0); + Rcl(move, 0); + res = res >> (bit + 1); + } + else + { + res = 0; } - return c; + return res; } diff --git a/ttmath/ttmathuint64.h b/ttmath/ttmathuint64.h index a2daab2..d2d42ff 100644 --- a/ttmath/ttmathuint64.h +++ b/ttmath/ttmathuint64.h @@ -826,9 +826,9 @@ namespace ttmath __asm__ __volatile__( "bsrq %1, %0 \n" - "jnz 1f \n" - "movq $-1, %0 \n" - "1: \n" + "jnz 1f \n" + "movq $-1, %0 \n" + "1: \n" : "=R" (result) : "R" (x)