From 6dd52284c7d25fa0d7befef8f65bec394cf00988 Mon Sep 17 00:00:00 2001 From: Romanova Date: Wed, 3 Dec 2025 08:33:52 -0800 Subject: [PATCH 1/2] [clang] [doc] Added documentation to intrinsics in cpuid.h --- clang/lib/Headers/cpuid.h | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/clang/lib/Headers/cpuid.h b/clang/lib/Headers/cpuid.h index 432747ba1f6ad..cd5828d925099 100644 --- a/clang/lib/Headers/cpuid.h +++ b/clang/lib/Headers/cpuid.h @@ -278,6 +278,23 @@ : "0"(__leaf), "2"(__count)) #endif +/// Queries the processor to determine the highest supported \c CPUID leaf. +/// +/// \headerfile +/// +/// This intrinsic corresponds to the CPUID instruction. +/// +/// \param __leaf +/// \a __leaf can be either 0x0 or 0x8000000. If \a __leaf == 0x0, the +/// highest supported value for basic \c CPUID information is returned. +/// If \a __leaf == 0x8000000, the highest supported value for extended +/// \c CPUID information is returned. +/// \param __sig +/// If the \a __sig pointer is non-null, the first four bytes of the +/// signature (as found in the \c ebx register) are returned in the +/// location pointed to by \a __sig. +/// \returns Returns 0 if \c CPUID is supported; otherwise returns the value +/// that \c CPUID returns in the \c eax register. static __inline unsigned int __get_cpuid_max (unsigned int __leaf, unsigned int *__sig) { @@ -311,6 +328,32 @@ static __inline unsigned int __get_cpuid_max (unsigned int __leaf, return __eax; } +/// For the requested \c CPUID leaf, queries the processor for information +/// about the CPU type and CPU features (such as processor vendor, supported +/// instruction sets, CPU capabilities, cache sizes, CPU model and family, and +/// other hardware details). This intrinsic is only available on x86 and x64. +/// +/// \headerfile +/// +/// This intrinsic corresponds to the CPUID instruction. +/// +/// \param __leaf +/// An unsigned integer that identifies the level (also called "leaf") at +/// which the \c CPUID instruction will be executed. +/// \param __eax +/// A pointer to an integer that corresponds to the \c eax register where +/// \c CPUID stores output results. +/// \param __ebx +/// A pointer to an integer that corresponds to the \c ebx register where +/// \c CPUID stores output results. +/// \param __ecx +/// A pointer to an integer that corresponds to the \c ecx register where +/// \c CPUID stores output results. +/// \param __edx +/// A pointer to an integer that corresponds to the \c edx register where +/// \c CPUID stores output results. +/// \returns Returns 1 if the requested \c CPUID leaf is supported; otherwise +/// returns 0. static __inline int __get_cpuid (unsigned int __leaf, unsigned int *__eax, unsigned int *__ebx, unsigned int *__ecx, unsigned int *__edx) @@ -324,6 +367,36 @@ static __inline int __get_cpuid (unsigned int __leaf, unsigned int *__eax, return 1; } +/// For the requested \c CPUID leaf and subleaf, queries the processor for +/// information about the CPU type and CPU features (such as processor vendor, +/// supported instruction sets, CPU capabilities, cache sizes, CPU model and +/// family, and other hardware details). This intrinsic is only available on +/// x86 and x64. +/// +/// \headerfile +/// +/// This intrinsic corresponds to the CPUID instruction. +/// +/// \param __leaf +/// An unsigned integer that identifies the level (also called "leaf") at +/// which the \c CPUID instruction will be executed. +/// \param __subleaf +/// An unsigned integer that identifies the sublevel (also called +/// "subleaf") at which the \c CPUID instruction will be executed. +/// \param __eax +/// A pointer to an integer that corresponds to the \c eax register where +/// \c CPUID stores output results. +/// \param __ebx +/// A pointer to an integer that corresponds to the \c ebx register where +/// \c CPUID stores output results. +/// \param __ecx +/// A pointer to an integer that corresponds to the \c ecx register where +/// \c CPUID stores output results. +/// \param __edx +/// A pointer to an integer that corresponds to the \c edx register where +/// \c CPUID stores output results. +/// \returns Returns 1 if the requested \c CPUID leaf is supported; otherwise +/// returns 0. static __inline int __get_cpuid_count (unsigned int __leaf, unsigned int __subleaf, unsigned int *__eax, unsigned int *__ebx, @@ -345,6 +418,27 @@ static __inline int __get_cpuid_count (unsigned int __leaf, // builtin. Given __has_builtin does not detect builtins on aux triples, we need // to explicitly check for some offloading cases. #if !defined(__NVPTX__) && !defined(__AMDGPU__) && !defined(__SPIRV__) +/// Executes the \c CPUID instruction with the specified leaf and subleaf +/// values, and returns the results from the CPU's registers. +/// +/// \headerfile +/// +/// This intrinsic corresponds to the CPUID instruction. +/// +/// \param __cpu_info +/// An output array of four integers: +///
    +///
  • \a __cpuInfo[0] receives the value of the \c eax register.
  • +///
  • \a__cpuInfo[1] receives the value of the \c ebx register.
  • +///
  • \a__cpuInfo[2] receives the value of the \c ecx register.
  • +///
  • \a__cpuInfo[3] receives the value of the \c edx register.
  • +///
+/// \param __leaf +/// An unsigned integer that identifies the level (also called the "leaf") +/// at which the \c CPUID instruction will be executed. +/// \param __subleaf +/// An unsigned integer that identifies the sublevel (also called the +/// "subleaf") at which the \c CPUID instruction will be executed. static __inline void __cpuidex(int __cpu_info[4], int __leaf, int __subleaf) { __cpuid_count(__leaf, __subleaf, __cpu_info[0], __cpu_info[1], __cpu_info[2], __cpu_info[3]); From f29da145ad063d03a55b14eeadbd441501147c3c Mon Sep 17 00:00:00 2001 From: Romanova Date: Fri, 5 Dec 2025 07:21:11 -0800 Subject: [PATCH 2/2] Responded to code review comments to intrinsics documentation in cpuid.h --- clang/lib/Headers/cpuid.h | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/clang/lib/Headers/cpuid.h b/clang/lib/Headers/cpuid.h index cd5828d925099..156425c7561bb 100644 --- a/clang/lib/Headers/cpuid.h +++ b/clang/lib/Headers/cpuid.h @@ -279,6 +279,7 @@ #endif /// Queries the processor to determine the highest supported \c CPUID leaf. +/// This intrinsic is only available on x86 and x64. /// /// \headerfile /// @@ -291,10 +292,10 @@ /// \c CPUID information is returned. /// \param __sig /// If the \a __sig pointer is non-null, the first four bytes of the -/// signature (as found in the \c ebx register) are returned in the +/// signature (as found in the \c EBX register) are returned in the /// location pointed to by \a __sig. /// \returns Returns 0 if \c CPUID is supported; otherwise returns the value -/// that \c CPUID returns in the \c eax register. +/// that \c CPUID returns in the \c EAX register. static __inline unsigned int __get_cpuid_max (unsigned int __leaf, unsigned int *__sig) { @@ -341,16 +342,16 @@ static __inline unsigned int __get_cpuid_max (unsigned int __leaf, /// An unsigned integer that identifies the level (also called "leaf") at /// which the \c CPUID instruction will be executed. /// \param __eax -/// A pointer to an integer that corresponds to the \c eax register where +/// A pointer to an integer that corresponds to the \c EAX register where /// \c CPUID stores output results. /// \param __ebx -/// A pointer to an integer that corresponds to the \c ebx register where +/// A pointer to an integer that corresponds to the \c EBX register where /// \c CPUID stores output results. /// \param __ecx -/// A pointer to an integer that corresponds to the \c ecx register where +/// A pointer to an integer that corresponds to the \c ECX register where /// \c CPUID stores output results. /// \param __edx -/// A pointer to an integer that corresponds to the \c edx register where +/// A pointer to an integer that corresponds to the \c EDX register where /// \c CPUID stores output results. /// \returns Returns 1 if the requested \c CPUID leaf is supported; otherwise /// returns 0. @@ -384,16 +385,16 @@ static __inline int __get_cpuid (unsigned int __leaf, unsigned int *__eax, /// An unsigned integer that identifies the sublevel (also called /// "subleaf") at which the \c CPUID instruction will be executed. /// \param __eax -/// A pointer to an integer that corresponds to the \c eax register where +/// A pointer to an integer that corresponds to the \c EAX register where /// \c CPUID stores output results. /// \param __ebx -/// A pointer to an integer that corresponds to the \c ebx register where +/// A pointer to an integer that corresponds to the \c EBX register where /// \c CPUID stores output results. /// \param __ecx -/// A pointer to an integer that corresponds to the \c ecx register where +/// A pointer to an integer that corresponds to the \c ECX register where /// \c CPUID stores output results. /// \param __edx -/// A pointer to an integer that corresponds to the \c edx register where +/// A pointer to an integer that corresponds to the \c EDX register where /// \c CPUID stores output results. /// \returns Returns 1 if the requested \c CPUID leaf is supported; otherwise /// returns 0. @@ -419,7 +420,8 @@ static __inline int __get_cpuid_count (unsigned int __leaf, // to explicitly check for some offloading cases. #if !defined(__NVPTX__) && !defined(__AMDGPU__) && !defined(__SPIRV__) /// Executes the \c CPUID instruction with the specified leaf and subleaf -/// values, and returns the results from the CPU's registers. +/// values, and returns the results from the CPU's registers. This intrinsic +/// is only available on x86 and x64. /// /// \headerfile /// @@ -428,10 +430,10 @@ static __inline int __get_cpuid_count (unsigned int __leaf, /// \param __cpu_info /// An output array of four integers: ///
    -///
  • \a __cpuInfo[0] receives the value of the \c eax register.
  • -///
  • \a__cpuInfo[1] receives the value of the \c ebx register.
  • -///
  • \a__cpuInfo[2] receives the value of the \c ecx register.
  • -///
  • \a__cpuInfo[3] receives the value of the \c edx register.
  • +///
  • \a __cpuInfo[0] receives the value of the \c EAX register.
  • +///
  • \a __cpuInfo[1] receives the value of the \c EBX register.
  • +///
  • \a __cpuInfo[2] receives the value of the \c ECX register.
  • +///
  • \a __cpuInfo[3] receives the value of the \c EDX register.
  • ///
/// \param __leaf /// An unsigned integer that identifies the level (also called the "leaf")