updates template

This commit is contained in:
Eyck-Alexander Jentzsch 2024-08-08 11:08:28 +02:00
parent 62d21e1156
commit 235a7e6e24
2 changed files with 207 additions and 275 deletions

View File

@ -195,7 +195,7 @@ private:
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, std::string("illegal_instruction")); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, std::string("illegal_instruction"));
} }
pc = pc + ((instr & 3) == 3 ? 4 : 2); pc = pc + ((instr & 3) == 3 ? 4 : 2);
gen_raise_trap(tu, 0, 2); // illegal instruction trap gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION));
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
vm_impl::gen_sync(tu, iss::POST_SYNC, instr_descr.size()); vm_impl::gen_sync(tu, iss::POST_SYNC, instr_descr.size());
vm_impl::gen_trap_check(tu); vm_impl::gen_trap_check(tu);

View File

@ -351,8 +351,7 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.constant((uint32_t)((int32_t)imm),32));
tu.constant((uint32_t)((int32_t)imm),32));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -387,8 +386,7 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.constant((uint32_t)(PC+(int32_t)imm),32));
tu.constant((uint32_t)(PC+(int32_t)imm),32));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -429,8 +427,7 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.constant((uint32_t)(PC+4),32));
tu.constant((uint32_t)(PC+4),32));
} }
auto PC_val_v = tu.assignment("PC_val", new_pc,32); auto PC_val_v = tu.assignment("PC_val", new_pc,32);
tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::NEXT_PC, PC_val_v);
@ -473,7 +470,7 @@ private:
auto addr_mask = (uint32_t)- 2; auto addr_mask = (uint32_t)- 2;
auto new_pc = tu.assignment(tu.ext((tu.bitwise_and( auto new_pc = tu.assignment(tu.ext((tu.bitwise_and(
(tu.add( (tu.add(
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.constant((int16_t)sext<12>(imm),16))), tu.constant((int16_t)sext<12>(imm),16))),
tu.constant(addr_mask,32))),32,false),32); tu.constant(addr_mask,32))),32,false),32);
tu.open_if(tu.urem( tu.open_if(tu.urem(
@ -483,8 +480,7 @@ private:
this->gen_raise_trap(tu, 0, 0); this->gen_raise_trap(tu, 0, 0);
tu.open_else(); tu.open_else();
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.constant((uint32_t)(PC+4),32));
tu.constant((uint32_t)(PC+4),32));
} }
auto PC_val_v = tu.assignment("PC_val", new_pc,32); auto PC_val_v = tu.assignment("PC_val", new_pc,32);
tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::NEXT_PC, PC_val_v);
@ -525,8 +521,8 @@ private:
} }
else{ else{
tu.open_if(tu.icmp(ICmpInst::ICMP_EQ, tu.open_if(tu.icmp(ICmpInst::ICMP_EQ,
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.load(rs2+ traits::X0, 0))); tu.load(rs2 + traits::X0, 0)));
auto new_pc = (uint32_t)(PC+(int16_t)sext<13>(imm)); 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); if(new_pc%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_set_tval(tu, new_pc);
this->gen_raise_trap(tu, 0, 0); this->gen_raise_trap(tu, 0, 0);
@ -572,8 +568,8 @@ private:
} }
else{ else{
tu.open_if(tu.icmp(ICmpInst::ICMP_NE, tu.open_if(tu.icmp(ICmpInst::ICMP_NE,
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.load(rs2+ traits::X0, 0))); tu.load(rs2 + traits::X0, 0)));
auto new_pc = (uint32_t)(PC+(int16_t)sext<13>(imm)); 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); if(new_pc%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_set_tval(tu, new_pc);
this->gen_raise_trap(tu, 0, 0); this->gen_raise_trap(tu, 0, 0);
@ -619,8 +615,8 @@ private:
} }
else{ else{
tu.open_if(tu.icmp(ICmpInst::ICMP_SLT, tu.open_if(tu.icmp(ICmpInst::ICMP_SLT,
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs1 + traits::X0, 0),32,true),
tu.ext(tu.load(rs2+ 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)); 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); if(new_pc%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_set_tval(tu, new_pc);
this->gen_raise_trap(tu, 0, 0); this->gen_raise_trap(tu, 0, 0);
@ -666,8 +662,8 @@ private:
} }
else{ else{
tu.open_if(tu.icmp(ICmpInst::ICMP_SGE, tu.open_if(tu.icmp(ICmpInst::ICMP_SGE,
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs1 + traits::X0, 0),32,true),
tu.ext(tu.load(rs2+ 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)); 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); if(new_pc%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_set_tval(tu, new_pc);
this->gen_raise_trap(tu, 0, 0); this->gen_raise_trap(tu, 0, 0);
@ -713,8 +709,8 @@ private:
} }
else{ else{
tu.open_if(tu.icmp(ICmpInst::ICMP_ULT, tu.open_if(tu.icmp(ICmpInst::ICMP_ULT,
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.load(rs2+ traits::X0, 0))); tu.load(rs2 + traits::X0, 0)));
auto new_pc = (uint32_t)(PC+(int16_t)sext<13>(imm)); 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); if(new_pc%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_set_tval(tu, new_pc);
this->gen_raise_trap(tu, 0, 0); this->gen_raise_trap(tu, 0, 0);
@ -760,8 +756,8 @@ private:
} }
else{ else{
tu.open_if(tu.icmp(ICmpInst::ICMP_UGE, tu.open_if(tu.icmp(ICmpInst::ICMP_UGE,
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.load(rs2+ traits::X0, 0))); tu.load(rs2 + traits::X0, 0)));
auto new_pc = (uint32_t)(PC+(int16_t)sext<13>(imm)); 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); if(new_pc%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_set_tval(tu, new_pc);
this->gen_raise_trap(tu, 0, 0); this->gen_raise_trap(tu, 0, 0);
@ -806,12 +802,11 @@ private:
} }
else{ else{
auto load_address = tu.assignment(tu.ext((tu.add( auto load_address = tu.assignment(tu.ext((tu.add(
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.constant((int16_t)sext<12>(imm),16))),32,false),32); tu.constant((int16_t)sext<12>(imm),16))),32,false),32);
auto res = tu.assignment(tu.ext(tu.read_mem(traits::MEM, load_address, 8),8,true),8); auto res = tu.assignment(tu.ext(tu.read_mem(traits::MEM, load_address, 8),8,true),8);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext(res,32,false));
tu.ext(res,32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -847,12 +842,11 @@ private:
} }
else{ else{
auto load_address = tu.assignment(tu.ext((tu.add( auto load_address = tu.assignment(tu.ext((tu.add(
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.constant((int16_t)sext<12>(imm),16))),32,false),32); tu.constant((int16_t)sext<12>(imm),16))),32,false),32);
auto res = tu.assignment(tu.ext(tu.read_mem(traits::MEM, load_address, 16),16,true),16); auto res = tu.assignment(tu.ext(tu.read_mem(traits::MEM, load_address, 16),16,true),16);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext(res,32,false));
tu.ext(res,32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -888,12 +882,11 @@ private:
} }
else{ else{
auto load_address = tu.assignment(tu.ext((tu.add( auto load_address = tu.assignment(tu.ext((tu.add(
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.constant((int16_t)sext<12>(imm),16))),32,false),32); tu.constant((int16_t)sext<12>(imm),16))),32,false),32);
auto res = tu.assignment(tu.ext(tu.read_mem(traits::MEM, load_address, 32),32,true),32); auto res = tu.assignment(tu.ext(tu.read_mem(traits::MEM, load_address, 32),32,true),32);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext(res,32,false));
tu.ext(res,32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -929,12 +922,11 @@ private:
} }
else{ else{
auto load_address = tu.assignment(tu.ext((tu.add( auto load_address = tu.assignment(tu.ext((tu.add(
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.constant((int16_t)sext<12>(imm),16))),32,false),32); tu.constant((int16_t)sext<12>(imm),16))),32,false),32);
auto res = tu.assignment(tu.read_mem(traits::MEM, load_address, 8),8); auto res = tu.assignment(tu.read_mem(traits::MEM, load_address, 8),8);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext(res,32,false));
tu.ext(res,32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -970,12 +962,11 @@ private:
} }
else{ else{
auto load_address = tu.assignment(tu.ext((tu.add( auto load_address = tu.assignment(tu.ext((tu.add(
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.constant((int16_t)sext<12>(imm),16))),32,false),32); tu.constant((int16_t)sext<12>(imm),16))),32,false),32);
auto res = tu.assignment(tu.read_mem(traits::MEM, load_address, 16),16); auto res = tu.assignment(tu.read_mem(traits::MEM, load_address, 16),16);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext(res,32,false));
tu.ext(res,32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1011,9 +1002,9 @@ private:
} }
else{ else{
auto store_address = tu.assignment(tu.ext((tu.add( auto store_address = tu.assignment(tu.ext((tu.add(
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.constant((int16_t)sext<12>(imm),16))),32,false),32); tu.constant((int16_t)sext<12>(imm),16))),32,false),32);
tu.write_mem(traits::MEM, store_address, tu.ext(tu.load(rs2+ traits::X0, 0),8,false)); tu.write_mem(traits::MEM, store_address, tu.ext(tu.load(rs2 + traits::X0, 0),8,false));
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1048,9 +1039,9 @@ private:
} }
else{ else{
auto store_address = tu.assignment(tu.ext((tu.add( auto store_address = tu.assignment(tu.ext((tu.add(
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.constant((int16_t)sext<12>(imm),16))),32,false),32); tu.constant((int16_t)sext<12>(imm),16))),32,false),32);
tu.write_mem(traits::MEM, store_address, tu.ext(tu.load(rs2+ traits::X0, 0),16,false)); tu.write_mem(traits::MEM, store_address, tu.ext(tu.load(rs2 + traits::X0, 0),16,false));
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1085,9 +1076,9 @@ private:
} }
else{ else{
auto store_address = tu.assignment(tu.ext((tu.add( auto store_address = tu.assignment(tu.ext((tu.add(
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.constant((int16_t)sext<12>(imm),16))),32,false),32); tu.constant((int16_t)sext<12>(imm),16))),32,false),32);
tu.write_mem(traits::MEM, store_address, tu.ext(tu.load(rs2+ traits::X0, 0),32,false)); tu.write_mem(traits::MEM, store_address, tu.ext(tu.load(rs2 + traits::X0, 0),32,false));
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1122,9 +1113,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext((tu.add(
tu.ext((tu.add( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0),
tu.constant((int16_t)sext<12>(imm),16))),32,false)); tu.constant((int16_t)sext<12>(imm),16))),32,false));
} }
} }
@ -1161,9 +1151,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.conditionalAssignment((tu.icmp(ICmpInst::ICMP_SLT,
tu.conditionalAssignment((tu.icmp(ICmpInst::ICMP_SLT, tu.ext(tu.load(rs1 + traits::X0, 0),32,true),
tu.ext(tu.load(rs1+ traits::X0, 0),32,true),
tu.constant((int16_t)sext<12>(imm),16))), tu.constant(1,8),tu.constant(0,8))); tu.constant((int16_t)sext<12>(imm),16))), tu.constant(1,8),tu.constant(0,8)));
} }
} }
@ -1200,9 +1189,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.conditionalAssignment((tu.icmp(ICmpInst::ICMP_ULT,
tu.conditionalAssignment((tu.icmp(ICmpInst::ICMP_ULT, tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0),
tu.constant((uint32_t)((int16_t)sext<12>(imm)),32))), tu.constant(1,8),tu.constant(0,8))); tu.constant((uint32_t)((int16_t)sext<12>(imm)),32))), tu.constant(1,8),tu.constant(0,8)));
} }
} }
@ -1239,9 +1227,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.bitwise_xor(
tu.bitwise_xor( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0),
tu.constant((uint32_t)((int16_t)sext<12>(imm)),32))); tu.constant((uint32_t)((int16_t)sext<12>(imm)),32)));
} }
} }
@ -1278,9 +1265,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.bitwise_or(
tu.bitwise_or( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0),
tu.constant((uint32_t)((int16_t)sext<12>(imm)),32))); tu.constant((uint32_t)((int16_t)sext<12>(imm)),32)));
} }
} }
@ -1317,9 +1303,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.bitwise_and(
tu.bitwise_and( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0),
tu.constant((uint32_t)((int16_t)sext<12>(imm)),32))); tu.constant((uint32_t)((int16_t)sext<12>(imm)),32)));
} }
} }
@ -1356,9 +1341,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.shl(
tu.shl( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0),
tu.constant(shamt,8))); tu.constant(shamt,8)));
} }
} }
@ -1395,9 +1379,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.lshr(
tu.lshr( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0),
tu.constant(shamt,8))); tu.constant(shamt,8)));
} }
} }
@ -1434,9 +1417,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext((tu.ashr(
tu.ext((tu.ashr( tu.ext(tu.load(rs1 + traits::X0, 0),32,true),
tu.ext(tu.load(rs1+ traits::X0, 0),32,true),
tu.constant(shamt,8))),32,false)); tu.constant(shamt,8))),32,false));
} }
} }
@ -1473,10 +1455,9 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext((tu.add(
tu.ext((tu.add( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0), tu.load(rs2 + traits::X0, 0))),32,false));
tu.load(rs2+ traits::X0, 0))),32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1512,10 +1493,9 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext((tu.sub(
tu.ext((tu.sub( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0), tu.load(rs2 + traits::X0, 0))),32,false));
tu.load(rs2+ traits::X0, 0))),32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1551,11 +1531,10 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.shl(
tu.shl( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0),
(tu.bitwise_and( (tu.bitwise_and(
tu.load(rs2+ traits::X0, 0), tu.load(rs2 + traits::X0, 0),
tu.constant((static_cast<uint32_t>(traits:: XLEN)-1),64))))); tu.constant((static_cast<uint32_t>(traits:: XLEN)-1),64)))));
} }
} }
@ -1592,10 +1571,9 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.conditionalAssignment(tu.icmp(ICmpInst::ICMP_SLT,
tu.conditionalAssignment(tu.icmp(ICmpInst::ICMP_SLT, tu.ext(tu.load(rs1 + traits::X0, 0),32,true),
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs2 + traits::X0, 0),32,true)), tu.constant(1,8),tu.constant(0,8)));
tu.ext(tu.load(rs2+ traits::X0, 0),32,true)), tu.constant(1,8),tu.constant(0,8)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1631,10 +1609,9 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.conditionalAssignment(tu.icmp(ICmpInst::ICMP_ULT,
tu.conditionalAssignment(tu.icmp(ICmpInst::ICMP_ULT, tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0), tu.load(rs2 + traits::X0, 0)), tu.constant(1,8),tu.constant(0,8)));
tu.load(rs2+ traits::X0, 0)), tu.constant(1,8),tu.constant(0,8)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1670,10 +1647,9 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.bitwise_xor(
tu.bitwise_xor( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0), tu.load(rs2 + traits::X0, 0)));
tu.load(rs2+ traits::X0, 0)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1709,11 +1685,10 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.lshr(
tu.lshr( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0),
(tu.bitwise_and( (tu.bitwise_and(
tu.load(rs2+ traits::X0, 0), tu.load(rs2 + traits::X0, 0),
tu.constant((static_cast<uint32_t>(traits:: XLEN)-1),64))))); tu.constant((static_cast<uint32_t>(traits:: XLEN)-1),64)))));
} }
} }
@ -1750,11 +1725,10 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext((tu.ashr(
tu.ext((tu.ashr( tu.ext(tu.load(rs1 + traits::X0, 0),32,true),
tu.ext(tu.load(rs1+ traits::X0, 0),32,true),
(tu.bitwise_and( (tu.bitwise_and(
tu.load(rs2+ traits::X0, 0), tu.load(rs2 + traits::X0, 0),
tu.constant((static_cast<uint32_t>(traits:: XLEN)-1),64))))),32,false)); tu.constant((static_cast<uint32_t>(traits:: XLEN)-1),64))))),32,false));
} }
} }
@ -1791,10 +1765,9 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.bitwise_or(
tu.bitwise_or( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0), tu.load(rs2 + traits::X0, 0)));
tu.load(rs2+ traits::X0, 0)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1830,10 +1803,9 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.bitwise_and(
tu.bitwise_and( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0), tu.load(rs2 + traits::X0, 0)));
tu.load(rs2+ traits::X0, 0)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2002,11 +1974,10 @@ private:
this->gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION)); this->gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
auto xrs1 = tu.assignment(tu.load(rs1+ traits::X0, 0),32); auto xrs1 = tu.assignment(tu.load(rs1 + traits::X0, 0),32);
if(rd!=0){ auto xrd = tu.assignment(tu.read_mem(traits::CSR, csr, 32),32); if(rd!=0){ auto xrd = tu.assignment(tu.read_mem(traits::CSR, csr, 32),32);
tu.write_mem(traits::CSR, csr, xrs1); tu.write_mem(traits::CSR, csr, xrs1);
tu.store(rd + traits::X0, tu.store(rd + traits::X0, xrd);
xrd);
} }
else{ else{
tu.write_mem(traits::CSR, csr, xrs1); tu.write_mem(traits::CSR, csr, xrs1);
@ -2045,15 +2016,14 @@ private:
} }
else{ else{
auto xrd = tu.assignment(tu.read_mem(traits::CSR, csr, 32),32); auto xrd = tu.assignment(tu.read_mem(traits::CSR, csr, 32),32);
auto xrs1 = tu.assignment(tu.load(rs1+ traits::X0, 0),32); auto xrs1 = tu.assignment(tu.load(rs1 + traits::X0, 0),32);
if(rs1!=0) { if(rs1!=0) {
tu.write_mem(traits::CSR, csr, tu.bitwise_or( tu.write_mem(traits::CSR, csr, tu.bitwise_or(
xrd, xrd,
xrs1)); xrs1));
} }
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, xrd);
xrd);
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2089,15 +2059,14 @@ private:
} }
else{ else{
auto xrd = tu.assignment(tu.read_mem(traits::CSR, csr, 32),32); auto xrd = tu.assignment(tu.read_mem(traits::CSR, csr, 32),32);
auto xrs1 = tu.assignment(tu.load(rs1+ traits::X0, 0),32); auto xrs1 = tu.assignment(tu.load(rs1 + traits::X0, 0),32);
if(rs1!=0) { if(rs1!=0) {
tu.write_mem(traits::CSR, csr, tu.bitwise_and( tu.write_mem(traits::CSR, csr, tu.bitwise_and(
xrd, xrd,
tu.logical_neg(xrs1))); tu.logical_neg(xrs1)));
} }
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, xrd);
xrd);
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2135,8 +2104,7 @@ private:
auto xrd = tu.assignment(tu.read_mem(traits::CSR, csr, 32),32); auto xrd = tu.assignment(tu.read_mem(traits::CSR, csr, 32),32);
tu.write_mem(traits::CSR, csr, tu.constant((uint32_t)zimm,32)); tu.write_mem(traits::CSR, csr, tu.constant((uint32_t)zimm,32));
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, xrd);
xrd);
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2178,8 +2146,7 @@ private:
tu.constant((uint32_t)zimm,32))); tu.constant((uint32_t)zimm,32)));
} }
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, xrd);
xrd);
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2221,8 +2188,7 @@ private:
tu.constant(~ ((uint32_t)zimm),32))); tu.constant(~ ((uint32_t)zimm),32)));
} }
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, xrd);
xrd);
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2287,11 +2253,10 @@ private:
} }
else{ else{
auto res = tu.assignment(tu.mul( auto res = tu.assignment(tu.mul(
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs1 + traits::X0, 0),32,true),
tu.ext(tu.load(rs2+ traits::X0, 0),32,true)),64); tu.ext(tu.load(rs2 + traits::X0, 0),32,true)),64);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext(res,32,false));
tu.ext(res,32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2327,11 +2292,10 @@ private:
} }
else{ else{
auto res = tu.assignment(tu.mul( auto res = tu.assignment(tu.mul(
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs1 + traits::X0, 0),32,true),
tu.ext(tu.load(rs2+ traits::X0, 0),32,true)),64); tu.ext(tu.load(rs2 + traits::X0, 0),32,true)),64);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext((tu.ashr(
tu.ext((tu.ashr(
res, res,
tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false)); tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false));
} }
@ -2369,11 +2333,10 @@ private:
} }
else{ else{
auto res = tu.assignment(tu.mul( auto res = tu.assignment(tu.mul(
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs1 + traits::X0, 0),32,true),
tu.load(rs2+ traits::X0, 0)),64); tu.load(rs2 + traits::X0, 0)),64);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext((tu.ashr(
tu.ext((tu.ashr(
res, res,
tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false)); tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false));
} }
@ -2411,11 +2374,10 @@ private:
} }
else{ else{
auto res = tu.assignment(tu.mul( auto res = tu.assignment(tu.mul(
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.load(rs2+ traits::X0, 0)),64); tu.load(rs2 + traits::X0, 0)),64);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext((tu.lshr(
tu.ext((tu.lshr(
res, res,
tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false)); tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false));
} }
@ -2452,30 +2414,27 @@ private:
this->gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION)); this->gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
auto dividend = tu.assignment(tu.ext(tu.load(rs1+ traits::X0, 0),32,true),32); auto dividend = tu.assignment(tu.ext(tu.load(rs1 + traits::X0, 0),32,true),32);
auto divisor = tu.assignment(tu.ext(tu.load(rs2+ traits::X0, 0),32,true),32); auto divisor = tu.assignment(tu.ext(tu.load(rs2 + traits::X0, 0),32,true),32);
if(rd!=0){ tu.open_if(tu.icmp(ICmpInst::ICMP_NE, if(rd!=0){ tu.open_if(tu.icmp(ICmpInst::ICMP_NE,
divisor, divisor,
tu.constant(0,8))); tu.constant(0,8)));
auto MMIN = ((uint32_t)1)<<(static_cast<uint32_t>(traits:: XLEN)-1); auto MMIN = ((uint32_t)1)<<(static_cast<uint32_t>(traits:: XLEN)-1);
tu.open_if(tu.logical_and( tu.open_if(tu.logical_and(
tu.icmp(ICmpInst::ICMP_EQ, tu.icmp(ICmpInst::ICMP_EQ,
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.constant(MMIN,32)), tu.constant(MMIN,32)),
tu.icmp(ICmpInst::ICMP_EQ, tu.icmp(ICmpInst::ICMP_EQ,
divisor, divisor,
tu.constant(- 1,8)))); tu.constant(- 1,8))));
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.constant(MMIN,32));
tu.constant(MMIN,32));
tu.open_else(); tu.open_else();
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext((tu.sdiv(
tu.ext((tu.sdiv(
dividend, dividend,
divisor)),32,false)); divisor)),32,false));
tu.close_scope(); tu.close_scope();
tu.open_else(); tu.open_else();
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.constant((uint32_t)- 1,32));
tu.constant((uint32_t)- 1,32));
tu.close_scope(); tu.close_scope();
} }
} }
@ -2512,18 +2471,16 @@ private:
} }
else{ else{
tu.open_if(tu.icmp(ICmpInst::ICMP_NE, tu.open_if(tu.icmp(ICmpInst::ICMP_NE,
tu.load(rs2+ traits::X0, 0), tu.load(rs2 + traits::X0, 0),
tu.constant(0,8))); tu.constant(0,8)));
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.udiv(
tu.udiv( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0), tu.load(rs2 + traits::X0, 0)));
tu.load(rs2+ traits::X0, 0)));
} }
tu.open_else(); tu.open_else();
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.constant((uint32_t)- 1,32));
tu.constant((uint32_t)- 1,32));
} }
tu.close_scope(); tu.close_scope();
} }
@ -2560,32 +2517,29 @@ private:
} }
else{ else{
tu.open_if(tu.icmp(ICmpInst::ICMP_NE, tu.open_if(tu.icmp(ICmpInst::ICMP_NE,
tu.load(rs2+ traits::X0, 0), tu.load(rs2 + traits::X0, 0),
tu.constant(0,8))); tu.constant(0,8)));
auto MMIN = (uint32_t)1<<(static_cast<uint32_t>(traits:: XLEN)-1); auto MMIN = (uint32_t)1<<(static_cast<uint32_t>(traits:: XLEN)-1);
tu.open_if(tu.logical_and( tu.open_if(tu.logical_and(
tu.icmp(ICmpInst::ICMP_EQ, tu.icmp(ICmpInst::ICMP_EQ,
tu.load(rs1+ traits::X0, 0), tu.load(rs1 + traits::X0, 0),
tu.constant(MMIN,32)), tu.constant(MMIN,32)),
tu.icmp(ICmpInst::ICMP_EQ, tu.icmp(ICmpInst::ICMP_EQ,
tu.ext(tu.load(rs2+ traits::X0, 0),32,true), tu.ext(tu.load(rs2 + traits::X0, 0),32,true),
tu.constant(- 1,8)))); tu.constant(- 1,8))));
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.constant(0,8));
tu.constant(0,8));
} }
tu.open_else(); tu.open_else();
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext((tu.srem(
tu.ext((tu.srem( tu.ext(tu.load(rs1 + traits::X0, 0),32,true),
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs2 + traits::X0, 0),32,true))),32,false));
tu.ext(tu.load(rs2+ traits::X0, 0),32,true))),32,false));
} }
tu.close_scope(); tu.close_scope();
tu.open_else(); tu.open_else();
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.load(rs1 + traits::X0, 0));
tu.load(rs1+ traits::X0, 0));
} }
tu.close_scope(); tu.close_scope();
} }
@ -2622,18 +2576,16 @@ private:
} }
else{ else{
tu.open_if(tu.icmp(ICmpInst::ICMP_NE, tu.open_if(tu.icmp(ICmpInst::ICMP_NE,
tu.load(rs2+ traits::X0, 0), tu.load(rs2 + traits::X0, 0),
tu.constant(0,8))); tu.constant(0,8)));
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.urem(
tu.urem( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0), tu.load(rs2 + traits::X0, 0)));
tu.load(rs2+ traits::X0, 0)));
} }
tu.open_else(); tu.open_else();
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.load(rs1 + traits::X0, 0));
tu.load(rs1+ traits::X0, 0));
} }
tu.close_scope(); tu.close_scope();
} }
@ -2665,9 +2617,8 @@ private:
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
if(imm) { if(imm) {
tu.store(rd+8 + traits::X0, tu.store(rd+8 + traits::X0, tu.ext((tu.add(
tu.ext((tu.add( tu.load(2 + traits::X0, 0),
tu.load(2+ traits::X0, 0),
tu.constant(imm,16))),32,false)); tu.constant(imm,16))),32,false));
} }
else{ else{
@ -2702,10 +2653,9 @@ private:
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
auto offs = tu.assignment(tu.ext((tu.add( auto offs = tu.assignment(tu.ext((tu.add(
tu.load(rs1+8+ traits::X0, 0), tu.load(rs1+8 + traits::X0, 0),
tu.constant(uimm,8))),32,false),32); tu.constant(uimm,8))),32,false),32);
tu.store(rd+8 + traits::X0, tu.store(rd+8 + traits::X0, tu.ext(tu.ext(tu.read_mem(traits::MEM, offs, 32),32,true),32,false));
tu.ext(tu.ext(tu.read_mem(traits::MEM, offs, 32),32,true),32,false));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
tu.close_scope(); tu.close_scope();
@ -2735,9 +2685,9 @@ private:
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
auto offs = tu.assignment(tu.ext((tu.add( auto offs = tu.assignment(tu.ext((tu.add(
tu.load(rs1+8+ traits::X0, 0), tu.load(rs1+8 + traits::X0, 0),
tu.constant(uimm,8))),32,false),32); tu.constant(uimm,8))),32,false),32);
tu.write_mem(traits::MEM, offs, tu.ext(tu.load(rs2+8+ traits::X0, 0),32,false)); tu.write_mem(traits::MEM, offs, tu.ext(tu.load(rs2+8 + traits::X0, 0),32,false));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
tu.close_scope(); tu.close_scope();
@ -2770,9 +2720,8 @@ private:
} }
else{ else{
if(rs1!=0) { if(rs1!=0) {
tu.store(rs1 + traits::X0, tu.store(rs1 + traits::X0, tu.ext((tu.add(
tu.ext((tu.add( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0),
tu.constant((int8_t)sext<6>(imm),8))),32,false)); tu.constant((int8_t)sext<6>(imm),8))),32,false));
} }
} }
@ -2828,8 +2777,7 @@ private:
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(NO_JUMP),32)); tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(NO_JUMP),32));
tu.store(1 + traits::X0, tu.store(1 + traits::X0, tu.constant((uint32_t)(PC+2),32));
tu.constant((uint32_t)(PC+2),32));
auto PC_val_v = tu.assignment("PC_val", (uint32_t)(PC+(int16_t)sext<12>(imm)),32); auto PC_val_v = tu.assignment("PC_val", (uint32_t)(PC+(int16_t)sext<12>(imm)),32);
tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::NEXT_PC, PC_val_v);
tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(KNOWN_JUMP), 2)); tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(KNOWN_JUMP), 2));
@ -2865,8 +2813,7 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.constant((uint32_t)((int8_t)sext<6>(imm)),32));
tu.constant((uint32_t)((int8_t)sext<6>(imm)),32));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2900,8 +2847,7 @@ private:
this->gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION)); this->gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.constant((uint32_t)((int32_t)sext<18>(imm)),32));
tu.constant((uint32_t)((int32_t)sext<18>(imm)),32));
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2930,9 +2876,8 @@ private:
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
if(nzimm) { if(nzimm) {
tu.store(2 + traits::X0, tu.store(2 + traits::X0, tu.ext((tu.add(
tu.ext((tu.add( tu.load(2 + traits::X0, 0),
tu.load(2+ traits::X0, 0),
tu.constant((int16_t)sext<10>(nzimm),16))),32,false)); tu.constant((int16_t)sext<10>(nzimm),16))),32,false));
} }
else{ else{
@ -2991,9 +2936,8 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(rs1+8 + traits::X0, tu.store(rs1+8 + traits::X0, tu.lshr(
tu.lshr( tu.load(rs1+8 + traits::X0, 0),
tu.load(rs1+8+ traits::X0, 0),
tu.constant(shamt,8))); tu.constant(shamt,8)));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3022,15 +2966,13 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
if(shamt){ tu.store(rs1+8 + traits::X0, if(shamt){ tu.store(rs1+8 + traits::X0, tu.ext((tu.ashr(
tu.ext((tu.ashr( (tu.ext(tu.load(rs1+8 + traits::X0, 0),32,true)),
(tu.ext(tu.load(rs1+8+ traits::X0, 0),32,true)),
tu.constant(shamt,8))),32,false)); tu.constant(shamt,8))),32,false));
} }
else{ else{
if(static_cast<uint32_t>(traits:: XLEN)==128){ tu.store(rs1+8 + traits::X0, if(static_cast<uint32_t>(traits:: XLEN)==128){ tu.store(rs1+8 + traits::X0, tu.ext((tu.ashr(
tu.ext((tu.ashr( (tu.ext(tu.load(rs1+8 + traits::X0, 0),32,true)),
(tu.ext(tu.load(rs1+8+ traits::X0, 0),32,true)),
tu.constant(64,8))),32,false)); tu.constant(64,8))),32,false));
} }
} }
@ -3061,9 +3003,8 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(rs1+8 + traits::X0, tu.store(rs1+8 + traits::X0, tu.ext((tu.bitwise_and(
tu.ext((tu.bitwise_and( tu.load(rs1+8 + traits::X0, 0),
tu.load(rs1+8+ traits::X0, 0),
tu.constant((int8_t)sext<6>(imm),8))),32,false)); tu.constant((int8_t)sext<6>(imm),8))),32,false));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3092,10 +3033,9 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(rd+8 + traits::X0, tu.store(rd+8 + traits::X0, tu.ext((tu.sub(
tu.ext((tu.sub( tu.load(rd+8 + traits::X0, 0),
tu.load(rd+8+ traits::X0, 0), tu.load(rs2+8 + traits::X0, 0))),32,false));
tu.load(rs2+8+ traits::X0, 0))),32,false));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
tu.close_scope(); tu.close_scope();
@ -3123,10 +3063,9 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(rd+8 + traits::X0, tu.store(rd+8 + traits::X0, tu.bitwise_xor(
tu.bitwise_xor( tu.load(rd+8 + traits::X0, 0),
tu.load(rd+8+ traits::X0, 0), tu.load(rs2+8 + traits::X0, 0)));
tu.load(rs2+8+ traits::X0, 0)));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
tu.close_scope(); tu.close_scope();
@ -3154,10 +3093,9 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(rd+8 + traits::X0, tu.store(rd+8 + traits::X0, tu.bitwise_or(
tu.bitwise_or( tu.load(rd+8 + traits::X0, 0),
tu.load(rd+8+ traits::X0, 0), tu.load(rs2+8 + traits::X0, 0)));
tu.load(rs2+8+ traits::X0, 0)));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
tu.close_scope(); tu.close_scope();
@ -3185,10 +3123,9 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(rd+8 + traits::X0, tu.store(rd+8 + traits::X0, tu.bitwise_and(
tu.bitwise_and( tu.load(rd+8 + traits::X0, 0),
tu.load(rd+8+ traits::X0, 0), tu.load(rs2+8 + traits::X0, 0)));
tu.load(rs2+8+ traits::X0, 0)));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
tu.close_scope(); tu.close_scope();
@ -3248,7 +3185,7 @@ private:
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(NO_JUMP),32)); tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(NO_JUMP),32));
tu.open_if(tu.icmp(ICmpInst::ICMP_EQ, tu.open_if(tu.icmp(ICmpInst::ICMP_EQ,
tu.load(rs1+8+ traits::X0, 0), tu.load(rs1+8 + traits::X0, 0),
tu.constant(0,8))); tu.constant(0,8)));
auto PC_val_v = tu.assignment("PC_val", (uint32_t)(PC+(int16_t)sext<9>(imm)),32); 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::NEXT_PC, PC_val_v);
@ -3283,7 +3220,7 @@ private:
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(NO_JUMP),32)); tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(NO_JUMP),32));
tu.open_if(tu.icmp(ICmpInst::ICMP_NE, tu.open_if(tu.icmp(ICmpInst::ICMP_NE,
tu.load(rs1+8+ traits::X0, 0), tu.load(rs1+8 + traits::X0, 0),
tu.constant(0,8))); tu.constant(0,8)));
auto PC_val_v = tu.assignment("PC_val", (uint32_t)(PC+(int16_t)sext<9>(imm)),32); 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::NEXT_PC, PC_val_v);
@ -3321,9 +3258,8 @@ private:
} }
else{ else{
if(rs1!=0) { if(rs1!=0) {
tu.store(rs1 + traits::X0, tu.store(rs1 + traits::X0, tu.shl(
tu.shl( tu.load(rs1 + traits::X0, 0),
tu.load(rs1+ traits::X0, 0),
tu.constant(nzuimm,8))); tu.constant(nzuimm,8)));
} }
} }
@ -3359,10 +3295,9 @@ private:
} }
else{ else{
auto offs = tu.assignment(tu.ext((tu.add( auto offs = tu.assignment(tu.ext((tu.add(
tu.load(2+ traits::X0, 0), tu.load(2 + traits::X0, 0),
tu.constant(uimm,8))),32,false),32); tu.constant(uimm,8))),32,false),32);
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext(tu.ext(tu.read_mem(traits::MEM, offs, 32),32,true),32,false));
tu.ext(tu.ext(tu.read_mem(traits::MEM, offs, 32),32,true),32,false));
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3396,8 +3331,7 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.load(rs2 + traits::X0, 0));
tu.load(rs2+ traits::X0, 0));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3429,7 +3363,7 @@ private:
tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(NO_JUMP),32)); tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(NO_JUMP),32));
if(rs1&&rs1<static_cast<uint32_t>(traits:: RFS)){ auto addr_mask = (uint32_t)- 2; 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( auto PC_val_v = tu.assignment("PC_val", tu.bitwise_and(
tu.load(rs1%static_cast<uint32_t>(traits:: RFS)+ traits::X0, 0), tu.load(rs1%static_cast<uint32_t>(traits:: RFS) + traits::X0, 0),
tu.constant(addr_mask,32)),32); tu.constant(addr_mask,32)),32);
tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::NEXT_PC, PC_val_v);
tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(UNKNOWN_JUMP), 2)); tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(UNKNOWN_JUMP), 2));
@ -3494,10 +3428,9 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0, tu.ext((tu.add(
tu.ext((tu.add( tu.load(rd + traits::X0, 0),
tu.load(rd+ traits::X0, 0), tu.load(rs2 + traits::X0, 0))),32,false));
tu.load(rs2+ traits::X0, 0))),32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3532,9 +3465,8 @@ private:
} }
else{ else{
auto addr_mask = (uint32_t)- 2; auto addr_mask = (uint32_t)- 2;
auto new_pc = tu.assignment(tu.load(rs1+ traits::X0, 0),32); auto new_pc = tu.assignment(tu.load(rs1 + traits::X0, 0),32);
tu.store(1 + traits::X0, tu.store(1 + traits::X0, tu.constant((uint32_t)(PC+2),32));
tu.constant((uint32_t)(PC+2),32));
auto PC_val_v = tu.assignment("PC_val", tu.bitwise_and( auto PC_val_v = tu.assignment("PC_val", tu.bitwise_and(
new_pc, new_pc,
tu.constant(addr_mask,32)),32); tu.constant(addr_mask,32)),32);
@ -3598,9 +3530,9 @@ private:
} }
else{ else{
auto offs = tu.assignment(tu.ext((tu.add( auto offs = tu.assignment(tu.ext((tu.add(
tu.load(2+ traits::X0, 0), tu.load(2 + traits::X0, 0),
tu.constant(uimm,8))),32,false),32); tu.constant(uimm,8))),32,false),32);
tu.write_mem(traits::MEM, offs, tu.ext(tu.load(rs2+ traits::X0, 0),32,false)); tu.write_mem(traits::MEM, offs, tu.ext(tu.load(rs2 + traits::X0, 0),32,false));
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3645,7 +3577,7 @@ private:
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, std::string("illegal_instruction")); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, std::string("illegal_instruction"));
} }
pc = pc + ((instr & 3) == 3 ? 4 : 2); pc = pc + ((instr & 3) == 3 ? 4 : 2);
gen_raise_trap(tu, 0, 2); // illegal instruction trap gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION));
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
vm_impl::gen_sync(tu, iss::POST_SYNC, instr_descr.size()); vm_impl::gen_sync(tu, iss::POST_SYNC, instr_descr.size());
vm_impl::gen_trap_check(tu); vm_impl::gen_trap_check(tu);