diff --git a/tests/main.cpp b/tests/main.cpp index 25d458f..3fda820 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -40,68 +40,12 @@ #include #include "uinttest.h" -//#include + const char uint_tests_file[] = "tests.uint32"; - -bool test_lahf() -{ -#ifdef TTMATH_PLATFORM64 - - - #ifndef __GNUC__ - #error "another compiler than GCC is currently not supported in 64bit mode" - #endif - - - std::cout << "Processor 64bit: checking LAHF and SAHF instructions...."; - - unsigned long int is_lahf; - - - __asm__ __volatile__ ( - - "push %%rax \n" - "push %%rcx \n" - "push %%rdx \n" - - "mov $0x80000001, %%rax \n" - "CPUID \n" - "test $1, %%rcx \n" - "setnz %%al \n" - "movzx %%al, %%rbx \n" - - "pop %%rdx \n" - "pop %%rcx \n" - "pop %%rax \n" - - : "=b" (is_lahf) - : - : "cc" - ); - - if( is_lahf ) - { - std::cout << "ok" << std::endl; - return true; - } - - std::cout << "fail" << std::endl; - - - return false; - -#endif - - - // 32bit platform -return true; -} - - void test_uint() { UIntTest test; @@ -116,8 +60,6 @@ int main() { using namespace ttmath; - if( !test_lahf() ) - return 1; test_uint(); diff --git a/ttmath/ttmathuint.h b/ttmath/ttmathuint.h index 5a4e363..8848f53 100644 --- a/ttmath/ttmathuint.h +++ b/ttmath/ttmathuint.h @@ -245,6 +245,8 @@ public: register uint * p1 = table; register uint * p2 = const_cast(ss2.table); + // we don't have to use TTMATH_REFERENCE_ASSERT here + // this algorithm doesn't require it #ifndef __GNUC__ @@ -354,6 +356,8 @@ public: register uint * p1 = table; register uint c; + TTMATH_ASSERT( index < value_size ) + #ifndef __GNUC__ __asm @@ -466,6 +470,8 @@ public: register uint * p1 = table; register uint c; + TTMATH_ASSERT( index < value_size - 1 ) + #ifndef __GNUC__ __asm { @@ -566,6 +572,9 @@ public: register uint * p1 = table; register uint * p2 = const_cast(ss2.table); + // we don't have to use TTMATH_REFERENCE_ASSERT here + // this algorithm doesn't require it + #ifndef __GNUC__ __asm @@ -667,6 +676,8 @@ public: register uint * p1 = table; register uint c; + TTMATH_ASSERT( index < value_size ) + #ifndef __GNUC__ __asm { @@ -1424,15 +1435,12 @@ public: push eax push edx - and edx,-1 - bsr eax, x + mov edx,-1 + bsr eax,x cmovz eax,edx mov result, eax - // pop edx - // - pop eax } #endif @@ -1441,11 +1449,10 @@ public: #ifdef __GNUC__ __asm__ __volatile__( - "push %%edx \n" - "andl $-1,%%edx \n" "bsrl %1, %0 \n" - "cmovz %%edx,%0 \n" - "pop %%edx \n" + "jnz 1f \n" + "movl $-1, %0 \n" + "1: \n" : "=R" (result) : "R" (x) @@ -1507,6 +1514,8 @@ public: */ static uint SetBitInWord(uint value, uint bit) { + TTMATH_ASSERT( bit < TTMATH_BITS_PER_UINT ) + #ifndef __GNUC__ __asm { diff --git a/ttmath/ttmathuint64.h b/ttmath/ttmathuint64.h index 6643bd9..a2daab2 100644 --- a/ttmath/ttmathuint64.h +++ b/ttmath/ttmathuint64.h @@ -825,14 +825,13 @@ namespace ttmath #ifdef __GNUC__ __asm__ __volatile__( - "push %%rdx \n" - "andq $-1,%%rdx \n" - "bsrq %%rbx, %%rax \n" - "cmovz %%rdx,%%rax \n" - "pop %%rdx \n" + "bsrq %1, %0 \n" + "jnz 1f \n" + "movq $-1, %0 \n" + "1: \n" - : "=a" (result) - : "b" (x) + : "=R" (result) + : "R" (x) : "cc" ); #endif