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

◆ IndexOfAny() [1/6]

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

Definition at line 717 of file SpanHelpers.cs.

718 {
719 nuint num = 0u;
720 nuint num2 = (uint)length;
722 {
723 if (length >= Vector128<byte>.Count * 2)
724 {
726 }
727 }
729 {
731 }
732 while (true)
733 {
734 if (num2 >= 8)
735 {
736 num2 -= 8;
737 uint num3 = Unsafe.AddByteOffset(ref searchSpace, num);
738 if (value0 == num3 || value1 == num3 || value2 == num3)
739 {
740 goto IL_0504;
741 }
742 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 1);
743 if (value0 == num3 || value1 == num3 || value2 == num3)
744 {
745 goto IL_0507;
746 }
747 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 2);
748 if (value0 == num3 || value1 == num3 || value2 == num3)
749 {
750 goto IL_050d;
751 }
752 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 3);
753 if (value0 != num3 && value1 != num3 && value2 != num3)
754 {
755 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 4);
756 if (value0 != num3 && value1 != num3 && value2 != num3)
757 {
758 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 5);
759 if (value0 != num3 && value1 != num3 && value2 != num3)
760 {
761 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 6);
762 if (value0 != num3 && value1 != num3 && value2 != num3)
763 {
764 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 7);
765 if (value0 == num3 || value1 == num3 || value2 == num3)
766 {
767 break;
768 }
769 num += 8;
770 continue;
771 }
772 return (int)(num + 6);
773 }
774 return (int)(num + 5);
775 }
776 return (int)(num + 4);
777 }
778 goto IL_0513;
779 }
780 if (num2 >= 4)
781 {
782 num2 -= 4;
783 uint num3 = Unsafe.AddByteOffset(ref searchSpace, num);
784 if (value0 == num3 || value1 == num3 || value2 == num3)
785 {
786 goto IL_0504;
787 }
788 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 1);
789 if (value0 == num3 || value1 == num3 || value2 == num3)
790 {
791 goto IL_0507;
792 }
793 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 2);
794 if (value0 == num3 || value1 == num3 || value2 == num3)
795 {
796 goto IL_050d;
797 }
798 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 3);
799 if (value0 == num3 || value1 == num3 || value2 == num3)
800 {
801 goto IL_0513;
802 }
803 num += 4;
804 }
805 while (num2 != 0)
806 {
807 num2--;
808 uint num3 = Unsafe.AddByteOffset(ref searchSpace, num);
809 if (value0 != num3 && value1 != num3 && value2 != num3)
810 {
811 num++;
812 continue;
813 }
814 goto IL_0504;
815 }
816 if (Avx2.IsSupported)
817 {
818 if (num < (uint)length)
819 {
821 if (num2 > num)
822 {
826 do
827 {
829 Vector256<byte> left4 = Avx2.CompareEqual(left, right);
833 if (num4 == 0)
834 {
835 num += (nuint)Vector256<byte>.Count;
836 continue;
837 }
838 return (int)(num + (uint)BitOperations.TrailingZeroCount(num4));
839 }
840 while (num2 > num);
841 }
843 if (num2 > num)
844 {
853 if (num5 != 0)
854 {
855 return (int)(num + (uint)BitOperations.TrailingZeroCount(num5));
856 }
857 num += (nuint)Vector128<byte>.Count;
858 }
859 if (num < (uint)length)
860 {
861 num2 = (uint)length - num;
862 continue;
863 }
864 }
865 }
866 else if (Sse2.IsSupported)
867 {
868 if (num < (uint)length)
869 {
874 for (; num2 > num; num += (nuint)Vector128<byte>.Count)
875 {
881 if (num6 != 0)
882 {
883 return (int)(num + (uint)BitOperations.TrailingZeroCount(num6));
884 }
885 }
886 if (num < (uint)length)
887 {
888 num2 = (uint)length - num;
889 continue;
890 }
891 }
892 }
893 else
894 {
896 {
897 }
898 if (Vector.IsHardwareAccelerated && num < (uint)length)
899 {
904 for (; num2 > num; num += (nuint)Vector<byte>.Count)
905 {
908 if (!Vector<byte>.Zero.Equals(vector))
909 {
910 return (int)num + LocateFirstFoundByte(vector);
911 }
912 }
913 if (num < (uint)length)
914 {
915 num2 = (uint)length - num;
916 continue;
917 }
918 }
919 }
920 return -1;
921 IL_0507:
922 return (int)(num + 1);
923 IL_0513:
924 return (int)(num + 3);
925 IL_050d:
926 return (int)(num + 2);
927 IL_0504:
928 return (int)num;
929 }
930 return (int)(num + 7);
931 }
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 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.Runtime.Intrinsics.X86.Sse2.Or(), System.Runtime.Intrinsics.X86.Avx2.Or(), System.Numerics.BitOperations.TrailingZeroCount(), System.SpanHelpers.UnalignedCountVector(), and System.SpanHelpers.UnalignedCountVector128().