summaryrefslogtreecommitdiffstats
path: root/js/src/jit/arm/MacroAssembler-arm.h
blob: 958cdf4718c0b0a6e83ee894629fd00259cf365b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: set ts=8 sts=2 et sw=2 tw=80:
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef jit_arm_MacroAssembler_arm_h
#define jit_arm_MacroAssembler_arm_h

#include "mozilla/DebugOnly.h"

#include "jit/arm/Assembler-arm.h"
#include "jit/MoveResolver.h"
#include "vm/BytecodeUtil.h"
#include "wasm/WasmBuiltins.h"
#include "wasm/WasmCodegenTypes.h"

namespace js {
namespace jit {

static Register CallReg = ip;
static const int defaultShift = 3;
static_assert(1 << defaultShift == sizeof(JS::Value));

// See documentation for ScratchTagScope and ScratchTagScopeRelease in
// MacroAssembler-x64.h.

class ScratchTagScope {
  const ValueOperand& v_;

 public:
  ScratchTagScope(MacroAssembler&, const ValueOperand& v) : v_(v) {}
  operator Register() { return v_.typeReg(); }
  void release() {}
  void reacquire() {}
};

class ScratchTagScopeRelease {
 public:
  explicit ScratchTagScopeRelease(ScratchTagScope*) {}
};

// MacroAssemblerARM is inheriting form Assembler defined in
// Assembler-arm.{h,cpp}
class MacroAssemblerARM : public Assembler {
 private:
  // Perform a downcast. Should be removed by Bug 996602.
  MacroAssembler& asMasm();
  const MacroAssembler& asMasm() const;

 protected:
  // On ARM, some instructions require a second scratch register. This
  // register defaults to lr, since it's non-allocatable (as it can be
  // clobbered by some instructions). Allow the baseline compiler to override
  // this though, since baseline IC stubs rely on lr holding the return
  // address.
  Register secondScratchReg_;

 public:
  Register getSecondScratchReg() const { return secondScratchReg_; }

 public:
  // Higher level tag testing code.
  // TODO: Can probably remove the Operand versions.
  Operand ToPayload(Operand base) const {
    return Operand(Register::FromCode(base.base()), base.disp());
  }
  Address ToPayload(const Address& base) const { return base; }
  BaseIndex ToPayload(const BaseIndex& base) const { return base; }

 protected:
  Operand ToType(Operand base) const {
    return Operand(Register::FromCode(base.base()),
                   base.disp() + sizeof(void*));
  }
  Address ToType(const Address& base) const {
    return ToType(Operand(base)).toAddress();
  }
  BaseIndex ToType(const BaseIndex& base) const {
    return BaseIndex(base.base, base.index, base.scale,
                     base.offset + sizeof(void*));
  }

  Address ToPayloadAfterStackPush(const Address& base) const {
    // If we are based on StackPointer, pass over the type tag just pushed.
    if (base.base == StackPointer) {
      return Address(base.base, base.offset + sizeof(void*));
    }
    return ToPayload(base);
  }

 public:
  MacroAssemblerARM() : secondScratchReg_(lr) {}

  void setSecondScratchReg(Register reg) {
    MOZ_ASSERT(reg != ScratchRegister);
    secondScratchReg_ = reg;
  }

  void convertBoolToInt32(Register source, Register dest);
  void convertInt32ToDouble(Register src, FloatRegister dest);
  void convertInt32ToDouble(const Address& src, FloatRegister dest);
  void convertInt32ToDouble(const BaseIndex& src, FloatRegister dest);
  void convertUInt32ToFloat32(Register src, FloatRegister dest);
  void convertUInt32ToDouble(Register src, FloatRegister dest);
  void convertDoubleToFloat32(FloatRegister src, FloatRegister dest,
                              Condition c = Always);
  void convertDoubleToInt32(FloatRegister src, Register dest, Label* fail,
                            bool negativeZeroCheck = true);
  void convertDoubleToPtr(FloatRegister src, Register dest, Label* fail,
                          bool negativeZeroCheck = true) {
    convertDoubleToInt32(src, dest, fail, negativeZeroCheck);
  }
  void convertFloat32ToInt32(FloatRegister src, Register dest, Label* fail,
                             bool negativeZeroCheck = true);

  void convertFloat32ToDouble(FloatRegister src, FloatRegister dest);
  void convertInt32ToFloat32(Register src, FloatRegister dest);
  void convertInt32ToFloat32(const Address& src, FloatRegister dest);

  void wasmTruncateToInt32(FloatRegister input, Register output,
                           MIRType fromType, bool isUnsigned, bool isSaturating,
                           Label* oolEntry);
  void outOfLineWasmTruncateToIntCheck(FloatRegister input, MIRType fromType,
                                       MIRType toType, TruncFlags flags,
                                       Label* rejoin,
                                       wasm::BytecodeOffset trapOffset);

  // Somewhat direct wrappers for the low-level assembler funcitons
  // bitops. Attempt to encode a virtual alu instruction using two real
  // instructions.
 private:
  bool alu_dbl(Register src1, Imm32 imm, Register dest, ALUOp op, SBit s,
               Condition c);

 public:
  void ma_alu(Register src1, Imm32 imm, Register dest,
              AutoRegisterScope& scratch, ALUOp op, SBit s = LeaveCC,
              Condition c = Always);
  void ma_alu(Register src1, Operand2 op2, Register dest, ALUOp op,
              SBit s = LeaveCC, Condition c = Always);
  void ma_alu(Register src1, Operand op2, Register dest, ALUOp op,
              SBit s = LeaveCC, Condition c = Always);
  void ma_nop();

  BufferOffset ma_movPatchable(Imm32 imm, Register dest,
                               Assembler::Condition c);
  BufferOffset ma_movPatchable(ImmPtr imm, Register dest,
                               Assembler::Condition c);

  // To be used with Iter := InstructionIterator or BufferInstructionIterator.
  template <class Iter>
  static void ma_mov_patch(Imm32 imm, Register dest, Assembler::Condition c,
                           RelocStyle rs, Iter iter);

  // ALU based ops
  // mov
  void ma_mov(Register src, Register dest, SBit s = LeaveCC,
              Condition c = Always);

  void ma_mov(Imm32 imm, Register dest, Condition c = Always);
  void ma_mov(ImmWord imm, Register dest, Condition c = Always);

  void ma_mov(ImmGCPtr ptr, Register dest);

  // Shifts (just a move with a shifting op2)
  void ma_lsl(Imm32 shift, Register src, Register dst);
  void ma_lsr(Imm32 shift, Register src, Register dst);
  void ma_asr(Imm32 shift, Register src, Register dst);
  void ma_ror(Imm32 shift, Register src, Register dst);
  void ma_rol(Imm32 shift, Register src, Register dst);

  void ma_lsl(Register shift, Register src, Register dst);
  void ma_lsr(Register shift, Register src, Register dst);
  void ma_asr(Register shift, Register src, Register dst);
  void ma_ror(Register shift, Register src, Register dst);
  void ma_rol(Register shift, Register src, Register dst,
              AutoRegisterScope& scratch);

  // Move not (dest <- ~src)
  void ma_mvn(Register src1, Register dest, SBit s = LeaveCC,
              Condition c = Always);

  // Negate (dest <- -src) implemented as rsb dest, src, 0
  void ma_neg(Register src, Register dest, SBit s = LeaveCC,
              Condition c = Always);

  void ma_neg(Register64 src, Register64 dest);

  // And
  void ma_and(Register src, Register dest, SBit s = LeaveCC,
              Condition c = Always);

  void ma_and(Register src1, Register src2, Register dest, SBit s = LeaveCC,
              Condition c = Always);

  void ma_and(Imm32 imm, Register dest, AutoRegisterScope& scratch,
              SBit s = LeaveCC, Condition c = Always);

  void ma_and(Imm32 imm, Register src1, Register dest,
              AutoRegisterScope& scratch, SBit s = LeaveCC,
              Condition c = Always);

  // Bit clear (dest <- dest & ~imm) or (dest <- src1 & ~src2)
  void ma_bic(Imm32 imm, Register dest, AutoRegisterScope& scratch,
              SBit s = LeaveCC, Condition c = Always);

  // Exclusive or
  void ma_eor(Register src, Register dest, SBit s = LeaveCC,
              Condition c = Always);

  void ma_eor(Register src1, Register src2, Register dest, SBit s = LeaveCC,
              Condition c = Always);

  void ma_eor(Imm32 imm, Register dest, AutoRegisterScope& scratch,
              SBit s = LeaveCC, Condition c = Always);

  void ma_eor(Imm32 imm, Register src1, Register dest,
              AutoRegisterScope& scratch, SBit s = LeaveCC,
              Condition c = Always);

  // Or
  void ma_orr(Register src, Register dest, SBit s = LeaveCC,
              Condition c = Always);

  void ma_orr(Register src1, Register src2, Register dest, SBit s = LeaveCC,
              Condition c = Always);

  void ma_orr(Imm32 imm, Register dest, AutoRegisterScope& scratch,
              SBit s = LeaveCC, Condition c = Always);

  void ma_orr(Imm32 imm, Register src1, Register dest,
              AutoRegisterScope& scratch, SBit s = LeaveCC,
              Condition c = Always);

  // Arithmetic based ops.
  // Add with carry:
  void ma_adc(Imm32 imm, Register dest, AutoRegisterScope& scratch,
              SBit s = LeaveCC, Condition c = Always);
  void ma_adc(Register src, Register dest, SBit s = LeaveCC,
              Condition c = Always);
  void ma_adc(Register src1, Register src2, Register dest, SBit s = LeaveCC,
              Condition c = Always);
  void ma_adc(Register src1, Imm32 op, Register dest,
              AutoRegisterScope& scratch, SBit s = LeaveCC,
              Condition c = Always);

  // Add:
  void ma_add(Imm32 imm, Register dest, AutoRegisterScope& scratch,
              SBit s = LeaveCC, Condition c = Always);
  void ma_add(Register src1, Register dest, SBit s = LeaveCC,
              Condition c = Always);
  void ma_add(Register src1, Register src2, Register dest, SBit s = LeaveCC,
              Condition c = Always);
  void ma_add(Register src1, Operand op, Register dest, SBit s = LeaveCC,
              Condition c = Always);
  void ma_add(Register src1, Imm32 op, Register dest,
              AutoRegisterScope& scratch, SBit s = LeaveCC,
              Condition c = Always);

  // Subtract with carry:
  void ma_sbc(Imm32 imm, Register dest, AutoRegisterScope& scratch,
              SBit s = LeaveCC, Condition c = Always);
  void ma_sbc(Register src1, Register dest, SBit s = LeaveCC,
              Condition c = Always);
  void ma_sbc(Register src1, Register src2, Register dest, SBit s = LeaveCC,
              Condition c = Always);

  // Subtract:
  void ma_sub(Imm32 imm, Register dest, AutoRegisterScope& scratch,
              SBit s = LeaveCC, Condition c = Always);
  void ma_sub(Register src1, Register dest, SBit s = LeaveCC,
              Condition c = Always);
  void ma_sub(Register src1, Register src2, Register dest, SBit s = LeaveCC,
              Condition c = Always);
  void ma_sub(Register src1, Operand op, Register dest, SBit s = LeaveCC,
              Condition c = Always);
  void ma_sub(Register src1, Imm32 op, Register dest,
              AutoRegisterScope& scratch, SBit s = LeaveCC,
              Condition c = Always);

  // Reverse subtract:
  void ma_rsb(Imm32 imm, Register dest, AutoRegisterScope& scratch,
              SBit s = LeaveCC, Condition c = Always);
  void ma_rsb(Register src1, Register dest, SBit s = LeaveCC,
              Condition c = Always);
  void ma_rsb(Register src1, Register src2, Register dest, SBit s = LeaveCC,
              Condition c = Always);
  void ma_rsb(Register src1, Imm32 op2, Register dest,
              AutoRegisterScope& scratch, SBit s = LeaveCC,
              Condition c = Always);

  // Reverse subtract with carry:
  void ma_rsc(Imm32 imm, Register dest, AutoRegisterScope& scratch,
              SBit s = LeaveCC, Condition c = Always);
  void ma_rsc(Register src1, Register dest, SBit s = LeaveCC,
              Condition c = Always);
  void ma_rsc(Register src1, Register src2, Register dest, SBit s = LeaveCC,
              Condition c = Always);

  // Compares/tests.
  // Compare negative (sets condition codes as src1 + src2 would):
  void ma_cmn(Register src1, Imm32 imm, AutoRegisterScope& scratch,
              Condition c = Always);
  void ma_cmn(Register src1, Register src2, Condition c = Always);
  void ma_cmn(Register src1, Operand op, Condition c = Always);

  // Compare (src - src2):
  void ma_cmp(Register src1, Imm32 imm, AutoRegisterScope& scratch,
              Condition c = Always);
  void ma_cmp(Register src1, ImmTag tag, Condition c = Always);
  void ma_cmp(Register src1, ImmWord ptr, AutoRegisterScope& scratch,
              Condition c = Always);
  void ma_cmp(Register src1, ImmGCPtr ptr, AutoRegisterScope& scratch,
              Condition c = Always);
  void ma_cmp(Register src1, Operand op, AutoRegisterScope& scratch,
              AutoRegisterScope& scratch2, Condition c = Always);
  void ma_cmp(Register src1, Register src2, Condition c = Always);

  // Test for equality, (src1 ^ src2):
  void ma_teq(Register src1, Imm32 imm, AutoRegisterScope& scratch,
              Condition c = Always);
  void ma_teq(Register src1, Register src2, Condition c = Always);
  void ma_teq(Register src1, Operand op, Condition c = Always);

  // Test (src1 & src2):
  void ma_tst(Register src1, Imm32 imm, AutoRegisterScope& scratch,
              Condition c = Always);
  void ma_tst(Register src1, Register src2, Condition c = Always);
  void ma_tst(Register src1, Operand op, Condition c = Always);

  // Multiplies. For now, there are only two that we care about.
  void ma_mul(Register src1, Register src2, Register dest);
  void ma_mul(Register src1, Imm32 imm, Register dest,
              AutoRegisterScope& scratch);
  Condition ma_check_mul(Register src1, Register src2, Register dest,
                         AutoRegisterScope& scratch, Condition cond);
  Condition ma_check_mul(Register src1, Imm32 imm, Register dest,
                         AutoRegisterScope& scratch, Condition cond);

  void ma_umull(Register src1, Imm32 imm, Register destHigh, Register destLow,
                AutoRegisterScope& scratch);
  void ma_umull(Register src1, Register src2, Register destHigh,
                Register destLow);

  // Fast mod, uses scratch registers, and thus needs to be in the assembler
  // implicitly assumes that we can overwrite dest at the beginning of the
  // sequence.
  void ma_mod_mask(Register src, Register dest, Register hold, Register tmp,
                   AutoRegisterScope& scratch, AutoRegisterScope& scratch2,
                   int32_t shift);

  // Mod - depends on integer divide instructions being supported.
  void ma_smod(Register num, Register div, Register dest,
               AutoRegisterScope& scratch);
  void ma_umod(Register num, Register div, Register dest,
               AutoRegisterScope& scratch);

  // Division - depends on integer divide instructions being supported.
  void ma_sdiv(Register num, Register div, Register dest,
               Condition cond = Always);
  void ma_udiv(Register num, Register div, Register dest,
               Condition cond = Always);
  // Misc operations
  void ma_clz(Register src, Register dest, Condition cond = Always);
  void ma_ctz(Register src, Register dest, AutoRegisterScope& scratch);
  // Memory:
  // Shortcut for when we know we're transferring 32 bits of data.
  void ma_dtr(LoadStore ls, Register rn, Imm32 offset, Register rt,
              AutoRegisterScope& scratch, Index mode = Offset,
              Condition cc = Always);
  void ma_dtr(LoadStore ls, Register rt, const Address& addr,
              AutoRegisterScope& scratch, Index mode, Condition cc);

  void ma_str(Register rt, DTRAddr addr, Index mode = Offset,
              Condition cc = Always);
  void ma_str(Register rt, const Address& addr, AutoRegisterScope& scratch,
              Index mode = Offset, Condition cc = Always);

  void ma_ldr(DTRAddr addr, Register rt, Index mode = Offset,
              Condition cc = Always);
  void ma_ldr(const Address& addr, Register rt, AutoRegisterScope& scratch,
              Index mode = Offset, Condition cc = Always);

  void ma_ldrb(DTRAddr addr, Register rt, Index mode = Offset,
               Condition cc = Always);
  void ma_ldrh(EDtrAddr addr, Register rt, Index mode = Offset,
               Condition cc = Always);
  void ma_ldrsh(EDtrAddr addr, Register rt, Index mode = Offset,
                Condition cc = Always);
  void ma_ldrsb(EDtrAddr addr, Register rt, Index mode = Offset,
                Condition cc = Always);
  void ma_ldrd(EDtrAddr addr, Register rt, mozilla::DebugOnly<Register> rt2,
               Index mode = Offset, Condition cc = Always);
  void ma_strb(Register rt, DTRAddr addr, Index mode = Offset,
               Condition cc = Always);
  void ma_strh(Register rt, EDtrAddr addr, Index mode = Offset,
               Condition cc = Always);
  void ma_strd(Register rt, mozilla::DebugOnly<Register> rt2, EDtrAddr addr,
               Index mode = Offset, Condition cc = Always);

  // Specialty for moving N bits of data, where n == 8,16,32,64.
  BufferOffset ma_dataTransferN(LoadStore ls, int size, bool IsSigned,
                                Register rn, Register rm, Register rt,
                                AutoRegisterScope& scratch, Index mode = Offset,
                                Condition cc = Always, Scale scale = TimesOne);

  BufferOffset ma_dataTransferN(LoadStore ls, int size, bool IsSigned,
                                Register rn, Register rm, Register rt,
                                Index mode = Offset, Condition cc = Always);

  BufferOffset ma_dataTransferN(LoadStore ls, int size, bool IsSigned,
                                Register rn, Imm32 offset, Register rt,
                                AutoRegisterScope& scratch, Index mode = Offset,
                                Condition cc = Always);

  void ma_pop(Register r);
  void ma_popn_pc(Imm32 n, AutoRegisterScope& scratch,
                  AutoRegisterScope& scratch2);
  void ma_push(Register r);
  void ma_push_sp(Register r, AutoRegisterScope& scratch);

  void ma_vpop(VFPRegister r);
  void ma_vpush(VFPRegister r);

  // Barriers.
  void ma_dmb(BarrierOption option = BarrierSY);
  void ma_dsb(BarrierOption option = BarrierSY);

  // Branches when done from within arm-specific code.
  BufferOffset ma_b(Label* dest, Condition c = Always);
  void ma_b(void* target, Condition c = Always);
  void ma_bx(Register dest, Condition c = Always);

  // This is almost NEVER necessary, we'll basically never be calling a label
  // except, possibly in the crazy bailout-table case.
  void ma_bl(Label* dest, Condition c = Always);

  void ma_blx(Register dest, Condition c = Always);

  // VFP/ALU:
  void ma_vadd(FloatRegister src1, FloatRegister src2, FloatRegister dst);
  void ma_vsub(FloatRegister src1, FloatRegister src2, FloatRegister dst);

  void ma_vmul(FloatRegister src1, FloatRegister src2, FloatRegister dst);
  void ma_vdiv(FloatRegister src1, FloatRegister src2, FloatRegister dst);

  void ma_vneg(FloatRegister src, FloatRegister dest, Condition cc = Always);
  void ma_vmov(FloatRegister src, FloatRegister dest, Condition cc = Always);
  void ma_vmov_f32(FloatRegister src, FloatRegister dest,
                   Condition cc = Always);
  void ma_vabs(FloatRegister src, FloatRegister dest, Condition cc = Always);
  void ma_vabs_f32(FloatRegister src, FloatRegister dest,
                   Condition cc = Always);

  void ma_vsqrt(FloatRegister src, FloatRegister dest, Condition cc = Always);
  void ma_vsqrt_f32(FloatRegister src, FloatRegister dest,
                    Condition cc = Always);

  void ma_vimm(double value, FloatRegister dest, Condition cc = Always);
  void ma_vimm_f32(float value, FloatRegister dest, Condition cc = Always);

  void ma_vcmp(FloatRegister src1, FloatRegister src2, Condition cc = Always);
  void ma_vcmp_f32(FloatRegister src1, FloatRegister src2,
                   Condition cc = Always);
  void ma_vcmpz(FloatRegister src1, Condition cc = Always);
  void ma_vcmpz_f32(FloatRegister src1, Condition cc = Always);

  void ma_vadd_f32(FloatRegister src1, FloatRegister src2, FloatRegister dst);
  void ma_vsub_f32(FloatRegister src1, FloatRegister src2, FloatRegister dst);

  void ma_vmul_f32(FloatRegister src1, FloatRegister src2, FloatRegister dst);
  void ma_vdiv_f32(FloatRegister src1, FloatRegister src2, FloatRegister dst);

  void ma_vneg_f32(FloatRegister src, FloatRegister dest,
                   Condition cc = Always);

  // Source is F64, dest is I32:
  void ma_vcvt_F64_I32(FloatRegister src, FloatRegister dest,
                       Condition cc = Always);
  void ma_vcvt_F64_U32(FloatRegister src, FloatRegister dest,
                       Condition cc = Always);

  // Source is I32, dest is F64:
  void ma_vcvt_I32_F64(FloatRegister src, FloatRegister dest,
                       Condition cc = Always);
  void ma_vcvt_U32_F64(FloatRegister src, FloatRegister dest,
                       Condition cc = Always);

  // Source is F32, dest is I32:
  void ma_vcvt_F32_I32(FloatRegister src, FloatRegister dest,
                       Condition cc = Always);
  void ma_vcvt_F32_U32(FloatRegister src, FloatRegister dest,
                       Condition cc = Always);

  // Source is I32, dest is F32:
  void ma_vcvt_I32_F32(FloatRegister src, FloatRegister dest,
                       Condition cc = Always);
  void ma_vcvt_U32_F32(FloatRegister src, FloatRegister dest,
                       Condition cc = Always);

  // Transfer (do not coerce) a float into a gpr.
  void ma_vxfer(VFPRegister src, Register dest, Condition cc = Always);
  // Transfer (do not coerce) a double into a couple of gpr.
  void ma_vxfer(VFPRegister src, Register dest1, Register dest2,
                Condition cc = Always);

  // Transfer (do not coerce) a gpr into a float
  void ma_vxfer(Register src, FloatRegister dest, Condition cc = Always);
  // Transfer (do not coerce) a couple of gpr into a double
  void ma_vxfer(Register src1, Register src2, FloatRegister dest,
                Condition cc = Always);

  BufferOffset ma_vdtr(LoadStore ls, const Address& addr, VFPRegister dest,
                       AutoRegisterScope& scratch, Condition cc = Always);

  BufferOffset ma_vldr(VFPAddr addr, VFPRegister dest, Condition cc = Always);
  BufferOffset ma_vldr(const Address& addr, VFPRegister dest,
                       AutoRegisterScope& scratch, Condition cc = Always);
  BufferOffset ma_vldr(VFPRegister src, Register base, Register index,
                       AutoRegisterScope& scratch, int32_t shift = defaultShift,
                       Condition cc = Always);

  BufferOffset ma_vstr(VFPRegister src, VFPAddr addr, Condition cc = Always);
  BufferOffset ma_vstr(VFPRegister src, const Address& addr,
                       AutoRegisterScope& scratch, Condition cc = Always);
  BufferOffset ma_vstr(VFPRegister src, Register base, Register index,
                       AutoRegisterScope& scratch, AutoRegisterScope& scratch2,
                       int32_t shift, int32_t offset, Condition cc = Always);
  BufferOffset ma_vstr(VFPRegister src, Register base, Register index,
                       AutoRegisterScope& scratch, int32_t shift,
                       Condition cc = Always);

  void ma_call(ImmPtr dest);

  // Float registers can only be loaded/stored in continuous runs when using
  // vstm/vldm. This function breaks set into continuous runs and loads/stores
  // them at [rm]. rm will be modified and left in a state logically suitable
  // for the next load/store. Returns the offset from [dm] for the logical
  // next load/store.
  int32_t transferMultipleByRuns(FloatRegisterSet set, LoadStore ls,
                                 Register rm, DTMMode mode) {
    if (mode == IA) {
      return transferMultipleByRunsImpl<FloatRegisterForwardIterator>(
          set, ls, rm, mode, 1);
    }
    if (mode == DB) {
      return transferMultipleByRunsImpl<FloatRegisterBackwardIterator>(
          set, ls, rm, mode, -1);
    }
    MOZ_CRASH("Invalid data transfer addressing mode");
  }

  // `outAny` is valid if and only if `out64` == Register64::Invalid().
  void wasmLoadImpl(const wasm::MemoryAccessDesc& access, Register memoryBase,
                    Register ptr, Register ptrScratch, AnyRegister outAny,
                    Register64 out64);

  // `valAny` is valid if and only if `val64` == Register64::Invalid().
  void wasmStoreImpl(const wasm::MemoryAccessDesc& access, AnyRegister valAny,
                     Register64 val64, Register memoryBase, Register ptr,
                     Register ptrScratch);

 private:
  // Implementation for transferMultipleByRuns so we can use different
  // iterators for forward/backward traversals. The sign argument should be 1
  // if we traverse forwards, -1 if we traverse backwards.
  template <typename RegisterIterator>
  int32_t transferMultipleByRunsImpl(FloatRegisterSet set, LoadStore ls,
                                     Register rm, DTMMode mode, int32_t sign) {
    MOZ_ASSERT(sign == 1 || sign == -1);

    int32_t delta = sign * sizeof(float);
    int32_t offset = 0;
    // Build up a new set, which is the sum of all of the single and double
    // registers. This set can have up to 48 registers in it total
    // s0-s31 and d16-d31
    FloatRegisterSet mod = set.reduceSetForPush();

    RegisterIterator iter(mod);
    while (iter.more()) {
      startFloatTransferM(ls, rm, mode, WriteBack);
      int32_t reg = (*iter).code();
      do {
        offset += delta;
        if ((*iter).isDouble()) {
          offset += delta;
        }
        transferFloatReg(*iter);
      } while ((++iter).more() && int32_t((*iter).code()) == (reg += sign));
      finishFloatTransfer();
    }
    return offset;
  }
};

class MacroAssembler;

class MacroAssemblerARMCompat : public MacroAssemblerARM {
 private:
  // Perform a downcast. Should be removed by Bug 996602.
  MacroAssembler& asMasm();
  const MacroAssembler& asMasm() const;

 public:
  MacroAssemblerARMCompat() {}

 public:
  // Jumps + other functions that should be called from non-arm specific
  // code. Basically, an x86 front end on top of the ARM code.
  void j(Condition code, Label* dest) { as_b(dest, code); }
  void j(Label* dest) { as_b(dest, Always); }

  void mov(Register src, Register dest) { ma_mov(src, dest); }
  void mov(ImmWord imm, Register dest) { ma_mov(Imm32(imm.value), dest); }
  void mov(ImmPtr imm, Register dest) {
    mov(ImmWord(uintptr_t(imm.value)), dest);
  }

  void branch(JitCode* c) {
    BufferOffset bo = m_buffer.nextOffset();
    addPendingJump(bo, ImmPtr(c->raw()), RelocationKind::JITCODE);
    ScratchRegisterScope scratch(asMasm());
    ma_movPatchable(ImmPtr(c->raw()), scratch, Always);
    ma_bx(scratch);
  }
  void branch(const Register reg) { ma_bx(reg); }
  void nop() { ma_nop(); }
  void shortJumpSizedNop() { ma_nop(); }
  void ret() { ma_pop(pc); }
  void retn(Imm32 n) {
    ScratchRegisterScope scratch(asMasm());
    SecondScratchRegisterScope scratch2(asMasm());
    ma_popn_pc(n, scratch, scratch2);
  }
  void push(Imm32 imm) {
    ScratchRegisterScope scratch(asMasm());
    ma_mov(imm, scratch);
    ma_push(scratch);
  }
  void push(ImmWord imm) { push(Imm32(imm.value)); }
  void push(ImmGCPtr imm) {
    ScratchRegisterScope scratch(asMasm());
    ma_mov(imm, scratch);
    ma_push(scratch);
  }
  void push(const Address& addr) {
    ScratchRegisterScope scratch(asMasm());
    SecondScratchRegisterScope scratch2(asMasm());
    ma_ldr(addr, scratch, scratch2);
    ma_push(scratch);
  }
  void push(Register reg) {
    if (reg == sp) {
      ScratchRegisterScope scratch(asMasm());
      ma_push_sp(reg, scratch);
    } else {
      ma_push(reg);
    }
  }
  void push(FloatRegister reg) { ma_vpush(VFPRegister(reg)); }
  void pushWithPadding(Register reg, const Imm32 extraSpace) {
    ScratchRegisterScope scratch(asMasm());
    Imm32 totSpace = Imm32(extraSpace.value + 4);
    ma_dtr(IsStore, sp, totSpace, reg, scratch, PreIndex);
  }
  void pushWithPadding(Imm32 imm, const Imm32 extraSpace) {
    ScratchRegisterScope scratch(asMasm());
    SecondScratchRegisterScope scratch2(asMasm());
    Imm32 totSpace = Imm32(extraSpace.value + 4);
    ma_mov(imm, scratch);
    ma_dtr(IsStore, sp, totSpace, scratch, scratch2, PreIndex);
  }

