From a900207d2f222521c82e7645ec15b9b3e124b961 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Sun, 7 Jul 2024 22:37:28 +0100 Subject: [PATCH] Use `GetArrayDataReference` in `Vector*` --- .../src/System/Numerics/Vector2.cs | 4 +-- .../src/System/Numerics/Vector3.cs | 4 +-- .../src/System/Numerics/VectorDebugView_1.cs | 25 ++++++++++--------- .../src/System/Numerics/Vector_1.cs | 8 +++--- .../System/Runtime/Intrinsics/Vector128.cs | 8 +++--- .../Intrinsics/Vector128DebugView_1.cs | 25 ++++++++++--------- .../System/Runtime/Intrinsics/Vector256.cs | 8 +++--- .../Intrinsics/Vector256DebugView_1.cs | 25 ++++++++++--------- .../System/Runtime/Intrinsics/Vector512.cs | 8 +++--- .../Intrinsics/Vector512DebugView_1.cs | 25 ++++++++++--------- .../src/System/Runtime/Intrinsics/Vector64.cs | 8 +++--- .../Runtime/Intrinsics/Vector64DebugView_1.cs | 25 ++++++++++--------- 12 files changed, 89 insertions(+), 84 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector2.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector2.cs index e101a75ea91544..224609aaf8f28c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector2.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector2.cs @@ -597,7 +597,7 @@ public readonly void CopyTo(float[] array) ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - Unsafe.WriteUnaligned(ref Unsafe.As(ref array[0]), this); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(array)), this); } /// Copies the elements of the vector to a specified array starting at a specified index position. @@ -625,7 +625,7 @@ public readonly void CopyTo(float[] array, int index) ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - Unsafe.WriteUnaligned(ref Unsafe.As(ref array[index]), this); + Unsafe.WriteUnaligned(ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(array), (uint)index)), this); } /// Copies the vector to the given .The length of the destination span must be at least 2. diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.cs index 8519f382655dec..f0f20717c366ff 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.cs @@ -630,7 +630,7 @@ public readonly void CopyTo(float[] array) ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - Unsafe.WriteUnaligned(ref Unsafe.As(ref array[0]), this); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(array)), this); } /// Copies the elements of the vector to a specified array starting at a specified index position. @@ -658,7 +658,7 @@ public readonly void CopyTo(float[] array, int index) ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - Unsafe.WriteUnaligned(ref Unsafe.As(ref array[index]), this); + Unsafe.WriteUnaligned(ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(array), (uint)index)), this); } /// Copies the vector to the given . The length of the destination span must be at least 3. diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/VectorDebugView_1.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/VectorDebugView_1.cs index dc01af4c68bd79..60a771b95bbae8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/VectorDebugView_1.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/VectorDebugView_1.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Numerics { @@ -20,7 +21,7 @@ public byte[] ByteView get { var items = new byte[Vector.Count]; - Unsafe.WriteUnaligned(ref items[0], _value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetArrayDataReference(items), _value); return items; } } @@ -30,7 +31,7 @@ public double[] DoubleView get { var items = new double[Vector.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -40,7 +41,7 @@ public short[] Int16View get { var items = new short[Vector.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -50,7 +51,7 @@ public int[] Int32View get { var items = new int[Vector.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -60,7 +61,7 @@ public long[] Int64View get { var items = new long[Vector.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -70,7 +71,7 @@ public nint[] NIntView get { var items = new nint[Vector.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -80,7 +81,7 @@ public nuint[] NUIntView get { var items = new nuint[Vector.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -90,7 +91,7 @@ public sbyte[] SByteView get { var items = new sbyte[Vector.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -100,7 +101,7 @@ public float[] SingleView get { var items = new float[Vector.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -110,7 +111,7 @@ public ushort[] UInt16View get { var items = new ushort[Vector.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -120,7 +121,7 @@ public uint[] UInt32View get { var items = new uint[Vector.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -130,7 +131,7 @@ public ulong[] UInt64View get { var items = new ulong[Vector.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector_1.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector_1.cs index 0910caadcf37cb..28045a8a79c187 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector_1.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector_1.cs @@ -63,7 +63,7 @@ public Vector(T[] values) ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } - this = Unsafe.ReadUnaligned>(ref Unsafe.As(ref values[0])); + this = Unsafe.ReadUnaligned>(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(values))); } /// Creates a new from a given array. @@ -82,7 +82,7 @@ public Vector(T[] values, int index) ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } - this = Unsafe.ReadUnaligned>(ref Unsafe.As(ref values[index])); + this = Unsafe.ReadUnaligned>(ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(values), (uint)index))); } /// Creates a new from a given readonly span. @@ -624,7 +624,7 @@ public void CopyTo(T[] destination) ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - Unsafe.WriteUnaligned(ref Unsafe.As(ref destination[0]), this); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(destination)), this); } /// Copies a to a given array starting at the specified index. @@ -648,7 +648,7 @@ public void CopyTo(T[] destination, int startIndex) ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - Unsafe.WriteUnaligned(ref Unsafe.As(ref destination[startIndex]), this); + Unsafe.WriteUnaligned(ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(destination), (uint)startIndex)), this); } /// Copies a to a given span. diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128.cs index 2011025c0455d0..b3781b41c68767 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128.cs @@ -777,7 +777,7 @@ public static void CopyTo(this Vector128 vector, T[] destination) ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - Unsafe.WriteUnaligned(ref Unsafe.As(ref destination[0]), vector); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(destination)), vector); } /// Copies a to a given array starting at the specified index. @@ -804,7 +804,7 @@ public static unsafe void CopyTo(this Vector128 vector, T[] destination, i ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - Unsafe.WriteUnaligned(ref Unsafe.As(ref destination[startIndex]), vector); + Unsafe.WriteUnaligned(ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(destination), (uint)startIndex)), vector); } /// Copies a to a given span. @@ -940,7 +940,7 @@ public static Vector128 Create(T[] values) ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } - return Unsafe.ReadUnaligned>(ref Unsafe.As(ref values[0])); + return Unsafe.ReadUnaligned>(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(values))); } /// Creates a new from a given array. @@ -961,7 +961,7 @@ public static Vector128 Create(T[] values, int index) ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } - return Unsafe.ReadUnaligned>(ref Unsafe.As(ref values[index])); + return Unsafe.ReadUnaligned>(ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(values), (uint)index))); } /// Creates a new from a given readonly span. diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128DebugView_1.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128DebugView_1.cs index 2c8612a5913320..abc4f4a3a6d87c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128DebugView_1.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128DebugView_1.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Runtime.Intrinsics { @@ -19,7 +20,7 @@ public byte[] ByteView get { var items = new byte[Vector128.Count]; - Unsafe.WriteUnaligned(ref items[0], _value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetArrayDataReference(items), _value); return items; } } @@ -29,7 +30,7 @@ public double[] DoubleView get { var items = new double[Vector128.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -39,7 +40,7 @@ public short[] Int16View get { var items = new short[Vector128.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -49,7 +50,7 @@ public int[] Int32View get { var items = new int[Vector128.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -59,7 +60,7 @@ public long[] Int64View get { var items = new long[Vector128.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -69,7 +70,7 @@ public nint[] NIntView get { var items = new nint[Vector128.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -79,7 +80,7 @@ public nuint[] NUIntView get { var items = new nuint[Vector128.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -89,7 +90,7 @@ public sbyte[] SByteView get { var items = new sbyte[Vector128.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -99,7 +100,7 @@ public float[] SingleView get { var items = new float[Vector128.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -109,7 +110,7 @@ public ushort[] UInt16View get { var items = new ushort[Vector128.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -119,7 +120,7 @@ public uint[] UInt32View get { var items = new uint[Vector128.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -129,7 +130,7 @@ public ulong[] UInt64View get { var items = new ulong[Vector128.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs index d1dde486f58033..243f43e20173d4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256.cs @@ -616,7 +616,7 @@ public static void CopyTo(this Vector256 vector, T[] destination) ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - Unsafe.WriteUnaligned(ref Unsafe.As(ref destination[0]), vector); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(destination)), vector); } /// Copies a to a given array starting at the specified index. @@ -643,7 +643,7 @@ public static void CopyTo(this Vector256 vector, T[] destination, int star ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - Unsafe.WriteUnaligned(ref Unsafe.As(ref destination[startIndex]), vector); + Unsafe.WriteUnaligned(ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(destination), (uint)startIndex)), vector); } /// Copies a to a given span. @@ -779,7 +779,7 @@ public static Vector256 Create(T[] values) ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } - return Unsafe.ReadUnaligned>(ref Unsafe.As(ref values[0])); + return Unsafe.ReadUnaligned>(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(values))); } /// Creates a new from a given array. @@ -800,7 +800,7 @@ public static Vector256 Create(T[] values, int index) ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } - return Unsafe.ReadUnaligned>(ref Unsafe.As(ref values[index])); + return Unsafe.ReadUnaligned>(ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(values), (uint)index))); } /// Creates a new from a given readonly span. diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256DebugView_1.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256DebugView_1.cs index c407777fbe3fec..862d7f0256b0cc 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256DebugView_1.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256DebugView_1.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Runtime.Intrinsics { @@ -19,7 +20,7 @@ public byte[] ByteView get { var items = new byte[Vector256.Count]; - Unsafe.WriteUnaligned(ref items[0], _value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetArrayDataReference(items), _value); return items; } } @@ -29,7 +30,7 @@ public double[] DoubleView get { var items = new double[Vector256.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -39,7 +40,7 @@ public short[] Int16View get { var items = new short[Vector256.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -49,7 +50,7 @@ public int[] Int32View get { var items = new int[Vector256.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -59,7 +60,7 @@ public long[] Int64View get { var items = new long[Vector256.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -69,7 +70,7 @@ public nint[] NIntView get { var items = new nint[Vector256.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -79,7 +80,7 @@ public nuint[] NUIntView get { var items = new nuint[Vector256.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -89,7 +90,7 @@ public sbyte[] SByteView get { var items = new sbyte[Vector256.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -99,7 +100,7 @@ public float[] SingleView get { var items = new float[Vector256.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -109,7 +110,7 @@ public ushort[] UInt16View get { var items = new ushort[Vector256.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -119,7 +120,7 @@ public uint[] UInt32View get { var items = new uint[Vector256.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -129,7 +130,7 @@ public ulong[] UInt64View get { var items = new ulong[Vector256.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512.cs index 7a22ec76818246..234eca09b05789 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512.cs @@ -544,7 +544,7 @@ public static void CopyTo(this Vector512 vector, T[] destination) ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - Unsafe.WriteUnaligned(ref Unsafe.As(ref destination[0]), vector); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(destination)), vector); } /// Copies a to a given array starting at the specified index. @@ -570,7 +570,7 @@ public static void CopyTo(this Vector512 vector, T[] destination, int star ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - Unsafe.WriteUnaligned(ref Unsafe.As(ref destination[startIndex]), vector); + Unsafe.WriteUnaligned(ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(destination), (uint)startIndex)), vector); } /// Copies a to a given span. @@ -704,7 +704,7 @@ public static Vector512 Create(T[] values) ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } - return Unsafe.ReadUnaligned>(ref Unsafe.As(ref values[0])); + return Unsafe.ReadUnaligned>(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(values))); } /// Creates a new from a given array. @@ -724,7 +724,7 @@ public static Vector512 Create(T[] values, int index) ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } - return Unsafe.ReadUnaligned>(ref Unsafe.As(ref values[index])); + return Unsafe.ReadUnaligned>(ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(values), (uint)index))); } /// Creates a new from a given readonly span. diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512DebugView_1.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512DebugView_1.cs index e20717b6d7f6eb..fa20f8552f41d8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512DebugView_1.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector512DebugView_1.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Runtime.Intrinsics { @@ -19,7 +20,7 @@ public byte[] ByteView get { var items = new byte[Vector512.Count]; - Unsafe.WriteUnaligned(ref items[0], _value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetArrayDataReference(items), _value); return items; } } @@ -29,7 +30,7 @@ public double[] DoubleView get { var items = new double[Vector512.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -39,7 +40,7 @@ public short[] Int16View get { var items = new short[Vector512.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -49,7 +50,7 @@ public int[] Int32View get { var items = new int[Vector512.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -59,7 +60,7 @@ public long[] Int64View get { var items = new long[Vector512.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -69,7 +70,7 @@ public nint[] NIntView get { var items = new nint[Vector512.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -79,7 +80,7 @@ public nuint[] NUIntView get { var items = new nuint[Vector512.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -89,7 +90,7 @@ public sbyte[] SByteView get { var items = new sbyte[Vector512.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -99,7 +100,7 @@ public float[] SingleView get { var items = new float[Vector512.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -109,7 +110,7 @@ public ushort[] UInt16View get { var items = new ushort[Vector512.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -119,7 +120,7 @@ public uint[] UInt32View get { var items = new uint[Vector512.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -129,7 +130,7 @@ public ulong[] UInt64View get { var items = new ulong[Vector512.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64.cs index 7203311532d703..4b74f3b5253787 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64.cs @@ -560,7 +560,7 @@ public static void CopyTo(this Vector64 vector, T[] destination) ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - Unsafe.WriteUnaligned(ref Unsafe.As(ref destination[0]), vector); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(destination)), vector); } /// Copies a to a given array starting at the specified index. @@ -587,7 +587,7 @@ public static unsafe void CopyTo(this Vector64 vector, T[] destination, in ThrowHelper.ThrowArgumentException_DestinationTooShort(); } - Unsafe.WriteUnaligned(ref Unsafe.As(ref destination[startIndex]), vector); + Unsafe.WriteUnaligned(ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(destination), (uint)startIndex)), vector); } /// Copies a to a given span. @@ -725,7 +725,7 @@ public static Vector64 Create(T[] values) ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } - return Unsafe.ReadUnaligned>(ref Unsafe.As(ref values[0])); + return Unsafe.ReadUnaligned>(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(values))); } /// Creates a new from a given array. @@ -746,7 +746,7 @@ public static Vector64 Create(T[] values, int index) ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); } - return Unsafe.ReadUnaligned>(ref Unsafe.As(ref values[index])); + return Unsafe.ReadUnaligned>(ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(values), (uint)index))); } /// Creates a new from a given readonly span. diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64DebugView_1.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64DebugView_1.cs index 35e9fd143d94e3..602a48bf9482bf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64DebugView_1.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64DebugView_1.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Runtime.Intrinsics { @@ -19,7 +20,7 @@ public byte[] ByteView get { var items = new byte[Vector64.Count]; - Unsafe.WriteUnaligned(ref items[0], _value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetArrayDataReference(items), _value); return items; } } @@ -29,7 +30,7 @@ public double[] DoubleView get { var items = new double[Vector64.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -39,7 +40,7 @@ public short[] Int16View get { var items = new short[Vector64.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -49,7 +50,7 @@ public int[] Int32View get { var items = new int[Vector64.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -59,7 +60,7 @@ public long[] Int64View get { var items = new long[Vector64.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -69,7 +70,7 @@ public nint[] NIntView get { var items = new nint[Vector64.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -79,7 +80,7 @@ public nuint[] NUIntView get { var items = new nuint[Vector64.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -89,7 +90,7 @@ public sbyte[] SByteView get { var items = new sbyte[Vector64.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -99,7 +100,7 @@ public float[] SingleView get { var items = new float[Vector64.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -109,7 +110,7 @@ public ushort[] UInt16View get { var items = new ushort[Vector64.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -119,7 +120,7 @@ public uint[] UInt32View get { var items = new uint[Vector64.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } } @@ -129,7 +130,7 @@ public ulong[] UInt64View get { var items = new ulong[Vector64.Count]; - Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), _value); + Unsafe.WriteUnaligned(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(items)), _value); return items; } }