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

◆ GetIndexOfFirstNonAsciiByte_Intrinsified()

static unsafe nuint System.Text.ASCIIUtility.GetIndexOfFirstNonAsciiByte_Intrinsified ( byte * pBuffer,
nuint bufferLength )
inlinestaticprivate

Definition at line 134 of file ASCIIUtility.cs.

135 {
136 uint num = (uint)Unsafe.SizeOf<Vector128<byte>>();
137 nuint num2 = num - 1;
138 if (!BitConverter.IsLittleEndian)
139 {
140 }
141 Vector128<byte> vector = Vector128.Create((ushort)4097).AsByte();
142 uint num3 = uint.MaxValue;
143 uint num4 = uint.MaxValue;
144 uint num5 = uint.MaxValue;
145 uint num6 = uint.MaxValue;
146 byte* ptr = pBuffer;
147 if (bufferLength >= num)
148 {
149 if (Sse2.IsSupported)
150 {
151 num3 = (uint)Sse2.MoveMask(Sse2.LoadVector128(pBuffer));
152 if (!ContainsNonAsciiByte_Sse2(num3))
153 {
154 if (bufferLength < 2 * num)
155 {
156 goto IL_0122;
157 }
158 pBuffer = (byte*)((nuint)(pBuffer + num) & ~num2);
159 bufferLength = (nuint)(bufferLength + ptr);
160 bufferLength -= (nuint)pBuffer;
161 if (bufferLength < 2 * num)
162 {
163 goto IL_00ef;
164 }
165 byte* ptr2 = pBuffer + bufferLength - 2 * num;
166 while (true)
167 {
168 if (Sse2.IsSupported)
169 {
171 Vector128<byte> value2 = Sse2.LoadAlignedVector128(pBuffer + num);
172 num3 = (uint)Sse2.MoveMask(value);
173 num4 = (uint)Sse2.MoveMask(value2);
174 if (ContainsNonAsciiByte_Sse2(num3 | num4))
175 {
176 break;
177 }
178 pBuffer += 2 * num;
179 if (pBuffer <= ptr2)
180 {
181 continue;
182 }
183 goto IL_00ef;
184 }
186 {
187 }
188 throw new PlatformNotSupportedException();
189 }
190 if (!Sse2.IsSupported)
191 {
193 {
194 }
195 throw new PlatformNotSupportedException();
196 }
197 if (!ContainsNonAsciiByte_Sse2(num3))
198 {
199 pBuffer += num;
200 num3 = num4;
201 }
202 }
203 goto IL_0197;
204 }
206 {
207 }
208 throw new PlatformNotSupportedException();
209 }
210 if ((bufferLength & 8) != 0)
211 {
212 _ = UIntPtr.Size;
213 ulong num7 = Unsafe.ReadUnaligned<ulong>(pBuffer);
214 if (!AllBytesInUInt64AreAscii(num7))
215 {
216 num7 &= 0x8080808080808080uL;
217 pBuffer += (nuint)(BitOperations.TrailingZeroCount(num7) >> 3);
218 goto IL_016b;
219 }
220 pBuffer += 8;
221 }
222 if ((bufferLength & 4) != 0)
223 {
224 uint value3 = Unsafe.ReadUnaligned<uint>(pBuffer);
225 if (!AllBytesInUInt32AreAscii(value3))
226 {
228 goto IL_016b;
229 }
230 pBuffer += 4;
231 }
232 if ((bufferLength & 2) != 0)
233 {
234 uint value3 = Unsafe.ReadUnaligned<ushort>(pBuffer);
235 if (!AllBytesInUInt32AreAscii(value3))
236 {
237 pBuffer += (nuint)(((nint)(sbyte)value3 >> 7) + 1);
238 goto IL_016b;
239 }
240 pBuffer += 2;
241 }
242 if ((bufferLength & 1) != 0 && *pBuffer >= 0)
243 {
244 pBuffer++;
245 }
246 goto IL_016b;
247 IL_00ef:
248 if ((bufferLength & num) == 0)
249 {
250 goto IL_0128;
251 }
252 if (Sse2.IsSupported)
253 {
254 num3 = (uint)Sse2.MoveMask(Sse2.LoadAlignedVector128(pBuffer));
255 if (!ContainsNonAsciiByte_Sse2(num3))
256 {
257 goto IL_0122;
258 }
259 goto IL_0197;
260 }
262 {
263 }
264 throw new PlatformNotSupportedException();
265 IL_016b:
266 return (nuint)(pBuffer - (nuint)ptr);
267 IL_0122:
268 pBuffer += num;
269 goto IL_0128;
270 IL_0197:
271 if (Sse2.IsSupported)
272 {
273 pBuffer += (uint)BitOperations.TrailingZeroCount(num3);
274 goto IL_016b;
275 }
277 {
278 }
279 throw new PlatformNotSupportedException();
280 IL_0128:
281 if (((byte)bufferLength & num2) != 0)
282 {
283 pBuffer += (bufferLength & num2) - num;
284 if (!Sse2.IsSupported)
285 {
287 {
288 }
289 throw new PlatformNotSupportedException();
290 }
291 num3 = (uint)Sse2.MoveMask(Sse2.LoadVector128(pBuffer));
293 {
294 goto IL_0197;
295 }
296 pBuffer += num;
297 }
298 goto IL_016b;
299 }
static int TrailingZeroCount(int value)
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 unsafe Vector128< sbyte > LoadAlignedVector128(sbyte *address)
Definition Sse2.cs:632
static new bool IsSupported
Definition Sse2.cs:60
static uint CountNumberOfLeadingAsciiBytesFromUInt32WithSomeNonAsciiData(uint value)
static bool ContainsNonAsciiByte_Sse2(uint sseMask)
static bool AllBytesInUInt32AreAscii(uint value)
static bool AllBytesInUInt64AreAscii(ulong value)

References System.Text.ASCIIUtility.AllBytesInUInt32AreAscii(), System.Text.ASCIIUtility.AllBytesInUInt64AreAscii(), System.Text.ASCIIUtility.ContainsNonAsciiByte_Sse2(), System.Text.ASCIIUtility.CountNumberOfLeadingAsciiBytesFromUInt32WithSomeNonAsciiData(), System.Runtime.Intrinsics.Vector128< T >.Create(), System.BitConverter.IsLittleEndian, System.Runtime.Intrinsics.Arm.AdvSimd.Arm64.IsSupported, System.Runtime.Intrinsics.Arm.AdvSimd.IsSupported, System.Runtime.Intrinsics.X86.Sse2.IsSupported, System.Runtime.Intrinsics.X86.Sse2.LoadAlignedVector128(), System.Runtime.Intrinsics.X86.Sse2.LoadVector128(), System.Runtime.Intrinsics.X86.Sse2.MoveMask(), System.UIntPtr.Size, System.Numerics.BitOperations.TrailingZeroCount(), and System.value.

Referenced by System.Text.ASCIIUtility.GetIndexOfFirstNonAsciiByte().