Debian Codegraph @

js/src/jit/x64/Lowering-x64.cpp

raw
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/Lowering-x64.h"
8
9 #include "mozilla/CheckedInt.h"
10
11 #include "jit/Lowering.h"
12 #include "jit/MIR-wasm.h"
13 #include "jit/MIR.h"
14 #include "jit/x64/Assembler-x64.h"
15
16 #include "jit/shared/Lowering-shared-inl.h"
17
18 using namespace js;
19 using namespace js::jit;
20
21 LBoxAllocation LIRGeneratorX64::useBoxFixed(MDefinition* mir, Register reg1,
22 Register, bool useAtStart) {
23 MOZ_ASSERT(mir->type() == MIRType::Value);
24
25 ensureDefined(mir);
26 return LBoxAllocation(LUse(reg1, mir->virtualRegister(), useAtStart));
27 }
28
29 LAllocation LIRGeneratorX64::useByteOpRegister(MDefinition* mir) {
30 return useRegister(mir);
31 }
32
33 LAllocation LIRGeneratorX64::useByteOpRegisterAtStart(MDefinition* mir) {
34 return useRegisterAtStart(mir);
35 }
36
37 LAllocation LIRGeneratorX64::useByteOpRegisterOrNonDoubleConstant(
38 MDefinition* mir) {
39 return useRegisterOrNonDoubleConstant(mir);
40 }
41
42 LDefinition LIRGeneratorX64::tempByteOpRegister() { return temp(); }
43
44 LDefinition LIRGeneratorX64::tempToUnbox() { return temp(); }
45
46 void LIRGeneratorX64::lowerForALUInt64(
47 LInstructionHelper<INT64_PIECES, INT64_PIECES, 0>* ins, MDefinition* mir,
48 MDefinition* input) {
49 ins->setInt64Operand(0, useInt64RegisterAtStart(input));
50 defineInt64ReuseInput(ins, mir, 0);
51 }
52
53 void LIRGeneratorX64::lowerForALUInt64(
54 LInstructionHelper<INT64_PIECES, 2 * INT64_PIECES, 0>* ins,
55 MDefinition* mir, MDefinition* lhs, MDefinition* rhs) {
56 ins->setInt64Operand(0, useInt64RegisterAtStart(lhs));
57 ins->setInt64Operand(INT64_PIECES, willHaveDifferentLIRNodes(lhs, rhs)
58 ? useInt64OrConstant(rhs)
59 : useInt64OrConstantAtStart(rhs));
60 defineInt64ReuseInput(ins, mir, 0);
61 }
62
63 void LIRGeneratorX64::lowerForMulInt64(LMulI64* ins, MMul* mir,
64 MDefinition* lhs, MDefinition* rhs) {
65 // X64 doesn't need a temp for 64bit multiplication.
66 ins->setLhs(useInt64RegisterAtStart(lhs));
67 ins->setRhs(willHaveDifferentLIRNodes(lhs, rhs)
68 ? useInt64OrConstant(rhs)
69 : useInt64OrConstantAtStart(rhs));
70 defineInt64ReuseInput(ins, mir, 0);
71 }
72
73 void LIRGenerator::visitBox(MBox* box) {
74 MDefinition* opd = box->getOperand(0);
75
76 // If the operand is a constant, emit near its uses.
77 if (opd->isConstant() && box->canEmitAtUses()) {
78 emitAtUses(box);
79 return;
80 }
81
82 if (opd->isConstant()) {
83 define(new (alloc()) LValue(opd->toConstant()->toJSValue()), box,
84 LDefinition(LDefinition::BOX));
85 } else {
86 LBox* ins = new (alloc()) LBox(useRegister(opd), opd->type());
87 define(ins, box, LDefinition(LDefinition::BOX));
88 }
89 }
90
91 void LIRGenerator::visitUnbox(MUnbox* unbox) {
92 MDefinition* box = unbox->getOperand(0);
93 MOZ_ASSERT(box->type() == MIRType::Value);
94
95 LInstructionHelper<1, BOX_PIECES, 0>* lir;
96 if (IsFloatingPointType(unbox->type())) {
97 MOZ_ASSERT(unbox->type() == MIRType::Double);
98 lir = new (alloc()) LUnboxFloatingPoint(useBoxAtStart(box));
99 } else if (unbox->fallible()) {
100 // If the unbox is fallible, load the Value in a register first to
101 // avoid multiple loads.
102 lir = new (alloc()) LUnbox(useRegisterAtStart(box));
103 } else {
104 lir = new (alloc()) LUnbox(useAtStart(box));
105 }
106
107 if (unbox->fallible()) {
108 assignSnapshot(lir, unbox->bailoutKind());
109 }
110
111 define(lir, unbox);
112 }
113
114 void LIRGenerator::visitReturnImpl(MDefinition* opd, bool isGenerator) {
115 MOZ_ASSERT(opd->type() == MIRType::Value);
116
117 LReturn* ins = new (alloc()) LReturn(isGenerator);
118 ins->setOperand(0, useFixed(opd, JSReturnReg));
119 add(ins);
120 }
121
122 void LIRGeneratorX64::lowerUntypedPhiInput(MPhi* phi, uint32_t inputPosition,
123 LBlock* block, size_t lirIndex) {
124 lowerTypedPhiInput(phi, inputPosition, block, lirIndex);
125 }
126
127 void LIRGeneratorX64::defineInt64Phi(MPhi* phi, size_t lirIndex) {
128 defineTypedPhi(phi, lirIndex);
129 }
130
131 void LIRGeneratorX64::lowerInt64PhiInput(MPhi* phi, uint32_t inputPosition,
132 LBlock* block, size_t lirIndex) {
133 lowerTypedPhiInput(phi, inputPosition, block, lirIndex);
134 }
135
136 void LIRGenerator::visitCompareExchangeTypedArrayElement(
137 MCompareExchangeTypedArrayElement* ins) {
138 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
139 MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr);
140
141 if (Scalar::isBigIntType(ins->arrayType())) {
142 LUse elements = useRegister(ins->elements());
143 LAllocation index =
144 useRegisterOrIndexConstant(ins->index(), ins->arrayType());
145 LInt64Allocation oldval = useInt64Register(ins->oldval());
146 LInt64Allocation newval = useInt64Register(ins->newval());
147
148 auto* lir = new (alloc())
149 LCompareExchangeTypedArrayElement64(elements, index, oldval, newval);
150 defineInt64Fixed(lir, ins, LInt64Allocation(LAllocation(AnyRegister(rax))));
151 return;
152 }
153
154 lowerCompareExchangeTypedArrayElement(ins,
155 /* useI386ByteRegisters = */ false);
156 }
157
158 void LIRGenerator::visitAtomicExchangeTypedArrayElement(
159 MAtomicExchangeTypedArrayElement* ins) {
160 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
161 MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr);
162
163 if (Scalar::isBigIntType(ins->arrayType())) {
164 LUse elements = useRegister(ins->elements());
165 LAllocation index =
166 useRegisterOrIndexConstant(ins->index(), ins->arrayType());
167 LInt64Allocation value = useInt64Register(ins->value());
168
169 auto* lir = new (alloc())
170 LAtomicExchangeTypedArrayElement64(elements, index, value);
171 defineInt64(lir, ins);
172 return;
173 }
174
175 lowerAtomicExchangeTypedArrayElement(ins, /* useI386ByteRegisters = */ false);
176 }
177
178 void LIRGenerator::visitAtomicTypedArrayElementBinop(
179 MAtomicTypedArrayElementBinop* ins) {
180 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
181 MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr);
182
183 if (Scalar::isBigIntType(ins->arrayType())) {
184 LUse elements = useRegister(ins->elements());
185 LAllocation index =
186 useRegisterOrIndexConstant(ins->index(), ins->arrayType());
187
188 // Case 1: the result of the operation is not used.
189
190 if (ins->isForEffect()) {
191 LInt64Allocation value = useInt64Register(ins->value());
192
193 auto* lir = new (alloc())
194 LAtomicTypedArrayElementBinopForEffect64(elements, index, value);
195 add(lir, ins);
196 return;
197 }
198
199 // Case 2: the result of the operation is used.
200 //
201 // For ADD and SUB we'll use XADD.
202 //
203 // For AND/OR/XOR we need to use a CMPXCHG loop with rax as the output.
204
205 bool bitOp = !(ins->operation() == AtomicOp::Add ||
206 ins->operation() == AtomicOp::Sub);
207
208 LInt64Allocation value;
209 LInt64Definition temp;
210 if (bitOp) {
211 value = useInt64Register(ins->value());
212 temp = tempInt64();
213 } else {
214 value = useInt64RegisterAtStart(ins->value());
215 temp = LInt64Definition::BogusTemp();
216 }
217
218 auto* lir = new (alloc())
219 LAtomicTypedArrayElementBinop64(elements, index, value, temp);
220 if (bitOp) {
221 defineInt64Fixed(lir, ins,
222 LInt64Allocation(LAllocation(AnyRegister(rax))));
223 } else {
224 defineInt64ReuseInput(lir, ins, 2);
225 }
226 return;
227 }
228
229 lowerAtomicTypedArrayElementBinop(ins, /* useI386ByteRegisters = */ false);
230 }
231
232 void LIRGeneratorX64::lowerAtomicLoad64(MLoadUnboxedScalar* ins) {
233 const LUse elements = useRegister(ins->elements());
234 const LAllocation index =
235 useRegisterOrIndexConstant(ins->index(), ins->storageType());
236
237 auto* lir = new (alloc()) LAtomicLoad64(elements, index);
238 defineInt64(lir, ins);
239 }
240
241 void LIRGeneratorX64::lowerAtomicStore64(MStoreUnboxedScalar* ins) {
242 LUse elements = useRegister(ins->elements());
243 LAllocation index =
244 useRegisterOrIndexConstant(ins->index(), ins->writeType());
245 LInt64Allocation value = useInt64Register(ins->value());
246
247 add(new (alloc()) LAtomicStore64(elements, index, value), ins);
248 }
249
250 void LIRGenerator::visitWasmUnsignedToDouble(MWasmUnsignedToDouble* ins) {
251 MOZ_ASSERT(ins->input()->type() == MIRType::Int32);
252 LWasmUint32ToDouble* lir =
253 new (alloc()) LWasmUint32ToDouble(useRegisterAtStart(ins->input()));
254 define(lir, ins);
255 }
256
257 void LIRGenerator::visitWasmUnsignedToFloat32(MWasmUnsignedToFloat32* ins) {
258 MOZ_ASSERT(ins->input()->type() == MIRType::Int32);
259 LWasmUint32ToFloat32* lir =
260 new (alloc()) LWasmUint32ToFloat32(useRegisterAtStart(ins->input()));
261 define(lir, ins);
262 }
263
264 void LIRGenerator::visitWasmLoad(MWasmLoad* ins) {
265 MDefinition* base = ins->base();
266 // 'base' is a GPR but may be of either type. If it is 32-bit it is
267 // zero-extended and can act as 64-bit.
268 MOZ_ASSERT(base->type() == MIRType::Int32 || base->type() == MIRType::Int64);
269
270 LAllocation memoryBase =
271 ins->hasMemoryBase() ? LAllocation(useRegisterAtStart(ins->memoryBase()))
272 : LGeneralReg(HeapReg);
273
274 if (ins->type() != MIRType::Int64) {
275 auto* lir =
276 new (alloc()) LWasmLoad(useRegisterOrZeroAtStart(base), memoryBase);
277 define(lir, ins);
278 return;
279 }
280
281 auto* lir =
282 new (alloc()) LWasmLoadI64(useRegisterOrZeroAtStart(base), memoryBase);
283 defineInt64(lir, ins);
284 }
285
286 static bool CanUseInt32OrInt64Constant(MDefinition* value) {
287 MOZ_ASSERT(IsIntType(value->type()));
288 if (!value->isConstant()) {
289 return false;
290 }
291 if (value->type() == MIRType::Int64) {
292 // Immediate needs to fit into int32 for direct to memory move on x64.
293 return mozilla::CheckedInt32(value->toConstant()->toInt64()).isValid();
294 }
295 MOZ_ASSERT(value->type() == MIRType::Int32);
296 return true;
297 }
298
299 void LIRGenerator::visitWasmStore(MWasmStore* ins) {
300 MDefinition* base = ins->base();
301 // See comment in visitWasmLoad re the type of 'base'.
302 MOZ_ASSERT(base->type() == MIRType::Int32 || base->type() == MIRType::Int64);
303
304 MDefinition* value = ins->value();
305 LAllocation valueAlloc;
306 switch (ins->access().type()) {
307 case Scalar::Int8:
308 case Scalar::Uint8:
309 case Scalar::Int16:
310 case Scalar::Uint16:
311 case Scalar::Int32:
312 case Scalar::Uint32:
313 valueAlloc = useRegisterOrConstantAtStart(value);
314 break;
315 case Scalar::Int64:
316 if (CanUseInt32OrInt64Constant(value)) {
317 valueAlloc = useOrConstantAtStart(value);
318 } else {
319 valueAlloc = useRegisterAtStart(value);
320 }
321 break;
322 case Scalar::Float32:
323 case Scalar::Float64:
324 valueAlloc = useRegisterAtStart(value);
325 break;
326 case Scalar::Simd128:
327 #ifdef ENABLE_WASM_SIMD
328 valueAlloc = useRegisterAtStart(value);
329 break;
330 #else
331 MOZ_CRASH("unexpected array type");
332 #endif
333 case Scalar::BigInt64:
334 case Scalar::BigUint64:
335 case Scalar::Uint8Clamped:
336 case Scalar::Float16:
337 case Scalar::MaxTypedArrayViewType:
338 MOZ_CRASH("unexpected array type");
339 }
340
341 LAllocation baseAlloc = useRegisterOrZeroAtStart(base);
342 LAllocation memoryBaseAlloc =
343 ins->hasMemoryBase() ? LAllocation(useRegisterAtStart(ins->memoryBase()))
344 : LGeneralReg(HeapReg);
345 auto* lir = new (alloc()) LWasmStore(baseAlloc, valueAlloc, memoryBaseAlloc);
346 add(lir, ins);
347 }
348
349 void LIRGenerator::visitWasmCompareExchangeHeap(MWasmCompareExchangeHeap* ins) {
350 MDefinition* base = ins->base();
351 // See comment in visitWasmLoad re the type of 'base'.
352 MOZ_ASSERT(base->type() == MIRType::Int32 || base->type() == MIRType::Int64);
353
354 // The output may not be used but will be clobbered regardless, so
355 // pin the output to eax.
356 //
357 // The input values must both be in registers.
358
359 const LAllocation oldval = useRegister(ins->oldValue());
360 const LAllocation newval = useRegister(ins->newValue());
361 const LAllocation memoryBase =
362 ins->hasMemoryBase() ? LAllocation(useRegister(ins->memoryBase()))
363 : LGeneralReg(HeapReg);
364
365 LWasmCompareExchangeHeap* lir = new (alloc())
366 LWasmCompareExchangeHeap(useRegister(base), oldval, newval, memoryBase);
367
368 defineFixed(lir, ins, LAllocation(AnyRegister(eax)));
369 }
370
371 void LIRGenerator::visitWasmAtomicExchangeHeap(MWasmAtomicExchangeHeap* ins) {
372 // See comment in visitWasmLoad re the type of 'base'.
373 MOZ_ASSERT(ins->base()->type() == MIRType::Int32 ||
374 ins->base()->type() == MIRType::Int64);
375
376 const LAllocation base = useRegister(ins->base());
377 const LAllocation value = useRegister(ins->value());
378 const LAllocation memoryBase =
379 ins->hasMemoryBase() ? LAllocation(useRegister(ins->memoryBase()))
380 : LGeneralReg(HeapReg);
381
382 // The output may not be used but will be clobbered regardless,
383 // so ignore the case where we're not using the value and just
384 // use the output register as a temp.
385
386 LWasmAtomicExchangeHeap* lir =
387 new (alloc()) LWasmAtomicExchangeHeap(base, value, memoryBase);
388 define(lir, ins);
389 }
390
391 void LIRGenerator::visitWasmAtomicBinopHeap(MWasmAtomicBinopHeap* ins) {
392 MDefinition* base = ins->base();
393 // See comment in visitWasmLoad re the type of 'base'.
394 MOZ_ASSERT(base->type() == MIRType::Int32 || base->type() == MIRType::Int64);
395
396 const LAllocation memoryBase =
397 ins->hasMemoryBase() ? LAllocation(useRegister(ins->memoryBase()))
398 : LGeneralReg(HeapReg);
399
400 // No support for 64-bit operations with constants at the masm level.
401
402 bool canTakeConstant = ins->access().type() != Scalar::Int64;
403
404 // Case 1: the result of the operation is not used.
405 //
406 // We'll emit a single instruction: LOCK ADD, LOCK SUB, LOCK AND,
407 // LOCK OR, or LOCK XOR.
408
409 if (!ins->hasUses()) {
410 LAllocation value = canTakeConstant ? useRegisterOrConstant(ins->value())
411 : useRegister(ins->value());
412 auto* lir = new (alloc())
413 LWasmAtomicBinopHeapForEffect(useRegister(base), value, memoryBase);
414 add(lir, ins);
415 return;
416 }
417
418 // Case 2: the result of the operation is used.
419 //
420 // For ADD and SUB we'll use XADD with word and byte ops as
421 // appropriate. Any output register can be used and if value is a
422 // register it's best if it's the same as output:
423 //
424 // movl value, output ; if value != output
425 // lock xaddl output, mem
426 //
427 // For AND/OR/XOR we need to use a CMPXCHG loop, and the output is
428 // always in rax:
429 //
430 // movl *mem, rax
431 // L: mov rax, temp
432 // andl value, temp
433 // lock cmpxchg temp, mem ; reads rax also
434 // jnz L
435 // ; result in rax
436 //
437 // Note the placement of L, cmpxchg will update rax with *mem if
438 // *mem does not have the expected value, so reloading it at the
439 // top of the loop would be redundant.
440
441 bool bitOp =
442 !(ins->operation() == AtomicOp::Add || ins->operation() == AtomicOp::Sub);
443 bool reuseInput = false;
444 LAllocation value;
445
446 if (bitOp || ins->value()->isConstant()) {
447 value = canTakeConstant ? useRegisterOrConstant(ins->value())
448 : useRegister(ins->value());
449 } else {
450 reuseInput = true;
451 value = useRegisterAtStart(ins->value());
452 }
453
454 auto* lir = new (alloc())
455 LWasmAtomicBinopHeap(useRegister(base), value, memoryBase,
456 bitOp ? temp() : LDefinition::BogusTemp());
457
458 if (reuseInput) {
459 defineReuseInput(lir, ins, LWasmAtomicBinopHeap::ValueIndex);
460 } else if (bitOp) {
461 defineFixed(lir, ins, LAllocation(AnyRegister(rax)));
462 } else {
463 define(lir, ins);
464 }
465 }
466
467 void LIRGenerator::visitSubstr(MSubstr* ins) {
468 LSubstr* lir = new (alloc())
469 LSubstr(useRegister(ins->string()), useRegister(ins->begin()),
470 useRegister(ins->length()), temp(), temp(), tempByteOpRegister());
471 define(lir, ins);
472 assignSafepoint(lir, ins);
473 }
474
475 void LIRGeneratorX64::lowerDivI64(MDiv* div) {
476 if (div->isUnsigned()) {
477 lowerUDivI64(div);
478 return;
479 }
480
481 LDivOrModI64* lir = new (alloc()) LDivOrModI64(
482 useRegister(div->lhs()), useRegister(div->rhs()), tempFixed(rdx));
483 defineInt64Fixed(lir, div, LInt64Allocation(LAllocation(AnyRegister(rax))));
484 }
485
486 void LIRGeneratorX64::lowerWasmBuiltinDivI64(MWasmBuiltinDivI64* div) {
487 MOZ_CRASH("We don't use runtime div for this architecture");
488 }
489
490 void LIRGeneratorX64::lowerModI64(MMod* mod) {
491 if (mod->isUnsigned()) {
492 lowerUModI64(mod);
493 return;
494 }
495
496 LDivOrModI64* lir = new (alloc()) LDivOrModI64(
497 useRegister(mod->lhs()), useRegister(mod->rhs()), tempFixed(rax));
498 defineInt64Fixed(lir, mod, LInt64Allocation(LAllocation(AnyRegister(rdx))));
499 }
500
501 void LIRGeneratorX64::lowerWasmBuiltinModI64(MWasmBuiltinModI64* mod) {
502 MOZ_CRASH("We don't use runtime mod for this architecture");
503 }
504
505 void LIRGeneratorX64::lowerUDivI64(MDiv* div) {
506 LUDivOrModI64* lir = new (alloc()) LUDivOrModI64(
507 useRegister(div->lhs()), useRegister(div->rhs()), tempFixed(rdx));
508 defineInt64Fixed(lir, div, LInt64Allocation(LAllocation(AnyRegister(rax))));
509 }
510
511 void LIRGeneratorX64::lowerUModI64(MMod* mod) {
512 LUDivOrModI64* lir = new (alloc()) LUDivOrModI64(
513 useRegister(mod->lhs()), useRegister(mod->rhs()), tempFixed(rax));
514 defineInt64Fixed(lir, mod, LInt64Allocation(LAllocation(AnyRegister(rdx))));
515 }
516
517 void LIRGeneratorX64::lowerBigIntPtrDiv(MBigIntPtrDiv* ins) {
518 auto* lir = new (alloc())
519 LBigIntPtrDiv(useRegister(ins->lhs()), useRegister(ins->rhs()),
520 tempFixed(rdx), LDefinition::BogusTemp());
521 assignSnapshot(lir, ins->bailoutKind());
522 defineFixed(lir, ins, LAllocation(AnyRegister(rax)));
523 }
524
525 void LIRGeneratorX64::lowerBigIntPtrMod(MBigIntPtrMod* ins) {
526 auto* lir = new (alloc())
527 LBigIntPtrMod(useRegister(ins->lhs()), useRegister(ins->rhs()),
528 tempFixed(rax), LDefinition::BogusTemp());
529 if (ins->canBeDivideByZero()) {
530 assignSnapshot(lir, ins->bailoutKind());
531 }
532 defineFixed(lir, ins, LAllocation(AnyRegister(rdx)));
533 }
534
535 void LIRGeneratorX64::lowerTruncateDToInt32(MTruncateToInt32* ins) {
536 MDefinition* opd = ins->input();
537 MOZ_ASSERT(opd->type() == MIRType::Double);
538
539 define(new (alloc()) LTruncateDToInt32(useRegister(opd), tempShift()), ins);
540 }
541
542 void LIRGeneratorX64::lowerTruncateFToInt32(MTruncateToInt32* ins) {
543 MDefinition* opd = ins->input();
544 MOZ_ASSERT(opd->type() == MIRType::Float32);
545
546 LDefinition maybeTemp = LDefinition::BogusTemp();
547 define(new (alloc()) LTruncateFToInt32(useRegister(opd), maybeTemp), ins);
548 }
549
550 void LIRGenerator::visitWasmTruncateToInt64(MWasmTruncateToInt64* ins) {
551 MDefinition* opd = ins->input();
552 MOZ_ASSERT(opd->type() == MIRType::Double || opd->type() == MIRType::Float32);
553
554 LDefinition maybeTemp =
555 ins->isUnsigned() ? tempDouble() : LDefinition::BogusTemp();
556 defineInt64(new (alloc()) LWasmTruncateToInt64(useRegister(opd), maybeTemp),
557 ins);
558 }
559
560 void LIRGeneratorX64::lowerWasmBuiltinTruncateToInt64(
561 MWasmBuiltinTruncateToInt64* ins) {
562 MOZ_CRASH("We don't use it for this architecture");
563 }
564
565 void LIRGenerator::visitInt64ToFloatingPoint(MInt64ToFloatingPoint* ins) {
566 MDefinition* opd = ins->input();
567 MOZ_ASSERT(opd->type() == MIRType::Int64);
568 MOZ_ASSERT(IsFloatingPointType(ins->type()));
569
570 LDefinition maybeTemp = ins->isUnsigned() ? temp() : LDefinition::BogusTemp();
571 define(new (alloc()) LInt64ToFloatingPoint(useInt64Register(opd), maybeTemp),
572 ins);
573 }
574
575 void LIRGeneratorX64::lowerWasmBuiltinTruncateToInt32(
576 MWasmBuiltinTruncateToInt32* ins) {
577 MDefinition* opd = ins->input();
578 MOZ_ASSERT(opd->type() == MIRType::Double || opd->type() == MIRType::Float32);
579
580 if (opd->type() == MIRType::Double) {
581 define(new (alloc()) LWasmBuiltinTruncateDToInt32(
582 useRegister(opd), LAllocation(), tempShift()),
583 ins);
584 return;
585 }
586
587 LDefinition maybeTemp = LDefinition::BogusTemp();
588 define(new (alloc()) LWasmBuiltinTruncateFToInt32(useRegister(opd),
589 LAllocation(), maybeTemp),
590 ins);
591 }
592
593 void LIRGeneratorX64::lowerBuiltinInt64ToFloatingPoint(
594 MBuiltinInt64ToFloatingPoint* ins) {
595 MOZ_CRASH("We don't use it for this architecture");
596 }
597
598 void LIRGenerator::visitExtendInt32ToInt64(MExtendInt32ToInt64* ins) {
599 defineInt64(new (alloc()) LExtendInt32ToInt64(useAtStart(ins->input())), ins);
600 }
601
602 void LIRGenerator::visitSignExtendInt64(MSignExtendInt64* ins) {
603 defineInt64(new (alloc())
604 LSignExtendInt64(useInt64RegisterAtStart(ins->input())),
605 ins);
606 }
607
608 // On x64 we specialize the cases: compare is {U,}Int{32,64}, and select is
609 // {U,}Int{32,64}, independently.
610 bool LIRGeneratorShared::canSpecializeWasmCompareAndSelect(
611 MCompare::CompareType compTy, MIRType insTy) {
612 return (insTy == MIRType::Int32 || insTy == MIRType::Int64) &&
613 (compTy == MCompare::Compare_Int32 ||
614 compTy == MCompare::Compare_UInt32 ||
615 compTy == MCompare::Compare_Int64 ||
616 compTy == MCompare::Compare_UInt64);
617 }
618
619 void LIRGeneratorShared::lowerWasmCompareAndSelect(MWasmSelect* ins,
620 MDefinition* lhs,
621 MDefinition* rhs,
622 MCompare::CompareType compTy,
623 JSOp jsop) {
624 MOZ_ASSERT(canSpecializeWasmCompareAndSelect(compTy, ins->type()));
625 auto* lir = new (alloc()) LWasmCompareAndSelect(
626 useRegister(lhs), useAny(rhs), useRegisterAtStart(ins->trueExpr()),
627 useAny(ins->falseExpr()), compTy, jsop);
628 defineReuseInput(lir, ins, LWasmCompareAndSelect::IfTrueExprIndex);
629 }