Skip to content

Commit

Permalink
Merge pull request #25 from huxuan0307/gh-rvv-cpu
Browse files Browse the repository at this point in the history
arch-riscv: Add vnop when vl equals 0
  • Loading branch information
ksco authored Nov 30, 2022
2 parents 64cccbc + aa5e0bc commit 0d3b7b4
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 9 deletions.
22 changes: 22 additions & 0 deletions src/arch/riscv/insts/vector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ protected:
}
};

class VectorNopMicroInst : public RiscvMicroInst
{
public:
VectorNopMicroInst(ExtMachInst _machInst)
: RiscvMicroInst("vnop", _machInst, No_OpClass)
{}

Fault execute(ExecContext* xc, Trace::InstRecord* traceData)
const override
{
return NoFault;
}

std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab)
const override
{
std::stringstream ss;
ss << mnemonic;
return ss.str();
}
};

class VectorArithMicroInst : public VectorMicroInst
{
protected:
Expand Down
43 changes: 43 additions & 0 deletions src/arch/riscv/isa/templates/vector_arith.isa
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ template<typename ElemType>
int32_t micro_vl = std::min(tmp_vl, micro_vlmax);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
for (int i = 0; i < num_microops && micro_vl > 0; ++i) {
microop = new %(class_name)sMicro<ElemType>(_machInst, micro_vl, i);
microop->setDelayedCommit();
Expand Down Expand Up @@ -290,6 +294,10 @@ template<typename ElemType>
int32_t micro_vl = std::min(tmp_vl, micro_vlmax);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
for (int i = 0; i < num_microops && micro_vl > 0; ++i) {
microop = new %(class_name)sMicro<ElemType>(_machInst, micro_vl, i);
microop->setDelayedCommit();
Expand Down Expand Up @@ -441,6 +449,10 @@ template<typename ElemType>
int32_t micro_vl = std::min(tmp_vl, micro_vlmax);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
for (int i = 0; i < num_microops && micro_vl > 0; ++i) {
microop = new %(class_name)sMicro<ElemType>(_machInst, micro_vl, i);
microop->setDelayedCommit();
Expand Down Expand Up @@ -871,6 +883,10 @@ template<typename ElemType>
int32_t micro_vl = std::min(tmp_vl, micro_vlmax);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
for (int i = 0; i < num_microops && micro_vl > 0; ++i) {
microop = new %(class_name)sMicro<ElemType>(_machInst, micro_vl, i);
microop->setDelayedCommit();
Expand Down Expand Up @@ -979,6 +995,10 @@ template<typename ElemType>
int32_t micro_vl = std::min(tmp_vl, micro_vlmax);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
for (int i = 0; i < num_microops && micro_vl > 0; ++i) {
microop = new %(class_name)sMicro<ElemType>(_machInst, micro_vl, i);
microop->setDelayedCommit();
Expand Down Expand Up @@ -1301,6 +1321,10 @@ template<typename ElemType>
int32_t micro_vl = std::min(tmp_vl, micro_vlmax);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
for (int i = 0; i < num_microops && micro_vl > 0; ++i) {
microop = new %(class_name)sMicro<ElemType>(_machInst, micro_vl, i);
microop->setDelayedCommit();
Expand Down Expand Up @@ -1494,6 +1518,11 @@ template<typename ElemType, typename IndexType>
int32_t remaining_vl = this->vl;
int32_t micro_vl = std::min(remaining_vl, micro_vlmax);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
for (uint8_t i = 0; i < std::max(vs1_vregs, vd_vregs) && micro_vl > 0;
i++) {
for (uint8_t j = 0; j < vs2_vregs; j++) {
Expand Down Expand Up @@ -1658,6 +1687,10 @@ template<typename ElemType>
int32_t micro_vl = std::min(tmp_vl, micro_vlmax);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
for (int i = 0; i < num_microops && micro_vl > 0; ++i) {
microop = new %(class_name)sMicro<ElemType>(_machInst,
micro_vl, i, &vxsat);
Expand Down Expand Up @@ -1780,6 +1813,11 @@ template<typename ElemType>
const int32_t micro_vlmax = vtype_VLMAX(_machInst.vtype8, true);
int32_t micro_vl = std::min(tmp_vl, micro_vlmax);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
// Todo static filter out useless uop
int micro_idx = 0;
for (int i = 0; i < num_microops && micro_vl > 0; ++i) {
Expand Down Expand Up @@ -1810,6 +1848,11 @@ template<typename ElemType>
const int32_t micro_vlmax = vtype_VLMAX(_machInst.vtype8, true);
int32_t micro_vl = std::min(tmp_vl, micro_vlmax);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
// Todo static filter out useless uop
int micro_idx = 0;
for (int i = 0; i < num_microops && micro_vl > 0; ++i) {
Expand Down
47 changes: 38 additions & 9 deletions src/arch/riscv/isa/templates/vector_mem.isa
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def template VleConstructor {{
int32_t micro_vl = std::min(remaining_vl, micro_vlmax);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
for (int i = 0; i < num_microops && micro_vl > 0; ++i) {
microop = new %(class_name)sMicro(_machInst, micro_vl, i);
microop->setDelayedCommit();
Expand Down Expand Up @@ -193,6 +197,10 @@ def template VseConstructor {{

StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
for (int i = 0; i < num_microops && micro_vl > 0; ++i) {
microop = new %(class_name)sMicro(_machInst, micro_vl, i);
microop->setDelayedCommit();
Expand Down Expand Up @@ -344,9 +352,13 @@ def template VlmConstructor {{
int32_t micro_vl = (std::min(this->vl, micro_vlmax) + 7) / 8;
StaticInstPtr microop;

microop = new Vle8_vMicro(_machInst, micro_vl, 0);
microop->setDelayedCommit();
microop->setFlag(IsLoad);
if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
} else {
microop = new Vle8_vMicro(_machInst, micro_vl, 0);
microop->setDelayedCommit();
microop->setFlag(IsLoad);
}
this->microops.push_back(microop);

this->microops.front()->setFirstMicroop();
Expand All @@ -367,16 +379,17 @@ def template VsmConstructor {{
int32_t micro_vl = (std::min(this->vl, micro_vlmax) + 7) / 8;

StaticInstPtr microop;
microop = new Vse8_vMicro(_machInst, micro_vl, 0);
microop->setDelayedCommit();
microop->setFlag(IsStore);
if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
} else {
microop = new Vse8_vMicro(_machInst, micro_vl, 0);
microop->setDelayedCommit();
microop->setFlag(IsStore);
}
this->microops.push_back(microop);

this->microops.front()->setFirstMicroop();
this->microops.back()->setLastMicroop();

this->microops.front()->setFlag(IsFirstMicroop);
this->microops.back()->setFlag(IsLastMicroop);
}

}};
Expand Down Expand Up @@ -623,6 +636,10 @@ def template VlStrideConstructor {{
int32_t micro_vl = std::min(remaining_vl, num_elems_per_vreg);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
for (int i = 0; micro_vl > 0; ++i) {
for (int j = 0; j < micro_vl; ++j) {
microop = new %(class_name)sMicro(machInst, i, j, micro_vl);
Expand Down Expand Up @@ -809,6 +826,10 @@ def template VsStrideConstructor {{
int32_t micro_vl = std::min(remaining_vl, num_elems_per_vreg);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
for (int i = 0; micro_vl > 0; ++i) {
for (int j = 0; j < micro_vl; ++j) {
microop = new %(class_name)sMicro(machInst, i, j, micro_vl);
Expand Down Expand Up @@ -960,6 +981,10 @@ template<typename ElemType>
int32_t micro_vl = std::min(remaining_vl, micro_vlmax);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
for (uint8_t i = 0; micro_vl > 0; i++) {
for (uint8_t j = 0; j < micro_vl; ++j) {
uint8_t vdRegIdx = i / vd_split_num;
Expand Down Expand Up @@ -1154,6 +1179,10 @@ template<typename ElemType>
int32_t micro_vl = std::min(remaining_vl, micro_vlmax);
StaticInstPtr microop;

if (micro_vl == 0) {
microop = new VectorNopMicroInst(_machInst);
this->microops.push_back(microop);
}
for (uint8_t i = 0; micro_vl > 0; i++) {
for (uint8_t j = 0; j < micro_vl; ++j) {
uint8_t vs3RegIdx = i / vs3_split_num;
Expand Down

0 comments on commit 0d3b7b4

Please sign in to comment.