Skip to content

Commit

Permalink
arch-riscv: Improve style
Browse files Browse the repository at this point in the history
Minor style fixes in vector code

Change-Id: If0de45a2dbfb5d5aaa65ed3b5d91d9bee9bcc960
Signed-off-by: Jason Lowe-Power <jason@lowepower.com>
  • Loading branch information
powerjg committed Aug 1, 2023
1 parent a1e4243 commit b276954
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
20 changes: 11 additions & 9 deletions src/arch/riscv/insts/vector.cc
Expand Up @@ -56,18 +56,20 @@ namespace RiscvISA
*
**/
float
getVflmul(uint32_t vlmul_encoding) {
int vlmul = sext<3>(vlmul_encoding & 7);
float vflmul = vlmul >= 0 ? 1 << vlmul : 1.0 / (1 << -vlmul);
return vflmul;
getVflmul(uint32_t vlmul_encoding)
{
int vlmul = sext<3>(vlmul_encoding & 7);
float vflmul = vlmul >= 0 ? 1 << vlmul : 1.0 / (1 << -vlmul);
return vflmul;
}

uint32_t
getVlmax(VTYPE vtype, uint32_t vlen) {
uint32_t sew = getSew(vtype.vsew);
// vlmax is defined in RVV 1.0 spec p12 chapter 3.4.2.
uint32_t vlmax = (vlen/sew) * getVflmul(vtype.vlmul);
return vlmax;
getVlmax(VTYPE vtype, uint32_t vlen)
{
uint32_t sew = getSew(vtype.vsew);
// vlmax is defined in RVV 1.0 spec p12 chapter 3.4.2.
uint32_t vlmax = (vlen/sew) * getVflmul(vtype.vlmul);
return vlmax;
}

std::string
Expand Down
33 changes: 19 additions & 14 deletions src/arch/riscv/insts/vector.hh
Expand Up @@ -47,7 +47,9 @@ namespace RiscvISA
float
getVflmul(uint32_t vlmul_encoding);

inline uint32_t getSew(uint32_t vsew) {
inline uint32_t
getSew(uint32_t vsew)
{
assert(vsew <= 3);
return (8 << vsew);
}
Expand Down Expand Up @@ -124,7 +126,7 @@ class VectorMacroInst : public RiscvMacroInst

class VectorMicroInst : public RiscvMicroInst
{
protected:
protected:
uint8_t microVl;
uint8_t microIdx;
uint8_t vtype;
Expand Down Expand Up @@ -420,7 +422,7 @@ class VsStrideMacroInst : public VectorMemMacroInst
class VsStrideMicroInst : public VectorMemMicroInst
{
protected:
uint8_t regIdx;
uint8_t regIdx;
VsStrideMicroInst(const char *mnem, ExtMachInst _machInst,
OpClass __opClass, uint8_t _regIdx,
uint8_t _microIdx, uint8_t _microVl)
Expand Down Expand Up @@ -487,9 +489,9 @@ class VsIndexMicroInst : public VectorMemMicroInst
VsIndexMicroInst(const char *mnem, ExtMachInst _machInst,
OpClass __opClass, uint8_t _vs3RegIdx, uint8_t _vs3ElemIdx,
uint8_t _vs2RegIdx, uint8_t _vs2ElemIdx)
: VectorMemMicroInst(mnem, _machInst, __opClass, 1, 0, 0)
, vs3RegIdx(_vs3RegIdx), vs3ElemIdx(_vs3ElemIdx)
, vs2RegIdx(_vs2RegIdx), vs2ElemIdx(_vs2ElemIdx)
: VectorMemMicroInst(mnem, _machInst, __opClass, 1, 0, 0),
vs3RegIdx(_vs3RegIdx), vs3ElemIdx(_vs3ElemIdx),
vs2RegIdx(_vs2RegIdx), vs2ElemIdx(_vs2ElemIdx)
{}

std::string generateDisassembly(
Expand Down Expand Up @@ -532,7 +534,7 @@ class VMaskMergeMicroInst : public VectorArithMicroInst
VMaskMergeMicroInst(ExtMachInst extMachInst, uint8_t _dstReg,
uint8_t _numSrcs)
: VectorArithMicroInst("vmask_mv_micro", extMachInst,
VectorIntegerArithOp, 0, 0)
VectorIntegerArithOp, 0, 0)
{
setRegIdxArrays(
reinterpret_cast<RegIdArrayPtr>(
Expand All @@ -550,8 +552,9 @@ class VMaskMergeMicroInst : public VectorArithMicroInst
}
}

Fault execute(ExecContext* xc, trace::InstRecord* traceData)
const override {
Fault
execute(ExecContext* xc, trace::InstRecord* traceData) const override
{
vreg_t tmp_d0 = *(vreg_t *)xc->getWritableRegOperand(this, 0);
auto Vd = tmp_d0.as<uint8_t>();
constexpr uint8_t elems_per_vreg = VLENB / sizeof(ElemType);
Expand Down Expand Up @@ -582,8 +585,10 @@ class VMaskMergeMicroInst : public VectorArithMicroInst
return NoFault;
}

std::string generateDisassembly(
Addr pc, const loader::SymbolTable *symtab) const override {
std::string
generateDisassembly(Addr pc, const loader::SymbolTable *symtab)
const override
{
std::stringstream ss;
ss << mnemonic << ' ' << registerName(destRegIdx(0));
for (uint8_t i = 0; i < this->_numSrcRegs; i++) {
Expand All @@ -605,16 +610,16 @@ class VxsatMicroInst : public VectorArithMicroInst
{
vxsat = Vxsat;
}
Fault execute(ExecContext* xc, trace::InstRecord* traceData)
const override
Fault
execute(ExecContext* xc, trace::InstRecord* traceData) const override
{
xc->setMiscReg(MISCREG_VXSAT,*vxsat);
auto vcsr = xc->readMiscReg(MISCREG_VCSR);
xc->setMiscReg(MISCREG_VCSR, ((vcsr&~1)|*vxsat));
return NoFault;
}
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab)
const override
const override
{
std::stringstream ss;
ss << mnemonic << ' ' << "VXSAT" << ", " << (*vxsat ? "0x1" : "0x0");
Expand Down

0 comments on commit b276954

Please sign in to comment.