aboutsummaryrefslogtreecommitdiff
path: root/target/riscv/insn16.decode
blob: 3c79edf1c99631196af42d9969f569aecd7347eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#
# RISC-V translation routines for the RVXI Base Integer Instruction Set.
#
# Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de
#                    Bastian Koppelmann, kbastian@mail.uni-paderborn.de
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 2 or later, as published by the Free Software Foundation.
#
# This program is distributed in the hope it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see <http://www.gnu.org/licenses/>.

# Fields:
%rd        7:5
%rs1_3     7:3                !function=ex_rvc_register
%rs2_3     2:3                !function=ex_rvc_register
%rs2_5     2:5

# Immediates:
%imm_ci        12:s1 2:5
%nzuimm_ciw    7:4 11:2 5:1 6:1   !function=ex_shift_2
%uimm_cl_d     5:2 10:3           !function=ex_shift_3
%uimm_cl_w     5:1 10:3 6:1       !function=ex_shift_2
%imm_cb        12:s1 5:2 2:1 10:2 3:2 !function=ex_shift_1
%imm_cj        12:s1 8:1 9:2 6:1 7:1 2:1 11:1 3:3 !function=ex_shift_1

%shimm_6bit   12:1 2:5               !function=ex_rvc_shifti
%uimm_6bit_ld 2:3 12:1 5:2           !function=ex_shift_3
%uimm_6bit_lw 2:2 12:1 4:3           !function=ex_shift_2
%uimm_6bit_sd 7:3 10:3               !function=ex_shift_3
%uimm_6bit_sw 7:2 9:4                !function=ex_shift_2

%imm_addi16sp  12:s1 3:2 5:1 2:1 6:1 !function=ex_shift_4
%imm_lui       12:s1 2:5             !function=ex_shift_12


# Argument sets imported from insn32.decode:
&empty                  !extern
&r         rd rs1 rs2   !extern
&i         imm rs1 rd   !extern
&s         imm rs1 rs2  !extern
&j         imm rd       !extern
&b         imm rs2 rs1  !extern
&u         imm rd       !extern
&shift     shamt rs1 rd !extern

# Argument sets:
&cl               rs1 rd
&cl_dw     uimm   rs1 rd
&ciw       nzuimm     rd
&cs               rs1 rs2
&cs_dw     uimm   rs1 rs2
&cb        imm    rs1
&cr               rd  rs2
&c_shift   shamt      rd

&c_ld      uimm  rd
&c_sd      uimm  rs2

&caddi16sp_lui  imm_lui imm_addi16sp rd
&cflwsp_ldsp    uimm_flwsp uimm_ldsp rd
&cfswsp_sdsp    uimm_fswsp uimm_sdsp rs2

# Formats 16:
@cr        ....  ..... .....  .. &r      rs2=%rs2_5       rs1=%rd     %rd
@ci        ... . ..... .....  .. &i      imm=%imm_ci      rs1=%rd     %rd
@cl_d      ... ... ... .. ... .. &i      imm=%uimm_cl_d   rs1=%rs1_3  rd=%rs2_3
@cl_w      ... ... ... .. ... .. &i      imm=%uimm_cl_w   rs1=%rs1_3  rd=%rs2_3
@cl        ... ... ... .. ... .. &cl                      rs1=%rs1_3  rd=%rs2_3
@cs        ... ... ... .. ... .. &cs                      rs1=%rs1_3  rs2=%rs2_3
@cs_2      ... ... ... .. ... .. &r      rs2=%rs2_3       rs1=%rs1_3  rd=%rs1_3
@cs_d      ... ... ... .. ... .. &s      imm=%uimm_cl_d   rs1=%rs1_3  rs2=%rs2_3
@cs_w      ... ... ... .. ... .. &s      imm=%uimm_cl_w   rs1=%rs1_3  rs2=%rs2_3
@cj        ...    ........... .. &j      imm=%imm_cj
@cb_z      ... ... ... .. ... .. &b      imm=%imm_cb      rs1=%rs1_3  rs2=0

