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