Merge pull request #1226 from ashwinyes/develop_arm_clang_ual_fix
[platform/upstream/openblas.git] / cpuid_arm64.c
index c7a27f8..9b318e7 100644 (file)
 
 #define CPU_UNKNOWN            0
 #define CPU_ARMV8              1
+#define CPU_CORTEXA57          2
+#define CPU_VULCAN             3
+#define CPU_THUNDERX           4
+#define CPU_THUNDERX2T99       5
 
 static char *cpuname[] = {
-  "UNKOWN",
-  "ARMV8"
+  "UNKNOWN",
+  "ARMV8" ,
+  "CORTEXA57",
+  "VULCAN",
+  "THUNDERX",
+  "THUNDERX2T99"
 };
 
+static char *cpuname_lower[] = {
+  "unknown",
+  "armv8" ,
+  "cortexa57",
+  "vulcan",
+  "thunderx",
+  "thunderx2t99"
+};
 
 int get_feature(char *search)
 {
@@ -53,13 +69,13 @@ int get_feature(char *search)
                {
                        p = strchr(buffer, ':') + 2;
                        break;
-               }
-       }
+               }
+       }
 
-       fclose(infile);
+       fclose(infile);
 
 
-       if( p == NULL ) return;
+       if( p == NULL ) return 0;
 
        t = strtok(p," ");
        while( t = strtok(NULL," "))
@@ -78,15 +94,43 @@ int detect(void)
 #ifdef linux
 
        FILE *infile;
-       char buffer[512], *p;
-       p = (char *) NULL ;
+       char buffer[512], *p, *cpu_part = NULL, *cpu_implementer = NULL;
+       p = (char *) NULL ;
 
-       infile = fopen("/proc/cpuinfo", "r");
+       infile = fopen("/proc/cpuinfo", "r");
+       while (fgets(buffer, sizeof(buffer), infile)) {
+               if ((cpu_part != NULL) && (cpu_implementer != NULL)) {
+                       break;
+               }
+
+               if ((cpu_part == NULL) && !strncmp("CPU part", buffer, 8)) {
+                       cpu_part = strchr(buffer, ':') + 2;
+                       cpu_part = strdup(cpu_part);
+               } else if ((cpu_implementer == NULL) && !strncmp("CPU implementer", buffer, 15)) {
+                       cpu_implementer = strchr(buffer, ':') + 2;
+                       cpu_implementer = strdup(cpu_implementer);
+               }
+       }
+
+       fclose(infile);
+       if(cpu_part != NULL && cpu_implementer != NULL) {
+               if (strstr(cpu_part, "0xd07") && strstr(cpu_implementer, "0x41"))
+                       return CPU_CORTEXA57;
+               else if (strstr(cpu_part, "0x516") && strstr(cpu_implementer, "0x42"))
+                       return CPU_VULCAN;
+               else if (strstr(cpu_part, "0x0a1") && strstr(cpu_implementer, "0x43"))
+                       return CPU_THUNDERX;
+               else if (strstr(cpu_part, "0xFFF") && strstr(cpu_implementer, "0x43")) /* TODO */
+                       return CPU_THUNDERX2T99;
+       }
 
+       p = (char *) NULL ;
+       infile = fopen("/proc/cpuinfo", "r");
        while (fgets(buffer, sizeof(buffer), infile))
        {
 
-               if ((!strncmp("model name", buffer, 10)) || (!strncmp("Processor", buffer, 9)))
+               if ((!strncmp("model name", buffer, 10)) || (!strncmp("Processor", buffer, 9)) ||
+                   (!strncmp("CPU architecture", buffer, 16)))
                {
                        p = strchr(buffer, ':') + 2;
                        break;
@@ -100,7 +144,7 @@ int detect(void)
 
                if (strstr(p, "AArch64"))
                {
-                               return CPU_ARMV8;
+                       return CPU_ARMV8;
 
                }
 
@@ -118,23 +162,13 @@ char *get_corename(void)
 
 void get_architecture(void)
 {
-       printf("ARM");
+       printf("ARM64");
 }
 
 void get_subarchitecture(void)
 {
        int d = detect();
-       switch (d)
-       {
-
-               case CPU_ARMV8:
-                       printf("ARMV8");
-                       break;
-
-               default:
-                       printf("UNKNOWN");
-                       break;
-       }
+       printf("%s", cpuname[d]);
 }
 
 void get_subdirname(void)
@@ -160,26 +194,90 @@ void get_cpuconfig(void)
                        printf("#define L2_ASSOCIATIVE 4\n");
                        break;
 
+               case CPU_VULCAN:
+                       printf("#define VULCAN                        \n");
+                       printf("#define HAVE_VFP                      \n");
+                       printf("#define HAVE_VFPV3                    \n");
+                       printf("#define HAVE_NEON                     \n");
+                       printf("#define HAVE_VFPV4                    \n");
+                       printf("#define L1_CODE_SIZE         32768    \n");
+                       printf("#define L1_CODE_LINESIZE     64       \n");
+                       printf("#define L1_CODE_ASSOCIATIVE  8        \n");
+                       printf("#define L1_DATA_SIZE         32768    \n");
+                       printf("#define L1_DATA_LINESIZE     64       \n");
+                       printf("#define L1_DATA_ASSOCIATIVE  8        \n");
+                       printf("#define L2_SIZE              262144   \n");
+                       printf("#define L2_LINESIZE          64       \n");
+                       printf("#define L2_ASSOCIATIVE       8        \n");
+                       printf("#define L3_SIZE              33554432 \n");
+                       printf("#define L3_LINESIZE          64       \n");
+                       printf("#define L3_ASSOCIATIVE       32       \n");
+                       printf("#define DTB_DEFAULT_ENTRIES  64       \n");
+                       printf("#define DTB_SIZE             4096     \n");
+                       break;
+
+               case CPU_CORTEXA57:
+                       printf("#define CORTEXA57\n");
+                       printf("#define HAVE_VFP\n");
+                       printf("#define HAVE_VFPV3\n");
+                       printf("#define HAVE_NEON\n");
+                       printf("#define HAVE_VFPV4\n");
+                       printf("#define L1_CODE_SIZE 49152\n");
+                       printf("#define L1_CODE_LINESIZE 64\n");
+                       printf("#define L1_CODE_ASSOCIATIVE 3\n");
+                       printf("#define L1_DATA_SIZE 32768\n");
+                       printf("#define L1_DATA_LINESIZE 64\n");
+                       printf("#define L1_DATA_ASSOCIATIVE 2\n");
+                       printf("#define L2_SIZE 2097152\n");
+                       printf("#define L2_LINESIZE 64\n");
+                       printf("#define L2_ASSOCIATIVE 16\n");
+                       printf("#define DTB_DEFAULT_ENTRIES 64\n");
+                       printf("#define DTB_SIZE 4096\n");
+                       break;
 
+               case CPU_THUNDERX:
+                       printf("#define ARMV8\n");
+                       printf("#define THUNDERX\n");
+                       printf("#define L1_DATA_SIZE 32768\n");
+                       printf("#define L1_DATA_LINESIZE 128\n");
+                       printf("#define L2_SIZE 16777216\n");
+                       printf("#define L2_LINESIZE 128\n");
+                       printf("#define DTB_DEFAULT_ENTRIES 64\n");
+                       printf("#define DTB_SIZE 4096\n");
+                       printf("#define L2_ASSOCIATIVE 16\n");
+                       break;
+
+               case CPU_THUNDERX2T99:
+                       printf("#define VULCAN                        \n");
+                       printf("#define HAVE_VFP                      \n");
+                       printf("#define HAVE_VFPV3                    \n");
+                       printf("#define HAVE_NEON                     \n");
+                       printf("#define HAVE_VFPV4                    \n");
+                       printf("#define L1_CODE_SIZE         32768    \n");
+                       printf("#define L1_CODE_LINESIZE     64       \n");
+                       printf("#define L1_CODE_ASSOCIATIVE  8        \n");
+                       printf("#define L1_DATA_SIZE         32768    \n");
+                       printf("#define L1_DATA_LINESIZE     64       \n");
+                       printf("#define L1_DATA_ASSOCIATIVE  8        \n");
+                       printf("#define L2_SIZE              262144   \n");
+                       printf("#define L2_LINESIZE          64       \n");
+                       printf("#define L2_ASSOCIATIVE       8        \n");
+                       printf("#define L3_SIZE              33554432 \n");
+                       printf("#define L3_LINESIZE          64       \n");
+                       printf("#define L3_ASSOCIATIVE       32       \n");
+                       printf("#define DTB_DEFAULT_ENTRIES  64       \n");
+                       printf("#define DTB_SIZE             4096     \n");
+                       break;
        }
 }
 
 
 void get_libname(void)
 {
-
        int d = detect();
-       switch (d)
-       {
-
-               case CPU_ARMV8:
-                       printf("armv8\n");
-                       break;
-
-       }
+       printf("%s", cpuname_lower[d]);
 }
 
-
 void get_features(void)
 {