Skip to content

Commit fbe82b9

Browse files
committed
Reduce the amount of copying required to evaluated vector constants
1 parent 1cca48e commit fbe82b9

File tree

5 files changed

+127
-259
lines changed

5 files changed

+127
-259
lines changed

src/coreclr/jit/gentree.cpp

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18377,42 +18377,32 @@ void GenTreeVecCon::EvaluateUnaryInPlace(genTreeOps oper, bool scalar, var_types
1837718377
{
1837818378
case TYP_SIMD8:
1837918379
{
18380-
simd8_t result = {};
18381-
EvaluateUnarySimd<simd8_t>(oper, scalar, baseType, &result, gtSimd8Val);
18382-
gtSimd8Val = result;
18380+
EvaluateUnarySimd<simd8_t>(oper, scalar, baseType, &gtSimd8Val, gtSimd8Val);
1838318381
break;
1838418382
}
1838518383

1838618384
case TYP_SIMD12:
1838718385
{
18388-
simd12_t result = {};
18389-
EvaluateUnarySimd<simd12_t>(oper, scalar, baseType, &result, gtSimd12Val);
18390-
gtSimd12Val = result;
18386+
EvaluateUnarySimd<simd12_t>(oper, scalar, baseType, &gtSimd12Val, gtSimd12Val);
1839118387
break;
1839218388
}
1839318389

1839418390
case TYP_SIMD16:
1839518391
{
18396-
simd16_t result = {};
18397-
EvaluateUnarySimd<simd16_t>(oper, scalar, baseType, &result, gtSimd16Val);
18398-
gtSimd16Val = result;
18392+
EvaluateUnarySimd<simd16_t>(oper, scalar, baseType, &gtSimd16Val, gtSimd16Val);
1839918393
break;
1840018394
}
1840118395

1840218396
#if defined(TARGET_XARCH)
1840318397
case TYP_SIMD32:
1840418398
{
18405-
simd32_t result = {};
18406-
EvaluateUnarySimd<simd32_t>(oper, scalar, baseType, &result, gtSimd32Val);
18407-
gtSimd32Val = result;
18399+
EvaluateUnarySimd<simd32_t>(oper, scalar, baseType, &gtSimd32Val, gtSimd32Val);
1840818400
break;
1840918401
}
1841018402

1841118403
case TYP_SIMD64:
1841218404
{
18413-
simd64_t result = {};
18414-
EvaluateUnarySimd<simd64_t>(oper, scalar, baseType, &result, gtSimd64Val);
18415-
gtSimd64Val = result;
18405+
EvaluateUnarySimd<simd64_t>(oper, scalar, baseType, &gtSimd64Val, gtSimd64Val);
1841618406
break;
1841718407
}
1841818408
#endif // TARGET_XARCH
@@ -18441,42 +18431,32 @@ void GenTreeVecCon::EvaluateBinaryInPlace(
1844118431
{
1844218432
case TYP_SIMD8:
1844318433
{
18444-
simd8_t result = {};
18445-
EvaluateBinarySimd<simd8_t>(oper, scalar, baseType, &result, gtSimd8Val, other->gtSimd8Val);
18446-
gtSimd8Val = result;
18434+
EvaluateBinarySimd<simd8_t>(oper, scalar, baseType, &gtSimd8Val, gtSimd8Val, other->gtSimd8Val);
1844718435
break;
1844818436
}
1844918437

1845018438
case TYP_SIMD12:
1845118439
{
18452-
simd12_t result = {};
18453-
EvaluateBinarySimd<simd12_t>(oper, scalar, baseType, &result, gtSimd12Val, other->gtSimd12Val);
18454-
gtSimd12Val = result;
18440+
EvaluateBinarySimd<simd12_t>(oper, scalar, baseType, &gtSimd12Val, gtSimd12Val, other->gtSimd12Val);
1845518441
break;
1845618442
}
1845718443

1845818444
case TYP_SIMD16:
1845918445
{
18460-
simd16_t result = {};
18461-
EvaluateBinarySimd<simd16_t>(oper, scalar, baseType, &result, gtSimd16Val, other->gtSimd16Val);
18462-
gtSimd16Val = result;
18446+
EvaluateBinarySimd<simd16_t>(oper, scalar, baseType, &gtSimd16Val, gtSimd16Val, other->gtSimd16Val);
1846318447
break;
1846418448
}
1846518449

1846618450
#if defined(TARGET_XARCH)
1846718451
case TYP_SIMD32:
1846818452
{
18469-
simd32_t result = {};
18470-
EvaluateBinarySimd<simd32_t>(oper, scalar, baseType, &result, gtSimd32Val, other->gtSimd32Val);
18471-
gtSimd32Val = result;
18453+
EvaluateBinarySimd<simd32_t>(oper, scalar, baseType, &gtSimd32Val, gtSimd32Val, other->gtSimd32Val);
1847218454
break;
1847318455
}
1847418456

1847518457
case TYP_SIMD64:
1847618458
{
18477-
simd64_t result = {};
18478-
EvaluateBinarySimd<simd64_t>(oper, scalar, baseType, &result, gtSimd64Val, other->gtSimd64Val);
18479-
gtSimd64Val = result;
18459+
EvaluateBinarySimd<simd64_t>(oper, scalar, baseType, &gtSimd64Val, gtSimd64Val, other->gtSimd64Val);
1848018460
break;
1848118461
}
1848218462
#endif // TARGET_XARCH

src/coreclr/jit/gentree.h

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6889,42 +6889,32 @@ struct GenTreeVecCon : public GenTree
68896889
#if defined(FEATURE_SIMD)
68906890
case TYP_SIMD8:
68916891
{
6892-
simd8_t result = {};
6893-
BroadcastConstantToSimd<simd8_t, TBase>(&result, scalar);
6894-
gtSimd8Val = result;
6892+
BroadcastConstantToSimd<simd8_t, TBase>(&gtSimd8Val, scalar);
68956893
break;
68966894
}
68976895

68986896
case TYP_SIMD12:
68996897
{
6900-
simd12_t result = {};
6901-
BroadcastConstantToSimd<simd12_t, TBase>(&result, scalar);
6902-
gtSimd12Val = result;
6898+
BroadcastConstantToSimd<simd12_t, TBase>(&gtSimd12Val, scalar);
69036899
break;
69046900
}
69056901

69066902
case TYP_SIMD16:
69076903
{
6908-
simd16_t result = {};
6909-
BroadcastConstantToSimd<simd16_t, TBase>(&result, scalar);
6910-
gtSimd16Val = result;
6904+
BroadcastConstantToSimd<simd16_t, TBase>(&gtSimd16Val, scalar);
69116905
break;
69126906
}
69136907

69146908
#if defined(TARGET_XARCH)
69156909
case TYP_SIMD32:
69166910
{
6917-
simd32_t result = {};
6918-
BroadcastConstantToSimd<simd32_t, TBase>(&result, scalar);
6919-
gtSimd32Val = result;
6911+
BroadcastConstantToSimd<simd32_t, TBase>(&gtSimd32Val, scalar);
69206912
break;
69216913
}
69226914

69236915
case TYP_SIMD64:
69246916
{
6925-
simd64_t result = {};
6926-
BroadcastConstantToSimd<simd64_t, TBase>(&result, scalar);
6927-
gtSimd64Val = result;
6917+
BroadcastConstantToSimd<simd64_t, TBase>(&gtSimd64Val, scalar);
69286918
break;
69296919
}
69306920
#endif // TARGET_XARCH
@@ -6947,42 +6937,32 @@ struct GenTreeVecCon : public GenTree
69476937
#if defined(FEATURE_SIMD)
69486938
case TYP_SIMD8:
69496939
{
6950-
simd8_t result = {};
6951-
EvaluateWithElementFloating<simd8_t>(simdBaseType, &result, gtSimd8Val, index, value);
6952-
gtSimd8Val = result;
6940+
EvaluateWithElementFloating<simd8_t>(simdBaseType, &gtSimd8Val, gtSimd8Val, index, value);
69536941
break;
69546942
}
69556943

69566944
case TYP_SIMD12:
69576945
{
6958-
simd12_t result = {};
6959-
EvaluateWithElementFloating<simd12_t>(simdBaseType, &result, gtSimd12Val, index, value);
6960-
gtSimd12Val = result;
6946+
EvaluateWithElementFloating<simd12_t>(simdBaseType, &gtSimd12Val, gtSimd12Val, index, value);
69616947
break;
69626948
}
69636949

69646950
case TYP_SIMD16:
69656951
{
6966-
simd16_t result = {};
6967-
EvaluateWithElementFloating<simd16_t>(simdBaseType, &result, gtSimd16Val, index, value);
6968-
gtSimd16Val = result;
6952+
EvaluateWithElementFloating<simd16_t>(simdBaseType, &gtSimd16Val, gtSimd16Val, index, value);
69696953
break;
69706954
}
69716955

69726956
#if defined(TARGET_XARCH)
69736957
case TYP_SIMD32:
69746958
{
6975-
simd32_t result = {};
6976-
EvaluateWithElementFloating<simd32_t>(simdBaseType, &result, gtSimd32Val, index, value);
6977-
gtSimd32Val = result;
6959+
EvaluateWithElementFloating<simd32_t>(simdBaseType, &gtSimd32Val, gtSimd32Val, index, value);
69786960
break;
69796961
}
69806962

69816963
case TYP_SIMD64:
69826964
{
6983-
simd64_t result = {};
6984-
EvaluateWithElementFloating<simd64_t>(simdBaseType, &result, gtSimd64Val, index, value);
6985-
gtSimd64Val = result;
6965+
EvaluateWithElementFloating<simd64_t>(simdBaseType, &gtSimd64Val, gtSimd64Val, index, value);
69866966
break;
69876967
}
69886968
#endif // TARGET_XARCH
@@ -7002,42 +6982,32 @@ struct GenTreeVecCon : public GenTree
70026982
#if defined(FEATURE_SIMD)
70036983
case TYP_SIMD8:
70046984
{
7005-
simd8_t result = {};
7006-
EvaluateWithElementIntegral<simd8_t>(simdBaseType, &result, gtSimd8Val, index, value);
7007-
gtSimd8Val = result;
6985+
EvaluateWithElementIntegral<simd8_t>(simdBaseType, &gtSimd8Val, gtSimd8Val, index, value);
70086986
break;
70096987
}
70106988

70116989
case TYP_SIMD12:
70126990
{
7013-
simd12_t result = {};
7014-
EvaluateWithElementIntegral<simd12_t>(simdBaseType, &result, gtSimd12Val, index, value);
7015-
gtSimd12Val = result;
6991+
EvaluateWithElementIntegral<simd12_t>(simdBaseType, &gtSimd12Val, gtSimd12Val, index, value);
70166992
break;
70176993
}
70186994

70196995
case TYP_SIMD16:
70206996
{
7021-
simd16_t result = {};
7022-
EvaluateWithElementIntegral<simd16_t>(simdBaseType, &result, gtSimd16Val, index, value);
7023-
gtSimd16Val = result;
6997+
EvaluateWithElementIntegral<simd16_t>(simdBaseType, &gtSimd16Val, gtSimd16Val, index, value);
70246998
break;
70256999
}
70267000

70277001
#if defined(TARGET_XARCH)
70287002
case TYP_SIMD32:
70297003
{
7030-
simd32_t result = {};
7031-
EvaluateWithElementIntegral<simd32_t>(simdBaseType, &result, gtSimd32Val, index, value);
7032-
gtSimd32Val = result;
7004+
EvaluateWithElementIntegral<simd32_t>(simdBaseType, &gtSimd32Val, gtSimd32Val, index, value);
70337005
break;
70347006
}
70357007

70367008
case TYP_SIMD64:
70377009
{
7038-
simd64_t result = {};
7039-
EvaluateWithElementIntegral<simd64_t>(simdBaseType, &result, gtSimd64Val, index, value);
7040-
gtSimd64Val = result;
7010+
EvaluateWithElementIntegral<simd64_t>(simdBaseType, &gtSimd64Val, gtSimd64Val, index, value);
70417011
break;
70427012
}
70437013
#endif // TARGET_XARCH

src/coreclr/jit/simd.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ TBase EvaluateUnaryScalar(genTreeOps oper, TBase arg0)
415415
}
416416

417417
template <typename TSimd, typename TBase>
418-
void EvaluateUnarySimd(genTreeOps oper, bool scalar, TSimd* result, TSimd arg0)
418+
void EvaluateUnarySimd(genTreeOps oper, bool scalar, TSimd* result, const TSimd& arg0)
419419
{
420420
uint32_t count = sizeof(TSimd) / sizeof(TBase);
421421

@@ -445,7 +445,7 @@ void EvaluateUnarySimd(genTreeOps oper, bool scalar, TSimd* result, TSimd arg0)
445445
}
446446

447447
template <typename TSimd>
448-
void EvaluateUnarySimd(genTreeOps oper, bool scalar, var_types baseType, TSimd* result, TSimd arg0)
448+
void EvaluateUnarySimd(genTreeOps oper, bool scalar, var_types baseType, TSimd* result, const TSimd& arg0)
449449
{
450450
switch (baseType)
451451
{
@@ -725,7 +725,7 @@ TBase EvaluateBinaryScalar(genTreeOps oper, TBase arg0, TBase arg1)
725725
}
726726

727727
template <typename TSimd, typename TBase>
728-
void EvaluateBinarySimd(genTreeOps oper, bool scalar, TSimd* result, TSimd arg0, TSimd arg1)
728+
void EvaluateBinarySimd(genTreeOps oper, bool scalar, TSimd* result, const TSimd& arg0, const TSimd& arg1)
729729
{
730730
uint32_t count = sizeof(TSimd) / sizeof(TBase);
731731

@@ -758,7 +758,8 @@ void EvaluateBinarySimd(genTreeOps oper, bool scalar, TSimd* result, TSimd arg0,
758758
}
759759

760760
template <typename TSimd>
761-
void EvaluateBinarySimd(genTreeOps oper, bool scalar, var_types baseType, TSimd* result, TSimd arg0, TSimd arg1)
761+
void EvaluateBinarySimd(
762+
genTreeOps oper, bool scalar, var_types baseType, TSimd* result, const TSimd& arg0, const TSimd& arg1)
762763
{
763764
switch (baseType)
764765
{
@@ -830,7 +831,7 @@ void EvaluateBinarySimd(genTreeOps oper, bool scalar, var_types baseType, TSimd*
830831
}
831832

832833
template <typename TSimd>
833-
double EvaluateGetElementFloating(var_types simdBaseType, TSimd arg0, int32_t arg1)
834+
double EvaluateGetElementFloating(var_types simdBaseType, const TSimd& arg0, int32_t arg1)
834835
{
835836
switch (simdBaseType)
836837
{
@@ -852,7 +853,7 @@ double EvaluateGetElementFloating(var_types simdBaseType, TSimd arg0, int32_t ar
852853
}
853854

854855
template <typename TSimd>
855-
int64_t EvaluateGetElementIntegral(var_types simdBaseType, TSimd arg0, int32_t arg1)
856+
int64_t EvaluateGetElementIntegral(var_types simdBaseType, const TSimd& arg0, int32_t arg1)
856857
{
857858
switch (simdBaseType)
858859
{
@@ -904,7 +905,7 @@ int64_t EvaluateGetElementIntegral(var_types simdBaseType, TSimd arg0, int32_t a
904905
}
905906

906907
template <typename TSimd>
907-
void EvaluateWithElementFloating(var_types simdBaseType, TSimd* result, TSimd arg0, int32_t arg1, double arg2)
908+
void EvaluateWithElementFloating(var_types simdBaseType, TSimd* result, const TSimd& arg0, int32_t arg1, double arg2)
908909
{
909910
*result = arg0;
910911

@@ -930,7 +931,7 @@ void EvaluateWithElementFloating(var_types simdBaseType, TSimd* result, TSimd ar
930931
}
931932

932933
template <typename TSimd>
933-
void EvaluateWithElementIntegral(var_types simdBaseType, TSimd* result, TSimd arg0, int32_t arg1, int64_t arg2)
934+
void EvaluateWithElementIntegral(var_types simdBaseType, TSimd* result, const TSimd& arg0, int32_t arg1, int64_t arg2)
934935
{
935936
*result = arg0;
936937

0 commit comments

Comments
 (0)