Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ EncodeToUtf16_Ssse3()

static void System.HexConverter.EncodeToUtf16_Ssse3 ( ReadOnlySpan< byte > bytes,
Span< char > chars,
Casing casing )
inlinestaticprivate

Definition at line 65 of file HexConverter.cs.

66 {
67 nint num = 0;
68 Vector128<byte> mask = Vector128.Create(byte.MaxValue, byte.MaxValue, 0, byte.MaxValue, byte.MaxValue, byte.MaxValue, 1, byte.MaxValue, byte.MaxValue, byte.MaxValue, 2, byte.MaxValue, byte.MaxValue, byte.MaxValue, 3, byte.MaxValue);
69 Vector128<byte> value = ((casing == Casing.Upper) ? Vector128.Create((byte)48, (byte)49, (byte)50, (byte)51, (byte)52, (byte)53, (byte)54, (byte)55, (byte)56, (byte)57, (byte)65, (byte)66, (byte)67, (byte)68, (byte)69, (byte)70) : Vector128.Create((byte)48, (byte)49, (byte)50, (byte)51, (byte)52, (byte)53, (byte)54, (byte)55, (byte)56, (byte)57, (byte)97, (byte)98, (byte)99, (byte)100, (byte)101, (byte)102));
70 do
71 {
72 uint value2 = Unsafe.ReadUnaligned<uint>(ref Unsafe.Add(ref MemoryMarshal.GetReference(bytes), num));
73 Vector128<byte> vector = Ssse3.Shuffle(Vector128.CreateScalarUnsafe(value2).AsByte(), mask);
74 Vector128<byte> right = Sse2.ShiftRightLogical(Sse2.ShiftRightLogical128BitLane(vector, 2).AsInt32(), 4).AsByte();
75 Vector128<byte> mask2 = Sse2.And(Sse2.Or(vector, right), Vector128.Create((byte)15));
76 Vector128<byte> left = Ssse3.Shuffle(value, mask2);
77 left = Sse2.And(left, Vector128.Create((ushort)255).AsByte());
78 Unsafe.WriteUnaligned(ref Unsafe.As<char, byte>(ref Unsafe.Add(ref MemoryMarshal.GetReference(chars), num * 2)), left);
79 num += 4;
80 }
81 while (num < bytes.Length - 3);
82 for (; num < bytes.Length; num++)
83 {
84 ToCharsBuffer(Unsafe.Add(ref MemoryMarshal.GetReference(bytes), num), chars, (int)num * 2, casing);
85 }
86 }
static void ToCharsBuffer(byte value, Span< char > buffer, int startingIndex=0, Casing casing=Casing.Upper)
static Vector128< byte > Create(byte value)
Definition Vector128.cs:138
static unsafe Vector128< byte > CreateScalarUnsafe(byte value)
Definition Vector128.cs:829
static Vector128< sbyte > ShiftRightLogical128BitLane(Vector128< sbyte > value, byte numBytes)
Definition Sse2.cs:1117
static Vector128< byte > Or(Vector128< byte > left, Vector128< byte > right)
Definition Sse2.cs:837
static Vector128< byte > And(Vector128< byte > left, Vector128< byte > right)
Definition Sse2.cs:132
static Vector128< short > ShiftRightLogical(Vector128< short > value, Vector128< short > count)
Definition Sse2.cs:1057
static Vector128< sbyte > Shuffle(Vector128< sbyte > value, Vector128< sbyte > mask)
Definition Ssse3.cs:112

References System.Runtime.Intrinsics.X86.Sse2.And(), System.bytes, System.chars, System.Runtime.Intrinsics.Vector128< T >.Create(), System.Runtime.Intrinsics.Vector128< T >.CreateScalarUnsafe(), System.Runtime.Intrinsics.X86.Sse2.Or(), System.Runtime.Intrinsics.X86.Sse2.ShiftRightLogical(), System.Runtime.Intrinsics.X86.Sse2.ShiftRightLogical128BitLane(), System.Runtime.Intrinsics.X86.Ssse3.Shuffle(), System.HexConverter.ToCharsBuffer(), and System.value.

Referenced by System.HexConverter.EncodeToUtf16().