Skip to content

Commit

Permalink
Upgrading SpanHelpers with Vector512 (#86655)
Browse files Browse the repository at this point in the history
* Adding required internal library methods to support Vector512.

* Making Vector512.IsHardwareAccelerated return 'False' on targets with Vector512Throttling issues

* SpanHelper library upgrades.

* Using AVX512 directly in packed implementation

* Fixing cpuid tests

* Cleanup + Addressing review comments

* Address review comments.
  • Loading branch information
DeepakRajendrakumaran committed Jun 27, 2023
1 parent 6d6fbe0 commit b16b29b
Show file tree
Hide file tree
Showing 12 changed files with 1,618 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2298,7 +2298,7 @@ void Compiler::compSetProcessor()

instructionSetFlags.AddInstructionSet(InstructionSet_Vector512);

if ((preferredVectorByteLength == 0) && jitFlags.IsSet(JitFlags::JIT_FLAG_VECTOR512_THROTTLING))
if ((preferredVectorByteLength == 0) && opts.Vector512Throttling())
{
// Some architectures can experience frequency throttling when
// executing 512-bit width instructions. To account for this we set the
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9508,6 +9508,16 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
return jitFlags->IsSet(JitFlags::JIT_FLAG_REVERSE_PINVOKE);
}

// true if JitFlags::JIT_FLAG_VECTOR512_THROTTLING is set to true
bool Vector512Throttling()
{
#if defined(TARGET_XARCH)
return jitFlags->IsSet(JitFlags::JIT_FLAG_VECTOR512_THROTTLING);
#else
return false;
#endif
}

bool compScopeInfo; // Generate the LocalVar info ?
bool compDbgCode; // Generate debugger-friendly code?
bool compDbgInfo; // Gather debugging info?
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/jit/hwintrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,11 @@ NamedIntrinsic HWIntrinsicInfo::lookupId(Compiler* comp,
}
else if (strcmp(className, "Vector512") == 0)
{
// If the JitFlags::JIT_FLAG_VECTOR512_THROTTLING flag is set, we do not need to do any further checks.
if (comp->opts.Vector512Throttling())
{
return NI_IsSupported_False;
}
isa = InstructionSet_AVX512F;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,17 @@ internal static uint ResetLowestSetBit(uint value)
return value & (value - 1);
}

/// <summary>
/// Reset specific bit in the given value
/// Reset the lowest significant bit in the given value
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ulong ResetLowestSetBit(ulong value)
{
// It's lowered to BLSR on x86
return value & (value - 1);
}

/// <summary>
/// Flip the bit at a specific position in a given value.
/// Similar in behavior to the x86 instruction BTC (Bit Test and Complement).
Expand All @@ -957,5 +968,19 @@ internal static uint FlipBit(uint value, int index)
{
return value ^ (1u << index);
}

/// <summary>
/// Flip the bit at a specific position in a given value.
/// Similar in behavior to the x86 instruction BTC (Bit Test and Complement).
/// /// </summary>
/// <param name="value">The value.</param>
/// <param name="index">The zero-based index of the bit to flip.
/// Any value outside the range [0..63] is treated as congruent mod 64.</param>
/// <returns>The new value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ulong FlipBit(ulong value, int index)
{
return value ^ (1ul << index);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,21 @@ public static Vector512<T> LoadUnsafe<T>(ref T source, nuint elementOffset)
return Unsafe.ReadUnaligned<Vector512<T>>(ref Unsafe.As<T, byte>(ref source));
}

/// <summary>Loads a vector from the given source and reinterprets it as <see cref="ushort"/>.</summary>
/// <param name="source">The source from which the vector will be loaded.</param>
/// <returns>The vector loaded from <paramref name="source" />.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static Vector512<ushort> LoadUnsafe(ref char source) =>
LoadUnsafe(ref Unsafe.As<char, ushort>(ref source));

/// <summary>Loads a vector from the given source and element offset and reinterprets it as <see cref="ushort"/>.</summary>
/// <param name="source">The source to which <paramref name="elementOffset" /> will be added before loading the vector.</param>
/// <param name="elementOffset">The element offset from <paramref name="source" /> from which the vector will be loaded.</param>
/// <returns>The vector loaded from <paramref name="source" /> plus <paramref name="elementOffset" />.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static Vector512<ushort> LoadUnsafe(ref char source, nuint elementOffset) =>
LoadUnsafe(ref Unsafe.As<char, ushort>(ref source), elementOffset);

/// <summary>Computes the maximum of two vectors on a per-element basis.</summary>
/// <typeparam name="T">The type of the elements in the vector.</typeparam>
/// <param name="left">The vector to compare with <paramref name="right" />.</param>
Expand Down
Loading

0 comments on commit b16b29b

Please sign in to comment.