@c_ldsp    ... . .....  ..... .. &i      imm=%uimm_6bit_ld rs1=2 %rd
@c_lwsp    ... . .....  ..... .. &i      imm=%uimm_6bit_lw rs1=2 %rd
@c_sdsp    ... . .....  ..... .. &s      imm=%uimm_6bit_sd rs1=2 rs2=%rs2_5
@c_swsp    ... . .....  ..... .. &s      imm=%uimm_6bit_sw rs1=2 rs2=%rs2_5
@c_li      ... . .....  ..... .. &i      imm=%imm_ci rs1=0 %rd
@c_lui     ... . .....  ..... .. &u      imm=%imm_lui %rd
@c_jalr    ... . .....  ..... .. &i      imm=0 rs1=%rd
@c_mv      ... . ..... .....  .. &i      imm=0 rs1=%rs2_5 %rd

@c_addi4spn     ... .  ..... ..... .. &i imm=%nzuimm_ciw rs1=2 rd=%rs2_3
@c_addi16sp     ... .  ..... ..... .. &i imm=%imm_addi16sp rs1=2 rd=2
@c_flwsp_ldsp   ... .  ..... ..... .. &cflwsp_ldsp uimm_flwsp=%uimm_6bit_lw \
    uimm_ldsp=%uimm_6bit_ld %rd
@c_fswsp_sdsp   ... .  ..... ..... .. &cfswsp_sdsp uimm_fswsp=%uimm_6bit_sw \
    uimm_sdsp=%uimm_6bit_sd rs2=%rs2_5

@c_shift        ... . .. ... ..... .. \
                &shift rd=%rs1_3 rs1=%rs1_3 shamt=%shimm_6bit
@c_shift2       ... . .. ... ..... .. \
                &shift rd=%rd rs1=%rd shamt=%shimm_6bit

@c_andi         ... . .. ... ..... .. &i imm=%imm_ci rs1=%rs1_3 rd=%rs1_3

# *** RV64C Standard Extension (Quadrant 0) ***
{
  # Opcode of all zeros is illegal; rd != 0, nzuimm == 0 is reserved.
  illegal         000  000 000 00 --- 00
  addi            000  ... ... .. ... 00 @c_addi4spn
}
fld               001  ... ... .. ... 00 @cl_d
lw                010  ... ... .. ... 00 @cl_w
c_flw_ld          011  --- ... -- ... 00 @cl    #Note: Must parse uimm manually
fsd               101  ... ... .. ... 00 @cs_d
sw                110  ... ... .. ... 00 @cs_w
c_fsw_sd          111  --- ... -- ... 00 @cs    #Note: Must parse uimm manually

# *** RV64C Standard Extension (Quadrant 1) ***
addi              000 .  .....  ..... 01 @ci
c_jal_addiw       001 .  .....  ..... 01 @ci #Note: parse rd and/or imm manually
addi              010 .  .....  ..... 01 @c_li
{
  addi            011 .  00010  ..... 01 @c_addi16sp
  lui             011 .  .....  ..... 01 @c_lui
}
srli              100 . 00 ...  ..... 01 @c_shift
srai              100 . 01 ...  ..... 01 @c_shift
andi              100 . 10 ...  ..... 01 @c_andi
sub               100 0 11 ... 00 ... 01 @cs_2
xor               100 0 11 ... 01 ... 01 @cs_2
or                100 0 11 ... 10 ... 01 @cs_2
and               100 0 11 ... 11 ... 01 @cs_2
c_subw            100 1 11 ... 00 ... 01 @cs_2
c_addw            100 1 11 ... 01 ... 01 @cs_2
jal               101     ........... 01 @cj    rd=0  # C.J
beq               110  ... ...  ..... 01 @cb_z
bne               111  ... ...  ..... 01 @cb_z

# *** RV64C Standard Extension (Quadrant 2) ***
slli              000 .  .....  ..... 10 @c_shift2
fld               001 .  .....  ..... 10 @c_ldsp
lw                010 .  .....  ..... 10 @c_lwsp
c_flwsp_ldsp      011 .  .....  ..... 10 @c_flwsp_ldsp #C.LDSP:RV64;C.FLWSP:RV32
{
  jalr            100 0  .....  00000 10 @c_jalr rd=0  # C.JR
  addi            100 0  .....  ..... 10 @c_mv
}
{
  ebreak          100 1  00000  00000 10
  jalr            100 1  .....  00000 10 @c_jalr rd=1  # C.JALR
  add             100 1  .....  ..... 10 @cr
}
fsd               101   ......  ..... 10 @c_sdsp
sw                110 .  .....  ..... 10 @c_swsp
c_fswsp_sdsp      111 .  .....  ..... 10 @c_fswsp_sdsp #C.SDSP:RV64;C.FSWSP:RV32