Compare commits

..

No commits in common. "212fb1c8fff472723295a561dde59ab75ae069d2" and "f074092a78ca97023401798e367f3b5c061445a2" have entirely different histories.

7 changed files with 138 additions and 407 deletions

View File

@ -304,9 +304,9 @@ protected:
*/ */
const std::string core_type_name() const override { return traits<BASE>::core_type; } const std::string core_type_name() const override { return traits<BASE>::core_type; }
uint64_t get_pc() override { return arch.reg.PC; } uint64_t get_pc() override { return arch.reg.PC; };
uint64_t get_next_pc() override { return arch.reg.NEXT_PC; } uint64_t get_next_pc() override { return arch.reg.NEXT_PC; };
uint64_t get_instr_word() override { return arch.reg.instruction; } uint64_t get_instr_word() override { return arch.reg.instruction; }
@ -316,11 +316,9 @@ protected:
uint64_t get_total_cycles() override { return arch.reg.icount + arch.cycle_offset; } uint64_t get_total_cycles() override { return arch.reg.icount + arch.cycle_offset; }
void update_last_instr_cycles(unsigned cycles) override { arch.cycle_offset += cycles - 1; } void update_last_instr_cycles(unsigned cycles) override { arch.cycle_offset += cycles - 1; };
bool is_branch_taken() override { return arch.reg.last_branch; } bool is_branch_taken() override { return arch.reg.last_branch; };
unsigned get_reg_num() override {return traits<BASE>::NUM_REGS;}
riscv_hart_m_p<BASE, FEAT> &arch; riscv_hart_m_p<BASE, FEAT> &arch;
}; };

View File

@ -331,9 +331,9 @@ protected:
*/ */
const std::string core_type_name() const override { return traits<BASE>::core_type; } const std::string core_type_name() const override { return traits<BASE>::core_type; }
uint64_t get_pc() override { return arch.reg.PC; } uint64_t get_pc() override { return arch.reg.PC; };
uint64_t get_next_pc() override { return arch.reg.NEXT_PC; } uint64_t get_next_pc() override { return arch.reg.NEXT_PC; };
uint64_t get_instr_word() override { return arch.reg.instruction; } uint64_t get_instr_word() override { return arch.reg.instruction; }
@ -343,11 +343,9 @@ protected:
uint64_t get_total_cycles() override { return arch.reg.icount + arch.cycle_offset; } uint64_t get_total_cycles() override { return arch.reg.icount + arch.cycle_offset; }
void update_last_instr_cycles(unsigned cycles) override { arch.cycle_offset += cycles - 1; } void update_last_instr_cycles(unsigned cycles) override { arch.cycle_offset += cycles - 1; };
bool is_branch_taken() override { return arch.reg.last_branch; } bool is_branch_taken() override { return arch.reg.last_branch; };
unsigned get_reg_num() override {return traits<BASE>::NUM_REGS; }
riscv_hart_msu_vp<BASE> &arch; riscv_hart_msu_vp<BASE> &arch;
}; };

View File

@ -329,9 +329,9 @@ protected:
*/ */
const std::string core_type_name() const override { return traits<BASE>::core_type; } const std::string core_type_name() const override { return traits<BASE>::core_type; }
uint64_t get_pc() override { return arch.reg.PC; } uint64_t get_pc() override { return arch.reg.PC; };
uint64_t get_next_pc() override { return arch.reg.NEXT_PC; } uint64_t get_next_pc() override { return arch.reg.NEXT_PC; };
uint64_t get_instr_word() override { return arch.reg.instruction; } uint64_t get_instr_word() override { return arch.reg.instruction; }
@ -341,11 +341,9 @@ protected:
uint64_t get_total_cycles() override { return arch.reg.icount + arch.cycle_offset; } uint64_t get_total_cycles() override { return arch.reg.icount + arch.cycle_offset; }
void update_last_instr_cycles(unsigned cycles) override { arch.cycle_offset += cycles - 1; } void update_last_instr_cycles(unsigned cycles) override { arch.cycle_offset += cycles - 1; };
bool is_branch_taken() override { return arch.reg.last_branch; } bool is_branch_taken() override { return arch.reg.last_branch; };
unsigned get_reg_num() override {return traits<BASE>::NUM_REGS; }
riscv_hart_mu_p<BASE, FEAT> &arch; riscv_hart_mu_p<BASE, FEAT> &arch;
}; };

View File

@ -1,8 +0,0 @@
# pctrace
Trace functionality to allow visualizing coverage in lcov and cachegrind tools. Use environment variables NOCOMPRES and REGDUMP to toggle functionality.
- NOCOMPRES: any value turns off the LZ4 compression
- REGDUMP: any value switches to tracing the registers instead. Also turns off compression.
Known Bugs:
- currently does not work correctly with jit backends, the plugin cant tell if instructions are compressed. Additionaly the cost of instrs that raise a trap is not known. It takes the cost of the instrid -1 (0 at the moment).

