| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#ifndef jit_loong64_Assembler_loong64_h |
| 8 |
#define jit_loong64_Assembler_loong64_h |
| 9 |
|
| 10 |
#include "mozilla/Sprintf.h" |
| 11 |
#include <iterator> |
| 12 |
|
| 13 |
#include "jit/CompactBuffer.h" |
| 14 |
#include "jit/JitCode.h" |
| 15 |
#include "jit/JitSpewer.h" |
| 16 |
#include "jit/loong64/Architecture-loong64.h" |
| 17 |
#include "jit/shared/Assembler-shared.h" |
| 18 |
#include "jit/shared/Disassembler-shared.h" |
| 19 |
#include "jit/shared/IonAssemblerBuffer.h" |
| 20 |
#include "wasm/WasmTypeDecls.h" |
| 21 |
|
| 22 |
namespace js { |
| 23 |
namespace jit { |
| 24 |
|
| 25 |
static constexpr Register zero{Registers::zero}; |
| 26 |
static constexpr Register ra{Registers::ra}; |
| 27 |
static constexpr Register tp{Registers::tp}; |
| 28 |
static constexpr Register sp{Registers::sp}; |
| 29 |
static constexpr Register a0{Registers::a0}; |
| 30 |
static constexpr Register a1{Registers::a1}; |
| 31 |
static constexpr Register a2{Registers::a2}; |
| 32 |
static constexpr Register a3{Registers::a3}; |
| 33 |
static constexpr Register a4{Registers::a4}; |
| 34 |
static constexpr Register a5{Registers::a5}; |
| 35 |
static constexpr Register a6{Registers::a6}; |
| 36 |
static constexpr Register a7{Registers::a7}; |
| 37 |
static constexpr Register t0{Registers::t0}; |
| 38 |
static constexpr Register t1{Registers::t1}; |
| 39 |
static constexpr Register t2{Registers::t2}; |
| 40 |
static constexpr Register t3{Registers::t3}; |
| 41 |
static constexpr Register t4{Registers::t4}; |
| 42 |
static constexpr Register t5{Registers::t5}; |
| 43 |
static constexpr Register t6{Registers::t6}; |
| 44 |
static constexpr Register t7{Registers::t7}; |
| 45 |
static constexpr Register t8{Registers::t8}; |
| 46 |
static constexpr Register rx{Registers::rx}; |
| 47 |
static constexpr Register fp{Registers::fp}; |
| 48 |
static constexpr Register s0{Registers::s0}; |
| 49 |
static constexpr Register s1{Registers::s1}; |
| 50 |
static constexpr Register s2{Registers::s2}; |
| 51 |
static constexpr Register s3{Registers::s3}; |
| 52 |
static constexpr Register s4{Registers::s4}; |
| 53 |
static constexpr Register s5{Registers::s5}; |
| 54 |
static constexpr Register s6{Registers::s6}; |
| 55 |
static constexpr Register s7{Registers::s7}; |
| 56 |
static constexpr Register s8{Registers::s8}; |
| 57 |
|
| 58 |
static constexpr FloatRegister f0{FloatRegisters::f0, FloatRegisters::Double}; |
| 59 |
static constexpr FloatRegister f1{FloatRegisters::f1, FloatRegisters::Double}; |
| 60 |
static constexpr FloatRegister f2{FloatRegisters::f2, FloatRegisters::Double}; |
| 61 |
static constexpr FloatRegister f3{FloatRegisters::f3, FloatRegisters::Double}; |
| 62 |
static constexpr FloatRegister f4{FloatRegisters::f4, FloatRegisters::Double}; |
| 63 |
static constexpr FloatRegister f5{FloatRegisters::f5, FloatRegisters::Double}; |
| 64 |
static constexpr FloatRegister f6{FloatRegisters::f6, FloatRegisters::Double}; |
| 65 |
static constexpr FloatRegister f7{FloatRegisters::f7, FloatRegisters::Double}; |
| 66 |
static constexpr FloatRegister f8{FloatRegisters::f8, FloatRegisters::Double}; |
| 67 |
static constexpr FloatRegister f9{FloatRegisters::f9, FloatRegisters::Double}; |
| 68 |
static constexpr FloatRegister f10{FloatRegisters::f10, FloatRegisters::Double}; |
| 69 |
static constexpr FloatRegister f11{FloatRegisters::f11, FloatRegisters::Double}; |
| 70 |
static constexpr FloatRegister f12{FloatRegisters::f12, FloatRegisters::Double}; |
| 71 |
static constexpr FloatRegister f13{FloatRegisters::f13, FloatRegisters::Double}; |
| 72 |
static constexpr FloatRegister f14{FloatRegisters::f14, FloatRegisters::Double}; |
| 73 |
static constexpr FloatRegister f15{FloatRegisters::f15, FloatRegisters::Double}; |
| 74 |
static constexpr FloatRegister f16{FloatRegisters::f16, FloatRegisters::Double}; |
| 75 |
static constexpr FloatRegister f17{FloatRegisters::f17, FloatRegisters::Double}; |
| 76 |
static constexpr FloatRegister f18{FloatRegisters::f18, FloatRegisters::Double}; |
| 77 |
static constexpr FloatRegister f19{FloatRegisters::f19, FloatRegisters::Double}; |
| 78 |
static constexpr FloatRegister f20{FloatRegisters::f20, FloatRegisters::Double}; |
| 79 |
static constexpr FloatRegister f21{FloatRegisters::f21, FloatRegisters::Double}; |
| 80 |
static constexpr FloatRegister f22{FloatRegisters::f22, FloatRegisters::Double}; |
| 81 |
static constexpr FloatRegister f23{FloatRegisters::f23, FloatRegisters::Double}; |
| 82 |
static constexpr FloatRegister f24{FloatRegisters::f24, FloatRegisters::Double}; |
| 83 |
static constexpr FloatRegister f25{FloatRegisters::f25, FloatRegisters::Double}; |
| 84 |
static constexpr FloatRegister f26{FloatRegisters::f26, FloatRegisters::Double}; |
| 85 |
static constexpr FloatRegister f27{FloatRegisters::f27, FloatRegisters::Double}; |
| 86 |
static constexpr FloatRegister f28{FloatRegisters::f28, FloatRegisters::Double}; |
| 87 |
static constexpr FloatRegister f29{FloatRegisters::f29, FloatRegisters::Double}; |
| 88 |
static constexpr FloatRegister f30{FloatRegisters::f30, FloatRegisters::Double}; |
| 89 |
static constexpr FloatRegister f31{FloatRegisters::f31, FloatRegisters::Double}; |
| 90 |
|
| 91 |
static constexpr Register InvalidReg{Registers::Invalid}; |
| 92 |
static constexpr FloatRegister InvalidFloatReg; |
| 93 |
|
| 94 |
static constexpr Register StackPointer = sp; |
| 95 |
static constexpr Register FramePointer = fp; |
| 96 |
static constexpr Register ReturnReg = a0; |
| 97 |
static constexpr Register64 ReturnReg64(ReturnReg); |
| 98 |
static constexpr FloatRegister ReturnFloat32Reg{FloatRegisters::f0, |
| 99 |
FloatRegisters::Single}; |
| 100 |
static constexpr FloatRegister ReturnDoubleReg = f0; |
| 101 |
static constexpr FloatRegister ReturnSimd128Reg = InvalidFloatReg; |
| 102 |
|
| 103 |
static constexpr Register ScratchRegister = t7; |
| 104 |
static constexpr Register SecondScratchReg = t8; |
| 105 |
|
| 106 |
// Helper classes for ScratchRegister usage. Asserts that only one piece |
| 107 |
// of code thinks it has exclusive ownership of each scratch register. |
| 108 |
struct ScratchRegisterScope : public AutoRegisterScope { |
| 109 |
explicit ScratchRegisterScope(MacroAssembler& masm) |
| 110 |
: AutoRegisterScope(masm, ScratchRegister) {} |
| 111 |
}; |
| 112 |
|
| 113 |
struct SecondScratchRegisterScope : public AutoRegisterScope { |
| 114 |
explicit SecondScratchRegisterScope(MacroAssembler& masm) |
| 115 |
: AutoRegisterScope(masm, SecondScratchReg) {} |
| 116 |
}; |
| 117 |
|
| 118 |
static constexpr FloatRegister ScratchFloat32Reg{FloatRegisters::f23, |
| 119 |
FloatRegisters::Single}; |
| 120 |
static constexpr FloatRegister ScratchDoubleReg = f23; |
| 121 |
static constexpr FloatRegister ScratchSimd128Reg = InvalidFloatReg; |
| 122 |
|
| 123 |
struct ScratchFloat32Scope : public AutoFloatRegisterScope { |
| 124 |
explicit ScratchFloat32Scope(MacroAssembler& masm) |
| 125 |
: AutoFloatRegisterScope(masm, ScratchFloat32Reg) {} |
| 126 |
}; |
| 127 |
|
| 128 |
struct ScratchDoubleScope : public AutoFloatRegisterScope { |
| 129 |
explicit ScratchDoubleScope(MacroAssembler& masm) |
| 130 |
: AutoFloatRegisterScope(masm, ScratchDoubleReg) {} |
| 131 |
}; |
| 132 |
|
| 133 |
// Use arg reg from EnterJIT function as OsrFrameReg. |
| 134 |
static constexpr Register OsrFrameReg = a3; |
| 135 |
static constexpr Register PreBarrierReg = a1; |
| 136 |
static constexpr Register InterpreterPCReg = t0; |
| 137 |
static constexpr Register CallTempReg0 = t0; |
| 138 |
static constexpr Register CallTempReg1 = t1; |
| 139 |
static constexpr Register CallTempReg2 = t2; |
| 140 |
static constexpr Register CallTempReg3 = t3; |
| 141 |
static constexpr Register CallTempReg4 = t4; |
| 142 |
static constexpr Register CallTempReg5 = t5; |
| 143 |
static constexpr Register CallTempNonArgRegs[] = {t0, t1, t2, t3}; |
| 144 |
static const uint32_t NumCallTempNonArgRegs = std::size(CallTempNonArgRegs); |
| 145 |
|
| 146 |
static constexpr Register IntArgReg0 = a0; |
| 147 |
static constexpr Register IntArgReg1 = a1; |
| 148 |
static constexpr Register IntArgReg2 = a2; |
| 149 |
static constexpr Register IntArgReg3 = a3; |
| 150 |
static constexpr Register IntArgReg4 = a4; |
| 151 |
static constexpr Register IntArgReg5 = a5; |
| 152 |
static constexpr Register IntArgReg6 = a6; |
| 153 |
static constexpr Register IntArgReg7 = a7; |
| 154 |
static constexpr Register HeapReg = s7; |
| 155 |
|
| 156 |
// Registers used by RegExpMatcher and RegExpExecMatch stubs (do not use |
| 157 |
// JSReturnOperand). |
| 158 |
static constexpr Register RegExpMatcherRegExpReg = CallTempReg0; |
| 159 |
static constexpr Register RegExpMatcherStringReg = CallTempReg1; |
| 160 |
static constexpr Register RegExpMatcherLastIndexReg = CallTempReg2; |
| 161 |
|
| 162 |
// Registers used by RegExpExecTest stub (do not use ReturnReg). |
| 163 |
static constexpr Register RegExpExecTestRegExpReg = CallTempReg0; |
| 164 |
static constexpr Register RegExpExecTestStringReg = CallTempReg1; |
| 165 |
|
| 166 |
// Registers used by RegExpSearcher stub (do not use ReturnReg). |
| 167 |
static constexpr Register RegExpSearcherRegExpReg = CallTempReg0; |
| 168 |
static constexpr Register RegExpSearcherStringReg = CallTempReg1; |
| 169 |
static constexpr Register RegExpSearcherLastIndexReg = CallTempReg2; |
| 170 |
|
| 171 |
static constexpr Register JSReturnReg_Type = a3; |
| 172 |
static constexpr Register JSReturnReg_Data = a2; |
| 173 |
static constexpr Register JSReturnReg = a2; |
| 174 |
static constexpr ValueOperand JSReturnOperand = ValueOperand(JSReturnReg); |
| 175 |
|
| 176 |
// These registers may be volatile or nonvolatile. |
| 177 |
static constexpr Register ABINonArgReg0 = t0; |
| 178 |
static constexpr Register ABINonArgReg1 = t1; |
| 179 |
static constexpr Register ABINonArgReg2 = t2; |
| 180 |
static constexpr Register ABINonArgReg3 = t3; |
| 181 |
|
| 182 |
// These registers may be volatile or nonvolatile. |
| 183 |
// Note: these three registers are all guaranteed to be different |
| 184 |
static constexpr Register ABINonArgReturnReg0 = t0; |
| 185 |
static constexpr Register ABINonArgReturnReg1 = t1; |
| 186 |
static constexpr Register ABINonVolatileReg = s0; |
| 187 |
|
| 188 |
// This register is guaranteed to be clobberable during the prologue and |
| 189 |
// epilogue of an ABI call which must preserve both ABI argument, return |
| 190 |
// and non-volatile registers. |
| 191 |
static constexpr Register ABINonArgReturnVolatileReg = ra; |
| 192 |
|
| 193 |
// This register may be volatile or nonvolatile. |
| 194 |
// Avoid f23 which is the scratch register. |
| 195 |
static constexpr FloatRegister ABINonArgDoubleReg{FloatRegisters::f21, |
| 196 |
FloatRegisters::Double}; |
| 197 |
|
| 198 |
// Instance pointer argument register for WebAssembly functions. This must not |
| 199 |
// alias any other register used for passing function arguments or return |
| 200 |
// values. Preserved by WebAssembly functions. Must be nonvolatile. |
| 201 |
static constexpr Register InstanceReg = s4; |
| 202 |
|
| 203 |
// Registers used for wasm table calls. These registers must be disjoint |
| 204 |
// from the ABI argument registers, InstanceReg and each other. |
| 205 |
static constexpr Register WasmTableCallScratchReg0 = ABINonArgReg0; |
| 206 |
static constexpr Register WasmTableCallScratchReg1 = ABINonArgReg1; |
| 207 |
static constexpr Register WasmTableCallSigReg = ABINonArgReg2; |
| 208 |
static constexpr Register WasmTableCallIndexReg = ABINonArgReg3; |
| 209 |
|
| 210 |
// Registers used for ref calls. |
| 211 |
static constexpr Register WasmCallRefCallScratchReg0 = ABINonArgReg0; |
| 212 |
static constexpr Register WasmCallRefCallScratchReg1 = ABINonArgReg1; |
| 213 |
static constexpr Register WasmCallRefCallScratchReg2 = ABINonArgReg2; |
| 214 |
static constexpr Register WasmCallRefReg = ABINonArgReg3; |
| 215 |
|
| 216 |
// Registers used for wasm tail calls operations. |
| 217 |
static constexpr Register WasmTailCallInstanceScratchReg = ABINonArgReg1; |
| 218 |
static constexpr Register WasmTailCallRAScratchReg = ra; |
| 219 |
static constexpr Register WasmTailCallFPScratchReg = ABINonArgReg3; |
| 220 |
|
| 221 |
// Register used as a scratch along the return path in the fast js -> wasm stub |
| 222 |
// code. This must not overlap ReturnReg, JSReturnOperand, or InstanceReg. |
| 223 |
// It must be a volatile register. |
| 224 |
static constexpr Register WasmJitEntryReturnScratch = t1; |
| 225 |
|
| 226 |
static constexpr uint32_t ABIStackAlignment = 16; |
| 227 |
static constexpr uint32_t CodeAlignment = 16; |
| 228 |
static constexpr uint32_t JitStackAlignment = 16; |
| 229 |
|
| 230 |
static constexpr uint32_t JitStackValueAlignment = |
| 231 |
JitStackAlignment / sizeof(Value); |
| 232 |
static_assert(JitStackAlignment % sizeof(Value) == 0 && |
| 233 |
JitStackValueAlignment >= 1, |
| 234 |
"Stack alignment should be a non-zero multiple of sizeof(Value)"); |
| 235 |
|
| 236 |
// TODO(loong64): this is just a filler to prevent a build failure. The |
| 237 |
// LoongArch SIMD alignment requirements still need to be explored. |
| 238 |
static constexpr uint32_t SimdMemoryAlignment = 16; |
| 239 |
|
| 240 |
static_assert(CodeAlignment % SimdMemoryAlignment == 0, |
| 241 |
"Code alignment should be larger than any of the alignments " |
| 242 |
"which are used for " |
| 243 |
"the constant sections of the code buffer. Thus it should be " |
| 244 |
"larger than the " |
| 245 |
"alignment for SIMD constants."); |
| 246 |
|
| 247 |
static constexpr uint32_t WasmStackAlignment = SimdMemoryAlignment; |
| 248 |
static const uint32_t WasmTrapInstructionLength = 4; |
| 249 |
|
| 250 |
// See comments in wasm::GenerateFunctionPrologue. The difference between these |
| 251 |
// is the size of the largest callable prologue on the platform. |
| 252 |
static constexpr uint32_t WasmCheckedCallEntryOffset = 0u; |
| 253 |
|
| 254 |
static constexpr Scale ScalePointer = TimesEight; |
| 255 |
|
| 256 |
// TODO(loong64): Add LoongArch instruction types description. |
| 257 |
|
| 258 |
// LoongArch instruction encoding constants. |
| 259 |
static const uint32_t RJShift = 5; |
| 260 |
static const uint32_t RJBits = 5; |
| 261 |
static const uint32_t RKShift = 10; |
| 262 |
static const uint32_t RKBits = 5; |
| 263 |
static const uint32_t RDShift = 0; |
| 264 |
static const uint32_t RDBits = 5; |
| 265 |
static const uint32_t FJShift = 5; |
| 266 |
static const uint32_t FJBits = 5; |
| 267 |
static const uint32_t FKShift = 10; |
| 268 |
static const uint32_t FKBits = 5; |
| 269 |
static const uint32_t FDShift = 0; |
| 270 |
static const uint32_t FDBits = 5; |
| 271 |
static const uint32_t FAShift = 15; |
| 272 |
static const uint32_t FABits = 5; |
| 273 |
static const uint32_t CJShift = 5; |
| 274 |
static const uint32_t CJBits = 3; |
| 275 |
static const uint32_t CDShift = 0; |
| 276 |
static const uint32_t CDBits = 3; |
| 277 |
static const uint32_t CAShift = 15; |
| 278 |
static const uint32_t CABits = 3; |
| 279 |
static const uint32_t CONDShift = 15; |
| 280 |
static const uint32_t CONDBits = 5; |
| 281 |
|
| 282 |
static const uint32_t SAShift = 15; |
| 283 |
static const uint32_t SA2Bits = 2; |
| 284 |
static const uint32_t SA3Bits = 3; |
| 285 |
static const uint32_t LSBWShift = 10; |
| 286 |
static const uint32_t LSBWBits = 5; |
| 287 |
static const uint32_t LSBDShift = 10; |
| 288 |
static const uint32_t LSBDBits = 6; |
| 289 |
static const uint32_t MSBWShift = 16; |
| 290 |
static const uint32_t MSBWBits = 5; |
| 291 |
static const uint32_t MSBDShift = 16; |
| 292 |
static const uint32_t MSBDBits = 6; |
| 293 |
static const uint32_t Imm5Shift = 10; |
| 294 |
static const uint32_t Imm5Bits = 5; |
| 295 |
static const uint32_t Imm6Shift = 10; |
| 296 |
static const uint32_t Imm6Bits = 6; |
| 297 |
static const uint32_t Imm12Shift = 10; |
| 298 |
static const uint32_t Imm12Bits = 12; |
| 299 |
static const uint32_t Imm14Shift = 10; |
| 300 |
static const uint32_t Imm14Bits = 14; |
| 301 |
static const uint32_t Imm15Shift = 0; |
| 302 |
static const uint32_t Imm15Bits = 15; |
| 303 |
static const uint32_t Imm16Shift = 10; |
| 304 |
static const uint32_t Imm16Bits = 16; |
| 305 |
static const uint32_t Imm20Shift = 5; |
| 306 |
static const uint32_t Imm20Bits = 20; |
| 307 |
static const uint32_t Imm21Shift = 0; |
| 308 |
static const uint32_t Imm21Bits = 21; |
| 309 |
static const uint32_t Imm26Shift = 0; |
| 310 |
static const uint32_t Imm26Bits = 26; |
| 311 |
static const uint32_t CODEShift = 0; |
| 312 |
static const uint32_t CODEBits = 15; |
| 313 |
static const uint32_t HINTBits = 5; |
| 314 |
|
| 315 |
// LoongArch instruction field bit masks. |
| 316 |
static const uint32_t RJMask = (1 << RJBits) - 1; |
| 317 |
static const uint32_t RKMask = (1 << RKBits) - 1; |
| 318 |
static const uint32_t RDMask = (1 << RDBits) - 1; |
| 319 |
static const uint32_t SA2Mask = (1 << SA2Bits) - 1; |
| 320 |
static const uint32_t SA3Mask = (1 << SA3Bits) - 1; |
| 321 |
static const uint32_t CDMask = (1 << CDBits) - 1; |
| 322 |
static const uint32_t CONDMask = (1 << CONDBits) - 1; |
| 323 |
static const uint32_t HINTMask = (1 << HINTBits) - 1; |
| 324 |
static const uint32_t LSBWMask = (1 << LSBWBits) - 1; |
| 325 |
static const uint32_t LSBDMask = (1 << LSBDBits) - 1; |
| 326 |
static const uint32_t MSBWMask = (1 << MSBWBits) - 1; |
| 327 |
static const uint32_t MSBDMask = (1 << MSBDBits) - 1; |
| 328 |
static const uint32_t CODEMask = (1 << CODEBits) - 1; |
| 329 |
static const uint32_t Imm5Mask = (1 << Imm5Bits) - 1; |
| 330 |
static const uint32_t Imm6Mask = (1 << Imm6Bits) - 1; |
| 331 |
static const uint32_t Imm12Mask = (1 << Imm12Bits) - 1; |
| 332 |
static const uint32_t Imm14Mask = (1 << Imm14Bits) - 1; |
| 333 |
static const uint32_t Imm15Mask = (1 << Imm15Bits) - 1; |
| 334 |
static const uint32_t Imm16Mask = (1 << Imm16Bits) - 1; |
| 335 |
static const uint32_t Imm20Mask = (1 << Imm20Bits) - 1; |
| 336 |
static const uint32_t Imm21Mask = (1 << Imm21Bits) - 1; |
| 337 |
static const uint32_t Imm26Mask = (1 << Imm26Bits) - 1; |
| 338 |
static const uint32_t BOffImm16Mask = ((1 << Imm16Bits) - 1) << Imm16Shift; |
| 339 |
static const uint32_t BOffImm21Mask = ((1 << Imm21Bits) - 1) << Imm21Shift; |
| 340 |
static const uint32_t BOffImm26Mask = ((1 << Imm26Bits) - 1) << Imm26Shift; |
| 341 |
static const uint32_t RegMask = Registers::Total - 1; |
| 342 |
|
| 343 |
// TODO(loong64) Change to syscall? |
| 344 |
static const uint32_t MAX_BREAK_CODE = 1024 - 1; |
| 345 |
static const uint32_t WASM_TRAP = 6; // BRK_OVERFLOW |
| 346 |
|
| 347 |
// TODO(loong64) Change to LoongArch instruction type. |
| 348 |
class Instruction; |
| 349 |
class InstReg; |
| 350 |
class InstImm; |
| 351 |
class InstJump; |
| 352 |
|
| 353 |
uint32_t RJ(Register r); |
| 354 |
uint32_t RK(Register r); |
| 355 |
uint32_t RD(Register r); |
| 356 |
uint32_t FJ(FloatRegister r); |
| 357 |
uint32_t FK(FloatRegister r); |
| 358 |
uint32_t FD(FloatRegister r); |
| 359 |
uint32_t FA(FloatRegister r); |
| 360 |
uint32_t SA2(uint32_t value); |
| 361 |
uint32_t SA2(FloatRegister r); |
| 362 |
uint32_t SA3(uint32_t value); |
| 363 |
uint32_t SA3(FloatRegister r); |
| 364 |
|
| 365 |
Register toRK(Instruction& i); |
| 366 |
Register toRJ(Instruction& i); |
| 367 |
Register toRD(Instruction& i); |
| 368 |
Register toR(Instruction& i); |
| 369 |
|
| 370 |
// LoongArch enums for instruction fields |
| 371 |
enum OpcodeField { |
| 372 |
op_beqz = 0x10U << 26, |
| 373 |
op_bnez = 0x11U << 26, |
| 374 |
op_bcz = 0x12U << 26, // bceqz & bcnez |
| 375 |
op_jirl = 0x13U << 26, |
| 376 |
op_b = 0x14U << 26, |
| 377 |
op_bl = 0x15U << 26, |
| 378 |
op_beq = 0x16U << 26, |
| 379 |
op_bne = 0x17U << 26, |
| 380 |
op_blt = 0x18U << 26, |
| 381 |
op_bge = 0x19U << 26, |
| 382 |
op_bltu = 0x1aU << 26, |
| 383 |
op_bgeu = 0x1bU << 26, |
| 384 |
|
| 385 |
op_addu16i_d = 0x4U << 26, |
| 386 |
|
| 387 |
op_lu12i_w = 0xaU << 25, |
| 388 |
op_lu32i_d = 0xbU << 25, |
| 389 |
op_pcaddi = 0xcU << 25, |
| 390 |
op_pcalau12i = 0xdU << 25, |
| 391 |
op_pcaddu12i = 0xeU << 25, |
| 392 |
op_pcaddu18i = 0xfU << 25, |
| 393 |
op_ll_w = 0x20U << 24, |
| 394 |
op_sc_w = 0x21U << 24, |
| 395 |
op_ll_d = 0x22U << 24, |
| 396 |
op_sc_d = 0x23U << 24, |
| 397 |
op_ldptr_w = 0x24U << 24, |
| 398 |
op_stptr_w = 0x25U << 24, |
| 399 |
op_ldptr_d = 0x26U << 24, |
| 400 |
op_stptr_d = 0x27U << 24, |
| 401 |
op_bstrins_d = 0x2U << 22, |
| 402 |
op_bstrpick_d = 0x3U << 22, |
| 403 |
op_slti = 0x8U << 22, |
| 404 |
op_sltui = 0x9U << 22, |
| 405 |
op_addi_w = 0xaU << 22, |
| 406 |
op_addi_d = 0xbU << 22, |
| 407 |
op_lu52i_d = 0xcU << 22, |
| 408 |
op_andi = 0xdU << 22, |
| 409 |
op_ori = 0xeU << 22, |
| 410 |
op_xori = 0xfU << 22, |
| 411 |
op_ld_b = 0xa0U << 22, |
| 412 |
op_ld_h = 0xa1U << 22, |
| 413 |
op_ld_w = 0xa2U << 22, |
| 414 |
op_ld_d = 0xa3U << 22, |
| 415 |
op_st_b = 0xa4U << 22, |
| 416 |
op_st_h = 0xa5U << 22, |
| 417 |
op_st_w = 0xa6U << 22, |
| 418 |
op_st_d = 0xa7U << 22, |
| 419 |
op_ld_bu = 0xa8U << 22, |
| 420 |
op_ld_hu = 0xa9U << 22, |
| 421 |
op_ld_wu = 0xaaU << 22, |
| 422 |
op_preld = 0xabU << 22, |
| 423 |
op_fld_s = 0xacU << 22, |
| 424 |
op_fst_s = 0xadU << 22, |
| 425 |
op_fld_d = 0xaeU << 22, |
| 426 |
op_fst_d = 0xafU << 22, |
| 427 |
op_bstr_w = 0x3U << 21, // BSTRINS_W & BSTRPICK_W |
| 428 |
op_fmadd_s = 0x81U << 20, |
| 429 |
op_fmadd_d = 0x82U << 20, |
| 430 |
op_fmsub_s = 0x85U << 20, |
| 431 |
op_fmsub_d = 0x86U << 20, |
| 432 |
op_fnmadd_s = 0x89U << 20, |
| 433 |
op_fnmadd_d = 0x8aU << 20, |
| 434 |
op_fnmsub_s = 0x8dU << 20, |
| 435 |
op_fnmsub_d = 0x8eU << 20, |
| 436 |
op_fcmp_cond_s = 0xc1U << 20, |
| 437 |
op_fcmp_cond_d = 0xc2U << 20, |
| 438 |
|
| 439 |
op_bytepick_d = 0x3U << 18, |
| 440 |
op_fsel = 0x340U << 18, |
| 441 |
|
| 442 |
op_bytepick_w = 0x4U << 17, |
| 443 |
op_alsl_w = 0x2U << 17, |
| 444 |
op_alsl_wu = 0x3U << 17, |
| 445 |
op_alsl_d = 0x16U << 17, |
| 446 |
|
| 447 |
op_slli_d = 0x41U << 16, |
| 448 |
op_srli_d = 0x45U << 16, |
| 449 |
op_srai_d = 0x49U << 16, |
| 450 |
|
| 451 |
op_slli_w = 0x81U << 15, |
| 452 |
op_srli_w = 0x89U << 15, |
| 453 |
op_srai_w = 0x91U << 15, |
| 454 |
op_add_w = 0x20U << 15, |
| 455 |
op_add_d = 0x21U << 15, |
| 456 |
op_sub_w = 0x22U << 15, |
| 457 |
op_sub_d = 0x23U << 15, |
| 458 |
op_slt = 0x24U << 15, |
| 459 |
op_sltu = 0x25U << 15, |
| 460 |
op_maskeqz = 0x26U << 15, |
| 461 |
op_masknez = 0x27U << 15, |
| 462 |
op_nor = 0x28U << 15, |
| 463 |
op_and = 0x29U << 15, |
| 464 |
op_or = 0x2aU << 15, |
| 465 |
op_xor = 0x2bU << 15, |
| 466 |
op_orn = 0x2cU << 15, |
| 467 |
op_andn = 0x2dU << 15, |
| 468 |
op_sll_w = 0x2eU << 15, |
| 469 |
op_srl_w = 0x2fU << 15, |
| 470 |
op_sra_w = 0x30U << 15, |
| 471 |
op_sll_d = 0x31U << 15, |
| 472 |
op_srl_d = 0x32U << 15, |
| 473 |
op_sra_d = 0x33U << 15, |
| 474 |
op_rotr_w = 0x36U << 15, |
| 475 |
op_rotr_d = 0x37U << 15, |
| 476 |
op_rotri_w = 0x99U << 15, |
| 477 |
op_rotri_d = 0x4DU << 16, |
| 478 |
op_mul_w = 0x38U << 15, |
| 479 |
op_mulh_w = 0x39U << 15, |
| 480 |
op_mulh_wu = 0x3aU << 15, |
| 481 |
op_mul_d = 0x3bU << 15, |
| 482 |
op_mulh_d = 0x3cU << 15, |
| 483 |
op_mulh_du = 0x3dU << 15, |
| 484 |
op_mulw_d_w = 0x3eU << 15, |
| 485 |
op_mulw_d_wu = 0x3fU << 15, |
| 486 |
op_div_w = 0x40U << 15, |
| 487 |
op_mod_w = 0x41U << 15, |
| 488 |
op_div_wu = 0x42U << 15, |
| 489 |
op_mod_wu = 0x43U << 15, |
| 490 |
op_div_d = 0x44U << 15, |
| 491 |
op_mod_d = 0x45U << 15, |
| 492 |
op_div_du = 0x46U << 15, |
| 493 |
op_mod_du = 0x47U << 15, |
| 494 |
op_break = 0x54U << 15, |
| 495 |
op_syscall = 0x56U << 15, |
| 496 |
op_fadd_s = 0x201U << 15, |
| 497 |
op_fadd_d = 0x202U << 15, |
| 498 |
op_fsub_s = 0x205U << 15, |
| 499 |
op_fsub_d = 0x206U << 15, |
| 500 |
op_fmul_s = 0x209U << 15, |
| 501 |
op_fmul_d = 0x20aU << 15, |
| 502 |
op_fdiv_s = 0x20dU << 15, |
| 503 |
op_fdiv_d = 0x20eU << 15, |
| 504 |
op_fmax_s = 0x211U << 15, |
| 505 |
op_fmax_d = 0x212U << 15, |
| 506 |
op_fmin_s = 0x215U << 15, |
| 507 |
op_fmin_d = 0x216U << 15, |
| 508 |
op_fmaxa_s = 0x219U << 15, |
| 509 |
op_fmaxa_d = 0x21aU << 15, |
| 510 |
op_fmina_s = 0x21dU << 15, |
| 511 |
op_fmina_d = 0x21eU << 15, |
| 512 |
op_fcopysign_s = 0x225U << 15, |
| 513 |
op_fcopysign_d = 0x226U << 15, |
| 514 |
op_ldx_b = 0x7000U << 15, |
| 515 |
op_ldx_h = 0x7008U << 15, |
| 516 |
op_ldx_w = 0x7010U << 15, |
| 517 |
op_ldx_d = 0x7018U << 15, |
| 518 |
op_stx_b = 0x7020U << 15, |
| 519 |
op_stx_h = 0x7028U << 15, |
| 520 |
op_stx_w = 0x7030U << 15, |
| 521 |
op_stx_d = 0x7038U << 15, |
| 522 |
op_ldx_bu = 0x7040U << 15, |
| 523 |
op_ldx_hu = 0x7048U << 15, |
| 524 |
op_ldx_wu = 0x7050U << 15, |
| 525 |
op_fldx_s = 0x7060U << 15, |
| 526 |
op_fldx_d = 0x7068U << 15, |
| 527 |
op_fstx_s = 0x7070U << 15, |
| 528 |
op_fstx_d = 0x7078U << 15, |
| 529 |
op_amswap_w = 0x70c0U << 15, |
| 530 |
op_amswap_d = 0x70c1U << 15, |
| 531 |
op_amadd_w = 0x70c2U << 15, |
| 532 |
op_amadd_d = 0x70c3U << 15, |
| 533 |
op_amand_w = 0x70c4U << 15, |
| 534 |
op_amand_d = 0x70c5U << 15, |
| 535 |
op_amor_w = 0x70c6U << 15, |
| 536 |
op_amor_d = 0x70c7U << 15, |
| 537 |
op_amxor_w = 0x70c8U << 15, |
| 538 |
op_amxor_d = 0x70c9U << 15, |
| 539 |
op_ammax_w = 0x70caU << 15, |
| 540 |
op_ammax_d = 0x70cbU << 15, |
| 541 |
op_ammin_w = 0x70ccU << 15, |
| 542 |
op_ammin_d = 0x70cdU << 15, |
| 543 |
op_ammax_wu = 0x70ceU << 15, |
| 544 |
op_ammax_du = 0x70cfU << 15, |
| 545 |
op_ammin_wu = 0x70d0U << 15, |
| 546 |
op_ammin_du = 0x70d1U << 15, |
| 547 |
op_amswap_db_w = 0x70d2U << 15, |
| 548 |
op_amswap_db_d = 0x70d3U << 15, |
| 549 |
op_amadd_db_w = 0x70d4U << 15, |
| 550 |
op_amadd_db_d = 0x70d5U << 15, |
| 551 |
op_amand_db_w = 0x70d6U << 15, |
| 552 |
op_amand_db_d = 0x70d7U << 15, |
| 553 |
op_amor_db_w = 0x70d8U << 15, |
| 554 |
op_amor_db_d = 0x70d9U << 15, |
| 555 |
op_amxor_db_w = 0x70daU << 15, |
| 556 |
op_amxor_db_d = 0x70dbU << 15, |
| 557 |
op_ammax_db_w = 0x70dcU << 15, |
| 558 |
op_ammax_db_d = 0x70ddU << 15, |
| 559 |
op_ammin_db_w = 0x70deU << 15, |
| 560 |
op_ammin_db_d = 0x70dfU << 15, |
| 561 |
op_ammax_db_wu = 0x70e0U << 15, |
| 562 |
op_ammax_db_du = 0x70e1U << 15, |
| 563 |
op_ammin_db_wu = 0x70e2U << 15, |
| 564 |
op_ammin_db_du = 0x70e3U << 15, |
| 565 |
op_dbar = 0x70e4U << 15, |
| 566 |
op_ibar = 0x70e5U << 15, |
| 567 |
op_clo_w = 0x4U << 10, |
| 568 |
op_clz_w = 0x5U << 10, |
| 569 |
op_cto_w = 0x6U << 10, |
| 570 |
op_ctz_w = 0x7U << 10, |
| 571 |
op_clo_d = 0x8U << 10, |
| 572 |
op_clz_d = 0x9U << 10, |
| 573 |
op_cto_d = 0xaU << 10, |
| 574 |
op_ctz_d = 0xbU << 10, |
| 575 |
op_revb_2h = 0xcU << 10, |
| 576 |
op_revb_4h = 0xdU << 10, |
| 577 |
op_revb_2w = 0xeU << 10, |
| 578 |
op_revb_d = 0xfU << 10, |
| 579 |
op_revh_2w = 0x10U << 10, |
| 580 |
op_revh_d = 0x11U << 10, |
| 581 |
op_bitrev_4b = 0x12U << 10, |
| 582 |
op_bitrev_8b = 0x13U << 10, |
| 583 |
op_bitrev_w = 0x14U << 10, |
| 584 |
op_bitrev_d = 0x15U << 10, |
| 585 |
op_ext_w_h = 0x16U << 10, |
| 586 |
op_ext_w_b = 0x17U << 10, |
| 587 |
op_fabs_s = 0x4501U << 10, |
| 588 |
op_fabs_d = 0x4502U << 10, |
| 589 |
op_fneg_s = 0x4505U << 10, |
| 590 |
op_fneg_d = 0x4506U << 10, |
| 591 |
op_fsqrt_s = 0x4511U << 10, |
| 592 |
op_fsqrt_d = 0x4512U << 10, |
| 593 |
op_fmov_s = 0x4525U << 10, |
| 594 |
op_fmov_d = 0x4526U << 10, |
| 595 |
op_movgr2fr_w = 0x4529U << 10, |
| 596 |
op_movgr2fr_d = 0x452aU << 10, |
| 597 |
op_movgr2frh_w = 0x452bU << 10, |
| 598 |
op_movfr2gr_s = 0x452dU << 10, |
| 599 |
op_movfr2gr_d = 0x452eU << 10, |
| 600 |
op_movfrh2gr_s = 0x452fU << 10, |
| 601 |
op_movgr2fcsr = 0x4530U << 10, |
| 602 |
op_movfcsr2gr = 0x4532U << 10, |
| 603 |
op_movfr2cf = 0x4534U << 10, |
| 604 |
op_movgr2cf = 0x4536U << 10, |
| 605 |
op_fcvt_s_d = 0x4646U << 10, |
| 606 |
op_fcvt_d_s = 0x4649U << 10, |
| 607 |
op_ftintrm_w_s = 0x4681U << 10, |
| 608 |
op_ftintrm_w_d = 0x4682U << 10, |
| 609 |
op_ftintrm_l_s = 0x4689U << 10, |
| 610 |
op_ftintrm_l_d = 0x468aU << 10, |
| 611 |
op_ftintrp_w_s = 0x4691U << 10, |
| 612 |
op_ftintrp_w_d = 0x4692U << 10, |
| 613 |
op_ftintrp_l_s = 0x4699U << 10, |
| 614 |
op_ftintrp_l_d = 0x469aU << 10, |
| 615 |
op_ftintrz_w_s = 0x46a1U << 10, |
| 616 |
op_ftintrz_w_d = 0x46a2U << 10, |
| 617 |
op_ftintrz_l_s = 0x46a9U << 10, |
| 618 |
op_ftintrz_l_d = 0x46aaU << 10, |
| 619 |
op_ftintrne_w_s = 0x46b1U << 10, |
| 620 |
op_ftintrne_w_d = 0x46b2U << 10, |
| 621 |
op_ftintrne_l_s = 0x46b9U << 10, |
| 622 |
op_ftintrne_l_d = 0x46baU << 10, |
| 623 |
op_ftint_w_s = 0x46c1U << 10, |
| 624 |
op_ftint_w_d = 0x46c2U << 10, |
| 625 |
op_ftint_l_s = 0x46c9U << 10, |
| 626 |
op_ftint_l_d = 0x46caU << 10, |
| 627 |
op_ffint_s_w = 0x4744U << 10, |
| 628 |
op_ffint_s_l = 0x4746U << 10, |
| 629 |
op_ffint_d_w = 0x4748U << 10, |
| 630 |
op_ffint_d_l = 0x474aU << 10, |
| 631 |
op_frint_s = 0x4791U << 10, |
| 632 |
op_frint_d = 0x4792U << 10, |
| 633 |
op_movcf2fr = 0x114d4U << 8, |
| 634 |
op_movcf2gr = 0x114dcU << 8, |
| 635 |
}; |
| 636 |
|
| 637 |
class Operand; |
| 638 |
|
| 639 |
// A BOffImm16 is a 16 bit immediate that is used for branches. |
| 640 |
class BOffImm16 { |
| 641 |
uint32_t data; |
| 642 |
|
| 643 |
public: |
| 644 |
uint32_t encode() { |
| 645 |
MOZ_ASSERT(!isInvalid()); |
| 646 |
return data; |
| 647 |
} |
| 648 |
int32_t decode() { |
| 649 |
MOZ_ASSERT(!isInvalid()); |
| 650 |
return (int32_t(data << 18) >> 16); |
| 651 |
} |
| 652 |
|
| 653 |
explicit BOffImm16(int offset) : data((offset) >> 2 & Imm16Mask) { |
| 654 |
MOZ_ASSERT((offset & 0x3) == 0); |
| 655 |
MOZ_ASSERT(IsInRange(offset)); |
| 656 |
} |
| 657 |
static bool IsInRange(int offset) { |
| 658 |
if ((offset) < int(unsigned(INT16_MIN) << 2)) { |
| 659 |
return false; |
| 660 |
} |
| 661 |
if ((offset) > (INT16_MAX << 2)) { |
| 662 |
return false; |
| 663 |
} |
| 664 |
return true; |
| 665 |
} |
| 666 |
static const uint32_t INVALID = 0x00020000; |
| 667 |
BOffImm16() : data(INVALID) {} |
| 668 |
|
| 669 |
bool isInvalid() { return data == INVALID; } |
| 670 |
Instruction* getDest(Instruction* src) const; |
| 671 |
|
| 672 |
BOffImm16(InstImm inst); |
| 673 |
}; |
| 674 |
|
| 675 |
// A JOffImm26 is a 26 bit immediate that is used for unconditional jumps. |
| 676 |
class JOffImm26 { |
| 677 |
uint32_t data; |
| 678 |
|
| 679 |
public: |
| 680 |
uint32_t encode() { |
| 681 |
MOZ_ASSERT(!isInvalid()); |
| 682 |
return data; |
| 683 |
} |
| 684 |
int32_t decode() { |
| 685 |
MOZ_ASSERT(!isInvalid()); |
| 686 |
return (int32_t(data << 8) >> 6); |
| 687 |
} |
| 688 |
|
| 689 |
explicit JOffImm26(int offset) : data((offset) >> 2 & Imm26Mask) { |
| 690 |
MOZ_ASSERT((offset & 0x3) == 0); |
| 691 |
MOZ_ASSERT(IsInRange(offset)); |
| 692 |
} |
| 693 |
static bool IsInRange(int offset) { |
| 694 |
if ((offset) < -536870912) { |
| 695 |
return false; |
| 696 |
} |
| 697 |
if ((offset) > 536870908) { |
| 698 |
return false; |
| 699 |
} |
| 700 |
return true; |
| 701 |
} |
| 702 |
static const uint32_t INVALID = 0x20000000; |
| 703 |
JOffImm26() : data(INVALID) {} |
| 704 |
|
| 705 |
bool isInvalid() { return data == INVALID; } |
| 706 |
Instruction* getDest(Instruction* src); |
| 707 |
}; |
| 708 |
|
| 709 |
class Imm16 { |
| 710 |
uint16_t value; |
| 711 |
|
| 712 |
public: |
| 713 |
Imm16(); |
| 714 |
Imm16(uint32_t imm) : value(imm) {} |
| 715 |
uint32_t encode() { return value; } |
| 716 |
int32_t decodeSigned() { return value; } |
| 717 |
uint32_t decodeUnsigned() { return value; } |
| 718 |
|
| 719 |
static bool IsInSignedRange(int32_t imm) { |
| 720 |
return imm >= INT16_MIN && imm <= INT16_MAX; |
| 721 |
} |
| 722 |
|
| 723 |
static bool IsInUnsignedRange(uint32_t imm) { return imm <= UINT16_MAX; } |
| 724 |
}; |
| 725 |
|
| 726 |
class Imm8 { |
| 727 |
uint8_t value; |
| 728 |
|
| 729 |
public: |
| 730 |
Imm8(); |
| 731 |
Imm8(uint32_t imm) : value(imm) {} |
| 732 |
uint32_t encode(uint32_t shift) { return value << shift; } |
| 733 |
int32_t decodeSigned() { return value; } |
| 734 |
uint32_t decodeUnsigned() { return value; } |
| 735 |
static bool IsInSignedRange(int32_t imm) { |
| 736 |
return imm >= INT8_MIN && imm <= INT8_MAX; |
| 737 |
} |
| 738 |
static bool IsInUnsignedRange(uint32_t imm) { return imm <= UINT8_MAX; } |
| 739 |
static Imm8 Lower(Imm16 imm) { return Imm8(imm.decodeSigned() & 0xff); } |
| 740 |
static Imm8 Upper(Imm16 imm) { |
| 741 |
return Imm8((imm.decodeSigned() >> 8) & 0xff); |
| 742 |
} |
| 743 |
}; |
| 744 |
|
| 745 |
class Operand { |
| 746 |
public: |
| 747 |
enum Tag { REG, FREG, MEM }; |
| 748 |
|
| 749 |
private: |
| 750 |
Tag tag : 3; |
| 751 |
uint32_t reg : 5; |
| 752 |
int32_t offset; |
| 753 |
|
| 754 |
public: |
| 755 |
Operand(Register reg_) : tag(REG), reg(reg_.code()) {} |
| 756 |
|
| 757 |
Operand(FloatRegister freg) : tag(FREG), reg(freg.code()) {} |
| 758 |
|
| 759 |
Operand(Register base, Imm32 off) |
| 760 |
: tag(MEM), reg(base.code()), offset(off.value) {} |
| 761 |
|
| 762 |
Operand(Register base, int32_t off) |
| 763 |
: tag(MEM), reg(base.code()), offset(off) {} |
| 764 |
|
| 765 |
Operand(const Address& addr) |
| 766 |
: tag(MEM), reg(addr.base.code()), offset(addr.offset) {} |
| 767 |
|
| 768 |
Tag getTag() const { return tag; } |
| 769 |
|
| 770 |
Register toReg() const { |
| 771 |
MOZ_ASSERT(tag == REG); |
| 772 |
return Register::FromCode(reg); |
| 773 |
} |
| 774 |
|
| 775 |
FloatRegister toFReg() const { |
| 776 |
MOZ_ASSERT(tag == FREG); |
| 777 |
return FloatRegister::FromCode(reg); |
| 778 |
} |
| 779 |
|
| 780 |
void toAddr(Register* r, Imm32* dest) const { |
| 781 |
MOZ_ASSERT(tag == MEM); |
| 782 |
*r = Register::FromCode(reg); |
| 783 |
*dest = Imm32(offset); |
| 784 |
} |
| 785 |
Address toAddress() const { |
| 786 |
MOZ_ASSERT(tag == MEM); |
| 787 |
return Address(Register::FromCode(reg), offset); |
| 788 |
} |
| 789 |
int32_t disp() const { |
| 790 |
MOZ_ASSERT(tag == MEM); |
| 791 |
return offset; |
| 792 |
} |
| 793 |
|
| 794 |
int32_t base() const { |
| 795 |
MOZ_ASSERT(tag == MEM); |
| 796 |
return reg; |
| 797 |
} |
| 798 |
Register baseReg() const { |
| 799 |
MOZ_ASSERT(tag == MEM); |
| 800 |
return Register::FromCode(reg); |
| 801 |
} |
| 802 |
}; |
| 803 |
|
| 804 |
// int check. |
| 805 |
inline bool is_intN(int32_t x, unsigned n) { |
| 806 |
MOZ_ASSERT((0 < n) && (n < 64)); |
| 807 |
int32_t limit = static_cast<int32_t>(1) << (n - 1); |
| 808 |
return (-limit <= x) && (x < limit); |
| 809 |
} |
| 810 |
|
| 811 |
inline bool is_uintN(int32_t x, unsigned n) { |
| 812 |
MOZ_ASSERT((0 < n) && (n < (sizeof(x) * 8))); |
| 813 |
return !(x >> n); |
| 814 |
} |
| 815 |
|
| 816 |
static constexpr int32_t SliceSize = 1024; |
| 817 |
typedef js::jit::AssemblerBuffer<SliceSize, Instruction> LOONGBuffer; |
| 818 |
|
| 819 |
class LOONGBufferWithExecutableCopy : public LOONGBuffer { |
| 820 |
public: |
| 821 |
void executableCopy(uint8_t* buffer) { |
| 822 |
if (this->oom()) { |
| 823 |
return; |
| 824 |
} |
| 825 |
|
| 826 |
for (Slice* cur = head; cur != nullptr; cur = cur->getNext()) { |
| 827 |
memcpy(buffer, &cur->instructions, cur->length()); |
| 828 |
buffer += cur->length(); |
| 829 |
} |
| 830 |
} |
| 831 |
|
| 832 |
bool appendRawCode(const uint8_t* code, size_t numBytes) { |
| 833 |
if (this->oom()) { |
| 834 |
return false; |
| 835 |
} |
| 836 |
while (numBytes > SliceSize) { |
| 837 |
this->putBytes(SliceSize, code); |
| 838 |
numBytes -= SliceSize; |
| 839 |
code += SliceSize; |
| 840 |
} |
| 841 |
this->putBytes(numBytes, code); |
| 842 |
return !this->oom(); |
| 843 |
} |
| 844 |
}; |
| 845 |
|
| 846 |
class AssemblerLOONG64 : public AssemblerShared { |
| 847 |
public: |
| 848 |
// TODO(loong64): Should we remove these conditions here? |
| 849 |
enum Condition { |
| 850 |
Equal, |
| 851 |
NotEqual, |
| 852 |
Above, |
| 853 |
AboveOrEqual, |
| 854 |
Below, |
| 855 |
BelowOrEqual, |
| 856 |
GreaterThan, |
| 857 |
GreaterThanOrEqual, |
| 858 |
GreaterThanOrEqual_Signed, |
| 859 |
GreaterThanOrEqual_NotSigned, |
| 860 |
LessThan, |
| 861 |
LessThan_Signed, |
| 862 |
LessThan_NotSigned, |
| 863 |
LessThanOrEqual, |
| 864 |
Overflow, |
| 865 |
CarrySet, |
| 866 |
CarryClear, |
| 867 |
Signed, |
| 868 |
NotSigned, |
| 869 |
Zero, |
| 870 |
NonZero, |
| 871 |
Always, |
| 872 |
}; |
| 873 |
|
| 874 |
enum DoubleCondition { |
| 875 |
DoubleOrdered, |
| 876 |
DoubleEqual, |
| 877 |
DoubleNotEqual, |
| 878 |
DoubleGreaterThan, |
| 879 |
DoubleGreaterThanOrEqual, |
| 880 |
DoubleLessThan, |
| 881 |
DoubleLessThanOrEqual, |
| 882 |
DoubleUnordered, |
| 883 |
DoubleEqualOrUnordered, |
| 884 |
DoubleNotEqualOrUnordered, |
| 885 |
DoubleGreaterThanOrUnordered, |
| 886 |
DoubleGreaterThanOrEqualOrUnordered, |
| 887 |
DoubleLessThanOrUnordered, |
| 888 |
DoubleLessThanOrEqualOrUnordered |
| 889 |
}; |
| 890 |
|
| 891 |
enum FPUCondition { |
| 892 |
kNoFPUCondition = -1, |
| 893 |
|
| 894 |
CAF = 0x00, |
| 895 |
SAF = 0x01, |
| 896 |
CLT = 0x02, |
| 897 |
SLT = 0x03, |
| 898 |
CEQ = 0x04, |
| 899 |
SEQ = 0x05, |
| 900 |
CLE = 0x06, |
| 901 |
SLE = 0x07, |
| 902 |
CUN = 0x08, |
| 903 |
SUN = 0x09, |
| 904 |
CULT = 0x0a, |
| 905 |
SULT = 0x0b, |
| 906 |
CUEQ = 0x0c, |
| 907 |
SUEQ = 0x0d, |
| 908 |
CULE = 0x0e, |
| 909 |
SULE = 0x0f, |
| 910 |
CNE = 0x10, |
| 911 |
SNE = 0x11, |
| 912 |
COR = 0x14, |
| 913 |
SOR = 0x15, |
| 914 |
CUNE = 0x18, |
| 915 |
SUNE = 0x19, |
| 916 |
}; |
| 917 |
|
| 918 |
enum FPConditionBit { FCC0 = 0, FCC1, FFC2, FCC3, FCC4, FCC5, FCC6, FCC7 }; |
| 919 |
|
| 920 |
enum FPControl { FCSR = 0 }; |
| 921 |
|
| 922 |
enum FCSRBit { CauseI = 24, CauseU, CauseO, CauseZ, CauseV }; |
| 923 |
|
| 924 |
enum FloatFormat { SingleFloat, DoubleFloat }; |
| 925 |
|
| 926 |
enum JumpOrCall { BranchIsJump, BranchIsCall }; |
| 927 |
|
| 928 |
enum FloatTestKind { TestForTrue, TestForFalse }; |
| 929 |
|
| 930 |
// :( this should be protected, but since CodeGenerator |
| 931 |
// wants to use it, It needs to go out here :( |
| 932 |
|
| 933 |
BufferOffset nextOffset() { return m_buffer.nextOffset(); } |
| 934 |
|
| 935 |
protected: |
| 936 |
Instruction* editSrc(BufferOffset bo) { return m_buffer.getInst(bo); } |
| 937 |
|
| 938 |
// structure for fixing up pc-relative loads/jumps when a the machine code |
| 939 |
// gets moved (executable copy, gc, etc.) |
| 940 |
struct RelativePatch { |
| 941 |
// the offset within the code buffer where the value is loaded that |
| 942 |
// we want to fix-up |
| 943 |
BufferOffset offset; |
| 944 |
void* target; |
| 945 |
RelocationKind kind; |
| 946 |
|
| 947 |
RelativePatch(BufferOffset offset, void* target, RelocationKind kind) |
| 948 |
: offset(offset), target(target), kind(kind) {} |
| 949 |
}; |
| 950 |
|
| 951 |
js::Vector<RelativePatch, 8, SystemAllocPolicy> jumps_; |
| 952 |
|
| 953 |
CompactBufferWriter jumpRelocations_; |
| 954 |
CompactBufferWriter dataRelocations_; |
| 955 |
|
| 956 |
LOONGBufferWithExecutableCopy m_buffer; |
| 957 |
|
| 958 |
#ifdef JS_JITSPEW |
| 959 |
Sprinter* printer; |
| 960 |
#endif |
| 961 |
|
| 962 |
public: |
| 963 |
AssemblerLOONG64() |
| 964 |
: m_buffer(), |
| 965 |
#ifdef JS_JITSPEW |
| 966 |
printer(nullptr), |
| 967 |
#endif |
| 968 |
isFinished(false) { |
| 969 |
} |
| 970 |
|
| 971 |
static Condition InvertCondition(Condition cond); |
| 972 |
static DoubleCondition InvertCondition(DoubleCondition cond); |
| 973 |
// This is changing the condition codes for cmp a, b to the same codes for cmp |
| 974 |
// b, a. |
| 975 |
static Condition InvertCmpCondition(Condition cond); |
| 976 |
|
| 977 |
// As opposed to x86/x64 version, the data relocation has to be executed |
| 978 |
// before to recover the pointer, and not after. |
| 979 |
void writeDataRelocation(ImmGCPtr ptr) { |
| 980 |
// Raw GC pointer relocations and Value relocations both end up in |
| 981 |
// TraceOneDataRelocation. |
| 982 |
if (ptr.value) { |
| 983 |
if (gc::IsInsideNursery(ptr.value)) { |
| 984 |
embedsNurseryPointers_ = true; |
| 985 |
} |
| 986 |
dataRelocations_.writeUnsigned(nextOffset().getOffset()); |
| 987 |
} |
| 988 |
} |
| 989 |
|
| 990 |
void assertNoGCThings() const { |
| 991 |
#ifdef DEBUG |
| 992 |
MOZ_ASSERT(dataRelocations_.length() == 0); |
| 993 |
for (auto& j : jumps_) { |
| 994 |
MOZ_ASSERT(j.kind == RelocationKind::HARDCODED); |
| 995 |
} |
| 996 |
#endif |
| 997 |
} |
| 998 |
|
| 999 |
public: |
| 1000 |
void setUnlimitedBuffer() { m_buffer.setUnlimited(); } |
| 1001 |
bool oom() const; |
| 1002 |
|
| 1003 |
void setPrinter(Sprinter* sp) { |
| 1004 |
#ifdef JS_JITSPEW |
| 1005 |
printer = sp; |
| 1006 |
#endif |
| 1007 |
} |
| 1008 |
|
| 1009 |
#ifdef JS_JITSPEW |
| 1010 |
inline void spew(const char* fmt, ...) MOZ_FORMAT_PRINTF(2, 3) { |
| 1011 |
if (MOZ_UNLIKELY(printer || JitSpewEnabled(JitSpew_Codegen))) { |
| 1012 |
va_list va; |
| 1013 |
va_start(va, fmt); |
| 1014 |
spew(fmt, va); |
| 1015 |
va_end(va); |
| 1016 |
} |
| 1017 |
} |
| 1018 |
|
| 1019 |
void decodeBranchInstAndSpew(InstImm branch); |
| 1020 |
#else |
| 1021 |
MOZ_ALWAYS_INLINE void spew(const char* fmt, ...) MOZ_FORMAT_PRINTF(2, 3) {} |
| 1022 |
#endif |
| 1023 |
|
| 1024 |
#ifdef JS_JITSPEW |
| 1025 |
MOZ_COLD void spew(const char* fmt, va_list va) MOZ_FORMAT_PRINTF(2, 0) { |
| 1026 |
// Buffer to hold the formatted string. Note that this may contain |
| 1027 |
// '%' characters, so do not pass it directly to printf functions. |
| 1028 |
char buf[200]; |
| 1029 |
|
| 1030 |
int i = VsprintfLiteral(buf, fmt, va); |
| 1031 |
if (i > -1) { |
| 1032 |
if (printer) { |
| 1033 |
printer->printf("%s\n", buf); |
| 1034 |
} |
| 1035 |
js::jit::JitSpew(js::jit::JitSpew_Codegen, "%s", buf); |
| 1036 |
} |
| 1037 |
} |
| 1038 |
#endif |
| 1039 |
|
| 1040 |
Register getStackPointer() const { return StackPointer; } |
| 1041 |
|
| 1042 |
protected: |
| 1043 |
bool isFinished; |
| 1044 |
|
| 1045 |
public: |
| 1046 |
void finish(); |
| 1047 |
bool appendRawCode(const uint8_t* code, size_t numBytes); |
| 1048 |
bool reserve(size_t size); |
| 1049 |
bool swapBuffer(wasm::Bytes& bytes); |
| 1050 |
void executableCopy(void* buffer); |
| 1051 |
void copyJumpRelocationTable(uint8_t* dest); |
| 1052 |
void copyDataRelocationTable(uint8_t* dest); |
| 1053 |
|
| 1054 |
// Size of the instruction stream, in bytes. |
| 1055 |
size_t size() const; |
| 1056 |
// Size of the jump relocation table, in bytes. |
| 1057 |
size_t jumpRelocationTableBytes() const; |
| 1058 |
size_t dataRelocationTableBytes() const; |
| 1059 |
|
| 1060 |
// Size of the data table, in bytes. |
| 1061 |
size_t bytesNeeded() const; |
| 1062 |
|
| 1063 |
// Write a blob of binary into the instruction stream *OR* |
| 1064 |
// into a destination address. If dest is nullptr (the default), then the |
| 1065 |
// instruction gets written into the instruction stream. If dest is not null |
| 1066 |
// it is interpreted as a pointer to the location that we want the |
| 1067 |
// instruction to be written. |
| 1068 |
BufferOffset writeInst(uint32_t x, uint32_t* dest = nullptr); |
| 1069 |
// A static variant for the cases where we don't want to have an assembler |
| 1070 |
// object at all. Normally, you would use the dummy (nullptr) object. |
| 1071 |
static void WriteInstStatic(uint32_t x, uint32_t* dest); |
| 1072 |
|
| 1073 |
public: |
| 1074 |
BufferOffset haltingAlign(int alignment); |
| 1075 |
BufferOffset nopAlign(int alignment); |
| 1076 |
BufferOffset as_nop() { return as_andi(zero, zero, 0); } |
| 1077 |
|
| 1078 |
// Branch and jump instructions |
| 1079 |
BufferOffset as_b(JOffImm26 off); |
| 1080 |
BufferOffset as_bl(JOffImm26 off); |
| 1081 |
BufferOffset as_jirl(Register rd, Register rj, BOffImm16 off); |
| 1082 |
|
| 1083 |
InstImm getBranchCode(JumpOrCall jumpOrCall); // b, bl |
| 1084 |
InstImm getBranchCode(Register rd, Register rj, |
| 1085 |
Condition c); // beq, bne, bge, bgeu, blt, bltu |
| 1086 |
InstImm getBranchCode(Register rj, Condition c); // beqz, bnez |
| 1087 |
InstImm getBranchCode(FPConditionBit cj); // bceqz, bcnez |
| 1088 |
|
| 1089 |
// Arithmetic instructions |
| 1090 |
BufferOffset as_add_w(Register rd, Register rj, Register rk); |
| 1091 |
BufferOffset as_add_d(Register rd, Register rj, Register rk); |
| 1092 |
BufferOffset as_sub_w(Register rd, Register rj, Register rk); |
| 1093 |
BufferOffset as_sub_d(Register rd, Register rj, Register rk); |
| 1094 |
|
| 1095 |
BufferOffset as_addi_w(Register rd, Register rj, int32_t si12); |
| 1096 |
BufferOffset as_addi_d(Register rd, Register rj, int32_t si12); |
| 1097 |
BufferOffset as_addu16i_d(Register rd, Register rj, int32_t si16); |
| 1098 |
|
| 1099 |
BufferOffset as_alsl_w(Register rd, Register rj, Register rk, uint32_t sa2); |
| 1100 |
BufferOffset as_alsl_wu(Register rd, Register rj, Register rk, uint32_t sa2); |
| 1101 |
BufferOffset as_alsl_d(Register rd, Register rj, Register rk, uint32_t sa2); |
| 1102 |
|
| 1103 |
BufferOffset as_lu12i_w(Register rd, int32_t si20); |
| 1104 |
BufferOffset as_lu32i_d(Register rd, int32_t si20); |
| 1105 |
BufferOffset as_lu52i_d(Register rd, Register rj, int32_t si12); |
| 1106 |
|
| 1107 |
BufferOffset as_slt(Register rd, Register rj, Register rk); |
| 1108 |
BufferOffset as_sltu(Register rd, Register rj, Register rk); |
| 1109 |
BufferOffset as_slti(Register rd, Register rj, int32_t si12); |
| 1110 |
BufferOffset as_sltui(Register rd, Register rj, int32_t si12); |
| 1111 |
|
| 1112 |
BufferOffset as_pcaddi(Register rd, int32_t si20); |
| 1113 |
BufferOffset as_pcaddu12i(Register rd, int32_t si20); |
| 1114 |
BufferOffset as_pcaddu18i(Register rd, int32_t si20); |
| 1115 |
BufferOffset as_pcalau12i(Register rd, int32_t si20); |
| 1116 |
|
| 1117 |
BufferOffset as_mul_w(Register rd, Register rj, Register rk); |
| 1118 |
BufferOffset as_mulh_w(Register rd, Register rj, Register rk); |
| 1119 |
BufferOffset as_mulh_wu(Register rd, Register rj, Register rk); |
| 1120 |
BufferOffset as_mul_d(Register rd, Register rj, Register rk); |
| 1121 |
BufferOffset as_mulh_d(Register rd, Register rj, Register rk); |
| 1122 |
BufferOffset as_mulh_du(Register rd, Register rj, Register rk); |
| 1123 |
|
| 1124 |
BufferOffset as_mulw_d_w(Register rd, Register rj, Register rk); |
| 1125 |
BufferOffset as_mulw_d_wu(Register rd, Register rj, Register rk); |
| 1126 |
|
| 1127 |
BufferOffset as_div_w(Register rd, Register rj, Register rk); |
| 1128 |
BufferOffset as_mod_w(Register rd, Register rj, Register rk); |
| 1129 |
BufferOffset as_div_wu(Register rd, Register rj, Register rk); |
| 1130 |
BufferOffset as_mod_wu(Register rd, Register rj, Register rk); |
| 1131 |
BufferOffset as_div_d(Register rd, Register rj, Register rk); |
| 1132 |
BufferOffset as_mod_d(Register rd, Register rj, Register rk); |
| 1133 |
BufferOffset as_div_du(Register rd, Register rj, Register rk); |
| 1134 |
BufferOffset as_mod_du(Register rd, Register rj, Register rk); |
| 1135 |
|
| 1136 |
// Logical instructions |
| 1137 |
BufferOffset as_and(Register rd, Register rj, Register rk); |
| 1138 |
BufferOffset as_or(Register rd, Register rj, Register rk); |
| 1139 |
BufferOffset as_xor(Register rd, Register rj, Register rk); |
| 1140 |
BufferOffset as_nor(Register rd, Register rj, Register rk); |
| 1141 |
BufferOffset as_andn(Register rd, Register rj, Register rk); |
| 1142 |
BufferOffset as_orn(Register rd, Register rj, Register rk); |
| 1143 |
|
| 1144 |
BufferOffset as_andi(Register rd, Register rj, int32_t ui12); |
| 1145 |
BufferOffset as_ori(Register rd, Register rj, int32_t ui12); |
| 1146 |
BufferOffset as_xori(Register rd, Register rj, int32_t ui12); |
| 1147 |
|
| 1148 |
// Shift instructions |
| 1149 |
BufferOffset as_sll_w(Register rd, Register rj, Register rk); |
| 1150 |
BufferOffset as_srl_w(Register rd, Register rj, Register rk); |
| 1151 |
BufferOffset as_sra_w(Register rd, Register rj, Register rk); |
| 1152 |
BufferOffset as_rotr_w(Register rd, Register rj, Register rk); |
| 1153 |
|
| 1154 |
BufferOffset as_slli_w(Register rd, Register rj, int32_t ui5); |
| 1155 |
BufferOffset as_srli_w(Register rd, Register rj, int32_t ui5); |
| 1156 |
BufferOffset as_srai_w(Register rd, Register rj, int32_t ui5); |
| 1157 |
BufferOffset as_rotri_w(Register rd, Register rj, int32_t ui5); |
| 1158 |
|
| 1159 |
BufferOffset as_sll_d(Register rd, Register rj, Register rk); |
| 1160 |
BufferOffset as_srl_d(Register rd, Register rj, Register rk); |
| 1161 |
BufferOffset as_sra_d(Register rd, Register rj, Register rk); |
| 1162 |
BufferOffset as_rotr_d(Register rd, Register rj, Register rk); |
| 1163 |
|
| 1164 |
BufferOffset as_slli_d(Register rd, Register rj, int32_t ui6); |
| 1165 |
BufferOffset as_srli_d(Register rd, Register rj, int32_t ui6); |
| 1166 |
BufferOffset as_srai_d(Register rd, Register rj, int32_t ui6); |
| 1167 |
BufferOffset as_rotri_d(Register rd, Register rj, int32_t ui6); |
| 1168 |
|
| 1169 |
// Bit operation instrucitons |
| 1170 |
BufferOffset as_ext_w_b(Register rd, Register rj); |
| 1171 |
BufferOffset as_ext_w_h(Register rd, Register rj); |
| 1172 |
|
| 1173 |
BufferOffset as_clo_w(Register rd, Register rj); |
| 1174 |
BufferOffset as_clz_w(Register rd, Register rj); |
| 1175 |
BufferOffset as_cto_w(Register rd, Register rj); |
| 1176 |
BufferOffset as_ctz_w(Register rd, Register rj); |
| 1177 |
BufferOffset as_clo_d(Register rd, Register rj); |
| 1178 |
BufferOffset as_clz_d(Register rd, Register rj); |
| 1179 |
BufferOffset as_cto_d(Register rd, Register rj); |
| 1180 |
BufferOffset as_ctz_d(Register rd, Register rj); |
| 1181 |
|
| 1182 |
BufferOffset as_bytepick_w(Register rd, Register rj, Register rk, |
| 1183 |
int32_t sa2); |
| 1184 |
BufferOffset as_bytepick_d(Register rd, Register rj, Register rk, |
| 1185 |
int32_t sa3); |
| 1186 |
|
| 1187 |
BufferOffset as_revb_2h(Register rd, Register rj); |
| 1188 |
BufferOffset as_revb_4h(Register rd, Register rj); |
| 1189 |
BufferOffset as_revb_2w(Register rd, Register rj); |
| 1190 |
BufferOffset as_revb_d(Register rd, Register rj); |
| 1191 |
|
| 1192 |
BufferOffset as_revh_2w(Register rd, Register rj); |
| 1193 |
BufferOffset as_revh_d(Register rd, Register rj); |
| 1194 |
|
| 1195 |
BufferOffset as_bitrev_4b(Register rd, Register rj); |
| 1196 |
BufferOffset as_bitrev_8b(Register rd, Register rj); |
| 1197 |
|
| 1198 |
BufferOffset as_bitrev_w(Register rd, Register rj); |
| 1199 |
BufferOffset as_bitrev_d(Register rd, Register rj); |
| 1200 |
|
| 1201 |
BufferOffset as_bstrins_w(Register rd, Register rj, int32_t msbw, |
| 1202 |
int32_t lsbw); |
| 1203 |
BufferOffset as_bstrins_d(Register rd, Register rj, int32_t msbd, |
| 1204 |
int32_t lsbd); |
| 1205 |
BufferOffset as_bstrpick_w(Register rd, Register rj, int32_t msbw, |
| 1206 |
int32_t lsbw); |
| 1207 |
BufferOffset as_bstrpick_d(Register rd, Register rj, int32_t msbd, |
| 1208 |
int32_t lsbd); |
| 1209 |
|
| 1210 |
BufferOffset as_maskeqz(Register rd, Register rj, Register rk); |
| 1211 |
BufferOffset as_masknez(Register rd, Register rj, Register rk); |
| 1212 |
|
| 1213 |
// Load and store instructions |
| 1214 |
BufferOffset as_ld_b(Register rd, Register rj, int32_t si12); |
| 1215 |
BufferOffset as_ld_h(Register rd, Register rj, int32_t si12); |
| 1216 |
BufferOffset as_ld_w(Register rd, Register rj, int32_t si12); |
| 1217 |
BufferOffset as_ld_d(Register rd, Register rj, int32_t si12); |
| 1218 |
BufferOffset as_ld_bu(Register rd, Register rj, int32_t si12); |
| 1219 |
BufferOffset as_ld_hu(Register rd, Register rj, int32_t si12); |
| 1220 |
BufferOffset as_ld_wu(Register rd, Register rj, int32_t si12); |
| 1221 |
BufferOffset as_st_b(Register rd, Register rj, int32_t si12); |
| 1222 |
BufferOffset as_st_h(Register rd, Register rj, int32_t si12); |
| 1223 |
BufferOffset as_st_w(Register rd, Register rj, int32_t si12); |
| 1224 |
BufferOffset as_st_d(Register rd, Register rj, int32_t si12); |
| 1225 |
|
| 1226 |
BufferOffset as_ldx_b(Register rd, Register rj, Register rk); |
| 1227 |
BufferOffset as_ldx_h(Register rd, Register rj, Register rk); |
| 1228 |
BufferOffset as_ldx_w(Register rd, Register rj, Register rk); |
| 1229 |
BufferOffset as_ldx_d(Register rd, Register rj, Register rk); |
| 1230 |
BufferOffset as_ldx_bu(Register rd, Register rj, Register rk); |
| 1231 |
BufferOffset as_ldx_hu(Register rd, Register rj, Register rk); |
| 1232 |
BufferOffset as_ldx_wu(Register rd, Register rj, Register rk); |
| 1233 |
BufferOffset as_stx_b(Register rd, Register rj, Register rk); |
| 1234 |
BufferOffset as_stx_h(Register rd, Register rj, Register rk); |
| 1235 |
BufferOffset as_stx_w(Register rd, Register rj, Register rk); |
| 1236 |
BufferOffset as_stx_d(Register rd, Register rj, Register rk); |
| 1237 |
|
| 1238 |
BufferOffset as_ldptr_w(Register rd, Register rj, int32_t si14); |
| 1239 |
BufferOffset as_ldptr_d(Register rd, Register rj, int32_t si14); |
| 1240 |
BufferOffset as_stptr_w(Register rd, Register rj, int32_t si14); |
| 1241 |
BufferOffset as_stptr_d(Register rd, Register rj, int32_t si14); |
| 1242 |
|
| 1243 |
BufferOffset as_preld(int32_t hint, Register rj, int32_t si12); |
| 1244 |
|
| 1245 |
// Atomic instructions |
| 1246 |
BufferOffset as_amswap_w(Register rd, Register rj, Register rk); |
| 1247 |
BufferOffset as_amswap_d(Register rd, Register rj, Register rk); |
| 1248 |
BufferOffset as_amadd_w(Register rd, Register rj, Register rk); |
| 1249 |
BufferOffset as_amadd_d(Register rd, Register rj, Register rk); |
| 1250 |
BufferOffset as_amand_w(Register rd, Register rj, Register rk); |
| 1251 |
BufferOffset as_amand_d(Register rd, Register rj, Register rk); |
| 1252 |
BufferOffset as_amor_w(Register rd, Register rj, Register rk); |
| 1253 |
BufferOffset as_amor_d(Register rd, Register rj, Register rk); |
| 1254 |
BufferOffset as_amxor_w(Register rd, Register rj, Register rk); |
| 1255 |
BufferOffset as_amxor_d(Register rd, Register rj, Register rk); |
| 1256 |
BufferOffset as_ammax_w(Register rd, Register rj, Register rk); |
| 1257 |
BufferOffset as_ammax_d(Register rd, Register rj, Register rk); |
| 1258 |
BufferOffset as_ammin_w(Register rd, Register rj, Register rk); |
| 1259 |
BufferOffset as_ammin_d(Register rd, Register rj, Register rk); |
| 1260 |
BufferOffset as_ammax_wu(Register rd, Register rj, Register rk); |
| 1261 |
BufferOffset as_ammax_du(Register rd, Register rj, Register rk); |
| 1262 |
BufferOffset as_ammin_wu(Register rd, Register rj, Register rk); |
| 1263 |
BufferOffset as_ammin_du(Register rd, Register rj, Register rk); |
| 1264 |
|
| 1265 |
BufferOffset as_amswap_db_w(Register rd, Register rj, Register rk); |
| 1266 |
BufferOffset as_amswap_db_d(Register rd, Register rj, Register rk); |
| 1267 |
BufferOffset as_amadd_db_w(Register rd, Register rj, Register rk); |
| 1268 |
BufferOffset as_amadd_db_d(Register rd, Register rj, Register rk); |
| 1269 |
BufferOffset as_amand_db_w(Register rd, Register rj, Register rk); |
| 1270 |
BufferOffset as_amand_db_d(Register rd, Register rj, Register rk); |
| 1271 |
BufferOffset as_amor_db_w(Register rd, Register rj, Register rk); |
| 1272 |
BufferOffset as_amor_db_d(Register rd, Register rj, Register rk); |
| 1273 |
BufferOffset as_amxor_db_w(Register rd, Register rj, Register rk); |
| 1274 |
BufferOffset as_amxor_db_d(Register rd, Register rj, Register rk); |
| 1275 |
BufferOffset as_ammax_db_w(Register rd, Register rj, Register rk); |
| 1276 |
BufferOffset as_ammax_db_d(Register rd, Register rj, Register rk); |
| 1277 |
BufferOffset as_ammin_db_w(Register rd, Register rj, Register rk); |
| 1278 |
BufferOffset as_ammin_db_d(Register rd, Register rj, Register rk); |
| 1279 |
BufferOffset as_ammax_db_wu(Register rd, Register rj, Register rk); |
| 1280 |
BufferOffset as_ammax_db_du(Register rd, Register rj, Register rk); |
| 1281 |
BufferOffset as_ammin_db_wu(Register rd, Register rj, Register rk); |
| 1282 |
BufferOffset as_ammin_db_du(Register rd, Register rj, Register rk); |
| 1283 |
|
| 1284 |
BufferOffset as_ll_w(Register rd, Register rj, int32_t si14); |
| 1285 |
BufferOffset as_ll_d(Register rd, Register rj, int32_t si14); |
| 1286 |
BufferOffset as_sc_w(Register rd, Register rj, int32_t si14); |
| 1287 |
BufferOffset as_sc_d(Register rd, Register rj, int32_t si14); |
| 1288 |
|
| 1289 |
// Barrier instructions |
| 1290 |
BufferOffset as_dbar(int32_t hint); |
| 1291 |
BufferOffset as_ibar(int32_t hint); |
| 1292 |
|
| 1293 |
// FP Arithmetic instructions |
| 1294 |
BufferOffset as_fadd_s(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1295 |
BufferOffset as_fadd_d(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1296 |
BufferOffset as_fsub_s(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1297 |
BufferOffset as_fsub_d(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1298 |
BufferOffset as_fmul_s(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1299 |
BufferOffset as_fmul_d(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1300 |
BufferOffset as_fdiv_s(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1301 |
BufferOffset as_fdiv_d(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1302 |
|
| 1303 |
BufferOffset as_fmadd_s(FloatRegister fd, FloatRegister fj, FloatRegister fk, |
| 1304 |
FloatRegister fa); |
| 1305 |
BufferOffset as_fmadd_d(FloatRegister fd, FloatRegister fj, FloatRegister fk, |
| 1306 |
FloatRegister fa); |
| 1307 |
BufferOffset as_fmsub_s(FloatRegister fd, FloatRegister fj, FloatRegister fk, |
| 1308 |
FloatRegister fa); |
| 1309 |
BufferOffset as_fmsub_d(FloatRegister fd, FloatRegister fj, FloatRegister fk, |
| 1310 |
FloatRegister fa); |
| 1311 |
BufferOffset as_fnmadd_s(FloatRegister fd, FloatRegister fj, FloatRegister fk, |
| 1312 |
FloatRegister fa); |
| 1313 |
BufferOffset as_fnmadd_d(FloatRegister fd, FloatRegister fj, FloatRegister fk, |
| 1314 |
FloatRegister fa); |
| 1315 |
BufferOffset as_fnmsub_s(FloatRegister fd, FloatRegister fj, FloatRegister fk, |
| 1316 |
FloatRegister fa); |
| 1317 |
BufferOffset as_fnmsub_d(FloatRegister fd, FloatRegister fj, FloatRegister fk, |
| 1318 |
FloatRegister fa); |
| 1319 |
|
| 1320 |
BufferOffset as_fmax_s(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1321 |
BufferOffset as_fmax_d(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1322 |
BufferOffset as_fmin_s(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1323 |
BufferOffset as_fmin_d(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1324 |
|
| 1325 |
BufferOffset as_fmaxa_s(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1326 |
BufferOffset as_fmaxa_d(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1327 |
BufferOffset as_fmina_s(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1328 |
BufferOffset as_fmina_d(FloatRegister fd, FloatRegister fj, FloatRegister fk); |
| 1329 |
|
| 1330 |
BufferOffset as_fabs_s(FloatRegister fd, FloatRegister fj); |
| 1331 |
BufferOffset as_fabs_d(FloatRegister fd, FloatRegister fj); |
| 1332 |
BufferOffset as_fneg_s(FloatRegister fd, FloatRegister fj); |
| 1333 |
BufferOffset as_fneg_d(FloatRegister fd, FloatRegister fj); |
| 1334 |
|
| 1335 |
BufferOffset as_fsqrt_s(FloatRegister fd, FloatRegister fj); |
| 1336 |
BufferOffset as_fsqrt_d(FloatRegister fd, FloatRegister fj); |
| 1337 |
BufferOffset as_fcopysign_s(FloatRegister fd, FloatRegister fj, |
| 1338 |
FloatRegister fk); |
| 1339 |
BufferOffset as_fcopysign_d(FloatRegister fd, FloatRegister fj, |
| 1340 |
FloatRegister fk); |
| 1341 |
|
| 1342 |
// FP compare instructions (fcmp.cond.s fcmp.cond.d) |
| 1343 |
BufferOffset as_fcmp_cor(FloatFormat fmt, FloatRegister fj, FloatRegister fk, |
| 1344 |
FPConditionBit cd); |
| 1345 |
BufferOffset as_fcmp_ceq(FloatFormat fmt, FloatRegister fj, FloatRegister fk, |
| 1346 |
FPConditionBit cd); |
| 1347 |
BufferOffset as_fcmp_cne(FloatFormat fmt, FloatRegister fj, FloatRegister fk, |
| 1348 |
FPConditionBit cd); |
| 1349 |
BufferOffset as_fcmp_cle(FloatFormat fmt, FloatRegister fj, FloatRegister fk, |
| 1350 |
FPConditionBit cd); |
| 1351 |
BufferOffset as_fcmp_clt(FloatFormat fmt, FloatRegister fj, FloatRegister fk, |
| 1352 |
FPConditionBit cd); |
| 1353 |
BufferOffset as_fcmp_cun(FloatFormat fmt, FloatRegister fj, FloatRegister fk, |
| 1354 |
FPConditionBit cd); |
| 1355 |
BufferOffset as_fcmp_cueq(FloatFormat fmt, FloatRegister fj, FloatRegister fk, |
| 1356 |
FPConditionBit cd); |
| 1357 |
BufferOffset as_fcmp_cune(FloatFormat fmt, FloatRegister fj, FloatRegister fk, |
| 1358 |
FPConditionBit cd); |
| 1359 |
BufferOffset as_fcmp_cule(FloatFormat fmt, FloatRegister fj, FloatRegister fk, |
| 1360 |
FPConditionBit cd); |
| 1361 |
BufferOffset as_fcmp_cult(FloatFormat fmt, FloatRegister fj, FloatRegister fk, |
| 1362 |
FPConditionBit cd); |
| 1363 |
|
| 1364 |
// FP conversion instructions |
| 1365 |
BufferOffset as_fcvt_s_d(FloatRegister fd, FloatRegister fj); |
| 1366 |
BufferOffset as_fcvt_d_s(FloatRegister fd, FloatRegister fj); |
| 1367 |
|
| 1368 |
BufferOffset as_ffint_s_w(FloatRegister fd, FloatRegister fj); |
| 1369 |
BufferOffset as_ffint_s_l(FloatRegister fd, FloatRegister fj); |
| 1370 |
BufferOffset as_ffint_d_w(FloatRegister fd, FloatRegister fj); |
| 1371 |
BufferOffset as_ffint_d_l(FloatRegister fd, FloatRegister fj); |
| 1372 |
BufferOffset as_ftint_w_s(FloatRegister fd, FloatRegister fj); |
| 1373 |
BufferOffset as_ftint_w_d(FloatRegister fd, FloatRegister fj); |
| 1374 |
BufferOffset as_ftint_l_s(FloatRegister fd, FloatRegister fj); |
| 1375 |
BufferOffset as_ftint_l_d(FloatRegister fd, FloatRegister fj); |
| 1376 |
|
| 1377 |
BufferOffset as_ftintrm_w_s(FloatRegister fd, FloatRegister fj); |
| 1378 |
BufferOffset as_ftintrm_w_d(FloatRegister fd, FloatRegister fj); |
| 1379 |
BufferOffset as_ftintrm_l_s(FloatRegister fd, FloatRegister fj); |
| 1380 |
BufferOffset as_ftintrm_l_d(FloatRegister fd, FloatRegister fj); |
| 1381 |
BufferOffset as_ftintrp_w_s(FloatRegister fd, FloatRegister fj); |
| 1382 |
BufferOffset as_ftintrp_w_d(FloatRegister fd, FloatRegister fj); |
| 1383 |
BufferOffset as_ftintrp_l_s(FloatRegister fd, FloatRegister fj); |
| 1384 |
BufferOffset as_ftintrp_l_d(FloatRegister fd, FloatRegister fj); |
| 1385 |
BufferOffset as_ftintrz_w_s(FloatRegister fd, FloatRegister fj); |
| 1386 |
BufferOffset as_ftintrz_w_d(FloatRegister fd, FloatRegister fj); |
| 1387 |
BufferOffset as_ftintrz_l_s(FloatRegister fd, FloatRegister fj); |
| 1388 |
BufferOffset as_ftintrz_l_d(FloatRegister fd, FloatRegister fj); |
| 1389 |
BufferOffset as_ftintrne_w_s(FloatRegister fd, FloatRegister fj); |
| 1390 |
BufferOffset as_ftintrne_w_d(FloatRegister fd, FloatRegister fj); |
| 1391 |
BufferOffset as_ftintrne_l_s(FloatRegister fd, FloatRegister fj); |
| 1392 |
BufferOffset as_ftintrne_l_d(FloatRegister fd, FloatRegister fj); |
| 1393 |
|
| 1394 |
BufferOffset as_frint_s(FloatRegister fd, FloatRegister fj); |
| 1395 |
BufferOffset as_frint_d(FloatRegister fd, FloatRegister fj); |
| 1396 |
|
| 1397 |
// FP mov instructions |
| 1398 |
BufferOffset as_fmov_s(FloatRegister fd, FloatRegister fj); |
| 1399 |
BufferOffset as_fmov_d(FloatRegister fd, FloatRegister fj); |
| 1400 |
|
| 1401 |
BufferOffset as_fsel(FloatRegister fd, FloatRegister fj, FloatRegister fk, |
| 1402 |
FPConditionBit ca); |
| 1403 |
|
| 1404 |
BufferOffset as_movgr2fr_w(FloatRegister fd, Register rj); |
| 1405 |
BufferOffset as_movgr2fr_d(FloatRegister fd, Register rj); |
| 1406 |
BufferOffset as_movgr2frh_w(FloatRegister fd, Register rj); |
| 1407 |
|
| 1408 |
BufferOffset as_movfr2gr_s(Register rd, FloatRegister fj); |
| 1409 |
BufferOffset as_movfr2gr_d(Register rd, FloatRegister fj); |
| 1410 |
BufferOffset as_movfrh2gr_s(Register rd, FloatRegister fj); |
| 1411 |
|
| 1412 |
BufferOffset as_movgr2fcsr(Register rj); |
| 1413 |
BufferOffset as_movfcsr2gr(Register rd); |
| 1414 |
|
| 1415 |
BufferOffset as_movfr2cf(FPConditionBit cd, FloatRegister fj); |
| 1416 |
BufferOffset as_movcf2fr(FloatRegister fd, FPConditionBit cj); |
| 1417 |
|
| 1418 |
BufferOffset as_movgr2cf(FPConditionBit cd, Register rj); |
| 1419 |
BufferOffset as_movcf2gr(Register rd, FPConditionBit cj); |
| 1420 |
|
| 1421 |
// FP load/store instructions |
| 1422 |
BufferOffset as_fld_s(FloatRegister fd, Register rj, int32_t si12); |
| 1423 |
BufferOffset as_fld_d(FloatRegister fd, Register rj, int32_t si12); |
| 1424 |
BufferOffset as_fst_s(FloatRegister fd, Register rj, int32_t si12); |
| 1425 |
BufferOffset as_fst_d(FloatRegister fd, Register rj, int32_t si12); |
| 1426 |
|
| 1427 |
BufferOffset as_fldx_s(FloatRegister fd, Register rj, Register rk); |
| 1428 |
BufferOffset as_fldx_d(FloatRegister fd, Register rj, Register rk); |
| 1429 |
BufferOffset as_fstx_s(FloatRegister fd, Register rj, Register rk); |
| 1430 |
BufferOffset as_fstx_d(FloatRegister fd, Register rj, Register rk); |
| 1431 |
|
| 1432 |
// label operations |
| 1433 |
void bind(Label* label, BufferOffset boff = BufferOffset()); |
| 1434 |
virtual void bind(InstImm* inst, uintptr_t branch, uintptr_t target) = 0; |
| 1435 |
void bind(CodeLabel* label) { label->target()->bind(currentOffset()); } |
| 1436 |
uint32_t currentOffset() { return nextOffset().getOffset(); } |
| 1437 |
void retarget(Label* label, Label* target); |
| 1438 |
|
| 1439 |
void call(Label* label); |
| 1440 |
void call(void* target); |
| 1441 |
|
| 1442 |
void as_break(uint32_t code); |
| 1443 |
|
| 1444 |
public: |
| 1445 |
static bool SupportsFloatingPoint() { |
| 1446 |
#if defined(__loongarch_hard_float) || defined(JS_SIMULATOR_LOONG64) |
| 1447 |
return true; |
| 1448 |
#else |
| 1449 |
return false; |
| 1450 |
#endif |
| 1451 |
} |
| 1452 |
static bool SupportsUnalignedAccesses() { return true; } |
| 1453 |
static bool SupportsFastUnalignedFPAccesses() { return true; } |
| 1454 |
static bool SupportsFloat64To16() { return false; } |
| 1455 |
static bool SupportsFloat32To16() { return false; } |
| 1456 |
|
| 1457 |
static bool HasRoundInstruction(RoundingMode mode) { return false; } |
| 1458 |
|
| 1459 |
protected: |
| 1460 |
InstImm invertBranch(InstImm branch, BOffImm16 skipOffset); |
| 1461 |
void addPendingJump(BufferOffset src, ImmPtr target, RelocationKind kind) { |
| 1462 |
enoughMemory_ &= jumps_.append(RelativePatch(src, target.value, kind)); |
| 1463 |
if (kind == RelocationKind::JITCODE) { |
| 1464 |
jumpRelocations_.writeUnsigned(src.getOffset()); |
| 1465 |
} |
| 1466 |
} |
| 1467 |
|
| 1468 |
void addLongJump(BufferOffset src, BufferOffset dst) { |
| 1469 |
CodeLabel cl; |
| 1470 |
cl.patchAt()->bind(src.getOffset()); |
| 1471 |
cl.target()->bind(dst.getOffset()); |
| 1472 |
cl.setLinkMode(CodeLabel::JumpImmediate); |
| 1473 |
addCodeLabel(std::move(cl)); |
| 1474 |
} |
| 1475 |
|
| 1476 |
public: |
| 1477 |
void flushBuffer() {} |
| 1478 |
|
| 1479 |
void comment(const char* msg) { spew("; %s", msg); } |
| 1480 |
|
| 1481 |
static uint32_t NopSize() { return 4; } |
| 1482 |
|
| 1483 |
static void PatchWrite_Imm32(CodeLocationLabel label, Imm32 imm); |
| 1484 |
|
| 1485 |
static uint8_t* NextInstruction(uint8_t* instruction, |
| 1486 |
uint32_t* count = nullptr); |
| 1487 |
|
| 1488 |
static void ToggleToJmp(CodeLocationLabel inst_); |
| 1489 |
static void ToggleToCmp(CodeLocationLabel inst_); |
| 1490 |
|
| 1491 |
void verifyHeapAccessDisassembly(uint32_t begin, uint32_t end, |
| 1492 |
const Disassembler::HeapAccess& heapAccess) { |
| 1493 |
// Implement this if we implement a disassembler. |
| 1494 |
} |
| 1495 |
}; // AssemblerLOONG64 |
| 1496 |
|
| 1497 |
// andi r0, r0, 0 |
| 1498 |
const uint32_t NopInst = 0x03400000; |
| 1499 |
|
| 1500 |
// An Instruction is a structure for both encoding and decoding any and all |
| 1501 |
// LoongArch instructions. |
| 1502 |
class Instruction { |
| 1503 |
public: |
| 1504 |
uint32_t data; |
| 1505 |
|
| 1506 |
protected: |
| 1507 |
// Standard constructor |
| 1508 |
Instruction(uint32_t data_) : data(data_) {} |
| 1509 |
// You should never create an instruction directly. You should create a |
| 1510 |
// more specific instruction which will eventually call one of these |
| 1511 |
// constructors for you. |
| 1512 |
|
| 1513 |
public: |
| 1514 |
uint32_t encode() const { return data; } |
| 1515 |
|
| 1516 |
void makeNop() { data = NopInst; } |
| 1517 |
|
| 1518 |
void setData(uint32_t data) { this->data = data; } |
| 1519 |
|
| 1520 |
const Instruction& operator=(const Instruction& src) { |
| 1521 |
data = src.data; |
| 1522 |
return *this; |
| 1523 |
} |
| 1524 |
|
| 1525 |
// Extract the one particular bit. |
| 1526 |
uint32_t extractBit(uint32_t bit) { return (encode() >> bit) & 1; } |
| 1527 |
// Extract a bit field out of the instruction |
| 1528 |
uint32_t extractBitField(uint32_t hi, uint32_t lo) { |
| 1529 |
return (encode() >> lo) & ((2 << (hi - lo)) - 1); |
| 1530 |
} |
| 1531 |
|
| 1532 |
// Get the next instruction in the instruction stream. |
| 1533 |
// This does neat things like ignoreconstant pools and their guards. |
| 1534 |
Instruction* next(); |
| 1535 |
|
| 1536 |
// Sometimes, an api wants a uint32_t (or a pointer to it) rather than |
| 1537 |
// an instruction. raw() just coerces this into a pointer to a uint32_t |
| 1538 |
const uint32_t* raw() const { return &data; } |
| 1539 |
uint32_t size() const { return 4; } |
| 1540 |
}; // Instruction |
| 1541 |
|
| 1542 |
// make sure that it is the right size |
| 1543 |
static_assert(sizeof(Instruction) == 4, |
| 1544 |
"Size of Instruction class has to be 4 bytes."); |
| 1545 |
|
| 1546 |
class InstNOP : public Instruction { |
| 1547 |
public: |
| 1548 |
InstNOP() : Instruction(NopInst) {} |
| 1549 |
}; |
| 1550 |
|
| 1551 |
// Class for register type instructions. |
| 1552 |
class InstReg : public Instruction { |
| 1553 |
public: |
| 1554 |
InstReg(OpcodeField op, Register rj, Register rd) |
| 1555 |
: Instruction(op | RJ(rj) | RD(rd)) {} |
| 1556 |
InstReg(OpcodeField op, Register rk, Register rj, Register rd) |
| 1557 |
: Instruction(op | RK(rk) | RJ(rj) | RD(rd)) {} |
| 1558 |
InstReg(OpcodeField op, uint32_t sa, Register rk, Register rj, Register rd, |
| 1559 |
uint32_t sa_bit) |
| 1560 |
: Instruction(sa_bit == 2 ? op | SA2(sa) | RK(rk) | RJ(rj) | RD(rd) |
| 1561 |
: op | SA3(sa) | RK(rk) | RJ(rj) | RD(rd)) { |
| 1562 |
MOZ_ASSERT(sa_bit == 2 || sa_bit == 3); |
| 1563 |
} |
| 1564 |
InstReg(OpcodeField op, Register rj, Register rd, bool HasRd) |
| 1565 |
: Instruction(HasRd ? op | RJ(rj) | RD(rd) : op | RK(rj) | RJ(rd)) {} |
| 1566 |
|
| 1567 |
// For floating-point |
| 1568 |
InstReg(OpcodeField op, Register rj, FloatRegister fd) |
| 1569 |
: Instruction(op | RJ(rj) | FD(fd)) {} |
| 1570 |
InstReg(OpcodeField op, FloatRegister fj, FloatRegister fd) |
| 1571 |
: Instruction(op | FJ(fj) | FD(fd)) {} |
| 1572 |
InstReg(OpcodeField op, FloatRegister fk, FloatRegister fj, FloatRegister fd) |
| 1573 |
: Instruction(op | FK(fk) | FJ(fj) | FD(fd)) {} |
| 1574 |
InstReg(OpcodeField op, Register rk, Register rj, FloatRegister fd) |
| 1575 |
: Instruction(op | RK(rk) | RJ(rj) | FD(fd)) {} |
| 1576 |
InstReg(OpcodeField op, FloatRegister fa, FloatRegister fk, FloatRegister fj, |
| 1577 |
FloatRegister fd) |
| 1578 |
: Instruction(op | FA(fa) | FK(fk) | FJ(fj) | FD(fd)) {} |
| 1579 |
InstReg(OpcodeField op, AssemblerLOONG64::FPConditionBit ca, FloatRegister fk, |
| 1580 |
FloatRegister fj, FloatRegister fd) |
| 1581 |
: Instruction(op | ca << CAShift | FK(fk) | FJ(fj) | FD(fd)) { |
| 1582 |
MOZ_ASSERT(op == op_fsel); |
| 1583 |
} |
| 1584 |
InstReg(OpcodeField op, FloatRegister fj, Register rd) |
| 1585 |
: Instruction(op | FJ(fj) | RD(rd)) { |
| 1586 |
MOZ_ASSERT((op == op_movfr2gr_s) || (op == op_movfr2gr_d) || |
| 1587 |
(op == op_movfrh2gr_s)); |
| 1588 |
} |
| 1589 |
InstReg(OpcodeField op, Register rj, uint32_t fd) |
| 1590 |
: Instruction(op | RJ(rj) | fd) { |
| 1591 |
MOZ_ASSERT(op == op_movgr2fcsr); |
| 1592 |
} |
| 1593 |
InstReg(OpcodeField op, uint32_t fj, Register rd) |
| 1594 |
: Instruction(op | (fj << FJShift) | RD(rd)) { |
| 1595 |
MOZ_ASSERT(op == op_movfcsr2gr); |
| 1596 |
} |
| 1597 |
InstReg(OpcodeField op, FloatRegister fj, AssemblerLOONG64::FPConditionBit cd) |
| 1598 |
: Instruction(op | FJ(fj) | cd) { |
| 1599 |
MOZ_ASSERT(op == op_movfr2cf); |
| 1600 |
} |
| 1601 |
InstReg(OpcodeField op, AssemblerLOONG64::FPConditionBit cj, FloatRegister fd) |
| 1602 |
: Instruction(op | (cj << CJShift) | FD(fd)) { |
| 1603 |
MOZ_ASSERT(op == op_movcf2fr); |
| 1604 |
} |
| 1605 |
InstReg(OpcodeField op, Register rj, AssemblerLOONG64::FPConditionBit cd) |
| 1606 |
: Instruction(op | RJ(rj) | cd) { |
| 1607 |
MOZ_ASSERT(op == op_movgr2cf); |
| 1608 |
} |
| 1609 |
InstReg(OpcodeField op, AssemblerLOONG64::FPConditionBit cj, Register rd) |
| 1610 |
: Instruction(op | (cj << CJShift) | RD(rd)) { |
| 1611 |
MOZ_ASSERT(op == op_movcf2gr); |
| 1612 |
} |
| 1613 |
InstReg(OpcodeField op, int32_t cond, FloatRegister fk, FloatRegister fj, |
| 1614 |
AssemblerLOONG64::FPConditionBit cd) |
| 1615 |
: Instruction(op | (cond & CONDMask) << CONDShift | FK(fk) | FJ(fj) | |
| 1616 |
(cd & CDMask)) { |
| 1617 |
MOZ_ASSERT(is_uintN(cond, 5)); |
| 1618 |
} |
| 1619 |
|
| 1620 |
uint32_t extractRK() { |
| 1621 |
return extractBitField(RKShift + RKBits - 1, RKShift); |
| 1622 |
} |
| 1623 |
uint32_t extractRJ() { |
| 1624 |
return extractBitField(RJShift + RJBits - 1, RJShift); |
| 1625 |
} |
| 1626 |
uint32_t extractRD() { |
| 1627 |
return extractBitField(RDShift + RDBits - 1, RDShift); |
| 1628 |
} |
| 1629 |
uint32_t extractSA2() { |
| 1630 |
return extractBitField(SAShift + SA2Bits - 1, SAShift); |
| 1631 |
} |
| 1632 |
uint32_t extractSA3() { |
| 1633 |
return extractBitField(SAShift + SA3Bits - 1, SAShift); |
| 1634 |
} |
| 1635 |
}; |
| 1636 |
|
| 1637 |
// Class for branch, load and store instructions with immediate offset. |
| 1638 |
class InstImm : public Instruction { |
| 1639 |
public: |
| 1640 |
void extractImm16(BOffImm16* dest); |
| 1641 |
uint32_t genImm(int32_t value, uint32_t value_bits) { |
| 1642 |
uint32_t imm = value & Imm5Mask; |
| 1643 |
if (value_bits == 6) { |
| 1644 |
imm = value & Imm6Mask; |
| 1645 |
} else if (value_bits == 12) { |
| 1646 |
imm = value & Imm12Mask; |
| 1647 |
} else if (value_bits == 14) { |
| 1648 |
imm = value & Imm14Mask; |
| 1649 |
} |
| 1650 |
|
| 1651 |
return imm; |
| 1652 |
} |
| 1653 |
|
| 1654 |
InstImm(OpcodeField op, int32_t value, Register rj, Register rd, |
| 1655 |
uint32_t value_bits) |
| 1656 |
: Instruction(op | genImm(value, value_bits) << RKShift | RJ(rj) | |
| 1657 |
RD(rd)) { |
| 1658 |
MOZ_ASSERT(value_bits == 5 || value_bits == 6 || value_bits == 12 || |
| 1659 |
value_bits == 14); |
| 1660 |
} |
| 1661 |
InstImm(OpcodeField op, BOffImm16 off, Register rj, Register rd) |
| 1662 |
: Instruction(op | (off.encode() & Imm16Mask) << Imm16Shift | RJ(rj) | |
| 1663 |
RD(rd)) {} |
| 1664 |
InstImm(OpcodeField op, int32_t si21, Register rj, bool NotHasRd) |
| 1665 |
: Instruction(NotHasRd ? op | (si21 & Imm16Mask) << RKShift | RJ(rj) | |
| 1666 |
(si21 & Imm21Mask) >> 16 |
| 1667 |
: op | (si21 & Imm20Mask) << Imm20Shift | RD(rj)) { |
| 1668 |
if (NotHasRd) { |
| 1669 |
MOZ_ASSERT(op == op_beqz || op == op_bnez); |
| 1670 |
MOZ_ASSERT(is_intN(si21, 21)); |
| 1671 |
} else { |
| 1672 |
MOZ_ASSERT(op == op_lu12i_w || op == op_lu32i_d || op == op_pcaddi || |
| 1673 |
op == op_pcaddu12i || op == op_pcaddu18i || |
| 1674 |
op == op_pcalau12i); |
| 1675 |
// si20 |
| 1676 |
MOZ_ASSERT(is_intN(si21, 20) || is_uintN(si21, 20)); |
| 1677 |
} |
| 1678 |
} |
| 1679 |
InstImm(OpcodeField op, int32_t si21, AssemblerLOONG64::FPConditionBit cj, |
| 1680 |
bool isNotEqual) |
| 1681 |
: Instruction(isNotEqual |
| 1682 |
? op | (si21 & Imm16Mask) << RKShift | |
| 1683 |
(cj + 8) << CJShift | (si21 & Imm21Mask) >> 16 |
| 1684 |
: op | (si21 & Imm16Mask) << RKShift | cj << CJShift | |
| 1685 |
(si21 & Imm21Mask) >> 16) { |
| 1686 |
MOZ_ASSERT(is_intN(si21, 21)); |
| 1687 |
MOZ_ASSERT(op == op_bcz); |
| 1688 |
MOZ_ASSERT(cj >= 0 && cj <= 7); |
| 1689 |
} |
| 1690 |
InstImm(OpcodeField op, Imm16 off, Register rj, Register rd) |
| 1691 |
: Instruction(op | (off.encode() & Imm16Mask) << Imm16Shift | RJ(rj) | |
| 1692 |
RD(rd)) {} |
| 1693 |
InstImm(OpcodeField op, int32_t bit15) |
| 1694 |
: Instruction(op | (bit15 & Imm15Mask)) { |
| 1695 |
MOZ_ASSERT(is_uintN(bit15, 15)); |
| 1696 |
} |
| 1697 |
|
| 1698 |
InstImm(OpcodeField op, int32_t bit26, bool jump) |
| 1699 |
: Instruction(op | (bit26 & Imm16Mask) << Imm16Shift | |
| 1700 |
(bit26 & Imm26Mask) >> 16) { |
| 1701 |
MOZ_ASSERT(is_intN(bit26, 26)); |
| 1702 |
} |
| 1703 |
InstImm(OpcodeField op, int32_t si12, Register rj, int32_t hint) |
| 1704 |
: Instruction(op | (si12 & Imm12Mask) << Imm12Shift | RJ(rj) | |
| 1705 |
(hint & HINTMask)) { |
| 1706 |
MOZ_ASSERT(op == op_preld); |
| 1707 |
} |
| 1708 |
InstImm(OpcodeField op, int32_t msb, int32_t lsb, Register rj, Register rd, |
| 1709 |
uint32_t sb_bits) |
| 1710 |
: Instruction((sb_bits == 5) |
| 1711 |
? op | (msb & MSBWMask) << MSBWShift | |
| 1712 |
(lsb & LSBWMask) << LSBWShift | RJ(rj) | RD(rd) |
| 1713 |
: op | (msb & MSBDMask) << MSBDShift | |
| 1714 |
(lsb & LSBDMask) << LSBDShift | RJ(rj) | RD(rd)) { |
| 1715 |
MOZ_ASSERT(sb_bits == 5 || sb_bits == 6); |
| 1716 |
MOZ_ASSERT(op == op_bstr_w || op == op_bstrins_d || op == op_bstrpick_d); |
| 1717 |
} |
| 1718 |
InstImm(OpcodeField op, int32_t msb, int32_t lsb, Register rj, Register rd) |
| 1719 |
: Instruction(op | (msb & MSBWMask) << MSBWShift | |
| 1720 |
((lsb + 0x20) & LSBDMask) << LSBWShift | RJ(rj) | RD(rd)) { |
| 1721 |
MOZ_ASSERT(op == op_bstr_w); |
| 1722 |
} |
| 1723 |
|
| 1724 |
// For floating-point loads and stores. |
| 1725 |
InstImm(OpcodeField op, int32_t si12, Register rj, FloatRegister fd) |
| 1726 |
: Instruction(op | (si12 & Imm12Mask) << Imm12Shift | RJ(rj) | FD(fd)) { |
| 1727 |
MOZ_ASSERT(is_intN(si12, 12)); |
| 1728 |
} |
| 1729 |
|
| 1730 |
void setOpcode(OpcodeField op, uint32_t opBits) { |
| 1731 |
// opBits not greater than 24. |
| 1732 |
MOZ_ASSERT(opBits < 25); |
| 1733 |
uint32_t OpcodeShift = 32 - opBits; |
| 1734 |
uint32_t OpcodeMask = ((1 << opBits) - 1) << OpcodeShift; |
| 1735 |
data = (data & ~OpcodeMask) | op; |
| 1736 |
} |
| 1737 |
uint32_t extractRK() { |
| 1738 |
return extractBitField(RKShift + RKBits - 1, RKShift); |
| 1739 |
} |
| 1740 |
uint32_t extractRJ() { |
| 1741 |
return extractBitField(RJShift + RJBits - 1, RJShift); |
| 1742 |
} |
| 1743 |
void setRJ(uint32_t rj) { |
| 1744 |
data = (data & ~(RJMask << RJShift)) | (rj << RJShift); |
| 1745 |
} |
| 1746 |
uint32_t extractRD() { |
| 1747 |
return extractBitField(RDShift + RDBits - 1, RDShift); |
| 1748 |
} |
| 1749 |
uint32_t extractImm16Value() { |
| 1750 |
return extractBitField(Imm16Shift + Imm16Bits - 1, Imm16Shift); |
| 1751 |
} |
| 1752 |
void setBOffImm16(BOffImm16 off) { |
| 1753 |
// Reset immediate field and replace it |
| 1754 |
data = (data & ~BOffImm16Mask) | (off.encode() << Imm16Shift); |
| 1755 |
} |
| 1756 |
void setImm21(int32_t off) { |
| 1757 |
// Reset immediate field and replace it |
| 1758 |
uint32_t low16 = (off >> 2) & Imm16Mask; |
| 1759 |
int32_t high5 = (off >> 18) & Imm5Mask; |
| 1760 |
uint32_t fcc_info = (data >> 5) & 0x1F; |
| 1761 |
data = (data & ~BOffImm26Mask) | (low16 << Imm16Shift) | high5 | |
| 1762 |
(fcc_info << 5); |
| 1763 |
} |
| 1764 |
}; |
| 1765 |
|
| 1766 |
// Class for Jump type instructions. |
| 1767 |
class InstJump : public Instruction { |
| 1768 |
public: |
| 1769 |
InstJump(OpcodeField op, JOffImm26 off) |
| 1770 |
: Instruction(op | (off.encode() & Imm16Mask) << Imm16Shift | |
| 1771 |
(off.encode() & Imm26Mask) >> 16) { |
| 1772 |
MOZ_ASSERT(op == op_b || op == op_bl); |
| 1773 |
} |
| 1774 |
|
| 1775 |
void setJOffImm26(JOffImm26 off) { |
| 1776 |
// Reset immediate field and replace it |
| 1777 |
data = (data & ~BOffImm26Mask) | |
| 1778 |
((off.encode() & Imm16Mask) << Imm16Shift) | |
| 1779 |
((off.encode() >> 16) & 0x3ff); |
| 1780 |
} |
| 1781 |
uint32_t extractImm26Value() { |
| 1782 |
return extractBitField(Imm26Shift + Imm26Bits - 1, Imm26Shift); |
| 1783 |
} |
| 1784 |
}; |
| 1785 |
|
| 1786 |
class ABIArgGenerator { |
| 1787 |
public: |
| 1788 |
ABIArgGenerator() |
| 1789 |
: intRegIndex_(0), floatRegIndex_(0), stackOffset_(0), current_() {} |
| 1790 |
|
| 1791 |
ABIArg next(MIRType argType); |
| 1792 |
ABIArg& current() { return current_; } |
| 1793 |
uint32_t stackBytesConsumedSoFar() const { return stackOffset_; } |
| 1794 |
void increaseStackOffset(uint32_t bytes) { stackOffset_ += bytes; } |
| 1795 |
|
| 1796 |
protected: |
| 1797 |
unsigned intRegIndex_; |
| 1798 |
unsigned floatRegIndex_; |
| 1799 |
uint32_t stackOffset_; |
| 1800 |
ABIArg current_; |
| 1801 |
}; |
| 1802 |
|
| 1803 |
class Assembler : public AssemblerLOONG64 { |
| 1804 |
public: |
| 1805 |
Assembler() : AssemblerLOONG64() {} |
| 1806 |
|
| 1807 |
static uintptr_t GetPointer(uint8_t*); |
| 1808 |
|
| 1809 |
using AssemblerLOONG64::bind; |
| 1810 |
|
| 1811 |
static void Bind(uint8_t* rawCode, const CodeLabel& label); |
| 1812 |
|
| 1813 |
void processCodeLabels(uint8_t* rawCode); |
| 1814 |
|
| 1815 |
static void TraceJumpRelocations(JSTracer* trc, JitCode* code, |
| 1816 |
CompactBufferReader& reader); |
| 1817 |
static void TraceDataRelocations(JSTracer* trc, JitCode* code, |
| 1818 |
CompactBufferReader& reader); |
| 1819 |
|
| 1820 |
void bind(InstImm* inst, uintptr_t branch, uintptr_t target); |
| 1821 |
|
| 1822 |
// Copy the assembly code to the given buffer, and perform any pending |
| 1823 |
// relocations relying on the target address. |
| 1824 |
void executableCopy(uint8_t* buffer); |
| 1825 |
|
| 1826 |
static uint32_t PatchWrite_NearCallSize(); |
| 1827 |
|
| 1828 |
static uint64_t ExtractLoad64Value(Instruction* inst0); |
| 1829 |
static void UpdateLoad64Value(Instruction* inst0, uint64_t value); |
| 1830 |
static void WriteLoad64Instructions(Instruction* inst0, Register reg, |
| 1831 |
uint64_t value); |
| 1832 |
|
| 1833 |
static void PatchWrite_NearCall(CodeLocationLabel start, |
| 1834 |
CodeLocationLabel toCall); |
| 1835 |
static void PatchDataWithValueCheck(CodeLocationLabel label, ImmPtr newValue, |
| 1836 |
ImmPtr expectedValue); |
| 1837 |
static void PatchDataWithValueCheck(CodeLocationLabel label, |
| 1838 |
PatchedImmPtr newValue, |
| 1839 |
PatchedImmPtr expectedValue); |
| 1840 |
|
| 1841 |
static uint64_t ExtractInstructionImmediate(uint8_t* code); |
| 1842 |
|
| 1843 |
static void ToggleCall(CodeLocationLabel inst_, bool enabled); |
| 1844 |
}; // Assembler |
| 1845 |
|
| 1846 |
static const uint32_t NumIntArgRegs = 8; |
| 1847 |
static const uint32_t NumFloatArgRegs = 8; |
| 1848 |
|
| 1849 |
static inline bool GetIntArgReg(uint32_t usedIntArgs, Register* out) { |
| 1850 |
if (usedIntArgs < NumIntArgRegs) { |
| 1851 |
*out = Register::FromCode(a0.code() + usedIntArgs); |
| 1852 |
return true; |
| 1853 |
} |
| 1854 |
return false; |
| 1855 |
} |
| 1856 |
|
| 1857 |
static inline bool GetFloatArgReg(uint32_t usedFloatArgs, FloatRegister* out) { |
| 1858 |
if (usedFloatArgs < NumFloatArgRegs) { |
| 1859 |
*out = FloatRegister::FromCode(f0.code() + usedFloatArgs); |
| 1860 |
return true; |
| 1861 |
} |
| 1862 |
return false; |
| 1863 |
} |
| 1864 |
|
| 1865 |
// Get a register in which we plan to put a quantity that will be used as an |
| 1866 |
// integer argument. This differs from GetIntArgReg in that if we have no more |
| 1867 |
// actual argument registers to use we will fall back on using whatever |
| 1868 |
// CallTempReg* don't overlap the argument registers, and only fail once those |
| 1869 |
// run out too. |
| 1870 |
static inline bool GetTempRegForIntArg(uint32_t usedIntArgs, |
| 1871 |
uint32_t usedFloatArgs, Register* out) { |
| 1872 |
// NOTE: We can't properly determine which regs are used if there are |
| 1873 |
// float arguments. If this is needed, we will have to guess. |
| 1874 |
MOZ_ASSERT(usedFloatArgs == 0); |
| 1875 |
|
| 1876 |
if (GetIntArgReg(usedIntArgs, out)) { |
| 1877 |
return true; |
| 1878 |
} |
| 1879 |
// Unfortunately, we have to assume things about the point at which |
| 1880 |
// GetIntArgReg returns false, because we need to know how many registers it |
| 1881 |
// can allocate. |
| 1882 |
usedIntArgs -= NumIntArgRegs; |
| 1883 |
if (usedIntArgs >= NumCallTempNonArgRegs) { |
| 1884 |
return false; |
| 1885 |
} |
| 1886 |
*out = CallTempNonArgRegs[usedIntArgs]; |
| 1887 |
return true; |
| 1888 |
} |
| 1889 |
|
| 1890 |
} // namespace jit |
| 1891 |
} // namespace js |
| 1892 |
|
| 1893 |
#endif /* jit_loong64_Assembler_loong64_h */ |