Select one of the symbols to view example projects that use it.
 
Outline
#include "encoding.h"
#define ZERO
#define T0
#define S0
#define S1
bits(uint32_t, unsigned int, unsigned int)
bit(uint32_t, unsigned int)
inst_rd(uint32_t);
inst_rd(uint32_t)
inst_rs1(uint32_t);
inst_rs1(uint32_t)
inst_rs2(uint32_t);
inst_rs2(uint32_t)
imm_i(uint32_t);
imm_i(uint32_t)
imm_s(uint32_t);
imm_s(uint32_t)
imm_b(uint32_t);
imm_b(uint32_t)
imm_u(uint32_t);
imm_u(uint32_t)
imm_j(uint32_t);
imm_j(uint32_t)
jal(unsigned int, uint32_t);
jal(unsigned int, uint32_t)
csrsi(unsigned int, uint16_t);
csrsi(unsigned int, uint16_t)
sw(unsigned int, unsigned int, uint16_t);
sw(unsigned int, unsigned int, uint16_t)
sd(unsigned int, unsigned int, uint16_t);
sd(unsigned int, unsigned int, uint16_t)
sh(unsigned int, unsigned int, uint16_t);
sh(unsigned int, unsigned int, uint16_t)
sb(unsigned int, unsigned int, uint16_t);
sb(unsigned int, unsigned int, uint16_t)
ld(unsigned int, unsigned int, uint16_t);
ld(unsigned int, unsigned int, uint16_t)
lw(unsigned int, unsigned int, uint16_t);
lw(unsigned int, unsigned int, uint16_t)
lh(unsigned int, unsigned int, uint16_t);
lh(unsigned int, unsigned int, uint16_t)
lb(unsigned int, unsigned int, uint16_t);
lb(unsigned int, unsigned int, uint16_t)
csrw(unsigned int, unsigned int);
csrw(unsigned int, unsigned int)
addi(unsigned int, unsigned int, uint16_t);
addi(unsigned int, unsigned int, uint16_t)
csrr(unsigned int, unsigned int);
csrr(unsigned int, unsigned int)
csrrs(unsigned int, unsigned int, unsigned int);
csrrs(unsigned int, unsigned int, unsigned int)
csrrw(unsigned int, unsigned int, unsigned int);
csrrw(unsigned int, unsigned int, unsigned int)
csrrci(unsigned int, unsigned int, unsigned int);
csrrci(unsigned int, unsigned int, unsigned int)
csrrsi(unsigned int, unsigned int, unsigned int);
csrrsi(unsigned int, unsigned int, unsigned int)
fsw(unsigned int, unsigned int, uint16_t);
fsw(unsigned int, unsigned int, uint16_t)
fsd(unsigned int, unsigned int, uint16_t);
fsd(unsigned int, unsigned int, uint16_t)
flw(unsigned int, unsigned int, uint16_t);
flw(unsigned int, unsigned int, uint16_t)
fld(unsigned int, unsigned int, uint16_t);
fld(unsigned int, unsigned int, uint16_t)
fmv_x_w(unsigned int, unsigned int);
fmv_x_w(unsigned int, unsigned int)
fmv_x_d(unsigned int, unsigned int);
fmv_x_d(unsigned int, unsigned int)
fmv_w_x(unsigned int, unsigned int);
fmv_w_x(unsigned int, unsigned int)
fmv_d_x(unsigned int, unsigned int);
fmv_d_x(unsigned int, unsigned int)
ebreak();
ebreak()
ebreak_c();
ebreak_c()
wfi();
wfi()
fence_i();
fence_i()
lui(unsigned int, uint32_t);
lui(unsigned int, uint32_t)
xori(unsigned int, unsigned int, uint16_t);
xori(unsigned int, unsigned int, uint16_t)
srli(unsigned int, unsigned int, uint8_t);
srli(unsigned int, unsigned int, uint8_t)
fence();
fence()
auipc(unsigned int);
auipc(unsigned int)
vsetvli(unsigned int, unsigned int, uint16_t);
vsetvli(unsigned int, unsigned int, uint16_t)
vmv_x_s(unsigned int, unsigned int);
vmv_x_s(unsigned int, unsigned int)
vmv_s_x(unsigned int, unsigned int);
vmv_s_x(unsigned int, unsigned int)
vslide1down_vx(unsigned int, unsigned int, unsigned int, unsigned int);
vslide1down_vx(unsigned int, unsigned int, unsigned int, unsigned int)
Files
loading...
SourceVuDevelopment ToolsOpenOCDsrc/target/riscv/opcodes.h
 
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* SPDX-License-Identifier: GPL-2.0-or-later */ #include "encoding.h" #define ZERO 0 #define T0 5 #define S0 8 #define S1 9 static uint32_t bits(uint32_t value, unsigned int hi, unsigned int lo) { return (value >> lo) & ((1 << (hi+1-lo)) - 1); }{ ... } static uint32_t bit(uint32_t value, unsigned int b) { return (value >> b) & 1; }{ ... } static uint32_t inst_rd(uint32_t r) __attribute__ ((unused)); static uint32_t inst_rd(uint32_t r) { return bits(r, 4, 0) << 7; }{ ... } static uint32_t inst_rs1(uint32_t r) __attribute__ ((unused)); static uint32_t inst_rs1(uint32_t r) { return bits(r, 4, 0) << 15; }{ ... } static uint32_t inst_rs2(uint32_t r) __attribute__ ((unused)); static uint32_t inst_rs2(uint32_t r) { return bits(r, 4, 0) << 20; }{ ... } static uint32_t imm_i(uint32_t imm) __attribute__ ((unused)); static uint32_t imm_i(uint32_t imm) { return bits(imm, 11, 0) << 20; }{ ... } static uint32_t imm_s(uint32_t imm) __attribute__ ((unused)); static uint32_t imm_s(uint32_t imm) { return (bits(imm, 4, 0) << 7) | (bits(imm, 11, 5) << 25); }{ ... } static uint32_t imm_b(uint32_t imm) __attribute__ ((unused)); static uint32_t imm_b(uint32_t imm) { return (bit(imm, 11) << 7) | (bits(imm, 4, 1) << 8) | (bits(imm, 10, 5) << 25) | (bit(imm, 12) << 31); }{ ... } static uint32_t imm_u(uint32_t imm) __attribute__ ((unused)); static uint32_t imm_u(uint32_t imm) { return bits(imm, 31, 12) << 12; }{ ... } static uint32_t imm_j(uint32_t imm) __attribute__ ((unused)); static uint32_t imm_j(uint32_t imm) { return (bits(imm, 19, 12) << 12) | (bit(imm, 11) << 20) | (bits(imm, 10, 1) << 21) | (bit(imm, 20) << 31); }{ ... } static uint32_t jal(unsigned int rd, uint32_t imm) __attribute__ ((unused)); static uint32_t jal(unsigned int rd, uint32_t imm) { return imm_j(imm) | inst_rd(rd) | MATCH_JAL; }{ ... } static uint32_t csrsi(unsigned int csr, uint16_t imm) __attribute__ ((unused)); static uint32_t csrsi(unsigned int csr, uint16_t imm) { return imm_i(csr) | inst_rs1(imm) | MATCH_CSRRSI; }{ ... } static uint32_t sw(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused)); static uint32_t sw(unsigned int src, unsigned int base, uint16_t offset) { return imm_s(offset) | inst_rs2(src) | inst_rs1(base) | MATCH_SW; }{ ... } static uint32_t sd(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused)); static uint32_t sd(unsigned int src, unsigned int base, uint16_t offset) { return imm_s(offset) | inst_rs2(src) | inst_rs1(base) | MATCH_SD; }{ ... } static uint32_t sh(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused)); static uint32_t sh(unsigned int src, unsigned int base, uint16_t offset) { return imm_s(offset) | inst_rs2(src) | inst_rs1(base) | MATCH_SH; }{ ... } static uint32_t sb(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused)); static uint32_t sb(unsigned int src, unsigned int base, uint16_t offset) { return imm_s(offset) | inst_rs2(src) | inst_rs1(base) | MATCH_SB; }{ ... } static uint32_t ld(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused)); static uint32_t ld(unsigned int rd, unsigned int base, uint16_t offset) { return imm_i(offset) | inst_rs1(base) | inst_rd(rd) | MATCH_LD; }{ ... } static uint32_t lw(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused)); static uint32_t lw(unsigned int rd, unsigned int base, uint16_t offset) { return imm_i(offset) | inst_rs1(base) | inst_rd(rd) | MATCH_LW; }{ ... } static uint32_t lh(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused)); static uint32_t lh(unsigned int rd, unsigned int base, uint16_t offset) { return imm_i(offset) | inst_rs1(base) | inst_rd(rd) | MATCH_LH; }{ ... } static uint32_t lb(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused)); static uint32_t lb(unsigned int rd, unsigned int base, uint16_t offset) { return imm_i(offset) | inst_rs1(base) | inst_rd(rd) | MATCH_LB; }{ ... } static uint32_t csrw(unsigned int source, unsigned int csr) __attribute__ ((unused)); static uint32_t csrw(unsigned int source, unsigned int csr) { return imm_i(csr) | inst_rs1(source) | MATCH_CSRRW; }{ ... } static uint32_t addi(unsigned int dest, unsigned int src, uint16_t imm) __attribute__ ((unused)); static uint32_t addi(unsigned int dest, unsigned int src, uint16_t imm) { return imm_i(imm) | inst_rs1(src) | inst_rd(dest) | MATCH_ADDI; }{ ... } static uint32_t csrr(unsigned int rd, unsigned int csr) __attribute__ ((unused)); static uint32_t csrr(unsigned int rd, unsigned int csr) { return imm_i(csr) | inst_rd(rd) | MATCH_CSRRS; }{ ... } static uint32_t csrrs(unsigned int rd, unsigned int rs, unsigned int csr) __attribute__ ((unused)); static uint32_t csrrs(unsigned int rd, unsigned int rs, unsigned int csr) { return imm_i(csr) | inst_rs1(rs) | inst_rd(rd) | MATCH_CSRRS; }{ ... } static uint32_t csrrw(unsigned int rd, unsigned int rs, unsigned int csr) __attribute__ ((unused)); static uint32_t csrrw(unsigned int rd, unsigned int rs, unsigned int csr) { return imm_i(csr) | inst_rs1(rs) | inst_rd(rd) | MATCH_CSRRW; }{ ... } static uint32_t csrrci(unsigned int rd, unsigned int zimm, unsigned int csr) __attribute__ ((unused)); static uint32_t csrrci(unsigned int rd, unsigned int zimm, unsigned int csr) { return imm_i(csr) | inst_rs1(zimm) | inst_rd(rd) | MATCH_CSRRCI; }{ ... } static uint32_t csrrsi(unsigned int rd, unsigned int zimm, unsigned int csr) __attribute__ ((unused)); static uint32_t csrrsi(unsigned int rd, unsigned int zimm, unsigned int csr) { return imm_i(csr) | inst_rs1(zimm) | inst_rd(rd) | MATCH_CSRRSI; }{ ... } static uint32_t fsw(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused)); static uint32_t fsw(unsigned int src, unsigned int base, uint16_t offset) { return imm_s(offset) | inst_rs2(src) | inst_rs1(base) | MATCH_FSW; }{ ... } static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused)); static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset) { return imm_s(offset) | inst_rs2(src) | inst_rs1(base) | MATCH_FSD; }{ ... } static uint32_t flw(unsigned int dest, unsigned int base, uint16_t offset) __attribute__ ((unused)); static uint32_t flw(unsigned int dest, unsigned int base, uint16_t offset) { return imm_i(offset) | inst_rs1(base) | inst_rd(dest) | MATCH_FLW; }{ ... } static uint32_t fld(unsigned int dest, unsigned int base, uint16_t offset) __attribute__ ((unused)); static uint32_t fld(unsigned int dest, unsigned int base, uint16_t offset) { return imm_i(offset) | inst_rs1(base) | inst_rd(dest) | MATCH_FLD; }{ ... } static uint32_t fmv_x_w(unsigned dest, unsigned src) __attribute__ ((unused)); static uint32_t fmv_x_w(unsigned dest, unsigned src) { return inst_rs1(src) | inst_rd(dest) | MATCH_FMV_X_W; }{ ... } static uint32_t fmv_x_d(unsigned dest, unsigned src) __attribute__ ((unused)); static uint32_t fmv_x_d(unsigned dest, unsigned src) { return inst_rs1(src) | inst_rd(dest) | MATCH_FMV_X_D; }{ ... } static uint32_t fmv_w_x(unsigned dest, unsigned src) __attribute__ ((unused)); static uint32_t fmv_w_x(unsigned dest, unsigned src) { return inst_rs1(src) | inst_rd(dest) | MATCH_FMV_W_X; }{ ... } static uint32_t fmv_d_x(unsigned dest, unsigned src) __attribute__ ((unused)); static uint32_t fmv_d_x(unsigned dest, unsigned src) { return inst_rs1(src) | inst_rd(dest) | MATCH_FMV_D_X; }{ ... } static uint32_t ebreak(void) __attribute__ ((unused)); static uint32_t ebreak(void) { return MATCH_EBREAK; }{ ... } static uint32_t ebreak_c(void) __attribute__ ((unused)); static uint32_t ebreak_c(void) { return MATCH_C_EBREAK; }{ ... } static uint32_t wfi(void) __attribute__ ((unused)); static uint32_t wfi(void) { return MATCH_WFI; } static uint32_t fence_i(void) __attribute__ ((unused)); static uint32_t fence_i(void) { return MATCH_FENCE_I; }{ ... } static uint32_t lui(unsigned int dest, uint32_t imm) __attribute__ ((unused)); static uint32_t lui(unsigned int dest, uint32_t imm) { return imm_u(imm) | inst_rd(dest) | MATCH_LUI; }{ ... } /* static uint32_t csrci(unsigned int csr, uint16_t imm) __attribute__ ((unused)); static uint32_t csrci(unsigned int csr, uint16_t imm) { return (csr << 20) | (bits(imm, 4, 0) << 15) | MATCH_CSRRCI; } static uint32_t li(unsigned int dest, uint16_t imm) __attribute__ ((unused)); static uint32_t li(unsigned int dest, uint16_t imm) { return addi(dest, 0, imm); } static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused)); static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset) { return (bits(offset, 11, 5) << 25) | (bits(src, 4, 0) << 20) | (base << 15) | (bits(offset, 4, 0) << 7) | MATCH_FSD; } static uint32_t ori(unsigned int dest, unsigned int src, uint16_t imm) __attribute__ ((unused)); static uint32_t ori(unsigned int dest, unsigned int src, uint16_t imm) { return (bits(imm, 11, 0) << 20) | (src << 15) | (dest << 7) | MATCH_ORI; } static uint32_t nop(void) __attribute__ ((unused)); static uint32_t nop(void) { return addi(0, 0, 0); } *//* ... */ static uint32_t xori(unsigned int dest, unsigned int src, uint16_t imm) __attribute__ ((unused)); static uint32_t xori(unsigned int dest, unsigned int src, uint16_t imm) { return imm_i(imm) | inst_rs1(src) | inst_rd(dest) | MATCH_XORI; }{ ... } static uint32_t srli(unsigned int dest, unsigned int src, uint8_t shamt) __attribute__ ((unused)); static uint32_t srli(unsigned int dest, unsigned int src, uint8_t shamt) { return inst_rs2(shamt) | inst_rs1(src) | inst_rd(dest) | MATCH_SRLI; }{ ... } static uint32_t fence(void) __attribute__((unused)); static uint32_t fence(void) { return MATCH_FENCE; }{ ... } static uint32_t auipc(unsigned int dest) __attribute__((unused)); static uint32_t auipc(unsigned int dest) { return MATCH_AUIPC | inst_rd(dest); }{ ... } static uint32_t vsetvli(unsigned int dest, unsigned int src, uint16_t imm) __attribute__((unused)); static uint32_t vsetvli(unsigned int dest, unsigned int src, uint16_t imm) { return (bits(imm, 10, 0) << 20) | inst_rs1(src) | inst_rd(dest) | MATCH_VSETVLI; }{ ... } static uint32_t vmv_x_s(unsigned int rd, unsigned int vs2) __attribute__((unused)); static uint32_t vmv_x_s(unsigned int rd, unsigned int vs2) { return inst_rs2(vs2) | inst_rd(rd) | MATCH_VMV_X_S; }{ ... } static uint32_t vmv_s_x(unsigned int vd, unsigned int vs2) __attribute__((unused)); static uint32_t vmv_s_x(unsigned int vd, unsigned int rs1) { return inst_rs1(rs1) | inst_rd(vd) | MATCH_VMV_S_X; }{ ... } static uint32_t vslide1down_vx(unsigned int vd, unsigned int vs2, unsigned int rs1, unsigned int vm) __attribute__((unused)); static uint32_t vslide1down_vx(unsigned int vd, unsigned int vs2, unsigned int rs1, unsigned int vm) { return ((vm & 1) << 25) | inst_rs2(vs2) | inst_rs1(rs1) | inst_rd(vd) | MATCH_VSLIDE1DOWN_VX; }{ ... }
Details
Show:
from
Types: Columns:
Click anywhere in the source to view detailed information here...