-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
emitarm64.cpp
17523 lines (15481 loc) · 581 KB
/
emitarm64.cpp
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX XX
XX emitArm64.cpp XX
XX XX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/
#include "jitpch.h"
#ifdef _MSC_VER
#pragma hdrstop
#endif
#if defined(TARGET_ARM64)
/*****************************************************************************/
/*****************************************************************************/
#include "instr.h"
#include "emit.h"
#include "codegen.h"
/* static */ bool emitter::strictArmAsm = true;
/*****************************************************************************/
const instruction emitJumpKindInstructions[] = {
INS_nop,
#define JMP_SMALL(en, rev, ins) INS_##ins,
#include "emitjmps.h"
};
const emitJumpKind emitReverseJumpKinds[] = {
EJ_NONE,
#define JMP_SMALL(en, rev, ins) EJ_##rev,
#include "emitjmps.h"
};
/*****************************************************************************
* Look up the instruction for a jump kind
*/
/*static*/ instruction emitter::emitJumpKindToIns(emitJumpKind jumpKind)
{
assert((unsigned)jumpKind < ArrLen(emitJumpKindInstructions));
return emitJumpKindInstructions[jumpKind];
}
/*****************************************************************************
* Look up the jump kind for an instruction. It better be a conditional
* branch instruction with a jump kind!
*/
/*static*/ emitJumpKind emitter::emitInsToJumpKind(instruction ins)
{
for (unsigned i = 0; i < ArrLen(emitJumpKindInstructions); i++)
{
if (ins == emitJumpKindInstructions[i])
{
emitJumpKind ret = (emitJumpKind)i;
assert(EJ_NONE < ret && ret < EJ_COUNT);
return ret;
}
}
unreached();
}
/*****************************************************************************
* Reverse the conditional jump
*/
/*static*/ emitJumpKind emitter::emitReverseJumpKind(emitJumpKind jumpKind)
{
assert(jumpKind < EJ_COUNT);
return emitReverseJumpKinds[jumpKind];
}
/*****************************************************************************
*
* Return the allocated size (in bytes) of the given instruction descriptor.
*/
size_t emitter::emitSizeOfInsDsc(instrDesc* id) const
{
if (emitIsSmallInsDsc(id))
return SMALL_IDSC_SIZE;
assert((unsigned)id->idInsFmt() < emitFmtCount);
ID_OPS idOp = (ID_OPS)emitFmtToOps[id->idInsFmt()];
bool isCallIns = (id->idIns() == INS_bl) || (id->idIns() == INS_blr) || (id->idIns() == INS_b_tail) ||
(id->idIns() == INS_br_tail);
bool maybeCallIns = (id->idIns() == INS_b) || (id->idIns() == INS_br);
switch (idOp)
{
case ID_OP_NONE:
break;
case ID_OP_JMP:
return sizeof(instrDescJmp);
case ID_OP_CALL:
assert(isCallIns || maybeCallIns);
if (id->idIsLargeCall())
{
/* Must be a "fat" call descriptor */
return sizeof(instrDescCGCA);
}
else
{
assert(!id->idIsLargeDsp());
assert(!id->idIsLargeCns());
return sizeof(instrDesc);
}
break;
default:
NO_WAY("unexpected instruction descriptor format");
break;
}
if (id->idIsLargeCns())
{
if (id->idIsLclVarPair())
{
return sizeof(instrDescLclVarPairCns);
}
else if (id->idIsLargeDsp())
{
return sizeof(instrDescCnsDsp);
}
else
{
return sizeof(instrDescCns);
}
}
else
{
if (id->idIsLclVarPair())
{
return sizeof(instrDescLclVarPair);
}
else if (id->idIsLargeDsp())
{
return sizeof(instrDescDsp);
}
else
{
#if FEATURE_LOOP_ALIGN
if (id->idIns() == INS_align)
{
return sizeof(instrDescAlign);
}
#endif
return sizeof(instrDesc);
}
}
}
#ifdef DEBUG
/*****************************************************************************
*
* The following is called for each recorded instruction -- use for debugging.
*/
void emitter::emitInsSanityCheck(instrDesc* id)
{
/* What instruction format have we got? */
switch (id->idInsFmt())
{
instruction ins;
emitAttr elemsize;
emitAttr datasize;
emitAttr dstsize;
emitAttr srcsize;
ssize_t imm;
unsigned immShift;
ssize_t index;
ssize_t index2;
case IF_BI_0A: // BI_0A ......iiiiiiiiii iiiiiiiiiiiiiiii simm26:00
break;
case IF_BI_0B: // BI_0B ......iiiiiiiiii iiiiiiiiiiii.... simm19:00
break;
case IF_LARGEJMP:
case IF_LARGEADR:
case IF_LARGELDC:
break;
case IF_BI_0C: // BI_0C ......iiiiiiiiii iiiiiiiiiiiiiiii simm26:00
break;
case IF_BI_1A: // BI_1A ......iiiiiiiiii iiiiiiiiiiittttt Rt simm19:00
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
break;
case IF_BI_1B: // BI_1B B.......bbbbbiii iiiiiiiiiiittttt Rt imm6, simm14:00
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isValidImmShift(emitGetInsSC(id), id->idOpSize()));
break;
case IF_BR_1A: // BR_1A ................ ......nnnnn..... Rn
assert(isGeneralRegister(id->idReg1()));
break;
case IF_BR_1B: // BR_1B ................ ......nnnnn..... Rn
if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && id->idIsTlsGD())
{
assert(isGeneralRegister(id->idReg1()));
assert(id->idAddr()->iiaAddr != nullptr);
}
else
{
assert(isGeneralRegister(id->idReg3()));
}
break;
case IF_LS_1A: // LS_1A .X......iiiiiiii iiiiiiiiiiittttt Rt PC imm(1MB)
assert(isGeneralRegister(id->idReg1()) || isVectorRegister(id->idReg1()));
assert(insOptsNone(id->idInsOpt()));
break;
case IF_LS_2A: // LS_2A .X.......X...... ......nnnnnttttt Rt Rn
assert(isIntegerRegister(id->idReg1()) || // ZR
isVectorRegister(id->idReg1()));
assert(isIntegerRegister(id->idReg2())); // SP
assert((emitGetInsSC(id) == 0) || (id->idIsTlsGD()));
assert(insOptsNone(id->idInsOpt()));
break;
case IF_LS_2B: // LS_2B .X.......Xiiiiii iiiiiinnnnnttttt Rt Rn imm(0-4095)
assert(isIntegerRegister(id->idReg1()) || // ZR
isVectorRegister(id->idReg1()));
assert(isIntegerRegister(id->idReg2())); // SP
assert(isValidUimm<12>(emitGetInsSC(id)));
assert(insOptsNone(id->idInsOpt()));
break;
case IF_LS_2C: // LS_2C .X.......X.iiiii iiiiPPnnnnnttttt Rt Rn imm(-256..+255) no/pre/post inc
assert(isIntegerRegister(id->idReg1()) || // ZR
isVectorRegister(id->idReg1()));
assert(isIntegerRegister(id->idReg2())); // SP
assert(emitGetInsSC(id) >= -0x100);
assert(emitGetInsSC(id) < 0x100);
assert(insOptsNone(id->idInsOpt()) || insOptsIndexed(id->idInsOpt()));
break;
case IF_LS_2D: // LS_2D .Q.............. ....ssnnnnnttttt Vt Rn
case IF_LS_2E: // LS_2E .Q.............. ....ssnnnnnttttt Vt Rn
case IF_LS_2F: // LS_2F .Q.............. xx.Sssnnnnnttttt Vt[] Rn
case IF_LS_2G: // LS_2G .Q.............. xx.Sssnnnnnttttt Vt[] Rn
assert(isVectorRegister(id->idReg1()));
assert(isIntegerRegister(id->idReg2())); // SP
if (insOptsAnyArrangement(id->idInsOpt()))
{
datasize = id->idOpSize();
assert(isValidVectorDatasize(datasize));
assert(isValidArrangement(id->idOpSize(), id->idInsOpt()));
}
else
{
elemsize = id->idOpSize();
assert(isValidVectorElemsize(elemsize));
assert(insOptsNone(id->idInsOpt()) || insOptsPostIndex(id->idInsOpt()));
}
assert(!id->idIsLclVar());
break;
case IF_LS_3A: // LS_3A .X.......X.mmmmm oooS..nnnnnttttt Rt Rn Rm ext(Rm) LSL {}
assert(isIntegerRegister(id->idReg1()) || // ZR
isVectorRegister(id->idReg1()));
assert(isIntegerRegister(id->idReg2())); // SP
if (id->idIsLclVar())
{
assert(isGeneralRegister(codeGen->rsGetRsvdReg()));
}
else
{
assert(isGeneralRegister(id->idReg3()));
}
assert(insOptsLSExtend(id->idInsOpt()));
break;
case IF_LS_3B: // LS_3B X............... .aaaaannnnnttttt Rt Ra Rn
assert((isValidGeneralDatasize(id->idOpSize()) && isIntegerRegister(id->idReg1())) ||
(isValidVectorLSPDatasize(id->idOpSize()) && isVectorRegister(id->idReg1())));
assert(isIntegerRegister(id->idReg1()) || // ZR
isVectorRegister(id->idReg1()));
assert(isIntegerRegister(id->idReg2()) || // ZR
isVectorRegister(id->idReg2()));
assert(isIntegerRegister(id->idReg3())); // SP
assert(emitGetInsSC(id) == 0);
assert(insOptsNone(id->idInsOpt()));
break;
case IF_LS_3C: // LS_3C X.........iiiiii iaaaaannnnnttttt Rt Ra Rn imm(im7,sh)
assert((isValidGeneralDatasize(id->idOpSize()) && isIntegerRegister(id->idReg1())) ||
(isValidVectorLSPDatasize(id->idOpSize()) && isVectorRegister(id->idReg1())));
assert(isIntegerRegister(id->idReg1()) || // ZR
isVectorRegister(id->idReg1()));
assert(isIntegerRegister(id->idReg2()) || // ZR
isVectorRegister(id->idReg2()));
assert(isIntegerRegister(id->idReg3())); // SP
assert(emitGetInsSC(id) >= -0x40);
assert(emitGetInsSC(id) < 0x40);
assert(insOptsNone(id->idInsOpt()) || insOptsIndexed(id->idInsOpt()));
break;
case IF_LS_3D: // LS_3D .X.......X.mmmmm ......nnnnnttttt Wm Rt Rn
assert(isIntegerRegister(id->idReg1()));
assert(isIntegerRegister(id->idReg2()));
assert(isIntegerRegister(id->idReg3()));
assert(emitGetInsSC(id) == 0);
assert(!id->idIsLclVar());
assert(insOptsNone(id->idInsOpt()));
break;
case IF_LS_3E: // LS_3E .X.........mmmmm ......nnnnnttttt Rm Rt Rn ARMv8.1 LSE Atomics
assert(isIntegerRegister(id->idReg1()));
assert(isIntegerRegister(id->idReg2()));
assert(isIntegerRegister(id->idReg3()));
assert(emitGetInsSC(id) == 0);
assert(!id->idIsLclVar());
assert(insOptsNone(id->idInsOpt()));
break;
case IF_LS_3F: // LS_3F .Q.........mmmmm ....ssnnnnnttttt Vt Rn Rm
case IF_LS_3G: // LS_3G .Q.........mmmmm ...Sssnnnnnttttt Vt[] Rn Rm
assert(isVectorRegister(id->idReg1()));
assert(isIntegerRegister(id->idReg2())); // SP
assert(isGeneralRegister(id->idReg3()));
if (insOptsAnyArrangement(id->idInsOpt()))
{
datasize = id->idOpSize();
assert(isValidVectorDatasize(datasize));
assert(isValidArrangement(id->idOpSize(), id->idInsOpt()));
}
else
{
elemsize = id->idOpSize();
assert(isValidVectorElemsize(elemsize));
assert(insOptsNone(id->idInsOpt()) || insOptsPostIndex(id->idInsOpt()));
}
assert(!id->idIsLclVar());
break;
case IF_DI_1A: // DI_1A X.......shiiiiii iiiiiinnnnn..... Rn imm(i12,sh)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isValidUimm<12>(emitGetInsSC(id)));
assert(insOptsNone(id->idInsOpt()) || insOptsLSL12(id->idInsOpt()));
break;
case IF_DI_1B: // DI_1B X........hwiiiii iiiiiiiiiiiddddd Rd imm(i16,hw)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isValidImmHWVal(emitGetInsSC(id), id->idOpSize()));
break;
case IF_DI_1C: // DI_1C X........Nrrrrrr ssssssnnnnn..... Rn imm(N,r,s)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isValidImmNRS(emitGetInsSC(id), id->idOpSize()));
break;
case IF_DI_1D: // DI_1D X........Nrrrrrr ssssss.....ddddd Rd imm(N,r,s)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isIntegerRegister(id->idReg1())); // SP
assert(isValidImmNRS(emitGetInsSC(id), id->idOpSize()));
break;
case IF_DI_1E: // DI_1E .ii.....iiiiiiii iiiiiiiiiiiddddd Rd simm21
assert(isGeneralRegister(id->idReg1()));
break;
case IF_DI_1F: // DI_1F X..........iiiii cccc..nnnnn.nzcv Rn imm5 nzcv cond
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isValidImmCondFlagsImm5(emitGetInsSC(id)));
break;
case IF_DI_2A: // DI_2A X.......shiiiiii iiiiiinnnnnddddd Rd Rn imm(i12,sh)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isIntegerRegister(id->idReg1())); // SP
assert(isIntegerRegister(id->idReg2())); // SP
assert(isValidUimm<12>(emitGetInsSC(id)));
assert(insOptsNone(id->idInsOpt()) || insOptsLSL12(id->idInsOpt()));
break;
case IF_DI_2B: // DI_2B X.........Xnnnnn ssssssnnnnnddddd Rd Rn imm(0-63)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isGeneralRegister(id->idReg2()));
assert(isValidImmShift(emitGetInsSC(id), id->idOpSize()));
break;
case IF_DI_2C: // DI_2C X........Nrrrrrr ssssssnnnnnddddd Rd Rn imm(N,r,s)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isIntegerRegister(id->idReg1())); // SP
assert(isGeneralRegister(id->idReg2()));
assert(isValidImmNRS(emitGetInsSC(id), id->idOpSize()));
break;
case IF_DI_2D: // DI_2D X........Nrrrrrr ssssssnnnnnddddd Rd Rn imr, imms (N,r,s)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isGeneralRegisterOrZR(id->idReg2()));
assert(isValidImmNRS(emitGetInsSC(id), id->idOpSize()));
break;
case IF_DR_1D: // DR_1D X............... cccc.......ddddd Rd cond
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isValidImmCond(emitGetInsSC(id)));
break;
case IF_DR_2A: // DR_2A X..........mmmmm ......nnnnn..... Rn Rm
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isGeneralRegister(id->idReg2()));
break;
case IF_DR_2B: // DR_2B X.......sh.mmmmm ssssssnnnnn..... Rn Rm {LSL,LSR,ASR,ROR} imm(0-63)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isIntegerRegister(id->idReg1())); // ZR
assert(isGeneralRegister(id->idReg2()));
assert(isValidImmShift(emitGetInsSC(id), id->idOpSize()));
if (!insOptsNone(id->idInsOpt()))
{
if (id->idIns() == INS_tst) // tst allows ROR, cmp/cmn don't
{
assert(insOptsAnyShift(id->idInsOpt()));
}
else
{
assert(insOptsAluShift(id->idInsOpt()));
}
}
assert(insOptsNone(id->idInsOpt()) || (emitGetInsSC(id) > 0));
break;
case IF_DR_2C: // DR_2C X..........mmmmm ooosssnnnnn..... Rn Rm ext(Rm) LSL imm(0-4)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isIntegerRegister(id->idReg1())); // SP
assert(isGeneralRegister(id->idReg2()));
assert(insOptsNone(id->idInsOpt()) || insOptsLSL(id->idInsOpt()) || insOptsAnyExtend(id->idInsOpt()));
assert(emitGetInsSC(id) >= 0);
assert(emitGetInsSC(id) <= 4);
if (insOptsLSL(id->idInsOpt()))
{
assert(emitGetInsSC(id) > 0);
}
break;
case IF_DR_2D: // DR_2D X..........nnnnn cccc..nnnnnmmmmm Rd Rn cond
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isGeneralRegisterOrZR(id->idReg2()));
assert(isValidImmCond(emitGetInsSC(id)));
break;
case IF_DR_2E: // DR_2E X..........mmmmm ...........ddddd Rd Rm
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isIntegerRegister(id->idReg2())); // ZR
break;
case IF_DR_2F: // DR_2F X.......sh.mmmmm ssssss.....ddddd Rd Rm {LSL,LSR,ASR} imm(0-63)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isGeneralRegister(id->idReg2()));
assert(isValidImmShift(emitGetInsSC(id), id->idOpSize()));
assert(insOptsNone(id->idInsOpt()) || insOptsAluShift(id->idInsOpt()));
assert(insOptsNone(id->idInsOpt()) || (emitGetInsSC(id) > 0));
break;
case IF_DR_2G: // DR_2G X............... ......nnnnnddddd Rd Rm
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isIntegerRegister(id->idReg1())); // SP
assert(isIntegerRegister(id->idReg2())); // SP
break;
case IF_DR_2H: // DR_2H X........X...... ......nnnnnddddd Rd Rn
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isGeneralRegister(id->idReg2()));
break;
case IF_DR_2I: // DR_2I X..........mmmmm cccc..nnnnn.nzcv Rn Rm nzcv cond
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isGeneralRegister(id->idReg2()));
assert(isValidImmCondFlags(emitGetInsSC(id)));
break;
case IF_DR_3A: // DR_3A X..........mmmmm ......nnnnnmmmmm Rd Rn Rm
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isIntegerRegister(id->idReg1())); // SP
assert(isIntegerRegister(id->idReg2())); // SP
if (id->idIsLclVar())
{
assert(isGeneralRegister(codeGen->rsGetRsvdReg()));
}
else
{
assert(isGeneralRegister(id->idReg3()));
}
assert(insOptsNone(id->idInsOpt()));
break;
case IF_DR_3B: // DR_3B X.......sh.mmmmm ssssssnnnnnddddd Rd Rn Rm {LSL,LSR,ASR,ROR} imm(0-63)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isGeneralRegister(id->idReg2()));
assert(isGeneralRegister(id->idReg3()));
assert(isValidImmShift(emitGetInsSC(id), id->idOpSize()));
assert(insOptsNone(id->idInsOpt()) || insOptsAnyShift(id->idInsOpt()));
assert(insOptsNone(id->idInsOpt()) || (emitGetInsSC(id) > 0));
break;
case IF_DR_3C: // DR_3C X..........mmmmm ooosssnnnnnddddd Rd Rn Rm ext(Rm) LSL imm(0-4)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isIntegerRegister(id->idReg1())); // SP
assert(isIntegerRegister(id->idReg2())); // SP
assert(isGeneralRegister(id->idReg3()));
assert(insOptsNone(id->idInsOpt()) || insOptsLSL(id->idInsOpt()) || insOptsAnyExtend(id->idInsOpt()));
assert(emitGetInsSC(id) >= 0);
assert(emitGetInsSC(id) <= 4);
if (insOptsLSL(id->idInsOpt()))
{
assert((emitGetInsSC(id) > 0) || (id->idReg2() == REG_ZR)); // REG_ZR encodes SP and we allow a shift of
// zero
}
break;
case IF_DR_3D: // DR_3D X..........mmmmm cccc..nnnnnmmmmm Rd Rn Rm cond
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isGeneralRegisterOrZR(id->idReg2()));
assert(isGeneralRegisterOrZR(id->idReg3()));
assert(isValidImmCond(emitGetInsSC(id)));
break;
case IF_DR_3E: // DR_3E X........X.mmmmm ssssssnnnnnddddd Rd Rn Rm imm(0-63)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isGeneralRegister(id->idReg2()));
assert(isGeneralRegister(id->idReg3()));
assert(isValidImmShift(emitGetInsSC(id), id->idOpSize()));
assert(insOptsNone(id->idInsOpt()));
break;
case IF_DR_4A: // DR_4A X..........mmmmm .aaaaannnnnddddd Rd Rn Rm Ra
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isGeneralRegister(id->idReg1()));
assert(isGeneralRegister(id->idReg2()));
assert(isGeneralRegister(id->idReg3()));
assert(isGeneralRegister(id->idReg4()));
break;
case IF_DV_1A: // DV_1A .........X.iiiii iii........ddddd Vd imm8 (fmov - immediate scalar)
assert(insOptsNone(id->idInsOpt()));
elemsize = id->idOpSize();
assert(isValidVectorElemsizeFloat(elemsize));
assert(isVectorRegister(id->idReg1()));
assert(isValidUimm<8>(emitGetInsSC(id)));
break;
case IF_DV_1B: // DV_1B .QX..........iii cmod..iiiiiddddd Vd imm8 (immediate vector)
ins = id->idIns();
imm = emitGetInsSC(id) & 0x0ff;
immShift = (emitGetInsSC(id) & 0x700) >> 8;
assert(immShift >= 0);
datasize = id->idOpSize();
assert(isValidVectorDatasize(datasize));
assert(isValidArrangement(datasize, id->idInsOpt()));
elemsize = optGetElemsize(id->idInsOpt());
if (ins == INS_fmov)
{
assert(isValidVectorElemsizeFloat(elemsize));
assert(id->idInsOpt() != INS_OPTS_1D); // Reserved encoding
assert(immShift == 0);
}
else
{
assert(isValidVectorElemsize(elemsize));
assert((immShift != 4) && (immShift != 7)); // always invalid values
if (ins != INS_movi) // INS_mvni, INS_orr, INS_bic
{
assert((elemsize != EA_1BYTE) && (elemsize != EA_8BYTE)); // only H or S
if (elemsize == EA_2BYTE)
{
assert(immShift < 2);
}
else // (elemsize == EA_4BYTE)
{
if (ins != INS_mvni)
{
assert(immShift < 4);
}
}
}
}
assert(isVectorRegister(id->idReg1()));
assert(isValidUimm<8>(imm));
break;
case IF_DV_1C: // DV_1C .........X...... ......nnnnn..... Vn #0.0 (fcmp - with zero)
assert(insOptsNone(id->idInsOpt()));
elemsize = id->idOpSize();
assert(isValidVectorElemsizeFloat(elemsize));
assert(isVectorRegister(id->idReg1()));
break;
case IF_DV_2A: // DV_2A .Q.......X...... ......nnnnnddddd Vd Vn (fabs, fcvt - vector)
case IF_DV_2M: // DV_2M .Q......XX...... ......nnnnnddddd Vd Vn (abs, neg - vector)
case IF_DV_2P: // DV_2P ................ ......nnnnnddddd Vd Vn (aes*, sha1su1)
assert(isValidVectorDatasize(id->idOpSize()));
assert(isValidArrangement(id->idOpSize(), id->idInsOpt()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
break;
case IF_DV_2N: // DV_2N .........iiiiiii ......nnnnnddddd Vd Vn imm (shift - scalar)
ins = id->idIns();
datasize = id->idOpSize();
assert(insOptsNone(id->idInsOpt()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
assert(isValidVectorShiftAmount(emitGetInsSC(id), datasize, emitInsIsVectorRightShift(ins)));
break;
case IF_DV_2O: // DV_2O .Q.......iiiiiii ......nnnnnddddd Vd Vn imm (shift - vector)
ins = id->idIns();
datasize = id->idOpSize();
elemsize = optGetElemsize(id->idInsOpt());
assert(isValidVectorDatasize(datasize));
assert(isValidArrangement(datasize, id->idInsOpt()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
assert(isValidVectorShiftAmount(emitGetInsSC(id), elemsize, emitInsIsVectorRightShift(ins)));
break;
case IF_DV_2B: // DV_2B .Q.........iiiii ......nnnnnddddd Rd Vn[] (umov/smov - to general)
elemsize = id->idOpSize();
index = emitGetInsSC(id);
assert(insOptsNone(id->idInsOpt()));
assert(isValidVectorIndex(EA_16BYTE, elemsize, index));
assert(isValidVectorElemsize(elemsize));
assert(isGeneralRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
break;
case IF_DV_2C: // DV_2C .Q.........iiiii ......nnnnnddddd Vd Rn (dup/ins - vector from general)
if (id->idIns() == INS_dup)
{
datasize = id->idOpSize();
assert(isValidVectorDatasize(datasize));
assert(isValidArrangement(datasize, id->idInsOpt()));
elemsize = optGetElemsize(id->idInsOpt());
}
else // INS_ins
{
datasize = EA_16BYTE;
elemsize = id->idOpSize();
assert(isValidVectorElemsize(elemsize));
}
assert(isVectorRegister(id->idReg1()));
assert(isGeneralRegisterOrZR(id->idReg2()));
break;
case IF_DV_2D: // DV_2D .Q.........iiiii ......nnnnnddddd Vd Vn[] (dup - vector)
ins = id->idIns();
datasize = id->idOpSize();
assert(isValidVectorDatasize(datasize));
assert(isValidArrangement(datasize, id->idInsOpt()));
elemsize = optGetElemsize(id->idInsOpt());
index = emitGetInsSC(id);
assert((ins == INS_dup) || isValidVectorIndex(datasize, elemsize, index));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
break;
case IF_DV_2E: // DV_2E ...........iiiii ......nnnnnddddd Vd Vn[] (dup - scalar)
elemsize = id->idOpSize();
index = emitGetInsSC(id);
assert(isValidVectorIndex(EA_16BYTE, elemsize, index));
assert(isValidVectorElemsize(elemsize));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
break;
case IF_DV_2F: // DV_2F ...........iiiii .jjjj.nnnnnddddd Vd[] Vn[] (ins - element)
imm = emitGetInsSC(id);
index = (imm >> 4) & 0xf;
index2 = imm & 0xf;
elemsize = id->idOpSize();
assert(isValidVectorElemsize(elemsize));
assert(isValidVectorIndex(EA_16BYTE, elemsize, index));
assert(isValidVectorIndex(EA_16BYTE, elemsize, index2));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
break;
case IF_DV_2L: // DV_2L ........XX...... ......nnnnnddddd Vd Vn (abs, neg - scalar)
assert(insOptsNone(id->idInsOpt()));
assert(isValidVectorElemsize(id->idOpSize()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
break;
case IF_DV_2G: // DV_2G .........X...... ......nnnnnddddd Vd Vn (fmov, fcvtXX - register)
case IF_DV_2K: // DV_2K .........X.mmmmm ......nnnnn..... Vn Vm (fcmp)
assert(insOptsNone(id->idInsOpt()));
assert(isValidVectorElemsizeFloat(id->idOpSize()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
break;
case IF_DV_2H: // DV_2H X........X...... ......nnnnnddddd Rd Vn (fmov/fcvtXX - to general)
assert(insOptsConvertFloatToInt(id->idInsOpt()));
dstsize = optGetDstsize(id->idInsOpt());
srcsize = optGetSrcsize(id->idInsOpt());
assert(isValidGeneralDatasize(dstsize));
assert(isValidVectorElemsizeFloat(srcsize));
assert(dstsize == id->idOpSize());
assert(isGeneralRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
break;
case IF_DV_2I: // DV_2I X........X...... ......nnnnnddddd Vd Rn (fmov/Xcvtf - from general)
assert(insOptsConvertIntToFloat(id->idInsOpt()));
dstsize = optGetDstsize(id->idInsOpt());
srcsize = optGetSrcsize(id->idInsOpt());
assert(isValidGeneralDatasize(srcsize));
assert(isValidVectorElemsizeFloat(dstsize));
assert(dstsize == id->idOpSize());
assert(isVectorRegister(id->idReg1()));
assert(isGeneralRegister(id->idReg2()));
break;
case IF_DV_2J: // DV_2J ........SS.....D D.....nnnnnddddd Vd Vn (fcvt)
assert(insOptsConvertFloatToFloat(id->idInsOpt()));
dstsize = optGetDstsize(id->idInsOpt());
srcsize = optGetSrcsize(id->idInsOpt());
assert(isValidVectorFcvtsize(srcsize));
assert(isValidVectorFcvtsize(dstsize));
assert(dstsize == id->idOpSize());
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
break;
case IF_DV_2Q: // DV_2Q .........X...... ......nnnnnddddd Sd Vn (faddp, fmaxnmp, fmaxp, fminnmp,
// fminp - scalar)
if (id->idOpSize() == EA_16BYTE)
{
assert(id->idInsOpt() == INS_OPTS_2D);
}
else
{
assert(id->idOpSize() == EA_8BYTE);
assert(id->idInsOpt() == INS_OPTS_2S);
}
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
break;
case IF_DV_2R: // DV_2R .Q.......X...... ......nnnnnddddd Sd Vn (fmaxnmv, fmaxv, fminnmv, fminv)
assert(id->idOpSize() == EA_16BYTE);
assert(id->idInsOpt() == INS_OPTS_4S);
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
break;
case IF_DV_2S: // DV_2S ........XX...... ......nnnnnddddd Sd Vn (addp - scalar)
assert(id->idOpSize() == EA_16BYTE);
assert(id->idInsOpt() == INS_OPTS_2D);
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
break;
case IF_DV_2T: // DV_2T .Q......XX...... ......nnnnnddddd Sd Vn (addv, saddlv, smaxv, sminv, uaddlv,
// umaxv, uminv)
assert(isValidVectorDatasize(id->idOpSize()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
break;
case IF_DV_2U: // DV_2U ................ ......nnnnnddddd Sd Sn (sha1h)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
break;
case IF_DV_3A: // DV_3A .Q......XX.mmmmm ......nnnnnddddd Vd Vn Vm (vector)
assert(isValidVectorDatasize(id->idOpSize()));
assert(isValidArrangement(id->idOpSize(), id->idInsOpt()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
assert(isVectorRegister(id->idReg3()));
elemsize = optGetElemsize(id->idInsOpt());
ins = id->idIns();
if (ins == INS_mul)
{
assert(elemsize != EA_8BYTE); // can't use 2D or 1D
}
else if (ins == INS_pmul)
{
assert(elemsize == EA_1BYTE); // only supports 8B or 16B
}
break;
case IF_DV_3AI: // DV_3AI .Q......XXLMmmmm ....H.nnnnnddddd Vd Vn Vm[] (vector by element)
assert(isValidVectorDatasize(id->idOpSize()));
assert(isValidArrangement(id->idOpSize(), id->idInsOpt()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
assert(isVectorRegister(id->idReg3()));
elemsize = optGetElemsize(id->idInsOpt());
assert(isValidVectorIndex(EA_16BYTE, elemsize, emitGetInsSC(id)));
// Only has encodings for H or S elemsize
assert((elemsize == EA_2BYTE) || (elemsize == EA_4BYTE));
break;
case IF_DV_3B: // DV_3B .Q.......X.mmmmm ......nnnnnddddd Vd Vn Vm (vector)
assert(isValidVectorDatasize(id->idOpSize()));
assert(isValidArrangement(id->idOpSize(), id->idInsOpt()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
assert(isVectorRegister(id->idReg3()));
break;
case IF_DV_3BI: // DV_3BI .Q.......XLmmmmm ....H.nnnnnddddd Vd Vn Vm[] (vector by element)
assert(isValidVectorDatasize(id->idOpSize()));
assert(isValidArrangement(id->idOpSize(), id->idInsOpt()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
assert(isVectorRegister(id->idReg3()));
elemsize = optGetElemsize(id->idInsOpt());
assert(isValidVectorIndex(EA_16BYTE, elemsize, emitGetInsSC(id)));
break;
case IF_DV_3C: // DV_3C .Q.........mmmmm ......nnnnnddddd Vd Vn Vm (vector)
switch (id->idIns())
{
case INS_tbl:
case INS_tbl_2regs:
case INS_tbl_3regs:
case INS_tbl_4regs:
case INS_tbx:
case INS_tbx_2regs:
case INS_tbx_3regs:
case INS_tbx_4regs:
elemsize = optGetElemsize(id->idInsOpt());
assert(elemsize == EA_1BYTE);
break;
default:
break;
}
assert(isValidVectorDatasize(id->idOpSize()));
assert(isValidArrangement(id->idOpSize(), id->idInsOpt()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
assert(isVectorRegister(id->idReg3()));
break;
case IF_DV_3D: // DV_3D .........X.mmmmm ......nnnnnddddd Vd Vn Vm (scalar)
assert(isValidScalarDatasize(id->idOpSize()));
assert(insOptsNone(id->idInsOpt()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
assert(isVectorRegister(id->idReg3()));
break;
case IF_DV_3DI: // DV_3DI .........XLmmmmm ....H.nnnnnddddd Vd Vn Vm[] (scalar by element)
assert(isValidScalarDatasize(id->idOpSize()));
assert(insOptsNone(id->idInsOpt()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
assert(isVectorRegister(id->idReg3()));
elemsize = id->idOpSize();
assert(isValidVectorIndex(EA_16BYTE, elemsize, emitGetInsSC(id)));
break;
case IF_DV_3E: // DV_3E ........XX.mmmmm ......nnnnnddddd Vd Vn Vm (scalar)
assert(isValidVectorElemsize(id->idOpSize()));
assert(insOptsNone(id->idInsOpt()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
assert(isVectorRegister(id->idReg3()));
elemsize = id->idOpSize();
index = emitGetInsSC(id);
assert(isValidVectorIndex(EA_16BYTE, elemsize, index));
break;
case IF_DV_3EI: // DV_3EI ........XXLMmmmm ....H.nnnnnddddd Vd Vn Vm[] (scalar by element)
assert(isValidVectorElemsize(id->idOpSize()));
assert(insOptsNone(id->idInsOpt()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
assert(isVectorRegister(id->idReg3()));
elemsize = id->idOpSize();
index = emitGetInsSC(id);
assert(isValidVectorIndex(EA_16BYTE, elemsize, index));
break;
case IF_DV_3F: // DV_3F ...........mmmmm ......nnnnnddddd Vd Vn Vm
assert(isValidVectorDatasize(id->idOpSize()));
assert(isValidArrangement(id->idOpSize(), id->idInsOpt()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
assert(isVectorRegister(id->idReg3()));
break;
case IF_DV_3G: // DV_3G .Q.........mmmmm .iiii.nnnnnddddd Vd Vn Vm imm (vector)
assert(isValidVectorDatasize(id->idOpSize()));
assert(isValidArrangement(id->idOpSize(), id->idInsOpt()));
assert(isValidVectorIndex(id->idOpSize(), EA_1BYTE, emitGetInsSC(id)));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
assert(isVectorRegister(id->idReg3()));
break;
case IF_DV_4A: // DR_4A .........X.mmmmm .aaaaannnnnddddd Rd Rn Rm Ra (scalar)
assert(isValidGeneralDatasize(id->idOpSize()));
assert(isVectorRegister(id->idReg1()));
assert(isVectorRegister(id->idReg2()));
assert(isVectorRegister(id->idReg3()));
assert(isVectorRegister(id->idReg4()));
break;
case IF_PC_1A: // PC_1A ................ ...........ddddd Rd
assert(id->idOpSize() == EA_8BYTE);
assert(isGeneralRegister(id->idReg1()));
break;
case IF_PC_2A: // PC_2A X........X...... ......nnnnnddddd Rd Rn
assert(id->idOpSize() == EA_8BYTE);
assert(isGeneralRegister(id->idReg1()));
assert(isIntegerRegister(id->idReg2())); // SP
break;
case IF_PC_0A: // PC_0A ................ ................
case IF_SN_0A: // SN_0A ................ ................
case IF_SI_0A: // SI_0A ...........iiiii iiiiiiiiiii..... imm16
case IF_SI_0B: // SI_0B ................ ....bbbb........ imm4 - barrier
break;
case IF_SR_1A: // SR_1A ................ ...........ttttt Rt (dc zva, mrs)
datasize = id->idOpSize();
assert(isGeneralRegister(id->idReg1()));
assert(datasize == EA_8BYTE);
break;
default:
// fallback to check SVE instructions.
emitInsSveSanityCheck(id);
break;
}
}
#endif // DEBUG
bool emitter::emitInsMayWriteToGCReg(instrDesc* id)
{
instruction ins = id->idIns();
insFormat fmt = id->idInsFmt();
switch (fmt)
{
// These are the formats with "destination" registers:
case IF_DI_1B: // DI_1B X........hwiiiii iiiiiiiiiiiddddd Rd imm(i16,hw)
case IF_DI_1D: // DI_1D X........Nrrrrrr ssssss.....ddddd Rd imm(N,r,s)
case IF_DI_1E: // DI_1E .ii.....iiiiiiii iiiiiiiiiiiddddd Rd simm21
case IF_DI_2A: // DI_2A X.......shiiiiii iiiiiinnnnnddddd Rd Rn imm(i12,sh)
case IF_DI_2B: // DI_2B X.........Xnnnnn ssssssnnnnnddddd Rd Rn imm(0-63)
case IF_DI_2C: // DI_2C X........Nrrrrrr ssssssnnnnnddddd Rd Rn imm(N,r,s)
case IF_DI_2D: // DI_2D X........Nrrrrrr ssssssnnnnnddddd Rd Rn imr, imms (N,r,s)
case IF_DR_1D: // DR_1D X............... cccc.......ddddd Rd cond
case IF_DR_2D: // DR_2D X..........nnnnn cccc..nnnnnddddd Rd Rn cond
case IF_DR_2E: // DR_2E X..........mmmmm ...........ddddd Rd Rm
case IF_DR_2F: // DR_2F X.......sh.mmmmm ssssss.....ddddd Rd Rm {LSL,LSR,ASR} imm(0-63)
case IF_DR_2G: // DR_2G X............... ......nnnnnddddd Rd Rn
case IF_DR_2H: // DR_2H X........X...... ......nnnnnddddd Rd Rn