  void pop(Register reg) { ma_pop(reg); }
  void pop(FloatRegister reg) { ma_vpop(VFPRegister(reg)); }

  void popN(Register reg, Imm32 extraSpace) {
    ScratchRegisterScope scratch(asMasm());
    Imm32 totSpace = Imm32(extraSpace.value + 4);
    ma_dtr(IsLoad, sp, totSpace, reg, scratch, PostIndex);
  }

  CodeOffset toggledJump(Label* label);

  // Emit a BLX or NOP instruction. ToggleCall can be used to patch this
  // instruction.
  CodeOffset toggledCall(JitCode* target, bool enabled);

  CodeOffset pushWithPatch(ImmWord imm) {
    ScratchRegisterScope scratch(asMasm());
    CodeOffset label = movWithPatch(imm, scratch);
    ma_push(scratch);
    return label;
  }

  CodeOffset movWithPatch(ImmWord imm, Register dest) {
    CodeOffset label = CodeOffset(currentOffset());
    ma_movPatchable(Imm32(imm.value), dest, Always);
    return label;
  }
  CodeOffset movWithPatch(ImmPtr imm, Register dest) {
    return movWithPatch(ImmWord(uintptr_t(imm.value)), dest);
  }

  void jump(Label* label) { as_b(label); }
  void jump(JitCode* code) { branch(code); }
  void jump(ImmPtr ptr) {
    ScratchRegisterScope scratch(asMasm());
    movePtr(ptr, scratch);
    ma_bx(scratch);
  }
  void jump(TrampolinePtr code) { jump(ImmPtr(code.value)); }
  void jump(Register reg) { ma_bx(reg); }
  void jump(const Address& addr) {
    ScratchRegisterScope scratch(asMasm());
    SecondScratchRegisterScope scratch2(asMasm());
    ma_ldr(addr, scratch, scratch2);
    ma_bx(scratch);
  }

  void negl(Register reg) { ma_neg(reg, reg, SetCC); }
  void test32(Register lhs, Register rhs) { ma_tst(lhs, rhs); }
  void test32(Register lhs, Imm32 imm) {
    ScratchRegisterScope scratch(asMasm());
    ma_tst(lhs, imm, scratch);
  }
  void test32(const Address& addr, Imm32 imm) {
    ScratchRegisterScope scratch(asMasm());
    SecondScratchRegisterScope scratch2(asMasm());
    ma_ldr(addr, scratch, scratch2);
    ma_tst(scratch, imm, scratch2);
  }
  void testPtr(Register lhs, Register rhs) { test32(lhs, rhs); }

  void splitTagForTest(const ValueOperand& value, ScratchTagScope& tag) {
    MOZ_ASSERT(value.typeReg() == tag);
  }

  // Higher level tag testing code.
  Condition testInt32(Condition cond, const ValueOperand& value);
  Condition testBoolean(Condition cond, const ValueOperand& value);
  Condition testDouble(Condition cond, const ValueOperand& value);
  Condition testNull(Condition cond, const ValueOperand& value);
  Condition testUndefined(Condition cond, const ValueOperand& value);
  Condition testString(Condition cond, const ValueOperand& value);
  Condition testSymbol(Condition cond, const ValueOperand& value);
  Condition testBigInt(Condition cond, const ValueOperand& value);
  Condition testObject(Condition cond, const ValueOperand& value);
  Condition testNumber(Condition cond, const ValueOperand& value);
  Condition testMagic(Condition cond, const ValueOperand& value);

  Condition testPrimitive(Condition cond, const ValueOperand& value);
  Condition testGCThing(Condition cond, const ValueOperand& value);

  // Register-based tests.
  Condition testInt32(Condition cond, Register tag);
  Condition testBoolean(Condition cond, Register tag);
  Condition testNull(Condition cond, Register tag);
  Condition testUndefined(Condition cond, Register tag);
  Condition testString(Condition cond, Register tag);
  Condition testSymbol(Condition cond, Register tag);
  Condition testBigInt(Condition cond, Register tag);
  Condition testObject(Condition cond, Register tag);
  Condition testDouble(Condition cond, Register tag);
  Condition testNumber(Condition cond, Register tag);
  Condition testMagic(Condition cond, Register tag);
  Condition testPrimitive(Condition cond, Register tag);
  Condition testGCThing(Condition cond, Register tag);

  Condition testGCThing(Condition cond, const Address& address);
  Condition testMagic(Condition cond, const Address& address);
  Condition testInt32(Condition cond, const Address& address);
  Condition testDouble(Condition cond, const Address& address);
  Condition testBoolean(Condition cond, const Address& address);
  Condition testNull(Condition cond, const Address& address);
  Condition testUndefined(Condition cond, const Address& address);
  Condition testString(Condition cond, const Address& address);
  Condition testSymbol(Condition cond, const Address& address);
  Condition testBigInt(Condition cond, const Address& address);
  Condition testObject(Condition cond, const Address& address);
  Condition testNumber(Condition cond, const Address& address);

  Condition testUndefined(Condition cond, const BaseIndex& src);
  Condition testNull(Condition cond, const BaseIndex& src);
  Condition testBoolean(Condition cond, const BaseIndex& src);
  Condition testString(Condition cond, const BaseIndex& src);
  Condition testSymbol(Condition cond, const BaseIndex& src);
  Condition testBigInt(Condition cond, const BaseIndex& src);
  Condition testInt32(Condition cond, const BaseIndex& src);
  Condition testObject(Condition cond, const BaseIndex& src);
  Condition testDouble(Condition cond, const BaseIndex& src);
  Condition testMagic(Condition cond, const BaseIndex& src);
  Condition testGCThing(Condition cond, const BaseIndex& src);

