From 1393c30da7d686229dc0a5ad78e7f683caa8d313 Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Tue, 16 Apr 2024 12:08:39 +0100 Subject: [PATCH 01/14] Add option to change SVE vector length for current and children processes. --- src/coreclr/inc/clrconfigvalues.h | 4 ++++ src/coreclr/vm/codeman.cpp | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/coreclr/inc/clrconfigvalues.h b/src/coreclr/inc/clrconfigvalues.h index ddc7c79506ad4..acf983668b3ee 100644 --- a/src/coreclr/inc/clrconfigvalues.h +++ b/src/coreclr/inc/clrconfigvalues.h @@ -790,6 +790,10 @@ RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableArm64Sha256, W("EnableArm64Sh RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableArm64Rcpc, W("EnableArm64Rcpc"), 1, "Allows Arm64 Rcpc+ hardware intrinsics to be disabled") RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableArm64Rcpc2, W("EnableArm64Rcpc2"), 1, "Allows Arm64 Rcpc2+ hardware intrinsics to be disabled") RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableArm64Sve, W("EnableArm64Sve"), 1, "Allows Arm64 SVE hardware intrinsics to be disabled") +#if defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) +// TODO-SVE: Once coreclr supports vector lengths >16bytes, the default should be -1. +RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_MaxVectorLength, W("MaxVectorLength"), 16, "Specifies maximum size of the vector length in bytes while using SVE on Arm64", CLRConfig::LookupOptions::ParseIntegerAsBase10) +#endif //defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) #endif /// diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index 3bb10ac6c6bb6..e1b52ec336b46 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -4,7 +4,10 @@ // // codeman.cpp - a managment class for handling multiple code managers // - +#if defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) +#include +#include +#endif // defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) #include "common.h" #include "jitinterface.h" #include "corjit.h" @@ -1525,6 +1528,18 @@ void EEJitManager::SetCpuInfo() if (((cpuFeatures & ARM64IntrinsicConstants_Sve) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableArm64Sve)) { +#if defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) + int maxVectorLength = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_MaxVectorLength); + + // Limit the SVE vector length to 'maxVectorLength' if the underlying hardware offers longer vectors. + if ((prctl(PR_SVE_GET_VL, 0,0,0,0) & PR_SVE_VL_LEN_MASK) > maxVectorLength) + { + if (prctl(PR_SVE_SET_VL, (maxVectorLength | PR_SVE_VL_INHERIT), 0, 0, 0) == -1) + { + LogErrorToHost("LoadAndInitializeJIT: prctl() FAILED - unable to set maxVectorLength to %d", maxVectorLength); + } + } +#endif // defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) CPUCompileFlags.Set(InstructionSet_Sve); } From 2c040a75580b1a99b90a37be0b13172b1d0a69d0 Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Wed, 24 Apr 2024 11:41:05 +0100 Subject: [PATCH 02/14] Use maxVectorTBitWidth to get desired SVE length --- src/coreclr/inc/clrconfigvalues.h | 4 ---- src/coreclr/vm/codeman.cpp | 27 +++++++++++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/coreclr/inc/clrconfigvalues.h b/src/coreclr/inc/clrconfigvalues.h index acf983668b3ee..ddc7c79506ad4 100644 --- a/src/coreclr/inc/clrconfigvalues.h +++ b/src/coreclr/inc/clrconfigvalues.h @@ -790,10 +790,6 @@ RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableArm64Sha256, W("EnableArm64Sh RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableArm64Rcpc, W("EnableArm64Rcpc"), 1, "Allows Arm64 Rcpc+ hardware intrinsics to be disabled") RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableArm64Rcpc2, W("EnableArm64Rcpc2"), 1, "Allows Arm64 Rcpc2+ hardware intrinsics to be disabled") RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableArm64Sve, W("EnableArm64Sve"), 1, "Allows Arm64 SVE hardware intrinsics to be disabled") -#if defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) -// TODO-SVE: Once coreclr supports vector lengths >16bytes, the default should be -1. -RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_MaxVectorLength, W("MaxVectorLength"), 16, "Specifies maximum size of the vector length in bytes while using SVE on Arm64", CLRConfig::LookupOptions::ParseIntegerAsBase10) -#endif //defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) #endif /// diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index e1b52ec336b46..844f40b10409e 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -4,10 +4,10 @@ // // codeman.cpp - a managment class for handling multiple code managers // -#if defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) +#if defined(TARGET_LINUX) #include #include -#endif // defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) +#endif // defined(TARGET_LINUX) #include "common.h" #include "jitinterface.h" #include "corjit.h" @@ -45,6 +45,13 @@ #include "perfmap.h" #endif +#if defined(TARGET_LINUX) && !defined(PR_SVE_GET_VL) +#define PR_SVE_SET_VL 50 /* set task vector length */ +#define PR_SVE_GET_VL 51 /* get task vector length */ +#define PR_SVE_VL_LEN_MASK 0xffff +#define PR_SVE_VL_INHERIT (1 << 17) /* inherit across exec */ +#endif // defined(TARGET_LINUX) && !defined(PR_SVE_GET_VL) + // Default number of jump stubs in a jump stub block #define DEFAULT_JUMPSTUBS_PER_BLOCK 32 @@ -1260,6 +1267,9 @@ void EEJitManager::SetCpuInfo() int cpuFeatures = minipal_getcpufeatures(); + // Get the maximum bitwidth of Vector, rounding down to the nearest multiple of 128-bits + uint32_t maxVectorTBitWidth = (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_MaxVectorTBitWidth) / 128) * 128; + #if defined(TARGET_X86) || defined(TARGET_AMD64) #if defined(TARGET_X86) && !defined(TARGET_WINDOWS) @@ -1274,9 +1284,6 @@ void EEJitManager::SetCpuInfo() CPUCompileFlags.Set(InstructionSet_VectorT128); - // Get the maximum bitwidth of Vector, rounding down to the nearest multiple of 128-bits - uint32_t maxVectorTBitWidth = (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_MaxVectorTBitWidth) / 128) * 128; - if (((cpuFeatures & XArchIntrinsicConstants_VectorT256) != 0) && ((maxVectorTBitWidth == 0) || (maxVectorTBitWidth >= 256))) { // We allow 256-bit Vector by default @@ -1528,8 +1535,9 @@ void EEJitManager::SetCpuInfo() if (((cpuFeatures & ARM64IntrinsicConstants_Sve) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableArm64Sve)) { -#if defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) - int maxVectorLength = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_MaxVectorLength); +#if defined(TARGET_LINUX) + // prctl() expects vector length in bytes. + int maxVectorLength = (maxVectorTBitWidth >> 3); // Limit the SVE vector length to 'maxVectorLength' if the underlying hardware offers longer vectors. if ((prctl(PR_SVE_GET_VL, 0,0,0,0) & PR_SVE_VL_LEN_MASK) > maxVectorLength) @@ -1539,7 +1547,10 @@ void EEJitManager::SetCpuInfo() LogErrorToHost("LoadAndInitializeJIT: prctl() FAILED - unable to set maxVectorLength to %d", maxVectorLength); } } -#endif // defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) +#elif defined(TARGET_WINDOWS) + // TODO-SVE: Add prctl() equivalent for windows. +#endif + CPUCompileFlags.Set(InstructionSet_Sve); } From 22aa47e02bb28f5fc009f06b7f526ee5aa33dfd7 Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Tue, 30 Apr 2024 17:40:50 +0100 Subject: [PATCH 03/14] Use CNTB to determine current vector length --- src/coreclr/vm/codeman.cpp | 31 +++++++------------------------ src/coreclr/vm/codeman.h | 10 ++++++++++ 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index 844f40b10409e..d3835093715da 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -4,10 +4,7 @@ // // codeman.cpp - a managment class for handling multiple code managers // -#if defined(TARGET_LINUX) -#include -#include -#endif // defined(TARGET_LINUX) + #include "common.h" #include "jitinterface.h" #include "corjit.h" @@ -45,13 +42,6 @@ #include "perfmap.h" #endif -#if defined(TARGET_LINUX) && !defined(PR_SVE_GET_VL) -#define PR_SVE_SET_VL 50 /* set task vector length */ -#define PR_SVE_GET_VL 51 /* get task vector length */ -#define PR_SVE_VL_LEN_MASK 0xffff -#define PR_SVE_VL_INHERIT (1 << 17) /* inherit across exec */ -#endif // defined(TARGET_LINUX) && !defined(PR_SVE_GET_VL) - // Default number of jump stubs in a jump stub block #define DEFAULT_JUMPSTUBS_PER_BLOCK 32 @@ -1535,23 +1525,16 @@ void EEJitManager::SetCpuInfo() if (((cpuFeatures & ARM64IntrinsicConstants_Sve) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableArm64Sve)) { -#if defined(TARGET_LINUX) - // prctl() expects vector length in bytes. int maxVectorLength = (maxVectorTBitWidth >> 3); + uint64_t systemVectorTLength = GetSystemVectorLength(); - // Limit the SVE vector length to 'maxVectorLength' if the underlying hardware offers longer vectors. - if ((prctl(PR_SVE_GET_VL, 0,0,0,0) & PR_SVE_VL_LEN_MASK) > maxVectorLength) + if (maxVectorLength >= systemVectorTLength) { - if (prctl(PR_SVE_SET_VL, (maxVectorLength | PR_SVE_VL_INHERIT), 0, 0, 0) == -1) - { - LogErrorToHost("LoadAndInitializeJIT: prctl() FAILED - unable to set maxVectorLength to %d", maxVectorLength); - } + // Enable SVE only when user specified vector length larger than or equal to the system + // vector length. When eabled, SVE would use full vector length available to the process. + // For a 256-bit machine, if user provides DOTNET_MaxVectorTBitWidth=128, disable SVE. + CPUCompileFlags.Set(InstructionSet_Sve); } -#elif defined(TARGET_WINDOWS) - // TODO-SVE: Add prctl() equivalent for windows. -#endif - - CPUCompileFlags.Set(InstructionSet_Sve); } // DCZID_EL0<4> (DZP) indicates whether use of DC ZVA instructions is permitted (0) or prohibited (1). diff --git a/src/coreclr/vm/codeman.h b/src/coreclr/vm/codeman.h index 7d874c6ba7e69..d49306c6a32c2 100644 --- a/src/coreclr/vm/codeman.h +++ b/src/coreclr/vm/codeman.h @@ -1912,6 +1912,16 @@ protected : return m_CPUCompileFlags; } +#ifdef __GNUC__ + __attribute__((target("sve"))) +#endif + inline UINT64 GetSystemVectorLength() + { + UINT64 size; + __asm__ __volatile__("cntb %0" : "=r"(size)); + return size; + } + private: bool m_storeRichDebugInfo; From 43ece1e83930e6a982a19d58744eb4c5920458a3 Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Fri, 3 May 2024 16:56:37 +0100 Subject: [PATCH 04/14] Use ACLE to detect vector length on Linux and hardcode on Windows --- src/coreclr/vm/codeman.cpp | 10 ++++------ src/coreclr/vm/codeman.h | 22 ++++++++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index d3835093715da..c24197b66f968 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -1525,14 +1525,12 @@ void EEJitManager::SetCpuInfo() if (((cpuFeatures & ARM64IntrinsicConstants_Sve) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableArm64Sve)) { - int maxVectorLength = (maxVectorTBitWidth >> 3); - uint64_t systemVectorTLength = GetSystemVectorLength(); + uint32_t maxVectorTLength = (maxVectorTBitWidth / 8); + uint64_t sveLengthFromOS = GetSveLengthFromOS(); - if (maxVectorLength >= systemVectorTLength) + // Do not enable SVE when the user specified vector length is smaller than the one offered by underlying OS. + if ((maxVectorTLength >= sveLengthFromOS) || (maxVectorTBitWidth == 0)) { - // Enable SVE only when user specified vector length larger than or equal to the system - // vector length. When eabled, SVE would use full vector length available to the process. - // For a 256-bit machine, if user provides DOTNET_MaxVectorTBitWidth=128, disable SVE. CPUCompileFlags.Set(InstructionSet_Sve); } } diff --git a/src/coreclr/vm/codeman.h b/src/coreclr/vm/codeman.h index d49306c6a32c2..56b8b0bb11ba4 100644 --- a/src/coreclr/vm/codeman.h +++ b/src/coreclr/vm/codeman.h @@ -69,6 +69,10 @@ Module Name: #include "gcinfo.h" #include "eexcp.h" +#if defined(TARGET_ARM64) || defined(TARGET_LINUX) +#include +#endif + class MethodDesc; class ICorJitCompiler; class IJitManager; @@ -1912,15 +1916,21 @@ protected : return m_CPUCompileFlags; } -#ifdef __GNUC__ +#if defined(TARGET_ARM64) +#if defined(TARGET_LINUX) __attribute__((target("sve"))) -#endif - inline UINT64 GetSystemVectorLength() + inline UINT64 GetSveLengthFromOS() + { + return svcntb(); + } +#elif defined(TARGET_WINDOWS) + inline UINT64 GetSveLengthFromOS() { - UINT64 size; - __asm__ __volatile__("cntb %0" : "=r"(size)); - return size; + //TODO-SVE: SVE vector length is hardcoded to 128-bits on Windows until a suitable method is available. + return 16; } +#endif // TARGET_LINUX +#endif // TARGET_ARM64 private: bool m_storeRichDebugInfo; From 9140d8295a1f5878a5b6ff4aa527c70553705052 Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Tue, 7 May 2024 22:19:40 +0100 Subject: [PATCH 05/14] Use rdvl instead of cntb to count vector length --- src/coreclr/vm/codeman.h | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/coreclr/vm/codeman.h b/src/coreclr/vm/codeman.h index 56b8b0bb11ba4..325bb6de8f75b 100644 --- a/src/coreclr/vm/codeman.h +++ b/src/coreclr/vm/codeman.h @@ -69,10 +69,6 @@ Module Name: #include "gcinfo.h" #include "eexcp.h" -#if defined(TARGET_ARM64) || defined(TARGET_LINUX) -#include -#endif - class MethodDesc; class ICorJitCompiler; class IJitManager; @@ -1919,17 +1915,13 @@ protected : #if defined(TARGET_ARM64) #if defined(TARGET_LINUX) __attribute__((target("sve"))) +#endif // TARGET_LINUX inline UINT64 GetSveLengthFromOS() { - return svcntb(); - } -#elif defined(TARGET_WINDOWS) - inline UINT64 GetSveLengthFromOS() - { - //TODO-SVE: SVE vector length is hardcoded to 128-bits on Windows until a suitable method is available. - return 16; + UINT64 size; + __asm__ __volatile__("rdvl %0, #1" : "=r"(size)); + return size; } -#endif // TARGET_LINUX #endif // TARGET_ARM64 private: From aca2809e8ada738dff67212c900bf4ce2a0dc8c1 Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Wed, 8 May 2024 11:34:29 +0100 Subject: [PATCH 06/14] Add inline assembly suitable for MSVC --- src/coreclr/vm/codeman.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/coreclr/vm/codeman.h b/src/coreclr/vm/codeman.h index 325bb6de8f75b..448bf536655a7 100644 --- a/src/coreclr/vm/codeman.h +++ b/src/coreclr/vm/codeman.h @@ -1913,15 +1913,22 @@ protected : } #if defined(TARGET_ARM64) -#if defined(TARGET_LINUX) +#if defined(_MSC_VER) + inline UINT64 GetSveLengthFromOS() + { + UINT64 size; + __asm rdvl size, 1 + return size; + } +#else // defined(__GNUC__) __attribute__((target("sve"))) -#endif // TARGET_LINUX inline UINT64 GetSveLengthFromOS() { UINT64 size; __asm__ __volatile__("rdvl %0, #1" : "=r"(size)); return size; } +#endif // _MSC_VER #endif // TARGET_ARM64 private: From 1d1422781177d367e485f2bf355134b5bdc59f58 Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Fri, 10 May 2024 13:53:35 +0100 Subject: [PATCH 07/14] Add MSCV compatible assembly helper instead of inline assembly --- src/coreclr/vm/arm64/asmhelpers.S | 8 ++++++++ src/coreclr/vm/arm64/asmhelpers.asm | 8 ++++++++ src/coreclr/vm/codeman.h | 15 +++++---------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/coreclr/vm/arm64/asmhelpers.S b/src/coreclr/vm/arm64/asmhelpers.S index 0edbb3fdf92fc..09a2aa3b23763 100644 --- a/src/coreclr/vm/arm64/asmhelpers.S +++ b/src/coreclr/vm/arm64/asmhelpers.S @@ -23,6 +23,14 @@ LEAF_ENTRY GetDataCacheZeroIDReg, _TEXT ret lr LEAF_END GetDataCacheZeroIDReg, _TEXT +#if defined(_MSC_VER) +// DWORD64 __stdcall GetSveLengthFromOS(void); + LEAF_ENTRY GetSveLengthFromOS, _TEXT + rdvl x0, 1 + ret lr + LEAF_END GetSveLengthFromOS, _TEXT +#endif // _MSC_VER + //----------------------------------------------------------------------------- // This routine captures the machine state. It is used by helper method frame //----------------------------------------------------------------------------- diff --git a/src/coreclr/vm/arm64/asmhelpers.asm b/src/coreclr/vm/arm64/asmhelpers.asm index bc88d15ee330f..0f9743ff20248 100644 --- a/src/coreclr/vm/arm64/asmhelpers.asm +++ b/src/coreclr/vm/arm64/asmhelpers.asm @@ -78,6 +78,14 @@ ret lr LEAF_END +#if defined(_MSC_VER) +;; DWORD64 __stdcall GetSveLengthFromOS(void); + LEAF_ENTRY GetSveLengthFromOS + rdvl x0, 1 + ret lr + LEAF_END +#endif // _MSC_VER + ;;----------------------------------------------------------------------------- ;; This routine captures the machine state. It is used by helper method frame ;;----------------------------------------------------------------------------- diff --git a/src/coreclr/vm/codeman.h b/src/coreclr/vm/codeman.h index 448bf536655a7..16282f7f987f7 100644 --- a/src/coreclr/vm/codeman.h +++ b/src/coreclr/vm/codeman.h @@ -69,6 +69,10 @@ Module Name: #include "gcinfo.h" #include "eexcp.h" +#if defined(TARGET_ARM64) && defined(_MSC_VER) +extern "C" DWORD64 __stdcall GetSveLengthFromOS(); +#endif + class MethodDesc; class ICorJitCompiler; class IJitManager; @@ -1912,15 +1916,7 @@ protected : return m_CPUCompileFlags; } -#if defined(TARGET_ARM64) -#if defined(_MSC_VER) - inline UINT64 GetSveLengthFromOS() - { - UINT64 size; - __asm rdvl size, 1 - return size; - } -#else // defined(__GNUC__) +#if defined(TARGET_ARM64) && !defined(_MSC_VER) __attribute__((target("sve"))) inline UINT64 GetSveLengthFromOS() { @@ -1928,7 +1924,6 @@ protected : __asm__ __volatile__("rdvl %0, #1" : "=r"(size)); return size; } -#endif // _MSC_VER #endif // TARGET_ARM64 private: From c080aad6f4a8ea945d627ff14994576eac055f68 Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Mon, 20 May 2024 18:19:39 +0100 Subject: [PATCH 08/14] Declare GetSveLengthFromOS on Arm64 --- src/coreclr/vm/codeman.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/codeman.h b/src/coreclr/vm/codeman.h index 16282f7f987f7..58c50cedb033f 100644 --- a/src/coreclr/vm/codeman.h +++ b/src/coreclr/vm/codeman.h @@ -69,7 +69,7 @@ Module Name: #include "gcinfo.h" #include "eexcp.h" -#if defined(TARGET_ARM64) && defined(_MSC_VER) +#if defined(TARGET_ARM64) extern "C" DWORD64 __stdcall GetSveLengthFromOS(); #endif From a0c5247c7584be445c7f03288a9a153c151d26f4 Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Tue, 21 May 2024 16:29:41 +0100 Subject: [PATCH 09/14] Remove definition of GetSveLengthFromOS from .S file --- src/coreclr/vm/arm64/asmhelpers.S | 8 -------- src/coreclr/vm/arm64/asmhelpers.asm | 2 -- 2 files changed, 10 deletions(-) diff --git a/src/coreclr/vm/arm64/asmhelpers.S b/src/coreclr/vm/arm64/asmhelpers.S index 09a2aa3b23763..0edbb3fdf92fc 100644 --- a/src/coreclr/vm/arm64/asmhelpers.S +++ b/src/coreclr/vm/arm64/asmhelpers.S @@ -23,14 +23,6 @@ LEAF_ENTRY GetDataCacheZeroIDReg, _TEXT ret lr LEAF_END GetDataCacheZeroIDReg, _TEXT -#if defined(_MSC_VER) -// DWORD64 __stdcall GetSveLengthFromOS(void); - LEAF_ENTRY GetSveLengthFromOS, _TEXT - rdvl x0, 1 - ret lr - LEAF_END GetSveLengthFromOS, _TEXT -#endif // _MSC_VER - //----------------------------------------------------------------------------- // This routine captures the machine state. It is used by helper method frame //----------------------------------------------------------------------------- diff --git a/src/coreclr/vm/arm64/asmhelpers.asm b/src/coreclr/vm/arm64/asmhelpers.asm index b068c43d5d05f..883ac0c0249bc 100644 --- a/src/coreclr/vm/arm64/asmhelpers.asm +++ b/src/coreclr/vm/arm64/asmhelpers.asm @@ -78,13 +78,11 @@ ret lr LEAF_END -#if defined(_MSC_VER) ;; DWORD64 __stdcall GetSveLengthFromOS(void); LEAF_ENTRY GetSveLengthFromOS rdvl x0, 1 ret lr LEAF_END -#endif // _MSC_VER ;;----------------------------------------------------------------------------- ;; This routine captures the machine state. It is used by helper method frame From 4c0ffa7a7ac7a76a1bfe8307f1bc3cac9598ff30 Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Wed, 5 Jun 2024 10:15:00 +0100 Subject: [PATCH 10/14] Move non-windows definition of GetSveLengthFromOS to .S file --- src/coreclr/vm/arm64/asmhelpers.S | 7 +++++++ src/coreclr/vm/codeman.h | 10 ---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/coreclr/vm/arm64/asmhelpers.S b/src/coreclr/vm/arm64/asmhelpers.S index 0edbb3fdf92fc..292873cad946d 100644 --- a/src/coreclr/vm/arm64/asmhelpers.S +++ b/src/coreclr/vm/arm64/asmhelpers.S @@ -23,6 +23,13 @@ LEAF_ENTRY GetDataCacheZeroIDReg, _TEXT ret lr LEAF_END GetDataCacheZeroIDReg, _TEXT +// DWORD64 __stdcall GetSveLengthFromOS(void); +.arch_extension sve + LEAF_ENTRY GetSveLengthFromOS, _TEXT + rdvl x0, 1 + ret lr + LEAF_END GetSveLengthFromOS, _TEXT + //----------------------------------------------------------------------------- // This routine captures the machine state. It is used by helper method frame //----------------------------------------------------------------------------- diff --git a/src/coreclr/vm/codeman.h b/src/coreclr/vm/codeman.h index 58c50cedb033f..ca95adb7140c0 100644 --- a/src/coreclr/vm/codeman.h +++ b/src/coreclr/vm/codeman.h @@ -1916,16 +1916,6 @@ protected : return m_CPUCompileFlags; } -#if defined(TARGET_ARM64) && !defined(_MSC_VER) - __attribute__((target("sve"))) - inline UINT64 GetSveLengthFromOS() - { - UINT64 size; - __asm__ __volatile__("rdvl %0, #1" : "=r"(size)); - return size; - } -#endif // TARGET_ARM64 - private: bool m_storeRichDebugInfo; From 8b07210b3bb22d9cfbc18e486ae990eeceb7d470 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Wed, 5 Jun 2024 07:17:42 -0700 Subject: [PATCH 11/14] Apply suggestions from code review --- src/coreclr/vm/arm64/asmhelpers.S | 2 +- src/coreclr/vm/arm64/asmhelpers.asm | 2 +- src/coreclr/vm/codeman.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreclr/vm/arm64/asmhelpers.S b/src/coreclr/vm/arm64/asmhelpers.S index 292873cad946d..55a275bf5cfd7 100644 --- a/src/coreclr/vm/arm64/asmhelpers.S +++ b/src/coreclr/vm/arm64/asmhelpers.S @@ -23,7 +23,7 @@ LEAF_ENTRY GetDataCacheZeroIDReg, _TEXT ret lr LEAF_END GetDataCacheZeroIDReg, _TEXT -// DWORD64 __stdcall GetSveLengthFromOS(void); +// uint64_t GetSveLengthFromOS(void); .arch_extension sve LEAF_ENTRY GetSveLengthFromOS, _TEXT rdvl x0, 1 diff --git a/src/coreclr/vm/arm64/asmhelpers.asm b/src/coreclr/vm/arm64/asmhelpers.asm index 883ac0c0249bc..4953717af6868 100644 --- a/src/coreclr/vm/arm64/asmhelpers.asm +++ b/src/coreclr/vm/arm64/asmhelpers.asm @@ -78,7 +78,7 @@ ret lr LEAF_END -;; DWORD64 __stdcall GetSveLengthFromOS(void); +;; uint64_t GetSveLengthFromOS(void); LEAF_ENTRY GetSveLengthFromOS rdvl x0, 1 ret lr diff --git a/src/coreclr/vm/codeman.h b/src/coreclr/vm/codeman.h index ca95adb7140c0..9504e893c7924 100644 --- a/src/coreclr/vm/codeman.h +++ b/src/coreclr/vm/codeman.h @@ -70,7 +70,7 @@ Module Name: #include "eexcp.h" #if defined(TARGET_ARM64) -extern "C" DWORD64 __stdcall GetSveLengthFromOS(); +extern "C" uint64_t GetSveLengthFromOS(); #endif class MethodDesc; From c0a6910fbab11ea50758244ce78f1be9a994927a Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Wed, 5 Jun 2024 16:47:31 +0100 Subject: [PATCH 12/14] Move declaration of GetSveLengthFromOS to .cpp file --- src/coreclr/vm/codeman.cpp | 1 + src/coreclr/vm/codeman.h | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index 2528ae7360f99..7d296977d26fe 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -1243,6 +1243,7 @@ EEJitManager::EEJitManager() #ifdef TARGET_ARM64 extern "C" DWORD64 __stdcall GetDataCacheZeroIDReg(); +extern "C" uint64_t GetSveLengthFromOS(); #endif void EEJitManager::SetCpuInfo() diff --git a/src/coreclr/vm/codeman.h b/src/coreclr/vm/codeman.h index 9504e893c7924..7d874c6ba7e69 100644 --- a/src/coreclr/vm/codeman.h +++ b/src/coreclr/vm/codeman.h @@ -69,10 +69,6 @@ Module Name: #include "gcinfo.h" #include "eexcp.h" -#if defined(TARGET_ARM64) -extern "C" uint64_t GetSveLengthFromOS(); -#endif - class MethodDesc; class ICorJitCompiler; class IJitManager; From 528e157069768357e73c88066345f3494faa7690 Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Wed, 5 Jun 2024 17:58:38 +0100 Subject: [PATCH 13/14] Disable temporarily for Windows on Arm machines --- src/coreclr/vm/arm64/asmhelpers.asm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/arm64/asmhelpers.asm b/src/coreclr/vm/arm64/asmhelpers.asm index 4953717af6868..ca5738f4a51a4 100644 --- a/src/coreclr/vm/arm64/asmhelpers.asm +++ b/src/coreclr/vm/arm64/asmhelpers.asm @@ -80,7 +80,8 @@ ;; uint64_t GetSveLengthFromOS(void); LEAF_ENTRY GetSveLengthFromOS - rdvl x0, 1 + ;; TODO-SVE: Uncomment once CI machines are updated to use MASM 14.4 or later + ;; rdvl x0, 1 ret lr LEAF_END From ec0c317aa250aa58b34bdc7bd87103d19b3438a3 Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Thu, 6 Jun 2024 11:43:42 +0100 Subject: [PATCH 14/14] Hardcode GetSveLengthFromOS() to return SVE length as 128 --- src/coreclr/vm/arm64/asmhelpers.asm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/arm64/asmhelpers.asm b/src/coreclr/vm/arm64/asmhelpers.asm index ca5738f4a51a4..e27d2e178c3f8 100644 --- a/src/coreclr/vm/arm64/asmhelpers.asm +++ b/src/coreclr/vm/arm64/asmhelpers.asm @@ -80,8 +80,9 @@ ;; uint64_t GetSveLengthFromOS(void); LEAF_ENTRY GetSveLengthFromOS - ;; TODO-SVE: Uncomment once CI machines are updated to use MASM 14.4 or later + ;; TODO-SVE: Remove the hardcoded value 128 and uncomment once CI machines are updated to use MASM 14.4 or later ;; rdvl x0, 1 + mov x0, #128 ret lr LEAF_END