Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions compiler-rt/lib/builtins/cpu_model/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ enum VendorSignatures {
SIG_AMD = 0x68747541, // Auth
};

enum ProcessorVendors {
enum ProcessorVendors : unsigned int {
Copy link
Member

Choose a reason for hiding this comment

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

Is this ISO-compliant C? In C17 standard 6.7.2.2 enum-specifier has no enum-base which I am afraid that is only a C++11 feature.

Copy link
Member

Choose a reason for hiding this comment

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

Ok. enum-type-specifier is a C23 feature and only supported in gcc-13+. Is this : unsigned int important here and can we get rid of it in favor of compatibility with older compilers?

VENDOR_INTEL = 1,
VENDOR_AMD,
VENDOR_OTHER,
VENDOR_MAX
};

enum ProcessorTypes {
enum ProcessorTypes : unsigned int {
INTEL_BONNELL = 1,
INTEL_CORE2,
INTEL_COREI7,
Expand Down Expand Up @@ -319,11 +319,9 @@ static void detectX86FamilyModel(unsigned EAX, unsigned *Family,

#define testFeature(F) (Features[F / 32] & (1 << (F % 32))) != 0

static const char *getIntelProcessorTypeAndSubtype(unsigned Family,
unsigned Model,
const unsigned *Features,
unsigned *Type,
unsigned *Subtype) {
static const char *getIntelProcessorTypeAndSubtype(
unsigned Family, unsigned Model, const unsigned *Features,
enum ProcessorTypes *Type, enum ProcessorSubtypes *Subtype) {
// We select CPU strings to match the code in Host.cpp, but we don't use them
// in compiler-rt.
const char *CPU = 0;
Expand Down Expand Up @@ -616,8 +614,7 @@ static const char *getIntelProcessorTypeAndSubtype(unsigned Family,
// Clearwaterforest:
case 0xdd:
CPU = "clearwaterforest";
*Type = INTEL_COREI7;
*Subtype = INTEL_CLEARWATERFOREST;
*Type = INTEL_CLEARWATERFOREST;
break;

case 0x57:
Expand Down Expand Up @@ -667,11 +664,9 @@ static const char *getIntelProcessorTypeAndSubtype(unsigned Family,
return CPU;
}

static const char *getAMDProcessorTypeAndSubtype(unsigned Family,
unsigned Model,
const unsigned *Features,
unsigned *Type,
unsigned *Subtype) {
static const char *getAMDProcessorTypeAndSubtype(
unsigned Family, unsigned Model, const unsigned *Features,
enum ProcessorTypes *Type, enum ProcessorSubtypes *Subtype) {
const char *CPU = 0;

switch (Family) {
Expand Down Expand Up @@ -1162,11 +1157,14 @@ __attribute__((visibility("hidden")))
#endif
struct __processor_model {
unsigned int __cpu_vendor;
unsigned int __cpu_type;
unsigned int __cpu_subtype;
enum ProcessorTypes __cpu_type;
enum ProcessorSubtypes __cpu_subtype;
unsigned int __cpu_features[1];
} __cpu_model = {0, 0, 0, {0}};

static_assert(sizeof(__cpu_model) == 16,
"Wrong size of __cpu_model will result in ABI break");

#ifndef _WIN32
__attribute__((visibility("hidden")))
#endif
Expand Down