  // Unboxing code.
  void unboxNonDouble(const ValueOperand& operand, Register dest,
                      JSValueType type);
  void unboxNonDouble(const Address& src, Register dest, JSValueType type);
  void unboxNonDouble(const BaseIndex& src, Register dest, JSValueType type);
  void unboxInt32(const ValueOperand& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_INT32);
  }
  void unboxInt32(const Address& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_INT32);
  }
  void unboxInt32(const BaseIndex& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_INT32);
  }
  void unboxBoolean(const ValueOperand& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_BOOLEAN);
  }
  void unboxBoolean(const Address& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_BOOLEAN);
  }
  void unboxBoolean(const BaseIndex& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_BOOLEAN);
  }
  void unboxString(const ValueOperand& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_STRING);
  }
  void unboxString(const Address& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_STRING);
  }
  void unboxSymbol(const ValueOperand& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_SYMBOL);
  }
  void unboxSymbol(const Address& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_SYMBOL);
  }
  void unboxBigInt(const ValueOperand& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_BIGINT);
  }
  void unboxBigInt(const Address& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_BIGINT);
  }
  void unboxObject(const ValueOperand& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_OBJECT);
  }
  void unboxObject(const Address& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_OBJECT);
  }
  void unboxObject(const BaseIndex& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_OBJECT);
  }
  void unboxObjectOrNull(const ValueOperand& src, Register dest) {
    // Due to Spectre mitigation logic (see Value.h), if the value is an Object
    // then this yields the object; otherwise it yields zero (null), as desired.
    unboxNonDouble(src, dest, JSVAL_TYPE_OBJECT);
  }
  void unboxObjectOrNull(const Address& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_OBJECT);
  }
  void unboxObjectOrNull(const BaseIndex& src, Register dest) {
    unboxNonDouble(src, dest, JSVAL_TYPE_OBJECT);
  }
  void unboxDouble(const ValueOperand& src, FloatRegister dest);
  void unboxDouble(const Address& src, FloatRegister dest);
  void unboxDouble(const BaseIndex& src, FloatRegister dest);

  void unboxValue(const ValueOperand& src, AnyRegister dest, JSValueType type);

  // See comment in MacroAssembler-x64.h.
  void unboxGCThingForGCBarrier(const Address& src, Register dest) {
    load32(ToPayload(src), dest);
  }

  void notBoolean(const ValueOperand& val) {
    as_eor(val.payloadReg(), val.payloadReg(), Imm8(1));
  }

  template <typename T>
  void fallibleUnboxPtrImpl(const T& src, Register dest, JSValueType type,
                            Label* fail);

  // Boxing code.
  void boxDouble(FloatRegister src, const ValueOperand& dest, FloatRegister);
  void boxNonDouble(JSValueType type, Register src, const ValueOperand& dest);

  // Extended unboxing API. If the payload is already in a register, returns
  // that register. Otherwise, provides a move to the given scratch register,
  // and returns that.
  [[nodiscard]] Register extractObject(const Address& address,
                                       Register scratch);
  [[nodiscard]] Register extractObject(const ValueOperand& value,
                                       Register scratch) {
    unboxNonDouble(value, value.payloadReg(), JSVAL_TYPE_OBJECT);
    return value.payloadReg();
  }
  [[nodiscard]] Register extractSymbol(const ValueOperand& value,
                                       Register scratch) {
    unboxNonDouble(value, value.payloadReg(), JSVAL_TYPE_SYMBOL);
    return value.payloadReg();
  }
  [[nodiscard]] Register extractInt32(const ValueOperand& value,
                                      Register scratch) {
    return value.payloadReg();
  }
  [[nodiscard]] Register extractBoolean(const ValueOperand& value,
                                        Register scratch) {
    return value.payloadReg();
  }
  [[nodiscard]] Register extractTag(const Address& address, Register scratch);
  [[nodiscard]] Register extractTag(const BaseIndex& address, Register scratch);
  [[nodiscard]] Register extractTag(const ValueOperand& value,
                                    Register scratch) {
    return value.typeReg();
  }

  void boolValueToDouble(const ValueOperand& operand, FloatRegister dest);
  void int32ValueToDouble(const ValueOperand& operand, FloatRegister dest);
  void loadInt32OrDouble(const Address& src, FloatRegister dest);
  void loadInt32OrDouble(Register base, Register index, FloatRegister dest,
                         int32_t shift = defaultShift);
  void loadConstantDouble(double dp, FloatRegister dest);

  // Treat the value as a boolean, and set condition codes accordingly.
  Condition testInt32Truthy(bool truthy, const ValueOperand& operand);
  Condition testBooleanTruthy(bool truthy, const ValueOperand& operand);
  Condition testDoubleTruthy(bool truthy, FloatRegister reg);
  Condition testStringTruthy(bool truthy, const ValueOperand& value);
  Condition testBigIntTruthy(bool truthy, const ValueOperand& value);

  void boolValueToFloat32(const ValueOperand& operand, FloatRegister dest);
  void int32ValueToFloat32(const ValueOperand& operand, FloatRegister dest);
  void loadConstantFloat32(float f, FloatRegister dest);

  void loadUnboxedValue(Address address, MIRType type, AnyRegister dest) {
    if (dest.isFloat()) {
      loadInt32OrDouble(address, dest.fpu());
    } else {
      ScratchRegisterScope scratch(asMasm());
      ma_ldr(address, dest.gpr(), scratch);
    }
  }

  void loadUnboxedValue(BaseIndex address, MIRType type, AnyRegister dest) {
    if (dest.isFloat()) {
      loadInt32OrDouble(address.base, address.index, dest.fpu(), address.scale);
    } else {
      load32(address, dest.gpr());
    }
  }

  template <typename T>
  void storeUnboxedPayload(ValueOperand value, T address, size_t nbytes,
                           JSValueType) {
    switch (nbytes) {
      case 4:
        storePtr(value.payloadReg(), address);
        return;
      case 1:
        store8(value.payloadReg(), address);
        return;
      default:
        MOZ_CRASH("Bad payload width");
    }
  }

  void storeValue(ValueOperand val, const Address& dst);
  void storeValue(ValueOperand val, const BaseIndex& dest);
  void storeValue(JSValueType type, Register reg, BaseIndex dest) {
    ScratchRegisterScope scratch(asMasm());
    SecondScratchRegisterScope scratch2(asMasm());

    int32_t payloadoffset = dest.offset + NUNBOX32_PAYLOAD_OFFSET;
    int32_t typeoffset = dest.offset + NUNBOX32_TYPE_OFFSET;

    ma_alu(dest.base, lsl(dest.index, dest.scale), scratch, OpAdd);

    // Store the payload.
    if (payloadoffset < 4096 && payloadoffset > -4096) {
      ma_str(reg, DTRAddr(scratch, DtrOffImm(payloadoffset)));
    } else {
      ma_str(reg, Address(scratch, payloadoffset), scratch2);
    }

    // Store the type.
    if (typeoffset < 4096 && typeoffset > -4096) {
      // Encodable as DTRAddr, so only two instructions needed.
      ma_mov(ImmTag(JSVAL_TYPE_TO_TAG(type)), scratch2);
      ma_str(scratch2, DTRAddr(scratch, DtrOffImm(typeoffset)));
    } else {
      // Since there are only two scratch registers, the offset must be
      // applied early using a third instruction to be safe.
      ma_add(Imm32(typeoffset), scratch, scratch2);
      ma_mov(ImmTag(JSVAL_TYPE_TO_TAG(type)), scratch2);
      ma_str(scratch2, DTRAddr(scratch, DtrOffImm(0)));
    }
  }
  void storeValue(JSValueType type, Register reg, Address dest) {
    ScratchRegisterScope scratch(asMasm());
    SecondScratchRegisterScope scratch2(asMasm());

    ma_str(reg, dest, scratch2);
    ma_mov(ImmTag(JSVAL_TYPE_TO_TAG(type)), scratch);
    ma_str(scratch, Address(dest.base, dest.offset + NUNBOX32_TYPE_OFFSET),
           scratch2);
  }
  void storeValue(const Value& val, const Address& dest) {
    ScratchRegisterScope scratch(asMasm());
    SecondScratchRegisterScope scratch2(asMasm());

    ma_mov(Imm32(val.toNunboxTag()), scratch);
    ma_str(scratch, ToType(dest), scratch2);
    if (val.isGCThing()) {
      ma_mov(ImmGCPtr(val.toGCThing()), scratch);
    } else {
      ma_mov(Imm32(val.toNunboxPayload()), scratch);
    }
    ma_str(scratch, ToPayload(dest), scratch2);
  }
  void storeValue(const Value& val, BaseIndex dest) {
    ScratchRegisterScope scratch(asMasm());
    SecondScratchRegisterScope scratch2(asMasm());

    int32_t typeoffset = dest.offset + NUNBOX32_TYPE_OFFSET;
    int32_t payloadoffset = dest.offset + NUNBOX32_PAYLOAD_OFFSET;

    ma_alu(dest.base, lsl(dest.index, dest.scale), scratch, OpAdd);

    // Store the type.
    if (typeoffset < 4096 && typeoffset > -4096) {
      ma_mov(Imm32(val.toNunboxTag()), scratch2);
      ma_str(scratch2, DTRAddr(scratch, DtrOffImm(typeoffset)));
    } else {
      ma_add(Imm32(typeoffset), scratch, scratch2);
      ma_mov(Imm32(val.toNunboxTag()), scratch2);
      ma_str(scratch2, DTRAddr(scratch, DtrOffImm(0)));
      // Restore scratch for the payload store.
      ma_alu(dest.base, lsl(dest.index, dest.scale), scratch, OpAdd);
    }

    // Store the payload, marking if necessary.
    if (payloadoffset < 4096 && payloadoffset > -4096) {
      if (val.isGCThing()) {
        ma_mov(ImmGCPtr(val.toGCThing()), scratch2);
      } else {
        ma_mov(Imm32(val.toNunboxPayload()), scratch2);
      }
      ma_str(scratch2, DTRAddr(scratch, DtrOffImm(payloadoffset)));
    } else {
      ma_add(Imm32(payloadoffset), scratch, scratch2);
      if (val.isGCThing()) {
        ma_mov(ImmGCPtr(val.toGCThing()), scratch2);
      } else {
        ma_mov(Imm32(val.toNunboxPayload()), scratch2);
      }
      ma_str(scratch2, DTRAddr(scratch, DtrOffImm(0)));
    }
  }
  void storeValue(const Address& src, const Address& dest, Register temp) {
    load32(ToType(src), temp);
    store32(temp, ToType(dest));

    load32(ToPayload(src), temp);
    store32(temp, ToPayload(dest));
  }

  void storePrivateValue(Register src, const Address& dest) {
    store32(Imm32(0), ToType(dest));
    store32(src, ToPayload(dest));
  }
  void storePrivateValue(ImmGCPtr imm, const Address& dest) {
    store32(Imm32(0), ToType(dest));
    storePtr(imm, ToPayload(dest));
  }

  void loadValue(Address src, ValueOperand val);
  void loadValue(Operand dest, ValueOperand val) {
    loadValue(dest.toAddress(), val);
  }
  void loadValue(const BaseIndex& addr, ValueOperand val);

  // Like loadValue but guaranteed to not use LDRD or LDM instructions (these
  // don't support unaligned accesses).
  void loadUnalignedValue(const Address& src, ValueOperand dest);

  void tagValue(JSValueType type, Register payload, ValueOperand dest);

  void pushValue(ValueOperand val);
  void popValue(ValueOperand val);
  void pushValue(const Value& val) {
    push(Imm32(val.toNunboxTag()));
    if (val.isGCThing()) {
      push(ImmGCPtr(val.toGCThing()));
    } else {
      push(Imm32(val.toNunboxPayload()));
    }
  }
  void pushValue(JSValueType type, Register reg) {
    push(ImmTag(JSVAL_TYPE_TO_TAG(type)));
    ma_push(reg);
  }
  void pushValue(const Address& addr);
  void pushValue(const BaseIndex& addr, Register scratch);

  void storePayload(const Value& val, const Address& dest);
  void storePayload(Register src, const Address& dest);
  void storePayload(const Value& val, const BaseIndex& dest);
  void storePayload(Register src, const BaseIndex& dest);
  void storeTypeTag(ImmTag tag, const Address& dest);
  void storeTypeTag(ImmTag tag, const BaseIndex& dest);

  void handleFailureWithHandlerTail(Label* profilerExitTail,
                                    Label* bailoutTail);

  /////////////////////////////////////////////////////////////////
  // Common interface.
  /////////////////////////////////////////////////////////////////
 public:
  void not32(Register reg);

  void move32(Imm32 imm, Register dest);
  void move32(Register src, Register dest);

  void movePtr(Register src, Register dest);
  void movePtr(ImmWord imm, Register dest);
  void movePtr(ImmPtr imm, Register dest);
  void movePtr(wasm::SymbolicAddress imm, Register dest);
  void movePtr(ImmGCPtr imm, Register dest);

  void load8SignExtend(const Address& address, Register dest);
  void load8SignExtend(const BaseIndex& src, Register dest);

  void load8ZeroExtend(const Address& address, Register dest);
  void load8ZeroExtend(const BaseIndex& src, Register dest);

  void load16SignExtend(const Address& address, Register dest);
  void load16SignExtend(const BaseIndex& src, Register dest);

  template <typename S>
  void load16UnalignedSignExtend(const S& src, Register dest) {
    // load16SignExtend uses |ldrsh|, which supports unaligned access.
    load16SignExtend(src, dest);
  }

  void load16ZeroExtend(const Address& address, Register dest);
  void load16ZeroExtend(const BaseIndex& src, Register dest);

  template <typename S>
  void load16UnalignedZeroExtend(const S& src, Register dest) {
    // load16ZeroExtend uses |ldrh|, which supports unaligned access.
    load16ZeroExtend(src, dest);
  }

  void load32(const Address& address, Register dest);
  void load32(const BaseIndex& address, Register dest);
  void load32(AbsoluteAddress address, Register dest);

  template <typename S>
  void load32Unaligned(const S& src, Register dest) {
    // load32 uses |ldr|, which supports unaligned access.
    load32(src, dest);
  }

  void load64(const Address& address, Register64 dest) {
    bool highBeforeLow = address.base == dest.low;
    if (highBeforeLow) {
      load32(HighWord(address), dest.high);
      load32(LowWord(address), dest.low);
    } else {
      load32(LowWord(address), dest.low);
      load32(HighWord(address), dest.high);
    }
  }
  void load64(const BaseIndex& address, Register64 dest) {
    // If you run into this, relax your register allocation constraints.
    MOZ_RELEASE_ASSERT(
        !((address.base == dest.low || address.base == dest.high) &&
          (address.index == dest.low || address.index == dest.high)));
    bool highBeforeLow = address.base == dest.low || address.index == dest.low;
    if (highBeforeLow) {
      load32(HighWord(address), dest.high);
      load32(LowWord(address), dest.low);
    } else {
      load32(LowWord(address), dest.low);
      load32(HighWord(address), dest.high);
    }
  }

  template <typename S>
  void load64Unaligned(const S& src, Register64 dest) {
    // load64 calls load32, which supports unaligned accesses.
    load64(src, dest);
  }

  void loadPtr(const Address& address, Register dest);
  void loadPtr(const BaseIndex& src, Register dest);
  void loadPtr(AbsoluteAddress address, Register dest);
  void loadPtr(wasm::SymbolicAddress address, Register dest);

  void loadPrivate(const Address& address, Register dest);

  void loadDouble(const Address& addr, FloatRegister dest);
  void loadDouble(const BaseIndex& src, FloatRegister dest);

  // Load a float value into a register, then expand it to a double.
  void loadFloatAsDouble(const Address& addr, FloatRegister dest);
  void loadFloatAsDouble(const BaseIndex& src, FloatRegister dest);

  void loadFloat32(const Address& addr, FloatRegister dest);
  void loadFloat32(const BaseIndex& src, FloatRegister dest);

  void store8(Register src, const Address& address);
  void store8(Imm32 imm, const Address& address);
  void store8(Register src, const BaseIndex& address);
  void store8(Imm32 imm, const BaseIndex& address);

  void store16(Register src, const Address& address);
  void store16(Imm32 imm, const Address& address);
  void store16(Register src, const BaseIndex& address);
  void store16(Imm32 imm, const BaseIndex& address);

  template <typename S, typename T>
  void store16Unaligned(const S& src, const T& dest) {
    // store16 uses |strh|, which supports unaligned access.
    store16(src, dest);
  }

  void store32(Register src, AbsoluteAddress address);
  void store32(Register src, const Address& address);
  void store32(Register src, const BaseIndex& address);
  void store32(Imm32 src, const Address& address);
  void store32(Imm32 src, const BaseIndex& address);

  template <typename S, typename T>
  void store32Unaligned(const S& src, const T& dest) {
    // store32 uses |str|, which supports unaligned access.
    store32(src, dest);
  }

  void store64(Register64 src, Address address) {
    store32(src.low, LowWord(address));
    store32(src.high, HighWord(address));
  }

  void store64(Register64 src, const BaseIndex& address) {
    store32(src.low, LowWord(address));
    store32(src.high, HighWord(address));
  }

  void store64(Imm64 imm, Address address) {
    store32(imm.low(), LowWord(address));
    store32(imm.hi(), HighWord(address));
  }

  void store64(Imm64 imm, const BaseIndex& address) {
    store32(imm.low(), LowWord(address));
    store32(imm.hi(), HighWord(address));
  }

  template <typename S, typename T>
  void store64Unaligned(const S& src, const T& dest) {
    // store64 calls store32, which supports unaligned access.
    store64(src, dest);
  }

  void storePtr(ImmWord imm, const Address& address);
  void storePtr(ImmWord imm, const BaseIndex& address);
  void storePtr(ImmPtr imm, const Address& address);
  void storePtr(ImmPtr imm, const BaseIndex& address);
  void storePtr(ImmGCPtr imm, const Address& address);
  void storePtr(ImmGCPtr imm, const BaseIndex& address);
  void storePtr(Register src, const Address& address);
  void storePtr(Register src, const BaseIndex& address);
  void storePtr(Register src, AbsoluteAddress dest);

  void moveDouble(FloatRegister src, FloatRegister dest,
                  Condition cc = Always) {
    ma_vmov(src, dest, cc);
  }

  inline void incrementInt32Value(const Address& addr);

  void cmp32(Register lhs, Imm32 rhs);
  void cmp32(Register lhs, Register rhs);
  void cmp32(const Address& lhs, Imm32 rhs);
  void cmp32(const Address& lhs, Register rhs);

  void cmpPtr(Register lhs, Register rhs);
  void cmpPtr(Register lhs, ImmWord rhs);
  void cmpPtr(Register lhs, ImmPtr rhs);
  void cmpPtr(Register lhs, ImmGCPtr rhs);
  void cmpPtr(Register lhs, Imm32 rhs);
  void cmpPtr(const Address& lhs, Register rhs);
  void cmpPtr(const Address& lhs, ImmWord rhs);
  void cmpPtr(const Address& lhs, ImmPtr rhs);
  void cmpPtr(const Address& lhs, ImmGCPtr rhs);
  void cmpPtr(const Address& lhs, Imm32 rhs);

  void setStackArg(Register reg, uint32_t arg);

  void breakpoint();
  // Conditional breakpoint.
  void breakpoint(Condition cc);

  // Trigger the simulator's interactive read-eval-print loop.
  // The message will be printed at the stopping point.
  // (On non-simulator builds, does nothing.)
  void simulatorStop(const char* msg);

  // Evaluate srcDest = minmax<isMax>{Float32,Double}(srcDest, other).
  // Checks for NaN if canBeNaN is true.
  void minMaxDouble(FloatRegister srcDest, FloatRegister other, bool canBeNaN,
                    bool isMax);
  void minMaxFloat32(FloatRegister srcDest, FloatRegister other, bool canBeNaN,
                     bool isMax);

  void compareDouble(FloatRegister lhs, FloatRegister rhs);

  void compareFloat(FloatRegister lhs, FloatRegister rhs);

  void checkStackAlignment();

  // If source is a double, load it into dest. If source is int32, convert it
  // to double. Else, branch to failure.
  void ensureDouble(const ValueOperand& source, FloatRegister dest,
                    Label* failure);

  void emitSet(Assembler::Condition cond, Register dest) {
    ma_mov(Imm32(0), dest);
    ma_mov(Imm32(1), dest, cond);
  }

  void testNullSet(Condition cond, const ValueOperand& value, Register dest) {
    cond = testNull(cond, value);
    emitSet(cond, dest);
  }

  void testObjectSet(Condition cond, const ValueOperand& value, Register dest) {
    cond = testObject(cond, value);
    emitSet(cond, dest);
  }

  void testUndefinedSet(Condition cond, const ValueOperand& value,
                        Register dest) {
    cond = testUndefined(cond, value);
    emitSet(cond, dest);
  }

 protected:
  bool buildOOLFakeExitFrame(void* fakeReturnAddr);

 public:
  void computeEffectiveAddress(const Address& address, Register dest) {
    ScratchRegisterScope scratch(asMasm());
    ma_add(address.base, Imm32(address.offset), dest, scratch, LeaveCC);
  }
  void computeEffectiveAddress(const BaseIndex& address, Register dest) {
    ScratchRegisterScope scratch(asMasm());
    ma_alu(address.base, lsl(address.index, address.scale), dest, OpAdd,
           LeaveCC);
    if (address.offset) {
      ma_add(dest, Imm32(address.offset), dest, scratch, LeaveCC);
    }
  }
  void floor(FloatRegister input, Register output, Label* handleNotAnInt);
  void floorf(FloatRegister input, Register output, Label* handleNotAnInt);
  void ceil(FloatRegister input, Register output, Label* handleNotAnInt);
  void ceilf(FloatRegister input, Register output, Label* handleNotAnInt);
  void round(FloatRegister input, Register output, Label* handleNotAnInt,
             FloatRegister tmp);
  void roundf(FloatRegister input, Register output, Label* handleNotAnInt,
              FloatRegister tmp);
  void trunc(FloatRegister input, Register output, Label* handleNotAnInt);
  void truncf(FloatRegister input, Register output, Label* handleNotAnInt);

  void lea(Operand addr, Register dest) {
    ScratchRegisterScope scratch(asMasm());
    ma_add(addr.baseReg(), Imm32(addr.disp()), dest, scratch);
  }

  void abiret() { as_bx(lr); }

  void moveFloat32(FloatRegister src, FloatRegister dest,
                   Condition cc = Always) {
    as_vmov(VFPRegister(dest).singleOverlay(), VFPRegister(src).singleOverlay(),
            cc);
  }

  // Instrumentation for entering and leaving the profiler.
  void profilerEnterFrame(Register framePtr, Register scratch);
  void profilerExitFrame();
};

typedef MacroAssemblerARMCompat MacroAssemblerSpecific;

}  // namespace jit
}  // namespace js

#endif /* jit_arm_MacroAssembler_arm_h */