1 /**************************************************************************
2 Copyright (c) 2013, The OpenBLAS Project
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
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
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 *****************************************************************************/
33 #define CPU_CORTEXA9 3
34 #define CPU_CORTEXA15 4
36 static char *cpuname[] = {
45 static char *cpuname_lower[] = {
54 int get_feature(char *search)
59 char buffer[2048], *p,*t;
62 infile = fopen("/proc/cpuinfo", "r");
64 while (fgets(buffer, sizeof(buffer), infile))
67 if (!strncmp("Features", buffer, 8))
69 p = strchr(buffer, ':') + 2;
77 if( p == NULL ) return 0;
80 while( t = strtok(NULL," "))
82 if (!strcmp(t, search)) { return(1); }
99 infile = fopen("/proc/cpuinfo", "r");
100 while (fgets(buffer, sizeof(buffer), infile))
103 if (!strncmp("CPU part", buffer, 8))
105 p = strchr(buffer, ':') + 2;
112 if (strstr(p, "0xc09")) {
115 if (strstr(p, "0xc0f")) {
116 return CPU_CORTEXA15;
118 if (strstr(p, "0xd07")) {
119 return CPU_ARMV7; //ARMV8 on 32-bit
125 infile = fopen("/proc/cpuinfo", "r");
127 while (fgets(buffer, sizeof(buffer), infile))
130 if ((!strncmp("model name", buffer, 10)) || (!strncmp("Processor", buffer, 9)))
132 p = strchr(buffer, ':') + 2;
142 if (strstr(p, "ARMv7"))
144 if ( get_feature("vfpv4"))
147 if ( get_feature("vfpv3"))
150 if ( get_feature("vfp"))
156 if (strstr(p, "ARMv6"))
158 if ( get_feature("vfp"))
166 infile = fopen("/proc/cpuinfo", "r");
168 while (fgets(buffer, sizeof(buffer), infile))
171 if ((!strncmp("CPU architecture", buffer, 16)))
173 p = strchr(buffer, ':') + 2;
179 if (strstr(p, "8")) {
180 return CPU_ARMV7; //ARMV8 on 32-bit
190 char *get_corename(void)
192 return cpuname[detect()];
195 void get_architecture(void)
200 void get_subarchitecture(void)
203 printf("%s", cpuname[d]);
206 void get_subdirname(void)
211 void get_cpuconfig(void)
218 printf("#define CORTEXA9\n");
219 printf("#define ARMV7\n");
220 printf("#define HAVE_VFP\n");
221 printf("#define HAVE_VFPV3\n");
222 if ( get_feature("neon")) printf("#define HAVE_NEON\n");
223 if ( get_feature("vfpv4")) printf("#define HAVE_VFPV4\n");
224 printf("#define L1_DATA_SIZE 32768\n");
225 printf("#define L1_DATA_LINESIZE 32\n");
226 printf("#define L2_SIZE 1048576\n");
227 printf("#define L2_LINESIZE 32\n");
228 printf("#define DTB_DEFAULT_ENTRIES 128\n");
229 printf("#define DTB_SIZE 4096\n");
230 printf("#define L2_ASSOCIATIVE 4\n");
234 printf("#define CORTEXA15\n");
235 printf("#define ARMV7\n");
236 printf("#define HAVE_VFP\n");
237 printf("#define HAVE_VFPV3\n");
238 if ( get_feature("neon")) printf("#define HAVE_NEON\n");
239 if ( get_feature("vfpv4")) printf("#define HAVE_VFPV4\n");
240 printf("#define L1_DATA_SIZE 32768\n");
241 printf("#define L1_DATA_LINESIZE 32\n");
242 printf("#define L2_SIZE 1048576\n");
243 printf("#define L2_LINESIZE 32\n");
244 printf("#define DTB_DEFAULT_ENTRIES 128\n");
245 printf("#define DTB_SIZE 4096\n");
246 printf("#define L2_ASSOCIATIVE 4\n");
251 printf("#define ARMV7\n");
252 printf("#define HAVE_VFP\n");
253 printf("#define HAVE_VFPV3\n");
254 if ( get_feature("neon")) printf("#define HAVE_NEON\n");
255 if ( get_feature("vfpv4")) printf("#define HAVE_VFPV4\n");
256 printf("#define L1_DATA_SIZE 65536\n");
257 printf("#define L1_DATA_LINESIZE 32\n");
258 printf("#define L2_SIZE 512488\n");
259 printf("#define L2_LINESIZE 32\n");
260 printf("#define DTB_DEFAULT_ENTRIES 64\n");
261 printf("#define DTB_SIZE 4096\n");
262 printf("#define L2_ASSOCIATIVE 4\n");
266 printf("#define ARMV6\n");
267 printf("#define HAVE_VFP\n");
268 printf("#define L1_DATA_SIZE 65536\n");
269 printf("#define L1_DATA_LINESIZE 32\n");
270 printf("#define L2_SIZE 512488\n");
271 printf("#define L2_LINESIZE 32\n");
272 printf("#define DTB_DEFAULT_ENTRIES 64\n");
273 printf("#define DTB_SIZE 4096\n");
274 printf("#define L2_ASSOCIATIVE 4\n");
281 void get_libname(void)
285 printf("%s", cpuname_lower[d]);
289 void get_features(void)
294 char buffer[2048], *p,*t;
297 infile = fopen("/proc/cpuinfo", "r");
299 while (fgets(buffer, sizeof(buffer), infile))
302 if (!strncmp("Features", buffer, 8))
304 p = strchr(buffer, ':') + 2;
312 if( p == NULL ) return;
315 while( t = strtok(NULL," "))
317 if (!strcmp(t, "vfp")) { printf("HAVE_VFP=1\n"); continue; }
318 if (!strcmp(t, "vfpv3")) { printf("HAVE_VFPV3=1\n"); continue; }
319 if (!strcmp(t, "vfpv4")) { printf("HAVE_VFPV4=1\n"); continue; }
320 if (!strcmp(t, "neon")) { printf("HAVE_NEON=1\n"); continue; }