Debian Codegraph @

js/src/jit/mips-shared/MacroAssembler-mips-shared-inl.h

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 #ifndef jit_mips_shared_MacroAssembler_mips_shared_inl_h
8 #define jit_mips_shared_MacroAssembler_mips_shared_inl_h
9
10 #include "jit/mips-shared/MacroAssembler-mips-shared.h"
11
12 namespace js {
13 namespace jit {
14
15 //{{{ check_macroassembler_style
16
17 void MacroAssembler::moveGPRToFloat16(Register src, FloatRegister dest) {
18 MOZ_CRASH("Not supported for this target");
19 }
20
21 void MacroAssembler::moveFloat32ToGPR(FloatRegister src, Register dest) {
22 moveFromFloat32(src, dest);
23 }
24
25 void MacroAssembler::moveGPRToFloat32(Register src, FloatRegister dest) {
26 moveToFloat32(src, dest);
27 }
28
29 void MacroAssembler::moveLowDoubleToGPR(FloatRegister src, Register dest) {
30 MOZ_CRASH("Not supported for this target");
31 }
32
33 void MacroAssembler::move8ZeroExtend(Register src, Register dest) {
34 as_andi(dest, src, 0xff);
35 }
36
37 void MacroAssembler::move8SignExtend(Register src, Register dest) {
38 ma_seb(dest, src);
39 }
40
41 void MacroAssembler::move16SignExtend(Register src, Register dest) {
42 ma_seh(dest, src);
43 }
44
45 void MacroAssembler::loadAbiReturnAddress(Register dest) { movePtr(ra, dest); }
46
47 // ===============================================================
48 // Logical instructions
49
50 void MacroAssembler::not32(Register reg) { ma_not(reg, reg); }
51
52 void MacroAssembler::and32(Register src, Register dest) {
53 as_and(dest, dest, src);
54 }
55
56 void MacroAssembler::and32(Imm32 imm, Register dest) { ma_and(dest, imm); }
57
58 void MacroAssembler::and32(Imm32 imm, Register src, Register dest) {
59 ma_and(dest, src, imm);
60 }
61
62 void MacroAssembler::and32(Imm32 imm, const Address& dest) {
63 load32(dest, SecondScratchReg);
64 ma_and(SecondScratchReg, imm);
65 store32(SecondScratchReg, dest);
66 }
67
68 void MacroAssembler::and32(const Address& src, Register dest) {
69 load32(src, SecondScratchReg);
70 ma_and(dest, SecondScratchReg);
71 }
72
73 void MacroAssembler::or32(Register src, Register dest) { ma_or(dest, src); }
74
75 void MacroAssembler::or32(Imm32 imm, Register dest) { ma_or(dest, imm); }
76
77 void MacroAssembler::or32(Imm32 imm, Register src, Register dest) {
78 ma_or(dest, src, imm);
79 }
80
81 void MacroAssembler::or32(Imm32 imm, const Address& dest) {
82 load32(dest, SecondScratchReg);
83 ma_or(SecondScratchReg, imm);
84 store32(SecondScratchReg, dest);
85 }
86
87 void MacroAssembler::xor32(Register src, Register dest) { ma_xor(dest, src); }
88
89 void MacroAssembler::xor32(Imm32 imm, Register dest) { ma_xor(dest, imm); }
90
91 void MacroAssembler::xor32(Imm32 imm, Register src, Register dest) {
92 ma_xor(dest, src, imm);
93 }
94
95 void MacroAssembler::xor32(Imm32 imm, const Address& dest) {
96 load32(dest, SecondScratchReg);
97 ma_xor(SecondScratchReg, imm);
98 store32(SecondScratchReg, dest);
99 }
100
101 void MacroAssembler::xor32(const Address& src, Register dest) {
102 load32(src, SecondScratchReg);
103 ma_xor(dest, SecondScratchReg);
104 }
105
106 // ===============================================================
107 // Swap instructions
108
109 void MacroAssembler::byteSwap16SignExtend(Register reg) {
110 ma_wsbh(reg, reg);
111 ma_seh(reg, reg);
112 }
113
114 void MacroAssembler::byteSwap16ZeroExtend(Register reg) {
115 ma_wsbh(reg, reg);
116 ma_and(reg, Imm32(0xFFFF));
117 }
118
119 void MacroAssembler::byteSwap32(Register reg) {
120 ma_wsbh(reg, reg);
121 as_rotr(reg, reg, 16);
122 }
123
124 // ===============================================================
125 // Arithmetic instructions
126
127 void MacroAssembler::add32(Register src, Register dest) {
128 as_addu(dest, dest, src);
129 }
130
131 void MacroAssembler::add32(Imm32 imm, Register dest) {
132 ma_addu(dest, dest, imm);
133 }
134
135 void MacroAssembler::add32(Imm32 imm, Register src, Register dest) {
136 ma_addu(dest, src, imm);
137 }
138
139 void MacroAssembler::add32(Imm32 imm, const Address& dest) {
140 load32(dest, SecondScratchReg);
141 ma_addu(SecondScratchReg, imm);
142 store32(SecondScratchReg, dest);
143 }
144
145 void MacroAssembler::addPtr(Imm32 imm, const Address& dest) {
146 loadPtr(dest, ScratchRegister);
147 addPtr(imm, ScratchRegister);
148 storePtr(ScratchRegister, dest);
149 }
150
151 void MacroAssembler::addPtr(const Address& src, Register dest) {
152 loadPtr(src, ScratchRegister);
153 addPtr(ScratchRegister, dest);
154 }
155
156 void MacroAssembler::addDouble(FloatRegister src, FloatRegister dest) {
157 as_addd(dest, dest, src);
158 }
159
160 void MacroAssembler::addFloat32(FloatRegister src, FloatRegister dest) {
161 as_adds(dest, dest, src);
162 }
163
164 void MacroAssembler::sub32(Register src, Register dest) {
165 as_subu(dest, dest, src);
166 }
167
168 void MacroAssembler::sub32(Imm32 imm, Register dest) {
169 ma_subu(dest, dest, imm);
170 }
171
172 void MacroAssembler::sub32(const Address& src, Register dest) {
173 load32(src, SecondScratchReg);
174 as_subu(dest, dest, SecondScratchReg);
175 }
176
177 void MacroAssembler::subPtr(Register src, const Address& dest) {
178 loadPtr(dest, SecondScratchReg);
179 subPtr(src, SecondScratchReg);
180 storePtr(SecondScratchReg, dest);
181 }
182
183 void MacroAssembler::subPtr(const Address& addr, Register dest) {
184 loadPtr(addr, SecondScratchReg);
185 subPtr(SecondScratchReg, dest);
186 }
187
188 void MacroAssembler::subDouble(FloatRegister src, FloatRegister dest) {
189 as_subd(dest, dest, src);
190 }
191
192 void MacroAssembler::subFloat32(FloatRegister src, FloatRegister dest) {
193 as_subs(dest, dest, src);
194 }
195
196 void MacroAssembler::mul32(Register rhs, Register srcDest) {
197 as_mul(srcDest, srcDest, rhs);
198 }
199
200 void MacroAssembler::mul32(Imm32 imm, Register srcDest) {
201 move32(imm, SecondScratchReg);
202 mul32(SecondScratchReg, srcDest);
203 }
204
205 void MacroAssembler::mulFloat32(FloatRegister src, FloatRegister dest) {
206 as_muls(dest, dest, src);
207 }
208
209 void MacroAssembler::mulDouble(FloatRegister src, FloatRegister dest) {
210 as_muld(dest, dest, src);
211 }
212
213 void MacroAssembler::mulDoublePtr(ImmPtr imm, Register temp,
214 FloatRegister dest) {
215 movePtr(imm, ScratchRegister);
216 loadDouble(Address(ScratchRegister, 0), ScratchDoubleReg);
217 mulDouble(ScratchDoubleReg, dest);
218 }
219
220 void MacroAssembler::quotient32(Register rhs, Register srcDest,
221 bool isUnsigned) {
222 if (isUnsigned) {
223 #ifdef MIPSR6
224 as_divu(srcDest, srcDest, rhs);
225 #else
226 as_divu(srcDest, rhs);
227 #endif
228 } else {
229 #ifdef MIPSR6
230 as_div(srcDest, srcDest, rhs);
231 #else
232 as_div(srcDest, rhs);
233 #endif
234 }
235 #ifndef MIPSR6
236 as_mflo(srcDest);
237 #endif
238 }
239
240 void MacroAssembler::remainder32(Register rhs, Register srcDest,
241 bool isUnsigned) {
242 if (isUnsigned) {
243 #ifdef MIPSR6
244 as_modu(srcDest, srcDest, rhs);
245 #else
246 as_divu(srcDest, rhs);
247 #endif
248 } else {
249 #ifdef MIPSR6
250 as_mod(srcDest, srcDest, rhs);
251 #else
252 as_div(srcDest, rhs);
253 #endif
254 }
255 #ifndef MIPSR6
256 as_mfhi(srcDest);
257 #endif
258 }
259
260 void MacroAssembler::divFloat32(FloatRegister src, FloatRegister dest) {
261 as_divs(dest, dest, src);
262 }
263
264 void MacroAssembler::divDouble(FloatRegister src, FloatRegister dest) {
265 as_divd(dest, dest, src);
266 }
267
268 void MacroAssembler::neg32(Register reg) { ma_negu(reg, reg); }
269
270 void MacroAssembler::negateDouble(FloatRegister reg) { as_negd(reg, reg); }
271
272 void MacroAssembler::negateFloat(FloatRegister reg) { as_negs(reg, reg); }
273
274 void MacroAssembler::abs32(Register src, Register dest) {
275 // TODO: There's probably a better way to do this.
276 if (src != dest) {
277 move32(src, dest);
278 }
279 Label positive;
280 branchTest32(Assembler::NotSigned, dest, dest, &positive);
281 neg32(dest);
282 bind(&positive);
283 }
284
285 void MacroAssembler::absFloat32(FloatRegister src, FloatRegister dest) {
286 as_abss(dest, src);
287 }
288
289 void MacroAssembler::absDouble(FloatRegister src, FloatRegister dest) {
290 as_absd(dest, src);
291 }
292
293 void MacroAssembler::sqrtFloat32(FloatRegister src, FloatRegister dest) {
294 as_sqrts(dest, src);
295 }
296
297 void MacroAssembler::sqrtDouble(FloatRegister src, FloatRegister dest) {
298 as_sqrtd(dest, src);
299 }
300
301 void MacroAssembler::minFloat32(FloatRegister other, FloatRegister srcDest,
302 bool handleNaN) {
303 minMaxFloat32(srcDest, other, handleNaN, false);
304 }
305
306 void MacroAssembler::minDouble(FloatRegister other, FloatRegister srcDest,
307 bool handleNaN) {
308 minMaxDouble(srcDest, other, handleNaN, false);
309 }
310
311 void MacroAssembler::maxFloat32(FloatRegister other, FloatRegister srcDest,
312 bool handleNaN) {
313 minMaxFloat32(srcDest, other, handleNaN, true);
314 }
315
316 void MacroAssembler::maxDouble(FloatRegister other, FloatRegister srcDest,
317 bool handleNaN) {
318 minMaxDouble(srcDest, other, handleNaN, true);
319 }
320
321 // ===============================================================
322 // Shift functions
323
324 void MacroAssembler::lshift32(Register src, Register dest) {
325 ma_sll(dest, dest, src);
326 }
327
328 void MacroAssembler::flexibleLshift32(Register src, Register dest) {
329 lshift32(src, dest);
330 }
331
332 void MacroAssembler::flexibleLshiftPtr(Register shift, Register srcDest) {
333 lshiftPtr(shift, srcDest);
334 }
335
336 void MacroAssembler::lshift32(Imm32 imm, Register dest) {
337 lshift32(imm, dest, dest);
338 }
339
340 void MacroAssembler::lshift32(Imm32 imm, Register src, Register dest) {
341 ma_sll(dest, src, imm);
342 }
343
344 void MacroAssembler::rshift32(Register src, Register dest) {
345 ma_srl(dest, dest, src);
346 }
347
348 void MacroAssembler::flexibleRshift32(Register src, Register dest) {
349 rshift32(src, dest);
350 }
351
352 void MacroAssembler::rshift32(Imm32 imm, Register dest) {
353 rshift32(imm, dest, dest);
354 }
355
356 void MacroAssembler::rshift32(Imm32 imm, Register src, Register dest) {
357 ma_srl(dest, src, imm);
358 }
359
360 void MacroAssembler::rshift32Arithmetic(Register src, Register dest) {
361 ma_sra(dest, dest, src);
362 }
363
364 void MacroAssembler::flexibleRshift32Arithmetic(Register src, Register dest) {
365 rshift32Arithmetic(src, dest);
366 }
367
368 void MacroAssembler::rshift32Arithmetic(Imm32 imm, Register dest) {
369 rshift32Arithmetic(imm, dest, dest);
370 }
371
372 void MacroAssembler::rshift32Arithmetic(Imm32 imm, Register src,
373 Register dest) {
374 ma_sra(dest, src, imm);
375 }
376
377 void MacroAssembler::flexibleRshiftPtr(Register shift, Register srcDest) {
378 rshiftPtr(shift, srcDest);
379 }
380
381 void MacroAssembler::flexibleRshiftPtrArithmetic(Register shift,
382 Register srcDest) {
383 rshiftPtrArithmetic(shift, srcDest);
384 }
385
386 // ===============================================================
387 // Rotation functions
388 void MacroAssembler::rotateLeft(Imm32 count, Register input, Register dest) {
389 if (count.value) {
390 ma_rol(dest, input, count);
391 } else {
392 ma_move(dest, input);
393 }
394 }
395 void MacroAssembler::rotateLeft(Register count, Register input, Register dest) {
396 ma_rol(dest, input, count);
397 }
398 void MacroAssembler::rotateRight(Imm32 count, Register input, Register dest) {
399 if (count.value) {
400 ma_ror(dest, input, count);
401 } else {
402 ma_move(dest, input);
403 }
404 }
405 void MacroAssembler::rotateRight(Register count, Register input,
406 Register dest) {
407 ma_ror(dest, input, count);
408 }
409
410 // ===============================================================
411 // Bit counting functions
412
413 void MacroAssembler::clz32(Register src, Register dest, bool knownNotZero) {
414 as_clz(dest, src);
415 }
416
417 void MacroAssembler::ctz32(Register src, Register dest, bool knownNotZero) {
418 ma_ctz(dest, src);
419 }
420
421 void MacroAssembler::popcnt32(Register input, Register output, Register tmp) {
422 // Equivalent to GCC output of mozilla::CountPopulation32()
423 ma_move(output, input);
424 ma_sra(tmp, input, Imm32(1));
425 ma_and(tmp, Imm32(0x55555555));
426 ma_subu(output, tmp);
427 ma_sra(tmp, output, Imm32(2));
428 ma_and(output, Imm32(0x33333333));
429 ma_and(tmp, Imm32(0x33333333));
430 ma_addu(output, tmp);
431 ma_srl(tmp, output, Imm32(4));
432 ma_addu(output, tmp);
433 ma_and(output, Imm32(0xF0F0F0F));
434 ma_sll(tmp, output, Imm32(8));
435 ma_addu(output, tmp);
436 ma_sll(tmp, output, Imm32(16));
437 ma_addu(output, tmp);
438 ma_sra(output, output, Imm32(24));
439 }
440
441 // ===============================================================
442 // Condition functions
443
444 void MacroAssembler::cmp8Set(Condition cond, Address lhs, Imm32 rhs,
445 Register dest) {
446 SecondScratchRegisterScope scratch2(*this);
447 MOZ_ASSERT(scratch2 != lhs.base);
448
449 switch (cond) {
450 case Assembler::Equal:
451 case Assembler::NotEqual:
452 case Assembler::Above:
453 case Assembler::AboveOrEqual:
454 case Assembler::Below:
455 case Assembler::BelowOrEqual:
456 load8ZeroExtend(lhs, scratch2);
457 ma_cmp_set(dest, scratch2, Imm32(uint8_t(rhs.value)), cond);
458 break;
459
460 case Assembler::GreaterThan:
461 case Assembler::GreaterThanOrEqual:
462 case Assembler::LessThan:
463 case Assembler::LessThanOrEqual:
464 load8SignExtend(lhs, scratch2);
465 ma_cmp_set(dest, scratch2, Imm32(int8_t(rhs.value)), cond);
466 break;
467
468 default:
469 MOZ_CRASH("unexpected condition");
470 }
471 }
472
473 void MacroAssembler::cmp16Set(Condition cond, Address lhs, Imm32 rhs,
474 Register dest) {
475 SecondScratchRegisterScope scratch2(*this);
476 MOZ_ASSERT(scratch2 != lhs.base);
477
478 switch (cond) {
479 case Assembler::Equal:
480 case Assembler::NotEqual:
481 case Assembler::Above:
482 case Assembler::AboveOrEqual:
483 case Assembler::Below:
484 case Assembler::BelowOrEqual:
485 load16ZeroExtend(lhs, scratch2);
486 ma_cmp_set(dest, scratch2, Imm32(uint16_t(rhs.value)), cond);
487 break;
488
489 case Assembler::GreaterThan:
490 case Assembler::GreaterThanOrEqual:
491 case Assembler::LessThan:
492 case Assembler::LessThanOrEqual:
493 load16SignExtend(lhs, scratch2);
494 ma_cmp_set(dest, scratch2, Imm32(int16_t(rhs.value)), cond);
495 break;
496
497 default:
498 MOZ_CRASH("unexpected condition");
499 }
500 }
501
502 // ===============================================================
503 // Branch functions
504
505 void MacroAssembler::branch8(Condition cond, const Address& lhs, Imm32 rhs,
506 Label* label) {
507 SecondScratchRegisterScope scratch2(*this);
508 MOZ_ASSERT(scratch2 != lhs.base);
509
510 switch (cond) {
511 case Assembler::Equal:
512 case Assembler::NotEqual:
513 case Assembler::Above:
514 case Assembler::AboveOrEqual:
515 case Assembler::Below:
516 case Assembler::BelowOrEqual:
517 load8ZeroExtend(lhs, scratch2);
518 branch32(cond, scratch2, Imm32(uint8_t(rhs.value)), label);
519 break;
520
521 case Assembler::GreaterThan:
522 case Assembler::GreaterThanOrEqual:
523 case Assembler::LessThan:
524 case Assembler::LessThanOrEqual:
525 load8SignExtend(lhs, scratch2);
526 branch32(cond, scratch2, Imm32(int8_t(rhs.value)), label);
527 break;
528
529 default:
530 MOZ_CRASH("unexpected condition");
531 }
532 }
533
534 void MacroAssembler::branch8(Condition cond, const BaseIndex& lhs, Register rhs,
535 Label* label) {
536 SecondScratchRegisterScope scratch2(*this);
537 MOZ_ASSERT(scratch2 != lhs.base);
538
539 computeScaledAddress(lhs, scratch2);
540
541 switch (cond) {
542 case Assembler::Equal:
543 case Assembler::NotEqual:
544 case Assembler::Above:
545 case Assembler::AboveOrEqual:
546 case Assembler::Below:
547 case Assembler::BelowOrEqual:
548 load8ZeroExtend(Address(scratch2, lhs.offset), scratch2);
549 branch32(cond, scratch2, rhs, label);
550 break;
551
552 case Assembler::GreaterThan:
553 case Assembler::GreaterThanOrEqual:
554 case Assembler::LessThan:
555 case Assembler::LessThanOrEqual:
556 load8SignExtend(Address(scratch2, lhs.offset), scratch2);
557 branch32(cond, scratch2, rhs, label);
558 break;
559
560 default:
561 MOZ_CRASH("unexpected condition");
562 }
563 }
564
565 void MacroAssembler::branch16(Condition cond, const Address& lhs, Imm32 rhs,
566 Label* label) {
567 SecondScratchRegisterScope scratch2(*this);
568 MOZ_ASSERT(scratch2 != lhs.base);
569
570 switch (cond) {
571 case Assembler::Equal:
572 case Assembler::NotEqual:
573 case Assembler::Above:
574 case Assembler::AboveOrEqual:
575 case Assembler::Below:
576 case Assembler::BelowOrEqual:
577 load16ZeroExtend(lhs, scratch2);
578 branch32(cond, scratch2, Imm32(uint16_t(rhs.value)), label);
579 break;
580
581 case Assembler::GreaterThan:
582 case Assembler::GreaterThanOrEqual:
583 case Assembler::LessThan:
584 case Assembler::LessThanOrEqual:
585 load16SignExtend(lhs, scratch2);
586 branch32(cond, scratch2, Imm32(int16_t(rhs.value)), label);
587 break;
588
589 default:
590 MOZ_CRASH("unexpected condition");
591 }
592 }
593
594 void MacroAssembler::branch32(Condition cond, Register lhs, Register rhs,
595 Label* label, LhsHighBitsAreClean clean) {
596 if (clean == LhsHighBitsAreClean::No) {
597 ScratchRegisterScope scratch(asMasm());
598 as_sll(scratch, lhs, 0);
599 ma_b(scratch, rhs, label, cond);
600 return;
601 }
602 ma_b(lhs, rhs, label, cond);
603 }
604
605 void MacroAssembler::branch32(Condition cond, Register lhs, Imm32 imm,
606 Label* label, LhsHighBitsAreClean clean) {
607 if (clean == LhsHighBitsAreClean::No) {
608 SecondScratchRegisterScope scratch(asMasm());
609 as_sll(scratch, lhs, 0);
610 ma_b(scratch, imm, label, cond);
611 return;
612 }
613 ma_b(lhs, imm, label, cond);
614 }
615
616 void MacroAssembler::branch32(Condition cond, const Address& lhs, Register rhs,
617 Label* label) {
618 load32(lhs, SecondScratchReg);
619 ma_b(SecondScratchReg, rhs, label, cond);
620 }
621
622 void MacroAssembler::branch32(Condition cond, const Address& lhs, Imm32 rhs,
623 Label* label) {
624 load32(lhs, SecondScratchReg);
625 ma_b(SecondScratchReg, rhs, label, cond);
626 }
627
628 void MacroAssembler::branch32(Condition cond, const AbsoluteAddress& lhs,
629 Register rhs, Label* label) {
630 load32(lhs, SecondScratchReg);
631 ma_b(SecondScratchReg, rhs, label, cond);
632 }
633
634 void MacroAssembler::branch32(Condition cond, const AbsoluteAddress& lhs,
635 Imm32 rhs, Label* label) {
636 load32(lhs, SecondScratchReg);
637 ma_b(SecondScratchReg, rhs, label, cond);
638 }
639
640 void MacroAssembler::branch32(Condition cond, const BaseIndex& lhs, Imm32 rhs,
641 Label* label) {
642 load32(lhs, SecondScratchReg);
643 ma_b(SecondScratchReg, rhs, label, cond);
644 }
645
646 void MacroAssembler::branch32(Condition cond, wasm::SymbolicAddress addr,
647 Imm32 imm, Label* label) {
648 load32(addr, SecondScratchReg);
649 ma_b(SecondScratchReg, imm, label, cond);
650 }
651
652 void MacroAssembler::branchPtr(Condition cond, Register lhs, Register rhs,
653 Label* label) {
654 ma_b(lhs, rhs, label, cond);
655 }
656
657 void MacroAssembler::branchPtr(Condition cond, Register lhs, Imm32 rhs,
658 Label* label) {
659 ma_b(lhs, rhs, label, cond);
660 }
661
662 void MacroAssembler::branchPtr(Condition cond, Register lhs, ImmPtr rhs,
663 Label* label) {
664 ma_b(lhs, rhs, label, cond);
665 }
666
667 void MacroAssembler::branchPtr(Condition cond, Register lhs, ImmGCPtr rhs,
668 Label* label) {
669 ma_b(lhs, rhs, label, cond);
670 }
671
672 void MacroAssembler::branchPtr(Condition cond, Register lhs, ImmWord rhs,
673 Label* label) {
674 ma_b(lhs, rhs, label, cond);
675 }
676
677 void MacroAssembler::branchPtr(Condition cond, const Address& lhs, Register rhs,
678 Label* label) {
679 loadPtr(lhs, SecondScratchReg);
680 branchPtr(cond, SecondScratchReg, rhs, label);
681 }
682
683 void MacroAssembler::branchPtr(Condition cond, const Address& lhs, ImmPtr rhs,
684 Label* label) {
685 loadPtr(lhs, SecondScratchReg);
686 branchPtr(cond, SecondScratchReg, rhs, label);
687 }
688
689 void MacroAssembler::branchPtr(Condition cond, const Address& lhs, ImmGCPtr rhs,
690 Label* label) {
691 loadPtr(lhs, SecondScratchReg);
692 branchPtr(cond, SecondScratchReg, rhs, label);
693 }
694
695 void MacroAssembler::branchPtr(Condition cond, const Address& lhs, ImmWord rhs,
696 Label* label) {
697 loadPtr(lhs, SecondScratchReg);
698 branchPtr(cond, SecondScratchReg, rhs, label);
699 }
700
701 void MacroAssembler::branchPtr(Condition cond, const AbsoluteAddress& lhs,
702 Register rhs, Label* label) {
703 loadPtr(lhs, SecondScratchReg);
704 branchPtr(cond, SecondScratchReg, rhs, label);
705 }
706
707 void MacroAssembler::branchPtr(Condition cond, const AbsoluteAddress& lhs,
708 ImmWord rhs, Label* label) {
709 loadPtr(lhs, SecondScratchReg);
710 branchPtr(cond, SecondScratchReg, rhs, label);
711 }
712
713 void MacroAssembler::branchPtr(Condition cond, wasm::SymbolicAddress lhs,
714 Register rhs, Label* label) {
715 loadPtr(lhs, SecondScratchReg);
716 branchPtr(cond, SecondScratchReg, rhs, label);
717 }
718
719 void MacroAssembler::branchPtr(Condition cond, const BaseIndex& lhs,
720 ImmWord rhs, Label* label) {
721 loadPtr(lhs, SecondScratchReg);
722 branchPtr(cond, SecondScratchReg, rhs, label);
723 }
724
725 void MacroAssembler::branchPtr(Condition cond, const BaseIndex& lhs,
726 Register rhs, Label* label) {
727 SecondScratchRegisterScope scratch(*this);
728 loadPtr(lhs, scratch);
729 branchPtr(cond, scratch, rhs, label);
730 }
731
732 void MacroAssembler::branchFloat(DoubleCondition cond, FloatRegister lhs,
733 FloatRegister rhs, Label* label) {
734 ma_bc1s(lhs, rhs, label, cond);
735 }
736
737 void MacroAssembler::branchTruncateFloat32ToInt32(FloatRegister src,
738 Register dest, Label* fail) {
739 convertFloat32ToInt32(src, dest, fail, false);
740 }
741
742 void MacroAssembler::branchDouble(DoubleCondition cond, FloatRegister lhs,
743 FloatRegister rhs, Label* label) {
744 ma_bc1d(lhs, rhs, label, cond);
745 }
746
747 template <typename T>
748 void MacroAssembler::branchAdd32(Condition cond, T src, Register dest,
749 Label* overflow) {
750 switch (cond) {
751 case Overflow:
752 ma_add32TestOverflow(dest, dest, src, overflow);
753 break;
754 case CarryClear:
755 case CarrySet:
756 ma_add32TestCarry(cond, dest, dest, src, overflow);
757 break;
758 default:
759 MOZ_CRASH("NYI");
760 }
761 }
762
763 template <typename T>
764 void MacroAssembler::branchSub32(Condition cond, T src, Register dest,
765 Label* overflow) {
766 switch (cond) {
767 case Overflow:
768 ma_sub32TestOverflow(dest, dest, src, overflow);
769 break;
770 case NonZero:
771 case Zero:
772 case Signed:
773 case NotSigned:
774 ma_subu(dest, src);
775 ma_b(dest, dest, overflow, cond);
776 break;
777 default:
778 MOZ_CRASH("NYI");
779 }
780 }
781
782 template <typename T>
783 void MacroAssembler::branchMul32(Condition cond, T src, Register dest,
784 Label* overflow) {
785 MOZ_ASSERT(cond == Assembler::Overflow);
786 ma_mul32TestOverflow(dest, dest, src, overflow);
787 }
788
789 template <typename T>
790 void MacroAssembler::branchRshift32(Condition cond, T src, Register dest,
791 Label* label) {
792 MOZ_ASSERT(cond == Zero || cond == NonZero);
793 rshift32(src, dest);
794 branch32(cond == Zero ? Equal : NotEqual, dest, Imm32(0), label);
795 }
796
797 void MacroAssembler::branchNeg32(Condition cond, Register reg, Label* label) {
798 MOZ_ASSERT(cond == Overflow);
799 neg32(reg);
800 branch32(Assembler::Equal, reg, Imm32(INT32_MIN), label);
801 }
802
803 template <typename T>
804 void MacroAssembler::branchAddPtr(Condition cond, T src, Register dest,
805 Label* label) {
806 switch (cond) {
807 case Overflow:
808 ma_addPtrTestOverflow(dest, dest, src, label);
809 break;
810 case CarryClear:
811 case CarrySet:
812 ma_addPtrTestCarry(cond, dest, dest, src, label);
813 break;
814 default:
815 MOZ_CRASH("NYI");
816 }
817 }
818
819 template <typename T>
820 void MacroAssembler::branchSubPtr(Condition cond, T src, Register dest,
821 Label* label) {
822 switch (cond) {
823 case Overflow:
824 ma_subPtrTestOverflow(dest, dest, src, label);
825 break;
826 case NonZero:
827 case Zero:
828 case Signed:
829 case NotSigned:
830 subPtr(src, dest);
831 ma_b(dest, dest, label, cond);
832 break;
833 default:
834 MOZ_CRASH("NYI");
835 }
836 }
837
838 void MacroAssembler::branchMulPtr(Condition cond, Register src, Register dest,
839 Label* label) {
840 MOZ_ASSERT(cond == Assembler::Overflow);
841 ma_mulPtrTestOverflow(dest, dest, src, label);
842 }
843
844 void MacroAssembler::branchNegPtr(Condition cond, Register reg, Label* label) {
845 MOZ_ASSERT(cond == Assembler::Overflow);
846 negPtr(reg);
847 branchPtr(Assembler::Equal, reg, ImmWord(INTPTR_MIN), label);
848 }
849
850 void MacroAssembler::decBranchPtr(Condition cond, Register lhs, Imm32 rhs,
851 Label* label) {
852 subPtr(rhs, lhs);
853 branchPtr(cond, lhs, Imm32(0), label);
854 }
855
856 void MacroAssembler::branchTest32(Condition cond, Register lhs, Register rhs,
857 Label* label) {
858 MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed ||
859 cond == NotSigned);
860 if (lhs == rhs) {
861 ma_b(lhs, rhs, label, cond);
862 } else {
863 as_and(ScratchRegister, lhs, rhs);
864 ma_b(ScratchRegister, ScratchRegister, label, cond);
865 }
866 }
867
868 void MacroAssembler::branchTest32(Condition cond, Register lhs, Imm32 rhs,
869 Label* label) {
870 MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed ||
871 cond == NotSigned);
872 ma_and(ScratchRegister, lhs, rhs);
873 ma_b(ScratchRegister, ScratchRegister, label, cond);
874 }
875
876 void MacroAssembler::branchTest32(Condition cond, const Address& lhs, Imm32 rhs,
877 Label* label) {
878 load32(lhs, SecondScratchReg);
879 branchTest32(cond, SecondScratchReg, rhs, label);
880 }
881
882 void MacroAssembler::branchTest32(Condition cond, const AbsoluteAddress& lhs,
883 Imm32 rhs, Label* label) {
884 load32(lhs, SecondScratchReg);
885 branchTest32(cond, SecondScratchReg, rhs, label);
886 }
887
888 void MacroAssembler::branchTestPtr(Condition cond, Register lhs, Register rhs,
889 Label* label) {
890 MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed ||
891 cond == NotSigned);
892 if (lhs == rhs) {
893 ma_b(lhs, rhs, label, cond);
894 } else {
895 as_and(ScratchRegister, lhs, rhs);
896 ma_b(ScratchRegister, ScratchRegister, label, cond);
897 }
898 }
899
900 void MacroAssembler::branchTestPtr(Condition cond, Register lhs, Imm32 rhs,
901 Label* label) {
902 MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed ||
903 cond == NotSigned);
904 ma_and(ScratchRegister, lhs, rhs);
905 ma_b(ScratchRegister, ScratchRegister, label, cond);
906 }
907
908 void MacroAssembler::branchTestPtr(Condition cond, Register lhs, ImmWord rhs,
909 Label* label) {
910 MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed ||
911 cond == NotSigned);
912 ScratchRegisterScope scratch(asMasm());
913 ma_li(scratch, rhs);
914 as_and(scratch, lhs, scratch);
915 ma_b(scratch, scratch, label, cond);
916 }
917
918 void MacroAssembler::branchTestPtr(Condition cond, const Address& lhs,
919 Imm32 rhs, Label* label) {
920 loadPtr(lhs, SecondScratchReg);
921 branchTestPtr(cond, SecondScratchReg, rhs, label);
922 }
923
924 void MacroAssembler::branchTestUndefined(Condition cond, Register tag,
925 Label* label) {
926 MOZ_ASSERT(cond == Equal || cond == NotEqual);
927 ma_b(tag, ImmTag(JSVAL_TAG_UNDEFINED), label, cond);
928 }
929
930 void MacroAssembler::branchTestUndefined(Condition cond, const Address& address,
931 Label* label) {
932 SecondScratchRegisterScope scratch2(*this);
933 Register tag = extractTag(address, scratch2);
934 branchTestUndefined(cond, tag, label);
935 }
936
937 void MacroAssembler::branchTestUndefined(Condition cond,
938 const BaseIndex& address,
939 Label* label) {
940 SecondScratchRegisterScope scratch2(*this);
941 Register tag = extractTag(address, scratch2);
942 branchTestUndefined(cond, tag, label);
943 }
944
945 void MacroAssembler::branchTestInt32(Condition cond, Register tag,
946 Label* label) {
947 MOZ_ASSERT(cond == Equal || cond == NotEqual);
948 ma_b(tag, ImmTag(JSVAL_TAG_INT32), label, cond);
949 }
950
951 void MacroAssembler::branchTestInt32(Condition cond, const Address& address,
952 Label* label) {
953 SecondScratchRegisterScope scratch2(*this);
954 Register tag = extractTag(address, scratch2);
955 branchTestInt32(cond, tag, label);
956 }
957
958 void MacroAssembler::branchTestInt32(Condition cond, const BaseIndex& address,
959 Label* label) {
960 SecondScratchRegisterScope scratch2(*this);
961 Register tag = extractTag(address, scratch2);
962 branchTestInt32(cond, tag, label);
963 }
964
965 void MacroAssembler::branchTestDouble(Condition cond, const Address& address,
966 Label* label) {
967 SecondScratchRegisterScope scratch2(*this);
968 Register tag = extractTag(address, scratch2);
969 branchTestDouble(cond, tag, label);
970 }
971
972 void MacroAssembler::branchTestDouble(Condition cond, const BaseIndex& address,
973 Label* label) {
974 SecondScratchRegisterScope scratch2(*this);
975 Register tag = extractTag(address, scratch2);
976 branchTestDouble(cond, tag, label);
977 }
978
979 void MacroAssembler::branchTestDoubleTruthy(bool b, FloatRegister value,
980 Label* label) {
981 ma_lid(ScratchDoubleReg, 0.0);
982 DoubleCondition cond = b ? DoubleNotEqual : DoubleEqualOrUnordered;
983 ma_bc1d(value, ScratchDoubleReg, label, cond);
984 }
985
986 void MacroAssembler::branchTestNumber(Condition cond, Register tag,
987 Label* label) {
988 MOZ_ASSERT(cond == Equal || cond == NotEqual);
989 Condition actual = cond == Equal ? BelowOrEqual : Above;
990 ma_b(tag, ImmTag(JS::detail::ValueUpperInclNumberTag), label, actual);
991 }
992
993 void MacroAssembler::branchTestBoolean(Condition cond, Register tag,
994 Label* label) {
995 MOZ_ASSERT(cond == Equal || cond == NotEqual);
996 ma_b(tag, ImmTag(JSVAL_TAG_BOOLEAN), label, cond);
997 }
998
999 void MacroAssembler::branchTestBoolean(Condition cond, const Address& address,
1000 Label* label) {
1001 SecondScratchRegisterScope scratch2(*this);
1002 Register tag = extractTag(address, scratch2);
1003 branchTestBoolean(cond, tag, label);
1004 }
1005
1006 void MacroAssembler::branchTestBoolean(Condition cond, const BaseIndex& address,
1007 Label* label) {
1008 SecondScratchRegisterScope scratch2(*this);
1009 Register tag = extractTag(address, scratch2);
1010 branchTestBoolean(cond, tag, label);
1011 }
1012
1013 void MacroAssembler::branchTestString(Condition cond, Register tag,
1014 Label* label) {
1015 MOZ_ASSERT(cond == Equal || cond == NotEqual);
1016 ma_b(tag, ImmTag(JSVAL_TAG_STRING), label, cond);
1017 }
1018
1019 void MacroAssembler::branchTestString(Condition cond, const Address& address,
1020 Label* label) {
1021 SecondScratchRegisterScope scratch2(*this);
1022 Register tag = extractTag(address, scratch2);
1023 branchTestString(cond, tag, label);
1024 }
1025
1026 void MacroAssembler::branchTestString(Condition cond, const BaseIndex& address,
1027 Label* label) {
1028 SecondScratchRegisterScope scratch2(*this);
1029 Register tag = extractTag(address, scratch2);
1030 branchTestString(cond, tag, label);
1031 }
1032
1033 void MacroAssembler::branchTestSymbol(Condition cond, Register tag,
1034 Label* label) {
1035 MOZ_ASSERT(cond == Equal || cond == NotEqual);
1036 ma_b(tag, ImmTag(JSVAL_TAG_SYMBOL), label, cond);
1037 }
1038
1039 void MacroAssembler::branchTestSymbol(Condition cond, const BaseIndex& address,
1040 Label* label) {
1041 SecondScratchRegisterScope scratch2(*this);
1042 Register tag = extractTag(address, scratch2);
1043 branchTestSymbol(cond, tag, label);
1044 }
1045
1046 void MacroAssembler::branchTestSymbol(Condition cond, const Address& address,
1047 Label* label) {
1048 SecondScratchRegisterScope scratch2(*this);
1049 Register tag = extractTag(address, scratch2);
1050 branchTestSymbol(cond, tag, label);
1051 }
1052
1053 void MacroAssembler::branchTestBigInt(Condition cond, Register tag,
1054 Label* label) {
1055 MOZ_ASSERT(cond == Equal || cond == NotEqual);
1056 ma_b(tag, ImmTag(JSVAL_TAG_BIGINT), label, cond);
1057 }
1058
1059 void MacroAssembler::branchTestBigInt(Condition cond, const Address& address,
1060 Label* label) {
1061 SecondScratchRegisterScope scratch2(*this);
1062 Register tag = extractTag(address, scratch2);
1063 branchTestBigInt(cond, tag, label);
1064 }
1065
1066 void MacroAssembler::branchTestNull(Condition cond, Register tag,
1067 Label* label) {
1068 MOZ_ASSERT(cond == Equal || cond == NotEqual);
1069 ma_b(tag, ImmTag(JSVAL_TAG_NULL), label, cond);
1070 }
1071
1072 void MacroAssembler::branchTestNull(Condition cond, const Address& address,
1073 Label* label) {
1074 SecondScratchRegisterScope scratch2(*this);
1075 Register tag = extractTag(address, scratch2);
1076 branchTestNull(cond, tag, label);
1077 }
1078
1079 void MacroAssembler::branchTestNull(Condition cond, const BaseIndex& address,
1080 Label* label) {
1081 SecondScratchRegisterScope scratch2(*this);
1082 Register tag = extractTag(address, scratch2);
1083 branchTestNull(cond, tag, label);
1084 }
1085
1086 void MacroAssembler::branchTestObject(Condition cond, Register tag,
1087 Label* label) {
1088 MOZ_ASSERT(cond == Equal || cond == NotEqual);
1089 ma_b(tag, ImmTag(JSVAL_TAG_OBJECT), label, cond);
1090 }
1091
1092 void MacroAssembler::branchTestObject(Condition cond, const Address& address,
1093 Label* label) {
1094 SecondScratchRegisterScope scratch2(*this);
1095 Register tag = extractTag(address, scratch2);
1096 branchTestObject(cond, tag, label);
1097 }
1098
1099 void MacroAssembler::branchTestObject(Condition cond, const BaseIndex& address,
1100 Label* label) {
1101 SecondScratchRegisterScope scratch2(*this);
1102 Register tag = extractTag(address, scratch2);
1103 branchTestObject(cond, tag, label);
1104 }
1105
1106 void MacroAssembler::branchTestGCThing(Condition cond, const Address& address,
1107 Label* label) {
1108 branchTestGCThingImpl(cond, address, label);
1109 }
1110
1111 void MacroAssembler::branchTestGCThing(Condition cond, const BaseIndex& address,
1112 Label* label) {
1113 branchTestGCThingImpl(cond, address, label);
1114 }
1115
1116 void MacroAssembler::branchTestGCThing(Condition cond,
1117 const ValueOperand& address,
1118 Label* label) {
1119 branchTestGCThingImpl(cond, address, label);
1120 }
1121
1122 template <typename T>
1123 void MacroAssembler::branchTestGCThingImpl(Condition cond, const T& address,
1124 Label* label) {
1125 MOZ_ASSERT(cond == Equal || cond == NotEqual);
1126 SecondScratchRegisterScope scratch2(*this);
1127 Register tag = extractTag(address, scratch2);
1128 ma_b(tag, ImmTag(JS::detail::ValueLowerInclGCThingTag), label,
1129 (cond == Equal) ? AboveOrEqual : Below);
1130 }
1131
1132 void MacroAssembler::branchTestPrimitive(Condition cond, Register tag,
1133 Label* label) {
1134 MOZ_ASSERT(cond == Equal || cond == NotEqual);
1135 ma_b(tag, ImmTag(JS::detail::ValueUpperExclPrimitiveTag), label,
1136 (cond == Equal) ? Below : AboveOrEqual);
1137 }
1138
1139 void MacroAssembler::branchTestMagic(Condition cond, Register tag,
1140 Label* label) {
1141 MOZ_ASSERT(cond == Equal || cond == NotEqual);
1142 ma_b(tag, ImmTag(JSVAL_TAG_MAGIC), label, cond);
1143 }
1144
1145 void MacroAssembler::branchTestMagic(Condition cond, const Address& address,
1146 Label* label) {
1147 SecondScratchRegisterScope scratch2(*this);
1148 Register tag = extractTag(address, scratch2);
1149 branchTestMagic(cond, tag, label);
1150 }
1151
1152 void MacroAssembler::branchTestMagic(Condition cond, const BaseIndex& address,
1153 Label* label) {
1154 SecondScratchRegisterScope scratch2(*this);
1155 Register tag = extractTag(address, scratch2);
1156 branchTestMagic(cond, tag, label);
1157 }
1158
1159 template <typename T>
1160 void MacroAssembler::testNumberSet(Condition cond, const T& src,
1161 Register dest) {
1162 MOZ_ASSERT(cond == Equal || cond == NotEqual);
1163 SecondScratchRegisterScope scratch2(*this);
1164 Register tag = extractTag(src, scratch2);
1165 ma_cmp_set(dest, tag, ImmTag(JS::detail::ValueUpperInclNumberTag),
1166 cond == Equal ? BelowOrEqual : Above);
1167 }
1168
1169 template <typename T>
1170 void MacroAssembler::testBooleanSet(Condition cond, const T& src,
1171 Register dest) {
1172 MOZ_ASSERT(cond == Equal || cond == NotEqual);
1173 SecondScratchRegisterScope scratch2(*this);
1174 Register tag = extractTag(src, scratch2);
1175 ma_cmp_set(dest, tag, ImmTag(JSVAL_TAG_BOOLEAN), cond);
1176 }
1177
1178 template <typename T>
1179 void MacroAssembler::testStringSet(Condition cond, const T& src,
1180 Register dest) {
1181 MOZ_ASSERT(cond == Equal || cond == NotEqual);
1182 SecondScratchRegisterScope scratch2(*this);
1183 Register tag = extractTag(src, scratch2);
1184 ma_cmp_set(dest, tag, ImmTag(JSVAL_TAG_STRING), cond);
1185 }
1186
1187 template <typename T>
1188 void MacroAssembler::testSymbolSet(Condition cond, const T& src,
1189 Register dest) {
1190 MOZ_ASSERT(cond == Equal || cond == NotEqual);
1191 SecondScratchRegisterScope scratch2(*this);
1192 Register tag = extractTag(src, scratch2);
1193 ma_cmp_set(dest, tag, ImmTag(JSVAL_TAG_SYMBOL), cond);
1194 }
1195
1196 template <typename T>
1197 void MacroAssembler::testBigIntSet(Condition cond, const T& src,
1198 Register dest) {
1199 MOZ_ASSERT(cond == Equal || cond == NotEqual);
1200 SecondScratchRegisterScope scratch2(*this);
1201 Register tag = extractTag(src, scratch2);
1202 ma_cmp_set(dest, tag, ImmTag(JSVAL_TAG_BIGINT), cond);
1203 }
1204
1205 void MacroAssembler::branchToComputedAddress(const BaseIndex& addr) {
1206 loadPtr(addr, ScratchRegister);
1207 branch(ScratchRegister);
1208 }
1209
1210 void MacroAssembler::cmp32Move32(Condition cond, Register lhs, Imm32 rhs,
1211 Register src, Register dest) {
1212 Register scratch = ScratchRegister;
1213 MOZ_ASSERT(src != scratch && dest != scratch);
1214 cmp32Set(cond, lhs, rhs, scratch);
1215 #ifdef MIPSR6
1216 as_selnez(src, src, scratch);
1217 as_seleqz(dest, dest, scratch);
1218 as_or(dest, dest, src);
1219 #else
1220 as_movn(dest, src, scratch);
1221 #endif
1222 }
1223
1224 void MacroAssembler::cmp32Move32(Condition cond, Register lhs, Register rhs,
1225 Register src, Register dest) {
1226 Register scratch = ScratchRegister;
1227 MOZ_ASSERT(src != scratch && dest != scratch);
1228 cmp32Set(cond, lhs, rhs, scratch);
1229 #ifdef MIPSR6
1230 as_selnez(src, src, scratch);
1231 as_seleqz(dest, dest, scratch);
1232 as_or(dest, dest, src);
1233 #else
1234 as_movn(dest, src, scratch);
1235 #endif
1236 }
1237
1238 void MacroAssembler::cmp32MovePtr(Condition cond, Register lhs, Imm32 rhs,
1239 Register src, Register dest) {
1240 Register scratch = ScratchRegister;
1241 MOZ_ASSERT(src != scratch && dest != scratch);
1242 cmp32Set(cond, lhs, rhs, scratch);
1243 #ifdef MIPSR6
1244 as_selnez(src, src, scratch);
1245 as_seleqz(dest, dest, scratch);
1246 as_or(dest, dest, src);
1247 #else
1248 as_movn(dest, src, scratch);
1249 #endif
1250 }
1251
1252 void MacroAssembler::cmp32Move32(Condition cond, Register lhs,
1253 const Address& rhs, Register src,
1254 Register dest) {
1255 SecondScratchRegisterScope scratch2(*this);
1256 MOZ_ASSERT(lhs != scratch2 && src != scratch2 && dest != scratch2);
1257 load32(rhs, scratch2);
1258 cmp32Move32(cond, lhs, scratch2, src, dest);
1259 }
1260
1261 void MacroAssembler::cmp32Load32(Condition cond, Register lhs,
1262 const Address& rhs, const Address& src,
1263 Register dest) {
1264 ScratchRegisterScope scratch(*this);
1265 MOZ_ASSERT(lhs != scratch && dest != scratch);
1266 load32(rhs, scratch);
1267 cmp32Load32(cond, lhs, scratch, src, dest);
1268 }
1269
1270 void MacroAssembler::cmp32Load32(Condition cond, Register lhs, Register rhs,
1271 const Address& src, Register dest) {
1272 Label skip;
1273 branch32(Assembler::InvertCondition(cond), lhs, rhs, &skip);
1274 load32(src, dest);
1275 bind(&skip);
1276 }
1277
1278 void MacroAssembler::cmp32Load32(Condition cond, Register lhs, Imm32 rhs,
1279 const Address& src, Register dest) {
1280 Label skip;
1281 branch32(Assembler::InvertCondition(cond), lhs, rhs, &skip);
1282 load32(src, dest);
1283 bind(&skip);
1284 }
1285
1286 void MacroAssembler::cmp32LoadPtr(Condition cond, const Address& lhs, Imm32 rhs,
1287 const Address& src, Register dest) {
1288 Label skip;
1289 branch32(Assembler::InvertCondition(cond), lhs, rhs, &skip);
1290 loadPtr(src, dest);
1291 bind(&skip);
1292 }
1293
1294 void MacroAssembler::test32LoadPtr(Condition cond, const Address& addr,
1295 Imm32 mask, const Address& src,
1296 Register dest) {
1297 MOZ_RELEASE_ASSERT(!JitOptions.spectreStringMitigations);
1298 Label skip;
1299 branchTest32(Assembler::InvertCondition(cond), addr, mask, &skip);
1300 loadPtr(src, dest);
1301 bind(&skip);
1302 }
1303
1304 void MacroAssembler::test32MovePtr(Condition cond, Register operand, Imm32 mask,
1305 Register src, Register dest) {
1306 MOZ_ASSERT(cond == Assembler::Zero || cond == Assembler::NonZero);
1307 Label skip;
1308 branchTest32(Assembler::InvertCondition(cond), operand, mask, &skip);
1309 movePtr(src, dest);
1310 bind(&skip);
1311 }
1312
1313 void MacroAssembler::test32MovePtr(Condition cond, const Address& addr,
1314 Imm32 mask, Register src, Register dest) {
1315 MOZ_ASSERT(cond == Assembler::Zero || cond == Assembler::NonZero);
1316 Label skip;
1317 branchTest32(Assembler::InvertCondition(cond), addr, mask, &skip);
1318 movePtr(src, dest);
1319 bind(&skip);
1320 }
1321
1322 void MacroAssembler::spectreBoundsCheck32(Register index, Register length,
1323 Register maybeScratch,
1324 Label* failure) {
1325 MOZ_RELEASE_ASSERT(!JitOptions.spectreIndexMasking);
1326 branch32(Assembler::BelowOrEqual, length, index, failure);
1327 }
1328
1329 void MacroAssembler::spectreBoundsCheck32(Register index, const Address& length,
1330 Register maybeScratch,
1331 Label* failure) {
1332 MOZ_RELEASE_ASSERT(!JitOptions.spectreIndexMasking);
1333 branch32(Assembler::BelowOrEqual, length, index, failure);
1334 }
1335
1336 void MacroAssembler::spectreBoundsCheckPtr(Register index, Register length,
1337 Register maybeScratch,
1338 Label* failure) {
1339 MOZ_RELEASE_ASSERT(!JitOptions.spectreIndexMasking);
1340 branchPtr(Assembler::BelowOrEqual, length, index, failure);
1341 }
1342
1343 void MacroAssembler::spectreBoundsCheckPtr(Register index,
1344 const Address& length,
1345 Register maybeScratch,
1346 Label* failure) {
1347 MOZ_RELEASE_ASSERT(!JitOptions.spectreIndexMasking);
1348 branchPtr(Assembler::BelowOrEqual, length, index, failure);
1349 }
1350
1351 void MacroAssembler::spectreMovePtr(Condition cond, Register src,
1352 Register dest) {
1353 MOZ_CRASH();
1354 }
1355
1356 void MacroAssembler::spectreZeroRegister(Condition cond, Register scratch,
1357 Register dest) {
1358 MOZ_CRASH();
1359 }
1360
1361 // ========================================================================
1362 // Memory access primitives.
1363
1364 FaultingCodeOffset MacroAssembler::storeDouble(FloatRegister src,
1365 const Address& addr) {
1366 return ma_sd(src, addr);
1367 }
1368 FaultingCodeOffset MacroAssembler::storeDouble(FloatRegister src,
1369 const BaseIndex& addr) {
1370 return ma_sd(src, addr);
1371 }
1372
1373 FaultingCodeOffset MacroAssembler::storeFloat32(FloatRegister src,
1374 const Address& addr) {
1375 return ma_ss(src, addr);
1376 }
1377 FaultingCodeOffset MacroAssembler::storeFloat32(FloatRegister src,
1378 const BaseIndex& addr) {
1379 return ma_ss(src, addr);
1380 }
1381
1382 FaultingCodeOffset MacroAssembler::storeFloat16(FloatRegister src,
1383 const Address& dest, Register) {
1384 MOZ_CRASH("Not supported for this target");
1385 }
1386 FaultingCodeOffset MacroAssembler::storeFloat16(FloatRegister src,
1387 const BaseIndex& dest,
1388 Register) {
1389 MOZ_CRASH("Not supported for this target");
1390 }
1391
1392 void MacroAssembler::memoryBarrier(MemoryBarrier barrier) {
1393 if (!barrier.isNone()) {
1394 as_sync();
1395 }
1396 }
1397
1398 // ===============================================================
1399 // Clamping functions.
1400
1401 void MacroAssembler::clampIntToUint8(Register reg) {
1402 // If reg is < 0, then we want to clamp to 0.
1403 as_slti(ScratchRegister, reg, 0);
1404 #ifdef MIPSR6
1405 as_seleqz(reg, reg, ScratchRegister);
1406 #else
1407 as_movn(reg, zero, ScratchRegister);
1408 #endif
1409 // If reg is >= 255, then we want to clamp to 255.
1410 ma_li(SecondScratchReg, Imm32(255));
1411 as_slti(ScratchRegister, reg, 255);
1412 #ifdef MIPSR6
1413 as_seleqz(SecondScratchReg, SecondScratchReg, ScratchRegister);
1414 as_selnez(reg, reg, ScratchRegister);
1415 as_or(reg, reg, SecondScratchReg);
1416 #else
1417 as_movz(reg, SecondScratchReg, ScratchRegister);
1418 #endif
1419 }
1420
1421 //}}} check_macroassembler_style
1422 // ===============================================================
1423
1424 } // namespace jit
1425 } // namespace js
1426
1427 #endif /* jit_mips_shared_MacroAssembler_mips_shared_inl_h */