Skip to content

Commit

Permalink
Ensure that the various Min and Max APIs are accelerated where possib…
Browse files Browse the repository at this point in the history
…le (#87641)

* Updating Math.Max and Math.Min to utilize AVX512 when available

* Ensure that Single/Double APIs can be directly handled as intrinsic

* Ensure that the various Min and Max APIs are accelerated where possible

* Don't include ILogB for the time being

* Ensure FixupScalar is passed all 4 parameters

* Apply suggestions from code review
  • Loading branch information
tannergooding authored Jun 20, 2023
1 parent 5671669 commit 05e25ff
Show file tree
Hide file tree
Showing 14 changed files with 1,656 additions and 419 deletions.
20 changes: 20 additions & 0 deletions src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,16 +690,36 @@ void CodeGen::genIntrinsic(GenTreeIntrinsic* treeNode)
break;

case NI_System_Math_Max:
{
genConsumeOperands(treeNode->AsOp());
GetEmitter()->emitIns_R_R_R(INS_fmax, emitActualTypeSize(treeNode), treeNode->GetRegNum(),
srcNode->GetRegNum(), treeNode->gtGetOp2()->GetRegNum());
break;
}

case NI_System_Math_MaxNumber:
{
genConsumeOperands(treeNode->AsOp());
GetEmitter()->emitIns_R_R_R(INS_fmaxnm, emitActualTypeSize(treeNode), treeNode->GetRegNum(),
srcNode->GetRegNum(), treeNode->gtGetOp2()->GetRegNum());
break;
}

case NI_System_Math_Min:
{
genConsumeOperands(treeNode->AsOp());
GetEmitter()->emitIns_R_R_R(INS_fmin, emitActualTypeSize(treeNode), treeNode->GetRegNum(),
srcNode->GetRegNum(), treeNode->gtGetOp2()->GetRegNum());
break;
}

case NI_System_Math_MinNumber:
{
genConsumeOperands(treeNode->AsOp());
GetEmitter()->emitIns_R_R_R(INS_fminnm, emitActualTypeSize(treeNode), treeNode->GetRegNum(),
srcNode->GetRegNum(), treeNode->gtGetOp2()->GetRegNum());
break;
}
#endif // TARGET_ARM64

case NI_System_Math_Sqrt:
Expand Down
11 changes: 10 additions & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3957,8 +3957,17 @@ class Compiler
var_types callType,
NamedIntrinsic intrinsicName,
bool tailCall);
GenTree* impMinMaxIntrinsic(CORINFO_METHOD_HANDLE method,
CORINFO_SIG_INFO* sig,
CorInfoType callJitType,
NamedIntrinsic intrinsicName,
bool tailCall,
bool isMax,
bool isMagnitude,
bool isNumber);
NamedIntrinsic lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method);
NamedIntrinsic lookupPrimitiveNamedIntrinsic(CORINFO_METHOD_HANDLE method, const char* methodName);
NamedIntrinsic lookupPrimitiveFloatNamedIntrinsic(CORINFO_METHOD_HANDLE method, const char* methodName);
NamedIntrinsic lookupPrimitiveIntNamedIntrinsic(CORINFO_METHOD_HANDLE method, const char* methodName);
GenTree* impUnsupportedNamedIntrinsic(unsigned helper,
CORINFO_METHOD_HANDLE method,
CORINFO_SIG_INFO* sig,
Expand Down
32 changes: 32 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5477,7 +5477,13 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree)
case NI_System_Math_Log2:
case NI_System_Math_Log10:
case NI_System_Math_Max:
case NI_System_Math_MaxMagnitude:
case NI_System_Math_MaxMagnitudeNumber:
case NI_System_Math_MaxNumber:
case NI_System_Math_Min:
case NI_System_Math_MinMagnitude:
case NI_System_Math_MinMagnitudeNumber:
case NI_System_Math_MinNumber:
case NI_System_Math_Pow:
case NI_System_Math_Round:
case NI_System_Math_Sin:
Expand Down Expand Up @@ -5824,9 +5830,17 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree)
break;

case NI_System_Math_Max:
case NI_System_Math_MaxMagnitude:
case NI_System_Math_MaxMagnitudeNumber:
case NI_System_Math_MaxNumber:
case NI_System_Math_Min:
case NI_System_Math_MinMagnitude:
case NI_System_Math_MinMagnitudeNumber:
case NI_System_Math_MinNumber:
{
level++;
break;
}

default:
assert(!"Unknown binary GT_INTRINSIC operator");
Expand Down Expand Up @@ -12235,9 +12249,27 @@ void Compiler::gtDispTree(GenTree* tree,
case NI_System_Math_Max:
printf(" max");
break;
case NI_System_Math_MaxMagnitude:
printf(" maxMagnitude");
break;
case NI_System_Math_MaxMagnitudeNumber:
printf(" maxMagnitudeNumber");
break;
case NI_System_Math_MaxNumber:
printf(" maxNumber");
break;
case NI_System_Math_Min:
printf(" min");
break;
case NI_System_Math_MinMagnitude:
printf(" minMagnitude");
break;
case NI_System_Math_MinMagnitudeNumber:
printf(" minMagnitudeNumber");
break;
case NI_System_Math_MinNumber:
printf(" minNumber");
break;
case NI_System_Math_Pow:
printf(" pow");
break;
Expand Down
Loading

0 comments on commit 05e25ff

Please sign in to comment.