changed: asm code in UInt::Add, UInt::AddInt, AddTwoInts

32 and 64 bits, much faster now
added:   tests for UInt::AddInt
fixed:   tests: test_lahf() returned incorrect value for 32bit platform


git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@82 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2008-10-25 20:05:51 +00:00
parent f1115a2ce9
commit cfd719cca2
7 changed files with 280 additions and 320 deletions

View File

@@ -1,6 +1,6 @@
CC = g++
o = main.o uinttest.o
CFLAGS = -Wall -pedantic
CFLAGS = -Wall
ttmath = ..
name = tests

View File

@@ -40,6 +40,7 @@
#include <ttmath/ttmath.h>
#include "uinttest.h"
//#include <windows.h>
const char uint_tests_file[] = "tests.uint32";
@@ -90,9 +91,13 @@ bool test_lahf()
std::cout << "fail" << std::endl;
return false;
#endif
return false;
// 32bit platform
return true;
}
@@ -117,7 +122,5 @@ using namespace ttmath;
return 0;
}

View File

@@ -22,6 +22,42 @@ add 192 192 6277101735386680763835789423207666416102355444464034
add 192 192 6277101735386680763835789423207666416102355444464034512895 0 6277101735386680763835789423207666416102355444464034512895 0
# AddInt
# min_bits max_bits bits_per_int a b(int) index result carry
addint 32 0 32 0 0 0 0 0
addint 32 0 32 1000 2000 0 3000 0
addint 64 0 32 562342345 1423445 1 6113650284997065 0
addint 64 0 32 5342342455 3423553423 0 8765895878 0
addint 96 0 32 478895734 46756734 2 862509505820513898647477878 0
addint 128 0 32 27370506140054471803784984408165997441 24543 3 27372450636847059393422542757339093889 0
addint 128 128 32 340282366841711102552375003685868034945 2234543 3 177038656721750864719686733515479937 1
addint 160 160 32 1461501637330902918124457471805283415910032366465 3 3 158457126631793409034731674497 1
addint 192 0 32 6277101735386680763835789423128439055191355840718134336385 3354 1 6277101735386680763835789423128439055191355855123454647169 0
addint 192 192 32 6277101735386680763835789423128439055191355840718134336385 3354 5 4901876491607848387655079701569502248322251848964993 1
addint 64 0 64 0 0 0 0 0
addint 64 0 64 5342342 345534234 0 350876576 0
addint 64 0 64 5342342455 34235534234 0 39577876689 0
addint 64 64 64 18446744073709550615 2000 0 999 1
addint 128 0 64 42895062544824211012058135 3453234 0 42895062544824211015511369 0
addint 128 0 64 42895062544824211012058135 456234234 1 8458931214807741031021280279 0
addint 128 128 64 340282366920938426569886460012664978455 45623 1 804702316727431770143767 1
addint 192 192 64 6277101735386680763835789423207666379208867297044931279895 45623234 1 841563227924816702308613143 1
addint 192 192 64 6277101735386679588840776445207152040176347835149297122327 45623234 2 15523607057094857017675614218510090830281178135 1
addint 192 192 64 6277101735386680763835789423207666416102355444464034512895 1 0 0 1

View File

