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

◆ Fill< T >()

static void System.SpanHelpers.Fill< T > ( ref T refData,
nuint numElements,
T value )
inlinestatic

Definition at line 2842 of file SpanHelpers.cs.

2843 {
2844 if (!RuntimeHelpers.IsReferenceOrContainsReferences<T>() && Vector.IsHardwareAccelerated && Unsafe.SizeOf<T>() <= Vector<byte>.Count && BitOperations.IsPow2(Unsafe.SizeOf<T>()) && numElements >= (uint)(Vector<byte>.Count / Unsafe.SizeOf<T>()))
2845 {
2846 T source = value;
2848 if (Unsafe.SizeOf<T>() == 1)
2849 {
2850 value2 = new Vector<byte>(Unsafe.As<T, byte>(ref source));
2851 }
2852 else if (Unsafe.SizeOf<T>() == 2)
2853 {
2854 value2 = (Vector<byte>)new Vector<ushort>(Unsafe.As<T, ushort>(ref source));
2855 }
2856 else if (Unsafe.SizeOf<T>() == 4)
2857 {
2858 value2 = ((typeof(T) == typeof(float)) ? ((Vector<byte>)new Vector<float>((float)(object)source)) : ((Vector<byte>)new Vector<uint>(Unsafe.As<T, uint>(ref source))));
2859 }
2860 else if (Unsafe.SizeOf<T>() == 8)
2861 {
2862 value2 = ((typeof(T) == typeof(double)) ? ((Vector<byte>)new Vector<double>((double)(object)source)) : ((Vector<byte>)new Vector<ulong>(Unsafe.As<T, ulong>(ref source))));
2863 }
2864 else if (Unsafe.SizeOf<T>() == 16)
2865 {
2867 if (Vector<byte>.Count == 16)
2868 {
2869 value2 = vector.AsVector();
2870 }
2871 else
2872 {
2873 if (Vector<byte>.Count != 32)
2874 {
2875 goto IL_022e;
2876 }
2877 value2 = Vector256.Create(vector, vector).AsVector();
2878 }
2879 }
2880 else
2881 {
2882 if (Unsafe.SizeOf<T>() != 32 || Vector<byte>.Count != 32)
2883 {
2884 goto IL_022e;
2885 }
2886 value2 = Unsafe.As<T, Vector256<byte>>(ref source).AsVector();
2887 }
2888 ref byte source2 = ref Unsafe.As<T, byte>(ref refData);
2889 nuint num = numElements * (nuint)Unsafe.SizeOf<T>();
2890 nuint num2 = num & (nuint)(2 * -Vector<byte>.Count);
2891 nuint num3 = 0u;
2892 if (numElements >= (uint)(2 * Vector<byte>.Count / Unsafe.SizeOf<T>()))
2893 {
2894 do
2895 {
2896 Unsafe.WriteUnaligned(ref Unsafe.AddByteOffset(ref source2, num3), value2);
2897 Unsafe.WriteUnaligned(ref Unsafe.AddByteOffset(ref source2, num3 + (nuint)Vector<byte>.Count), value2);
2898 num3 += (uint)(2 * Vector<byte>.Count);
2899 }
2900 while (num3 < num2);
2901 }
2902 if ((num & (nuint)Vector<byte>.Count) != 0)
2903 {
2904 Unsafe.WriteUnaligned(ref Unsafe.AddByteOffset(ref source2, num3), value2);
2905 }
2906 Unsafe.WriteUnaligned(ref Unsafe.AddByteOffset(ref source2, num - (nuint)Vector<byte>.Count), value2);
2907 return;
2908 }
2909 goto IL_022e;
2910 IL_022e:
2911 nuint num4 = 0u;
2912 if (numElements >= 8)
2913 {
2914 nuint num5 = numElements & ~(nuint)7u;
2915 do
2916 {
2917 Unsafe.Add(ref refData, (nint)(num4 + 0)) = value;
2918 Unsafe.Add(ref refData, (nint)(num4 + 1)) = value;
2919 Unsafe.Add(ref refData, (nint)(num4 + 2)) = value;
2920 Unsafe.Add(ref refData, (nint)(num4 + 3)) = value;
2921 Unsafe.Add(ref refData, (nint)(num4 + 4)) = value;
2922 Unsafe.Add(ref refData, (nint)(num4 + 5)) = value;
2923 Unsafe.Add(ref refData, (nint)(num4 + 6)) = value;
2924 Unsafe.Add(ref refData, (nint)(num4 + 7)) = value;
2925 }
2926 while ((num4 += 8) < num5);
2927 }
2928 if ((numElements & 4) != 0)
2929 {
2930 Unsafe.Add(ref refData, (nint)(num4 + 0)) = value;
2931 Unsafe.Add(ref refData, (nint)(num4 + 1)) = value;
2932 Unsafe.Add(ref refData, (nint)(num4 + 2)) = value;
2933 Unsafe.Add(ref refData, (nint)(num4 + 3)) = value;
2934 num4 += 4;
2935 }
2936 if ((numElements & 2) != 0)
2937 {
2938 Unsafe.Add(ref refData, (nint)(num4 + 0)) = value;
2939 Unsafe.Add(ref refData, (nint)(num4 + 1)) = value;
2940 num4 += 2;
2941 }
2942 if ((numElements & 1) != 0)
2943 {
2944 Unsafe.Add(ref refData, (nint)num4) = value;
2945 }
2946 }
static bool IsPow2(int value)
static bool IsHardwareAccelerated
Definition Vector.cs:14
static Vector256< byte > Create(byte value)
Definition Vector256.cs:105

References System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Runtime.Intrinsics.Vector256< T >.Create(), System.Numerics.Vector< T >.IsHardwareAccelerated, System.Numerics.BitOperations.IsPow2(), System.source, System.T, and System.value.