xref: /aosp_15_r20/external/ltp/include/lapi/cpuid.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 #if !(defined(__i386__) || defined(__x86_64__))
4 #  error "cpuid.h should only be included on x86"
5 #endif
6 
7 #ifdef HAVE_CPUID_H
8 #  include <cpuid.h>
9 #endif
10 
11 #ifndef LAPI_CPUID_H__
12 #define LAPI_CPUID_H__
13 
14 /*
15  * gcc cpuid.h provides __cpuid_count() since v4.4.
16  * Clang/LLVM cpuid.h provides __cpuid_count() since v3.4.0.
17  *
18  * Provide local define for tests needing __cpuid_count() because
19  * ltp needs to work in older environments that do not yet
20  * have __cpuid_count().
21  */
22 #ifndef __cpuid_count
23 #define __cpuid_count(level, count, a, b, c, d) ({			\
24 	__asm__ __volatile__ ("cpuid\n\t"				\
25 			      : "=a" (a), "=b" (b), "=c" (c), "=d" (d)	\
26 			      : "0" (level), "2" (count));		\
27 })
28 #endif
29 
30 #endif /* LAPI_CPUID_H__ */
31