CodeGen: Moved to another repository.

git-svn-id: http://svn.purei.org/purei/trunk@675 b36208d7-6611-0410-8bec-b1987f11c4a2
This commit is contained in:
jpd002 2010-06-24 02:07:39 +00:00
parent bcd81d5397
commit 6d1c1940f8
13 changed files with 0 additions and 735 deletions

View File

@ -1,64 +0,0 @@
#include "CompareTest.h"
#include "MemStream.h"
CCompareTest::CCompareTest()
: m_function(NULL)
{
}
CCompareTest::~CCompareTest()
{
}
void CCompareTest::Run()
{
memset(&m_context, 0, sizeof(m_context));
m_context.number1 = 0x80000000;
m_context.number2 = 0x10;
m_context.number3 = 0x10000;
(*m_function)(&m_context);
TEST_VERIFY(m_context.number1 == 0x10000);
TEST_VERIFY(m_context.number3 == 0);
}
void CCompareTest::Compile(Jitter::CJitter& jitter)
{
if(m_function != NULL) return;
Framework::CMemStream codeStream;
jitter.SetStream(&codeStream);
jitter.Begin();
{
//number1 = ((number1 >> number2) < -1) << number2
jitter.PushRel(offsetof(CONTEXT, number1));
jitter.PushRel(offsetof(CONTEXT, number2));
jitter.Sra();
jitter.PushCst(0xFFFFFFFF);
jitter.Cmp(Jitter::CONDITION_LT);
//jitter.PushTop();
//jitter.PullRel(offsetof(CONTEXT, number4));
jitter.PushRel(offsetof(CONTEXT, number2));
jitter.Shl();
jitter.PullRel(offsetof(CONTEXT, number1));
//number3 = number1 != number3
jitter.PushRel(offsetof(CONTEXT, number1));
jitter.PushRel(offsetof(CONTEXT, number3));
jitter.Cmp(Jitter::CONDITION_NE);
jitter.PullRel(offsetof(CONTEXT, number3));
}
jitter.End();
m_function = new CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize());
}

View File

@ -1,30 +0,0 @@
#ifndef _COMPARETEST_H_
#define _COMPARETEST_H_
#include "Test.h"
#include "../MemoryFunction.h"
class CCompareTest : public CTest
{
public:
CCompareTest();
virtual ~CCompareTest();
void Run();
void Compile(Jitter::CJitter&);
private:
struct CONTEXT
{
uint32 number1;
uint32 number2;
uint32 number3;
uint32 number4;
uint32 number5;
};
CONTEXT m_context;
CMemoryFunction* m_function;
};
#endif

View File

