Skip to content

Commit

Permalink
Draft for Min/Max intrinsics xarch (dotnet#65625)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkiFoD committed Feb 22, 2022
1 parent 4017327 commit 954fa30
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7400,6 +7400,20 @@ void CodeGen::genIntrinsic(GenTree* treeNode)
// Handle intrinsics that can be implemented by target-specific instructions
switch (treeNode->AsIntrinsic()->gtIntrinsicName)
{
#ifdef TARGET_XARCH

case NI_System_Math_Max:
genConsumeOperands(treeNode->AsOp());
GetEmitter()->emitIns_R_R_R(INS_maxss, emitActualTypeSize(treeNode), treeNode->GetRegNum(),
treeNode->gtGetOp1()->GetRegNum(), treeNode->gtGetOp2()->GetRegNum());
break;

case NI_System_Math_Min:
genConsumeOperands(treeNode->AsOp());
GetEmitter()->emitIns_R_R_R(INS_minss, emitActualTypeSize(treeNode), treeNode->GetRegNum(),
treeNode->gtGetOp1()->GetRegNum(), treeNode->gtGetOp2()->GetRegNum());
break;
#endif
case NI_System_Math_Abs:
genSSE2BitwiseOp(treeNode);
break;
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4492,13 +4492,14 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
case NI_System_Math_Log:
case NI_System_Math_Log2:
case NI_System_Math_Log10:
#ifdef TARGET_ARM64
#if defined TARGET_ARM64 || defined TARGET_XARCH
// ARM64 has fmax/fmin which are IEEE754:2019 minimum/maximum compatible
// TODO-XARCH-CQ: Enable this for XARCH when one of the arguments is a constant
// so we can then emit maxss/minss and avoid NaN/-0.0 handling
case NI_System_Math_Max:
case NI_System_Math_Min:
#endif

case NI_System_Math_Pow:
case NI_System_Math_Round:
case NI_System_Math_Sin:
Expand Down Expand Up @@ -20541,6 +20542,8 @@ bool Compiler::IsTargetIntrinsic(NamedIntrinsic intrinsicName)

case NI_System_Math_Abs:
case NI_System_Math_Sqrt:
case NI_System_Math_Max:
case NI_System_Math_Min:
return true;

case NI_System_Math_Ceiling:
Expand Down
16 changes: 14 additions & 2 deletions src/coreclr/jit/lsraxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1804,9 +1804,21 @@ int LinearScan::BuildIntrinsic(GenTree* tree)
assert(varTypeIsFloating(op1));
assert(op1->TypeGet() == tree->TypeGet());
RefPosition* internalFloatDef = nullptr;

int srcCount;
switch (tree->AsIntrinsic()->gtIntrinsicName)
{
#ifdef TARGET_XARCH
case NI_System_Math_Max:
case NI_System_Math_Min:
assert(varTypeIsFloating(tree->gtGetOp1()));
assert(varTypeIsFloating(tree->gtGetOp2()));
assert(tree->gtGetOp1()->TypeIs(tree->TypeGet()));

srcCount = BuildBinaryUses(tree->AsOp());

BuildDef(tree);
return srcCount;
#endif
case NI_System_Math_Abs:
// Abs(float x) = x & 0x7fffffff
// Abs(double x) = x & 0x7ffffff ffffffff
Expand Down Expand Up @@ -1837,7 +1849,7 @@ int LinearScan::BuildIntrinsic(GenTree* tree)
break;
}
assert(tree->gtGetOp2IfPresent() == nullptr);
int srcCount;

if (op1->isContained())
{
srcCount = BuildOperandUses(op1);
Expand Down

0 comments on commit 954fa30

Please sign in to comment.