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

◆ CopyTo()

unsafe void System.Collections.BitArray.CopyTo ( Array array,
int index )
inline

Implements System.Collections.ICollection.

Definition at line 820 of file BitArray.cs.

821 {
822 if (array == null)
823 {
824 throw new ArgumentNullException("array");
825 }
826 if (index < 0)
827 {
828 throw new ArgumentOutOfRangeException("index", index, System.SR.ArgumentOutOfRange_NeedNonNegNum);
829 }
830 if (array.Rank != 1)
831 {
833 }
834 if (array is int[] array2)
835 {
836 Div32Rem(m_length, out var remainder);
837 if (remainder == 0)
838 {
839 Array.Copy(m_array, 0, array2, index, m_array.Length);
840 return;
841 }
842 int num = m_length - 1 >> 5;
843 Array.Copy(m_array, 0, array2, index, num);
844 array2[index + num] = m_array[num] & ((1 << remainder) - 1);
845 return;
846 }
847 if (array is byte[] array3)
848 {
850 if (array.Length - index < num2)
851 {
853 }
854 uint num3 = (uint)m_length & 7u;
855 if (num3 != 0)
856 {
857 num2--;
858 }
859 Span<byte> destination = array3.AsSpan(index);
860 int remainder2;
861 int num4 = Div4Rem(num2, out remainder2);
862 for (int i = 0; i < num4; i++)
863 {
865 destination = destination.Slice(4);
866 }
867 if (num3 != 0)
868 {
869 destination[remainder2] = (byte)((m_array[num4] >> remainder2 * 8) & ((1 << (int)num3) - 1));
870 }
871 switch (remainder2)
872 {
873 default:
874 return;
875 case 3:
876 destination[2] = (byte)(m_array[num4] >> 16);
877 goto case 2;
878 case 2:
879 destination[1] = (byte)(m_array[num4] >> 8);
880 break;
881 case 1:
882 break;
883 }
884 destination[0] = (byte)m_array[num4];
885 return;
886 }
887 if (array is bool[] array4)
888 {
889 if (array.Length - index < m_length)
890 {
892 }
893 uint num5 = 0u;
894 if (m_length >= 32)
895 {
896 Vector128<byte> vector = Vector128.Create(0L, 72340172838076673L).AsByte();
897 Vector128<byte> vector2 = Vector128.Create(144680345676153346L, 217020518514230019L).AsByte();
898 if (Avx2.IsSupported)
899 {
900 Vector256<byte> mask = Vector256.Create(vector, vector2);
901 Vector256<byte> right = Vector256.Create(9241421688590303745uL).AsByte();
902 Vector256<byte> right2 = Vector256.Create((byte)1);
903 fixed (bool* ptr = &array4[index])
904 {
905 for (; num5 + 32 <= (uint)m_length; num5 += 32)
906 {
907 int value = m_array[num5 / 32];
909 Vector256<byte> left = Avx2.Shuffle(vector3.AsByte(), mask);
910 Vector256<byte> left2 = Avx2.And(left, right);
911 Vector256<byte> source = Avx2.Min(left2, right2);
912 Avx.Store((byte*)(ptr + num5), source);
913 }
914 }
915 }
916 else if (Ssse3.IsSupported)
917 {
918 Vector128<byte> mask2 = vector;
919 Vector128<byte> mask3 = vector2;
920 Vector128<byte> right3 = Vector128.Create((byte)1);
921 Vector128<byte> right4 = (BitConverter.IsLittleEndian ? Vector128.Create(9241421688590303745uL).AsByte() : Vector128.Create(72624976668147840L).AsByte());
922 fixed (bool* ptr2 = &array4[index])
923 {
924 for (; num5 + 32 <= (uint)m_length; num5 += 32)
925 {
926 int value2 = m_array[num5 / 32];
928 Vector128<byte> left3 = Ssse3.Shuffle(vector4.AsByte(), mask2);
929 Vector128<byte> left4 = Sse2.And(left3, right4);
930 Vector128<byte> source2 = Sse2.Min(left4, right3);
931 Sse2.Store((byte*)(ptr2 + num5), source2);
932 Vector128<byte> left5 = Ssse3.Shuffle(vector4.AsByte(), mask3);
933 Vector128<byte> left6 = Sse2.And(left5, right4);
934 Vector128<byte> source3 = Sse2.Min(left6, right3);
935 Sse2.Store((byte*)(ptr2 + num5 + Vector128<byte>.Count), source3);
936 }
937 }
938 }
939 else if (AdvSimd.IsSupported)
940 {
941 Vector128<byte> right5 = Vector128.Create((byte)1);
942 Vector128<byte> right6 = (BitConverter.IsLittleEndian ? Vector128.Create(9241421688590303745uL).AsByte() : Vector128.Create(72624976668147840L).AsByte());
943 fixed (bool* ptr3 = &array4[index])
944 {
945 for (; num5 + 32 <= (uint)m_length; num5 += 32)
946 {
947 int value3 = m_array[num5 / 32];
948 if (!BitConverter.IsLittleEndian)
949 {
950 value3 = BinaryPrimitives.ReverseEndianness(value3);
951 }
952 Vector128<byte> vector5 = Vector128.Create(value3).AsByte();
953 vector5 = AdvSimd.Arm64.ZipLow(vector5, vector5);
954 vector5 = AdvSimd.Arm64.ZipLow(vector5, vector5);
955 Vector128<byte> left7 = AdvSimd.Arm64.ZipLow(vector5, vector5);
956 Vector128<byte> left8 = AdvSimd.And(left7, right6);
957 Vector128<byte> source4 = AdvSimd.Min(left8, right5);
958 AdvSimd.Store((byte*)(ptr3 + num5), source4);
959 Vector128<byte> left9 = AdvSimd.Arm64.ZipHigh(vector5, vector5);
960 Vector128<byte> left10 = AdvSimd.And(left9, right6);
961 Vector128<byte> source5 = AdvSimd.Min(left10, right5);
962 AdvSimd.Store((byte*)(ptr3 + num5 + Vector128<byte>.Count), source5);
963 }
964 }
965 }
966 }
967 for (; num5 < (uint)m_length; num5++)
968 {
969 int remainder3;
970 int num6 = Div32Rem((int)num5, out remainder3);
971 array4[index + (int)num5] = ((m_array[num6] >> remainder3) & 1) != 0;
972 }
973 return;
974 }
976 }
static void WriteInt32LittleEndian(Span< byte > destination, int value)
static sbyte ReverseEndianness(sbyte value)
static int Div4Rem(int number, out int remainder)
Definition BitArray.cs:1010
static int Div32Rem(int number, out int remainder)
Definition BitArray.cs:1003
static int GetByteArrayLengthFromBitLength(int n)
Definition BitArray.cs:998
static Vector64< byte > ZipLow(Vector64< byte > left, Vector64< byte > right)
Definition AdvSimd.cs:2879
static Vector64< byte > ZipHigh(Vector64< byte > left, Vector64< byte > right)
Definition AdvSimd.cs:2794
static Vector64< byte > Min(Vector64< byte > left, Vector64< byte > right)
Definition AdvSimd.cs:6209
static unsafe void Store(byte *address, Vector64< byte > source)
Definition AdvSimd.cs:10249
static Vector64< byte > And(Vector64< byte > left, Vector64< byte > right)
Definition AdvSimd.cs:3919
static Vector128< byte > Create(byte value)
Definition Vector128.cs:138
static unsafe Vector128< byte > CreateScalarUnsafe(byte value)
Definition Vector128.cs:829
static Vector256< byte > Create(byte value)
Definition Vector256.cs:105
static Vector256< sbyte > And(Vector256< sbyte > left, Vector256< sbyte > right)
Definition Avx2.cs:132
static new bool IsSupported
Definition Avx2.cs:15
static Vector256< sbyte > Min(Vector256< sbyte > left, Vector256< sbyte > right)
Definition Avx2.cs:1548
static Vector256< sbyte > Shuffle(Vector256< sbyte > value, Vector256< sbyte > mask)
Definition Avx2.cs:2078
static unsafe void Store(sbyte *address, Vector256< sbyte > source)
Definition Avx.cs:962
static unsafe void Store(sbyte *address, Vector128< sbyte > source)
Definition Sse2.cs:1287
static Vector128< byte > And(Vector128< byte > left, Vector128< byte > right)
Definition Sse2.cs:132
static Vector128< byte > Min(Vector128< byte > left, Vector128< byte > right)
Definition Sse2.cs:747
static Vector128< sbyte > Shuffle(Vector128< sbyte > value, Vector128< sbyte > mask)
Definition Ssse3.cs:112
static string Arg_BitArrayTypeUnsupported
Definition SR.cs:46
static string Arg_RankMultiDimNotSupported
Definition SR.cs:18
static string Argument_InvalidOffLen
Definition SR.cs:22
static string ArgumentOutOfRange_NeedNonNegNum
Definition SR.cs:32
Definition SR.cs:7

References System.Runtime.Intrinsics.X86.Sse2.And(), System.Runtime.Intrinsics.X86.Avx2.And(), System.Runtime.Intrinsics.Arm.AdvSimd.And(), System.SR.Arg_BitArrayTypeUnsupported, System.SR.Arg_RankMultiDimNotSupported, System.SR.Argument_InvalidOffLen, System.SR.ArgumentOutOfRange_NeedNonNegNum, System.array, System.Array.Copy(), System.Runtime.Intrinsics.Vector128< T >.Count, System.Runtime.Intrinsics.Vector128< T >.Create(), System.Runtime.Intrinsics.Vector256< T >.Create(), System.Runtime.Intrinsics.Vector128< T >.CreateScalarUnsafe(), System.destination, System.Collections.BitArray.Div32Rem(), System.Collections.BitArray.Div4Rem(), System.Collections.BitArray.GetByteArrayLengthFromBitLength(), System.index, System.BitConverter.IsLittleEndian, System.Runtime.Intrinsics.Arm.AdvSimd.IsSupported, System.Runtime.Intrinsics.X86.Avx2.IsSupported, System.Runtime.Intrinsics.X86.Ssse3.IsSupported, System.L, System.Collections.BitArray.m_array, System.Collections.BitArray.m_length, System.Runtime.Intrinsics.X86.Sse2.Min(), System.Runtime.Intrinsics.X86.Avx2.Min(), System.Runtime.Intrinsics.Arm.AdvSimd.Min(), System.Buffers.Binary.BinaryPrimitives.ReverseEndianness(), System.Runtime.Intrinsics.X86.Ssse3.Shuffle(), System.Runtime.Intrinsics.X86.Avx2.Shuffle(), System.source, System.Runtime.Intrinsics.Arm.AdvSimd.Store(), System.Runtime.Intrinsics.X86.Sse2.Store(), System.Runtime.Intrinsics.X86.Avx.Store(), System.value, System.Buffers.Binary.BinaryPrimitives.WriteInt32LittleEndian(), System.Runtime.Intrinsics.Arm.AdvSimd.Arm64.ZipHigh(), and System.Runtime.Intrinsics.Arm.AdvSimd.Arm64.ZipLow().

Referenced by System.Security.Cryptography.EccKeyFormatHelper.GetSpecifiedECCurveCore(), and System.Security.Cryptography.EccKeyFormatHelper.GetSpecifiedECCurveCore().