Skip to content

[NFC][Docs] Documenting __builtin_cpu_supports. #84098

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
Mar 6, 2024

Conversation

ilinpv
Copy link
Contributor

@ilinpv ilinpv commented Mar 6, 2024

No description provided.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Mar 6, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 6, 2024

@llvm/pr-subscribers-clang

Author: Pavel Iliin (ilinpv)

Changes

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

1 Files Affected:

  • (modified) clang/docs/LanguageExtensions.rst (+28)
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``
 -------------------------
 

Copy link
Contributor

@jroelofs jroelofs left a comment

Choose a reason for hiding this comment

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

Some small nits, but LGTM.

@ilinpv
Copy link
Contributor Author

ilinpv commented Mar 6, 2024

Thanks @MaskRay for valuable comments, all addressed.

@ilinpv ilinpv force-pushed the builtin_cpu_supports_doc branch from 280583a to 85fd36e Compare March 6, 2024 17:43
@ilinpv ilinpv merged commit dcd08da into llvm:main Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants