Skip to content

[Clang][AArch64]Add FP8 ACLE macros implementation #140591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 27, 2025

Conversation

CarolineConcatto
Copy link
Contributor

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:AArch64 clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 19, 2025
@llvmbot
Copy link
Member

llvmbot commented May 19, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-aarch64

Author: None (CarolineConcatto)

Changes

This patch implements the macros described in the ACLE[1]

[1] https://github.com/ARM-software/acle/blob/main/main/acle.md#modal-8-bit-floating-point-extensions


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

3 Files Affected:

  • (modified) clang/lib/Basic/Targets/AArch64.cpp (+59)
  • (modified) clang/lib/Basic/Targets/AArch64.h (+9)
  • (modified) clang/test/Preprocessor/aarch64-target-features.c (+31)
diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp
index e1f6c7b834dc7..7267b17704a41 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -596,6 +596,33 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
   if (HasSMEB16B16)
     Builder.defineMacro("__ARM_FEATURE_SME_B16B16", "1");
 
+  if (HasFP8)
+    Builder.defineMacro("__ARM_FEATURE_FP8", "1");
+
+  if (HasFP8FMA)
+    Builder.defineMacro("__ARM_FEATURE_FP8FMA", "1");
+
+  if (HasFP8DOT2)
+    Builder.defineMacro("__ARM_FEATURE_FP8DOT2", "1");
+
+  if (HasFP8DOT4)
+    Builder.defineMacro("__ARM_FEATURE_FP8DOT4", "1");
+
+  if (HasSSVE_FP8DOT2)
+    Builder.defineMacro("__ARM_FEATURE_SSVE_FP8DOT2", "1");
+
+  if (HasSSVE_FP8DOT4)
+    Builder.defineMacro("__ARM_FEATURE_SSVE_FP8DOT4", "1");
+
+  if (HasSSVE_FP8FMA)
+    Builder.defineMacro("__ARM_FEATURE_SSVE_FP8FMA", "1");
+
+  if (HasSME_F8F32)
+    Builder.defineMacro("__ARM_FEATURE_SME_F8F32", "1");
+
+  if (HasSME_F8F16)
+    Builder.defineMacro("__ARM_FEATURE_SME_F8F16", "1");
+
   if (HasCRC)
     Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
 
@@ -885,6 +912,15 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const {
       .Cases("ls64", "ls64_v", "ls64_accdata", HasLS64)
       .Case("wfxt", HasWFxT)
       .Case("rcpc3", HasRCPC3)
+      .Case("fp8", HasFP8)
+      .Case("fp8fma", HasFP8FMA)
+      .Case("fp8dot2", HasFP8DOT2)
+      .Case("fp8dot4", HasFP8DOT4)
+      .Case("ssve-fp8dot2", HasSSVE_FP8DOT2)
+      .Case("ssve-fp8dot4", HasSSVE_FP8DOT4)
+      .Case("ssve-fp8fma", HasSSVE_FP8FMA)
+      .Case("sme-f8f32", HasSME_F8F32)
+      .Case("sme-f8f16", HasSME_F8F16)
       .Default(false);
 }
 
@@ -1046,6 +1082,29 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
       HasSVEB16B16 = true;
       HasSMEB16B16 = true;
     }
+
+    if (Feature == "+fp8")
+      HasFP8 = true;
+    if (Feature == "+fp8fma")
+      HasFP8FMA = true;
+    if (Feature == "+fp8dot2")
+      HasFP8DOT2 = true;
+    if (Feature == "+fp8dot4")
+      HasFP8DOT4 = true;
+    if (Feature == "+ssve-fp8dot2")
+      HasSSVE_FP8DOT2 = true;
+    if (Feature == "+ssve-fp8dot4")
+      HasSSVE_FP8DOT4 = true;
+    if (Feature == "+ssve-fp8fma")
+      HasSSVE_FP8FMA = true;
+    if (Feature == "+sme-f8f32") {
+      HasSME2 = true;
+      HasSME_F8F32 = true;
+    }
+    if (Feature == "+sme-f8f16") {
+      HasSME2 = true;
+      HasSME_F8F16 = true;
+    }
     if (Feature == "+sb")
       HasSB = true;
     if (Feature == "+predres")
diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h
index 6eeac69af20df..7230f22d5bb86 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -106,6 +106,15 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
   bool HasSMEF16F16 = false;
   bool HasSMEB16B16 = false;
   bool HasSME2p1 = false;
+  bool HasFP8 = false;
+  bool HasFP8FMA = false;
+  bool HasFP8DOT2 = false;
+  bool HasFP8DOT4 = false;
+  bool HasSSVE_FP8DOT2 = false;
+  bool HasSSVE_FP8DOT4 = false;
+  bool HasSSVE_FP8FMA = false;
+  bool HasSME_F8F32 = false;
+  bool HasSME_F8F16 = false;
   bool HasSB = false;
   bool HasPredRes = false;
   bool HasSSBS = false;
diff --git a/clang/test/Preprocessor/aarch64-target-features.c b/clang/test/Preprocessor/aarch64-target-features.c
index 3f801c4344940..52045d216262f 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -744,3 +744,34 @@
 // CHECK-SMEB16B16: __ARM_FEATURE_SME2 1
 // CHECK-SMEB16B16: __ARM_FEATURE_SME_B16B16 1
 // CHECK-SMEB16B16: __ARM_FEATURE_SVE_B16B16 1
+//
+//  RUN: %clang --target=aarch64 -march=armv9-a+fp8 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FP8 %s
+// CHECK-FP8: __ARM_FEATURE_FP8 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+fp8fma -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FP8FMA %s
+// CHECK-FP8FMA: __ARM_FEATURE_FP8FMA 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+fp8dot2 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FP8DOT2 %s
+// CHECK-FP8DOT2: __ARM_FEATURE_FP8DOT2 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+fp8dot4 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FP8DOT4 %s
+// CHECK-FP8DOT4: __ARM_FEATURE_FP8DOT4 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+ssve-fp8dot2 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SSVE-FP8DOT2 %s
+// CHECK-SSVE-FP8DOT2: __ARM_FEATURE_SSVE_FP8DOT2 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+ssve-fp8dot4 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SSVE-FP8DOT4 %s
+// CHECK-SSVE-FP8DOT4: __ARM_FEATURE_SSVE_FP8DOT4 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+ssve-fp8fma -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SSVE-FP8FMA %s
+// CHECK-SSVE-FP8FMA: __ARM_FEATURE_SSVE_FP8FMA 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+sme-f8f32 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SMEF8F32 %s
+// CHECK-SMEF8F32: __ARM_FEATURE_LOCALLY_STREAMING 1
+// CHECK-SMEF8F32: __ARM_FEATURE_SME2 1
+// CHECK-SMEF8F32: __ARM_FEATURE_SME_F8F32 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+sme-f8f16 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SMEF8F16 %s
+// CHECK-SMEF8F16: __ARM_FEATURE_LOCALLY_STREAMING 1
+// CHECK-SMEF8F16: __ARM_FEATURE_SME2 1
+// CHECK-SMEF8F16: __ARM_FEATURE_SME_F8F16 1

It looks like other features are set by default, following the
dependendy in Features. We only need to set the new ones.
Copy link
Collaborator

@paulwalker-arm paulwalker-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last question but otherwise this looks good to me.

@CarolineConcatto CarolineConcatto merged commit 7569de5 into llvm:main May 27, 2025
11 checks passed
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AArch64 clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants