From 39ce8da5e02a08db5f25440a65196df369b0ffe7 Mon Sep 17 00:00:00 2001 From: Fei Peng Date: Fri, 15 Dec 2017 16:51:21 -0800 Subject: [PATCH] Enable Vector256 with AVX --- src/jit/compiler.h | 21 ++++++++++++++++++++- src/jit/ee_il_dll.cpp | 6 +++++- src/jit/morph.cpp | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/jit/compiler.h b/src/jit/compiler.h index 5b47689..d397239 100644 --- a/src/jit/compiler.h +++ b/src/jit/compiler.h @@ -7705,7 +7705,8 @@ private: // Get preferred alignment of SIMD type. int getSIMDTypeAlignment(var_types simdType); - // Get the number of bytes in a SIMD Vector for the current compilation. + // Get the number of bytes in a System.Numeric.Vector for the current compilation. + // Note - cannot be used for System.Runtime.Intrinsic unsigned getSIMDVectorRegisterByteLength() { #if defined(_TARGET_XARCH_) && !defined(LEGACY_BACKEND) @@ -7727,9 +7728,27 @@ private: } // The minimum and maximum possible number of bytes in a SIMD vector. + + // maxSIMDStructBytes + // The minimum SIMD size supported by System.Numeric.Vectors or System.Runtime.Intrinsic + // SSE: 16-byte Vector and Vector128 + // AVX: 32-byte Vector256 (Vector is 16-byte) + // AVX2: 32-byte Vector and Vector256 unsigned int maxSIMDStructBytes() { +#if FEATURE_HW_INTRINSICS && defined(_TARGET_XARCH_) + if (compSupports(InstructionSet_AVX)) + { + return YMM_REGSIZE_BYTES; + } + else + { + assert(getSIMDSupportLevel() >= SIMD_SSE2_Supported); + return XMM_REGSIZE_BYTES; + } +#else return getSIMDVectorRegisterByteLength(); +#endif } unsigned int minSIMDStructBytes() { diff --git a/src/jit/ee_il_dll.cpp b/src/jit/ee_il_dll.cpp index 45df939..8707376 100644 --- a/src/jit/ee_il_dll.cpp +++ b/src/jit/ee_il_dll.cpp @@ -386,7 +386,11 @@ unsigned CILJit::getMaxIntrinsicSIMDVectorLength(CORJIT_FLAGS cpuCompileFlags) if (!jitFlags.IsSet(JitFlags::JIT_FLAG_PREJIT) && jitFlags.IsSet(JitFlags::JIT_FLAG_FEATURE_SIMD) && jitFlags.IsSet(JitFlags::JIT_FLAG_USE_AVX2)) { - if (JitConfig.EnableAVX() != 0) + if (JitConfig.EnableAVX() != 0 +#ifdef DEBUG + && JitConfig.EnableAVX2() != 0 +#endif + ) { if (GetJitTls() != nullptr && JitTls::GetCompiler() != nullptr) { diff --git a/src/jit/morph.cpp b/src/jit/morph.cpp index 4265289..88d382b 100644 --- a/src/jit/morph.cpp +++ b/src/jit/morph.cpp @@ -5944,7 +5944,7 @@ GenTreePtr Compiler::fgMorphArrayIndex(GenTreePtr tree) noway_assert(elemTyp != TYP_STRUCT || elemStructType != nullptr); #ifdef FEATURE_SIMD - if (featureSIMD && varTypeIsStruct(elemTyp) && elemSize <= getSIMDVectorRegisterByteLength()) + if (featureSIMD && varTypeIsStruct(elemTyp) && elemSize <= maxSIMDStructBytes()) { // If this is a SIMD type, this is the point at which we lose the type information, // so we need to set the correct type on the GT_IND. -- 2.7.4