From aa5e0bc4471008ccd48bd03cdea6a02d498a1488 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Wed, 30 Nov 2022 21:05:52 +0800 Subject: [PATCH] arch-riscv: Add vnop when vl equals 0 Change-Id: Id654a56dd2d7c8940bc658c43ef22ff29dcd7274 --- src/arch/riscv/insts/vector.hh | 22 +++++++++ src/arch/riscv/isa/templates/vector_arith.isa | 43 +++++++++++++++++ src/arch/riscv/isa/templates/vector_mem.isa | 47 +++++++++++++++---- 3 files changed, 103 insertions(+), 9 deletions(-) diff --git a/src/arch/riscv/insts/vector.hh b/src/arch/riscv/insts/vector.hh index 564ea7647b..c6235f884f 100644 --- a/src/arch/riscv/insts/vector.hh +++ b/src/arch/riscv/insts/vector.hh @@ -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: diff --git a/src/arch/riscv/isa/templates/vector_arith.isa b/src/arch/riscv/isa/templates/vector_arith.isa index 6ad5eebf3b..67cc166b00 100644 --- a/src/arch/riscv/isa/templates/vector_arith.isa +++ b/src/arch/riscv/isa/templates/vector_arith.isa @@ -65,6 +65,10 @@ template 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(_machInst, micro_vl, i); microop->setDelayedCommit(); @@ -290,6 +294,10 @@ template 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(_machInst, micro_vl, i); microop->setDelayedCommit(); @@ -441,6 +449,10 @@ template 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(_machInst, micro_vl, i); microop->setDelayedCommit(); @@ -871,6 +883,10 @@ template 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(_machInst, micro_vl, i); microop->setDelayedCommit(); @@ -979,6 +995,10 @@ template 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(_machInst, micro_vl, i); microop->setDelayedCommit(); @@ -1301,6 +1321,10 @@ template 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(_machInst, micro_vl, i); microop->setDelayedCommit(); @@ -1494,6 +1518,11 @@ template 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++) { @@ -1658,6 +1687,10 @@ template 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(_machInst, micro_vl, i, &vxsat); @@ -1780,6 +1813,11 @@ template 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) { @@ -1810,6 +1848,11 @@ template 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) { diff --git a/src/arch/riscv/isa/templates/vector_mem.isa b/src/arch/riscv/isa/templates/vector_mem.isa index 3abe23c587..ecfda4ad2d 100644 --- a/src/arch/riscv/isa/templates/vector_mem.isa +++ b/src/arch/riscv/isa/templates/vector_mem.isa @@ -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(); @@ -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(); @@ -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(); @@ -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); } }}; @@ -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); @@ -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); @@ -960,6 +981,10 @@ template 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; @@ -1154,6 +1179,10 @@ template 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;