added: macros TTMATH_ASSERT to: UInt::AddInt UInt::AddTwoInts UInt::SubInt UInt::SetBitInWord
fixed: UInt::FindLeadingBitInWord(x) didn't correctly return result -1 when the x was 0 the mistake made by Thomas Braby, it was not in the 0.8.2 release changed: tests: we do not test for lahf/sahf instructions now (in 64bit code) we don't use these instructions git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@97 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
6da0386a2d
commit
5b24101a83
|
@ -40,68 +40,12 @@
|
|||
#include <ttmath/ttmath.h>
|
||||
#include "uinttest.h"
|
||||
|
||||
//#include <windows.h>
|
||||
|
||||
|
||||
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();
|
||||
|
||||
|
|
|
@ -245,6 +245,8 @@ public:
|
|||
register uint * p1 = table;
|
||||
register uint * p2 = const_cast<uint*>(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<uint*>(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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue