| 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/x64/MacroAssembler-x64.h" |
| 8 |
|
| 9 |
#include "jit/BaselineFrame.h" |
| 10 |
#include "jit/JitFrames.h" |
| 11 |
#include "jit/JitRuntime.h" |
| 12 |
#include "jit/MacroAssembler.h" |
| 13 |
#include "jit/MoveEmitter.h" |
| 14 |
#include "util/Memory.h" |
| 15 |
#include "vm/BigIntType.h" |
| 16 |
#include "vm/JitActivation.h" // js::jit::JitActivation |
| 17 |
#include "vm/JSContext.h" |
| 18 |
#include "vm/StringType.h" |
| 19 |
#include "wasm/WasmStubs.h" |
| 20 |
|
| 21 |
#include "jit/MacroAssembler-inl.h" |
| 22 |
|
| 23 |
using namespace js; |
| 24 |
using namespace js::jit; |
| 25 |
|
| 26 |
void MacroAssemblerX64::loadConstantDouble(double d, FloatRegister dest) { |
| 27 |
if (maybeInlineDouble(d, dest)) { |
| 28 |
return; |
| 29 |
} |
| 30 |
Double* dbl = getDouble(d); |
| 31 |
if (!dbl) { |
| 32 |
return; |
| 33 |
} |
| 34 |
// The constants will be stored in a pool appended to the text (see |
| 35 |
// finish()), so they will always be a fixed distance from the |
| 36 |
// instructions which reference them. This allows the instructions to use |
| 37 |
// PC-relative addressing. Use "jump" label support code, because we need |
| 38 |
// the same PC-relative address patching that jumps use. |
| 39 |
JmpSrc j = masm.vmovsd_ripr(dest.encoding()); |
| 40 |
propagateOOM(dbl->uses.append(j)); |
| 41 |
} |
| 42 |
|
| 43 |
void MacroAssemblerX64::loadConstantFloat32(float f, FloatRegister dest) { |
| 44 |
if (maybeInlineFloat(f, dest)) { |
| 45 |
return; |
| 46 |
} |
| 47 |
Float* flt = getFloat(f); |
| 48 |
if (!flt) { |
| 49 |
return; |
| 50 |
} |
| 51 |
// See comment in loadConstantDouble |
| 52 |
JmpSrc j = masm.vmovss_ripr(dest.encoding()); |
| 53 |
propagateOOM(flt->uses.append(j)); |
| 54 |
} |
| 55 |
|
| 56 |
void MacroAssemblerX64::vpRiprOpSimd128( |
| 57 |
const SimdConstant& v, FloatRegister reg, |
| 58 |
JmpSrc (X86Encoding::BaseAssemblerX64::*op)( |
| 59 |
X86Encoding::XMMRegisterID id)) { |
| 60 |
SimdData* val = getSimdData(v); |
| 61 |
if (!val) { |
| 62 |
return; |
| 63 |
} |
| 64 |
JmpSrc j = (masm.*op)(reg.encoding()); |
| 65 |
propagateOOM(val->uses.append(j)); |
| 66 |
} |
| 67 |
|
| 68 |
void MacroAssemblerX64::vpRiprOpSimd128( |
| 69 |
const SimdConstant& v, FloatRegister src, FloatRegister dest, |
| 70 |
JmpSrc (X86Encoding::BaseAssemblerX64::*op)( |
| 71 |
X86Encoding::XMMRegisterID srcId, X86Encoding::XMMRegisterID destId)) { |
| 72 |
SimdData* val = getSimdData(v); |
| 73 |
if (!val) { |
| 74 |
return; |
| 75 |
} |
| 76 |
JmpSrc j = (masm.*op)(src.encoding(), dest.encoding()); |
| 77 |
propagateOOM(val->uses.append(j)); |
| 78 |
} |
| 79 |
|
| 80 |
void MacroAssemblerX64::loadConstantSimd128Int(const SimdConstant& v, |
| 81 |
FloatRegister dest) { |
| 82 |
if (maybeInlineSimd128Int(v, dest)) { |
| 83 |
return; |
| 84 |
} |
| 85 |
vpRiprOpSimd128(v, dest, &X86Encoding::BaseAssemblerX64::vmovdqa_ripr); |
| 86 |
} |
| 87 |
|
| 88 |
void MacroAssemblerX64::loadConstantSimd128Float(const SimdConstant& v, |
| 89 |
FloatRegister dest) { |
| 90 |
if (maybeInlineSimd128Float(v, dest)) { |
| 91 |
return; |
| 92 |
} |
| 93 |
vpRiprOpSimd128(v, dest, &X86Encoding::BaseAssemblerX64::vmovaps_ripr); |
| 94 |
} |
| 95 |
|
| 96 |
void MacroAssemblerX64::vpaddbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 97 |
FloatRegister dest) { |
| 98 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpaddb_ripr); |
| 99 |
} |
| 100 |
|
| 101 |
void MacroAssemblerX64::vpaddwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 102 |
FloatRegister dest) { |
| 103 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpaddw_ripr); |
| 104 |
} |
| 105 |
|
| 106 |
void MacroAssemblerX64::vpadddSimd128(const SimdConstant& v, FloatRegister lhs, |
| 107 |
FloatRegister dest) { |
| 108 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpaddd_ripr); |
| 109 |
} |
| 110 |
|
| 111 |
void MacroAssemblerX64::vpaddqSimd128(const SimdConstant& v, FloatRegister lhs, |
| 112 |
FloatRegister dest) { |
| 113 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpaddq_ripr); |
| 114 |
} |
| 115 |
|
| 116 |
void MacroAssemblerX64::vpsubbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 117 |
FloatRegister dest) { |
| 118 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpsubb_ripr); |
| 119 |
} |
| 120 |
|
| 121 |
void MacroAssemblerX64::vpsubwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 122 |
FloatRegister dest) { |
| 123 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpsubw_ripr); |
| 124 |
} |
| 125 |
|
| 126 |
void MacroAssemblerX64::vpsubdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 127 |
FloatRegister dest) { |
| 128 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpsubd_ripr); |
| 129 |
} |
| 130 |
|
| 131 |
void MacroAssemblerX64::vpsubqSimd128(const SimdConstant& v, FloatRegister lhs, |
| 132 |
FloatRegister dest) { |
| 133 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpsubq_ripr); |
| 134 |
} |
| 135 |
|
| 136 |
void MacroAssemblerX64::vpmullwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 137 |
FloatRegister dest) { |
| 138 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpmullw_ripr); |
| 139 |
} |
| 140 |
|
| 141 |
void MacroAssemblerX64::vpmulldSimd128(const SimdConstant& v, FloatRegister lhs, |
| 142 |
FloatRegister dest) { |
| 143 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpmulld_ripr); |
| 144 |
} |
| 145 |
|
| 146 |
void MacroAssemblerX64::vpaddsbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 147 |
FloatRegister dest) { |
| 148 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpaddsb_ripr); |
| 149 |
} |
| 150 |
|
| 151 |
void MacroAssemblerX64::vpaddusbSimd128(const SimdConstant& v, |
| 152 |
FloatRegister lhs, FloatRegister dest) { |
| 153 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpaddusb_ripr); |
| 154 |
} |
| 155 |
|
| 156 |
void MacroAssemblerX64::vpaddswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 157 |
FloatRegister dest) { |
| 158 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpaddsw_ripr); |
| 159 |
} |
| 160 |
|
| 161 |
void MacroAssemblerX64::vpadduswSimd128(const SimdConstant& v, |
| 162 |
FloatRegister lhs, FloatRegister dest) { |
| 163 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpaddusw_ripr); |
| 164 |
} |
| 165 |
|
| 166 |
void MacroAssemblerX64::vpsubsbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 167 |
FloatRegister dest) { |
| 168 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpsubsb_ripr); |
| 169 |
} |
| 170 |
|
| 171 |
void MacroAssemblerX64::vpsubusbSimd128(const SimdConstant& v, |
| 172 |
FloatRegister lhs, FloatRegister dest) { |
| 173 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpsubusb_ripr); |
| 174 |
} |
| 175 |
|
| 176 |
void MacroAssemblerX64::vpsubswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 177 |
FloatRegister dest) { |
| 178 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpsubsw_ripr); |
| 179 |
} |
| 180 |
|
| 181 |
void MacroAssemblerX64::vpsubuswSimd128(const SimdConstant& v, |
| 182 |
FloatRegister lhs, FloatRegister dest) { |
| 183 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpsubusw_ripr); |
| 184 |
} |
| 185 |
|
| 186 |
void MacroAssemblerX64::vpminsbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 187 |
FloatRegister dest) { |
| 188 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpminsb_ripr); |
| 189 |
} |
| 190 |
|
| 191 |
void MacroAssemblerX64::vpminubSimd128(const SimdConstant& v, FloatRegister lhs, |
| 192 |
FloatRegister dest) { |
| 193 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpminub_ripr); |
| 194 |
} |
| 195 |
|
| 196 |
void MacroAssemblerX64::vpminswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 197 |
FloatRegister dest) { |
| 198 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpminsw_ripr); |
| 199 |
} |
| 200 |
|
| 201 |
void MacroAssemblerX64::vpminuwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 202 |
FloatRegister dest) { |
| 203 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpminuw_ripr); |
| 204 |
} |
| 205 |
|
| 206 |
void MacroAssemblerX64::vpminsdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 207 |
FloatRegister dest) { |
| 208 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpminsd_ripr); |
| 209 |
} |
| 210 |
|
| 211 |
void MacroAssemblerX64::vpminudSimd128(const SimdConstant& v, FloatRegister lhs, |
| 212 |
FloatRegister dest) { |
| 213 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpminud_ripr); |
| 214 |
} |
| 215 |
|
| 216 |
void MacroAssemblerX64::vpmaxsbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 217 |
FloatRegister dest) { |
| 218 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpmaxsb_ripr); |
| 219 |
} |
| 220 |
|
| 221 |
void MacroAssemblerX64::vpmaxubSimd128(const SimdConstant& v, FloatRegister lhs, |
| 222 |
FloatRegister dest) { |
| 223 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpmaxub_ripr); |
| 224 |
} |
| 225 |
|
| 226 |
void MacroAssemblerX64::vpmaxswSimd128(const SimdConstant& v, FloatRegister lhs, |
| 227 |
FloatRegister dest) { |
| 228 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpmaxsw_ripr); |
| 229 |
} |
| 230 |
|
| 231 |
void MacroAssemblerX64::vpmaxuwSimd128(const SimdConstant& v, FloatRegister lhs, |
| 232 |
FloatRegister dest) { |
| 233 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpmaxuw_ripr); |
| 234 |
} |
| 235 |
|
| 236 |
void MacroAssemblerX64::vpmaxsdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 237 |
FloatRegister dest) { |
| 238 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpmaxsd_ripr); |
| 239 |
} |
| 240 |
|
| 241 |
void MacroAssemblerX64::vpmaxudSimd128(const SimdConstant& v, FloatRegister lhs, |
| 242 |
FloatRegister dest) { |
| 243 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpmaxud_ripr); |
| 244 |
} |
| 245 |
|
| 246 |
void MacroAssemblerX64::vpandSimd128(const SimdConstant& v, FloatRegister lhs, |
| 247 |
FloatRegister dest) { |
| 248 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpand_ripr); |
| 249 |
} |
| 250 |
|
| 251 |
void MacroAssemblerX64::vpxorSimd128(const SimdConstant& v, FloatRegister lhs, |
| 252 |
FloatRegister dest) { |
| 253 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpxor_ripr); |
| 254 |
} |
| 255 |
|
| 256 |
void MacroAssemblerX64::vporSimd128(const SimdConstant& v, FloatRegister lhs, |
| 257 |
FloatRegister dest) { |
| 258 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpor_ripr); |
| 259 |
} |
| 260 |
|
| 261 |
void MacroAssemblerX64::vaddpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 262 |
FloatRegister dest) { |
| 263 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vaddps_ripr); |
| 264 |
} |
| 265 |
|
| 266 |
void MacroAssemblerX64::vaddpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 267 |
FloatRegister dest) { |
| 268 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vaddpd_ripr); |
| 269 |
} |
| 270 |
|
| 271 |
void MacroAssemblerX64::vsubpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 272 |
FloatRegister dest) { |
| 273 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vsubps_ripr); |
| 274 |
} |
| 275 |
|
| 276 |
void MacroAssemblerX64::vsubpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 277 |
FloatRegister dest) { |
| 278 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vsubpd_ripr); |
| 279 |
} |
| 280 |
|
| 281 |
void MacroAssemblerX64::vdivpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 282 |
FloatRegister dest) { |
| 283 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vdivps_ripr); |
| 284 |
} |
| 285 |
|
| 286 |
void MacroAssemblerX64::vdivpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 287 |
FloatRegister dest) { |
| 288 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vdivpd_ripr); |
| 289 |
} |
| 290 |
|
| 291 |
void MacroAssemblerX64::vmulpsSimd128(const SimdConstant& v, FloatRegister lhs, |
| 292 |
FloatRegister dest) { |
| 293 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vmulps_ripr); |
| 294 |
} |
| 295 |
|
| 296 |
void MacroAssemblerX64::vmulpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 297 |
FloatRegister dest) { |
| 298 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vmulpd_ripr); |
| 299 |
} |
| 300 |
|
| 301 |
void MacroAssemblerX64::vandpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 302 |
FloatRegister dest) { |
| 303 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vandpd_ripr); |
| 304 |
} |
| 305 |
|
| 306 |
void MacroAssemblerX64::vminpdSimd128(const SimdConstant& v, FloatRegister lhs, |
| 307 |
FloatRegister dest) { |
| 308 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vminpd_ripr); |
| 309 |
} |
| 310 |
|
| 311 |
void MacroAssemblerX64::vpacksswbSimd128(const SimdConstant& v, |
| 312 |
FloatRegister lhs, |
| 313 |
FloatRegister dest) { |
| 314 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpacksswb_ripr); |
| 315 |
} |
| 316 |
|
| 317 |
void MacroAssemblerX64::vpackuswbSimd128(const SimdConstant& v, |
| 318 |
FloatRegister lhs, |
| 319 |
FloatRegister dest) { |
| 320 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpackuswb_ripr); |
| 321 |
} |
| 322 |
|
| 323 |
void MacroAssemblerX64::vpackssdwSimd128(const SimdConstant& v, |
| 324 |
FloatRegister lhs, |
| 325 |
FloatRegister dest) { |
| 326 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpackssdw_ripr); |
| 327 |
} |
| 328 |
|
| 329 |
void MacroAssemblerX64::vpackusdwSimd128(const SimdConstant& v, |
| 330 |
FloatRegister lhs, |
| 331 |
FloatRegister dest) { |
| 332 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpackusdw_ripr); |
| 333 |
} |
| 334 |
|
| 335 |
void MacroAssemblerX64::vpunpckldqSimd128(const SimdConstant& v, |
| 336 |
FloatRegister lhs, |
| 337 |
FloatRegister dest) { |
| 338 |
vpRiprOpSimd128(v, lhs, dest, |
| 339 |
&X86Encoding::BaseAssemblerX64::vpunpckldq_ripr); |
| 340 |
} |
| 341 |
|
| 342 |
void MacroAssemblerX64::vunpcklpsSimd128(const SimdConstant& v, |
| 343 |
FloatRegister lhs, |
| 344 |
FloatRegister dest) { |
| 345 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vunpcklps_ripr); |
| 346 |
} |
| 347 |
|
| 348 |
void MacroAssemblerX64::vpshufbSimd128(const SimdConstant& v, FloatRegister lhs, |
| 349 |
FloatRegister dest) { |
| 350 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpshufb_ripr); |
| 351 |
} |
| 352 |
|
| 353 |
void MacroAssemblerX64::vptestSimd128(const SimdConstant& v, |
| 354 |
FloatRegister lhs) { |
| 355 |
vpRiprOpSimd128(v, lhs, &X86Encoding::BaseAssemblerX64::vptest_ripr); |
| 356 |
} |
| 357 |
|
| 358 |
void MacroAssemblerX64::vpmaddwdSimd128(const SimdConstant& v, |
| 359 |
FloatRegister lhs, FloatRegister dest) { |
| 360 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpmaddwd_ripr); |
| 361 |
} |
| 362 |
|
| 363 |
void MacroAssemblerX64::vpcmpeqbSimd128(const SimdConstant& v, |
| 364 |
FloatRegister lhs, FloatRegister dest) { |
| 365 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpcmpeqb_ripr); |
| 366 |
} |
| 367 |
|
| 368 |
void MacroAssemblerX64::vpcmpgtbSimd128(const SimdConstant& v, |
| 369 |
FloatRegister lhs, FloatRegister dest) { |
| 370 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpcmpgtb_ripr); |
| 371 |
} |
| 372 |
|
| 373 |
void MacroAssemblerX64::vpcmpeqwSimd128(const SimdConstant& v, |
| 374 |
FloatRegister lhs, FloatRegister dest) { |
| 375 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpcmpeqw_ripr); |
| 376 |
} |
| 377 |
|
| 378 |
void MacroAssemblerX64::vpcmpgtwSimd128(const SimdConstant& v, |
| 379 |
FloatRegister lhs, FloatRegister dest) { |
| 380 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpcmpgtw_ripr); |
| 381 |
} |
| 382 |
|
| 383 |
void MacroAssemblerX64::vpcmpeqdSimd128(const SimdConstant& v, |
| 384 |
FloatRegister lhs, FloatRegister dest) { |
| 385 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpcmpeqd_ripr); |
| 386 |
} |
| 387 |
|
| 388 |
void MacroAssemblerX64::vpcmpgtdSimd128(const SimdConstant& v, |
| 389 |
FloatRegister lhs, FloatRegister dest) { |
| 390 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpcmpgtd_ripr); |
| 391 |
} |
| 392 |
|
| 393 |
void MacroAssemblerX64::vcmpeqpsSimd128(const SimdConstant& v, |
| 394 |
FloatRegister lhs, FloatRegister dest) { |
| 395 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vcmpeqps_ripr); |
| 396 |
} |
| 397 |
|
| 398 |
void MacroAssemblerX64::vcmpneqpsSimd128(const SimdConstant& v, |
| 399 |
FloatRegister lhs, |
| 400 |
FloatRegister dest) { |
| 401 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vcmpneqps_ripr); |
| 402 |
} |
| 403 |
|
| 404 |
void MacroAssemblerX64::vcmpltpsSimd128(const SimdConstant& v, |
| 405 |
FloatRegister lhs, FloatRegister dest) { |
| 406 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vcmpltps_ripr); |
| 407 |
} |
| 408 |
|
| 409 |
void MacroAssemblerX64::vcmplepsSimd128(const SimdConstant& v, |
| 410 |
FloatRegister lhs, FloatRegister dest) { |
| 411 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vcmpleps_ripr); |
| 412 |
} |
| 413 |
|
| 414 |
void MacroAssemblerX64::vcmpgepsSimd128(const SimdConstant& v, |
| 415 |
FloatRegister lhs, FloatRegister dest) { |
| 416 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vcmpgeps_ripr); |
| 417 |
} |
| 418 |
|
| 419 |
void MacroAssemblerX64::vcmpeqpdSimd128(const SimdConstant& v, |
| 420 |
FloatRegister lhs, FloatRegister dest) { |
| 421 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vcmpeqpd_ripr); |
| 422 |
} |
| 423 |
|
| 424 |
void MacroAssemblerX64::vcmpneqpdSimd128(const SimdConstant& v, |
| 425 |
FloatRegister lhs, |
| 426 |
FloatRegister dest) { |
| 427 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vcmpneqpd_ripr); |
| 428 |
} |
| 429 |
|
| 430 |
void MacroAssemblerX64::vcmpltpdSimd128(const SimdConstant& v, |
| 431 |
FloatRegister lhs, FloatRegister dest) { |
| 432 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vcmpltpd_ripr); |
| 433 |
} |
| 434 |
|
| 435 |
void MacroAssemblerX64::vcmplepdSimd128(const SimdConstant& v, |
| 436 |
FloatRegister lhs, FloatRegister dest) { |
| 437 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vcmplepd_ripr); |
| 438 |
} |
| 439 |
|
| 440 |
void MacroAssemblerX64::vpmaddubswSimd128(const SimdConstant& v, |
| 441 |
FloatRegister lhs, |
| 442 |
FloatRegister dest) { |
| 443 |
vpRiprOpSimd128(v, lhs, dest, |
| 444 |
&X86Encoding::BaseAssemblerX64::vpmaddubsw_ripr); |
| 445 |
} |
| 446 |
|
| 447 |
void MacroAssemblerX64::vpmuludqSimd128(const SimdConstant& v, |
| 448 |
FloatRegister lhs, FloatRegister dest) { |
| 449 |
vpRiprOpSimd128(v, lhs, dest, &X86Encoding::BaseAssemblerX64::vpmuludq_ripr); |
| 450 |
} |
| 451 |
|
| 452 |
void MacroAssemblerX64::bindOffsets( |
| 453 |
const MacroAssemblerX86Shared::UsesVector& uses) { |
| 454 |
for (JmpSrc src : uses) { |
| 455 |
JmpDst dst(currentOffset()); |
| 456 |
// Using linkJump here is safe, as explained in the comment in |
| 457 |
// loadConstantDouble. |
| 458 |
masm.linkJump(src, dst); |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
void MacroAssemblerX64::finish() { |
| 463 |
if (!doubles_.empty()) { |
| 464 |
masm.haltingAlign(sizeof(double)); |
| 465 |
} |
| 466 |
for (const Double& d : doubles_) { |
| 467 |
bindOffsets(d.uses); |
| 468 |
masm.doubleConstant(d.value); |
| 469 |
} |
| 470 |
|
| 471 |
if (!floats_.empty()) { |
| 472 |
masm.haltingAlign(sizeof(float)); |
| 473 |
} |
| 474 |
for (const Float& f : floats_) { |
| 475 |
bindOffsets(f.uses); |
| 476 |
masm.floatConstant(f.value); |
| 477 |
} |
| 478 |
|
| 479 |
// SIMD memory values must be suitably aligned. |
| 480 |
if (!simds_.empty()) { |
| 481 |
masm.haltingAlign(SimdMemoryAlignment); |
| 482 |
} |
| 483 |
for (const SimdData& v : simds_) { |
| 484 |
bindOffsets(v.uses); |
| 485 |
masm.simd128Constant(v.value.bytes()); |
| 486 |
} |
| 487 |
|
| 488 |
MacroAssemblerX86Shared::finish(); |
| 489 |
} |
| 490 |
|
| 491 |
void MacroAssemblerX64::boxValue(JSValueType type, Register src, |
| 492 |
Register dest) { |
| 493 |
MOZ_ASSERT(src != dest); |
| 494 |
|
| 495 |
#ifdef DEBUG |
| 496 |
if (type == JSVAL_TYPE_INT32 || type == JSVAL_TYPE_BOOLEAN) { |
| 497 |
Label upper32BitsZeroed; |
| 498 |
movePtr(ImmWord(UINT32_MAX), dest); |
| 499 |
asMasm().branchPtr(Assembler::BelowOrEqual, src, dest, &upper32BitsZeroed); |
| 500 |
breakpoint(); |
| 501 |
bind(&upper32BitsZeroed); |
| 502 |
} |
| 503 |
#endif |
| 504 |
mov(ImmShiftedTag(type), dest); |
| 505 |
orq(src, dest); |
| 506 |
} |
| 507 |
|
| 508 |
void MacroAssemblerX64::handleFailureWithHandlerTail( |
| 509 |
Label* profilerExitTail, Label* bailoutTail, |
| 510 |
uint32_t* returnValueCheckOffset) { |
| 511 |
// Reserve space for exception information. |
| 512 |
subq(Imm32(sizeof(ResumeFromException)), rsp); |
| 513 |
movq(rsp, rax); |
| 514 |
|
| 515 |
// Call the handler. |
| 516 |
using Fn = void (*)(ResumeFromException* rfe); |
| 517 |
asMasm().setupUnalignedABICall(rcx); |
| 518 |
asMasm().passABIArg(rax); |
| 519 |
asMasm().callWithABI<Fn, HandleException>( |
| 520 |
ABIType::General, CheckUnsafeCallWithABI::DontCheckHasExitFrame); |
| 521 |
|
| 522 |
*returnValueCheckOffset = asMasm().currentOffset(); |
| 523 |
|
| 524 |
Label entryFrame; |
| 525 |
Label catch_; |
| 526 |
Label finally; |
| 527 |
Label returnBaseline; |
| 528 |
Label returnIon; |
| 529 |
Label bailout; |
| 530 |
Label wasmInterpEntry; |
| 531 |
Label wasmCatch; |
| 532 |
|
| 533 |
load32(Address(rsp, ResumeFromException::offsetOfKind()), rax); |
| 534 |
asMasm().branch32(Assembler::Equal, rax, |
| 535 |
Imm32(ExceptionResumeKind::EntryFrame), &entryFrame); |
| 536 |
asMasm().branch32(Assembler::Equal, rax, Imm32(ExceptionResumeKind::Catch), |
| 537 |
&catch_); |
| 538 |
asMasm().branch32(Assembler::Equal, rax, Imm32(ExceptionResumeKind::Finally), |
| 539 |
&finally); |
| 540 |
asMasm().branch32(Assembler::Equal, rax, |
| 541 |
Imm32(ExceptionResumeKind::ForcedReturnBaseline), |
| 542 |
&returnBaseline); |
| 543 |
asMasm().branch32(Assembler::Equal, rax, |
| 544 |
Imm32(ExceptionResumeKind::ForcedReturnIon), &returnIon); |
| 545 |
asMasm().branch32(Assembler::Equal, rax, Imm32(ExceptionResumeKind::Bailout), |
| 546 |
&bailout); |
| 547 |
asMasm().branch32(Assembler::Equal, rax, |
| 548 |
Imm32(ExceptionResumeKind::WasmInterpEntry), |
| 549 |
&wasmInterpEntry); |
| 550 |
asMasm().branch32(Assembler::Equal, rax, |
| 551 |
Imm32(ExceptionResumeKind::WasmCatch), &wasmCatch); |
| 552 |
|
| 553 |
breakpoint(); // Invalid kind. |
| 554 |
|
| 555 |
// No exception handler. Load the error value, restore state and return from |
| 556 |
// the entry frame. |
| 557 |
bind(&entryFrame); |
| 558 |
asMasm().moveValue(MagicValue(JS_ION_ERROR), JSReturnOperand); |
| 559 |
loadPtr(Address(rsp, ResumeFromException::offsetOfFramePointer()), rbp); |
| 560 |
loadPtr(Address(rsp, ResumeFromException::offsetOfStackPointer()), rsp); |
| 561 |
ret(); |
| 562 |
|
| 563 |
// If we found a catch handler, this must be a baseline frame. Restore state |
| 564 |
// and jump to the catch block. |
| 565 |
bind(&catch_); |
| 566 |
loadPtr(Address(rsp, ResumeFromException::offsetOfTarget()), rax); |
| 567 |
loadPtr(Address(rsp, ResumeFromException::offsetOfFramePointer()), rbp); |
| 568 |
loadPtr(Address(rsp, ResumeFromException::offsetOfStackPointer()), rsp); |
| 569 |
jmp(Operand(rax)); |
| 570 |
|
| 571 |
// If we found a finally block, this must be a baseline frame. Push three |
| 572 |
// values expected by the finally block: the exception, the exception stack, |
| 573 |
// and BooleanValue(true). |
| 574 |
bind(&finally); |
| 575 |
ValueOperand exception = ValueOperand(rcx); |
| 576 |
loadValue(Address(rsp, ResumeFromException::offsetOfException()), exception); |
| 577 |
|
| 578 |
ValueOperand exceptionStack = ValueOperand(rdx); |
| 579 |
loadValue(Address(rsp, ResumeFromException::offsetOfExceptionStack()), |
| 580 |
exceptionStack); |
| 581 |
|
| 582 |
loadPtr(Address(rsp, ResumeFromException::offsetOfTarget()), rax); |
| 583 |
loadPtr(Address(rsp, ResumeFromException::offsetOfFramePointer()), rbp); |
| 584 |
loadPtr(Address(rsp, ResumeFromException::offsetOfStackPointer()), rsp); |
| 585 |
|
| 586 |
pushValue(exception); |
| 587 |
pushValue(exceptionStack); |
| 588 |
pushValue(BooleanValue(true)); |
| 589 |
jmp(Operand(rax)); |
| 590 |
|
| 591 |
// Return BaselineFrame->returnValue() to the caller. |
| 592 |
// Used in debug mode and for GeneratorReturn. |
| 593 |
Label profilingInstrumentation; |
| 594 |
bind(&returnBaseline); |
| 595 |
loadPtr(Address(rsp, ResumeFromException::offsetOfFramePointer()), rbp); |
| 596 |
loadPtr(Address(rsp, ResumeFromException::offsetOfStackPointer()), rsp); |
| 597 |
loadValue(Address(rbp, BaselineFrame::reverseOffsetOfReturnValue()), |
| 598 |
JSReturnOperand); |
| 599 |
jmp(&profilingInstrumentation); |
| 600 |
|
| 601 |
// Return the given value to the caller. |
| 602 |
bind(&returnIon); |
| 603 |
loadValue(Address(rsp, ResumeFromException::offsetOfException()), |
| 604 |
JSReturnOperand); |
| 605 |
loadPtr(Address(rsp, ResumeFromException::offsetOfFramePointer()), rbp); |
| 606 |
loadPtr(Address(rsp, ResumeFromException::offsetOfStackPointer()), rsp); |
| 607 |
|
| 608 |
// If profiling is enabled, then update the lastProfilingFrame to refer to |
| 609 |
// caller frame before returning. This code is shared by ForcedReturnIon |
| 610 |
// and ForcedReturnBaseline. |
| 611 |
bind(&profilingInstrumentation); |
| 612 |
{ |
| 613 |
Label skipProfilingInstrumentation; |
| 614 |
AbsoluteAddress addressOfEnabled( |
| 615 |
asMasm().runtime()->geckoProfiler().addressOfEnabled()); |
| 616 |
asMasm().branch32(Assembler::Equal, addressOfEnabled, Imm32(0), |
| 617 |
&skipProfilingInstrumentation); |
| 618 |
jump(profilerExitTail); |
| 619 |
bind(&skipProfilingInstrumentation); |
| 620 |
} |
| 621 |
|
| 622 |
movq(rbp, rsp); |
| 623 |
pop(rbp); |
| 624 |
ret(); |
| 625 |
|
| 626 |
// If we are bailing out to baseline to handle an exception, jump to the |
| 627 |
// bailout tail stub. Load 1 (true) in ReturnReg to indicate success. |
| 628 |
bind(&bailout); |
| 629 |
loadPtr(Address(rsp, ResumeFromException::offsetOfBailoutInfo()), r9); |
| 630 |
loadPtr(Address(rsp, ResumeFromException::offsetOfStackPointer()), rsp); |
| 631 |
move32(Imm32(1), ReturnReg); |
| 632 |
jump(bailoutTail); |
| 633 |
|
| 634 |
// Reset SP and FP; SP is pointing to the unwound return address to the wasm |
| 635 |
// interpreter entry, so we can just ret(). |
| 636 |
bind(&wasmInterpEntry); |
| 637 |
loadPtr(Address(rsp, ResumeFromException::offsetOfFramePointer()), rbp); |
| 638 |
loadPtr(Address(rsp, ResumeFromException::offsetOfStackPointer()), rsp); |
| 639 |
movePtr(ImmPtr((const void*)wasm::InterpFailInstanceReg), InstanceReg); |
| 640 |
masm.ret(); |
| 641 |
|
| 642 |
// Found a wasm catch handler, restore state and jump to it. |
| 643 |
bind(&wasmCatch); |
| 644 |
wasm::GenerateJumpToCatchHandler(asMasm(), rsp, rax, rbx); |
| 645 |
} |
| 646 |
|
| 647 |
void MacroAssemblerX64::profilerEnterFrame(Register framePtr, |
| 648 |
Register scratch) { |
| 649 |
asMasm().loadJSContext(scratch); |
| 650 |
loadPtr(Address(scratch, offsetof(JSContext, profilingActivation_)), scratch); |
| 651 |
storePtr(framePtr, |
| 652 |
Address(scratch, JitActivation::offsetOfLastProfilingFrame())); |
| 653 |
storePtr(ImmPtr(nullptr), |
| 654 |
Address(scratch, JitActivation::offsetOfLastProfilingCallSite())); |
| 655 |
} |
| 656 |
|
| 657 |
void MacroAssemblerX64::profilerExitFrame() { |
| 658 |
jump(asMasm().runtime()->jitRuntime()->getProfilerExitFrameTail()); |
| 659 |
} |
| 660 |
|
| 661 |
Assembler::Condition MacroAssemblerX64::testStringTruthy( |
| 662 |
bool truthy, const ValueOperand& value) { |
| 663 |
ScratchRegisterScope scratch(asMasm()); |
| 664 |
unboxString(value, scratch); |
| 665 |
cmp32(Operand(scratch, JSString::offsetOfLength()), Imm32(0)); |
| 666 |
return truthy ? Assembler::NotEqual : Assembler::Equal; |
| 667 |
} |
| 668 |
|
| 669 |
Assembler::Condition MacroAssemblerX64::testBigIntTruthy( |
| 670 |
bool truthy, const ValueOperand& value) { |
| 671 |
ScratchRegisterScope scratch(asMasm()); |
| 672 |
unboxBigInt(value, scratch); |
| 673 |
cmp32(Operand(scratch, JS::BigInt::offsetOfDigitLength()), Imm32(0)); |
| 674 |
return truthy ? Assembler::NotEqual : Assembler::Equal; |
| 675 |
} |
| 676 |
|
| 677 |
MacroAssembler& MacroAssemblerX64::asMasm() { |
| 678 |
return *static_cast<MacroAssembler*>(this); |
| 679 |
} |
| 680 |
|
| 681 |
const MacroAssembler& MacroAssemblerX64::asMasm() const { |
| 682 |
return *static_cast<const MacroAssembler*>(this); |
| 683 |
} |
| 684 |
|
| 685 |
void MacroAssembler::subFromStackPtr(Imm32 imm32) { |
| 686 |
if (imm32.value) { |
| 687 |
// On windows, we cannot skip very far down the stack without touching the |
| 688 |
// memory pages in-between. This is a corner-case code for situations where |
| 689 |
// the Ion frame data for a piece of code is very large. To handle this |
| 690 |
// special case, for frames over 4k in size we allocate memory on the stack |
| 691 |
// incrementally, touching it as we go. |
| 692 |
// |
| 693 |
// When the amount is quite large, which it can be, we emit an actual loop, |
| 694 |
// in order to keep the function prologue compact. Compactness is a |
| 695 |
// requirement for eg Wasm's CodeRange data structure, which can encode only |
| 696 |
// 8-bit offsets. |
| 697 |
uint32_t amountLeft = imm32.value; |
| 698 |
uint32_t fullPages = amountLeft / 4096; |
| 699 |
if (fullPages <= 8) { |
| 700 |
while (amountLeft > 4096) { |
| 701 |
subq(Imm32(4096), StackPointer); |
| 702 |
store32(Imm32(0), Address(StackPointer, 0)); |
| 703 |
amountLeft -= 4096; |
| 704 |
} |
| 705 |
subq(Imm32(amountLeft), StackPointer); |
| 706 |
} else { |
| 707 |
ScratchRegisterScope scratch(*this); |
| 708 |
Label top; |
| 709 |
move32(Imm32(fullPages), scratch); |
| 710 |
bind(&top); |
| 711 |
subq(Imm32(4096), StackPointer); |
| 712 |
store32(Imm32(0), Address(StackPointer, 0)); |
| 713 |
subl(Imm32(1), scratch); |
| 714 |
j(Assembler::NonZero, &top); |
| 715 |
amountLeft -= fullPages * 4096; |
| 716 |
if (amountLeft) { |
| 717 |
subq(Imm32(amountLeft), StackPointer); |
| 718 |
} |
| 719 |
} |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
void MacroAssemblerX64::convertDoubleToPtr(FloatRegister src, Register dest, |
| 724 |
Label* fail, |
| 725 |
bool negativeZeroCheck) { |
| 726 |
// Check for -0.0 |
| 727 |
if (negativeZeroCheck) { |
| 728 |
branchNegativeZero(src, dest, fail); |
| 729 |
} |
| 730 |
|
| 731 |
ScratchDoubleScope scratch(asMasm()); |
| 732 |
vcvttsd2sq(src, dest); |
| 733 |
asMasm().convertInt64ToDouble(Register64(dest), scratch); |
| 734 |
vucomisd(scratch, src); |
| 735 |
j(Assembler::Parity, fail); |
| 736 |
j(Assembler::NotEqual, fail); |
| 737 |
} |
| 738 |
|
| 739 |
// This operation really consists of five phases, in order to enforce the |
| 740 |
// restriction that on x64, srcDest must be rax and rdx will be clobbered. |
| 741 |
// |
| 742 |
// Input: { rhs, lhsOutput } |
| 743 |
// |
| 744 |
// [PUSH] Preserve registers |
| 745 |
// [MOVE] Generate moves to specific registers |
| 746 |
// |
| 747 |
// [DIV] Input: { regForRhs, RAX } |
| 748 |
// [DIV] extend RAX into RDX |
| 749 |
// [DIV] x64 Division operator |
| 750 |
// [DIV] Ouptut: { RAX, RDX } |
| 751 |
// |
| 752 |
// [MOVE] Move specific registers to outputs |
| 753 |
// [POP] Restore registers |
| 754 |
// |
| 755 |
// Output: { lhsOutput, remainderOutput } |
| 756 |
void MacroAssemblerX64::flexibleDivMod64(Register rhs, Register lhsOutput, |
| 757 |
bool isUnsigned, bool isDiv) { |
| 758 |
if (lhsOutput == rhs) { |
| 759 |
movq(ImmWord(isDiv ? 1 : 0), lhsOutput); |
| 760 |
return; |
| 761 |
} |
| 762 |
|
| 763 |
// Choose a register that is neither rdx nor rax to hold the rhs; |
| 764 |
// rbx is chosen arbitrarily, and will be preserved if necessary. |
| 765 |
Register regForRhs = (rhs == rax || rhs == rdx) ? rbx : rhs; |
| 766 |
|
| 767 |
// Add registers we will be clobbering as live, but also remove the set we |
| 768 |
// do not restore. |
| 769 |
LiveGeneralRegisterSet preserve; |
| 770 |
preserve.add(rdx); |
| 771 |
preserve.add(rax); |
| 772 |
preserve.add(regForRhs); |
| 773 |
|
| 774 |
preserve.takeUnchecked(lhsOutput); |
| 775 |
|
| 776 |
asMasm().PushRegsInMask(preserve); |
| 777 |
|
| 778 |
// Shuffle input into place. |
| 779 |
asMasm().moveRegPair(lhsOutput, rhs, rax, regForRhs); |
| 780 |
if (oom()) { |
| 781 |
return; |
| 782 |
} |
| 783 |
|
| 784 |
// Sign extend rax into rdx to make (rdx:rax): idiv/udiv are 128-bit. |
| 785 |
if (isUnsigned) { |
| 786 |
movq(ImmWord(0), rdx); |
| 787 |
udivq(regForRhs); |
| 788 |
} else { |
| 789 |
cqo(); |
| 790 |
idivq(regForRhs); |
| 791 |
} |
| 792 |
|
| 793 |
Register result = isDiv ? rax : rdx; |
| 794 |
if (result != lhsOutput) { |
| 795 |
movq(result, lhsOutput); |
| 796 |
} |
| 797 |
|
| 798 |
asMasm().PopRegsInMask(preserve); |
| 799 |
} |
| 800 |
|
| 801 |
//{{{ check_macroassembler_style |
| 802 |
// =============================================================== |
| 803 |
// ABI function calls. |
| 804 |
|
| 805 |
void MacroAssembler::setupUnalignedABICall(Register scratch) { |
| 806 |
setupNativeABICall(); |
| 807 |
dynamicAlignment_ = true; |
| 808 |
|
| 809 |
movq(rsp, scratch); |
| 810 |
andq(Imm32(~(ABIStackAlignment - 1)), rsp); |
| 811 |
push(scratch); |
| 812 |
} |
| 813 |
|
| 814 |
void MacroAssembler::callWithABIPre(uint32_t* stackAdjust, bool callFromWasm) { |
| 815 |
MOZ_ASSERT(inCall_); |
| 816 |
uint32_t stackForCall = abiArgs_.stackBytesConsumedSoFar(); |
| 817 |
|
| 818 |
if (dynamicAlignment_) { |
| 819 |
// sizeof(intptr_t) accounts for the saved stack pointer pushed by |
| 820 |
// setupUnalignedABICall. |
| 821 |
stackForCall += ComputeByteAlignment(stackForCall + sizeof(intptr_t), |
| 822 |
ABIStackAlignment); |
| 823 |
} else { |
| 824 |
uint32_t alignmentAtPrologue = callFromWasm ? sizeof(wasm::Frame) : 0; |
| 825 |
stackForCall += ComputeByteAlignment( |
| 826 |
stackForCall + framePushed() + alignmentAtPrologue, ABIStackAlignment); |
| 827 |
} |
| 828 |
|
| 829 |
*stackAdjust = stackForCall; |
| 830 |
reserveStack(stackForCall); |
| 831 |
|
| 832 |
// Position all arguments. |
| 833 |
{ |
| 834 |
enoughMemory_ &= moveResolver_.resolve(); |
| 835 |
if (!enoughMemory_) { |
| 836 |
return; |
| 837 |
} |
| 838 |
|
| 839 |
MoveEmitter emitter(*this); |
| 840 |
emitter.emit(moveResolver_); |
| 841 |
emitter.finish(); |
| 842 |
} |
| 843 |
|
| 844 |
assertStackAlignment(ABIStackAlignment); |
| 845 |
} |
| 846 |
|
| 847 |
void MacroAssembler::callWithABIPost(uint32_t stackAdjust, ABIType result, |
| 848 |
bool callFromWasm) { |
| 849 |
freeStack(stackAdjust); |
| 850 |
if (dynamicAlignment_) { |
| 851 |
pop(rsp); |
| 852 |
} |
| 853 |
|
| 854 |
#ifdef DEBUG |
| 855 |
MOZ_ASSERT(inCall_); |
| 856 |
inCall_ = false; |
| 857 |
#endif |
| 858 |
} |
| 859 |
|
| 860 |
static bool IsIntArgReg(Register reg) { |
| 861 |
for (uint32_t i = 0; i < NumIntArgRegs; i++) { |
| 862 |
if (IntArgRegs[i] == reg) { |
| 863 |
return true; |
| 864 |
} |
| 865 |
} |
| 866 |
|
| 867 |
return false; |
| 868 |
} |
| 869 |
|
| 870 |
void MacroAssembler::callWithABINoProfiler(Register fun, ABIType result) { |
| 871 |
if (IsIntArgReg(fun)) { |
| 872 |
// Callee register may be clobbered for an argument. Move the callee to |
| 873 |
// r10, a volatile, non-argument register. |
| 874 |
propagateOOM(moveResolver_.addMove(MoveOperand(fun), MoveOperand(r10), |
| 875 |
MoveOp::GENERAL)); |
| 876 |
fun = r10; |
| 877 |
} |
| 878 |
|
| 879 |
MOZ_ASSERT(!IsIntArgReg(fun)); |
| 880 |
|
| 881 |
uint32_t stackAdjust; |
| 882 |
callWithABIPre(&stackAdjust); |
| 883 |
call(fun); |
| 884 |
callWithABIPost(stackAdjust, result); |
| 885 |
} |
| 886 |
|
| 887 |
void MacroAssembler::callWithABINoProfiler(const Address& fun, ABIType result) { |
| 888 |
Address safeFun = fun; |
| 889 |
if (IsIntArgReg(safeFun.base)) { |
| 890 |
// Callee register may be clobbered for an argument. Move the callee to |
| 891 |
// r10, a volatile, non-argument register. |
| 892 |
propagateOOM(moveResolver_.addMove(MoveOperand(fun.base), MoveOperand(r10), |
| 893 |
MoveOp::GENERAL)); |
| 894 |
safeFun.base = r10; |
| 895 |
} |
| 896 |
|
| 897 |
MOZ_ASSERT(!IsIntArgReg(safeFun.base)); |
| 898 |
|
| 899 |
uint32_t stackAdjust; |
| 900 |
callWithABIPre(&stackAdjust); |
| 901 |
call(safeFun); |
| 902 |
callWithABIPost(stackAdjust, result); |
| 903 |
} |
| 904 |
|
| 905 |
// =============================================================== |
| 906 |
// Move instructions |
| 907 |
|
| 908 |
void MacroAssembler::moveValue(const ValueOperand& src, |
| 909 |
const ValueOperand& dest) { |
| 910 |
if (src == dest) { |
| 911 |
return; |
| 912 |
} |
| 913 |
movq(src.valueReg(), dest.valueReg()); |
| 914 |
} |
| 915 |
|
| 916 |
void MacroAssembler::moveValue(const Value& src, const ValueOperand& dest) { |
| 917 |
movWithPatch(ImmWord(src.asRawBits()), dest.valueReg()); |
| 918 |
writeDataRelocation(src); |
| 919 |
} |
| 920 |
|
| 921 |
// =============================================================== |
| 922 |
// Arithmetic functions |
| 923 |
|
| 924 |
void MacroAssembler::flexibleQuotientPtr( |
| 925 |
Register rhs, Register srcDest, bool isUnsigned, |
| 926 |
const LiveRegisterSet& volatileLiveRegs) { |
| 927 |
flexibleDivMod64(rhs, srcDest, isUnsigned, /* isDiv= */ true); |
| 928 |
} |
| 929 |
|
| 930 |
void MacroAssembler::flexibleRemainderPtr( |
| 931 |
Register rhs, Register srcDest, bool isUnsigned, |
| 932 |
const LiveRegisterSet& volatileLiveRegs) { |
| 933 |
flexibleDivMod64(rhs, srcDest, isUnsigned, /* isDiv= */ false); |
| 934 |
} |
| 935 |
|
| 936 |
// =============================================================== |
| 937 |
// Branch functions |
| 938 |
|
| 939 |
void MacroAssembler::loadStoreBuffer(Register ptr, Register buffer) { |
| 940 |
if (ptr != buffer) { |
| 941 |
movePtr(ptr, buffer); |
| 942 |
} |
| 943 |
andPtr(Imm32(int32_t(~gc::ChunkMask)), buffer); |
| 944 |
loadPtr(Address(buffer, gc::ChunkStoreBufferOffset), buffer); |
| 945 |
} |
| 946 |
|
| 947 |
void MacroAssembler::branchPtrInNurseryChunk(Condition cond, Register ptr, |
| 948 |
Register temp, Label* label) { |
| 949 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 950 |
|
| 951 |
ScratchRegisterScope scratch(*this); |
| 952 |
MOZ_ASSERT(ptr != temp); |
| 953 |
MOZ_ASSERT(ptr != scratch); |
| 954 |
|
| 955 |
movePtr(ptr, scratch); |
| 956 |
andPtr(Imm32(int32_t(~gc::ChunkMask)), scratch); |
| 957 |
branchPtr(InvertCondition(cond), Address(scratch, gc::ChunkStoreBufferOffset), |
| 958 |
ImmWord(0), label); |
| 959 |
} |
| 960 |
|
| 961 |
template <typename T> |
| 962 |
void MacroAssembler::branchValueIsNurseryCellImpl(Condition cond, |
| 963 |
const T& value, Register temp, |
| 964 |
Label* label) { |
| 965 |
MOZ_ASSERT(cond == Assembler::Equal || cond == Assembler::NotEqual); |
| 966 |
MOZ_ASSERT(temp != InvalidReg); |
| 967 |
|
| 968 |
Label done; |
| 969 |
branchTestGCThing(Assembler::NotEqual, value, |
| 970 |
cond == Assembler::Equal ? &done : label); |
| 971 |
|
| 972 |
getGCThingValueChunk(value, temp); |
| 973 |
branchPtr(InvertCondition(cond), Address(temp, gc::ChunkStoreBufferOffset), |
| 974 |
ImmWord(0), label); |
| 975 |
|
| 976 |
bind(&done); |
| 977 |
} |
| 978 |
|
| 979 |
void MacroAssembler::branchValueIsNurseryCell(Condition cond, |
| 980 |
const Address& address, |
| 981 |
Register temp, Label* label) { |
| 982 |
branchValueIsNurseryCellImpl(cond, address, temp, label); |
| 983 |
} |
| 984 |
|
| 985 |
void MacroAssembler::branchValueIsNurseryCell(Condition cond, |
| 986 |
ValueOperand value, Register temp, |
| 987 |
Label* label) { |
| 988 |
branchValueIsNurseryCellImpl(cond, value, temp, label); |
| 989 |
} |
| 990 |
|
| 991 |
void MacroAssembler::branchTestValue(Condition cond, const ValueOperand& lhs, |
| 992 |
const Value& rhs, Label* label) { |
| 993 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 994 |
MOZ_ASSERT(!rhs.isNaN()); |
| 995 |
ScratchRegisterScope scratch(*this); |
| 996 |
MOZ_ASSERT(lhs.valueReg() != scratch); |
| 997 |
moveValue(rhs, ValueOperand(scratch)); |
| 998 |
cmpPtr(lhs.valueReg(), scratch); |
| 999 |
j(cond, label); |
| 1000 |
} |
| 1001 |
|
| 1002 |
void MacroAssembler::branchTestNaNValue(Condition cond, const ValueOperand& val, |
| 1003 |
Register temp, Label* label) { |
| 1004 |
MOZ_ASSERT(cond == Equal || cond == NotEqual); |
| 1005 |
ScratchRegisterScope scratch(*this); |
| 1006 |
|
| 1007 |
// When testing for NaN, we want to ignore the sign bit. |
| 1008 |
movq(ImmWord(~mozilla::FloatingPoint<double>::kSignBit), scratch); |
| 1009 |
andq(val.valueReg(), scratch); |
| 1010 |
|
| 1011 |
// Compare against a NaN with sign bit 0. |
| 1012 |
static_assert(JS::detail::CanonicalizedNaNSignBit == 0); |
| 1013 |
moveValue(DoubleValue(JS::GenericNaN()), ValueOperand(temp)); |
| 1014 |
cmpPtr(scratch, temp); |
| 1015 |
j(cond, label); |
| 1016 |
} |
| 1017 |
|
| 1018 |
// ======================================================================== |
| 1019 |
// Memory access primitives. |
| 1020 |
template <typename T> |
| 1021 |
void MacroAssembler::storeUnboxedValue(const ConstantOrRegister& value, |
| 1022 |
MIRType valueType, const T& dest) { |
| 1023 |
MOZ_ASSERT(valueType < MIRType::Value); |
| 1024 |
|
| 1025 |
if (valueType == MIRType::Double) { |
| 1026 |
boxDouble(value.reg().typedReg().fpu(), dest); |
| 1027 |
return; |
| 1028 |
} |
| 1029 |
|
| 1030 |
if (value.constant()) { |
| 1031 |
storeValue(value.value(), dest); |
| 1032 |
} else { |
| 1033 |
storeValue(ValueTypeFromMIRType(valueType), value.reg().typedReg().gpr(), |
| 1034 |
dest); |
| 1035 |
} |
| 1036 |
} |
| 1037 |
|
| 1038 |
template void MacroAssembler::storeUnboxedValue(const ConstantOrRegister& value, |
| 1039 |
MIRType valueType, |
| 1040 |
const Address& dest); |
| 1041 |
template void MacroAssembler::storeUnboxedValue( |
| 1042 |
const ConstantOrRegister& value, MIRType valueType, |
| 1043 |
const BaseObjectElementIndex& dest); |
| 1044 |
|
| 1045 |
void MacroAssembler::PushBoxed(FloatRegister reg) { |
| 1046 |
subq(Imm32(sizeof(double)), StackPointer); |
| 1047 |
boxDouble(reg, Address(StackPointer, 0)); |
| 1048 |
adjustFrame(sizeof(double)); |
| 1049 |
} |
| 1050 |
|
| 1051 |
// ======================================================================== |
| 1052 |
// wasm support |
| 1053 |
|
| 1054 |
void MacroAssembler::wasmLoad(const wasm::MemoryAccessDesc& access, |
| 1055 |
Operand srcAddr, AnyRegister out) { |
| 1056 |
// NOTE: the generated code must match the assembly code in gen_load in |
| 1057 |
// GenerateAtomicOperations.py |
| 1058 |
memoryBarrierBefore(access.sync()); |
| 1059 |
|
| 1060 |
MOZ_ASSERT_IF( |
| 1061 |
access.isZeroExtendSimd128Load(), |
| 1062 |
access.type() == Scalar::Float32 || access.type() == Scalar::Float64); |
| 1063 |
MOZ_ASSERT_IF( |
| 1064 |
access.isSplatSimd128Load(), |
| 1065 |
access.type() == Scalar::Uint8 || access.type() == Scalar::Uint16 || |
| 1066 |
access.type() == Scalar::Float32 || access.type() == Scalar::Float64); |
| 1067 |
MOZ_ASSERT_IF(access.isWidenSimd128Load(), access.type() == Scalar::Float64); |
| 1068 |
|
| 1069 |
switch (access.type()) { |
| 1070 |
case Scalar::Int8: |
| 1071 |
append(access, wasm::TrapMachineInsn::Load8, |
| 1072 |
FaultingCodeOffset(currentOffset())); |
| 1073 |
movsbl(srcAddr, out.gpr()); |
| 1074 |
break; |
| 1075 |
case Scalar::Uint8: |
| 1076 |
append(access, wasm::TrapMachineInsn::Load8, |
| 1077 |
FaultingCodeOffset(currentOffset())); |
| 1078 |
if (access.isSplatSimd128Load()) { |
| 1079 |
vbroadcastb(srcAddr, out.fpu()); |
| 1080 |
} else { |
| 1081 |
movzbl(srcAddr, out.gpr()); |
| 1082 |
} |
| 1083 |
break; |
| 1084 |
case Scalar::Int16: |
| 1085 |
append(access, wasm::TrapMachineInsn::Load16, |
| 1086 |
FaultingCodeOffset(currentOffset())); |
| 1087 |
movswl(srcAddr, out.gpr()); |
| 1088 |
break; |
| 1089 |
case Scalar::Uint16: |
| 1090 |
append(access, wasm::TrapMachineInsn::Load16, |
| 1091 |
FaultingCodeOffset(currentOffset())); |
| 1092 |
if (access.isSplatSimd128Load()) { |
| 1093 |
vbroadcastw(srcAddr, out.fpu()); |
| 1094 |
} else { |
| 1095 |
movzwl(srcAddr, out.gpr()); |
| 1096 |
} |
| 1097 |
break; |
| 1098 |
case Scalar::Int32: |
| 1099 |
case Scalar::Uint32: |
| 1100 |
append(access, wasm::TrapMachineInsn::Load32, |
| 1101 |
FaultingCodeOffset(currentOffset())); |
| 1102 |
movl(srcAddr, out.gpr()); |
| 1103 |
break; |
| 1104 |
case Scalar::Float32: |
| 1105 |
append(access, wasm::TrapMachineInsn::Load32, |
| 1106 |
FaultingCodeOffset(currentOffset())); |
| 1107 |
if (access.isSplatSimd128Load()) { |
| 1108 |
vbroadcastss(srcAddr, out.fpu()); |
| 1109 |
} else { |
| 1110 |
// vmovss does the right thing also for access.isZeroExtendSimd128Load() |
| 1111 |
vmovss(srcAddr, out.fpu()); |
| 1112 |
} |
| 1113 |
break; |
| 1114 |
case Scalar::Float64: |
| 1115 |
append(access, wasm::TrapMachineInsn::Load64, |
| 1116 |
FaultingCodeOffset(currentOffset())); |
| 1117 |
if (access.isSplatSimd128Load()) { |
| 1118 |
vmovddup(srcAddr, out.fpu()); |
| 1119 |
} else if (access.isWidenSimd128Load()) { |
| 1120 |
switch (access.widenSimdOp()) { |
| 1121 |
case wasm::SimdOp::V128Load8x8S: |
| 1122 |
vpmovsxbw(srcAddr, out.fpu()); |
| 1123 |
break; |
| 1124 |
case wasm::SimdOp::V128Load8x8U: |
| 1125 |
vpmovzxbw(srcAddr, out.fpu()); |
| 1126 |
break; |
| 1127 |
case wasm::SimdOp::V128Load16x4S: |
| 1128 |
vpmovsxwd(srcAddr, out.fpu()); |
| 1129 |
break; |
| 1130 |
case wasm::SimdOp::V128Load16x4U: |
| 1131 |
vpmovzxwd(srcAddr, out.fpu()); |
| 1132 |
break; |
| 1133 |
case wasm::SimdOp::V128Load32x2S: |
| 1134 |
vpmovsxdq(srcAddr, out.fpu()); |
| 1135 |
break; |
| 1136 |
case wasm::SimdOp::V128Load32x2U: |
| 1137 |
vpmovzxdq(srcAddr, out.fpu()); |
| 1138 |
break; |
| 1139 |
default: |
| 1140 |
MOZ_CRASH("Unexpected widening op for wasmLoad"); |
| 1141 |
} |
| 1142 |
} else { |
| 1143 |
// vmovsd does the right thing also for access.isZeroExtendSimd128Load() |
| 1144 |
vmovsd(srcAddr, out.fpu()); |
| 1145 |
} |
| 1146 |
break; |
| 1147 |
case Scalar::Simd128: { |
| 1148 |
FaultingCodeOffset fco = |
| 1149 |
MacroAssemblerX64::loadUnalignedSimd128(srcAddr, out.fpu()); |
| 1150 |
append(access, wasm::TrapMachineInsn::Load128, fco); |
| 1151 |
break; |
| 1152 |
} |
| 1153 |
case Scalar::Int64: |
| 1154 |
MOZ_CRASH("int64 loads must use load64"); |
| 1155 |
case Scalar::Float16: |
| 1156 |
case Scalar::BigInt64: |
| 1157 |
case Scalar::BigUint64: |
| 1158 |
case Scalar::Uint8Clamped: |
| 1159 |
case Scalar::MaxTypedArrayViewType: |
| 1160 |
MOZ_CRASH("unexpected scalar type for wasmLoad"); |
| 1161 |
} |
| 1162 |
|
| 1163 |
memoryBarrierAfter(access.sync()); |
| 1164 |
} |
| 1165 |
|
| 1166 |
void MacroAssembler::wasmLoadI64(const wasm::MemoryAccessDesc& access, |
| 1167 |
Operand srcAddr, Register64 out) { |
| 1168 |
// NOTE: the generated code must match the assembly code in gen_load in |
| 1169 |
// GenerateAtomicOperations.py |
| 1170 |
memoryBarrierBefore(access.sync()); |
| 1171 |
|
| 1172 |
switch (access.type()) { |
| 1173 |
case Scalar::Int8: |
| 1174 |
append(access, wasm::TrapMachineInsn::Load8, |
| 1175 |
FaultingCodeOffset(currentOffset())); |
| 1176 |
movsbq(srcAddr, out.reg); |
| 1177 |
break; |
| 1178 |
case Scalar::Uint8: |
| 1179 |
append(access, wasm::TrapMachineInsn::Load8, |
| 1180 |
FaultingCodeOffset(currentOffset())); |
| 1181 |
movzbq(srcAddr, out.reg); |
| 1182 |
break; |
| 1183 |
case Scalar::Int16: |
| 1184 |
append(access, wasm::TrapMachineInsn::Load16, |
| 1185 |
FaultingCodeOffset(currentOffset())); |
| 1186 |
movswq(srcAddr, out.reg); |
| 1187 |
break; |
| 1188 |
case Scalar::Uint16: |
| 1189 |
append(access, wasm::TrapMachineInsn::Load16, |
| 1190 |
FaultingCodeOffset(currentOffset())); |
| 1191 |
movzwq(srcAddr, out.reg); |
| 1192 |
break; |
| 1193 |
case Scalar::Int32: |
| 1194 |
append(access, wasm::TrapMachineInsn::Load32, |
| 1195 |
FaultingCodeOffset(currentOffset())); |
| 1196 |
movslq(srcAddr, out.reg); |
| 1197 |
break; |
| 1198 |
// Int32 to int64 moves zero-extend by default. |
| 1199 |
case Scalar::Uint32: |
| 1200 |
append(access, wasm::TrapMachineInsn::Load32, |
| 1201 |
FaultingCodeOffset(currentOffset())); |
| 1202 |
movl(srcAddr, out.reg); |
| 1203 |
break; |
| 1204 |
case Scalar::Int64: |
| 1205 |
append(access, wasm::TrapMachineInsn::Load64, |
| 1206 |
FaultingCodeOffset(currentOffset())); |
| 1207 |
movq(srcAddr, out.reg); |
| 1208 |
break; |
| 1209 |
case Scalar::Float16: |
| 1210 |
case Scalar::Float32: |
| 1211 |
case Scalar::Float64: |
| 1212 |
case Scalar::Simd128: |
| 1213 |
MOZ_CRASH("float loads must use wasmLoad"); |
| 1214 |
case Scalar::Uint8Clamped: |
| 1215 |
case Scalar::BigInt64: |
| 1216 |
case Scalar::BigUint64: |
| 1217 |
case Scalar::MaxTypedArrayViewType: |
| 1218 |
MOZ_CRASH("unexpected scalar type for wasmLoadI64"); |
| 1219 |
} |
| 1220 |
|
| 1221 |
memoryBarrierAfter(access.sync()); |
| 1222 |
} |
| 1223 |
|
| 1224 |
void MacroAssembler::wasmStore(const wasm::MemoryAccessDesc& access, |
| 1225 |
AnyRegister value, Operand dstAddr) { |
| 1226 |
// NOTE: the generated code must match the assembly code in gen_store in |
| 1227 |
// GenerateAtomicOperations.py |
| 1228 |
memoryBarrierBefore(access.sync()); |
| 1229 |
|
| 1230 |
switch (access.type()) { |
| 1231 |
case Scalar::Int8: |
| 1232 |
case Scalar::Uint8: |
| 1233 |
append(access, wasm::TrapMachineInsn::Store8, |
| 1234 |
FaultingCodeOffset(currentOffset())); |
| 1235 |
movb(value.gpr(), dstAddr); |
| 1236 |
break; |
| 1237 |
case Scalar::Int16: |
| 1238 |
case Scalar::Uint16: |
| 1239 |
append(access, wasm::TrapMachineInsn::Store16, |
| 1240 |
FaultingCodeOffset(currentOffset())); |
| 1241 |
movw(value.gpr(), dstAddr); |
| 1242 |
break; |
| 1243 |
case Scalar::Int32: |
| 1244 |
case Scalar::Uint32: |
| 1245 |
append(access, wasm::TrapMachineInsn::Store32, |
| 1246 |
FaultingCodeOffset(currentOffset())); |
| 1247 |
movl(value.gpr(), dstAddr); |
| 1248 |
break; |
| 1249 |
case Scalar::Int64: |
| 1250 |
append(access, wasm::TrapMachineInsn::Store64, |
| 1251 |
FaultingCodeOffset(currentOffset())); |
| 1252 |
movq(value.gpr(), dstAddr); |
| 1253 |
break; |
| 1254 |
case Scalar::Float32: { |
| 1255 |
FaultingCodeOffset fco = storeFloat32(value.fpu(), dstAddr); |
| 1256 |
append(access, wasm::TrapMachineInsn::Store32, fco); |
| 1257 |
break; |
| 1258 |
} |
| 1259 |
case Scalar::Float64: { |
| 1260 |
FaultingCodeOffset fco = storeDouble(value.fpu(), dstAddr); |
| 1261 |
append(access, wasm::TrapMachineInsn::Store64, fco); |
| 1262 |
break; |
| 1263 |
} |
| 1264 |
case Scalar::Simd128: { |
| 1265 |
FaultingCodeOffset fco = |
| 1266 |
MacroAssemblerX64::storeUnalignedSimd128(value.fpu(), dstAddr); |
| 1267 |
append(access, wasm::TrapMachineInsn::Store128, fco); |
| 1268 |
break; |
| 1269 |
} |
| 1270 |
case Scalar::Uint8Clamped: |
| 1271 |
case Scalar::BigInt64: |
| 1272 |
case Scalar::BigUint64: |
| 1273 |
case Scalar::Float16: |
| 1274 |
case Scalar::MaxTypedArrayViewType: |
| 1275 |
MOZ_CRASH("unexpected array type"); |
| 1276 |
} |
| 1277 |
|
| 1278 |
memoryBarrierAfter(access.sync()); |
| 1279 |
} |
| 1280 |
|
| 1281 |
void MacroAssembler::wasmTruncateDoubleToUInt32(FloatRegister input, |
| 1282 |
Register output, |
| 1283 |
bool isSaturating, |
| 1284 |
Label* oolEntry) { |
| 1285 |
vcvttsd2sq(input, output); |
| 1286 |
|
| 1287 |
// Check that the result is in the uint32_t range. |
| 1288 |
ScratchRegisterScope scratch(*this); |
| 1289 |
move32(Imm32(0xffffffff), scratch); |
| 1290 |
cmpq(scratch, output); |
| 1291 |
j(Assembler::Above, oolEntry); |
| 1292 |
} |
| 1293 |
|
| 1294 |
void MacroAssembler::wasmTruncateFloat32ToUInt32(FloatRegister input, |
| 1295 |
Register output, |
| 1296 |
bool isSaturating, |
| 1297 |
Label* oolEntry) { |
| 1298 |
vcvttss2sq(input, output); |
| 1299 |
|
| 1300 |
// Check that the result is in the uint32_t range. |
| 1301 |
ScratchRegisterScope scratch(*this); |
| 1302 |
move32(Imm32(0xffffffff), scratch); |
| 1303 |
cmpq(scratch, output); |
| 1304 |
j(Assembler::Above, oolEntry); |
| 1305 |
} |
| 1306 |
|
| 1307 |
void MacroAssembler::wasmTruncateDoubleToInt64( |
| 1308 |
FloatRegister input, Register64 output, bool isSaturating, Label* oolEntry, |
| 1309 |
Label* oolRejoin, FloatRegister tempReg) { |
| 1310 |
vcvttsd2sq(input, output.reg); |
| 1311 |
cmpq(Imm32(1), output.reg); |
| 1312 |
j(Assembler::Overflow, oolEntry); |
| 1313 |
bind(oolRejoin); |
| 1314 |
} |
| 1315 |
|
| 1316 |
void MacroAssembler::wasmTruncateFloat32ToInt64( |
| 1317 |
FloatRegister input, Register64 output, bool isSaturating, Label* oolEntry, |
| 1318 |
Label* oolRejoin, FloatRegister tempReg) { |
| 1319 |
vcvttss2sq(input, output.reg); |
| 1320 |
cmpq(Imm32(1), output.reg); |
| 1321 |
j(Assembler::Overflow, oolEntry); |
| 1322 |
bind(oolRejoin); |
| 1323 |
} |
| 1324 |
|
| 1325 |
void MacroAssembler::wasmTruncateDoubleToUInt64( |
| 1326 |
FloatRegister input, Register64 output, bool isSaturating, Label* oolEntry, |
| 1327 |
Label* oolRejoin, FloatRegister tempReg) { |
| 1328 |
// If the input < INT64_MAX, vcvttsd2sq will do the right thing, so |
| 1329 |
// we use it directly. Else, we subtract INT64_MAX, convert to int64, |
| 1330 |
// and then add INT64_MAX to the result. |
| 1331 |
|
| 1332 |
Label isLarge; |
| 1333 |
|
| 1334 |
ScratchDoubleScope scratch(*this); |
| 1335 |
loadConstantDouble(double(0x8000000000000000), scratch); |
| 1336 |
branchDouble(Assembler::DoubleGreaterThanOrEqual, input, scratch, &isLarge); |
| 1337 |
vcvttsd2sq(input, output.reg); |
| 1338 |
testq(output.reg, output.reg); |
| 1339 |
j(Assembler::Signed, oolEntry); |
| 1340 |
jump(oolRejoin); |
| 1341 |
|
| 1342 |
bind(&isLarge); |
| 1343 |
|
| 1344 |
moveDouble(input, tempReg); |
| 1345 |
vsubsd(scratch, tempReg, tempReg); |
| 1346 |
vcvttsd2sq(tempReg, output.reg); |
| 1347 |
testq(output.reg, output.reg); |
| 1348 |
j(Assembler::Signed, oolEntry); |
| 1349 |
or64(Imm64(0x8000000000000000), output); |
| 1350 |
|
| 1351 |
bind(oolRejoin); |
| 1352 |
} |
| 1353 |
|
| 1354 |
void MacroAssembler::wasmTruncateFloat32ToUInt64( |
| 1355 |
FloatRegister input, Register64 output, bool isSaturating, Label* oolEntry, |
| 1356 |
Label* oolRejoin, FloatRegister tempReg) { |
| 1357 |
// If the input < INT64_MAX, vcvttss2sq will do the right thing, so |
| 1358 |
// we use it directly. Else, we subtract INT64_MAX, convert to int64, |
| 1359 |
// and then add INT64_MAX to the result. |
| 1360 |
|
| 1361 |
Label isLarge; |
| 1362 |
|
| 1363 |
ScratchFloat32Scope scratch(*this); |
| 1364 |
loadConstantFloat32(float(0x8000000000000000), scratch); |
| 1365 |
branchFloat(Assembler::DoubleGreaterThanOrEqual, input, scratch, &isLarge); |
| 1366 |
vcvttss2sq(input, output.reg); |
| 1367 |
testq(output.reg, output.reg); |
| 1368 |
j(Assembler::Signed, oolEntry); |
| 1369 |
jump(oolRejoin); |
| 1370 |
|
| 1371 |
bind(&isLarge); |
| 1372 |
|
| 1373 |
moveFloat32(input, tempReg); |
| 1374 |
vsubss(scratch, tempReg, tempReg); |
| 1375 |
vcvttss2sq(tempReg, output.reg); |
| 1376 |
testq(output.reg, output.reg); |
| 1377 |
j(Assembler::Signed, oolEntry); |
| 1378 |
or64(Imm64(0x8000000000000000), output); |
| 1379 |
|
| 1380 |
bind(oolRejoin); |
| 1381 |
} |
| 1382 |
|
| 1383 |
void MacroAssembler::widenInt32(Register r) { |
| 1384 |
move32To64ZeroExtend(r, Register64(r)); |
| 1385 |
} |
| 1386 |
|
| 1387 |
// ======================================================================== |
| 1388 |
// Convert floating point. |
| 1389 |
|
| 1390 |
void MacroAssembler::convertInt64ToDouble(Register64 input, |
| 1391 |
FloatRegister output) { |
| 1392 |
// Zero the output register to break dependencies, see convertInt32ToDouble. |
| 1393 |
zeroDouble(output); |
| 1394 |
|
| 1395 |
vcvtsq2sd(input.reg, output, output); |
| 1396 |
} |
| 1397 |
|
| 1398 |
void MacroAssembler::convertInt64ToFloat32(Register64 input, |
| 1399 |
FloatRegister output) { |
| 1400 |
// Zero the output register to break dependencies, see convertInt32ToDouble. |
| 1401 |
zeroFloat32(output); |
| 1402 |
|
| 1403 |
vcvtsq2ss(input.reg, output, output); |
| 1404 |
} |
| 1405 |
|
| 1406 |
bool MacroAssembler::convertUInt64ToDoubleNeedsTemp() { return true; } |
| 1407 |
|
| 1408 |
void MacroAssembler::convertUInt64ToDouble(Register64 input, |
| 1409 |
FloatRegister output, |
| 1410 |
Register temp) { |
| 1411 |
// Zero the output register to break dependencies, see convertInt32ToDouble. |
| 1412 |
zeroDouble(output); |
| 1413 |
|
| 1414 |
// If the input's sign bit is not set we use vcvtsq2sd directly. |
| 1415 |
// Else, we divide by 2 and keep the LSB, convert to double, and multiply |
| 1416 |
// the result by 2. |
| 1417 |
Label done; |
| 1418 |
Label isSigned; |
| 1419 |
|
| 1420 |
testq(input.reg, input.reg); |
| 1421 |
j(Assembler::Signed, &isSigned); |
| 1422 |
vcvtsq2sd(input.reg, output, output); |
| 1423 |
jump(&done); |
| 1424 |
|
| 1425 |
bind(&isSigned); |
| 1426 |
|
| 1427 |
ScratchRegisterScope scratch(*this); |
| 1428 |
mov(input.reg, scratch); |
| 1429 |
mov(input.reg, temp); |
| 1430 |
shrq(Imm32(1), scratch); |
| 1431 |
andq(Imm32(1), temp); |
| 1432 |
orq(temp, scratch); |
| 1433 |
|
| 1434 |
vcvtsq2sd(scratch, output, output); |
| 1435 |
vaddsd(output, output, output); |
| 1436 |
|
| 1437 |
bind(&done); |
| 1438 |
} |
| 1439 |
|
| 1440 |
void MacroAssembler::convertUInt64ToFloat32(Register64 input, |
| 1441 |
FloatRegister output, |
| 1442 |
Register temp) { |
| 1443 |
// Zero the output register to break dependencies, see convertInt32ToDouble. |
| 1444 |
zeroFloat32(output); |
| 1445 |
|
| 1446 |
// See comment in convertUInt64ToDouble. |
| 1447 |
Label done; |
| 1448 |
Label isSigned; |
| 1449 |
|
| 1450 |
testq(input.reg, input.reg); |
| 1451 |
j(Assembler::Signed, &isSigned); |
| 1452 |
vcvtsq2ss(input.reg, output, output); |
| 1453 |
jump(&done); |
| 1454 |
|
| 1455 |
bind(&isSigned); |
| 1456 |
|
| 1457 |
ScratchRegisterScope scratch(*this); |
| 1458 |
mov(input.reg, scratch); |
| 1459 |
mov(input.reg, temp); |
| 1460 |
shrq(Imm32(1), scratch); |
| 1461 |
andq(Imm32(1), temp); |
| 1462 |
orq(temp, scratch); |
| 1463 |
|
| 1464 |
vcvtsq2ss(scratch, output, output); |
| 1465 |
vaddss(output, output, output); |
| 1466 |
|
| 1467 |
bind(&done); |
| 1468 |
} |
| 1469 |
|
| 1470 |
void MacroAssembler::convertIntPtrToDouble(Register src, FloatRegister dest) { |
| 1471 |
convertInt64ToDouble(Register64(src), dest); |
| 1472 |
} |
| 1473 |
|
| 1474 |
// ======================================================================== |
| 1475 |
// Primitive atomic operations. |
| 1476 |
|
| 1477 |
void MacroAssembler::wasmCompareExchange64(const wasm::MemoryAccessDesc& access, |
| 1478 |
const Address& mem, |
| 1479 |
Register64 expected, |
| 1480 |
Register64 replacement, |
| 1481 |
Register64 output) { |
| 1482 |
MOZ_ASSERT(output.reg == rax); |
| 1483 |
if (expected != output) { |
| 1484 |
movq(expected.reg, output.reg); |
| 1485 |
} |
| 1486 |
append(access, wasm::TrapMachineInsn::Atomic, |
| 1487 |
FaultingCodeOffset(currentOffset())); |
| 1488 |
lock_cmpxchgq(replacement.reg, Operand(mem)); |
| 1489 |
} |
| 1490 |
|
| 1491 |
void MacroAssembler::wasmCompareExchange64(const wasm::MemoryAccessDesc& access, |
| 1492 |
const BaseIndex& mem, |
| 1493 |
Register64 expected, |
| 1494 |
Register64 replacement, |
| 1495 |
Register64 output) { |
| 1496 |
MOZ_ASSERT(output.reg == rax); |
| 1497 |
if (expected != output) { |
| 1498 |
movq(expected.reg, output.reg); |
| 1499 |
} |
| 1500 |
append(access, wasm::TrapMachineInsn::Atomic, |
| 1501 |
FaultingCodeOffset(currentOffset())); |
| 1502 |
lock_cmpxchgq(replacement.reg, Operand(mem)); |
| 1503 |
} |
| 1504 |
|
| 1505 |
void MacroAssembler::wasmAtomicExchange64(const wasm::MemoryAccessDesc& access, |
| 1506 |
const Address& mem, Register64 value, |
| 1507 |
Register64 output) { |
| 1508 |
if (value != output) { |
| 1509 |
movq(value.reg, output.reg); |
| 1510 |
} |
| 1511 |
append(access, wasm::TrapMachineInsn::Atomic, |
| 1512 |
FaultingCodeOffset(masm.currentOffset())); |
| 1513 |
xchgq(output.reg, Operand(mem)); |
| 1514 |
} |
| 1515 |
|
| 1516 |
void MacroAssembler::wasmAtomicExchange64(const wasm::MemoryAccessDesc& access, |
| 1517 |
const BaseIndex& mem, |
| 1518 |
Register64 value, Register64 output) { |
| 1519 |
if (value != output) { |
| 1520 |
movq(value.reg, output.reg); |
| 1521 |
} |
| 1522 |
append(access, wasm::TrapMachineInsn::Atomic, |
| 1523 |
FaultingCodeOffset(masm.currentOffset())); |
| 1524 |
xchgq(output.reg, Operand(mem)); |
| 1525 |
} |
| 1526 |
|
| 1527 |
template <typename T> |
| 1528 |
static void AtomicFetchOp64(MacroAssembler& masm, |
| 1529 |
const wasm::MemoryAccessDesc* access, AtomicOp op, |
| 1530 |
Register value, const T& mem, Register temp, |
| 1531 |
Register output) { |
| 1532 |
// NOTE: the generated code must match the assembly code in gen_fetchop in |
| 1533 |
// GenerateAtomicOperations.py |
| 1534 |
if (op == AtomicOp::Add) { |
| 1535 |
if (value != output) { |
| 1536 |
masm.movq(value, output); |
| 1537 |
} |
| 1538 |
if (access) { |
| 1539 |
masm.append(*access, wasm::TrapMachineInsn::Atomic, |
| 1540 |
FaultingCodeOffset(masm.currentOffset())); |
| 1541 |
} |
| 1542 |
masm.lock_xaddq(output, Operand(mem)); |
| 1543 |
} else if (op == AtomicOp::Sub) { |
| 1544 |
if (value != output) { |
| 1545 |
masm.movq(value, output); |
| 1546 |
} |
| 1547 |
masm.negq(output); |
| 1548 |
if (access) { |
| 1549 |
masm.append(*access, wasm::TrapMachineInsn::Atomic, |
| 1550 |
FaultingCodeOffset(masm.currentOffset())); |
| 1551 |
} |
| 1552 |
masm.lock_xaddq(output, Operand(mem)); |
| 1553 |
} else { |
| 1554 |
Label again; |
| 1555 |
MOZ_ASSERT(output == rax); |
| 1556 |
MOZ_ASSERT(value != output); |
| 1557 |
MOZ_ASSERT(value != temp); |
| 1558 |
MOZ_ASSERT(temp != output); |
| 1559 |
if (access) { |
| 1560 |
masm.append(*access, wasm::TrapMachineInsn::Load64, |
| 1561 |
FaultingCodeOffset(masm.currentOffset())); |
| 1562 |
} |
| 1563 |
masm.movq(Operand(mem), rax); |
| 1564 |
masm.bind(&again); |
| 1565 |
masm.movq(rax, temp); |
| 1566 |
switch (op) { |
| 1567 |
case AtomicOp::And: |
| 1568 |
masm.andq(value, temp); |
| 1569 |
break; |
| 1570 |
case AtomicOp::Or: |
| 1571 |
masm.orq(value, temp); |
| 1572 |
break; |
| 1573 |
case AtomicOp::Xor: |
| 1574 |
masm.xorq(value, temp); |
| 1575 |
break; |
| 1576 |
default: |
| 1577 |
MOZ_CRASH(); |
| 1578 |
} |
| 1579 |
masm.lock_cmpxchgq(temp, Operand(mem)); |
| 1580 |
masm.j(MacroAssembler::NonZero, &again); |
| 1581 |
} |
| 1582 |
} |
| 1583 |
|
| 1584 |
void MacroAssembler::wasmAtomicFetchOp64(const wasm::MemoryAccessDesc& access, |
| 1585 |
AtomicOp op, Register64 value, |
| 1586 |
const Address& mem, Register64 temp, |
| 1587 |
Register64 output) { |
| 1588 |
AtomicFetchOp64(*this, &access, op, value.reg, mem, temp.reg, output.reg); |
| 1589 |
} |
| 1590 |
|
| 1591 |
void MacroAssembler::wasmAtomicFetchOp64(const wasm::MemoryAccessDesc& access, |
| 1592 |
AtomicOp op, Register64 value, |
| 1593 |
const BaseIndex& mem, Register64 temp, |
| 1594 |
Register64 output) { |
| 1595 |
AtomicFetchOp64(*this, &access, op, value.reg, mem, temp.reg, output.reg); |
| 1596 |
} |
| 1597 |
|
| 1598 |
template <typename T> |
| 1599 |
static void AtomicEffectOp64(MacroAssembler& masm, |
| 1600 |
const wasm::MemoryAccessDesc* access, AtomicOp op, |
| 1601 |
Register value, const T& mem) { |
| 1602 |
if (access) { |
| 1603 |
masm.append(*access, wasm::TrapMachineInsn::Atomic, |
| 1604 |
FaultingCodeOffset(masm.currentOffset())); |
| 1605 |
} |
| 1606 |
switch (op) { |
| 1607 |
case AtomicOp::Add: |
| 1608 |
masm.lock_addq(value, Operand(mem)); |
| 1609 |
break; |
| 1610 |
case AtomicOp::Sub: |
| 1611 |
masm.lock_subq(value, Operand(mem)); |
| 1612 |
break; |
| 1613 |
case AtomicOp::And: |
| 1614 |
masm.lock_andq(value, Operand(mem)); |
| 1615 |
break; |
| 1616 |
case AtomicOp::Or: |
| 1617 |
masm.lock_orq(value, Operand(mem)); |
| 1618 |
break; |
| 1619 |
case AtomicOp::Xor: |
| 1620 |
masm.lock_xorq(value, Operand(mem)); |
| 1621 |
break; |
| 1622 |
default: |
| 1623 |
MOZ_CRASH(); |
| 1624 |
} |
| 1625 |
} |
| 1626 |
|
| 1627 |
void MacroAssembler::wasmAtomicEffectOp64(const wasm::MemoryAccessDesc& access, |
| 1628 |
AtomicOp op, Register64 value, |
| 1629 |
const BaseIndex& mem) { |
| 1630 |
AtomicEffectOp64(*this, &access, op, value.reg, mem); |
| 1631 |
} |
| 1632 |
|
| 1633 |
void MacroAssembler::compareExchange64(Synchronization, const Address& mem, |
| 1634 |
Register64 expected, |
| 1635 |
Register64 replacement, |
| 1636 |
Register64 output) { |
| 1637 |
// NOTE: the generated code must match the assembly code in gen_cmpxchg in |
| 1638 |
// GenerateAtomicOperations.py |
| 1639 |
MOZ_ASSERT(output.reg == rax); |
| 1640 |
if (expected != output) { |
| 1641 |
movq(expected.reg, output.reg); |
| 1642 |
} |
| 1643 |
lock_cmpxchgq(replacement.reg, Operand(mem)); |
| 1644 |
} |
| 1645 |
|
| 1646 |
void MacroAssembler::compareExchange64(Synchronization, const BaseIndex& mem, |
| 1647 |
Register64 expected, |
| 1648 |
Register64 replacement, |
| 1649 |
Register64 output) { |
| 1650 |
MOZ_ASSERT(output.reg == rax); |
| 1651 |
if (expected != output) { |
| 1652 |
movq(expected.reg, output.reg); |
| 1653 |
} |
| 1654 |
lock_cmpxchgq(replacement.reg, Operand(mem)); |
| 1655 |
} |
| 1656 |
|
| 1657 |
void MacroAssembler::atomicExchange64(Synchronization, const Address& mem, |
| 1658 |
Register64 value, Register64 output) { |
| 1659 |
// NOTE: the generated code must match the assembly code in gen_exchange in |
| 1660 |
// GenerateAtomicOperations.py |
| 1661 |
if (value != output) { |
| 1662 |
movq(value.reg, output.reg); |
| 1663 |
} |
| 1664 |
xchgq(output.reg, Operand(mem)); |
| 1665 |
} |
| 1666 |
|
| 1667 |
void MacroAssembler::atomicExchange64(Synchronization, const BaseIndex& mem, |
| 1668 |
Register64 value, Register64 output) { |
| 1669 |
if (value != output) { |
| 1670 |
movq(value.reg, output.reg); |
| 1671 |
} |
| 1672 |
xchgq(output.reg, Operand(mem)); |
| 1673 |
} |
| 1674 |
|
| 1675 |
void MacroAssembler::atomicFetchOp64(Synchronization sync, AtomicOp op, |
| 1676 |
Register64 value, const Address& mem, |
| 1677 |
Register64 temp, Register64 output) { |
| 1678 |
AtomicFetchOp64(*this, nullptr, op, value.reg, mem, temp.reg, output.reg); |
| 1679 |
} |
| 1680 |
|
| 1681 |
void MacroAssembler::atomicFetchOp64(Synchronization sync, AtomicOp op, |
| 1682 |
Register64 value, const BaseIndex& mem, |
| 1683 |
Register64 temp, Register64 output) { |
| 1684 |
AtomicFetchOp64(*this, nullptr, op, value.reg, mem, temp.reg, output.reg); |
| 1685 |
} |
| 1686 |
|
| 1687 |
void MacroAssembler::atomicEffectOp64(Synchronization sync, AtomicOp op, |
| 1688 |
Register64 value, const Address& mem) { |
| 1689 |
AtomicEffectOp64(*this, nullptr, op, value.reg, mem); |
| 1690 |
} |
| 1691 |
|
| 1692 |
void MacroAssembler::atomicEffectOp64(Synchronization sync, AtomicOp op, |
| 1693 |
Register64 value, const BaseIndex& mem) { |
| 1694 |
AtomicEffectOp64(*this, nullptr, op, value.reg, mem); |
| 1695 |
} |
| 1696 |
|
| 1697 |
CodeOffset MacroAssembler::moveNearAddressWithPatch(Register dest) { |
| 1698 |
return leaRipRelative(dest); |
| 1699 |
} |
| 1700 |
|
| 1701 |
void MacroAssembler::patchNearAddressMove(CodeLocationLabel loc, |
| 1702 |
CodeLocationLabel target) { |
| 1703 |
ptrdiff_t off = target - loc; |
| 1704 |
MOZ_ASSERT(off > ptrdiff_t(INT32_MIN)); |
| 1705 |
MOZ_ASSERT(off < ptrdiff_t(INT32_MAX)); |
| 1706 |
PatchWrite_Imm32(loc, Imm32(off)); |
| 1707 |
} |
| 1708 |
|
| 1709 |
void MacroAssembler::wasmBoundsCheck64(Condition cond, Register64 index, |
| 1710 |
Register64 boundsCheckLimit, Label* ok) { |
| 1711 |
cmpPtr(index.reg, boundsCheckLimit.reg); |
| 1712 |
j(cond, ok); |
| 1713 |
if (JitOptions.spectreIndexMasking) { |
| 1714 |
cmovCCq(cond, Operand(boundsCheckLimit.reg), index.reg); |
| 1715 |
} |
| 1716 |
} |
| 1717 |
|
| 1718 |
void MacroAssembler::wasmBoundsCheck64(Condition cond, Register64 index, |
| 1719 |
Address boundsCheckLimit, Label* ok) { |
| 1720 |
cmpPtr(index.reg, Operand(boundsCheckLimit)); |
| 1721 |
j(cond, ok); |
| 1722 |
if (JitOptions.spectreIndexMasking) { |
| 1723 |
cmovCCq(cond, Operand(boundsCheckLimit), index.reg); |
| 1724 |
} |
| 1725 |
} |
| 1726 |
|
| 1727 |
void MacroAssembler::wasmMarkCallAsSlow() { |
| 1728 |
static_assert(InstanceReg == r14); |
| 1729 |
orPtr(Imm32(0), r14); |
| 1730 |
} |
| 1731 |
|
| 1732 |
const int32_t SlowCallMarker = 0x00ce8349; // OR r14, 0 |
| 1733 |
|
| 1734 |
void MacroAssembler::wasmCheckSlowCallsite(Register ra, Label* notSlow, |
| 1735 |
Register temp1, Register temp2) { |
| 1736 |
// Check if RA has slow marker. |
| 1737 |
cmp32(Address(ra, 0), Imm32(SlowCallMarker)); |
| 1738 |
j(Assembler::NotEqual, notSlow); |
| 1739 |
} |
| 1740 |
|
| 1741 |
// ======================================================================== |
| 1742 |
// Integer compare-then-conditionally-load/move operations. |
| 1743 |
|
| 1744 |
// cmpMove, Cond-Reg-Reg-Reg-Reg cases |
| 1745 |
|
| 1746 |
template <size_t CmpSize, size_t MoveSize> |
| 1747 |
void MacroAssemblerX64::cmpMove(Condition cond, Register lhs, Register rhs, |
| 1748 |
Register falseVal, Register trueValAndDest) { |
| 1749 |
if constexpr (CmpSize == 32) { |
| 1750 |
cmp32(lhs, rhs); |
| 1751 |
} else { |
| 1752 |
static_assert(CmpSize == 64); |
| 1753 |
cmpPtr(lhs, rhs); |
| 1754 |
} |
| 1755 |
if constexpr (MoveSize == 32) { |
| 1756 |
cmovCCl(cond, Operand(falseVal), trueValAndDest); |
| 1757 |
} else { |
| 1758 |
static_assert(MoveSize == 64); |
| 1759 |
cmovCCq(cond, Operand(falseVal), trueValAndDest); |
| 1760 |
} |
| 1761 |
} |
| 1762 |
template void MacroAssemblerX64::cmpMove<32, 32>(Condition cond, Register lhs, |
| 1763 |
Register rhs, |
| 1764 |
Register falseVal, |
| 1765 |
Register trueValAndDest); |
| 1766 |
template void MacroAssemblerX64::cmpMove<32, 64>(Condition cond, Register lhs, |
| 1767 |
Register rhs, |
| 1768 |
Register falseVal, |
| 1769 |
Register trueValAndDest); |
| 1770 |
template void MacroAssemblerX64::cmpMove<64, 32>(Condition cond, Register lhs, |
| 1771 |
Register rhs, |
| 1772 |
Register falseVal, |
| 1773 |
Register trueValAndDest); |
| 1774 |
template void MacroAssemblerX64::cmpMove<64, 64>(Condition cond, Register lhs, |
| 1775 |
Register rhs, |
| 1776 |
Register falseVal, |
| 1777 |
Register trueValAndDest); |
| 1778 |
|
| 1779 |
// cmpMove, Cond-Reg-Addr-Reg-Reg cases |
| 1780 |
|
| 1781 |
template <size_t CmpSize, size_t MoveSize> |
| 1782 |
void MacroAssemblerX64::cmpMove(Condition cond, Register lhs, |
| 1783 |
const Address& rhs, Register falseVal, |
| 1784 |
Register trueValAndDest) { |
| 1785 |
if constexpr (CmpSize == 32) { |
| 1786 |
cmp32(lhs, Operand(rhs)); |
| 1787 |
} else { |
| 1788 |
static_assert(CmpSize == 64); |
| 1789 |
cmpPtr(lhs, Operand(rhs)); |
| 1790 |
} |
| 1791 |
if constexpr (MoveSize == 32) { |
| 1792 |
cmovCCl(cond, Operand(falseVal), trueValAndDest); |
| 1793 |
} else { |
| 1794 |
static_assert(MoveSize == 64); |
| 1795 |
cmovCCq(cond, Operand(falseVal), trueValAndDest); |
| 1796 |
} |
| 1797 |
} |
| 1798 |
template void MacroAssemblerX64::cmpMove<32, 32>(Condition cond, Register lhs, |
| 1799 |
const Address& rhs, |
| 1800 |
Register falseVal, |
| 1801 |
Register trueValAndDest); |
| 1802 |
template void MacroAssemblerX64::cmpMove<32, 64>(Condition cond, Register lhs, |
| 1803 |
const Address& rhs, |
| 1804 |
Register falseVal, |
| 1805 |
Register trueValAndDest); |
| 1806 |
template void MacroAssemblerX64::cmpMove<64, 32>(Condition cond, Register lhs, |
| 1807 |
const Address& rhs, |
| 1808 |
Register falseVal, |
| 1809 |
Register trueValAndDest); |
| 1810 |
template void MacroAssemblerX64::cmpMove<64, 64>(Condition cond, Register lhs, |
| 1811 |
const Address& rhs, |
| 1812 |
Register falseVal, |
| 1813 |
Register trueValAndDest); |
| 1814 |
|
| 1815 |
// cmpLoad, Cond-Reg-Reg-Addr-Reg cases |
| 1816 |
|
| 1817 |
template <size_t CmpSize, size_t LoadSize> |
| 1818 |
void MacroAssemblerX64::cmpLoad(Condition cond, Register lhs, Register rhs, |
| 1819 |
const Address& falseVal, |
| 1820 |
Register trueValAndDest) { |
| 1821 |
if constexpr (CmpSize == 32) { |
| 1822 |
cmp32(lhs, rhs); |
| 1823 |
} else { |
| 1824 |
static_assert(CmpSize == 64); |
| 1825 |
cmpPtr(lhs, rhs); |
| 1826 |
} |
| 1827 |
if constexpr (LoadSize == 32) { |
| 1828 |
cmovCCl(cond, Operand(falseVal), trueValAndDest); |
| 1829 |
} else { |
| 1830 |
static_assert(LoadSize == 64); |
| 1831 |
cmovCCq(cond, Operand(falseVal), trueValAndDest); |
| 1832 |
} |
| 1833 |
} |
| 1834 |
template void MacroAssemblerX64::cmpLoad<32, 32>(Condition cond, Register lhs, |
| 1835 |
Register rhs, |
| 1836 |
const Address& falseVal, |
| 1837 |
Register trueValAndDest); |
| 1838 |
template void MacroAssemblerX64::cmpLoad<32, 64>(Condition cond, Register lhs, |
| 1839 |
Register rhs, |
| 1840 |
const Address& falseVal, |
| 1841 |
Register trueValAndDest); |
| 1842 |
template void MacroAssemblerX64::cmpLoad<64, 32>(Condition cond, Register lhs, |
| 1843 |
Register rhs, |
| 1844 |
const Address& falseVal, |
| 1845 |
Register trueValAndDest); |
| 1846 |
template void MacroAssemblerX64::cmpLoad<64, 64>(Condition cond, Register lhs, |
| 1847 |
Register rhs, |
| 1848 |
const Address& falseVal, |
| 1849 |
Register trueValAndDest); |
| 1850 |
|
| 1851 |
// cmpLoad, Cond-Reg-Addr-Addr-Reg cases |
| 1852 |
|
| 1853 |
template <size_t CmpSize, size_t LoadSize> |
| 1854 |
void MacroAssemblerX64::cmpLoad(Condition cond, Register lhs, |
| 1855 |
const Address& rhs, const Address& falseVal, |
| 1856 |
Register trueValAndDest) { |
| 1857 |
if constexpr (CmpSize == 32) { |
| 1858 |
cmp32(lhs, Operand(rhs)); |
| 1859 |
} else { |
| 1860 |
static_assert(CmpSize == 64); |
| 1861 |
cmpPtr(lhs, Operand(rhs)); |
| 1862 |
} |
| 1863 |
if constexpr (LoadSize == 32) { |
| 1864 |
cmovCCl(cond, Operand(falseVal), trueValAndDest); |
| 1865 |
} else { |
| 1866 |
static_assert(LoadSize == 64); |
| 1867 |
cmovCCq(cond, Operand(falseVal), trueValAndDest); |
| 1868 |
} |
| 1869 |
} |
| 1870 |
template void MacroAssemblerX64::cmpLoad<32, 32>(Condition cond, Register lhs, |
| 1871 |
const Address& rhs, |
| 1872 |
const Address& falseVal, |
| 1873 |
Register trueValAndDest); |
| 1874 |
template void MacroAssemblerX64::cmpLoad<32, 64>(Condition cond, Register lhs, |
| 1875 |
const Address& rhs, |
| 1876 |
const Address& falseVal, |
| 1877 |
Register trueValAndDest); |
| 1878 |
template void MacroAssemblerX64::cmpLoad<64, 32>(Condition cond, Register lhs, |
| 1879 |
const Address& rhs, |
| 1880 |
const Address& falseVal, |
| 1881 |
Register trueValAndDest); |
| 1882 |
template void MacroAssemblerX64::cmpLoad<64, 64>(Condition cond, Register lhs, |
| 1883 |
const Address& rhs, |
| 1884 |
const Address& falseVal, |
| 1885 |
Register trueValAndDest); |
| 1886 |
|
| 1887 |
//}}} check_macroassembler_style |