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

◆ IndexOfAny() [2/6]

static int System.SpanHelpers.IndexOfAny ( ref byte searchSpace,
byte value0,
byte value1,
int length )
inlinestatic

Definition at line 509 of file SpanHelpers.cs.

510 {
511 nuint num = 0u;
512 nuint num2 = (uint)length;
514 {
515 nint num3 = (nint)length - (nint)Vector128<byte>.Count;
516 if (num3 >= 0)
517 {
518 num2 = (nuint)num3;
519 goto IL_0212;
520 }
521 }
523 {
524 nint num4 = (nint)length - (nint)Vector<byte>.Count;
525 if (num4 >= 0)
526 {
527 num2 = (nuint)num4;
528 goto IL_0212;
529 }
530 }
531 while (num2 >= 8)
532 {
533 num2 -= 8;
534 uint num5 = Unsafe.AddByteOffset(ref searchSpace, num);
535 if (value0 == num5 || value1 == num5)
536 {
537 goto IL_01e5;
538 }
539 num5 = Unsafe.AddByteOffset(ref searchSpace, num + 1);
540 if (value0 == num5 || value1 == num5)
541 {
542 goto IL_01e8;
543 }
544 num5 = Unsafe.AddByteOffset(ref searchSpace, num + 2);
545 if (value0 == num5 || value1 == num5)
546 {
547 goto IL_01ee;
548 }
549 num5 = Unsafe.AddByteOffset(ref searchSpace, num + 3);
550 if (value0 != num5 && value1 != num5)
551 {
552 num5 = Unsafe.AddByteOffset(ref searchSpace, num + 4);
553 if (value0 != num5 && value1 != num5)
554 {
555 num5 = Unsafe.AddByteOffset(ref searchSpace, num + 5);
556 if (value0 != num5 && value1 != num5)
557 {
558 num5 = Unsafe.AddByteOffset(ref searchSpace, num + 6);
559 if (value0 != num5 && value1 != num5)
560 {
561 num5 = Unsafe.AddByteOffset(ref searchSpace, num + 7);
562 if (value0 != num5 && value1 != num5)
563 {
564 num += 8;
565 continue;
566 }
567 return (int)(num + 7);
568 }
569 return (int)(num + 6);
570 }
571 return (int)(num + 5);
572 }
573 return (int)(num + 4);
574 }
575 goto IL_01f4;
576 }
577 if (num2 >= 4)
578 {
579 num2 -= 4;
580 uint num5 = Unsafe.AddByteOffset(ref searchSpace, num);
581 if (value0 == num5 || value1 == num5)
582 {
583 goto IL_01e5;
584 }
585 num5 = Unsafe.AddByteOffset(ref searchSpace, num + 1);
586 if (value0 == num5 || value1 == num5)
587 {
588 goto IL_01e8;
589 }
590 num5 = Unsafe.AddByteOffset(ref searchSpace, num + 2);
591 if (value0 == num5 || value1 == num5)
592 {
593 goto IL_01ee;
594 }
595 num5 = Unsafe.AddByteOffset(ref searchSpace, num + 3);
596 if (value0 == num5 || value1 == num5)
597 {
598 goto IL_01f4;
599 }
600 num += 4;
601 }
602 while (num2 != 0)
603 {
604 uint num5 = Unsafe.AddByteOffset(ref searchSpace, num);
605 if (value0 != num5 && value1 != num5)
606 {
607 num++;
608 num2--;
609 continue;
610 }
611 goto IL_01e5;
612 }
613 goto IL_01e3;
614 IL_0212:
615 int num6;
616 if (Sse2.IsSupported)
617 {
618 if (Avx2.IsSupported && num2 >= (nuint)Vector128<byte>.Count)
619 {
622 num2 -= (nuint)Vector128<byte>.Count;
623 Vector256<byte> right;
624 while (num2 > num)
625 {
626 right = LoadVector256(ref searchSpace, num);
627 num6 = Avx2.MoveMask(Avx2.Or(Avx2.CompareEqual(left, right), Avx2.CompareEqual(left2, right)));
628 if (num6 == 0)
629 {
630 num += (nuint)Vector256<byte>.Count;
631 continue;
632 }
633 goto IL_033c;
634 }
636 num = num2;
637 num6 = Avx2.MoveMask(Avx2.Or(Avx2.CompareEqual(left, right), Avx2.CompareEqual(left2, right)));
638 if (num6 == 0)
639 {
640 goto IL_01e3;
641 }
642 }
643 else
644 {
648 while (num2 > num)
649 {
652 if (num6 == 0)
653 {
654 num += (nuint)Vector128<byte>.Count;
655 continue;
656 }
657 goto IL_033c;
658 }
660 num = num2;
662 if (num6 == 0)
663 {
664 goto IL_01e3;
665 }
666 }
667 goto IL_033c;
668 }
670 {
671 }
673 {
674 goto IL_01e5;
675 }
679 while (num2 > num)
680 {
683 if (Vector<byte>.Zero.Equals(left5))
684 {
685 num += (nuint)Vector<byte>.Count;
686 continue;
687 }
688 goto IL_03ec;
689 }
691 num = num2;
693 if (Vector<byte>.Zero.Equals(left5))
694 {
695 goto IL_01e3;
696 }
697 goto IL_03ec;
698 IL_033c:
699 num += (nuint)BitOperations.TrailingZeroCount(num6);
700 goto IL_01e5;
701 IL_01e3:
702 return -1;
703 IL_01e5:
704 return (int)num;
705 IL_03ec:
706 num += (nuint)LocateFirstFoundByte(left5);
707 goto IL_01e5;
708 IL_01ee:
709 return (int)(num + 2);
710 IL_01e8:
711 return (int)(num + 1);
712 IL_01f4:
713 return (int)(num + 3);
714 }
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 Vector256< sbyte > Or(Vector256< sbyte > left, Vector256< sbyte > right)
Definition Avx2.cs:1638
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 Vector128< byte > Or(Vector128< byte > left, Vector128< byte > right)
Definition Sse2.cs:837
static new bool IsSupported
Definition Sse2.cs:60
static Vector< byte > LoadVector(ref byte start, nuint offset)
static Vector128< byte > LoadVector128(ref byte start, nuint offset)
static int LocateFirstFoundByte(Vector< byte > match)
static Vector256< byte > LoadVector256(ref byte start, nuint offset)

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.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.Runtime.Intrinsics.X86.Sse2.Or(), System.Runtime.Intrinsics.X86.Avx2.Or(), and System.Numerics.BitOperations.TrailingZeroCount().

Referenced by System.MemoryExtensions.IndexOfAny< T >(), System.MemoryExtensions.IndexOfAny< T >(), System.MemoryExtensions.IndexOfAny< T >(), System.MemoryExtensions.IndexOfAny< T >(), and System.MemoryExtensions.IndexOfAny< T >().