@ -1,169 +0,0 @@
#include "Crc32Test.h"
#include "MemStream.h"
bool CCrc32Test::m_tableBuilt = false;
uint32 CCrc32Test::m_table[0x100];
CCrc32Test::CCrc32Test(const char* input, uint32 result)
: m_testFunction(NULL)
, m_computeFunction(NULL)
, m_input(input)
, m_inputPtr(0)
, m_result(result)
{
}
CCrc32Test::~CCrc32Test()
{
delete m_testFunction;
delete m_computeFunction;
}
void CCrc32Test::Run()
{
m_inputPtr = 0;
memset(&m_context, 0, sizeof(m_context));
m_context.state = STATE_TEST;
m_context.testCase = this;
while(m_context.state != STATE_DONE)
{
CMemoryFunction* function(NULL);
switch(m_context.state)
{
case STATE_TEST:
function = m_testFunction;
break;
case STATE_COMPUTE:
function = m_computeFunction;
break;
}
assert(function != NULL);
(*function)(&m_context);
}
TEST_VERIFY(m_context.currentCrc == m_result);
}
void CCrc32Test::Compile(Jitter::CJitter& jitter)
{
BuildTable();
CompileTestFunction(jitter);
CompileComputeFunction(jitter);
}
void CCrc32Test::CompileTestFunction(Jitter::CJitter& jitter)
{
if(m_testFunction != NULL) return;
//b = GetByte()
//if(b == 0)
// done
Framework::CMemStream codeStream;
jitter.SetStream(&codeStream);
jitter.Begin();
{
jitter.PushCtx();
jitter.Call(reinterpret_cast<void*>(&CCrc32Test::GetNextByte), 1, true);
jitter.PullRel(offsetof(CONTEXT, nextByte));
jitter.PushRel(offsetof(CONTEXT, nextByte));
jitter.PushCst(0);
jitter.BeginIf(Jitter::CONDITION_EQ);
{
jitter.PushCst(STATE_DONE);
jitter.PullRel(offsetof(CONTEXT, state));
}
jitter.Else();
{
jitter.PushCst(STATE_COMPUTE);
jitter.PullRel(offsetof(CONTEXT, state));
}
jitter.EndIf();
}
jitter.End();
m_testFunction = new CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize());
}
void CCrc32Test::CompileComputeFunction(Jitter::CJitter& jitter)
{
if(m_computeFunction != NULL) return;
//t = b ^ crc
//tv = GetTable(t)
//t = crc >> 8
//crc = t ^ tv
Framework::CMemStream codeStream;
jitter.SetStream(&codeStream);
jitter.Begin();
{
jitter.PushRel(offsetof(CONTEXT, nextByte));
jitter.PushRel(offsetof(CONTEXT, currentCrc));
jitter.Xor();
jitter.Call(reinterpret_cast<void*>(&CCrc32Test::GetTableValue), 1, true);
jitter.PushRel(offsetof(CONTEXT, currentCrc));
jitter.Srl(8);
jitter.Xor();
jitter.PullRel(offsetof(CONTEXT, currentCrc));
jitter.PushCst(STATE_TEST);
jitter.PullRel(offsetof(CONTEXT, state));
}
jitter.End();
m_computeFunction = new CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize());
}
uint32 CCrc32Test::GetNextByte(CONTEXT* context)
{
return context->testCase->GetNextByteImpl();
}
uint32 CCrc32Test::GetNextByteImpl()
{
return m_input[m_inputPtr++];
}
uint32 CCrc32Test::GetTableValue(uint32 index)
{
assert(m_tableBuilt);
return m_table[index & 0xFF];
}
void CCrc32Test::BuildTable()
{
if(m_tableBuilt) return;
uint32 polynomial = 0xEDB88320;
for(uint32 i = 0; i < 256; i++)
{
uint32 crc = i;
for(int j = 8; j > 0; j--)
{
if(crc & 1)
crc = (crc >> 1) ^ polynomial;
else
crc >>= 1;
}
m_table[i] = crc;
}
m_tableBuilt = true;
}

View File

@ -1,55 +0,0 @@
#ifndef _CRC32TEST_H_
#define _CRC32TEST_H_
#include "Test.h"
#include "../MemoryFunction.h"
#include <string>
class CCrc32Test : public CTest
{
public:
CCrc32Test(const char*, uint32);
virtual ~CCrc32Test();
void Run();
void Compile(Jitter::CJitter&);
private:
enum STATE
{
STATE_TEST,
STATE_COMPUTE,
STATE_DONE,
};
struct CONTEXT
{
uint32 nextByte;
uint32 currentCrc;
uint32 state;
CCrc32Test* testCase;
};
void CompileTestFunction(Jitter::CJitter&);
void CompileComputeFunction(Jitter::CJitter&);
static uint32 GetNextByte(CONTEXT*);
uint32 GetNextByteImpl();
static uint32 GetTableValue(uint32);
CONTEXT m_context;
CMemoryFunction* m_testFunction;
CMemoryFunction* m_computeFunction;
static void BuildTable();
static bool m_tableBuilt;
static uint32 m_table[0x100];
std::string m_input;
unsigned int m_inputPtr;
uint32 m_result;
};
#endif

View File

