Fixed #456. Merged the optimizations for APM's
[platform/upstream/openblas.git] / cpuid_arm64.c
1 /**************************************************************************
2   Copyright (c) 2013, The OpenBLAS Project
3   All rights reserved.
4   Redistribution and use in source and binary forms, with or without
5   modification, are permitted provided that the following conditions are
6   met:
7   1. Redistributions of source code must retain the above copyright
8   notice, this list of conditions and the following disclaimer.
9   2. Redistributions in binary form must reproduce the above copyright
10   notice, this list of conditions and the following disclaimer in
11   the documentation and/or other materials provided with the
12   distribution.
13   3. Neither the name of the OpenBLAS project nor the names of
14   its contributors may be used to endorse or promote products
15   derived from this software without specific prior written permission.
16   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19   ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
20   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25   USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26   *****************************************************************************/
27
28 #include <string.h>
29
30 #define CPU_UNKNOWN             0
31 #define CPU_ARMV8               1
32
33 static char *cpuname[] = {
34   "UNKOWN",
35   "ARMV8"
36 };
37
38
39 int get_feature(char *search)
40 {
41
42 #ifdef linux
43         FILE *infile;
44         char buffer[2048], *p,*t;
45         p = (char *) NULL ;
46
47         infile = fopen("/proc/cpuinfo", "r");
48
49         while (fgets(buffer, sizeof(buffer), infile))
50         {
51
52                 if (!strncmp("Features", buffer, 8))
53                 {
54                         p = strchr(buffer, ':') + 2;
55                         break;
56                 }
57         }
58
59         fclose(infile);
60
61
62         if( p == NULL ) return;
63
64         t = strtok(p," ");
65         while( t = strtok(NULL," "))
66         {
67                 if (!strcmp(t, search))   { return(1); }
68         }
69
70 #endif
71         return(0);
72 }
73
74
75 int detect(void)
76 {
77
78 #ifdef linux
79
80         FILE *infile;
81         char buffer[512], *p;
82         p = (char *) NULL ;
83
84         infile = fopen("/proc/cpuinfo", "r");
85
86         while (fgets(buffer, sizeof(buffer), infile))
87         {
88
89                 if ((!strncmp("model name", buffer, 10)) || (!strncmp("Processor", buffer, 9)))
90                 {
91                         p = strchr(buffer, ':') + 2;
92                         break;
93                 }
94         }
95
96         fclose(infile);
97
98         if(p != NULL)
99         {
100
101                 if (strstr(p, "AArch64"))
102                 {
103                                 return CPU_ARMV8;
104
105                 }
106
107
108         }
109 #endif
110
111         return CPU_UNKNOWN;
112 }
113
114 char *get_corename(void)
115 {
116         return cpuname[detect()];
117 }
118
119 void get_architecture(void)
120 {
121         printf("ARM");
122 }
123
124 void get_subarchitecture(void)
125 {
126         int d = detect();
127         switch (d)
128         {
129
130                 case CPU_ARMV8:
131                         printf("ARMV8");
132                         break;
133
134                 default:
135                         printf("UNKNOWN");
136                         break;
137         }
138 }
139
140 void get_subdirname(void)
141 {
142         printf("arm64");
143 }
144
145 void get_cpuconfig(void)
146 {
147
148         int d = detect();
149         switch (d)
150         {
151
152                 case CPU_ARMV8:
153                         printf("#define ARMV8\n");
154                         printf("#define L1_DATA_SIZE 32768\n");
155                         printf("#define L1_DATA_LINESIZE 64\n");
156                         printf("#define L2_SIZE 262144\n");
157                         printf("#define L2_LINESIZE 64\n");
158                         printf("#define DTB_DEFAULT_ENTRIES 64\n");
159                         printf("#define DTB_SIZE 4096\n");
160                         printf("#define L2_ASSOCIATIVE 4\n");
161                         break;
162
163
164         }
165 }
166
167
168 void get_libname(void)
169 {
170
171         int d = detect();
172         switch (d)
173         {
174
175                 case CPU_ARMV8:
176                         printf("armv8\n");
177                         break;
178
179         }
180 }
181
182
183 void get_features(void)
184 {
185
186 #ifdef linux
187         FILE *infile;
188         char buffer[2048], *p,*t;
189         p = (char *) NULL ;
190
191         infile = fopen("/proc/cpuinfo", "r");
192
193         while (fgets(buffer, sizeof(buffer), infile))
194         {
195
196                 if (!strncmp("Features", buffer, 8))
197                 {
198                         p = strchr(buffer, ':') + 2;
199                         break;
200                 }
201         }
202
203         fclose(infile);
204
205
206         if( p == NULL ) return;
207
208         t = strtok(p," ");
209         while( t = strtok(NULL," "))
210         {
211         }
212
213 #endif
214         return;
215 }
216
217