-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathhwintrinsicxarch.cpp
More file actions
5612 lines (4762 loc) · 197 KB
/
hwintrinsicxarch.cpp
File metadata and controls
5612 lines (4762 loc) · 197 KB
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.
#include "jitpch.h"
#include "hwintrinsic.h"
#ifdef FEATURE_HW_INTRINSICS
//------------------------------------------------------------------------
// X64VersionOfIsa: Gets the corresponding 64-bit only InstructionSet for a given InstructionSet
//
// Arguments:
// isa -- The InstructionSet ID
//
// Return Value:
// The 64-bit only InstructionSet associated with isa
static CORINFO_InstructionSet X64VersionOfIsa(CORINFO_InstructionSet isa)
{
switch (isa)
{
case InstructionSet_X86Base:
return InstructionSet_X86Base_X64;
case InstructionSet_AVX:
return InstructionSet_AVX_X64;
case InstructionSet_AVX2:
return InstructionSet_AVX2_X64;
case InstructionSet_AVX512:
return InstructionSet_AVX512_X64;
case InstructionSet_AVX512v2:
return InstructionSet_AVX512v2_X64;
case InstructionSet_AVX512v3:
return InstructionSet_AVX512v3_X64;
case InstructionSet_AVX10v1:
return InstructionSet_AVX10v1_X64;
case InstructionSet_AVX10v2:
return InstructionSet_AVX10v2_X64;
case InstructionSet_AES:
return InstructionSet_AES_X64;
case InstructionSet_AVX512VP2INTERSECT:
return InstructionSet_AVX512VP2INTERSECT_X64;
case InstructionSet_AVXIFMA:
return InstructionSet_AVXIFMA_X64;
case InstructionSet_AVXVNNI:
return InstructionSet_AVXVNNI_X64;
case InstructionSet_AVXVNNIINT:
return InstructionSet_AVXVNNIINT;
case InstructionSet_AVXVNNIINT_V512:
return InstructionSet_AVXVNNIINT_V512;
case InstructionSet_GFNI:
return InstructionSet_GFNI_X64;
case InstructionSet_SHA:
return InstructionSet_SHA_X64;
case InstructionSet_WAITPKG:
return InstructionSet_WAITPKG_X64;
case InstructionSet_X86Serialize:
return InstructionSet_X86Serialize_X64;
default:
return InstructionSet_NONE;
}
}
//------------------------------------------------------------------------
// VLVersionOfIsa: Gets the corresponding AVX512VL only InstructionSet for a given InstructionSet
//
// Arguments:
// isa -- The InstructionSet ID
//
// Return Value:
// The AVX512VL only InstructionSet associated with isa
static CORINFO_InstructionSet VLVersionOfIsa(CORINFO_InstructionSet isa)
{
switch (isa)
{
case InstructionSet_AVX512:
case InstructionSet_AVX512v2:
case InstructionSet_AVX512v3:
case InstructionSet_AVX10v1:
{
// These nested ISAs aren't tracked by the JIT support
return isa;
}
default:
{
return InstructionSet_NONE;
}
}
}
//------------------------------------------------------------------------
// V256VersionOfIsa: Gets the corresponding V256 only InstructionSet for a given InstructionSet
//
// Arguments:
// isa -- The InstructionSet ID
//
// Return Value:
// The V256 only InstructionSet associated with isa
static CORINFO_InstructionSet V256VersionOfIsa(CORINFO_InstructionSet isa)
{
switch (isa)
{
case InstructionSet_AES:
{
return InstructionSet_AES_V256;
}
case InstructionSet_GFNI:
{
return InstructionSet_GFNI_V256;
}
default:
{
return InstructionSet_NONE;
}
}
}
//------------------------------------------------------------------------
// V512VersionOfIsa: Gets the corresponding V512 only InstructionSet for a given InstructionSet
//
// Arguments:
// isa -- The InstructionSet ID
//
// Return Value:
// The V512 only InstructionSet associated with isa
static CORINFO_InstructionSet V512VersionOfIsa(CORINFO_InstructionSet isa)
{
switch (isa)
{
case InstructionSet_AVX10v1:
case InstructionSet_AVX10v1_X64:
case InstructionSet_AVX10v2:
case InstructionSet_AVX10v2_X64:
{
// These nested ISAs aren't tracked by the JIT support
return isa;
}
case InstructionSet_AES:
{
return InstructionSet_AES_V512;
}
case InstructionSet_GFNI:
{
return InstructionSet_GFNI_V512;
}
case InstructionSet_AVXVNNIINT:
case InstructionSet_AVXVNNIINT_V512:
{
return InstructionSet_AVXVNNIINT_V512;
}
default:
{
return InstructionSet_NONE;
}
}
}
//------------------------------------------------------------------------
// lookupInstructionSet: Gets the InstructionSet for a given class name
//
// Arguments:
// className -- The name of the class associated with the InstructionSet to lookup
//
// Return Value:
// The InstructionSet associated with className
CORINFO_InstructionSet Compiler::lookupInstructionSet(const char* className)
{
assert(className != nullptr);
if (className[0] == 'A')
{
if (strcmp(className + 1, "es") == 0)
{
return InstructionSet_AES;
}
else if (strncmp(className + 1, "vx", 2) == 0)
{
if (className[3] == '\0')
{
return InstructionSet_AVX;
}
else if (strncmp(className + 3, "10v", 3) == 0)
{
if (strcmp(className + 6, "1") == 0)
{
return InstructionSet_AVX10v1;
}
else if (strcmp(className + 6, "2") == 0)
{
return InstructionSet_AVX10v2;
}
}
else if (strcmp(className + 3, "2") == 0)
{
return InstructionSet_AVX2;
}
else if (strncmp(className + 3, "512", 3) == 0)
{
if (className[6] == 'B')
{
if (strcmp(className + 7, "italg") == 0)
{
return InstructionSet_AVX512v3;
}
else if (strcmp(className + 7, "f16") == 0)
{
return InstructionSet_AVX10v1;
}
else if (strcmp(className + 7, "W") == 0)
{
return InstructionSet_AVX512;
}
}
else if ((strcmp(className + 6, "CD") == 0) || (strcmp(className + 6, "DQ") == 0))
{
return InstructionSet_AVX512;
}
else if (className[6] == 'F')
{
if (className[7] == '\0')
{
return InstructionSet_AVX512;
}
else if (strcmp(className + 7, "p16") == 0)
{
return InstructionSet_AVX10v1;
}
}
else if (className[6] == 'V')
{
if (strncmp(className + 7, "bmi", 3) == 0)
{
if (className[10] == '\0')
{
return InstructionSet_AVX512v2;
}
else if (strcmp(className + 10, "2") == 0)
{
return InstructionSet_AVX512v3;
}
}
else if (className[7] == 'p')
{
if (strcmp(className + 8, "p2intersect") == 0)
{
return InstructionSet_AVX512VP2INTERSECT;
}
else if (strcmp(className + 8, "opcntdq") == 0)
{
return InstructionSet_AVX512v3;
}
}
}
}
else if (strcmp(className + 3, "Ifma") == 0)
{
return InstructionSet_AVXIFMA;
}
else if (strncmp(className + 3, "Vnni", 4) == 0)
{
if (className[7] == '\0')
{
return InstructionSet_AVXVNNI;
}
else if (strncmp(className + 7, "Int", 3) == 0)
{
if ((strcmp(className + 10, "8") == 0) || (strcmp(className + 10, "16") == 0))
{
if (compSupportsHWIntrinsic(InstructionSet_AVXVNNIINT))
{
return InstructionSet_AVXVNNIINT;
}
else
{
return InstructionSet_AVXVNNIINT_V512;
}
}
}
}
}
}
else if (className[0] == 'B')
{
if (strncmp(className + 1, "mi", 2) == 0)
{
if (strcmp(className + 3, "1") == 0)
{
return InstructionSet_AVX2;
}
else if (strcmp(className + 3, "2") == 0)
{
return InstructionSet_AVX2;
}
}
}
else if (className[0] == 'F')
{
if (strcmp(className + 1, "ma") == 0)
{
return InstructionSet_AVX2;
}
else if (strcmp(className + 1, "16c") == 0)
{
return InstructionSet_AVX2;
}
}
else if (className[0] == 'G')
{
if (strcmp(className + 1, "fni") == 0)
{
return InstructionSet_GFNI;
}
}
else if (className[0] == 'L')
{
if (strcmp(className + 1, "zcnt") == 0)
{
return InstructionSet_AVX2;
}
}
else if (className[0] == 'P')
{
if (strcmp(className + 1, "clmulqdq") == 0)
{
return InstructionSet_AES;
}
else if (strcmp(className + 1, "opcnt") == 0)
{
return InstructionSet_X86Base;
}
}
else if (className[0] == 'S')
{
if (strcmp(className + 1, "ha") == 0)
{
return InstructionSet_SHA;
}
else if (strncmp(className + 1, "se", 2) == 0)
{
if ((className[3] == '\0') || (strcmp(className + 3, "2") == 0))
{
return InstructionSet_X86Base;
}
else if (strcmp(className + 3, "3") == 0)
{
return InstructionSet_X86Base;
}
else if (strcmp(className + 3, "41") == 0)
{
return InstructionSet_X86Base;
}
else if (strcmp(className + 3, "42") == 0)
{
return InstructionSet_X86Base;
}
}
else if (strcmp(className + 1, "sse3") == 0)
{
return InstructionSet_X86Base;
}
}
else if (className[0] == 'V')
{
if (strncmp(className + 1, "ector", 5) == 0)
{
if (strncmp(className + 6, "128", 3) == 0)
{
if ((className[9] == '\0') || (strcmp(className + 9, "`1") == 0))
{
return InstructionSet_Vector128;
}
}
else if (strncmp(className + 6, "256", 3) == 0)
{
if ((className[9] == '\0') || (strcmp(className + 9, "`1") == 0))
{
return InstructionSet_Vector256;
}
}
else if (strncmp(className + 6, "512", 3) == 0)
{
if ((className[9] == '\0') || (strcmp(className + 9, "`1") == 0))
{
return InstructionSet_Vector512;
}
}
}
else if (strcmp(className + 1, "L") == 0)
{
assert(!"VL.X64 support doesn't exist in the managed libraries and so is not yet implemented");
return InstructionSet_ILLEGAL;
}
}
else if (strcmp(className, "WaitPkg") == 0)
{
return InstructionSet_WAITPKG;
}
else if (strncmp(className, "X86", 3) == 0)
{
if (strcmp(className + 3, "Base") == 0)
{
return InstructionSet_X86Base;
}
else if (strcmp(className + 3, "Serialize") == 0)
{
return InstructionSet_X86Serialize;
}
}
return InstructionSet_ILLEGAL;
}
//------------------------------------------------------------------------
// lookupIsa: Gets the InstructionSet for a given class name and enclosing class name
//
// Arguments:
// className -- The name of the class associated with the InstructionSet to lookup
// innerEnclosingClassName -- The name of the inner enclosing class of X64 classes
// outerEnclosingClassName -- The name of the outer enclosing class of X64 classes
//
// Return Value:
// The InstructionSet associated with className and enclosingClassName
CORINFO_InstructionSet Compiler::lookupIsa(const char* className,
const char* innerEnclosingClassName,
const char* outerEnclosingClassName)
{
assert(className != nullptr);
if (innerEnclosingClassName == nullptr)
{
// No nested class is the most common, so fast path it
return lookupInstructionSet(className);
}
// Since lookupId is only called for the xplat intrinsics
// or intrinsics in the platform specific namespace, we assume
// that it will be one we can handle and don't try to early out.
CORINFO_InstructionSet enclosingIsa = lookupIsa(innerEnclosingClassName, outerEnclosingClassName, nullptr);
if (className[0] == 'V')
{
if (strcmp(className, "V256") == 0)
{
return V256VersionOfIsa(enclosingIsa);
}
else if (strcmp(className, "V512") == 0)
{
return V512VersionOfIsa(enclosingIsa);
}
else if (strcmp(className, "VL") == 0)
{
return VLVersionOfIsa(enclosingIsa);
}
}
else if (strcmp(className, "X64") == 0)
{
return X64VersionOfIsa(enclosingIsa);
}
return InstructionSet_ILLEGAL;
}
//------------------------------------------------------------------------
// lookupImmUpperBound: Gets the upper bound for the imm-value of a given NamedIntrinsic
//
// Arguments:
// id -- The NamedIntrinsic associated with the HWIntrinsic to lookup
//
// Return Value:
// The upper bound for the imm-value of the intrinsic associated with id
//
int HWIntrinsicInfo::lookupImmUpperBound(NamedIntrinsic id)
{
if (HWIntrinsicInfo::IsEmbRoundingCompatible(id))
{
// The only case this branch should be hit is that JIT is generating a jump table fallback when the
// FloatRoundingMode is not a compile-time constant.
// Although the expected FloatRoundingMode values are 8, 9, 10, 11, but in the generated jump table, results for
// entries within [0, 11] are all calculated,
// Any unexpected value, say [0, 7] should be blocked by the managed code.
return 11;
}
assert(HWIntrinsicInfo::lookupCategory(id) == HW_Category_IMM);
switch (id)
{
case NI_AVX_Compare:
case NI_AVX_CompareScalar:
case NI_AVX512_Compare:
case NI_AVX512_CompareMask:
case NI_AVX10v2_MinMaxScalar:
case NI_AVX10v2_MinMax:
{
assert(!HWIntrinsicInfo::HasFullRangeImm(id));
return 31; // enum FloatComparisonMode has 32 values
}
case NI_AVX2_GatherVector128:
case NI_AVX2_GatherVector256:
case NI_AVX2_GatherMaskVector128:
case NI_AVX2_GatherMaskVector256:
{
assert(!HWIntrinsicInfo::HasFullRangeImm(id));
return 8;
}
case NI_AVX512_GetMantissa:
case NI_AVX512_GetMantissaScalar:
case NI_AVX512_Range:
case NI_AVX512_RangeScalar:
{
assert(!HWIntrinsicInfo::HasFullRangeImm(id));
return 15;
}
default:
{
assert(HWIntrinsicInfo::HasFullRangeImm(id));
return 255;
}
}
}
//------------------------------------------------------------------------
// isAVX2GatherIntrinsic: Check if the intrinsic is AVX Gather*
//
// Arguments:
// id -- The NamedIntrinsic associated with the HWIntrinsic to lookup
//
// Return Value:
// true if id is AVX Gather* intrinsic
//
bool HWIntrinsicInfo::isAVX2GatherIntrinsic(NamedIntrinsic id)
{
switch (id)
{
case NI_AVX2_GatherVector128:
case NI_AVX2_GatherVector256:
case NI_AVX2_GatherMaskVector128:
case NI_AVX2_GatherMaskVector256:
return true;
default:
return false;
}
}
//------------------------------------------------------------------------
// lookupIdForFloatComparisonMode: Get the intrinsic ID to use for a given float comparison mode
//
// Arguments:
// intrinsic -- The base intrinsic that is being simplified
// comparison -- The comparison mode used
// simdBaseType -- The base type for which the comparison is being done
// simdSize -- The simd size for which the comparison is being done
//
// Return Value:
// The intrinsic ID to use instead of intrinsic
//
NamedIntrinsic HWIntrinsicInfo::lookupIdForFloatComparisonMode(NamedIntrinsic intrinsic,
FloatComparisonMode comparison,
var_types simdBaseType,
unsigned simdSize)
{
assert(varTypeIsFloating(simdBaseType));
assert((simdSize == 16) || (simdSize == 32) || (simdSize == 64));
// .NET doesn't differentiate between signalling and non-signalling
// we disable IEEE 754 exceptions on startup and make it undefined
// behavior to enable it, so we'll just normalize to the same form
switch (comparison)
{
case FloatComparisonMode::OrderedEqualNonSignaling:
case FloatComparisonMode::OrderedEqualSignaling:
{
if (intrinsic == NI_AVX512_CompareMask)
{
return NI_AVX512_CompareEqualMask;
}
else if (intrinsic == NI_AVX_CompareScalar)
{
return NI_X86Base_CompareScalarEqual;
}
assert(intrinsic == NI_AVX_Compare);
if (simdSize == 32)
{
return NI_AVX_CompareEqual;
}
return NI_X86Base_CompareEqual;
}
case FloatComparisonMode::OrderedGreaterThanSignaling:
case FloatComparisonMode::OrderedGreaterThanNonSignaling:
{
if (intrinsic == NI_AVX512_CompareMask)
{
return NI_AVX512_CompareGreaterThanMask;
}
else if (intrinsic == NI_AVX_CompareScalar)
{
return NI_X86Base_CompareScalarGreaterThan;
}
assert(intrinsic == NI_AVX_Compare);
if (simdSize == 32)
{
return NI_AVX_CompareGreaterThan;
}
return NI_X86Base_CompareGreaterThan;
}
case FloatComparisonMode::OrderedGreaterThanOrEqualSignaling:
case FloatComparisonMode::OrderedGreaterThanOrEqualNonSignaling:
{
if (intrinsic == NI_AVX512_CompareMask)
{
return NI_AVX512_CompareGreaterThanOrEqualMask;
}
else if (intrinsic == NI_AVX_CompareScalar)
{
return NI_X86Base_CompareScalarGreaterThanOrEqual;
}
assert(intrinsic == NI_AVX_Compare);
if (simdSize == 32)
{
return NI_AVX_CompareGreaterThanOrEqual;
}
return NI_X86Base_CompareGreaterThanOrEqual;
}
case FloatComparisonMode::OrderedLessThanSignaling:
case FloatComparisonMode::OrderedLessThanNonSignaling:
{
if (intrinsic == NI_AVX512_CompareMask)
{
return NI_AVX512_CompareLessThanMask;
}
else if (intrinsic == NI_AVX_CompareScalar)
{
return NI_X86Base_CompareScalarLessThan;
}
assert(intrinsic == NI_AVX_Compare);
if (simdSize == 32)
{
return NI_AVX_CompareLessThan;
}
return NI_X86Base_CompareLessThan;
}
case FloatComparisonMode::OrderedLessThanOrEqualSignaling:
case FloatComparisonMode::OrderedLessThanOrEqualNonSignaling:
{
if (intrinsic == NI_AVX512_CompareMask)
{
return NI_AVX512_CompareLessThanOrEqualMask;
}
else if (intrinsic == NI_AVX_CompareScalar)
{
return NI_X86Base_CompareScalarLessThanOrEqual;
}
assert(intrinsic == NI_AVX_Compare);
if (simdSize == 32)
{
return NI_AVX_CompareLessThanOrEqual;
}
return NI_X86Base_CompareLessThanOrEqual;
}
case FloatComparisonMode::UnorderedNotEqualNonSignaling:
case FloatComparisonMode::UnorderedNotEqualSignaling:
{
if (intrinsic == NI_AVX512_CompareMask)
{
return NI_AVX512_CompareNotEqualMask;
}
else if (intrinsic == NI_AVX_CompareScalar)
{
return NI_X86Base_CompareScalarNotEqual;
}
assert(intrinsic == NI_AVX_Compare);
if (simdSize == 32)
{
return NI_AVX_CompareNotEqual;
}
return NI_X86Base_CompareNotEqual;
}
case FloatComparisonMode::UnorderedNotGreaterThanSignaling:
case FloatComparisonMode::UnorderedNotGreaterThanNonSignaling:
{
if (intrinsic == NI_AVX512_CompareMask)
{
return NI_AVX512_CompareNotGreaterThanMask;
}
else if (intrinsic == NI_AVX_CompareScalar)
{
return NI_X86Base_CompareScalarNotGreaterThan;
}
assert(intrinsic == NI_AVX_Compare);
if (simdSize == 32)
{
return NI_AVX_CompareNotGreaterThan;
}
return NI_X86Base_CompareNotGreaterThan;
}
case FloatComparisonMode::UnorderedNotGreaterThanOrEqualSignaling:
case FloatComparisonMode::UnorderedNotGreaterThanOrEqualNonSignaling:
{
if (intrinsic == NI_AVX512_CompareMask)
{
return NI_AVX512_CompareNotGreaterThanOrEqualMask;
}
else if (intrinsic == NI_AVX_CompareScalar)
{
return NI_X86Base_CompareScalarNotGreaterThanOrEqual;
}
assert(intrinsic == NI_AVX_Compare);
if (simdSize == 32)
{
return NI_AVX_CompareNotGreaterThanOrEqual;
}
return NI_X86Base_CompareNotGreaterThanOrEqual;
}
case FloatComparisonMode::UnorderedNotLessThanSignaling:
case FloatComparisonMode::UnorderedNotLessThanNonSignaling:
{
if (intrinsic == NI_AVX512_CompareMask)
{
return NI_AVX512_CompareNotLessThanMask;
}
else if (intrinsic == NI_AVX_CompareScalar)
{
return NI_X86Base_CompareScalarNotLessThan;
}
assert(intrinsic == NI_AVX_Compare);
if (simdSize == 32)
{
return NI_AVX_CompareNotLessThan;
}
return NI_X86Base_CompareNotLessThan;
}
case FloatComparisonMode::UnorderedNotLessThanOrEqualSignaling:
case FloatComparisonMode::UnorderedNotLessThanOrEqualNonSignaling:
{
if (intrinsic == NI_AVX512_CompareMask)
{
return NI_AVX512_CompareNotLessThanOrEqualMask;
}
else if (intrinsic == NI_AVX_CompareScalar)
{
return NI_X86Base_CompareScalarNotLessThanOrEqual;
}
assert(intrinsic == NI_AVX_Compare);
if (simdSize == 32)
{
return NI_AVX_CompareNotLessThanOrEqual;
}
return NI_X86Base_CompareNotLessThanOrEqual;
}
case FloatComparisonMode::OrderedNonSignaling:
case FloatComparisonMode::OrderedSignaling:
{
if (intrinsic == NI_AVX512_CompareMask)
{
return NI_AVX512_CompareOrderedMask;
}
else if (intrinsic == NI_AVX_CompareScalar)
{
return NI_X86Base_CompareScalarOrdered;
}
assert(intrinsic == NI_AVX_Compare);
if (simdSize == 32)
{
return NI_AVX_CompareOrdered;
}
return NI_X86Base_CompareOrdered;
}
case FloatComparisonMode::UnorderedNonSignaling:
case FloatComparisonMode::UnorderedSignaling:
{
if (intrinsic == NI_AVX512_CompareMask)
{
return NI_AVX512_CompareUnorderedMask;
}
else if (intrinsic == NI_AVX_CompareScalar)
{
return NI_X86Base_CompareScalarUnordered;
}
assert(intrinsic == NI_AVX_Compare);
if (simdSize == 32)
{
return NI_AVX_CompareUnordered;
}
return NI_X86Base_CompareUnordered;
}
default:
{
return intrinsic;
}
}
}
//------------------------------------------------------------------------
// lookupIval: Gets a the implicit immediate value for the given intrinsic
//
// Arguments:
// comp - The compiler
// id - The intrinsic for which to get the ival
// simdBaseType - The base type for the intrinsic
//
// Return Value:
// The immediate value for the given intrinsic or -1 if none exists
int HWIntrinsicInfo::lookupIval(Compiler* comp, NamedIntrinsic id, var_types simdBaseType)
{
switch (id)
{
case NI_X86Base_CompareEqual:
case NI_X86Base_CompareScalarEqual:
case NI_AVX_CompareEqual:
case NI_AVX512_CompareEqualMask:
{
if (varTypeIsFloating(simdBaseType))
{
return static_cast<int>(FloatComparisonMode::OrderedEqualNonSignaling);
}
else
{
// We can emit `vpcmpeqb`, `vpcmpeqw`, `vpcmpeqd`, or `vpcmpeqq`
}
break;
}
case NI_X86Base_CompareGreaterThan:
case NI_X86Base_CompareScalarGreaterThan:
case NI_AVX_CompareGreaterThan:
case NI_AVX512_CompareGreaterThanMask:
{
if (varTypeIsFloating(simdBaseType))
{
// CompareGreaterThan is not directly supported in hardware without AVX support.
// Lowering ensures we swap the operands and change to the correct ID.
assert(comp->compIsaSupportedDebugOnly(InstructionSet_AVX));
return static_cast<int>(FloatComparisonMode::OrderedGreaterThanSignaling);
}
else if ((id == NI_AVX512_CompareGreaterThanMask) && varTypeIsUnsigned(simdBaseType))
{
// TODO-XARCH-CQ: Allow the other integer paths to use the EVEX encoding
return static_cast<int>(IntComparisonMode::GreaterThan);
}
break;
}
case NI_X86Base_CompareLessThan:
case NI_X86Base_CompareScalarLessThan:
case NI_AVX_CompareLessThan:
case NI_AVX512_CompareLessThanMask:
{
if (varTypeIsFloating(simdBaseType))
{
return static_cast<int>(FloatComparisonMode::OrderedLessThanSignaling);
}
else if (id == NI_AVX512_CompareLessThanMask)
{
// TODO-XARCH-CQ: Allow the other integer paths to use the EVEX encoding
return static_cast<int>(IntComparisonMode::LessThan);
}
break;
}
case NI_X86Base_CompareGreaterThanOrEqual:
case NI_X86Base_CompareScalarGreaterThanOrEqual:
case NI_AVX_CompareGreaterThanOrEqual:
case NI_AVX512_CompareGreaterThanOrEqualMask:
{
if (varTypeIsFloating(simdBaseType))
{
// CompareGreaterThanOrEqual is not directly supported in hardware without AVX support.
// Lowering ensures we swap the operands and change to the correct ID.
assert(comp->compIsaSupportedDebugOnly(InstructionSet_AVX));
return static_cast<int>(FloatComparisonMode::OrderedGreaterThanOrEqualSignaling);
}
else
{
assert(id == NI_AVX512_CompareGreaterThanOrEqualMask);
return static_cast<int>(IntComparisonMode::GreaterThanOrEqual);
}
break;
}
case NI_X86Base_CompareLessThanOrEqual:
case NI_X86Base_CompareScalarLessThanOrEqual:
case NI_AVX_CompareLessThanOrEqual:
case NI_AVX512_CompareLessThanOrEqualMask:
{
if (varTypeIsFloating(simdBaseType))
{
return static_cast<int>(FloatComparisonMode::OrderedLessThanOrEqualSignaling);
}
else
{
assert(id == NI_AVX512_CompareLessThanOrEqualMask);
return static_cast<int>(IntComparisonMode::LessThanOrEqual);
}
break;
}
case NI_X86Base_CompareNotEqual:
case NI_X86Base_CompareScalarNotEqual:
case NI_AVX_CompareNotEqual:
case NI_AVX512_CompareNotEqualMask:
{
if (varTypeIsFloating(simdBaseType))
{
return static_cast<int>(FloatComparisonMode::UnorderedNotEqualNonSignaling);
}
else
{
assert(id == NI_AVX512_CompareNotEqualMask);
return static_cast<int>(IntComparisonMode::NotEqual);
}
break;
}
case NI_X86Base_CompareNotGreaterThan:
case NI_X86Base_CompareScalarNotGreaterThan:
case NI_AVX_CompareNotGreaterThan:
case NI_AVX512_CompareNotGreaterThanMask:
{
if (varTypeIsFloating(simdBaseType))
{
// CompareNotGreaterThan is not directly supported in hardware without AVX support.
// Lowering ensures we swap the operands and change to the correct ID.
assert(comp->compIsaSupportedDebugOnly(InstructionSet_AVX));
return static_cast<int>(FloatComparisonMode::UnorderedNotGreaterThanSignaling);
}
else
{
assert(id == NI_AVX512_CompareNotGreaterThanMask);
return static_cast<int>(IntComparisonMode::LessThanOrEqual);
}
break;
}
case NI_X86Base_CompareNotLessThan:
case NI_X86Base_CompareScalarNotLessThan:
case NI_AVX_CompareNotLessThan:
case NI_AVX512_CompareNotLessThanMask:
{
if (varTypeIsFloating(simdBaseType))
{
return static_cast<int>(FloatComparisonMode::UnorderedNotLessThanSignaling);
}
else
{
assert(id == NI_AVX512_CompareNotLessThanMask);
return static_cast<int>(IntComparisonMode::GreaterThanOrEqual);
}
break;
}
case NI_X86Base_CompareNotGreaterThanOrEqual:
case NI_X86Base_CompareScalarNotGreaterThanOrEqual: