Skip to content

Conversation

@SchrodingerZhu
Copy link
Contributor

@SchrodingerZhu SchrodingerZhu commented Nov 7, 2025

Add in SVE/SVE2/MOPS features for aarch64 cpus. These features may be interesting for future memory/math routines.

SVE/SVE2 are now being accepted in more implementations:

❯ echo | clang-21 -dM -E - -march=native | grep -i ARM_FEAT
#define __ARM_FEATURE_ATOMICS 1
#define __ARM_FEATURE_BF16 1
#define __ARM_FEATURE_BF16_SCALAR_ARITHMETIC 1
#define __ARM_FEATURE_BF16_VECTOR_ARITHMETIC 1
#define __ARM_FEATURE_BTI 1
#define __ARM_FEATURE_CLZ 1
#define __ARM_FEATURE_COMPLEX 1
#define __ARM_FEATURE_CRC32 1
#define __ARM_FEATURE_DIRECTED_ROUNDING 1
#define __ARM_FEATURE_DIV 1
#define __ARM_FEATURE_DOTPROD 1
#define __ARM_FEATURE_FMA 1
#define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1
#define __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 1
#define __ARM_FEATURE_FRINT 1
#define __ARM_FEATURE_IDIV 1
#define __ARM_FEATURE_JCVT 1
#define __ARM_FEATURE_LDREX 0xF
#define __ARM_FEATURE_MATMUL_INT8 1
#define __ARM_FEATURE_NUMERIC_MAXMIN 1
#define __ARM_FEATURE_PAUTH 1
#define __ARM_FEATURE_QRDMX 1
#define __ARM_FEATURE_RCPC 1
#define __ARM_FEATURE_SVE 1
#define __ARM_FEATURE_SVE2 1
#define __ARM_FEATURE_SVE_BF16 1
#define __ARM_FEATURE_SVE_MATMUL_INT8 1
#define __ARM_FEATURE_SVE_VECTOR_OPERATORS 2
#define __ARM_FEATURE_UNALIGNED 1

MOPS is another set of extension for string operations, but may not be generally available for now:

❯ echo | clang-21 -dM -E - -march=armv9.2a+mops | grep -i MOPS
#define __ARM_FEATURE_MOPS 1

@llvmbot llvmbot added the libc label Nov 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 7, 2025

@llvm/pr-subscribers-libc

Author: Schrodinger ZHU Yifan (SchrodingerZhu)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/166884.diff

5 Files Affected:

  • (modified) libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake (+1-1)
  • (added) libc/cmake/modules/cpu_features/check_MOPS.cpp (+7)
  • (added) libc/cmake/modules/cpu_features/check_SVE.cpp (+7)
  • (added) libc/cmake/modules/cpu_features/check_SVE2.cpp (+7)
  • (modified) libc/src/__support/macros/properties/cpu_features.h (+12)
diff --git a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
index c09d4751d3907..d76f3b16b30ec 100644
--- a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
+++ b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
@@ -9,7 +9,7 @@ if(LIBC_TARGET_ARCHITECTURE_IS_X86_64)
   set(ALL_CPU_FEATURES SSE2 SSE4_2 AVX AVX2 AVX512F AVX512BW FMA)
   set(LIBC_COMPILE_OPTIONS_NATIVE -march=native)
 elseif(LIBC_TARGET_ARCHITECTURE_IS_AARCH64)
-  set(ALL_CPU_FEATURES "FullFP16")
+  set(ALL_CPU_FEATURES FullFP16 MOPS SVE SVE2)
   set(LIBC_COMPILE_OPTIONS_NATIVE -mcpu=native)
 endif()
 
diff --git a/libc/cmake/modules/cpu_features/check_MOPS.cpp b/libc/cmake/modules/cpu_features/check_MOPS.cpp
new file mode 100644
index 0000000000000..bf5d392242b44
--- /dev/null
+++ b/libc/cmake/modules/cpu_features/check_MOPS.cpp
@@ -0,0 +1,7 @@
+#include "src/__support/macros/properties/cpu_features.h"
+
+#ifndef LIBC_TARGET_CPU_HAS_MOPS
+#error unsupported
+#endif
+
+
diff --git a/libc/cmake/modules/cpu_features/check_SVE.cpp b/libc/cmake/modules/cpu_features/check_SVE.cpp
new file mode 100644
index 0000000000000..0ae4b4dcf3558
--- /dev/null
+++ b/libc/cmake/modules/cpu_features/check_SVE.cpp
@@ -0,0 +1,7 @@
+#include "src/__support/macros/properties/cpu_features.h"
+
+#ifndef LIBC_TARGET_CPU_HAS_SVE
+#error unsupported
+#endif
+
+
diff --git a/libc/cmake/modules/cpu_features/check_SVE2.cpp b/libc/cmake/modules/cpu_features/check_SVE2.cpp
new file mode 100644
index 0000000000000..b46d1ac421267
--- /dev/null
+++ b/libc/cmake/modules/cpu_features/check_SVE2.cpp
@@ -0,0 +1,7 @@
+#include "src/__support/macros/properties/cpu_features.h"
+
+#ifndef LIBC_TARGET_CPU_HAS_SVE2
+#error unsupported
+#endif
+
+
diff --git a/libc/src/__support/macros/properties/cpu_features.h b/libc/src/__support/macros/properties/cpu_features.h
index fc6099ca6ccc5..1fe20d9b23a34 100644
--- a/libc/src/__support/macros/properties/cpu_features.h
+++ b/libc/src/__support/macros/properties/cpu_features.h
@@ -18,6 +18,18 @@
 #define LIBC_TARGET_CPU_HAS_FULLFP16
 #endif
 
