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

◆ IndexOf() [1/4]

static unsafe int System.SpanHelpers.IndexOf ( ref byte searchSpace,
byte value,
int length )
inlinestatic

Definition at line 167 of file SpanHelpers.cs.

168 {
169 nuint num = 0u;
170 nuint num2 = (uint)length;
172 {
173 if (length >= Vector128<byte>.Count * 2)
174 {
176 }
177 }
179 {
181 }
182 while (true)
183 {
184 if (num2 >= 8)
185 {
186 num2 -= 8;
187 if (value == Unsafe.AddByteOffset(ref searchSpace, num))
188 {
189 goto IL_033c;
190 }
191 if (value == Unsafe.AddByteOffset(ref searchSpace, num + 1))
192 {
193 goto IL_033f;
194 }
195 if (value == Unsafe.AddByteOffset(ref searchSpace, num + 2))
196 {
197 goto IL_0345;
198 }
199 if (value != Unsafe.AddByteOffset(ref searchSpace, num + 3))
200 {
201 if (value != Unsafe.AddByteOffset(ref searchSpace, num + 4))
202 {
203 if (value != Unsafe.AddByteOffset(ref searchSpace, num + 5))
204 {
205 if (value != Unsafe.AddByteOffset(ref searchSpace, num + 6))
206 {
207 if (value == Unsafe.AddByteOffset(ref searchSpace, num + 7))
208 {
209 break;
210 }
211 num += 8;
212 continue;
213 }
214 return (int)(num + 6);
215 }
216 return (int)(num + 5);
217 }
218 return (int)(num + 4);
219 }
220 goto IL_034b;
221 }
222 if (num2 >= 4)
223 {
224 num2 -= 4;
225 if (value == Unsafe.AddByteOffset(ref searchSpace, num))
226 {
227 goto IL_033c;
228 }
229 if (value == Unsafe.AddByteOffset(ref searchSpace, num + 1))
230 {
231 goto IL_033f;
232 }
233 if (value == Unsafe.AddByteOffset(ref searchSpace, num + 2))
234 {
235 goto IL_0345;
236 }
237 if (value == Unsafe.AddByteOffset(ref searchSpace, num + 3))
238 {
239 goto IL_034b;
240 }
241 num += 4;
242 }
243 while (num2 != 0)
244 {
245 num2--;
246 if (value != Unsafe.AddByteOffset(ref searchSpace, num))
247 {
248 num++;
249 continue;
250 }
251 goto IL_033c;
252 }
253 if (Avx2.IsSupported)
254 {
255 if (num < (uint)length)
256 {
257 if ((((uint)Unsafe.AsPointer(ref searchSpace) + num) & (nuint)(Vector256<byte>.Count - 1)) != 0)
258 {
261 int num3 = Sse2.MoveMask(Sse2.CompareEqual(left, right));
262 if (num3 != 0)
263 {
264 return (int)(num + (uint)BitOperations.TrailingZeroCount(num3));
265 }
266 num += (nuint)Vector128<byte>.Count;
267 }
269 if (num2 > num)
270 {
272 do
273 {
276 if (num4 == 0)
277 {
278 num += (nuint)Vector256<byte>.Count;
279 continue;
280 }
281 return (int)(num + (uint)BitOperations.TrailingZeroCount(num4));
282 }
283 while (num2 > num);
284 }
286 if (num2 > num)
287 {
291 if (num5 != 0)
292 {
293 return (int)(num + (uint)BitOperations.TrailingZeroCount(num5));
294 }
295 num += (nuint)Vector128<byte>.Count;
296 }
297 if (num < (uint)length)
298 {
299 num2 = (uint)length - num;
300 continue;
301 }
302 }
303 }
304 else if (Sse2.IsSupported)
305 {
306 if (num < (uint)length)
307 {
310 for (; num2 > num; num += (nuint)Vector128<byte>.Count)
311 {
314 if (num6 != 0)
315 {
316 return (int)(num + (uint)BitOperations.TrailingZeroCount(num6));
317 }
318 }
319 if (num < (uint)length)
320 {
321 num2 = (uint)length - num;
322 continue;
323 }
324 }
325 }
326 else
327 {
329 {
330 }
331 if (Vector.IsHardwareAccelerated && num < (uint)length)
332 {
335 for (; num2 > num; num += (nuint)Vector<byte>.Count)
336 {
338 if (!Vector<byte>.Zero.Equals(vector))
339 {
340 return (int)num + LocateFirstFoundByte(vector);
341 }
342 }
343 if (num < (uint)length)
344 {
345 num2 = (uint)length - num;
346 continue;
347 }
348 }
349 }
350 return -1;
351 IL_0345:
352 return (int)(num + 2);
353 IL_033f:
354 return (int)(num + 1);
355 IL_034b:
356 return (int)(num + 3);
357 IL_033c:
358 return (int)num;
359 }
360 return (int)(num + 7);
361 }
static int TrailingZeroCount(int value)
static bool IsHardwareAccelerated
Definition Vector.cs:14
static Vector< int > Equals(Vector< float > left, Vector< float > right)
Definition Vector.cs:52
static Vector128< byte > Create(byte value)
Definition Vector128.cs:138
static Vector256< byte > Create(byte value)
Definition Vector256.cs:105
static int MoveMask(Vector256< sbyte > value)
Definition Avx2.cs:1578
static Vector256< sbyte > CompareEqual(Vector256< sbyte > left, Vector256< sbyte > right)
Definition Avx2.cs:512
static new bool IsSupported
Definition Avx2.cs:15
static int MoveMask(Vector128< sbyte > value)
Definition Sse2.cs:772
static Vector128< sbyte > CompareEqual(Vector128< sbyte > left, Vector128< sbyte > right)
Definition Sse2.cs:232
static new bool IsSupported
Definition Sse2.cs:60
static unsafe nuint UnalignedCountVector(ref byte searchSpace)
static Vector< byte > LoadVector(ref byte start, nuint offset)
static Vector128< byte > LoadVector128(ref byte start, nuint offset)
static nuint GetByteVector256SpanLength(nuint offset, int length)
static nuint GetByteVector128SpanLength(nuint offset, int length)
static int LocateFirstFoundByte(Vector< byte > match)
static nuint GetByteVectorSpanLength(nuint offset, int length)
static Vector256< byte > LoadVector256(ref byte start, nuint offset)
static unsafe nuint UnalignedCountVector128(ref byte searchSpace)

References System.Runtime.Intrinsics.X86.Sse2.CompareEqual(), System.Runtime.Intrinsics.X86.Avx2.CompareEqual(), System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Runtime.Intrinsics.Vector128< T >.Create(), System.Runtime.Intrinsics.Vector256< T >.Create(), System.Numerics.Vector< T >.Equals(), System.SpanHelpers.GetByteVector128SpanLength(), System.SpanHelpers.GetByteVector256SpanLength(), System.SpanHelpers.GetByteVectorSpanLength(), System.Numerics.Vector< T >.IsHardwareAccelerated, System.Runtime.Intrinsics.Arm.AdvSimd.Arm64.IsSupported, System.Runtime.Intrinsics.X86.Avx2.IsSupported, System.Runtime.Intrinsics.X86.Sse2.IsSupported, System.length, System.SpanHelpers.LoadVector(), System.SpanHelpers.LoadVector128(), System.SpanHelpers.LoadVector256(), System.SpanHelpers.LocateFirstFoundByte(), System.Runtime.Intrinsics.X86.Sse2.MoveMask(), System.Runtime.Intrinsics.X86.Avx2.MoveMask(), System.Numerics.BitOperations.TrailingZeroCount(), System.SpanHelpers.UnalignedCountVector(), System.SpanHelpers.UnalignedCountVector128(), and System.value.