From e19d12d3cf6eecec3f6e9f643a8b5d3019df2076 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Mon, 22 Oct 2018 14:37:00 -0700 Subject: [PATCH 1/4] Renaming Vector64.cs, Vector128.cs, and Vector256.cs to be Vector64_1.cs, etc --- .../shared/System.Private.CoreLib.Shared.projitems | 12 ++++++------ ...Vector128DebugView.cs => Vector128DebugView_1.cs} | 0 .../Intrinsics/{Vector128.cs => Vector128_1.cs} | 0 ...Vector256DebugView.cs => Vector256DebugView_1.cs} | 0 .../Intrinsics/{Vector256.cs => Vector256_1.cs} | 0 .../{Vector64DebugView.cs => Vector64DebugView_1.cs} | 0 .../Intrinsics/{Vector64.cs => Vector64_1.cs} | 0 7 files changed, 6 insertions(+), 6 deletions(-) rename src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/{Vector128DebugView.cs => Vector128DebugView_1.cs} (100%) rename src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/{Vector128.cs => Vector128_1.cs} (100%) rename src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/{Vector256DebugView.cs => Vector256DebugView_1.cs} (100%) rename src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/{Vector256.cs => Vector256_1.cs} (100%) rename src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/{Vector64DebugView.cs => Vector64DebugView_1.cs} (100%) rename src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/{Vector64.cs => Vector64_1.cs} (100%) diff --git a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems index 078444fb8f48..e5ad6c2ff93e 100644 --- a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems @@ -516,12 +516,12 @@ - - - - - - + + + + + + diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128DebugView.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128DebugView_1.cs similarity index 100% rename from src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128DebugView.cs rename to src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128DebugView_1.cs diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs similarity index 100% rename from src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs rename to src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256DebugView.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256DebugView_1.cs similarity index 100% rename from src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256DebugView.cs rename to src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256DebugView_1.cs diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs similarity index 100% rename from src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs rename to src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64DebugView.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64DebugView_1.cs similarity index 100% rename from src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64DebugView.cs rename to src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64DebugView_1.cs diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs similarity index 100% rename from src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs rename to src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs From 4ad9dc47ab187a80dd90b558329021f3b8e5ee8e Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Mon, 22 Oct 2018 14:39:07 -0700 Subject: [PATCH 2/4] Adding some core helper methods to the Vector64, Vector128, and Vecto256 types. --- .../System.Private.CoreLib.Shared.projitems | 3 + .../System/Runtime/Intrinsics/Vector128.cs | 625 +++++++++++++++ .../System/Runtime/Intrinsics/Vector128_1.cs | 178 +++- .../System/Runtime/Intrinsics/Vector256.cs | 757 ++++++++++++++++++ .../System/Runtime/Intrinsics/Vector256_1.cs | 155 +++- .../System/Runtime/Intrinsics/Vector64.cs | 346 ++++++++ .../System/Runtime/Intrinsics/Vector64_1.cs | 141 +++- 7 files changed, 2184 insertions(+), 21 deletions(-) create mode 100644 src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs create mode 100644 src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs create mode 100644 src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs diff --git a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems index e5ad6c2ff93e..c3ef9a3211f1 100644 --- a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems @@ -516,10 +516,13 @@ + + + diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs new file mode 100644 index 000000000000..12ee75c18e01 --- /dev/null +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs @@ -0,0 +1,625 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Internal.Runtime.CompilerServices; + +namespace System.Runtime.Intrinsics +{ + public static class Vector128 + { + internal const int Size = 16; + + public static unsafe Vector128 Create(byte value) + { + var pResult = stackalloc byte[16] + { + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 Create(double value) + { + var pResult = stackalloc double[2] + { + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 Create(short value) + { + var pResult = stackalloc short[8] + { + value, + value, + value, + value, + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 Create(int value) + { + var pResult = stackalloc int[4] + { + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 Create(long value) + { + var pResult = stackalloc long[2] + { + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector128 Create(sbyte value) + { + var pResult = stackalloc sbyte[16] + { + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 Create(float value) + { + var pResult = stackalloc float[4] + { + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector128 Create(ushort value) + { + var pResult = stackalloc ushort[8] + { + value, + value, + value, + value, + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector128 Create(uint value) + { + var pResult = stackalloc uint[4] + { + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector128 Create(ulong value) + { + var pResult = stackalloc ulong[2] + { + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 Create(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7, byte e8, byte e9, byte e10, byte e11, byte e12, byte e13, byte e14, byte e15) + { + var pResult = stackalloc byte[16] + { + e0, + e1, + e2, + e3, + e4, + e5, + e6, + e7, + e8, + e9, + e10, + e11, + e12, + e13, + e14, + e15, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 Create(double e0, double e1) + { + var pResult = stackalloc double[2] + { + e0, + e1, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 Create(short e0, short e1, short e2, short e3, short e4, short e5, short e6, short e7) + { + var pResult = stackalloc short[8] + { + e0, + e1, + e2, + e3, + e4, + e5, + e6, + e7, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 Create(int e0, int e1, int e2, int e3) + { + var pResult = stackalloc int[4] + { + e0, + e1, + e2, + e3, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 Create(long e0, long e1) + { + var pResult = stackalloc long[2] + { + e0, + e1, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector128 Create(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7, sbyte e8, sbyte e9, sbyte e10, sbyte e11, sbyte e12, sbyte e13, sbyte e14, sbyte e15) + { + var pResult = stackalloc sbyte[16] + { + e0, + e1, + e2, + e3, + e4, + e5, + e6, + e7, + e8, + e9, + e10, + e11, + e12, + e13, + e14, + e15, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 Create(float e0, float e1, float e2, float e3) + { + var pResult = stackalloc float[4] + { + e0, + e1, + e2, + e3, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector128 Create(ushort e0, ushort e1, ushort e2, ushort e3, ushort e4, ushort e5, ushort e6, ushort e7) + { + var pResult = stackalloc ushort[8] + { + e0, + e1, + e2, + e3, + e4, + e5, + e6, + e7, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector128 Create(uint e0, uint e1, uint e2, uint e3) + { + var pResult = stackalloc uint[4] + { + e0, + e1, + e2, + e3, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector128 Create(ulong e0, ulong e1) + { + var pResult = stackalloc ulong[2] + { + e0, + e1, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) + { + Vector128 result128 = Vector128.Zero; + + ref Vector64 result64 = ref Unsafe.As, Vector64>(ref result128); + result64 = lower; + Unsafe.Add(ref result64, 1) = upper; + + return result128; + } + + public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) + { + Vector128 result128 = Vector128.Zero; + + ref Vector64 result64 = ref Unsafe.As, Vector64>(ref result128); + result64 = lower; + Unsafe.Add(ref result64, 1) = upper; + + return result128; + } + + public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) + { + Vector128 result128 = Vector128.Zero; + + ref Vector64 result64 = ref Unsafe.As, Vector64>(ref result128); + result64 = lower; + Unsafe.Add(ref result64, 1) = upper; + + return result128; + } + + public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) + { + Vector128 result128 = Vector128.Zero; + + ref Vector64 result64 = ref Unsafe.As, Vector64>(ref result128); + result64 = lower; + Unsafe.Add(ref result64, 1) = upper; + + return result128; + } + + public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) + { + Vector128 result128 = Vector128.Zero; + + ref Vector64 result64 = ref Unsafe.As, Vector64>(ref result128); + result64 = lower; + Unsafe.Add(ref result64, 1) = upper; + + return result128; + } + + [CLSCompliant(false)] + public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) + { + Vector128 result128 = Vector128.Zero; + + ref Vector64 result64 = ref Unsafe.As, Vector64>(ref result128); + result64 = lower; + Unsafe.Add(ref result64, 1) = upper; + + return result128; + } + + public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) + { + Vector128 result128 = Vector128.Zero; + + ref Vector64 result64 = ref Unsafe.As, Vector64>(ref result128); + result64 = lower; + Unsafe.Add(ref result64, 1) = upper; + + return result128; + } + + [CLSCompliant(false)] + public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) + { + Vector128 result128 = Vector128.Zero; + + ref Vector64 result64 = ref Unsafe.As, Vector64>(ref result128); + result64 = lower; + Unsafe.Add(ref result64, 1) = upper; + + return result128; + } + + [CLSCompliant(false)] + public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) + { + Vector128 result128 = Vector128.Zero; + + ref Vector64 result64 = ref Unsafe.As, Vector64>(ref result128); + result64 = lower; + Unsafe.Add(ref result64, 1) = upper; + + return result128; + } + + [CLSCompliant(false)] + public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) + { + Vector128 result128 = Vector128.Zero; + + ref Vector64 result64 = ref Unsafe.As, Vector64>(ref result128); + result64 = lower; + Unsafe.Add(ref result64, 1) = upper; + + return result128; + } + + public static unsafe Vector128 CreateScalar(byte value) + { + var result = Vector128.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector128 CreateScalar(double value) + { + var result = Vector128.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector128 CreateScalar(short value) + { + var result = Vector128.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector128 CreateScalar(int value) + { + var result = Vector128.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector128 CreateScalar(long value) + { + var result = Vector128.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + [CLSCompliant(false)] + public static unsafe Vector128 CreateScalar(sbyte value) + { + var result = Vector128.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector128 CreateScalar(float value) + { + var result = Vector128.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + [CLSCompliant(false)] + public static unsafe Vector128 CreateScalar(ushort value) + { + var result = Vector128.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + [CLSCompliant(false)] + public static unsafe Vector128 CreateScalar(uint value) + { + var result = Vector128.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + [CLSCompliant(false)] + public static unsafe Vector128 CreateScalar(ulong value) + { + var result = Vector128.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector128 CreateScalarUnsafe(byte value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc byte[16]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 CreateScalarUnsafe(double value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc double[2]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 CreateScalarUnsafe(short value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc short[8]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 CreateScalarUnsafe(int value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc int[4]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 CreateScalarUnsafe(long value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc long[2]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector128 CreateScalarUnsafe(sbyte value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc sbyte[16]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector128 CreateScalarUnsafe(float value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc float[4]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector128 CreateScalarUnsafe(ushort value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc ushort[8]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector128 CreateScalarUnsafe(uint value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc uint[4]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector128 CreateScalarUnsafe(ulong value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc ulong[2]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + } +} diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs index b2e72ddf8933..ad4087c558d8 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs @@ -12,7 +12,7 @@ namespace System.Runtime.Intrinsics [Intrinsic] [DebuggerDisplay("{DisplayString,nq}")] [DebuggerTypeProxy(typeof(Vector128DebugView<>))] - [StructLayout(LayoutKind.Sequential, Size = 16)] + [StructLayout(LayoutKind.Sequential, Size = Vector128.Size)] public readonly struct Vector128 where T : struct { // These fields exist to ensure the alignment is 8, rather than 1. @@ -20,17 +20,22 @@ namespace System.Runtime.Intrinsics private readonly ulong _00; private readonly ulong _01; - private unsafe string DisplayString + public static Vector128 Zero { get { - // The IsPrimitive check ends up working for `bool`, `char`, `IntPtr`, and `UIntPtr` - // which are not actually supported by any current architecture. This shouldn't be - // an issue however and greatly simplifies the check + ThrowIfUnsupportedType(); + return default; + } + } - if (typeof(T).IsPrimitive) + internal unsafe string DisplayString + { + get + { + if (IsSupported) { - var items = new T[16 / Unsafe.SizeOf()]; + var items = new T[ElementCount]; Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), this); return $"({string.Join(", ", items)})"; } @@ -40,5 +45,164 @@ private unsafe string DisplayString } } } + + internal static int ElementCount + { + get + { + ThrowIfUnsupportedType(); + return Vector128.Size / Unsafe.SizeOf(); + } + } + + internal static bool IsSupported + { + get + { + return (typeof(T) == typeof(byte)) || + (typeof(T) == typeof(sbyte)) || + (typeof(T) == typeof(short)) || + (typeof(T) == typeof(ushort)) || + (typeof(T) == typeof(int)) || + (typeof(T) == typeof(uint)) || + (typeof(T) == typeof(long)) || + (typeof(T) == typeof(ulong)) || + (typeof(T) == typeof(float)) || + (typeof(T) == typeof(double)); + } + } + + internal static void ThrowIfUnsupportedType() + { + if (!IsSupported) + { + throw new NotSupportedException(SR.Arg_TypeNotSupported); + } + } + + public Vector128 As() where U : struct + { + ThrowIfUnsupportedType(); + Vector128.ThrowIfUnsupportedType(); + return Unsafe.As, Vector128>(ref Unsafe.AsRef(in this)); + } + + public Vector128 AsByte() => As(); + + public Vector128 AsDouble() => As(); + + public Vector128 AsInt16() => As(); + + public Vector128 AsInt32() => As(); + + public Vector128 AsInt64() => As(); + + [CLSCompliant(false)] + public Vector128 AsSByte() => As(); + + public Vector128 AsSingle() => As(); + + [CLSCompliant(false)] + public Vector128 AsUInt16() => As(); + + [CLSCompliant(false)] + public Vector128 AsUInt32() => As(); + + [CLSCompliant(false)] + public Vector128 AsUInt64() => As(); + + public T GetElement(int index) + { + ThrowIfUnsupportedType(); + + if ((uint)(index) >= (uint)(ElementCount)) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + + ref T e0 = ref Unsafe.As, T>(ref Unsafe.AsRef(in this)); + return Unsafe.Add(ref e0, index); + } + + public Vector128 SetElement(int index, T value) + { + ThrowIfUnsupportedType(); + + if ((uint)(index) >= (uint)(ElementCount)) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + + Vector128 result = this; + ref T e0 = ref Unsafe.As, T>(ref result); + Unsafe.Add(ref e0, index) = value; + return result; + } + + public Vector64 GetLower() + { + ThrowIfUnsupportedType(); + Vector64.ThrowIfUnsupportedType(); + return Unsafe.As, Vector64>(ref Unsafe.AsRef(in this)); + } + + public Vector128 SetLower(Vector64 value) + { + ThrowIfUnsupportedType(); + Vector64.ThrowIfUnsupportedType(); + + Vector128 result = this; + Unsafe.As, Vector64>(ref result) = value; + return result; + } + + public Vector64 GetUpper() + { + ThrowIfUnsupportedType(); + Vector64.ThrowIfUnsupportedType(); + + ref Vector64 lower = ref Unsafe.As, Vector64>(ref Unsafe.AsRef(in this)); + return Unsafe.Add(ref lower, 1); + } + + public Vector128 SetUpper(Vector64 value) + { + ThrowIfUnsupportedType(); + Vector64.ThrowIfUnsupportedType(); + + Vector128 result = this; + ref Vector64 lower = ref Unsafe.As, Vector64>(ref result); + Unsafe.Add(ref lower, 1) = value; + return result; + } + + public T ToScalar() + { + ThrowIfUnsupportedType(); + return Unsafe.As, T>(ref Unsafe.AsRef(in this)); + } + + public Vector256 ToVector256() + { + ThrowIfUnsupportedType(); + Vector256.ThrowIfUnsupportedType(); + + Vector256 result = Vector256.Zero; + Unsafe.As, Vector128>(ref result) = this; + return result; + } + + public unsafe Vector256 ToVector256Unsafe() + { + ThrowIfUnsupportedType(); + Vector256.ThrowIfUnsupportedType(); + + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc byte[Vector256.Size]; + Unsafe.AsRef>(pResult) = this; + return Unsafe.AsRef>(pResult); + } } } diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs new file mode 100644 index 000000000000..f926cf6bbd3e --- /dev/null +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs @@ -0,0 +1,757 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Internal.Runtime.CompilerServices; + +namespace System.Runtime.Intrinsics +{ + public static class Vector256 + { + internal const int Size = 32; + + public static unsafe Vector256 Create(byte value) + { + var pResult = stackalloc byte[32] + { + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 Create(double value) + { + var pResult = stackalloc double[4] + { + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 Create(short value) + { + var pResult = stackalloc short[16] + { + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 Create(int value) + { + var pResult = stackalloc int[8] + { + value, + value, + value, + value, + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 Create(long value) + { + var pResult = stackalloc long[4] + { + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector256 Create(sbyte value) + { + var pResult = stackalloc sbyte[32] + { + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 Create(float value) + { + var pResult = stackalloc float[8] + { + value, + value, + value, + value, + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector256 Create(ushort value) + { + var pResult = stackalloc ushort[16] + { + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector256 Create(uint value) + { + var pResult = stackalloc uint[8] + { + value, + value, + value, + value, + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector256 Create(ulong value) + { + var pResult = stackalloc ulong[4] + { + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 Create(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7, byte e8, byte e9, byte e10, byte e11, byte e12, byte e13, byte e14, byte e15, byte e16, byte e17, byte e18, byte e19, byte e20, byte e21, byte e22, byte e23, byte e24, byte e25, byte e26, byte e27, byte e28, byte e29, byte e30, byte e31) + { + var pResult = stackalloc byte[32] + { + e0, + e1, + e2, + e3, + e4, + e5, + e6, + e7, + e8, + e9, + e10, + e11, + e12, + e13, + e14, + e15, + e16, + e17, + e18, + e19, + e20, + e21, + e22, + e23, + e24, + e25, + e26, + e27, + e28, + e29, + e30, + e31, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 Create(double e0, double e1, double e2, double e3) + { + var pResult = stackalloc double[4] + { + e0, + e1, + e2, + e3, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 Create(short e0, short e1, short e2, short e3, short e4, short e5, short e6, short e7, short e8, short e9, short e10, short e11, short e12, short e13, short e14, short e15) + { + var pResult = stackalloc short[16] + { + e0, + e1, + e2, + e3, + e4, + e5, + e6, + e7, + e8, + e9, + e10, + e11, + e12, + e13, + e14, + e15, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 Create(int e0, int e1, int e2, int e3, int e4, int e5, int e6, int e7) + { + var pResult = stackalloc int[8] + { + e0, + e1, + e2, + e3, + e4, + e5, + e6, + e7, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 Create(long e0, long e1, long e2, long e3) + { + var pResult = stackalloc long[4] + { + e0, + e1, + e2, + e3, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector256 Create(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7, sbyte e8, sbyte e9, sbyte e10, sbyte e11, sbyte e12, sbyte e13, sbyte e14, sbyte e15, sbyte e16, sbyte e17, sbyte e18, sbyte e19, sbyte e20, sbyte e21, sbyte e22, sbyte e23, sbyte e24, sbyte e25, sbyte e26, sbyte e27, sbyte e28, sbyte e29, sbyte e30, sbyte e31) + { + var pResult = stackalloc sbyte[32] + { + e0, + e1, + e2, + e3, + e4, + e5, + e6, + e7, + e8, + e9, + e10, + e11, + e12, + e13, + e14, + e15, + e16, + e17, + e18, + e19, + e20, + e21, + e22, + e23, + e24, + e25, + e26, + e27, + e28, + e29, + e30, + e31, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 Create(float e0, float e1, float e2, float e3, float e4, float e5, float e6, float e7) + { + var pResult = stackalloc float[8] + { + e0, + e1, + e2, + e3, + e4, + e5, + e6, + e7, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector256 Create(ushort e0, ushort e1, ushort e2, ushort e3, ushort e4, ushort e5, ushort e6, ushort e7, ushort e8, ushort e9, ushort e10, ushort e11, ushort e12, ushort e13, ushort e14, ushort e15) + { + var pResult = stackalloc ushort[16] + { + e0, + e1, + e2, + e3, + e4, + e5, + e6, + e7, + e8, + e9, + e10, + e11, + e12, + e13, + e14, + e15, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector256 Create(uint e0, uint e1, uint e2, uint e3, uint e4, uint e5, uint e6, uint e7) + { + var pResult = stackalloc uint[8] + { + e0, + e1, + e2, + e3, + e4, + e5, + e6, + e7, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector256 Create(ulong e0, ulong e1, ulong e2, ulong e3) + { + var pResult = stackalloc ulong[4] + { + e0, + e1, + e2, + e3, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) + { + Vector256 result256 = Vector256.Zero; + + ref Vector128 result128 = ref Unsafe.As, Vector128>(ref result256); + result128 = lower; + Unsafe.Add(ref result128, 1) = upper; + + return result256; + } + + public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) + { + Vector256 result256 = Vector256.Zero; + + ref Vector128 result128 = ref Unsafe.As, Vector128>(ref result256); + result128 = lower; + Unsafe.Add(ref result128, 1) = upper; + + return result256; + } + + public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) + { + Vector256 result256 = Vector256.Zero; + + ref Vector128 result128 = ref Unsafe.As, Vector128>(ref result256); + result128 = lower; + Unsafe.Add(ref result128, 1) = upper; + + return result256; + } + + public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) + { + Vector256 result256 = Vector256.Zero; + + ref Vector128 result128 = ref Unsafe.As, Vector128>(ref result256); + result128 = lower; + Unsafe.Add(ref result128, 1) = upper; + + return result256; + } + + public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) + { + Vector256 result256 = Vector256.Zero; + + ref Vector128 result128 = ref Unsafe.As, Vector128>(ref result256); + result128 = lower; + Unsafe.Add(ref result128, 1) = upper; + + return result256; + } + + [CLSCompliant(false)] + public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) + { + Vector256 result256 = Vector256.Zero; + + ref Vector128 result128 = ref Unsafe.As, Vector128>(ref result256); + result128 = lower; + Unsafe.Add(ref result128, 1) = upper; + + return result256; + } + + public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) + { + Vector256 result256 = Vector256.Zero; + + ref Vector128 result128 = ref Unsafe.As, Vector128>(ref result256); + result128 = lower; + Unsafe.Add(ref result128, 1) = upper; + + return result256; + } + + [CLSCompliant(false)] + public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) + { + Vector256 result256 = Vector256.Zero; + + ref Vector128 result128 = ref Unsafe.As, Vector128>(ref result256); + result128 = lower; + Unsafe.Add(ref result128, 1) = upper; + + return result256; + } + + [CLSCompliant(false)] + public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) + { + Vector256 result256 = Vector256.Zero; + + ref Vector128 result128 = ref Unsafe.As, Vector128>(ref result256); + result128 = lower; + Unsafe.Add(ref result128, 1) = upper; + + return result256; + } + + [CLSCompliant(false)] + public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) + { + Vector256 result256 = Vector256.Zero; + + ref Vector128 result128 = ref Unsafe.As, Vector128>(ref result256); + result128 = lower; + Unsafe.Add(ref result128, 1) = upper; + + return result256; + } + + public static unsafe Vector256 CreateScalar(byte value) + { + var result = Vector256.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector256 CreateScalar(double value) + { + var result = Vector256.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector256 CreateScalar(short value) + { + var result = Vector256.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector256 CreateScalar(int value) + { + var result = Vector256.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector256 CreateScalar(long value) + { + var result = Vector256.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + [CLSCompliant(false)] + public static unsafe Vector256 CreateScalar(sbyte value) + { + var result = Vector256.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector256 CreateScalar(float value) + { + var result = Vector256.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + [CLSCompliant(false)] + public static unsafe Vector256 CreateScalar(ushort value) + { + var result = Vector256.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + [CLSCompliant(false)] + public static unsafe Vector256 CreateScalar(uint value) + { + var result = Vector256.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + [CLSCompliant(false)] + public static unsafe Vector256 CreateScalar(ulong value) + { + var result = Vector256.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector256 CreateScalarUnsafe(byte value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc byte[32]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 CreateScalarUnsafe(double value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc double[4]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 CreateScalarUnsafe(short value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc short[16]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 CreateScalarUnsafe(int value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc int[8]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 CreateScalarUnsafe(long value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc long[4]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector256 CreateScalarUnsafe(sbyte value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc sbyte[32]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector256 CreateScalarUnsafe(float value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc float[8]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector256 CreateScalarUnsafe(ushort value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc ushort[16]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector256 CreateScalarUnsafe(uint value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc uint[8]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector256 CreateScalarUnsafe(ulong value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc ulong[4]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + } +} diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs index 48744bb5eab3..350e188bfbe9 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs @@ -12,7 +12,7 @@ namespace System.Runtime.Intrinsics [Intrinsic] [DebuggerDisplay("{DisplayString,nq}")] [DebuggerTypeProxy(typeof(Vector256DebugView<>))] - [StructLayout(LayoutKind.Sequential, Size = 32)] + [StructLayout(LayoutKind.Sequential, Size = Vector256.Size)] public readonly struct Vector256 where T : struct { // These fields exist to ensure the alignment is 8, rather than 1. @@ -22,17 +22,22 @@ namespace System.Runtime.Intrinsics private readonly ulong _02; private readonly ulong _03; - private unsafe string DisplayString + public static Vector256 Zero { get { - // The IsPrimitive check ends up working for `bool`, `char`, `IntPtr`, and `UIntPtr` - // which are not actually supported by any current architecture. This shouldn't be - // an issue however and greatly simplifies the check + ThrowIfUnsupportedType(); + return default; + } + } - if (typeof(T).IsPrimitive) + internal unsafe string DisplayString + { + get + { + if (IsSupported) { - var items = new T[32 / Unsafe.SizeOf()]; + var items = new T[ElementCount]; Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), this); return $"({string.Join(", ", items)})"; } @@ -42,5 +47,141 @@ private unsafe string DisplayString } } } + + internal static int ElementCount + { + get + { + ThrowIfUnsupportedType(); + return Vector256.Size / Unsafe.SizeOf(); + } + } + + internal static bool IsSupported + { + get + { + return (typeof(T) == typeof(byte)) || + (typeof(T) == typeof(sbyte)) || + (typeof(T) == typeof(short)) || + (typeof(T) == typeof(ushort)) || + (typeof(T) == typeof(int)) || + (typeof(T) == typeof(uint)) || + (typeof(T) == typeof(long)) || + (typeof(T) == typeof(ulong)) || + (typeof(T) == typeof(float)) || + (typeof(T) == typeof(double)); + } + } + + internal static void ThrowIfUnsupportedType() + { + if (!IsSupported) + { + throw new NotSupportedException(SR.Arg_TypeNotSupported); + } + } + + public Vector256 As() where U : struct + { + ThrowIfUnsupportedType(); + Vector256.ThrowIfUnsupportedType(); + return Unsafe.As, Vector256>(ref Unsafe.AsRef(in this)); + } + + public Vector256 AsByte() => As(); + + public Vector256 AsDouble() => As(); + + public Vector256 AsInt16() => As(); + + public Vector256 AsInt32() => As(); + + public Vector256 AsInt64() => As(); + + [CLSCompliant(false)] + public Vector256 AsSByte() => As(); + + public Vector256 AsSingle() => As(); + + [CLSCompliant(false)] + public Vector256 AsUInt16() => As(); + + [CLSCompliant(false)] + public Vector256 AsUInt32() => As(); + + [CLSCompliant(false)] + public Vector256 AsUInt64() => As(); + + public T GetElement(int index) + { + ThrowIfUnsupportedType(); + + if ((uint)(index) >= (uint)(ElementCount)) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + + ref T e0 = ref Unsafe.As, T>(ref Unsafe.AsRef(in this)); + return Unsafe.Add(ref e0, index); + } + + public Vector256 SetElement(int index, T value) + { + ThrowIfUnsupportedType(); + + if ((uint)(index) >= (uint)(ElementCount)) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + + Vector256 result = this; + ref T e0 = ref Unsafe.As, T>(ref result); + Unsafe.Add(ref e0, index) = value; + return result; + } + + public Vector128 GetLower() + { + ThrowIfUnsupportedType(); + Vector128.ThrowIfUnsupportedType(); + return Unsafe.As, Vector128>(ref Unsafe.AsRef(in this)); + } + + public Vector256 SetLower(Vector128 value) + { + ThrowIfUnsupportedType(); + Vector128.ThrowIfUnsupportedType(); + + Vector256 result = this; + Unsafe.As, Vector128>(ref result) = value; + return result; + } + + public Vector128 GetUpper() + { + ThrowIfUnsupportedType(); + Vector128.ThrowIfUnsupportedType(); + + ref Vector128 lower = ref Unsafe.As, Vector128>(ref Unsafe.AsRef(in this)); + return Unsafe.Add(ref lower, 1); + } + + public Vector256 SetUpper(Vector128 value) + { + ThrowIfUnsupportedType(); + Vector128.ThrowIfUnsupportedType(); + + Vector256 result = this; + ref Vector128 lower = ref Unsafe.As, Vector128>(ref result); + Unsafe.Add(ref lower, 1) = value; + return result; + } + + public T ToScalar() + { + ThrowIfUnsupportedType(); + return Unsafe.As, T>(ref Unsafe.AsRef(in this)); + } } } diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs new file mode 100644 index 000000000000..7988bb442b54 --- /dev/null +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs @@ -0,0 +1,346 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Internal.Runtime.CompilerServices; + +namespace System.Runtime.Intrinsics +{ + public static class Vector64 + { + internal const int Size = 8; + + public static unsafe Vector64 Create(byte value) + { + var pResult = stackalloc byte[8] + { + value, + value, + value, + value, + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector64 Create(double value) + { + return Unsafe.As>(ref value); + } + + public static unsafe Vector64 Create(short value) + { + var pResult = stackalloc short[4] + { + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector64 Create(int value) + { + var pResult = stackalloc int[2] + { + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector64 Create(long value) + { + return Unsafe.As>(ref value); + } + + [CLSCompliant(false)] + public static unsafe Vector64 Create(sbyte value) + { + var pResult = stackalloc sbyte[8] + { + value, + value, + value, + value, + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector64 Create(float value) + { + var pResult = stackalloc float[2] + { + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector64 Create(ushort value) + { + var pResult = stackalloc ushort[4] + { + value, + value, + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector64 Create(uint value) + { + var pResult = stackalloc uint[2] + { + value, + value, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector64 Create(ulong value) + { + return Unsafe.As>(ref value); + } + + public static unsafe Vector64 Create(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7) + { + var pResult = stackalloc byte[8] + { + e0, + e1, + e2, + e3, + e4, + e5, + e6, + e7, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector64 Create(short e0, short e1, short e2, short e3) + { + var pResult = stackalloc short[4] + { + e0, + e1, + e2, + e3, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector64 Create(int e0, int e1) + { + var pResult = stackalloc int[2] + { + e0, + e1, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector64 Create(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7) + { + var pResult = stackalloc sbyte[8] + { + e0, + e1, + e2, + e3, + e4, + e5, + e6, + e7, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector64 Create(float e0, float e1) + { + var pResult = stackalloc float[2] + { + e0, + e1, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector64 Create(ushort e0, ushort e1, ushort e2, ushort e3) + { + var pResult = stackalloc ushort[4] + { + e0, + e1, + e2, + e3, + }; + + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector64 Create(uint e0, uint e1) + { + var pResult = stackalloc uint[2] + { + e0, + e1, + }; + + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector64 CreateScalar(byte value) + { + var result = Vector64.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector64 CreateScalar(short value) + { + var result = Vector64.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector64 CreateScalar(int value) + { + var result = Vector64.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + [CLSCompliant(false)] + public static unsafe Vector64 CreateScalar(sbyte value) + { + var result = Vector64.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector64 CreateScalar(float value) + { + var result = Vector64.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + [CLSCompliant(false)] + public static unsafe Vector64 CreateScalar(ushort value) + { + var result = Vector64.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + [CLSCompliant(false)] + public static unsafe Vector64 CreateScalar(uint value) + { + var result = Vector64.Zero; + Unsafe.WriteUnaligned(ref Unsafe.As, byte>(ref result), value); + return result; + } + + public static unsafe Vector64 CreateScalarUnsafe(byte value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc byte[8]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector64 CreateScalarUnsafe(short value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc short[4]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector64 CreateScalarUnsafe(int value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc int[2]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector64 CreateScalarUnsafe(sbyte value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc sbyte[8]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + public static unsafe Vector64 CreateScalarUnsafe(float value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc float[2]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector64 CreateScalarUnsafe(ushort value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc ushort[4]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + + [CLSCompliant(false)] + public static unsafe Vector64 CreateScalarUnsafe(uint value) + { + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc uint[2]; + pResult[0] = value; + return Unsafe.AsRef>(pResult); + } + } +} diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs index 8ce90b9d0fa7..87bbfc3e076e 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs @@ -12,24 +12,29 @@ namespace System.Runtime.Intrinsics [Intrinsic] [DebuggerDisplay("{DisplayString,nq}")] [DebuggerTypeProxy(typeof(Vector64DebugView<>))] - [StructLayout(LayoutKind.Sequential, Size = 8)] + [StructLayout(LayoutKind.Sequential, Size = Vector64.Size)] public readonly struct Vector64 where T : struct { // These fields exist to ensure the alignment is 8, rather than 1. // This also allows the debug view to work https://github.com/dotnet/coreclr/issues/15694) private readonly ulong _00; - private unsafe string DisplayString + public static Vector64 Zero { get { - // The IsPrimitive check ends up working for `bool`, `char`, `IntPtr`, and `UIntPtr` - // which are not actually supported by any current architecture. This shouldn't be - // an issue however and greatly simplifies the check + ThrowIfUnsupportedType(); + return default; + } + } - if (typeof(T).IsPrimitive) + internal unsafe string DisplayString + { + get + { + if (IsSupported) { - var items = new T[8 / Unsafe.SizeOf()]; + var items = new T[ElementCount]; Unsafe.WriteUnaligned(ref Unsafe.As(ref items[0]), this); return $"({string.Join(", ", items)})"; } @@ -39,5 +44,127 @@ private unsafe string DisplayString } } } + + internal static int ElementCount + { + get + { + ThrowIfUnsupportedType(); + return Vector64.Size / Unsafe.SizeOf(); + } + } + + internal static bool IsSupported + { + get + { + return (typeof(T) == typeof(byte)) || + (typeof(T) == typeof(sbyte)) || + (typeof(T) == typeof(short)) || + (typeof(T) == typeof(ushort)) || + (typeof(T) == typeof(int)) || + (typeof(T) == typeof(uint)) || + (typeof(T) == typeof(long)) || + (typeof(T) == typeof(ulong)) || + (typeof(T) == typeof(float)) || + (typeof(T) == typeof(double)); + } + } + + internal static void ThrowIfUnsupportedType() + { + if (!IsSupported) + { + throw new NotSupportedException(SR.Arg_TypeNotSupported); + } + } + + public Vector64 As() where U : struct + { + ThrowIfUnsupportedType(); + Vector64.ThrowIfUnsupportedType(); + return Unsafe.As, Vector64>(ref Unsafe.AsRef(in this)); + } + + public Vector64 AsByte() => As(); + + public Vector64 AsDouble() => As(); + + public Vector64 AsInt16() => As(); + + public Vector64 AsInt32() => As(); + + public Vector64 AsInt64() => As(); + + [CLSCompliant(false)] + public Vector64 AsSByte() => As(); + + public Vector64 AsSingle() => As(); + + [CLSCompliant(false)] + public Vector64 AsUInt16() => As(); + + [CLSCompliant(false)] + public Vector64 AsUInt32() => As(); + + [CLSCompliant(false)] + public Vector64 AsUInt64() => As(); + + public T GetElement(int index) + { + ThrowIfUnsupportedType(); + + if ((uint)(index) >= (uint)(ElementCount)) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + + ref T e0 = ref Unsafe.As, T>(ref Unsafe.AsRef(in this)); + return Unsafe.Add(ref e0, index); + } + + public Vector64 SetElement(int index, T value) + { + ThrowIfUnsupportedType(); + + if ((uint)(index) >= (uint)(ElementCount)) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + + Vector64 result = this; + ref T e0 = ref Unsafe.As, T>(ref result); + Unsafe.Add(ref e0, index) = value; + return result; + } + + public T ToScalar() + { + ThrowIfUnsupportedType(); + return Unsafe.As, T>(ref Unsafe.AsRef(in this)); + } + + public Vector128 ToVector128() + { + ThrowIfUnsupportedType(); + Vector128.ThrowIfUnsupportedType(); + + Vector128 result = Vector128.Zero; + Unsafe.As, Vector64>(ref result) = this; + return result; + } + + public unsafe Vector128 ToVector128Unsafe() + { + ThrowIfUnsupportedType(); + Vector128.ThrowIfUnsupportedType(); + + // This relies on us stripping the "init" flag from the ".locals" + // declaration to let the upper bits be uninitialized. + + var pResult = stackalloc byte[Vector128.Size]; + Unsafe.AsRef>(pResult) = this; + return Unsafe.AsRef>(pResult); + } } } From dc2a4d1058a2b246dc14e7ceec3dfa7860470c08 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Wed, 7 Nov 2018 07:39:27 -0800 Subject: [PATCH 3/4] Adding some documentation comments to the System.Runtime.Intrinsics.Vector types --- .../System/Runtime/Intrinsics/Vector128.cs | 216 ++++++++++++++ .../System/Runtime/Intrinsics/Vector128_1.cs | 70 +++++ .../System/Runtime/Intrinsics/Vector256.cs | 282 ++++++++++++++++++ .../System/Runtime/Intrinsics/Vector256_1.cs | 64 ++++ .../System/Runtime/Intrinsics/Vector64.cs | 116 +++++++ .../System/Runtime/Intrinsics/Vector64_1.cs | 56 ++++ 6 files changed, 804 insertions(+) diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs index 12ee75c18e01..f8eefb7dc092 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs @@ -10,6 +10,9 @@ public static class Vector128 { internal const int Size = 16; + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector128 Create(byte value) { var pResult = stackalloc byte[16] @@ -35,6 +38,9 @@ public static unsafe Vector128 Create(byte value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector128 Create(double value) { var pResult = stackalloc double[2] @@ -46,6 +52,9 @@ public static unsafe Vector128 Create(double value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector128 Create(short value) { var pResult = stackalloc short[8] @@ -63,6 +72,9 @@ public static unsafe Vector128 Create(short value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector128 Create(int value) { var pResult = stackalloc int[4] @@ -76,6 +88,9 @@ public static unsafe Vector128 Create(int value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector128 Create(long value) { var pResult = stackalloc long[2] @@ -87,6 +102,9 @@ public static unsafe Vector128 Create(long value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . [CLSCompliant(false)] public static unsafe Vector128 Create(sbyte value) { @@ -113,6 +131,9 @@ public static unsafe Vector128 Create(sbyte value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector128 Create(float value) { var pResult = stackalloc float[4] @@ -126,6 +147,9 @@ public static unsafe Vector128 Create(float value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . [CLSCompliant(false)] public static unsafe Vector128 Create(ushort value) { @@ -144,6 +168,9 @@ public static unsafe Vector128 Create(ushort value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . [CLSCompliant(false)] public static unsafe Vector128 Create(uint value) { @@ -158,6 +185,9 @@ public static unsafe Vector128 Create(uint value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . [CLSCompliant(false)] public static unsafe Vector128 Create(ulong value) { @@ -170,6 +200,24 @@ public static unsafe Vector128 Create(ulong value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// The value that element 4 will be initialized to. + /// The value that element 5 will be initialized to. + /// The value that element 6 will be initialized to. + /// The value that element 7 will be initialized to. + /// The value that element 8 will be initialized to. + /// The value that element 9 will be initialized to. + /// The value that element 10 will be initialized to. + /// The value that element 11 will be initialized to. + /// The value that element 12 will be initialized to. + /// The value that element 13 will be initialized to. + /// The value that element 14 will be initialized to. + /// The value that element 15 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector128 Create(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7, byte e8, byte e9, byte e10, byte e11, byte e12, byte e13, byte e14, byte e15) { var pResult = stackalloc byte[16] @@ -195,6 +243,10 @@ public static unsafe Vector128 Create(byte e0, byte e1, byte e2, byte e3, return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector128 Create(double e0, double e1) { var pResult = stackalloc double[2] @@ -206,6 +258,16 @@ public static unsafe Vector128 Create(double e0, double e1) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// The value that element 4 will be initialized to. + /// The value that element 5 will be initialized to. + /// The value that element 6 will be initialized to. + /// The value that element 7 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector128 Create(short e0, short e1, short e2, short e3, short e4, short e5, short e6, short e7) { var pResult = stackalloc short[8] @@ -223,6 +285,12 @@ public static unsafe Vector128 Create(short e0, short e1, short e2, short return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector128 Create(int e0, int e1, int e2, int e3) { var pResult = stackalloc int[4] @@ -236,6 +304,10 @@ public static unsafe Vector128 Create(int e0, int e1, int e2, int e3) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector128 Create(long e0, long e1) { var pResult = stackalloc long[2] @@ -247,6 +319,24 @@ public static unsafe Vector128 Create(long e0, long e1) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// The value that element 4 will be initialized to. + /// The value that element 5 will be initialized to. + /// The value that element 6 will be initialized to. + /// The value that element 7 will be initialized to. + /// The value that element 8 will be initialized to. + /// The value that element 9 will be initialized to. + /// The value that element 10 will be initialized to. + /// The value that element 11 will be initialized to. + /// The value that element 12 will be initialized to. + /// The value that element 13 will be initialized to. + /// The value that element 14 will be initialized to. + /// The value that element 15 will be initialized to. + /// A new with each element initialized to corresponding specified value. [CLSCompliant(false)] public static unsafe Vector128 Create(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7, sbyte e8, sbyte e9, sbyte e10, sbyte e11, sbyte e12, sbyte e13, sbyte e14, sbyte e15) { @@ -273,6 +363,12 @@ public static unsafe Vector128 Create(sbyte e0, sbyte e1, sbyte e2, sbyte return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector128 Create(float e0, float e1, float e2, float e3) { var pResult = stackalloc float[4] @@ -286,6 +382,16 @@ public static unsafe Vector128 Create(float e0, float e1, float e2, float return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// The value that element 4 will be initialized to. + /// The value that element 5 will be initialized to. + /// The value that element 6 will be initialized to. + /// The value that element 7 will be initialized to. + /// A new with each element initialized to corresponding specified value. [CLSCompliant(false)] public static unsafe Vector128 Create(ushort e0, ushort e1, ushort e2, ushort e3, ushort e4, ushort e5, ushort e6, ushort e7) { @@ -304,6 +410,12 @@ public static unsafe Vector128 Create(ushort e0, ushort e1, ushort e2, u return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// A new with each element initialized to corresponding specified value. [CLSCompliant(false)] public static unsafe Vector128 Create(uint e0, uint e1, uint e2, uint e3) { @@ -318,6 +430,10 @@ public static unsafe Vector128 Create(uint e0, uint e1, uint e2, uint e3) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// A new with each element initialized to corresponding specified value. [CLSCompliant(false)] public static unsafe Vector128 Create(ulong e0, ulong e1) { @@ -330,6 +446,10 @@ public static unsafe Vector128 Create(ulong e0, ulong e1) return Unsafe.AsRef>(pResult); } + /// Creates a new instance from two instances. + /// The value that the lower 64-bits will be initialized to. + /// The value that the upper 64-bits will be initialized to. + /// A new initialized from and . public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) { Vector128 result128 = Vector128.Zero; @@ -341,6 +461,10 @@ public static unsafe Vector128 Create(Vector64 lower, Vector64 return result128; } + /// Creates a new instance from two instances. + /// The value that the lower 64-bits will be initialized to. + /// The value that the upper 64-bits will be initialized to. + /// A new initialized from and . public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) { Vector128 result128 = Vector128.Zero; @@ -352,6 +476,10 @@ public static unsafe Vector128 Create(Vector64 lower, Vector64Creates a new instance from two instances. + /// The value that the lower 64-bits will be initialized to. + /// The value that the upper 64-bits will be initialized to. + /// A new initialized from and . public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) { Vector128 result128 = Vector128.Zero; @@ -363,6 +491,10 @@ public static unsafe Vector128 Create(Vector64 lower, Vector64Creates a new instance from two instances. + /// The value that the lower 64-bits will be initialized to. + /// The value that the upper 64-bits will be initialized to. + /// A new initialized from and . public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) { Vector128 result128 = Vector128.Zero; @@ -374,6 +506,10 @@ public static unsafe Vector128 Create(Vector64 lower, Vector64 up return result128; } + /// Creates a new instance from two instances. + /// The value that the lower 64-bits will be initialized to. + /// The value that the upper 64-bits will be initialized to. + /// A new initialized from and . public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) { Vector128 result128 = Vector128.Zero; @@ -385,6 +521,10 @@ public static unsafe Vector128 Create(Vector64 lower, Vector64 return result128; } + /// Creates a new instance from two instances. + /// The value that the lower 64-bits will be initialized to. + /// The value that the upper 64-bits will be initialized to. + /// A new initialized from and . [CLSCompliant(false)] public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) { @@ -397,6 +537,10 @@ public static unsafe Vector128 Create(Vector64 lower, Vector64Creates a new instance from two instances. + /// The value that the lower 64-bits will be initialized to. + /// The value that the upper 64-bits will be initialized to. + /// A new initialized from and . public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) { Vector128 result128 = Vector128.Zero; @@ -408,6 +552,10 @@ public static unsafe Vector128 Create(Vector64 lower, Vector64Creates a new instance from two instances. + /// The value that the lower 64-bits will be initialized to. + /// The value that the upper 64-bits will be initialized to. + /// A new initialized from and . [CLSCompliant(false)] public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) { @@ -420,6 +568,10 @@ public static unsafe Vector128 Create(Vector64 lower, Vector64Creates a new instance from two instances. + /// The value that the lower 64-bits will be initialized to. + /// The value that the upper 64-bits will be initialized to. + /// A new initialized from and . [CLSCompliant(false)] public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) { @@ -432,6 +584,10 @@ public static unsafe Vector128 Create(Vector64 lower, Vector64 return result128; } + /// Creates a new instance from two instances. + /// The value that the lower 64-bits will be initialized to. + /// The value that the upper 64-bits will be initialized to. + /// A new initialized from and . [CLSCompliant(false)] public static unsafe Vector128 Create(Vector64 lower, Vector64 upper) { @@ -444,6 +600,9 @@ public static unsafe Vector128 Create(Vector64 lower, Vector64Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector128 CreateScalar(byte value) { var result = Vector128.Zero; @@ -451,6 +610,9 @@ public static unsafe Vector128 CreateScalar(byte value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector128 CreateScalar(double value) { var result = Vector128.Zero; @@ -458,6 +620,9 @@ public static unsafe Vector128 CreateScalar(double value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector128 CreateScalar(short value) { var result = Vector128.Zero; @@ -465,6 +630,9 @@ public static unsafe Vector128 CreateScalar(short value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector128 CreateScalar(int value) { var result = Vector128.Zero; @@ -472,6 +640,9 @@ public static unsafe Vector128 CreateScalar(int value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector128 CreateScalar(long value) { var result = Vector128.Zero; @@ -479,6 +650,9 @@ public static unsafe Vector128 CreateScalar(long value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. [CLSCompliant(false)] public static unsafe Vector128 CreateScalar(sbyte value) { @@ -487,6 +661,9 @@ public static unsafe Vector128 CreateScalar(sbyte value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector128 CreateScalar(float value) { var result = Vector128.Zero; @@ -494,6 +671,9 @@ public static unsafe Vector128 CreateScalar(float value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. [CLSCompliant(false)] public static unsafe Vector128 CreateScalar(ushort value) { @@ -502,6 +682,9 @@ public static unsafe Vector128 CreateScalar(ushort value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. [CLSCompliant(false)] public static unsafe Vector128 CreateScalar(uint value) { @@ -510,6 +693,9 @@ public static unsafe Vector128 CreateScalar(uint value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. [CLSCompliant(false)] public static unsafe Vector128 CreateScalar(ulong value) { @@ -518,6 +704,9 @@ public static unsafe Vector128 CreateScalar(ulong value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector128 CreateScalarUnsafe(byte value) { // This relies on us stripping the "init" flag from the ".locals" @@ -528,6 +717,9 @@ public static unsafe Vector128 CreateScalarUnsafe(byte value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector128 CreateScalarUnsafe(double value) { // This relies on us stripping the "init" flag from the ".locals" @@ -538,6 +730,9 @@ public static unsafe Vector128 CreateScalarUnsafe(double value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector128 CreateScalarUnsafe(short value) { // This relies on us stripping the "init" flag from the ".locals" @@ -548,6 +743,9 @@ public static unsafe Vector128 CreateScalarUnsafe(short value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector128 CreateScalarUnsafe(int value) { // This relies on us stripping the "init" flag from the ".locals" @@ -558,6 +756,9 @@ public static unsafe Vector128 CreateScalarUnsafe(int value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector128 CreateScalarUnsafe(long value) { // This relies on us stripping the "init" flag from the ".locals" @@ -568,6 +769,9 @@ public static unsafe Vector128 CreateScalarUnsafe(long value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. [CLSCompliant(false)] public static unsafe Vector128 CreateScalarUnsafe(sbyte value) { @@ -579,6 +783,9 @@ public static unsafe Vector128 CreateScalarUnsafe(sbyte value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector128 CreateScalarUnsafe(float value) { // This relies on us stripping the "init" flag from the ".locals" @@ -589,6 +796,9 @@ public static unsafe Vector128 CreateScalarUnsafe(float value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. [CLSCompliant(false)] public static unsafe Vector128 CreateScalarUnsafe(ushort value) { @@ -600,6 +810,9 @@ public static unsafe Vector128 CreateScalarUnsafe(ushort value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. [CLSCompliant(false)] public static unsafe Vector128 CreateScalarUnsafe(uint value) { @@ -611,6 +824,9 @@ public static unsafe Vector128 CreateScalarUnsafe(uint value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. [CLSCompliant(false)] public static unsafe Vector128 CreateScalarUnsafe(ulong value) { diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs index ad4087c558d8..0e05152ee5c4 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs @@ -20,6 +20,8 @@ namespace System.Runtime.Intrinsics private readonly ulong _00; private readonly ulong _01; + /// Gets a new with all elements initialized to zero. + /// The type of the current instance () is not supported. public static Vector128 Zero { get @@ -80,6 +82,10 @@ internal static void ThrowIfUnsupportedType() } } + /// Reinterprets the current instance as a new . + /// The type of the vector the current instance should be reinterpreted as. + /// The current instance reinterpreted as a new . + /// The type of the current instance () or the type of the target () is not supported. public Vector128 As() where U : struct { ThrowIfUnsupportedType(); @@ -87,30 +93,65 @@ public Vector128 As() where U : struct return Unsafe.As, Vector128>(ref Unsafe.AsRef(in this)); } + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector128 AsByte() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector128 AsDouble() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector128 AsInt16() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector128 AsInt32() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector128 AsInt64() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. [CLSCompliant(false)] public Vector128 AsSByte() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector128 AsSingle() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. [CLSCompliant(false)] public Vector128 AsUInt16() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. [CLSCompliant(false)] public Vector128 AsUInt32() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. [CLSCompliant(false)] public Vector128 AsUInt64() => As(); + /// Gets the element at the specified index. + /// The index of the element to get. + /// The value of the element at . + /// The type of the current instance () is not supported. + /// was less than zero or greater than the number of elements. public T GetElement(int index) { ThrowIfUnsupportedType(); @@ -124,6 +165,12 @@ public T GetElement(int index) return Unsafe.Add(ref e0, index); } + /// Creates a new with the element at the specified index set to the specified value and the remaining elements set to the same value as that in the current instance. + /// The index of the element to set. + /// The value to set the value to. + /// A with the value of the element at set to and the remaining elements set to the same value as that in the current instance. + /// The type of the current instance () is not supported. + /// was less than zero or greater than the number of elements. public Vector128 SetElement(int index, T value) { ThrowIfUnsupportedType(); @@ -139,6 +186,9 @@ public Vector128 SetElement(int index, T value) return result; } + /// Gets the value of the lower 64-bits as a new . + /// The value of the lower 64-bits as a new . + /// The type of the current instance () is not supported. public Vector64 GetLower() { ThrowIfUnsupportedType(); @@ -146,6 +196,10 @@ public Vector64 GetLower() return Unsafe.As, Vector64>(ref Unsafe.AsRef(in this)); } + /// Creates a new with the lower 64-bits set to the specified value and the upper 64-bits set to the same value as that in the current instance. + /// The value of the lower 64-bits as a . + /// A new with the lower 64-bits set to the specified value and the upper 64-bits set to the same value as that in the current instance. + /// The type of the current instance () is not supported. public Vector128 SetLower(Vector64 value) { ThrowIfUnsupportedType(); @@ -156,6 +210,9 @@ public Vector128 SetLower(Vector64 value) return result; } + /// Gets the value of the upper 64-bits as a new . + /// The value of the upper 64-bits as a new . + /// The type of the current instance () is not supported. public Vector64 GetUpper() { ThrowIfUnsupportedType(); @@ -165,6 +222,10 @@ public Vector64 GetUpper() return Unsafe.Add(ref lower, 1); } + /// Creates a new with the upper 64-bits set to the specified value and the upper 64-bits set to the same value as that in the current instance. + /// The value of the upper 64-bits as a . + /// A new with the upper 64-bits set to the specified value and the upper 64-bits set to the same value as that in the current instance. + /// The type of the current instance () is not supported. public Vector128 SetUpper(Vector64 value) { ThrowIfUnsupportedType(); @@ -176,12 +237,18 @@ public Vector128 SetUpper(Vector64 value) return result; } + /// Converts the current instance to a scalar containing the value of the first element. + /// A scalar containing the value of the first element. + /// The type of the current instance () is not supported. public T ToScalar() { ThrowIfUnsupportedType(); return Unsafe.As, T>(ref Unsafe.AsRef(in this)); } + /// Converts the current instance to a new with the lower 128-bits set to the value of the current instance and the upper 128-bits initialized to zero. + /// A new with the lower 128-bits set to the value of the current instance and the upper 128-bits initialized to zero. + /// The type of the current instance () is not supported. public Vector256 ToVector256() { ThrowIfUnsupportedType(); @@ -192,6 +259,9 @@ public Vector256 ToVector256() return result; } + /// Converts the current instance to a new with the lower 128-bits set to the value of the current instance and the upper 128-bits left uninitialized. + /// A new with the lower 128-bits set to the value of the current instance and the upper 128-bits left uninitialized. + /// The type of the current instance () is not supported. public unsafe Vector256 ToVector256Unsafe() { ThrowIfUnsupportedType(); diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs index f926cf6bbd3e..a4f4cd66d719 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs @@ -10,6 +10,9 @@ public static class Vector256 { internal const int Size = 32; + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector256 Create(byte value) { var pResult = stackalloc byte[32] @@ -51,6 +54,9 @@ public static unsafe Vector256 Create(byte value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector256 Create(double value) { var pResult = stackalloc double[4] @@ -64,6 +70,9 @@ public static unsafe Vector256 Create(double value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector256 Create(short value) { var pResult = stackalloc short[16] @@ -89,6 +98,9 @@ public static unsafe Vector256 Create(short value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector256 Create(int value) { var pResult = stackalloc int[8] @@ -106,6 +118,9 @@ public static unsafe Vector256 Create(int value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector256 Create(long value) { var pResult = stackalloc long[4] @@ -119,6 +134,9 @@ public static unsafe Vector256 Create(long value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . [CLSCompliant(false)] public static unsafe Vector256 Create(sbyte value) { @@ -161,6 +179,9 @@ public static unsafe Vector256 Create(sbyte value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector256 Create(float value) { var pResult = stackalloc float[8] @@ -178,6 +199,9 @@ public static unsafe Vector256 Create(float value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . [CLSCompliant(false)] public static unsafe Vector256 Create(ushort value) { @@ -204,6 +228,9 @@ public static unsafe Vector256 Create(ushort value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . [CLSCompliant(false)] public static unsafe Vector256 Create(uint value) { @@ -222,6 +249,9 @@ public static unsafe Vector256 Create(uint value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . [CLSCompliant(false)] public static unsafe Vector256 Create(ulong value) { @@ -236,6 +266,40 @@ public static unsafe Vector256 Create(ulong value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// The value that element 4 will be initialized to. + /// The value that element 5 will be initialized to. + /// The value that element 6 will be initialized to. + /// The value that element 7 will be initialized to. + /// The value that element 8 will be initialized to. + /// The value that element 9 will be initialized to. + /// The value that element 10 will be initialized to. + /// The value that element 11 will be initialized to. + /// The value that element 12 will be initialized to. + /// The value that element 13 will be initialized to. + /// The value that element 14 will be initialized to. + /// The value that element 15 will be initialized to. + /// The value that element 16 will be initialized to. + /// The value that element 17 will be initialized to. + /// The value that element 18 will be initialized to. + /// The value that element 19 will be initialized to. + /// The value that element 20 will be initialized to. + /// The value that element 21 will be initialized to. + /// The value that element 22 will be initialized to. + /// The value that element 23 will be initialized to. + /// The value that element 24 will be initialized to. + /// The value that element 25 will be initialized to. + /// The value that element 26 will be initialized to. + /// The value that element 27 will be initialized to. + /// The value that element 28 will be initialized to. + /// The value that element 29 will be initialized to. + /// The value that element 30 will be initialized to. + /// The value that element 31 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector256 Create(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7, byte e8, byte e9, byte e10, byte e11, byte e12, byte e13, byte e14, byte e15, byte e16, byte e17, byte e18, byte e19, byte e20, byte e21, byte e22, byte e23, byte e24, byte e25, byte e26, byte e27, byte e28, byte e29, byte e30, byte e31) { var pResult = stackalloc byte[32] @@ -277,6 +341,12 @@ public static unsafe Vector256 Create(byte e0, byte e1, byte e2, byte e3, return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector256 Create(double e0, double e1, double e2, double e3) { var pResult = stackalloc double[4] @@ -290,6 +360,24 @@ public static unsafe Vector256 Create(double e0, double e1, double e2, d return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// The value that element 4 will be initialized to. + /// The value that element 5 will be initialized to. + /// The value that element 6 will be initialized to. + /// The value that element 7 will be initialized to. + /// The value that element 8 will be initialized to. + /// The value that element 9 will be initialized to. + /// The value that element 10 will be initialized to. + /// The value that element 11 will be initialized to. + /// The value that element 12 will be initialized to. + /// The value that element 13 will be initialized to. + /// The value that element 14 will be initialized to. + /// The value that element 15 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector256 Create(short e0, short e1, short e2, short e3, short e4, short e5, short e6, short e7, short e8, short e9, short e10, short e11, short e12, short e13, short e14, short e15) { var pResult = stackalloc short[16] @@ -315,6 +403,16 @@ public static unsafe Vector256 Create(short e0, short e1, short e2, short return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// The value that element 4 will be initialized to. + /// The value that element 5 will be initialized to. + /// The value that element 6 will be initialized to. + /// The value that element 7 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector256 Create(int e0, int e1, int e2, int e3, int e4, int e5, int e6, int e7) { var pResult = stackalloc int[8] @@ -332,6 +430,12 @@ public static unsafe Vector256 Create(int e0, int e1, int e2, int e3, int e return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector256 Create(long e0, long e1, long e2, long e3) { var pResult = stackalloc long[4] @@ -345,6 +449,40 @@ public static unsafe Vector256 Create(long e0, long e1, long e2, long e3) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// The value that element 4 will be initialized to. + /// The value that element 5 will be initialized to. + /// The value that element 6 will be initialized to. + /// The value that element 7 will be initialized to. + /// The value that element 8 will be initialized to. + /// The value that element 9 will be initialized to. + /// The value that element 10 will be initialized to. + /// The value that element 11 will be initialized to. + /// The value that element 12 will be initialized to. + /// The value that element 13 will be initialized to. + /// The value that element 14 will be initialized to. + /// The value that element 15 will be initialized to. + /// The value that element 16 will be initialized to. + /// The value that element 17 will be initialized to. + /// The value that element 18 will be initialized to. + /// The value that element 19 will be initialized to. + /// The value that element 20 will be initialized to. + /// The value that element 21 will be initialized to. + /// The value that element 22 will be initialized to. + /// The value that element 23 will be initialized to. + /// The value that element 24 will be initialized to. + /// The value that element 25 will be initialized to. + /// The value that element 26 will be initialized to. + /// The value that element 27 will be initialized to. + /// The value that element 28 will be initialized to. + /// The value that element 29 will be initialized to. + /// The value that element 30 will be initialized to. + /// The value that element 31 will be initialized to. + /// A new with each element initialized to corresponding specified value. [CLSCompliant(false)] public static unsafe Vector256 Create(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7, sbyte e8, sbyte e9, sbyte e10, sbyte e11, sbyte e12, sbyte e13, sbyte e14, sbyte e15, sbyte e16, sbyte e17, sbyte e18, sbyte e19, sbyte e20, sbyte e21, sbyte e22, sbyte e23, sbyte e24, sbyte e25, sbyte e26, sbyte e27, sbyte e28, sbyte e29, sbyte e30, sbyte e31) { @@ -387,6 +525,16 @@ public static unsafe Vector256 Create(sbyte e0, sbyte e1, sbyte e2, sbyte return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// The value that element 4 will be initialized to. + /// The value that element 5 will be initialized to. + /// The value that element 6 will be initialized to. + /// The value that element 7 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector256 Create(float e0, float e1, float e2, float e3, float e4, float e5, float e6, float e7) { var pResult = stackalloc float[8] @@ -404,6 +552,24 @@ public static unsafe Vector256 Create(float e0, float e1, float e2, float return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// The value that element 4 will be initialized to. + /// The value that element 5 will be initialized to. + /// The value that element 6 will be initialized to. + /// The value that element 7 will be initialized to. + /// The value that element 8 will be initialized to. + /// The value that element 9 will be initialized to. + /// The value that element 10 will be initialized to. + /// The value that element 11 will be initialized to. + /// The value that element 12 will be initialized to. + /// The value that element 13 will be initialized to. + /// The value that element 14 will be initialized to. + /// The value that element 15 will be initialized to. + /// A new with each element initialized to corresponding specified value. [CLSCompliant(false)] public static unsafe Vector256 Create(ushort e0, ushort e1, ushort e2, ushort e3, ushort e4, ushort e5, ushort e6, ushort e7, ushort e8, ushort e9, ushort e10, ushort e11, ushort e12, ushort e13, ushort e14, ushort e15) { @@ -430,6 +596,16 @@ public static unsafe Vector256 Create(ushort e0, ushort e1, ushort e2, u return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// The value that element 4 will be initialized to. + /// The value that element 5 will be initialized to. + /// The value that element 6 will be initialized to. + /// The value that element 7 will be initialized to. + /// A new with each element initialized to corresponding specified value. [CLSCompliant(false)] public static unsafe Vector256 Create(uint e0, uint e1, uint e2, uint e3, uint e4, uint e5, uint e6, uint e7) { @@ -448,6 +624,12 @@ public static unsafe Vector256 Create(uint e0, uint e1, uint e2, uint e3, return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// A new with each element initialized to corresponding specified value. [CLSCompliant(false)] public static unsafe Vector256 Create(ulong e0, ulong e1, ulong e2, ulong e3) { @@ -462,6 +644,10 @@ public static unsafe Vector256 Create(ulong e0, ulong e1, ulong e2, ulong return Unsafe.AsRef>(pResult); } + /// Creates a new instance from two instances. + /// The value that the lower 128-bits will be initialized to. + /// The value that the upper 128-bits will be initialized to. + /// A new initialized from and . public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) { Vector256 result256 = Vector256.Zero; @@ -473,6 +659,10 @@ public static unsafe Vector256 Create(Vector128 lower, Vector128Creates a new instance from two instances. + /// The value that the lower 128-bits will be initialized to. + /// The value that the upper 128-bits will be initialized to. + /// A new initialized from and . public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) { Vector256 result256 = Vector256.Zero; @@ -484,6 +674,10 @@ public static unsafe Vector256 Create(Vector128 lower, Vector128 return result256; } + /// Creates a new instance from two instances. + /// The value that the lower 128-bits will be initialized to. + /// The value that the upper 128-bits will be initialized to. + /// A new initialized from and . public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) { Vector256 result256 = Vector256.Zero; @@ -495,6 +689,10 @@ public static unsafe Vector256 Create(Vector128 lower, Vector128Creates a new instance from two instances. + /// The value that the lower 128-bits will be initialized to. + /// The value that the upper 128-bits will be initialized to. + /// A new initialized from and . public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) { Vector256 result256 = Vector256.Zero; @@ -506,6 +704,10 @@ public static unsafe Vector256 Create(Vector128 lower, Vector128 return result256; } + /// Creates a new instance from two instances. + /// The value that the lower 128-bits will be initialized to. + /// The value that the upper 128-bits will be initialized to. + /// A new initialized from and . public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) { Vector256 result256 = Vector256.Zero; @@ -517,6 +719,10 @@ public static unsafe Vector256 Create(Vector128 lower, Vector128Creates a new instance from two instances. + /// The value that the lower 128-bits will be initialized to. + /// The value that the upper 128-bits will be initialized to. + /// A new initialized from and . [CLSCompliant(false)] public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) { @@ -529,6 +735,10 @@ public static unsafe Vector256 Create(Vector128 lower, Vector128Creates a new instance from two instances. + /// The value that the lower 128-bits will be initialized to. + /// The value that the upper 128-bits will be initialized to. + /// A new initialized from and . public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) { Vector256 result256 = Vector256.Zero; @@ -540,6 +750,10 @@ public static unsafe Vector256 Create(Vector128 lower, Vector128Creates a new instance from two instances. + /// The value that the lower 128-bits will be initialized to. + /// The value that the upper 128-bits will be initialized to. + /// A new initialized from and . [CLSCompliant(false)] public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) { @@ -552,6 +766,10 @@ public static unsafe Vector256 Create(Vector128 lower, Vector128 return result256; } + /// Creates a new instance from two instances. + /// The value that the lower 128-bits will be initialized to. + /// The value that the upper 128-bits will be initialized to. + /// A new initialized from and . [CLSCompliant(false)] public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) { @@ -564,6 +782,10 @@ public static unsafe Vector256 Create(Vector128 lower, Vector128Creates a new instance from two instances. + /// The value that the lower 128-bits will be initialized to. + /// The value that the upper 128-bits will be initialized to. + /// A new initialized from and . [CLSCompliant(false)] public static unsafe Vector256 Create(Vector128 lower, Vector128 upper) { @@ -576,6 +798,9 @@ public static unsafe Vector256 Create(Vector128 lower, Vector128Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector256 CreateScalar(byte value) { var result = Vector256.Zero; @@ -583,6 +808,9 @@ public static unsafe Vector256 CreateScalar(byte value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector256 CreateScalar(double value) { var result = Vector256.Zero; @@ -590,6 +818,9 @@ public static unsafe Vector256 CreateScalar(double value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector256 CreateScalar(short value) { var result = Vector256.Zero; @@ -597,6 +828,9 @@ public static unsafe Vector256 CreateScalar(short value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector256 CreateScalar(int value) { var result = Vector256.Zero; @@ -604,6 +838,9 @@ public static unsafe Vector256 CreateScalar(int value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector256 CreateScalar(long value) { var result = Vector256.Zero; @@ -611,6 +848,9 @@ public static unsafe Vector256 CreateScalar(long value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. [CLSCompliant(false)] public static unsafe Vector256 CreateScalar(sbyte value) { @@ -619,6 +859,9 @@ public static unsafe Vector256 CreateScalar(sbyte value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector256 CreateScalar(float value) { var result = Vector256.Zero; @@ -626,6 +869,9 @@ public static unsafe Vector256 CreateScalar(float value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. [CLSCompliant(false)] public static unsafe Vector256 CreateScalar(ushort value) { @@ -634,6 +880,9 @@ public static unsafe Vector256 CreateScalar(ushort value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. [CLSCompliant(false)] public static unsafe Vector256 CreateScalar(uint value) { @@ -642,6 +891,9 @@ public static unsafe Vector256 CreateScalar(uint value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. [CLSCompliant(false)] public static unsafe Vector256 CreateScalar(ulong value) { @@ -650,6 +902,9 @@ public static unsafe Vector256 CreateScalar(ulong value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector256 CreateScalarUnsafe(byte value) { // This relies on us stripping the "init" flag from the ".locals" @@ -660,6 +915,9 @@ public static unsafe Vector256 CreateScalarUnsafe(byte value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector256 CreateScalarUnsafe(double value) { // This relies on us stripping the "init" flag from the ".locals" @@ -670,6 +928,9 @@ public static unsafe Vector256 CreateScalarUnsafe(double value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector256 CreateScalarUnsafe(short value) { // This relies on us stripping the "init" flag from the ".locals" @@ -680,6 +941,9 @@ public static unsafe Vector256 CreateScalarUnsafe(short value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector256 CreateScalarUnsafe(int value) { // This relies on us stripping the "init" flag from the ".locals" @@ -690,6 +954,9 @@ public static unsafe Vector256 CreateScalarUnsafe(int value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector256 CreateScalarUnsafe(long value) { // This relies on us stripping the "init" flag from the ".locals" @@ -700,6 +967,9 @@ public static unsafe Vector256 CreateScalarUnsafe(long value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. [CLSCompliant(false)] public static unsafe Vector256 CreateScalarUnsafe(sbyte value) { @@ -711,6 +981,9 @@ public static unsafe Vector256 CreateScalarUnsafe(sbyte value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector256 CreateScalarUnsafe(float value) { // This relies on us stripping the "init" flag from the ".locals" @@ -721,6 +994,9 @@ public static unsafe Vector256 CreateScalarUnsafe(float value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. [CLSCompliant(false)] public static unsafe Vector256 CreateScalarUnsafe(ushort value) { @@ -732,6 +1008,9 @@ public static unsafe Vector256 CreateScalarUnsafe(ushort value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. [CLSCompliant(false)] public static unsafe Vector256 CreateScalarUnsafe(uint value) { @@ -743,6 +1022,9 @@ public static unsafe Vector256 CreateScalarUnsafe(uint value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. [CLSCompliant(false)] public static unsafe Vector256 CreateScalarUnsafe(ulong value) { diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs index 350e188bfbe9..7e3ca7246caa 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs @@ -22,6 +22,8 @@ namespace System.Runtime.Intrinsics private readonly ulong _02; private readonly ulong _03; + /// Gets a new with all elements initialized to zero. + /// The type of the current instance () is not supported. public static Vector256 Zero { get @@ -82,6 +84,10 @@ internal static void ThrowIfUnsupportedType() } } + /// Reinterprets the current instance as a new . + /// The type of the vector the current instance should be reinterpreted as. + /// The current instance reinterpreted as a new . + /// The type of the current instance () or the type of the target () is not supported. public Vector256 As() where U : struct { ThrowIfUnsupportedType(); @@ -89,30 +95,65 @@ public Vector256 As() where U : struct return Unsafe.As, Vector256>(ref Unsafe.AsRef(in this)); } + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector256 AsByte() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector256 AsDouble() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector256 AsInt16() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector256 AsInt32() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector256 AsInt64() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. [CLSCompliant(false)] public Vector256 AsSByte() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector256 AsSingle() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. [CLSCompliant(false)] public Vector256 AsUInt16() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. [CLSCompliant(false)] public Vector256 AsUInt32() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. [CLSCompliant(false)] public Vector256 AsUInt64() => As(); + /// Gets the element at the specified index. + /// The index of the element to get. + /// The value of the element at . + /// The type of the current instance () is not supported. + /// was less than zero or greater than the number of elements. public T GetElement(int index) { ThrowIfUnsupportedType(); @@ -126,6 +167,12 @@ public T GetElement(int index) return Unsafe.Add(ref e0, index); } + /// Creates a new with the element at the specified index set to the specified value and the remaining elements set to the same value as that in the current instance. + /// The index of the element to set. + /// The value to set the value to. + /// A with the value of the element at set to and the remaining elements set to the same value as that in the current instance. + /// The type of the current instance () is not supported. + /// was less than zero or greater than the number of elements. public Vector256 SetElement(int index, T value) { ThrowIfUnsupportedType(); @@ -141,6 +188,9 @@ public Vector256 SetElement(int index, T value) return result; } + /// Gets the value of the lower 128-bits as a new . + /// The value of the lower 128-bits as a new . + /// The type of the current instance () is not supported. public Vector128 GetLower() { ThrowIfUnsupportedType(); @@ -148,6 +198,10 @@ public Vector128 GetLower() return Unsafe.As, Vector128>(ref Unsafe.AsRef(in this)); } + /// Creates a new with the lower 128-bits set to the specified value and the lower 128-bits set to the same value as that in the current instance. + /// The value of the lower 128-bits as a . + /// A new with the lower 128-bits set to the specified value and the lower 128-bits set to the same value as that in the current instance. + /// The type of the current instance () is not supported. public Vector256 SetLower(Vector128 value) { ThrowIfUnsupportedType(); @@ -158,6 +212,9 @@ public Vector256 SetLower(Vector128 value) return result; } + /// Gets the value of the upper 128-bits as a new . + /// The value of the upper 128-bits as a new . + /// The type of the current instance () is not supported. public Vector128 GetUpper() { ThrowIfUnsupportedType(); @@ -167,6 +224,10 @@ public Vector128 GetUpper() return Unsafe.Add(ref lower, 1); } + /// Creates a new with the upper 128-bits set to the specified value and the upper 128-bits set to the same value as that in the current instance. + /// The value of the upper 128-bits as a . + /// A new with the upper 128-bits set to the specified value and the upper 128-bits set to the same value as that in the current instance. + /// The type of the current instance () is not supported. public Vector256 SetUpper(Vector128 value) { ThrowIfUnsupportedType(); @@ -178,6 +239,9 @@ public Vector256 SetUpper(Vector128 value) return result; } + /// Converts the current instance to a scalar containing the value of the first element. + /// A scalar containing the value of the first element. + /// The type of the current instance () is not supported. public T ToScalar() { ThrowIfUnsupportedType(); diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs index 7988bb442b54..aa95c612c884 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs @@ -10,6 +10,9 @@ public static class Vector64 { internal const int Size = 8; + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector64 Create(byte value) { var pResult = stackalloc byte[8] @@ -27,11 +30,17 @@ public static unsafe Vector64 Create(byte value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector64 Create(double value) { return Unsafe.As>(ref value); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector64 Create(short value) { var pResult = stackalloc short[4] @@ -45,6 +54,9 @@ public static unsafe Vector64 Create(short value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector64 Create(int value) { var pResult = stackalloc int[2] @@ -56,11 +68,17 @@ public static unsafe Vector64 Create(int value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector64 Create(long value) { return Unsafe.As>(ref value); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . [CLSCompliant(false)] public static unsafe Vector64 Create(sbyte value) { @@ -79,6 +97,9 @@ public static unsafe Vector64 Create(sbyte value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . public static unsafe Vector64 Create(float value) { var pResult = stackalloc float[2] @@ -90,6 +111,9 @@ public static unsafe Vector64 Create(float value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . [CLSCompliant(false)] public static unsafe Vector64 Create(ushort value) { @@ -104,6 +128,9 @@ public static unsafe Vector64 Create(ushort value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . [CLSCompliant(false)] public static unsafe Vector64 Create(uint value) { @@ -116,12 +143,25 @@ public static unsafe Vector64 Create(uint value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with all elements initialized to the specified value. + /// The value that all elements will be initialized to. + /// A new with all elements initialized to . [CLSCompliant(false)] public static unsafe Vector64 Create(ulong value) { return Unsafe.As>(ref value); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// The value that element 4 will be initialized to. + /// The value that element 5 will be initialized to. + /// The value that element 6 will be initialized to. + /// The value that element 7 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector64 Create(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7) { var pResult = stackalloc byte[8] @@ -139,6 +179,12 @@ public static unsafe Vector64 Create(byte e0, byte e1, byte e2, byte e3, b return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector64 Create(short e0, short e1, short e2, short e3) { var pResult = stackalloc short[4] @@ -152,6 +198,10 @@ public static unsafe Vector64 Create(short e0, short e1, short e2, short return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector64 Create(int e0, int e1) { var pResult = stackalloc int[2] @@ -163,6 +213,16 @@ public static unsafe Vector64 Create(int e0, int e1) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// The value that element 4 will be initialized to. + /// The value that element 5 will be initialized to. + /// The value that element 6 will be initialized to. + /// The value that element 7 will be initialized to. + /// A new with each element initialized to corresponding specified value. [CLSCompliant(false)] public static unsafe Vector64 Create(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7) { @@ -181,6 +241,10 @@ public static unsafe Vector64 Create(sbyte e0, sbyte e1, sbyte e2, sbyte return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// A new with each element initialized to corresponding specified value. public static unsafe Vector64 Create(float e0, float e1) { var pResult = stackalloc float[2] @@ -192,6 +256,12 @@ public static unsafe Vector64 Create(float e0, float e1) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// The value that element 2 will be initialized to. + /// The value that element 3 will be initialized to. + /// A new with each element initialized to corresponding specified value. [CLSCompliant(false)] public static unsafe Vector64 Create(ushort e0, ushort e1, ushort e2, ushort e3) { @@ -206,6 +276,10 @@ public static unsafe Vector64 Create(ushort e0, ushort e1, ushort e2, us return Unsafe.AsRef>(pResult); } + /// Creates a new instance with each element initialized to the corresponding specified value. + /// The value that element 0 will be initialized to. + /// The value that element 1 will be initialized to. + /// A new with each element initialized to corresponding specified value. [CLSCompliant(false)] public static unsafe Vector64 Create(uint e0, uint e1) { @@ -218,6 +292,9 @@ public static unsafe Vector64 Create(uint e0, uint e1) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector64 CreateScalar(byte value) { var result = Vector64.Zero; @@ -225,6 +302,9 @@ public static unsafe Vector64 CreateScalar(byte value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector64 CreateScalar(short value) { var result = Vector64.Zero; @@ -232,6 +312,9 @@ public static unsafe Vector64 CreateScalar(short value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector64 CreateScalar(int value) { var result = Vector64.Zero; @@ -239,6 +322,9 @@ public static unsafe Vector64 CreateScalar(int value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. [CLSCompliant(false)] public static unsafe Vector64 CreateScalar(sbyte value) { @@ -247,6 +333,9 @@ public static unsafe Vector64 CreateScalar(sbyte value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. public static unsafe Vector64 CreateScalar(float value) { var result = Vector64.Zero; @@ -254,6 +343,9 @@ public static unsafe Vector64 CreateScalar(float value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. [CLSCompliant(false)] public static unsafe Vector64 CreateScalar(ushort value) { @@ -262,6 +354,9 @@ public static unsafe Vector64 CreateScalar(ushort value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements initialized to zero. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements initialized to zero. [CLSCompliant(false)] public static unsafe Vector64 CreateScalar(uint value) { @@ -270,6 +365,9 @@ public static unsafe Vector64 CreateScalar(uint value) return result; } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector64 CreateScalarUnsafe(byte value) { // This relies on us stripping the "init" flag from the ".locals" @@ -280,6 +378,9 @@ public static unsafe Vector64 CreateScalarUnsafe(byte value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector64 CreateScalarUnsafe(short value) { // This relies on us stripping the "init" flag from the ".locals" @@ -290,6 +391,9 @@ public static unsafe Vector64 CreateScalarUnsafe(short value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector64 CreateScalarUnsafe(int value) { // This relies on us stripping the "init" flag from the ".locals" @@ -300,6 +404,9 @@ public static unsafe Vector64 CreateScalarUnsafe(int value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. [CLSCompliant(false)] public static unsafe Vector64 CreateScalarUnsafe(sbyte value) { @@ -311,6 +418,9 @@ public static unsafe Vector64 CreateScalarUnsafe(sbyte value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. public static unsafe Vector64 CreateScalarUnsafe(float value) { // This relies on us stripping the "init" flag from the ".locals" @@ -321,6 +431,9 @@ public static unsafe Vector64 CreateScalarUnsafe(float value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. [CLSCompliant(false)] public static unsafe Vector64 CreateScalarUnsafe(ushort value) { @@ -332,6 +445,9 @@ public static unsafe Vector64 CreateScalarUnsafe(ushort value) return Unsafe.AsRef>(pResult); } + /// Creates a new instance with the first element initialized to the specified value and the remaining elements left uninitialized. + /// The value that element 0 will be initialized to. + /// A new instance with the first element initialized to and the remaining elements left uninitialized. [CLSCompliant(false)] public static unsafe Vector64 CreateScalarUnsafe(uint value) { diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs index 87bbfc3e076e..51c7c4c367e0 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs @@ -19,6 +19,8 @@ namespace System.Runtime.Intrinsics // This also allows the debug view to work https://github.com/dotnet/coreclr/issues/15694) private readonly ulong _00; + /// Gets a new with all elements initialized to zero. + /// The type of the current instance () is not supported. public static Vector64 Zero { get @@ -79,6 +81,10 @@ internal static void ThrowIfUnsupportedType() } } + /// Reinterprets the current instance as a new . + /// The type of the vector the current instance should be reinterpreted as. + /// The current instance reinterpreted as a new . + /// The type of the current instance () or the type of the target () is not supported. public Vector64 As() where U : struct { ThrowIfUnsupportedType(); @@ -86,30 +92,65 @@ public Vector64 As() where U : struct return Unsafe.As, Vector64>(ref Unsafe.AsRef(in this)); } + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector64 AsByte() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector64 AsDouble() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector64 AsInt16() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector64 AsInt32() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector64 AsInt64() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. [CLSCompliant(false)] public Vector64 AsSByte() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. public Vector64 AsSingle() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. [CLSCompliant(false)] public Vector64 AsUInt16() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. [CLSCompliant(false)] public Vector64 AsUInt32() => As(); + /// Reinterprets the current instance as a new . + /// The current instance reinterpreted as a new . + /// The type of the current instance () is not supported. [CLSCompliant(false)] public Vector64 AsUInt64() => As(); + /// Gets the element at the specified index. + /// The index of the element to get. + /// The value of the element at . + /// The type of the current instance () is not supported. + /// was less than zero or greater than the number of elements. public T GetElement(int index) { ThrowIfUnsupportedType(); @@ -123,6 +164,12 @@ public T GetElement(int index) return Unsafe.Add(ref e0, index); } + /// Creates a new with the element at the specified index set to the specified value and the remaining elements set to the same value as that in the current instance. + /// The index of the element to set. + /// The value to set the value to. + /// A with the value of the element at set to and the remaining elements set to the same value as that in the current instance. + /// The type of the current instance () is not supported. + /// was less than zero or greater than the number of elements. public Vector64 SetElement(int index, T value) { ThrowIfUnsupportedType(); @@ -138,12 +185,18 @@ public Vector64 SetElement(int index, T value) return result; } + /// Converts the current instance to a scalar containing the value of the first element. + /// A scalar containing the value of the first element. + /// The type of the current instance () is not supported. public T ToScalar() { ThrowIfUnsupportedType(); return Unsafe.As, T>(ref Unsafe.AsRef(in this)); } + /// Converts the current instance to a new with the lower 64-bits set to the value of the current instance and the upper 64-bits initialized to zero. + /// A new with the lower 64-bits set to the value of the current instance and the upper 64-bits initialized to zero. + /// The type of the current instance () is not supported. public Vector128 ToVector128() { ThrowIfUnsupportedType(); @@ -154,6 +207,9 @@ public Vector128 ToVector128() return result; } + /// Converts the current instance to a new with the lower 64-bits set to the value of the current instance and the upper 64-bits left uninitialized. + /// A new with the lower 64-bits set to the value of the current instance and the upper 64-bits initialized to zero. + /// The type of the current instance () is not supported. public unsafe Vector128 ToVector128Unsafe() { ThrowIfUnsupportedType(); From c362b367e6c105f38dcc11b6c50179a3578da164 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Wed, 7 Nov 2018 19:02:19 -0800 Subject: [PATCH 4/4] Changing `Set` to `With` --- .../shared/System/Runtime/Intrinsics/Vector128_1.cs | 6 +++--- .../shared/System/Runtime/Intrinsics/Vector256_1.cs | 6 +++--- .../shared/System/Runtime/Intrinsics/Vector64_1.cs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs index 0e05152ee5c4..d8d4095d9d35 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs @@ -171,7 +171,7 @@ public T GetElement(int index) /// A with the value of the element at set to and the remaining elements set to the same value as that in the current instance. /// The type of the current instance () is not supported. /// was less than zero or greater than the number of elements. - public Vector128 SetElement(int index, T value) + public Vector128 WithElement(int index, T value) { ThrowIfUnsupportedType(); @@ -200,7 +200,7 @@ public Vector64 GetLower() /// The value of the lower 64-bits as a . /// A new with the lower 64-bits set to the specified value and the upper 64-bits set to the same value as that in the current instance. /// The type of the current instance () is not supported. - public Vector128 SetLower(Vector64 value) + public Vector128 WithLower(Vector64 value) { ThrowIfUnsupportedType(); Vector64.ThrowIfUnsupportedType(); @@ -226,7 +226,7 @@ public Vector64 GetUpper() /// The value of the upper 64-bits as a . /// A new with the upper 64-bits set to the specified value and the upper 64-bits set to the same value as that in the current instance. /// The type of the current instance () is not supported. - public Vector128 SetUpper(Vector64 value) + public Vector128 WithUpper(Vector64 value) { ThrowIfUnsupportedType(); Vector64.ThrowIfUnsupportedType(); diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs index 7e3ca7246caa..cd49d4832fb6 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs @@ -173,7 +173,7 @@ public T GetElement(int index) /// A with the value of the element at set to and the remaining elements set to the same value as that in the current instance. /// The type of the current instance () is not supported. /// was less than zero or greater than the number of elements. - public Vector256 SetElement(int index, T value) + public Vector256 WithElement(int index, T value) { ThrowIfUnsupportedType(); @@ -202,7 +202,7 @@ public Vector128 GetLower() /// The value of the lower 128-bits as a . /// A new with the lower 128-bits set to the specified value and the lower 128-bits set to the same value as that in the current instance. /// The type of the current instance () is not supported. - public Vector256 SetLower(Vector128 value) + public Vector256 WithLower(Vector128 value) { ThrowIfUnsupportedType(); Vector128.ThrowIfUnsupportedType(); @@ -228,7 +228,7 @@ public Vector128 GetUpper() /// The value of the upper 128-bits as a . /// A new with the upper 128-bits set to the specified value and the upper 128-bits set to the same value as that in the current instance. /// The type of the current instance () is not supported. - public Vector256 SetUpper(Vector128 value) + public Vector256 WithUpper(Vector128 value) { ThrowIfUnsupportedType(); Vector128.ThrowIfUnsupportedType(); diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs index 51c7c4c367e0..da9d0d20bd79 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs @@ -170,7 +170,7 @@ public T GetElement(int index) /// A with the value of the element at set to and the remaining elements set to the same value as that in the current instance. /// The type of the current instance () is not supported. /// was less than zero or greater than the number of elements. - public Vector64 SetElement(int index, T value) + public Vector64 WithElement(int index, T value) { ThrowIfUnsupportedType();