Skip to content

Commit 1e3ada6

Browse files
authored
Merge pull request #1960 from cnjsdfcy/Hygon
Add support for Hygon Dhyana
2 parents dbc9a06 + 29dc728 commit 1e3ada6

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

cpuid.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#define VENDOR_SIS 8
5454
#define VENDOR_TRANSMETA 9
5555
#define VENDOR_NSC 10
56+
#define VENDOR_HYGON 11
5657
#define VENDOR_UNKNOWN 99
5758

5859
#define BITMASK(a, b, c) ((((a) >> (b)) & (c)))
@@ -116,6 +117,7 @@
116117
#define CORE_EXCAVATOR 26
117118
#define CORE_ZEN 27
118119
#define CORE_SKYLAKEX 28
120+
#define CORE_DHYANA 29
119121

120122
#define HAVE_SSE (1 << 0)
121123
#define HAVE_SSE2 (1 << 1)
@@ -215,5 +217,8 @@ typedef struct {
215217
#define CPUTYPE_EXCAVATOR 50
216218
#define CPUTYPE_ZEN 51
217219
#define CPUTYPE_SKYLAKEX 52
220+
#define CPUTYPE_DHYANA 53
221+
222+
#define CPUTYPE_HYGON_UNKNOWN 54
218223

219224
#endif

cpuid_x86.c

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ int get_vendor(void){
271271
if (!strcmp(vendor, " SiS SiS SiS")) return VENDOR_SIS;
272272
if (!strcmp(vendor, "GenuineTMx86")) return VENDOR_TRANSMETA;
273273
if (!strcmp(vendor, "Geode by NSC")) return VENDOR_NSC;
274+
if (!strcmp(vendor, "HygonGenuine")) return VENDOR_HYGON;
274275

275276
if ((eax == 0) || ((eax & 0x500) != 0)) return VENDOR_INTEL;
276277

@@ -1046,7 +1047,9 @@ int get_cacheinfo(int type, cache_info_t *cacheinfo){
10461047
}
10471048
}
10481049

1049-
if ((get_vendor() == VENDOR_AMD) || (get_vendor() == VENDOR_CENTAUR)) {
1050+
if ((get_vendor() == VENDOR_AMD) ||
1051+
(get_vendor() == VENDOR_HYGON) ||
1052+
(get_vendor() == VENDOR_CENTAUR)) {
10501053
cpuid(0x80000005, &eax, &ebx, &ecx, &edx);
10511054

10521055
LDTB.size = 4096;
@@ -1483,6 +1486,26 @@ int get_cpuname(void){
14831486
return CPUTYPE_AMD_UNKNOWN;
14841487
}
14851488

1489+
if (vendor == VENDOR_HYGON){
1490+
switch (family) {
1491+
case 0xf:
1492+
switch (exfamily) {
1493+
case 9:
1494+
//Hygon Dhyana
1495+
if(support_avx())
1496+
#ifndef NO_AVX2
1497+
return CPUTYPE_ZEN;
1498+
#else
1499+
return CPUTYPE_SANDYBRIDGE; // closer in architecture to Sandy Bridge than to Excavator
1500+
#endif
1501+
else
1502+
return CPUTYPE_BARCELONA;
1503+
}
1504+
break;
1505+
}
1506+
return CPUTYPE_HYGON_UNKNOWN;
1507+
}
1508+
14861509
if (vendor == VENDOR_CYRIX){
14871510
switch (family) {
14881511
case 0x4:
@@ -1604,7 +1627,8 @@ static char *cpuname[] = {
16041627
"STEAMROLLER",
16051628
"EXCAVATOR",
16061629
"ZEN",
1607-
"SKYLAKEX"
1630+
"SKYLAKEX",
1631+
"DHYANA"
16081632
};
16091633

16101634
static char *lowercpuname[] = {
@@ -1659,7 +1683,8 @@ static char *lowercpuname[] = {
16591683
"steamroller",
16601684
"excavator",
16611685
"zen",
1662-
"skylakex"
1686+
"skylakex",
1687+
"dhyana"
16631688
};
16641689

16651690
static char *corename[] = {
@@ -1691,7 +1716,8 @@ static char *corename[] = {
16911716
"STEAMROLLER",
16921717
"EXCAVATOR",
16931718
"ZEN",
1694-
"SKYLAKEX"
1719+
"SKYLAKEX",
1720+
"DHYANA"
16951721
};
16961722

16971723
static char *corename_lower[] = {
@@ -1723,7 +1749,8 @@ static char *corename_lower[] = {
17231749
"steamroller",
17241750
"excavator",
17251751
"zen",
1726-
"skylakex"
1752+
"skylakex",
1753+
"dhyana"
17271754
};
17281755

17291756

@@ -2040,6 +2067,23 @@ int get_coretype(void){
20402067
}
20412068
}
20422069

2070+
if (vendor == VENDOR_HYGON){
2071+
if (family == 0xf){
2072+
if (exfamily == 9) {
2073+
if(support_avx())
2074+
#ifndef NO_AVX2
2075+
return CORE_ZEN;
2076+
#else
2077+
return CORE_SANDYBRIDGE; // closer in architecture to Sandy Bridge than to Excavator
2078+
#endif
2079+
else
2080+
return CORE_BARCELONA;
2081+
} else {
2082+
return CORE_BARCELONA;
2083+
}
2084+
}
2085+
}
2086+
20432087
if (vendor == VENDOR_CENTAUR) {
20442088
switch (family) {
20452089
case 0x6:

driver/others/dynamic.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ extern gotoblas_t gotoblas_SKYLAKEX;
274274
#define VENDOR_INTEL 1
275275
#define VENDOR_AMD 2
276276
#define VENDOR_CENTAUR 3
277+
#define VENDOR_HYGON 4
277278
#define VENDOR_UNKNOWN 99
278279

279280
#define BITMASK(a, b, c) ((((a) >> (b)) & (c)))
@@ -369,6 +370,7 @@ static int get_vendor(void){
369370
if (!strcmp(vendor.vchar, "GenuineIntel")) return VENDOR_INTEL;
370371
if (!strcmp(vendor.vchar, "AuthenticAMD")) return VENDOR_AMD;
371372
if (!strcmp(vendor.vchar, "CentaurHauls")) return VENDOR_CENTAUR;
373+
if (!strcmp(vendor.vchar, "HygonGenuine")) return VENDOR_HYGON;
372374

373375
if ((eax == 0) || ((eax & 0x500) != 0)) return VENDOR_INTEL;
374376

@@ -604,7 +606,7 @@ static gotoblas_t *get_coretype(void){
604606
}
605607
}
606608

607-
if (vendor == VENDOR_AMD){
609+
if (vendor == VENDOR_AMD || vendor == VENDOR_HYGON){
608610
if (family <= 0xe) {
609611
// Verify that CPU has 3dnow and 3dnowext before claiming it is Athlon
610612
cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
@@ -684,6 +686,13 @@ static gotoblas_t *get_coretype(void){
684686
return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
685687
}
686688
}
689+
} else if (exfamily == 9) {
690+
if(support_avx())
691+
return &gotoblas_ZEN;
692+
else{
693+
openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
694+
return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
695+
}
687696
}else {
688697
return &gotoblas_BARCELONA;
689698
}

0 commit comments

Comments
 (0)