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

◆ IndexOf() [3/4]

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

Definition at line 1760 of file SpanHelpers.cs.

1761 {
1762 nint num = 0;
1763 nint num2 = length;
1764 if (((int)Unsafe.AsPointer(ref searchSpace) & 1) == 0)
1765 {
1767 {
1768 if (length >= Vector128<ushort>.Count * 2)
1769 {
1771 }
1772 }
1774 {
1776 }
1777 }
1778 while (true)
1779 {
1780 if (num2 >= 4)
1781 {
1782 ref char reference = ref Unsafe.Add(ref searchSpace, num);
1783 if (value == reference)
1784 {
1785 break;
1786 }
1787 if (value != Unsafe.Add(ref reference, 1))
1788 {
1789 if (value != Unsafe.Add(ref reference, 2))
1790 {
1791 if (value != Unsafe.Add(ref reference, 3))
1792 {
1793 num += 4;
1794 num2 -= 4;
1795 continue;
1796 }
1797 return (int)(num + 3);
1798 }
1799 return (int)(num + 2);
1800 }
1801 return (int)(num + 1);
1802 }
1803 while (num2 > 0)
1804 {
1805 if (value == Unsafe.Add(ref searchSpace, num))
1806 {
1807 goto end_IL_0090;
1808 }
1809 num++;
1810 num2--;
1811 }
1812 if (Avx2.IsSupported)
1813 {
1814 if (num < length)
1815 {
1816 if (((nuint)Unsafe.AsPointer(ref Unsafe.Add(ref searchSpace, num)) & (nuint)(Vector256<byte>.Count - 1)) != 0)
1817 {
1820 int num3 = Sse2.MoveMask(Sse2.CompareEqual(left, right).AsByte());
1821 if (num3 != 0)
1822 {
1823 return (int)(num + (uint)BitOperations.TrailingZeroCount(num3) / 2u);
1824 }
1825 num += Vector128<ushort>.Count;
1826 }
1828 if (num2 > 0)
1829 {
1831 do
1832 {
1834 int num4 = Avx2.MoveMask(Avx2.CompareEqual(left2, right2).AsByte());
1835 if (num4 == 0)
1836 {
1837 num += Vector256<ushort>.Count;
1839 continue;
1840 }
1841 return (int)(num + (uint)BitOperations.TrailingZeroCount(num4) / 2u);
1842 }
1843 while (num2 > 0);
1844 }
1846 if (num2 > 0)
1847 {
1850 int num5 = Sse2.MoveMask(Sse2.CompareEqual(left3, right3).AsByte());
1851 if (num5 != 0)
1852 {
1853 return (int)(num + (uint)BitOperations.TrailingZeroCount(num5) / 2u);
1854 }
1855 num += Vector128<ushort>.Count;
1856 }
1857 if (num < length)
1858 {
1859 num2 = length - num;
1860 continue;
1861 }
1862 }
1863 }
1864 else if (Sse2.IsSupported)
1865 {
1866 if (num < length)
1867 {
1869 if (num2 > 0)
1870 {
1872 do
1873 {
1875 int num6 = Sse2.MoveMask(Sse2.CompareEqual(left4, right4).AsByte());
1876 if (num6 == 0)
1877 {
1878 num += Vector128<ushort>.Count;
1880 continue;
1881 }
1882 return (int)(num + (uint)BitOperations.TrailingZeroCount(num6) / 2u);
1883 }
1884 while (num2 > 0);
1885 }
1886 if (num < length)
1887 {
1888 num2 = length - num;
1889 continue;
1890 }
1891 }
1892 }
1893 else
1894 {
1896 {
1897 }
1898 if (Vector.IsHardwareAccelerated && num < length)
1899 {
1901 if (num2 > 0)
1902 {
1904 do
1905 {
1907 if (Vector<ushort>.Zero.Equals(vector))
1908 {
1909 num += Vector<ushort>.Count;
1911 continue;
1912 }
1913 return (int)(num + LocateFirstFoundChar(vector));
1914 }
1915 while (num2 > 0);
1916 }
1917 if (num < length)
1918 {
1919 num2 = length - num;
1920 continue;
1921 }
1922 }
1923 }
1924 return -1;
1925 continue;
1927 break;
1928 }
1929 return (int)num;
1930 }
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 nint GetCharVector128SpanLength(nint offset, nint length)
static unsafe nuint UnalignedCountVector(ref byte searchSpace)
static nint GetCharVector256SpanLength(nint offset, nint length)
static Vector< byte > LoadVector(ref byte start, nuint offset)
static nint GetCharVectorSpanLength(nint offset, nint length)
static Vector128< byte > LoadVector128(ref byte start, nuint offset)
static int LocateFirstFoundChar(Vector< ushort > match)
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.GetCharVector128SpanLength(), System.SpanHelpers.GetCharVector256SpanLength(), System.SpanHelpers.GetCharVectorSpanLength(), 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.LocateFirstFoundChar(), 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.