arch-riscv: Add checking CSR condition for RVV instructions (#170)
If status.vs == OFF, the RVV instruction should raise Illegal Instruction according to RISC-V V spec. If RVV is not implemented, all of the RVV instruction need to raise exception.
This commit is contained in:
@@ -671,6 +671,9 @@ ISA::setMiscReg(RegIndex idx, RegVal val)
|
||||
2, 0) != 0) {
|
||||
new_misa.rvc = new_misa.rvc | cur_misa.rvc;
|
||||
}
|
||||
if (!getEnableRvv()) {
|
||||
new_misa.rvv = 0;
|
||||
}
|
||||
setMiscRegNoEffect(idx, new_misa);
|
||||
}
|
||||
break;
|
||||
@@ -682,6 +685,10 @@ ISA::setMiscReg(RegIndex idx, RegVal val)
|
||||
val &= ~(STATUS_SXL_MASK | STATUS_UXL_MASK);
|
||||
val |= cur & (STATUS_SXL_MASK | STATUS_UXL_MASK);
|
||||
}
|
||||
if (!getEnableRvv()) {
|
||||
// Always OFF is rvv is disabled.
|
||||
val &= ~STATUS_VS_MASK;
|
||||
}
|
||||
setMiscRegNoEffect(idx, val);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -41,6 +41,12 @@ def template VConfExecute {{
|
||||
trace::InstRecord *traceData) const
|
||||
{
|
||||
auto tc = xc->tcBase();
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
|
||||
%(op_decl)s;
|
||||
%(op_rd)s;
|
||||
|
||||
@@ -158,6 +158,13 @@ Fault
|
||||
using vi [[maybe_unused]] = std::make_signed_t<ElemType>;
|
||||
[[maybe_unused]] constexpr size_t sew = sizeof(vu) * 8;
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
|
||||
@@ -230,6 +237,13 @@ Fault
|
||||
using vu [[maybe_unused]] = std::make_unsigned_t<ElemType>;
|
||||
using vi [[maybe_unused]] = std::make_signed_t<ElemType>;
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
|
||||
@@ -389,6 +403,13 @@ Fault
|
||||
using vwi [[maybe_unused]] = typename double_width<vi>::type;
|
||||
[[maybe_unused]] constexpr size_t sew = sizeof(vu) * 8;
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
const int64_t vlmul = vtype_vlmul(machInst.vtype8);
|
||||
@@ -421,6 +442,13 @@ Fault
|
||||
using vwi [[maybe_unused]] = typename double_width<vi>::type;
|
||||
[[maybe_unused]] constexpr size_t sew = sizeof(vu) * 8;
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
const int64_t vlmul = vtype_vlmul(machInst.vtype8);
|
||||
@@ -538,6 +566,14 @@ Fault
|
||||
{
|
||||
using et = ElemType;
|
||||
using vu = decltype(et::v);
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
|
||||
@@ -625,6 +661,13 @@ Fault
|
||||
using ewt = typename double_width<et>::type;
|
||||
using vwu = decltype(ewt::v);
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
|
||||
@@ -659,6 +702,13 @@ Fault
|
||||
using ewt = typename double_width<et>::type;
|
||||
using vwu = decltype(ewt::v);
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
|
||||
@@ -783,6 +833,13 @@ Fault
|
||||
{
|
||||
using vu [[maybe_unused]] = std::make_unsigned_t<ElemType>;
|
||||
using vi [[maybe_unused]] = std::make_signed_t<ElemType>;
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
%(op_decl)s;
|
||||
@@ -820,6 +877,12 @@ Fault
|
||||
trace::InstRecord* traceData) const
|
||||
{
|
||||
using vu = uint8_t;
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
%(op_decl)s;
|
||||
@@ -872,6 +935,12 @@ Fault
|
||||
{
|
||||
using vu [[maybe_unused]] = std::make_unsigned_t<ElemType>;
|
||||
using vi [[maybe_unused]] = std::make_signed_t<ElemType>;
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
%(op_rd)s;
|
||||
@@ -978,6 +1047,12 @@ Fault
|
||||
{
|
||||
using vu [[maybe_unused]] = std::make_unsigned_t<ElemType>;
|
||||
using vi [[maybe_unused]] = std::make_signed_t<ElemType>;
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
|
||||
@@ -1089,6 +1164,12 @@ Fault
|
||||
{
|
||||
using et = ElemType;
|
||||
using vu = decltype(et::v);
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
|
||||
@@ -1182,6 +1263,13 @@ Fault
|
||||
{
|
||||
// TODO: Check register alignment.
|
||||
// TODO: If vd is equal to vs2 the instruction is an architectural NOP.
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
|
||||
%(op_decl)s;
|
||||
%(op_rd)s;
|
||||
for (size_t i = 0; i < (VLEN / 64); i++) {
|
||||
@@ -1229,6 +1317,12 @@ Fault
|
||||
trace::InstRecord* traceData) const
|
||||
{
|
||||
using vu = uint8_t;
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
@@ -1288,6 +1382,12 @@ Fault
|
||||
{
|
||||
using vu [[maybe_unused]] = std::make_unsigned_t<ElemType>;
|
||||
using vi [[maybe_unused]] = std::make_signed_t<ElemType>;
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
%(op_decl)s;
|
||||
@@ -1309,7 +1409,12 @@ Fault
|
||||
{
|
||||
using et = ElemType;
|
||||
using vu = decltype(et::v);
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
%(op_decl)s;
|
||||
@@ -1410,6 +1515,12 @@ Fault
|
||||
trace::InstRecord* traceData) const
|
||||
{
|
||||
%(type_def)s;
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
|
||||
@@ -1445,6 +1556,12 @@ Fault
|
||||
trace::InstRecord* traceData) const
|
||||
{
|
||||
%(type_def)s;
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
|
||||
@@ -1482,6 +1599,12 @@ Fault
|
||||
trace::InstRecord* traceData) const
|
||||
{
|
||||
%(type_def)s;
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
|
||||
@@ -1626,7 +1749,12 @@ Fault
|
||||
{
|
||||
using vu [[maybe_unused]] = std::make_unsigned_t<ElemType>;
|
||||
[[maybe_unused]] constexpr size_t sew = sizeof(vu) * 8;
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
|
||||
@@ -1785,7 +1913,12 @@ Fault
|
||||
using vi [[maybe_unused]] = std::make_signed_t<ElemType>;
|
||||
using vwu [[maybe_unused]] = typename double_width<vu>::type;
|
||||
using vwi [[maybe_unused]] = typename double_width<vi>::type;
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
|
||||
@@ -1945,7 +2078,12 @@ Fault
|
||||
{
|
||||
using vu [[maybe_unused]] = std::make_unsigned_t<ElemType>;
|
||||
using vi [[maybe_unused]] = std::make_signed_t<ElemType>;
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
[[maybe_unused]]const uint32_t vlmax = vtype_VLMAX(vtype);
|
||||
@@ -1971,7 +2109,12 @@ Fault
|
||||
{
|
||||
using et = ElemType;
|
||||
using vu = decltype(et::v);
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if (machInst.vill)
|
||||
return std::make_shared<IllegalInstFault>("VILL is set", machInst);
|
||||
[[maybe_unused]]const uint32_t vlmax = vtype_VLMAX(vtype);
|
||||
|
||||
@@ -131,6 +131,12 @@ Fault
|
||||
|
||||
RiscvISA::vreg_t tmp_v0;
|
||||
uint8_t *v0;
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if(!machInst.vm) {
|
||||
xc->getRegOperand(this, _numSrcRegs - 1, &tmp_v0);
|
||||
v0 = tmp_v0.as<uint8_t>();
|
||||
@@ -285,6 +291,12 @@ Fault
|
||||
|
||||
RiscvISA::vreg_t tmp_v0;
|
||||
uint8_t *v0;
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
if(!machInst.vm) {
|
||||
xc->getRegOperand(this, _numSrcRegs - 1, &tmp_v0);
|
||||
v0 = tmp_v0.as<uint8_t>();
|
||||
@@ -482,6 +494,12 @@ Fault
|
||||
%(class_name)s::execute(ExecContext *xc, trace::InstRecord *traceData) const
|
||||
{
|
||||
Addr EA;
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
%(op_decl)s;
|
||||
%(op_rd)s;
|
||||
%(ea_code)s;
|
||||
@@ -591,6 +609,12 @@ Fault
|
||||
%(class_name)s::execute(ExecContext *xc, trace::InstRecord *traceData) const
|
||||
{
|
||||
Addr EA;
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
%(op_decl)s;
|
||||
%(op_rd)s;
|
||||
%(ea_code)s;
|
||||
@@ -731,7 +755,12 @@ Fault
|
||||
{
|
||||
Fault fault = NoFault;
|
||||
Addr EA;
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
%(op_decl)s;
|
||||
%(op_rd)s;
|
||||
constexpr uint8_t elem_size = sizeof(Vd[0]);
|
||||
@@ -918,7 +947,12 @@ Fault
|
||||
{
|
||||
Fault fault = NoFault;
|
||||
Addr EA;
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
%(op_decl)s;
|
||||
%(op_rd)s;
|
||||
constexpr uint8_t elem_size = sizeof(Vs3[0]);
|
||||
@@ -1086,7 +1120,12 @@ Fault
|
||||
using vu = std::make_unsigned_t<ElemType>;
|
||||
Fault fault = NoFault;
|
||||
Addr EA;
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
%(op_decl)s;
|
||||
%(op_rd)s;
|
||||
%(ea_code)s;
|
||||
@@ -1282,7 +1321,12 @@ Fault
|
||||
using vu = std::make_unsigned_t<ElemType>;
|
||||
Fault fault = NoFault;
|
||||
Addr EA;
|
||||
|
||||
MISA misa = xc->readMiscReg(MISCREG_ISA);
|
||||
STATUS status = xc->readMiscReg(MISCREG_STATUS);
|
||||
if (!misa.rvv || status.vs == VPUStatus::OFF) {
|
||||
return std::make_shared<IllegalInstFault>(
|
||||
"RVV is disabled or VPU is off", machInst);
|
||||
}
|
||||
%(op_decl)s;
|
||||
%(op_rd)s;
|
||||
%(ea_code)s;
|
||||
|
||||
Reference in New Issue
Block a user