Skip to content

Commit 11ea214

Browse files
committed
Add decoder for RVV instructions
1 parent a00c49f commit 11ea214

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

src/decode.c

+54-1
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,58 @@ static inline bool op_cfsw(rv_insn_t *ir, const uint32_t insn)
17911791
#define op_cflwsp OP_UNIMP
17921792
#endif /* RV32_HAS(EXT_C) && RV32_HAS(EXT_F) */
17931793

1794+
/* OP: RVV
1795+
* opcode is 0x57
1796+
* 31 26 25 24 20 19 15 14 12 11 7 6 0
1797+
* | funct6 |vm| vs2 | vs1 | funct3 | vd | opcode |
1798+
*
1799+
* funct3
1800+
* | 0 | 0 | 0 | OPIVV | vector-vector | N/A
1801+
* | 0 | 0 | 1 | OPFVV | vector-vector | N/A
1802+
* | 0 | 1 | 0 | OPMVV | vector-vector | N/A
1803+
* | 0 | 1 | 1 | OPIVI | vector-immediate | `imm[4:0]`
1804+
* | 1 | 0 | 0 | OPIVX | vector-scalar | GPR `x` register `rs1`
1805+
* | 1 | 0 | 1 | OPFVF | vector-scalar | FP `f` register `rs1`
1806+
* | 1 | 1 | 0 | OPMVX | vector-scalar | GPR `x` register `rs1`
1807+
*/
1808+
static inline bool op_v(rv_insn_t *ir, const uint32_t insn)
1809+
{
1810+
uint32_t funct3_mask = 0x7000;
1811+
switch (insn & funct3_mask) {
1812+
case 0:
1813+
return op_ivv(ir, insn);
1814+
break;
1815+
case 1:
1816+
return op_fvv(ir, insn);
1817+
break;
1818+
case 2:
1819+
return op_mvv(ir, insn);
1820+
break;
1821+
case 3:
1822+
return op_ivi(ir, insn);
1823+
break;
1824+
case 4:
1825+
return op_ivx(ir, insn);
1826+
break;
1827+
case 5:
1828+
return op_fvf(ir, insn);
1829+
break;
1830+
case 6:
1831+
return op_mvx(ir, insn);
1832+
break;
1833+
default:
1834+
return false;
1835+
}
1836+
}
1837+
1838+
static inline bool op_ivv(rv_insn_t *ir, const uint32_t insn) {}
1839+
static inline bool op_fvv(rv_insn_t *ir, const uint32_t insn) {}
1840+
static inline bool op_mvv(rv_insn_t *ir, const uint32_t insn) {}
1841+
static inline bool op_ivi(rv_insn_t *ir, const uint32_t insn) {}
1842+
static inline bool op_ivx(rv_insn_t *ir, const uint32_t insn) {}
1843+
static inline bool op_fvf(rv_insn_t *ir, const uint32_t insn) {}
1844+
static inline bool op_mvx(rv_insn_t *ir, const uint32_t insn) {}
1845+
17941846
/* handler for all unimplemented opcodes */
17951847
static inline bool op_unimp(rv_insn_t *ir UNUSED, uint32_t insn UNUSED)
17961848
{
@@ -1811,7 +1863,8 @@ bool rv_decode(rv_insn_t *ir, uint32_t insn)
18111863
/* RV32 base opcode map */
18121864
/* clang-format off */
18131865
static const decode_t rv_jump_table[] = {
1814-
// 000 001 010 011 100 101 110 111
1866+
// insn[4:2]
1867+
// 000 001 010 011 100 101 110 111 // insn[6:5]
18151868
OP(load), OP(load_fp), OP(unimp), OP(misc_mem), OP(op_imm), OP(auipc), OP(unimp), OP(unimp), // 00
18161869
OP(store), OP(store_fp), OP(unimp), OP(amo), OP(op), OP(lui), OP(unimp), OP(unimp), // 01
18171870
OP(madd), OP(msub), OP(nmsub), OP(nmadd), OP(op_fp), OP(unimp), OP(unimp), OP(unimp), // 10

0 commit comments

Comments
 (0)