未验证 提交 a5136765 编写于 作者: A anthonycanino 提交者: GitHub

Light up core ASCII.Utility methods with Vector256/Vector512 code paths. (#88532)

* Lib upgrade for ToUtf16

* Upgrade NarrowUtf16ToAscii with Vector512

* Complete the upgrade in NarrowUtf16ToAscii method
with Vector512 and Vector256 APIs.

* Adding VectorXX paths to `GetIndexOfFirstNonAscii` functions.

* Adding optimization to Vecto256 VectorContainsNonAsciiChar method.

* Code path refactoring and cleanup.

* Code changes based on the review:
1. turn some variables into explicitly specified const.
2. removed some helper functions and inlined them.

* Resolve comments

* revert the changes at GetIndexOfFirstNonAsciiByte

---------
Co-authored-by: NRuihan-Yin <ruihan.yin@intel.com>
上级 2268fb32
......@@ -19,15 +19,15 @@ public static unsafe void EmptyInputs()
[Fact]
public static void AllAsciiInput()
{
using BoundedMemory<char> utf16Mem = BoundedMemory.Allocate<char>(128);
using BoundedMemory<byte> asciiMem = BoundedMemory.Allocate<byte>(128);
using BoundedMemory<char> utf16Mem = BoundedMemory.Allocate<char>(256);
using BoundedMemory<byte> asciiMem = BoundedMemory.Allocate<byte>(256);
// Fill source with 00 .. 7F.
Span<char> utf16Span = utf16Mem.Span;
for (int i = 0; i < utf16Span.Length; i++)
{
utf16Span[i] = (char)i;
utf16Span[i] = (char)(i % 128);
}
utf16Mem.MakeReadonly();
......@@ -42,11 +42,11 @@ public static void AllAsciiInput()
// First, validate that the workhorse saw the incoming data as all-ASCII.
Assert.Equal(OperationStatus.Done, Ascii.FromUtf16(utf16Span.Slice(i), asciiSpan.Slice(i), out int bytesWritten));
Assert.Equal(128 - i, bytesWritten);
Assert.Equal(256 - i, bytesWritten);
// Then, validate that the data was transcoded properly.
for (int j = i; j < 128; j++)
for (int j = i; j < 256; j++)
{
Assert.Equal((ushort)utf16Span[i], (ushort)asciiSpan[i]);
}
......@@ -56,15 +56,15 @@ public static void AllAsciiInput()
[Fact]
public static void SomeNonAsciiInput()
{
using BoundedMemory<char> utf16Mem = BoundedMemory.Allocate<char>(128);
using BoundedMemory<byte> asciiMem = BoundedMemory.Allocate<byte>(128);
using BoundedMemory<char> utf16Mem = BoundedMemory.Allocate<char>(256);
using BoundedMemory<byte> asciiMem = BoundedMemory.Allocate<byte>(256);
// Fill source with 00 .. 7F.
Span<char> utf16Span = utf16Mem.Span;
for (int i = 0; i < utf16Span.Length; i++)
{
utf16Span[i] = (char)i;
utf16Span[i] = (char)(i % 128);
}
// We'll write to the ASCII span.
......
......@@ -20,15 +20,15 @@ public static void EmptyInputs()
[Fact]
public static void AllAsciiInput()
{
using BoundedMemory<byte> asciiMem = BoundedMemory.Allocate<byte>(128);
using BoundedMemory<char> utf16Mem = BoundedMemory.Allocate<char>(128);
using BoundedMemory<byte> asciiMem = BoundedMemory.Allocate<byte>(256);
using BoundedMemory<char> utf16Mem = BoundedMemory.Allocate<char>(256);
// Fill source with 00 .. 7F, then trap future writes.
Span<byte> asciiSpan = asciiMem.Span;
for (int i = 0; i < asciiSpan.Length; i++)
{
asciiSpan[i] = (byte)i;
asciiSpan[i] = (byte)(i % 128);
}
asciiMem.MakeReadonly();
......@@ -44,11 +44,11 @@ public static void AllAsciiInput()
// First, validate that the workhorse saw the incoming data as all-ASCII.
Assert.Equal(OperationStatus.Done, Ascii.ToUtf16(asciiSpan.Slice(i), utf16Span.Slice(i), out int charsWritten));
Assert.Equal(128 - i, charsWritten);
Assert.Equal(256 - i, charsWritten);
// Then, validate that the data was transcoded properly.
for (int j = i; j < 128; j++)
for (int j = i; j < 256; j++)
{
Assert.Equal((ushort)asciiSpan[i], (ushort)utf16Span[i]);
}
......@@ -58,15 +58,15 @@ public static void AllAsciiInput()
[Fact]
public static void SomeNonAsciiInput()
{
using BoundedMemory<byte> asciiMem = BoundedMemory.Allocate<byte>(128);
using BoundedMemory<char> utf16Mem = BoundedMemory.Allocate<char>(128);
using BoundedMemory<byte> asciiMem = BoundedMemory.Allocate<byte>(256);
using BoundedMemory<char> utf16Mem = BoundedMemory.Allocate<char>(256);
// Fill source with 00 .. 7F, then trap future writes.
Span<byte> asciiSpan = asciiMem.Span;
for (int i = 0; i < asciiSpan.Length; i++)
{
asciiSpan[i] = (byte)i;
asciiSpan[i] = (byte)(i % 128);
}
// We'll write to the UTF-16 span.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册