@ -1,62 +0,0 @@
#include "FpuTest.h"
#include "MemStream.h"
CFpuTest::CFpuTest()
{
}
CFpuTest::~CFpuTest()
{
delete m_function;
}
void CFpuTest::Compile(Jitter::CJitter& jitter)
{
Framework::CMemStream codeStream;
jitter.SetStream(&codeStream);
jitter.Begin();
{
jitter.FP_PushSingle(offsetof(CONTEXT, number1));
jitter.FP_PushSingle(offsetof(CONTEXT, number2));
jitter.FP_Add();
jitter.FP_PullSingle(offsetof(CONTEXT, number1));
jitter.FP_PushSingle(offsetof(CONTEXT, number2));
jitter.FP_PushSingle(offsetof(CONTEXT, number1));
jitter.FP_Div();
jitter.FP_PullSingle(offsetof(CONTEXT, number1));
jitter.FP_PushSingle(offsetof(CONTEXT, number1));
jitter.FP_Rcpl();
jitter.FP_PullSingle(offsetof(CONTEXT, number1));
jitter.FP_PushSingle(offsetof(CONTEXT, number1));
jitter.FP_Neg();
jitter.FP_PullSingle(offsetof(CONTEXT, number2));
jitter.FP_PushSingle(offsetof(CONTEXT, number2));
jitter.FP_PushSingle(offsetof(CONTEXT, number2));
jitter.FP_Mul();
jitter.FP_PullSingle(offsetof(CONTEXT, number3));
jitter.FP_PushSingle(offsetof(CONTEXT, number3));
jitter.FP_Sqrt();
jitter.FP_PullSingle(offsetof(CONTEXT, number3));
}
jitter.End();
m_function = new CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize());
}
void CFpuTest::Run()
{
memset(&m_context, 0, sizeof(CONTEXT));
m_context.number1 = 1.0;
m_context.number2 = 2.0;
(*m_function)(&m_context);
TEST_VERIFY(m_context.number1 == 1.5f);
TEST_VERIFY(m_context.number2 == -1.5f);
TEST_VERIFY(m_context.number1 == m_context.number3);
}

View File

@ -1,29 +0,0 @@
#ifndef _FPUTEST_H_
#define _FPUTEST_H_
#include "Test.h"
#include "../MemoryFunction.h"
class CFpuTest : public CTest
{
public:
CFpuTest();
virtual ~CFpuTest();
void Compile(Jitter::CJitter&);
void Run();
private:
struct CONTEXT
{
float number1;
float number2;
float number3;
};
bool m_useConstant;
CONTEXT m_context;
CMemoryFunction* m_function;
};
#endif

View File

@ -1,97 +0,0 @@
#include "MultTest.h"
#include "MemStream.h"
CMultTest::CMultTest(bool isSigned)
: m_function(NULL)
, m_isSigned(isSigned)
{
}
CMultTest::~CMultTest()
{
}
void CMultTest::Run()
{
memset(&m_context, 0, sizeof(m_context));
m_context.relArg0 = 0xFFFF8000;
m_context.relArg1 = 0x8000FFFF;
(*m_function)(&m_context);
if(!m_isSigned)
{
TEST_VERIFY(m_context.cstResultLo == 0x30200000);
TEST_VERIFY(m_context.cstResultHi == 0x20205020);
TEST_VERIFY(m_context.relResultLo == 0x80008000);
TEST_VERIFY(m_context.relResultHi == 0x8000BFFE);
}
else
{
TEST_VERIFY(m_context.cstResultLo == 0x30200000);
TEST_VERIFY(m_context.cstResultHi == 0xDFDFD020);
TEST_VERIFY(m_context.relResultLo == 0x80008000);
TEST_VERIFY(m_context.relResultHi == 0x00003FFF);
}
}
void CMultTest::Compile(Jitter::CJitter& jitter)
{
if(m_function != NULL) return;
Framework::CMemStream codeStream;
jitter.SetStream(&codeStream);
jitter.Begin();
{
//Cst x Cst
jitter.PushCst(0x80004040);
jitter.PushCst(0x40408000);
if(m_isSigned)
{
jitter.MultS();
}
else
{
jitter.Mult();
}
jitter.PushTop();
jitter.ExtLow64();
jitter.PullRel(offsetof(CONTEXT, cstResultLo));
jitter.ExtHigh64();
jitter.PullRel(offsetof(CONTEXT, cstResultHi));
//Rel x Rel
jitter.PushRel(offsetof(CONTEXT, relArg0));
jitter.PushRel(offsetof(CONTEXT, relArg1));
if(m_isSigned)
{
jitter.MultS();
}
else
{
jitter.Mult();
}
jitter.PushTop();
jitter.ExtLow64();
jitter.PullRel(offsetof(CONTEXT, relResultLo));
jitter.ExtHigh64();
jitter.PullRel(offsetof(CONTEXT, relResultHi));
}
jitter.End();
m_function = new CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize());
}

View File

@ -1,34 +0,0 @@
#ifndef _MULTTEST_H_
#define _MULTTEST_H_
#include "Test.h"
#include "../MemoryFunction.h"
class CMultTest : public CTest
{
public:
CMultTest(bool);
virtual ~CMultTest();
void Run();
void Compile(Jitter::CJitter&);
private:
struct CONTEXT
{
uint32 cstResultLo;
uint32 cstResultHi;
uint32 relArg0;
uint32 relArg1;
uint32 relResultLo;
uint32 relResultHi;
};
bool m_isSigned;
CONTEXT m_context;
CMemoryFunction* m_function;
};
#endif

View File

@ -1,56 +0,0 @@
#include "RandomAluTest.h"
#include "MemStream.h"
#define TEST_NUMBER (23)
CRandomAluTest::CRandomAluTest(bool useConstant)
: m_useConstant(useConstant)
, m_function(NULL)
{
}
CRandomAluTest::~CRandomAluTest()
{
delete m_function;
}
void CRandomAluTest::Compile(Jitter::CJitter& jitter)
{
Framework::CMemStream codeStream;
jitter.SetStream(&codeStream);
jitter.Begin();
{
if(m_useConstant)
{
jitter.PushCst(TEST_NUMBER);
}
else
{
jitter.PushRel(offsetof(CONTEXT, number));
}
jitter.PushCst(4);
jitter.Div();
jitter.PushCst(34);
jitter.Sub();
jitter.PushCst(0xFFFF00FF);
jitter.And();
jitter.PullRel(offsetof(CONTEXT, number));
}
jitter.End();
m_function = new CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize());
}
void CRandomAluTest::Run()
{
memset(&m_context, 0, sizeof(CONTEXT));
m_context.number = TEST_NUMBER;
(*m_function)(&m_context);
TEST_VERIFY(m_context.number == 0xFFFF00E3);
}

View File

@ -1,27 +0,0 @@
#ifndef _RANDOMALUTEST_H_
#define _RANDOMALUTEST_H_
#include "Test.h"
#include "../MemoryFunction.h"
class CRandomAluTest : public CTest
{
public:
CRandomAluTest(bool);
virtual ~CRandomAluTest();
void Compile(Jitter::CJitter&);
void Run();
private:
struct CONTEXT
{
uint32 number;
};
bool m_useConstant;
CONTEXT m_context;
CMemoryFunction* m_function;
};
#endif

View File

@ -1,66 +0,0 @@
#include "RandomAluTest2.h"
#include "MemStream.h"
#define TEST_NUMBER1 (0xFF00FF00)
#define TEST_NUMBER2 (0x8888FFFF)
CRandomAluTest2::CRandomAluTest2(bool useConstant)
: m_useConstant(useConstant)
, m_function(NULL)
{
}
CRandomAluTest2::~CRandomAluTest2()
{
delete m_function;
}
void CRandomAluTest2::Compile(Jitter::CJitter& jitter)
{
Framework::CMemStream codeStream;
jitter.SetStream(&codeStream);
jitter.Begin();
{
if(m_useConstant)
{
jitter.PushCst(TEST_NUMBER1);
}
else
{
jitter.PushRel(offsetof(CONTEXT, number1));
}
jitter.Not();
jitter.SignExt8();
jitter.PushCst(0);
if(m_useConstant)
{
jitter.PushCst(TEST_NUMBER2);
}
else
{
jitter.PushRel(offsetof(CONTEXT, number2));
}
jitter.SignExt16();
jitter.Sub();
jitter.Add();
jitter.PullRel(offsetof(CONTEXT, result));
}
jitter.End();
m_function = new CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize());
}
void CRandomAluTest2::Run()
{
memset(&m_context, 0, sizeof(CONTEXT));
m_context.number1 = TEST_NUMBER1;
m_context.number2 = TEST_NUMBER2;
m_context.result = -1;
(*m_function)(&m_context);
TEST_VERIFY(m_context.result == 0);
}

View File

@ -1,29 +0,0 @@
#ifndef _RANDOMALUTEST2_H_
#define _RANDOMALUTEST2_H_
#include "Test.h"
#include "../MemoryFunction.h"
class CRandomAluTest2 : public CTest
{
public:
CRandomAluTest2(bool);
virtual ~CRandomAluTest2();
void Compile(Jitter::CJitter&);
void Run();
private:
struct CONTEXT
{
uint32 number1;
uint32 number2;
uint32 result;
};
bool m_useConstant;
CONTEXT m_context;
CMemoryFunction* m_function;
};
#endif

View File

@ -1,17 +0,0 @@
#ifndef _TEST_H_
#define _TEST_H_
#include "../Jitter.h"
#define TEST_VERIFY(a) if(!(a)) { int* p = 0; (*p) = 0; }
class CTest
{
public:
virtual ~CTest() {}
virtual void Run() = 0;
virtual void Compile(Jitter::CJitter&) = 0;
};
#endif