-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathsimd.h
1690 lines (1425 loc) · 38.6 KB
/
simd.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 _SIMD_H_
#define _SIMD_H_
template <typename T>
static bool ElementsAreSame(T* array, size_t size)
{
for (size_t i = 1; i < size; i++)
{
if (array[0] != array[i])
return false;
}
return true;
}
template <typename T>
static bool ElementsAreAllBitsSetOrZero(T* array, size_t size)
{
for (size_t i = 0; i < size; i++)
{
if (array[i] != static_cast<T>(0) && array[i] != static_cast<T>(~0))
return false;
}
return true;
}
struct simd8_t
{
union
{
float f32[2];
double f64[1];
int8_t i8[8];
int16_t i16[4];
int32_t i32[2];
int64_t i64[1];
uint8_t u8[8];
uint16_t u16[4];
uint32_t u32[2];
uint64_t u64[1];
};
bool operator==(const simd8_t& other) const
{
return (u64[0] == other.u64[0]);
}
bool operator!=(const simd8_t& other) const
{
return !(*this == other);
}
static simd8_t AllBitsSet()
{
simd8_t result;
result.u64[0] = 0xFFFFFFFFFFFFFFFF;
return result;
}
bool IsAllBitsSet() const
{
return *this == AllBitsSet();
}
bool IsZero() const
{
return *this == Zero();
}
static simd8_t Zero()
{
return {};
}
};
static_assert_no_msg(sizeof(simd8_t) == 8);
#include <pshpack4.h>
struct simd12_t
{
union
{
float f32[3];
int8_t i8[12];
int16_t i16[6];
int32_t i32[3];
uint8_t u8[12];
uint16_t u16[6];
uint32_t u32[3];
// These three exist to simplify templatized code
// they won't actually be accessed for real scenarios
double f64[1];
int64_t i64[1];
uint64_t u64[1];
};
bool operator==(const simd12_t& other) const
{
return (u32[0] == other.u32[0]) && (u32[1] == other.u32[1]) && (u32[2] == other.u32[2]);
}
bool operator!=(const simd12_t& other) const
{
return !(*this == other);
}
static simd12_t AllBitsSet()
{
simd12_t result;
result.u32[0] = 0xFFFFFFFF;
result.u32[1] = 0xFFFFFFFF;
result.u32[2] = 0xFFFFFFFF;
return result;
}
bool IsAllBitsSet() const
{
return *this == AllBitsSet();
}
bool IsZero() const
{
return *this == Zero();
}
static simd12_t Zero()
{
return {};
}
};
#include <poppack.h>
static_assert_no_msg(sizeof(simd12_t) == 12);
struct simd16_t
{
union
{
float f32[4];
double f64[2];
int8_t i8[16];
int16_t i16[8];
int32_t i32[4];
int64_t i64[2];
uint8_t u8[16];
uint16_t u16[8];
uint32_t u32[4];
uint64_t u64[2];
simd8_t v64[2];
};
bool operator==(const simd16_t& other) const
{
return (v64[0] == other.v64[0]) && (v64[1] == other.v64[1]);
}
bool operator!=(const simd16_t& other) const
{
return !(*this == other);
}
static simd16_t AllBitsSet()
{
simd16_t result;
result.v64[0] = simd8_t::AllBitsSet();
result.v64[1] = simd8_t::AllBitsSet();
return result;
}
bool IsAllBitsSet() const
{
return *this == AllBitsSet();
}
bool IsZero() const
{
return *this == Zero();
}
static simd16_t Zero()
{
return {};
}
};
static_assert_no_msg(sizeof(simd16_t) == 16);
#if defined(TARGET_XARCH)
struct simd32_t
{
union
{
float f32[8];
double f64[4];
int8_t i8[32];
int16_t i16[16];
int32_t i32[8];
int64_t i64[4];
uint8_t u8[32];
uint16_t u16[16];
uint32_t u32[8];
uint64_t u64[4];
simd8_t v64[4];
simd16_t v128[2];
};
bool operator==(const simd32_t& other) const
{
return (v128[0] == other.v128[0]) && (v128[1] == other.v128[1]);
}
bool operator!=(const simd32_t& other) const
{
return !(*this == other);
}
static simd32_t AllBitsSet()
{
simd32_t result;
result.v128[0] = simd16_t::AllBitsSet();
result.v128[1] = simd16_t::AllBitsSet();
return result;
}
bool IsAllBitsSet() const
{
return *this == AllBitsSet();
}
bool IsZero() const
{
return *this == Zero();
}
static simd32_t Zero()
{
return {};
}
};
static_assert_no_msg(sizeof(simd32_t) == 32);
struct simd64_t
{
union
{
float f32[16];
double f64[8];
int8_t i8[64];
int16_t i16[32];
int32_t i32[16];
int64_t i64[8];
uint8_t u8[64];
uint16_t u16[32];
uint32_t u32[16];
uint64_t u64[8];
simd8_t v64[8];
simd16_t v128[4];
simd32_t v256[2];
};
bool operator==(const simd64_t& other) const
{
return (v256[0] == other.v256[0]) && (v256[1] == other.v256[1]);
}
bool operator!=(const simd64_t& other) const
{
return !(*this == other);
}
static simd64_t AllBitsSet()
{
simd64_t result;
result.v256[0] = simd32_t::AllBitsSet();
result.v256[1] = simd32_t::AllBitsSet();
return result;
}
bool IsAllBitsSet() const
{
return *this == AllBitsSet();
}
bool IsZero() const
{
return *this == Zero();
}
static simd64_t Zero()
{
return {};
}
};
static_assert_no_msg(sizeof(simd64_t) == 64);
#endif // TARGET_XARCH
#if defined(FEATURE_MASKED_HW_INTRINSICS)
struct simdmask_t
{
union
{
int8_t i8[8];
int16_t i16[4];
int32_t i32[2];
int64_t i64[1];
uint8_t u8[8];
uint16_t u16[4];
uint32_t u32[2];
uint64_t u64[1];
};
bool operator==(const simdmask_t& other) const
{
return (u64[0] == other.u64[0]);
}
bool operator!=(const simdmask_t& other) const
{
return !(*this == other);
}
static simdmask_t AllBitsSet()
{
simdmask_t result;
result.u64[0] = 0xFFFFFFFFFFFFFFFF;
return result;
}
bool IsAllBitsSet() const
{
return *this == AllBitsSet();
}
bool IsZero() const
{
return *this == Zero();
}
static simdmask_t Zero()
{
return {};
}
};
static_assert_no_msg(sizeof(simdmask_t) == 8);
#endif // FEATURE_MASKED_HW_INTRINSICS
#if defined(TARGET_XARCH)
typedef simd64_t simd_t;
#else
typedef simd16_t simd_t;
#endif
inline bool IsUnaryBitwiseOperation(genTreeOps oper)
{
return (oper == GT_LZCNT) || (oper == GT_NOT);
}
template <typename TBase>
TBase EvaluateUnaryScalarSpecialized(genTreeOps oper, TBase arg0)
{
switch (oper)
{
case GT_NEG:
{
return static_cast<TBase>(0) - arg0;
}
case GT_NOT:
{
return ~arg0;
}
case GT_LZCNT:
{
if (sizeof(TBase) == sizeof(uint32_t))
{
uint32_t result = BitOperations::LeadingZeroCount(static_cast<uint32_t>(arg0));
return static_cast<TBase>(result);
}
else if (sizeof(TBase) == sizeof(uint64_t))
{
uint64_t result = BitOperations::LeadingZeroCount(static_cast<uint64_t>(arg0));
return static_cast<TBase>(result);
}
unreached();
}
default:
{
unreached();
}
}
}
template <>
inline float EvaluateUnaryScalarSpecialized<float>(genTreeOps oper, float arg0)
{
switch (oper)
{
case GT_NEG:
{
return -arg0;
}
default:
{
unreached();
}
}
}
template <>
inline double EvaluateUnaryScalarSpecialized<double>(genTreeOps oper, double arg0)
{
switch (oper)
{
case GT_NEG:
{
return -arg0;
}
default:
{
unreached();
}
}
}
template <typename TBase>
TBase EvaluateUnaryScalar(genTreeOps oper, TBase arg0)
{
return EvaluateUnaryScalarSpecialized<TBase>(oper, arg0);
}
#if defined(FEATURE_MASKED_HW_INTRINSICS)
template <typename TBase>
void EvaluateUnaryMask(genTreeOps oper, bool scalar, unsigned simdSize, simdmask_t* result, const simdmask_t& arg0)
{
uint32_t count = simdSize / sizeof(TBase);
#if defined(TARGET_XARCH)
// For xarch we have count sequential bits, but an 8 count minimum
if (count < 8)
{
count = 8;
}
assert((count == 8) || (count == 16) || (count == 32) || (count == 64));
uint64_t bitMask = static_cast<uint64_t>((static_cast<int64_t>(1) << count) - 1);
#elif defined(TARGET_ARM64)
// For Arm64 we have count total bits to write, but they are sizeof(TBase) bits apart
uint64_t bitMask;
switch (sizeof(TBase))
{
case 1:
{
bitMask = 0xFFFFFFFFFFFFFFFF;
break;
}
case 2:
{
bitMask = 0x5555555555555555;
break;
}
case 4:
{
bitMask = 0x1111111111111111;
break;
}
case 8:
{
bitMask = 0x0101010101010101;
break;
}
default:
{
unreached();
}
}
#else
#error Unsupported platform
#endif
uint64_t arg0Value;
memcpy(&arg0Value, &arg0.u64[0], sizeof(simdmask_t));
// We're only considering these bits
arg0Value &= bitMask;
uint64_t resultValue = 0;
switch (oper)
{
case GT_NOT:
{
resultValue = ~arg0Value;
break;
}
default:
{
unreached();
}
}
resultValue &= bitMask;
if (resultValue == bitMask)
{
// Output is equivalent to AllBitsSet, so normalize
memset(&resultValue, 0xFF, sizeof(uint64_t));
}
memcpy(&result->u64[0], &resultValue, sizeof(uint64_t));
}
inline void EvaluateUnaryMask(
genTreeOps oper, bool scalar, var_types baseType, unsigned simdSize, simdmask_t* result, const simdmask_t& arg0)
{
switch (baseType)
{
case TYP_FLOAT:
case TYP_INT:
case TYP_UINT:
{
EvaluateUnaryMask<uint32_t>(oper, scalar, simdSize, result, arg0);
break;
}
case TYP_DOUBLE:
case TYP_LONG:
case TYP_ULONG:
{
EvaluateUnaryMask<uint64_t>(oper, scalar, simdSize, result, arg0);
break;
}
case TYP_BYTE:
case TYP_UBYTE:
{
EvaluateUnaryMask<uint8_t>(oper, scalar, simdSize, result, arg0);
break;
}
case TYP_SHORT:
case TYP_USHORT:
{
EvaluateUnaryMask<uint16_t>(oper, scalar, simdSize, result, arg0);
break;
}
default:
{
unreached();
}
}
}
#endif // FEATURE_MASKED_HW_INTRINSICS
template <typename TSimd, typename TBase>
void EvaluateUnarySimd(genTreeOps oper, bool scalar, TSimd* result, const TSimd& arg0)
{
uint32_t count = sizeof(TSimd) / sizeof(TBase);
if (scalar)
{
count = 1;
#if defined(TARGET_XARCH)
// scalar operations on xarch copy the upper bits from arg0
*result = arg0;
#elif defined(TARGET_ARM64)
// scalar operations on arm64 zero the upper bits
*result = {};
#endif
}
for (uint32_t i = 0; i < count; i++)
{
// Safely execute `result[i] = oper(arg0[i])`
TBase input0;
memcpy(&input0, &arg0.u8[i * sizeof(TBase)], sizeof(TBase));
TBase output = EvaluateUnaryScalar<TBase>(oper, input0);
memcpy(&result->u8[i * sizeof(TBase)], &output, sizeof(TBase));
}
}
template <typename TSimd>
void EvaluateUnarySimd(genTreeOps oper, bool scalar, var_types baseType, TSimd* result, const TSimd& arg0)
{
switch (baseType)
{
case TYP_FLOAT:
{
// Some operations are bitwise and we want to ensure inputs like
// sNaN are preserved rather than being converted to a qNaN when
// the CPU encounters them. So we check for and handle that early
// prior to extracting the element out of the vector value.
if (IsUnaryBitwiseOperation(oper))
{
EvaluateUnarySimd<TSimd, int32_t>(oper, scalar, result, arg0);
}
else
{
EvaluateUnarySimd<TSimd, float>(oper, scalar, result, arg0);
}
break;
}
case TYP_DOUBLE:
{
// Some operations are bitwise and we want to ensure inputs like
// sNaN are preserved rather than being converted to a qNaN when
// the CPU encounters them. So we check for and handle that early
// prior to extracting the element out of the vector value.
if (IsUnaryBitwiseOperation(oper))
{
EvaluateUnarySimd<TSimd, int64_t>(oper, scalar, result, arg0);
}
else
{
EvaluateUnarySimd<TSimd, double>(oper, scalar, result, arg0);
}
break;
}
case TYP_BYTE:
{
EvaluateUnarySimd<TSimd, int8_t>(oper, scalar, result, arg0);
break;
}
case TYP_SHORT:
{
EvaluateUnarySimd<TSimd, int16_t>(oper, scalar, result, arg0);
break;
}
case TYP_INT:
{
EvaluateUnarySimd<TSimd, int32_t>(oper, scalar, result, arg0);
break;
}
case TYP_LONG:
{
EvaluateUnarySimd<TSimd, int64_t>(oper, scalar, result, arg0);
break;
}
case TYP_UBYTE:
{
EvaluateUnarySimd<TSimd, uint8_t>(oper, scalar, result, arg0);
break;
}
case TYP_USHORT:
{
EvaluateUnarySimd<TSimd, uint16_t>(oper, scalar, result, arg0);
break;
}
case TYP_UINT:
{
EvaluateUnarySimd<TSimd, uint32_t>(oper, scalar, result, arg0);
break;
}
case TYP_ULONG:
{
EvaluateUnarySimd<TSimd, uint64_t>(oper, scalar, result, arg0);
break;
}
default:
{
unreached();
}
}
}
inline bool IsBinaryBitwiseOperation(genTreeOps oper)
{
return (oper == GT_AND) || (oper == GT_AND_NOT) || (oper == GT_LSH) || (oper == GT_OR) || (oper == GT_OR_NOT) ||
(oper == GT_ROL) || (oper == GT_ROR) || (oper == GT_RSH) || (oper == GT_RSZ) || (oper == GT_XOR) ||
(oper == GT_XOR_NOT);
}
template <typename TBase>
TBase EvaluateBinaryScalarRSZ(TBase arg0, TBase arg1)
{
#if defined(TARGET_XARCH) || defined(TARGET_ARM64)
if ((arg1 < 0) || (arg1 >= (sizeof(TBase) * 8)))
{
// For SIMD, xarch and ARM64 allow overshifting and treat
// it as zeroing. So ensure we do the same here.
//
// The xplat APIs ensure the shiftAmount is masked
// to be within range, so we can't hit this for them.
return static_cast<TBase>(0);
}
#else
// Other platforms enforce masking in their encoding
unsigned shiftCountMask = (sizeof(TBase) * 8) - 1;
arg1 &= shiftCountMask;
#endif
return arg0 >> arg1;
}
template <>
inline int8_t EvaluateBinaryScalarRSZ<int8_t>(int8_t arg0, int8_t arg1)
{
uint8_t arg0Bits = static_cast<uint8_t>(arg0);
uint8_t arg1Bits = static_cast<uint8_t>(arg1);
uint8_t resultBits = EvaluateBinaryScalarRSZ<uint8_t>(arg0Bits, arg1Bits);
return static_cast<int8_t>(resultBits);
}
template <>
inline int16_t EvaluateBinaryScalarRSZ<int16_t>(int16_t arg0, int16_t arg1)
{
uint16_t arg0Bits = static_cast<uint16_t>(arg0);
uint16_t arg1Bits = static_cast<uint16_t>(arg1);
uint16_t resultBits = EvaluateBinaryScalarRSZ<uint16_t>(arg0Bits, arg1Bits);
return static_cast<int16_t>(resultBits);
}
template <>
inline int32_t EvaluateBinaryScalarRSZ<int32_t>(int32_t arg0, int32_t arg1)
{
uint32_t arg0Bits = static_cast<uint32_t>(arg0);
uint32_t arg1Bits = static_cast<uint32_t>(arg1);
uint32_t resultBits = EvaluateBinaryScalarRSZ<uint32_t>(arg0Bits, arg1Bits);
return static_cast<int32_t>(resultBits);
}
template <>
inline int64_t EvaluateBinaryScalarRSZ<int64_t>(int64_t arg0, int64_t arg1)
{
uint64_t arg0Bits = static_cast<uint64_t>(arg0);
uint64_t arg1Bits = static_cast<uint64_t>(arg1);
uint64_t resultBits = EvaluateBinaryScalarRSZ<uint64_t>(arg0Bits, arg1Bits);
return static_cast<int64_t>(resultBits);
}
template <typename TBase>
TBase EvaluateBinaryScalarSpecialized(genTreeOps oper, TBase arg0, TBase arg1)
{
switch (oper)
{
case GT_AND:
{
return arg0 & arg1;
}
case GT_AND_NOT:
{
return arg0 & ~arg1;
}
case GT_EQ:
{
return (arg0 == arg1) ? static_cast<TBase>(~0) : static_cast<TBase>(0);
}
case GT_GT:
{
return (arg0 > arg1) ? static_cast<TBase>(~0) : static_cast<TBase>(0);
}
case GT_GE:
{
return (arg0 >= arg1) ? static_cast<TBase>(~0) : static_cast<TBase>(0);
}
case GT_LSH:
{
#if defined(TARGET_XARCH) || defined(TARGET_ARM64)
if ((arg1 < 0) || (arg1 >= (sizeof(TBase) * 8)))
{
// For SIMD, xarch and ARM64 allow overshifting and treat
// it as zeroing. So ensure we do the same here.
//
// The xplat APIs ensure the shiftAmount is masked
// to be within range, so we can't hit this for them.
return static_cast<TBase>(0);
}
#else
// Other platforms enforce masking in their encoding
unsigned shiftCountMask = (sizeof(TBase) * 8) - 1;
arg1 &= shiftCountMask;
#endif
return arg0 << arg1;
}
case GT_LT:
{
return (arg0 < arg1) ? static_cast<TBase>(~0) : static_cast<TBase>(0);
}
case GT_LE:
{
return (arg0 <= arg1) ? static_cast<TBase>(~0) : static_cast<TBase>(0);
}
case GT_NE:
{
return (arg0 != arg1) ? static_cast<TBase>(~0) : static_cast<TBase>(0);
}
case GT_OR:
{
return arg0 | arg1;
}
case GT_OR_NOT:
{
return arg0 | ~arg1;
}
case GT_ROL:
{
// Normalize the "rotate by" value
// EvaluateBinaryScalarRSZ allows overshifting and treats
// it as zeroing.
// But ROL ensures the rotateAmount is masked
// to be within range, so we pre-calculates this.
unsigned rotateCountMask = (sizeof(TBase) * BITS_PER_BYTE) - 1;
arg1 &= rotateCountMask;
return EvaluateBinaryScalarSpecialized<TBase>(GT_LSH, arg0, arg1) |
EvaluateBinaryScalarRSZ<TBase>(arg0, (sizeof(TBase) * BITS_PER_BYTE) - arg1);
}
case GT_ROR:
{
// Normalize the "rotate by" value
// EvaluateBinaryScalarRSZ allows overshifting and treats
// it as zeroing.
// But ROR ensures the rotateAmount is masked
// to be within range, so we pre-calculates this.
unsigned rotateCountMask = (sizeof(TBase) * BITS_PER_BYTE) - 1;
arg1 &= rotateCountMask;
return EvaluateBinaryScalarRSZ<TBase>(arg0, arg1) |
EvaluateBinaryScalarSpecialized<TBase>(GT_LSH, arg0, (sizeof(TBase) * BITS_PER_BYTE) - arg1);
}
case GT_RSH:
{
#if defined(TARGET_XARCH) || defined(TARGET_ARM64)
if ((arg1 < 0) || (arg1 >= (sizeof(TBase) * 8)))
{
// For SIMD, xarch and ARM64 allow overshifting and treat
// it as propagating the sign bit (returning Zero
// or AllBitsSet). So ensure we do the same here.
//
// The xplat APIs ensure the shiftAmount is masked
// to be within range, so we can't hit this for them.
arg0 >>= ((sizeof(TBase) * 8) - 1);
arg1 = static_cast<TBase>(1);
}
#else
// Other platforms enforce masking in their encoding
unsigned shiftCountMask = (sizeof(TBase) * 8) - 1;
arg1 &= shiftCountMask;
#endif
return arg0 >> arg1;
}
case GT_RSZ:
{
return EvaluateBinaryScalarRSZ<TBase>(arg0, arg1);
}
case GT_XOR:
{
return arg0 ^ arg1;
}
case GT_XOR_NOT:
{
return arg0 ^ ~arg1;
}
default:
{
unreached();
}
}
}
template <>
inline float EvaluateBinaryScalarSpecialized<float>(genTreeOps oper, float arg0, float arg1)
{
switch (oper)
{
case GT_EQ:
{
return (arg0 == arg1) ? BitOperations::UInt32BitsToSingle(0xFFFFFFFF) : 0;
}
case GT_GT:
{
return (arg0 > arg1) ? BitOperations::UInt32BitsToSingle(0xFFFFFFFF) : 0;
}
case GT_GE:
{
return (arg0 >= arg1) ? BitOperations::UInt32BitsToSingle(0xFFFFFFFF) : 0;
}
case GT_LT:
{
return (arg0 < arg1) ? BitOperations::UInt32BitsToSingle(0xFFFFFFFF) : 0;
}
case GT_LE:
{
return (arg0 <= arg1) ? BitOperations::UInt32BitsToSingle(0xFFFFFFFF) : 0;
}
case GT_NE:
{
return (arg0 != arg1) ? BitOperations::UInt32BitsToSingle(0xFFFFFFFF) : 0;
}
default:
{
unreached();
}
}
}
template <>
inline double EvaluateBinaryScalarSpecialized<double>(genTreeOps oper, double arg0, double arg1)
{
switch (oper)
{
case GT_EQ:
{
return (arg0 == arg1) ? BitOperations::UInt64BitsToDouble(0xFFFFFFFFFFFFFFFF) : 0;
}
case GT_GT:
{
return (arg0 > arg1) ? BitOperations::UInt64BitsToDouble(0xFFFFFFFFFFFFFFFF) : 0;
}
case GT_GE:
{
return (arg0 >= arg1) ? BitOperations::UInt64BitsToDouble(0xFFFFFFFFFFFFFFFF) : 0;
}
case GT_LT:
{
return (arg0 < arg1) ? BitOperations::UInt64BitsToDouble(0xFFFFFFFFFFFFFFFF) : 0;
}
case GT_LE:
{
return (arg0 <= arg1) ? BitOperations::UInt64BitsToDouble(0xFFFFFFFFFFFFFFFF) : 0;
}
case GT_NE:
{
return (arg0 != arg1) ? BitOperations::UInt64BitsToDouble(0xFFFFFFFFFFFFFFFF) : 0;
}
default:
{