Fix dynamic dispatch to work for clang.

This commit is contained in:
Chip-Kerchner 2023-10-06 12:20:40 -05:00
parent c60f9d9c08
commit 71c6689af4
1 changed files with 62 additions and 85 deletions

View File

@ -36,13 +36,6 @@ char *gotoblas_corename(void) {
return corename[0]; return corename[0];
} }
#if defined(__clang__) && !defined(_AIX)
static int __builtin_cpu_supports(char* arg)
{
return 0;
}
#endif
#define CPU_UNKNOWN 0 #define CPU_UNKNOWN 0
#define CPU_POWER5 5 #define CPU_POWER5 5
#define CPU_POWER6 6 #define CPU_POWER6 6
@ -51,7 +44,31 @@ static int __builtin_cpu_supports(char* arg)
#define CPU_POWER9 9 #define CPU_POWER9 9
#define CPU_POWER10 10 #define CPU_POWER10 10
#if defined(C_PGI) || (defined(__clang__) && !defined(_AIX)) #ifdef _AIX
#include <sys/systemcfg.h>
static int cpuid(void)
{
int arch = _system_configuration.implementation;
#ifdef POWER_6
if (arch == POWER_6) return CPU_POWER6;
#endif
#ifdef POWER_7
else if (arch == POWER_7) return CPU_POWER7;
#endif
#ifdef POWER_8
else if (arch == POWER_8) return CPU_POWER8;
#endif
#ifdef POWER_9
else if (arch == POWER_9) return CPU_POWER9;
#endif
#ifdef POWER_10
else if (arch == POWER_10) return CPU_POWER10;
#endif
return CPU_UNKNOWN;
}
#else
#if defined(C_PGI) || defined(__clang__)
/* /*
* NV HPC compilers do not yet implement __builtin_cpu_is(). * NV HPC compilers do not yet implement __builtin_cpu_is().
* Fake a version here for use in the CPU detection code below. * Fake a version here for use in the CPU detection code below.
@ -61,8 +78,6 @@ static int __builtin_cpu_supports(char* arg)
* what was requested. * what was requested.
*/ */
#include <string.h>
/* /*
* Define POWER processor version table. * Define POWER processor version table.
* *
@ -161,7 +176,8 @@ static struct {
}, },
}; };
static int __builtin_cpu_is(const char *cpu) { static int cpuid(void)
{
int i; int i;
uint32_t pvr; uint32_t pvr;
uint32_t cpu_type; uint32_t cpu_type;
@ -179,61 +195,13 @@ static int __builtin_cpu_is(const char *cpu) {
pvrPOWER[i].cpu_name, pvrPOWER[i].cpu_type); pvrPOWER[i].cpu_name, pvrPOWER[i].cpu_type);
#endif #endif
cpu_type = pvrPOWER[i].cpu_type; cpu_type = pvrPOWER[i].cpu_type;
return (int)(cpu_type);
if (!strcmp(cpu, "power8"))
return cpu_type == CPU_POWER8;
if (!strcmp(cpu, "power9"))
return cpu_type == CPU_POWER9;
return 0;
} }
#endif /* C_PGI */ #endif /* C_PGI */
#endif /* _AIX */
#ifdef _AIX
#include <sys/systemcfg.h>
static int cpuid(void)
{
int arch = _system_configuration.implementation;
#ifdef POWER_6
if (arch == POWER_6) return CPU_POWER6;
#endif
#ifdef POWER_7
else if (arch == POWER_7) return CPU_POWER7;
#endif
#ifdef POWER_8
else if (arch == POWER_8) return CPU_POWER8;
#endif
#ifdef POWER_9
else if (arch == POWER_9) return CPU_POWER9;
#endif
#ifdef POWER_10
else if (arch == POWER_10) return CPU_POWER10;
#endif
return CPU_UNKNOWN;
}
#ifndef __BUILTIN_CPU_SUPPORTS__ #ifndef __BUILTIN_CPU_SUPPORTS__
static int __builtin_cpu_supports(const char* arg) #include <string.h>
{
static int ipinfo = -1;
if (ipinfo < 0) {
ipinfo = cpuid();
}
if (ipinfo >= CPU_POWER10) {
if (!strcmp(arg, "power10")) return 1;
}
if (ipinfo >= CPU_POWER9) {
if (!strcmp(arg, "power9")) return 1;
}
if (ipinfo >= CPU_POWER8) {
if (!strcmp(arg, "power8")) return 1;
}
if (ipinfo >= CPU_POWER6) {
if (!strcmp(arg, "power6")) return 1;
}
return 0;
}
static int __builtin_cpu_is(const char *arg) static int __builtin_cpu_is(const char *arg)
{ {
@ -241,19 +209,28 @@ static int __builtin_cpu_is(const char *arg)
if (ipinfo < 0) { if (ipinfo < 0) {
ipinfo = cpuid(); ipinfo = cpuid();
} }
#ifdef HAVE_P10_SUPPORT
if (ipinfo == CPU_POWER10) { if (ipinfo == CPU_POWER10) {
if (!strcmp(arg, "power10")) return 1; if (!strcmp(arg, "power10")) return 1;
} else if (ipinfo == CPU_POWER9) { }
#endif
if (ipinfo == CPU_POWER9) {
if (!strcmp(arg, "power9")) return 1; if (!strcmp(arg, "power9")) return 1;
} else if (ipinfo == CPU_POWER8) { } else if (ipinfo == CPU_POWER8) {
if (!strcmp(arg, "power8")) return 1; if (!strcmp(arg, "power8")) return 1;
#ifndef C_PGI
} else if (ipinfo == CPU_POWER6) { } else if (ipinfo == CPU_POWER6) {
if (!strcmp(arg, "power6")) return 1; if (!strcmp(arg, "power6")) return 1;
#endif
} }
return 0; return 0;
} }
static int __builtin_cpu_supports(const char *arg)
{
return 0;
}
#endif #endif
#endif /* _AIX */
static gotoblas_t *get_coretype(void) { static gotoblas_t *get_coretype(void) {
@ -268,8 +245,8 @@ static gotoblas_t *get_coretype(void) {
return &gotoblas_POWER9; return &gotoblas_POWER9;
#endif #endif
#ifdef HAVE_P10_SUPPORT #ifdef HAVE_P10_SUPPORT
#ifdef _AIX #if defined(_AIX) || defined(__clang__)
if (__builtin_cpu_supports("power10")) if (__builtin_cpu_is("power10"))
#else #else
if (__builtin_cpu_supports ("arch_3_1") && __builtin_cpu_supports ("mma")) if (__builtin_cpu_supports ("arch_3_1") && __builtin_cpu_supports ("mma"))
#endif #endif