Compare commits

..

2 Commits

5 changed files with 99 additions and 59 deletions

View File

@ -308,6 +308,7 @@ inline void vm_impl<ARCH>::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 <typename ARCH>
template <typename T, typename>

View File

@ -279,6 +279,7 @@ template <typename ARCH>
void vm_impl<ARCH>::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 <typename ARCH>

View File

@ -1421,25 +1421,23 @@ 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;
gen_sync(jh, POST_SYNC, 19);
@ -1484,24 +1482,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_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;
gen_sync(jh, POST_SYNC, 20);
@ -1992,26 +1988,24 @@ 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;
gen_sync(jh, POST_SYNC, 30);
@ -2056,24 +2050,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_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;
gen_sync(jh, POST_SYNC, 31);
@ -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<void, int32_t>());
setArg(call_wait, 0, 1);
jh.cc.invoke(&call_wait_15, &wait, FuncSignature::build<void, int32_t>());
setArg(call_wait_15, 0, 1);
auto returnValue = CONT;
gen_sync(jh, POST_SYNC, 41);
@ -4875,6 +4867,7 @@ inline void vm_impl<ARCH>::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 <typename ARCH>
template <typename T, typename>

View File

@ -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<Value*> wait_args{
std::vector<Value*> 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);
@ -4972,6 +4972,7 @@ template <typename ARCH>
void vm_impl<ARCH>::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 <typename ARCH>

View File

@ -474,15 +474,19 @@ private:
tu.open_if(tu.urem(
new_pc,
tu.constant(static_cast<uint32_t>(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<int>(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<uint32_t>(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<int>(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<uint32_t>(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<int>(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<uint32_t>(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<int>(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<uint32_t>(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<int>(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<uint32_t>(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<int>(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<uint32_t>(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<int>(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<uint32_t>(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<uint32_t>(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<int>(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<int>(KNOWN_JUMP), 2));
}
tu.close_scope();
auto returnValue = std::make_tuple(BRANCH);