void CAliasTest2::Compile(Jitter::CJitter& jitter) { Framework::CMemStream codeStream; jitter.SetStream(&codeStream); jitter.Begin(); { jitter.PushCst(CONSTANT_1); jitter.PullRel(offsetof(CONTEXT, value1[0])); jitter.PushCst(CONSTANT_2); jitter.PullRel(offsetof(CONTEXT, value1[1])); jitter.PushCst(CONSTANT_3); jitter.PullRel(offsetof(CONTEXT, value1[2])); jitter.PushCst(CONSTANT_4); jitter.PullRel(offsetof(CONTEXT, value1[3])); jitter.MD_PushRel(offsetof(CONTEXT, value2)); jitter.MD_PushRelExpand(offsetof(CONTEXT, value1[2])); jitter.MD_AddS(); jitter.MD_PullRel(offsetof(CONTEXT, value1), true, true, true, false); //Here value1 should be (3, 3, 3, 4) jitter.MD_PushRel(offsetof(CONTEXT, value2)); jitter.MD_PushRelExpand(offsetof(CONTEXT, value1[2])); jitter.MD_AddS(); jitter.MD_PullRel(offsetof(CONTEXT, value3)); //Here value3 should be (4, 4, 4, 4) } jitter.End(); m_function = CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize()); }
void CMemAccessRefTest::Compile(Jitter::CJitter& jitter) { Framework::CMemStream codeStream; jitter.SetStream(&codeStream); jitter.Begin(); { //Read ref test { jitter.PushRelRef(offsetof(CONTEXT, memory)); jitter.PushCst(LOAD_IDX * sizeof(void*)); jitter.AddRef(); jitter.LoadRefFromRef(); jitter.LoadFromRef(); jitter.PullRel(offsetof(CONTEXT, readValueResult)); } EmitNullTest(jitter, NULLCHECK_IDX, offsetof(CONTEXT, nullCheck0)); EmitNullTest(jitter, LOAD_IDX, offsetof(CONTEXT, nullCheck1)); EmitNullComparison(jitter, NULLCHECK_IDX, offsetof(CONTEXT, nullCheck2)); EmitNullComparison(jitter, LOAD_IDX, offsetof(CONTEXT, nullCheck3)); } jitter.End(); m_function = CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize()); }
void CFpIntMixTest::Compile(Jitter::CJitter& jitter) { Framework::CMemStream codeStream; jitter.SetStream(&codeStream); jitter.Begin(); { //number1 = 100.f jitter.PushCst(0x42C80000); jitter.PullRel(offsetof(CONTEXT, number1)); //number2 = toFloat(multiplier) jitter.FP_PushWord(offsetof(CONTEXT, multiplier)); jitter.FP_PullSingle(offsetof(CONTEXT, number2)); //number1 = number1 * number2 jitter.FP_PushSingle(offsetof(CONTEXT, number1)); jitter.FP_PushSingle(offsetof(CONTEXT, number2)); jitter.FP_Mul(); jitter.FP_PullSingle(offsetof(CONTEXT, number1)); //number1 = toInt(number1) jitter.FP_PushSingle(offsetof(CONTEXT, number1)); jitter.FP_PullWordTruncate(offsetof(CONTEXT, number1)); //result = number1 jitter.PushRel(offsetof(CONTEXT, number1)); jitter.PullRel(offsetof(CONTEXT, result)); } jitter.End(); m_function = CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize()); }
bool CPacketUtils::HasPacket(Framework::CMemStream& stream) { if (stream.GetSize() < sizeof(PACKETHEADER)) { return false; } stream.Seek(0, Framework::STREAM_SEEK_SET); PACKETHEADER header; stream.Read(&header, sizeof(PACKETHEADER)); stream.Seek(0, Framework::STREAM_SEEK_END); if (stream.GetSize() < header.packetSize) { return false; } return true; }
void CMdTest::Compile(Jitter::CJitter& jitter) { Framework::CMemStream codeStream; jitter.SetStream(&codeStream); jitter.Begin(); { jitter.MD_PushRel(offsetof(CONTEXT, src1)); jitter.MD_PullRel(offsetof(CONTEXT, dstMov)); //Shifts jitter.MD_PushRel(offsetof(CONTEXT, src0)); jitter.MD_PushRel(offsetof(CONTEXT, src1)); jitter.PushCst(48); jitter.MD_Srl256(); jitter.MD_PullRel(offsetof(CONTEXT, dstSrl256_1)); jitter.MD_PushRel(offsetof(CONTEXT, src0)); jitter.MD_PushRel(offsetof(CONTEXT, src1)); jitter.PushRel(offsetof(CONTEXT, shiftAmount)); jitter.MD_Srl256(); jitter.MD_PullRel(offsetof(CONTEXT, dstSrl256_2)); //Packs jitter.MD_PushRel(offsetof(CONTEXT, src0)); jitter.MD_PushRel(offsetof(CONTEXT, src1)); jitter.MD_PackHB(); jitter.MD_PullRel(offsetof(CONTEXT, dstPackHB)); jitter.MD_PushRel(offsetof(CONTEXT, src0)); jitter.MD_PushRel(offsetof(CONTEXT, src1)); jitter.MD_PackWH(); jitter.MD_PullRel(offsetof(CONTEXT, dstPackWH)); //Aliased packs jitter.MD_PushRel(offsetof(CONTEXT, dstPackHBAlias)); jitter.MD_PushRel(offsetof(CONTEXT, src1)); jitter.MD_PackHB(); jitter.MD_PullRel(offsetof(CONTEXT, dstPackHBAlias)); jitter.MD_PushRel(offsetof(CONTEXT, dstPackWHAlias)); jitter.MD_PushRel(offsetof(CONTEXT, src1)); jitter.MD_PackWH(); jitter.MD_PullRel(offsetof(CONTEXT, dstPackWHAlias)); } jitter.End(); m_function = CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize()); }
void CSimpleMdTest::Compile(Jitter::CJitter& jitter) { Framework::CMemStream codeStream; jitter.SetStream(&codeStream); jitter.Begin(); { jitter.MD_PushRel(offsetof(CONTEXT, op1)); jitter.MD_PushRel(offsetof(CONTEXT, op2)); jitter.MD_AddW(); jitter.MD_PullRel(offsetof(CONTEXT, result)); } jitter.End(); m_function = CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize()); }
void CMemAccessTest::Compile(Jitter::CJitter& jitter) { Framework::CMemStream codeStream; jitter.SetStream(&codeStream); jitter.Begin(); { //Store test jitter.PushRelRef(offsetof(CONTEXT, memory)); jitter.PushRel(offsetof(CONTEXT, offset)); jitter.AddRef(); jitter.PushCst(CONSTANT_1); jitter.StoreAtRef(); //Read test jitter.PushRelRef(offsetof(CONTEXT, memory)); jitter.PushCst(0x08); jitter.AddRef(); jitter.LoadFromRef(); jitter.PullRel(offsetof(CONTEXT, result0)); //Write array test jitter.PushRelAddrRef(offsetof(CONTEXT, array0)); jitter.PushCst(ARRAY_IDX_0 * 4); jitter.AddRef(); jitter.PushCst(CONSTANT_2); jitter.StoreAtRef(); //Read array test jitter.PushRelAddrRef(offsetof(CONTEXT, array0)); jitter.PushCst(ARRAY_IDX_1 * 4); jitter.AddRef(); jitter.LoadFromRef(); jitter.PullRel(offsetof(CONTEXT, result1)); } jitter.End(); m_function = CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize()); }
std::string CEmbedRemoteCall::ToString() const { auto rpcParamsNode = new Framework::Xml::CNode("Params", true); for(const auto& param : m_params) { auto rpcParamNode = new Framework::Xml::CNode("Param", true); rpcParamNode->InsertAttribute(Framework::Xml::CreateAttributeStringValue("Name", param.first.c_str())); rpcParamNode->InsertAttribute(Framework::Xml::CreateAttributeStringValue("Value", param.second.c_str())); rpcParamsNode->InsertNode(rpcParamNode); } auto rpcNode = std::make_unique<Framework::Xml::CNode>("Call", true); rpcNode->InsertAttribute(Framework::Xml::CreateAttributeStringValue("Method", m_method.c_str())); rpcNode->InsertNode(rpcParamsNode); Framework::CMemStream rpcNodeStream; Framework::Xml::CWriter::WriteDocument(rpcNodeStream, rpcNode.get()); return std::string(rpcNodeStream.GetBuffer(), rpcNodeStream.GetBuffer() + rpcNodeStream.GetSize()); }
void CAlu64Test::Compile(Jitter::CJitter& jitter) { Framework::CMemStream codeStream; jitter.SetStream(&codeStream); jitter.Begin(); { jitter.PushRel64(offsetof(CONTEXT, value0)); jitter.PushRel64(offsetof(CONTEXT, value1)); jitter.Add64(); jitter.PullRel64(offsetof(CONTEXT, resultAdd0)); jitter.PushRel64(offsetof(CONTEXT, value2)); jitter.PushRel64(offsetof(CONTEXT, value3)); jitter.Add64(); jitter.PullRel64(offsetof(CONTEXT, resultAdd1)); jitter.PushRel64(offsetof(CONTEXT, value0)); jitter.PushCst64(CONSTANT_5); jitter.Add64(); jitter.PullRel64(offsetof(CONTEXT, resultAddCst)); jitter.PushRel64(offsetof(CONTEXT, value0)); jitter.PushRel64(offsetof(CONTEXT, value1)); jitter.Sub64(); jitter.PullRel64(offsetof(CONTEXT, resultSub0)); jitter.PushRel64(offsetof(CONTEXT, value2)); jitter.PushRel64(offsetof(CONTEXT, value3)); jitter.Sub64(); jitter.PullRel64(offsetof(CONTEXT, resultSub1)); jitter.PushCst64(CONSTANT_5); jitter.PushRel64(offsetof(CONTEXT, value0)); jitter.Sub64(); jitter.PullRel64(offsetof(CONTEXT, resultSubCst)); } jitter.End(); m_function = CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize()); }
void CMdMemAccessTest::Compile(Jitter::CJitter& jitter) { Framework::CMemStream codeStream; jitter.SetStream(&codeStream); jitter.Begin(); { jitter.PushRelRef(offsetof(CONTEXT, array)); jitter.MD_LoadFromRef(); jitter.MD_PullRel(offsetof(CONTEXT, result)); jitter.PushRelRef(offsetof(CONTEXT, array)); jitter.PushCst(0x10); jitter.AddRef(); jitter.MD_PushRel(offsetof(CONTEXT, op)); jitter.MD_StoreAtRef(); } jitter.End(); m_function = CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize()); }
void CRandomAluTest3::Compile(Jitter::CJitter& jitter) { Framework::CMemStream codeStream; jitter.SetStream(&codeStream); jitter.Begin(); { //a = b ^ a if(m_useConstant) { jitter.PushCst(TEST_NUMBER1); } else { jitter.PushRel(offsetof(CONTEXT, number1)); } if(m_useConstant) { jitter.PushCst(TEST_NUMBER2); } else { jitter.PushRel(offsetof(CONTEXT, number2)); } jitter.Xor(); //b = a jitter.PullRel(offsetof(CONTEXT, number1)); jitter.PushRel(offsetof(CONTEXT, number1)); jitter.PullRel(offsetof(CONTEXT, number2)); } jitter.End(); m_function = CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize()); }
void CMdFpFlagTest::Compile(Jitter::CJitter& jitter) { Framework::CMemStream codeStream; jitter.SetStream(&codeStream); jitter.Begin(); { //0 jitter.MD_PushRel(offsetof(CONTEXT, src0)); jitter.MD_IsNegative(); jitter.PullRel(offsetof(CONTEXT, dstIsNegative0)); jitter.MD_PushRel(offsetof(CONTEXT, src0)); jitter.MD_IsZero(); jitter.PullRel(offsetof(CONTEXT, dstIsZero0)); //1 jitter.MD_PushRel(offsetof(CONTEXT, src1)); jitter.MD_IsNegative(); jitter.PullRel(offsetof(CONTEXT, dstIsNegative1)); jitter.MD_PushRel(offsetof(CONTEXT, src1)); jitter.MD_IsZero(); jitter.PullRel(offsetof(CONTEXT, dstIsZero1)); //2 jitter.MD_PushRel(offsetof(CONTEXT, src2)); jitter.MD_IsNegative(); jitter.PullRel(offsetof(CONTEXT, dstIsNegative2)); jitter.MD_PushRel(offsetof(CONTEXT, src2)); jitter.MD_IsZero(); jitter.PullRel(offsetof(CONTEXT, dstIsZero2)); } jitter.End(); m_function = CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize()); }
void CAliasTest::Compile(Jitter::CJitter& jitter) { Framework::CMemStream codeStream; jitter.SetStream(&codeStream); jitter.Begin(); { jitter.PushCst64(0); jitter.PullRel64(offsetof(CONTEXT, value0)); jitter.PushCst(CONSTANT_1); jitter.PullRel(offsetof(CONTEXT, value0[0])); jitter.PushCst(CONSTANT_2); jitter.PullRel(offsetof(CONTEXT, value0[1])); jitter.PushRel64(offsetof(CONTEXT, value0)); jitter.PushRel64(offsetof(CONTEXT, value1)); jitter.Cmp64(Jitter::CONDITION_EQ); jitter.PullRel(offsetof(CONTEXT, result)); for(unsigned int i = 0; i < 4; i++) { jitter.PushCst(0); jitter.PullRel(offsetof(CONTEXT, value4[i])); } jitter.MD_PushRel(offsetof(CONTEXT, value2)); jitter.MD_PushRel(offsetof(CONTEXT, value3)); jitter.MD_AddWSS(); jitter.MD_PullRel(offsetof(CONTEXT, value4), true, false, false, true); } jitter.End(); m_function = CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize()); }
void CBasicBlock::Compile() { #ifndef AOT_USE_CACHE Framework::CMemStream stream; { static #ifdef AOT_BUILD_CACHE __declspec(thread) #endif CMipsJitter* jitter = nullptr; if(jitter == nullptr) { Jitter::CCodeGen* codeGen = Jitter::CreateCodeGen(); jitter = new CMipsJitter(codeGen); for(unsigned int i = 0; i < 4; i++) { jitter->SetVariableAsConstant( offsetof(CMIPS, m_State.nGPR[CMIPS::R0].nV[i]), 0); } } jitter->SetStream(&stream); jitter->Begin(); CompileRange(jitter); // codeGen.DumpVariables(0); // codeGen.EndQuota(); jitter->End(); } m_function = CMemoryFunction(stream.GetBuffer(), stream.GetSize()); #ifdef VTUNE_ENABLED if(iJIT_IsProfilingActive() == iJIT_SAMPLING_ON) { iJIT_Method_Load jmethod = {}; jmethod.method_id = iJIT_GetNewMethodID(); jmethod.class_file_name = ""; jmethod.source_file_name = __FILE__; jmethod.method_load_address = m_function.GetCode(); jmethod.method_size = m_function.GetSize(); jmethod.line_number_size = 0; auto functionName = string_format("BasicBlock_0x%08X_0x%08X", m_begin, m_end); jmethod.method_name = const_cast<char*>(functionName.c_str()); iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, reinterpret_cast<void*>(&jmethod)); } #endif #endif #ifdef AOT_ENABLED size_t blockSize = ((m_end - m_begin) / 4) + 1; auto blockData = new uint32[blockSize]; for(uint32 i = 0; i < blockSize; i++) { blockData[i] = m_context.m_pMemoryMap->GetWord(m_begin + (i * 4)); } uint32 blockChecksum = crc32(0, reinterpret_cast<Bytef*>(blockData), blockSize * 4); #endif #ifdef AOT_USE_CACHE AOT_BLOCK* blocksBegin = &_aot_firstBlock; AOT_BLOCK* blocksEnd = blocksBegin + _aot_blockCount; AOT_BLOCK blockRef = {blockChecksum, m_begin, m_end, nullptr}; static const auto blockComparer = [](const AOT_BLOCK& item1, const AOT_BLOCK& item2) { return item1.key < item2.key; }; // assert(std::is_sorted(blocksBegin, blocksEnd, blockComparer)); bool blockExists = std::binary_search(blocksBegin, blocksEnd, blockRef, blockComparer); auto blockIterator = std::lower_bound(blocksBegin, blocksEnd, blockRef, blockComparer); assert(blockExists); assert(blockIterator != blocksEnd); assert(blockIterator->key.crc == blockChecksum); assert(blockIterator->key.begin == m_begin); assert(blockIterator->key.end == m_end); m_function = reinterpret_cast<void (*)(void*)>(blockIterator->fct); #endif #ifdef AOT_BUILD_CACHE { std::lock_guard<std::mutex> lock(m_aotBlockOutputStreamMutex); m_aotBlockOutputStream->Write32(blockChecksum); m_aotBlockOutputStream->Write32(m_begin); m_aotBlockOutputStream->Write32(m_end); m_aotBlockOutputStream->Write(blockData, blockSize * 4); } #endif }
unsigned int CompileFunction(CPsfVm& virtualMachine, CMipsJitter* jitter, const std::vector<uint32>& blockCode, Jitter::CObjectFile& objectFile, const std::string& functionName, uint32 begin, uint32 end) { auto& context = virtualMachine.GetCpu(); uint8* ram = virtualMachine.GetRam(); for(uint32 address = begin; address <= end; address += 4) { *reinterpret_cast<uint32*>(&ram[address]) = blockCode[(address - begin) / 4]; } { Framework::CMemStream outputStream; Jitter::CObjectFile::INTERNAL_SYMBOL func; jitter->GetCodeGen()->SetExternalSymbolReferencedHandler( [&] (void* symbol, uint32 offset) { Jitter::CObjectFile::SYMBOL_REFERENCE ref; ref.offset = offset; ref.type = Jitter::CObjectFile::SYMBOL_TYPE_EXTERNAL; ref.symbolIndex = objectFile.GetExternalSymbolIndexByValue(symbol); func.symbolReferences.push_back(ref); } ); jitter->SetStream(&outputStream); jitter->Begin(); for(uint32 address = begin; address <= end; address += 4) { context.m_pArch->CompileInstruction(address, jitter, &context); //Sanity check assert(jitter->IsStackEmpty()); } jitter->End(); func.name = functionName; func.data = std::vector<uint8>(outputStream.GetBuffer(), outputStream.GetBuffer() + outputStream.GetSize()); func.location = Jitter::CObjectFile::INTERNAL_SYMBOL_LOCATION_TEXT; return objectFile.AddInternalSymbol(func); } }
extern "C" JNIEXPORT jstring JNICALL Java_com_virtualapplications_play_InputManager_getVirtualPadItems(JNIEnv* env, jobject obj, jfloat screenWidth, jfloat screenHeight) { auto items = CVirtualPad::GetItems(screenWidth, screenHeight); auto documentNode = std::make_unique<Framework::Xml::CNode>("Document", true); for(const auto& item : items) { auto itemNode = new Framework::Xml::CNode("Item", true); itemNode->InsertAttribute("isAnalog", item.isAnalog ? "true" : "false"); itemNode->InsertAttribute("x1", std::to_string(item.x1).c_str()); itemNode->InsertAttribute("y1", std::to_string(item.y1).c_str()); itemNode->InsertAttribute("x2", std::to_string(item.x2).c_str()); itemNode->InsertAttribute("y2", std::to_string(item.y2).c_str()); itemNode->InsertAttribute("code0", std::to_string(item.code0).c_str()); itemNode->InsertAttribute("code1", std::to_string(item.code1).c_str()); itemNode->InsertAttribute("caption", item.caption.c_str()); itemNode->InsertAttribute("imageName", item.imageName.c_str()); documentNode->InsertNode(itemNode); } Framework::CMemStream outputStream; Framework::Xml::CWriter::WriteDocument(outputStream, documentNode.get()); auto resultString = std::string(outputStream.GetBuffer(), outputStream.GetBuffer() + outputStream.GetSize()); jstring result = env->NewStringUTF(resultString.c_str()); return result; }
void CCmp64Test::Compile(Jitter::CJitter& jitter) { Framework::CMemStream codeStream; jitter.SetStream(&codeStream); jitter.Begin(); { //Equal //--------------------------------- jitter.PushRel64(offsetof(CONTEXT, value0)); if(m_useConstant) { jitter.PushCst64(m_value1); } else { jitter.PushRel64(offsetof(CONTEXT, value1)); } jitter.Cmp64(Jitter::CONDITION_EQ); jitter.PullRel(offsetof(CONTEXT, resultEq)); //Not Equal //--------------------------------- jitter.PushRel64(offsetof(CONTEXT, value0)); if(m_useConstant) { jitter.PushCst64(m_value1); } else { jitter.PushRel64(offsetof(CONTEXT, value1)); } jitter.Cmp64(Jitter::CONDITION_NE); jitter.PullRel(offsetof(CONTEXT, resultNe)); //Less Than (unsigned) //--------------------------------- jitter.PushRel64(offsetof(CONTEXT, value0)); if(m_useConstant) { jitter.PushCst64(m_value1); } else { jitter.PushRel64(offsetof(CONTEXT, value1)); } jitter.Cmp64(Jitter::CONDITION_BL); jitter.PullRel(offsetof(CONTEXT, resultBl)); //Less Than (signed) //--------------------------------- jitter.PushRel64(offsetof(CONTEXT, value0)); if(m_useConstant) { jitter.PushCst64(m_value1); } else { jitter.PushRel64(offsetof(CONTEXT, value1)); } jitter.Cmp64(Jitter::CONDITION_LT); jitter.PullRel(offsetof(CONTEXT, resultLt)); //Less Equal (signed) //--------------------------------- jitter.PushRel64(offsetof(CONTEXT, value0)); if(m_useConstant) { jitter.PushCst64(m_value1); } else { jitter.PushRel64(offsetof(CONTEXT, value1)); } jitter.Cmp64(Jitter::CONDITION_LE); jitter.PullRel(offsetof(CONTEXT, resultLe)); //Greater Than (unsigned) //--------------------------------- jitter.PushRel64(offsetof(CONTEXT, value0)); if(m_useConstant) { jitter.PushCst64(m_value1); } else { jitter.PushRel64(offsetof(CONTEXT, value1)); } jitter.Cmp64(Jitter::CONDITION_AB); jitter.PullRel(offsetof(CONTEXT, resultAb)); //Greater Than (signed) //--------------------------------- jitter.PushRel64(offsetof(CONTEXT, value0)); if(m_useConstant) { jitter.PushCst64(m_value1); } else { jitter.PushRel64(offsetof(CONTEXT, value1)); } jitter.Cmp64(Jitter::CONDITION_GT); jitter.PullRel(offsetof(CONTEXT, resultGt)); } jitter.End(); m_function = CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize()); }