updates template with fcsr check, adds extra braces on If Statements

This commit is contained in:
Eyck-Alexander Jentzsch 2024-08-14 14:32:58 +02:00
parent 4a19e27926
commit efc11d87a5
2 changed files with 42 additions and 6 deletions

View File

@ -37,7 +37,9 @@
#include <iss/llvm/vm_base.h>
#include <util/logging.h>
#include <iss/instruction_decoder.h>
<%def fcsr = registers.find {it.name=='FCSR'}
if(fcsr != null) {%>
#include <vm/fp_functions.h><%}%>
#ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY
#endif
@ -83,7 +85,9 @@ protected:
using vm_base<ARCH>::get_reg_ptr;
inline const char *name(size_t index){return traits::reg_aliases.at(index);}
<%if(fcsr != null) {%>
inline const char *fname(size_t index){return index < 32?name(index+traits::F0):"illegal";}
<%}%>
template <typename T> inline ConstantInt *size(T type) {
return ConstantInt::get(getContext(), APInt(32, type->getType()->getScalarSizeInBits()));
}
@ -131,7 +135,9 @@ protected:
auto sign_mask = 1ULL<<(W-1);
return (from & mask) | ((from & sign_mask) ? ~mask : 0);
}
<%functions.each{ it.eachLine { %>
${it}<%}%>
<%}%>
private:
/****************************************************************************
* start opcode definitions

View File

@ -516,6 +516,7 @@ private:
this->gen_ext(this->gen_const(32,addr_mask), 64,false))
),
32, true);
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge);
@ -543,6 +544,7 @@ private:
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge);
}
}
bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -585,6 +587,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
}
else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_EQ,
@ -606,6 +609,7 @@ private:
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge);
}
}
bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -648,6 +652,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
}
else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_NE,
@ -669,6 +674,7 @@ private:
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge);
}
}
bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -711,6 +717,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
}
else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_SLT,
@ -736,6 +743,7 @@ private:
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge);
}
}
bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -778,6 +786,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
}
else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_SGE,
@ -803,6 +812,7 @@ private:
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge);
}
}
bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -845,6 +855,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
}
else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_ULT,
@ -866,6 +877,7 @@ private:
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge);
}
}
bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -908,6 +920,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
}
else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_UGE,
@ -929,6 +942,7 @@ private:
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge);
}
}
bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -3184,7 +3198,8 @@ private:
this->gen_reg_load(traits::X0+ rs1), 32,true);
auto divisor =this->gen_ext(
this->gen_reg_load(traits::X0+ rs2), 32,true);
if(rd!=0){ auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
if(rd!=0){ {
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_NE,
@ -3194,6 +3209,7 @@ private:
this->builder.SetInsertPoint(bb_then);
{
auto MMIN =((uint32_t)1)<<(static_cast<uint32_t>(traits::XLEN)-1);
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge);
@ -3228,6 +3244,7 @@ private:
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge);
}
}
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_else);
{
@ -3239,6 +3256,7 @@ private:
this->builder.SetInsertPoint(bb_merge);
}
}
}
bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk);
auto returnValue = std::make_tuple(CONT,bb);
@ -3280,6 +3298,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
}
else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge);
@ -3310,6 +3329,7 @@ private:
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge);
}
}
bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk);
auto returnValue = std::make_tuple(CONT,bb);
@ -3351,6 +3371,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
}
else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge);
@ -3361,6 +3382,7 @@ private:
this->builder.SetInsertPoint(bb_then);
{
auto MMIN =(uint32_t)1<<(static_cast<uint32_t>(traits::XLEN)-1);
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge);
@ -3402,6 +3424,7 @@ private:
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge);
}
}
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_else);
{
@ -3414,6 +3437,7 @@ private:
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge);
}
}
bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk);
auto returnValue = std::make_tuple(CONT,bb);
@ -3455,6 +3479,7 @@ private:
this->gen_raise_trap(0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
}
else{
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
auto bb_else = BasicBlock::Create(this->mod->getContext(), "bb_else", this->func, bb_merge);
@ -3485,6 +3510,7 @@ private:
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge);
}
}
bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk);
auto returnValue = std::make_tuple(CONT,bb);
@ -4324,6 +4350,7 @@ private:
this->gen_instr_prologue();
/*generate behavior*/
this->builder.CreateStore(this->gen_const(32U, static_cast<int>(NO_JUMP)), get_reg_ptr(traits::LAST_BRANCH), false);
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_EQ,
@ -4338,6 +4365,7 @@ private:
}
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge);
}
bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr);
@ -4375,6 +4403,7 @@ private:
this->gen_instr_prologue();
/*generate behavior*/
this->builder.CreateStore(this->gen_const(32U, static_cast<int>(NO_JUMP)), get_reg_ptr(traits::LAST_BRANCH), false);
{
auto bb_merge = BasicBlock::Create(this->mod->getContext(), "bb_merge", this->func, this->leave_blk);
auto bb_then = BasicBlock::Create(this->mod->getContext(), "bb_then", this->func, bb_merge);
this->builder.CreateCondBr(this->gen_bool(this->builder.CreateICmp(ICmpInst::ICMP_NE,
@ -4389,6 +4418,7 @@ private:
}
this->builder.CreateBr(bb_merge);
this->builder.SetInsertPoint(bb_merge);
}
bb = this->leave_blk;
auto returnValue = std::make_tuple(BRANCH,nullptr);