Skip to content

Commit 5644260

Browse files
author
Prashanth Govindarajan
authored
Narrow four utf16 chars to ascii and write to buffer (#39508)
* Shims * shim * Cherry-pick * NarrowFourUtf16CharsToAsciiAndWriteToBuffer * Address comments * Nit
1 parent 652297c commit 5644260

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/libraries/System.Private.CoreLib/src/System/Text/ASCIIUtility.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,16 @@ private static void NarrowFourUtf16CharsToAsciiAndWriteToBuffer(ref byte outputB
10031003
Vector128<uint> vecNarrow = Sse2.PackUnsignedSaturate(vecWide, vecWide).AsUInt32();
10041004
Unsafe.WriteUnaligned<uint>(ref outputBuffer, Sse2.ConvertToUInt32(vecNarrow));
10051005
}
1006+
else if (AdvSimd.IsSupported)
1007+
{
1008+
// Narrows a vector of words [ w0 w1 w2 w3 ] to a vector of bytes
1009+
// [ b0 b1 b2 b3 * * * * ], then writes 4 bytes (32 bits) to the destination.
1010+
1011+
Vector128<short> vecWide = Vector128.CreateScalarUnsafe(value).AsInt16();
1012+
Vector64<byte> lower = AdvSimd.ExtractNarrowingSaturateUnsignedLower(vecWide);
1013+
Unsafe.WriteUnaligned<uint>(ref outputBuffer, lower.AsUInt32().ToScalar());
1014+
}
1015+
10061016
else
10071017
{
10081018
if (BitConverter.IsLittleEndian)

src/libraries/System.Utf8String.Experimental/src/System/Runtime/Intrinsics/Intrinsics.Shims.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ internal static class Vector64
99
public static Vector64<uint> CreateScalar(uint value) => throw new PlatformNotSupportedException();
1010
public static Vector64<byte> AsByte<T>(this Vector64<T> vector) where T : struct => throw new PlatformNotSupportedException();
1111
public static Vector64<uint> AsUInt32<T>(this Vector64<T> vector) where T : struct => throw new PlatformNotSupportedException();
12+
public static Vector64<T> GetLower<T>(this Vector128<T> vector) where T : struct => throw new PlatformNotSupportedException();
13+
public static Vector64<ulong> AsUInt64<T>(this Vector64<T> vector) where T : struct => throw new PlatformNotSupportedException();
1214
}
1315
internal readonly struct Vector64<T>
1416
where T : struct
@@ -21,6 +23,8 @@ internal static class Vector128
2123
public static Vector128<short> Create(short value) => throw new PlatformNotSupportedException();
2224
public static Vector128<ulong> Create(ulong value) => throw new PlatformNotSupportedException();
2325
public static Vector128<ushort> Create(ushort value) => throw new PlatformNotSupportedException();
26+
public static Vector128<byte> Create(byte value) => throw new PlatformNotSupportedException();
27+
public static Vector128<uint> Create(uint value) => throw new PlatformNotSupportedException();
2428
public static Vector128<ulong> CreateScalarUnsafe(ulong value) => throw new PlatformNotSupportedException();
2529
public static Vector128<byte> AsByte<T>(this Vector128<T> vector) where T : struct => throw new PlatformNotSupportedException();
2630
public static Vector128<short> AsInt16<T>(this Vector128<T> vector) where T : struct => throw new PlatformNotSupportedException();

0 commit comments

Comments
 (0)