[OpenMP][host runtime] Introduce kmp_cpuinfo_flags_t to replace integer flags
Store CPUID support flags as bits instead of using entire integers. Differential Revision: https://reviews.llvm.org/D110091
This commit is contained in:
parent
957b4c5750
commit
343b9e8590
|
@ -1206,6 +1206,12 @@ typedef struct kmp_cpuid {
|
|||
kmp_uint32 edx;
|
||||
} kmp_cpuid_t;
|
||||
|
||||
typedef struct kmp_cpuinfo_flags_t {
|
||||
unsigned sse2 : 1; // 0 if SSE2 instructions are not supported, 1 otherwise.
|
||||
unsigned rtm : 1; // 0 if RTM instructions are not supported, 1 otherwise.
|
||||
unsigned reserved : 30; // Ensure size of 32 bits
|
||||
} kmp_cpuinfo_flags_t;
|
||||
|
||||
typedef struct kmp_cpuinfo {
|
||||
int initialized; // If 0, other fields are not initialized.
|
||||
int signature; // CPUID(1).EAX
|
||||
|
@ -1213,8 +1219,7 @@ typedef struct kmp_cpuinfo {
|
|||
int model; // ( CPUID(1).EAX[19:16] << 4 ) + CPUID(1).EAX[7:4] ( ( Extended
|
||||
// Model << 4 ) + Model)
|
||||
int stepping; // CPUID(1).EAX[3:0] ( Stepping )
|
||||
int sse2; // 0 if SSE2 instructions are not supported, 1 otherwise.
|
||||
int rtm; // 0 if RTM instructions are not supported, 1 otherwise.
|
||||
kmp_cpuinfo_flags_t flags;
|
||||
int apic_id;
|
||||
int physical_id;
|
||||
int logical_id;
|
||||
|
|
|
@ -683,7 +683,7 @@ void __kmpc_flush(ident_t *loc) {
|
|||
if (!__kmp_cpuinfo.initialized) {
|
||||
__kmp_query_cpuid(&__kmp_cpuinfo);
|
||||
}
|
||||
if (!__kmp_cpuinfo.sse2) {
|
||||
if (!__kmp_cpuinfo.flags.sse2) {
|
||||
// CPU cannot execute SSE2 instructions.
|
||||
} else {
|
||||
#if KMP_COMPILER_ICC
|
||||
|
@ -1356,7 +1356,7 @@ static __forceinline kmp_dyna_lockseq_t __kmp_map_hint_to_lock(uintptr_t hint) {
|
|||
#endif
|
||||
|
||||
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
|
||||
#define KMP_CPUINFO_RTM (__kmp_cpuinfo.rtm)
|
||||
#define KMP_CPUINFO_RTM (__kmp_cpuinfo.flags.rtm)
|
||||
#else
|
||||
#define KMP_CPUINFO_RTM 0
|
||||
#endif
|
||||
|
|
|
@ -3202,13 +3202,13 @@ __kmp_lookup_indirect_lock(void **user_lock, const char *func) {
|
|||
static void __kmp_init_indirect_lock(kmp_dyna_lock_t *lock,
|
||||
kmp_dyna_lockseq_t seq) {
|
||||
#if KMP_USE_ADAPTIVE_LOCKS
|
||||
if (seq == lockseq_adaptive && !__kmp_cpuinfo.rtm) {
|
||||
if (seq == lockseq_adaptive && !__kmp_cpuinfo.flags.rtm) {
|
||||
KMP_WARNING(AdaptiveNotSupported, "kmp_lockseq_t", "adaptive");
|
||||
seq = lockseq_queuing;
|
||||
}
|
||||
#endif
|
||||
#if KMP_USE_TSX
|
||||
if (seq == lockseq_rtm_queuing && !__kmp_cpuinfo.rtm) {
|
||||
if (seq == lockseq_rtm_queuing && !__kmp_cpuinfo.flags.rtm) {
|
||||
seq = lockseq_queuing;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1040,7 +1040,7 @@ extern kmp_real64 __kmp_xchg_real64(volatile kmp_real64 *p, kmp_real64 v);
|
|||
if (UNLIKELY(!__kmp_cpuinfo.initialized)) { \
|
||||
__kmp_query_cpuid(&__kmp_cpuinfo); \
|
||||
} \
|
||||
if (__kmp_cpuinfo.sse2) { \
|
||||
if (__kmp_cpuinfo.flags.sse2) { \
|
||||
KMP_MFENCE_(); \
|
||||
}
|
||||
#define KMP_SFENCE() KMP_SFENCE_()
|
||||
|
|
|
@ -4467,7 +4467,7 @@ static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
|
|||
}
|
||||
#if KMP_USE_ADAPTIVE_LOCKS
|
||||
else if (__kmp_str_match("adaptive", 1, value)) {
|
||||
if (__kmp_cpuinfo.rtm) { // ??? Is cpuinfo available here?
|
||||
if (__kmp_cpuinfo.flags.rtm) { // ??? Is cpuinfo available here?
|
||||
__kmp_user_lock_kind = lk_adaptive;
|
||||
KMP_STORE_LOCK_SEQ(adaptive);
|
||||
} else {
|
||||
|
@ -4479,7 +4479,7 @@ static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
|
|||
#endif // KMP_USE_ADAPTIVE_LOCKS
|
||||
#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
|
||||
else if (__kmp_str_match("rtm_queuing", 1, value)) {
|
||||
if (__kmp_cpuinfo.rtm) {
|
||||
if (__kmp_cpuinfo.flags.rtm) {
|
||||
__kmp_user_lock_kind = lk_rtm_queuing;
|
||||
KMP_STORE_LOCK_SEQ(rtm_queuing);
|
||||
} else {
|
||||
|
@ -4488,7 +4488,7 @@ static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
|
|||
KMP_STORE_LOCK_SEQ(queuing);
|
||||
}
|
||||
} else if (__kmp_str_match("rtm_spin", 1, value)) {
|
||||
if (__kmp_cpuinfo.rtm) {
|
||||
if (__kmp_cpuinfo.flags.rtm) {
|
||||
__kmp_user_lock_kind = lk_rtm_spin;
|
||||
KMP_STORE_LOCK_SEQ(rtm_spin);
|
||||
} else {
|
||||
|
|
|
@ -129,7 +129,7 @@ void __kmp_query_cpuid(kmp_cpuinfo_t *p) {
|
|||
|
||||
p->initialized = 1;
|
||||
|
||||
p->sse2 = 1; // Assume SSE2 by default.
|
||||
p->flags.sse2 = 1; // Assume SSE2 by default.
|
||||
|
||||
__kmp_x86_cpuid(0, 0, &buf);
|
||||
|
||||
|
@ -169,7 +169,7 @@ void __kmp_query_cpuid(kmp_cpuinfo_t *p) {
|
|||
data[i] = (t & 0xff);
|
||||
}
|
||||
|
||||
p->sse2 = (buf.edx >> 26) & 1;
|
||||
p->flags.sse2 = (buf.edx >> 26) & 1;
|
||||
|
||||
#ifdef KMP_DEBUG
|
||||
|
||||
|
@ -248,11 +248,11 @@ void __kmp_query_cpuid(kmp_cpuinfo_t *p) {
|
|||
}
|
||||
#endif
|
||||
#if KMP_USE_ADAPTIVE_LOCKS
|
||||
p->rtm = 0;
|
||||
p->flags.rtm = 0;
|
||||
if (max_arg > 7) {
|
||||
/* RTM bit CPUID.07:EBX, bit 11 */
|
||||
__kmp_x86_cpuid(7, 0, &buf);
|
||||
p->rtm = (buf.ebx >> 11) & 1;
|
||||
p->flags.rtm = (buf.ebx >> 11) & 1;
|
||||
KA_TRACE(trace_level, (" RTM"));
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue