Skip to content

Commit 22aa47e

Browse files
Use CNTB to determine current vector length
1 parent 19dce8d commit 22aa47e

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

src/coreclr/vm/codeman.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
//
55
// codeman.cpp - a managment class for handling multiple code managers
66
//
7-
#if defined(TARGET_LINUX)
8-
#include <sys/prctl.h>
9-
#include <sys/syscall.h>
10-
#endif // defined(TARGET_LINUX)
7+
118
#include "common.h"
129
#include "jitinterface.h"
1310
#include "corjit.h"
@@ -45,13 +42,6 @@
4542
#include "perfmap.h"
4643
#endif
4744

48-
#if defined(TARGET_LINUX) && !defined(PR_SVE_GET_VL)
49-
#define PR_SVE_SET_VL 50 /* set task vector length */
50-
#define PR_SVE_GET_VL 51 /* get task vector length */
51-
#define PR_SVE_VL_LEN_MASK 0xffff
52-
#define PR_SVE_VL_INHERIT (1 << 17) /* inherit across exec */
53-
#endif // defined(TARGET_LINUX) && !defined(PR_SVE_GET_VL)
54-
5545
// Default number of jump stubs in a jump stub block
5646
#define DEFAULT_JUMPSTUBS_PER_BLOCK 32
5747

@@ -1535,23 +1525,16 @@ void EEJitManager::SetCpuInfo()
15351525

15361526
if (((cpuFeatures & ARM64IntrinsicConstants_Sve) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableArm64Sve))
15371527
{
1538-
#if defined(TARGET_LINUX)
1539-
// prctl() expects vector length in bytes.
15401528
int maxVectorLength = (maxVectorTBitWidth >> 3);
1529+
uint64_t systemVectorTLength = GetSystemVectorLength();
15411530

1542-
// Limit the SVE vector length to 'maxVectorLength' if the underlying hardware offers longer vectors.
1543-
if ((prctl(PR_SVE_GET_VL, 0,0,0,0) & PR_SVE_VL_LEN_MASK) > maxVectorLength)
1531+
if (maxVectorLength >= systemVectorTLength)
15441532
{
1545-
if (prctl(PR_SVE_SET_VL, (maxVectorLength | PR_SVE_VL_INHERIT), 0, 0, 0) == -1)
1546-
{
1547-
LogErrorToHost("LoadAndInitializeJIT: prctl() FAILED - unable to set maxVectorLength to %d", maxVectorLength);
1548-
}
1533+
// Enable SVE only when user specified vector length larger than or equal to the system
1534+
// vector length. When eabled, SVE would use full vector length available to the process.
1535+
// For a 256-bit machine, if user provides DOTNET_MaxVectorTBitWidth=128, disable SVE.
1536+
CPUCompileFlags.Set(InstructionSet_Sve);
15491537
}
1550-
#elif defined(TARGET_WINDOWS)
1551-
// TODO-SVE: Add prctl() equivalent for windows.
1552-
#endif
1553-
1554-
CPUCompileFlags.Set(InstructionSet_Sve);
15551538
}
15561539

15571540
// DCZID_EL0<4> (DZP) indicates whether use of DC ZVA instructions is permitted (0) or prohibited (1).

src/coreclr/vm/codeman.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,16 @@ protected :
19121912
return m_CPUCompileFlags;
19131913
}
19141914

1915+
#ifdef __GNUC__
1916+
__attribute__((target("sve")))
1917+
#endif
1918+
inline UINT64 GetSystemVectorLength()
1919+
{
1920+
UINT64 size;
1921+
__asm__ __volatile__("cntb %0" : "=r"(size));
1922+
return size;
1923+
}
1924+
19151925
private:
19161926
bool m_storeRichDebugInfo;
19171927

0 commit comments

Comments
 (0)