Skip to content

Commit bdfef3c

Browse files
committed
Refactored to move common logic inside isSupportedBaseType
1 parent 5c4a1fb commit bdfef3c

1 file changed

Lines changed: 39 additions & 33 deletions

File tree

src/coreclr/src/jit/hwintrinsic.cpp

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,40 @@ static bool impIsTableDrivenHWIntrinsic(NamedIntrinsic intrinsicId, HWIntrinsicC
627627
!HWIntrinsicInfo::HasSpecialImport(intrinsicId);
628628
}
629629

630+
//------------------------------------------------------------------------
631+
// isSupportedBaseType
632+
//
633+
// Arguments:
634+
// intrinsicId - HW intrinsic id
635+
// baseType - Base type of the intrinsic.
636+
//
637+
// Return Value:
638+
// returns true if the baseType is supported for given intrinsic.
639+
//
640+
static bool isSupportedBaseType(NamedIntrinsic intrinsic, var_types baseType)
641+
{
642+
// We don't actually check the intrinsic outside of the false case as we expect
643+
// the exposed managed signatures are either generic and support all types
644+
// or they are explicit and support the type indicated.
645+
if (varTypeIsArithmetic(baseType))
646+
{
647+
return true;
648+
}
649+
650+
#ifdef TARGET_XARCH
651+
assert((intrinsic >= NI_Vector128_As && intrinsic <= NI_Vector128_AsUInt64) ||
652+
(intrinsic >= NI_Vector128_get_AllBitsSet && intrinsic <= NI_Vector128_ToVector256Unsafe) ||
653+
(intrinsic >= NI_Vector256_As && intrinsic <= NI_Vector256_AsUInt64) ||
654+
(intrinsic >= NI_Vector256_get_AllBitsSet && intrinsic <= NI_Vector256_ToScalar));
655+
#else
656+
assert((intrinsic >= NI_Vector64_AsByte && intrinsic <= NI_Vector64_AsUInt32) ||
657+
(intrinsic >= NI_Vector64_get_AllBitsSet && intrinsic <= NI_Vector64_ToScalar) ||
658+
(intrinsic >= NI_Vector128_As && intrinsic <= NI_Vector128_AsUInt64) ||
659+
(intrinsic >= NI_Vector128_get_AllBitsSet && intrinsic <= NI_Vector128_ToScalar));
660+
#endif
661+
return false;
662+
}
663+
630664
//------------------------------------------------------------------------
631665
// impHWIntrinsic: Import a hardware intrinsic as a GT_HWINTRINSIC node if possible
632666
//
@@ -659,23 +693,10 @@ GenTree* Compiler::impHWIntrinsic(NamedIntrinsic intrinsic,
659693
retType = getSIMDTypeForSize(sizeBytes);
660694
assert(sizeBytes != 0);
661695

662-
// Immediately return if this is non-arithmetic type.
663-
if (!varTypeIsArithmetic(baseType))
696+
// We want to return early here for cases where retType was TYP_STRUCT as per method signature and
697+
// rather than deferring the decision after getting the baseType of arg.
698+
if (!isSupportedBaseType(intrinsic, baseType))
664699
{
665-
// We want to return early here for cases where retType was TYP_STRUCT as per method signature and
666-
// rather than deferring the decision after getting the baseType of arg.
667-
#ifdef TARGET_XARCH
668-
assert(intrinsic == NI_Vector128_As || intrinsic == NI_Vector128_get_AllBitsSet ||
669-
intrinsic == NI_Vector128_get_Zero || intrinsic == NI_Vector128_WithElement ||
670-
intrinsic == NI_Vector128_ToVector256 || intrinsic == NI_Vector128_ToVector256Unsafe ||
671-
intrinsic == NI_Vector256_get_Zero || intrinsic == NI_Vector256_get_AllBitsSet ||
672-
intrinsic == NI_Vector256_As || intrinsic == NI_Vector256_WithElement ||
673-
intrinsic == NI_Vector256_GetLower);
674-
#else
675-
assert((intrinsic == NI_Vector64_AsByte) || (intrinsic == NI_Vector64_get_Zero) ||
676-
(intrinsic == NI_Vector64_get_AllBitsSet) || (intrinsic == NI_Vector128_As) ||
677-
(intrinsic == NI_Vector128_get_Zero) || (intrinsic == NI_Vector128_get_AllBitsSet));
678-
#endif
679700
return nullptr;
680701
}
681702
}
@@ -696,24 +717,9 @@ GenTree* Compiler::impHWIntrinsic(NamedIntrinsic intrinsic,
696717
}
697718
}
698719

699-
// Immediately return if this is non-arithmetic type and category is other than scalar/special.
700-
if (!varTypeIsArithmetic(baseType) && category != HW_Category_Special && category != HW_Category_Scalar)
720+
// Immediately return if the category is other than scalar/special and this is not a supported base type.
721+
if (category != HW_Category_Special && category != HW_Category_Scalar && !isSupportedBaseType(intrinsic, baseType))
701722
{
702-
#ifdef TARGET_XARCH
703-
assert((intrinsic >= NI_Vector128_As && intrinsic <= NI_Vector128_AsUInt64) ||
704-
(intrinsic == NI_Vector128_GetElement || intrinsic == NI_Vector128_get_Count ||
705-
intrinsic == NI_Vector128_ToScalar) ||
706-
(intrinsic >= NI_Vector256_As && intrinsic <= NI_Vector256_AsUInt64) ||
707-
(intrinsic == NI_Vector256_GetElement || intrinsic == NI_Vector256_get_Count ||
708-
intrinsic == NI_Vector256_ToScalar));
709-
#else
710-
assert((intrinsic >= NI_Vector64_AsByte && intrinsic <= NI_Vector64_AsUInt32) ||
711-
(intrinsic == NI_Vector64_GetElement || intrinsic == NI_Vector64_get_Count ||
712-
intrinsic == NI_Vector64_ToScalar) ||
713-
(intrinsic >= NI_Vector128_As && intrinsic <= NI_Vector128_AsUInt64) ||
714-
(intrinsic == NI_Vector128_GetElement || intrinsic == NI_Vector128_get_Count ||
715-
intrinsic == NI_Vector128_ToScalar));
716-
#endif
717723
return nullptr;
718724
}
719725

0 commit comments

Comments
 (0)