Skip to content
Draft
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
14 changes: 14 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35411,6 +35411,20 @@ GenTree* Compiler::gtFoldExprHWIntrinsic(GenTreeHWIntrinsic* tree)
}
}

#if defined(TARGET_XARCH)
if ((ni == NI_Vector_ToVector512) && op1->OperIsHWIntrinsic(NI_Vector_ToVector256))
{
// A single zero extension from 128 bits also clears the upper 384 bits.
GenTreeHWIntrinsic* extend = op1->AsHWIntrinsic();
assert(extend->TypeIs(TYP_SIMD32));
assert(extend->Op(1)->TypeIs(TYP_SIMD16));
tree->Op(1) = extend->Op(1);
tree->SetSimdSize(16);
DEBUG_DESTROY_NODE(extend);
return tree;
}
#endif

#if defined(FEATURE_MASKED_HW_INTRINSICS)
// Fold ConvertMaskToVector(ConvertVectorToMask(vec)) to vec
if (tree->OperIsConvertMaskToVector())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace System.Buffers.Text
{
public static partial class Base64
{
private const int MaxStackallocThreshold = 256;

/// <summary>
/// Returns the maximum length (in bytes) of the result if you were to decode base 64 encoded text from a span of size <paramref name="base64Length"/>.
/// </summary>
Expand Down Expand Up @@ -99,26 +97,8 @@ public static int DecodeFromUtf8(ReadOnlySpan<byte> source, Span<byte> destinati
/// <returns>A byte array which contains the result of the decoding operation.</returns>
/// <exception cref="FormatException"><paramref name="source"/> contains an invalid Base64 character,
/// more than two padding characters, or a non white space character among the padding characters.</exception>
public static unsafe byte[] DecodeFromUtf8(ReadOnlySpan<byte> source)
{
int upperBound = GetMaxDecodedLength(source.Length);
byte[]? rented = null;

Span<byte> destination = (uint)upperBound <= MaxStackallocThreshold
? stackalloc byte[MaxStackallocThreshold]
: (rented = ArrayPool<byte>.Shared.Rent(upperBound));

OperationStatus status = DecodeFromUtf8(source, destination, out _, out int bytesWritten);
Debug.Assert(status is OperationStatus.Done or OperationStatus.InvalidData);
byte[] result = destination.Slice(0, bytesWritten).ToArray();

if (rented is not null)
{
ArrayPool<byte>.Shared.Return(rented);
}

return status == OperationStatus.Done ? result : throw new FormatException(SR.Format_BadBase64Char);
}
public static byte[] DecodeFromUtf8(ReadOnlySpan<byte> source) =>
DecodeToArray(default(Base64DecoderByte), source);

/// <summary>
/// Decodes the span of UTF-8 encoded text represented as Base64 into binary data.
Expand Down Expand Up @@ -231,25 +211,7 @@ public static bool TryDecodeFromChars(ReadOnlySpan<char> source, Span<byte> dest
/// <returns>A byte array which contains the result of the decoding operation.</returns>
/// <exception cref="FormatException"><paramref name="source"/> contains an invalid Base64 character,
/// more than two padding characters, or a non white space character among the padding characters.</exception>
public static unsafe byte[] DecodeFromChars(ReadOnlySpan<char> source)
{
int upperBound = GetMaxDecodedLength(source.Length);
byte[]? rented = null;

Span<byte> destination = (uint)upperBound <= MaxStackallocThreshold
? stackalloc byte[MaxStackallocThreshold]
: (rented = ArrayPool<byte>.Shared.Rent(upperBound));

OperationStatus status = DecodeFromChars(source, destination, out _, out int bytesWritten);
Debug.Assert(status is OperationStatus.Done or OperationStatus.InvalidData);
byte[] result = destination.Slice(0, bytesWritten).ToArray();

if (rented is not null)
{
ArrayPool<byte>.Shared.Return(rented);
}

return status == OperationStatus.Done ? result : throw new FormatException(SR.Format_BadBase64Char);
}
public static byte[] DecodeFromChars(ReadOnlySpan<char> source) =>
DecodeToArray(default(Base64DecoderChar), MemoryMarshal.Cast<char, ushort>(source));
}
}
Loading
Loading