integrates generator changes to canPrecompute

This commit is contained in:
Eyck-Alexander Jentzsch 2024-07-17 15:14:13 +02:00
parent ac1a26a10c
commit 11a30caae8

View File

@ -426,21 +426,19 @@ private:
this->gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION));
}
else{
auto new_pc = tu.assignment(tu.constant((uint32_t)(PC+(int32_t)sext<21>(imm)),32),32);
tu.open_if(tu.urem(
new_pc,
tu.constant(static_cast<uint32_t>(traits:: INSTR_ALIGNMENT),32)));
this->gen_set_tval(tu, new_pc);
auto new_pc = (uint32_t)(PC+(int32_t)sext<21>(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);
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(2U, 2));
tu.close_scope();
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(2U, 2));
}
}
auto returnValue = std::make_tuple(BRANCH);
@ -474,12 +472,12 @@ private:
this->gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION));
}
else{
auto addr_mask = tu.assignment(tu.constant((uint32_t)- 2,32),32);
auto addr_mask = (uint32_t)- 2;
auto new_pc = tu.assignment(tu.ext((tu.bitwise_and(
(tu.add(
tu.load(rs1+ traits::X0, 0),
tu.constant((int16_t)sext<12>(imm),16))),
addr_mask)),32,false),32);
tu.constant(addr_mask,32))),32,false),32);
tu.open_if(tu.urem(
new_pc,
tu.constant(static_cast<uint32_t>(traits:: INSTR_ALIGNMENT),32)));
@ -530,17 +528,15 @@ private:
tu.open_if(tu.icmp(ICmpInst::ICMP_EQ,
tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0)));
auto new_pc = tu.assignment(tu.constant((uint32_t)(PC+(int16_t)sext<13>(imm)),32),32);
tu.open_if(tu.urem(
new_pc,
tu.constant(static_cast<uint32_t>(traits:: INSTR_ALIGNMENT),32)));
this->gen_set_tval(tu, new_pc);
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);
tu.open_else();
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(2U, 2));
tu.close_scope();
}
else{
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(2U, 2));
}
tu.close_scope();
}
auto returnValue = std::make_tuple(BRANCH);
@ -578,17 +574,15 @@ private:
tu.open_if(tu.icmp(ICmpInst::ICMP_NE,
tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0)));
auto new_pc = tu.assignment(tu.constant((uint32_t)(PC+(int16_t)sext<13>(imm)),32),32);
tu.open_if(tu.urem(
new_pc,
tu.constant(static_cast<uint32_t>(traits:: INSTR_ALIGNMENT),32)));
this->gen_set_tval(tu, new_pc);
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);
tu.open_else();
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(2U, 2));
tu.close_scope();
}
else{
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(2U, 2));
}
tu.close_scope();
}
auto returnValue = std::make_tuple(BRANCH);
@ -626,17 +620,15 @@ 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 = tu.assignment(tu.constant((uint32_t)(PC+(int16_t)sext<13>(imm)),32),32);
tu.open_if(tu.urem(
new_pc,
tu.constant(static_cast<uint32_t>(traits:: INSTR_ALIGNMENT),32)));
this->gen_set_tval(tu, new_pc);
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);
tu.open_else();
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(2U, 2));
tu.close_scope();
}
else{
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(2U, 2));
}
tu.close_scope();
}
auto returnValue = std::make_tuple(BRANCH);
@ -674,17 +666,15 @@ 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 = tu.assignment(tu.constant((uint32_t)(PC+(int16_t)sext<13>(imm)),32),32);
tu.open_if(tu.urem(
new_pc,
tu.constant(static_cast<uint32_t>(traits:: INSTR_ALIGNMENT),32)));
this->gen_set_tval(tu, new_pc);
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);
tu.open_else();
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(2U, 2));
tu.close_scope();
}
else{
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(2U, 2));
}
tu.close_scope();
}
auto returnValue = std::make_tuple(BRANCH);
@ -722,17 +712,15 @@ private:
tu.open_if(tu.icmp(ICmpInst::ICMP_ULT,
tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0)));
auto new_pc = tu.assignment(tu.constant((uint32_t)(PC+(int16_t)sext<13>(imm)),32),32);
tu.open_if(tu.urem(
new_pc,
tu.constant(static_cast<uint32_t>(traits:: INSTR_ALIGNMENT),32)));
this->gen_set_tval(tu, new_pc);
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);
tu.open_else();
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(2U, 2));
tu.close_scope();
}
else{
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(2U, 2));
}
tu.close_scope();
}
auto returnValue = std::make_tuple(BRANCH);
@ -770,17 +758,15 @@ private:
tu.open_if(tu.icmp(ICmpInst::ICMP_UGE,
tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0)));
auto new_pc = tu.assignment(tu.constant((uint32_t)(PC+(int16_t)sext<13>(imm)),32),32);
tu.open_if(tu.urem(
new_pc,
tu.constant(static_cast<uint32_t>(traits:: INSTR_ALIGNMENT),32)));
this->gen_set_tval(tu, new_pc);
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);
tu.open_else();
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(2U, 2));
tu.close_scope();
}
else{
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(2U, 2));
}
tu.close_scope();
}
auto returnValue = std::make_tuple(BRANCH);
@ -2456,16 +2442,16 @@ private:
if(rd!=0){ tu.open_if(tu.icmp(ICmpInst::ICMP_NE,
divisor,
tu.constant(0,8)));
auto MMIN = tu.assignment(tu.constant(((uint32_t)1)<<(static_cast<uint32_t>(traits:: XLEN)-1),32),32);
auto MMIN = ((uint32_t)1)<<(static_cast<uint32_t>(traits:: XLEN)-1);
tu.open_if(tu.logical_and(
tu.icmp(ICmpInst::ICMP_EQ,
tu.load(rs1+ traits::X0, 0),
MMIN),
tu.constant(MMIN,32)),
tu.icmp(ICmpInst::ICMP_EQ,
divisor,
tu.constant(- 1,8))));
tu.store(rd + traits::X0,
MMIN);
tu.constant(MMIN,32));
tu.open_else();
tu.store(rd + traits::X0,
tu.ext((tu.sdiv(
@ -2561,11 +2547,11 @@ private:
tu.open_if(tu.icmp(ICmpInst::ICMP_NE,
tu.load(rs2+ traits::X0, 0),
tu.constant(0,8)));
auto MMIN = tu.assignment(tu.constant((uint32_t)1<<(static_cast<uint32_t>(traits:: XLEN)-1),32),32);
auto MMIN = (uint32_t)1<<(static_cast<uint32_t>(traits:: XLEN)-1);
tu.open_if(tu.logical_and(
tu.icmp(ICmpInst::ICMP_EQ,
tu.load(rs1+ traits::X0, 0),
MMIN),
tu.constant(MMIN,32)),
tu.icmp(ICmpInst::ICMP_EQ,
tu.ext(tu.load(rs2+ traits::X0, 0),32,true),
tu.constant(- 1,8))));
@ -3417,10 +3403,10 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope();
this->gen_set_tval(tu, instr);
if(rs1&&rs1<static_cast<uint32_t>(traits:: RFS)){ auto addr_mask = tu.assignment(tu.constant((uint32_t)- 2,32),32);
if(rs1&&rs1<static_cast<uint32_t>(traits:: RFS)){ auto addr_mask = (uint32_t)- 2;
auto PC_val_v = tu.assignment("PC_val", tu.bitwise_and(
tu.load(rs1%static_cast<uint32_t>(traits:: RFS)+ traits::X0, 0),
addr_mask),32);
tu.constant(addr_mask,32)),32);
tu.store(traits::NEXT_PC, PC_val_v);
tu.store(traits::LAST_BRANCH, tu.constant(2U, 2));
}
@ -3518,13 +3504,13 @@ private:
this->gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION));
}
else{
auto addr_mask = tu.assignment(tu.constant((uint32_t)- 2,32),32);
auto addr_mask = (uint32_t)- 2;
auto new_pc = tu.assignment(tu.load(rs1+ traits::X0, 0),32);
tu.store(1 + traits::X0,
tu.constant((uint32_t)(PC+2),32));
auto PC_val_v = tu.assignment("PC_val", tu.bitwise_and(
new_pc,
addr_mask),32);
tu.constant(addr_mask,32)),32);
tu.store(traits::NEXT_PC, PC_val_v);
tu.store(traits::LAST_BRANCH, tu.constant(2U, 2));
}