Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading SpanHelpers with Vector512 #86655

Merged
merged 7 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
tannergooding marked this conversation as resolved.
Show resolved Hide resolved
{
#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