@@ -1668,15 +1668,92 @@ static inline bool op_cbnez(rv_insn_t *ir, const uint32_t insn)
1668
1668
#define op_cbnez OP_UNIMP
1669
1669
#endif /* RV32_HAS(EXT_C) */
1670
1670
1671
- /* TODO: RV32C.F support */
1672
- #define op_cfldsp OP_UNIMP
1673
- #define op_cflwsp OP_UNIMP
1674
- #define op_cfswsp OP_UNIMP
1675
- #define op_cfsdsp OP_UNIMP
1676
- #define op_cfld OP_UNIMP
1677
- #define op_cflw OP_UNIMP
1671
+ #if RV32_HAS (EXT_C ) && RV32_HAS (EXT_F )
1672
+ /* C.FLWSP: CI-format
1673
+ * 15 13 12 11 7 6 2 1 0
1674
+ * | funct3 | imm | rd | imm | op |
1675
+ */
1676
+ static inline bool op_cflwsp (rv_insn_t * ir , const uint32_t insn )
1677
+ {
1678
+ /* inst funct3 imm rd imm op
1679
+ * -------+------+-------+-----+-------------+--
1680
+ * C.FLWSP 001 uimm[5] rd uimm[4:2|7:6] 10
1681
+ */
1682
+ uint16_t tmp = 0 ;
1683
+ tmp |= (insn & 0x70 ) >> 2 ;
1684
+ tmp |= (insn & 0x0c ) << 4 ;
1685
+ tmp |= (insn & 0x1000 ) >> 7 ;
1686
+ ir -> imm = tmp ;
1687
+ ir -> rd = c_decode_rd (insn );
1688
+ ir -> opcode = rv_insn_cflwsp ;
1689
+ return true;
1690
+ }
1691
+
1692
+ /* C.FSWSP: CSS-Format
1693
+ * 15 13 12 7 6 2 1 0
1694
+ * | funct3 | imm | rs2 | op |
1695
+ */
1696
+ static inline bool op_cfswsp (rv_insn_t * ir , const uint32_t insn )
1697
+ {
1698
+ /* inst funct3 imm rs2 op
1699
+ * -------+------+-------------+---+--
1700
+ * C.FSWSP 111 uimm[5:2|7:6] rs2 10
1701
+ */
1702
+ ir -> imm = (insn & 0x1e00 ) >> 7 | (insn & 0x180 ) >> 1 ;
1703
+ ir -> rs2 = c_decode_rs2 (insn );
1704
+ ir -> opcode = rv_insn_cfswsp ;
1705
+ return true;
1706
+ }
1707
+
1708
+ /* C.LW: CL-format
1709
+ * 15 13 12 10 9 7 6 5 4 2 1 0
1710
+ * | funct3 | imm | rs1' | imm | rd' | op |
1711
+ */
1712
+ static inline bool op_cflw (rv_insn_t * ir , const uint32_t insn )
1713
+ {
1714
+ /* inst funct3 imm rs1' imm rd' op
1715
+ * -----+------+---------+----+---------+---+--
1716
+ * C.FLW 010 uimm[5:3] rs1' uimm[7:6] rd' 00
1717
+ */
1718
+ uint16_t tmp = 0 ;
1719
+ tmp |= (insn & 0b0000000001000000 ) >> 4 ;
1720
+ tmp |= (insn & FC_IMM_12_10 ) >> 7 ;
1721
+ tmp |= (insn & 0b0000000000100000 ) << 1 ;
1722
+ ir -> imm = tmp ;
1723
+ ir -> rd = c_decode_rdc (insn ) | 0x08 ;
1724
+ ir -> rs1 = c_decode_rs1c (insn ) | 0x08 ;
1725
+ ir -> opcode = rv_insn_cflw ;
1726
+ return true;
1727
+ }
1728
+
1729
+ /* C.FSW: CS-format
1730
+ * 15 13 12 10 9 7 6 5 4 2 1 0
1731
+ * | funct3 | imm | rs1' | imm | rs2' | op |
1732
+ */
1733
+ static inline bool op_cfsw (rv_insn_t * ir , const uint32_t insn )
1734
+ {
1735
+ /* inst funct3 imm rs1' imm rs2' op
1736
+ * -----+------+---------+----+---------+----+--
1737
+ * C.FSW 110 uimm[5:3] rs1' uimm[2|6] rs2' 00
1738
+ */
1739
+ uint32_t tmp = 0 ;
1740
+ /* ....xxxx....xxxx */
1741
+ tmp |= (insn & 0b0000000001000000 ) >> 4 ;
1742
+ tmp |= (insn & FC_IMM_12_10 ) >> 7 ;
1743
+ tmp |= (insn & 0b0000000000100000 ) << 1 ;
1744
+ ir -> imm = tmp ;
1745
+ ir -> rs1 = c_decode_rs1c (insn ) | 0x08 ;
1746
+ ir -> rs2 = c_decode_rs2c (insn ) | 0x08 ;
1747
+ ir -> opcode = rv_insn_cfsw ;
1748
+ return true;
1749
+ }
1750
+
1751
+ #else /* !(RV32_HAS(EXT_C) && RV32_HAS(EXT_F)) */
1678
1752
#define op_cfsw OP_UNIMP
1679
- #define op_cfsd OP_UNIMP
1753
+ #define op_cflw OP_UNIMP
1754
+ #define op_cfswsp OP_UNIMP
1755
+ #define op_cflwsp OP_UNIMP
1756
+ #endif /* RV32_HAS(EXT_C) && RV32_HAS(EXT_F) */
1680
1757
1681
1758
/* handler for all unimplemented opcodes */
1682
1759
static inline bool op_unimp (rv_insn_t * ir UNUSED , uint32_t insn UNUSED )
@@ -1710,11 +1787,11 @@ bool rv_decode(rv_insn_t *ir, uint32_t insn)
1710
1787
static const decode_t rvc_jump_table [] = {
1711
1788
// 00 01 10 11
1712
1789
OP (caddi4spn ), OP (caddi ), OP (cslli ), OP (unimp ), // 000
1713
- OP (cfld ), OP (cjal ), OP (cfldsp ), OP (unimp ), // 001
1790
+ OP (unimp ), OP (cjal ), OP (unimp ), OP (unimp ), // 001
1714
1791
OP (clw ), OP (cli ), OP (clwsp ), OP (unimp ), // 010
1715
1792
OP (cflw ), OP (clui ), OP (cflwsp ), OP (unimp ), // 011
1716
1793
OP (unimp ), OP (cmisc_alu ), OP (ccr ), OP (unimp ), // 100
1717
- OP (cfsd ), OP (cj ), OP (cfsdsp ), OP (unimp ), // 101
1794
+ OP (unimp ), OP (cj ), OP (unimp ), OP (unimp ), // 101
1718
1795
OP (csw ), OP (cbeqz ), OP (cswsp ), OP (unimp ), // 110
1719
1796
OP (cfsw ), OP (cbnez ), OP (cfswsp ), OP (unimp ), // 111
1720
1797
};
0 commit comments