+#if defined(__ARM_FEATURE_SVE)
+#define LIBC_TARGET_CPU_HAS_SVE
+#endif
+
+#if defined(__ARM_FEATURE_SVE2)
+#define LIBC_TARGET_CPU_HAS_SVE2
+#endif
+
+#if defined(__ARM_FEATURE_MOPS)
+#define LIBC_TARGET_CPU_HAS_MOPS
+#endif
+
 #if defined(__SSE2__)
 #define LIBC_TARGET_CPU_HAS_SSE2
 #define LIBC_TARGET_CPU_HAS_FPU_FLOAT

@github-actions
Copy link

github-actions bot commented Nov 7, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@Andarwinux
Copy link
Contributor

Just for reference, Arm's latest C1 series CPUs support MOPS, but according to Arm's Software Developer Errata Notice, MOPS might cause performance degradation. may need dispatch like FSRM.

4043997
FEAT_MOPS instructions might cause performance degradation

@SchrodingerZhu
Copy link
Contributor Author

Just for reference, Arm's latest C1 series CPUs support MOPS, but according to Arm's Software Developer Errata Notice, MOPS might cause performance degradation. may need dispatch like FSRM.

4043997

FEAT_MOPS instructions might cause performance degradation

Got it. Thank you for the info!

Currently it is really just a feature flag. When we are going to use it, we could either look for ways to dispatch it or just leave it as a config flag.

@SchrodingerZhu SchrodingerZhu merged commit 2dd7705 into llvm:main Nov 7, 2025
20 checks passed
@SchrodingerZhu SchrodingerZhu deleted the libc/aarch64-flags branch November 7, 2025 18:58
vinay-deshmukh pushed a commit to vinay-deshmukh/llvm-project that referenced this pull request Nov 8, 2025
Add in SVE/SVE2/MOPS features for aarch64 cpus. These features may be
interesting for future memory/math routines.

SVE/SVE2 are now being accepted in more implementations:

```
❯ echo | clang-21 -dM -E - -march=native | grep -i ARM_FEAT
#define __ARM_FEATURE_ATOMICS 1
#define __ARM_FEATURE_BF16 1
#define __ARM_FEATURE_BF16_SCALAR_ARITHMETIC 1
#define __ARM_FEATURE_BF16_VECTOR_ARITHMETIC 1
#define __ARM_FEATURE_BTI 1
#define __ARM_FEATURE_CLZ 1
#define __ARM_FEATURE_COMPLEX 1
#define __ARM_FEATURE_CRC32 1
#define __ARM_FEATURE_DIRECTED_ROUNDING 1
#define __ARM_FEATURE_DIV 1
#define __ARM_FEATURE_DOTPROD 1
#define __ARM_FEATURE_FMA 1
#define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1
#define __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 1
#define __ARM_FEATURE_FRINT 1
#define __ARM_FEATURE_IDIV 1
#define __ARM_FEATURE_JCVT 1
#define __ARM_FEATURE_LDREX 0xF
#define __ARM_FEATURE_MATMUL_INT8 1
#define __ARM_FEATURE_NUMERIC_MAXMIN 1
#define __ARM_FEATURE_PAUTH 1
#define __ARM_FEATURE_QRDMX 1
#define __ARM_FEATURE_RCPC 1
#define __ARM_FEATURE_SVE 1
#define __ARM_FEATURE_SVE2 1
#define __ARM_FEATURE_SVE_BF16 1
#define __ARM_FEATURE_SVE_MATMUL_INT8 1
#define __ARM_FEATURE_SVE_VECTOR_OPERATORS 2
#define __ARM_FEATURE_UNALIGNED 1
```
MOPS is another set of extension for string operations, but may not be
generally available for now:
```
❯ echo | clang-21 -dM -E - -march=armv9.2a+mops | grep -i MOPS
#define __ARM_FEATURE_MOPS 1
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants