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:
@@ -40,68 +40,12 @@
|
|||||||
#include <ttmath/ttmath.h>
|
#include <ttmath/ttmath.h>
|
||||||
#include "uinttest.h"
|
#include "uinttest.h"
|
||||||
|
|
||||||
//#include <windows.h>
|
|
||||||
|
|
||||||
const char uint_tests_file[] = "tests.uint32";
|
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()
|
void test_uint()
|
||||||
{
|
{
|
||||||
UIntTest test;
|
UIntTest test;
|
||||||
@@ -116,8 +60,6 @@ int main()
|
|||||||
{
|
{
|
||||||
using namespace ttmath;
|
using namespace ttmath;
|
||||||
|
|
||||||
if( !test_lahf() )
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
test_uint();
|
test_uint();
|
||||||
|
|
||||||
|
@@ -245,6 +245,8 @@ public:
|
|||||||
register uint * p1 = table;
|
register uint * p1 = table;
|
||||||
register uint * p2 = const_cast<uint*>(ss2.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__
|
#ifndef __GNUC__
|
||||||
|
|
||||||
@@ -354,6 +356,8 @@ public:
|
|||||||
register uint * p1 = table;
|
register uint * p1 = table;
|
||||||
register uint c;
|
register uint c;
|
||||||
|
|
||||||
|
TTMATH_ASSERT( index < value_size )
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
|
|
||||||
__asm
|
__asm
|
||||||
@@ -466,6 +470,8 @@ public:
|
|||||||
register uint * p1 = table;
|
register uint * p1 = table;
|
||||||
register uint c;
|
register uint c;
|
||||||
|
|
||||||
|
TTMATH_ASSERT( index < value_size - 1 )
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
__asm
|
__asm
|
||||||
{
|
{
|
||||||
@@ -566,6 +572,9 @@ public:
|
|||||||
register uint * p1 = table;
|
register uint * p1 = table;
|
||||||
register uint * p2 = const_cast<uint*>(ss2.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__
|
#ifndef __GNUC__
|
||||||
|
|
||||||
__asm
|
__asm
|
||||||
@@ -667,6 +676,8 @@ public:
|
|||||||
register uint * p1 = table;
|
register uint * p1 = table;
|
||||||
register uint c;
|
register uint c;
|
||||||
|
|
||||||
|
TTMATH_ASSERT( index < value_size )
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
__asm
|
__asm
|
||||||
{
|
{
|
||||||
@@ -1424,15 +1435,12 @@ public:
|
|||||||
push eax
|
push eax
|
||||||
push edx
|
push edx
|
||||||
|
|
||||||
and edx,-1
|
mov edx,-1
|
||||||
bsr eax,x
|
bsr eax,x
|
||||||
cmovz eax,edx
|
cmovz eax,edx
|
||||||
mov result, eax
|
mov result, eax
|
||||||
|
|
||||||
//
|
|
||||||
pop edx
|
pop edx
|
||||||
//
|
|
||||||
|
|
||||||
pop eax
|
pop eax
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1441,11 +1449,10 @@ public:
|
|||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__(
|
||||||
|
|
||||||
"push %%edx \n"
|
|
||||||
"andl $-1,%%edx \n"
|
|
||||||
"bsrl %1, %0 \n"
|
"bsrl %1, %0 \n"
|
||||||
"cmovz %%edx,%0 \n"
|
"jnz 1f \n"
|
||||||
"pop %%edx \n"
|
"movl $-1, %0 \n"
|
||||||
|
"1: \n"
|
||||||
|
|
||||||
: "=R" (result)
|
: "=R" (result)
|
||||||
: "R" (x)
|
: "R" (x)
|
||||||
@@ -1507,6 +1514,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
static uint SetBitInWord(uint value, uint bit)
|
static uint SetBitInWord(uint value, uint bit)
|
||||||
{
|
{
|
||||||
|
TTMATH_ASSERT( bit < TTMATH_BITS_PER_UINT )
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
__asm
|
__asm
|
||||||
{
|
{
|
||||||
|
@@ -825,14 +825,13 @@ namespace ttmath
|
|||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__(
|
||||||
|
|
||||||
"push %%rdx \n"
|
"bsrq %1, %0 \n"
|
||||||
"andq $-1,%%rdx \n"
|
"jnz 1f \n"
|
||||||
"bsrq %%rbx, %%rax \n"
|
"movq $-1, %0 \n"
|
||||||
"cmovz %%rdx,%%rax \n"
|
"1: \n"
|
||||||
"pop %%rdx \n"
|
|
||||||
|
|
||||||
: "=a" (result)
|
: "=R" (result)
|
||||||
: "b" (x)
|
: "R" (x)
|
||||||
: "cc" );
|
: "cc" );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user