f38f3752e27826c97492a1d28ae673c2d78c063f
[platform/upstream/dotnet/runtime.git] / src / coreclr / jit / instrsriscv64.h
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3
4 /*****************************************************************************
5  *  RISCV64 instructions for JIT compiler
6  *
7  *          id          -- the enum name for the instruction
8  *          nm          -- textual name (for assembly dipslay)
9  *          ld/st/cmp   -- load/store/compare instruction
10  *          encode      -- encoding 1
11  *
12  ******************************************************************************/
13
14 #if !defined(TARGET_RISCV64)
15 #error Unexpected target type
16 #endif
17
18 #ifndef INST
19 #error INST must be defined before including this file.
20 #endif
21
22 /*****************************************************************************/
23 /*               The following is RISCV64-specific                               */
24 /*****************************************************************************/
25
26 // If you're adding a new instruction:
27 // You need not only to fill in one of these macros describing the instruction, but also:
28 //   * If the instruction writes to more than one destination register, update the function
29 //     emitInsMayWriteMultipleRegs in emitriscv64.cpp.
30
31 // clang-format off
32
33 // RV32I & RV64I
34 INST(invalid,       "INVALID",        0,    BAD_CODE)
35 INST(nop,           "nop",            0,    0x00000013)
36
37 //// R_R
38 INST(mov,           "mov",            0,    0x00000013)
39
40 ////R_I
41 INST(lui,           "lui",            0,    0x00000037)
42 INST(auipc,         "auipc",          0,    0x00000017)
43
44 //// R_R_I
45 INST(addi,          "addi",           0,    0x00000013)
46 INST(slti,          "slti",           0,    0x00002013)
47 INST(sltiu,         "sltiu",          0,    0x00003013)
48 INST(xori,          "xori",           0,    0x00004013)
49 INST(ori,           "ori",            0,    0x00006013)
50 INST(andi,          "andi",           0,    0x00007013)
51 INST(slli,          "slli",           0,    0x00001013)
52 INST(srli,          "srli",           0,    0x00005013)
53 INST(srai,          "srai",           0,    0x40005013)
54
55 //// R_R_R
56 INST(add,           "add",            0,    0x00000033)
57 INST(sub,           "sub",            0,    0x40000033)
58 INST(sll,           "sll",            0,    0x00001033)
59 INST(slt,           "slt",            0,    0x00002033)
60 INST(sltu,          "sltu",           0,    0x00003033)
61 INST(xor,           "xor",            0,    0x00004033)
62 INST(srl,           "srl",            0,    0x00005033)
63 INST(sra,           "sra",            0,    0x40005033)
64 INST(or,            "or",             0,    0x00006033)
65 INST(and,           "and",            0,    0x00007033)
66
67 INST(fence,         "fence",          0,    0x0000000f)
68 INST(fence_i,       "fence.i",        0,    0x0000100f)
69
70 //// R_I_R
71 INST(csrrw,         "csrrw",          0,    0x00001073)
72 INST(csrrs,         "csrrs",          0,    0x00002073)
73 INST(csrrc,         "csrrc",          0,    0x00003073)
74
75 //// R_I_I
76 INST(csrrwi,        "csrrwi",         0,    0x00005073)
77 INST(csrrsi,        "csrrsi",         0,    0x00006073)
78 INST(csrrci,        "csrrci",         0,    0x00007073)
79
80 INST(ecall,         "ecall",          0,    0x00000073)
81 INST(ebreak,        "ebreak",         0,    0x00100073)
82 INST(uret,          "uret",           0,    0x00200073)
83 INST(sret,          "sret",           0,    0x10200073)
84 INST(mret,          "mret",           0,    0x30200073)
85 INST(wfi,           "wfi",            0,    0x10500073)
86 INST(sfence_vma,    "sfence.vma",     0,    0x12000073)
87
88 //// R_R_I
89 INST(lb,            "lb",             LD,   0x00000003)
90 INST(lh,            "lh",             LD,   0x00001003)
91 INST(lw,            "lw",             LD,   0x00002003)
92 INST(lbu,           "lbu",            LD,   0x00004003)
93 INST(lhu,           "lhu",            LD,   0x00005003)
94
95 INST(sb,            "sb",             ST,   0x00000023)
96 INST(sh,            "sh",             ST,   0x00001023)
97 INST(sw,            "sw",             ST,   0x00002023)
98
99 //// R_I
100 INST(jal,           "jal",            0,    0x0000006f)
101 INST(j,             "j",              0,    0x0000006f)
102 INST(beqz,          "beqz",           0,    0x00000063)
103 INST(bnez,          "bnez",           0,    0x00001063)
104
105 //// R_R_I
106 INST(jalr,          "jalr",           0,    0x00000067)
107 INST(beq,           "beq",            0,    0x00000063)
108 INST(bne,           "bne",            0,    0x00001063)
109 INST(blt,           "blt",            0,    0x00004063)
110 INST(bge,           "bge",            0,    0x00005063)
111 INST(bltu,          "bltu",           0,    0x00006063)
112 INST(bgeu,          "bgeu",           0,    0x00007063)
113
114 // RV64I
115 //// R_R_I
116 INST(addiw,         "addiw",          0,    0x0000001b)
117 INST(slliw,         "slliw",          0,    0x0000101b)
118 INST(srliw,         "srliw",          0,    0x0000501b)
119 INST(sraiw,         "sraiw",          0,    0x4000501b)
120
121 //// R_R_R
122 INST(addw,          "addw",           0,    0x0000003b)
123 INST(subw,          "subw",           0,    0x4000003b)
124 INST(sllw,          "sllw",           0,    0x0000103b)
125 INST(srlw,          "srlw",           0,    0x0000503b)
126 INST(sraw,          "sraw",           0,    0x4000503b)
127
128 //// R_R_I
129 INST(lwu,           "lwu",            LD,   0x00006003)
130 INST(ld,            "ld",             LD,   0x00003003)
131 INST(sd,            "sd",             ST,   0x00003023)
132
133
134 // RV32M & RV64M
135 //// R_R_R
136 INST(mul,           "mul",            0,   0x02000033)
137 INST(mulh,          "mulh",           0,   0x02001033)
138 INST(mulhsu,        "mulhsu",         0,   0x02002033)
139 INST(mulhu,         "mulhu",          0,   0x02003033)
140 INST(div,           "div",            0,   0x02004033)
141 INST(divu,          "divu",           0,   0x02005033)
142 INST(rem,           "rem",            0,   0x02006033)
143 INST(remu,          "remu",           0,   0x02007033)
144
145
146 // RV64M
147 //// R_R_R
148 INST(mulw,          "mulw",           0,   0x0200003b)
149 INST(divw,          "divw",           0,   0x0200403b)
150 INST(divuw,         "divuw",          0,   0x0200503b)
151 INST(remw,          "remw",           0,   0x0200603b)
152 INST(remuw,         "remuw",          0,   0x0200703b)
153
154 // RV32F & RV64D
155 //// R_R_R_R
156 INST(fmadd_s,       "fmadd.s",        0,   0x00000043)
157 INST(fmsub_s,       "fmsub.s",        0,   0x00000047)
158 INST(fnmsub_s,      "fnmsub.s",       0,   0x0000004b)
159 INST(fnmadd_s,      "fnmadd.s",       0,   0x0000004f)
160
161 //// R_R_R
162 INST(fadd_s,        "fadd.s",         0,   0x00000053)
163 INST(fsub_s,        "fsub.s",         0,   0x08000053)
164 INST(fmul_s,        "fmul.s",         0,   0x10000053)
165 INST(fdiv_s,        "fdiv.s",         0,   0x18000053)
166 INST(fsqrt_s,       "fsqrt.s",        0,   0x58000053)
167 INST(fsgnj_s,       "fsgnj.s",        0,   0x20000053)
168 INST(fsgnjn_s,      "fsgnjn.s",       0,   0x20001053)
169 INST(fsgnjx_s,      "fsgnjx.s",       0,   0x20002053)
170 INST(fmin_s,        "fmin.s",         0,   0x28000053)
171 INST(fmax_s,        "fmax.s",         0,   0x28001053)
172
173 //// R_R
174 INST(fcvt_w_s,      "fcvt.w.s",       0,   0xc0000053)
175 INST(fcvt_wu_s,     "fcvt.wu.s",      0,   0xc0100053)
176 INST(fmv_x_w,       "fmv.x.w",        0,   0xe0000053)
177
178 //// R_R_R
179 INST(feq_s,         "feq.s",          0,   0xa0002053)
180 INST(flt_s,         "flt.s",          0,   0xa0001053)
181 INST(fle_s,         "fle.s",          0,   0xa0000053)
182
183 //// R_R
184 INST(fclass_s,      "fclass.s",       0,   0xe0001053)
185 INST(fcvt_s_w,      "fcvt.s.w",       0,   0xd0000053)
186 INST(fcvt_s_wu,     "fcvt.s.wu",      0,   0xd0100053)
187 INST(fmv_w_x,       "fmv.w.x",        0,   0xf0000053)
188
189 //// R_R_R_R
190 INST(fmadd_d,       "fmadd.d",        0,   0x02000043)
191 INST(fmsub_d,       "fmsub.d",        0,   0x02000047)
192 INST(fnmsub_d,      "fnmsub.d",       0,   0x0200004b)
193 INST(fnmadd_d,      "fnmadd.d",       0,   0x0200004f)
194
195 //// R_R_R
196 INST(fadd_d,        "fadd.d",         0,   0x02000053)
197 INST(fsub_d,        "fsub.d",         0,   0x0a000053)
198 INST(fmul_d,        "fmul.d",         0,   0x12000053)
199 INST(fdiv_d,        "fdiv.d",         0,   0x1a000053)
200 INST(fsqrt_d,       "fsqrt.d",        0,   0x5a000053)
201 INST(fsgnj_d,       "fsgnj.d",        0,   0x22000053)
202 INST(fsgnjn_d,      "fsgnjn.d",       0,   0x22001053)
203 INST(fsgnjx_d,      "fsgnjx.d",       0,   0x22002053)
204 INST(fmin_d,        "fmin.d",         0,   0x2a000053)
205 INST(fmax_d,        "fmax.d",         0,   0x2a001053)
206
207 //// R_R
208 INST(fcvt_s_d,      "fcvt.s.d",       0,   0x40101053)
209 INST(fcvt_d_s,      "fcvt.d.s",       0,   0x42001053)
210
211 //// R_R_R
212 INST(feq_d,         "feq.d",          0,   0xa2002053)
213 INST(flt_d,         "flt.d",          0,   0xa2001053)
214 INST(fle_d,         "fle.d",          0,   0xa2000053)
215
216 //// R_R
217 INST(fclass_d,      "fclass.d",       0,   0xe2001053)
218 INST(fcvt_w_d,      "fcvt.w.d",       0,   0xc2001053)
219 INST(fcvt_wu_d,     "fcvt.wu.d",      0,   0xc2101053)
220 INST(fcvt_d_w,      "fcvt.d.w",       0,   0xd2001053)
221 INST(fcvt_d_wu,     "fcvt.d.wu",      0,   0xd2101053)
222
223 //// R_R_I
224 INST(flw,           "flw",            LD,  0x00002007)
225 INST(fsw,           "fsw",            ST,  0x00002027)
226 INST(fld,           "fld",            LD,  0x00003007)
227 INST(fsd,           "fsd",            ST,  0x00003027)
228
229 // RV64F
230 //// R_R
231 INST(fcvt_l_s,      "fcvt.l.s",       0,   0xc0200053)
232 INST(fcvt_lu_s,     "fcvt.lu.s",      0,   0xc0300053)
233 INST(fcvt_s_l,      "fcvt.s.l",       0,   0xd0200053)
234 INST(fcvt_s_lu,     "fcvt.s.lu",      0,   0xd0300053)
235
236 // RV64D
237 INST(fcvt_l_d,      "fcvt.l.d",       0,   0xc2200053)
238 INST(fcvt_lu_d,     "fcvt.lu.d",      0,   0xc2300053)
239 INST(fmv_x_d,       "fmv.x.d",        0,   0xe2000053)
240 INST(fcvt_d_l,      "fcvt.d.l",       0,   0xd2200053)
241 INST(fcvt_d_lu,     "fcvt.d.lu",      0,   0xd2300053)
242 INST(fmv_d_x,       "fmv.d.x",        0,   0xf2000053)
243
244 // RV32A + RV64A (R-type, R_R_R)
245 INST(lr_w,          "lr.w",           0,   0x1000202f) // funct5:00010
246 INST(lr_d,          "lr.d",           0,   0x1000302f) // funct5:00010
247 INST(sc_w,          "sc.w",           0,   0x1800202f) // funct5:00011
248 INST(sc_d,          "sc.d",           0,   0x1800302f) // funct5:00011
249 INST(amoswap_w,     "amoswap.w",      0,   0x0800202f) // funct5:00001
250 INST(amoswap_d,     "amoswap.d",      0,   0x0800302f) // funct5:00001
251 INST(amoadd_w,      "amoadd.w",       0,   0x0000202f) // funct5:00000
252 INST(amoadd_d,      "amoadd.d",       0,   0x0000302f) // funct5:00000
253 INST(amoxor_w,      "amoxor.w",       0,   0x2000202f) // funct5:00100
254 INST(amoxor_d,      "amoxor.d",       0,   0x2000302f) // funct5:00100
255 INST(amoand_w,      "amoand.w",       0,   0x6000202f) // funct5:01100
256 INST(amoand_d,      "amoand.d",       0,   0x6000302f) // funct5:01100
257 INST(amoor_w,       "amoor.w",        0,   0x4000202f) // funct5:01000
258 INST(amoor_d,       "amoor.d",        0,   0x4000302f) // funct5:01000
259 INST(amomin_w,      "amomin.w",       0,   0x8000202f) // funct5:10000
260 INST(amomin_d,      "amomin.d",       0,   0x8000302f) // funct5:10000
261 INST(amomax_w,      "amomax.w",       0,   0xa000202f) // funct5:10100
262 INST(amomax_d,      "amomax.d",       0,   0xa000302f) // funct5:10100
263 INST(amominu_w,     "amominu.w",      0,   0xc000202f) // funct5:11000
264 INST(amominu_d,     "amominu.d",      0,   0xc000302f) // funct5:11000
265 INST(amomaxu_w,     "amomaxu.w",      0,   0xe000202f) // funct5:11100
266 INST(amomaxu_d,     "amomaxu.d",      0,   0xe000302f) // funct5:11100
267 // clang-format on
268 /*****************************************************************************/
269 #undef INST
270 /*****************************************************************************/