From e18201ba350ec1a4c9d4dec0c8b6dfa15d78af19 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Tue, 3 Mar 2009 20:41:00 +0000 Subject: [PATCH] changed: UInt::Div3_Normalize - faster now git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@101 e52654a7-88a9-db11-a3e9-0013d4bc506e --- ttmath/ttmathuint.h | 34 ++++++++++++++++++---------------- ttmath/ttmathuint64.h | 6 +++--- 2 files changed, 21 insertions(+), 19 deletions(-) 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)