View File

@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* Contributors: * Contributors:
* alex@minres.com - initial implementation * alex.com - initial implementation
******************************************************************************/ ******************************************************************************/
#include <iss/arch_if.h> #include <iss/arch_if.h>
@ -55,11 +55,11 @@ using namespace rapidjson;
using namespace std; using namespace std;
#ifdef WITH_LZ4 #ifdef WITH_LZ4
class lz4compress_streambuf: public std::streambuf { class lz4compress_steambuf: public std::streambuf {
public: public:
lz4compress_streambuf(const lz4compress_streambuf&) = delete; lz4compress_steambuf(const lz4compress_steambuf&) = delete;
lz4compress_streambuf& operator=(const lz4compress_streambuf&) = delete; lz4compress_steambuf& operator=(const lz4compress_steambuf&) = delete;
lz4compress_streambuf(std::ostream &sink, size_t buf_size) lz4compress_steambuf(std::ostream &sink, size_t buf_size)
: sink(sink) : sink(sink)
, src_buf(buf_size) , src_buf(buf_size)
, dest_buf(LZ4F_compressBound(buf_size, nullptr)) , dest_buf(LZ4F_compressBound(buf_size, nullptr))
@ -74,7 +74,7 @@ public:
sink.write(dest_buf.data(), ret); sink.write(dest_buf.data(), ret);
} }
~lz4compress_streambuf() { ~lz4compress_steambuf() {
close(); close();
} }
@ -126,11 +126,9 @@ private:
pctrace::pctrace(std::string const &filename) pctrace::pctrace(std::string const &filename)
: instr_if(nullptr) : instr_if(nullptr)
, filename(filename) , filename(filename)
, reg_dump(getenv("REGDUMP"))
, no_compres(getenv("NOCOMPRES"))
, output("output.trc") , output("output.trc")
#ifdef WITH_LZ4 #ifdef WITH_LZ4
, strbuf( (no_compres || reg_dump)? nullptr: new lz4compress_streambuf(output, 4096)) , strbuf(new lz4compress_steambuf(output, 4096))
, ostr(strbuf.get()) , ostr(strbuf.get())
#endif #endif
{ } { }
@ -139,8 +137,6 @@ pctrace::~pctrace() { }
bool pctrace::registration(const char *const version, vm_if& vm) { bool pctrace::registration(const char *const version, vm_if& vm) {
instr_if = vm.get_arch()->get_instrumentation_if(); instr_if = vm.get_arch()->get_instrumentation_if();
reg_base_ptr = reinterpret_cast<uint32_t*>(vm.get_arch()->get_regs_base_ptr());
if(!instr_if) return false; if(!instr_if) return false;
const string core_name = instr_if->core_type_name(); const string core_name = instr_if->core_type_name();
if (filename.length() > 0) { if (filename.length() > 0) {
@ -207,22 +203,12 @@ void pctrace::callback(instr_info_t iinfo) {
if (entry.not_taken > 1) if (entry.not_taken > 1)
instr_if->update_last_instr_cycles(entry.not_taken); instr_if->update_last_instr_cycles(entry.not_taken);
} }
if(no_compres|| reg_dump){ #ifndef WITH_LZ4
if(reg_dump){ output<<std::hex <<"0x" << instr_if->get_pc() <<"," << delay <<"," << call<<","<<(compressed?2:4) <<"\n";
for(size_t i=0; i< instr_if->get_reg_num(); ++i){ #else
uint32_t reg_val = *(reg_base_ptr+i); auto rdbuf=ostr.rdbuf();
output << "0x" << std::setfill('0') << std::setw(8) << std::hex << reg_val << " ";
}
output<<"\n" ;
}
else{
output<<std::hex <<"0x" << instr_if->get_pc() <<"," << delay <<"," << call<<","<<(compressed?2:4) <<std::endl;
}
}else{
ostr<<std::hex <<"0x" << instr_if->get_pc() <<"," << delay <<"," << call<<","<<(compressed?2:4) <<"\n"; ostr<<std::hex <<"0x" << instr_if->get_pc() <<"," << delay <<"," << call<<","<<(compressed?2:4) <<"\n";
#endif
}
} }
} }
}//namespace plugin
}//namespace iss

View File

