From 22aa47e02bb28f5fc009f06b7f526ee5aa33dfd7 Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Tue, 30 Apr 2024 17:40:50 +0100 Subject: [PATCH] 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;