diff --git a/src/vm/asmjit/vm_tgc5c.cpp b/src/vm/asmjit/vm_tgc5c.cpp index 19e10a6..791941f 100644 --- a/src/vm/asmjit/vm_tgc5c.cpp +++ b/src/vm/asmjit/vm_tgc5c.cpp @@ -1421,23 +1421,21 @@ private: } else{ if(rd!=0){ - { - auto label_then = cc.newLabel(); - auto label_merge = cc.newLabel(); - auto tmp_reg = get_reg_for(cc, 1); + auto label_then11 = cc.newLabel(); + auto label_merge11 = cc.newLabel(); + auto tmp_reg11 = get_reg(cc, 8, false); cmp(cc, gen_ext(cc, load_reg_from_mem(jh, traits::X0 + rs1), 32, true), (int16_t)sext<12>(imm)); - cc.jl(label_then); - mov(cc, tmp_reg,0); - cc.jmp(label_merge); - cc.bind(label_then); - mov(cc, tmp_reg,1); - cc.bind(label_merge); + cc.jl(label_then11); + mov(cc, tmp_reg11,0); + cc.jmp(label_merge11); + cc.bind(label_then11); + mov(cc, tmp_reg11, 1); + cc.bind(label_merge11); mov(cc, get_ptr_for(jh, traits::X0+ rd), - gen_ext(cc, tmp_reg + gen_ext(cc, tmp_reg11 , 32, false) ); - } } } auto returnValue = CONT; @@ -1484,22 +1482,20 @@ private: } else{ if(rd!=0){ - { - auto label_then = cc.newLabel(); - auto label_merge = cc.newLabel(); - auto tmp_reg = get_reg_for(cc, 1); + auto label_then12 = cc.newLabel(); + auto label_merge12 = cc.newLabel(); + auto tmp_reg12 = get_reg(cc, 8, false); cmp(cc, load_reg_from_mem(jh, traits::X0 + rs1), (uint32_t)((int16_t)sext<12>(imm))); - cc.jb(label_then); - mov(cc, tmp_reg,0); - cc.jmp(label_merge); - cc.bind(label_then); - mov(cc, tmp_reg,1); - cc.bind(label_merge); + cc.jb(label_then12); + mov(cc, tmp_reg12,0); + cc.jmp(label_merge12); + cc.bind(label_then12); + mov(cc, tmp_reg12, 1); + cc.bind(label_merge12); mov(cc, get_ptr_for(jh, traits::X0+ rd), - gen_ext(cc, tmp_reg + gen_ext(cc, tmp_reg12 , 32, false) ); - } } } auto returnValue = CONT; @@ -1992,24 +1988,22 @@ private: } else{ if(rd!=0){ - { - auto label_then = cc.newLabel(); - auto label_merge = cc.newLabel(); - auto tmp_reg = get_reg_for(cc, 1); + auto label_then13 = cc.newLabel(); + auto label_merge13 = cc.newLabel(); + auto tmp_reg13 = get_reg(cc, 8, false); cmp(cc, gen_ext(cc, load_reg_from_mem(jh, traits::X0 + rs1), 32, true), gen_ext(cc, load_reg_from_mem(jh, traits::X0 + rs2), 32, true)); - cc.jl(label_then); - mov(cc, tmp_reg,0); - cc.jmp(label_merge); - cc.bind(label_then); - mov(cc, tmp_reg,1); - cc.bind(label_merge); + cc.jl(label_then13); + mov(cc, tmp_reg13,0); + cc.jmp(label_merge13); + cc.bind(label_then13); + mov(cc, tmp_reg13, 1); + cc.bind(label_merge13); mov(cc, get_ptr_for(jh, traits::X0+ rd), - gen_ext(cc, tmp_reg + gen_ext(cc, tmp_reg13 , 32, false) ); - } } } auto returnValue = CONT; @@ -2056,22 +2050,20 @@ private: } else{ if(rd!=0){ - { - auto label_then = cc.newLabel(); - auto label_merge = cc.newLabel(); - auto tmp_reg = get_reg_for(cc, 1); + auto label_then14 = cc.newLabel(); + auto label_merge14 = cc.newLabel(); + auto tmp_reg14 = get_reg(cc, 8, false); cmp(cc, load_reg_from_mem(jh, traits::X0 + rs1), load_reg_from_mem(jh, traits::X0 + rs2)); - cc.jb(label_then); - mov(cc, tmp_reg,0); - cc.jmp(label_merge); - cc.bind(label_then); - mov(cc, tmp_reg,1); - cc.bind(label_merge); + cc.jb(label_then14); + mov(cc, tmp_reg14,0); + cc.jmp(label_merge14); + cc.bind(label_then14); + mov(cc, tmp_reg14, 1); + cc.bind(label_merge14); mov(cc, get_ptr_for(jh, traits::X0+ rd), - gen_ext(cc, tmp_reg + gen_ext(cc, tmp_reg14 , 32, false) ); - } } } auto returnValue = CONT; @@ -2511,10 +2503,10 @@ private: gen_instr_prologue(jh); cc.comment("//behavior:"); /*generate behavior*/ - InvokeNode* call_wait; + InvokeNode* call_wait_15; jh.cc.comment("//call_wait"); - jh.cc.invoke(&call_wait, &wait, FuncSignature::build()); - setArg(call_wait, 0, 1); + jh.cc.invoke(&call_wait_15, &wait, FuncSignature::build()); + setArg(call_wait_15, 0, 1); auto returnValue = CONT; gen_sync(jh, POST_SYNC, 41); @@ -4875,6 +4867,7 @@ inline void vm_impl::gen_raise(jit_holder& jh, uint16_t trap_id, uint16_t auto tmp1 = get_reg_for(cc, traits::TRAP_STATE); mov(cc, tmp1, 0x80ULL << 24 | (cause << 16) | trap_id); mov(cc, get_ptr_for(jh, traits::TRAP_STATE), tmp1); + cc.jmp(jh.trap_entry); } template template diff --git a/src/vm/llvm/vm_tgc5c.cpp b/src/vm/llvm/vm_tgc5c.cpp index 9970704..870c498 100644 --- a/src/vm/llvm/vm_tgc5c.cpp +++ b/src/vm/llvm/vm_tgc5c.cpp @@ -1490,7 +1490,7 @@ private: ), this->gen_const(8,1), this->gen_const(8,0), - 1), 32), + 8), 32), get_reg_ptr(rd + traits::X0), false); } } @@ -1543,7 +1543,7 @@ private: ), this->gen_const(8,1), this->gen_const(8,0), - 1), 32), + 8), 32), get_reg_ptr(rd + traits::X0), false); } } @@ -2057,7 +2057,7 @@ private: , this->gen_const(8,1), this->gen_const(8,0), - 1), 32), + 8), 32), get_reg_ptr(rd + traits::X0), false); } } @@ -2110,7 +2110,7 @@ private: , this->gen_const(8,1), this->gen_const(8,0), - 1), 32), + 8), 32), get_reg_ptr(rd + traits::X0), false); } } @@ -2553,10 +2553,10 @@ private: this->gen_instr_prologue(); /*generate behavior*/ - std::vector wait_args{ + std::vector wait_231_args{ this->gen_ext(this->gen_const(8,1), 32) }; - this->builder.CreateCall(this->mod->getFunction("wait"), wait_args); + this->builder.CreateCall(this->mod->getFunction("wait"), wait_231_args); bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); auto returnValue = std::make_tuple(CONT,bb); @@ -4897,7 +4897,7 @@ private: }; this->builder.CreateCall(this->mod->getFunction("print_disass"), args); } - this->gen_sync(iss::PRE_SYNC, instr_descr.size()); + this->gen_sync(iss::PRE_SYNC, instr_descr.size()); this->builder.CreateStore(this->builder.CreateLoad(this->get_typeptr(traits::NEXT_PC), get_reg_ptr(traits::NEXT_PC), true), get_reg_ptr(traits::PC), true); this->builder.CreateStore( @@ -4972,6 +4972,7 @@ template void vm_impl::gen_raise_trap(uint16_t trap_id, uint16_t cause) { auto *TRAP_val = this->gen_const(32, 0x80 << 24 | (cause << 16) | trap_id); this->builder.CreateStore(TRAP_val, get_reg_ptr(traits::TRAP_STATE), true); + this->builder.CreateBr(this->trap_blk); } template @@ -5074,4 +5075,4 @@ volatile std::array dummy = { }; } } -// clang-format on \ No newline at end of file +// clang-format on diff --git a/src/vm/tcc/vm_tgc5c.cpp b/src/vm/tcc/vm_tgc5c.cpp index 71778f6..5306c39 100644 --- a/src/vm/tcc/vm_tgc5c.cpp +++ b/src/vm/tcc/vm_tgc5c.cpp @@ -474,15 +474,19 @@ private: tu.open_if(tu.urem( new_pc, tu.constant(static_cast(traits:: INSTR_ALIGNMENT),32))); + { this->gen_set_tval(tu, new_pc); this->gen_raise_trap(tu, 0, 0); + } tu.open_else(); + { if(rd!=0) { tu.store(rd + traits::X0, tu.constant((uint32_t)(PC+4),32)); } auto PC_val_v = tu.assignment("PC_val", new_pc,32); tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::LAST_BRANCH, tu.constant(static_cast(UNKNOWN_JUMP), 2)); + } tu.close_scope(); } auto returnValue = std::make_tuple(BRANCH); @@ -521,6 +525,7 @@ private: tu.open_if(tu.icmp(ICmpInst::ICMP_EQ, tu.load(rs1 + traits::X0, 0), tu.load(rs2 + traits::X0, 0))); + { auto new_pc = (uint32_t)(PC+(int16_t)sext<13>(imm)); if(new_pc%static_cast(traits:: INSTR_ALIGNMENT)){ this->gen_set_tval(tu, new_pc); this->gen_raise_trap(tu, 0, 0); @@ -530,6 +535,7 @@ private: tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::LAST_BRANCH, tu.constant(static_cast(KNOWN_JUMP), 2)); } + } tu.close_scope(); } auto returnValue = std::make_tuple(BRANCH); @@ -568,6 +574,7 @@ private: tu.open_if(tu.icmp(ICmpInst::ICMP_NE, tu.load(rs1 + traits::X0, 0), tu.load(rs2 + traits::X0, 0))); + { auto new_pc = (uint32_t)(PC+(int16_t)sext<13>(imm)); if(new_pc%static_cast(traits:: INSTR_ALIGNMENT)){ this->gen_set_tval(tu, new_pc); this->gen_raise_trap(tu, 0, 0); @@ -577,6 +584,7 @@ private: tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::LAST_BRANCH, tu.constant(static_cast(KNOWN_JUMP), 2)); } + } tu.close_scope(); } auto returnValue = std::make_tuple(BRANCH); @@ -615,6 +623,7 @@ private: tu.open_if(tu.icmp(ICmpInst::ICMP_SLT, tu.ext(tu.load(rs1 + traits::X0, 0),32,true), tu.ext(tu.load(rs2 + traits::X0, 0),32,true))); + { auto new_pc = (uint32_t)(PC+(int16_t)sext<13>(imm)); if(new_pc%static_cast(traits:: INSTR_ALIGNMENT)){ this->gen_set_tval(tu, new_pc); this->gen_raise_trap(tu, 0, 0); @@ -624,6 +633,7 @@ private: tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::LAST_BRANCH, tu.constant(static_cast(KNOWN_JUMP), 2)); } + } tu.close_scope(); } auto returnValue = std::make_tuple(BRANCH); @@ -662,6 +672,7 @@ private: tu.open_if(tu.icmp(ICmpInst::ICMP_SGE, tu.ext(tu.load(rs1 + traits::X0, 0),32,true), tu.ext(tu.load(rs2 + traits::X0, 0),32,true))); + { auto new_pc = (uint32_t)(PC+(int16_t)sext<13>(imm)); if(new_pc%static_cast(traits:: INSTR_ALIGNMENT)){ this->gen_set_tval(tu, new_pc); this->gen_raise_trap(tu, 0, 0); @@ -671,6 +682,7 @@ private: tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::LAST_BRANCH, tu.constant(static_cast(KNOWN_JUMP), 2)); } + } tu.close_scope(); } auto returnValue = std::make_tuple(BRANCH); @@ -709,6 +721,7 @@ private: tu.open_if(tu.icmp(ICmpInst::ICMP_ULT, tu.load(rs1 + traits::X0, 0), tu.load(rs2 + traits::X0, 0))); + { auto new_pc = (uint32_t)(PC+(int16_t)sext<13>(imm)); if(new_pc%static_cast(traits:: INSTR_ALIGNMENT)){ this->gen_set_tval(tu, new_pc); this->gen_raise_trap(tu, 0, 0); @@ -718,6 +731,7 @@ private: tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::LAST_BRANCH, tu.constant(static_cast(KNOWN_JUMP), 2)); } + } tu.close_scope(); } auto returnValue = std::make_tuple(BRANCH); @@ -756,6 +770,7 @@ private: tu.open_if(tu.icmp(ICmpInst::ICMP_UGE, tu.load(rs1 + traits::X0, 0), tu.load(rs2 + traits::X0, 0))); + { auto new_pc = (uint32_t)(PC+(int16_t)sext<13>(imm)); if(new_pc%static_cast(traits:: INSTR_ALIGNMENT)){ this->gen_set_tval(tu, new_pc); this->gen_raise_trap(tu, 0, 0); @@ -765,6 +780,7 @@ private: tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::LAST_BRANCH, tu.constant(static_cast(KNOWN_JUMP), 2)); } + } tu.close_scope(); } auto returnValue = std::make_tuple(BRANCH); @@ -2417,6 +2433,7 @@ private: if(rd!=0){ tu.open_if(tu.icmp(ICmpInst::ICMP_NE, divisor, tu.constant(0,8))); + { auto MMIN = ((uint32_t)1)<<(static_cast(traits:: XLEN)-1); tu.open_if(tu.logical_and( tu.icmp(ICmpInst::ICMP_EQ, @@ -2425,14 +2442,21 @@ private: tu.icmp(ICmpInst::ICMP_EQ, divisor, tu.constant(- 1,8)))); + { tu.store(rd + traits::X0, tu.constant(MMIN,32)); + } tu.open_else(); + { tu.store(rd + traits::X0, tu.ext((tu.sdiv( dividend, divisor)),32,false)); + } tu.close_scope(); + } tu.open_else(); + { tu.store(rd + traits::X0, tu.constant((uint32_t)- 1,32)); + } tu.close_scope(); } } @@ -2471,15 +2495,19 @@ private: tu.open_if(tu.icmp(ICmpInst::ICMP_NE, tu.load(rs2 + traits::X0, 0), tu.constant(0,8))); + { if(rd!=0) { tu.store(rd + traits::X0, tu.udiv( tu.load(rs1 + traits::X0, 0), tu.load(rs2 + traits::X0, 0))); } + } tu.open_else(); + { if(rd!=0) { tu.store(rd + traits::X0, tu.constant((uint32_t)- 1,32)); } + } tu.close_scope(); } auto returnValue = std::make_tuple(CONT); @@ -2517,6 +2545,7 @@ private: tu.open_if(tu.icmp(ICmpInst::ICMP_NE, tu.load(rs2 + traits::X0, 0), tu.constant(0,8))); + { auto MMIN = (uint32_t)1<<(static_cast(traits:: XLEN)-1); tu.open_if(tu.logical_and( tu.icmp(ICmpInst::ICMP_EQ, @@ -2525,20 +2554,27 @@ private: tu.icmp(ICmpInst::ICMP_EQ, tu.ext(tu.load(rs2 + traits::X0, 0),32,true), tu.constant(- 1,8)))); + { if(rd!=0) { tu.store(rd + traits::X0, tu.constant(0,8)); } + } tu.open_else(); + { if(rd!=0) { tu.store(rd + traits::X0, tu.ext((tu.srem( tu.ext(tu.load(rs1 + traits::X0, 0),32,true), tu.ext(tu.load(rs2 + traits::X0, 0),32,true))),32,false)); } + } tu.close_scope(); + } tu.open_else(); + { if(rd!=0) { tu.store(rd + traits::X0, tu.load(rs1 + traits::X0, 0)); } + } tu.close_scope(); } auto returnValue = std::make_tuple(CONT); @@ -2576,15 +2612,19 @@ private: tu.open_if(tu.icmp(ICmpInst::ICMP_NE, tu.load(rs2 + traits::X0, 0), tu.constant(0,8))); + { if(rd!=0) { tu.store(rd + traits::X0, tu.urem( tu.load(rs1 + traits::X0, 0), tu.load(rs2 + traits::X0, 0))); } + } tu.open_else(); + { if(rd!=0) { tu.store(rd + traits::X0, tu.load(rs1 + traits::X0, 0)); } + } tu.close_scope(); } auto returnValue = std::make_tuple(CONT); @@ -3185,9 +3225,11 @@ private: tu.open_if(tu.icmp(ICmpInst::ICMP_EQ, tu.load(rs1+8 + traits::X0, 0), tu.constant(0,8))); + { auto PC_val_v = tu.assignment("PC_val", (uint32_t)(PC+(int16_t)sext<9>(imm)),32); tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::LAST_BRANCH, tu.constant(static_cast(KNOWN_JUMP), 2)); + } tu.close_scope(); auto returnValue = std::make_tuple(BRANCH); @@ -3220,9 +3262,11 @@ private: tu.open_if(tu.icmp(ICmpInst::ICMP_NE, tu.load(rs1+8 + traits::X0, 0), tu.constant(0,8))); + { auto PC_val_v = tu.assignment("PC_val", (uint32_t)(PC+(int16_t)sext<9>(imm)),32); tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::LAST_BRANCH, tu.constant(static_cast(KNOWN_JUMP), 2)); + } tu.close_scope(); auto returnValue = std::make_tuple(BRANCH);