Skip to content

Commit

Permalink
Vector256.IsHardwareAccelerated to return true only on AVX2 (#64345)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored Jan 27, 2022
1 parent 9ae484f commit 19291cc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
21 changes: 20 additions & 1 deletion src/coreclr/jit/hwintrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,26 @@ NamedIntrinsic HWIntrinsicInfo::lookupId(Compiler* comp,

bool isIsaSupported = comp->compSupportsHWIntrinsic(isa);

if ((strcmp(methodName, "get_IsSupported") == 0) || (strcmp(methodName, "get_IsHardwareAccelerated") == 0))
bool isHardwareAcceleratedProp = (strcmp(methodName, "get_IsHardwareAccelerated") == 0);
#ifdef TARGET_XARCH
if (isHardwareAcceleratedProp)
{
// Special case: Some of Vector128/256 APIs are hardware accelerated with Sse1 and Avx1,
// but we want IsHardwareAccelerated to return true only when all of them are (there are
// still can be cases where e.g. Sse41 might give an additional boost for Vector128, but it's
// not important enough to bump the minimal Sse version here)
if (strcmp(className, "Vector128") == 0)
{
isa = InstructionSet_SSE2;
}
else if (strcmp(className, "Vector256") == 0)
{
isa = InstructionSet_AVX2;
}
}
#endif

if ((strcmp(methodName, "get_IsSupported") == 0) || isHardwareAcceleratedProp)
{
return isIsaSupported ? (comp->compExactlyDependsOn(isa) ? NI_IsSupported_True : NI_IsSupported_Dynamic)
: NI_IsSupported_False;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ref Unsafe.Add(ref searchSpace, offset + 1),
// Based on http://0x80.pl/articles/simd-strfind.html#algorithm-1-generic-simd "Algorithm 1: Generic SIMD" by Wojciech Muła
// Some details about the implementation can also be found in https://github.com/dotnet/runtime/pull/63285
SEARCH_TWO_BYTES:
if (Avx2.IsSupported && searchSpaceMinusValueTailLength - Vector256<byte>.Count >= 0)
if (Vector256.IsHardwareAccelerated && searchSpaceMinusValueTailLength - Vector256<byte>.Count >= 0)
{
// Find the last unique (which is not equal to ch1) byte
// the algorithm is fine if both are equal, just a little bit less efficient
Expand Down Expand Up @@ -212,7 +212,7 @@ ref Unsafe.Add(ref searchSpace, relativeIndex + 1),
// Based on http://0x80.pl/articles/simd-strfind.html#algorithm-1-generic-simd "Algorithm 1: Generic SIMD" by Wojciech Muła
// Some details about the implementation can also be found in https://github.com/dotnet/runtime/pull/63285
SEARCH_TWO_BYTES:
if (Avx2.IsSupported && searchSpaceMinusValueTailLength >= Vector256<byte>.Count)
if (Vector256.IsHardwareAccelerated && searchSpaceMinusValueTailLength >= Vector256<byte>.Count)
{
offset = searchSpaceMinusValueTailLength - Vector256<byte>.Count;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ref Unsafe.As<char, byte>(ref Unsafe.Add(ref searchSpace, offset + 1)),
// Based on http://0x80.pl/articles/simd-strfind.html#algorithm-1-generic-simd "Algorithm 1: Generic SIMD" by Wojciech Muła
// Some details about the implementation can also be found in https://github.com/dotnet/runtime/pull/63285
SEARCH_TWO_CHARS:
if (Avx2.IsSupported && searchSpaceMinusValueTailLength - Vector256<ushort>.Count >= 0)
if (Vector256.IsHardwareAccelerated && searchSpaceMinusValueTailLength - Vector256<ushort>.Count >= 0)
{
// Find the last unique (which is not equal to ch1) character
// the algorithm is fine if both are equal, just a little bit less efficient
Expand Down Expand Up @@ -231,7 +231,7 @@ ref Unsafe.As<char, byte>(ref Unsafe.Add(ref searchSpace, relativeIndex + 1)),
// Based on http://0x80.pl/articles/simd-strfind.html#algorithm-1-generic-simd "Algorithm 1: Generic SIMD" by Wojciech Muła
// Some details about the implementation can also be found in https://github.com/dotnet/runtime/pull/63285
SEARCH_TWO_CHARS:
if (Avx2.IsSupported && searchSpaceMinusValueTailLength >= Vector256<ushort>.Count)
if (Vector256.IsHardwareAccelerated && searchSpaceMinusValueTailLength >= Vector256<ushort>.Count)
{
offset = searchSpaceMinusValueTailLength - Vector256<ushort>.Count;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ static bool ValidateVector256()
{
bool succeeded = true;

if (Avx.IsSupported)
if (Avx2.IsSupported)
{
succeeded &= Vector256.IsHardwareAccelerated;
succeeded &= Vector256<byte>.Count == 32;
Expand Down

0 comments on commit 19291cc

Please sign in to comment.