@@ -46,9 +46,9 @@ void UIntTest::set_file_name(const std::string & f)
}
int UIntTest::read_int()
uuint UIntTest::read_uint()
{
int result = 0;
uuint result = 0;
skip_white_characters();
@@ -60,39 +60,55 @@ return result;
template<unsigned int type_size>
void UIntTest::test_add()
bool UIntTest::check_minmax_bits(int type_size)
{
using namespace ttmath;
UInt<type_size> a,b,result, new_result;
int min_bits = read_int();
int max_bits = read_int();
int min_bits = read_uint();
int max_bits = read_uint();
if( min_bits != 0 && type_size * TTMATH_BITS_PER_UINT < (unsigned int)min_bits )
return;
return false;
if( max_bits != 0 && type_size * TTMATH_BITS_PER_UINT > (unsigned int)max_bits )
return;
return false;
a.FromString(pline, 10, &pline);
b.FromString(pline, 10, &pline);
result.FromString(pline, 10, &pline);
int carry = read_int();
return true;
}
std::cerr << '[' << row << "] Add<" << type_size << ">: ";
bool UIntTest::check_minmax_bits_bitperint(int type_size)
{
if( !check_minmax_bits(type_size) )
return false;
int bits = read_uint();
if( TTMATH_BITS_PER_UINT != bits )
return false;
return true;
}
bool UIntTest::check_end()
{
skip_white_characters();
if( *pline!='#' && *pline!= 0 )
{
std::cerr << "syntax error" << std::endl;
return;
return false;
}
new_result = a;
int new_carry = new_result.Add(b);
bool ok = true;
return true;
}
template<uuint type_size>
bool UIntTest::check_result_carry(const ttmath::UInt<type_size> & result, const ttmath::UInt<type_size> & new_result,
int carry, int new_carry)
{
bool ok = true;
if( new_carry != carry )
{
@@ -106,15 +122,67 @@ using namespace ttmath;
ok = false;
}
if( ok )
{
std::cerr << "ok" << std::endl;
}
return ok;
}
template<uuint type_size>
void UIntTest::test_add()
{
UInt<type_size> a,b,result, new_result;
if( !check_minmax_bits(type_size) )
return;
a.FromString(pline, 10, &pline);
b.FromString(pline, 10, &pline);
result.FromString(pline, 10, &pline);
int carry = read_uint();
std::cerr << '[' << row << "] Add<" << type_size << ">: ";
if( !check_end() )
return;
new_result = a;
int new_carry = new_result.Add(b);
if( check_result_carry(result, new_result, carry, new_carry) )
std::cerr << "ok" << std::endl;
}
template<uuint type_size>
void UIntTest::test_addint()
{
UInt<type_size> a, result, new_result;
if( !check_minmax_bits_bitperint(type_size) )
return;
a.FromString(pline, 10, &pline);
uuint b = read_uint();
uuint index = read_uint();
result.FromString(pline, 10, &pline);
int carry = read_uint();
std::cerr << '[' << row << "] AddInt<" << type_size << ">: ";
if( !check_end() )
return;
new_result = a;
int new_carry = new_result.AddInt(b, index);
if( check_result_carry(result, new_result, carry, new_carry) )
std::cerr << "ok" << std::endl;
}
int UIntTest::upper_char(int c)
{
if( c>='a' && c<='z' )
@@ -191,6 +259,19 @@ const char * p = pline;
pline = p; test_add<9>();
}
else
if( method == "ADDINT" )
{
pline = p; test_addint<1>();
pline = p; test_addint<2>();
pline = p; test_addint<3>();
pline = p; test_addint<4>();
pline = p; test_addint<5>();
pline = p; test_addint<6>();
pline = p; test_addint<7>();
pline = p; test_addint<8>();
pline = p; test_addint<9>();
}
else
{
std::cerr << '[' << row << "] ";
std::cerr << "method " << method << " is not supported" << std::endl;

View File

@@ -45,7 +45,8 @@
#include <ttmath/ttmath.h>
using namespace ttmath;
typedef ttmath::uint uuint;
class UIntTest
@@ -70,8 +71,11 @@ public:
void go();
template<unsigned int type_size>
void test_add();
template<uuint type_size> void test_add();
template<uuint type_size> void test_addint();
template<uuint type_size> bool check_result_carry(const ttmath::UInt<type_size> & result, const ttmath::UInt<type_size> & new_result,
int carry, int new_carry);
int upper_char(int c);
@@ -80,8 +84,10 @@ void skip_white_characters();
bool read_method();
void test_method();
bool check_line();
int read_int();
uuint read_uint();
bool check_minmax_bits(int type_size);
bool check_minmax_bits_bitperint(int type_size);
bool check_end();
};