forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhwintrinsic.h
1201 lines (962 loc) · 34.4 KB
/
hwintrinsic.h
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.
#ifndef _HW_INTRINSIC_H_
#define _HW_INTRINSIC_H_
#ifdef FEATURE_HW_INTRINSICS
#ifdef TARGET_XARCH
enum HWIntrinsicCategory : uint8_t
{
// Simple SIMD intrinsics
// - take Vector128/256<T> parameters
// - return a Vector128/256<T>
// - the codegen of overloads can be determined by intrinsicID and base type of returned vector
HW_Category_SimpleSIMD,
// IMM intrinsics
// - some SIMD intrinsics requires immediate value (i.e. imm8) to generate instruction
HW_Category_IMM,
// Scalar intrinsics
// - operate over general purpose registers, like crc32, lzcnt, popcnt, etc.
HW_Category_Scalar,
// SIMD scalar
// - operate over vector registers(XMM), but just compute on the first element
HW_Category_SIMDScalar,
// Memory access intrinsics
// - e.g., Avx.Load, Avx.Store, Sse.LoadAligned
HW_Category_MemoryLoad,
HW_Category_MemoryStore,
// Helper intrinsics
// - do not directly correspond to a instruction, such as Avx.SetAllVector256
HW_Category_Helper,
// Special intrinsics
// - have to be addressed specially
HW_Category_Special
};
#elif defined(TARGET_ARM64)
enum HWIntrinsicCategory : uint8_t
{
// Most of the Arm64 intrinsic fall into SIMD category:
// - vector or scalar intrinsics that operate on one-or-many SIMD registers
HW_Category_SIMD,
// Scalar intrinsics operate on general purpose registers (e.g. cls, clz, rbit)
HW_Category_Scalar,
// Memory access intrinsics
HW_Category_MemoryLoad,
HW_Category_MemoryStore,
// These are Arm64 that share some features in a given category (e.g. immediate operand value range)
HW_Category_ShiftLeftByImmediate,
HW_Category_ShiftRightByImmediate,
HW_Category_SIMDByIndexedElement,
// Helper intrinsics
// - do not directly correspond to a instruction, such as Vector64.AllBitsSet
HW_Category_Helper,
// Special intrinsics
// - have to be addressed specially
HW_Category_Special
};
#else
#error Unsupported platform
#endif
enum HWIntrinsicFlag : unsigned int
{
HW_Flag_NoFlag = 0,
// Commutative
// - if a binary-op intrinsic is commutative (e.g., Add, Multiply), its op1 can be contained
HW_Flag_Commutative = 0x1,
// NoCodeGen
// - should be transformed in the compiler front-end, cannot reach CodeGen
HW_Flag_NoCodeGen = 0x2,
// The intrinsic is invalid as the ID of a gtNode
HW_Flag_InvalidNodeId = 0x4,
// Select base type using the first argument type
HW_Flag_BaseTypeFromFirstArg = 0x8,
// Select base type using the second argument type
HW_Flag_BaseTypeFromSecondArg = 0x10,
// Indicates compFloatingPointUsed does not need to be set.
HW_Flag_NoFloatingPointUsed = 0x20,
// NoJmpTable IMM
// the imm intrinsic does not need jumptable fallback when it gets non-const argument
HW_Flag_NoJmpTableIMM = 0x40,
// Special codegen
// the intrinsics need special rules in CodeGen,
// but may be table-driven in the front-end
HW_Flag_SpecialCodeGen = 0x80,
// Special import
// the intrinsics need special rules in importer,
// but may be table-driven in the back-end
HW_Flag_SpecialImport = 0x100,
// The intrinsic returns result in multiple registers.
HW_Flag_MultiReg = 0x200,
// The below is for defining platform-specific flags
#if defined(TARGET_XARCH)
// Full range IMM intrinsic
// - the immediate value is valid on the full range of imm8 (0-255)
HW_Flag_FullRangeIMM = 0x400,
// Maybe IMM
// the intrinsic has either imm or Vector overloads
HW_Flag_MaybeIMM = 0x800,
// Copy Upper bits
// some SIMD scalar intrinsics need the semantics of copying upper bits from the source operand
HW_Flag_CopyUpperBits = 0x1000,
// Maybe Memory Load/Store
// - some intrinsics may have pointer overloads but without HW_Category_MemoryLoad/HW_Category_MemoryStore
HW_Flag_MaybeMemoryLoad = 0x2000,
HW_Flag_MaybeMemoryStore = 0x4000,
// No Read/Modify/Write Semantics
// the intrinsic doesn't have read/modify/write semantics in two/three-operand form.
HW_Flag_NoRMWSemantics = 0x8000,
// NoContainment
// the intrinsic cannot be handled by containment,
// all the intrinsic that have explicit memory load/store semantics should have this flag
HW_Flag_NoContainment = 0x10000,
// Returns Per-Element Mask
// the intrinsic returns a vector containing elements that are either "all bits set" or "all bits clear"
// this output can be used as a per-element mask
HW_Flag_ReturnsPerElementMask = 0x20000,
// AvxOnlyCompatible
// the intrinsic can be used on hardware with AVX but not AVX2 support
HW_Flag_AvxOnlyCompatible = 0x40000,
// MaybeCommutative
// - if a binary-op intrinsic is maybe commutative (e.g., Max or Min for float/double), its op1 can possibly be
// contained
HW_Flag_MaybeCommutative = 0x80000,
// The intrinsic has no EVEX compatible form
HW_Flag_NoEvexSemantics = 0x100000,
#elif defined(TARGET_ARM64)
// The intrinsic has an immediate operand
// - the value can be (and should be) encoded in a corresponding instruction when the operand value is constant
HW_Flag_HasImmediateOperand = 0x400,
// The intrinsic has read/modify/write semantics in multiple-operands form.
HW_Flag_HasRMWSemantics = 0x800,
// The intrinsic operates on the lower part of a SIMD register
// - the upper part of the source registers are ignored
// - the upper part of the destination register is zeroed
HW_Flag_SIMDScalar = 0x1000,
// The intrinsic supports some sort of containment analysis
HW_Flag_SupportsContainment = 0x2000,
// The intrinsic needs consecutive registers
HW_Flag_NeedsConsecutiveRegisters = 0x4000,
// The intrinsic uses scalable registers
HW_Flag_Scalable = 0x8000,
// Returns Per-Element Mask
// the intrinsic returns a vector containing elements that are either "all bits set" or "all bits clear"
// this output can be used as a per-element mask
HW_Flag_ReturnsPerElementMask = 0x10000,
// The intrinsic uses a mask in arg1 to select elements present in the result
HW_Flag_ExplicitMaskedOperation = 0x20000,
// The intrinsic uses a mask in arg1 to select elements present in the result, and must use a low register.
HW_Flag_LowMaskedOperation = 0x40000,
// The intrinsic can optionally use a mask in arg1 to select elements present in the result, which is not present in
// the API call
HW_Flag_OptionalEmbeddedMaskedOperation = 0x80000,
// The intrinsic uses a mask in arg1 to select elements present in the result, which is not present in the API call
HW_Flag_EmbeddedMaskedOperation = 0x100000,
#else
#error Unsupported platform
#endif
// The intrinsic has some barrier special side effect that should be tracked
HW_Flag_SpecialSideEffect_Barrier = 0x200000,
// The intrinsic has some other special side effect that should be tracked
HW_Flag_SpecialSideEffect_Other = 0x400000,
HW_Flag_SpecialSideEffectMask = (HW_Flag_SpecialSideEffect_Barrier | HW_Flag_SpecialSideEffect_Other),
// MaybeNoJmpTable IMM
// the imm intrinsic may not need jumptable fallback when it gets non-const argument
HW_Flag_MaybeNoJmpTableIMM = 0x800000,
#if defined(TARGET_XARCH)
// The intrinsic is an RMW intrinsic
HW_Flag_RmwIntrinsic = 0x1000000,
// The intrinsic is a PermuteVar2x intrinsic
HW_Flag_PermuteVar2x = 0x2000000,
// The intrinsic is an embedded broadcast compatible intrinsic
HW_Flag_EmbBroadcastCompatible = 0x4000000,
// The intrinsic is an embedded rounding compatible intrinsic
HW_Flag_EmbRoundingCompatible = 0x8000000,
// The intrinsic is an embedded masking compatible intrinsic
HW_Flag_EmbMaskingCompatible = 0x10000000,
#elif defined(TARGET_ARM64)
// The intrinsic has an enum operand. Using this implies HW_Flag_HasImmediateOperand.
HW_Flag_HasEnumOperand = 0x1000000,
// The intrinsic comes in both vector and scalar variants. During the import stage if the basetype is scalar,
// then the intrinsic should be switched to a scalar only version.
HW_Flag_HasScalarInputVariant = 0x2000000,
#endif // TARGET_XARCH
// The intrinsic is a FusedMultiplyAdd intrinsic
HW_Flag_FmaIntrinsic = 0x40000000,
#if defined(TARGET_ARM64)
// The intrinsic uses a mask in arg1 to select elements present in the result, and must use a low vector register.
HW_Flag_LowVectorOperation = 0x4000000,
#endif
HW_Flag_CanBenefitFromConstantProp = 0x80000000,
};
#if defined(TARGET_XARCH)
// This mirrors the System.Runtime.Intrinsics.X86.FloatComparisonMode enumeration
enum class FloatComparisonMode : uint8_t
{
// _CMP_EQ_OQ
OrderedEqualNonSignaling = 0,
// _CMP_LT_OS
OrderedLessThanSignaling = 1,
// _CMP_LE_OS
OrderedLessThanOrEqualSignaling = 2,
// _CMP_UNORD_Q
UnorderedNonSignaling = 3,
// _CMP_NEQ_UQ
UnorderedNotEqualNonSignaling = 4,
// _CMP_NLT_US
UnorderedNotLessThanSignaling = 5,
// _CMP_NLE_US
UnorderedNotLessThanOrEqualSignaling = 6,
// _CMP_ORD_Q
OrderedNonSignaling = 7,
// _CMP_EQ_UQ
UnorderedEqualNonSignaling = 8,
// _CMP_NGE_US
UnorderedNotGreaterThanOrEqualSignaling = 9,
// _CMP_NGT_US
UnorderedNotGreaterThanSignaling = 10,
// _CMP_FALSE_OQ
OrderedFalseNonSignaling = 11,
// _CMP_NEQ_OQ
OrderedNotEqualNonSignaling = 12,
// _CMP_GE_OS
OrderedGreaterThanOrEqualSignaling = 13,
// _CMP_GT_OS
OrderedGreaterThanSignaling = 14,
// _CMP_TRUE_UQ
UnorderedTrueNonSignaling = 15,
// _CMP_EQ_OS
OrderedEqualSignaling = 16,
// _CMP_LT_OQ
OrderedLessThanNonSignaling = 17,
// _CMP_LE_OQ
OrderedLessThanOrEqualNonSignaling = 18,
// _CMP_UNORD_S
UnorderedSignaling = 19,
// _CMP_NEQ_US
UnorderedNotEqualSignaling = 20,
// _CMP_NLT_UQ
UnorderedNotLessThanNonSignaling = 21,
// _CMP_NLE_UQ
UnorderedNotLessThanOrEqualNonSignaling = 22,
// _CMP_ORD_S
OrderedSignaling = 23,
// _CMP_EQ_US
UnorderedEqualSignaling = 24,
// _CMP_NGE_UQ
UnorderedNotGreaterThanOrEqualNonSignaling = 25,
// _CMP_NGT_UQ
UnorderedNotGreaterThanNonSignaling = 26,
// _CMP_FALSE_OS
OrderedFalseSignaling = 27,
// _CMP_NEQ_OS
OrderedNotEqualSignaling = 28,
// _CMP_GE_OQ
OrderedGreaterThanOrEqualNonSignaling = 29,
// _CMP_GT_OQ
OrderedGreaterThanNonSignaling = 30,
// _CMP_TRUE_US
UnorderedTrueSignaling = 31,
};
enum class FloatRoundingMode : uint8_t
{
// _MM_FROUND_TO_NEAREST_INT
ToNearestInteger = 0x00,
// _MM_FROUND_TO_NEG_INF
ToNegativeInfinity = 0x01,
// _MM_FROUND_TO_POS_INF
ToPositiveInfinity = 0x02,
// _MM_FROUND_TO_ZERO
ToZero = 0x03,
// _MM_FROUND_CUR_DIRECTION
CurrentDirection = 0x04,
// _MM_FROUND_RAISE_EXC
RaiseException = 0x00,
// _MM_FROUND_NO_EXC
NoException = 0x08,
};
enum class IntComparisonMode : uint8_t
{
Equal = 0,
LessThan = 1,
LessThanOrEqual = 2,
False = 3,
NotEqual = 4,
GreaterThanOrEqual = 5,
GreaterThan = 6,
True = 7,
NotGreaterThanOrEqual = LessThan,
NotGreaterThan = LessThanOrEqual,
NotLessThan = GreaterThanOrEqual,
NotLessThanOrEqual = GreaterThan
};
enum class TernaryLogicUseFlags : uint8_t
{
// Indicates no flags are present
None = 0,
// Indicates the ternary logic uses A
A = 1 << 0,
// Indicates the ternary logic uses B
B = 1 << 1,
// Indicates the ternary logic uses C
C = 1 << 2,
// Indicates the ternary logic uses A and B
AB = (A | B),
// Indicates the ternary logic uses A and C
AC = (A | C),
// Indicates the ternary logic uses B and C
BC = (B | C),
// Indicates the ternary logic uses A, B, and C
ABC = (A | B | C),
};
enum class TernaryLogicOperKind : uint8_t
{
// Indicates no operation is done
None = 0,
// value
Select = 1,
// constant true (1)
True = 2,
// constant false (0)
False = 3,
// ~value
Not = 4,
// left & right
And = 5,
// ~(left & right)
Nand = 6,
// left | right
Or = 7,
// ~(left | right)
Nor = 8,
// left ^ right
Xor = 9,
// ~(left ^ right)
Xnor = 10,
// cond ? left : right
Cond = 11,
// returns 0 if two+ of the three input bits are 0; else 1
Major = 12,
// returns 0 if two+ of the three input bits are 1; else 0
Minor = 13,
};
struct TernaryLogicInfo
{
// We have 256 entries, so we compress as much as possible
// This gives us 3-bytes per entry (21-bits)
TernaryLogicOperKind oper1 : 4;
TernaryLogicUseFlags oper1Use : 3;
TernaryLogicOperKind oper2 : 4;
TernaryLogicUseFlags oper2Use : 3;
TernaryLogicOperKind oper3 : 4;
TernaryLogicUseFlags oper3Use : 3;
static const TernaryLogicInfo& lookup(uint8_t control);
TernaryLogicUseFlags GetAllUseFlags() const
{
uint8_t useFlagsBits = 0;
useFlagsBits |= static_cast<uint8_t>(oper1Use);
useFlagsBits |= static_cast<uint8_t>(oper2Use);
useFlagsBits |= static_cast<uint8_t>(oper3Use);
return static_cast<TernaryLogicUseFlags>(useFlagsBits);
}
};
#endif // TARGET_XARCH
struct HWIntrinsicInfo
{
// 32-bit: 36-bytes (34+2 trailing padding)
// 64-bit: 40-bytes (38+2 trailing padding)
const char* name; // 4 or 8-bytes
HWIntrinsicFlag flags; // 4-bytes
NamedIntrinsic id; // 2-bytes
uint16_t ins[10]; // 10 * 2-bytes
uint8_t isa; // 1-byte
int8_t simdSize; // 1-byte
int8_t numArgs; // 1-byte
HWIntrinsicCategory category; // 1-byte
static const HWIntrinsicInfo& lookup(NamedIntrinsic id);
static NamedIntrinsic lookupId(Compiler* comp,
CORINFO_SIG_INFO* sig,
const char* className,
const char* methodName,
const char* enclosingClassName);
static CORINFO_InstructionSet lookupIsa(const char* className, const char* enclosingClassName);
static unsigned lookupSimdSize(Compiler* comp, NamedIntrinsic id, CORINFO_SIG_INFO* sig);
#if defined(TARGET_XARCH)
static int lookupImmUpperBound(NamedIntrinsic intrinsic);
#elif defined(TARGET_ARM64)
static void lookupImmBounds(
NamedIntrinsic intrinsic, int simdSize, var_types baseType, int immNumber, int* lowerBound, int* upperBound);
#else
#error Unsupported platform
#endif
static bool isImmOp(NamedIntrinsic id, const GenTree* op);
static bool isFullyImplementedIsa(CORINFO_InstructionSet isa);
static bool isScalarIsa(CORINFO_InstructionSet isa);
#ifdef TARGET_XARCH
static bool isAVX2GatherIntrinsic(NamedIntrinsic id);
static FloatComparisonMode lookupFloatComparisonModeForSwappedArgs(FloatComparisonMode comparison);
#endif
// Member lookup
static NamedIntrinsic lookupId(NamedIntrinsic id)
{
return lookup(id).id;
}
static const char* lookupName(NamedIntrinsic id)
{
return lookup(id).name;
}
static CORINFO_InstructionSet lookupIsa(NamedIntrinsic id)
{
uint8_t result = lookup(id).isa;
return static_cast<CORINFO_InstructionSet>(result);
}
#if defined(TARGET_XARCH)
static int lookupIval(Compiler* comp, NamedIntrinsic id, var_types simdBaseType);
#elif defined(TARGET_ARM64)
static int lookupIval(NamedIntrinsic id);
#endif
static bool tryLookupSimdSize(NamedIntrinsic id, unsigned* pSimdSize)
{
bool succeeded = false;
if (lookup(id).simdSize != -1)
{
*pSimdSize = lookup(id).simdSize;
succeeded = true;
}
return succeeded;
}
static int lookupNumArgs(NamedIntrinsic id)
{
return lookup(id).numArgs;
}
static instruction lookupIns(NamedIntrinsic id, var_types type)
{
if ((type < TYP_BYTE) || (type > TYP_DOUBLE))
{
assert(!"Unexpected type");
return INS_invalid;
}
uint16_t result = lookup(id).ins[type - TYP_BYTE];
return static_cast<instruction>(result);
}
static instruction lookupIns(GenTreeHWIntrinsic* intrinsicNode)
{
assert(intrinsicNode != nullptr);
NamedIntrinsic intrinsic = intrinsicNode->GetHWIntrinsicId();
var_types type = TYP_UNKNOWN;
if (lookupCategory(intrinsic) == HW_Category_Scalar)
{
type = intrinsicNode->TypeGet();
}
else
{
type = intrinsicNode->GetSimdBaseType();
}
return lookupIns(intrinsic, type);
}
static HWIntrinsicCategory lookupCategory(NamedIntrinsic id)
{
return lookup(id).category;
}
static HWIntrinsicFlag lookupFlags(NamedIntrinsic id)
{
return lookup(id).flags;
}
// Flags lookup
static bool IsCommutative(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_Commutative) != 0;
}
#if defined(TARGET_XARCH)
static bool IsEmbBroadcastCompatible(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_EmbBroadcastCompatible) != 0;
}
static bool IsEmbRoundingCompatible(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_EmbRoundingCompatible) != 0;
}
static bool IsEmbMaskingCompatible(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_EmbMaskingCompatible) != 0;
}
#endif // TARGET_XARCH
static bool CanBenefitFromConstantProp(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_CanBenefitFromConstantProp) != 0;
}
static bool IsMaybeCommutative(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
#if defined(TARGET_XARCH)
return (flags & HW_Flag_MaybeCommutative) != 0;
#elif defined(TARGET_ARM64)
return false;
#else
#error Unsupported platform
#endif
}
static bool RequiresCodegen(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & (HW_Flag_NoCodeGen | HW_Flag_InvalidNodeId)) == 0;
}
static bool SupportsContainment(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
#if defined(TARGET_XARCH)
return (flags & HW_Flag_NoContainment) == 0;
#elif defined(TARGET_ARM64)
return (flags & HW_Flag_SupportsContainment) != 0;
#else
#error Unsupported platform
#endif
}
static bool ReturnsPerElementMask(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
#if defined(TARGET_XARCH) || defined(TARGET_ARM64)
return (flags & HW_Flag_ReturnsPerElementMask) != 0;
#else
#error Unsupported platform
#endif
}
#if defined(TARGET_XARCH)
static bool AvxOnlyCompatible(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_AvxOnlyCompatible) != 0;
}
#endif
static bool BaseTypeFromFirstArg(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_BaseTypeFromFirstArg) != 0;
}
static bool IsFloatingPointUsed(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_NoFloatingPointUsed) == 0;
}
#ifdef TARGET_XARCH
static bool HasFullRangeImm(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_FullRangeIMM) != 0;
}
static bool MaybeImm(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_MaybeIMM) != 0;
}
static bool CopiesUpperBits(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_CopyUpperBits) != 0;
}
static bool MaybeMemoryLoad(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_MaybeMemoryLoad) != 0;
}
static bool MaybeMemoryStore(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_MaybeMemoryStore) != 0;
}
#endif
static bool NoJmpTableImm(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_NoJmpTableIMM) != 0;
}
static bool BaseTypeFromSecondArg(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_BaseTypeFromSecondArg) != 0;
}
static bool HasSpecialCodegen(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_SpecialCodeGen) != 0;
}
#ifdef TARGET_ARM64
static bool NeedsConsecutiveRegisters(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_NeedsConsecutiveRegisters) != 0;
}
#endif
static bool HasRMWSemantics(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
#if defined(TARGET_XARCH)
return (flags & HW_Flag_NoRMWSemantics) == 0;
#elif defined(TARGET_ARM64)
return (flags & HW_Flag_HasRMWSemantics) != 0;
#else
#error Unsupported platform
#endif
}
//------------------------------------------------------------------------
// HasEvexSemantics: Checks if the NamedIntrinsic has a lowering to
// to an instruction with an EVEX form.
//
// Return Value:
// true if the NamedIntrinsic lowering has an EVEX form.
//
static bool HasEvexSemantics(NamedIntrinsic id)
{
#if defined(TARGET_XARCH)
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_NoEvexSemantics) == 0;
#else
return false;
#endif
}
static bool HasSpecialImport(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & (HW_Flag_SpecialImport | HW_Flag_InvalidNodeId)) != 0;
}
static bool IsInvalidNodeId(NamedIntrinsic id)
{
HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_InvalidNodeId) != 0;
}
static bool IsMultiReg(NamedIntrinsic id)
{
const HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_MultiReg) != 0;
}
static int GetMultiRegCount(NamedIntrinsic id)
{
assert(IsMultiReg(id));
switch (id)
{
#ifdef TARGET_ARM64
case NI_AdvSimd_Arm64_LoadPairScalarVector64:
case NI_AdvSimd_Arm64_LoadPairScalarVector64NonTemporal:
case NI_AdvSimd_Arm64_LoadPairVector64:
case NI_AdvSimd_Arm64_LoadPairVector64NonTemporal:
case NI_AdvSimd_Arm64_LoadPairVector128:
case NI_AdvSimd_Arm64_LoadPairVector128NonTemporal:
case NI_AdvSimd_Load2xVector64AndUnzip:
case NI_AdvSimd_Arm64_Load2xVector128AndUnzip:
case NI_AdvSimd_Load2xVector64:
case NI_AdvSimd_Arm64_Load2xVector128:
case NI_AdvSimd_LoadAndInsertScalarVector64x2:
case NI_AdvSimd_Arm64_LoadAndInsertScalarVector128x2:
case NI_AdvSimd_LoadAndReplicateToVector64x2:
case NI_AdvSimd_Arm64_LoadAndReplicateToVector128x2:
case NI_Sve_Load2xVectorAndUnzip:
return 2;
case NI_AdvSimd_Load3xVector64AndUnzip:
case NI_AdvSimd_Arm64_Load3xVector128AndUnzip:
case NI_AdvSimd_Load3xVector64:
case NI_AdvSimd_Arm64_Load3xVector128:
case NI_AdvSimd_LoadAndInsertScalarVector64x3:
case NI_AdvSimd_Arm64_LoadAndInsertScalarVector128x3:
case NI_AdvSimd_LoadAndReplicateToVector64x3:
case NI_AdvSimd_Arm64_LoadAndReplicateToVector128x3:
case NI_Sve_Load3xVectorAndUnzip:
return 3;
case NI_AdvSimd_Load4xVector64AndUnzip:
case NI_AdvSimd_Arm64_Load4xVector128AndUnzip:
case NI_AdvSimd_Load4xVector64:
case NI_AdvSimd_Arm64_Load4xVector128:
case NI_AdvSimd_LoadAndInsertScalarVector64x4:
case NI_AdvSimd_Arm64_LoadAndInsertScalarVector128x4:
case NI_AdvSimd_LoadAndReplicateToVector64x4:
case NI_AdvSimd_Arm64_LoadAndReplicateToVector128x4:
case NI_Sve_Load4xVectorAndUnzip:
return 4;
#endif
#ifdef TARGET_XARCH
case NI_X86Base_DivRem:
case NI_X86Base_X64_DivRem:
return 2;
#endif // TARGET_XARCH
default:
unreached();
}
}
static bool HasImmediateOperand(NamedIntrinsic id)
{
#if defined(TARGET_ARM64)
const HWIntrinsicFlag flags = lookupFlags(id);
return ((flags & HW_Flag_HasImmediateOperand) != 0) || HasEnumOperand(id);
#elif defined(TARGET_XARCH)
return lookupCategory(id) == HW_Category_IMM;
#else
return false;
#endif
}
#ifdef TARGET_ARM64
static bool SIMDScalar(NamedIntrinsic id)
{
const HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_SIMDScalar) != 0;
}
static bool IsScalable(NamedIntrinsic id)
{
const HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_Scalable) != 0;
}
static bool IsMaskedOperation(NamedIntrinsic id)
{
const HWIntrinsicFlag flags = lookupFlags(id);
return IsLowMaskedOperation(id) || IsOptionalEmbeddedMaskedOperation(id) || IsExplicitMaskedOperation(id);
}
static bool IsLowMaskedOperation(NamedIntrinsic id)
{
const HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_LowMaskedOperation) != 0;
}
static bool IsLowVectorOperation(NamedIntrinsic id)
{
const HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_LowVectorOperation) != 0;
}
static bool IsOptionalEmbeddedMaskedOperation(NamedIntrinsic id)
{
const HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_OptionalEmbeddedMaskedOperation) != 0;
}
static bool IsEmbeddedMaskedOperation(NamedIntrinsic id)
{
const HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_EmbeddedMaskedOperation) != 0;
}
static bool IsExplicitMaskedOperation(NamedIntrinsic id)
{
const HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_ExplicitMaskedOperation) != 0;
}
// Checks if the intrinsic has an embedded mask operation and the intrinsic returns a scalar.
static bool IsEmbeddedMaskForScalarResult(NamedIntrinsic id)
{
if (IsEmbeddedMaskedOperation(id))
{
switch (id)
{
case NI_Sve_ExtractAfterLastScalar:
case NI_Sve_ExtractLastScalar:
return true;
default:
break;
}
}
return false;
}
static bool HasEnumOperand(NamedIntrinsic id)
{
const HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_HasEnumOperand) != 0;
}
static bool HasScalarInputVariant(NamedIntrinsic id)
{
const HWIntrinsicFlag flags = lookupFlags(id);
return (flags & HW_Flag_HasScalarInputVariant) != 0;
}
static NamedIntrinsic GetScalarInputVariant(NamedIntrinsic id)
{
assert(HasScalarInputVariant(id));
switch (id)
{
case NI_Sve_SaturatingDecrementBy16BitElementCount:
return NI_Sve_SaturatingDecrementBy16BitElementCountScalar;
case NI_Sve_SaturatingDecrementBy32BitElementCount:
return NI_Sve_SaturatingDecrementBy32BitElementCountScalar;
case NI_Sve_SaturatingDecrementBy64BitElementCount:
return NI_Sve_SaturatingDecrementBy64BitElementCountScalar;
case NI_Sve_SaturatingIncrementBy16BitElementCount:
return NI_Sve_SaturatingIncrementBy16BitElementCountScalar;
case NI_Sve_SaturatingIncrementBy32BitElementCount:
return NI_Sve_SaturatingIncrementBy32BitElementCountScalar;
case NI_Sve_SaturatingIncrementBy64BitElementCount:
return NI_Sve_SaturatingIncrementBy64BitElementCountScalar;
default:
unreached();
}
}
#endif // TARGET_ARM64
static bool HasSpecialSideEffect(NamedIntrinsic id)
{