mirror of
https://github.com/libretro/Play-.git
synced 2025-01-09 18:10:57 +00:00
CodeGen:
Moved tests to seperate folder. Added ArmAssembler and CodeGen_Arm. git-svn-id: http://svn.purei.org/purei/trunk@664 b36208d7-6611-0410-8bec-b1987f11c4a2
This commit is contained in:
parent
ea37977b04
commit
8b5e8c0d39
@ -1,15 +1,9 @@
|
||||
#include <assert.h>
|
||||
#include "ArmAssembler.h"
|
||||
|
||||
CArmAssembler::CArmAssembler(
|
||||
const WriteFunctionType& WriteFunction,
|
||||
const WriteAtFunctionType& WriteAtFunction,
|
||||
const TellFunctionType& TellFunction
|
||||
) :
|
||||
m_WriteFunction(WriteFunction),
|
||||
m_WriteAtFunction(WriteAtFunction),
|
||||
m_TellFunction(TellFunction),
|
||||
m_nextLabelId(1)
|
||||
CArmAssembler::CArmAssembler() :
|
||||
m_nextLabelId(1),
|
||||
m_stream(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
@ -19,6 +13,11 @@ CArmAssembler::~CArmAssembler()
|
||||
|
||||
}
|
||||
|
||||
void CArmAssembler::SetStream(Framework::CStream* stream)
|
||||
{
|
||||
m_stream = stream;
|
||||
}
|
||||
|
||||
CArmAssembler::LdrAddress CArmAssembler::MakeImmediateLdrAddress(uint32 immediate)
|
||||
{
|
||||
LdrAddress result;
|
||||
@ -68,9 +67,14 @@ CArmAssembler::LABEL CArmAssembler::CreateLabel()
|
||||
return m_nextLabelId++;
|
||||
}
|
||||
|
||||
void CArmAssembler::ClearLabels()
|
||||
{
|
||||
m_labels.clear();
|
||||
}
|
||||
|
||||
void CArmAssembler::MarkLabel(LABEL label)
|
||||
{
|
||||
m_labels[label] = m_TellFunction();
|
||||
m_labels[label] = static_cast<size_t>(m_stream->Tell());
|
||||
}
|
||||
|
||||
void CArmAssembler::ResolveLabelReferences()
|
||||
@ -88,16 +92,19 @@ void CArmAssembler::ResolveLabelReferences()
|
||||
int offset = static_cast<int>(labelPos - referencePos) / 4;
|
||||
assert(offset >= 2);
|
||||
offset -= 2;
|
||||
m_WriteAtFunction(static_cast<unsigned int>(referencePos + 0), static_cast<uint8>(offset >> 0));
|
||||
m_WriteAtFunction(static_cast<unsigned int>(referencePos + 1), static_cast<uint8>(offset >> 8));
|
||||
m_WriteAtFunction(static_cast<unsigned int>(referencePos + 2), static_cast<uint8>(offset >> 16));
|
||||
|
||||
m_stream->Seek(referencePos, Framework::STREAM_SEEK_SET);
|
||||
m_stream->Write8(static_cast<uint8>(offset >> 0));
|
||||
m_stream->Write8(static_cast<uint8>(offset >> 8));
|
||||
m_stream->Write8(static_cast<uint8>(offset >> 16));
|
||||
m_stream->Seek(0, Framework::STREAM_SEEK_END);
|
||||
}
|
||||
m_labelReferences.clear();
|
||||
}
|
||||
|
||||
void CArmAssembler::CreateLabelReference(LABEL label)
|
||||
{
|
||||
LABELREF reference = m_TellFunction();
|
||||
LABELREF reference = static_cast<size_t>(m_stream->Tell());
|
||||
m_labelReferences.insert(LabelReferenceMapType::value_type(label, reference));
|
||||
}
|
||||
|
||||
@ -324,8 +331,5 @@ void CArmAssembler::Teq(REGISTER rn, const ImmediateAluOperand& operand)
|
||||
|
||||
void CArmAssembler::WriteWord(uint32 value)
|
||||
{
|
||||
m_WriteFunction(reinterpret_cast<uint8*>(&value)[0]);
|
||||
m_WriteFunction(reinterpret_cast<uint8*>(&value)[1]);
|
||||
m_WriteFunction(reinterpret_cast<uint8*>(&value)[2]);
|
||||
m_WriteFunction(reinterpret_cast<uint8*>(&value)[3]);
|
||||
m_stream->Write32(value);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include "Stream.h"
|
||||
#include "Types.h"
|
||||
|
||||
class CArmAssembler
|
||||
@ -81,10 +82,6 @@ public:
|
||||
SHIFT_ROR = 0x03,
|
||||
};
|
||||
|
||||
typedef std::tr1::function<void (uint8)> WriteFunctionType;
|
||||
typedef std::tr1::function<void (unsigned int, uint8)> WriteAtFunctionType;
|
||||
typedef std::tr1::function<size_t ()> TellFunctionType;
|
||||
|
||||
struct InstructionAlu
|
||||
{
|
||||
InstructionAlu()
|
||||
@ -156,14 +153,13 @@ public:
|
||||
typedef unsigned int LABEL;
|
||||
|
||||
|
||||
CArmAssembler(
|
||||
const WriteFunctionType&,
|
||||
const WriteAtFunctionType&,
|
||||
const TellFunctionType&);
|
||||
|
||||
CArmAssembler();
|
||||
virtual ~CArmAssembler();
|
||||
|
||||
void SetStream(Framework::CStream*);
|
||||
|
||||
LABEL CreateLabel();
|
||||
void ClearLabels();
|
||||
void MarkLabel(LABEL);
|
||||
void ResolveLabelReferences();
|
||||
|
||||
@ -207,9 +203,7 @@ private:
|
||||
LabelMapType m_labels;
|
||||
LabelReferenceMapType m_labelReferences;
|
||||
|
||||
WriteFunctionType m_WriteFunction;
|
||||
WriteAtFunctionType m_WriteAtFunction;
|
||||
TellFunctionType m_TellFunction;
|
||||
Framework::CStream* m_stream;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
51
tools/CodeGen/Source/Jitter_CodeGen_Arm.cpp
Normal file
51
tools/CodeGen/Source/Jitter_CodeGen_Arm.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "Jitter_CodeGen_Arm.h"
|
||||
|
||||
using namespace Jitter;
|
||||
|
||||
CCodeGen_Arm::CCodeGen_Arm()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CCodeGen_Arm::~CCodeGen_Arm()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
unsigned int CCodeGen_Arm::GetAvailableRegisterCount() const
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
void CCodeGen_Arm::SetStream(Framework::CStream* stream)
|
||||
{
|
||||
m_assembler.SetStream(stream);
|
||||
}
|
||||
|
||||
void CCodeGen_Arm::GenerateCode(const StatementList& statements, unsigned int stackSize)
|
||||
{
|
||||
//for(StatementList::const_iterator statementIterator(statements.begin());
|
||||
// statementIterator != statements.end(); statementIterator++)
|
||||
//{
|
||||
// const STATEMENT& statement(*statementIterator);
|
||||
|
||||
// bool found = false;
|
||||
// MatcherMapType::const_iterator begin = m_matchers.lower_bound(statement.op);
|
||||
// MatcherMapType::const_iterator end = m_matchers.upper_bound(statement.op);
|
||||
|
||||
// for(MatcherMapType::const_iterator matchIterator(begin); matchIterator != end; matchIterator++)
|
||||
// {
|
||||
// const MATCHER& matcher(matchIterator->second);
|
||||
// if(!SymbolMatches(matcher.dstType, statement.dst)) continue;
|
||||
// if(!SymbolMatches(matcher.src1Type, statement.src1)) continue;
|
||||
// if(!SymbolMatches(matcher.src2Type, statement.src2)) continue;
|
||||
// matcher.emitter(statement);
|
||||
// found = true;
|
||||
// break;
|
||||
// }
|
||||
// assert(found);
|
||||
//}
|
||||
|
||||
m_assembler.ResolveLabelReferences();
|
||||
m_assembler.ClearLabels();
|
||||
}
|
68
tools/CodeGen/Source/Jitter_CodeGen_Arm.h
Normal file
68
tools/CodeGen/Source/Jitter_CodeGen_Arm.h
Normal file
@ -0,0 +1,68 @@
|
||||
#ifndef _JITTER_CODEGEN_ARM_H_
|
||||
#define _JITTER_CODEGEN_ARM_H_
|
||||
|
||||
#include "Jitter_CodeGen.h"
|
||||
#include "ArmAssembler.h"
|
||||
|
||||
namespace Jitter
|
||||
{
|
||||
class CCodeGen_Arm : public CCodeGen
|
||||
{
|
||||
public:
|
||||
CCodeGen_Arm();
|
||||
virtual ~CCodeGen_Arm();
|
||||
|
||||
void GenerateCode(const StatementList&, unsigned int);
|
||||
void SetStream(Framework::CStream*);
|
||||
unsigned int GetAvailableRegisterCount() const;
|
||||
|
||||
private:
|
||||
enum MATCHTYPE
|
||||
{
|
||||
MATCH_ANY,
|
||||
MATCH_NIL,
|
||||
MATCH_CONTEXT,
|
||||
MATCH_CONSTANT,
|
||||
MATCH_REGISTER,
|
||||
MATCH_RELATIVE,
|
||||
MATCH_TEMPORARY,
|
||||
MATCH_RELATIVE64,
|
||||
MATCH_TEMPORARY64,
|
||||
MATCH_CONSTANT64,
|
||||
};
|
||||
|
||||
typedef std::tr1::function<void (const STATEMENT&)> CodeEmitterType;
|
||||
|
||||
struct MATCHER
|
||||
{
|
||||
OPERATION op;
|
||||
MATCHTYPE dstType;
|
||||
MATCHTYPE src1Type;
|
||||
MATCHTYPE src2Type;
|
||||
CodeEmitterType emitter;
|
||||
};
|
||||
|
||||
typedef std::multimap<OPERATION, MATCHER> MatcherMapType;
|
||||
|
||||
typedef void (CCodeGen_Arm::*ConstCodeEmitterType)(const STATEMENT&);
|
||||
|
||||
struct CONSTMATCHER
|
||||
{
|
||||
OPERATION op;
|
||||
MATCHTYPE dstType;
|
||||
MATCHTYPE src1Type;
|
||||
MATCHTYPE src2Type;
|
||||
ConstCodeEmitterType emitter;
|
||||
};
|
||||
|
||||
static CONSTMATCHER g_constMatchers[];
|
||||
|
||||
bool SymbolMatches(MATCHTYPE, const SymbolRefPtr&);
|
||||
CArmAssembler::LABEL GetLabel(uint32);
|
||||
|
||||
MatcherMapType m_matchers;
|
||||
CArmAssembler m_assembler;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
@ -242,6 +242,7 @@ CCodeGen_x86::CONSTMATCHER CCodeGen_x86::g_constMatchers[] =
|
||||
{ OP_XOR, MATCH_REGISTER, MATCH_REGISTER, MATCH_REGISTER, &CCodeGen_x86::Emit_Alu_RegRegReg<ALUOP_XOR> },
|
||||
{ OP_XOR, MATCH_REGISTER, MATCH_RELATIVE, MATCH_REGISTER, &CCodeGen_x86::Emit_Alu_RegRelReg<ALUOP_XOR> },
|
||||
|
||||
{ OP_NOT, MATCH_REGISTER, MATCH_REGISTER, MATCH_NIL, &CCodeGen_x86::Emit_Not_RegReg },
|
||||
{ OP_NOT, MATCH_REGISTER, MATCH_RELATIVE, MATCH_NIL, &CCodeGen_x86::Emit_Not_RegRel },
|
||||
|
||||
{ OP_SRL, MATCH_TEMPORARY, MATCH_REGISTER, MATCH_CONSTANT, &CCodeGen_x86::Emit_Shift_TmpRegCst<SHIFTOP_SRL> },
|
||||
@ -418,6 +419,19 @@ void CCodeGen_x86::Emit_Nop(const STATEMENT& statement)
|
||||
|
||||
}
|
||||
|
||||
void CCodeGen_x86::Emit_Not_RegReg(const STATEMENT& statement)
|
||||
{
|
||||
CSymbol* dst = statement.dst->GetSymbol().get();
|
||||
CSymbol* src1 = statement.src1->GetSymbol().get();
|
||||
|
||||
if(!dst->Equals(src1))
|
||||
{
|
||||
m_assembler.MovEd(m_registers[dst->m_valueLow], CX86Assembler::MakeRegisterAddress(m_registers[src1->m_valueLow]));
|
||||
}
|
||||
|
||||
m_assembler.NotEd(CX86Assembler::MakeRegisterAddress(m_registers[dst->m_valueLow]));
|
||||
}
|
||||
|
||||
void CCodeGen_x86::Emit_Not_RegRel(const STATEMENT& statement)
|
||||
{
|
||||
CSymbol* dst = statement.dst->GetSymbol().get();
|
||||
|
@ -160,6 +160,7 @@ namespace Jitter
|
||||
template <typename> void Emit_Shift_RegRelCst(const STATEMENT&);
|
||||
|
||||
//NOT
|
||||
void Emit_Not_RegReg(const STATEMENT&);
|
||||
void Emit_Not_RegRel(const STATEMENT&);
|
||||
|
||||
//ADD64
|
||||
|
@ -32,7 +32,7 @@ CCodeGen_x86::CONSTMATCHER CCodeGen_x86::g_fpuConstMatchers[] =
|
||||
|
||||
{ OP_FP_RCPL, MATCH_RELATIVE_FP_SINGLE, MATCH_RELATIVE_FP_SINGLE, MATCH_NIL, &CCodeGen_x86::Emit_Fpu_RelRel<FPUOP_RCPL> },
|
||||
|
||||
{ OP_FP_NEG, MATCH_RELATIVE_FP_SINGLE, MATCH_RELATIVE_FP_SINGLE, MATCH_NIL, &CCodeGen_x86::Emit_Fp_Neg_RelRel },
|
||||
// { OP_FP_NEG, MATCH_RELATIVE_FP_SINGLE, MATCH_RELATIVE_FP_SINGLE, MATCH_NIL, &CCodeGen_x86::Emit_Fp_Neg_RelRel },
|
||||
|
||||
{ OP_MOV, MATCH_NIL, MATCH_NIL, MATCH_NIL, NULL },
|
||||
};
|
||||
|
@ -34,6 +34,7 @@ namespace Jitter
|
||||
OP_FP_ADD,
|
||||
OP_FP_DIV,
|
||||
OP_FP_RCPL,
|
||||
OP_FP_NEG,
|
||||
|
||||
OP_PARAM,
|
||||
OP_CALL,
|
||||
|
@ -3,17 +3,18 @@
|
||||
#else
|
||||
#include "Jitter_CodeGen_x86_32.h"
|
||||
#endif
|
||||
#include "Jitter_CodeGen_Arm.h"
|
||||
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/lambda/bind.hpp>
|
||||
#include <boost/lambda/construct.hpp>
|
||||
|
||||
#include "Crc32Test.h"
|
||||
#include "MultTest.h"
|
||||
#include "RandomAluTest.h"
|
||||
#include "RandomAluTest2.h"
|
||||
#include "FpuTest.h"
|
||||
#include "tests/Crc32Test.h"
|
||||
#include "tests/MultTest.h"
|
||||
#include "tests/RandomAluTest.h"
|
||||
#include "tests/RandomAluTest2.h"
|
||||
#include "tests/FpuTest.h"
|
||||
|
||||
typedef boost::function<CTest* ()> TestFactoryFunction;
|
||||
|
||||
@ -34,6 +35,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
#ifdef AMD64
|
||||
Jitter::CJitter jitter(new Jitter::CCodeGen_x86_64());
|
||||
// Jitter::CJitter jitter(new Jitter::CCodeGen_Arm());
|
||||
#elif defined(WIN32)
|
||||
Jitter::CJitter jitter(new Jitter::CCodeGen_x86_32());
|
||||
#endif
|
||||
|
@ -32,9 +32,9 @@ void CFpuTest::Compile(Jitter::CJitter& jitter)
|
||||
jitter.FP_Rcpl();
|
||||
jitter.FP_PullSingle(offsetof(CONTEXT, number1));
|
||||
|
||||
jitter.FP_PushSingle(offsetof(CONTEXT, number2));
|
||||
jitter.FP_Neg();
|
||||
jitter.FP_PullSingle(offsetof(CONTEXT, number2));
|
||||
// jitter.FP_PushSingle(offsetof(CONTEXT, number2));
|
||||
// jitter.FP_Neg();
|
||||
// jitter.FP_PullSingle(offsetof(CONTEXT, number2));
|
||||
}
|
||||
jitter.End();
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef _TEST_H_
|
||||
#define _TEST_H_
|
||||
|
||||
#include "Jitter.h"
|
||||
#include "../Jitter.h"
|
||||
|
||||
#define TEST_VERIFY(a) if(!(a)) { int* p = 0; (*p) = 0; }
|
||||
|
Loading…
Reference in New Issue
Block a user