Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Utf16Utility.cs
Go to the documentation of this file.
7
8namespace System.Text.Unicode;
9
10internal static class Utf16Utility
11{
12 [MethodImpl(MethodImplOptions.AggressiveInlining)]
13 internal static bool AllCharsInUInt32AreAscii(uint value)
14 {
15 return (value & 0xFF80FF80u) == 0;
16 }
17
18 [MethodImpl(MethodImplOptions.AggressiveInlining)]
19 internal static bool AllCharsInUInt64AreAscii(ulong value)
20 {
21 return (value & 0xFF80FF80FF80FF80uL) == 0;
22 }
23
24 [MethodImpl(MethodImplOptions.AggressiveInlining)]
26 {
27 uint num = value + 8388736 - 4259905;
28 uint num2 = value + 8388736 - 5963867;
29 uint num3 = num ^ num2;
30 uint num4 = (num3 & 0x800080) >> 2;
31 return value ^ num4;
32 }
33
34 [MethodImpl(MethodImplOptions.AggressiveInlining)]
36 {
37 uint num = value + 8388736 - 6357089;
38 uint num2 = value + 8388736 - 8061051;
39 uint num3 = num ^ num2;
40 uint num4 = (num3 & 0x800080) >> 2;
41 return value ^ num4;
42 }
43
44 [MethodImpl(MethodImplOptions.AggressiveInlining)]
45 internal static bool UInt32ContainsAnyLowercaseAsciiChar(uint value)
46 {
47 uint num = value + 8388736 - 6357089;
48 uint num2 = value + 8388736 - 8061051;
49 uint num3 = num ^ num2;
50 return (num3 & 0x800080) != 0;
51 }
52
53 [MethodImpl(MethodImplOptions.AggressiveInlining)]
54 internal static bool UInt32ContainsAnyUppercaseAsciiChar(uint value)
55 {
56 uint num = value + 8388736 - 4259905;
57 uint num2 = value + 8388736 - 5963867;
58 uint num3 = num ^ num2;
59 return (num3 & 0x800080) != 0;
60 }
61
62 [MethodImpl(MethodImplOptions.AggressiveInlining)]
63 internal static bool UInt32OrdinalIgnoreCaseAscii(uint valueA, uint valueB)
64 {
65 uint num = (valueA ^ valueB) << 2;
66 uint num2 = valueA + 327685;
67 num2 |= 0xA000A0u;
68 num2 += 1703962;
69 num2 |= 0xFF7FFF7Fu;
70 return (num & num2) == 0;
71 }
72
73 [MethodImpl(MethodImplOptions.AggressiveInlining)]
74 internal static bool UInt64OrdinalIgnoreCaseAscii(ulong valueA, ulong valueB)
75 {
76 ulong num = (valueA ^ valueB) << 2;
77 ulong num2 = valueA + 1407396358717445L;
78 num2 |= 0xA000A000A000A0uL;
79 num2 += 7318461065330714L;
80 num2 |= 0xFF7FFF7FFF7FFF7FuL;
81 return (num & num2) == 0;
82 }
83
84 public unsafe static char* GetPointerToFirstInvalidChar(char* pInputBuffer, int inputLength, out long utf8CodeUnitCountAdjustment, out int scalarCountAdjustment)
85 {
86 int num = (int)ASCIIUtility.GetIndexOfFirstNonAsciiChar(pInputBuffer, (uint)inputLength);
87 pInputBuffer += (uint)num;
88 inputLength -= num;
89 if (inputLength == 0)
90 {
91 utf8CodeUnitCountAdjustment = 0L;
92 scalarCountAdjustment = 0;
93 return pInputBuffer;
94 }
95 long num2 = 0L;
96 int num3 = 0;
97 char* ptr = pInputBuffer + (uint)inputLength;
99 {
100 if (inputLength >= Vector128<ushort>.Count)
101 {
102 Vector128<ushort> right = Vector128.Create((ushort)128);
103 Vector128<ushort> vector = Vector128.Create((ushort)30720);
104 Vector128<ushort> right2 = Vector128.Create((ushort)40960);
106 {
107 }
108 Vector128<byte> vector2 = Vector128.Create(9241421688590303745uL).AsByte();
109 char* ptr2 = ptr - Vector128<ushort>.Count;
110 do
111 {
113 {
114 }
115 Vector128<ushort> vector3 = Sse2.LoadVector128((ushort*)pInputBuffer);
116 pInputBuffer += Vector128<ushort>.Count;
118 {
119 }
120 Vector128<ushort> left = Sse41.Min(vector3, right);
122 {
123 }
124 Vector128<ushort> right3 = Sse2.AddSaturate(vector3, vector);
125 uint value = (uint)Sse2.MoveMask(Sse2.Or(left, right3).AsByte());
126 nuint num4 = (uint)BitOperations.PopCount(value);
128 {
129 }
130 value = (uint)Sse2.MoveMask(Sse2.CompareLessThan(Sse2.Add(vector3, right2).AsInt16(), vector.AsInt16()).AsByte());
131 while (value != 65535)
132 {
133 value = ~value;
135 {
136 }
137 uint num5 = (uint)Sse2.MoveMask(Sse2.ShiftRightLogical(vector3, 3).AsByte());
138 uint num6 = num5 & value;
139 uint num7 = (num5 ^ 0x5555u) & value;
140 num7 <<= 2;
141 if ((ushort)num7 == num6)
142 {
143 if (num7 > 65535)
144 {
145 num7 = (ushort)num7;
146 num4 -= 2;
147 pInputBuffer--;
148 }
149 nuint num8 = (uint)BitOperations.PopCount(num7);
150 num3 -= (int)num8;
151 _ = IntPtr.Size;
152 num2 -= (long)num8;
153 num2 -= (long)num8;
154 value = 65535u;
155 continue;
156 }
157 goto IL_01c6;
158 }
159 num2 += (long)num4;
160 continue;
161 IL_01c6:
162 pInputBuffer -= Vector128<ushort>.Count;
163 break;
164 }
165 while (pInputBuffer <= ptr2);
166 }
167 }
168 else if (Vector.IsHardwareAccelerated && inputLength >= Vector<ushort>.Count)
169 {
170 Vector<ushort> right4 = new Vector<ushort>(128);
171 Vector<ushort> right5 = new Vector<ushort>(1024);
172 Vector<ushort> right6 = new Vector<ushort>(2048);
173 Vector<ushort> vector4 = new Vector<ushort>(55296);
174 char* ptr3 = ptr - Vector<ushort>.Count;
175 while (true)
176 {
177 Vector<ushort> left2 = Unsafe.ReadUnaligned<Vector<ushort>>(pInputBuffer);
178 Vector<ushort> vector5 = Vector.GreaterThanOrEqual(left2, right4);
179 Vector<ushort> vector6 = Vector.GreaterThanOrEqual(left2, right6);
180 Vector<UIntPtr> vector7 = (Vector<nuint>)(Vector<ushort>.Zero - vector5 - vector6);
181 nuint num9 = 0u;
182 for (int i = 0; i < Vector<UIntPtr>.Count; i++)
183 {
184 num9 += (nuint)(nint)(nuint)vector7[i];
185 }
186 uint num10 = (uint)num9;
187 _ = IntPtr.Size;
188 num10 += (uint)(int)(num9 >> 32);
189 num10 = (ushort)num10 + (num10 >> 16);
190 left2 -= vector4;
191 Vector<ushort> vector8 = Vector.LessThan(left2, right6);
192 if (vector8 != Vector<ushort>.Zero)
193 {
194 Vector<ushort> right7 = Vector.LessThan(left2, right5);
195 Vector<ushort> vector9 = Vector.AndNot(vector8, right7);
196 if (vector9[0] != 0)
197 {
198 break;
199 }
200 ushort num11 = 0;
201 int num12 = 0;
202 while (num12 < Vector<ushort>.Count - 1)
203 {
204 num11 -= right7[num12];
205 if (right7[num12] == vector9[num12 + 1])
206 {
207 num12++;
208 continue;
209 }
210 goto IL_03e0;
211 }
212 if (right7[Vector<ushort>.Count - 1] != 0)
213 {
214 pInputBuffer--;
215 num10 -= 2;
216 }
217 nint num13 = num11;
218 num3 -= (int)num13;
219 num2 -= num13;
220 num2 -= num13;
221 }
222 num2 += num10;
223 pInputBuffer += Vector<ushort>.Count;
224 if (pInputBuffer <= ptr3)
225 {
226 continue;
227 }
228 goto IL_03e0;
229 }
230 goto IL_03e4;
231 }
232 goto IL_03e0;
233 IL_03e0:
234 while (pInputBuffer < ptr)
235 {
236 uint num14 = *pInputBuffer;
237 if (num14 > 127)
238 {
239 num2 += num14 + 129024 >> 16;
241 {
242 num2 -= 2;
243 if ((nuint)((byte*)ptr - (nuint)pInputBuffer) < (nuint)4u)
244 {
245 break;
246 }
247 num14 = Unsafe.ReadUnaligned<uint>(pInputBuffer);
248 uint num15 = num14;
250 {
251 }
252 if (((num15 - 3691042816u) & 0xFC00FC00u) != 0)
253 {
254 break;
255 }
256 num3--;
257 num2 += 2;
258 pInputBuffer++;
259 }
260 }
261 pInputBuffer++;
262 }
263 goto IL_03e4;
264 IL_03e4:
265 utf8CodeUnitCountAdjustment = num2;
266 scalarCountAdjustment = num3;
267 return pInputBuffer;
268 }
269}
static readonly bool IsLittleEndian
static int PopCount(uint value)
static Vector< int > LessThan(Vector< float > left, Vector< float > right)
Definition Vector.cs:99
static bool IsHardwareAccelerated
Definition Vector.cs:14
static Vector< int > GreaterThanOrEqual(Vector< float > left, Vector< float > right)
Definition Vector.cs:240
static Vector128< byte > Create(byte value)
Definition Vector128.cs:138
static unsafe Vector128< sbyte > LoadVector128(sbyte *address)
Definition Sse2.cs:582
static int MoveMask(Vector128< sbyte > value)
Definition Sse2.cs:772
static Vector128< sbyte > CompareLessThan(Vector128< sbyte > left, Vector128< sbyte > right)
Definition Sse2.cs:337
static Vector128< byte > Or(Vector128< byte > left, Vector128< byte > right)
Definition Sse2.cs:837
static Vector128< sbyte > AddSaturate(Vector128< sbyte > left, Vector128< sbyte > right)
Definition Sse2.cs:112
static Vector128< byte > Add(Vector128< byte > left, Vector128< byte > right)
Definition Sse2.cs:62
static Vector128< short > ShiftRightLogical(Vector128< short > value, Vector128< short > count)
Definition Sse2.cs:1057
static Vector128< sbyte > Min(Vector128< sbyte > left, Vector128< sbyte > right)
Definition Sse41.cs:372
static unsafe nuint GetIndexOfFirstNonAsciiChar(char *pBuffer, nuint bufferLength)
static bool IsSurrogateCodePoint(uint value)
static bool UInt32OrdinalIgnoreCaseAscii(uint valueA, uint valueB)
static uint ConvertAllAsciiCharsInUInt32ToLowercase(uint value)
static bool AllCharsInUInt32AreAscii(uint value)
static bool UInt64OrdinalIgnoreCaseAscii(ulong valueA, ulong valueB)
static uint ConvertAllAsciiCharsInUInt32ToUppercase(uint value)
static bool UInt32ContainsAnyUppercaseAsciiChar(uint value)
static bool UInt32ContainsAnyLowercaseAsciiChar(uint value)
static bool AllCharsInUInt64AreAscii(ulong value)
static unsafe char * GetPointerToFirstInvalidChar(char *pInputBuffer, int inputLength, out long utf8CodeUnitCountAdjustment, out int scalarCountAdjustment)
static int Size
Definition IntPtr.cs:21