Skip to content

Commit 4888ebd

Browse files
Test build
1 parent 4ca6174 commit 4888ebd

File tree

133 files changed

+524
-510
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+524
-510
lines changed

CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "DragonFly" OR ${CMAKE_SYSTEM_NAME} STREQUAL "N
3131
find_package(Threads REQUIRED)
3232
endif()
3333

34-
# check if popcount64 is available
3534
include(CheckSymbolExists)
36-
check_symbol_exists(popcount64 "string.h" HAVE_POPCOUNT64)
37-
if(HAVE_POPCOUNT64)
38-
add_definitions(-DHAVE_POPCOUNT64)
39-
endif(HAVE_POPCOUNT64)
4035

4136
# check if auxiliary vector is available
4237
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")

configure.ac

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ LT_INIT
5151
AM_CPPFLAGS="$CPPFLAGS"
5252

5353
AC_CHECK_HEADERS([stdint.h])
54-
AC_CHECK_FUNCS([popcount64])
5554

5655
AC_CHECK_PROGS([DOXYGEN], [doxygen])
5756
AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"])

libcpuid/libcpuid_util.c

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,10 @@ void debugf(int verboselevel, const char* format, ...)
8080
_warn_fun(buff);
8181
}
8282

83-
#ifndef HAVE_POPCOUNT64
84-
static unsigned int popcount64(uint64_t mask)
83+
static int score(const struct match_entry_t* entry, const struct cpu_id_t* data)
8584
{
86-
unsigned int num_set_bits = 0;
87-
88-
while (mask) {
89-
mask &= mask - 1;
90-
num_set_bits++;
91-
}
92-
93-
return num_set_bits;
94-
}
95-
#endif
96-
97-
static int score(const struct match_entry_t* entry, const struct cpu_id_t* data,
98-
int brand_code, uint64_t bits, int model_code)
99-
{
100-
int i, tmp, res = 0;
85+
int i, res = 0;
86+
char brand_str[BRAND_STR_MAX];
10187
const struct { const char *field; int entry; int data; int score; } array[] = {
10288
{ "family", entry->family, data->x86.family, 2 },
10389
{ "model", entry->model, data->x86.model, 2 },
@@ -107,36 +93,41 @@ static int score(const struct match_entry_t* entry, const struct cpu_id_t* data,
10793
{ "ncores", entry->ncores, data->num_cores, 2 },
10894
{ "l2cache", entry->l2cache, data->l2_cache, 1 },
10995
{ "l3cache", entry->l3cache, data->l3_cache, 1 },
110-
{ "brand_code", entry->brand_code, brand_code, 2 },
111-
{ "model_code", entry->model_code, model_code, 2 },
11296
};
11397
for (i = 0; i < sizeof(array) / sizeof(array[0]); i++) {
114-
if(array[i].entry == array[i].data) {
98+
if ((array[i].entry >= 0) && (array[i].entry == array[i].data)) {
11599
res += array[i].score;
116100
debugf(4, "Score: %-12s matches, adding %2i (current score for this entry: %2i)\n", array[i].field, array[i].score, res);
117101
}
118102
}
119103

120-
tmp = popcount64(entry->model_bits & bits) * 2;
121-
res += tmp;
122-
debugf(4, "Score: %-12s matches, adding %2i (current score for this entry: %2i)\n", "model_bits", tmp, res);
104+
if ((entry->brand.score > 0) && (strlen(entry->brand.pattern) > 0)) {
105+
/* Remove useless substrings in brand_str */
106+
strncpy(brand_str, data->brand_str, BRAND_STR_MAX);
107+
remove_substring(brand_str, "CPU ");
108+
/* Test pattern */
109+
debugf(5, "Test if '%s' brand pattern matches '%s'...\n", entry->brand.pattern, brand_str);
110+
if (match_pattern(brand_str, entry->brand.pattern)) {
111+
res += entry->brand.score;
112+
debugf(4, "Score: %-12s matches, adding %2i (current score for this entry: %2i)\n", "brand", entry->brand.score, res);
113+
}
114+
}
115+
123116
return res;
124117
}
125118

126-
int match_cpu_codename(const struct match_entry_t* matchtable, int count,
127-
struct cpu_id_t* data, int brand_code, uint64_t bits,
128-
int model_code)
119+
int match_cpu_codename(const struct match_entry_t* matchtable, int count, struct cpu_id_t* data)
129120
{
130121
int bestscore = -1;
131122
int bestindex = 0;
132123
int i, t;
133124

134-
debugf(3, "Matching cpu f:%d, m:%d, s:%d, xf:%d, xm:%d, ncore:%d, l2:%d, bcode:%d, bits:%llu, code:%d\n",
125+
debugf(3, "Matching cpu f:%d, m:%d, s:%d, xf:%d, xm:%d, ncore:%d, l2:%d, l3:%d\n",
135126
data->x86.family, data->x86.model, data->x86.stepping, data->x86.ext_family,
136-
data->x86.ext_model, data->num_cores, data->l2_cache, brand_code, (unsigned long long) bits, model_code);
127+
data->x86.ext_model, data->num_cores, data->l2_cache, data->l3_cache);
137128

138129
for (i = 0; i < count; i++) {
139-
t = score(&matchtable[i], data, brand_code, bits, model_code);
130+
t = score(&matchtable[i], data);
140131
debugf(3, "Entry %d, `%s', score %d\n", i, matchtable[i].name, t);
141132
if (t > bestscore) {
142133
debugf(2, "Entry `%s' selected - best score so far (%d)\n", matchtable[i].name, t);
@@ -192,15 +183,15 @@ static int xmatch_entry(char c, const char* p)
192183
{
193184
int i, j;
194185
if (c == 0) return -1;
195-
if (c == p[0]) return 1;
186+
if (tolower(c) == tolower(p[0])) return 1;
196187
if (p[0] == '.') return 1;
197188
if (p[0] == '#' && isdigit(c)) return 1;
198189
if (p[0] == '[') {
199190
j = 1;
200191
while (p[j] && p[j] != ']') j++;
201192
if (!p[j]) return -1;
202193
for (i = 1; i < j; i++)
203-
if (p[i] == c) return j + 1;
194+
if (tolower(p[i]) == tolower(c)) return j + 1;
204195
}
205196
return -1;
206197
}
@@ -224,6 +215,17 @@ int match_pattern(const char* s, const char* p)
224215
return 0;
225216
}
226217

218+
void remove_substring(char* string, const char* substring)
219+
{
220+
size_t len;
221+
char *pos = strstr(string, substring);
222+
223+
if (pos != NULL) {
224+
len = strlen(substring);
225+
memmove(pos, pos + len, strlen(pos + len) + 1);
226+
}
227+
}
228+
227229
struct cpu_id_t* get_cached_cpuid(void)
228230
{
229231
static int initialized = 0;

libcpuid/libcpuid_util.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,21 @@ struct feature_map_t {
3939
void match_features(const struct feature_map_t* matchtable, int count,
4040
uint32_t reg, struct cpu_id_t* data);
4141

42+
struct brand_t {
43+
char pattern[BRAND_STR_MAX];
44+
int score;
45+
};
46+
4247
struct match_entry_t {
4348
int family, model, stepping, ext_family, ext_model;
44-
int ncores, l2cache, l3cache, brand_code;
45-
uint64_t model_bits;
46-
int model_code;
49+
int ncores, l2cache, l3cache;
50+
struct brand_t brand;
4751
char name[CODENAME_STR_MAX];
4852
};
4953

5054
// returns the match score:
51-
int match_cpu_codename(const struct match_entry_t* matchtable, int count,
52-
struct cpu_id_t* data, int brand_code, uint64_t bits,
53-
int model_code);
55+
56+
int match_cpu_codename(const struct match_entry_t* matchtable, int count, struct cpu_id_t* data);
5457

5558
void warnf(const char* format, ...)
5659
#ifdef __GNUC__
@@ -77,6 +80,11 @@ void generic_get_cpu_list(const struct match_entry_t* matchtable, int count,
7780
*/
7881
int match_pattern(const char* haystack, const char* pattern);
7982

83+
/*
84+
* Remove a substring from a string
85+
*/
86+
void remove_substring(char* string, const char* substring);
87+
8088
/*
8189
* Gets an initialized cpu_id_t. It is cached, so that internal libcpuid
8290
* machinery doesn't need to issue cpu_identify more than once.

libcpuid/recog_amd.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ struct amd_code_and_bits_t {
4646

4747

4848
const struct match_entry_t cpudb_amd[] = {
49-
// F M S EF EM #cores L2$ L3$ BC ModelBits ModelCode Name
50-
{ -1, -1, -1, -1, -1, 1, -1, -1, NC, 0 , 0, "Unknown AMD CPU" },
5149

50+
// F M S EF EM #cores L2$ L3$ Pattern Name
51+
{ -1, -1, -1, -1, -1, 1, -1, -1, { "", 0 }, "Unknown AMD CPU" },
52+
#if 0
5253
/* 486 and the likes */
5354
{ 4, -1, -1, -1, -1, 1, -1, -1, NC, 0 , 0, "Unknown AMD 486" },
5455
{ 4, 3, -1, -1, -1, 1, -1, -1, NC, 0 , 0, "AMD 486DX2" },
@@ -394,6 +395,7 @@ const struct match_entry_t cpudb_amd[] = {
394395
{ 15, -1, -1, 26, 36, -1, -1, -1, NC, RYZEN_|_AI_|_9 , 0, "Ryzen AI 9 (Strix Point)" },
395396
{ 15, -1, -1, 26, 36, -1, -1, -1, NC, RYZEN_|_AI_|_7 , 0, "Ryzen AI 7 (Strix Point)" },
396397
/* F M S EF EM #cores L2$ L3$ BC ModelBits ModelCode Name */
398+
#endif
397399
};
398400

399401

@@ -678,12 +680,13 @@ static void decode_amd_codename(struct cpu_id_t* data, struct internal_id_info_t
678680

679681
internal->code.amd = code_and_bits.code;
680682
internal->bits = code_and_bits.bits;
681-
internal->score = match_cpu_codename(cpudb_amd, COUNT_OF(cpudb_amd), data, code_and_bits.code,
682-
code_and_bits.bits, model_code);
683+
/*internal->score = match_cpu_codename(cpudb_amd, COUNT_OF(cpudb_amd), data, code_and_bits.code,
684+
code_and_bits.bits, model_code);*/
683685
}
684686

685687
int cpuid_identify_amd(struct cpu_raw_data_t* raw, struct cpu_id_t* data, struct internal_id_info_t* internal)
686688
{
689+
#if 0
687690
load_amd_features(raw, data);
688691
if ((EXTRACTS_BIT(raw->ext_cpuid[1][ECX], 22) == 1) && (EXTRACTS_BITS(raw->amd_fn8000001dh[0][EAX], 4, 0) != 0)) /* TopologyExtensions supported */
689692
decode_deterministic_cache_info_x86(raw->amd_fn8000001dh, MAX_AMDFN8000001DH_LEVEL, data, internal);
@@ -693,6 +696,7 @@ int cpuid_identify_amd(struct cpu_raw_data_t* raw, struct cpu_id_t* data, struct
693696
decode_amd_codename(data, internal);
694697
decode_architecture_version_x86(data);
695698
data->purpose = cpuid_identify_purpose_amd(raw);
699+
#endif
696700
return 0;
697701
}
698702

libcpuid/recog_centaur.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ enum _centaur_model_t {
5757
typedef enum _centaur_model_t centaur_model_t;
5858

5959
const struct match_entry_t cpudb_centaur[] = {
60-
// F M S EF EM #cores L2$ L3$ BC ModelBits ModelCode Name
61-
{ -1, -1, -1, -1, -1, -1, -1, -1, NC, 0, 0, "Unknown Centaur CPU" },
62-
// F M S EF EM #cores L2$ L3$ BC ModelBits ModelCode Name
60+
// F M S EF EM #cores L2$ L3$ Pattern Name
61+
{ -1, -1, -1, -1, -1, -1, -1, -1, { "", 0 }, "Unknown Centaur CPU" },
62+
// F M S EF EM #cores L2$ L3$ Pattern Name
6363

6464

6565
/* VIA */
66-
// F M S EF EM #cores L2$ L3$ BC ModelBits ModelCode Name
67-
{ 6, -1, -1, -1, -1, -1, -1, -1, VIA, 0 , 0, "Unknown VIA CPU" },
66+
// F M S EF EM #cores L2$ L3$ Pattern Name
67+
{ 6, -1, -1, -1, -1, -1, -1, -1, { "VIA", 2 }, "Unknown VIA CPU" },
68+
#if 0
6869
/* Samuel (2000, 180 nm) */
6970
{ 6, 6, -1, -1, -1, -1, -1, -1, VIA, SAMUEL_ , 0, "VIA Cyrix III (Samuel)" },
7071
/* Samuel 2 (2001, 150 nm) */
@@ -83,12 +84,13 @@ const struct match_entry_t cpudb_centaur[] = {
8384
{ 6, 15, -1, -1, -1, 2, -1, -1, VIA, NANO_ , 0, "VIA Nano X2 (Isaiah)" },
8485
{ 6, 15, -1, -1, -1, -1, -1, -1, VIA, QUADCORE_ , 0, "VIA Nano X4 (Isaiah)" },
8586
{ 6, 15, -1, -1, -1, 4, -1, -1, VIA, EDEN_ , 0, "VIA Eden X4 (Isaiah)" },
86-
// F M S EF EM #cores L2$ L3$ BC ModelBits ModelCode Name
87+
// F M S EF EM #cores L2$ L3$ Pattern Name
8788

8889

8990
/* Zhaoxin */
90-
// F M S EF EM #cores L2$ L3$ BC ModelBits ModelCode Name
91-
{ 7, -1, -1, -1, -1, -1, -1, -1, ZHAOXIN, 0 , 0, "Unknown Zhaoxin CPU" },
91+
// F M S EF EM #cores L2$ L3$ Pattern Name
92+
{ 7, -1, -1, -1, -1, -1, -1, -1, "ZHAOXIN", "Unknown Zhaoxin CPU" },
93+
9294
/* Zhangjiang (2015, 28 nm) */
9395
{ 7, -1, -1, -1, 15, -1, -1, -1, ZHAOXIN, KAISHENG_|_KH_|__C, 0, "Zhaoxin KaisHeng (ZhangJiang)" }, // C+ (4000)
9496
{ 7, -1, -1, -1, 15, -1, -1, -1, ZHAOXIN, KAIXIAN_|_ZX_|__C , 0, "Zhaoxin KaiXian (ZhangJiang)" }, // C/C+ (4000)
@@ -101,7 +103,8 @@ const struct match_entry_t cpudb_centaur[] = {
101103
/* Yongfeng (2022, 16 nm) */
102104
{ 7, -1, -1, -1, 91, -1, -1, -1, ZHAOXIN, KAISHENG_|_KH_ , _40000, "Zhaoxin KaisHeng (Yongfeng)" }, // KH (40000)
103105
{ 7, -1, -1, -1, 91, -1, -1, -1, ZHAOXIN, KAIXIAN_|_KX_ , _7000, "Zhaoxin KaiXian (Yongfeng)" }, // KX (7000)
104-
// F M S EF EM #cores L2$ L3$ BC ModelBits ModelCode Name
106+
#endif
107+
// F M S EF EM #cores L2$ L3$ Pattern Name
105108
};
106109

107110
static centaur_code_and_bits_t get_brand_code_and_bits(struct cpu_id_t* data)
@@ -199,6 +202,7 @@ static centaur_model_t get_model_code(struct cpu_id_t* data, centaur_code_and_bi
199202

200203
int cpuid_identify_centaur(struct cpu_raw_data_t* raw, struct cpu_id_t* data, struct internal_id_info_t* internal)
201204
{
205+
#if 0
202206
centaur_code_and_bits_t brand;
203207
centaur_model_t model_code;
204208
int i;
@@ -229,9 +233,8 @@ int cpuid_identify_centaur(struct cpu_raw_data_t* raw, struct cpu_id_t* data, st
229233

230234
internal->code.centaur = brand.code;
231235
internal->bits = brand.bits;
232-
internal->score = match_cpu_codename(cpudb_centaur, COUNT_OF(cpudb_centaur), data,
233-
brand.code, brand.bits, model_code);
234-
236+
internal->score = match_cpu_codename(cpudb_centaur, COUNT_OF(cpudb_centaur), data, model_code);
237+
#endif
235238
return 0;
236239
}
237240

0 commit comments

Comments
 (0)