Oh FFS. LOAD_CLOCK.

This commit is contained in:
Ben Vanik 2014-01-08 00:12:22 -08:00
parent a8ade5d33b
commit 894f22cd0b
7 changed files with 40 additions and 7 deletions

View File

@ -1138,6 +1138,19 @@ int Translate_LOAD_VECTOR_SHR(TranslationContext& ctx, Instr* i) {
return DispatchToC(ctx, i, IntCode_LOAD_VECTOR_SHR); return DispatchToC(ctx, i, IntCode_LOAD_VECTOR_SHR);
} }
uint32_t IntCode_LOAD_CLOCK(IntCodeState& ics, const IntCode* i) {
LARGE_INTEGER counter;
uint64_t time = 0;
if (QueryPerformanceCounter(&counter)) {
time = counter.QuadPart;
}
ics.rf[i->dest_reg].i64 = time;
return IA_NEXT;
}
int Translate_LOAD_CLOCK(TranslationContext& ctx, Instr* i) {
return DispatchToC(ctx, i, IntCode_LOAD_CLOCK);
}
uint32_t IntCode_LOAD_CONTEXT_I8(IntCodeState& ics, const IntCode* i) { uint32_t IntCode_LOAD_CONTEXT_I8(IntCodeState& ics, const IntCode* i) {
ics.rf[i->dest_reg].i8 = *((int8_t*)(ics.context + ics.rf[i->src1_reg].u64)); ics.rf[i->dest_reg].i8 = *((int8_t*)(ics.context + ics.rf[i->src1_reg].u64));
DPRINT("%d (%.X) = ctx i8 +%d\n", ics.rf[i->dest_reg].i8, ics.rf[i->dest_reg].u8, ics.rf[i->src1_reg].u64); DPRINT("%d (%.X) = ctx i8 +%d\n", ics.rf[i->dest_reg].i8, ics.rf[i->dest_reg].u8, ics.rf[i->src1_reg].u64);
@ -3434,6 +3447,8 @@ static const TranslateFn dispatch_table[] = {
Translate_LOAD_VECTOR_SHL, Translate_LOAD_VECTOR_SHL,
Translate_LOAD_VECTOR_SHR, Translate_LOAD_VECTOR_SHR,
Translate_LOAD_CLOCK,
Translate_LOAD_CONTEXT, Translate_LOAD_CONTEXT,
Translate_STORE_CONTEXT, Translate_STORE_CONTEXT,

View File

@ -230,6 +230,12 @@ void alloy::backend::x64::lowering::RegisterSequences(LoweringTable* table) {
return true; return true;
}); });
table->AddSequence(OPCODE_LOAD_CLOCK, [](LIRBuilder& lb, Instr*& instr) {
// TODO
instr = instr->next;
return true;
});
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Context // Context
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View File

@ -498,13 +498,7 @@ XEEMITTER(mfspr, 0x7C0002A6, XFX)(PPCHIRBuilder& f, InstrData& i) {
} }
XEEMITTER(mftb, 0x7C0002E6, XFX)(PPCHIRBuilder& f, InstrData& i) { XEEMITTER(mftb, 0x7C0002E6, XFX)(PPCHIRBuilder& f, InstrData& i) {
Value* time; Value* time = f.LoadClock();
LARGE_INTEGER counter;
if (QueryPerformanceCounter(&counter)) {
time = f.LoadConstant(counter.QuadPart);
} else {
time = f.LoadZero(INT64_TYPE);
}
f.StoreGPR(i.XFX.RT, time); f.StoreGPR(i.XFX.RT, time);
return 0; return 0;

View File

@ -848,6 +848,14 @@ Value* HIRBuilder::LoadVectorShr(Value* sh) {
return i->dest; return i->dest;
} }
Value* HIRBuilder::LoadClock() {
Instr* i = AppendInstr(
OPCODE_LOAD_CLOCK_info, 0,
AllocValue(INT64_TYPE));
i->src1.value = i->src2.value = i->src3.value = NULL;
return i->dest;
}
Value* HIRBuilder::LoadContext(size_t offset, TypeName type) { Value* HIRBuilder::LoadContext(size_t offset, TypeName type) {
Instr* i = AppendInstr( Instr* i = AppendInstr(
OPCODE_LOAD_CONTEXT_info, 0, OPCODE_LOAD_CONTEXT_info, 0,

View File

@ -117,6 +117,8 @@ public:
Value* LoadVectorShl(Value* sh); Value* LoadVectorShl(Value* sh);
Value* LoadVectorShr(Value* sh); Value* LoadVectorShr(Value* sh);
Value* LoadClock();
Value* LoadContext(size_t offset, TypeName type); Value* LoadContext(size_t offset, TypeName type);
void StoreContext(size_t offset, Value* value); void StoreContext(size_t offset, Value* value);

View File

@ -101,6 +101,8 @@ enum Opcode {
OPCODE_LOAD_VECTOR_SHL, OPCODE_LOAD_VECTOR_SHL,
OPCODE_LOAD_VECTOR_SHR, OPCODE_LOAD_VECTOR_SHR,
OPCODE_LOAD_CLOCK,
OPCODE_LOAD_CONTEXT, OPCODE_LOAD_CONTEXT,
OPCODE_STORE_CONTEXT, OPCODE_STORE_CONTEXT,

View File

@ -170,6 +170,12 @@ DEFINE_OPCODE(
OPCODE_SIG_V_V, OPCODE_SIG_V_V,
0); 0);
DEFINE_OPCODE(
OPCODE_LOAD_CLOCK,
"load_clock",
OPCODE_SIG_V,
0);
DEFINE_OPCODE( DEFINE_OPCODE(
OPCODE_LOAD_CONTEXT, OPCODE_LOAD_CONTEXT,
"load_context", "load_context",