@ -39,10 +39,11 @@
#include "iss/instrumentation_if.h" #include "iss/instrumentation_if.h"
#include <string> #include <string>
#include <fstream> #include <fstream>
#include <cstdlib>
namespace iss { namespace iss {
namespace plugin { namespace plugin {
class lz4compress_streambuf; class lz4compress_steambuf;
class pctrace : public iss::vm_plugin { class pctrace : public iss::vm_plugin {
struct instr_delay { struct instr_delay {
std::string instr_name; std::string instr_name;
@ -85,13 +86,9 @@ public:
private: private:
iss::instrumentation_if *instr_if {nullptr}; iss::instrumentation_if *instr_if {nullptr};
uint32_t* reg_base_ptr {nullptr};
bool reg_dump {false};
bool no_compres {false};
std::ofstream output; std::ofstream output;
#ifdef WITH_LZ4 #ifdef WITH_LZ4
std::unique_ptr<lz4compress_streambuf> strbuf; std::unique_ptr<lz4compress_steambuf> strbuf;
std::ostream ostr; std::ostream ostr;
#endif #endif
std::string filename; std::string filename;

View File

@ -350,8 +350,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);
@ -385,8 +384,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);
@ -423,8 +421,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", (uint32_t)(PC+(int32_t)sext<21>(imm)),32); auto PC_val_v = tu.assignment("PC_val", (uint32_t)(PC+(int32_t)sext<21>(imm)),32);
tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::NEXT_PC, PC_val_v);
@ -463,19 +460,12 @@ private:
} }
else{ else{
auto addr_mask = tu.assignment(tu.constant((uint32_t)- 2,32),32); auto addr_mask = tu.assignment(tu.constant((uint32_t)- 2,32),32);
auto new_pc = tu.assignment(tu.ext((tu.bitwise_and( 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.add( tu.open_if(tu.srem(new_pc,tu.constant(static_cast<uint32_t>(traits:: INSTR_ALIGNMENT),32)));
tu.load(rs1+ traits::X0, 0),
tu.constant((int16_t)sext<12>(imm),16))),
addr_mask)),32,false),32);
tu.open_if(tu.urem(
new_pc,
tu.constant(static_cast<uint32_t>(traits:: INSTR_ALIGNMENT),32)));
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);
@ -513,9 +503,7 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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(rs2+ traits::X0, 0)));
tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0)));
if(imm%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_raise_trap(tu, 0, 0); if(imm%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_raise_trap(tu, 0, 0);
} }
else{ else{
@ -556,9 +544,7 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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(rs2+ traits::X0, 0)));
tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0)));
if(imm%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_raise_trap(tu, 0, 0); if(imm%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_raise_trap(tu, 0, 0);
} }
else{ else{
@ -599,9 +585,7 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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(rs2+ 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)));
if(imm%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_raise_trap(tu, 0, 0); if(imm%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_raise_trap(tu, 0, 0);
} }
else{ else{
@ -642,9 +626,7 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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(rs2+ 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)));
if(imm%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_raise_trap(tu, 0, 0); if(imm%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_raise_trap(tu, 0, 0);
} }
else{ else{
@ -685,9 +667,7 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
else{ else{
tu.open_if(tu.icmp(ICmpInst::ICMP_ULT, tu.open_if(tu.icmp(ICmpInst::ICMP_SLT,tu.load(rs1+ traits::X0, 0),tu.load(rs2+ traits::X0, 0)));
tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0)));
if(imm%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_raise_trap(tu, 0, 0); if(imm%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_raise_trap(tu, 0, 0);
} }
else{ else{
@ -728,9 +708,7 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
else{ else{
tu.open_if(tu.icmp(ICmpInst::ICMP_UGE, tu.open_if(tu.icmp(ICmpInst::ICMP_SGE,tu.load(rs1+ traits::X0, 0),tu.load(rs2+ traits::X0, 0)));
tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0)));
if(imm%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_raise_trap(tu, 0, 0); if(imm%static_cast<uint32_t>(traits:: INSTR_ALIGNMENT)){ this->gen_raise_trap(tu, 0, 0);
} }
else{ else{
@ -771,13 +749,10 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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.constant((int16_t)sext<12>(imm),16))),32,false),32);
tu.load(rs1+ traits::X0, 0),
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);
@ -811,13 +786,10 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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.constant((int16_t)sext<12>(imm),16))),32,false),32);
tu.load(rs1+ traits::X0, 0),
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);
@ -851,13 +823,10 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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.constant((int16_t)sext<12>(imm),16))),32,false),32);
tu.load(rs1+ traits::X0, 0),
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);
@ -891,13 +860,10 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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.constant((int16_t)sext<12>(imm),16))),32,false),32);
tu.load(rs1+ traits::X0, 0),
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);
@ -931,13 +897,10 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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.constant((int16_t)sext<12>(imm),16))),32,false),32);
tu.load(rs1+ traits::X0, 0),
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);
@ -971,9 +934,7 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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.constant((int16_t)sext<12>(imm),16))),32,false),32);
tu.load(rs1+ traits::X0, 0),
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);
@ -1007,9 +968,7 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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.constant((int16_t)sext<12>(imm),16))),32,false),32);
tu.load(rs1+ traits::X0, 0),
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);
@ -1043,9 +1002,7 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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.constant((int16_t)sext<12>(imm),16))),32,false),32);
tu.load(rs1+ traits::X0, 0),
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);
@ -1080,10 +1037,7 @@ private:
} }
else{ else{
if(rd!= 0) { if(rd!= 0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.ext((tu.add(tu.load(rs1+ traits::X0, 0),tu.constant((int16_t)sext<12>(imm),16))),32,false));
tu.ext((tu.add(
tu.load(rs1+ traits::X0, 0),
tu.constant((int16_t)sext<12>(imm),16))),32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1118,10 +1072,7 @@ 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.ext(tu.load(rs1+ traits::X0, 0),32,false),tu.constant((int16_t)sext<12>(imm),16))), tu.constant( 1,8),tu.constant( 0,8)));
tu.conditionalAssignment((tu.icmp(ICmpInst::ICMP_SLT,
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)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1156,10 +1107,7 @@ 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.load(rs1+ traits::X0, 0),tu.constant((uint32_t)((int16_t)sext<12>(imm)),32))), tu.constant( 1,8),tu.constant( 0,8)));
tu.conditionalAssignment((tu.icmp(ICmpInst::ICMP_ULT,
tu.load(rs1+ traits::X0, 0),
tu.constant((uint32_t)((int16_t)sext<12>(imm)),32))), tu.constant( 1,8),tu.constant( 0,8)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1194,10 +1142,7 @@ private:
} }
else{ else{
if(rd!= 0) { if(rd!= 0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.bitwise_xor(tu.load(rs1+ traits::X0, 0),tu.constant((uint32_t)((int16_t)sext<12>(imm)),32)));
tu.bitwise_xor(
tu.load(rs1+ traits::X0, 0),
tu.constant((uint32_t)((int16_t)sext<12>(imm)),32)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1232,10 +1177,7 @@ private:
} }
else{ else{
if(rd!= 0) { if(rd!= 0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.bitwise_or(tu.load(rs1+ traits::X0, 0),tu.constant((uint32_t)((int16_t)sext<12>(imm)),32)));
tu.bitwise_or(
tu.load(rs1+ traits::X0, 0),
tu.constant((uint32_t)((int16_t)sext<12>(imm)),32)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1270,10 +1212,7 @@ private:
} }
else{ else{
if(rd!= 0) { if(rd!= 0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.bitwise_and(tu.load(rs1+ traits::X0, 0),tu.constant((uint32_t)((int16_t)sext<12>(imm)),32)));
tu.bitwise_and(
tu.load(rs1+ traits::X0, 0),
tu.constant((uint32_t)((int16_t)sext<12>(imm)),32)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1308,10 +1247,7 @@ private:
} }
else{ else{
if(rd!= 0) { if(rd!= 0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.shl(tu.load(rs1+ traits::X0, 0),tu.constant(shamt,8)));
tu.shl(
tu.load(rs1+ traits::X0, 0),
tu.constant(shamt,8)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1346,10 +1282,7 @@ private:
} }
else{ else{
if(rd!= 0) { if(rd!= 0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.ashr(tu.load(rs1+ traits::X0, 0),tu.constant(shamt,8)));
tu.lshr(
tu.load(rs1+ traits::X0, 0),
tu.constant(shamt,8)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1384,10 +1317,7 @@ 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.load(rs1+ traits::X0, 0),32,false),tu.constant(shamt,8))),32,false));
tu.ext((tu.ashr(
tu.ext(tu.load(rs1+ traits::X0, 0),32,true),
tu.constant(shamt,8))),32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1422,10 +1352,7 @@ private:
} }
else{ else{
if(rd!= 0) { if(rd!= 0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.ext((tu.add(tu.load(rs1+ traits::X0, 0),tu.load(rs2+ traits::X0, 0))),32,false));
tu.ext((tu.add(
tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0))),32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1460,10 +1387,7 @@ private:
} }
else{ else{
if(rd!= 0) { if(rd!= 0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.ext((tu.sub(tu.load(rs1+ traits::X0, 0),tu.load(rs2+ traits::X0, 0))),32,false));
tu.ext((tu.sub(
tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0))),32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1498,12 +1422,7 @@ private:
} }
else{ else{
if(rd!= 0) { if(rd!= 0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.shl(tu.load(rs1+ traits::X0, 0),(tu.bitwise_and(tu.load(rs2+ traits::X0, 0),tu.constant((static_cast<uint32_t>(traits:: XLEN)- 1),64)))));
tu.shl(
tu.load(rs1+ traits::X0, 0),
(tu.bitwise_and(
tu.load(rs2+ traits::X0, 0),
tu.constant((static_cast<uint32_t>(traits:: XLEN)- 1),64)))));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1538,10 +1457,7 @@ 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.ext(tu.load(rs1+ traits::X0, 0),32,false),tu.ext(tu.load(rs2+ traits::X0, 0),32,false)), tu.constant( 1,8),tu.constant( 0,8)));
tu.conditionalAssignment(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)), tu.constant( 1,8),tu.constant( 0,8)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1576,10 +1492,7 @@ 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.load(rs1+ traits::X0, 0),tu.load(rs2+ traits::X0, 0)), tu.constant( 1,8),tu.constant( 0,8)));
tu.conditionalAssignment(tu.icmp(ICmpInst::ICMP_ULT,
tu.load(rs1+ traits::X0, 0),
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);
@ -1614,10 +1527,7 @@ private:
} }
else{ else{
if(rd!= 0) { if(rd!= 0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.bitwise_xor(tu.load(rs1+ traits::X0, 0),tu.load(rs2+ traits::X0, 0)));
tu.bitwise_xor(
tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1652,12 +1562,7 @@ private:
} }
else{ else{
if(rd!= 0) { if(rd!= 0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.ashr(tu.load(rs1+ traits::X0, 0),(tu.bitwise_and(tu.load(rs2+ traits::X0, 0),tu.constant((static_cast<uint32_t>(traits:: XLEN)- 1),64)))));
tu.lshr(
tu.load(rs1+ traits::X0, 0),
(tu.bitwise_and(
tu.load(rs2+ traits::X0, 0),
tu.constant((static_cast<uint32_t>(traits:: XLEN)- 1),64)))));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1692,12 +1597,7 @@ 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.load(rs1+ traits::X0, 0),32,false),(tu.bitwise_and(tu.load(rs2+ traits::X0, 0),tu.constant((static_cast<uint32_t>(traits:: XLEN)- 1),64))))),32,false));
tu.ext((tu.ashr(
tu.ext(tu.load(rs1+ traits::X0, 0),32,true),
(tu.bitwise_and(
tu.load(rs2+ traits::X0, 0),
tu.constant((static_cast<uint32_t>(traits:: XLEN)- 1),64))))),32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1732,10 +1632,7 @@ private:
} }
else{ else{
if(rd!= 0) { if(rd!= 0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.bitwise_or(tu.load(rs1+ traits::X0, 0),tu.load(rs2+ traits::X0, 0)));
tu.bitwise_or(
tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1770,10 +1667,7 @@ private:
} }
else{ else{
if(rd!= 0) { if(rd!= 0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.bitwise_and(tu.load(rs1+ traits::X0, 0),tu.load(rs2+ traits::X0, 0)));
tu.bitwise_and(
tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1928,8 +1822,7 @@ private:
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);
@ -1969,13 +1862,10 @@ 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);
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,xrs1));
xrd,
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);
@ -2012,13 +1902,10 @@ 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);
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,tu.logical_neg(xrs1)));
xrd,
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);
@ -2055,8 +1942,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);
@ -2092,13 +1978,10 @@ 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);
if(zimm!= 0) { if(zimm!= 0) {
tu.write_mem(traits::CSR, csr, tu.bitwise_or( tu.write_mem(traits::CSR, csr, tu.bitwise_or(xrd,tu.constant((uint32_t)zimm,32)));
xrd,
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);
@ -2134,13 +2017,10 @@ 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);
if(zimm!= 0) { if(zimm!= 0) {
tu.write_mem(traits::CSR, csr, tu.bitwise_and( tu.write_mem(traits::CSR, csr, tu.bitwise_and(xrd,tu.constant(~ ((uint32_t)zimm),32)));
xrd,
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);
@ -2202,12 +2082,9 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
else{ else{
auto res = tu.assignment(tu.ext((tu.mul( auto res = tu.assignment(tu.ext((tu.mul(tu.ext(tu.ext(tu.load(rs1+ traits::X0, 0),32,false),64,true),tu.ext(tu.ext(tu.load(rs2+ traits::X0, 0),32,false),64,true))),64,true),64);
tu.ext(tu.ext(tu.load(rs1+ traits::X0, 0),32,true),64,true),
tu.ext(tu.ext(tu.load(rs2+ traits::X0, 0),32,true),64,true))),64,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);
@ -2241,14 +2118,9 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
else{ else{
auto res = tu.assignment(tu.ext((tu.mul( auto res = tu.assignment(tu.ext((tu.mul(tu.ext(tu.ext(tu.load(rs1+ traits::X0, 0),32,false),64,true),tu.ext(tu.ext(tu.load(rs2+ traits::X0, 0),32,false),64,true))),64,true),64);
tu.ext(tu.ext(tu.load(rs1+ traits::X0, 0),32,true),64,true),
tu.ext(tu.ext(tu.load(rs2+ traits::X0, 0),32,true),64,true))),64,true),64);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.ext((tu.ashr(res,tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false));
tu.ext((tu.ashr(
res,
tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2282,14 +2154,9 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
else{ else{
auto res = tu.assignment(tu.ext((tu.mul( auto res = tu.assignment(tu.ext((tu.mul(tu.ext(tu.ext(tu.load(rs1+ traits::X0, 0),32,false),64,true),tu.ext(tu.load(rs2+ traits::X0, 0),64,false))),64,true),64);
tu.ext(tu.ext(tu.load(rs1+ traits::X0, 0),32,true),64,true),
tu.ext(tu.load(rs2+ traits::X0, 0),64,false))),64,true),64);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.ext((tu.ashr(res,tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false));
tu.ext((tu.ashr(
res,
tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2323,14 +2190,9 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
else{ else{
auto res = tu.assignment(tu.ext((tu.mul( auto res = tu.assignment(tu.ext((tu.mul(tu.ext(tu.load(rs1+ traits::X0, 0),64,false),tu.ext(tu.load(rs2+ traits::X0, 0),64,false))),64,false),64);
tu.ext(tu.load(rs1+ traits::X0, 0),64,false),
tu.ext(tu.load(rs2+ traits::X0, 0),64,false))),64,false),64);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.ext((tu.ashr(res,tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false));
tu.ext((tu.lshr(
res,
tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2366,28 +2228,15 @@ private:
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,tu.constant( 0,8)));
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 = tu.assignment(tu.constant(((uint32_t)1)<<(static_cast<uint32_t>(traits:: XLEN)-1),32),32);
tu.open_if(tu.logical_and( tu.open_if(tu.logical_and(tu.icmp(ICmpInst::ICMP_EQ,tu.load(rs1+ traits::X0, 0),MMIN),tu.icmp(ICmpInst::ICMP_EQ,divisor,tu.constant(- 1,8))));
tu.icmp(ICmpInst::ICMP_EQ, tu.store(rd + traits::X0,MMIN);
tu.load(rs1+ traits::X0, 0),
MMIN),
tu.icmp(ICmpInst::ICMP_EQ,
divisor,
tu.constant(- 1,8))));
tu.store(rd + traits::X0,
MMIN);
tu.open_else(); tu.open_else();
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.ext((tu.sdiv(dividend,divisor)),32,false));
tu.ext((tu.sdiv(
dividend,
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();
} }
} }
@ -2422,19 +2271,13 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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.constant( 0,8)));
tu.load(rs2+ traits::X0, 0),
tu.constant( 0,8)));
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.ext((tu.sdiv(tu.load(rs1+ traits::X0, 0),tu.load(rs2+ traits::X0, 0))),32,false));
tu.ext((tu.udiv(
tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0))),32,false));
} }
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();
} }
@ -2469,33 +2312,20 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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.constant( 0,8)));
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 = tu.assignment(tu.constant((uint32_t)1<<(static_cast<uint32_t>(traits:: XLEN)-1),32),32);
tu.open_if(tu.logical_and( tu.open_if(tu.logical_and(tu.icmp(ICmpInst::ICMP_EQ,tu.load(rs1+ traits::X0, 0),MMIN),tu.icmp(ICmpInst::ICMP_EQ,tu.ext(tu.load(rs2+ traits::X0, 0),32,true),tu.constant(- 1,8))));
tu.icmp(ICmpInst::ICMP_EQ,
tu.load(rs1+ traits::X0, 0),
MMIN),
tu.icmp(ICmpInst::ICMP_EQ,
tu.ext(tu.load(rs2+ traits::X0, 0),32,true),
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.load(rs1+ traits::X0, 0),32,true),tu.ext(tu.load(rs2+ traits::X0, 0),32,true))),32,false));
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.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();
} }
@ -2530,19 +2360,13 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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.constant( 0,8)));
tu.load(rs2+ traits::X0, 0),
tu.constant( 0,8)));
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.srem(tu.load(rs1+ traits::X0, 0),tu.load(rs2+ traits::X0, 0)));
tu.urem(
tu.load(rs1+ 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();
} }
@ -2573,10 +2397,7 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
if(imm) { if(imm) {
tu.store(rd+ 8 + traits::X0, tu.store(rd+ 8 + traits::X0,tu.ext((tu.add(tu.load(2+ traits::X0, 0),tu.constant(imm,16))),32,false));
tu.ext((tu.add(
tu.load(2+ traits::X0, 0),
tu.constant(imm,16))),32,false));
} }
else{ else{
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
@ -2608,11 +2429,8 @@ private:
pc=pc+ 2; pc=pc+ 2;
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
auto offs = tu.assignment(tu.ext((tu.add( auto offs = tu.assignment(tu.ext((tu.add(tu.load(rs1+ 8+ traits::X0, 0),tu.constant(uimm,8))),32,false),32);
tu.load(rs1+ 8+ traits::X0, 0), tu.store(rd+ 8 + traits::X0,tu.ext(tu.ext(tu.read_mem(traits::MEM, offs, 32),32,true),32,false));
tu.constant(uimm,8))),32,false),32);
tu.store(rd+ 8 + traits::X0,
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();
@ -2640,9 +2458,7 @@ private:
pc=pc+ 2; pc=pc+ 2;
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
auto offs = tu.assignment(tu.ext((tu.add( auto offs = tu.assignment(tu.ext((tu.add(tu.load(rs1+ 8+ traits::X0, 0),tu.constant(uimm,8))),32,false),32);
tu.load(rs1+ 8+ traits::X0, 0),
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);
@ -2675,10 +2491,7 @@ private:
} }
else{ else{
if(rs1!= 0) { if(rs1!= 0) {
tu.store(rs1 + traits::X0, tu.store(rs1 + traits::X0,tu.ext((tu.add(tu.load(rs1+ traits::X0, 0),tu.constant((int8_t)sext<6>(imm),8))),32,false));
tu.ext((tu.add(
tu.load(rs1+ traits::X0, 0),
tu.constant((int8_t)sext<6>(imm),8))),32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2728,8 +2541,7 @@ private:
pc=pc+ 2; pc=pc+ 2;
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
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(2U, 2)); tu.store(traits::LAST_BRANCH, tu.constant(2U, 2));
@ -2764,8 +2576,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);
@ -2798,8 +2609,7 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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);
@ -2827,10 +2637,7 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
if(nzimm) { if(nzimm) {
tu.store(2 + traits::X0, tu.store(2 + traits::X0,tu.ext((tu.add(tu.load(2+ traits::X0, 0),tu.constant((int16_t)sext<10>(nzimm),16))),32,false));
tu.ext((tu.add(
tu.load(2+ traits::X0, 0),
tu.constant((int16_t)sext<10>(nzimm),16))),32,false));
} }
else{ else{
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
@ -2884,10 +2691,7 @@ private:
pc=pc+ 2; pc=pc+ 2;
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
tu.store(rs1+ 8 + traits::X0, tu.store(rs1+ 8 + traits::X0,tu.ashr(tu.load(rs1+ 8+ traits::X0, 0),tu.constant(shamt,8)));
tu.lshr(
tu.load(rs1+ 8+ traits::X0, 0),
tu.constant(shamt,8)));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
tu.close_scope(); tu.close_scope();
@ -2914,16 +2718,10 @@ private:
pc=pc+ 2; pc=pc+ 2;
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
if(shamt){ tu.store(rs1+ 8 + traits::X0, if(shamt){ tu.store(rs1+ 8 + traits::X0,tu.ext((tu.ashr((tu.ext(tu.load(rs1+ 8+ traits::X0, 0),32,true)),tu.constant(shamt,8))),32,false));
tu.ext((tu.ashr(
(tu.ext(tu.load(rs1+ 8+ traits::X0, 0),32,true)),
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.load(rs1+ 8+ traits::X0, 0),32,true)),tu.constant( 64,8))),32,false));
tu.ext((tu.ashr(
(tu.ext(tu.load(rs1+ 8+ traits::X0, 0),32,true)),
tu.constant( 64,8))),32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2952,10 +2750,7 @@ private:
pc=pc+ 2; pc=pc+ 2;
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
tu.store(rs1+ 8 + traits::X0, tu.store(rs1+ 8 + traits::X0,tu.ext((tu.bitwise_and(tu.load(rs1+ 8+ traits::X0, 0),tu.constant((int8_t)sext<6>(imm),8))),32,false));
tu.ext((tu.bitwise_and(
tu.load(rs1+ 8+ traits::X0, 0),
tu.constant((int8_t)sext<6>(imm),8))),32,false));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
tu.close_scope(); tu.close_scope();
@ -2982,10 +2777,7 @@ private:
pc=pc+ 2; pc=pc+ 2;
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
tu.store(rd+ 8 + traits::X0, tu.store(rd+ 8 + traits::X0,tu.ext((tu.sub(tu.load(rd+ 8+ traits::X0, 0),tu.load(rs2+ 8+ traits::X0, 0))),32,false));
tu.ext((tu.sub(
tu.load(rd+ 8+ traits::X0, 0),
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();
@ -3012,10 +2804,7 @@ private:
pc=pc+ 2; pc=pc+ 2;
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
tu.store(rd+ 8 + traits::X0, tu.store(rd+ 8 + traits::X0,tu.bitwise_xor(tu.load(rd+ 8+ traits::X0, 0),tu.load(rs2+ 8+ traits::X0, 0)));
tu.bitwise_xor(
tu.load(rd+ 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();
@ -3042,10 +2831,7 @@ private:
pc=pc+ 2; pc=pc+ 2;
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
tu.store(rd+ 8 + traits::X0, tu.store(rd+ 8 + traits::X0,tu.bitwise_or(tu.load(rd+ 8+ traits::X0, 0),tu.load(rs2+ 8+ traits::X0, 0)));
tu.bitwise_or(
tu.load(rd+ 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();
@ -3072,10 +2858,7 @@ private:
pc=pc+ 2; pc=pc+ 2;
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
tu.store(rd+ 8 + traits::X0, tu.store(rd+ 8 + traits::X0,tu.bitwise_and(tu.load(rd+ 8+ traits::X0, 0),tu.load(rs2+ 8+ traits::X0, 0)));
tu.bitwise_and(
tu.load(rd+ 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();
@ -3130,9 +2913,7 @@ private:
pc=pc+ 2; pc=pc+ 2;
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
tu.open_if(tu.icmp(ICmpInst::ICMP_EQ, tu.open_if(tu.icmp(ICmpInst::ICMP_EQ,tu.load(rs1+ 8+ traits::X0, 0),tu.constant( 0,8)));
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); 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);
tu.store(traits::LAST_BRANCH, tu.constant(2U, 2)); tu.store(traits::LAST_BRANCH, tu.constant(2U, 2));
@ -3163,9 +2944,7 @@ private:
pc=pc+ 2; pc=pc+ 2;
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
tu.open_if(tu.icmp(ICmpInst::ICMP_NE, tu.open_if(tu.icmp(ICmpInst::ICMP_NE,tu.load(rs1+ 8+ traits::X0, 0),tu.constant( 0,8)));
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); 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);
tu.store(traits::LAST_BRANCH, tu.constant(2U, 2)); tu.store(traits::LAST_BRANCH, tu.constant(2U, 2));
@ -3201,10 +2980,7 @@ private:
} }
else{ else{
if(rs1!= 0) { if(rs1!= 0) {
tu.store(rs1 + traits::X0, tu.store(rs1 + traits::X0,tu.shl(tu.load(rs1+ traits::X0, 0),tu.constant(nzuimm,8)));
tu.shl(
tu.load(rs1+ traits::X0, 0),
tu.constant(nzuimm,8)));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3237,11 +3013,8 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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.constant(uimm,8))),32,false),32);
tu.load(2+ traits::X0, 0), tu.store(rd + traits::X0,tu.ext(tu.ext(tu.read_mem(traits::MEM, offs, 32),32,true),32,false));
tu.constant(uimm,8))),32,false),32);
tu.store(rd + traits::X0,
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);
@ -3274,8 +3047,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);
@ -3304,9 +3076,7 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
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 = tu.assignment(tu.constant((uint32_t)- 2,32),32);
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),addr_mask),32);
tu.load(rs1%static_cast<uint32_t>(traits:: RFS)+ traits::X0, 0),
addr_mask),32);
tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::NEXT_PC, PC_val_v);
tu.store(traits::LAST_BRANCH, tu.constant(2U, 2)); tu.store(traits::LAST_BRANCH, tu.constant(2U, 2));
} }
@ -3366,10 +3136,7 @@ private:
} }
else{ else{
if(rd!= 0) { if(rd!= 0) {
tu.store(rd + traits::X0, tu.store(rd + traits::X0,tu.ext((tu.add(tu.load(rd+ traits::X0, 0),tu.load(rs2+ traits::X0, 0))),32,false));
tu.ext((tu.add(
tu.load(rd+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0))),32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3403,11 +3170,8 @@ private:
else{ else{
auto addr_mask = tu.assignment(tu.constant((uint32_t)- 2,32),32); auto addr_mask = tu.assignment(tu.constant((uint32_t)- 2,32),32);
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(new_pc,addr_mask),32);
auto PC_val_v = tu.assignment("PC_val", tu.bitwise_and(
new_pc,
addr_mask),32);
tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::NEXT_PC, PC_val_v);
tu.store(traits::LAST_BRANCH, tu.constant(2U, 2)); tu.store(traits::LAST_BRANCH, tu.constant(2U, 2));
} }
@ -3463,9 +3227,7 @@ private:
this->gen_raise_trap(tu, 0, 2); this->gen_raise_trap(tu, 0, 2);
} }
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.constant(uimm,8))),32,false),32);
tu.load(2+ traits::X0, 0),
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);