[clang] [NFC][Docs] Documenting __builtin_cpu_supports. (PR #84098)

Pavel Iliin via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 5 16:32:30 PST 2024


https://github.com/ilinpv created https://github.com/llvm/llvm-project/pull/84098

None

>From 528af71d043d306a4aeb5c448a0780fa42644c15 Mon Sep 17 00:00:00 2001
From: Pavel Iliin <pavel.iliin at arm.com>
Date: Wed, 6 Mar 2024 00:23:36 +0000
Subject: [PATCH] [NFC][Docs] Documenting __builtin_cpu_supports.

---
 clang/docs/LanguageExtensions.rst | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst
index bcd69198eafdbe..f939d1c765e91a 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2799,6 +2799,34 @@ counter's true frequency will need to be provided by the user.
 
 Query for this feature with ``__has_builtin(__builtin_readsteadycounter)``.
 
+``__builtin_cpu_supports``
+--------------------------
+
+**Syntax**:
+
+.. code-block:: c++
+
+  int __builtin_cpu_supports(const char *features);
+
+**Example of Use:**:
+
+.. code-block:: c++
+
+  if (__builtin_cpu_supports("sve"))
+    sve_code();
+
+**Description**:
+
+The ``__builtin_cpu_supports`` function detects at runtime if target CPU
+supports features specified in string argument. It returns positive integer
+if all features are supported and 0 otherwise. Names of features and format is
+target specific. For example on AArch64 features are combined using ``+`` like
+this ``__builtin_cpu_supports("flagm+sha3+lse+rcpc2+fcma+memtag+bti+sme2")``.
+If feature name is not supported or format is wrong, compiler will issue a
+warning and replace builtin by constant 0.
+
+Query for this feature with ``__has_builtin(__builtin_cpu_supports)``.
+
 ``__builtin_dump_struct``
 -------------------------
 



More information about the cfe-commits mailing list