From c1e43ad8f1423483f84f42efeb792935aede8a61 Mon Sep 17 00:00:00 2001 From: Steven He Date: Mon, 12 Feb 2024 20:13:02 +0900 Subject: [PATCH] Faster Vector64 fallback --- .../src/System/Runtime/Intrinsics/Vector64.cs | 102 ++++++++---------- 1 file changed, 44 insertions(+), 58 deletions(-) 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 ddd59d1adcab2..50e9f697c94f4 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 @@ -700,18 +700,16 @@ public static Vector64 Create(ReadOnlySpan values) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe Vector64 Create(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7) { - byte* pResult = stackalloc byte[8] - { - e0, - e1, - e2, - e3, - e4, - e5, - e6, - e7, - }; - return Unsafe.AsRef>(pResult); + Unsafe.SkipInit(out Vector64 result); + result.SetElementUnsafe(0, e0); + result.SetElementUnsafe(1, e1); + result.SetElementUnsafe(2, e2); + result.SetElementUnsafe(3, e3); + result.SetElementUnsafe(4, e4); + result.SetElementUnsafe(5, e5); + result.SetElementUnsafe(6, e6); + result.SetElementUnsafe(7, e7); + return result; } /// Creates a new instance with each element initialized to the corresponding specified value. @@ -725,14 +723,12 @@ public static unsafe Vector64 Create(byte e0, byte e1, byte e2, byte e3, b [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe Vector64 Create(short e0, short e1, short e2, short e3) { - short* pResult = stackalloc short[4] - { - e0, - e1, - e2, - e3, - }; - return Unsafe.AsRef>(pResult); + Unsafe.SkipInit(out Vector64 result); + result.SetElementUnsafe(0, e0); + result.SetElementUnsafe(1, e1); + result.SetElementUnsafe(2, e2); + result.SetElementUnsafe(3, e3); + return result; } /// Creates a new instance with each element initialized to the corresponding specified value. @@ -744,12 +740,10 @@ public static unsafe Vector64 Create(short e0, short e1, short e2, short [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe Vector64 Create(int e0, int e1) { - int* pResult = stackalloc int[2] - { - e0, - e1, - }; - return Unsafe.AsRef>(pResult); + Unsafe.SkipInit(out Vector64 result); + result.SetElementUnsafe(0, e0); + result.SetElementUnsafe(1, e1); + return result; } /// Creates a new instance with each element initialized to the corresponding specified value. @@ -768,18 +762,16 @@ public static unsafe Vector64 Create(int e0, int e1) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe Vector64 Create(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7) { - sbyte* pResult = stackalloc sbyte[8] - { - e0, - e1, - e2, - e3, - e4, - e5, - e6, - e7, - }; - return Unsafe.AsRef>(pResult); + Unsafe.SkipInit(out Vector64 result); + result.SetElementUnsafe(0, e0); + result.SetElementUnsafe(1, e1); + result.SetElementUnsafe(2, e2); + result.SetElementUnsafe(3, e3); + result.SetElementUnsafe(4, e4); + result.SetElementUnsafe(5, e5); + result.SetElementUnsafe(6, e6); + result.SetElementUnsafe(7, e7); + return result; } /// Creates a new instance with each element initialized to the corresponding specified value. @@ -790,12 +782,10 @@ public static unsafe Vector64 Create(sbyte e0, sbyte e1, sbyte e2, sbyte [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe Vector64 Create(float e0, float e1) { - float* pResult = stackalloc float[2] - { - e0, - e1, - }; - return Unsafe.AsRef>(pResult); + Unsafe.SkipInit(out Vector64 result); + result.SetElementUnsafe(0, e0); + result.SetElementUnsafe(1, e1); + return result; } /// Creates a new instance with each element initialized to the corresponding specified value. @@ -810,14 +800,12 @@ public static unsafe Vector64 Create(float e0, float e1) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe Vector64 Create(ushort e0, ushort e1, ushort e2, ushort e3) { - ushort* pResult = stackalloc ushort[4] - { - e0, - e1, - e2, - e3, - }; - return Unsafe.AsRef>(pResult); + Unsafe.SkipInit(out Vector64 result); + result.SetElementUnsafe(0, e0); + result.SetElementUnsafe(1, e1); + result.SetElementUnsafe(2, e2); + result.SetElementUnsafe(3, e3); + return result; } /// Creates a new instance with each element initialized to the corresponding specified value. @@ -830,12 +818,10 @@ public static unsafe Vector64 Create(ushort e0, ushort e1, ushort e2, us [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe Vector64 Create(uint e0, uint e1) { - uint* pResult = stackalloc uint[2] - { - e0, - e1, - }; - return Unsafe.AsRef>(pResult); + Unsafe.SkipInit(out Vector64 result); + result.SetElementUnsafe(0, e0); + result.SetElementUnsafe(1, e1); + return result; } /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero.