| 1 |
// Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 |
// All Rights Reserved. |
| 3 |
// |
| 4 |
// Redistribution and use in source and binary forms, with or without |
| 5 |
// modification, are permitted provided that the following conditions are |
| 6 |
// met: |
| 7 |
// |
| 8 |
// - Redistributions of source code must retain the above copyright notice, |
| 9 |
// this list of conditions and the following disclaimer. |
| 10 |
// |
| 11 |
// - Redistribution in binary form must reproduce the above copyright |
| 12 |
// notice, this list of conditions and the following disclaimer in the |
| 13 |
// documentation and/or other materials provided with the distribution. |
| 14 |
// |
| 15 |
// - Neither the name of Sun Microsystems or the names of contributors may |
| 16 |
// be used to endorse or promote products derived from this software without |
| 17 |
// specific prior written permission. |
| 18 |
// |
| 19 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 20 |
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 21 |
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 22 |
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 23 |
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 |
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 |
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 |
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 27 |
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 28 |
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 29 |
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 |
|
| 31 |
// The original source code covered by the above license above has been |
| 32 |
// modified significantly by Google Inc. |
| 33 |
// Copyright 2021 the V8 project authors. All rights reserved. |
| 34 |
|
| 35 |
#include "jit/riscv64/extension/base-assembler-riscv.h" |
| 36 |
#include "jit/riscv64/Architecture-riscv64.h" |
| 37 |
|
| 38 |
namespace js { |
| 39 |
namespace jit { |
| 40 |
|
| 41 |
int ToNumber(Register reg) { |
| 42 |
MOZ_ASSERT(reg.code() < Registers::Total && reg.code() >= 0); |
| 43 |
const int kNumbers[] = { |
| 44 |
0, // zero_reg |
| 45 |
1, // ra |
| 46 |
2, // sp |
| 47 |
3, // gp |
| 48 |
4, // tp |
| 49 |
5, // t0 |
| 50 |
6, // t1 |
| 51 |
7, // t2 |
| 52 |
8, // s0/fp |
| 53 |
9, // s1 |
| 54 |
10, // a0 |
| 55 |
11, // a1 |
| 56 |
12, // a2 |
| 57 |
13, // a3 |
| 58 |
14, // a4 |
| 59 |
15, // a5 |
| 60 |
16, // a6 |
| 61 |
17, // a7 |
| 62 |
18, // s2 |
| 63 |
19, // s3 |
| 64 |
20, // s4 |
| 65 |
21, // s5 |
| 66 |
22, // s6 |
| 67 |
23, // s7 |
| 68 |
24, // s8 |
| 69 |
25, // s9 |
| 70 |
26, // s10 |
| 71 |
27, // s11 |
| 72 |
28, // t3 |
| 73 |
29, // t4 |
| 74 |
30, // t5 |
| 75 |
31, // t6 |
| 76 |
}; |
| 77 |
return kNumbers[reg.code()]; |
| 78 |
} |
| 79 |
|
| 80 |
Register ToRegister(uint32_t num) { |
| 81 |
MOZ_ASSERT(num >= 0 && num < Registers::Total); |
| 82 |
const Register kRegisters[] = { |
| 83 |
zero_reg, ra, sp, gp, tp, t0, t1, t2, fp, s1, a0, a1, a2, a3, a4, a5, |
| 84 |
a6, a7, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, t3, t4, t5, t6}; |
| 85 |
return kRegisters[num]; |
| 86 |
} |
| 87 |
|
| 88 |
// ----- Top-level instruction formats match those in the ISA manual |
| 89 |
// (R, I, S, B, U, J). These match the formats defined in the compiler |
| 90 |
void AssemblerRiscvBase::GenInstrR(uint8_t funct7, uint8_t funct3, |
| 91 |
BaseOpcode opcode, Register rd, Register rs1, |
| 92 |
Register rs2) { |
| 93 |
MOZ_ASSERT(is_uint7(funct7) && is_uint3(funct3)); |
| 94 |
Instr instr = opcode | (rd.code() << kRdShift) | (funct3 << kFunct3Shift) | |
| 95 |
(rs1.code() << kRs1Shift) | (rs2.code() << kRs2Shift) | |
| 96 |
(funct7 << kFunct7Shift); |
| 97 |
emit(instr); |
| 98 |
} |
| 99 |
|
| 100 |
void AssemblerRiscvBase::GenInstrR(uint8_t funct7, uint8_t funct3, |
| 101 |
BaseOpcode opcode, FPURegister rd, |
| 102 |
FPURegister rs1, FPURegister rs2) { |
| 103 |
MOZ_ASSERT(is_uint7(funct7) && is_uint3(funct3)); |
| 104 |
Instr instr = opcode | (rd.code() << kRdShift) | (funct3 << kFunct3Shift) | |
| 105 |
(rs1.code() << kRs1Shift) | (rs2.code() << kRs2Shift) | |
| 106 |
(funct7 << kFunct7Shift); |
| 107 |
emit(instr); |
| 108 |
} |
| 109 |
|
| 110 |
void AssemblerRiscvBase::GenInstrR(uint8_t funct7, uint8_t funct3, |
| 111 |
BaseOpcode opcode, Register rd, |
| 112 |
FPURegister rs1, Register rs2) { |
| 113 |
MOZ_ASSERT(is_uint7(funct7) && is_uint3(funct3)); |
| 114 |
Instr instr = opcode | (rd.code() << kRdShift) | (funct3 << kFunct3Shift) | |
| 115 |
(rs1.code() << kRs1Shift) | (rs2.code() << kRs2Shift) | |
| 116 |
(funct7 << kFunct7Shift); |
| 117 |
emit(instr); |
| 118 |
} |
| 119 |
|
| 120 |
void AssemblerRiscvBase::GenInstrR(uint8_t funct7, uint8_t funct3, |
| 121 |
BaseOpcode opcode, FPURegister rd, |
| 122 |
Register rs1, Register rs2) { |
| 123 |
MOZ_ASSERT(is_uint7(funct7) && is_uint3(funct3)); |
| 124 |
Instr instr = opcode | (rd.code() << kRdShift) | (funct3 << kFunct3Shift) | |
| 125 |
(rs1.code() << kRs1Shift) | (rs2.code() << kRs2Shift) | |
| 126 |
(funct7 << kFunct7Shift); |
| 127 |
emit(instr); |
| 128 |
} |
| 129 |
|
| 130 |
void AssemblerRiscvBase::GenInstrR(uint8_t funct7, uint8_t funct3, |
| 131 |
BaseOpcode opcode, FPURegister rd, |
| 132 |
FPURegister rs1, Register rs2) { |
| 133 |
MOZ_ASSERT(is_uint7(funct7) && is_uint3(funct3)); |
| 134 |
Instr instr = opcode | (rd.code() << kRdShift) | (funct3 << kFunct3Shift) | |
| 135 |
(rs1.code() << kRs1Shift) | (rs2.code() << kRs2Shift) | |
| 136 |
(funct7 << kFunct7Shift); |
| 137 |
emit(instr); |
| 138 |
} |
| 139 |
|
| 140 |
void AssemblerRiscvBase::GenInstrR(uint8_t funct7, uint8_t funct3, |
| 141 |
BaseOpcode opcode, Register rd, |
| 142 |
FPURegister rs1, FPURegister rs2) { |
| 143 |
MOZ_ASSERT(is_uint7(funct7) && is_uint3(funct3)); |
| 144 |
Instr instr = opcode | (rd.code() << kRdShift) | (funct3 << kFunct3Shift) | |
| 145 |
(rs1.code() << kRs1Shift) | (rs2.code() << kRs2Shift) | |
| 146 |
(funct7 << kFunct7Shift); |
| 147 |
emit(instr); |
| 148 |
} |
| 149 |
|
| 150 |
void AssemblerRiscvBase::GenInstrR4(uint8_t funct2, BaseOpcode opcode, |
| 151 |
Register rd, Register rs1, Register rs2, |
| 152 |
Register rs3, FPURoundingMode frm) { |
| 153 |
MOZ_ASSERT(is_uint2(funct2) && is_uint3(frm)); |
| 154 |
Instr instr = opcode | (rd.code() << kRdShift) | (frm << kFunct3Shift) | |
| 155 |
(rs1.code() << kRs1Shift) | (rs2.code() << kRs2Shift) | |
| 156 |
(funct2 << kFunct2Shift) | (rs3.code() << kRs3Shift); |
| 157 |
emit(instr); |
| 158 |
} |
| 159 |
|
| 160 |
void AssemblerRiscvBase::GenInstrR4(uint8_t funct2, BaseOpcode opcode, |
| 161 |
FPURegister rd, FPURegister rs1, |
| 162 |
FPURegister rs2, FPURegister rs3, |
| 163 |
FPURoundingMode frm) { |
| 164 |
MOZ_ASSERT(is_uint2(funct2) && is_uint3(frm)); |
| 165 |
Instr instr = opcode | (rd.code() << kRdShift) | (frm << kFunct3Shift) | |
| 166 |
(rs1.code() << kRs1Shift) | (rs2.code() << kRs2Shift) | |
| 167 |
(funct2 << kFunct2Shift) | (rs3.code() << kRs3Shift); |
| 168 |
emit(instr); |
| 169 |
} |
| 170 |
|
| 171 |
void AssemblerRiscvBase::GenInstrRAtomic(uint8_t funct5, bool aq, bool rl, |
| 172 |
uint8_t funct3, Register rd, |
| 173 |
Register rs1, Register rs2) { |
| 174 |
MOZ_ASSERT(is_uint5(funct5) && is_uint3(funct3)); |
| 175 |
Instr instr = AMO | (rd.code() << kRdShift) | (funct3 << kFunct3Shift) | |
| 176 |
(rs1.code() << kRs1Shift) | (rs2.code() << kRs2Shift) | |
| 177 |
(rl << kRlShift) | (aq << kAqShift) | (funct5 << kFunct5Shift); |
| 178 |
emit(instr); |
| 179 |
} |
| 180 |
|
| 181 |
void AssemblerRiscvBase::GenInstrRFrm(uint8_t funct7, BaseOpcode opcode, |
| 182 |
Register rd, Register rs1, Register rs2, |
| 183 |
FPURoundingMode frm) { |
| 184 |
MOZ_ASSERT(is_uint3(frm)); |
| 185 |
Instr instr = opcode | (rd.code() << kRdShift) | (frm << kFunct3Shift) | |
| 186 |
(rs1.code() << kRs1Shift) | (rs2.code() << kRs2Shift) | |
| 187 |
(funct7 << kFunct7Shift); |
| 188 |
emit(instr); |
| 189 |
} |
| 190 |
|
| 191 |
void AssemblerRiscvBase::GenInstrI(uint8_t funct3, BaseOpcode opcode, |
| 192 |
Register rd, Register rs1, int16_t imm12) { |
| 193 |
MOZ_ASSERT(is_uint3(funct3) && (is_uint12(imm12) || is_int12(imm12))); |
| 194 |
Instr instr = opcode | (rd.code() << kRdShift) | (funct3 << kFunct3Shift) | |
| 195 |
(rs1.code() << kRs1Shift) | (imm12 << kImm12Shift); |
| 196 |
emit(instr); |
| 197 |
} |
| 198 |
|
| 199 |
void AssemblerRiscvBase::GenInstrI(uint8_t funct3, BaseOpcode opcode, |
| 200 |
FPURegister rd, Register rs1, |
| 201 |
int16_t imm12) { |
| 202 |
MOZ_ASSERT(is_uint3(funct3) && (is_uint12(imm12) || is_int12(imm12))); |
| 203 |
Instr instr = opcode | (rd.code() << kRdShift) | (funct3 << kFunct3Shift) | |
| 204 |
(rs1.code() << kRs1Shift) | (imm12 << kImm12Shift); |
| 205 |
emit(instr); |
| 206 |
} |
| 207 |
|
| 208 |
void AssemblerRiscvBase::GenInstrIShift(bool arithshift, uint8_t funct3, |
| 209 |
BaseOpcode opcode, Register rd, |
| 210 |
Register rs1, uint8_t shamt) { |
| 211 |
MOZ_ASSERT(is_uint3(funct3) && is_uint6(shamt)); |
| 212 |
Instr instr = opcode | (rd.code() << kRdShift) | (funct3 << kFunct3Shift) | |
| 213 |
(rs1.code() << kRs1Shift) | (shamt << kShamtShift) | |
| 214 |
(arithshift << kArithShiftShift); |
| 215 |
emit(instr); |
| 216 |
} |
| 217 |
|
| 218 |
void AssemblerRiscvBase::GenInstrIShiftW(bool arithshift, uint8_t funct3, |
| 219 |
BaseOpcode opcode, Register rd, |
| 220 |
Register rs1, uint8_t shamt) { |
| 221 |
MOZ_ASSERT(is_uint3(funct3) && is_uint5(shamt)); |
| 222 |
Instr instr = opcode | (rd.code() << kRdShift) | (funct3 << kFunct3Shift) | |
| 223 |
(rs1.code() << kRs1Shift) | (shamt << kShamtWShift) | |
| 224 |
(arithshift << kArithShiftShift); |
| 225 |
emit(instr); |
| 226 |
} |
| 227 |
|
| 228 |
void AssemblerRiscvBase::GenInstrS(uint8_t funct3, BaseOpcode opcode, |
| 229 |
Register rs1, Register rs2, int16_t imm12) { |
| 230 |
MOZ_ASSERT(is_uint3(funct3) && is_int12(imm12)); |
| 231 |
Instr instr = opcode | ((imm12 & 0x1f) << 7) | // bits 4-0 |
| 232 |
(funct3 << kFunct3Shift) | (rs1.code() << kRs1Shift) | |
| 233 |
(rs2.code() << kRs2Shift) | |
| 234 |
((imm12 & 0xfe0) << 20); // bits 11-5 |
| 235 |
emit(instr); |
| 236 |
} |
| 237 |
|
| 238 |
void AssemblerRiscvBase::GenInstrS(uint8_t funct3, BaseOpcode opcode, |
| 239 |
Register rs1, FPURegister rs2, |
| 240 |
int16_t imm12) { |
| 241 |
MOZ_ASSERT(is_uint3(funct3) && is_int12(imm12)); |
| 242 |
Instr instr = opcode | ((imm12 & 0x1f) << 7) | // bits 4-0 |
| 243 |
(funct3 << kFunct3Shift) | (rs1.code() << kRs1Shift) | |
| 244 |
(rs2.code() << kRs2Shift) | |
| 245 |
((imm12 & 0xfe0) << 20); // bits 11-5 |
| 246 |
emit(instr); |
| 247 |
} |
| 248 |
|
| 249 |
void AssemblerRiscvBase::GenInstrB(uint8_t funct3, BaseOpcode opcode, |
| 250 |
Register rs1, Register rs2, int16_t imm13) { |
| 251 |
MOZ_ASSERT(is_uint3(funct3) && is_int13(imm13) && ((imm13 & 1) == 0)); |
| 252 |
Instr instr = opcode | ((imm13 & 0x800) >> 4) | // bit 11 |
| 253 |
((imm13 & 0x1e) << 7) | // bits 4-1 |
| 254 |
(funct3 << kFunct3Shift) | (rs1.code() << kRs1Shift) | |
| 255 |
(rs2.code() << kRs2Shift) | |
| 256 |
((imm13 & 0x7e0) << 20) | // bits 10-5 |
| 257 |
((imm13 & 0x1000) << 19); // bit 12 |
| 258 |
emit(instr); |
| 259 |
} |
| 260 |
|
| 261 |
void AssemblerRiscvBase::GenInstrU(BaseOpcode opcode, Register rd, |
| 262 |
int32_t imm20) { |
| 263 |
MOZ_ASSERT((is_int20(imm20) || is_uint20(imm20))); |
| 264 |
Instr instr = opcode | (rd.code() << kRdShift) | (imm20 << kImm20Shift); |
| 265 |
emit(instr); |
| 266 |
} |
| 267 |
|
| 268 |
void AssemblerRiscvBase::GenInstrJ(BaseOpcode opcode, Register rd, |
| 269 |
int32_t imm21) { |
| 270 |
MOZ_ASSERT(is_int21(imm21) && ((imm21 & 1) == 0)); |
| 271 |
Instr instr = opcode | (rd.code() << kRdShift) | |
| 272 |
(imm21 & 0xff000) | // bits 19-12 |
| 273 |
((imm21 & 0x800) << 9) | // bit 11 |
| 274 |
((imm21 & 0x7fe) << 20) | // bits 10-1 |
| 275 |
((imm21 & 0x100000) << 11); // bit 20 |
| 276 |
emit(instr); |
| 277 |
} |
| 278 |
|
| 279 |
void AssemblerRiscvBase::GenInstrCR(uint8_t funct4, BaseOpcode opcode, |
| 280 |
Register rd, Register rs2) { |
| 281 |
MOZ_ASSERT(is_uint4(funct4)); |
| 282 |
ShortInstr instr = opcode | (rs2.code() << kRvcRs2Shift) | |
| 283 |
(rd.code() << kRvcRdShift) | (funct4 << kRvcFunct4Shift); |
| 284 |
emit(instr); |
| 285 |
} |
| 286 |
|
| 287 |
void AssemblerRiscvBase::GenInstrCA(uint8_t funct6, BaseOpcode opcode, |
| 288 |
Register rd, uint8_t funct, Register rs2) { |
| 289 |
MOZ_ASSERT(is_uint6(funct6) && is_uint2(funct)); |
| 290 |
ShortInstr instr = opcode | ((rs2.code() & 0x7) << kRvcRs2sShift) | |
| 291 |
((rd.code() & 0x7) << kRvcRs1sShift) | |
| 292 |
(funct6 << kRvcFunct6Shift) | (funct << kRvcFunct2Shift); |
| 293 |
emit(instr); |
| 294 |
} |
| 295 |
|
| 296 |
void AssemblerRiscvBase::GenInstrCI(uint8_t funct3, BaseOpcode opcode, |
| 297 |
Register rd, int8_t imm6) { |
| 298 |
MOZ_ASSERT(is_uint3(funct3) && is_int6(imm6)); |
| 299 |
ShortInstr instr = opcode | ((imm6 & 0x1f) << 2) | |
| 300 |
(rd.code() << kRvcRdShift) | ((imm6 & 0x20) << 7) | |
| 301 |
(funct3 << kRvcFunct3Shift); |
| 302 |
emit(instr); |
| 303 |
} |
| 304 |
|
| 305 |
void AssemblerRiscvBase::GenInstrCIU(uint8_t funct3, BaseOpcode opcode, |
| 306 |
Register rd, uint8_t uimm6) { |
| 307 |
MOZ_ASSERT(is_uint3(funct3) && is_uint6(uimm6)); |
| 308 |
ShortInstr instr = opcode | ((uimm6 & 0x1f) << 2) | |
| 309 |
(rd.code() << kRvcRdShift) | ((uimm6 & 0x20) << 7) | |
| 310 |
(funct3 << kRvcFunct3Shift); |
| 311 |
emit(instr); |
| 312 |
} |
| 313 |
|
| 314 |
void AssemblerRiscvBase::GenInstrCIU(uint8_t funct3, BaseOpcode opcode, |
| 315 |
FPURegister rd, uint8_t uimm6) { |
| 316 |
MOZ_ASSERT(is_uint3(funct3) && is_uint6(uimm6)); |
| 317 |
ShortInstr instr = opcode | ((uimm6 & 0x1f) << 2) | |
| 318 |
(rd.code() << kRvcRdShift) | ((uimm6 & 0x20) << 7) | |
| 319 |
(funct3 << kRvcFunct3Shift); |
| 320 |
emit(instr); |
| 321 |
} |
| 322 |
|
| 323 |
void AssemblerRiscvBase::GenInstrCIW(uint8_t funct3, BaseOpcode opcode, |
| 324 |
Register rd, uint8_t uimm8) { |
| 325 |
MOZ_ASSERT(is_uint3(funct3) && is_uint8(uimm8)); |
| 326 |
ShortInstr instr = opcode | ((uimm8) << 5) | |
| 327 |
((rd.code() & 0x7) << kRvcRs2sShift) | |
| 328 |
(funct3 << kRvcFunct3Shift); |
| 329 |
emit(instr); |
| 330 |
} |
| 331 |
|
| 332 |
void AssemblerRiscvBase::GenInstrCSS(uint8_t funct3, BaseOpcode opcode, |
| 333 |
Register rs2, uint8_t uimm6) { |
| 334 |
MOZ_ASSERT(is_uint3(funct3) && is_uint6(uimm6)); |
| 335 |
ShortInstr instr = opcode | (uimm6 << 7) | (rs2.code() << kRvcRs2Shift) | |
| 336 |
(funct3 << kRvcFunct3Shift); |
| 337 |
emit(instr); |
| 338 |
} |
| 339 |
|
| 340 |
void AssemblerRiscvBase::GenInstrCSS(uint8_t funct3, BaseOpcode opcode, |
| 341 |
FPURegister rs2, uint8_t uimm6) { |
| 342 |
MOZ_ASSERT(is_uint3(funct3) && is_uint6(uimm6)); |
| 343 |
ShortInstr instr = opcode | (uimm6 << 7) | (rs2.code() << kRvcRs2Shift) | |
| 344 |
(funct3 << kRvcFunct3Shift); |
| 345 |
emit(instr); |
| 346 |
} |
| 347 |
|
| 348 |
void AssemblerRiscvBase::GenInstrCL(uint8_t funct3, BaseOpcode opcode, |
| 349 |
Register rd, Register rs1, uint8_t uimm5) { |
| 350 |
MOZ_ASSERT(is_uint3(funct3) && is_uint5(uimm5)); |
| 351 |
ShortInstr instr = opcode | ((uimm5 & 0x3) << 5) | |
| 352 |
((rd.code() & 0x7) << kRvcRs2sShift) | |
| 353 |
((uimm5 & 0x1c) << 8) | (funct3 << kRvcFunct3Shift) | |
| 354 |
((rs1.code() & 0x7) << kRvcRs1sShift); |
| 355 |
emit(instr); |
| 356 |
} |
| 357 |
|
| 358 |
void AssemblerRiscvBase::GenInstrCL(uint8_t funct3, BaseOpcode opcode, |
| 359 |
FPURegister rd, Register rs1, |
| 360 |
uint8_t uimm5) { |
| 361 |
MOZ_ASSERT(is_uint3(funct3) && is_uint5(uimm5)); |
| 362 |
ShortInstr instr = opcode | ((uimm5 & 0x3) << 5) | |
| 363 |
((rd.code() & 0x7) << kRvcRs2sShift) | |
| 364 |
((uimm5 & 0x1c) << 8) | (funct3 << kRvcFunct3Shift) | |
| 365 |
((rs1.code() & 0x7) << kRvcRs1sShift); |
| 366 |
emit(instr); |
| 367 |
} |
| 368 |
void AssemblerRiscvBase::GenInstrCJ(uint8_t funct3, BaseOpcode opcode, |
| 369 |
uint16_t uint11) { |
| 370 |
MOZ_ASSERT(is_uint11(uint11)); |
| 371 |
ShortInstr instr = opcode | (funct3 << kRvcFunct3Shift) | (uint11 << 2); |
| 372 |
emit(instr); |
| 373 |
} |
| 374 |
|
| 375 |
void AssemblerRiscvBase::GenInstrCS(uint8_t funct3, BaseOpcode opcode, |
| 376 |
Register rs2, Register rs1, uint8_t uimm5) { |
| 377 |
MOZ_ASSERT(is_uint3(funct3) && is_uint5(uimm5)); |
| 378 |
ShortInstr instr = opcode | ((uimm5 & 0x3) << 5) | |
| 379 |
((rs2.code() & 0x7) << kRvcRs2sShift) | |
| 380 |
((uimm5 & 0x1c) << 8) | (funct3 << kRvcFunct3Shift) | |
| 381 |
((rs1.code() & 0x7) << kRvcRs1sShift); |
| 382 |
emit(instr); |
| 383 |
} |
| 384 |
|
| 385 |
void AssemblerRiscvBase::GenInstrCS(uint8_t funct3, BaseOpcode opcode, |
| 386 |
FPURegister rs2, Register rs1, |
| 387 |
uint8_t uimm5) { |
| 388 |
MOZ_ASSERT(is_uint3(funct3) && is_uint5(uimm5)); |
| 389 |
ShortInstr instr = opcode | ((uimm5 & 0x3) << 5) | |
| 390 |
((rs2.code() & 0x7) << kRvcRs2sShift) | |
| 391 |
((uimm5 & 0x1c) << 8) | (funct3 << kRvcFunct3Shift) | |
| 392 |
((rs1.code() & 0x7) << kRvcRs1sShift); |
| 393 |
emit(instr); |
| 394 |
} |
| 395 |
|
| 396 |
void AssemblerRiscvBase::GenInstrCB(uint8_t funct3, BaseOpcode opcode, |
| 397 |
Register rs1, uint8_t uimm8) { |
| 398 |
MOZ_ASSERT(is_uint3(funct3) && is_uint8(uimm8)); |
| 399 |
ShortInstr instr = opcode | ((uimm8 & 0x1f) << 2) | ((uimm8 & 0xe0) << 5) | |
| 400 |
((rs1.code() & 0x7) << kRvcRs1sShift) | |
| 401 |
(funct3 << kRvcFunct3Shift); |
| 402 |
emit(instr); |
| 403 |
} |
| 404 |
|
| 405 |
void AssemblerRiscvBase::GenInstrCBA(uint8_t funct3, uint8_t funct2, |
| 406 |
BaseOpcode opcode, Register rs1, |
| 407 |
int8_t imm6) { |
| 408 |
MOZ_ASSERT(is_uint3(funct3) && is_uint2(funct2) && is_int6(imm6)); |
| 409 |
ShortInstr instr = opcode | ((imm6 & 0x1f) << 2) | ((imm6 & 0x20) << 7) | |
| 410 |
((rs1.code() & 0x7) << kRvcRs1sShift) | |
| 411 |
(funct3 << kRvcFunct3Shift) | (funct2 << 10); |
| 412 |
emit(instr); |
| 413 |
} |
| 414 |
// ----- Instruction class templates match those in the compiler |
| 415 |
|
| 416 |
void AssemblerRiscvBase::GenInstrBranchCC_rri(uint8_t funct3, Register rs1, |
| 417 |
Register rs2, int16_t imm13) { |
| 418 |
GenInstrB(funct3, BRANCH, rs1, rs2, imm13); |
| 419 |
} |
| 420 |
|
| 421 |
void AssemblerRiscvBase::GenInstrLoad_ri(uint8_t funct3, Register rd, |
| 422 |
Register rs1, int16_t imm12) { |
| 423 |
GenInstrI(funct3, LOAD, rd, rs1, imm12); |
| 424 |
} |
| 425 |
|
| 426 |
void AssemblerRiscvBase::GenInstrStore_rri(uint8_t funct3, Register rs1, |
| 427 |
Register rs2, int16_t imm12) { |
| 428 |
GenInstrS(funct3, STORE, rs1, rs2, imm12); |
| 429 |
} |
| 430 |
|
| 431 |
void AssemblerRiscvBase::GenInstrALU_ri(uint8_t funct3, Register rd, |
| 432 |
Register rs1, int16_t imm12) { |
| 433 |
GenInstrI(funct3, OP_IMM, rd, rs1, imm12); |
| 434 |
} |
| 435 |
|
| 436 |
void AssemblerRiscvBase::GenInstrShift_ri(bool arithshift, uint8_t funct3, |
| 437 |
Register rd, Register rs1, |
| 438 |
uint8_t shamt) { |
| 439 |
MOZ_ASSERT(is_uint6(shamt)); |
| 440 |
GenInstrI(funct3, OP_IMM, rd, rs1, (arithshift << 10) | shamt); |
| 441 |
} |
| 442 |
|
| 443 |
void AssemblerRiscvBase::GenInstrALU_rr(uint8_t funct7, uint8_t funct3, |
| 444 |
Register rd, Register rs1, |
| 445 |
Register rs2) { |
| 446 |
GenInstrR(funct7, funct3, OP, rd, rs1, rs2); |
| 447 |
} |
| 448 |
|
| 449 |
void AssemblerRiscvBase::GenInstrCSR_ir(uint8_t funct3, Register rd, |
| 450 |
ControlStatusReg csr, Register rs1) { |
| 451 |
GenInstrI(funct3, SYSTEM, rd, rs1, csr); |
| 452 |
} |
| 453 |
|
| 454 |
void AssemblerRiscvBase::GenInstrCSR_ii(uint8_t funct3, Register rd, |
| 455 |
ControlStatusReg csr, uint8_t imm5) { |
| 456 |
GenInstrI(funct3, SYSTEM, rd, ToRegister(imm5), csr); |
| 457 |
} |
| 458 |
|
| 459 |
void AssemblerRiscvBase::GenInstrShiftW_ri(bool arithshift, uint8_t funct3, |
| 460 |
Register rd, Register rs1, |
| 461 |
uint8_t shamt) { |
| 462 |
GenInstrIShiftW(arithshift, funct3, OP_IMM_32, rd, rs1, shamt); |
| 463 |
} |
| 464 |
|
| 465 |
void AssemblerRiscvBase::GenInstrALUW_rr(uint8_t funct7, uint8_t funct3, |
| 466 |
Register rd, Register rs1, |
| 467 |
Register rs2) { |
| 468 |
GenInstrR(funct7, funct3, OP_32, rd, rs1, rs2); |
| 469 |
} |
| 470 |
|
| 471 |
void AssemblerRiscvBase::GenInstrPriv(uint8_t funct7, Register rs1, |
| 472 |
Register rs2) { |
| 473 |
GenInstrR(funct7, 0b000, SYSTEM, ToRegister(0UL), rs1, rs2); |
| 474 |
} |
| 475 |
|
| 476 |
void AssemblerRiscvBase::GenInstrLoadFP_ri(uint8_t funct3, FPURegister rd, |
| 477 |
Register rs1, int16_t imm12) { |
| 478 |
GenInstrI(funct3, LOAD_FP, rd, rs1, imm12); |
| 479 |
} |
| 480 |
|
| 481 |
void AssemblerRiscvBase::GenInstrStoreFP_rri(uint8_t funct3, Register rs1, |
| 482 |
FPURegister rs2, int16_t imm12) { |
| 483 |
GenInstrS(funct3, STORE_FP, rs1, rs2, imm12); |
| 484 |
} |
| 485 |
|
| 486 |
void AssemblerRiscvBase::GenInstrALUFP_rr(uint8_t funct7, uint8_t funct3, |
| 487 |
FPURegister rd, FPURegister rs1, |
| 488 |
FPURegister rs2) { |
| 489 |
GenInstrR(funct7, funct3, OP_FP, rd, rs1, rs2); |
| 490 |
} |
| 491 |
|
| 492 |
void AssemblerRiscvBase::GenInstrALUFP_rr(uint8_t funct7, uint8_t funct3, |
| 493 |
FPURegister rd, Register rs1, |
| 494 |
Register rs2) { |
| 495 |
GenInstrR(funct7, funct3, OP_FP, rd, rs1, rs2); |
| 496 |
} |
| 497 |
|
| 498 |
void AssemblerRiscvBase::GenInstrALUFP_rr(uint8_t funct7, uint8_t funct3, |
| 499 |
FPURegister rd, FPURegister rs1, |
| 500 |
Register rs2) { |
| 501 |
GenInstrR(funct7, funct3, OP_FP, rd, rs1, rs2); |
| 502 |
} |
| 503 |
|
| 504 |
void AssemblerRiscvBase::GenInstrALUFP_rr(uint8_t funct7, uint8_t funct3, |
| 505 |
Register rd, FPURegister rs1, |
| 506 |
Register rs2) { |
| 507 |
GenInstrR(funct7, funct3, OP_FP, rd, rs1, rs2); |
| 508 |
} |
| 509 |
|
| 510 |
void AssemblerRiscvBase::GenInstrALUFP_rr(uint8_t funct7, uint8_t funct3, |
| 511 |
Register rd, FPURegister rs1, |
| 512 |
FPURegister rs2) { |
| 513 |
GenInstrR(funct7, funct3, OP_FP, rd, rs1, rs2); |
| 514 |
} |
| 515 |
|
| 516 |
} // namespace jit |
| 517 |
} // namespace js |