| 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 |
#include "jit/arm/MacroAssembler-arm.h" |
| 8 |
|
| 9 |
#include "mozilla/Casting.h" |
| 10 |
#include "mozilla/DebugOnly.h" |
| 11 |
#include "mozilla/MathAlgorithms.h" |
| 12 |
#include "mozilla/Maybe.h" |
| 13 |
|
| 14 |
#include "jsmath.h" |
| 15 |
|
| 16 |
#include "jit/arm/Simulator-arm.h" |
| 17 |
#include "jit/AtomicOp.h" |
| 18 |
#include "jit/AtomicOperations.h" |
| 19 |
#include "jit/Bailouts.h" |
| 20 |
#include "jit/BaselineFrame.h" |
| 21 |
#include "jit/JitFrames.h" |
| 22 |
#include "jit/JitRuntime.h" |
| 23 |
#include "jit/MacroAssembler.h" |
| 24 |
#include "jit/MoveEmitter.h" |
| 25 |
#include "jit/ProcessExecutableMemory.h" |
| 26 |
#include "js/ScalarType.h" // js::Scalar::Type |
| 27 |
#include "util/Memory.h" |
| 28 |
#include "vm/BigIntType.h" |
| 29 |
#include "vm/JitActivation.h" // js::jit::JitActivation |
| 30 |
#include "vm/JSContext.h" |
| 31 |
#include "vm/StringType.h" |
| 32 |
#include "wasm/WasmStubs.h" |
| 33 |
|
| 34 |
#include "jit/MacroAssembler-inl.h" |
| 35 |
|
| 36 |
using namespace js; |
| 37 |
using namespace jit; |
| 38 |
|
| 39 |
using mozilla::Abs; |
| 40 |
using mozilla::BitwiseCast; |
| 41 |
using mozilla::DebugOnly; |
| 42 |
using mozilla::IsPositiveZero; |
| 43 |
using mozilla::Maybe; |
| 44 |
|
| 45 |
bool isValueDTRDCandidate(ValueOperand& val) { |
| 46 |
// In order to be used for a DTRD memory function, the two target registers |
| 47 |
// need to be a) Adjacent, with the tag larger than the payload, and b) |
| 48 |
// Aligned to a multiple of two. |
| 49 |
if ((val.typeReg().code() != (val.payloadReg().code() + 1))) { |
| 50 |
return false; |
| 51 |
} |
| 52 |
if ((val.payloadReg().code() & 1) != 0) { |
| 53 |
return false; |
| 54 |
} |
| 55 |
return true; |
| 56 |
} |
| 57 |
|
| 58 |
void MacroAssemblerARM::convertBoolToInt32(Register source, Register dest) { |
| 59 |
// Note that C++ bool is only 1 byte, so zero extend it to clear the |
| 60 |
// higher-order bits. |
| 61 |
as_and(dest, source, Imm8(0xff)); |
| 62 |
} |
| 63 |
|
| 64 |
void MacroAssemblerARM::convertInt32ToDouble(Register src, |
| 65 |
FloatRegister dest_) { |
| 66 |
// Direct conversions aren't possible. |
| 67 |
VFPRegister dest = VFPRegister(dest_); |
| 68 |
as_vxfer(src, InvalidReg, dest.sintOverlay(), CoreToFloat); |
| 69 |
as_vcvt(dest, dest.sintOverlay()); |
| 70 |
} |
| 71 |
|
| 72 |
void MacroAssemblerARM::convertInt32ToDouble(const Address& src, |
| 73 |
FloatRegister dest) { |
| 74 |
ScratchDoubleScope scratch(asMasm()); |
| 75 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 76 |
ma_vldr(src, scratch, scratch2); |
| 77 |
as_vcvt(dest, VFPRegister(scratch).sintOverlay()); |
| 78 |
} |
| 79 |
|
| 80 |
void MacroAssemblerARM::convertInt32ToDouble(const BaseIndex& src, |
| 81 |
FloatRegister dest) { |
| 82 |
Register base = src.base; |
| 83 |
uint32_t scale = Imm32::ShiftOf(src.scale).value; |
| 84 |
|
| 85 |
ScratchRegisterScope scratch(asMasm()); |
| 86 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 87 |
|
| 88 |
if (src.offset != 0) { |
| 89 |
ma_add(base, Imm32(src.offset), scratch, scratch2); |
| 90 |
base = scratch; |
| 91 |
} |
| 92 |
ma_ldr(DTRAddr(base, DtrRegImmShift(src.index, LSL, scale)), scratch); |
| 93 |
convertInt32ToDouble(scratch, dest); |
| 94 |
} |
| 95 |
|
| 96 |
void MacroAssemblerARM::convertUInt32ToDouble(Register src, |
| 97 |
FloatRegister dest_) { |
| 98 |
// Direct conversions aren't possible. |
| 99 |
VFPRegister dest = VFPRegister(dest_); |
| 100 |
as_vxfer(src, InvalidReg, dest.uintOverlay(), CoreToFloat); |
| 101 |
as_vcvt(dest, dest.uintOverlay()); |
| 102 |
} |
| 103 |
|
| 104 |
static const double TO_DOUBLE_HIGH_SCALE = 0x100000000; |
| 105 |
|
| 106 |
void MacroAssemblerARM::convertUInt32ToFloat32(Register src, |
| 107 |
FloatRegister dest_) { |
| 108 |
// Direct conversions aren't possible. |
| 109 |
VFPRegister dest = VFPRegister(dest_); |
| 110 |
as_vxfer(src, InvalidReg, dest.uintOverlay(), CoreToFloat); |
| 111 |
as_vcvt(VFPRegister(dest).singleOverlay(), dest.uintOverlay()); |
| 112 |
} |
| 113 |
|
| 114 |
void MacroAssemblerARM::convertDoubleToFloat32(FloatRegister src, |
| 115 |
FloatRegister dest, |
| 116 |
Condition c) { |
| 117 |
as_vcvt(VFPRegister(dest).singleOverlay(), VFPRegister(src), false, c); |
| 118 |
} |
| 119 |
|
| 120 |
// Checks whether a double is representable as a 32-bit integer. If so, the |
| 121 |
// integer is written to the output register. Otherwise, a bailout is taken to |
| 122 |
// the given snapshot. This function overwrites the scratch float register. |
| 123 |
void MacroAssemblerARM::convertDoubleToInt32(FloatRegister src, Register dest, |
| 124 |
Label* fail, |
| 125 |
bool negativeZeroCheck) { |
| 126 |
// Convert the floating point value to an integer, if it did not fit, then |
| 127 |
// when we convert it *back* to a float, it will have a different value, |
| 128 |
// which we can test. |
| 129 |
ScratchDoubleScope scratchDouble(asMasm()); |
| 130 |
ScratchRegisterScope scratch(asMasm()); |
| 131 |
|
| 132 |
FloatRegister scratchSIntReg = scratchDouble.sintOverlay(); |
| 133 |
|
| 134 |
ma_vcvt_F64_I32(src, scratchSIntReg); |
| 135 |
// Move the value into the dest register. |
| 136 |
ma_vxfer(scratchSIntReg, dest); |
| 137 |
ma_vcvt_I32_F64(scratchSIntReg, scratchDouble); |
| 138 |
ma_vcmp(src, scratchDouble); |
| 139 |
as_vmrs(pc); |
| 140 |
ma_b(fail, Assembler::VFP_NotEqualOrUnordered); |
| 141 |
|
| 142 |
if (negativeZeroCheck) { |
| 143 |
Label nonzero; |
| 144 |
as_cmp(dest, Imm8(0)); |
| 145 |
ma_b(&nonzero, Assembler::NotEqual); |
| 146 |
// Test and bail for -0.0, when integer result is 0. Move the top word |
| 147 |
// of the double into the output reg, if it is non-zero, then the |
| 148 |
// original value was -0.0. |
| 149 |
as_vxfer(dest, InvalidReg, src, FloatToCore, Assembler::Always, 1); |
| 150 |
as_cmp(dest, Imm8(0)); |
| 151 |
ma_b(fail, Assembler::LessThan); |
| 152 |
ma_mov(Imm32(0), dest); |
| 153 |
bind(&nonzero); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
// Checks whether a float32 is representable as a 32-bit integer. If so, the |
| 158 |
// integer is written to the output register. Otherwise, a bailout is taken to |
| 159 |
// the given snapshot. This function overwrites the scratch float register. |
| 160 |
void MacroAssemblerARM::convertFloat32ToInt32(FloatRegister src, Register dest, |
| 161 |
Label* fail, |
| 162 |
bool negativeZeroCheck) { |
| 163 |
// Converting the floating point value to an integer and then converting it |
| 164 |
// back to a float32 would not work, as float to int32 conversions are |
| 165 |
// clamping (e.g. float(INT32_MAX + 1) would get converted into INT32_MAX |
| 166 |
// and then back to float(INT32_MAX + 1)). If this ever happens, we just |
| 167 |
// bail out. |
| 168 |
ScratchFloat32Scope scratchFloat(asMasm()); |
| 169 |
ScratchRegisterScope scratch(asMasm()); |
| 170 |
|
| 171 |
FloatRegister ScratchSIntReg = scratchFloat.sintOverlay(); |
| 172 |
ma_vcvt_F32_I32(src, ScratchSIntReg); |
| 173 |
|
| 174 |
// Store the result |
| 175 |
ma_vxfer(ScratchSIntReg, dest); |
| 176 |
|
| 177 |
ma_vcvt_I32_F32(ScratchSIntReg, scratchFloat); |
| 178 |
ma_vcmp(src, scratchFloat); |
| 179 |
as_vmrs(pc); |
| 180 |
ma_b(fail, Assembler::VFP_NotEqualOrUnordered); |
| 181 |
|
| 182 |
// Bail out in the clamped cases. |
| 183 |
ma_cmp(dest, Imm32(0x7fffffff), scratch); |
| 184 |
ma_cmp(dest, Imm32(0x80000000), scratch, Assembler::NotEqual); |
| 185 |
ma_b(fail, Assembler::Equal); |
| 186 |
|
| 187 |
if (negativeZeroCheck) { |
| 188 |
Label nonzero; |
| 189 |
as_cmp(dest, Imm8(0)); |
| 190 |
ma_b(&nonzero, Assembler::NotEqual); |
| 191 |
// Test and bail for -0.0, when integer result is 0. Move the float into |
| 192 |
// the output reg, and if it is non-zero then the original value was |
| 193 |
// -0.0 |
| 194 |
as_vxfer(dest, InvalidReg, VFPRegister(src).singleOverlay(), FloatToCore, |
| 195 |
Assembler::Always, 0); |
| 196 |
as_cmp(dest, Imm8(0)); |
| 197 |
ma_b(fail, Assembler::LessThan); |
| 198 |
ma_mov(Imm32(0), dest); |
| 199 |
bind(&nonzero); |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
void MacroAssemblerARM::convertFloat32ToDouble(FloatRegister src, |
| 204 |
FloatRegister dest) { |
| 205 |
MOZ_ASSERT(dest.isDouble()); |
| 206 |
MOZ_ASSERT(src.isSingle()); |
| 207 |
as_vcvt(VFPRegister(dest), VFPRegister(src).singleOverlay()); |
| 208 |
} |
| 209 |
|
| 210 |
void MacroAssemblerARM::convertInt32ToFloat32(Register src, |
| 211 |
FloatRegister dest) { |
| 212 |
// Direct conversions aren't possible. |
| 213 |
as_vxfer(src, InvalidReg, dest.sintOverlay(), CoreToFloat); |
| 214 |
as_vcvt(dest.singleOverlay(), dest.sintOverlay()); |
| 215 |
} |
| 216 |
|
| 217 |
void MacroAssemblerARM::convertInt32ToFloat32(const Address& src, |
| 218 |
FloatRegister dest) { |
| 219 |
ScratchFloat32Scope scratch(asMasm()); |
| 220 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 221 |
ma_vldr(src, scratch, scratch2); |
| 222 |
as_vcvt(dest, VFPRegister(scratch).sintOverlay()); |
| 223 |
} |
| 224 |
|
| 225 |
void MacroAssemblerARM::convertFloat32ToFloat16(FloatRegister src, |
| 226 |
FloatRegister dest) { |
| 227 |
MOZ_ASSERT(ARMFlags::HasFPHalfPrecision()); |
| 228 |
MOZ_ASSERT(src.isSingle()); |
| 229 |
MOZ_ASSERT(dest.isSingle()); |
| 230 |
|
| 231 |
as_vcvtb_s2h(dest, src); |
| 232 |
} |
| 233 |
|
| 234 |
void MacroAssemblerARM::convertFloat16ToFloat32(FloatRegister src, |
| 235 |
FloatRegister dest) { |
| 236 |
MOZ_ASSERT(ARMFlags::HasFPHalfPrecision()); |
| 237 |
MOZ_ASSERT(src.isSingle()); |
| 238 |
MOZ_ASSERT(dest.isSingle()); |
| 239 |
|
| 240 |
as_vcvtb_h2s(dest, src); |
| 241 |
} |
| 242 |
|
| 243 |
void MacroAssemblerARM::convertInt32ToFloat16(Register src, |
| 244 |
FloatRegister dest) { |
| 245 |
// Convert Int32 to Float32. |
| 246 |
convertInt32ToFloat32(src, dest); |
| 247 |
|
| 248 |
// Convert Float32 to Float16. |
| 249 |
convertFloat32ToFloat16(dest, dest); |
| 250 |
} |
| 251 |
|
| 252 |
bool MacroAssemblerARM::alu_dbl(Register src1, Imm32 imm, Register dest, |
| 253 |
ALUOp op, SBit s, Condition c) { |
| 254 |
if ((s == SetCC && !condsAreSafe(op)) || !can_dbl(op)) { |
| 255 |
return false; |
| 256 |
} |
| 257 |
|
| 258 |
ALUOp interop = getDestVariant(op); |
| 259 |
Imm8::TwoImm8mData both = Imm8::EncodeTwoImms(imm.value); |
| 260 |
if (both.fst().invalid()) { |
| 261 |
return false; |
| 262 |
} |
| 263 |
|
| 264 |
// For the most part, there is no good reason to set the condition codes for |
| 265 |
// the first instruction. We can do better things if the second instruction |
| 266 |
// doesn't have a dest, such as check for overflow by doing first operation |
| 267 |
// don't do second operation if first operation overflowed. This preserves |
| 268 |
// the overflow condition code. Unfortunately, it is horribly brittle. |
| 269 |
as_alu(dest, src1, Operand2(both.fst()), interop, LeaveCC, c); |
| 270 |
as_alu(dest, dest, Operand2(both.snd()), op, s, c); |
| 271 |
return true; |
| 272 |
} |
| 273 |
|
| 274 |
void MacroAssemblerARM::ma_alu(Register src1, Imm32 imm, Register dest, |
| 275 |
AutoRegisterScope& scratch, ALUOp op, SBit s, |
| 276 |
Condition c) { |
| 277 |
// ma_mov should be used for moves. |
| 278 |
MOZ_ASSERT(op != OpMov); |
| 279 |
MOZ_ASSERT(op != OpMvn); |
| 280 |
MOZ_ASSERT(src1 != scratch); |
| 281 |
|
| 282 |
// As it turns out, if you ask for a compare-like instruction you *probably* |
| 283 |
// want it to set condition codes. |
| 284 |
MOZ_ASSERT_IF(dest == InvalidReg, s == SetCC); |
| 285 |
|
| 286 |
// The operator gives us the ability to determine how this can be used. |
| 287 |
Imm8 imm8 = Imm8(imm.value); |
| 288 |
// One instruction: If we can encode it using an imm8m, then do so. |
| 289 |
if (!imm8.invalid()) { |
| 290 |
as_alu(dest, src1, imm8, op, s, c); |
| 291 |
return; |
| 292 |
} |
| 293 |
|
| 294 |
// One instruction, negated: |
| 295 |
Imm32 negImm = imm; |
| 296 |
Register negDest; |
| 297 |
ALUOp negOp = ALUNeg(op, dest, scratch, &negImm, &negDest); |
| 298 |
Imm8 negImm8 = Imm8(negImm.value); |
| 299 |
// 'add r1, r2, -15' can be replaced with 'sub r1, r2, 15'. |
| 300 |
// The dest can be replaced (InvalidReg => scratch). |
| 301 |
// This is useful if we wish to negate tst. tst has an invalid (aka not |
| 302 |
// used) dest, but its negation bic requires a dest. |
| 303 |
if (negOp != OpInvalid && !negImm8.invalid()) { |
| 304 |
as_alu(negDest, src1, negImm8, negOp, s, c); |
| 305 |
return; |
| 306 |
} |
| 307 |
|
| 308 |
// Start by attempting to generate a two instruction form. Some things |
| 309 |
// cannot be made into two-inst forms correctly. Namely, adds dest, src, |
| 310 |
// 0xffff. Since we want the condition codes (and don't know which ones |
| 311 |
// will be checked), we need to assume that the overflow flag will be |
| 312 |
// checked and add{,s} dest, src, 0xff00; add{,s} dest, dest, 0xff is not |
| 313 |
// guaranteed to set the overflof flag the same as the (theoretical) one |
| 314 |
// instruction variant. |
| 315 |
if (alu_dbl(src1, imm, dest, op, s, c)) { |
| 316 |
return; |
| 317 |
} |
| 318 |
|
| 319 |
// And try with its negative. |
| 320 |
if (negOp != OpInvalid && alu_dbl(src1, negImm, negDest, negOp, s, c)) { |
| 321 |
return; |
| 322 |
} |
| 323 |
|
| 324 |
ma_mov(imm, scratch, c); |
| 325 |
as_alu(dest, src1, O2Reg(scratch), op, s, c); |
| 326 |
} |
| 327 |
|
| 328 |
void MacroAssemblerARM::ma_alu(Register src1, Operand op2, Register dest, |
| 329 |
ALUOp op, SBit s, Assembler::Condition c) { |
| 330 |
MOZ_ASSERT(op2.tag() == Operand::Tag::OP2); |
| 331 |
as_alu(dest, src1, op2.toOp2(), op, s, c); |
| 332 |
} |
| 333 |
|
| 334 |
void MacroAssemblerARM::ma_alu(Register src1, Operand2 op2, Register dest, |
| 335 |
ALUOp op, SBit s, Condition c) { |
| 336 |
as_alu(dest, src1, op2, op, s, c); |
| 337 |
} |
| 338 |
|
| 339 |
void MacroAssemblerARM::ma_nop() { as_nop(); } |
| 340 |
|
| 341 |
BufferOffset MacroAssemblerARM::ma_movPatchable(Imm32 imm_, Register dest, |
| 342 |
Assembler::Condition c) { |
| 343 |
int32_t imm = imm_.value; |
| 344 |
if (ARMFlags::HasMOVWT()) { |
| 345 |
AutoForbidPoolsAndNops afp(this, |
| 346 |
/* max number of instructions in scope = */ 2); |
| 347 |
BufferOffset offset = as_movw(dest, Imm16(imm & 0xffff), c); |
| 348 |
as_movt(dest, Imm16(imm >> 16 & 0xffff), c); |
| 349 |
return offset; |
| 350 |
} else { |
| 351 |
return as_Imm32Pool(dest, imm, c); |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
BufferOffset MacroAssemblerARM::ma_movPatchable(ImmPtr imm, Register dest, |
| 356 |
Assembler::Condition c) { |
| 357 |
return ma_movPatchable(Imm32(int32_t(imm.value)), dest, c); |
| 358 |
} |
| 359 |
|
| 360 |
/* static */ |
| 361 |
template <class Iter> |
| 362 |
void MacroAssemblerARM::ma_mov_patch(Imm32 imm32, Register dest, |
| 363 |
Assembler::Condition c, RelocStyle rs, |
| 364 |
Iter iter) { |
| 365 |
// The current instruction must be an actual instruction, |
| 366 |
// not automatically-inserted boilerplate. |
| 367 |
MOZ_ASSERT(iter.cur()); |
| 368 |
MOZ_ASSERT(iter.cur() == iter.maybeSkipAutomaticInstructions()); |
| 369 |
|
| 370 |
int32_t imm = imm32.value; |
| 371 |
switch (rs) { |
| 372 |
case L_MOVWT: |
| 373 |
Assembler::as_movw_patch(dest, Imm16(imm & 0xffff), c, iter.cur()); |
| 374 |
Assembler::as_movt_patch(dest, Imm16(imm >> 16 & 0xffff), c, iter.next()); |
| 375 |
break; |
| 376 |
case L_LDR: |
| 377 |
Assembler::WritePoolEntry(iter.cur(), c, imm); |
| 378 |
break; |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
template void MacroAssemblerARM::ma_mov_patch(Imm32 imm32, Register dest, |
| 383 |
Assembler::Condition c, |
| 384 |
RelocStyle rs, |
| 385 |
InstructionIterator iter); |
| 386 |
template void MacroAssemblerARM::ma_mov_patch(Imm32 imm32, Register dest, |
| 387 |
Assembler::Condition c, |
| 388 |
RelocStyle rs, |
| 389 |
BufferInstructionIterator iter); |
| 390 |
|
| 391 |
void MacroAssemblerARM::ma_mov(Register src, Register dest, SBit s, |
| 392 |
Assembler::Condition c) { |
| 393 |
if (s == SetCC || dest != src) { |
| 394 |
as_mov(dest, O2Reg(src), s, c); |
| 395 |
} |
| 396 |
} |
| 397 |
|
| 398 |
void MacroAssemblerARM::ma_mov(Imm32 imm, Register dest, |
| 399 |
Assembler::Condition c) { |
| 400 |
// Try mov with Imm8 operand. |
| 401 |
Imm8 imm8 = Imm8(imm.value); |
| 402 |
if (!imm8.invalid()) { |
| 403 |
as_alu(dest, InvalidReg, imm8, OpMov, LeaveCC, c); |
| 404 |
return; |
| 405 |
} |
| 406 |
|
| 407 |
// Try mvn with Imm8 operand. |
| 408 |
Imm8 negImm8 = Imm8(~imm.value); |
| 409 |
if (!negImm8.invalid()) { |
| 410 |
as_alu(dest, InvalidReg, negImm8, OpMvn, LeaveCC, c); |
| 411 |
return; |
| 412 |
} |
| 413 |
|
| 414 |
// Try movw/movt. |
| 415 |
if (ARMFlags::HasMOVWT()) { |
| 416 |
// ARMv7 supports movw/movt. movw zero-extends its 16 bit argument, |
| 417 |
// so we can set the register this way. movt leaves the bottom 16 |
| 418 |
// bits in tact, so we always need a movw. |
| 419 |
as_movw(dest, Imm16(imm.value & 0xffff), c); |
| 420 |
if (uint32_t(imm.value) >> 16) { |
| 421 |
as_movt(dest, Imm16(uint32_t(imm.value) >> 16), c); |
| 422 |
} |
| 423 |
return; |
| 424 |
} |
| 425 |
|
| 426 |
// If we don't have movw/movt, we need a load. |
| 427 |
as_Imm32Pool(dest, imm.value, c); |
| 428 |
} |
| 429 |
|
| 430 |
void MacroAssemblerARM::ma_mov(ImmWord imm, Register dest, |
| 431 |
Assembler::Condition c) { |
| 432 |
ma_mov(Imm32(imm.value), dest, c); |
| 433 |
} |
| 434 |
|
| 435 |
void MacroAssemblerARM::ma_mov(ImmGCPtr ptr, Register dest) { |
| 436 |
BufferOffset offset = |
| 437 |
ma_movPatchable(Imm32(uintptr_t(ptr.value)), dest, Always); |
| 438 |
writeDataRelocation(offset, ptr); |
| 439 |
} |
| 440 |
|
| 441 |
// Shifts (just a move with a shifting op2) |
| 442 |
void MacroAssemblerARM::ma_lsl(Imm32 shift, Register src, Register dst) { |
| 443 |
as_mov(dst, lsl(src, shift.value)); |
| 444 |
} |
| 445 |
|
| 446 |
void MacroAssemblerARM::ma_lsr(Imm32 shift, Register src, Register dst) { |
| 447 |
as_mov(dst, lsr(src, shift.value)); |
| 448 |
} |
| 449 |
|
| 450 |
void MacroAssemblerARM::ma_asr(Imm32 shift, Register src, Register dst) { |
| 451 |
as_mov(dst, asr(src, shift.value)); |
| 452 |
} |
| 453 |
|
| 454 |
void MacroAssemblerARM::ma_ror(Imm32 shift, Register src, Register dst) { |
| 455 |
as_mov(dst, ror(src, shift.value)); |
| 456 |
} |
| 457 |
|
| 458 |
void MacroAssemblerARM::ma_rol(Imm32 shift, Register src, Register dst) { |
| 459 |
as_mov(dst, rol(src, shift.value)); |
| 460 |
} |
| 461 |
|
| 462 |
// Shifts (just a move with a shifting op2) |
| 463 |
void MacroAssemblerARM::ma_lsl(Register shift, Register src, Register dst) { |
| 464 |
as_mov(dst, lsl(src, shift)); |
| 465 |
} |
| 466 |
|
| 467 |
void MacroAssemblerARM::ma_lsr(Register shift, Register src, Register dst) { |
| 468 |
as_mov(dst, lsr(src, shift)); |
| 469 |
} |
| 470 |
|
| 471 |
void MacroAssemblerARM::ma_asr(Register shift, Register src, Register dst) { |
| 472 |
as_mov(dst, asr(src, shift)); |
| 473 |
} |
| 474 |
|
| 475 |
void MacroAssemblerARM::ma_ror(Register shift, Register src, Register dst) { |
| 476 |
as_mov(dst, ror(src, shift)); |
| 477 |
} |
| 478 |
|
| 479 |
void MacroAssemblerARM::ma_rol(Register shift, Register src, Register dst, |
| 480 |
AutoRegisterScope& scratch) { |
| 481 |
as_rsb(scratch, shift, Imm8(32)); |
| 482 |
as_mov(dst, ror(src, scratch)); |
| 483 |
} |
| 484 |
|
| 485 |
// Move not (dest <- ~src) |
| 486 |
void MacroAssemblerARM::ma_mvn(Register src1, Register dest, SBit s, |
| 487 |
Assembler::Condition c) { |
| 488 |
as_alu(dest, InvalidReg, O2Reg(src1), OpMvn, s, c); |
| 489 |
} |
| 490 |
|
| 491 |
// Negate (dest <- -src), src is a register, rather than a general op2. |
| 492 |
void MacroAssemblerARM::ma_neg(Register src1, Register dest, SBit s, |
| 493 |
Assembler::Condition c) { |
| 494 |
as_rsb(dest, src1, Imm8(0), s, c); |
| 495 |
} |
| 496 |
|
| 497 |
void MacroAssemblerARM::ma_neg(Register64 src, Register64 dest) { |
| 498 |
as_rsb(dest.low, src.low, Imm8(0), SetCC); |
| 499 |
as_rsc(dest.high, src.high, Imm8(0)); |
| 500 |
} |
| 501 |
|
| 502 |
// And. |
| 503 |
void MacroAssemblerARM::ma_and(Register src, Register dest, SBit s, |
| 504 |
Assembler::Condition c) { |
| 505 |
ma_and(dest, src, dest); |
| 506 |
} |
| 507 |
|
| 508 |
void MacroAssemblerARM::ma_and(Register src1, Register src2, Register dest, |
| 509 |
SBit s, Assembler::Condition c) { |
| 510 |
as_and(dest, src1, O2Reg(src2), s, c); |
| 511 |
} |
| 512 |
|
| 513 |
void MacroAssemblerARM::ma_and(Imm32 imm, Register dest, |
| 514 |
AutoRegisterScope& scratch, SBit s, |
| 515 |
Assembler::Condition c) { |
| 516 |
ma_alu(dest, imm, dest, scratch, OpAnd, s, c); |
| 517 |
} |
| 518 |
|
| 519 |
void MacroAssemblerARM::ma_and(Imm32 imm, Register src1, Register dest, |
| 520 |
AutoRegisterScope& scratch, SBit s, |
| 521 |
Assembler::Condition c) { |
| 522 |
ma_alu(src1, imm, dest, scratch, OpAnd, s, c); |
| 523 |
} |
| 524 |
|
| 525 |
// Bit clear (dest <- dest & ~imm) or (dest <- src1 & ~src2). |
| 526 |
void MacroAssemblerARM::ma_bic(Imm32 imm, Register dest, |
| 527 |
AutoRegisterScope& scratch, SBit s, |
| 528 |
Assembler::Condition c) { |
| 529 |
ma_alu(dest, imm, dest, scratch, OpBic, s, c); |
| 530 |
} |
| 531 |
|
| 532 |
// Exclusive or. |
| 533 |
void MacroAssemblerARM::ma_eor(Register src, Register dest, SBit s, |
| 534 |
Assembler::Condition c) { |
| 535 |
ma_eor(dest, src, dest, s, c); |
| 536 |
} |
| 537 |
|
| 538 |
void MacroAssemblerARM::ma_eor(Register src1, Register src2, Register dest, |
| 539 |
SBit s, Assembler::Condition c) { |
| 540 |
as_eor(dest, src1, O2Reg(src2), s, c); |
| 541 |
} |
| 542 |
|
| 543 |
void MacroAssemblerARM::ma_eor(Imm32 imm, Register dest, |
| 544 |
AutoRegisterScope& scratch, SBit s, |
| 545 |
Assembler::Condition c) { |
| 546 |
ma_alu(dest, imm, dest, scratch, OpEor, s, c); |
| 547 |
} |
| 548 |
|
| 549 |
void MacroAssemblerARM::ma_eor(Imm32 imm, Register src1, Register dest, |
| 550 |
AutoRegisterScope& scratch, SBit s, |
| 551 |
Assembler::Condition c) { |
| 552 |
ma_alu(src1, imm, dest, scratch, OpEor, s, c); |
| 553 |
} |
| 554 |
|
| 555 |
// Or. |
| 556 |
void MacroAssemblerARM::ma_orr(Register src, Register dest, SBit s, |
| 557 |
Assembler::Condition c) { |
| 558 |
ma_orr(dest, src, dest, s, c); |
| 559 |
} |
| 560 |
|
| 561 |
void MacroAssemblerARM::ma_orr(Register src1, Register src2, Register dest, |
| 562 |
SBit s, Assembler::Condition c) { |
| 563 |
as_orr(dest, src1, O2Reg(src2), s, c); |
| 564 |
} |
| 565 |
|
| 566 |
void MacroAssemblerARM::ma_orr(Imm32 imm, Register dest, |
| 567 |
AutoRegisterScope& scratch, SBit s, |
| 568 |
Assembler::Condition c) { |
| 569 |
ma_alu(dest, imm, dest, scratch, OpOrr, s, c); |
| 570 |
} |
| 571 |
|
| 572 |
void MacroAssemblerARM::ma_orr(Imm32 imm, Register src1, Register dest, |
| 573 |
AutoRegisterScope& scratch, SBit s, |
| 574 |
Assembler::Condition c) { |
| 575 |
ma_alu(src1, imm, dest, scratch, OpOrr, s, c); |
| 576 |
} |
| 577 |
|
| 578 |
// Arithmetic-based ops. |
| 579 |
// Add with carry. |
| 580 |
void MacroAssemblerARM::ma_adc(Imm32 imm, Register dest, |
| 581 |
AutoRegisterScope& scratch, SBit s, |
| 582 |
Condition c) { |
| 583 |
ma_alu(dest, imm, dest, scratch, OpAdc, s, c); |
| 584 |
} |
| 585 |
|
| 586 |
void MacroAssemblerARM::ma_adc(Register src, Register dest, SBit s, |
| 587 |
Condition c) { |
| 588 |
as_alu(dest, dest, O2Reg(src), OpAdc, s, c); |
| 589 |
} |
| 590 |
|
| 591 |
void MacroAssemblerARM::ma_adc(Register src1, Register src2, Register dest, |
| 592 |
SBit s, Condition c) { |
| 593 |
as_alu(dest, src1, O2Reg(src2), OpAdc, s, c); |
| 594 |
} |
| 595 |
|
| 596 |
void MacroAssemblerARM::ma_adc(Register src1, Imm32 op, Register dest, |
| 597 |
AutoRegisterScope& scratch, SBit s, |
| 598 |
Condition c) { |
| 599 |
ma_alu(src1, op, dest, scratch, OpAdc, s, c); |
| 600 |
} |
| 601 |
|
| 602 |
// Add. |
| 603 |
void MacroAssemblerARM::ma_add(Imm32 imm, Register dest, |
| 604 |
AutoRegisterScope& scratch, SBit s, |
| 605 |
Condition c) { |
| 606 |
ma_alu(dest, imm, dest, scratch, OpAdd, s, c); |
| 607 |
} |
| 608 |
|
| 609 |
void MacroAssemblerARM::ma_add(Register src1, Register dest, SBit s, |
| 610 |
Condition c) { |
| 611 |
ma_alu(dest, O2Reg(src1), dest, OpAdd, s, c); |
| 612 |
} |
| 613 |
|
| 614 |
void MacroAssemblerARM::ma_add(Register src1, Register src2, Register dest, |
| 615 |
SBit s, Condition c) { |
| 616 |
as_alu(dest, src1, O2Reg(src2), OpAdd, s, c); |
| 617 |
} |
| 618 |
|
| 619 |
void MacroAssemblerARM::ma_add(Register src1, Operand op, Register dest, SBit s, |
| 620 |
Condition c) { |
| 621 |
ma_alu(src1, op, dest, OpAdd, s, c); |
| 622 |
} |
| 623 |
|
| 624 |
void MacroAssemblerARM::ma_add(Register src1, Imm32 op, Register dest, |
| 625 |
AutoRegisterScope& scratch, SBit s, |
| 626 |
Condition c) { |
| 627 |
ma_alu(src1, op, dest, scratch, OpAdd, s, c); |
| 628 |
} |
| 629 |
|
| 630 |
// Subtract with carry. |
| 631 |
void MacroAssemblerARM::ma_sbc(Imm32 imm, Register dest, |
| 632 |
AutoRegisterScope& scratch, SBit s, |
| 633 |
Condition c) { |
| 634 |
ma_alu(dest, imm, dest, scratch, OpSbc, s, c); |
| 635 |
} |
| 636 |
|
| 637 |
void MacroAssemblerARM::ma_sbc(Register src1, Register dest, SBit s, |
| 638 |
Condition c) { |
| 639 |
as_alu(dest, dest, O2Reg(src1), OpSbc, s, c); |
| 640 |
} |
| 641 |
|
| 642 |
void MacroAssemblerARM::ma_sbc(Register src1, Register src2, Register dest, |
| 643 |
SBit s, Condition c) { |
| 644 |
as_alu(dest, src1, O2Reg(src2), OpSbc, s, c); |
| 645 |
} |
| 646 |
|
| 647 |
// Subtract. |
| 648 |
void MacroAssemblerARM::ma_sub(Imm32 imm, Register dest, |
| 649 |
AutoRegisterScope& scratch, SBit s, |
| 650 |
Condition c) { |
| 651 |
ma_alu(dest, imm, dest, scratch, OpSub, s, c); |
| 652 |
} |
| 653 |
|
| 654 |
void MacroAssemblerARM::ma_sub(Register src1, Register dest, SBit s, |
| 655 |
Condition c) { |
| 656 |
ma_alu(dest, Operand(src1), dest, OpSub, s, c); |
| 657 |
} |
| 658 |
|
| 659 |
void MacroAssemblerARM::ma_sub(Register src1, Register src2, Register dest, |
| 660 |
SBit s, Condition c) { |
| 661 |
ma_alu(src1, Operand(src2), dest, OpSub, s, c); |
| 662 |
} |
| 663 |
|
| 664 |
void MacroAssemblerARM::ma_sub(Register src1, Operand op, Register dest, SBit s, |
| 665 |
Condition c) { |
| 666 |
ma_alu(src1, op, dest, OpSub, s, c); |
| 667 |
} |
| 668 |
|
| 669 |
void MacroAssemblerARM::ma_sub(Register src1, Imm32 op, Register dest, |
| 670 |
AutoRegisterScope& scratch, SBit s, |
| 671 |
Condition c) { |
| 672 |
ma_alu(src1, op, dest, scratch, OpSub, s, c); |
| 673 |
} |
| 674 |
|
| 675 |
// Reverse subtract. |
| 676 |
void MacroAssemblerARM::ma_rsb(Imm32 imm, Register dest, |
| 677 |
AutoRegisterScope& scratch, SBit s, |
| 678 |
Condition c) { |
| 679 |
ma_alu(dest, imm, dest, scratch, OpRsb, s, c); |
| 680 |
} |
| 681 |
|
| 682 |
void MacroAssemblerARM::ma_rsb(Register src1, Register dest, SBit s, |
| 683 |
Condition c) { |
| 684 |
as_alu(dest, src1, O2Reg(dest), OpRsb, s, c); |
| 685 |
} |
| 686 |
|
| 687 |
void MacroAssemblerARM::ma_rsb(Register src1, Register src2, Register dest, |
| 688 |
SBit s, Condition c) { |
| 689 |
as_alu(dest, src1, O2Reg(src2), OpRsb, s, c); |
| 690 |
} |
| 691 |
|
| 692 |
void MacroAssemblerARM::ma_rsb(Register src1, Imm32 op2, Register dest, |
| 693 |
AutoRegisterScope& scratch, SBit s, |
| 694 |
Condition c) { |
| 695 |
ma_alu(src1, op2, dest, scratch, OpRsb, s, c); |
| 696 |
} |
| 697 |
|
| 698 |
// Reverse subtract with carry. |
| 699 |
void MacroAssemblerARM::ma_rsc(Imm32 imm, Register dest, |
| 700 |
AutoRegisterScope& scratch, SBit s, |
| 701 |
Condition c) { |
| 702 |
ma_alu(dest, imm, dest, scratch, OpRsc, s, c); |
| 703 |
} |
| 704 |
|
| 705 |
void MacroAssemblerARM::ma_rsc(Register src1, Register dest, SBit s, |
| 706 |
Condition c) { |
| 707 |
as_alu(dest, dest, O2Reg(src1), OpRsc, s, c); |
| 708 |
} |
| 709 |
|
| 710 |
void MacroAssemblerARM::ma_rsc(Register src1, Register src2, Register dest, |
| 711 |
SBit s, Condition c) { |
| 712 |
as_alu(dest, src1, O2Reg(src2), OpRsc, s, c); |
| 713 |
} |
| 714 |
|
| 715 |
// Compares/tests. |
| 716 |
// Compare negative (sets condition codes as src1 + src2 would). |
| 717 |
void MacroAssemblerARM::ma_cmn(Register src1, Imm32 imm, |
| 718 |
AutoRegisterScope& scratch, Condition c) { |
| 719 |
ma_alu(src1, imm, InvalidReg, scratch, OpCmn, SetCC, c); |
| 720 |
} |
| 721 |
|
| 722 |
void MacroAssemblerARM::ma_cmn(Register src1, Register src2, Condition c) { |
| 723 |
as_alu(InvalidReg, src2, O2Reg(src1), OpCmn, SetCC, c); |
| 724 |
} |
| 725 |
|
| 726 |
void MacroAssemblerARM::ma_cmn(Register src1, Operand op, Condition c) { |
| 727 |
MOZ_CRASH("Feature NYI"); |
| 728 |
} |
| 729 |
|
| 730 |
// Compare (src - src2). |
| 731 |
void MacroAssemblerARM::ma_cmp(Register src1, Imm32 imm, |
| 732 |
AutoRegisterScope& scratch, Condition c) { |
| 733 |
ma_alu(src1, imm, InvalidReg, scratch, OpCmp, SetCC, c); |
| 734 |
} |
| 735 |
|
| 736 |
void MacroAssemblerARM::ma_cmp(Register src1, ImmTag tag, Condition c) { |
| 737 |
// ImmTag comparisons can always be done without use of a scratch register. |
| 738 |
Imm8 negtag = Imm8(-tag.value); |
| 739 |
MOZ_ASSERT(!negtag.invalid()); |
| 740 |
as_cmn(src1, negtag, c); |
| 741 |
} |
| 742 |
|
| 743 |
void MacroAssemblerARM::ma_cmp(Register src1, ImmWord ptr, |
| 744 |
AutoRegisterScope& scratch, Condition c) { |
| 745 |
ma_cmp(src1, Imm32(ptr.value), scratch, c); |
| 746 |
} |
| 747 |
|
| 748 |
void MacroAssemblerARM::ma_cmp(Register src1, ImmGCPtr ptr, |
| 749 |
AutoRegisterScope& scratch, Condition c) { |
| 750 |
ma_mov(ptr, scratch); |
| 751 |
ma_cmp(src1, scratch, c); |
| 752 |
} |
| 753 |
|
| 754 |
void MacroAssemblerARM::ma_cmp(Register src1, Operand op, |
| 755 |
AutoRegisterScope& scratch, |
| 756 |
AutoRegisterScope& scratch2, Condition c) { |
| 757 |
switch (op.tag()) { |
| 758 |
case Operand::Tag::OP2: |
| 759 |
as_cmp(src1, op.toOp2(), c); |
| 760 |
break; |
| 761 |
case Operand::Tag::MEM: |
| 762 |
ma_ldr(op.toAddress(), scratch, scratch2); |
| 763 |
as_cmp(src1, O2Reg(scratch), c); |
| 764 |
break; |
| 765 |
default: |
| 766 |
MOZ_CRASH("trying to compare FP and integer registers"); |
| 767 |
} |
| 768 |
} |
| 769 |
|
| 770 |
void MacroAssemblerARM::ma_cmp(Register src1, Register src2, Condition c) { |
| 771 |
as_cmp(src1, O2Reg(src2), c); |
| 772 |
} |
| 773 |
|
| 774 |
// Test for equality, (src1 ^ src2). |
| 775 |
void MacroAssemblerARM::ma_teq(Register src1, Imm32 imm, |
| 776 |
AutoRegisterScope& scratch, Condition c) { |
| 777 |
ma_alu(src1, imm, InvalidReg, scratch, OpTeq, SetCC, c); |
| 778 |
} |
| 779 |
|
| 780 |
void MacroAssemblerARM::ma_teq(Register src1, Register src2, Condition c) { |
| 781 |
as_tst(src1, O2Reg(src2), c); |
| 782 |
} |
| 783 |
|
| 784 |
void MacroAssemblerARM::ma_teq(Register src1, Operand op, Condition c) { |
| 785 |
as_teq(src1, op.toOp2(), c); |
| 786 |
} |
| 787 |
|
| 788 |
// Test (src1 & src2). |
| 789 |
void MacroAssemblerARM::ma_tst(Register src1, Imm32 imm, |
| 790 |
AutoRegisterScope& scratch, Condition c) { |
| 791 |
ma_alu(src1, imm, InvalidReg, scratch, OpTst, SetCC, c); |
| 792 |
} |
| 793 |
|
| 794 |
void MacroAssemblerARM::ma_tst(Register src1, Register src2, Condition c) { |
| 795 |
as_tst(src1, O2Reg(src2), c); |
| 796 |
} |
| 797 |
|
| 798 |
void MacroAssemblerARM::ma_tst(Register src1, Operand op, Condition c) { |
| 799 |
as_tst(src1, op.toOp2(), c); |
| 800 |
} |
| 801 |
|
| 802 |
void MacroAssemblerARM::ma_mul(Register src1, Register src2, Register dest) { |
| 803 |
as_mul(dest, src1, src2); |
| 804 |
} |
| 805 |
|
| 806 |
void MacroAssemblerARM::ma_mul(Register src1, Imm32 imm, Register dest, |
| 807 |
AutoRegisterScope& scratch) { |
| 808 |
ma_mov(imm, scratch); |
| 809 |
as_mul(dest, src1, scratch); |
| 810 |
} |
| 811 |
|
| 812 |
Assembler::Condition MacroAssemblerARM::ma_check_mul(Register src1, |
| 813 |
Register src2, |
| 814 |
Register dest, |
| 815 |
AutoRegisterScope& scratch, |
| 816 |
Condition cond) { |
| 817 |
// TODO: this operation is illegal on armv6 and earlier |
| 818 |
// if src2 == scratch or src2 == dest. |
| 819 |
if (cond == Equal || cond == NotEqual) { |
| 820 |
as_smull(scratch, dest, src1, src2, SetCC); |
| 821 |
return cond; |
| 822 |
} |
| 823 |
|
| 824 |
if (cond == Overflow) { |
| 825 |
as_smull(scratch, dest, src1, src2); |
| 826 |
as_cmp(scratch, asr(dest, 31)); |
| 827 |
return NotEqual; |
| 828 |
} |
| 829 |
|
| 830 |
MOZ_CRASH("Condition NYI"); |
| 831 |
} |
| 832 |
|
| 833 |
Assembler::Condition MacroAssemblerARM::ma_check_mul(Register src1, Imm32 imm, |
| 834 |
Register dest, |
| 835 |
AutoRegisterScope& scratch, |
| 836 |
Condition cond) { |
| 837 |
ma_mov(imm, scratch); |
| 838 |
|
| 839 |
if (cond == Equal || cond == NotEqual) { |
| 840 |
as_smull(scratch, dest, scratch, src1, SetCC); |
| 841 |
return cond; |
| 842 |
} |
| 843 |
|
| 844 |
if (cond == Overflow) { |
| 845 |
as_smull(scratch, dest, scratch, src1); |
| 846 |
as_cmp(scratch, asr(dest, 31)); |
| 847 |
return NotEqual; |
| 848 |
} |
| 849 |
|
| 850 |
MOZ_CRASH("Condition NYI"); |
| 851 |
} |
| 852 |
|
| 853 |
void MacroAssemblerARM::ma_umull(Register src1, Imm32 imm, Register destHigh, |
| 854 |
Register destLow, AutoRegisterScope& scratch) { |
| 855 |
ma_mov(imm, scratch); |
| 856 |
as_umull(destHigh, destLow, src1, scratch); |
| 857 |
} |
| 858 |
|
| 859 |
void MacroAssemblerARM::ma_umull(Register src1, Register src2, |
| 860 |
Register destHigh, Register destLow) { |
| 861 |
as_umull(destHigh, destLow, src1, src2); |
| 862 |
} |
| 863 |
|
| 864 |
void MacroAssemblerARM::ma_mod_mask(Register src, Register dest, Register hold, |
| 865 |
Register tmp, AutoRegisterScope& scratch, |
| 866 |
AutoRegisterScope& scratch2, |
| 867 |
int32_t shift) { |
| 868 |
// We wish to compute x % (1<<y) - 1 for a known constant, y. |
| 869 |
// |
| 870 |
// 1. Let b = (1<<y) and C = (1<<y)-1, then think of the 32 bit dividend as |
| 871 |
// a number in base b, namely c_0*1 + c_1*b + c_2*b^2 ... c_n*b^n |
| 872 |
// |
| 873 |
// 2. Since both addition and multiplication commute with modulus: |
| 874 |
// x % C == (c_0 + c_1*b + ... + c_n*b^n) % C == |
| 875 |
// (c_0 % C) + (c_1%C) * (b % C) + (c_2 % C) * (b^2 % C)... |
| 876 |
// |
| 877 |
// 3. Since b == C + 1, b % C == 1, and b^n % C == 1 the whole thing |
| 878 |
// simplifies to: c_0 + c_1 + c_2 ... c_n % C |
| 879 |
// |
| 880 |
// Each c_n can easily be computed by a shift/bitextract, and the modulus |
| 881 |
// can be maintained by simply subtracting by C whenever the number gets |
| 882 |
// over C. |
| 883 |
int32_t mask = (1 << shift) - 1; |
| 884 |
Label head; |
| 885 |
|
| 886 |
// Register 'hold' holds -1 if the value was negative, 1 otherwise. The |
| 887 |
// scratch reg holds the remaining bits that have not been processed lr |
| 888 |
// serves as a temporary location to store extracted bits into as well as |
| 889 |
// holding the trial subtraction as a temp value dest is the accumulator |
| 890 |
// (and holds the final result) |
| 891 |
// |
| 892 |
// Move the whole value into tmp, setting the codition codes so we can muck |
| 893 |
// with them later. |
| 894 |
as_mov(tmp, O2Reg(src), SetCC); |
| 895 |
// Zero out the dest. |
| 896 |
ma_mov(Imm32(0), dest); |
| 897 |
// Set the hold appropriately. |
| 898 |
ma_mov(Imm32(1), hold); |
| 899 |
ma_mov(Imm32(-1), hold, Signed); |
| 900 |
as_rsb(tmp, tmp, Imm8(0), SetCC, Signed); |
| 901 |
|
| 902 |
// Begin the main loop. |
| 903 |
bind(&head); |
| 904 |
{ |
| 905 |
// Extract the bottom bits. |
| 906 |
ma_and(Imm32(mask), tmp, scratch, scratch2); |
| 907 |
// Add those bits to the accumulator. |
| 908 |
ma_add(scratch, dest, dest); |
| 909 |
// Do a trial subtraction, this is the same operation as cmp, but we store |
| 910 |
// the dest. |
| 911 |
ma_sub(dest, Imm32(mask), scratch, scratch2, SetCC); |
| 912 |
// If (sum - C) > 0, store sum - C back into sum, thus performing a modulus. |
| 913 |
ma_mov(scratch, dest, LeaveCC, NotSigned); |
| 914 |
// Get rid of the bits that we extracted before, and set the condition |
| 915 |
// codes. |
| 916 |
as_mov(tmp, lsr(tmp, shift), SetCC); |
| 917 |
// If the shift produced zero, finish, otherwise, continue in the loop. |
| 918 |
ma_b(&head, NonZero); |
| 919 |
} |
| 920 |
|
| 921 |
// Check the hold to see if we need to negate the result. Hold can only be |
| 922 |
// 1 or -1, so this will never set the 0 flag. |
| 923 |
as_cmp(hold, Imm8(0)); |
| 924 |
// If the hold was non-zero, negate the result to be in line with what JS |
| 925 |
// wants this will set the condition codes if we try to negate. |
| 926 |
as_rsb(dest, dest, Imm8(0), SetCC, Signed); |
| 927 |
// Since the Zero flag is not set by the compare, we can *only* set the Zero |
| 928 |
// flag in the rsb, so Zero is set iff we negated zero (e.g. the result of |
| 929 |
// the computation was -0.0). |
| 930 |
} |
| 931 |
|
| 932 |
void MacroAssemblerARM::ma_smod(Register num, Register div, Register dest, |
| 933 |
AutoRegisterScope& scratch) { |
| 934 |
as_sdiv(scratch, num, div); |
| 935 |
as_mls(dest, num, scratch, div); |
| 936 |
} |
| 937 |
|
| 938 |
void MacroAssemblerARM::ma_umod(Register num, Register div, Register dest, |
| 939 |
AutoRegisterScope& scratch) { |
| 940 |
as_udiv(scratch, num, div); |
| 941 |
as_mls(dest, num, scratch, div); |
| 942 |
} |
| 943 |
|
| 944 |
// Division |
| 945 |
void MacroAssemblerARM::ma_sdiv(Register num, Register div, Register dest, |
| 946 |
Condition cond) { |
| 947 |
as_sdiv(dest, num, div, cond); |
| 948 |
} |
| 949 |
|
| 950 |
void MacroAssemblerARM::ma_udiv(Register num, Register div, Register dest, |
| 951 |
Condition cond) { |
| 952 |
as_udiv(dest, num, div, cond); |
| 953 |
} |
| 954 |
|
| 955 |
// Miscellaneous instructions. |
| 956 |
void MacroAssemblerARM::ma_clz(Register src, Register dest, Condition cond) { |
| 957 |
as_clz(dest, src, cond); |
| 958 |
} |
| 959 |
|
| 960 |
void MacroAssemblerARM::ma_ctz(Register src, Register dest, |
| 961 |
AutoRegisterScope& scratch) { |
| 962 |
// int c = __clz(a & -a); |
| 963 |
// return a ? 31 - c : c; |
| 964 |
as_rsb(scratch, src, Imm8(0), SetCC); |
| 965 |
as_and(dest, src, O2Reg(scratch), LeaveCC); |
| 966 |
as_clz(dest, dest); |
| 967 |
as_rsb(dest, dest, Imm8(0x1F), LeaveCC, Assembler::NotEqual); |
| 968 |
} |
| 969 |
|
| 970 |
// Memory. |
| 971 |
// Shortcut for when we know we're transferring 32 bits of data. |
| 972 |
void MacroAssemblerARM::ma_dtr(LoadStore ls, Register rn, Imm32 offset, |
| 973 |
Register rt, AutoRegisterScope& scratch, |
| 974 |
Index mode, Assembler::Condition cc) { |
| 975 |
ma_dataTransferN(ls, 32, true, rn, offset, rt, scratch, mode, cc); |
| 976 |
} |
| 977 |
|
| 978 |
FaultingCodeOffset MacroAssemblerARM::ma_dtr(LoadStore ls, Register rt, |
| 979 |
const Address& addr, |
| 980 |
AutoRegisterScope& scratch, |
| 981 |
Index mode, Condition cc) { |
| 982 |
BufferOffset offset = ma_dataTransferN( |
| 983 |
ls, 32, true, addr.base, Imm32(addr.offset), rt, scratch, mode, cc); |
| 984 |
return FaultingCodeOffset(offset.getOffset()); |
| 985 |
} |
| 986 |
|
| 987 |
FaultingCodeOffset MacroAssemblerARM::ma_str(Register rt, DTRAddr addr, |
| 988 |
Index mode, Condition cc) { |
| 989 |
BufferOffset offset = as_dtr(IsStore, 32, mode, rt, addr, cc); |
| 990 |
return FaultingCodeOffset(offset.getOffset()); |
| 991 |
} |
| 992 |
|
| 993 |
FaultingCodeOffset MacroAssemblerARM::ma_str(Register rt, const Address& addr, |
| 994 |
AutoRegisterScope& scratch, |
| 995 |
Index mode, Condition cc) { |
| 996 |
return ma_dtr(IsStore, rt, addr, scratch, mode, cc); |
| 997 |
} |
| 998 |
|
| 999 |
void MacroAssemblerARM::ma_strd(Register rt, DebugOnly<Register> rt2, |
| 1000 |
EDtrAddr addr, Index mode, Condition cc) { |
| 1001 |
MOZ_ASSERT((rt.code() & 1) == 0); |
| 1002 |
MOZ_ASSERT(rt2.value.code() == rt.code() + 1); |
| 1003 |
as_extdtr(IsStore, 64, true, mode, rt, addr, cc); |
| 1004 |
} |
| 1005 |
|
| 1006 |
FaultingCodeOffset MacroAssemblerARM::ma_ldr(DTRAddr addr, Register rt, |
| 1007 |
Index mode, Condition cc) { |
| 1008 |
BufferOffset offset = as_dtr(IsLoad, 32, mode, rt, addr, cc); |
| 1009 |
return FaultingCodeOffset(offset.getOffset()); |
| 1010 |
} |
| 1011 |
|
| 1012 |
FaultingCodeOffset MacroAssemblerARM::ma_ldr(const Address& addr, Register rt, |
| 1013 |
AutoRegisterScope& scratch, |
| 1014 |
Index mode, Condition cc) { |
| 1015 |
return ma_dtr(IsLoad, rt, addr, scratch, mode, cc); |
| 1016 |
} |
| 1017 |
|
| 1018 |
FaultingCodeOffset MacroAssemblerARM::ma_ldrb(DTRAddr addr, Register rt, |
| 1019 |
Index mode, Condition cc) { |
| 1020 |
BufferOffset offset = as_dtr(IsLoad, 8, mode, rt, addr, cc); |
| 1021 |
return FaultingCodeOffset(offset.getOffset()); |
| 1022 |
} |
| 1023 |
|
| 1024 |
FaultingCodeOffset MacroAssemblerARM::ma_ldrsh(EDtrAddr addr, Register rt, |
| 1025 |
Index mode, Condition cc) { |
| 1026 |
BufferOffset offset = as_extdtr(IsLoad, 16, true, mode, rt, addr, cc); |
| 1027 |
return FaultingCodeOffset(offset.getOffset()); |
| 1028 |
} |
| 1029 |
|
| 1030 |
FaultingCodeOffset MacroAssemblerARM::ma_ldrh(EDtrAddr addr, Register rt, |
| 1031 |
Index mode, Condition cc) { |
| 1032 |
BufferOffset offset = as_extdtr(IsLoad, 16, false, mode, rt, addr, cc); |
| 1033 |
return FaultingCodeOffset(offset.getOffset()); |
| 1034 |
} |
| 1035 |
|
| 1036 |
FaultingCodeOffset MacroAssemblerARM::ma_ldrsb(EDtrAddr addr, Register rt, |
| 1037 |
Index mode, Condition cc) { |
| 1038 |
BufferOffset offset = as_extdtr(IsLoad, 8, true, mode, rt, addr, cc); |
| 1039 |
return FaultingCodeOffset(offset.getOffset()); |
| 1040 |
} |
| 1041 |
|
| 1042 |
void MacroAssemblerARM::ma_ldrd(EDtrAddr addr, Register rt, |
| 1043 |
DebugOnly<Register> rt2, Index mode, |
| 1044 |
Condition cc) { |
| 1045 |
MOZ_ASSERT((rt.code() & 1) == 0); |
| 1046 |
MOZ_ASSERT(rt2.value.code() == rt.code() + 1); |
| 1047 |
MOZ_ASSERT(addr.maybeOffsetRegister() != |
| 1048 |
rt); // Undefined behavior if rm == rt/rt2. |
| 1049 |
MOZ_ASSERT(addr.maybeOffsetRegister() != rt2); |
| 1050 |
as_extdtr(IsLoad, 64, true, mode, rt, addr, cc); |
| 1051 |
} |
| 1052 |
|
| 1053 |
FaultingCodeOffset MacroAssemblerARM::ma_strh(Register rt, EDtrAddr addr, |
| 1054 |
Index mode, Condition cc) { |
| 1055 |
BufferOffset offset = as_extdtr(IsStore, 16, false, mode, rt, addr, cc); |
| 1056 |
return FaultingCodeOffset(offset.getOffset()); |
| 1057 |
} |
| 1058 |
|
| 1059 |
FaultingCodeOffset MacroAssemblerARM::ma_strb(Register rt, DTRAddr addr, |
| 1060 |
Index mode, Condition cc) { |
| 1061 |
BufferOffset offset = as_dtr(IsStore, 8, mode, rt, addr, cc); |
| 1062 |
return FaultingCodeOffset(offset.getOffset()); |
| 1063 |
} |
| 1064 |
|
| 1065 |
// Specialty for moving N bits of data, where n == 8,16,32,64. |
| 1066 |
BufferOffset MacroAssemblerARM::ma_dataTransferN( |
| 1067 |
LoadStore ls, int size, bool IsSigned, Register rn, Register rm, |
| 1068 |
Register rt, AutoRegisterScope& scratch, Index mode, |
| 1069 |
Assembler::Condition cc, Scale scale) { |
| 1070 |
MOZ_ASSERT(size == 8 || size == 16 || size == 32 || size == 64); |
| 1071 |
|
| 1072 |
if (size == 32 || (size == 8 && !IsSigned)) { |
| 1073 |
return as_dtr(ls, size, mode, rt, |
| 1074 |
DTRAddr(rn, DtrRegImmShift(rm, LSL, scale)), cc); |
| 1075 |
} |
| 1076 |
|
| 1077 |
if (scale != TimesOne) { |
| 1078 |
ma_lsl(Imm32(scale), rm, scratch); |
| 1079 |
rm = scratch; |
| 1080 |
} |
| 1081 |
|
| 1082 |
return as_extdtr(ls, size, IsSigned, mode, rt, EDtrAddr(rn, EDtrOffReg(rm)), |
| 1083 |
cc); |
| 1084 |
} |
| 1085 |
|
| 1086 |
// No scratch register is required if scale is TimesOne. |
| 1087 |
BufferOffset MacroAssemblerARM::ma_dataTransferN(LoadStore ls, int size, |
| 1088 |
bool IsSigned, Register rn, |
| 1089 |
Register rm, Register rt, |
| 1090 |
Index mode, |
| 1091 |
Assembler::Condition cc) { |
| 1092 |
MOZ_ASSERT(size == 8 || size == 16 || size == 32 || size == 64); |
| 1093 |
if (size == 32 || (size == 8 && !IsSigned)) { |
| 1094 |
return as_dtr(ls, size, mode, rt, |
| 1095 |
DTRAddr(rn, DtrRegImmShift(rm, LSL, TimesOne)), cc); |
| 1096 |
} |
| 1097 |
return as_extdtr(ls, size, IsSigned, mode, rt, EDtrAddr(rn, EDtrOffReg(rm)), |
| 1098 |
cc); |
| 1099 |
} |
| 1100 |
|
| 1101 |
BufferOffset MacroAssemblerARM::ma_dataTransferN(LoadStore ls, int size, |
| 1102 |
bool IsSigned, Register rn, |
| 1103 |
Imm32 offset, Register rt, |
| 1104 |
AutoRegisterScope& scratch, |
| 1105 |
Index mode, |
| 1106 |
Assembler::Condition cc) { |
| 1107 |
MOZ_ASSERT(!(ls == IsLoad && mode == PostIndex && rt == pc), |
| 1108 |
"Large-offset PostIndex loading into PC requires special logic: " |
| 1109 |
"see ma_popn_pc()."); |
| 1110 |
|
| 1111 |
int off = offset.value; |
| 1112 |
|
| 1113 |
// We can encode this as a standard ldr. |
| 1114 |
if (size == 32 || (size == 8 && !IsSigned)) { |
| 1115 |
if (off < 4096 && off > -4096) { |
| 1116 |
// This encodes as a single instruction, Emulating mode's behavior |
| 1117 |
// in a multi-instruction sequence is not necessary. |
| 1118 |
return as_dtr(ls, size, mode, rt, DTRAddr(rn, DtrOffImm(off)), cc); |
| 1119 |
} |
| 1120 |
|
| 1121 |
// We cannot encode this offset in a single ldr. For mode == index, |
| 1122 |
// try to encode it as |add scratch, base, imm; ldr dest, [scratch, |
| 1123 |
// +offset]|. This does not wark for mode == PreIndex or mode == PostIndex. |
| 1124 |
// PreIndex is simple, just do the add into the base register first, |
| 1125 |
// then do a PreIndex'ed load. PostIndexed loads can be tricky. |
| 1126 |
// Normally, doing the load with an index of 0, then doing an add would |
| 1127 |
// work, but if the destination is the PC, you don't get to execute the |
| 1128 |
// instruction after the branch, which will lead to the base register |
| 1129 |
// not being updated correctly. Explicitly handle this case, without |
| 1130 |
// doing anything fancy, then handle all of the other cases. |
| 1131 |
|
| 1132 |
// mode == Offset |
| 1133 |
// add scratch, base, offset_hi |
| 1134 |
// ldr dest, [scratch, +offset_lo] |
| 1135 |
// |
| 1136 |
// mode == PreIndex |
| 1137 |
// add base, base, offset_hi |
| 1138 |
// ldr dest, [base, +offset_lo]! |
| 1139 |
|
| 1140 |
int bottom = off & 0xfff; |
| 1141 |
int neg_bottom = 0x1000 - bottom; |
| 1142 |
|
| 1143 |
MOZ_ASSERT(rn != scratch); |
| 1144 |
MOZ_ASSERT(mode != PostIndex); |
| 1145 |
|
| 1146 |
// At this point, both off - bottom and off + neg_bottom will be |
| 1147 |
// reasonable-ish quantities. |
| 1148 |
// |
| 1149 |
// Note a neg_bottom of 0x1000 can not be encoded as an immediate |
| 1150 |
// negative offset in the instruction and this occurs when bottom is |
| 1151 |
// zero, so this case is guarded against below. |
| 1152 |
if (off < 0) { |
| 1153 |
Operand2 sub_off = Imm8(-(off - bottom)); // sub_off = bottom - off |
| 1154 |
if (!sub_off.invalid()) { |
| 1155 |
// - sub_off = off - bottom |
| 1156 |
as_sub(scratch, rn, sub_off, LeaveCC, cc); |
| 1157 |
return as_dtr(ls, size, Offset, rt, DTRAddr(scratch, DtrOffImm(bottom)), |
| 1158 |
cc); |
| 1159 |
} |
| 1160 |
|
| 1161 |
// sub_off = -neg_bottom - off |
| 1162 |
sub_off = Imm8(-(off + neg_bottom)); |
| 1163 |
if (!sub_off.invalid() && bottom != 0) { |
| 1164 |
// Guarded against by: bottom != 0 |
| 1165 |
MOZ_ASSERT(neg_bottom < 0x1000); |
| 1166 |
// - sub_off = neg_bottom + off |
| 1167 |
as_sub(scratch, rn, sub_off, LeaveCC, cc); |
| 1168 |
return as_dtr(ls, size, Offset, rt, |
| 1169 |
DTRAddr(scratch, DtrOffImm(-neg_bottom)), cc); |
| 1170 |
} |
| 1171 |
} else { |
| 1172 |
// sub_off = off - bottom |
| 1173 |
Operand2 sub_off = Imm8(off - bottom); |
| 1174 |
if (!sub_off.invalid()) { |
| 1175 |
// sub_off = off - bottom |
| 1176 |
as_add(scratch, rn, sub_off, LeaveCC, cc); |
| 1177 |
return as_dtr(ls, size, Offset, rt, DTRAddr(scratch, DtrOffImm(bottom)), |
| 1178 |
cc); |
| 1179 |
} |
| 1180 |
|
| 1181 |
// sub_off = neg_bottom + off |
| 1182 |
sub_off = Imm8(off + neg_bottom); |
| 1183 |
if (!sub_off.invalid() && bottom != 0) { |
| 1184 |
// Guarded against by: bottom != 0 |
| 1185 |
MOZ_ASSERT(neg_bottom < 0x1000); |
| 1186 |
// sub_off = neg_bottom + off |
| 1187 |
as_add(scratch, rn, sub_off, LeaveCC, cc); |
| 1188 |
return as_dtr(ls, size, Offset, rt, |
| 1189 |
DTRAddr(scratch, DtrOffImm(-neg_bottom)), cc); |
| 1190 |
} |
| 1191 |
} |
| 1192 |
|
| 1193 |
ma_mov(offset, scratch); |
| 1194 |
return as_dtr(ls, size, mode, rt, |
| 1195 |
DTRAddr(rn, DtrRegImmShift(scratch, LSL, 0))); |
| 1196 |
} else { |
| 1197 |
// Should attempt to use the extended load/store instructions. |
| 1198 |
if (off < 256 && off > -256) { |
| 1199 |
return as_extdtr(ls, size, IsSigned, mode, rt, |
| 1200 |
EDtrAddr(rn, EDtrOffImm(off)), cc); |
| 1201 |
} |
| 1202 |
|
| 1203 |
// We cannot encode this offset in a single extldr. Try to encode it as |
| 1204 |
// an add scratch, base, imm; extldr dest, [scratch, +offset]. |
| 1205 |
int bottom = off & 0xff; |
| 1206 |
int neg_bottom = 0x100 - bottom; |
| 1207 |
// At this point, both off - bottom and off + neg_bottom will be |
| 1208 |
// reasonable-ish quantities. |
| 1209 |
// |
| 1210 |
// Note a neg_bottom of 0x100 can not be encoded as an immediate |
| 1211 |
// negative offset in the instruction and this occurs when bottom is |
| 1212 |
// zero, so this case is guarded against below. |
| 1213 |
if (off < 0) { |
| 1214 |
// sub_off = bottom - off |
| 1215 |
Operand2 sub_off = Imm8(-(off - bottom)); |
| 1216 |
if (!sub_off.invalid()) { |
| 1217 |
// - sub_off = off - bottom |
| 1218 |
as_sub(scratch, rn, sub_off, LeaveCC, cc); |
| 1219 |
return as_extdtr(ls, size, IsSigned, Offset, rt, |
| 1220 |
EDtrAddr(scratch, EDtrOffImm(bottom)), cc); |
| 1221 |
} |
| 1222 |
// sub_off = -neg_bottom - off |
| 1223 |
sub_off = Imm8(-(off + neg_bottom)); |
| 1224 |
if (!sub_off.invalid() && bottom != 0) { |
| 1225 |
// Guarded against by: bottom != 0 |
| 1226 |
MOZ_ASSERT(neg_bottom < 0x100); |
| 1227 |
// - sub_off = neg_bottom + off |
| 1228 |
as_sub(scratch, rn, sub_off, LeaveCC, cc); |
| 1229 |
return as_extdtr(ls, size, IsSigned, Offset, rt, |
| 1230 |
EDtrAddr(scratch, EDtrOffImm(-neg_bottom)), cc); |
| 1231 |
} |
| 1232 |
} else { |
| 1233 |
// sub_off = off - bottom |
| 1234 |
Operand2 sub_off = Imm8(off - bottom); |
| 1235 |
if (!sub_off.invalid()) { |
| 1236 |
// sub_off = off - bottom |
| 1237 |
as_add(scratch, rn, sub_off, LeaveCC, cc); |
| 1238 |
return as_extdtr(ls, size, IsSigned, Offset, rt, |
| 1239 |
EDtrAddr(scratch, EDtrOffImm(bottom)), cc); |
| 1240 |
} |
| 1241 |
// sub_off = neg_bottom + off |
| 1242 |
sub_off = Imm8(off + neg_bottom); |
| 1243 |
if (!sub_off.invalid() && bottom != 0) { |
| 1244 |
// Guarded against by: bottom != 0 |
| 1245 |
MOZ_ASSERT(neg_bottom < 0x100); |
| 1246 |
// sub_off = neg_bottom + off |
| 1247 |
as_add(scratch, rn, sub_off, LeaveCC, cc); |
| 1248 |
return as_extdtr(ls, size, IsSigned, Offset, rt, |
| 1249 |
EDtrAddr(scratch, EDtrOffImm(-neg_bottom)), cc); |
| 1250 |
} |
| 1251 |
} |
| 1252 |
ma_mov(offset, scratch); |
| 1253 |
return as_extdtr(ls, size, IsSigned, mode, rt, |
| 1254 |
EDtrAddr(rn, EDtrOffReg(scratch)), cc); |
| 1255 |
} |
| 1256 |
} |
| 1257 |
|
| 1258 |
void MacroAssemblerARM::ma_pop(Register r) { |
| 1259 |
as_dtr(IsLoad, 32, PostIndex, r, DTRAddr(sp, DtrOffImm(4))); |
| 1260 |
} |
| 1261 |
|
| 1262 |
void MacroAssemblerARM::ma_popn_pc(Imm32 n, AutoRegisterScope& scratch, |
| 1263 |
AutoRegisterScope& scratch2) { |
| 1264 |
// pc <- [sp]; sp += n |
| 1265 |
int32_t nv = n.value; |
| 1266 |
|
| 1267 |
if (nv < 4096 && nv >= -4096) { |
| 1268 |
as_dtr(IsLoad, 32, PostIndex, pc, DTRAddr(sp, DtrOffImm(nv))); |
| 1269 |
} else { |
| 1270 |
ma_mov(sp, scratch); |
| 1271 |
ma_add(Imm32(n), sp, scratch2); |
| 1272 |
as_dtr(IsLoad, 32, Offset, pc, DTRAddr(scratch, DtrOffImm(0))); |
| 1273 |
} |
| 1274 |
} |
| 1275 |
|
| 1276 |
void MacroAssemblerARM::ma_push(Register r) { |
| 1277 |
MOZ_ASSERT(r != sp, "Use ma_push_sp()."); |
| 1278 |
as_dtr(IsStore, 32, PreIndex, r, DTRAddr(sp, DtrOffImm(-4))); |
| 1279 |
} |
| 1280 |
|
| 1281 |
void MacroAssemblerARM::ma_push_sp(Register r, AutoRegisterScope& scratch) { |
| 1282 |
// Pushing sp is not well-defined: use two instructions. |
| 1283 |
MOZ_ASSERT(r == sp); |
| 1284 |
ma_mov(sp, scratch); |
| 1285 |
as_dtr(IsStore, 32, PreIndex, scratch, DTRAddr(sp, DtrOffImm(-4))); |
| 1286 |
} |
| 1287 |
|
| 1288 |
void MacroAssemblerARM::ma_vpop(VFPRegister r) { |
| 1289 |
startFloatTransferM(IsLoad, sp, IA, WriteBack); |
| 1290 |
transferFloatReg(r); |
| 1291 |
finishFloatTransfer(); |
| 1292 |
} |
| 1293 |
|
| 1294 |
void MacroAssemblerARM::ma_vpush(VFPRegister r) { |
| 1295 |
startFloatTransferM(IsStore, sp, DB, WriteBack); |
| 1296 |
transferFloatReg(r); |
| 1297 |
finishFloatTransfer(); |
| 1298 |
} |
| 1299 |
|
| 1300 |
// Barriers |
| 1301 |
void MacroAssemblerARM::ma_dmb(BarrierOption option) { |
| 1302 |
if (ARMFlags::HasDMBDSBISB()) { |
| 1303 |
as_dmb(option); |
| 1304 |
} else { |
| 1305 |
as_dmb_trap(); |
| 1306 |
} |
| 1307 |
} |
| 1308 |
|
| 1309 |
void MacroAssemblerARM::ma_dsb(BarrierOption option) { |
| 1310 |
if (ARMFlags::HasDMBDSBISB()) { |
| 1311 |
as_dsb(option); |
| 1312 |
} else { |
| 1313 |
as_dsb_trap(); |
| 1314 |
} |
| 1315 |
} |
| 1316 |
|
| 1317 |
// Branches when done from within arm-specific code. |
| 1318 |
BufferOffset MacroAssemblerARM::ma_b(Label* dest, Assembler::Condition c) { |
| 1319 |
return as_b(dest, c); |
| 1320 |
} |
| 1321 |
|
| 1322 |
void MacroAssemblerARM::ma_bx(Register dest, Assembler::Condition c) { |
| 1323 |
as_bx(dest, c); |
| 1324 |
} |
| 1325 |
|
| 1326 |
void MacroAssemblerARM::ma_b(void* target, Assembler::Condition c) { |
| 1327 |
// An immediate pool is used for easier patching. |
| 1328 |
as_Imm32Pool(pc, uint32_t(target), c); |
| 1329 |
} |
| 1330 |
|
| 1331 |
// This is almost NEVER necessary: we'll basically never be calling a label, |
| 1332 |
// except possibly in the crazy bailout-table case. |
| 1333 |
void MacroAssemblerARM::ma_bl(Label* dest, Assembler::Condition c) { |
| 1334 |
as_bl(dest, c); |
| 1335 |
} |
| 1336 |
|
| 1337 |
void MacroAssemblerARM::ma_blx(Register reg, Assembler::Condition c) { |
| 1338 |
as_blx(reg, c); |
| 1339 |
} |
| 1340 |
|
| 1341 |
// VFP/ALU |
| 1342 |
void MacroAssemblerARM::ma_vadd(FloatRegister src1, FloatRegister src2, |
| 1343 |
FloatRegister dst) { |
| 1344 |
as_vadd(VFPRegister(dst), VFPRegister(src1), VFPRegister(src2)); |
| 1345 |
} |
| 1346 |
|
| 1347 |
void MacroAssemblerARM::ma_vadd_f32(FloatRegister src1, FloatRegister src2, |
| 1348 |
FloatRegister dst) { |
| 1349 |
as_vadd(VFPRegister(dst).singleOverlay(), VFPRegister(src1).singleOverlay(), |
| 1350 |
VFPRegister(src2).singleOverlay()); |
| 1351 |
} |
| 1352 |
|
| 1353 |
void MacroAssemblerARM::ma_vsub(FloatRegister src1, FloatRegister src2, |
| 1354 |
FloatRegister dst) { |
| 1355 |
as_vsub(VFPRegister(dst), VFPRegister(src1), VFPRegister(src2)); |
| 1356 |
} |
| 1357 |
|
| 1358 |
void MacroAssemblerARM::ma_vsub_f32(FloatRegister src1, FloatRegister src2, |
| 1359 |
FloatRegister dst) { |
| 1360 |
as_vsub(VFPRegister(dst).singleOverlay(), VFPRegister(src1).singleOverlay(), |
| 1361 |
VFPRegister(src2).singleOverlay()); |
| 1362 |
} |
| 1363 |
|
| 1364 |
void MacroAssemblerARM::ma_vmul(FloatRegister src1, FloatRegister src2, |
| 1365 |
FloatRegister dst) { |
| 1366 |
as_vmul(VFPRegister(dst), VFPRegister(src1), VFPRegister(src2)); |
| 1367 |
} |
| 1368 |
|
| 1369 |
void MacroAssemblerARM::ma_vmul_f32(FloatRegister src1, FloatRegister src2, |
| 1370 |
FloatRegister dst) { |
| 1371 |
as_vmul(VFPRegister(dst).singleOverlay(), VFPRegister(src1).singleOverlay(), |
| 1372 |
VFPRegister(src2).singleOverlay()); |
| 1373 |
} |
| 1374 |
|
| 1375 |
void MacroAssemblerARM::ma_vdiv(FloatRegister src1, FloatRegister src2, |
| 1376 |
FloatRegister dst) { |
| 1377 |
as_vdiv(VFPRegister(dst), VFPRegister(src1), VFPRegister(src2)); |
| 1378 |
} |
| 1379 |
|
| 1380 |
void MacroAssemblerARM::ma_vdiv_f32(FloatRegister src1, FloatRegister src2, |
| 1381 |
FloatRegister dst) { |
| 1382 |
as_vdiv(VFPRegister(dst).singleOverlay(), VFPRegister(src1).singleOverlay(), |
| 1383 |
VFPRegister(src2).singleOverlay()); |
| 1384 |
} |
| 1385 |
|
| 1386 |
void MacroAssemblerARM::ma_vmov(FloatRegister src, FloatRegister dest, |
| 1387 |
Condition cc) { |
| 1388 |
as_vmov(dest, src, cc); |
| 1389 |
} |
| 1390 |
|
| 1391 |
void MacroAssemblerARM::ma_vmov_f32(FloatRegister src, FloatRegister dest, |
| 1392 |
Condition cc) { |
| 1393 |
as_vmov(VFPRegister(dest).singleOverlay(), VFPRegister(src).singleOverlay(), |
| 1394 |
cc); |
| 1395 |
} |
| 1396 |
|
| 1397 |
void MacroAssemblerARM::ma_vneg(FloatRegister src, FloatRegister dest, |
| 1398 |
Condition cc) { |
| 1399 |
as_vneg(dest, src, cc); |
| 1400 |
} |
| 1401 |
|
| 1402 |
void MacroAssemblerARM::ma_vneg_f32(FloatRegister src, FloatRegister dest, |
| 1403 |
Condition cc) { |
| 1404 |
as_vneg(VFPRegister(dest).singleOverlay(), VFPRegister(src).singleOverlay(), |
| 1405 |
cc); |
| 1406 |
} |
| 1407 |
|
| 1408 |
void MacroAssemblerARM::ma_vabs(FloatRegister src, FloatRegister dest, |
| 1409 |
Condition cc) { |
| 1410 |
as_vabs(dest, src, cc); |
| 1411 |
} |
| 1412 |
|
| 1413 |
void MacroAssemblerARM::ma_vabs_f32(FloatRegister src, FloatRegister dest, |
| 1414 |
Condition cc) { |
| 1415 |
as_vabs(VFPRegister(dest).singleOverlay(), VFPRegister(src).singleOverlay(), |
| 1416 |
cc); |
| 1417 |
} |
| 1418 |
|
| 1419 |
void MacroAssemblerARM::ma_vsqrt(FloatRegister src, FloatRegister dest, |
| 1420 |
Condition cc) { |
| 1421 |
as_vsqrt(dest, src, cc); |
| 1422 |
} |
| 1423 |
|
| 1424 |
void MacroAssemblerARM::ma_vsqrt_f32(FloatRegister src, FloatRegister dest, |
| 1425 |
Condition cc) { |
| 1426 |
as_vsqrt(VFPRegister(dest).singleOverlay(), VFPRegister(src).singleOverlay(), |
| 1427 |
cc); |
| 1428 |
} |
| 1429 |
|
| 1430 |
static inline uint32_t DoubleHighWord(double d) { |
| 1431 |
return static_cast<uint32_t>(BitwiseCast<uint64_t>(d) >> 32); |
| 1432 |
} |
| 1433 |
|
| 1434 |
static inline uint32_t DoubleLowWord(double d) { |
| 1435 |
return static_cast<uint32_t>(BitwiseCast<uint64_t>(d)) & uint32_t(0xffffffff); |
| 1436 |
} |
| 1437 |
|
| 1438 |
void MacroAssemblerARM::ma_vimm(double value, FloatRegister dest, |
| 1439 |
Condition cc) { |
| 1440 |
if (ARMFlags::HasVFPv3()) { |
| 1441 |
if (DoubleLowWord(value) == 0) { |
| 1442 |
if (DoubleHighWord(value) == 0) { |
| 1443 |
// To zero a register, load 1.0, then execute dN <- dN - dN |
| 1444 |
as_vimm(dest, VFPImm::One, cc); |
| 1445 |
as_vsub(dest, dest, dest, cc); |
| 1446 |
return; |
| 1447 |
} |
| 1448 |
|
| 1449 |
VFPImm enc(DoubleHighWord(value)); |
| 1450 |
if (enc.isValid()) { |
| 1451 |
as_vimm(dest, enc, cc); |
| 1452 |
return; |
| 1453 |
} |
| 1454 |
} |
| 1455 |
} |
| 1456 |
// Fall back to putting the value in a pool. |
| 1457 |
as_FImm64Pool(dest, value, cc); |
| 1458 |
} |
| 1459 |
|
| 1460 |
void MacroAssemblerARM::ma_vimm_f32(float value, FloatRegister dest, |
| 1461 |
Condition cc) { |
| 1462 |
VFPRegister vd = VFPRegister(dest).singleOverlay(); |
| 1463 |
if (ARMFlags::HasVFPv3()) { |
| 1464 |
if (IsPositiveZero(value)) { |
| 1465 |
// To zero a register, load 1.0, then execute sN <- sN - sN. |
| 1466 |
as_vimm(vd, VFPImm::One, cc); |
| 1467 |
as_vsub(vd, vd, vd, cc); |
| 1468 |
return; |
| 1469 |
} |
| 1470 |
|
| 1471 |
// Note that the vimm immediate float32 instruction encoding differs |
| 1472 |
// from the vimm immediate double encoding, but this difference matches |
| 1473 |
// the difference in the floating point formats, so it is possible to |
| 1474 |
// convert the float32 to a double and then use the double encoding |
| 1475 |
// paths. It is still necessary to firstly check that the double low |
| 1476 |
// word is zero because some float32 numbers set these bits and this can |
| 1477 |
// not be ignored. |
| 1478 |
double doubleValue(value); |
| 1479 |
if (DoubleLowWord(doubleValue) == 0) { |
| 1480 |
VFPImm enc(DoubleHighWord(doubleValue)); |
| 1481 |
if (enc.isValid()) { |
| 1482 |
as_vimm(vd, enc, cc); |
| 1483 |
return; |
| 1484 |
} |
| 1485 |
} |
| 1486 |
} |
| 1487 |
|
| 1488 |
// Fall back to putting the value in a pool. |
| 1489 |
as_FImm32Pool(vd, value, cc); |
| 1490 |
} |
| 1491 |
|
| 1492 |
void MacroAssemblerARM::ma_vcmp(FloatRegister src1, FloatRegister src2, |
| 1493 |
Condition cc) { |
| 1494 |
as_vcmp(VFPRegister(src1), VFPRegister(src2), cc); |
| 1495 |
} |
| 1496 |
|
| 1497 |
void MacroAssemblerARM::ma_vcmp_f32(FloatRegister src1, FloatRegister src2, |
| 1498 |
Condition cc) { |
| 1499 |
as_vcmp(VFPRegister(src1).singleOverlay(), VFPRegister(src2).singleOverlay(), |
| 1500 |
cc); |
| 1501 |
} |
| 1502 |
|
| 1503 |
void MacroAssemblerARM::ma_vcmpz(FloatRegister src1, Condition cc) { |
| 1504 |
as_vcmpz(VFPRegister(src1), cc); |
| 1505 |
} |
| 1506 |
|
| 1507 |
void MacroAssemblerARM::ma_vcmpz_f32(FloatRegister src1, Condition cc) { |
| 1508 |
as_vcmpz(VFPRegister(src1).singleOverlay(), cc); |
| 1509 |
} |
| 1510 |
|
| 1511 |
void MacroAssemblerARM::ma_vcvt_F64_I32(FloatRegister src, FloatRegister dest, |
| 1512 |
Condition cc) { |
| 1513 |
MOZ_ASSERT(src.isDouble()); |
| 1514 |
MOZ_ASSERT(dest.isSInt()); |
| 1515 |
as_vcvt(dest, src, false, cc); |
| 1516 |
} |
| 1517 |
|
| 1518 |
void MacroAssemblerARM::ma_vcvt_F64_U32(FloatRegister src, FloatRegister dest, |
| 1519 |
Condition cc) { |
| 1520 |
MOZ_ASSERT(src.isDouble()); |
| 1521 |
MOZ_ASSERT(dest.isUInt()); |
| 1522 |
as_vcvt(dest, src, false, cc); |
| 1523 |
} |
| 1524 |
|
| 1525 |
void MacroAssemblerARM::ma_vcvt_I32_F64(FloatRegister src, FloatRegister dest, |
| 1526 |
Condition cc) { |
| 1527 |
MOZ_ASSERT(src.isSInt()); |
| 1528 |
MOZ_ASSERT(dest.isDouble()); |
| 1529 |
as_vcvt(dest, src, false, cc); |
| 1530 |
} |
| 1531 |
|
| 1532 |
void MacroAssemblerARM::ma_vcvt_U32_F64(FloatRegister src, FloatRegister dest, |
| 1533 |
Condition cc) { |
| 1534 |
MOZ_ASSERT(src.isUInt()); |
| 1535 |
MOZ_ASSERT(dest.isDouble()); |
| 1536 |
as_vcvt(dest, src, false, cc); |
| 1537 |
} |
| 1538 |
|
| 1539 |
void MacroAssemblerARM::ma_vcvt_F32_I32(FloatRegister src, FloatRegister dest, |
| 1540 |
Condition cc) { |
| 1541 |
MOZ_ASSERT(src.isSingle()); |
| 1542 |
MOZ_ASSERT(dest.isSInt()); |
| 1543 |
as_vcvt(VFPRegister(dest).sintOverlay(), VFPRegister(src).singleOverlay(), |
| 1544 |
false, cc); |
| 1545 |
} |
| 1546 |
|
| 1547 |
void MacroAssemblerARM::ma_vcvt_F32_U32(FloatRegister src, FloatRegister dest, |
| 1548 |
Condition cc) { |
| 1549 |
MOZ_ASSERT(src.isSingle()); |
| 1550 |
MOZ_ASSERT(dest.isUInt()); |
| 1551 |
as_vcvt(VFPRegister(dest).uintOverlay(), VFPRegister(src).singleOverlay(), |
| 1552 |
false, cc); |
| 1553 |
} |
| 1554 |
|
| 1555 |
void MacroAssemblerARM::ma_vcvt_I32_F32(FloatRegister src, FloatRegister dest, |
| 1556 |
Condition cc) { |
| 1557 |
MOZ_ASSERT(src.isSInt()); |
| 1558 |
MOZ_ASSERT(dest.isSingle()); |
| 1559 |
as_vcvt(VFPRegister(dest).singleOverlay(), VFPRegister(src).sintOverlay(), |
| 1560 |
false, cc); |
| 1561 |
} |
| 1562 |
|
| 1563 |
void MacroAssemblerARM::ma_vcvt_U32_F32(FloatRegister src, FloatRegister dest, |
| 1564 |
Condition cc) { |
| 1565 |
MOZ_ASSERT(src.isUInt()); |
| 1566 |
MOZ_ASSERT(dest.isSingle()); |
| 1567 |
as_vcvt(VFPRegister(dest).singleOverlay(), VFPRegister(src).uintOverlay(), |
| 1568 |
false, cc); |
| 1569 |
} |
| 1570 |
|
| 1571 |
void MacroAssemblerARM::ma_vxfer(FloatRegister src, Register dest, |
| 1572 |
Condition cc) { |
| 1573 |
as_vxfer(dest, InvalidReg, VFPRegister(src).singleOverlay(), FloatToCore, cc); |
| 1574 |
} |
| 1575 |
|
| 1576 |
void MacroAssemblerARM::ma_vxfer(FloatRegister src, Register dest1, |
| 1577 |
Register dest2, Condition cc) { |
| 1578 |
as_vxfer(dest1, dest2, VFPRegister(src), FloatToCore, cc); |
| 1579 |
} |
| 1580 |
|
| 1581 |
void MacroAssemblerARM::ma_vxfer(Register src, FloatRegister dest, |
| 1582 |
Condition cc) { |
| 1583 |
as_vxfer(src, InvalidReg, VFPRegister(dest).singleOverlay(), CoreToFloat, cc); |
| 1584 |
} |
| 1585 |
|
| 1586 |
void MacroAssemblerARM::ma_vxfer(Register src1, Register src2, |
| 1587 |
FloatRegister dest, Condition cc) { |
| 1588 |
as_vxfer(src1, src2, VFPRegister(dest), CoreToFloat, cc); |
| 1589 |
} |
| 1590 |
|
| 1591 |
BufferOffset MacroAssemblerARM::ma_vdtr(LoadStore ls, const Address& addr, |
| 1592 |
VFPRegister rt, |
| 1593 |
AutoRegisterScope& scratch, |
| 1594 |
Condition cc) { |
| 1595 |
int off = addr.offset; |
| 1596 |
MOZ_ASSERT((off & 3) == 0); |
| 1597 |
Register base = addr.base; |
| 1598 |
if (off > -1024 && off < 1024) { |
| 1599 |
return as_vdtr(ls, rt, Operand(addr).toVFPAddr(), cc); |
| 1600 |
} |
| 1601 |
|
| 1602 |
// We cannot encode this offset in a a single ldr. Try to encode it as an |
| 1603 |
// add scratch, base, imm; ldr dest, [scratch, +offset]. |
| 1604 |
int bottom = off & (0xff << 2); |
| 1605 |
int neg_bottom = (0x100 << 2) - bottom; |
| 1606 |
// At this point, both off - bottom and off + neg_bottom will be |
| 1607 |
// reasonable-ish quantities. |
| 1608 |
// |
| 1609 |
// Note a neg_bottom of 0x400 can not be encoded as an immediate negative |
| 1610 |
// offset in the instruction and this occurs when bottom is zero, so this |
| 1611 |
// case is guarded against below. |
| 1612 |
if (off < 0) { |
| 1613 |
// sub_off = bottom - off |
| 1614 |
Operand2 sub_off = Imm8(-(off - bottom)); |
| 1615 |
if (!sub_off.invalid()) { |
| 1616 |
// - sub_off = off - bottom |
| 1617 |
as_sub(scratch, base, sub_off, LeaveCC, cc); |
| 1618 |
return as_vdtr(ls, rt, VFPAddr(scratch, VFPOffImm(bottom)), cc); |
| 1619 |
} |
| 1620 |
// sub_off = -neg_bottom - off |
| 1621 |
sub_off = Imm8(-(off + neg_bottom)); |
| 1622 |
if (!sub_off.invalid() && bottom != 0) { |
| 1623 |
// Guarded against by: bottom != 0 |
| 1624 |
MOZ_ASSERT(neg_bottom < 0x400); |
| 1625 |
// - sub_off = neg_bottom + off |
| 1626 |
as_sub(scratch, base, sub_off, LeaveCC, cc); |
| 1627 |
return as_vdtr(ls, rt, VFPAddr(scratch, VFPOffImm(-neg_bottom)), cc); |
| 1628 |
} |
| 1629 |
} else { |
| 1630 |
// sub_off = off - bottom |
| 1631 |
Operand2 sub_off = Imm8(off - bottom); |
| 1632 |
if (!sub_off.invalid()) { |
| 1633 |
// sub_off = off - bottom |
| 1634 |
as_add(scratch, base, sub_off, LeaveCC, cc); |
| 1635 |
return as_vdtr(ls, rt, VFPAddr(scratch, VFPOffImm(bottom)), cc); |
| 1636 |
} |
| 1637 |
// sub_off = neg_bottom + off |
| 1638 |
sub_off = Imm8(off + neg_bottom); |
| 1639 |
if (!sub_off.invalid() && bottom != 0) { |
| 1640 |
// Guarded against by: bottom != 0 |
| 1641 |
MOZ_ASSERT(neg_bottom < 0x400); |
| 1642 |
// sub_off = neg_bottom + off |
| 1643 |
as_add(scratch, base, sub_off, LeaveCC, cc); |
| 1644 |
return as_vdtr(ls, rt, VFPAddr(scratch, VFPOffImm(-neg_bottom)), cc); |
| 1645 |
} |
| 1646 |
} |
| 1647 |
|
| 1648 |
// Safe to use scratch as dest, since ma_add() overwrites dest at the end |
| 1649 |
// and can't use it as internal scratch since it may also == base. |
| 1650 |
ma_add(base, Imm32(off), scratch, scratch, LeaveCC, cc); |
| 1651 |
return as_vdtr(ls, rt, VFPAddr(scratch, VFPOffImm(0)), cc); |
| 1652 |
} |
| 1653 |
|
| 1654 |
BufferOffset MacroAssemblerARM::ma_vldr(VFPAddr addr, VFPRegister dest, |
| 1655 |
Condition cc) { |
| 1656 |
return as_vdtr(IsLoad, dest, addr, cc); |
| 1657 |
} |
| 1658 |
|
| 1659 |
BufferOffset MacroAssemblerARM::ma_vldr(const Address& addr, VFPRegister dest, |
| 1660 |
AutoRegisterScope& scratch, |
| 1661 |
Condition cc) { |
| 1662 |
return ma_vdtr(IsLoad, addr, dest, scratch, cc); |
| 1663 |
} |
| 1664 |
|
| 1665 |
BufferOffset MacroAssemblerARM::ma_vldr(VFPRegister src, Register base, |
| 1666 |
Register index, |
| 1667 |
AutoRegisterScope& scratch, |
| 1668 |
int32_t shift, Condition cc) { |
| 1669 |
as_add(scratch, base, lsl(index, shift), LeaveCC, cc); |
| 1670 |
return as_vdtr(IsLoad, src, Operand(Address(scratch, 0)).toVFPAddr(), cc); |
| 1671 |
} |
| 1672 |
|
| 1673 |
BufferOffset MacroAssemblerARM::ma_vstr(VFPRegister src, VFPAddr addr, |
| 1674 |
Condition cc) { |
| 1675 |
return as_vdtr(IsStore, src, addr, cc); |
| 1676 |
} |
| 1677 |
|
| 1678 |
BufferOffset MacroAssemblerARM::ma_vstr(VFPRegister src, const Address& addr, |
| 1679 |
AutoRegisterScope& scratch, |
| 1680 |
Condition cc) { |
| 1681 |
return ma_vdtr(IsStore, addr, src, scratch, cc); |
| 1682 |
} |
| 1683 |
|
| 1684 |
BufferOffset MacroAssemblerARM::ma_vstr( |
| 1685 |
VFPRegister src, Register base, Register index, AutoRegisterScope& scratch, |
| 1686 |
AutoRegisterScope& scratch2, int32_t shift, int32_t offset, Condition cc) { |
| 1687 |
as_add(scratch, base, lsl(index, shift), LeaveCC, cc); |
| 1688 |
return ma_vstr(src, Address(scratch, offset), scratch2, cc); |
| 1689 |
} |
| 1690 |
|
| 1691 |
// Without an offset, no second scratch register is necessary. |
| 1692 |
BufferOffset MacroAssemblerARM::ma_vstr(VFPRegister src, Register base, |
| 1693 |
Register index, |
| 1694 |
AutoRegisterScope& scratch, |
| 1695 |
int32_t shift, Condition cc) { |
| 1696 |
as_add(scratch, base, lsl(index, shift), LeaveCC, cc); |
| 1697 |
return as_vdtr(IsStore, src, Operand(Address(scratch, 0)).toVFPAddr(), cc); |
| 1698 |
} |
| 1699 |
|
| 1700 |
bool MacroAssemblerARMCompat::buildOOLFakeExitFrame(void* fakeReturnAddr) { |
| 1701 |
asMasm().PushFrameDescriptor(FrameType::IonJS); // descriptor_ |
| 1702 |
asMasm().Push(ImmPtr(fakeReturnAddr)); |
| 1703 |
asMasm().Push(FramePointer); |
| 1704 |
return true; |
| 1705 |
} |
| 1706 |
|
| 1707 |
void MacroAssemblerARMCompat::move32(Imm32 imm, Register dest) { |
| 1708 |
ma_mov(imm, dest); |
| 1709 |
} |
| 1710 |
|
| 1711 |
void MacroAssemblerARMCompat::move32(Register src, Register dest) { |
| 1712 |
ma_mov(src, dest); |
| 1713 |
} |
| 1714 |
|
| 1715 |
void MacroAssemblerARMCompat::movePtr(Register src, Register dest) { |
| 1716 |
ma_mov(src, dest); |
| 1717 |
} |
| 1718 |
|
| 1719 |
void MacroAssemblerARMCompat::movePtr(ImmWord imm, Register dest) { |
| 1720 |
ma_mov(Imm32(imm.value), dest); |
| 1721 |
} |
| 1722 |
|
| 1723 |
void MacroAssemblerARMCompat::movePtr(ImmGCPtr imm, Register dest) { |
| 1724 |
ma_mov(imm, dest); |
| 1725 |
} |
| 1726 |
|
| 1727 |
void MacroAssemblerARMCompat::movePtr(ImmPtr imm, Register dest) { |
| 1728 |
movePtr(ImmWord(uintptr_t(imm.value)), dest); |
| 1729 |
} |
| 1730 |
|
| 1731 |
void MacroAssemblerARMCompat::movePtr(wasm::SymbolicAddress imm, |
| 1732 |
Register dest) { |
| 1733 |
append(wasm::SymbolicAccess(CodeOffset(currentOffset()), imm)); |
| 1734 |
ma_movPatchable(Imm32(-1), dest, Always); |
| 1735 |
} |
| 1736 |
|
| 1737 |
FaultingCodeOffset MacroAssemblerARMCompat::load8ZeroExtend( |
| 1738 |
const Address& address, Register dest) { |
| 1739 |
ScratchRegisterScope scratch(asMasm()); |
| 1740 |
BufferOffset offset = ma_dataTransferN(IsLoad, 8, false, address.base, |
| 1741 |
Imm32(address.offset), dest, scratch); |
| 1742 |
return FaultingCodeOffset(offset.getOffset()); |
| 1743 |
} |
| 1744 |
|
| 1745 |
FaultingCodeOffset MacroAssemblerARMCompat::load8ZeroExtend( |
| 1746 |
const BaseIndex& src, Register dest) { |
| 1747 |
Register base = src.base; |
| 1748 |
uint32_t scale = Imm32::ShiftOf(src.scale).value; |
| 1749 |
|
| 1750 |
ScratchRegisterScope scratch(asMasm()); |
| 1751 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 1752 |
|
| 1753 |
FaultingCodeOffset fco; |
| 1754 |
if (src.offset == 0) { |
| 1755 |
fco = ma_ldrb(DTRAddr(base, DtrRegImmShift(src.index, LSL, scale)), dest); |
| 1756 |
} else { |
| 1757 |
ma_add(base, Imm32(src.offset), scratch, scratch2); |
| 1758 |
fco = |
| 1759 |
ma_ldrb(DTRAddr(scratch, DtrRegImmShift(src.index, LSL, scale)), dest); |
| 1760 |
} |
| 1761 |
return fco; |
| 1762 |
} |
| 1763 |
|
| 1764 |
FaultingCodeOffset MacroAssemblerARMCompat::load8SignExtend( |
| 1765 |
const Address& address, Register dest) { |
| 1766 |
ScratchRegisterScope scratch(asMasm()); |
| 1767 |
BufferOffset offset = ma_dataTransferN(IsLoad, 8, true, address.base, |
| 1768 |
Imm32(address.offset), dest, scratch); |
| 1769 |
return FaultingCodeOffset(offset.getOffset()); |
| 1770 |
} |
| 1771 |
|
| 1772 |
FaultingCodeOffset MacroAssemblerARMCompat::load8SignExtend( |
| 1773 |
const BaseIndex& src, Register dest) { |
| 1774 |
Register index = src.index; |
| 1775 |
|
| 1776 |
ScratchRegisterScope scratch(asMasm()); |
| 1777 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 1778 |
|
| 1779 |
// ARMv7 does not have LSL on an index register with an extended load. |
| 1780 |
if (src.scale != TimesOne) { |
| 1781 |
ma_lsl(Imm32::ShiftOf(src.scale), index, scratch); |
| 1782 |
index = scratch; |
| 1783 |
} |
| 1784 |
|
| 1785 |
if (src.offset != 0) { |
| 1786 |
if (index != scratch) { |
| 1787 |
ma_mov(index, scratch); |
| 1788 |
index = scratch; |
| 1789 |
} |
| 1790 |
ma_add(Imm32(src.offset), index, scratch2); |
| 1791 |
} |
| 1792 |
return ma_ldrsb(EDtrAddr(src.base, EDtrOffReg(index)), dest); |
| 1793 |
} |
| 1794 |
|
| 1795 |
FaultingCodeOffset MacroAssemblerARMCompat::load16ZeroExtend( |
| 1796 |
const Address& address, Register dest) { |
| 1797 |
ScratchRegisterScope scratch(asMasm()); |
| 1798 |
BufferOffset offset = ma_dataTransferN(IsLoad, 16, false, address.base, |
| 1799 |
Imm32(address.offset), dest, scratch); |
| 1800 |
return FaultingCodeOffset(offset.getOffset()); |
| 1801 |
} |
| 1802 |
|
| 1803 |
FaultingCodeOffset MacroAssemblerARMCompat::load16ZeroExtend( |
| 1804 |
const BaseIndex& src, Register dest) { |
| 1805 |
Register index = src.index; |
| 1806 |
|
| 1807 |
ScratchRegisterScope scratch(asMasm()); |
| 1808 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 1809 |
|
| 1810 |
// ARMv7 does not have LSL on an index register with an extended load. |
| 1811 |
if (src.scale != TimesOne) { |
| 1812 |
ma_lsl(Imm32::ShiftOf(src.scale), index, scratch); |
| 1813 |
index = scratch; |
| 1814 |
} |
| 1815 |
|
| 1816 |
if (src.offset != 0) { |
| 1817 |
if (index != scratch) { |
| 1818 |
ma_mov(index, scratch); |
| 1819 |
index = scratch; |
| 1820 |
} |
| 1821 |
ma_add(Imm32(src.offset), index, scratch2); |
| 1822 |
} |
| 1823 |
return ma_ldrh(EDtrAddr(src.base, EDtrOffReg(index)), dest); |
| 1824 |
} |
| 1825 |
|
| 1826 |
FaultingCodeOffset MacroAssemblerARMCompat::load16SignExtend( |
| 1827 |
const Address& address, Register dest) { |
| 1828 |
ScratchRegisterScope scratch(asMasm()); |
| 1829 |
BufferOffset offset = ma_dataTransferN(IsLoad, 16, true, address.base, |
| 1830 |
Imm32(address.offset), dest, scratch); |
| 1831 |
return FaultingCodeOffset(offset.getOffset()); |
| 1832 |
} |
| 1833 |
|
| 1834 |
FaultingCodeOffset MacroAssemblerARMCompat::load16SignExtend( |
| 1835 |
const BaseIndex& src, Register dest) { |
| 1836 |
Register index = src.index; |
| 1837 |
|
| 1838 |
ScratchRegisterScope scratch(asMasm()); |
| 1839 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 1840 |
|
| 1841 |
// We don't have LSL on index register yet. |
| 1842 |
if (src.scale != TimesOne) { |
| 1843 |
ma_lsl(Imm32::ShiftOf(src.scale), index, scratch); |
| 1844 |
index = scratch; |
| 1845 |
} |
| 1846 |
|
| 1847 |
if (src.offset != 0) { |
| 1848 |
if (index != scratch) { |
| 1849 |
ma_mov(index, scratch); |
| 1850 |
index = scratch; |
| 1851 |
} |
| 1852 |
ma_add(Imm32(src.offset), index, scratch2); |
| 1853 |
} |
| 1854 |
return ma_ldrsh(EDtrAddr(src.base, EDtrOffReg(index)), dest); |
| 1855 |
} |
| 1856 |
|
| 1857 |
FaultingCodeOffset MacroAssemblerARMCompat::load32(const Address& address, |
| 1858 |
Register dest) { |
| 1859 |
return loadPtr(address, dest); |
| 1860 |
} |
| 1861 |
|
| 1862 |
FaultingCodeOffset MacroAssemblerARMCompat::load32(const BaseIndex& address, |
| 1863 |
Register dest) { |
| 1864 |
return loadPtr(address, dest); |
| 1865 |
} |
| 1866 |
|
| 1867 |
void MacroAssemblerARMCompat::load32(AbsoluteAddress address, Register dest) { |
| 1868 |
loadPtr(address, dest); |
| 1869 |
} |
| 1870 |
|
| 1871 |
FaultingCodeOffset MacroAssemblerARMCompat::loadPtr(const Address& address, |
| 1872 |
Register dest) { |
| 1873 |
ScratchRegisterScope scratch(asMasm()); |
| 1874 |
return ma_ldr(address, dest, scratch); |
| 1875 |
} |
| 1876 |
|
| 1877 |
FaultingCodeOffset MacroAssemblerARMCompat::loadPtr(const BaseIndex& src, |
| 1878 |
Register dest) { |
| 1879 |
Register base = src.base; |
| 1880 |
uint32_t scale = Imm32::ShiftOf(src.scale).value; |
| 1881 |
|
| 1882 |
ScratchRegisterScope scratch(asMasm()); |
| 1883 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 1884 |
|
| 1885 |
FaultingCodeOffset fco; |
| 1886 |
if (src.offset != 0) { |
| 1887 |
ma_add(base, Imm32(src.offset), scratch, scratch2); |
| 1888 |
fco = ma_ldr(DTRAddr(scratch, DtrRegImmShift(src.index, LSL, scale)), dest); |
| 1889 |
} else { |
| 1890 |
fco = ma_ldr(DTRAddr(base, DtrRegImmShift(src.index, LSL, scale)), dest); |
| 1891 |
} |
| 1892 |
return fco; |
| 1893 |
} |
| 1894 |
|
| 1895 |
void MacroAssemblerARMCompat::loadPtr(AbsoluteAddress address, Register dest) { |
| 1896 |
MOZ_ASSERT(dest != pc); // Use dest as a scratch register. |
| 1897 |
movePtr(ImmWord(uintptr_t(address.addr)), dest); |
| 1898 |
loadPtr(Address(dest, 0), dest); |
| 1899 |
} |
| 1900 |
|
| 1901 |
void MacroAssemblerARMCompat::loadPtr(wasm::SymbolicAddress address, |
| 1902 |
Register dest) { |
| 1903 |
MOZ_ASSERT(dest != pc); // Use dest as a scratch register. |
| 1904 |
movePtr(address, dest); |
| 1905 |
loadPtr(Address(dest, 0), dest); |
| 1906 |
} |
| 1907 |
|
| 1908 |
void MacroAssemblerARMCompat::loadPrivate(const Address& address, |
| 1909 |
Register dest) { |
| 1910 |
ScratchRegisterScope scratch(asMasm()); |
| 1911 |
ma_ldr(ToPayload(address), dest, scratch); |
| 1912 |
} |
| 1913 |
|
| 1914 |
FaultingCodeOffset MacroAssemblerARMCompat::loadDouble(const Address& address, |
| 1915 |
FloatRegister dest) { |
| 1916 |
ScratchRegisterScope scratch(asMasm()); |
| 1917 |
BufferOffset offset = ma_vldr(address, dest, scratch); |
| 1918 |
return FaultingCodeOffset(offset.getOffset()); |
| 1919 |
} |
| 1920 |
|
| 1921 |
FaultingCodeOffset MacroAssemblerARMCompat::loadDouble(const BaseIndex& src, |
| 1922 |
FloatRegister dest) { |
| 1923 |
// VFP instructions don't even support register Base + register Index modes, |
| 1924 |
// so just add the index, then handle the offset like normal. |
| 1925 |
Register base = src.base; |
| 1926 |
Register index = src.index; |
| 1927 |
uint32_t scale = Imm32::ShiftOf(src.scale).value; |
| 1928 |
int32_t offset = src.offset; |
| 1929 |
|
| 1930 |
ScratchRegisterScope scratch(asMasm()); |
| 1931 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 1932 |
|
| 1933 |
as_add(scratch, base, lsl(index, scale)); |
| 1934 |
BufferOffset boffset = ma_vldr(Address(scratch, offset), dest, scratch2); |
| 1935 |
return FaultingCodeOffset(boffset.getOffset()); |
| 1936 |
} |
| 1937 |
|
| 1938 |
FaultingCodeOffset MacroAssemblerARMCompat::loadFloat32(const Address& address, |
| 1939 |
FloatRegister dest) { |
| 1940 |
ScratchRegisterScope scratch(asMasm()); |
| 1941 |
BufferOffset offset = |
| 1942 |
ma_vldr(address, VFPRegister(dest).singleOverlay(), scratch); |
| 1943 |
return FaultingCodeOffset(offset.getOffset()); |
| 1944 |
} |
| 1945 |
|
| 1946 |
FaultingCodeOffset MacroAssemblerARMCompat::loadFloat32(const BaseIndex& src, |
| 1947 |
FloatRegister dest) { |
| 1948 |
// VFP instructions don't even support register Base + register Index modes, |
| 1949 |
// so just add the index, then handle the offset like normal. |
| 1950 |
Register base = src.base; |
| 1951 |
Register index = src.index; |
| 1952 |
uint32_t scale = Imm32::ShiftOf(src.scale).value; |
| 1953 |
int32_t offset = src.offset; |
| 1954 |
|
| 1955 |
ScratchRegisterScope scratch(asMasm()); |
| 1956 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 1957 |
|
| 1958 |
as_add(scratch, base, lsl(index, scale)); |
| 1959 |
BufferOffset boffset = ma_vldr(Address(scratch, offset), |
| 1960 |
VFPRegister(dest).singleOverlay(), scratch2); |
| 1961 |
return FaultingCodeOffset(boffset.getOffset()); |
| 1962 |
} |
| 1963 |
|
| 1964 |
FaultingCodeOffset MacroAssemblerARMCompat::loadFloat16(const Address& address, |
| 1965 |
FloatRegister dest, |
| 1966 |
Register scratch) { |
| 1967 |
auto fco = load16ZeroExtend(address, scratch); |
| 1968 |
ma_vxfer(scratch, dest); |
| 1969 |
return fco; |
| 1970 |
} |
| 1971 |
|
| 1972 |
FaultingCodeOffset MacroAssemblerARMCompat::loadFloat16(const BaseIndex& src, |
| 1973 |
FloatRegister dest, |
| 1974 |
Register scratch) { |
| 1975 |
auto fco = load16ZeroExtend(src, scratch); |
| 1976 |
ma_vxfer(scratch, dest); |
| 1977 |
return fco; |
| 1978 |
} |
| 1979 |
|
| 1980 |
void MacroAssemblerARMCompat::store8(Imm32 imm, const Address& address) { |
| 1981 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 1982 |
ma_mov(imm, scratch2); |
| 1983 |
store8(scratch2, address); |
| 1984 |
} |
| 1985 |
|
| 1986 |
FaultingCodeOffset MacroAssemblerARMCompat::store8(Register src, |
| 1987 |
const Address& address) { |
| 1988 |
ScratchRegisterScope scratch(asMasm()); |
| 1989 |
BufferOffset offset = ma_dataTransferN(IsStore, 8, false, address.base, |
| 1990 |
Imm32(address.offset), src, scratch); |
| 1991 |
return FaultingCodeOffset(offset.getOffset()); |
| 1992 |
} |
| 1993 |
|
| 1994 |
void MacroAssemblerARMCompat::store8(Imm32 imm, const BaseIndex& dest) { |
| 1995 |
Register base = dest.base; |
| 1996 |
uint32_t scale = Imm32::ShiftOf(dest.scale).value; |
| 1997 |
|
| 1998 |
ScratchRegisterScope scratch(asMasm()); |
| 1999 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2000 |
|
| 2001 |
if (dest.offset != 0) { |
| 2002 |
ma_add(base, Imm32(dest.offset), scratch, scratch2); |
| 2003 |
ma_mov(imm, scratch2); |
| 2004 |
ma_strb(scratch2, DTRAddr(scratch, DtrRegImmShift(dest.index, LSL, scale))); |
| 2005 |
} else { |
| 2006 |
ma_mov(imm, scratch2); |
| 2007 |
ma_strb(scratch2, DTRAddr(base, DtrRegImmShift(dest.index, LSL, scale))); |
| 2008 |
} |
| 2009 |
} |
| 2010 |
|
| 2011 |
FaultingCodeOffset MacroAssemblerARMCompat::store8(Register src, |
| 2012 |
const BaseIndex& dest) { |
| 2013 |
Register base = dest.base; |
| 2014 |
uint32_t scale = Imm32::ShiftOf(dest.scale).value; |
| 2015 |
|
| 2016 |
ScratchRegisterScope scratch(asMasm()); |
| 2017 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2018 |
|
| 2019 |
FaultingCodeOffset fco; |
| 2020 |
if (dest.offset != 0) { |
| 2021 |
ma_add(base, Imm32(dest.offset), scratch, scratch2); |
| 2022 |
fco = |
| 2023 |
ma_strb(src, DTRAddr(scratch, DtrRegImmShift(dest.index, LSL, scale))); |
| 2024 |
} else { |
| 2025 |
fco = ma_strb(src, DTRAddr(base, DtrRegImmShift(dest.index, LSL, scale))); |
| 2026 |
} |
| 2027 |
return fco; |
| 2028 |
} |
| 2029 |
|
| 2030 |
void MacroAssemblerARMCompat::store16(Imm32 imm, const Address& address) { |
| 2031 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2032 |
ma_mov(imm, scratch2); |
| 2033 |
store16(scratch2, address); |
| 2034 |
} |
| 2035 |
|
| 2036 |
FaultingCodeOffset MacroAssemblerARMCompat::store16(Register src, |
| 2037 |
const Address& address) { |
| 2038 |
ScratchRegisterScope scratch(asMasm()); |
| 2039 |
BufferOffset offset = ma_dataTransferN(IsStore, 16, false, address.base, |
| 2040 |
Imm32(address.offset), src, scratch); |
| 2041 |
return FaultingCodeOffset(offset.getOffset()); |
| 2042 |
} |
| 2043 |
|
| 2044 |
void MacroAssemblerARMCompat::store16(Imm32 imm, const BaseIndex& dest) { |
| 2045 |
Register index = dest.index; |
| 2046 |
|
| 2047 |
ScratchRegisterScope scratch(asMasm()); |
| 2048 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2049 |
|
| 2050 |
// We don't have LSL on index register yet. |
| 2051 |
if (dest.scale != TimesOne) { |
| 2052 |
ma_lsl(Imm32::ShiftOf(dest.scale), index, scratch); |
| 2053 |
index = scratch; |
| 2054 |
} |
| 2055 |
|
| 2056 |
if (dest.offset != 0) { |
| 2057 |
ma_add(index, Imm32(dest.offset), scratch, scratch2); |
| 2058 |
index = scratch; |
| 2059 |
} |
| 2060 |
|
| 2061 |
ma_mov(imm, scratch2); |
| 2062 |
ma_strh(scratch2, EDtrAddr(dest.base, EDtrOffReg(index))); |
| 2063 |
} |
| 2064 |
|
| 2065 |
FaultingCodeOffset MacroAssemblerARMCompat::store16(Register src, |
| 2066 |
const BaseIndex& address) { |
| 2067 |
Register index = address.index; |
| 2068 |
|
| 2069 |
ScratchRegisterScope scratch(asMasm()); |
| 2070 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2071 |
|
| 2072 |
// We don't have LSL on index register yet. |
| 2073 |
if (address.scale != TimesOne) { |
| 2074 |
ma_lsl(Imm32::ShiftOf(address.scale), index, scratch); |
| 2075 |
index = scratch; |
| 2076 |
} |
| 2077 |
|
| 2078 |
if (address.offset != 0) { |
| 2079 |
ma_add(index, Imm32(address.offset), scratch, scratch2); |
| 2080 |
index = scratch; |
| 2081 |
} |
| 2082 |
return ma_strh(src, EDtrAddr(address.base, EDtrOffReg(index))); |
| 2083 |
} |
| 2084 |
|
| 2085 |
void MacroAssemblerARMCompat::store32(Register src, AbsoluteAddress address) { |
| 2086 |
storePtr(src, address); |
| 2087 |
} |
| 2088 |
|
| 2089 |
FaultingCodeOffset MacroAssemblerARMCompat::store32(Register src, |
| 2090 |
const Address& address) { |
| 2091 |
return storePtr(src, address); |
| 2092 |
} |
| 2093 |
|
| 2094 |
void MacroAssemblerARMCompat::store32(Imm32 src, const Address& address) { |
| 2095 |
ScratchRegisterScope scratch(asMasm()); |
| 2096 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2097 |
move32(src, scratch); |
| 2098 |
ma_str(scratch, address, scratch2); |
| 2099 |
} |
| 2100 |
|
| 2101 |
void MacroAssemblerARMCompat::store32(Imm32 imm, const BaseIndex& dest) { |
| 2102 |
Register base = dest.base; |
| 2103 |
uint32_t scale = Imm32::ShiftOf(dest.scale).value; |
| 2104 |
|
| 2105 |
ScratchRegisterScope scratch(asMasm()); |
| 2106 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2107 |
|
| 2108 |
if (dest.offset != 0) { |
| 2109 |
ma_add(base, Imm32(dest.offset), scratch, scratch2); |
| 2110 |
ma_mov(imm, scratch2); |
| 2111 |
ma_str(scratch2, DTRAddr(scratch, DtrRegImmShift(dest.index, LSL, scale))); |
| 2112 |
} else { |
| 2113 |
ma_mov(imm, scratch); |
| 2114 |
ma_str(scratch, DTRAddr(base, DtrRegImmShift(dest.index, LSL, scale))); |
| 2115 |
} |
| 2116 |
} |
| 2117 |
|
| 2118 |
FaultingCodeOffset MacroAssemblerARMCompat::store32(Register src, |
| 2119 |
const BaseIndex& dest) { |
| 2120 |
Register base = dest.base; |
| 2121 |
uint32_t scale = Imm32::ShiftOf(dest.scale).value; |
| 2122 |
|
| 2123 |
ScratchRegisterScope scratch(asMasm()); |
| 2124 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2125 |
|
| 2126 |
FaultingCodeOffset fco; |
| 2127 |
if (dest.offset != 0) { |
| 2128 |
ma_add(base, Imm32(dest.offset), scratch, scratch2); |
| 2129 |
fco = ma_str(src, DTRAddr(scratch, DtrRegImmShift(dest.index, LSL, scale))); |
| 2130 |
} else { |
| 2131 |
fco = ma_str(src, DTRAddr(base, DtrRegImmShift(dest.index, LSL, scale))); |
| 2132 |
} |
| 2133 |
return fco; |
| 2134 |
} |
| 2135 |
|
| 2136 |
void MacroAssemblerARMCompat::storePtr(ImmWord imm, const Address& address) { |
| 2137 |
store32(Imm32(imm.value), address); |
| 2138 |
} |
| 2139 |
|
| 2140 |
void MacroAssemblerARMCompat::storePtr(ImmWord imm, const BaseIndex& address) { |
| 2141 |
store32(Imm32(imm.value), address); |
| 2142 |
} |
| 2143 |
|
| 2144 |
void MacroAssemblerARMCompat::storePtr(ImmPtr imm, const Address& address) { |
| 2145 |
store32(Imm32(uintptr_t(imm.value)), address); |
| 2146 |
} |
| 2147 |
|
| 2148 |
void MacroAssemblerARMCompat::storePtr(ImmPtr imm, const BaseIndex& address) { |
| 2149 |
store32(Imm32(uintptr_t(imm.value)), address); |
| 2150 |
} |
| 2151 |
|
| 2152 |
void MacroAssemblerARMCompat::storePtr(ImmGCPtr imm, const Address& address) { |
| 2153 |
ScratchRegisterScope scratch(asMasm()); |
| 2154 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2155 |
ma_mov(imm, scratch); |
| 2156 |
ma_str(scratch, address, scratch2); |
| 2157 |
} |
| 2158 |
|
| 2159 |
void MacroAssemblerARMCompat::storePtr(ImmGCPtr imm, const BaseIndex& address) { |
| 2160 |
Register base = address.base; |
| 2161 |
uint32_t scale = Imm32::ShiftOf(address.scale).value; |
| 2162 |
|
| 2163 |
ScratchRegisterScope scratch(asMasm()); |
| 2164 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2165 |
|
| 2166 |
if (address.offset != 0) { |
| 2167 |
ma_add(base, Imm32(address.offset), scratch, scratch2); |
| 2168 |
ma_mov(imm, scratch2); |
| 2169 |
ma_str(scratch2, |
| 2170 |
DTRAddr(scratch, DtrRegImmShift(address.index, LSL, scale))); |
| 2171 |
} else { |
| 2172 |
ma_mov(imm, scratch); |
| 2173 |
ma_str(scratch, DTRAddr(base, DtrRegImmShift(address.index, LSL, scale))); |
| 2174 |
} |
| 2175 |
} |
| 2176 |
|
| 2177 |
FaultingCodeOffset MacroAssemblerARMCompat::storePtr(Register src, |
| 2178 |
const Address& address) { |
| 2179 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2180 |
return ma_str(src, address, scratch2); |
| 2181 |
} |
| 2182 |
|
| 2183 |
FaultingCodeOffset MacroAssemblerARMCompat::storePtr(Register src, |
| 2184 |
const BaseIndex& address) { |
| 2185 |
return store32(src, address); |
| 2186 |
} |
| 2187 |
|
| 2188 |
void MacroAssemblerARMCompat::storePtr(Register src, AbsoluteAddress dest) { |
| 2189 |
ScratchRegisterScope scratch(asMasm()); |
| 2190 |
movePtr(ImmWord(uintptr_t(dest.addr)), scratch); |
| 2191 |
ma_str(src, DTRAddr(scratch, DtrOffImm(0))); |
| 2192 |
} |
| 2193 |
|
| 2194 |
// Note: this function clobbers the input register. |
| 2195 |
void MacroAssembler::clampDoubleToUint8(FloatRegister input, Register output) { |
| 2196 |
ScratchDoubleScope scratchDouble(*this); |
| 2197 |
MOZ_ASSERT(input != scratchDouble); |
| 2198 |
|
| 2199 |
Label done; |
| 2200 |
|
| 2201 |
// Set to zero if NaN. |
| 2202 |
compareDouble(input, NoVFPRegister); |
| 2203 |
ma_mov(Imm32(0), output, VFP_Unordered); |
| 2204 |
ma_b(&done, VFP_Unordered); |
| 2205 |
|
| 2206 |
// Do the conversion to an integer. |
| 2207 |
as_vcvt(VFPRegister(scratchDouble).uintOverlay(), VFPRegister(input)); |
| 2208 |
|
| 2209 |
// Copy the converted value out. |
| 2210 |
as_vxfer(output, InvalidReg, scratchDouble, FloatToCore); |
| 2211 |
|
| 2212 |
// Clamp to 255. |
| 2213 |
as_cmp(output, Imm8(0xff)); |
| 2214 |
ma_mov(Imm32(0xff), output, Above); |
| 2215 |
ma_b(&done, AboveOrEqual); |
| 2216 |
|
| 2217 |
// Convert it back to see if we got the same value back. |
| 2218 |
as_vcvt(scratchDouble, VFPRegister(scratchDouble).uintOverlay()); |
| 2219 |
ma_vsub(input, scratchDouble, input); |
| 2220 |
|
| 2221 |
loadConstantDouble(0.5, scratchDouble); |
| 2222 |
|
| 2223 |
// Do the check. |
| 2224 |
compareDouble(input, scratchDouble); |
| 2225 |
|
| 2226 |
// Round up if > 0.5. |
| 2227 |
as_add(output, output, Imm8(1), LeaveCC, VFP_GreaterThan); |
| 2228 |
|
| 2229 |
// Round up if == 0.5 and output is odd. |
| 2230 |
as_add(output, output, Imm8(1), LeaveCC, VFP_Equal); |
| 2231 |
as_bic(output, output, Imm8(1), LeaveCC, VFP_Equal); |
| 2232 |
|
| 2233 |
bind(&done); |
| 2234 |
} |
| 2235 |
|
| 2236 |
void MacroAssemblerARMCompat::cmp32(Register lhs, Imm32 rhs) { |
| 2237 |
ScratchRegisterScope scratch(asMasm()); |
| 2238 |
ma_cmp(lhs, rhs, scratch); |
| 2239 |
} |
| 2240 |
|
| 2241 |
void MacroAssemblerARMCompat::cmp32(Register lhs, Register rhs) { |
| 2242 |
ma_cmp(lhs, rhs); |
| 2243 |
} |
| 2244 |
|
| 2245 |
void MacroAssemblerARMCompat::cmp32(const Address& lhs, Imm32 rhs) { |
| 2246 |
ScratchRegisterScope scratch(asMasm()); |
| 2247 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2248 |
ma_ldr(lhs, scratch, scratch2); |
| 2249 |
ma_cmp(scratch, rhs, scratch2); |
| 2250 |
} |
| 2251 |
|
| 2252 |
void MacroAssemblerARMCompat::cmp32(const Address& lhs, Register rhs) { |
| 2253 |
ScratchRegisterScope scratch(asMasm()); |
| 2254 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2255 |
ma_ldr(lhs, scratch, scratch2); |
| 2256 |
ma_cmp(scratch, rhs); |
| 2257 |
} |
| 2258 |
|
| 2259 |
void MacroAssemblerARMCompat::cmpPtr(Register lhs, ImmWord rhs) { |
| 2260 |
cmp32(lhs, Imm32(rhs.value)); |
| 2261 |
} |
| 2262 |
|
| 2263 |
void MacroAssemblerARMCompat::cmpPtr(Register lhs, ImmPtr rhs) { |
| 2264 |
cmpPtr(lhs, ImmWord(uintptr_t(rhs.value))); |
| 2265 |
} |
| 2266 |
|
| 2267 |
void MacroAssemblerARMCompat::cmpPtr(Register lhs, Register rhs) { |
| 2268 |
ma_cmp(lhs, rhs); |
| 2269 |
} |
| 2270 |
|
| 2271 |
void MacroAssemblerARMCompat::cmpPtr(Register lhs, ImmGCPtr rhs) { |
| 2272 |
ScratchRegisterScope scratch(asMasm()); |
| 2273 |
ma_cmp(lhs, rhs, scratch); |
| 2274 |
} |
| 2275 |
|
| 2276 |
void MacroAssemblerARMCompat::cmpPtr(Register lhs, Imm32 rhs) { |
| 2277 |
cmp32(lhs, rhs); |
| 2278 |
} |
| 2279 |
|
| 2280 |
void MacroAssemblerARMCompat::cmpPtr(const Address& lhs, Register rhs) { |
| 2281 |
ScratchRegisterScope scratch(asMasm()); |
| 2282 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2283 |
ma_ldr(lhs, scratch, scratch2); |
| 2284 |
ma_cmp(scratch, rhs); |
| 2285 |
} |
| 2286 |
|
| 2287 |
void MacroAssemblerARMCompat::cmpPtr(const Address& lhs, ImmWord rhs) { |
| 2288 |
ScratchRegisterScope scratch(asMasm()); |
| 2289 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2290 |
ma_ldr(lhs, scratch, scratch2); |
| 2291 |
ma_cmp(scratch, Imm32(rhs.value), scratch2); |
| 2292 |
} |
| 2293 |
|
| 2294 |
void MacroAssemblerARMCompat::cmpPtr(const Address& lhs, ImmPtr rhs) { |
| 2295 |
cmpPtr(lhs, ImmWord(uintptr_t(rhs.value))); |
| 2296 |
} |
| 2297 |
|
| 2298 |
void MacroAssemblerARMCompat::cmpPtr(const Address& lhs, ImmGCPtr rhs) { |
| 2299 |
ScratchRegisterScope scratch(asMasm()); |
| 2300 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2301 |
ma_ldr(lhs, scratch, scratch2); |
| 2302 |
ma_cmp(scratch, rhs, scratch2); |
| 2303 |
} |
| 2304 |
|
| 2305 |
void MacroAssemblerARMCompat::cmpPtr(const Address& lhs, Imm32 rhs) { |
| 2306 |
ScratchRegisterScope scratch(asMasm()); |
| 2307 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2308 |
ma_ldr(lhs, scratch, scratch2); |
| 2309 |
ma_cmp(scratch, rhs, scratch2); |
| 2310 |
} |
| 2311 |
|
| 2312 |
void MacroAssemblerARMCompat::setStackArg(Register reg, uint32_t arg) { |
| 2313 |
ScratchRegisterScope scratch(asMasm()); |
| 2314 |
ma_dataTransferN(IsStore, 32, true, sp, Imm32(arg * sizeof(intptr_t)), reg, |
| 2315 |
scratch); |
| 2316 |
} |
| 2317 |
|
| 2318 |
void MacroAssemblerARMCompat::minMaxDouble(FloatRegister srcDest, |
| 2319 |
FloatRegister second, bool canBeNaN, |
| 2320 |
bool isMax) { |
| 2321 |
FloatRegister first = srcDest; |
| 2322 |
|
| 2323 |
Label nan, equal, returnSecond, done; |
| 2324 |
|
| 2325 |
Assembler::Condition cond = isMax ? Assembler::VFP_LessThanOrEqual |
| 2326 |
: Assembler::VFP_GreaterThanOrEqual; |
| 2327 |
|
| 2328 |
compareDouble(first, second); |
| 2329 |
// First or second is NaN, result is NaN. |
| 2330 |
ma_b(&nan, Assembler::VFP_Unordered); |
| 2331 |
// Make sure we handle -0 and 0 right. |
| 2332 |
ma_b(&equal, Assembler::VFP_Equal); |
| 2333 |
ma_b(&returnSecond, cond); |
| 2334 |
ma_b(&done); |
| 2335 |
|
| 2336 |
// Check for zero. |
| 2337 |
bind(&equal); |
| 2338 |
compareDouble(first, NoVFPRegister); |
| 2339 |
// First wasn't 0 or -0, so just return it. |
| 2340 |
ma_b(&done, Assembler::VFP_NotEqualOrUnordered); |
| 2341 |
// So now both operands are either -0 or 0. |
| 2342 |
if (isMax) { |
| 2343 |
// -0 + -0 = -0 and -0 + 0 = 0. |
| 2344 |
ma_vadd(second, first, first); |
| 2345 |
} else { |
| 2346 |
ma_vneg(first, first); |
| 2347 |
ma_vsub(first, second, first); |
| 2348 |
ma_vneg(first, first); |
| 2349 |
} |
| 2350 |
ma_b(&done); |
| 2351 |
|
| 2352 |
bind(&nan); |
| 2353 |
// If the first argument is the NaN, return it; otherwise return the second |
| 2354 |
// operand. |
| 2355 |
compareDouble(first, first); |
| 2356 |
ma_vmov(first, srcDest, Assembler::VFP_Unordered); |
| 2357 |
ma_b(&done, Assembler::VFP_Unordered); |
| 2358 |
|
| 2359 |
bind(&returnSecond); |
| 2360 |
ma_vmov(second, srcDest); |
| 2361 |
|
| 2362 |
bind(&done); |
| 2363 |
} |
| 2364 |
|
| 2365 |
void MacroAssemblerARMCompat::minMaxFloat32(FloatRegister srcDest, |
| 2366 |
FloatRegister second, bool canBeNaN, |
| 2367 |
bool isMax) { |
| 2368 |
FloatRegister first = srcDest; |
| 2369 |
|
| 2370 |
Label nan, equal, returnSecond, done; |
| 2371 |
|
| 2372 |
Assembler::Condition cond = isMax ? Assembler::VFP_LessThanOrEqual |
| 2373 |
: Assembler::VFP_GreaterThanOrEqual; |
| 2374 |
|
| 2375 |
compareFloat(first, second); |
| 2376 |
// First or second is NaN, result is NaN. |
| 2377 |
ma_b(&nan, Assembler::VFP_Unordered); |
| 2378 |
// Make sure we handle -0 and 0 right. |
| 2379 |
ma_b(&equal, Assembler::VFP_Equal); |
| 2380 |
ma_b(&returnSecond, cond); |
| 2381 |
ma_b(&done); |
| 2382 |
|
| 2383 |
// Check for zero. |
| 2384 |
bind(&equal); |
| 2385 |
compareFloat(first, NoVFPRegister); |
| 2386 |
// First wasn't 0 or -0, so just return it. |
| 2387 |
ma_b(&done, Assembler::VFP_NotEqualOrUnordered); |
| 2388 |
// So now both operands are either -0 or 0. |
| 2389 |
if (isMax) { |
| 2390 |
// -0 + -0 = -0 and -0 + 0 = 0. |
| 2391 |
ma_vadd_f32(second, first, first); |
| 2392 |
} else { |
| 2393 |
ma_vneg_f32(first, first); |
| 2394 |
ma_vsub_f32(first, second, first); |
| 2395 |
ma_vneg_f32(first, first); |
| 2396 |
} |
| 2397 |
ma_b(&done); |
| 2398 |
|
| 2399 |
bind(&nan); |
| 2400 |
// See comment in minMaxDouble. |
| 2401 |
compareFloat(first, first); |
| 2402 |
ma_vmov_f32(first, srcDest, Assembler::VFP_Unordered); |
| 2403 |
ma_b(&done, Assembler::VFP_Unordered); |
| 2404 |
|
| 2405 |
bind(&returnSecond); |
| 2406 |
ma_vmov_f32(second, srcDest); |
| 2407 |
|
| 2408 |
bind(&done); |
| 2409 |
} |
| 2410 |
|
| 2411 |
void MacroAssemblerARMCompat::compareDouble(FloatRegister lhs, |
| 2412 |
FloatRegister rhs) { |
| 2413 |
// Compare the doubles, setting vector status flags. |
| 2414 |
if (rhs.isMissing()) { |
| 2415 |
ma_vcmpz(lhs); |
| 2416 |
} else { |
| 2417 |
ma_vcmp(lhs, rhs); |
| 2418 |
} |
| 2419 |
|
| 2420 |
// Move vector status bits to normal status flags. |
| 2421 |
as_vmrs(pc); |
| 2422 |
} |
| 2423 |
|
| 2424 |
void MacroAssemblerARMCompat::compareFloat(FloatRegister lhs, |
| 2425 |
FloatRegister rhs) { |
| 2426 |
// Compare the doubles, setting vector status flags. |
| 2427 |
if (rhs.isMissing()) { |
| 2428 |
as_vcmpz(VFPRegister(lhs).singleOverlay()); |
| 2429 |
} else { |
| 2430 |
as_vcmp(VFPRegister(lhs).singleOverlay(), VFPRegister(rhs).singleOverlay()); |
| 2431 |
} |
| 2432 |
|
| 2433 |
// Move vector status bits to normal status flags. |
| 2434 |
as_vmrs(pc); |
| 2435 |
} |
| 2436 |
|
| 2437 |
Assembler::Condition MacroAssemblerARMCompat::testInt32( |
| 2438 |
Assembler::Condition cond, const ValueOperand& value) { |
| 2439 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 2440 |
ma_cmp(value.typeReg(), ImmType(JSVAL_TYPE_INT32)); |
| 2441 |
return cond; |
| 2442 |
} |
| 2443 |
|
| 2444 |
Assembler::Condition MacroAssemblerARMCompat::testBoolean( |
| 2445 |
Assembler::Condition cond, const ValueOperand& value) { |
| 2446 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 2447 |
ma_cmp(value.typeReg(), ImmType(JSVAL_TYPE_BOOLEAN)); |
| 2448 |
return cond; |
| 2449 |
} |
| 2450 |
|
| 2451 |
Assembler::Condition MacroAssemblerARMCompat::testDouble( |
| 2452 |
Assembler::Condition cond, const ValueOperand& value) { |
| 2453 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 2454 |
Assembler::Condition actual = (cond == Equal) ? Below : AboveOrEqual; |
| 2455 |
ScratchRegisterScope scratch(asMasm()); |
| 2456 |
ma_cmp(value.typeReg(), ImmTag(JSVAL_TAG_CLEAR), scratch); |
| 2457 |
return actual; |
| 2458 |
} |
| 2459 |
|
| 2460 |
Assembler::Condition MacroAssemblerARMCompat::testNull( |
| 2461 |
Assembler::Condition cond, const ValueOperand& value) { |
| 2462 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 2463 |
ma_cmp(value.typeReg(), ImmType(JSVAL_TYPE_NULL)); |
| 2464 |
return cond; |
| 2465 |
} |
| 2466 |
|
| 2467 |
Assembler::Condition MacroAssemblerARMCompat::testUndefined( |
| 2468 |
Assembler::Condition cond, const ValueOperand& value) { |
| 2469 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 2470 |
ma_cmp(value.typeReg(), ImmType(JSVAL_TYPE_UNDEFINED)); |
| 2471 |
return cond; |
| 2472 |
} |
| 2473 |
|
| 2474 |
Assembler::Condition MacroAssemblerARMCompat::testString( |
| 2475 |
Assembler::Condition cond, const ValueOperand& value) { |
| 2476 |
return testString(cond, value.typeReg()); |
| 2477 |
} |
| 2478 |
|
| 2479 |
Assembler::Condition MacroAssemblerARMCompat::testSymbol( |
| 2480 |
Assembler::Condition cond, const ValueOperand& value) { |
| 2481 |
return testSymbol(cond, value.typeReg()); |
| 2482 |
} |
| 2483 |
|
| 2484 |
Assembler::Condition MacroAssemblerARMCompat::testBigInt( |
| 2485 |
Assembler::Condition cond, const ValueOperand& value) { |
| 2486 |
return testBigInt(cond, value.typeReg()); |
| 2487 |
} |
| 2488 |
|
| 2489 |
Assembler::Condition MacroAssemblerARMCompat::testObject( |
| 2490 |
Assembler::Condition cond, const ValueOperand& value) { |
| 2491 |
return testObject(cond, value.typeReg()); |
| 2492 |
} |
| 2493 |
|
| 2494 |
Assembler::Condition MacroAssemblerARMCompat::testNumber( |
| 2495 |
Assembler::Condition cond, const ValueOperand& value) { |
| 2496 |
return testNumber(cond, value.typeReg()); |
| 2497 |
} |
| 2498 |
|
| 2499 |
Assembler::Condition MacroAssemblerARMCompat::testMagic( |
| 2500 |
Assembler::Condition cond, const ValueOperand& value) { |
| 2501 |
return testMagic(cond, value.typeReg()); |
| 2502 |
} |
| 2503 |
|
| 2504 |
Assembler::Condition MacroAssemblerARMCompat::testPrimitive( |
| 2505 |
Assembler::Condition cond, const ValueOperand& value) { |
| 2506 |
return testPrimitive(cond, value.typeReg()); |
| 2507 |
} |
| 2508 |
|
| 2509 |
Assembler::Condition MacroAssemblerARMCompat::testGCThing( |
| 2510 |
Assembler::Condition cond, const ValueOperand& value) { |
| 2511 |
return testGCThing(cond, value.typeReg()); |
| 2512 |
} |
| 2513 |
|
| 2514 |
// Register-based tests. |
| 2515 |
Assembler::Condition MacroAssemblerARMCompat::testInt32( |
| 2516 |
Assembler::Condition cond, Register tag) { |
| 2517 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2518 |
ma_cmp(tag, ImmTag(JSVAL_TAG_INT32)); |
| 2519 |
return cond; |
| 2520 |
} |
| 2521 |
|
| 2522 |
Assembler::Condition MacroAssemblerARMCompat::testBoolean( |
| 2523 |
Assembler::Condition cond, Register tag) { |
| 2524 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2525 |
ma_cmp(tag, ImmTag(JSVAL_TAG_BOOLEAN)); |
| 2526 |
return cond; |
| 2527 |
} |
| 2528 |
|
| 2529 |
Assembler::Condition MacroAssemblerARMCompat::testNull( |
| 2530 |
Assembler::Condition cond, Register tag) { |
| 2531 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2532 |
ma_cmp(tag, ImmTag(JSVAL_TAG_NULL)); |
| 2533 |
return cond; |
| 2534 |
} |
| 2535 |
|
| 2536 |
Assembler::Condition MacroAssemblerARMCompat::testUndefined( |
| 2537 |
Assembler::Condition cond, Register tag) { |
| 2538 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2539 |
ma_cmp(tag, ImmTag(JSVAL_TAG_UNDEFINED)); |
| 2540 |
return cond; |
| 2541 |
} |
| 2542 |
|
| 2543 |
Assembler::Condition MacroAssemblerARMCompat::testString( |
| 2544 |
Assembler::Condition cond, Register tag) { |
| 2545 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2546 |
ma_cmp(tag, ImmTag(JSVAL_TAG_STRING)); |
| 2547 |
return cond; |
| 2548 |
} |
| 2549 |
|
| 2550 |
Assembler::Condition MacroAssemblerARMCompat::testSymbol( |
| 2551 |
Assembler::Condition cond, Register tag) { |
| 2552 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2553 |
ma_cmp(tag, ImmTag(JSVAL_TAG_SYMBOL)); |
| 2554 |
return cond; |
| 2555 |
} |
| 2556 |
|
| 2557 |
Assembler::Condition MacroAssemblerARMCompat::testBigInt( |
| 2558 |
Assembler::Condition cond, Register tag) { |
| 2559 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2560 |
ma_cmp(tag, ImmTag(JSVAL_TAG_BIGINT)); |
| 2561 |
return cond; |
| 2562 |
} |
| 2563 |
|
| 2564 |
Assembler::Condition MacroAssemblerARMCompat::testObject( |
| 2565 |
Assembler::Condition cond, Register tag) { |
| 2566 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2567 |
ma_cmp(tag, ImmTag(JSVAL_TAG_OBJECT)); |
| 2568 |
return cond; |
| 2569 |
} |
| 2570 |
|
| 2571 |
Assembler::Condition MacroAssemblerARMCompat::testMagic( |
| 2572 |
Assembler::Condition cond, Register tag) { |
| 2573 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2574 |
ma_cmp(tag, ImmTag(JSVAL_TAG_MAGIC)); |
| 2575 |
return cond; |
| 2576 |
} |
| 2577 |
|
| 2578 |
Assembler::Condition MacroAssemblerARMCompat::testPrimitive( |
| 2579 |
Assembler::Condition cond, Register tag) { |
| 2580 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2581 |
ma_cmp(tag, ImmTag(JS::detail::ValueUpperExclPrimitiveTag)); |
| 2582 |
return cond == Equal ? Below : AboveOrEqual; |
| 2583 |
} |
| 2584 |
|
| 2585 |
Assembler::Condition MacroAssemblerARMCompat::testGCThing( |
| 2586 |
Assembler::Condition cond, Register tag) { |
| 2587 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2588 |
ma_cmp(tag, ImmTag(JS::detail::ValueLowerInclGCThingTag)); |
| 2589 |
return cond == Equal ? AboveOrEqual : Below; |
| 2590 |
} |
| 2591 |
|
| 2592 |
Assembler::Condition MacroAssemblerARMCompat::testGCThing( |
| 2593 |
Assembler::Condition cond, const Address& address) { |
| 2594 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2595 |
ScratchRegisterScope scratch(asMasm()); |
| 2596 |
Register tag = extractTag(address, scratch); |
| 2597 |
ma_cmp(tag, ImmTag(JS::detail::ValueLowerInclGCThingTag)); |
| 2598 |
return cond == Equal ? AboveOrEqual : Below; |
| 2599 |
} |
| 2600 |
|
| 2601 |
Assembler::Condition MacroAssemblerARMCompat::testMagic( |
| 2602 |
Assembler::Condition cond, const Address& address) { |
| 2603 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2604 |
ScratchRegisterScope scratch(asMasm()); |
| 2605 |
Register tag = extractTag(address, scratch); |
| 2606 |
ma_cmp(tag, ImmTag(JSVAL_TAG_MAGIC)); |
| 2607 |
return cond; |
| 2608 |
} |
| 2609 |
|
| 2610 |
Assembler::Condition MacroAssemblerARMCompat::testInt32( |
| 2611 |
Assembler::Condition cond, const Address& address) { |
| 2612 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2613 |
ScratchRegisterScope scratch(asMasm()); |
| 2614 |
Register tag = extractTag(address, scratch); |
| 2615 |
ma_cmp(tag, ImmTag(JSVAL_TAG_INT32)); |
| 2616 |
return cond; |
| 2617 |
} |
| 2618 |
|
| 2619 |
Assembler::Condition MacroAssemblerARMCompat::testDouble( |
| 2620 |
Condition cond, const Address& address) { |
| 2621 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2622 |
ScratchRegisterScope scratch(asMasm()); |
| 2623 |
Register tag = extractTag(address, scratch); |
| 2624 |
return testDouble(cond, tag); |
| 2625 |
} |
| 2626 |
|
| 2627 |
Assembler::Condition MacroAssemblerARMCompat::testBoolean( |
| 2628 |
Condition cond, const Address& address) { |
| 2629 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2630 |
ScratchRegisterScope scratch(asMasm()); |
| 2631 |
Register tag = extractTag(address, scratch); |
| 2632 |
return testBoolean(cond, tag); |
| 2633 |
} |
| 2634 |
|
| 2635 |
Assembler::Condition MacroAssemblerARMCompat::testNull(Condition cond, |
| 2636 |
const Address& address) { |
| 2637 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2638 |
ScratchRegisterScope scratch(asMasm()); |
| 2639 |
Register tag = extractTag(address, scratch); |
| 2640 |
return testNull(cond, tag); |
| 2641 |
} |
| 2642 |
|
| 2643 |
Assembler::Condition MacroAssemblerARMCompat::testUndefined( |
| 2644 |
Condition cond, const Address& address) { |
| 2645 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2646 |
ScratchRegisterScope scratch(asMasm()); |
| 2647 |
Register tag = extractTag(address, scratch); |
| 2648 |
return testUndefined(cond, tag); |
| 2649 |
} |
| 2650 |
|
| 2651 |
Assembler::Condition MacroAssemblerARMCompat::testString( |
| 2652 |
Condition cond, const Address& address) { |
| 2653 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2654 |
ScratchRegisterScope scratch(asMasm()); |
| 2655 |
Register tag = extractTag(address, scratch); |
| 2656 |
return testString(cond, tag); |
| 2657 |
} |
| 2658 |
|
| 2659 |
Assembler::Condition MacroAssemblerARMCompat::testSymbol( |
| 2660 |
Condition cond, const Address& address) { |
| 2661 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2662 |
ScratchRegisterScope scratch(asMasm()); |
| 2663 |
Register tag = extractTag(address, scratch); |
| 2664 |
return testSymbol(cond, tag); |
| 2665 |
} |
| 2666 |
|
| 2667 |
Assembler::Condition MacroAssemblerARMCompat::testBigInt( |
| 2668 |
Condition cond, const Address& address) { |
| 2669 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2670 |
ScratchRegisterScope scratch(asMasm()); |
| 2671 |
Register tag = extractTag(address, scratch); |
| 2672 |
return testBigInt(cond, tag); |
| 2673 |
} |
| 2674 |
|
| 2675 |
Assembler::Condition MacroAssemblerARMCompat::testObject( |
| 2676 |
Condition cond, const Address& address) { |
| 2677 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2678 |
ScratchRegisterScope scratch(asMasm()); |
| 2679 |
Register tag = extractTag(address, scratch); |
| 2680 |
return testObject(cond, tag); |
| 2681 |
} |
| 2682 |
|
| 2683 |
Assembler::Condition MacroAssemblerARMCompat::testNumber( |
| 2684 |
Condition cond, const Address& address) { |
| 2685 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2686 |
ScratchRegisterScope scratch(asMasm()); |
| 2687 |
Register tag = extractTag(address, scratch); |
| 2688 |
return testNumber(cond, tag); |
| 2689 |
} |
| 2690 |
|
| 2691 |
Assembler::Condition MacroAssemblerARMCompat::testDouble(Condition cond, |
| 2692 |
Register tag) { |
| 2693 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 2694 |
Condition actual = (cond == Equal) ? Below : AboveOrEqual; |
| 2695 |
ma_cmp(tag, ImmTag(JSVAL_TAG_CLEAR)); |
| 2696 |
return actual; |
| 2697 |
} |
| 2698 |
|
| 2699 |
Assembler::Condition MacroAssemblerARMCompat::testNumber(Condition cond, |
| 2700 |
Register tag) { |
| 2701 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2702 |
ma_cmp(tag, ImmTag(JS::detail::ValueUpperInclNumberTag)); |
| 2703 |
return cond == Equal ? BelowOrEqual : Above; |
| 2704 |
} |
| 2705 |
|
| 2706 |
Assembler::Condition MacroAssemblerARMCompat::testUndefined( |
| 2707 |
Condition cond, const BaseIndex& src) { |
| 2708 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2709 |
ScratchRegisterScope scratch(asMasm()); |
| 2710 |
Register tag = extractTag(src, scratch); |
| 2711 |
ma_cmp(tag, ImmTag(JSVAL_TAG_UNDEFINED)); |
| 2712 |
return cond; |
| 2713 |
} |
| 2714 |
|
| 2715 |
Assembler::Condition MacroAssemblerARMCompat::testNull(Condition cond, |
| 2716 |
const BaseIndex& src) { |
| 2717 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2718 |
ScratchRegisterScope scratch(asMasm()); |
| 2719 |
Register tag = extractTag(src, scratch); |
| 2720 |
ma_cmp(tag, ImmTag(JSVAL_TAG_NULL)); |
| 2721 |
return cond; |
| 2722 |
} |
| 2723 |
|
| 2724 |
Assembler::Condition MacroAssemblerARMCompat::testBoolean( |
| 2725 |
Condition cond, const BaseIndex& src) { |
| 2726 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2727 |
ScratchRegisterScope scratch(asMasm()); |
| 2728 |
Register tag = extractTag(src, scratch); |
| 2729 |
ma_cmp(tag, ImmTag(JSVAL_TAG_BOOLEAN)); |
| 2730 |
return cond; |
| 2731 |
} |
| 2732 |
|
| 2733 |
Assembler::Condition MacroAssemblerARMCompat::testString(Condition cond, |
| 2734 |
const BaseIndex& src) { |
| 2735 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2736 |
ScratchRegisterScope scratch(asMasm()); |
| 2737 |
Register tag = extractTag(src, scratch); |
| 2738 |
ma_cmp(tag, ImmTag(JSVAL_TAG_STRING)); |
| 2739 |
return cond; |
| 2740 |
} |
| 2741 |
|
| 2742 |
Assembler::Condition MacroAssemblerARMCompat::testSymbol(Condition cond, |
| 2743 |
const BaseIndex& src) { |
| 2744 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2745 |
ScratchRegisterScope scratch(asMasm()); |
| 2746 |
Register tag = extractTag(src, scratch); |
| 2747 |
ma_cmp(tag, ImmTag(JSVAL_TAG_SYMBOL)); |
| 2748 |
return cond; |
| 2749 |
} |
| 2750 |
|
| 2751 |
Assembler::Condition MacroAssemblerARMCompat::testBigInt(Condition cond, |
| 2752 |
const BaseIndex& src) { |
| 2753 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2754 |
ScratchRegisterScope scratch(asMasm()); |
| 2755 |
Register tag = extractTag(src, scratch); |
| 2756 |
ma_cmp(tag, ImmTag(JSVAL_TAG_BIGINT)); |
| 2757 |
return cond; |
| 2758 |
} |
| 2759 |
|
| 2760 |
Assembler::Condition MacroAssemblerARMCompat::testInt32(Condition cond, |
| 2761 |
const BaseIndex& src) { |
| 2762 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2763 |
ScratchRegisterScope scratch(asMasm()); |
| 2764 |
Register tag = extractTag(src, scratch); |
| 2765 |
ma_cmp(tag, ImmTag(JSVAL_TAG_INT32)); |
| 2766 |
return cond; |
| 2767 |
} |
| 2768 |
|
| 2769 |
Assembler::Condition MacroAssemblerARMCompat::testObject(Condition cond, |
| 2770 |
const BaseIndex& src) { |
| 2771 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2772 |
ScratchRegisterScope scratch(asMasm()); |
| 2773 |
Register tag = extractTag(src, scratch); |
| 2774 |
ma_cmp(tag, ImmTag(JSVAL_TAG_OBJECT)); |
| 2775 |
return cond; |
| 2776 |
} |
| 2777 |
|
| 2778 |
Assembler::Condition MacroAssemblerARMCompat::testDouble(Condition cond, |
| 2779 |
const BaseIndex& src) { |
| 2780 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2781 |
Assembler::Condition actual = (cond == Equal) ? Below : AboveOrEqual; |
| 2782 |
ScratchRegisterScope scratch(asMasm()); |
| 2783 |
Register tag = extractTag(src, scratch); |
| 2784 |
ma_cmp(tag, ImmTag(JSVAL_TAG_CLEAR)); |
| 2785 |
return actual; |
| 2786 |
} |
| 2787 |
|
| 2788 |
Assembler::Condition MacroAssemblerARMCompat::testMagic( |
| 2789 |
Condition cond, const BaseIndex& address) { |
| 2790 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2791 |
ScratchRegisterScope scratch(asMasm()); |
| 2792 |
Register tag = extractTag(address, scratch); |
| 2793 |
ma_cmp(tag, ImmTag(JSVAL_TAG_MAGIC)); |
| 2794 |
return cond; |
| 2795 |
} |
| 2796 |
|
| 2797 |
Assembler::Condition MacroAssemblerARMCompat::testGCThing( |
| 2798 |
Condition cond, const BaseIndex& address) { |
| 2799 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 2800 |
ScratchRegisterScope scratch(asMasm()); |
| 2801 |
Register tag = extractTag(address, scratch); |
| 2802 |
ma_cmp(tag, ImmTag(JS::detail::ValueLowerInclGCThingTag)); |
| 2803 |
return cond == Equal ? AboveOrEqual : Below; |
| 2804 |
} |
| 2805 |
|
| 2806 |
// Unboxing code. |
| 2807 |
void MacroAssemblerARMCompat::unboxNonDouble(const ValueOperand& operand, |
| 2808 |
Register dest, JSValueType type) { |
| 2809 |
auto movPayloadToDest = [&]() { |
| 2810 |
if (operand.payloadReg() != dest) { |
| 2811 |
ma_mov(operand.payloadReg(), dest, LeaveCC); |
| 2812 |
} |
| 2813 |
}; |
| 2814 |
if (!JitOptions.spectreValueMasking) { |
| 2815 |
movPayloadToDest(); |
| 2816 |
return; |
| 2817 |
} |
| 2818 |
|
| 2819 |
// Spectre mitigation: We zero the payload if the tag does not match the |
| 2820 |
// expected type and if this is a pointer type. |
| 2821 |
if (type == JSVAL_TYPE_INT32 || type == JSVAL_TYPE_BOOLEAN) { |
| 2822 |
movPayloadToDest(); |
| 2823 |
return; |
| 2824 |
} |
| 2825 |
|
| 2826 |
// We zero the destination register and move the payload into it if |
| 2827 |
// the tag corresponds to the given type. |
| 2828 |
ma_cmp(operand.typeReg(), ImmType(type)); |
| 2829 |
movPayloadToDest(); |
| 2830 |
ma_mov(Imm32(0), dest, NotEqual); |
| 2831 |
} |
| 2832 |
|
| 2833 |
void MacroAssemblerARMCompat::unboxNonDouble(const Address& src, Register dest, |
| 2834 |
JSValueType type) { |
| 2835 |
ScratchRegisterScope scratch(asMasm()); |
| 2836 |
if (!JitOptions.spectreValueMasking) { |
| 2837 |
ma_ldr(ToPayload(src), dest, scratch); |
| 2838 |
return; |
| 2839 |
} |
| 2840 |
|
| 2841 |
// Spectre mitigation: We zero the payload if the tag does not match the |
| 2842 |
// expected type and if this is a pointer type. |
| 2843 |
if (type == JSVAL_TYPE_INT32 || type == JSVAL_TYPE_BOOLEAN) { |
| 2844 |
ma_ldr(ToPayload(src), dest, scratch); |
| 2845 |
return; |
| 2846 |
} |
| 2847 |
|
| 2848 |
// We zero the destination register and move the payload into it if |
| 2849 |
// the tag corresponds to the given type. |
| 2850 |
ma_ldr(ToType(src), scratch, scratch); |
| 2851 |
ma_cmp(scratch, ImmType(type)); |
| 2852 |
ma_ldr(ToPayload(src), dest, scratch, Offset, Equal); |
| 2853 |
ma_mov(Imm32(0), dest, NotEqual); |
| 2854 |
} |
| 2855 |
|
| 2856 |
void MacroAssemblerARMCompat::unboxNonDouble(const BaseIndex& src, |
| 2857 |
Register dest, JSValueType type) { |
| 2858 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2859 |
ma_alu(src.base, lsl(src.index, src.scale), scratch2, OpAdd); |
| 2860 |
Address value(scratch2, src.offset); |
| 2861 |
unboxNonDouble(value, dest, type); |
| 2862 |
} |
| 2863 |
|
| 2864 |
void MacroAssemblerARMCompat::unboxDouble(const ValueOperand& operand, |
| 2865 |
FloatRegister dest) { |
| 2866 |
MOZ_ASSERT(dest.isDouble()); |
| 2867 |
as_vxfer(operand.payloadReg(), operand.typeReg(), VFPRegister(dest), |
| 2868 |
CoreToFloat); |
| 2869 |
} |
| 2870 |
|
| 2871 |
void MacroAssemblerARMCompat::unboxDouble(const Address& src, |
| 2872 |
FloatRegister dest) { |
| 2873 |
MOZ_ASSERT(dest.isDouble()); |
| 2874 |
loadDouble(src, dest); |
| 2875 |
} |
| 2876 |
|
| 2877 |
void MacroAssemblerARMCompat::unboxDouble(const BaseIndex& src, |
| 2878 |
FloatRegister dest) { |
| 2879 |
MOZ_ASSERT(dest.isDouble()); |
| 2880 |
loadDouble(src, dest); |
| 2881 |
} |
| 2882 |
|
| 2883 |
void MacroAssemblerARMCompat::unboxValue(const ValueOperand& src, |
| 2884 |
AnyRegister dest, JSValueType type) { |
| 2885 |
if (dest.isFloat()) { |
| 2886 |
Label notInt32, end; |
| 2887 |
asMasm().branchTestInt32(Assembler::NotEqual, src, ¬Int32); |
| 2888 |
convertInt32ToDouble(src.payloadReg(), dest.fpu()); |
| 2889 |
ma_b(&end); |
| 2890 |
bind(¬Int32); |
| 2891 |
unboxDouble(src, dest.fpu()); |
| 2892 |
bind(&end); |
| 2893 |
} else { |
| 2894 |
unboxNonDouble(src, dest.gpr(), type); |
| 2895 |
} |
| 2896 |
} |
| 2897 |
|
| 2898 |
void MacroAssemblerARMCompat::boxDouble(FloatRegister src, |
| 2899 |
const ValueOperand& dest, |
| 2900 |
FloatRegister) { |
| 2901 |
as_vxfer(dest.payloadReg(), dest.typeReg(), VFPRegister(src), FloatToCore); |
| 2902 |
} |
| 2903 |
|
| 2904 |
void MacroAssemblerARMCompat::boxNonDouble(JSValueType type, Register src, |
| 2905 |
const ValueOperand& dest) { |
| 2906 |
if (src != dest.payloadReg()) { |
| 2907 |
ma_mov(src, dest.payloadReg()); |
| 2908 |
} |
| 2909 |
ma_mov(ImmType(type), dest.typeReg()); |
| 2910 |
} |
| 2911 |
|
| 2912 |
void MacroAssemblerARMCompat::loadConstantFloat32(float f, FloatRegister dest) { |
| 2913 |
ma_vimm_f32(f, dest); |
| 2914 |
} |
| 2915 |
|
| 2916 |
void MacroAssemblerARMCompat::loadInt32OrDouble(const Address& src, |
| 2917 |
FloatRegister dest) { |
| 2918 |
Label notInt32, end; |
| 2919 |
|
| 2920 |
// If it's an int, convert to a double. |
| 2921 |
{ |
| 2922 |
ScratchRegisterScope scratch(asMasm()); |
| 2923 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 2924 |
|
| 2925 |
ma_ldr(ToType(src), scratch, scratch2); |
| 2926 |
asMasm().branchTestInt32(Assembler::NotEqual, scratch, ¬Int32); |
| 2927 |
ma_ldr(ToPayload(src), scratch, scratch2); |
| 2928 |
convertInt32ToDouble(scratch, dest); |
| 2929 |
ma_b(&end); |
| 2930 |
} |
| 2931 |
|
| 2932 |
// Not an int, just load as double. |
| 2933 |
bind(¬Int32); |
| 2934 |
{ |
| 2935 |
ScratchRegisterScope scratch(asMasm()); |
| 2936 |
ma_vldr(src, dest, scratch); |
| 2937 |
} |
| 2938 |
bind(&end); |
| 2939 |
} |
| 2940 |
|
| 2941 |
void MacroAssemblerARMCompat::loadInt32OrDouble(Register base, Register index, |
| 2942 |
FloatRegister dest, |
| 2943 |
int32_t shift) { |
| 2944 |
Label notInt32, end; |
| 2945 |
|
| 2946 |
static_assert(NUNBOX32_PAYLOAD_OFFSET == 0); |
| 2947 |
|
| 2948 |
ScratchRegisterScope scratch(asMasm()); |
| 2949 |
|
| 2950 |
// If it's an int, convert it to double. |
| 2951 |
ma_alu(base, lsl(index, shift), scratch, OpAdd); |
| 2952 |
|
| 2953 |
// Since we only have one scratch register, we need to stomp over it with |
| 2954 |
// the tag. |
| 2955 |
ma_ldr(DTRAddr(scratch, DtrOffImm(NUNBOX32_TYPE_OFFSET)), scratch); |
| 2956 |
asMasm().branchTestInt32(Assembler::NotEqual, scratch, ¬Int32); |
| 2957 |
|
| 2958 |
// Implicitly requires NUNBOX32_PAYLOAD_OFFSET == 0: no offset provided |
| 2959 |
ma_ldr(DTRAddr(base, DtrRegImmShift(index, LSL, shift)), scratch); |
| 2960 |
convertInt32ToDouble(scratch, dest); |
| 2961 |
ma_b(&end); |
| 2962 |
|
| 2963 |
// Not an int, just load as double. |
| 2964 |
bind(¬Int32); |
| 2965 |
// First, recompute the offset that had been stored in the scratch register |
| 2966 |
// since the scratch register was overwritten loading in the type. |
| 2967 |
ma_alu(base, lsl(index, shift), scratch, OpAdd); |
| 2968 |
ma_vldr(VFPAddr(scratch, VFPOffImm(0)), dest); |
| 2969 |
bind(&end); |
| 2970 |
} |
| 2971 |
|
| 2972 |
void MacroAssemblerARMCompat::loadConstantDouble(double dp, |
| 2973 |
FloatRegister dest) { |
| 2974 |
ma_vimm(dp, dest); |
| 2975 |
} |
| 2976 |
|
| 2977 |
// Treat the value as a boolean, and set condition codes accordingly. |
| 2978 |
Assembler::Condition MacroAssemblerARMCompat::testInt32Truthy( |
| 2979 |
bool truthy, const ValueOperand& operand) { |
| 2980 |
ma_tst(operand.payloadReg(), operand.payloadReg()); |
| 2981 |
return truthy ? NonZero : Zero; |
| 2982 |
} |
| 2983 |
|
| 2984 |
Assembler::Condition MacroAssemblerARMCompat::testBooleanTruthy( |
| 2985 |
bool truthy, const ValueOperand& operand) { |
| 2986 |
ma_tst(operand.payloadReg(), operand.payloadReg()); |
| 2987 |
return truthy ? NonZero : Zero; |
| 2988 |
} |
| 2989 |
|
| 2990 |
Assembler::Condition MacroAssemblerARMCompat::testDoubleTruthy( |
| 2991 |
bool truthy, FloatRegister reg) { |
| 2992 |
as_vcmpz(VFPRegister(reg)); |
| 2993 |
as_vmrs(pc); |
| 2994 |
as_cmp(r0, O2Reg(r0), Overflow); |
| 2995 |
return truthy ? NonZero : Zero; |
| 2996 |
} |
| 2997 |
|
| 2998 |
Register MacroAssemblerARMCompat::extractObject(const Address& address, |
| 2999 |
Register scratch) { |
| 3000 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 3001 |
ma_ldr(ToPayload(address), scratch, scratch2); |
| 3002 |
return scratch; |
| 3003 |
} |
| 3004 |
|
| 3005 |
Register MacroAssemblerARMCompat::extractTag(const Address& address, |
| 3006 |
Register scratch) { |
| 3007 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 3008 |
ma_ldr(ToType(address), scratch, scratch2); |
| 3009 |
return scratch; |
| 3010 |
} |
| 3011 |
|
| 3012 |
Register MacroAssemblerARMCompat::extractTag(const BaseIndex& address, |
| 3013 |
Register scratch) { |
| 3014 |
ma_alu(address.base, lsl(address.index, address.scale), scratch, OpAdd, |
| 3015 |
LeaveCC); |
| 3016 |
return extractTag(Address(scratch, address.offset), scratch); |
| 3017 |
} |
| 3018 |
|
| 3019 |
///////////////////////////////////////////////////////////////// |
| 3020 |
// X86/X64-common (ARM too now) interface. |
| 3021 |
///////////////////////////////////////////////////////////////// |
| 3022 |
void MacroAssemblerARMCompat::storeValue(ValueOperand val, const Address& dst) { |
| 3023 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 3024 |
ma_str(val.payloadReg(), ToPayload(dst), scratch2); |
| 3025 |
ma_str(val.typeReg(), ToType(dst), scratch2); |
| 3026 |
} |
| 3027 |
|
| 3028 |
void MacroAssemblerARMCompat::storeValue(ValueOperand val, |
| 3029 |
const BaseIndex& dest) { |
| 3030 |
ScratchRegisterScope scratch(asMasm()); |
| 3031 |
|
| 3032 |
if (isValueDTRDCandidate(val) && Abs(dest.offset) <= 255) { |
| 3033 |
Register tmpIdx; |
| 3034 |
if (dest.offset == 0) { |
| 3035 |
if (dest.scale == TimesOne) { |
| 3036 |
tmpIdx = dest.index; |
| 3037 |
} else { |
| 3038 |
ma_lsl(Imm32(dest.scale), dest.index, scratch); |
| 3039 |
tmpIdx = scratch; |
| 3040 |
} |
| 3041 |
ma_strd(val.payloadReg(), val.typeReg(), |
| 3042 |
EDtrAddr(dest.base, EDtrOffReg(tmpIdx))); |
| 3043 |
} else { |
| 3044 |
ma_alu(dest.base, lsl(dest.index, dest.scale), scratch, OpAdd); |
| 3045 |
ma_strd(val.payloadReg(), val.typeReg(), |
| 3046 |
EDtrAddr(scratch, EDtrOffImm(dest.offset))); |
| 3047 |
} |
| 3048 |
} else { |
| 3049 |
ma_alu(dest.base, lsl(dest.index, dest.scale), scratch, OpAdd); |
| 3050 |
storeValue(val, Address(scratch, dest.offset)); |
| 3051 |
} |
| 3052 |
} |
| 3053 |
|
| 3054 |
void MacroAssemblerARMCompat::loadValue(const BaseIndex& addr, |
| 3055 |
ValueOperand val) { |
| 3056 |
ScratchRegisterScope scratch(asMasm()); |
| 3057 |
|
| 3058 |
if (isValueDTRDCandidate(val) && Abs(addr.offset) <= 255) { |
| 3059 |
Register tmpIdx; |
| 3060 |
if (addr.offset == 0) { |
| 3061 |
if (addr.scale == TimesOne) { |
| 3062 |
// If the offset register is the same as one of the destination |
| 3063 |
// registers, LDRD's behavior is undefined. Use the scratch |
| 3064 |
// register to avoid this. |
| 3065 |
if (val.aliases(addr.index)) { |
| 3066 |
ma_mov(addr.index, scratch); |
| 3067 |
tmpIdx = scratch; |
| 3068 |
} else { |
| 3069 |
tmpIdx = addr.index; |
| 3070 |
} |
| 3071 |
} else { |
| 3072 |
ma_lsl(Imm32(addr.scale), addr.index, scratch); |
| 3073 |
tmpIdx = scratch; |
| 3074 |
} |
| 3075 |
ma_ldrd(EDtrAddr(addr.base, EDtrOffReg(tmpIdx)), val.payloadReg(), |
| 3076 |
val.typeReg()); |
| 3077 |
} else { |
| 3078 |
ma_alu(addr.base, lsl(addr.index, addr.scale), scratch, OpAdd); |
| 3079 |
ma_ldrd(EDtrAddr(scratch, EDtrOffImm(addr.offset)), val.payloadReg(), |
| 3080 |
val.typeReg()); |
| 3081 |
} |
| 3082 |
} else { |
| 3083 |
ma_alu(addr.base, lsl(addr.index, addr.scale), scratch, OpAdd); |
| 3084 |
loadValue(Address(scratch, addr.offset), val); |
| 3085 |
} |
| 3086 |
} |
| 3087 |
|
| 3088 |
void MacroAssemblerARMCompat::loadValue(Address src, ValueOperand val) { |
| 3089 |
// TODO: copy this code into a generic function that acts on all sequences |
| 3090 |
// of memory accesses |
| 3091 |
if (isValueDTRDCandidate(val)) { |
| 3092 |
// If the value we want is in two consecutive registers starting with an |
| 3093 |
// even register, they can be combined as a single ldrd. |
| 3094 |
int offset = src.offset; |
| 3095 |
if (offset < 256 && offset > -256) { |
| 3096 |
ma_ldrd(EDtrAddr(src.base, EDtrOffImm(src.offset)), val.payloadReg(), |
| 3097 |
val.typeReg()); |
| 3098 |
return; |
| 3099 |
} |
| 3100 |
} |
| 3101 |
// If the value is lower than the type, then we may be able to use an ldm |
| 3102 |
// instruction. |
| 3103 |
|
| 3104 |
if (val.payloadReg().code() < val.typeReg().code()) { |
| 3105 |
if (src.offset <= 4 && src.offset >= -8 && (src.offset & 3) == 0) { |
| 3106 |
// Turns out each of the 4 value -8, -4, 0, 4 corresponds exactly |
| 3107 |
// with one of LDM{DB, DA, IA, IB} |
| 3108 |
DTMMode mode; |
| 3109 |
switch (src.offset) { |
| 3110 |
case -8: |
| 3111 |
mode = DB; |
| 3112 |
break; |
| 3113 |
case -4: |
| 3114 |
mode = DA; |
| 3115 |
break; |
| 3116 |
case 0: |
| 3117 |
mode = IA; |
| 3118 |
break; |
| 3119 |
case 4: |
| 3120 |
mode = IB; |
| 3121 |
break; |
| 3122 |
default: |
| 3123 |
MOZ_CRASH("Bogus Offset for LoadValue as DTM"); |
| 3124 |
} |
| 3125 |
startDataTransferM(IsLoad, src.base, mode); |
| 3126 |
transferReg(val.payloadReg()); |
| 3127 |
transferReg(val.typeReg()); |
| 3128 |
finishDataTransfer(); |
| 3129 |
return; |
| 3130 |
} |
| 3131 |
} |
| 3132 |
|
| 3133 |
loadUnalignedValue(src, val); |
| 3134 |
} |
| 3135 |
|
| 3136 |
void MacroAssemblerARMCompat::loadUnalignedValue(const Address& src, |
| 3137 |
ValueOperand dest) { |
| 3138 |
Address payload = ToPayload(src); |
| 3139 |
Address type = ToType(src); |
| 3140 |
|
| 3141 |
// Ensure that loading the payload does not erase the pointer to the Value |
| 3142 |
// in memory. |
| 3143 |
if (type.base != dest.payloadReg()) { |
| 3144 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 3145 |
ma_ldr(payload, dest.payloadReg(), scratch2); |
| 3146 |
ma_ldr(type, dest.typeReg(), scratch2); |
| 3147 |
} else { |
| 3148 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 3149 |
ma_ldr(type, dest.typeReg(), scratch2); |
| 3150 |
ma_ldr(payload, dest.payloadReg(), scratch2); |
| 3151 |
} |
| 3152 |
} |
| 3153 |
|
| 3154 |
void MacroAssemblerARMCompat::tagValue(JSValueType type, Register payload, |
| 3155 |
ValueOperand dest) { |
| 3156 |
MOZ_ASSERT(dest.typeReg() != dest.payloadReg()); |
| 3157 |
if (payload != dest.payloadReg()) { |
| 3158 |
ma_mov(payload, dest.payloadReg()); |
| 3159 |
} |
| 3160 |
ma_mov(ImmType(type), dest.typeReg()); |
| 3161 |
} |
| 3162 |
|
| 3163 |
void MacroAssemblerARMCompat::pushValue(ValueOperand val) { |
| 3164 |
ma_push(val.typeReg()); |
| 3165 |
ma_push(val.payloadReg()); |
| 3166 |
} |
| 3167 |
|
| 3168 |
void MacroAssemblerARMCompat::pushValue(const Address& addr) { |
| 3169 |
ScratchRegisterScope scratch(asMasm()); |
| 3170 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 3171 |
|
| 3172 |
ma_ldr(ToType(addr), scratch, scratch2); |
| 3173 |
ma_push(scratch); |
| 3174 |
ma_ldr(ToPayloadAfterStackPush(addr), scratch, scratch2); |
| 3175 |
ma_push(scratch); |
| 3176 |
} |
| 3177 |
|
| 3178 |
void MacroAssemblerARMCompat::pushValue(const BaseIndex& addr, |
| 3179 |
Register scratch) { |
| 3180 |
computeEffectiveAddress(addr, scratch); |
| 3181 |
pushValue(Address(scratch, 0)); |
| 3182 |
} |
| 3183 |
|
| 3184 |
void MacroAssemblerARMCompat::popValue(ValueOperand val) { |
| 3185 |
ma_pop(val.payloadReg()); |
| 3186 |
ma_pop(val.typeReg()); |
| 3187 |
} |
| 3188 |
|
| 3189 |
void MacroAssemblerARMCompat::storePayload(const Value& val, |
| 3190 |
const Address& dest) { |
| 3191 |
ScratchRegisterScope scratch(asMasm()); |
| 3192 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 3193 |
|
| 3194 |
if (val.isGCThing()) { |
| 3195 |
ma_mov(ImmGCPtr(val.toGCThing()), scratch); |
| 3196 |
} else { |
| 3197 |
ma_mov(Imm32(val.toNunboxPayload()), scratch); |
| 3198 |
} |
| 3199 |
ma_str(scratch, ToPayload(dest), scratch2); |
| 3200 |
} |
| 3201 |
|
| 3202 |
void MacroAssemblerARMCompat::storePayload(Register src, const Address& dest) { |
| 3203 |
ScratchRegisterScope scratch(asMasm()); |
| 3204 |
ma_str(src, ToPayload(dest), scratch); |
| 3205 |
} |
| 3206 |
|
| 3207 |
void MacroAssemblerARMCompat::storePayload(const Value& val, |
| 3208 |
const BaseIndex& dest) { |
| 3209 |
unsigned shift = ScaleToShift(dest.scale); |
| 3210 |
|
| 3211 |
ScratchRegisterScope scratch(asMasm()); |
| 3212 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 3213 |
|
| 3214 |
if (val.isGCThing()) { |
| 3215 |
ma_mov(ImmGCPtr(val.toGCThing()), scratch); |
| 3216 |
} else { |
| 3217 |
ma_mov(Imm32(val.toNunboxPayload()), scratch); |
| 3218 |
} |
| 3219 |
|
| 3220 |
// If NUNBOX32_PAYLOAD_OFFSET is not zero, the memory operand [base + index |
| 3221 |
// << shift + imm] cannot be encoded into a single instruction, and cannot |
| 3222 |
// be integrated into the as_dtr call. |
| 3223 |
static_assert(NUNBOX32_PAYLOAD_OFFSET == 0); |
| 3224 |
|
| 3225 |
// If an offset is used, modify the base so that a [base + index << shift] |
| 3226 |
// instruction format can be used. |
| 3227 |
if (dest.offset != 0) { |
| 3228 |
ma_add(dest.base, Imm32(dest.offset), dest.base, scratch2); |
| 3229 |
} |
| 3230 |
|
| 3231 |
as_dtr(IsStore, 32, Offset, scratch, |
| 3232 |
DTRAddr(dest.base, DtrRegImmShift(dest.index, LSL, shift))); |
| 3233 |
|
| 3234 |
// Restore the original value of the base, if necessary. |
| 3235 |
if (dest.offset != 0) { |
| 3236 |
ma_sub(dest.base, Imm32(dest.offset), dest.base, scratch); |
| 3237 |
} |
| 3238 |
} |
| 3239 |
|
| 3240 |
void MacroAssemblerARMCompat::storePayload(Register src, |
| 3241 |
const BaseIndex& dest) { |
| 3242 |
unsigned shift = ScaleToShift(dest.scale); |
| 3243 |
MOZ_ASSERT(shift < 32); |
| 3244 |
|
| 3245 |
ScratchRegisterScope scratch(asMasm()); |
| 3246 |
|
| 3247 |
// If NUNBOX32_PAYLOAD_OFFSET is not zero, the memory operand [base + index |
| 3248 |
// << shift + imm] cannot be encoded into a single instruction, and cannot |
| 3249 |
// be integrated into the as_dtr call. |
| 3250 |
static_assert(NUNBOX32_PAYLOAD_OFFSET == 0); |
| 3251 |
|
| 3252 |
// Save/restore the base if the BaseIndex has an offset, as above. |
| 3253 |
if (dest.offset != 0) { |
| 3254 |
ma_add(dest.base, Imm32(dest.offset), dest.base, scratch); |
| 3255 |
} |
| 3256 |
|
| 3257 |
// Technically, shift > -32 can be handle by changing LSL to ASR, but should |
| 3258 |
// never come up, and this is one less code path to get wrong. |
| 3259 |
as_dtr(IsStore, 32, Offset, src, |
| 3260 |
DTRAddr(dest.base, DtrRegImmShift(dest.index, LSL, shift))); |
| 3261 |
|
| 3262 |
if (dest.offset != 0) { |
| 3263 |
ma_sub(dest.base, Imm32(dest.offset), dest.base, scratch); |
| 3264 |
} |
| 3265 |
} |
| 3266 |
|
| 3267 |
void MacroAssemblerARMCompat::storeTypeTag(ImmTag tag, const Address& dest) { |
| 3268 |
ScratchRegisterScope scratch(asMasm()); |
| 3269 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 3270 |
|
| 3271 |
ma_mov(tag, scratch); |
| 3272 |
ma_str(scratch, ToType(dest), scratch2); |
| 3273 |
} |
| 3274 |
|
| 3275 |
void MacroAssemblerARMCompat::storeTypeTag(ImmTag tag, const BaseIndex& dest) { |
| 3276 |
Register base = dest.base; |
| 3277 |
Register index = dest.index; |
| 3278 |
unsigned shift = ScaleToShift(dest.scale); |
| 3279 |
|
| 3280 |
ScratchRegisterScope scratch(asMasm()); |
| 3281 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 3282 |
|
| 3283 |
MOZ_ASSERT(base != scratch && base != scratch2); |
| 3284 |
MOZ_ASSERT(index != scratch && index != scratch2); |
| 3285 |
|
| 3286 |
ma_add(base, Imm32(dest.offset + NUNBOX32_TYPE_OFFSET), scratch2, scratch); |
| 3287 |
ma_mov(tag, scratch); |
| 3288 |
ma_str(scratch, DTRAddr(scratch2, DtrRegImmShift(index, LSL, shift))); |
| 3289 |
} |
| 3290 |
|
| 3291 |
void MacroAssemblerARM::ma_call(ImmPtr dest) { |
| 3292 |
ma_movPatchable(dest, CallReg, Always); |
| 3293 |
as_blx(CallReg); |
| 3294 |
} |
| 3295 |
|
| 3296 |
void MacroAssemblerARMCompat::breakpoint() { as_bkpt(); } |
| 3297 |
|
| 3298 |
void MacroAssemblerARMCompat::simulatorStop(const char* msg) { |
| 3299 |
#ifdef JS_SIMULATOR_ARM |
| 3300 |
MOZ_ASSERT(sizeof(char*) == 4); |
| 3301 |
writeInst(0xefffffff); |
| 3302 |
writeInst((int)msg); |
| 3303 |
#endif |
| 3304 |
} |
| 3305 |
|
| 3306 |
void MacroAssemblerARMCompat::breakpoint(Condition cc) { |
| 3307 |
ma_ldr(DTRAddr(r12, DtrRegImmShift(r12, LSL, 0, IsDown)), r12, Offset, cc); |
| 3308 |
} |
| 3309 |
|
| 3310 |
void MacroAssemblerARMCompat::checkStackAlignment() { |
| 3311 |
asMasm().assertStackAlignment(ABIStackAlignment); |
| 3312 |
} |
| 3313 |
|
| 3314 |
void MacroAssemblerARMCompat::handleFailureWithHandlerTail( |
| 3315 |
Label* profilerExitTail, Label* bailoutTail, |
| 3316 |
uint32_t* returnValueCheckOffset) { |
| 3317 |
// Reserve space for exception information. |
| 3318 |
int size = (sizeof(ResumeFromException) + 7) & ~7; |
| 3319 |
|
| 3320 |
Imm8 size8(size); |
| 3321 |
as_sub(sp, sp, size8); |
| 3322 |
ma_mov(sp, r0); |
| 3323 |
|
| 3324 |
// Call the handler. |
| 3325 |
using Fn = void (*)(ResumeFromException* rfe); |
| 3326 |
asMasm().setupUnalignedABICall(r1); |
| 3327 |
asMasm().passABIArg(r0); |
| 3328 |
asMasm().callWithABI<Fn, HandleException>( |
| 3329 |
ABIType::General, CheckUnsafeCallWithABI::DontCheckHasExitFrame); |
| 3330 |
|
| 3331 |
*returnValueCheckOffset = asMasm().currentOffset(); |
| 3332 |
|
| 3333 |
Label entryFrame; |
| 3334 |
Label catch_; |
| 3335 |
Label finally; |
| 3336 |
Label returnBaseline; |
| 3337 |
Label returnIon; |
| 3338 |
Label bailout; |
| 3339 |
Label wasmInterpEntry; |
| 3340 |
Label wasmCatch; |
| 3341 |
|
| 3342 |
{ |
| 3343 |
ScratchRegisterScope scratch(asMasm()); |
| 3344 |
ma_ldr(Address(sp, ResumeFromException::offsetOfKind()), r0, scratch); |
| 3345 |
} |
| 3346 |
|
| 3347 |
asMasm().branch32(Assembler::Equal, r0, |
| 3348 |
Imm32(ExceptionResumeKind::EntryFrame), &entryFrame); |
| 3349 |
asMasm().branch32(Assembler::Equal, r0, Imm32(ExceptionResumeKind::Catch), |
| 3350 |
&catch_); |
| 3351 |
asMasm().branch32(Assembler::Equal, r0, Imm32(ExceptionResumeKind::Finally), |
| 3352 |
&finally); |
| 3353 |
asMasm().branch32(Assembler::Equal, r0, |
| 3354 |
Imm32(ExceptionResumeKind::ForcedReturnBaseline), |
| 3355 |
&returnBaseline); |
| 3356 |
asMasm().branch32(Assembler::Equal, r0, |
| 3357 |
Imm32(ExceptionResumeKind::ForcedReturnIon), &returnIon); |
| 3358 |
asMasm().branch32(Assembler::Equal, r0, Imm32(ExceptionResumeKind::Bailout), |
| 3359 |
&bailout); |
| 3360 |
asMasm().branch32(Assembler::Equal, r0, |
| 3361 |
Imm32(ExceptionResumeKind::WasmInterpEntry), |
| 3362 |
&wasmInterpEntry); |
| 3363 |
asMasm().branch32(Assembler::Equal, r0, Imm32(ExceptionResumeKind::WasmCatch), |
| 3364 |
&wasmCatch); |
| 3365 |
|
| 3366 |
breakpoint(); // Invalid kind. |
| 3367 |
|
| 3368 |
// No exception handler. Load the error value, restore state and return from |
| 3369 |
// the entry frame. |
| 3370 |
bind(&entryFrame); |
| 3371 |
asMasm().moveValue(MagicValue(JS_ION_ERROR), JSReturnOperand); |
| 3372 |
{ |
| 3373 |
ScratchRegisterScope scratch(asMasm()); |
| 3374 |
ma_ldr(Address(sp, ResumeFromException::offsetOfFramePointer()), r11, |
| 3375 |
scratch); |
| 3376 |
ma_ldr(Address(sp, ResumeFromException::offsetOfStackPointer()), sp, |
| 3377 |
scratch); |
| 3378 |
} |
| 3379 |
|
| 3380 |
// We're going to be returning by the ion calling convention, which returns |
| 3381 |
// by ??? (for now, I think ldr pc, [sp]!) |
| 3382 |
as_dtr(IsLoad, 32, PostIndex, pc, DTRAddr(sp, DtrOffImm(4))); |
| 3383 |
|
| 3384 |
// If we found a catch handler, this must be a baseline frame. Restore state |
| 3385 |
// and jump to the catch block. |
| 3386 |
bind(&catch_); |
| 3387 |
{ |
| 3388 |
ScratchRegisterScope scratch(asMasm()); |
| 3389 |
ma_ldr(Address(sp, ResumeFromException::offsetOfTarget()), r0, scratch); |
| 3390 |
ma_ldr(Address(sp, ResumeFromException::offsetOfFramePointer()), r11, |
| 3391 |
scratch); |
| 3392 |
ma_ldr(Address(sp, ResumeFromException::offsetOfStackPointer()), sp, |
| 3393 |
scratch); |
| 3394 |
} |
| 3395 |
jump(r0); |
| 3396 |
|
| 3397 |
// If we found a finally block, this must be a baseline frame. Push three |
| 3398 |
// values expected by the finally block: the exception, the exception stack, |
| 3399 |
// and BooleanValue(true). |
| 3400 |
bind(&finally); |
| 3401 |
ValueOperand exception = ValueOperand(r1, r2); |
| 3402 |
loadValue(Operand(sp, ResumeFromException::offsetOfException()), exception); |
| 3403 |
|
| 3404 |
ValueOperand exceptionStack = ValueOperand(r3, r4); |
| 3405 |
loadValue(Operand(sp, ResumeFromException::offsetOfExceptionStack()), |
| 3406 |
exceptionStack); |
| 3407 |
|
| 3408 |
{ |
| 3409 |
ScratchRegisterScope scratch(asMasm()); |
| 3410 |
ma_ldr(Address(sp, ResumeFromException::offsetOfTarget()), r0, scratch); |
| 3411 |
ma_ldr(Address(sp, ResumeFromException::offsetOfFramePointer()), r11, |
| 3412 |
scratch); |
| 3413 |
ma_ldr(Address(sp, ResumeFromException::offsetOfStackPointer()), sp, |
| 3414 |
scratch); |
| 3415 |
} |
| 3416 |
|
| 3417 |
pushValue(exception); |
| 3418 |
pushValue(exceptionStack); |
| 3419 |
pushValue(BooleanValue(true)); |
| 3420 |
jump(r0); |
| 3421 |
|
| 3422 |
// Return BaselineFrame->returnValue() to the caller. |
| 3423 |
// Used in debug mode and for GeneratorReturn. |
| 3424 |
Label profilingInstrumentation; |
| 3425 |
bind(&returnBaseline); |
| 3426 |
{ |
| 3427 |
ScratchRegisterScope scratch(asMasm()); |
| 3428 |
ma_ldr(Address(sp, ResumeFromException::offsetOfFramePointer()), r11, |
| 3429 |
scratch); |
| 3430 |
ma_ldr(Address(sp, ResumeFromException::offsetOfStackPointer()), sp, |
| 3431 |
scratch); |
| 3432 |
} |
| 3433 |
loadValue(Address(r11, BaselineFrame::reverseOffsetOfReturnValue()), |
| 3434 |
JSReturnOperand); |
| 3435 |
jump(&profilingInstrumentation); |
| 3436 |
|
| 3437 |
// Return the given value to the caller. |
| 3438 |
bind(&returnIon); |
| 3439 |
loadValue(Address(sp, ResumeFromException::offsetOfException()), |
| 3440 |
JSReturnOperand); |
| 3441 |
{ |
| 3442 |
ScratchRegisterScope scratch(asMasm()); |
| 3443 |
ma_ldr(Address(sp, ResumeFromException::offsetOfFramePointer()), r11, |
| 3444 |
scratch); |
| 3445 |
ma_ldr(Address(sp, ResumeFromException::offsetOfStackPointer()), sp, |
| 3446 |
scratch); |
| 3447 |
} |
| 3448 |
|
| 3449 |
// If profiling is enabled, then update the lastProfilingFrame to refer to |
| 3450 |
// caller frame before returning. This code is shared by ForcedReturnIon |
| 3451 |
// and ForcedReturnBaseline. |
| 3452 |
bind(&profilingInstrumentation); |
| 3453 |
{ |
| 3454 |
Label skipProfilingInstrumentation; |
| 3455 |
// Test if profiler enabled. |
| 3456 |
AbsoluteAddress addressOfEnabled( |
| 3457 |
asMasm().runtime()->geckoProfiler().addressOfEnabled()); |
| 3458 |
asMasm().branch32(Assembler::Equal, addressOfEnabled, Imm32(0), |
| 3459 |
&skipProfilingInstrumentation); |
| 3460 |
jump(profilerExitTail); |
| 3461 |
bind(&skipProfilingInstrumentation); |
| 3462 |
} |
| 3463 |
|
| 3464 |
ma_mov(r11, sp); |
| 3465 |
pop(r11); |
| 3466 |
ret(); |
| 3467 |
|
| 3468 |
// If we are bailing out to baseline to handle an exception, jump to the |
| 3469 |
// bailout tail stub. Load 1 (true) in ReturnReg to indicate success. |
| 3470 |
bind(&bailout); |
| 3471 |
{ |
| 3472 |
ScratchRegisterScope scratch(asMasm()); |
| 3473 |
ma_ldr(Address(sp, ResumeFromException::offsetOfBailoutInfo()), r2, |
| 3474 |
scratch); |
| 3475 |
ma_ldr(Address(sp, ResumeFromException::offsetOfStackPointer()), sp, |
| 3476 |
scratch); |
| 3477 |
ma_mov(Imm32(1), ReturnReg); |
| 3478 |
} |
| 3479 |
jump(bailoutTail); |
| 3480 |
|
| 3481 |
// Reset SP and FP; SP is pointing to the unwound return address to the wasm |
| 3482 |
// interpreter entry, so we can just ret(). |
| 3483 |
bind(&wasmInterpEntry); |
| 3484 |
{ |
| 3485 |
ScratchRegisterScope scratch(asMasm()); |
| 3486 |
ma_ldr(Address(sp, ResumeFromException::offsetOfFramePointer()), r11, |
| 3487 |
scratch); |
| 3488 |
ma_ldr(Address(sp, ResumeFromException::offsetOfStackPointer()), sp, |
| 3489 |
scratch); |
| 3490 |
ma_mov(Imm32(int32_t(wasm::InterpFailInstanceReg)), InstanceReg); |
| 3491 |
} |
| 3492 |
as_dtr(IsLoad, 32, PostIndex, pc, DTRAddr(sp, DtrOffImm(4))); |
| 3493 |
|
| 3494 |
// Found a wasm catch handler, restore state and jump to it. |
| 3495 |
bind(&wasmCatch); |
| 3496 |
wasm::GenerateJumpToCatchHandler(asMasm(), sp, r0, r1); |
| 3497 |
} |
| 3498 |
|
| 3499 |
Assembler::Condition MacroAssemblerARMCompat::testStringTruthy( |
| 3500 |
bool truthy, const ValueOperand& value) { |
| 3501 |
Register string = value.payloadReg(); |
| 3502 |
ScratchRegisterScope scratch(asMasm()); |
| 3503 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 3504 |
|
| 3505 |
ma_dtr(IsLoad, string, Imm32(JSString::offsetOfLength()), scratch, scratch2); |
| 3506 |
as_cmp(scratch, Imm8(0)); |
| 3507 |
return truthy ? Assembler::NotEqual : Assembler::Equal; |
| 3508 |
} |
| 3509 |
|
| 3510 |
Assembler::Condition MacroAssemblerARMCompat::testBigIntTruthy( |
| 3511 |
bool truthy, const ValueOperand& value) { |
| 3512 |
Register bi = value.payloadReg(); |
| 3513 |
ScratchRegisterScope scratch(asMasm()); |
| 3514 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 3515 |
|
| 3516 |
ma_dtr(IsLoad, bi, Imm32(BigInt::offsetOfDigitLength()), scratch, scratch2); |
| 3517 |
as_cmp(scratch, Imm8(0)); |
| 3518 |
return truthy ? Assembler::NotEqual : Assembler::Equal; |
| 3519 |
} |
| 3520 |
|
| 3521 |
void MacroAssemblerARMCompat::floor(FloatRegister input, Register output, |
| 3522 |
Label* bail) { |
| 3523 |
Label handleZero; |
| 3524 |
Label handleNeg; |
| 3525 |
Label fin; |
| 3526 |
|
| 3527 |
ScratchDoubleScope scratchDouble(asMasm()); |
| 3528 |
|
| 3529 |
compareDouble(input, NoVFPRegister); |
| 3530 |
ma_b(&handleZero, Assembler::Equal); |
| 3531 |
ma_b(&handleNeg, Assembler::Signed); |
| 3532 |
// NaN is always a bail condition, just bail directly. |
| 3533 |
ma_b(bail, Assembler::Overflow); |
| 3534 |
|
| 3535 |
// The argument is a positive number, truncation is the path to glory. Since |
| 3536 |
// it is known to be > 0.0, explicitly convert to a larger range, then a |
| 3537 |
// value that rounds to INT_MAX is explicitly different from an argument |
| 3538 |
// that clamps to INT_MAX. |
| 3539 |
ma_vcvt_F64_U32(input, scratchDouble.uintOverlay()); |
| 3540 |
ma_vxfer(scratchDouble.uintOverlay(), output); |
| 3541 |
ma_mov(output, output, SetCC); |
| 3542 |
ma_b(bail, Signed); |
| 3543 |
ma_b(&fin); |
| 3544 |
|
| 3545 |
bind(&handleZero); |
| 3546 |
// Move the top word of the double into the output reg, if it is non-zero, |
| 3547 |
// then the original value was -0.0. |
| 3548 |
as_vxfer(output, InvalidReg, input, FloatToCore, Always, 1); |
| 3549 |
as_cmp(output, Imm8(0)); |
| 3550 |
ma_b(bail, NonZero); |
| 3551 |
ma_b(&fin); |
| 3552 |
|
| 3553 |
bind(&handleNeg); |
| 3554 |
// Negative case, negate, then start dancing. |
| 3555 |
ma_vneg(input, input); |
| 3556 |
ma_vcvt_F64_U32(input, scratchDouble.uintOverlay()); |
| 3557 |
ma_vxfer(scratchDouble.uintOverlay(), output); |
| 3558 |
ma_vcvt_U32_F64(scratchDouble.uintOverlay(), scratchDouble); |
| 3559 |
compareDouble(scratchDouble, input); |
| 3560 |
as_add(output, output, Imm8(1), LeaveCC, NotEqual); |
| 3561 |
// Negate the output. Since INT_MIN < -INT_MAX, even after adding 1, the |
| 3562 |
// result will still be a negative number. |
| 3563 |
as_rsb(output, output, Imm8(0), SetCC); |
| 3564 |
// Flip the negated input back to its original value. |
| 3565 |
ma_vneg(input, input); |
| 3566 |
// If the result looks non-negative, then this value didn't actually fit |
| 3567 |
// into the int range, and special handling is required. Zero is also caught |
| 3568 |
// by this case, but floor of a negative number should never be zero. |
| 3569 |
ma_b(bail, NotSigned); |
| 3570 |
|
| 3571 |
bind(&fin); |
| 3572 |
} |
| 3573 |
|
| 3574 |
void MacroAssemblerARMCompat::floorf(FloatRegister input, Register output, |
| 3575 |
Label* bail) { |
| 3576 |
Label handleZero; |
| 3577 |
Label handleNeg; |
| 3578 |
Label fin; |
| 3579 |
compareFloat(input, NoVFPRegister); |
| 3580 |
ma_b(&handleZero, Assembler::Equal); |
| 3581 |
ma_b(&handleNeg, Assembler::Signed); |
| 3582 |
// NaN is always a bail condition, just bail directly. |
| 3583 |
ma_b(bail, Assembler::Overflow); |
| 3584 |
|
| 3585 |
// The argument is a positive number, truncation is the path to glory; Since |
| 3586 |
// it is known to be > 0.0, explicitly convert to a larger range, then a |
| 3587 |
// value that rounds to INT_MAX is explicitly different from an argument |
| 3588 |
// that clamps to INT_MAX. |
| 3589 |
{ |
| 3590 |
ScratchFloat32Scope scratch(asMasm()); |
| 3591 |
ma_vcvt_F32_U32(input, scratch.uintOverlay()); |
| 3592 |
ma_vxfer(VFPRegister(scratch).uintOverlay(), output); |
| 3593 |
} |
| 3594 |
ma_mov(output, output, SetCC); |
| 3595 |
ma_b(bail, Signed); |
| 3596 |
ma_b(&fin); |
| 3597 |
|
| 3598 |
bind(&handleZero); |
| 3599 |
// Move the top word of the double into the output reg, if it is non-zero, |
| 3600 |
// then the original value was -0.0. |
| 3601 |
as_vxfer(output, InvalidReg, VFPRegister(input).singleOverlay(), FloatToCore, |
| 3602 |
Always, 0); |
| 3603 |
as_cmp(output, Imm8(0)); |
| 3604 |
ma_b(bail, NonZero); |
| 3605 |
ma_b(&fin); |
| 3606 |
|
| 3607 |
bind(&handleNeg); |
| 3608 |
// Negative case, negate, then start dancing. |
| 3609 |
{ |
| 3610 |
ScratchFloat32Scope scratch(asMasm()); |
| 3611 |
ma_vneg_f32(input, input); |
| 3612 |
ma_vcvt_F32_U32(input, scratch.uintOverlay()); |
| 3613 |
ma_vxfer(VFPRegister(scratch).uintOverlay(), output); |
| 3614 |
ma_vcvt_U32_F32(scratch.uintOverlay(), scratch); |
| 3615 |
compareFloat(scratch, input); |
| 3616 |
as_add(output, output, Imm8(1), LeaveCC, NotEqual); |
| 3617 |
} |
| 3618 |
// Negate the output. Since INT_MIN < -INT_MAX, even after adding 1, the |
| 3619 |
// result will still be a negative number. |
| 3620 |
as_rsb(output, output, Imm8(0), SetCC); |
| 3621 |
// Flip the negated input back to its original value. |
| 3622 |
ma_vneg_f32(input, input); |
| 3623 |
// If the result looks non-negative, then this value didn't actually fit |
| 3624 |
// into the int range, and special handling is required. Zero is also caught |
| 3625 |
// by this case, but floor of a negative number should never be zero. |
| 3626 |
ma_b(bail, NotSigned); |
| 3627 |
|
| 3628 |
bind(&fin); |
| 3629 |
} |
| 3630 |
|
| 3631 |
void MacroAssemblerARMCompat::ceil(FloatRegister input, Register output, |
| 3632 |
Label* bail) { |
| 3633 |
Label handleZero; |
| 3634 |
Label handlePos; |
| 3635 |
Label fin; |
| 3636 |
|
| 3637 |
compareDouble(input, NoVFPRegister); |
| 3638 |
// NaN is always a bail condition, just bail directly. |
| 3639 |
ma_b(bail, Assembler::Overflow); |
| 3640 |
ma_b(&handleZero, Assembler::Equal); |
| 3641 |
ma_b(&handlePos, Assembler::NotSigned); |
| 3642 |
|
| 3643 |
ScratchDoubleScope scratchDouble(asMasm()); |
| 3644 |
|
| 3645 |
// We are in the ]-Inf; 0[ range |
| 3646 |
// If we are in the ]-1; 0[ range => bailout |
| 3647 |
loadConstantDouble(-1.0, scratchDouble); |
| 3648 |
compareDouble(input, scratchDouble); |
| 3649 |
ma_b(bail, Assembler::GreaterThan); |
| 3650 |
|
| 3651 |
// We are in the ]-Inf; -1] range: ceil(x) == -floor(-x) and floor can be |
| 3652 |
// computed with direct truncation here (x > 0). |
| 3653 |
ma_vneg(input, scratchDouble); |
| 3654 |
FloatRegister ScratchUIntReg = scratchDouble.uintOverlay(); |
| 3655 |
ma_vcvt_F64_U32(scratchDouble, ScratchUIntReg); |
| 3656 |
ma_vxfer(ScratchUIntReg, output); |
| 3657 |
ma_neg(output, output, SetCC); |
| 3658 |
ma_b(bail, NotSigned); |
| 3659 |
ma_b(&fin); |
| 3660 |
|
| 3661 |
// Test for 0.0 / -0.0: if the top word of the input double is not zero, |
| 3662 |
// then it was -0 and we need to bail out. |
| 3663 |
bind(&handleZero); |
| 3664 |
as_vxfer(output, InvalidReg, input, FloatToCore, Always, 1); |
| 3665 |
as_cmp(output, Imm8(0)); |
| 3666 |
ma_b(bail, NonZero); |
| 3667 |
ma_b(&fin); |
| 3668 |
|
| 3669 |
// We are in the ]0; +inf] range: truncate integer values, maybe add 1 for |
| 3670 |
// non integer values, maybe bail if overflow. |
| 3671 |
bind(&handlePos); |
| 3672 |
ma_vcvt_F64_U32(input, ScratchUIntReg); |
| 3673 |
ma_vxfer(ScratchUIntReg, output); |
| 3674 |
ma_vcvt_U32_F64(ScratchUIntReg, scratchDouble); |
| 3675 |
compareDouble(scratchDouble, input); |
| 3676 |
as_add(output, output, Imm8(1), LeaveCC, NotEqual); |
| 3677 |
// Bail out if the add overflowed or the result is non positive. |
| 3678 |
ma_mov(output, output, SetCC); |
| 3679 |
ma_b(bail, Signed); |
| 3680 |
ma_b(bail, Zero); |
| 3681 |
|
| 3682 |
bind(&fin); |
| 3683 |
} |
| 3684 |
|
| 3685 |
void MacroAssemblerARMCompat::ceilf(FloatRegister input, Register output, |
| 3686 |
Label* bail) { |
| 3687 |
Label handleZero; |
| 3688 |
Label handlePos; |
| 3689 |
Label fin; |
| 3690 |
|
| 3691 |
compareFloat(input, NoVFPRegister); |
| 3692 |
// NaN is always a bail condition, just bail directly. |
| 3693 |
ma_b(bail, Assembler::Overflow); |
| 3694 |
ma_b(&handleZero, Assembler::Equal); |
| 3695 |
ma_b(&handlePos, Assembler::NotSigned); |
| 3696 |
|
| 3697 |
// We are in the ]-Inf; 0[ range |
| 3698 |
// If we are in the ]-1; 0[ range => bailout |
| 3699 |
{ |
| 3700 |
ScratchFloat32Scope scratch(asMasm()); |
| 3701 |
loadConstantFloat32(-1.f, scratch); |
| 3702 |
compareFloat(input, scratch); |
| 3703 |
ma_b(bail, Assembler::GreaterThan); |
| 3704 |
} |
| 3705 |
|
| 3706 |
// We are in the ]-Inf; -1] range: ceil(x) == -floor(-x) and floor can be |
| 3707 |
// computed with direct truncation here (x > 0). |
| 3708 |
{ |
| 3709 |
ScratchDoubleScope scratchDouble(asMasm()); |
| 3710 |
FloatRegister scratchFloat = scratchDouble.asSingle(); |
| 3711 |
FloatRegister scratchUInt = scratchDouble.uintOverlay(); |
| 3712 |
|
| 3713 |
ma_vneg_f32(input, scratchFloat); |
| 3714 |
ma_vcvt_F32_U32(scratchFloat, scratchUInt); |
| 3715 |
ma_vxfer(scratchUInt, output); |
| 3716 |
ma_neg(output, output, SetCC); |
| 3717 |
ma_b(bail, NotSigned); |
| 3718 |
ma_b(&fin); |
| 3719 |
} |
| 3720 |
|
| 3721 |
// Test for 0.0 / -0.0: if the top word of the input double is not zero, |
| 3722 |
// then it was -0 and we need to bail out. |
| 3723 |
bind(&handleZero); |
| 3724 |
as_vxfer(output, InvalidReg, VFPRegister(input).singleOverlay(), FloatToCore, |
| 3725 |
Always, 0); |
| 3726 |
as_cmp(output, Imm8(0)); |
| 3727 |
ma_b(bail, NonZero); |
| 3728 |
ma_b(&fin); |
| 3729 |
|
| 3730 |
// We are in the ]0; +inf] range: truncate integer values, maybe add 1 for |
| 3731 |
// non integer values, maybe bail if overflow. |
| 3732 |
bind(&handlePos); |
| 3733 |
{ |
| 3734 |
ScratchDoubleScope scratchDouble(asMasm()); |
| 3735 |
FloatRegister scratchFloat = scratchDouble.asSingle(); |
| 3736 |
FloatRegister scratchUInt = scratchDouble.uintOverlay(); |
| 3737 |
|
| 3738 |
ma_vcvt_F32_U32(input, scratchUInt); |
| 3739 |
ma_vxfer(scratchUInt, output); |
| 3740 |
ma_vcvt_U32_F32(scratchUInt, scratchFloat); |
| 3741 |
compareFloat(scratchFloat, input); |
| 3742 |
as_add(output, output, Imm8(1), LeaveCC, NotEqual); |
| 3743 |
|
| 3744 |
// Bail on overflow or non-positive result. |
| 3745 |
ma_mov(output, output, SetCC); |
| 3746 |
ma_b(bail, Signed); |
| 3747 |
ma_b(bail, Zero); |
| 3748 |
} |
| 3749 |
|
| 3750 |
bind(&fin); |
| 3751 |
} |
| 3752 |
|
| 3753 |
void MacroAssemblerARMCompat::mov(CodeLabel* label, Register dest) { |
| 3754 |
BufferOffset bo = |
| 3755 |
ma_movPatchable(ImmPtr(/* placeholder */ nullptr), dest, Always); |
| 3756 |
label->patchAt()->bind(bo.getOffset()); |
| 3757 |
label->setLinkMode(CodeLabel::MoveImmediate); |
| 3758 |
} |
| 3759 |
|
| 3760 |
CodeOffset MacroAssemblerARMCompat::toggledJump(Label* label) { |
| 3761 |
// Emit a B that can be toggled to a CMP. See ToggleToJmp(), ToggleToCmp(). |
| 3762 |
BufferOffset b = ma_b(label, Always); |
| 3763 |
CodeOffset ret(b.getOffset()); |
| 3764 |
return ret; |
| 3765 |
} |
| 3766 |
|
| 3767 |
CodeOffset MacroAssemblerARMCompat::toggledCall(JitCode* target, bool enabled) { |
| 3768 |
BufferOffset bo = nextOffset(); |
| 3769 |
addPendingJump(bo, ImmPtr(target->raw()), RelocationKind::JITCODE); |
| 3770 |
ScratchRegisterScope scratch(asMasm()); |
| 3771 |
ma_movPatchable(ImmPtr(target->raw()), scratch, Always); |
| 3772 |
if (enabled) { |
| 3773 |
ma_blx(scratch); |
| 3774 |
} else { |
| 3775 |
ma_nop(); |
| 3776 |
} |
| 3777 |
return CodeOffset(bo.getOffset()); |
| 3778 |
} |
| 3779 |
|
| 3780 |
void MacroAssemblerARMCompat::round(FloatRegister input, Register output, |
| 3781 |
Label* bail, FloatRegister tmp) { |
| 3782 |
Label handleZero; |
| 3783 |
Label handleNeg; |
| 3784 |
Label fin; |
| 3785 |
|
| 3786 |
ScratchDoubleScope scratchDouble(asMasm()); |
| 3787 |
|
| 3788 |
// Do a compare based on the original value, then do most other things based |
| 3789 |
// on the shifted value. |
| 3790 |
ma_vcmpz(input); |
| 3791 |
// Since we already know the sign bit, flip all numbers to be positive, |
| 3792 |
// stored in tmp. |
| 3793 |
ma_vabs(input, tmp); |
| 3794 |
as_vmrs(pc); |
| 3795 |
ma_b(&handleZero, Assembler::Equal); |
| 3796 |
ma_b(&handleNeg, Assembler::Signed); |
| 3797 |
// NaN is always a bail condition, just bail directly. |
| 3798 |
ma_b(bail, Assembler::Overflow); |
| 3799 |
|
| 3800 |
// The argument is a positive number, truncation is the path to glory; Since |
| 3801 |
// it is known to be > 0.0, explicitly convert to a larger range, then a |
| 3802 |
// value that rounds to INT_MAX is explicitly different from an argument |
| 3803 |
// that clamps to INT_MAX. |
| 3804 |
|
| 3805 |
// Add the biggest number less than 0.5 (not 0.5, because adding that to |
| 3806 |
// the biggest number less than 0.5 would undesirably round up to 1), and |
| 3807 |
// store the result into tmp. |
| 3808 |
loadConstantDouble(GetBiggestNumberLessThan(0.5), scratchDouble); |
| 3809 |
ma_vadd(scratchDouble, tmp, tmp); |
| 3810 |
|
| 3811 |
ma_vcvt_F64_U32(tmp, scratchDouble.uintOverlay()); |
| 3812 |
ma_vxfer(VFPRegister(scratchDouble).uintOverlay(), output); |
| 3813 |
ma_mov(output, output, SetCC); |
| 3814 |
ma_b(bail, Signed); |
| 3815 |
ma_b(&fin); |
| 3816 |
|
| 3817 |
bind(&handleZero); |
| 3818 |
// Move the top word of the double into the output reg, if it is non-zero, |
| 3819 |
// then the original value was -0.0 |
| 3820 |
as_vxfer(output, InvalidReg, input, FloatToCore, Always, 1); |
| 3821 |
as_cmp(output, Imm8(0)); |
| 3822 |
ma_b(bail, NonZero); |
| 3823 |
ma_b(&fin); |
| 3824 |
|
| 3825 |
bind(&handleNeg); |
| 3826 |
// Negative case, negate, then start dancing. This number may be positive, |
| 3827 |
// since we added 0.5. |
| 3828 |
|
| 3829 |
// Add 0.5 to negative numbers, store the result into tmp |
| 3830 |
loadConstantDouble(0.5, scratchDouble); |
| 3831 |
ma_vadd(scratchDouble, tmp, tmp); |
| 3832 |
|
| 3833 |
ma_vcvt_F64_U32(tmp, scratchDouble.uintOverlay()); |
| 3834 |
ma_vxfer(VFPRegister(scratchDouble).uintOverlay(), output); |
| 3835 |
|
| 3836 |
// -output is now a correctly rounded value, unless the original value was |
| 3837 |
// exactly halfway between two integers, at which point, it has been rounded |
| 3838 |
// away from zero, when it should be rounded towards \infty. |
| 3839 |
ma_vcvt_U32_F64(scratchDouble.uintOverlay(), scratchDouble); |
| 3840 |
compareDouble(scratchDouble, tmp); |
| 3841 |
as_sub(output, output, Imm8(1), LeaveCC, Equal); |
| 3842 |
// Negate the output. Since INT_MIN < -INT_MAX, even after adding 1, the |
| 3843 |
// result will still be a negative number. |
| 3844 |
as_rsb(output, output, Imm8(0), SetCC); |
| 3845 |
|
| 3846 |
// If the result looks non-negative, then this value didn't actually fit |
| 3847 |
// into the int range, and special handling is required, or it was zero, |
| 3848 |
// which means the result is actually -0.0 which also requires special |
| 3849 |
// handling. |
| 3850 |
ma_b(bail, NotSigned); |
| 3851 |
|
| 3852 |
bind(&fin); |
| 3853 |
} |
| 3854 |
|
| 3855 |
void MacroAssemblerARMCompat::roundf(FloatRegister input, Register output, |
| 3856 |
Label* bail, FloatRegister tmp) { |
| 3857 |
Label handleZero; |
| 3858 |
Label handleNeg; |
| 3859 |
Label fin; |
| 3860 |
|
| 3861 |
ScratchFloat32Scope scratchFloat(asMasm()); |
| 3862 |
|
| 3863 |
// Do a compare based on the original value, then do most other things based |
| 3864 |
// on the shifted value. |
| 3865 |
compareFloat(input, NoVFPRegister); |
| 3866 |
ma_b(&handleZero, Assembler::Equal); |
| 3867 |
ma_b(&handleNeg, Assembler::Signed); |
| 3868 |
|
| 3869 |
// NaN is always a bail condition, just bail directly. |
| 3870 |
ma_b(bail, Assembler::Overflow); |
| 3871 |
|
| 3872 |
// The argument is a positive number, truncation is the path to glory; Since |
| 3873 |
// it is known to be > 0.0, explicitly convert to a larger range, then a |
| 3874 |
// value that rounds to INT_MAX is explicitly different from an argument |
| 3875 |
// that clamps to INT_MAX. |
| 3876 |
|
| 3877 |
// Add the biggest number less than 0.5f (not 0.5f, because adding that to |
| 3878 |
// the biggest number less than 0.5f would undesirably round up to 1), and |
| 3879 |
// store the result into tmp. |
| 3880 |
loadConstantFloat32(GetBiggestNumberLessThan(0.5f), scratchFloat); |
| 3881 |
ma_vadd_f32(scratchFloat, input, tmp); |
| 3882 |
|
| 3883 |
// Note: it doesn't matter whether x + .5 === x or not here, as it doesn't |
| 3884 |
// affect the semantics of the float to unsigned conversion (in particular, |
| 3885 |
// we are not applying any fixup after the operation). |
| 3886 |
ma_vcvt_F32_U32(tmp, scratchFloat.uintOverlay()); |
| 3887 |
ma_vxfer(VFPRegister(scratchFloat).uintOverlay(), output); |
| 3888 |
ma_mov(output, output, SetCC); |
| 3889 |
ma_b(bail, Signed); |
| 3890 |
ma_b(&fin); |
| 3891 |
|
| 3892 |
bind(&handleZero); |
| 3893 |
|
| 3894 |
// Move the whole float32 into the output reg, if it is non-zero, then the |
| 3895 |
// original value was -0.0. |
| 3896 |
as_vxfer(output, InvalidReg, input, FloatToCore, Always, 0); |
| 3897 |
as_cmp(output, Imm8(0)); |
| 3898 |
ma_b(bail, NonZero); |
| 3899 |
ma_b(&fin); |
| 3900 |
|
| 3901 |
bind(&handleNeg); |
| 3902 |
|
| 3903 |
// Add 0.5 to negative numbers, storing the result into tmp. |
| 3904 |
ma_vneg_f32(input, tmp); |
| 3905 |
loadConstantFloat32(0.5f, scratchFloat); |
| 3906 |
ma_vadd_f32(tmp, scratchFloat, scratchFloat); |
| 3907 |
|
| 3908 |
// Adding 0.5 to a float input has chances to yield the wrong result, if |
| 3909 |
// the input is too large. In this case, skip the -1 adjustment made below. |
| 3910 |
compareFloat(scratchFloat, tmp); |
| 3911 |
|
| 3912 |
// Negative case, negate, then start dancing. This number may be positive, |
| 3913 |
// since we added 0.5. |
| 3914 |
// /!\ The conditional jump afterwards depends on these two instructions |
| 3915 |
// *not* setting the status flags. They need to not change after the |
| 3916 |
// comparison above. |
| 3917 |
ma_vcvt_F32_U32(scratchFloat, tmp.uintOverlay()); |
| 3918 |
ma_vxfer(VFPRegister(tmp).uintOverlay(), output); |
| 3919 |
|
| 3920 |
Label flipSign; |
| 3921 |
ma_b(&flipSign, Equal); |
| 3922 |
|
| 3923 |
// -output is now a correctly rounded value, unless the original value was |
| 3924 |
// exactly halfway between two integers, at which point, it has been rounded |
| 3925 |
// away from zero, when it should be rounded towards \infty. |
| 3926 |
ma_vcvt_U32_F32(tmp.uintOverlay(), tmp); |
| 3927 |
compareFloat(tmp, scratchFloat); |
| 3928 |
as_sub(output, output, Imm8(1), LeaveCC, Equal); |
| 3929 |
|
| 3930 |
// Negate the output. Since INT_MIN < -INT_MAX, even after adding 1, the |
| 3931 |
// result will still be a negative number. |
| 3932 |
bind(&flipSign); |
| 3933 |
as_rsb(output, output, Imm8(0), SetCC); |
| 3934 |
|
| 3935 |
// If the result looks non-negative, then this value didn't actually fit |
| 3936 |
// into the int range, and special handling is required, or it was zero, |
| 3937 |
// which means the result is actually -0.0 which also requires special |
| 3938 |
// handling. |
| 3939 |
ma_b(bail, NotSigned); |
| 3940 |
|
| 3941 |
bind(&fin); |
| 3942 |
} |
| 3943 |
|
| 3944 |
void MacroAssemblerARMCompat::trunc(FloatRegister input, Register output, |
| 3945 |
Label* bail) { |
| 3946 |
Label handleZero; |
| 3947 |
Label handlePos; |
| 3948 |
Label fin; |
| 3949 |
|
| 3950 |
compareDouble(input, NoVFPRegister); |
| 3951 |
// NaN is always a bail condition, just bail directly. |
| 3952 |
ma_b(bail, Assembler::Overflow); |
| 3953 |
ma_b(&handleZero, Assembler::Equal); |
| 3954 |
ma_b(&handlePos, Assembler::NotSigned); |
| 3955 |
|
| 3956 |
ScratchDoubleScope scratchDouble(asMasm()); |
| 3957 |
|
| 3958 |
// We are in the ]-Inf; 0[ range |
| 3959 |
// If we are in the ]-1; 0[ range => bailout |
| 3960 |
loadConstantDouble(-1.0, scratchDouble); |
| 3961 |
compareDouble(input, scratchDouble); |
| 3962 |
ma_b(bail, Assembler::GreaterThan); |
| 3963 |
|
| 3964 |
// We are in the ]-Inf; -1] range: trunc(x) == -floor(-x) and floor can be |
| 3965 |
// computed with direct truncation here (x > 0). |
| 3966 |
ma_vneg(input, scratchDouble); |
| 3967 |
ma_vcvt_F64_U32(scratchDouble, scratchDouble.uintOverlay()); |
| 3968 |
ma_vxfer(scratchDouble.uintOverlay(), output); |
| 3969 |
ma_neg(output, output, SetCC); |
| 3970 |
ma_b(bail, NotSigned); |
| 3971 |
ma_b(&fin); |
| 3972 |
|
| 3973 |
// Test for 0.0 / -0.0: if the top word of the input double is not zero, |
| 3974 |
// then it was -0 and we need to bail out. |
| 3975 |
bind(&handleZero); |
| 3976 |
as_vxfer(output, InvalidReg, input, FloatToCore, Always, 1); |
| 3977 |
as_cmp(output, Imm8(0)); |
| 3978 |
ma_b(bail, NonZero); |
| 3979 |
ma_b(&fin); |
| 3980 |
|
| 3981 |
// We are in the ]0; +inf] range: truncation is the path to glory. Since |
| 3982 |
// it is known to be > 0.0, explicitly convert to a larger range, then a |
| 3983 |
// value that rounds to INT_MAX is explicitly different from an argument |
| 3984 |
// that clamps to INT_MAX. |
| 3985 |
bind(&handlePos); |
| 3986 |
ma_vcvt_F64_U32(input, scratchDouble.uintOverlay()); |
| 3987 |
ma_vxfer(scratchDouble.uintOverlay(), output); |
| 3988 |
ma_mov(output, output, SetCC); |
| 3989 |
ma_b(bail, Signed); |
| 3990 |
|
| 3991 |
bind(&fin); |
| 3992 |
} |
| 3993 |
|
| 3994 |
void MacroAssemblerARMCompat::truncf(FloatRegister input, Register output, |
| 3995 |
Label* bail) { |
| 3996 |
Label handleZero; |
| 3997 |
Label handlePos; |
| 3998 |
Label fin; |
| 3999 |
|
| 4000 |
compareFloat(input, NoVFPRegister); |
| 4001 |
// NaN is always a bail condition, just bail directly. |
| 4002 |
ma_b(bail, Assembler::Overflow); |
| 4003 |
ma_b(&handleZero, Assembler::Equal); |
| 4004 |
ma_b(&handlePos, Assembler::NotSigned); |
| 4005 |
|
| 4006 |
// We are in the ]-Inf; 0[ range |
| 4007 |
// If we are in the ]-1; 0[ range => bailout |
| 4008 |
{ |
| 4009 |
ScratchFloat32Scope scratch(asMasm()); |
| 4010 |
loadConstantFloat32(-1.f, scratch); |
| 4011 |
compareFloat(input, scratch); |
| 4012 |
ma_b(bail, Assembler::GreaterThan); |
| 4013 |
} |
| 4014 |
|
| 4015 |
// We are in the ]-Inf; -1] range: trunc(x) == -floor(-x) and floor can be |
| 4016 |
// computed with direct truncation here (x > 0). |
| 4017 |
{ |
| 4018 |
ScratchDoubleScope scratchDouble(asMasm()); |
| 4019 |
FloatRegister scratchFloat = scratchDouble.asSingle(); |
| 4020 |
FloatRegister scratchUInt = scratchDouble.uintOverlay(); |
| 4021 |
|
| 4022 |
ma_vneg_f32(input, scratchFloat); |
| 4023 |
ma_vcvt_F32_U32(scratchFloat, scratchUInt); |
| 4024 |
ma_vxfer(scratchUInt, output); |
| 4025 |
ma_neg(output, output, SetCC); |
| 4026 |
ma_b(bail, NotSigned); |
| 4027 |
ma_b(&fin); |
| 4028 |
} |
| 4029 |
|
| 4030 |
// Test for 0.0 / -0.0: if the top word of the input double is not zero, |
| 4031 |
// then it was -0 and we need to bail out. |
| 4032 |
bind(&handleZero); |
| 4033 |
as_vxfer(output, InvalidReg, VFPRegister(input).singleOverlay(), FloatToCore, |
| 4034 |
Always, 0); |
| 4035 |
as_cmp(output, Imm8(0)); |
| 4036 |
ma_b(bail, NonZero); |
| 4037 |
ma_b(&fin); |
| 4038 |
|
| 4039 |
// We are in the ]0; +inf] range: truncation is the path to glory; Since |
| 4040 |
// it is known to be > 0.0, explicitly convert to a larger range, then a |
| 4041 |
// value that rounds to INT_MAX is explicitly different from an argument |
| 4042 |
bind(&handlePos); |
| 4043 |
{ |
| 4044 |
// The argument is a positive number, |
| 4045 |
// that clamps to INT_MAX. |
| 4046 |
{ |
| 4047 |
ScratchFloat32Scope scratch(asMasm()); |
| 4048 |
ma_vcvt_F32_U32(input, scratch.uintOverlay()); |
| 4049 |
ma_vxfer(VFPRegister(scratch).uintOverlay(), output); |
| 4050 |
} |
| 4051 |
ma_mov(output, output, SetCC); |
| 4052 |
ma_b(bail, Signed); |
| 4053 |
} |
| 4054 |
|
| 4055 |
bind(&fin); |
| 4056 |
} |
| 4057 |
|
| 4058 |
void MacroAssemblerARMCompat::profilerEnterFrame(Register framePtr, |
| 4059 |
Register scratch) { |
| 4060 |
asMasm().loadJSContext(scratch); |
| 4061 |
loadPtr(Address(scratch, offsetof(JSContext, profilingActivation_)), scratch); |
| 4062 |
storePtr(framePtr, |
| 4063 |
Address(scratch, JitActivation::offsetOfLastProfilingFrame())); |
| 4064 |
storePtr(ImmPtr(nullptr), |
| 4065 |
Address(scratch, JitActivation::offsetOfLastProfilingCallSite())); |
| 4066 |
} |
| 4067 |
|
| 4068 |
void MacroAssemblerARMCompat::profilerExitFrame() { |
| 4069 |
jump(asMasm().runtime()->jitRuntime()->getProfilerExitFrameTail()); |
| 4070 |
} |
| 4071 |
|
| 4072 |
MacroAssembler& MacroAssemblerARM::asMasm() { |
| 4073 |
return *static_cast<MacroAssembler*>(this); |
| 4074 |
} |
| 4075 |
|
| 4076 |
const MacroAssembler& MacroAssemblerARM::asMasm() const { |
| 4077 |
return *static_cast<const MacroAssembler*>(this); |
| 4078 |
} |
| 4079 |
|
| 4080 |
MacroAssembler& MacroAssemblerARMCompat::asMasm() { |
| 4081 |
return *static_cast<MacroAssembler*>(this); |
| 4082 |
} |
| 4083 |
|
| 4084 |
const MacroAssembler& MacroAssemblerARMCompat::asMasm() const { |
| 4085 |
return *static_cast<const MacroAssembler*>(this); |
| 4086 |
} |
| 4087 |
|
| 4088 |
void MacroAssembler::subFromStackPtr(Imm32 imm32) { |
| 4089 |
ScratchRegisterScope scratch(*this); |
| 4090 |
if (imm32.value) { |
| 4091 |
ma_sub(imm32, sp, scratch); |
| 4092 |
} |
| 4093 |
} |
| 4094 |
|
| 4095 |
//{{{ check_macroassembler_style |
| 4096 |
// =============================================================== |
| 4097 |
// MacroAssembler high-level usage. |
| 4098 |
|
| 4099 |
void MacroAssembler::flush() { Assembler::flush(); } |
| 4100 |
|
| 4101 |
void MacroAssembler::comment(const char* msg) { Assembler::comment(msg); } |
| 4102 |
|
| 4103 |
// =============================================================== |
| 4104 |
// Stack manipulation functions. |
| 4105 |
|
| 4106 |
size_t MacroAssembler::PushRegsInMaskSizeInBytes(LiveRegisterSet set) { |
| 4107 |
return set.gprs().size() * sizeof(intptr_t) + set.fpus().getPushSizeInBytes(); |
| 4108 |
} |
| 4109 |
|
| 4110 |
void MacroAssembler::PushRegsInMask(LiveRegisterSet set) { |
| 4111 |
mozilla::DebugOnly<size_t> framePushedInitial = framePushed(); |
| 4112 |
|
| 4113 |
int32_t diffF = set.fpus().getPushSizeInBytes(); |
| 4114 |
int32_t diffG = set.gprs().size() * sizeof(intptr_t); |
| 4115 |
|
| 4116 |
if (set.gprs().size() > 1) { |
| 4117 |
adjustFrame(diffG); |
| 4118 |
startDataTransferM(IsStore, StackPointer, DB, WriteBack); |
| 4119 |
for (GeneralRegisterBackwardIterator iter(set.gprs()); iter.more(); |
| 4120 |
++iter) { |
| 4121 |
diffG -= sizeof(intptr_t); |
| 4122 |
transferReg(*iter); |
| 4123 |
} |
| 4124 |
finishDataTransfer(); |
| 4125 |
} else { |
| 4126 |
reserveStack(diffG); |
| 4127 |
for (GeneralRegisterBackwardIterator iter(set.gprs()); iter.more(); |
| 4128 |
++iter) { |
| 4129 |
diffG -= sizeof(intptr_t); |
| 4130 |
storePtr(*iter, Address(StackPointer, diffG)); |
| 4131 |
} |
| 4132 |
} |
| 4133 |
MOZ_ASSERT(diffG == 0); |
| 4134 |
|
| 4135 |
// It's possible that the logic is just fine as it is if the reduced set |
| 4136 |
// maps SIMD pairs to plain doubles and transferMultipleByRuns() stores |
| 4137 |
// and loads doubles. |
| 4138 |
#ifdef ENABLE_WASM_SIMD |
| 4139 |
# error "Needs more careful logic if SIMD is enabled" |
| 4140 |
#endif |
| 4141 |
|
| 4142 |
adjustFrame(diffF); |
| 4143 |
diffF += transferMultipleByRuns(set.fpus(), IsStore, StackPointer, DB); |
| 4144 |
MOZ_ASSERT(diffF == 0); |
| 4145 |
|
| 4146 |
MOZ_ASSERT(framePushed() - framePushedInitial == |
| 4147 |
PushRegsInMaskSizeInBytes(set)); |
| 4148 |
} |
| 4149 |
|
| 4150 |
void MacroAssembler::storeRegsInMask(LiveRegisterSet set, Address dest, |
| 4151 |
Register scratch) { |
| 4152 |
mozilla::DebugOnly<size_t> offsetInitial = dest.offset; |
| 4153 |
|
| 4154 |
int32_t diffF = set.fpus().getPushSizeInBytes(); |
| 4155 |
int32_t diffG = set.gprs().size() * sizeof(intptr_t); |
| 4156 |
|
| 4157 |
MOZ_ASSERT(dest.offset >= diffF + diffG); |
| 4158 |
|
| 4159 |
if (set.gprs().size() > 1) { |
| 4160 |
computeEffectiveAddress(dest, scratch); |
| 4161 |
|
| 4162 |
startDataTransferM(IsStore, scratch, DB, WriteBack); |
| 4163 |
for (GeneralRegisterBackwardIterator iter(set.gprs()); iter.more(); |
| 4164 |
++iter) { |
| 4165 |
diffG -= sizeof(intptr_t); |
| 4166 |
dest.offset -= sizeof(intptr_t); |
| 4167 |
transferReg(*iter); |
| 4168 |
} |
| 4169 |
finishDataTransfer(); |
| 4170 |
} else { |
| 4171 |
for (GeneralRegisterBackwardIterator iter(set.gprs()); iter.more(); |
| 4172 |
++iter) { |
| 4173 |
diffG -= sizeof(intptr_t); |
| 4174 |
dest.offset -= sizeof(intptr_t); |
| 4175 |
storePtr(*iter, dest); |
| 4176 |
} |
| 4177 |
} |
| 4178 |
MOZ_ASSERT(diffG == 0); |
| 4179 |
(void)diffG; |
| 4180 |
|
| 4181 |
// See above. |
| 4182 |
#ifdef ENABLE_WASM_SIMD |
| 4183 |
# error "Needs more careful logic if SIMD is enabled" |
| 4184 |
#endif |
| 4185 |
|
| 4186 |
MOZ_ASSERT(diffF >= 0); |
| 4187 |
if (diffF > 0) { |
| 4188 |
computeEffectiveAddress(dest, scratch); |
| 4189 |
diffF += transferMultipleByRuns(set.fpus(), IsStore, scratch, DB); |
| 4190 |
} |
| 4191 |
|
| 4192 |
MOZ_ASSERT(diffF == 0); |
| 4193 |
|
| 4194 |
// "The amount of space actually used does not exceed what |
| 4195 |
// `PushRegsInMaskSizeInBytes` claims will be used." |
| 4196 |
MOZ_ASSERT(offsetInitial - dest.offset <= PushRegsInMaskSizeInBytes(set)); |
| 4197 |
} |
| 4198 |
|
| 4199 |
void MacroAssembler::PopRegsInMaskIgnore(LiveRegisterSet set, |
| 4200 |
LiveRegisterSet ignore) { |
| 4201 |
mozilla::DebugOnly<size_t> framePushedInitial = framePushed(); |
| 4202 |
|
| 4203 |
int32_t diffG = set.gprs().size() * sizeof(intptr_t); |
| 4204 |
int32_t diffF = set.fpus().getPushSizeInBytes(); |
| 4205 |
const int32_t reservedG = diffG; |
| 4206 |
const int32_t reservedF = diffF; |
| 4207 |
|
| 4208 |
// See above. |
| 4209 |
#ifdef ENABLE_WASM_SIMD |
| 4210 |
# error "Needs more careful logic if SIMD is enabled" |
| 4211 |
#endif |
| 4212 |
|
| 4213 |
// ARM can load multiple registers at once, but only if we want back all |
| 4214 |
// the registers we previously saved to the stack. |
| 4215 |
if (ignore.emptyFloat()) { |
| 4216 |
diffF -= transferMultipleByRuns(set.fpus(), IsLoad, StackPointer, IA); |
| 4217 |
adjustFrame(-reservedF); |
| 4218 |
} else { |
| 4219 |
LiveFloatRegisterSet fpset(set.fpus().reduceSetForPush()); |
| 4220 |
LiveFloatRegisterSet fpignore(ignore.fpus().reduceSetForPush()); |
| 4221 |
for (FloatRegisterBackwardIterator iter(fpset); iter.more(); ++iter) { |
| 4222 |
diffF -= (*iter).size(); |
| 4223 |
if (!fpignore.has(*iter)) { |
| 4224 |
loadDouble(Address(StackPointer, diffF), *iter); |
| 4225 |
} |
| 4226 |
} |
| 4227 |
freeStack(reservedF); |
| 4228 |
} |
| 4229 |
MOZ_ASSERT(diffF == 0); |
| 4230 |
|
| 4231 |
if (set.gprs().size() > 1 && ignore.emptyGeneral()) { |
| 4232 |
startDataTransferM(IsLoad, StackPointer, IA, WriteBack); |
| 4233 |
for (GeneralRegisterBackwardIterator iter(set.gprs()); iter.more(); |
| 4234 |
++iter) { |
| 4235 |
diffG -= sizeof(intptr_t); |
| 4236 |
transferReg(*iter); |
| 4237 |
} |
| 4238 |
finishDataTransfer(); |
| 4239 |
adjustFrame(-reservedG); |
| 4240 |
} else { |
| 4241 |
for (GeneralRegisterBackwardIterator iter(set.gprs()); iter.more(); |
| 4242 |
++iter) { |
| 4243 |
diffG -= sizeof(intptr_t); |
| 4244 |
if (!ignore.has(*iter)) { |
| 4245 |
loadPtr(Address(StackPointer, diffG), *iter); |
| 4246 |
} |
| 4247 |
} |
| 4248 |
freeStack(reservedG); |
| 4249 |
} |
| 4250 |
MOZ_ASSERT(diffG == 0); |
| 4251 |
|
| 4252 |
MOZ_ASSERT(framePushedInitial - framePushed() == |
| 4253 |
PushRegsInMaskSizeInBytes(set)); |
| 4254 |
} |
| 4255 |
|
| 4256 |
void MacroAssembler::Push(Register reg) { |
| 4257 |
push(reg); |
| 4258 |
adjustFrame(sizeof(intptr_t)); |
| 4259 |
} |
| 4260 |
|
| 4261 |
void MacroAssembler::Push(const Imm32 imm) { |
| 4262 |
push(imm); |
| 4263 |
adjustFrame(sizeof(intptr_t)); |
| 4264 |
} |
| 4265 |
|
| 4266 |
void MacroAssembler::Push(const ImmWord imm) { |
| 4267 |
push(imm); |
| 4268 |
adjustFrame(sizeof(intptr_t)); |
| 4269 |
} |
| 4270 |
|
| 4271 |
void MacroAssembler::Push(const ImmPtr imm) { |
| 4272 |
Push(ImmWord(uintptr_t(imm.value))); |
| 4273 |
} |
| 4274 |
|
| 4275 |
void MacroAssembler::Push(const ImmGCPtr ptr) { |
| 4276 |
push(ptr); |
| 4277 |
adjustFrame(sizeof(intptr_t)); |
| 4278 |
} |
| 4279 |
|
| 4280 |
void MacroAssembler::Push(FloatRegister reg) { |
| 4281 |
MOZ_ASSERT(reg.isFloat(), "simd128 not supported"); |
| 4282 |
VFPRegister r = VFPRegister(reg); |
| 4283 |
ma_vpush(VFPRegister(reg)); |
| 4284 |
adjustFrame(r.size()); |
| 4285 |
} |
| 4286 |
|
| 4287 |
void MacroAssembler::PushBoxed(FloatRegister reg) { |
| 4288 |
MOZ_ASSERT(reg.isDouble()); |
| 4289 |
Push(reg); |
| 4290 |
} |
| 4291 |
|
| 4292 |
void MacroAssembler::Pop(Register reg) { |
| 4293 |
ma_pop(reg); |
| 4294 |
adjustFrame(-sizeof(intptr_t)); |
| 4295 |
} |
| 4296 |
|
| 4297 |
void MacroAssembler::Pop(FloatRegister reg) { |
| 4298 |
MOZ_ASSERT(reg.isFloat(), "simd128 not supported"); |
| 4299 |
ma_vpop(reg); |
| 4300 |
adjustFrame(-reg.size()); |
| 4301 |
} |
| 4302 |
|
| 4303 |
void MacroAssembler::Pop(const ValueOperand& val) { |
| 4304 |
popValue(val); |
| 4305 |
adjustFrame(-sizeof(Value)); |
| 4306 |
} |
| 4307 |
|
| 4308 |
void MacroAssembler::PopStackPtr() { |
| 4309 |
as_dtr(IsLoad, 32, Offset, sp, DTRAddr(sp, DtrOffImm(0))); |
| 4310 |
adjustFrame(-sizeof(intptr_t)); |
| 4311 |
} |
| 4312 |
|
| 4313 |
void MacroAssembler::freeStackTo(uint32_t framePushed) { |
| 4314 |
MOZ_ASSERT(framePushed <= framePushed_); |
| 4315 |
ScratchRegisterScope scratch(*this); |
| 4316 |
ma_sub(FramePointer, Imm32(int32_t(framePushed)), sp, scratch, LeaveCC, |
| 4317 |
Always); |
| 4318 |
framePushed_ = framePushed; |
| 4319 |
} |
| 4320 |
|
| 4321 |
// =============================================================== |
| 4322 |
// Simple call functions. |
| 4323 |
|
| 4324 |
CodeOffset MacroAssembler::call(Register reg) { |
| 4325 |
as_blx(reg); |
| 4326 |
return CodeOffset(currentOffset()); |
| 4327 |
} |
| 4328 |
|
| 4329 |
CodeOffset MacroAssembler::call(Label* label) { |
| 4330 |
// For now, assume that it'll be nearby. |
| 4331 |
as_bl(label, Always); |
| 4332 |
return CodeOffset(currentOffset()); |
| 4333 |
} |
| 4334 |
|
| 4335 |
void MacroAssembler::call(ImmWord imm) { call(ImmPtr((void*)imm.value)); } |
| 4336 |
|
| 4337 |
void MacroAssembler::call(ImmPtr imm) { |
| 4338 |
BufferOffset bo = m_buffer.nextOffset(); |
| 4339 |
addPendingJump(bo, imm, RelocationKind::HARDCODED); |
| 4340 |
ma_call(imm); |
| 4341 |
} |
| 4342 |
|
| 4343 |
CodeOffset MacroAssembler::call(wasm::SymbolicAddress imm) { |
| 4344 |
movePtr(imm, CallReg); |
| 4345 |
return call(CallReg); |
| 4346 |
} |
| 4347 |
|
| 4348 |
void MacroAssembler::call(const Address& addr) { |
| 4349 |
loadPtr(addr, CallReg); |
| 4350 |
call(CallReg); |
| 4351 |
} |
| 4352 |
|
| 4353 |
void MacroAssembler::call(JitCode* c) { |
| 4354 |
BufferOffset bo = m_buffer.nextOffset(); |
| 4355 |
addPendingJump(bo, ImmPtr(c->raw()), RelocationKind::JITCODE); |
| 4356 |
ScratchRegisterScope scratch(*this); |
| 4357 |
ma_movPatchable(ImmPtr(c->raw()), scratch, Always); |
| 4358 |
callJitNoProfiler(scratch); |
| 4359 |
} |
| 4360 |
|
| 4361 |
CodeOffset MacroAssembler::callWithPatch() { |
| 4362 |
// The caller ensures that the call is always in range using thunks (below) |
| 4363 |
// as necessary. |
| 4364 |
as_bl(BOffImm(), Always, /* documentation */ nullptr); |
| 4365 |
return CodeOffset(currentOffset()); |
| 4366 |
} |
| 4367 |
|
| 4368 |
void MacroAssembler::patchCall(uint32_t callerOffset, uint32_t calleeOffset) { |
| 4369 |
BufferOffset inst(callerOffset - 4); |
| 4370 |
BOffImm off = BufferOffset(calleeOffset).diffB<BOffImm>(inst); |
| 4371 |
MOZ_RELEASE_ASSERT(!off.isInvalid(), |
| 4372 |
"Failed to insert necessary far jump islands"); |
| 4373 |
as_bl(off, Always, inst); |
| 4374 |
} |
| 4375 |
|
| 4376 |
CodeOffset MacroAssembler::farJumpWithPatch() { |
| 4377 |
static_assert(32 * 1024 * 1024 - JumpImmediateRange > |
| 4378 |
wasm::MaxFuncs * 3 * sizeof(Instruction), |
| 4379 |
"always enough space for thunks"); |
| 4380 |
|
| 4381 |
// The goal of the thunk is to be able to jump to any address without the |
| 4382 |
// usual 32MiB branch range limitation. Additionally, to make the thunk |
| 4383 |
// simple to use, the thunk does not use the constant pool or require |
| 4384 |
// patching an absolute address. Instead, a relative offset is used which |
| 4385 |
// can be patched during compilation. |
| 4386 |
|
| 4387 |
// Inhibit pools since these three words must be contiguous so that the offset |
| 4388 |
// calculations below are valid. |
| 4389 |
AutoForbidPoolsAndNops afp(this, 3); |
| 4390 |
|
| 4391 |
// When pc is used, the read value is the address of the instruction + 8. |
| 4392 |
// This is exactly the address of the uint32 word we want to load. |
| 4393 |
ScratchRegisterScope scratch(*this); |
| 4394 |
ma_ldr(DTRAddr(pc, DtrOffImm(0)), scratch); |
| 4395 |
|
| 4396 |
// Branch by making pc the destination register. |
| 4397 |
ma_add(pc, scratch, pc, LeaveCC, Always); |
| 4398 |
|
| 4399 |
// Allocate space which will be patched by patchFarJump(). |
| 4400 |
CodeOffset farJump(currentOffset()); |
| 4401 |
writeInst(UINT32_MAX); |
| 4402 |
|
| 4403 |
return farJump; |
| 4404 |
} |
| 4405 |
|
| 4406 |
void MacroAssembler::patchFarJump(CodeOffset farJump, uint32_t targetOffset) { |
| 4407 |
uint32_t* u32 = |
| 4408 |
reinterpret_cast<uint32_t*>(editSrc(BufferOffset(farJump.offset()))); |
| 4409 |
MOZ_ASSERT(*u32 == UINT32_MAX); |
| 4410 |
|
| 4411 |
uint32_t addOffset = farJump.offset() - 4; |
| 4412 |
MOZ_ASSERT(editSrc(BufferOffset(addOffset))->is<InstALU>()); |
| 4413 |
|
| 4414 |
// When pc is read as the operand of the add, its value is the address of |
| 4415 |
// the add instruction + 8. |
| 4416 |
*u32 = (targetOffset - addOffset) - 8; |
| 4417 |
} |
| 4418 |
|
| 4419 |
void MacroAssembler::patchFarJump(uint8_t* farJump, uint8_t* target) { |
| 4420 |
uint32_t* u32 = reinterpret_cast<uint32_t*>(farJump); |
| 4421 |
MOZ_ASSERT(*u32 == UINT32_MAX); |
| 4422 |
|
| 4423 |
uint8_t* addPtr = reinterpret_cast<uint8_t*>(u32) - 4; |
| 4424 |
MOZ_ASSERT(reinterpret_cast<Instruction*>(addPtr)->is<InstALU>()); |
| 4425 |
|
| 4426 |
int32_t distance = target - addPtr; |
| 4427 |
MOZ_RELEASE_ASSERT(mozilla::Abs(distance) <= |
| 4428 |
(intptr_t)jit::MaxCodeBytesPerProcess); |
| 4429 |
|
| 4430 |
// When pc is read as the operand of the add, its value is the address of |
| 4431 |
// the add instruction + 8. |
| 4432 |
*u32 = distance - 8; |
| 4433 |
} |
| 4434 |
|
| 4435 |
CodeOffset MacroAssembler::nopPatchableToCall() { |
| 4436 |
AutoForbidPoolsAndNops afp(this, |
| 4437 |
/* max number of instructions in scope = */ 1); |
| 4438 |
ma_nop(); |
| 4439 |
return CodeOffset(currentOffset()); |
| 4440 |
} |
| 4441 |
|
| 4442 |
void MacroAssembler::patchNopToCall(uint8_t* call, uint8_t* target) { |
| 4443 |
uint8_t* inst = call - 4; |
| 4444 |
MOZ_ASSERT(reinterpret_cast<Instruction*>(inst)->is<InstBLImm>() || |
| 4445 |
reinterpret_cast<Instruction*>(inst)->is<InstNOP>()); |
| 4446 |
|
| 4447 |
new (inst) InstBLImm(BOffImm(target - inst), Assembler::Always); |
| 4448 |
} |
| 4449 |
|
| 4450 |
void MacroAssembler::patchCallToNop(uint8_t* call) { |
| 4451 |
uint8_t* inst = call - 4; |
| 4452 |
MOZ_ASSERT(reinterpret_cast<Instruction*>(inst)->is<InstBLImm>() || |
| 4453 |
reinterpret_cast<Instruction*>(inst)->is<InstNOP>()); |
| 4454 |
new (inst) InstNOP(); |
| 4455 |
} |
| 4456 |
|
| 4457 |
CodeOffset MacroAssembler::move32WithPatch(Register dest) { |
| 4458 |
return movWithPatch(ImmWord(uintptr_t(-1)), dest); |
| 4459 |
} |
| 4460 |
|
| 4461 |
void MacroAssembler::patchMove32(CodeOffset offset, Imm32 n) { |
| 4462 |
Register dest; |
| 4463 |
Assembler::RelocStyle rs; |
| 4464 |
|
| 4465 |
{ |
| 4466 |
BufferInstructionIterator iter(BufferOffset(offset.offset()), &m_buffer); |
| 4467 |
DebugOnly<const uint32_t*> val = GetPtr32Target(iter, &dest, &rs); |
| 4468 |
MOZ_ASSERT(uint32_t((const uint32_t*)val) == uint32_t(-1)); |
| 4469 |
} |
| 4470 |
|
| 4471 |
// Patch over actual instructions. |
| 4472 |
{ |
| 4473 |
BufferInstructionIterator iter(BufferOffset(offset.offset()), &m_buffer); |
| 4474 |
MacroAssembler::ma_mov_patch(n, dest, Always, rs, iter); |
| 4475 |
} |
| 4476 |
} |
| 4477 |
|
| 4478 |
void MacroAssembler::pushReturnAddress() { push(lr); } |
| 4479 |
|
| 4480 |
void MacroAssembler::popReturnAddress() { pop(lr); } |
| 4481 |
|
| 4482 |
// =============================================================== |
| 4483 |
// ABI function calls. |
| 4484 |
|
| 4485 |
void MacroAssembler::setupUnalignedABICall(Register scratch) { |
| 4486 |
setupNativeABICall(); |
| 4487 |
dynamicAlignment_ = true; |
| 4488 |
|
| 4489 |
ma_mov(sp, scratch); |
| 4490 |
// Force sp to be aligned. |
| 4491 |
as_bic(sp, sp, Imm8(ABIStackAlignment - 1)); |
| 4492 |
ma_push(scratch); |
| 4493 |
} |
| 4494 |
|
| 4495 |
void MacroAssembler::callWithABIPre(uint32_t* stackAdjust, bool callFromWasm) { |
| 4496 |
MOZ_ASSERT(inCall_); |
| 4497 |
uint32_t stackForCall = abiArgs_.stackBytesConsumedSoFar(); |
| 4498 |
|
| 4499 |
if (dynamicAlignment_) { |
| 4500 |
// sizeof(intptr_t) accounts for the saved stack pointer pushed by |
| 4501 |
// setupUnalignedABICall. |
| 4502 |
stackForCall += ComputeByteAlignment(stackForCall + sizeof(intptr_t), |
| 4503 |
ABIStackAlignment); |
| 4504 |
} else { |
| 4505 |
uint32_t alignmentAtPrologue = callFromWasm ? sizeof(wasm::Frame) : 0; |
| 4506 |
stackForCall += ComputeByteAlignment( |
| 4507 |
stackForCall + framePushed() + alignmentAtPrologue, ABIStackAlignment); |
| 4508 |
} |
| 4509 |
|
| 4510 |
*stackAdjust = stackForCall; |
| 4511 |
reserveStack(stackForCall); |
| 4512 |
|
| 4513 |
// Position all arguments. |
| 4514 |
{ |
| 4515 |
enoughMemory_ &= moveResolver_.resolve(); |
| 4516 |
if (!enoughMemory_) { |
| 4517 |
return; |
| 4518 |
} |
| 4519 |
|
| 4520 |
MoveEmitter emitter(*this); |
| 4521 |
emitter.emit(moveResolver_); |
| 4522 |
emitter.finish(); |
| 4523 |
} |
| 4524 |
|
| 4525 |
assertStackAlignment(ABIStackAlignment); |
| 4526 |
|
| 4527 |
// Save the lr register if we need to preserve it. |
| 4528 |
if (secondScratchReg_ != lr) { |
| 4529 |
ma_mov(lr, secondScratchReg_); |
| 4530 |
} |
| 4531 |
} |
| 4532 |
|
| 4533 |
void MacroAssembler::callWithABIPost(uint32_t stackAdjust, ABIType result, |
| 4534 |
bool callFromWasm) { |
| 4535 |
if (secondScratchReg_ != lr) { |
| 4536 |
ma_mov(secondScratchReg_, lr); |
| 4537 |
} |
| 4538 |
|
| 4539 |
// Calls to native functions in wasm pass through a thunk which already |
| 4540 |
// fixes up the return value for us. |
| 4541 |
if (!callFromWasm && !ARMFlags::UseHardFpABI()) { |
| 4542 |
switch (result) { |
| 4543 |
case ABIType::Float64: |
| 4544 |
// Move double from r0/r1 to ReturnFloatReg. |
| 4545 |
ma_vxfer(r0, r1, ReturnDoubleReg); |
| 4546 |
break; |
| 4547 |
case ABIType::Float32: |
| 4548 |
// Move float32 from r0 to ReturnFloatReg. |
| 4549 |
ma_vxfer(r0, ReturnFloat32Reg); |
| 4550 |
break; |
| 4551 |
case ABIType::General: |
| 4552 |
case ABIType::Int64: |
| 4553 |
break; |
| 4554 |
default: |
| 4555 |
MOZ_CRASH("unexpected callWithABI result"); |
| 4556 |
} |
| 4557 |
} |
| 4558 |
|
| 4559 |
freeStack(stackAdjust); |
| 4560 |
|
| 4561 |
if (dynamicAlignment_) { |
| 4562 |
// While the x86 supports pop esp, on ARM that isn't well defined, so |
| 4563 |
// just do it manually. |
| 4564 |
as_dtr(IsLoad, 32, Offset, sp, DTRAddr(sp, DtrOffImm(0))); |
| 4565 |
} |
| 4566 |
|
| 4567 |
#ifdef DEBUG |
| 4568 |
MOZ_ASSERT(inCall_); |
| 4569 |
inCall_ = false; |
| 4570 |
#endif |
| 4571 |
} |
| 4572 |
|
| 4573 |
void MacroAssembler::callWithABINoProfiler(Register fun, ABIType result) { |
| 4574 |
// Load the callee in r12, as above. |
| 4575 |
ma_mov(fun, r12); |
| 4576 |
uint32_t stackAdjust; |
| 4577 |
callWithABIPre(&stackAdjust); |
| 4578 |
call(r12); |
| 4579 |
callWithABIPost(stackAdjust, result); |
| 4580 |
} |
| 4581 |
|
| 4582 |
void MacroAssembler::callWithABINoProfiler(const Address& fun, ABIType result) { |
| 4583 |
// Load the callee in r12, no instruction between the ldr and call should |
| 4584 |
// clobber it. Note that we can't use fun.base because it may be one of the |
| 4585 |
// IntArg registers clobbered before the call. |
| 4586 |
{ |
| 4587 |
ScratchRegisterScope scratch(*this); |
| 4588 |
ma_ldr(fun, r12, scratch); |
| 4589 |
} |
| 4590 |
uint32_t stackAdjust; |
| 4591 |
callWithABIPre(&stackAdjust); |
| 4592 |
call(r12); |
| 4593 |
callWithABIPost(stackAdjust, result); |
| 4594 |
} |
| 4595 |
|
| 4596 |
// =============================================================== |
| 4597 |
// Jit Frames. |
| 4598 |
|
| 4599 |
uint32_t MacroAssembler::pushFakeReturnAddress(Register scratch) { |
| 4600 |
// On ARM any references to the pc, adds an additional 8 to it, which |
| 4601 |
// correspond to 2 instructions of 4 bytes. Thus we use an additional nop |
| 4602 |
// to pad until we reach the pushed pc. |
| 4603 |
// |
| 4604 |
// Note: In practice this should not be necessary, as this fake return |
| 4605 |
// address is never used for resuming any execution. Thus theoriticaly we |
| 4606 |
// could just do a Push(pc), and ignore the nop as well as the pool. |
| 4607 |
enterNoPool(2); |
| 4608 |
DebugOnly<uint32_t> offsetBeforePush = currentOffset(); |
| 4609 |
Push(pc); // actually pushes $pc + 8. |
| 4610 |
ma_nop(); |
| 4611 |
uint32_t pseudoReturnOffset = currentOffset(); |
| 4612 |
leaveNoPool(); |
| 4613 |
|
| 4614 |
MOZ_ASSERT_IF(!oom(), pseudoReturnOffset - offsetBeforePush == 8); |
| 4615 |
return pseudoReturnOffset; |
| 4616 |
} |
| 4617 |
|
| 4618 |
void MacroAssembler::enterFakeExitFrameForWasm(Register cxreg, Register scratch, |
| 4619 |
ExitFrameType type) { |
| 4620 |
enterFakeExitFrame(cxreg, scratch, type); |
| 4621 |
} |
| 4622 |
|
| 4623 |
CodeOffset MacroAssembler::sub32FromMemAndBranchIfNegativeWithPatch( |
| 4624 |
Address address, Label* label) { |
| 4625 |
ScratchRegisterScope value32(*this); |
| 4626 |
SecondScratchRegisterScope scratch(*this); |
| 4627 |
MOZ_ASSERT(scratch != address.base); |
| 4628 |
ma_ldr(address, value32, scratch); |
| 4629 |
// -128 is arbitrary, but makes `*address` count upwards, which may help |
| 4630 |
// to identify cases where the subsequent ::patch..() call was forgotten. |
| 4631 |
ma_sub(Imm32(-128), value32, scratch, SetCC); |
| 4632 |
// Points immediately after the insn to patch |
| 4633 |
CodeOffset patchPoint = CodeOffset(currentOffset()); |
| 4634 |
// This assumes that ma_str does not change the condition codes. |
| 4635 |
ma_str(value32, address, scratch); |
| 4636 |
ma_b(label, Assembler::Signed); |
| 4637 |
return patchPoint; |
| 4638 |
} |
| 4639 |
|
| 4640 |
void MacroAssembler::patchSub32FromMemAndBranchIfNegative(CodeOffset offset, |
| 4641 |
Imm32 imm) { |
| 4642 |
int32_t val = imm.value; |
| 4643 |
// Patching it to zero would make the insn pointless |
| 4644 |
MOZ_RELEASE_ASSERT(val >= 1 && val <= 127); |
| 4645 |
BufferInstructionIterator iter(BufferOffset(offset.offset() - 4), &m_buffer); |
| 4646 |
uint32_t* instrPtr = const_cast<uint32_t*>(iter.cur()->raw()); |
| 4647 |
// 31 27 23 19 15 11 |
| 4648 |
// | | | | | | |
| 4649 |
// 1110 0010 1001 Rn Rd imm12 = ADDS Rd, Rn, #imm12 // (expected) |
| 4650 |
// 1110 0010 0101 Rn Rd imm12 = SUBS Rd, Rn, #imm12 // (replacement) |
| 4651 |
uint32_t oldInstr = *instrPtr; |
| 4652 |
// Check opcode bits and imm field are as expected |
| 4653 |
MOZ_ASSERT((oldInstr >> 20) == 0b1110'0010'1001U); |
| 4654 |
MOZ_ASSERT((oldInstr & 0xFFF) == 128); // as created above |
| 4655 |
uint32_t newInstr = (0b1110'0010'0101U << 20) | // opcode bits |
| 4656 |
(oldInstr & 0x000FF000U) | // existing register fields |
| 4657 |
(val & 0xFFF); // #val |
| 4658 |
*instrPtr = newInstr; |
| 4659 |
} |
| 4660 |
|
| 4661 |
// =============================================================== |
| 4662 |
// Move instructions |
| 4663 |
|
| 4664 |
void MacroAssembler::moveValue(const ValueOperand& src, |
| 4665 |
const ValueOperand& dest) { |
| 4666 |
Register s0 = src.typeReg(); |
| 4667 |
Register s1 = src.payloadReg(); |
| 4668 |
Register d0 = dest.typeReg(); |
| 4669 |
Register d1 = dest.payloadReg(); |
| 4670 |
|
| 4671 |
// Either one or both of the source registers could be the same as a |
| 4672 |
// destination register. |
| 4673 |
if (s1 == d0) { |
| 4674 |
if (s0 == d1) { |
| 4675 |
// If both are, this is just a swap of two registers. |
| 4676 |
ScratchRegisterScope scratch(*this); |
| 4677 |
MOZ_ASSERT(d1 != scratch); |
| 4678 |
MOZ_ASSERT(d0 != scratch); |
| 4679 |
ma_mov(d1, scratch); |
| 4680 |
ma_mov(d0, d1); |
| 4681 |
ma_mov(scratch, d0); |
| 4682 |
return; |
| 4683 |
} |
| 4684 |
// If only one is, copy that source first. |
| 4685 |
std::swap(s0, s1); |
| 4686 |
std::swap(d0, d1); |
| 4687 |
} |
| 4688 |
|
| 4689 |
if (s0 != d0) { |
| 4690 |
ma_mov(s0, d0); |
| 4691 |
} |
| 4692 |
if (s1 != d1) { |
| 4693 |
ma_mov(s1, d1); |
| 4694 |
} |
| 4695 |
} |
| 4696 |
|
| 4697 |
void MacroAssembler::moveValue(const Value& src, const ValueOperand& dest) { |
| 4698 |
ma_mov(Imm32(src.toNunboxTag()), dest.typeReg()); |
| 4699 |
if (src.isGCThing()) { |
| 4700 |
ma_mov(ImmGCPtr(src.toGCThing()), dest.payloadReg()); |
| 4701 |
} else { |
| 4702 |
ma_mov(Imm32(src.toNunboxPayload()), dest.payloadReg()); |
| 4703 |
} |
| 4704 |
} |
| 4705 |
|
| 4706 |
// =============================================================== |
| 4707 |
// Branch functions |
| 4708 |
|
| 4709 |
void MacroAssembler::loadStoreBuffer(Register ptr, Register buffer) { |
| 4710 |
ma_lsr(Imm32(gc::ChunkShift), ptr, buffer); |
| 4711 |
ma_lsl(Imm32(gc::ChunkShift), buffer, buffer); |
| 4712 |
load32(Address(buffer, gc::ChunkStoreBufferOffset), buffer); |
| 4713 |
} |
| 4714 |
|
| 4715 |
void MacroAssembler::branchPtrInNurseryChunk(Condition cond, Register ptr, |
| 4716 |
Register temp, Label* label) { |
| 4717 |
Maybe<SecondScratchRegisterScope> scratch2; |
| 4718 |
if (temp == Register::Invalid()) { |
| 4719 |
scratch2.emplace(*this); |
| 4720 |
temp = scratch2.ref(); |
| 4721 |
} |
| 4722 |
|
| 4723 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 4724 |
MOZ_ASSERT(ptr != temp); |
| 4725 |
|
| 4726 |
ma_lsr(Imm32(gc::ChunkShift), ptr, temp); |
| 4727 |
ma_lsl(Imm32(gc::ChunkShift), temp, temp); |
| 4728 |
loadPtr(Address(temp, gc::ChunkStoreBufferOffset), temp); |
| 4729 |
branchPtr(InvertCondition(cond), temp, ImmWord(0), label); |
| 4730 |
} |
| 4731 |
|
| 4732 |
void MacroAssembler::branchValueIsNurseryCell(Condition cond, |
| 4733 |
const Address& address, |
| 4734 |
Register temp, Label* label) { |
| 4735 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 4736 |
|
| 4737 |
Label done; |
| 4738 |
|
| 4739 |
branchTestGCThing(Assembler::NotEqual, address, |
| 4740 |
cond == Assembler::Equal ? &done : label); |
| 4741 |
|
| 4742 |
loadPtr(ToPayload(address), temp); |
| 4743 |
SecondScratchRegisterScope scratch2(*this); |
| 4744 |
branchPtrInNurseryChunk(cond, temp, scratch2, label); |
| 4745 |
|
| 4746 |
bind(&done); |
| 4747 |
} |
| 4748 |
|
| 4749 |
void MacroAssembler::branchValueIsNurseryCell(Condition cond, |
| 4750 |
ValueOperand value, Register temp, |
| 4751 |
Label* label) { |
| 4752 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 4753 |
|
| 4754 |
Label done; |
| 4755 |
|
| 4756 |
branchTestGCThing(Assembler::NotEqual, value, |
| 4757 |
cond == Assembler::Equal ? &done : label); |
| 4758 |
branchPtrInNurseryChunk(cond, value.payloadReg(), temp, label); |
| 4759 |
|
| 4760 |
bind(&done); |
| 4761 |
} |
| 4762 |
|
| 4763 |
void MacroAssembler::branchTestValue(Condition cond, const ValueOperand& lhs, |
| 4764 |
const Value& rhs, Label* label) { |
| 4765 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 4766 |
MOZ_ASSERT(!rhs.isNaN()); |
| 4767 |
// If cond == NotEqual, branch when a.payload != b.payload || a.tag != |
| 4768 |
// b.tag. If the payloads are equal, compare the tags. If the payloads are |
| 4769 |
// not equal, short circuit true (NotEqual). |
| 4770 |
// |
| 4771 |
// If cand == Equal, branch when a.payload == b.payload && a.tag == b.tag. |
| 4772 |
// If the payloads are equal, compare the tags. If the payloads are not |
| 4773 |
// equal, short circuit false (NotEqual). |
| 4774 |
ScratchRegisterScope scratch(*this); |
| 4775 |
|
| 4776 |
if (rhs.isGCThing()) { |
| 4777 |
ma_cmp(lhs.payloadReg(), ImmGCPtr(rhs.toGCThing()), scratch); |
| 4778 |
} else { |
| 4779 |
ma_cmp(lhs.payloadReg(), Imm32(rhs.toNunboxPayload()), scratch); |
| 4780 |
} |
| 4781 |
ma_cmp(lhs.typeReg(), Imm32(rhs.toNunboxTag()), scratch, Equal); |
| 4782 |
ma_b(label, cond); |
| 4783 |
} |
| 4784 |
|
| 4785 |
void MacroAssembler::branchTestNaNValue(Condition cond, const ValueOperand& val, |
| 4786 |
Register temp, Label* label) { |
| 4787 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 4788 |
ScratchRegisterScope scratch(*this); |
| 4789 |
|
| 4790 |
// When testing for NaN, we want to ignore the sign bit. |
| 4791 |
static_assert(JS::detail::CanonicalizedNaNSignBit == 0); |
| 4792 |
const uint32_t SignBit = mozilla::FloatingPoint<double>::kSignBit >> 32; |
| 4793 |
as_bic(temp, val.typeReg(), Imm8(SignBit)); |
| 4794 |
|
| 4795 |
Value expected = DoubleValue(JS::GenericNaN()); |
| 4796 |
ma_cmp(val.payloadReg(), Imm32(expected.toNunboxPayload()), scratch); |
| 4797 |
ma_cmp(temp, Imm32(expected.toNunboxTag()), scratch, Equal); |
| 4798 |
ma_b(label, cond); |
| 4799 |
} |
| 4800 |
|
| 4801 |
// ======================================================================== |
| 4802 |
// Memory access primitives. |
| 4803 |
template <typename T> |
| 4804 |
void MacroAssembler::storeUnboxedValue(const ConstantOrRegister& value, |
| 4805 |
MIRType valueType, const T& dest) { |
| 4806 |
MOZ_ASSERT(valueType < MIRType::Value); |
| 4807 |
|
| 4808 |
if (valueType == MIRType::Double) { |
| 4809 |
storeDouble(value.reg().typedReg().fpu(), dest); |
| 4810 |
return; |
| 4811 |
} |
| 4812 |
|
| 4813 |
// Store the type tag. |
| 4814 |
storeTypeTag(ImmType(ValueTypeFromMIRType(valueType)), dest); |
| 4815 |
|
| 4816 |
// Store the payload. |
| 4817 |
if (value.constant()) { |
| 4818 |
storePayload(value.value(), dest); |
| 4819 |
} else { |
| 4820 |
storePayload(value.reg().typedReg().gpr(), dest); |
| 4821 |
} |
| 4822 |
} |
| 4823 |
|
| 4824 |
template void MacroAssembler::storeUnboxedValue(const ConstantOrRegister& value, |
| 4825 |
MIRType valueType, |
| 4826 |
const Address& dest); |
| 4827 |
template void MacroAssembler::storeUnboxedValue( |
| 4828 |
const ConstantOrRegister& value, MIRType valueType, |
| 4829 |
const BaseObjectElementIndex& dest); |
| 4830 |
|
| 4831 |
FaultingCodeOffset MacroAssembler::wasmTrapInstruction() { |
| 4832 |
return FaultingCodeOffset(as_illegal_trap().getOffset()); |
| 4833 |
} |
| 4834 |
|
| 4835 |
void MacroAssembler::wasmBoundsCheck32(Condition cond, Register index, |
| 4836 |
Register boundsCheckLimit, Label* ok) { |
| 4837 |
as_cmp(index, O2Reg(boundsCheckLimit)); |
| 4838 |
as_b(ok, cond); |
| 4839 |
if (JitOptions.spectreIndexMasking) { |
| 4840 |
ma_mov(boundsCheckLimit, index, LeaveCC, cond); |
| 4841 |
} |
| 4842 |
} |
| 4843 |
|
| 4844 |
void MacroAssembler::wasmBoundsCheck32(Condition cond, Register index, |
| 4845 |
Address boundsCheckLimit, Label* ok) { |
| 4846 |
ScratchRegisterScope scratch(*this); |
| 4847 |
// We want to do a word load from |
| 4848 |
// [boundsCheckLimit.base, #+boundsCheckLimit.offset], |
| 4849 |
// but the offset might exceed 4095, so we can't use ma_ldr directly. |
| 4850 |
// ma_dataTransferN will handle this correctly, but needs a scratch reg as |
| 4851 |
// an address temporary for the big-offset case. The scratch reg is also |
| 4852 |
// used in all cases for the loaded value; that's OK. |
| 4853 |
ma_dataTransferN(IsLoad, /*size=*/32, /*IsSigned=*/false, |
| 4854 |
boundsCheckLimit.base, Imm32(boundsCheckLimit.offset), |
| 4855 |
scratch, scratch); |
| 4856 |
as_cmp(index, O2Reg(scratch)); |
| 4857 |
as_b(ok, cond); |
| 4858 |
if (JitOptions.spectreIndexMasking) { |
| 4859 |
ma_mov(scratch, index, LeaveCC, cond); |
| 4860 |
} |
| 4861 |
} |
| 4862 |
|
| 4863 |
void MacroAssembler::wasmBoundsCheck64(Condition cond, Register64 index, |
| 4864 |
Register64 boundsCheckLimit, Label* ok) { |
| 4865 |
MOZ_ASSERT(cond == Assembler::AboveOrEqual || cond == Assembler::Below); |
| 4866 |
Label rejoin; |
| 4867 |
Label* failLabel = cond == Assembler::AboveOrEqual ? ok : &rejoin; |
| 4868 |
cmp32(index.high, Imm32(0)); |
| 4869 |
j(Assembler::NonZero, failLabel); |
| 4870 |
wasmBoundsCheck32(cond, index.low, boundsCheckLimit.low, ok); |
| 4871 |
bind(&rejoin); |
| 4872 |
} |
| 4873 |
|
| 4874 |
void MacroAssembler::wasmBoundsCheck64(Condition cond, Register64 index, |
| 4875 |
Address boundsCheckLimit, Label* ok) { |
| 4876 |
MOZ_ASSERT(cond == Assembler::AboveOrEqual || cond == Assembler::Below); |
| 4877 |
Label rejoin; |
| 4878 |
Label* failLabel = cond == Assembler::AboveOrEqual ? ok : &rejoin; |
| 4879 |
cmp32(index.high, Imm32(0)); |
| 4880 |
j(Assembler::NonZero, failLabel); |
| 4881 |
wasmBoundsCheck32(cond, index.low, boundsCheckLimit, ok); |
| 4882 |
bind(&rejoin); |
| 4883 |
} |
| 4884 |
|
| 4885 |
void MacroAssembler::wasmTruncateDoubleToUInt32(FloatRegister input, |
| 4886 |
Register output, |
| 4887 |
bool isSaturating, |
| 4888 |
Label* oolEntry) { |
| 4889 |
wasmTruncateToInt32(input, output, MIRType::Double, /* isUnsigned= */ true, |
| 4890 |
isSaturating, oolEntry); |
| 4891 |
} |
| 4892 |
|
| 4893 |
void MacroAssembler::wasmTruncateDoubleToInt32(FloatRegister input, |
| 4894 |
Register output, |
| 4895 |
bool isSaturating, |
| 4896 |
Label* oolEntry) { |
| 4897 |
wasmTruncateToInt32(input, output, MIRType::Double, /* isUnsigned= */ false, |
| 4898 |
isSaturating, oolEntry); |
| 4899 |
} |
| 4900 |
|
| 4901 |
void MacroAssembler::wasmTruncateFloat32ToUInt32(FloatRegister input, |
| 4902 |
Register output, |
| 4903 |
bool isSaturating, |
| 4904 |
Label* oolEntry) { |
| 4905 |
wasmTruncateToInt32(input, output, MIRType::Float32, /* isUnsigned= */ true, |
| 4906 |
isSaturating, oolEntry); |
| 4907 |
} |
| 4908 |
|
| 4909 |
void MacroAssembler::wasmTruncateFloat32ToInt32(FloatRegister input, |
| 4910 |
Register output, |
| 4911 |
bool isSaturating, |
| 4912 |
Label* oolEntry) { |
| 4913 |
wasmTruncateToInt32(input, output, MIRType::Float32, /* isUnsigned= */ false, |
| 4914 |
isSaturating, oolEntry); |
| 4915 |
} |
| 4916 |
|
| 4917 |
void MacroAssembler::oolWasmTruncateCheckF32ToI32( |
| 4918 |
FloatRegister input, Register output, TruncFlags flags, |
| 4919 |
const wasm::TrapSiteDesc& trapSiteDesc, Label* rejoin) { |
| 4920 |
outOfLineWasmTruncateToIntCheck(input, MIRType::Float32, MIRType::Int32, |
| 4921 |
flags, rejoin, trapSiteDesc); |
| 4922 |
} |
| 4923 |
|
| 4924 |
void MacroAssembler::oolWasmTruncateCheckF64ToI32( |
| 4925 |
FloatRegister input, Register output, TruncFlags flags, |
| 4926 |
const wasm::TrapSiteDesc& trapSiteDesc, Label* rejoin) { |
| 4927 |
outOfLineWasmTruncateToIntCheck(input, MIRType::Double, MIRType::Int32, flags, |
| 4928 |
rejoin, trapSiteDesc); |
| 4929 |
} |
| 4930 |
|
| 4931 |
void MacroAssembler::oolWasmTruncateCheckF32ToI64( |
| 4932 |
FloatRegister input, Register64 output, TruncFlags flags, |
| 4933 |
const wasm::TrapSiteDesc& trapSiteDesc, Label* rejoin) { |
| 4934 |
outOfLineWasmTruncateToIntCheck(input, MIRType::Float32, MIRType::Int64, |
| 4935 |
flags, rejoin, trapSiteDesc); |
| 4936 |
} |
| 4937 |
|
| 4938 |
void MacroAssembler::oolWasmTruncateCheckF64ToI64( |
| 4939 |
FloatRegister input, Register64 output, TruncFlags flags, |
| 4940 |
const wasm::TrapSiteDesc& trapSiteDesc, Label* rejoin) { |
| 4941 |
outOfLineWasmTruncateToIntCheck(input, MIRType::Double, MIRType::Int64, flags, |
| 4942 |
rejoin, trapSiteDesc); |
| 4943 |
} |
| 4944 |
|
| 4945 |
void MacroAssembler::wasmLoad(const wasm::MemoryAccessDesc& access, |
| 4946 |
Register memoryBase, Register ptr, |
| 4947 |
Register ptrScratch, AnyRegister output) { |
| 4948 |
wasmLoadImpl(access, memoryBase, ptr, ptrScratch, output, |
| 4949 |
Register64::Invalid()); |
| 4950 |
} |
| 4951 |
|
| 4952 |
void MacroAssembler::wasmLoadI64(const wasm::MemoryAccessDesc& access, |
| 4953 |
Register memoryBase, Register ptr, |
| 4954 |
Register ptrScratch, Register64 output) { |
| 4955 |
MOZ_ASSERT_IF(access.isAtomic(), access.byteSize() <= 4); |
| 4956 |
wasmLoadImpl(access, memoryBase, ptr, ptrScratch, AnyRegister(), output); |
| 4957 |
} |
| 4958 |
|
| 4959 |
void MacroAssembler::wasmStore(const wasm::MemoryAccessDesc& access, |
| 4960 |
AnyRegister value, Register memoryBase, |
| 4961 |
Register ptr, Register ptrScratch) { |
| 4962 |
wasmStoreImpl(access, value, Register64::Invalid(), memoryBase, ptr, |
| 4963 |
ptrScratch); |
| 4964 |
} |
| 4965 |
|
| 4966 |
void MacroAssembler::wasmStoreI64(const wasm::MemoryAccessDesc& access, |
| 4967 |
Register64 value, Register memoryBase, |
| 4968 |
Register ptr, Register ptrScratch) { |
| 4969 |
MOZ_ASSERT(!access.isAtomic()); |
| 4970 |
wasmStoreImpl(access, AnyRegister(), value, memoryBase, ptr, ptrScratch); |
| 4971 |
} |
| 4972 |
|
| 4973 |
// ======================================================================== |
| 4974 |
// Primitive atomic operations. |
| 4975 |
|
| 4976 |
static Register ComputePointerForAtomic(MacroAssembler& masm, |
| 4977 |
const BaseIndex& src, Register r) { |
| 4978 |
Register base = src.base; |
| 4979 |
Register index = src.index; |
| 4980 |
uint32_t scale = Imm32::ShiftOf(src.scale).value; |
| 4981 |
int32_t offset = src.offset; |
| 4982 |
|
| 4983 |
ScratchRegisterScope scratch(masm); |
| 4984 |
|
| 4985 |
masm.as_add(r, base, lsl(index, scale)); |
| 4986 |
if (offset != 0) { |
| 4987 |
masm.ma_add(r, Imm32(offset), r, scratch); |
| 4988 |
} |
| 4989 |
return r; |
| 4990 |
} |
| 4991 |
|
| 4992 |
static Register ComputePointerForAtomic(MacroAssembler& masm, |
| 4993 |
const Address& src, Register r) { |
| 4994 |
ScratchRegisterScope scratch(masm); |
| 4995 |
if (src.offset == 0) { |
| 4996 |
return src.base; |
| 4997 |
} |
| 4998 |
masm.ma_add(src.base, Imm32(src.offset), r, scratch); |
| 4999 |
return r; |
| 5000 |
} |
| 5001 |
|
| 5002 |
// General algorithm: |
| 5003 |
// |
| 5004 |
// ... ptr, <addr> ; compute address of item |
| 5005 |
// dmb |
| 5006 |
// L0 ldrex* output, [ptr] |
| 5007 |
// sxt* output, output, 0 ; sign-extend if applicable |
| 5008 |
// *xt* tmp, oldval, 0 ; sign-extend or zero-extend if applicable |
| 5009 |
// cmp output, tmp |
| 5010 |
// bne L1 ; failed - values are different |
| 5011 |
// strex* tmp, newval, [ptr] |
| 5012 |
// cmp tmp, 1 |
| 5013 |
// beq L0 ; failed - location is dirty, retry |
| 5014 |
// L1 dmb |
| 5015 |
// |
| 5016 |
// Discussion here: http://www.cl.cam.ac.uk/~pes20/cpp/cpp0xmappings.html. |
| 5017 |
// However note that that discussion uses 'isb' as the trailing fence. |
| 5018 |
// I've not quite figured out why, and I've gone with dmb here which |
| 5019 |
// is safe. Also see the LLVM source, which uses 'dmb ish' generally. |
| 5020 |
// (Apple's Swift CPU apparently handles ish in a non-default, faster |
| 5021 |
// way.) |
| 5022 |
|
| 5023 |
template <typename T> |
| 5024 |
static void CompareExchange(MacroAssembler& masm, |
| 5025 |
const wasm::MemoryAccessDesc* access, |
| 5026 |
Scalar::Type type, Synchronization sync, |
| 5027 |
const T& mem, Register oldval, Register newval, |
| 5028 |
Register output) { |
| 5029 |
bool signExtend = Scalar::isSignedIntType(type); |
| 5030 |
unsigned nbytes = Scalar::byteSize(type); |
| 5031 |
|
| 5032 |
MOZ_ASSERT(nbytes <= 4); |
| 5033 |
|
| 5034 |
Label again; |
| 5035 |
Label done; |
| 5036 |
|
| 5037 |
SecondScratchRegisterScope scratch2(masm); |
| 5038 |
Register ptr = ComputePointerForAtomic(masm, mem, scratch2); |
| 5039 |
|
| 5040 |
ScratchRegisterScope scratch(masm); |
| 5041 |
|
| 5042 |
// NOTE: the generated code must match the assembly code in gen_cmpxchg in |
| 5043 |
// GenerateAtomicOperations.py |
| 5044 |
masm.memoryBarrierBefore(sync); |
| 5045 |
|
| 5046 |
masm.bind(&again); |
| 5047 |
|
| 5048 |
BufferOffset firstAccess; |
| 5049 |
switch (nbytes) { |
| 5050 |
case 1: |
| 5051 |
firstAccess = masm.as_ldrexb(output, ptr); |
| 5052 |
if (signExtend) { |
| 5053 |
masm.as_sxtb(output, output, 0); |
| 5054 |
masm.as_sxtb(scratch, oldval, 0); |
| 5055 |
} else { |
| 5056 |
masm.as_uxtb(scratch, oldval, 0); |
| 5057 |
} |
| 5058 |
break; |
| 5059 |
case 2: |
| 5060 |
firstAccess = masm.as_ldrexh(output, ptr); |
| 5061 |
if (signExtend) { |
| 5062 |
masm.as_sxth(output, output, 0); |
| 5063 |
masm.as_sxth(scratch, oldval, 0); |
| 5064 |
} else { |
| 5065 |
masm.as_uxth(scratch, oldval, 0); |
| 5066 |
} |
| 5067 |
break; |
| 5068 |
case 4: |
| 5069 |
firstAccess = masm.as_ldrex(output, ptr); |
| 5070 |
break; |
| 5071 |
default: |
| 5072 |
MOZ_CRASH(); |
| 5073 |
} |
| 5074 |
if (access) { |
| 5075 |
masm.append(*access, js::wasm::TrapMachineInsnForLoad(nbytes), |
| 5076 |
FaultingCodeOffset(firstAccess.getOffset())); |
| 5077 |
} |
| 5078 |
|
| 5079 |
if (nbytes < 4) { |
| 5080 |
masm.as_cmp(output, O2Reg(scratch)); |
| 5081 |
} else { |
| 5082 |
masm.as_cmp(output, O2Reg(oldval)); |
| 5083 |
} |
| 5084 |
masm.as_b(&done, MacroAssembler::NotEqual); |
| 5085 |
switch (nbytes) { |
| 5086 |
case 1: |
| 5087 |
masm.as_strexb(scratch, newval, ptr); |
| 5088 |
break; |
| 5089 |
case 2: |
| 5090 |
masm.as_strexh(scratch, newval, ptr); |
| 5091 |
break; |
| 5092 |
case 4: |
| 5093 |
masm.as_strex(scratch, newval, ptr); |
| 5094 |
break; |
| 5095 |
default: |
| 5096 |
MOZ_CRASH(); |
| 5097 |
} |
| 5098 |
masm.as_cmp(scratch, Imm8(1)); |
| 5099 |
masm.as_b(&again, MacroAssembler::Equal); |
| 5100 |
masm.bind(&done); |
| 5101 |
|
| 5102 |
masm.memoryBarrierAfter(sync); |
| 5103 |
} |
| 5104 |
|
| 5105 |
void MacroAssembler::compareExchange(Scalar::Type type, Synchronization sync, |
| 5106 |
const Address& address, Register oldval, |
| 5107 |
Register newval, Register output) { |
| 5108 |
CompareExchange(*this, nullptr, type, sync, address, oldval, newval, output); |
| 5109 |
} |
| 5110 |
|
| 5111 |
void MacroAssembler::compareExchange(Scalar::Type type, Synchronization sync, |
| 5112 |
const BaseIndex& address, Register oldval, |
| 5113 |
Register newval, Register output) { |
| 5114 |
CompareExchange(*this, nullptr, type, sync, address, oldval, newval, output); |
| 5115 |
} |
| 5116 |
|
| 5117 |
void MacroAssembler::wasmCompareExchange(const wasm::MemoryAccessDesc& access, |
| 5118 |
const Address& mem, Register oldval, |
| 5119 |
Register newval, Register output) { |
| 5120 |
CompareExchange(*this, &access, access.type(), access.sync(), mem, oldval, |
| 5121 |
newval, output); |
| 5122 |
} |
| 5123 |
|
| 5124 |
void MacroAssembler::wasmCompareExchange(const wasm::MemoryAccessDesc& access, |
| 5125 |
const BaseIndex& mem, Register oldval, |
| 5126 |
Register newval, Register output) { |
| 5127 |
CompareExchange(*this, &access, access.type(), access.sync(), mem, oldval, |
| 5128 |
newval, output); |
| 5129 |
} |
| 5130 |
|
| 5131 |
template <typename T> |
| 5132 |
static void AtomicExchange(MacroAssembler& masm, |
| 5133 |
const wasm::MemoryAccessDesc* access, |
| 5134 |
Scalar::Type type, Synchronization sync, |
| 5135 |
const T& mem, Register value, Register output) { |
| 5136 |
bool signExtend = Scalar::isSignedIntType(type); |
| 5137 |
unsigned nbytes = Scalar::byteSize(type); |
| 5138 |
|
| 5139 |
MOZ_ASSERT(nbytes <= 4); |
| 5140 |
|
| 5141 |
// Bug 1077321: We may further optimize for ARMv8 (AArch32) here. |
| 5142 |
Label again; |
| 5143 |
Label done; |
| 5144 |
|
| 5145 |
SecondScratchRegisterScope scratch2(masm); |
| 5146 |
Register ptr = ComputePointerForAtomic(masm, mem, scratch2); |
| 5147 |
|
| 5148 |
ScratchRegisterScope scratch(masm); |
| 5149 |
|
| 5150 |
// NOTE: the generated code must match the assembly code in gen_exchange in |
| 5151 |
// GenerateAtomicOperations.py |
| 5152 |
masm.memoryBarrierBefore(sync); |
| 5153 |
|
| 5154 |
masm.bind(&again); |
| 5155 |
|
| 5156 |
BufferOffset firstAccess; |
| 5157 |
switch (nbytes) { |
| 5158 |
case 1: |
| 5159 |
firstAccess = masm.as_ldrexb(output, ptr); |
| 5160 |
if (signExtend) { |
| 5161 |
masm.as_sxtb(output, output, 0); |
| 5162 |
} |
| 5163 |
masm.as_strexb(scratch, value, ptr); |
| 5164 |
break; |
| 5165 |
case 2: |
| 5166 |
firstAccess = masm.as_ldrexh(output, ptr); |
| 5167 |
if (signExtend) { |
| 5168 |
masm.as_sxth(output, output, 0); |
| 5169 |
} |
| 5170 |
masm.as_strexh(scratch, value, ptr); |
| 5171 |
break; |
| 5172 |
case 4: |
| 5173 |
firstAccess = masm.as_ldrex(output, ptr); |
| 5174 |
masm.as_strex(scratch, value, ptr); |
| 5175 |
break; |
| 5176 |
default: |
| 5177 |
MOZ_CRASH(); |
| 5178 |
} |
| 5179 |
if (access) { |
| 5180 |
masm.append(*access, js::wasm::TrapMachineInsnForLoad(nbytes), |
| 5181 |
FaultingCodeOffset(firstAccess.getOffset())); |
| 5182 |
} |
| 5183 |
|
| 5184 |
masm.as_cmp(scratch, Imm8(1)); |
| 5185 |
masm.as_b(&again, MacroAssembler::Equal); |
| 5186 |
masm.bind(&done); |
| 5187 |
|
| 5188 |
masm.memoryBarrierAfter(sync); |
| 5189 |
} |
| 5190 |
|
| 5191 |
void MacroAssembler::atomicExchange(Scalar::Type type, Synchronization sync, |
| 5192 |
const Address& address, Register value, |
| 5193 |
Register output) { |
| 5194 |
AtomicExchange(*this, nullptr, type, sync, address, value, output); |
| 5195 |
} |
| 5196 |
|
| 5197 |
void MacroAssembler::atomicExchange(Scalar::Type type, Synchronization sync, |
| 5198 |
const BaseIndex& address, Register value, |
| 5199 |
Register output) { |
| 5200 |
AtomicExchange(*this, nullptr, type, sync, address, value, output); |
| 5201 |
} |
| 5202 |
|
| 5203 |
void MacroAssembler::wasmAtomicExchange(const wasm::MemoryAccessDesc& access, |
| 5204 |
const Address& mem, Register value, |
| 5205 |
Register output) { |
| 5206 |
AtomicExchange(*this, &access, access.type(), access.sync(), mem, value, |
| 5207 |
output); |
| 5208 |
} |
| 5209 |
|
| 5210 |
void MacroAssembler::wasmAtomicExchange(const wasm::MemoryAccessDesc& access, |
| 5211 |
const BaseIndex& mem, Register value, |
| 5212 |
Register output) { |
| 5213 |
AtomicExchange(*this, &access, access.type(), access.sync(), mem, value, |
| 5214 |
output); |
| 5215 |
} |
| 5216 |
|
| 5217 |
// General algorithm: |
| 5218 |
// |
| 5219 |
// ... ptr, <addr> ; compute address of item |
| 5220 |
// dmb |
| 5221 |
// L0 ldrex* output, [ptr] |
| 5222 |
// sxt* output, output, 0 ; sign-extend if applicable |
| 5223 |
// OP tmp, output, value ; compute value to store |
| 5224 |
// strex* tmp2, tmp, [ptr] ; tmp2 required by strex |
| 5225 |
// cmp tmp2, 1 |
| 5226 |
// beq L0 ; failed - location is dirty, retry |
| 5227 |
// dmb ; ordering barrier required |
| 5228 |
// |
| 5229 |
// Also see notes above at compareExchange re the barrier strategy. |
| 5230 |
// |
| 5231 |
// Observe that the value being operated into the memory element need |
| 5232 |
// not be sign-extended because no OP will make use of bits to the |
| 5233 |
// left of the bits indicated by the width of the element, and neither |
| 5234 |
// output nor the bits stored are affected by OP. |
| 5235 |
|
| 5236 |
template <typename T> |
| 5237 |
static void AtomicFetchOp(MacroAssembler& masm, |
| 5238 |
const wasm::MemoryAccessDesc* access, |
| 5239 |
Scalar::Type type, Synchronization sync, AtomicOp op, |
| 5240 |
const Register& value, const T& mem, |
| 5241 |
Register flagTemp, Register output) { |
| 5242 |
bool signExtend = Scalar::isSignedIntType(type); |
| 5243 |
unsigned nbytes = Scalar::byteSize(type); |
| 5244 |
|
| 5245 |
MOZ_ASSERT(nbytes <= 4); |
| 5246 |
MOZ_ASSERT(flagTemp != InvalidReg); |
| 5247 |
MOZ_ASSERT(output != value); |
| 5248 |
|
| 5249 |
Label again; |
| 5250 |
|
| 5251 |
SecondScratchRegisterScope scratch2(masm); |
| 5252 |
Register ptr = ComputePointerForAtomic(masm, mem, scratch2); |
| 5253 |
|
| 5254 |
// NOTE: the generated code must match the assembly code in gen_fetchop in |
| 5255 |
// GenerateAtomicOperations.py |
| 5256 |
masm.memoryBarrierBefore(sync); |
| 5257 |
|
| 5258 |
ScratchRegisterScope scratch(masm); |
| 5259 |
|
| 5260 |
masm.bind(&again); |
| 5261 |
|
| 5262 |
BufferOffset firstAccess; |
| 5263 |
switch (nbytes) { |
| 5264 |
case 1: |
| 5265 |
firstAccess = masm.as_ldrexb(output, ptr); |
| 5266 |
if (signExtend) { |
| 5267 |
masm.as_sxtb(output, output, 0); |
| 5268 |
} |
| 5269 |
break; |
| 5270 |
case 2: |
| 5271 |
firstAccess = masm.as_ldrexh(output, ptr); |
| 5272 |
if (signExtend) { |
| 5273 |
masm.as_sxth(output, output, 0); |
| 5274 |
} |
| 5275 |
break; |
| 5276 |
case 4: |
| 5277 |
firstAccess = masm.as_ldrex(output, ptr); |
| 5278 |
break; |
| 5279 |
default: |
| 5280 |
MOZ_CRASH(); |
| 5281 |
} |
| 5282 |
if (access) { |
| 5283 |
masm.append(*access, js::wasm::TrapMachineInsnForLoad(nbytes), |
| 5284 |
FaultingCodeOffset(firstAccess.getOffset())); |
| 5285 |
} |
| 5286 |
|
| 5287 |
switch (op) { |
| 5288 |
case AtomicOp::Add: |
| 5289 |
masm.as_add(scratch, output, O2Reg(value)); |
| 5290 |
break; |
| 5291 |
case AtomicOp::Sub: |
| 5292 |
masm.as_sub(scratch, output, O2Reg(value)); |
| 5293 |
break; |
| 5294 |
case AtomicOp::And: |
| 5295 |
masm.as_and(scratch, output, O2Reg(value)); |
| 5296 |
break; |
| 5297 |
case AtomicOp::Or: |
| 5298 |
masm.as_orr(scratch, output, O2Reg(value)); |
| 5299 |
break; |
| 5300 |
case AtomicOp::Xor: |
| 5301 |
masm.as_eor(scratch, output, O2Reg(value)); |
| 5302 |
break; |
| 5303 |
default: |
| 5304 |
MOZ_CRASH(); |
| 5305 |
} |
| 5306 |
// Rd must differ from the two other arguments to strex. |
| 5307 |
switch (nbytes) { |
| 5308 |
case 1: |
| 5309 |
masm.as_strexb(flagTemp, scratch, ptr); |
| 5310 |
break; |
| 5311 |
case 2: |
| 5312 |
masm.as_strexh(flagTemp, scratch, ptr); |
| 5313 |
break; |
| 5314 |
case 4: |
| 5315 |
masm.as_strex(flagTemp, scratch, ptr); |
| 5316 |
break; |
| 5317 |
default: |
| 5318 |
MOZ_CRASH(); |
| 5319 |
} |
| 5320 |
masm.as_cmp(flagTemp, Imm8(1)); |
| 5321 |
masm.as_b(&again, MacroAssembler::Equal); |
| 5322 |
|
| 5323 |
masm.memoryBarrierAfter(sync); |
| 5324 |
} |
| 5325 |
|
| 5326 |
void MacroAssembler::atomicFetchOp(Scalar::Type type, Synchronization sync, |
| 5327 |
AtomicOp op, Register value, |
| 5328 |
const Address& mem, Register temp, |
| 5329 |
Register output) { |
| 5330 |
AtomicFetchOp(*this, nullptr, type, sync, op, value, mem, temp, output); |
| 5331 |
} |
| 5332 |
|
| 5333 |
void MacroAssembler::atomicFetchOp(Scalar::Type type, Synchronization sync, |
| 5334 |
AtomicOp op, Register value, |
| 5335 |
const BaseIndex& mem, Register temp, |
| 5336 |
Register output) { |
| 5337 |
AtomicFetchOp(*this, nullptr, type, sync, op, value, mem, temp, output); |
| 5338 |
} |
| 5339 |
|
| 5340 |
void MacroAssembler::wasmAtomicFetchOp(const wasm::MemoryAccessDesc& access, |
| 5341 |
AtomicOp op, Register value, |
| 5342 |
const Address& mem, Register temp, |
| 5343 |
Register output) { |
| 5344 |
AtomicFetchOp(*this, &access, access.type(), access.sync(), op, value, mem, |
| 5345 |
temp, output); |
| 5346 |
} |
| 5347 |
|
| 5348 |
void MacroAssembler::wasmAtomicFetchOp(const wasm::MemoryAccessDesc& access, |
| 5349 |
AtomicOp op, Register value, |
| 5350 |
const BaseIndex& mem, Register temp, |
| 5351 |
Register output) { |
| 5352 |
AtomicFetchOp(*this, &access, access.type(), access.sync(), op, value, mem, |
| 5353 |
temp, output); |
| 5354 |
} |
| 5355 |
|
| 5356 |
// Uses both scratch registers, one for the address and one for a temp, |
| 5357 |
// but needs two temps for strex: |
| 5358 |
// |
| 5359 |
// ... ptr, <addr> ; compute address of item |
| 5360 |
// dmb |
| 5361 |
// L0 ldrex* temp, [ptr] |
| 5362 |
// OP temp, temp, value ; compute value to store |
| 5363 |
// strex* temp2, temp, [ptr] |
| 5364 |
// cmp temp2, 1 |
| 5365 |
// beq L0 ; failed - location is dirty, retry |
| 5366 |
// dmb ; ordering barrier required |
| 5367 |
|
| 5368 |
template <typename T> |
| 5369 |
static void AtomicEffectOp(MacroAssembler& masm, |
| 5370 |
const wasm::MemoryAccessDesc* access, |
| 5371 |
Scalar::Type type, Synchronization sync, AtomicOp op, |
| 5372 |
const Register& value, const T& mem, |
| 5373 |
Register flagTemp) { |
| 5374 |
unsigned nbytes = Scalar::byteSize(type); |
| 5375 |
|
| 5376 |
MOZ_ASSERT(nbytes <= 4); |
| 5377 |
MOZ_ASSERT(flagTemp != InvalidReg); |
| 5378 |
|
| 5379 |
Label again; |
| 5380 |
|
| 5381 |
SecondScratchRegisterScope scratch2(masm); |
| 5382 |
Register ptr = ComputePointerForAtomic(masm, mem, scratch2); |
| 5383 |
|
| 5384 |
masm.memoryBarrierBefore(sync); |
| 5385 |
|
| 5386 |
ScratchRegisterScope scratch(masm); |
| 5387 |
|
| 5388 |
masm.bind(&again); |
| 5389 |
|
| 5390 |
BufferOffset firstAccess; |
| 5391 |
switch (nbytes) { |
| 5392 |
case 1: |
| 5393 |
firstAccess = masm.as_ldrexb(scratch, ptr); |
| 5394 |
break; |
| 5395 |
case 2: |
| 5396 |
firstAccess = masm.as_ldrexh(scratch, ptr); |
| 5397 |
break; |
| 5398 |
case 4: |
| 5399 |
firstAccess = masm.as_ldrex(scratch, ptr); |
| 5400 |
break; |
| 5401 |
default: |
| 5402 |
MOZ_CRASH(); |
| 5403 |
} |
| 5404 |
if (access) { |
| 5405 |
masm.append(*access, js::wasm::TrapMachineInsnForLoad(nbytes), |
| 5406 |
FaultingCodeOffset(firstAccess.getOffset())); |
| 5407 |
} |
| 5408 |
|
| 5409 |
switch (op) { |
| 5410 |
case AtomicOp::Add: |
| 5411 |
masm.as_add(scratch, scratch, O2Reg(value)); |
| 5412 |
break; |
| 5413 |
case AtomicOp::Sub: |
| 5414 |
masm.as_sub(scratch, scratch, O2Reg(value)); |
| 5415 |
break; |
| 5416 |
case AtomicOp::And: |
| 5417 |
masm.as_and(scratch, scratch, O2Reg(value)); |
| 5418 |
break; |
| 5419 |
case AtomicOp::Or: |
| 5420 |
masm.as_orr(scratch, scratch, O2Reg(value)); |
| 5421 |
break; |
| 5422 |
case AtomicOp::Xor: |
| 5423 |
masm.as_eor(scratch, scratch, O2Reg(value)); |
| 5424 |
break; |
| 5425 |
default: |
| 5426 |
MOZ_CRASH(); |
| 5427 |
} |
| 5428 |
// Rd must differ from the two other arguments to strex. |
| 5429 |
switch (nbytes) { |
| 5430 |
case 1: |
| 5431 |
masm.as_strexb(flagTemp, scratch, ptr); |
| 5432 |
break; |
| 5433 |
case 2: |
| 5434 |
masm.as_strexh(flagTemp, scratch, ptr); |
| 5435 |
break; |
| 5436 |
case 4: |
| 5437 |
masm.as_strex(flagTemp, scratch, ptr); |
| 5438 |
break; |
| 5439 |
default: |
| 5440 |
MOZ_CRASH(); |
| 5441 |
} |
| 5442 |
masm.as_cmp(flagTemp, Imm8(1)); |
| 5443 |
masm.as_b(&again, MacroAssembler::Equal); |
| 5444 |
|
| 5445 |
masm.memoryBarrierAfter(sync); |
| 5446 |
} |
| 5447 |
|
| 5448 |
void MacroAssembler::wasmAtomicEffectOp(const wasm::MemoryAccessDesc& access, |
| 5449 |
AtomicOp op, Register value, |
| 5450 |
const Address& mem, Register temp) { |
| 5451 |
AtomicEffectOp(*this, &access, access.type(), access.sync(), op, value, mem, |
| 5452 |
temp); |
| 5453 |
} |
| 5454 |
|
| 5455 |
void MacroAssembler::wasmAtomicEffectOp(const wasm::MemoryAccessDesc& access, |
| 5456 |
AtomicOp op, Register value, |
| 5457 |
const BaseIndex& mem, Register temp) { |
| 5458 |
AtomicEffectOp(*this, &access, access.type(), access.sync(), op, value, mem, |
| 5459 |
temp); |
| 5460 |
} |
| 5461 |
|
| 5462 |
template <typename T> |
| 5463 |
static void AtomicLoad64(MacroAssembler& masm, |
| 5464 |
const wasm::MemoryAccessDesc* access, |
| 5465 |
Synchronization sync, const T& mem, |
| 5466 |
Register64 output) { |
| 5467 |
MOZ_ASSERT((output.low.code() & 1) == 0); |
| 5468 |
MOZ_ASSERT(output.low.code() + 1 == output.high.code()); |
| 5469 |
|
| 5470 |
masm.memoryBarrierBefore(sync); |
| 5471 |
|
| 5472 |
SecondScratchRegisterScope scratch2(masm); |
| 5473 |
Register ptr = ComputePointerForAtomic(masm, mem, scratch2); |
| 5474 |
|
| 5475 |
BufferOffset load = masm.as_ldrexd(output.low, output.high, ptr); |
| 5476 |
if (access) { |
| 5477 |
masm.append(*access, js::wasm::TrapMachineInsn::Load64, |
| 5478 |
FaultingCodeOffset(load.getOffset())); |
| 5479 |
} |
| 5480 |
masm.as_clrex(); |
| 5481 |
|
| 5482 |
masm.memoryBarrierAfter(sync); |
| 5483 |
} |
| 5484 |
|
| 5485 |
template <typename T> |
| 5486 |
static void WasmAtomicLoad64(MacroAssembler& masm, |
| 5487 |
const wasm::MemoryAccessDesc& access, const T& mem, |
| 5488 |
Register64 temp, Register64 output) { |
| 5489 |
MOZ_ASSERT(temp.low == InvalidReg && temp.high == InvalidReg); |
| 5490 |
|
| 5491 |
AtomicLoad64(masm, &access, access.sync(), mem, output); |
| 5492 |
} |
| 5493 |
|
| 5494 |
void MacroAssembler::wasmAtomicLoad64(const wasm::MemoryAccessDesc& access, |
| 5495 |
const Address& mem, Register64 temp, |
| 5496 |
Register64 output) { |
| 5497 |
WasmAtomicLoad64(*this, access, mem, temp, output); |
| 5498 |
} |
| 5499 |
|
| 5500 |
void MacroAssembler::wasmAtomicLoad64(const wasm::MemoryAccessDesc& access, |
| 5501 |
const BaseIndex& mem, Register64 temp, |
| 5502 |
Register64 output) { |
| 5503 |
WasmAtomicLoad64(*this, access, mem, temp, output); |
| 5504 |
} |
| 5505 |
|
| 5506 |
template <typename T> |
| 5507 |
static void CompareExchange64(MacroAssembler& masm, |
| 5508 |
const wasm::MemoryAccessDesc* access, |
| 5509 |
Synchronization sync, const T& mem, |
| 5510 |
Register64 expect, Register64 replace, |
| 5511 |
Register64 output) { |
| 5512 |
MOZ_ASSERT(expect != replace && replace != output && output != expect); |
| 5513 |
|
| 5514 |
MOZ_ASSERT((replace.low.code() & 1) == 0); |
| 5515 |
MOZ_ASSERT(replace.low.code() + 1 == replace.high.code()); |
| 5516 |
|
| 5517 |
MOZ_ASSERT((output.low.code() & 1) == 0); |
| 5518 |
MOZ_ASSERT(output.low.code() + 1 == output.high.code()); |
| 5519 |
|
| 5520 |
Label again; |
| 5521 |
Label done; |
| 5522 |
|
| 5523 |
SecondScratchRegisterScope scratch2(masm); |
| 5524 |
Register ptr = ComputePointerForAtomic(masm, mem, scratch2); |
| 5525 |
|
| 5526 |
// NOTE: the generated code must match the assembly code in gen_cmpxchg in |
| 5527 |
// GenerateAtomicOperations.py |
| 5528 |
masm.memoryBarrierBefore(sync); |
| 5529 |
|
| 5530 |
masm.bind(&again); |
| 5531 |
BufferOffset load = masm.as_ldrexd(output.low, output.high, ptr); |
| 5532 |
if (access) { |
| 5533 |
masm.append(*access, js::wasm::TrapMachineInsn::Load64, |
| 5534 |
FaultingCodeOffset(load.getOffset())); |
| 5535 |
} |
| 5536 |
|
| 5537 |
masm.as_cmp(output.low, O2Reg(expect.low)); |
| 5538 |
masm.as_cmp(output.high, O2Reg(expect.high), MacroAssembler::Equal); |
| 5539 |
masm.as_b(&done, MacroAssembler::NotEqual); |
| 5540 |
|
| 5541 |
ScratchRegisterScope scratch(masm); |
| 5542 |
|
| 5543 |
// Rd (temp) must differ from the two other arguments to strex. |
| 5544 |
masm.as_strexd(scratch, replace.low, replace.high, ptr); |
| 5545 |
masm.as_cmp(scratch, Imm8(1)); |
| 5546 |
masm.as_b(&again, MacroAssembler::Equal); |
| 5547 |
masm.bind(&done); |
| 5548 |
|
| 5549 |
masm.memoryBarrierAfter(sync); |
| 5550 |
} |
| 5551 |
|
| 5552 |
void MacroAssembler::wasmCompareExchange64(const wasm::MemoryAccessDesc& access, |
| 5553 |
const Address& mem, |
| 5554 |
Register64 expect, |
| 5555 |
Register64 replace, |
| 5556 |
Register64 output) { |
| 5557 |
CompareExchange64(*this, &access, access.sync(), mem, expect, replace, |
| 5558 |
output); |
| 5559 |
} |
| 5560 |
|
| 5561 |
void MacroAssembler::wasmCompareExchange64(const wasm::MemoryAccessDesc& access, |
| 5562 |
const BaseIndex& mem, |
| 5563 |
Register64 expect, |
| 5564 |
Register64 replace, |
| 5565 |
Register64 output) { |
| 5566 |
CompareExchange64(*this, &access, access.sync(), mem, expect, replace, |
| 5567 |
output); |
| 5568 |
} |
| 5569 |
|
| 5570 |
void MacroAssembler::compareExchange64(Synchronization sync, const Address& mem, |
| 5571 |
Register64 expect, Register64 replace, |
| 5572 |
Register64 output) { |
| 5573 |
CompareExchange64(*this, nullptr, sync, mem, expect, replace, output); |
| 5574 |
} |
| 5575 |
|
| 5576 |
void MacroAssembler::compareExchange64(Synchronization sync, |
| 5577 |
const BaseIndex& mem, Register64 expect, |
| 5578 |
Register64 replace, Register64 output) { |
| 5579 |
CompareExchange64(*this, nullptr, sync, mem, expect, replace, output); |
| 5580 |
} |
| 5581 |
|
| 5582 |
template <typename T> |
| 5583 |
static void AtomicExchange64(MacroAssembler& masm, |
| 5584 |
const wasm::MemoryAccessDesc* access, |
| 5585 |
Synchronization sync, const T& mem, |
| 5586 |
Register64 value, Register64 output) { |
| 5587 |
MOZ_ASSERT(output != value); |
| 5588 |
|
| 5589 |
MOZ_ASSERT((value.low.code() & 1) == 0); |
| 5590 |
MOZ_ASSERT(value.low.code() + 1 == value.high.code()); |
| 5591 |
|
| 5592 |
MOZ_ASSERT((output.low.code() & 1) == 0); |
| 5593 |
MOZ_ASSERT(output.low.code() + 1 == output.high.code()); |
| 5594 |
|
| 5595 |
Label again; |
| 5596 |
|
| 5597 |
SecondScratchRegisterScope scratch2(masm); |
| 5598 |
Register ptr = ComputePointerForAtomic(masm, mem, scratch2); |
| 5599 |
|
| 5600 |
masm.memoryBarrierBefore(sync); |
| 5601 |
|
| 5602 |
masm.bind(&again); |
| 5603 |
BufferOffset load = masm.as_ldrexd(output.low, output.high, ptr); |
| 5604 |
if (access) { |
| 5605 |
masm.append(*access, js::wasm::TrapMachineInsn::Load64, |
| 5606 |
FaultingCodeOffset(load.getOffset())); |
| 5607 |
} |
| 5608 |
|
| 5609 |
ScratchRegisterScope scratch(masm); |
| 5610 |
|
| 5611 |
masm.as_strexd(scratch, value.low, value.high, ptr); |
| 5612 |
masm.as_cmp(scratch, Imm8(1)); |
| 5613 |
masm.as_b(&again, MacroAssembler::Equal); |
| 5614 |
|
| 5615 |
masm.memoryBarrierAfter(sync); |
| 5616 |
} |
| 5617 |
|
| 5618 |
template <typename T> |
| 5619 |
static void WasmAtomicExchange64(MacroAssembler& masm, |
| 5620 |
const wasm::MemoryAccessDesc& access, |
| 5621 |
const T& mem, Register64 value, |
| 5622 |
Register64 output) { |
| 5623 |
AtomicExchange64(masm, &access, access.sync(), mem, value, output); |
| 5624 |
} |
| 5625 |
|
| 5626 |
void MacroAssembler::wasmAtomicExchange64(const wasm::MemoryAccessDesc& access, |
| 5627 |
const Address& mem, Register64 value, |
| 5628 |
Register64 output) { |
| 5629 |
WasmAtomicExchange64(*this, access, mem, value, output); |
| 5630 |
} |
| 5631 |
|
| 5632 |
void MacroAssembler::wasmAtomicExchange64(const wasm::MemoryAccessDesc& access, |
| 5633 |
const BaseIndex& mem, |
| 5634 |
Register64 value, Register64 output) { |
| 5635 |
WasmAtomicExchange64(*this, access, mem, value, output); |
| 5636 |
} |
| 5637 |
|
| 5638 |
void MacroAssembler::atomicExchange64(Synchronization sync, const Address& mem, |
| 5639 |
Register64 value, Register64 output) { |
| 5640 |
AtomicExchange64(*this, nullptr, sync, mem, value, output); |
| 5641 |
} |
| 5642 |
|
| 5643 |
void MacroAssembler::atomicExchange64(Synchronization sync, |
| 5644 |
const BaseIndex& mem, Register64 value, |
| 5645 |
Register64 output) { |
| 5646 |
AtomicExchange64(*this, nullptr, sync, mem, value, output); |
| 5647 |
} |
| 5648 |
|
| 5649 |
template <typename T> |
| 5650 |
static void AtomicFetchOp64(MacroAssembler& masm, |
| 5651 |
const wasm::MemoryAccessDesc* access, |
| 5652 |
Synchronization sync, AtomicOp op, Register64 value, |
| 5653 |
const T& mem, Register64 temp, Register64 output) { |
| 5654 |
MOZ_ASSERT(temp.low != InvalidReg && temp.high != InvalidReg); |
| 5655 |
MOZ_ASSERT(output != value); |
| 5656 |
MOZ_ASSERT(temp != value); |
| 5657 |
|
| 5658 |
MOZ_ASSERT((temp.low.code() & 1) == 0); |
| 5659 |
MOZ_ASSERT(temp.low.code() + 1 == temp.high.code()); |
| 5660 |
|
| 5661 |
// We could avoid this pair requirement but in that case we would end up |
| 5662 |
// with two moves in the loop to preserve the loaded value in output. The |
| 5663 |
// prize would be less register spilling around this op since the pair |
| 5664 |
// requirement will tend to force more spilling. |
| 5665 |
|
| 5666 |
MOZ_ASSERT((output.low.code() & 1) == 0); |
| 5667 |
MOZ_ASSERT(output.low.code() + 1 == output.high.code()); |
| 5668 |
|
| 5669 |
Label again; |
| 5670 |
|
| 5671 |
SecondScratchRegisterScope scratch2(masm); |
| 5672 |
Register ptr = ComputePointerForAtomic(masm, mem, scratch2); |
| 5673 |
|
| 5674 |
masm.memoryBarrierBefore(sync); |
| 5675 |
|
| 5676 |
masm.bind(&again); |
| 5677 |
BufferOffset load = masm.as_ldrexd(output.low, output.high, ptr); |
| 5678 |
if (access) { |
| 5679 |
masm.append(*access, js::wasm::TrapMachineInsn::Load64, |
| 5680 |
FaultingCodeOffset(load.getOffset())); |
| 5681 |
} |
| 5682 |
switch (op) { |
| 5683 |
case AtomicOp::Add: |
| 5684 |
masm.as_add(temp.low, output.low, O2Reg(value.low), SetCC); |
| 5685 |
masm.as_adc(temp.high, output.high, O2Reg(value.high)); |
| 5686 |
break; |
| 5687 |
case AtomicOp::Sub: |
| 5688 |
masm.as_sub(temp.low, output.low, O2Reg(value.low), SetCC); |
| 5689 |
masm.as_sbc(temp.high, output.high, O2Reg(value.high)); |
| 5690 |
break; |
| 5691 |
case AtomicOp::And: |
| 5692 |
masm.as_and(temp.low, output.low, O2Reg(value.low)); |
| 5693 |
masm.as_and(temp.high, output.high, O2Reg(value.high)); |
| 5694 |
break; |
| 5695 |
case AtomicOp::Or: |
| 5696 |
masm.as_orr(temp.low, output.low, O2Reg(value.low)); |
| 5697 |
masm.as_orr(temp.high, output.high, O2Reg(value.high)); |
| 5698 |
break; |
| 5699 |
case AtomicOp::Xor: |
| 5700 |
masm.as_eor(temp.low, output.low, O2Reg(value.low)); |
| 5701 |
masm.as_eor(temp.high, output.high, O2Reg(value.high)); |
| 5702 |
break; |
| 5703 |
} |
| 5704 |
|
| 5705 |
ScratchRegisterScope scratch(masm); |
| 5706 |
|
| 5707 |
// Rd (temp) must differ from the two other arguments to strex. |
| 5708 |
masm.as_strexd(scratch, temp.low, temp.high, ptr); |
| 5709 |
masm.as_cmp(scratch, Imm8(1)); |
| 5710 |
masm.as_b(&again, MacroAssembler::Equal); |
| 5711 |
|
| 5712 |
masm.memoryBarrierAfter(sync); |
| 5713 |
} |
| 5714 |
|
| 5715 |
template <typename T> |
| 5716 |
static void WasmAtomicFetchOp64(MacroAssembler& masm, |
| 5717 |
const wasm::MemoryAccessDesc& access, |
| 5718 |
AtomicOp op, Register64 value, const T& mem, |
| 5719 |
Register64 temp, Register64 output) { |
| 5720 |
AtomicFetchOp64(masm, &access, access.sync(), op, value, mem, temp, output); |
| 5721 |
} |
| 5722 |
|
| 5723 |
void MacroAssembler::wasmAtomicFetchOp64(const wasm::MemoryAccessDesc& access, |
| 5724 |
AtomicOp op, Register64 value, |
| 5725 |
const Address& mem, Register64 temp, |
| 5726 |
Register64 output) { |
| 5727 |
WasmAtomicFetchOp64(*this, access, op, value, mem, temp, output); |
| 5728 |
} |
| 5729 |
|
| 5730 |
void MacroAssembler::wasmAtomicFetchOp64(const wasm::MemoryAccessDesc& access, |
| 5731 |
AtomicOp op, Register64 value, |
| 5732 |
const BaseIndex& mem, Register64 temp, |
| 5733 |
Register64 output) { |
| 5734 |
WasmAtomicFetchOp64(*this, access, op, value, mem, temp, output); |
| 5735 |
} |
| 5736 |
|
| 5737 |
void MacroAssembler::atomicFetchOp64(Synchronization sync, AtomicOp op, |
| 5738 |
Register64 value, const Address& mem, |
| 5739 |
Register64 temp, Register64 output) { |
| 5740 |
AtomicFetchOp64(*this, nullptr, sync, op, value, mem, temp, output); |
| 5741 |
} |
| 5742 |
|
| 5743 |
void MacroAssembler::atomicFetchOp64(Synchronization sync, AtomicOp op, |
| 5744 |
Register64 value, const BaseIndex& mem, |
| 5745 |
Register64 temp, Register64 output) { |
| 5746 |
AtomicFetchOp64(*this, nullptr, sync, op, value, mem, temp, output); |
| 5747 |
} |
| 5748 |
|
| 5749 |
void MacroAssembler::atomicEffectOp64(Synchronization sync, AtomicOp op, |
| 5750 |
Register64 value, const Address& mem, |
| 5751 |
Register64 temp) { |
| 5752 |
AtomicFetchOp64(*this, nullptr, sync, op, value, mem, temp, temp); |
| 5753 |
} |
| 5754 |
|
| 5755 |
void MacroAssembler::atomicEffectOp64(Synchronization sync, AtomicOp op, |
| 5756 |
Register64 value, const BaseIndex& mem, |
| 5757 |
Register64 temp) { |
| 5758 |
AtomicFetchOp64(*this, nullptr, sync, op, value, mem, temp, temp); |
| 5759 |
} |
| 5760 |
|
| 5761 |
// ======================================================================== |
| 5762 |
// JS atomic operations. |
| 5763 |
|
| 5764 |
template <typename T> |
| 5765 |
static void CompareExchangeJS(MacroAssembler& masm, Scalar::Type arrayType, |
| 5766 |
Synchronization sync, const T& mem, |
| 5767 |
Register oldval, Register newval, Register temp, |
| 5768 |
AnyRegister output) { |
| 5769 |
if (arrayType == Scalar::Uint32) { |
| 5770 |
masm.compareExchange(arrayType, sync, mem, oldval, newval, temp); |
| 5771 |
masm.convertUInt32ToDouble(temp, output.fpu()); |
| 5772 |
} else { |
| 5773 |
masm.compareExchange(arrayType, sync, mem, oldval, newval, output.gpr()); |
| 5774 |
} |
| 5775 |
} |
| 5776 |
|
| 5777 |
void MacroAssembler::compareExchangeJS(Scalar::Type arrayType, |
| 5778 |
Synchronization sync, const Address& mem, |
| 5779 |
Register oldval, Register newval, |
| 5780 |
Register temp, AnyRegister output) { |
| 5781 |
CompareExchangeJS(*this, arrayType, sync, mem, oldval, newval, temp, output); |
| 5782 |
} |
| 5783 |
|
| 5784 |
void MacroAssembler::compareExchangeJS(Scalar::Type arrayType, |
| 5785 |
Synchronization sync, |
| 5786 |
const BaseIndex& mem, Register oldval, |
| 5787 |
Register newval, Register temp, |
| 5788 |
AnyRegister output) { |
| 5789 |
CompareExchangeJS(*this, arrayType, sync, mem, oldval, newval, temp, output); |
| 5790 |
} |
| 5791 |
|
| 5792 |
template <typename T> |
| 5793 |
static void AtomicExchangeJS(MacroAssembler& masm, Scalar::Type arrayType, |
| 5794 |
Synchronization sync, const T& mem, Register value, |
| 5795 |
Register temp, AnyRegister output) { |
| 5796 |
if (arrayType == Scalar::Uint32) { |
| 5797 |
masm.atomicExchange(arrayType, sync, mem, value, temp); |
| 5798 |
masm.convertUInt32ToDouble(temp, output.fpu()); |
| 5799 |
} else { |
| 5800 |
masm.atomicExchange(arrayType, sync, mem, value, output.gpr()); |
| 5801 |
} |
| 5802 |
} |
| 5803 |
|
| 5804 |
void MacroAssembler::atomicExchangeJS(Scalar::Type arrayType, |
| 5805 |
Synchronization sync, const Address& mem, |
| 5806 |
Register value, Register temp, |
| 5807 |
AnyRegister output) { |
| 5808 |
AtomicExchangeJS(*this, arrayType, sync, mem, value, temp, output); |
| 5809 |
} |
| 5810 |
|
| 5811 |
void MacroAssembler::atomicExchangeJS(Scalar::Type arrayType, |
| 5812 |
Synchronization sync, |
| 5813 |
const BaseIndex& mem, Register value, |
| 5814 |
Register temp, AnyRegister output) { |
| 5815 |
AtomicExchangeJS(*this, arrayType, sync, mem, value, temp, output); |
| 5816 |
} |
| 5817 |
|
| 5818 |
template <typename T> |
| 5819 |
static void AtomicFetchOpJS(MacroAssembler& masm, Scalar::Type arrayType, |
| 5820 |
Synchronization sync, AtomicOp op, Register value, |
| 5821 |
const T& mem, Register temp1, Register temp2, |
| 5822 |
AnyRegister output) { |
| 5823 |
if (arrayType == Scalar::Uint32) { |
| 5824 |
masm.atomicFetchOp(arrayType, sync, op, value, mem, temp2, temp1); |
| 5825 |
masm.convertUInt32ToDouble(temp1, output.fpu()); |
| 5826 |
} else { |
| 5827 |
masm.atomicFetchOp(arrayType, sync, op, value, mem, temp1, output.gpr()); |
| 5828 |
} |
| 5829 |
} |
| 5830 |
|
| 5831 |
void MacroAssembler::atomicFetchOpJS(Scalar::Type arrayType, |
| 5832 |
Synchronization sync, AtomicOp op, |
| 5833 |
Register value, const Address& mem, |
| 5834 |
Register temp1, Register temp2, |
| 5835 |
AnyRegister output) { |
| 5836 |
AtomicFetchOpJS(*this, arrayType, sync, op, value, mem, temp1, temp2, output); |
| 5837 |
} |
| 5838 |
|
| 5839 |
void MacroAssembler::atomicFetchOpJS(Scalar::Type arrayType, |
| 5840 |
Synchronization sync, AtomicOp op, |
| 5841 |
Register value, const BaseIndex& mem, |
| 5842 |
Register temp1, Register temp2, |
| 5843 |
AnyRegister output) { |
| 5844 |
AtomicFetchOpJS(*this, arrayType, sync, op, value, mem, temp1, temp2, output); |
| 5845 |
} |
| 5846 |
|
| 5847 |
void MacroAssembler::atomicEffectOpJS(Scalar::Type arrayType, |
| 5848 |
Synchronization sync, AtomicOp op, |
| 5849 |
Register value, const BaseIndex& mem, |
| 5850 |
Register temp) { |
| 5851 |
AtomicEffectOp(*this, nullptr, arrayType, sync, op, value, mem, temp); |
| 5852 |
} |
| 5853 |
|
| 5854 |
void MacroAssembler::atomicEffectOpJS(Scalar::Type arrayType, |
| 5855 |
Synchronization sync, AtomicOp op, |
| 5856 |
Register value, const Address& mem, |
| 5857 |
Register temp) { |
| 5858 |
AtomicEffectOp(*this, nullptr, arrayType, sync, op, value, mem, temp); |
| 5859 |
} |
| 5860 |
|
| 5861 |
void MacroAssembler::atomicPause() { as_yield(); } |
| 5862 |
|
| 5863 |
// ======================================================================== |
| 5864 |
// Primitive atomic operations. |
| 5865 |
|
| 5866 |
void MacroAssembler::atomicLoad64(Synchronization sync, const Address& mem, |
| 5867 |
Register64 output) { |
| 5868 |
AtomicLoad64(*this, nullptr, sync, mem, output); |
| 5869 |
} |
| 5870 |
|
| 5871 |
void MacroAssembler::atomicLoad64(Synchronization sync, const BaseIndex& mem, |
| 5872 |
Register64 output) { |
| 5873 |
AtomicLoad64(*this, nullptr, sync, mem, output); |
| 5874 |
} |
| 5875 |
|
| 5876 |
void MacroAssembler::atomicStore64(Synchronization sync, const Address& mem, |
| 5877 |
Register64 value, Register64 temp) { |
| 5878 |
AtomicExchange64(*this, nullptr, sync, mem, value, temp); |
| 5879 |
} |
| 5880 |
|
| 5881 |
void MacroAssembler::atomicStore64(Synchronization sync, const BaseIndex& mem, |
| 5882 |
Register64 value, Register64 temp) { |
| 5883 |
AtomicExchange64(*this, nullptr, sync, mem, value, temp); |
| 5884 |
} |
| 5885 |
|
| 5886 |
// ======================================================================== |
| 5887 |
// Convert floating point. |
| 5888 |
|
| 5889 |
bool MacroAssembler::convertUInt64ToDoubleNeedsTemp() { return false; } |
| 5890 |
|
| 5891 |
void MacroAssembler::convertUInt64ToDouble(Register64 src, FloatRegister dest, |
| 5892 |
Register temp) { |
| 5893 |
MOZ_ASSERT(temp == Register::Invalid()); |
| 5894 |
ScratchDoubleScope scratchDouble(*this); |
| 5895 |
|
| 5896 |
convertUInt32ToDouble(src.high, dest); |
| 5897 |
{ |
| 5898 |
ScratchRegisterScope scratch(*this); |
| 5899 |
movePtr(ImmPtr(&TO_DOUBLE_HIGH_SCALE), scratch); |
| 5900 |
ma_vldr(Operand(Address(scratch, 0)).toVFPAddr(), scratchDouble); |
| 5901 |
} |
| 5902 |
mulDouble(scratchDouble, dest); |
| 5903 |
convertUInt32ToDouble(src.low, scratchDouble); |
| 5904 |
addDouble(scratchDouble, dest); |
| 5905 |
} |
| 5906 |
|
| 5907 |
void MacroAssembler::convertInt64ToDouble(Register64 src, FloatRegister dest) { |
| 5908 |
ScratchDoubleScope scratchDouble(*this); |
| 5909 |
|
| 5910 |
convertInt32ToDouble(src.high, dest); |
| 5911 |
{ |
| 5912 |
ScratchRegisterScope scratch(*this); |
| 5913 |
movePtr(ImmPtr(&TO_DOUBLE_HIGH_SCALE), scratch); |
| 5914 |
ma_vldr(Operand(Address(scratch, 0)).toVFPAddr(), scratchDouble); |
| 5915 |
} |
| 5916 |
mulDouble(scratchDouble, dest); |
| 5917 |
convertUInt32ToDouble(src.low, scratchDouble); |
| 5918 |
addDouble(scratchDouble, dest); |
| 5919 |
} |
| 5920 |
|
| 5921 |
void MacroAssembler::convertIntPtrToDouble(Register src, FloatRegister dest) { |
| 5922 |
convertInt32ToDouble(src, dest); |
| 5923 |
} |
| 5924 |
|
| 5925 |
extern "C" { |
| 5926 |
extern MOZ_EXPORT int64_t __aeabi_idivmod(int, int); |
| 5927 |
extern MOZ_EXPORT int64_t __aeabi_uidivmod(int, int); |
| 5928 |
} |
| 5929 |
|
| 5930 |
inline void EmitRemainderOrQuotient(bool isRemainder, MacroAssembler& masm, |
| 5931 |
Register rhs, Register lhsOutput, |
| 5932 |
bool isUnsigned, |
| 5933 |
const LiveRegisterSet& volatileLiveRegs) { |
| 5934 |
// Currently this helper can't handle this situation. |
| 5935 |
MOZ_ASSERT(lhsOutput != rhs); |
| 5936 |
|
| 5937 |
if (ARMFlags::HasIDIV()) { |
| 5938 |
if (isRemainder) { |
| 5939 |
masm.remainder32(rhs, lhsOutput, isUnsigned); |
| 5940 |
} else { |
| 5941 |
masm.quotient32(rhs, lhsOutput, isUnsigned); |
| 5942 |
} |
| 5943 |
} else { |
| 5944 |
// Ensure that the output registers are saved and restored properly. |
| 5945 |
LiveRegisterSet liveRegs = volatileLiveRegs; |
| 5946 |
liveRegs.addUnchecked(ReturnRegVal0); |
| 5947 |
liveRegs.addUnchecked(ReturnRegVal1); |
| 5948 |
|
| 5949 |
masm.PushRegsInMask(liveRegs); |
| 5950 |
|
| 5951 |
using Fn = int64_t (*)(int, int); |
| 5952 |
{ |
| 5953 |
ScratchRegisterScope scratch(masm); |
| 5954 |
masm.setupUnalignedABICall(scratch); |
| 5955 |
} |
| 5956 |
masm.passABIArg(lhsOutput); |
| 5957 |
masm.passABIArg(rhs); |
| 5958 |
if (isUnsigned) { |
| 5959 |
masm.callWithABI<Fn, __aeabi_uidivmod>( |
| 5960 |
ABIType::Int64, CheckUnsafeCallWithABI::DontCheckOther); |
| 5961 |
} else { |
| 5962 |
masm.callWithABI<Fn, __aeabi_idivmod>( |
| 5963 |
ABIType::Int64, CheckUnsafeCallWithABI::DontCheckOther); |
| 5964 |
} |
| 5965 |
if (isRemainder) { |
| 5966 |
masm.mov(ReturnRegVal1, lhsOutput); |
| 5967 |
} else { |
| 5968 |
masm.mov(ReturnRegVal0, lhsOutput); |
| 5969 |
} |
| 5970 |
|
| 5971 |
LiveRegisterSet ignore; |
| 5972 |
ignore.add(lhsOutput); |
| 5973 |
masm.PopRegsInMaskIgnore(liveRegs, ignore); |
| 5974 |
} |
| 5975 |
} |
| 5976 |
|
| 5977 |
void MacroAssembler::flexibleQuotient32( |
| 5978 |
Register rhs, Register srcDest, bool isUnsigned, |
| 5979 |
const LiveRegisterSet& volatileLiveRegs) { |
| 5980 |
EmitRemainderOrQuotient(false, *this, rhs, srcDest, isUnsigned, |
| 5981 |
volatileLiveRegs); |
| 5982 |
} |
| 5983 |
|
| 5984 |
void MacroAssembler::flexibleQuotientPtr( |
| 5985 |
Register rhs, Register srcDest, bool isUnsigned, |
| 5986 |
const LiveRegisterSet& volatileLiveRegs) { |
| 5987 |
flexibleQuotient32(rhs, srcDest, isUnsigned, volatileLiveRegs); |
| 5988 |
} |
| 5989 |
|
| 5990 |
void MacroAssembler::flexibleRemainder32( |
| 5991 |
Register rhs, Register srcDest, bool isUnsigned, |
| 5992 |
const LiveRegisterSet& volatileLiveRegs) { |
| 5993 |
EmitRemainderOrQuotient(true, *this, rhs, srcDest, isUnsigned, |
| 5994 |
volatileLiveRegs); |
| 5995 |
} |
| 5996 |
|
| 5997 |
void MacroAssembler::flexibleRemainderPtr( |
| 5998 |
Register rhs, Register srcDest, bool isUnsigned, |
| 5999 |
const LiveRegisterSet& volatileLiveRegs) { |
| 6000 |
flexibleRemainder32(rhs, srcDest, isUnsigned, volatileLiveRegs); |
| 6001 |
} |
| 6002 |
|
| 6003 |
void MacroAssembler::flexibleDivMod32(Register rhs, Register lhsOutput, |
| 6004 |
Register remOutput, bool isUnsigned, |
| 6005 |
const LiveRegisterSet& volatileLiveRegs) { |
| 6006 |
// Currently this helper can't handle this situation. |
| 6007 |
MOZ_ASSERT(lhsOutput != rhs); |
| 6008 |
|
| 6009 |
if (ARMFlags::HasIDIV()) { |
| 6010 |
mov(lhsOutput, remOutput); |
| 6011 |
remainder32(rhs, remOutput, isUnsigned); |
| 6012 |
quotient32(rhs, lhsOutput, isUnsigned); |
| 6013 |
} else { |
| 6014 |
// Ensure that the output registers are saved and restored properly. |
| 6015 |
LiveRegisterSet liveRegs = volatileLiveRegs; |
| 6016 |
liveRegs.addUnchecked(ReturnRegVal0); |
| 6017 |
liveRegs.addUnchecked(ReturnRegVal1); |
| 6018 |
|
| 6019 |
PushRegsInMask(liveRegs); |
| 6020 |
|
| 6021 |
using Fn = int64_t (*)(int, int); |
| 6022 |
{ |
| 6023 |
ScratchRegisterScope scratch(*this); |
| 6024 |
setupUnalignedABICall(scratch); |
| 6025 |
} |
| 6026 |
passABIArg(lhsOutput); |
| 6027 |
passABIArg(rhs); |
| 6028 |
if (isUnsigned) { |
| 6029 |
callWithABI<Fn, __aeabi_uidivmod>(ABIType::Int64, |
| 6030 |
CheckUnsafeCallWithABI::DontCheckOther); |
| 6031 |
} else { |
| 6032 |
callWithABI<Fn, __aeabi_idivmod>(ABIType::Int64, |
| 6033 |
CheckUnsafeCallWithABI::DontCheckOther); |
| 6034 |
} |
| 6035 |
moveRegPair(ReturnRegVal0, ReturnRegVal1, lhsOutput, remOutput); |
| 6036 |
|
| 6037 |
LiveRegisterSet ignore; |
| 6038 |
ignore.add(remOutput); |
| 6039 |
ignore.add(lhsOutput); |
| 6040 |
PopRegsInMaskIgnore(liveRegs, ignore); |
| 6041 |
} |
| 6042 |
} |
| 6043 |
|
| 6044 |
CodeOffset MacroAssembler::moveNearAddressWithPatch(Register dest) { |
| 6045 |
return movWithPatch(ImmPtr(nullptr), dest); |
| 6046 |
} |
| 6047 |
|
| 6048 |
void MacroAssembler::patchNearAddressMove(CodeLocationLabel loc, |
| 6049 |
CodeLocationLabel target) { |
| 6050 |
PatchDataWithValueCheck(loc, ImmPtr(target.raw()), ImmPtr(nullptr)); |
| 6051 |
} |
| 6052 |
|
| 6053 |
// ======================================================================== |
| 6054 |
// Spectre Mitigations. |
| 6055 |
|
| 6056 |
void MacroAssembler::speculationBarrier() { |
| 6057 |
// Spectre mitigation recommended by ARM for cases where csel/cmov cannot be |
| 6058 |
// used. |
| 6059 |
as_csdb(); |
| 6060 |
} |
| 6061 |
|
| 6062 |
void MacroAssembler::floorFloat32ToInt32(FloatRegister src, Register dest, |
| 6063 |
Label* fail) { |
| 6064 |
floorf(src, dest, fail); |
| 6065 |
} |
| 6066 |
|
| 6067 |
void MacroAssembler::floorDoubleToInt32(FloatRegister src, Register dest, |
| 6068 |
Label* fail) { |
| 6069 |
floor(src, dest, fail); |
| 6070 |
} |
| 6071 |
|
| 6072 |
void MacroAssembler::ceilFloat32ToInt32(FloatRegister src, Register dest, |
| 6073 |
Label* fail) { |
| 6074 |
ceilf(src, dest, fail); |
| 6075 |
} |
| 6076 |
|
| 6077 |
void MacroAssembler::ceilDoubleToInt32(FloatRegister src, Register dest, |
| 6078 |
Label* fail) { |
| 6079 |
ceil(src, dest, fail); |
| 6080 |
} |
| 6081 |
|
| 6082 |
void MacroAssembler::roundFloat32ToInt32(FloatRegister src, Register dest, |
| 6083 |
FloatRegister temp, Label* fail) { |
| 6084 |
roundf(src, dest, fail, temp); |
| 6085 |
} |
| 6086 |
|
| 6087 |
void MacroAssembler::roundDoubleToInt32(FloatRegister src, Register dest, |
| 6088 |
FloatRegister temp, Label* fail) { |
| 6089 |
round(src, dest, fail, temp); |
| 6090 |
} |
| 6091 |
|
| 6092 |
void MacroAssembler::truncFloat32ToInt32(FloatRegister src, Register dest, |
| 6093 |
Label* fail) { |
| 6094 |
truncf(src, dest, fail); |
| 6095 |
} |
| 6096 |
|
| 6097 |
void MacroAssembler::truncDoubleToInt32(FloatRegister src, Register dest, |
| 6098 |
Label* fail) { |
| 6099 |
trunc(src, dest, fail); |
| 6100 |
} |
| 6101 |
|
| 6102 |
void MacroAssembler::nearbyIntDouble(RoundingMode mode, FloatRegister src, |
| 6103 |
FloatRegister dest) { |
| 6104 |
MOZ_CRASH("not supported on this platform"); |
| 6105 |
} |
| 6106 |
|
| 6107 |
void MacroAssembler::nearbyIntFloat32(RoundingMode mode, FloatRegister src, |
| 6108 |
FloatRegister dest) { |
| 6109 |
MOZ_CRASH("not supported on this platform"); |
| 6110 |
} |
| 6111 |
|
| 6112 |
void MacroAssembler::copySignDouble(FloatRegister lhs, FloatRegister rhs, |
| 6113 |
FloatRegister output) { |
| 6114 |
MOZ_CRASH("not supported on this platform"); |
| 6115 |
} |
| 6116 |
|
| 6117 |
void MacroAssembler::shiftIndex32AndAdd(Register indexTemp32, int shift, |
| 6118 |
Register pointer) { |
| 6119 |
if (IsShiftInScaleRange(shift)) { |
| 6120 |
computeEffectiveAddress( |
| 6121 |
BaseIndex(pointer, indexTemp32, ShiftToScale(shift)), pointer); |
| 6122 |
return; |
| 6123 |
} |
| 6124 |
lshift32(Imm32(shift), indexTemp32); |
| 6125 |
addPtr(indexTemp32, pointer); |
| 6126 |
} |
| 6127 |
|
| 6128 |
void MacroAssembler::wasmMarkCallAsSlow() { ma_and(lr, lr, lr); } |
| 6129 |
|
| 6130 |
const int32_t SlowCallMarker = 0xe00ee00e; |
| 6131 |
|
| 6132 |
void MacroAssembler::wasmCheckSlowCallsite(Register ra, Label* notSlow, |
| 6133 |
Register temp1, Register temp2) { |
| 6134 |
MOZ_ASSERT(temp1 != temp2); |
| 6135 |
// Check if RA has slow marker. |
| 6136 |
load32(Address(ra, 0), temp2); |
| 6137 |
ma_mov(Imm32(SlowCallMarker), temp1, Always); |
| 6138 |
ma_cmp(temp2, temp1); |
| 6139 |
j(Assembler::NotEqual, notSlow); |
| 6140 |
} |
| 6141 |
|
| 6142 |
CodeOffset MacroAssembler::wasmMarkedSlowCall(const wasm::CallSiteDesc& desc, |
| 6143 |
const Register reg) { |
| 6144 |
AutoForbidPoolsAndNops afp(this, 2); |
| 6145 |
CodeOffset offset = call(desc, reg); |
| 6146 |
wasmMarkCallAsSlow(); |
| 6147 |
return offset; |
| 6148 |
} |
| 6149 |
|
| 6150 |
//}}} check_macroassembler_style |
| 6151 |
|
| 6152 |
void MacroAssemblerARM::wasmTruncateToInt32(FloatRegister input, |
| 6153 |
Register output, MIRType fromType, |
| 6154 |
bool isUnsigned, bool isSaturating, |
| 6155 |
Label* oolEntry) { |
| 6156 |
ScratchDoubleScope scratchScope(asMasm()); |
| 6157 |
ScratchRegisterScope scratchReg(asMasm()); |
| 6158 |
FloatRegister scratch = scratchScope.uintOverlay(); |
| 6159 |
|
| 6160 |
// ARM conversion instructions clamp the value to ensure it fits within the |
| 6161 |
// target's type bounds, so every time we see those, we need to check the |
| 6162 |
// input. A NaN check is not necessary because NaN is converted to zero and |
| 6163 |
// on a zero result we branch out of line to do further processing anyway. |
| 6164 |
if (isUnsigned) { |
| 6165 |
if (fromType == MIRType::Double) { |
| 6166 |
ma_vcvt_F64_U32(input, scratch); |
| 6167 |
} else if (fromType == MIRType::Float32) { |
| 6168 |
ma_vcvt_F32_U32(input, scratch); |
| 6169 |
} else { |
| 6170 |
MOZ_CRASH("unexpected type in visitWasmTruncateToInt32"); |
| 6171 |
} |
| 6172 |
|
| 6173 |
ma_vxfer(scratch, output); |
| 6174 |
|
| 6175 |
if (!isSaturating) { |
| 6176 |
// int32_t(UINT32_MAX) == -1. |
| 6177 |
ma_cmp(output, Imm32(-1), scratchReg); |
| 6178 |
as_cmp(output, Imm8(0), Assembler::NotEqual); |
| 6179 |
ma_b(oolEntry, Assembler::Equal); |
| 6180 |
} |
| 6181 |
|
| 6182 |
return; |
| 6183 |
} |
| 6184 |
|
| 6185 |
// vcvt* converts NaN into 0, so check for NaNs here. |
| 6186 |
if (!isSaturating) { |
| 6187 |
if (fromType == MIRType::Double) { |
| 6188 |
asMasm().compareDouble(input, input); |
| 6189 |
} else if (fromType == MIRType::Float32) { |
| 6190 |
asMasm().compareFloat(input, input); |
| 6191 |
} else { |
| 6192 |
MOZ_CRASH("unexpected type in visitWasmTruncateToInt32"); |
| 6193 |
} |
| 6194 |
|
| 6195 |
ma_b(oolEntry, Assembler::VFP_Unordered); |
| 6196 |
} |
| 6197 |
|
| 6198 |
scratch = scratchScope.sintOverlay(); |
| 6199 |
|
| 6200 |
if (fromType == MIRType::Double) { |
| 6201 |
ma_vcvt_F64_I32(input, scratch); |
| 6202 |
} else if (fromType == MIRType::Float32) { |
| 6203 |
ma_vcvt_F32_I32(input, scratch); |
| 6204 |
} else { |
| 6205 |
MOZ_CRASH("unexpected type in visitWasmTruncateToInt32"); |
| 6206 |
} |
| 6207 |
|
| 6208 |
ma_vxfer(scratch, output); |
| 6209 |
|
| 6210 |
if (!isSaturating) { |
| 6211 |
ma_cmp(output, Imm32(INT32_MAX), scratchReg); |
| 6212 |
ma_cmp(output, Imm32(INT32_MIN), scratchReg, Assembler::NotEqual); |
| 6213 |
ma_b(oolEntry, Assembler::Equal); |
| 6214 |
} |
| 6215 |
} |
| 6216 |
|
| 6217 |
void MacroAssemblerARM::outOfLineWasmTruncateToIntCheck( |
| 6218 |
FloatRegister input, MIRType fromType, MIRType toType, TruncFlags flags, |
| 6219 |
Label* rejoin, const wasm::TrapSiteDesc& trapSiteDesc) { |
| 6220 |
// On ARM, saturating truncation codegen handles saturating itself rather |
| 6221 |
// than relying on out-of-line fixup code. |
| 6222 |
if (flags & TRUNC_SATURATING) { |
| 6223 |
return; |
| 6224 |
} |
| 6225 |
|
| 6226 |
bool isUnsigned = flags & TRUNC_UNSIGNED; |
| 6227 |
ScratchDoubleScope scratchScope(asMasm()); |
| 6228 |
FloatRegister scratch; |
| 6229 |
|
| 6230 |
// Eagerly take care of NaNs. |
| 6231 |
Label inputIsNaN; |
| 6232 |
if (fromType == MIRType::Double) { |
| 6233 |
asMasm().branchDouble(Assembler::DoubleUnordered, input, input, |
| 6234 |
&inputIsNaN); |
| 6235 |
} else if (fromType == MIRType::Float32) { |
| 6236 |
asMasm().branchFloat(Assembler::DoubleUnordered, input, input, &inputIsNaN); |
| 6237 |
} else { |
| 6238 |
MOZ_CRASH("unexpected type in visitOutOfLineWasmTruncateCheck"); |
| 6239 |
} |
| 6240 |
|
| 6241 |
// Handle special values. |
| 6242 |
Label fail; |
| 6243 |
|
| 6244 |
// By default test for the following inputs and bail: |
| 6245 |
// signed: ] -Inf, INTXX_MIN - 1.0 ] and [ INTXX_MAX + 1.0 : +Inf [ |
| 6246 |
// unsigned: ] -Inf, -1.0 ] and [ UINTXX_MAX + 1.0 : +Inf [ |
| 6247 |
// Note: we cannot always represent those exact values. As a result |
| 6248 |
// this changes the actual comparison a bit. |
| 6249 |
double minValue, maxValue; |
| 6250 |
Assembler::DoubleCondition minCond = Assembler::DoubleLessThanOrEqual; |
| 6251 |
Assembler::DoubleCondition maxCond = Assembler::DoubleGreaterThanOrEqual; |
| 6252 |
if (toType == MIRType::Int64) { |
| 6253 |
if (isUnsigned) { |
| 6254 |
minValue = -1; |
| 6255 |
maxValue = double(UINT64_MAX) + 1.0; |
| 6256 |
} else { |
| 6257 |
// In the float32/double range there exists no value between |
| 6258 |
// INT64_MIN and INT64_MIN - 1.0. Making INT64_MIN the lower-bound. |
| 6259 |
minValue = double(INT64_MIN); |
| 6260 |
minCond = Assembler::DoubleLessThan; |
| 6261 |
maxValue = double(INT64_MAX) + 1.0; |
| 6262 |
} |
| 6263 |
} else { |
| 6264 |
if (isUnsigned) { |
| 6265 |
minValue = -1; |
| 6266 |
maxValue = double(UINT32_MAX) + 1.0; |
| 6267 |
} else { |
| 6268 |
if (fromType == MIRType::Float32) { |
| 6269 |
// In the float32 range there exists no value between |
| 6270 |
// INT32_MIN and INT32_MIN - 1.0. Making INT32_MIN the lower-bound. |
| 6271 |
minValue = double(INT32_MIN); |
| 6272 |
minCond = Assembler::DoubleLessThan; |
| 6273 |
} else { |
| 6274 |
minValue = double(INT32_MIN) - 1.0; |
| 6275 |
} |
| 6276 |
maxValue = double(INT32_MAX) + 1.0; |
| 6277 |
} |
| 6278 |
} |
| 6279 |
|
| 6280 |
if (fromType == MIRType::Double) { |
| 6281 |
scratch = scratchScope.doubleOverlay(); |
| 6282 |
asMasm().loadConstantDouble(minValue, scratch); |
| 6283 |
asMasm().branchDouble(minCond, input, scratch, &fail); |
| 6284 |
|
| 6285 |
asMasm().loadConstantDouble(maxValue, scratch); |
| 6286 |
asMasm().branchDouble(maxCond, input, scratch, &fail); |
| 6287 |
} else { |
| 6288 |
MOZ_ASSERT(fromType == MIRType::Float32); |
| 6289 |
scratch = scratchScope.singleOverlay(); |
| 6290 |
asMasm().loadConstantFloat32(float(minValue), scratch); |
| 6291 |
asMasm().branchFloat(minCond, input, scratch, &fail); |
| 6292 |
|
| 6293 |
asMasm().loadConstantFloat32(float(maxValue), scratch); |
| 6294 |
asMasm().branchFloat(maxCond, input, scratch, &fail); |
| 6295 |
} |
| 6296 |
|
| 6297 |
// We had an actual correct value, get back to where we were. |
| 6298 |
ma_b(rejoin); |
| 6299 |
|
| 6300 |
// Handle errors. |
| 6301 |
bind(&fail); |
| 6302 |
asMasm().wasmTrap(wasm::Trap::IntegerOverflow, trapSiteDesc); |
| 6303 |
|
| 6304 |
bind(&inputIsNaN); |
| 6305 |
asMasm().wasmTrap(wasm::Trap::InvalidConversionToInteger, trapSiteDesc); |
| 6306 |
} |
| 6307 |
|
| 6308 |
void MacroAssemblerARM::wasmLoadImpl(const wasm::MemoryAccessDesc& access, |
| 6309 |
Register memoryBase, Register ptr, |
| 6310 |
Register ptrScratch, AnyRegister output, |
| 6311 |
Register64 out64) { |
| 6312 |
MOZ_ASSERT(memoryBase != ptr); |
| 6313 |
MOZ_ASSERT_IF(out64 != Register64::Invalid(), memoryBase != out64.high); |
| 6314 |
MOZ_ASSERT_IF(out64 != Register64::Invalid(), memoryBase != out64.low); |
| 6315 |
MOZ_ASSERT(ptr == ptrScratch); |
| 6316 |
MOZ_ASSERT(!access.isZeroExtendSimd128Load()); |
| 6317 |
MOZ_ASSERT(!access.isSplatSimd128Load()); |
| 6318 |
MOZ_ASSERT(!access.isWidenSimd128Load()); |
| 6319 |
|
| 6320 |
access.assertOffsetInGuardPages(); |
| 6321 |
uint32_t offset = access.offset32(); |
| 6322 |
|
| 6323 |
Scalar::Type type = access.type(); |
| 6324 |
|
| 6325 |
// Maybe add the offset. |
| 6326 |
if (offset || type == Scalar::Int64) { |
| 6327 |
ScratchRegisterScope scratch(asMasm()); |
| 6328 |
if (offset) { |
| 6329 |
ma_add(Imm32(offset), ptr, scratch); |
| 6330 |
} |
| 6331 |
} |
| 6332 |
|
| 6333 |
bool isSigned = Scalar::isSignedIntType(type); |
| 6334 |
unsigned byteSize = access.byteSize(); |
| 6335 |
|
| 6336 |
// NOTE: the generated code must match the assembly code in gen_load in |
| 6337 |
// GenerateAtomicOperations.py |
| 6338 |
asMasm().memoryBarrierBefore(access.sync()); |
| 6339 |
|
| 6340 |
BufferOffset load; |
| 6341 |
if (out64 != Register64::Invalid()) { |
| 6342 |
if (type == Scalar::Int64) { |
| 6343 |
static_assert(INT64LOW_OFFSET == 0); |
| 6344 |
|
| 6345 |
load = ma_dataTransferN(IsLoad, 32, /* signed = */ false, memoryBase, ptr, |
| 6346 |
out64.low); |
| 6347 |
append(access, js::wasm::TrapMachineInsn::Load32, |
| 6348 |
FaultingCodeOffset(load.getOffset())); |
| 6349 |
|
| 6350 |
as_add(ptr, ptr, Imm8(INT64HIGH_OFFSET)); |
| 6351 |
|
| 6352 |
load = |
| 6353 |
ma_dataTransferN(IsLoad, 32, isSigned, memoryBase, ptr, out64.high); |
| 6354 |
append(access, js::wasm::TrapMachineInsn::Load32, |
| 6355 |
FaultingCodeOffset(load.getOffset())); |
| 6356 |
} else { |
| 6357 |
load = ma_dataTransferN(IsLoad, byteSize * 8, isSigned, memoryBase, ptr, |
| 6358 |
out64.low); |
| 6359 |
append(access, js::wasm::TrapMachineInsnForLoad(byteSize), |
| 6360 |
FaultingCodeOffset(load.getOffset())); |
| 6361 |
|
| 6362 |
if (isSigned) { |
| 6363 |
ma_asr(Imm32(31), out64.low, out64.high); |
| 6364 |
} else { |
| 6365 |
ma_mov(Imm32(0), out64.high); |
| 6366 |
} |
| 6367 |
} |
| 6368 |
} else { |
| 6369 |
bool isFloat = output.isFloat(); |
| 6370 |
if (isFloat) { |
| 6371 |
MOZ_ASSERT((byteSize == 4) == output.fpu().isSingle()); |
| 6372 |
ScratchRegisterScope scratch(asMasm()); |
| 6373 |
FloatRegister dest = output.fpu(); |
| 6374 |
ma_add(memoryBase, ptr, scratch); |
| 6375 |
|
| 6376 |
// FP loads can't use VLDR as that has stringent alignment checks and will |
| 6377 |
// SIGBUS on unaligned accesses. Choose a different strategy depending on |
| 6378 |
// the available hardware. We don't gate Wasm on the presence of NEON. |
| 6379 |
if (ARMFlags::HasNEON()) { |
| 6380 |
// NEON available: The VLD1 multiple-single-elements variant will only |
| 6381 |
// trap if SCTRL.A==1, but we already assume (for integer accesses) that |
| 6382 |
// the hardware/OS handles that transparently. |
| 6383 |
// |
| 6384 |
// An additional complication is that if we're targeting the high single |
| 6385 |
// then an unaligned load is not possible, and we may need to go via the |
| 6386 |
// FPR scratch. |
| 6387 |
if (byteSize == 4 && dest.code() & 1) { |
| 6388 |
ScratchFloat32Scope fscratch(asMasm()); |
| 6389 |
load = as_vldr_unaligned(fscratch, scratch); |
| 6390 |
as_vmov(dest, fscratch); |
| 6391 |
} else { |
| 6392 |
load = as_vldr_unaligned(dest, scratch); |
| 6393 |
} |
| 6394 |
append(access, js::wasm::TrapMachineInsnForLoad(byteSize), |
| 6395 |
FaultingCodeOffset(load.getOffset())); |
| 6396 |
} else { |
| 6397 |
// NEON not available: Load to GPR scratch, move to FPR destination. We |
| 6398 |
// don't have adjacent scratches for the f64, so use individual LDRs, |
| 6399 |
// not LDRD. |
| 6400 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 6401 |
if (byteSize == 4) { |
| 6402 |
load = as_dtr(IsLoad, 32, Offset, scratch2, |
| 6403 |
DTRAddr(scratch, DtrOffImm(0)), Always); |
| 6404 |
as_vxfer(scratch2, InvalidReg, VFPRegister(dest), CoreToFloat, |
| 6405 |
Always); |
| 6406 |
append(access, js::wasm::TrapMachineInsn::Load32, |
| 6407 |
FaultingCodeOffset(load.getOffset())); |
| 6408 |
} else { |
| 6409 |
// The trap information is associated with the load of the high word, |
| 6410 |
// which must be done first. FIXME sewardj 20230825: is it still |
| 6411 |
// safe to skip the low word, now that we support wasm-gc? |
| 6412 |
load = as_dtr(IsLoad, 32, Offset, scratch2, |
| 6413 |
DTRAddr(scratch, DtrOffImm(4)), Always); |
| 6414 |
append(access, js::wasm::TrapMachineInsn::Load32, |
| 6415 |
FaultingCodeOffset(load.getOffset())); |
| 6416 |
as_dtr(IsLoad, 32, Offset, scratch, DTRAddr(scratch, DtrOffImm(0)), |
| 6417 |
Always); |
| 6418 |
as_vxfer(scratch, scratch2, VFPRegister(dest), CoreToFloat, Always); |
| 6419 |
} |
| 6420 |
} |
| 6421 |
} else { |
| 6422 |
load = ma_dataTransferN(IsLoad, byteSize * 8, isSigned, memoryBase, ptr, |
| 6423 |
output.gpr()); |
| 6424 |
append(access, js::wasm::TrapMachineInsnForLoad(byteSize), |
| 6425 |
FaultingCodeOffset(load.getOffset())); |
| 6426 |
} |
| 6427 |
} |
| 6428 |
|
| 6429 |
asMasm().memoryBarrierAfter(access.sync()); |
| 6430 |
} |
| 6431 |
|
| 6432 |
void MacroAssemblerARM::wasmStoreImpl(const wasm::MemoryAccessDesc& access, |
| 6433 |
AnyRegister value, Register64 val64, |
| 6434 |
Register memoryBase, Register ptr, |
| 6435 |
Register ptrScratch) { |
| 6436 |
static_assert(INT64LOW_OFFSET == 0); |
| 6437 |
static_assert(INT64HIGH_OFFSET == 4); |
| 6438 |
|
| 6439 |
MOZ_ASSERT(ptr == ptrScratch); |
| 6440 |
|
| 6441 |
access.assertOffsetInGuardPages(); |
| 6442 |
uint32_t offset = access.offset32(); |
| 6443 |
unsigned byteSize = access.byteSize(); |
| 6444 |
Scalar::Type type = access.type(); |
| 6445 |
|
| 6446 |
// Maybe add the offset. |
| 6447 |
if (offset || type == Scalar::Int64) { |
| 6448 |
ScratchRegisterScope scratch(asMasm()); |
| 6449 |
// We need to store the high word of an Int64 first, so always adjust the |
| 6450 |
// pointer to point to the high word in this case. The adjustment is always |
| 6451 |
// OK because wasmMaxOffsetGuardLimit is computed so that we can add up to |
| 6452 |
// sizeof(LargestValue)-1 without skipping past the guard page, and we |
| 6453 |
// assert above that offset < wasmMaxOffsetGuardLimit. |
| 6454 |
if (type == Scalar::Int64) { |
| 6455 |
offset += INT64HIGH_OFFSET; |
| 6456 |
} |
| 6457 |
if (offset) { |
| 6458 |
ma_add(Imm32(offset), ptr, scratch); |
| 6459 |
} |
| 6460 |
} |
| 6461 |
|
| 6462 |
// NOTE: the generated code must match the assembly code in gen_store in |
| 6463 |
// GenerateAtomicOperations.py |
| 6464 |
asMasm().memoryBarrierBefore(access.sync()); |
| 6465 |
|
| 6466 |
BufferOffset store; |
| 6467 |
if (type == Scalar::Int64) { |
| 6468 |
store = ma_dataTransferN(IsStore, 32 /* bits */, /* signed */ false, |
| 6469 |
memoryBase, ptr, val64.high); |
| 6470 |
append(access, js::wasm::TrapMachineInsn::Store32, |
| 6471 |
FaultingCodeOffset(store.getOffset())); |
| 6472 |
|
| 6473 |
as_sub(ptr, ptr, Imm8(INT64HIGH_OFFSET)); |
| 6474 |
|
| 6475 |
store = ma_dataTransferN(IsStore, 32 /* bits */, /* signed */ true, |
| 6476 |
memoryBase, ptr, val64.low); |
| 6477 |
append(access, js::wasm::TrapMachineInsn::Store32, |
| 6478 |
FaultingCodeOffset(store.getOffset())); |
| 6479 |
} else { |
| 6480 |
if (value.isFloat()) { |
| 6481 |
ScratchRegisterScope scratch(asMasm()); |
| 6482 |
FloatRegister val = value.fpu(); |
| 6483 |
MOZ_ASSERT((byteSize == 4) == val.isSingle()); |
| 6484 |
ma_add(memoryBase, ptr, scratch); |
| 6485 |
|
| 6486 |
// See comments above at wasmLoadImpl for more about this logic. |
| 6487 |
if (ARMFlags::HasNEON()) { |
| 6488 |
if (byteSize == 4 && (val.code() & 1)) { |
| 6489 |
ScratchFloat32Scope fscratch(asMasm()); |
| 6490 |
as_vmov(fscratch, val); |
| 6491 |
store = as_vstr_unaligned(fscratch, scratch); |
| 6492 |
} else { |
| 6493 |
store = as_vstr_unaligned(val, scratch); |
| 6494 |
} |
| 6495 |
append(access, js::wasm::TrapMachineInsnForStore(byteSize), |
| 6496 |
FaultingCodeOffset(store.getOffset())); |
| 6497 |
} else { |
| 6498 |
// NEON not available: Move FPR to GPR scratch, store GPR. We have only |
| 6499 |
// one scratch to hold the value, so for f64 we must do two separate |
| 6500 |
// moves. That's OK - this is really a corner case. If we really cared |
| 6501 |
// we would pass in a temp to avoid the second move. |
| 6502 |
SecondScratchRegisterScope scratch2(asMasm()); |
| 6503 |
if (byteSize == 4) { |
| 6504 |
as_vxfer(scratch2, InvalidReg, VFPRegister(val), FloatToCore, Always); |
| 6505 |
store = as_dtr(IsStore, 32, Offset, scratch2, |
| 6506 |
DTRAddr(scratch, DtrOffImm(0)), Always); |
| 6507 |
append(access, js::wasm::TrapMachineInsn::Store32, |
| 6508 |
FaultingCodeOffset(store.getOffset())); |
| 6509 |
} else { |
| 6510 |
// The trap information is associated with the store of the high word, |
| 6511 |
// which must be done first. FIXME sewardj 20230825: is it still |
| 6512 |
// safe to skip the low word, now that we support wasm-gc? |
| 6513 |
as_vxfer(scratch2, InvalidReg, VFPRegister(val).singleOverlay(1), |
| 6514 |
FloatToCore, Always); |
| 6515 |
store = as_dtr(IsStore, 32, Offset, scratch2, |
| 6516 |
DTRAddr(scratch, DtrOffImm(4)), Always); |
| 6517 |
append(access, js::wasm::TrapMachineInsn::Store32, |
| 6518 |
FaultingCodeOffset(store.getOffset())); |
| 6519 |
as_vxfer(scratch2, InvalidReg, VFPRegister(val).singleOverlay(0), |
| 6520 |
FloatToCore, Always); |
| 6521 |
as_dtr(IsStore, 32, Offset, scratch2, DTRAddr(scratch, DtrOffImm(0)), |
| 6522 |
Always); |
| 6523 |
} |
| 6524 |
} |
| 6525 |
} else { |
| 6526 |
bool isSigned = type == Scalar::Uint32 || |
| 6527 |
type == Scalar::Int32; // see AsmJSStoreHeap; |
| 6528 |
Register val = value.gpr(); |
| 6529 |
|
| 6530 |
store = ma_dataTransferN(IsStore, 8 * byteSize /* bits */, isSigned, |
| 6531 |
memoryBase, ptr, val); |
| 6532 |
append(access, js::wasm::TrapMachineInsnForStore(byteSize), |
| 6533 |
FaultingCodeOffset(store.getOffset())); |
| 6534 |
} |
| 6535 |
} |
| 6536 |
|
| 6537 |
asMasm().memoryBarrierAfter(access.sync()); |
| 6538 |
} |