From b2b7d2cce110293f14563644c0e1780d0cbe343e Mon Sep 17 00:00:00 2001 From: Fei Peng Date: Fri, 17 Nov 2017 09:42:29 -0800 Subject: [PATCH] Generic hardware intrinsics throw exception for non-numeric types (#15068) --- src/mscorlib/Resources/Strings.resx | 3 + .../src/System/Runtime/Intrinsics/X86/Avx.cs | 169 +++++++++++++++++---- .../src/System/Runtime/Intrinsics/X86/Avx2.cs | 12 +- .../src/System/Runtime/Intrinsics/X86/Sse.cs | 7 +- .../src/System/Runtime/Intrinsics/X86/Sse2.cs | 30 +++- .../src/System/Runtime/Intrinsics/X86/Sse41.cs | 84 ++++++++-- src/mscorlib/src/System/ThrowHelper.cs | 12 ++ 7 files changed, 267 insertions(+), 50 deletions(-) diff --git a/src/mscorlib/Resources/Strings.resx b/src/mscorlib/Resources/Strings.resx index ef3821a..8fde41a 100644 --- a/src/mscorlib/Resources/Strings.resx +++ b/src/mscorlib/Resources/Strings.resx @@ -3697,4 +3697,7 @@ HashCode is a mutable struct and should not be compared with other HashCodes. + + Specified type is not supported + diff --git a/src/mscorlib/src/System/Runtime/Intrinsics/X86/Avx.cs b/src/mscorlib/src/System/Runtime/Intrinsics/X86/Avx.cs index a69a5ea..725b1c4 100644 --- a/src/mscorlib/src/System/Runtime/Intrinsics/X86/Avx.cs +++ b/src/mscorlib/src/System/Runtime/Intrinsics/X86/Avx.cs @@ -183,42 +183,78 @@ namespace System.Runtime.Intrinsics.X86 /// /// __int8 _mm256_extract_epi8 (__m256i a, const int index) /// - public static sbyte ExtractSbyte(Vector256 value, byte index) where T : struct => ExtractSbyte(value, index); + public static sbyte ExtractSbyte(Vector256 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractSbyte(value, index); + } /// /// __int8 _mm256_extract_epi8 (__m256i a, const int index) /// - public static byte ExtractByte(Vector256 value, byte index) where T : struct => ExtractByte(value, index); + public static byte ExtractByte(Vector256 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractByte(value, index); + } /// /// __int16 _mm256_extract_epi16 (__m256i a, const int index) /// - public static short ExtractShort(Vector256 value, byte index) where T : struct => ExtractShort(value, index); + public static short ExtractShort(Vector256 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractShort(value, index); + } /// /// __int16 _mm256_extract_epi16 (__m256i a, const int index) /// - public static ushort ExtractUshort(Vector256 value, byte index) where T : struct => ExtractUshort(value, index); + public static ushort ExtractUshort(Vector256 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractUshort(value, index); + } /// /// __int32 _mm256_extract_epi32 (__m256i a, const int index) /// - public static int ExtractInt(Vector256 value, byte index) where T : struct => ExtractInt(value, index); + public static int ExtractInt(Vector256 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractInt(value, index); + } /// /// __int32 _mm256_extract_epi32 (__m256i a, const int index) /// - public static uint ExtractUint(Vector256 value, byte index) where T : struct => ExtractUint(value, index); + public static uint ExtractUint(Vector256 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractUint(value, index); + } /// /// __int64 _mm256_extract_epi64 (__m256i a, const int index) /// - public static long ExtractLong(Vector256 value, byte index) where T : struct => ExtractLong(value, index); + public static long ExtractLong(Vector256 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractLong(value, index); + } /// /// __int64 _mm256_extract_epi64 (__m256i a, const int index) /// - public static ulong ExtractUlong(Vector256 value, byte index) where T : struct => ExtractUlong(value, index); + public static ulong ExtractUlong(Vector256 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractUlong(value, index); + } /// /// __m128 _mm256_extractf128_ps (__m256 a, const int imm8) /// __m128d _mm256_extractf128_pd (__m256d a, const int imm8) /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8) /// - public static Vector128 ExtractVector128(Vector256 value, byte index) where T : struct => ExtractVector128(value, index); + public static Vector128 ExtractVector128(Vector256 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractVector128(value, index); + } /// /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8) @@ -266,7 +302,11 @@ namespace System.Runtime.Intrinsics.X86 /// __m256 _mm256_castps128_ps256 (__m128 a) /// __m256i _mm256_castsi128_si256 (__m128i a) /// - public static Vector256 ExtendToVector256(Vector128 value) where T : struct => ExtendToVector256(value); + public static Vector256 ExtendToVector256(Vector128 value) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtendToVector256(value); + } /// /// __m256 _mm256_floor_ps (__m256 a) @@ -282,7 +322,11 @@ namespace System.Runtime.Intrinsics.X86 /// __m128 _mm256_castps256_ps128 (__m256 a) /// __m128i _mm256_castsi256_si128 (__m256i a) /// - public static Vector128 GetLowerHalf(Vector256 value) where T : struct => GetLowerHalf(value); + public static Vector128 GetLowerHalf(Vector256 value) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return GetLowerHalf(value); + } /// /// __m256 _mm256_hadd_ps (__m256 a, __m256 b) @@ -305,42 +349,78 @@ namespace System.Runtime.Intrinsics.X86 /// /// __m256i _mm256_insert_epi8 (__m256i a, __int8 i, const int index) /// - public static Vector256 InsertSbyte(Vector256 value, sbyte data, byte index) where T : struct => InsertSbyte(value, data, index); + public static Vector256 InsertSbyte(Vector256 value, sbyte data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertSbyte(value, data, index); + } /// /// __m256i _mm256_insert_epi8 (__m256i a, __int8 i, const int index) /// - public static Vector256 InsertByte(Vector256 value, byte data, byte index) where T : struct => InsertByte(value, data, index); + public static Vector256 InsertByte(Vector256 value, byte data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertByte(value, data, index); + } /// /// __m256i _mm256_insert_epi16 (__m256i a, __int16 i, const int index) /// - public static Vector256 InsertShort(Vector256 value, short data, byte index) where T : struct => InsertShort(value, data, index); + public static Vector256 InsertShort(Vector256 value, short data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertShort(value, data, index); + } /// /// __m256i _mm256_insert_epi16 (__m256i a, __int16 i, const int index) /// - public static Vector256 InsertUshort(Vector256 value, ushort data, byte index) where T : struct => InsertUshort(value, data, index); + public static Vector256 InsertUshort(Vector256 value, ushort data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertUshort(value, data, index); + } /// /// __m256i _mm256_insert_epi32 (__m256i a, __int32 i, const int index) /// - public static Vector256 InsertInt(Vector256 value, int data, byte index) where T : struct => InsertInt(value, data, index); + public static Vector256 InsertInt(Vector256 value, int data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertInt(value, data, index); + } /// /// __m256i _mm256_insert_epi32 (__m256i a, __int32 i, const int index) /// - public static Vector256 InsertUint(Vector256 value, uint data, byte index) where T : struct => InsertUint(value, data, index); + public static Vector256 InsertUint(Vector256 value, uint data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertUint(value, data, index); + } /// /// __m256i _mm256_insert_epi64 (__m256i a, __int64 i, const int index) /// - public static Vector256 InsertLong(Vector256 value, long data, byte index) where T : struct => InsertLong(value, data, index); + public static Vector256 InsertLong(Vector256 value, long data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertLong(value, data, index); + } /// /// __m256i _mm256_insert_epi64 (__m256i a, __int64 i, const int index) /// - public static Vector256 InsertUlong(Vector256 value, ulong data, byte index) where T : struct => InsertUlong(value, data, index); + public static Vector256 InsertUlong(Vector256 value, ulong data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertUlong(value, data, index); + } /// /// __m256 _mm256_insertf128_ps (__m256 a, __m128 b, int imm8) /// __m256d _mm256_insertf128_pd (__m256d a, __m128d b, int imm8) /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8) /// - public static Vector256 Insert(Vector256 value, Vector128 data, byte index) where T : struct => Insert(value, data, index); + public static Vector256 Insert(Vector256 value, Vector128 data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return Insert(value, data, index); + } /// /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8) @@ -726,21 +806,33 @@ namespace System.Runtime.Intrinsics.X86 /// __m256 _mm256_set1_ps (float a) /// __m256d _mm256_set1_pd (double a) /// - public static Vector256 Set1(T value) where T : struct => Set1(value); + public static Vector256 Set1(T value) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return Set1(value); + } /// /// __m256 _mm256_set_m128 (__m128 hi, __m128 lo) /// __m256d _mm256_set_m128d (__m128d hi, __m128d lo) /// __m256i _mm256_set_m128i (__m128i hi, __m128i lo) /// - public static Vector256 SetHiLo(Vector128 hi, Vector128 lo) where T : struct => SetHiLo(hi, lo); + public static Vector256 SetHiLo(Vector128 hi, Vector128 lo) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return SetHiLo(hi, lo); + } /// /// __m256i _mm256_setzero_si256 (void) /// __m256 _mm256_setzero_ps (void) /// __m256d _mm256_setzero_pd (void) /// - public static Vector256 SetZero() where T : struct => SetZero(); + public static Vector256 SetZero() where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return SetZero(); + } /// /// __m256 _mm256_shuffle_ps (__m256 a, __m256 b, const int imm8) @@ -768,7 +860,12 @@ namespace System.Runtime.Intrinsics.X86 /// __m256d _mm256_castsi256_pd (__m256i a) /// __m256 _mm256_castsi256_ps (__m256i a) /// - public static Vector256 StaticCast(Vector256 value) where T : struct where U : struct => StaticCast(value); + public static Vector256 StaticCast(Vector256 value) where T : struct where U : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return StaticCast(value); + } /// /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a) @@ -916,7 +1013,11 @@ namespace System.Runtime.Intrinsics.X86 /// int _mm256_testc_ps (__m256 a, __m256 b) /// int _mm256_testc_pd (__m256d a, __m256d b) /// - public static bool TestC(Vector256 left, Vector256 right) where T : struct => TestC(left, right); + public static bool TestC(Vector256 left, Vector256 right) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return TestC(left, right); + } /// /// int _mm_testnzc_ps (__m128 a, __m128 b) @@ -932,7 +1033,11 @@ namespace System.Runtime.Intrinsics.X86 /// int _mm256_testnzc_ps (__m256 a, __m256 b) /// int _mm256_testnzc_pd (__m256d a, __m256d b) /// - public static bool TestNotZAndNotC(Vector256 left, Vector256 right) where T : struct => TestNotZAndNotC(left, right); + public static bool TestNotZAndNotC(Vector256 left, Vector256 right) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return TestNotZAndNotC(left, right); + } /// /// int _mm_testz_ps (__m128 a, __m128 b) @@ -948,7 +1053,11 @@ namespace System.Runtime.Intrinsics.X86 /// int _mm256_testz_ps (__m256 a, __m256 b) /// int _mm256_testz_pd (__m256d a, __m256d b) /// - public static bool TestZ(Vector256 left, Vector256 right) where T : struct => TestZ(left, right); + public static bool TestZ(Vector256 left, Vector256 right) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return TestZ(left, right); + } /// /// __m256 _mm256_unpackhi_ps (__m256 a, __m256 b) @@ -991,6 +1100,10 @@ namespace System.Runtime.Intrinsics.X86 /// __m256 _mm256_zextps128_ps256 (__m128 a) /// __m256i _mm256_zextsi128_si256 (__m128i a) /// - public static Vector256 ZeroExtendToVector256(Vector128 value) where T : struct => ZeroExtendToVector256(value); + public static Vector256 ZeroExtendToVector256(Vector128 value) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ZeroExtendToVector256(value); + } } } diff --git a/src/mscorlib/src/System/Runtime/Intrinsics/X86/Avx2.cs b/src/mscorlib/src/System/Runtime/Intrinsics/X86/Avx2.cs index f8ee1fd..aef7410 100644 --- a/src/mscorlib/src/System/Runtime/Intrinsics/X86/Avx2.cs +++ b/src/mscorlib/src/System/Runtime/Intrinsics/X86/Avx2.cs @@ -200,7 +200,11 @@ namespace System.Runtime.Intrinsics.X86 /// __m128 _mm_broadcastss_ps (__m128 a) /// __m128d _mm_broadcastsd_pd (__m128d a) /// - public static Vector128 BroadcastElementToVector128(Vector128 value) where T : struct => BroadcastElementToVector128(value); + public static Vector128 BroadcastElementToVector128(Vector128 value) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return BroadcastElementToVector128(value); + } /// /// __m256i _mm256_broadcastb_epi8 (__m128i a) @@ -210,7 +214,11 @@ namespace System.Runtime.Intrinsics.X86 /// __m256 _mm256_broadcastss_ps (__m128 a) /// __m256d _mm256_broadcastsd_pd (__m128d a) /// - public static Vector256 BroadcastElementToVector256(Vector128 value) where T : struct => BroadcastElementToVector256(value); + public static Vector256 BroadcastElementToVector256(Vector128 value) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return BroadcastElementToVector256(value); + } /// /// __m256i _mm256_broadcastsi128_si256 (__m128i a) diff --git a/src/mscorlib/src/System/Runtime/Intrinsics/X86/Sse.cs b/src/mscorlib/src/System/Runtime/Intrinsics/X86/Sse.cs index bd48cd8..424ffc5 100644 --- a/src/mscorlib/src/System/Runtime/Intrinsics/X86/Sse.cs +++ b/src/mscorlib/src/System/Runtime/Intrinsics/X86/Sse.cs @@ -168,7 +168,12 @@ namespace System.Runtime.Intrinsics.X86 /// __m128d _mm_castsi128_pd (__m128i a) /// __m128 _mm_castsi128_ps (__m128i a) /// - public static Vector128 StaticCast(Vector128 value) where T : struct where U : struct => StaticCast(value); + public static Vector128 StaticCast(Vector128 value) where T : struct where U : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return StaticCast(value); + } /// /// __m128 _mm_shuffle_ps (__m128 a, __m128 b, unsigned int control) diff --git a/src/mscorlib/src/System/Runtime/Intrinsics/X86/Sse2.cs b/src/mscorlib/src/System/Runtime/Intrinsics/X86/Sse2.cs index fef5507..54d59e4 100644 --- a/src/mscorlib/src/System/Runtime/Intrinsics/X86/Sse2.cs +++ b/src/mscorlib/src/System/Runtime/Intrinsics/X86/Sse2.cs @@ -302,20 +302,36 @@ namespace System.Runtime.Intrinsics.X86 /// /// int _mm_extract_epi16 (__m128i a, int immediate) /// - public static short ExtractShort(Vector128 value, byte index) where T : struct => ExtractShort(value, index); + public static short ExtractShort(Vector128 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractShort(value, index); + } /// /// int _mm_extract_epi16 (__m128i a, int immediate) /// - public static ushort ExtractUshort(Vector128 value, byte index) where T : struct => ExtractUshort(value, index); + public static ushort ExtractUshort(Vector128 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractUshort(value, index); + } /// /// __m128i _mm_insert_epi16 (__m128i a, int i, int immediate) /// - public static Vector128 InsertShort(Vector128 value, short data, byte index) where T : struct => InsertShort(value, data, index); + public static Vector128 InsertShort(Vector128 value, short data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertShort(value, data, index); + } /// /// __m128i _mm_insert_epi16 (__m128i a, int i, int immediate) /// - public static Vector128 InsertUshort(Vector128 value, ushort data, byte index) where T : struct => InsertUshort(value, data, index); + public static Vector128 InsertUshort(Vector128 value, ushort data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertUshort(value, data, index); + } /// /// __m128i _mm_loadu_si128 (__m128i const* mem_address) @@ -592,7 +608,11 @@ namespace System.Runtime.Intrinsics.X86 /// __m128i _mm_setzero_si128 () /// __m128d _mm_setzero_pd (void) /// - public static Vector128 SetZero() where T : struct => SetZero(); + public static Vector128 SetZero() where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return SetZero(); + } /// /// __m128i _mm_sad_epu8 (__m128i a, __m128i b) diff --git a/src/mscorlib/src/System/Runtime/Intrinsics/X86/Sse41.cs b/src/mscorlib/src/System/Runtime/Intrinsics/X86/Sse41.cs index 7003478..28879b4 100644 --- a/src/mscorlib/src/System/Runtime/Intrinsics/X86/Sse41.cs +++ b/src/mscorlib/src/System/Runtime/Intrinsics/X86/Sse41.cs @@ -122,36 +122,64 @@ namespace System.Runtime.Intrinsics.X86 /// /// int _mm_extract_epi8 (__m128i a, const int imm8) /// - public static sbyte ExtractSbyte(Vector128 value, byte index) where T : struct => ExtractSbyte(value, index); + public static sbyte ExtractSbyte(Vector128 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractSbyte(value, index); + } /// /// int _mm_extract_epi8 (__m128i a, const int imm8) /// - public static byte ExtractByte(Vector128 value, byte index) where T : struct => ExtractByte(value, index); + public static byte ExtractByte(Vector128 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractByte(value, index); + } /// /// int _mm_extract_epi32 (__m128i a, const int imm8) /// - public static int ExtractInt(Vector128 value, byte index) where T : struct => ExtractInt(value, index); + public static int ExtractInt(Vector128 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractInt(value, index); + } /// /// int _mm_extract_epi32 (__m128i a, const int imm8) /// - public static uint ExtractUint(Vector128 value, byte index) where T : struct => ExtractUint(value, index); + public static uint ExtractUint(Vector128 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractUint(value, index); + } /// /// __int64 _mm_extract_epi64 (__m128i a, const int imm8) /// - public static long ExtractLong(Vector128 value, byte index) where T : struct => ExtractLong(value, index); + public static long ExtractLong(Vector128 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractLong(value, index); + } /// /// __int64 _mm_extract_epi64 (__m128i a, const int imm8) /// - public static ulong ExtractUlong(Vector128 value, byte index) where T : struct => ExtractUlong(value, index); + public static ulong ExtractUlong(Vector128 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractUlong(value, index); + } /// /// int _mm_extract_ps (__m128 a, const int imm8) /// - public static float ExtractFloat(Vector128 value, byte index) where T : struct => ExtractFloat(value, index); + public static float ExtractFloat(Vector128 value, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return ExtractFloat(value, index); + } /// /// __m128 _mm_floor_ps (__m128 a) @@ -165,37 +193,65 @@ namespace System.Runtime.Intrinsics.X86 /// /// __m128i _mm_insert_epi8 (__m128i a, int i, const int imm8) /// - public static Vector128 InsertSbyte(Vector128 value, sbyte data, byte index) where T : struct => InsertSbyte(value, data, index); + public static Vector128 InsertSbyte(Vector128 value, sbyte data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertSbyte(value, data, index); + } /// /// __m128i _mm_insert_epi8 (__m128i a, int i, const int imm8) /// - public static Vector128 InsertByte(Vector128 value, byte data, byte index) where T : struct => InsertByte(value, data, index); + public static Vector128 InsertByte(Vector128 value, byte data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertByte(value, data, index); + } /// /// __m128i _mm_insert_epi32 (__m128i a, int i, const int imm8) /// - public static Vector128 InsertInt(Vector128 value, int data, byte index) where T : struct => InsertInt(value, data, index); + public static Vector128 InsertInt(Vector128 value, int data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertInt(value, data, index); + } /// /// __m128i _mm_insert_epi32 (__m128i a, int i, const int imm8) /// - public static Vector128 InsertUint(Vector128 value, uint data, byte index) where T : struct => InsertUint(value, data, index); + public static Vector128 InsertUint(Vector128 value, uint data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertUint(value, data, index); + } /// /// __m128i _mm_insert_epi64 (__m128i a, __int64 i, const int imm8) /// - public static Vector128 InsertLong(Vector128 value, long data, byte index) where T : struct => InsertLong(value, data, index); + public static Vector128 InsertLong(Vector128 value, long data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertLong(value, data, index); + } /// /// __m128i _mm_insert_epi64 (__m128i a, __int64 i, const int imm8) /// - public static Vector128 InsertUlong(Vector128 value, ulong data, byte index) where T : struct => InsertUlong(value, data, index); + public static Vector128 InsertUlong(Vector128 value, ulong data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertUlong(value, data, index); + } /// /// __m128 _mm_insert_ps (__m128 a, __m128 b, const int imm8) /// - public static Vector128 InsertFloat(Vector128 value, float data, byte index) where T : struct => InsertFloat(value, data, index); + public static Vector128 InsertFloat(Vector128 value, float data, byte index) where T : struct + { + ThrowHelper.ThrowNotSupportedExceptionIfNonNumericType(); + return InsertFloat(value, data, index); + } /// /// __m128i _mm_max_epi8 (__m128i a, __m128i b) diff --git a/src/mscorlib/src/System/ThrowHelper.cs b/src/mscorlib/src/System/ThrowHelper.cs index ef4955c..782c30a 100644 --- a/src/mscorlib/src/System/ThrowHelper.cs +++ b/src/mscorlib/src/System/ThrowHelper.cs @@ -351,6 +351,18 @@ namespace System return SR.GetResourceString(resource.ToString()); } + + internal static void ThrowNotSupportedExceptionIfNonNumericType() + { + if (typeof(T) != typeof(Byte) && typeof(T) != typeof(SByte) && + typeof(T) != typeof(Int16) && typeof(T) != typeof(UInt16) && + typeof(T) != typeof(Int32) && typeof(T) != typeof(UInt32) && + typeof(T) != typeof(Int64) && typeof(T) != typeof(UInt64) && + typeof(T) != typeof(Single) && typeof(T) != typeof(Double)) + { + throw new NotSupportedException(SR.Arg_TypeNotSupported); + } + } } // -- 2.7.4