Add POWER7/POWER8 as targets
[platform/upstream/openblas.git] / getarch.c
1 /*****************************************************************************
2 Copyright (c) 2011-2014, The OpenBLAS Project
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9    1. Redistributions of source code must retain the above copyright
10       notice, this list of conditions and the following disclaimer.
11
12    2. Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions and the following disclaimer in
14       the documentation and/or other materials provided with the
15       distribution.
16    3. Neither the name of the OpenBLAS project nor the names of 
17       its contributors may be used to endorse or promote products 
18       derived from this software without specific prior written 
19       permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 **********************************************************************************/
33
34 /*********************************************************************/
35 /* Copyright 2009, 2010 The University of Texas at Austin.           */
36 /* All rights reserved.                                              */
37 /*                                                                   */
38 /* Redistribution and use in source and binary forms, with or        */
39 /* without modification, are permitted provided that the following   */
40 /* conditions are met:                                               */
41 /*                                                                   */
42 /*   1. Redistributions of source code must retain the above         */
43 /*      copyright notice, this list of conditions and the following  */
44 /*      disclaimer.                                                  */
45 /*                                                                   */
46 /*   2. Redistributions in binary form must reproduce the above      */
47 /*      copyright notice, this list of conditions and the following  */
48 /*      disclaimer in the documentation and/or other materials       */
49 /*      provided with the distribution.                              */
50 /*                                                                   */
51 /*    THIS  SOFTWARE IS PROVIDED  BY THE  UNIVERSITY OF  TEXAS AT    */
52 /*    AUSTIN  ``AS IS''  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,    */
53 /*    INCLUDING, BUT  NOT LIMITED  TO, THE IMPLIED  WARRANTIES OF    */
54 /*    MERCHANTABILITY  AND FITNESS FOR  A PARTICULAR  PURPOSE ARE    */
55 /*    DISCLAIMED.  IN  NO EVENT SHALL THE UNIVERSITY  OF TEXAS AT    */
56 /*    AUSTIN OR CONTRIBUTORS BE  LIABLE FOR ANY DIRECT, INDIRECT,    */
57 /*    INCIDENTAL,  SPECIAL, EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES    */
58 /*    (INCLUDING, BUT  NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE    */
59 /*    GOODS  OR  SERVICES; LOSS  OF  USE,  DATA,  OR PROFITS;  OR    */
60 /*    BUSINESS INTERRUPTION) HOWEVER CAUSED  AND ON ANY THEORY OF    */
61 /*    LIABILITY, WHETHER  IN CONTRACT, STRICT  LIABILITY, OR TORT    */
62 /*    (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT    */
63 /*    OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF ADVISED  OF  THE    */
64 /*    POSSIBILITY OF SUCH DAMAGE.                                    */
65 /*                                                                   */
66 /* The views and conclusions contained in the software and           */
67 /* documentation are those of the authors and should not be          */
68 /* interpreted as representing official policies, either expressed   */
69 /* or implied, of The University of Texas at Austin.                 */
70 /*********************************************************************/
71
72 #if defined(__WIN32__) || defined(__WIN64__) || defined(__CYGWIN32__) || defined(__CYGWIN64__)
73 #define OS_WINDOWS
74 #endif
75
76 #include <stdio.h>
77 #include <string.h>
78 #ifdef OS_WINDOWS
79 #include <windows.h>
80 #endif
81 #if defined(__FreeBSD__) || defined(__APPLE__)
82 #include <sys/types.h>
83 #include <sys/sysctl.h>
84 #endif
85 #ifdef linux
86 #include <sys/sysinfo.h>
87 #include <unistd.h>
88 #endif
89
90 /* #define FORCE_P2             */
91 /* #define FORCE_KATMAI         */
92 /* #define FORCE_COPPERMINE     */
93 /* #define FORCE_NORTHWOOD      */
94 /* #define FORCE_PRESCOTT       */
95 /* #define FORCE_BANIAS         */
96 /* #define FORCE_YONAH          */
97 /* #define FORCE_CORE2          */
98 /* #define FORCE_PENRYN         */
99 /* #define FORCE_DUNNINGTON     */
100 /* #define FORCE_NEHALEM        */
101 /* #define FORCE_SANDYBRIDGE    */
102 /* #define FORCE_ATOM           */
103 /* #define FORCE_ATHLON         */
104 /* #define FORCE_OPTERON        */
105 /* #define FORCE_OPTERON_SSE3   */
106 /* #define FORCE_BARCELONA      */
107 /* #define FORCE_SHANGHAI       */
108 /* #define FORCE_ISTANBUL       */
109 /* #define FORCE_BOBCAT         */
110 /* #define FORCE_BULLDOZER      */
111 /* #define FORCE_PILEDRIVER     */
112 /* #define FORCE_SSE_GENERIC    */
113 /* #define FORCE_VIAC3          */
114 /* #define FORCE_NANO           */
115 /* #define FORCE_POWER3         */
116 /* #define FORCE_POWER4         */
117 /* #define FORCE_POWER5         */
118 /* #define FORCE_POWER6         */
119 /* #define FORCE_POWER7         */
120 /* #define FORCE_POWER8         */
121 /* #define FORCE_PPCG4          */
122 /* #define FORCE_PPC970         */
123 /* #define FORCE_PPC970MP       */
124 /* #define FORCE_PPC440         */
125 /* #define FORCE_PPC440FP2      */
126 /* #define FORCE_CELL           */
127 /* #define FORCE_SICORTEX       */
128 /* #define FORCE_LOONGSON3A     */
129 /* #define FORCE_LOONGSON3B     */
130 /* #define FORCE_ITANIUM2       */
131 /* #define FORCE_SPARC          */
132 /* #define FORCE_SPARCV7        */
133 /* #define FORCE_GENERIC        */
134
135 #ifdef FORCE_P2
136 #define FORCE
137 #define FORCE_INTEL
138 #define ARCHITECTURE    "X86"
139 #define SUBARCHITECTURE "PENTIUM2"
140 #define ARCHCONFIG   "-DPENTIUM2 " \
141                      "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=32 " \
142                      "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
143                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
144                      "-DHAVE_CMOV -DHAVE_MMX"
145 #define LIBNAME   "p2"
146 #define CORENAME  "P5"
147 #endif
148
149 #ifdef FORCE_KATMAI
150 #define FORCE
151 #define FORCE_INTEL
152 #define ARCHITECTURE    "X86"
153 #define SUBARCHITECTURE "PENTIUM3"
154 #define ARCHCONFIG   "-DPENTIUM3 " \
155                      "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=32 " \
156                      "-DL2_SIZE=524288 -DL2_LINESIZE=32 " \
157                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
158                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE "
159 #define LIBNAME   "katmai"
160 #define CORENAME  "KATMAI"
161 #endif
162
163 #ifdef FORCE_COPPERMINE
164 #define FORCE
165 #define FORCE_INTEL
166 #define ARCHITECTURE    "X86"
167 #define SUBARCHITECTURE "PENTIUM3"
168 #define ARCHCONFIG   "-DPENTIUM3 " \
169                      "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=32 " \
170                      "-DL2_SIZE=262144 -DL2_LINESIZE=32 " \
171                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
172                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE "
173 #define LIBNAME   "coppermine"
174 #define CORENAME  "COPPERMINE"
175 #endif
176
177 #ifdef FORCE_NORTHWOOD
178 #define FORCE
179 #define FORCE_INTEL
180 #define ARCHITECTURE    "X86"
181 #define SUBARCHITECTURE "PENTIUM4"
182 #define ARCHCONFIG   "-DPENTIUM4 " \
183                      "-DL1_DATA_SIZE=8192 -DL1_DATA_LINESIZE=64 " \
184                      "-DL2_SIZE=524288 -DL2_LINESIZE=64 " \
185                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 " \
186                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 "
187 #define LIBNAME   "northwood"
188 #define CORENAME  "NORTHWOOD"
189 #endif
190
191 #ifdef FORCE_PRESCOTT
192 #define FORCE
193 #define FORCE_INTEL
194 #define ARCHITECTURE    "X86"
195 #define SUBARCHITECTURE "PENTIUM4"
196 #define ARCHCONFIG   "-DPENTIUM4 " \
197                      "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=64 " \
198                      "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
199                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 " \
200                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3"
201 #define LIBNAME   "prescott"
202 #define CORENAME  "PRESCOTT"
203 #endif
204
205 #ifdef FORCE_BANIAS
206 #define FORCE
207 #define FORCE_INTEL
208 #define ARCHITECTURE    "X86"
209 #define SUBARCHITECTURE "BANIAS"
210 #define ARCHCONFIG   "-DPENTIUMM " \
211                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
212                      "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
213                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
214                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 "
215 #define LIBNAME   "banias"
216 #define CORENAME  "BANIAS"
217 #endif
218
219 #ifdef FORCE_YONAH
220 #define FORCE
221 #define FORCE_INTEL
222 #define ARCHITECTURE    "X86"
223 #define SUBARCHITECTURE "YONAH"
224 #define ARCHCONFIG   "-DPENTIUMM " \
225                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
226                      "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
227                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
228                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 "
229 #define LIBNAME   "yonah"
230 #define CORENAME  "YONAH"
231 #endif
232
233 #ifdef FORCE_CORE2
234 #define FORCE
235 #define FORCE_INTEL
236 #define ARCHITECTURE    "X86"
237 #define SUBARCHITECTURE "CONRORE"
238 #define ARCHCONFIG   "-DCORE2 " \
239                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
240                      "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
241                      "-DDTB_DEFAULT_ENTRIES=256 -DDTB_SIZE=4096 " \
242                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3"
243 #define LIBNAME   "core2"
244 #define CORENAME  "CORE2"
245 #endif
246
247 #ifdef FORCE_PENRYN
248 #define FORCE
249 #define FORCE_INTEL
250 #define ARCHITECTURE    "X86"
251 #define SUBARCHITECTURE "PENRYN"
252 #define ARCHCONFIG   "-DPENRYN " \
253                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
254                      "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
255                      "-DDTB_DEFAULT_ENTRIES=256 -DDTB_SIZE=4096 " \
256                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 -DHAVE_SSE4_1"
257 #define LIBNAME   "penryn"
258 #define CORENAME  "PENRYN"
259 #endif
260
261 #ifdef FORCE_DUNNINGTON
262 #define FORCE
263 #define FORCE_INTEL
264 #define ARCHITECTURE    "X86"
265 #define SUBARCHITECTURE "DUNNINGTON"
266 #define ARCHCONFIG   "-DDUNNINGTON " \
267                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
268                      "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
269                      "-DL3_SIZE=16777216 -DL3_LINESIZE=64 " \
270                      "-DDTB_DEFAULT_ENTRIES=256 -DDTB_SIZE=4096 " \
271                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 -DHAVE_SSE4_1"
272 #define LIBNAME   "dunnington"
273 #define CORENAME  "DUNNINGTON"
274 #endif
275
276 #ifdef FORCE_NEHALEM
277 #define FORCE
278 #define FORCE_INTEL
279 #define ARCHITECTURE    "X86"
280 #define SUBARCHITECTURE "NEHALEM"
281 #define ARCHCONFIG   "-DNEHALEM " \
282                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
283                      "-DL2_SIZE=262144 -DL2_LINESIZE=64 " \
284                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
285                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 -DHAVE_SSE4_1 -DHAVE_SSE4_2"
286 #define LIBNAME   "nehalem"
287 #define CORENAME  "NEHALEM"
288 #endif
289
290 #ifdef FORCE_SANDYBRIDGE
291 #define FORCE
292 #define FORCE_INTEL
293 #define ARCHITECTURE    "X86"
294 #define SUBARCHITECTURE "SANDYBRIDGE"
295 #define ARCHCONFIG   "-DSANDYBRIDGE " \
296                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
297                      "-DL2_SIZE=262144 -DL2_LINESIZE=64 " \
298                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
299                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 -DHAVE_SSE4_1 -DHAVE_SSE4_2 -DHAVE_AVX"
300 #define LIBNAME   "sandybridge"
301 #define CORENAME  "SANDYBRIDGE"
302 #endif
303
304 #ifdef FORCE_HASWELL
305 #define FORCE
306 #define FORCE_INTEL
307 #define ARCHITECTURE    "X86"
308 #define SUBARCHITECTURE "HASWELL"
309 #define ARCHCONFIG   "-DHASWELL " \
310                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
311                      "-DL2_SIZE=262144 -DL2_LINESIZE=64 " \
312                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
313                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 -DHAVE_SSE4_1 -DHAVE_SSE4_2 -DHAVE_AVX " \
314                      "-DFMA3"
315 #define LIBNAME   "haswell"
316 #define CORENAME  "HASWELL"
317 #endif
318
319 #ifdef FORCE_ATOM
320 #define FORCE
321 #define FORCE_INTEL
322 #define ARCHITECTURE    "X86"
323 #define SUBARCHITECTURE "ATOM"
324 #define ARCHCONFIG   "-DATOM " \
325                      "-DL1_DATA_SIZE=24576 -DL1_DATA_LINESIZE=64 " \
326                      "-DL2_SIZE=524288 -DL2_LINESIZE=64 " \
327                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 " \
328                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3"
329 #define LIBNAME   "atom"
330 #define CORENAME  "ATOM"
331 #endif
332
333 #ifdef FORCE_ATHLON
334 #define FORCE
335 #define FORCE_INTEL
336 #define ARCHITECTURE    "X86"
337 #define SUBARCHITECTURE "ATHLON"
338 #define ARCHCONFIG   "-DATHLON " \
339                      "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
340                      "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
341                      "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 -DHAVE_3DNOW  " \
342                      "-DHAVE_3DNOWEX -DHAVE_MMX -DHAVE_SSE "
343 #define LIBNAME   "athlon"
344 #define CORENAME  "ATHLON"
345 #endif
346
347 #ifdef FORCE_OPTERON
348 #define FORCE
349 #define FORCE_INTEL
350 #define ARCHITECTURE    "X86"
351 #define SUBARCHITECTURE "OPTERON"
352 #define ARCHCONFIG   "-DOPTERON " \
353                      "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
354                      "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
355                      "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 -DHAVE_3DNOW " \
356                      "-DHAVE_3DNOWEX -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 "
357 #define LIBNAME   "opteron"
358 #define CORENAME  "OPTERON"
359 #endif
360
361 #ifdef FORCE_OPTERON_SSE3
362 #define FORCE
363 #define FORCE_INTEL
364 #define ARCHITECTURE    "X86"
365 #define SUBARCHITECTURE "OPTERON"
366 #define ARCHCONFIG   "-DOPTERON " \
367                      "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
368                      "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
369                      "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 -DHAVE_3DNOW " \
370                      "-DHAVE_3DNOWEX -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3"
371 #define LIBNAME   "opteron"
372 #define CORENAME  "OPTERON"
373 #endif
374
375 #if defined(FORCE_BARCELONA) || defined(FORCE_SHANGHAI) || defined(FORCE_ISTANBUL)
376 #define FORCE
377 #define FORCE_INTEL
378 #define ARCHITECTURE    "X86"
379 #define SUBARCHITECTURE "BARCELONA"
380 #define ARCHCONFIG   "-DBARCELONA " \
381                      "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
382                      "-DL2_SIZE=524288 -DL2_LINESIZE=64  -DL3_SIZE=2097152 " \
383                      "-DDTB_DEFAULT_ENTRIES=48 -DDTB_SIZE=4096 " \
384                      "-DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 " \
385                      "-DHAVE_SSE4A -DHAVE_MISALIGNSSE -DHAVE_128BITFPU -DHAVE_FASTMOVU"
386 #define LIBNAME   "barcelona"
387 #define CORENAME  "BARCELONA"
388 #endif
389
390 #if defined(FORCE_BOBCAT)
391 #define FORCE
392 #define FORCE_INTEL
393 #define ARCHITECTURE    "X86"
394 #define SUBARCHITECTURE "BOBCAT"
395 #define ARCHCONFIG   "-DBOBCAT " \
396                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
397                      "-DL2_SIZE=524288 -DL2_LINESIZE=64 " \
398                      "-DDTB_DEFAULT_ENTRIES=40 -DDTB_SIZE=4096 " \
399                      "-DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 " \
400                      "-DHAVE_SSE4A -DHAVE_MISALIGNSSE -DHAVE_CFLUSH -DHAVE_CMOV"
401 #define LIBNAME   "bobcat"
402 #define CORENAME  "BOBCAT"
403 #endif
404
405 #if defined (FORCE_BULLDOZER)
406 #define FORCE
407 #define FORCE_INTEL
408 #define ARCHITECTURE    "X86"
409 #define SUBARCHITECTURE "BULLDOZER"
410 #define ARCHCONFIG   "-DBULLDOZER " \
411                      "-DL1_DATA_SIZE=49152 -DL1_DATA_LINESIZE=64 " \
412                      "-DL2_SIZE=1024000 -DL2_LINESIZE=64  -DL3_SIZE=16777216 " \
413                      "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 " \
414                      "-DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 " \
415                      "-DHAVE_SSE4A -DHAVE_MISALIGNSSE -DHAVE_128BITFPU -DHAVE_FASTMOVU " \
416                      "-DHAVE_AVX -DHAVE_FMA4"
417 #define LIBNAME   "bulldozer"
418 #define CORENAME  "BULLDOZER"
419 #endif
420
421 #if defined (FORCE_PILEDRIVER)
422 #define FORCE
423 #define FORCE_INTEL
424 #define ARCHITECTURE    "X86"
425 #define SUBARCHITECTURE "PILEDRIVER"
426 #define ARCHCONFIG   "-DPILEDRIVER " \
427                      "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=64 " \
428                      "-DL2_SIZE=2097152 -DL2_LINESIZE=64  -DL3_SIZE=12582912 " \
429                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
430                      "-DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSE4_1 -DHAVE_SSE4_2 " \
431                      "-DHAVE_SSE4A -DHAVE_MISALIGNSSE -DHAVE_128BITFPU -DHAVE_FASTMOVU -DHAVE_CFLUSH " \
432                      "-DHAVE_AVX -DHAVE_FMA4 -DHAVE_FMA3"
433 #define LIBNAME   "piledriver"
434 #define CORENAME  "PILEDRIVER"
435 #endif
436
437 #if defined (FORCE_STEAMROLLER)
438 #define FORCE
439 #define FORCE_INTEL
440 #define ARCHITECTURE    "X86"
441 #define SUBARCHITECTURE "STEAMROLLER"
442 #define ARCHCONFIG   "-DSTEAMROLLER " \
443                      "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=64 " \
444                      "-DL2_SIZE=2097152 -DL2_LINESIZE=64  -DL3_SIZE=12582912 " \
445                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
446                      "-DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSE4_1 -DHAVE_SSE4_2 " \
447                      "-DHAVE_SSE4A -DHAVE_MISALIGNSSE -DHAVE_128BITFPU -DHAVE_FASTMOVU -DHAVE_CFLUSH " \
448                      "-DHAVE_AVX -DHAVE_FMA4 -DHAVE_FMA3"
449 #define LIBNAME   "steamroller"
450 #define CORENAME  "STEAMROLLER"
451 #endif
452
453 #if defined (FORCE_EXCAVATOR)
454 #define FORCE
455 #define FORCE_INTEL
456 #define ARCHITECTURE    "X86"
457 #define SUBARCHITECTURE "EXCAVATOR"
458 #define ARCHCONFIG   "-DEXCAVATOR " \
459                      "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=64 " \
460                      "-DL2_SIZE=2097152 -DL2_LINESIZE=64  -DL3_SIZE=12582912 " \
461                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
462                      "-DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSE4_1 -DHAVE_SSE4_2 " \
463                      "-DHAVE_SSE4A -DHAVE_MISALIGNSSE -DHAVE_128BITFPU -DHAVE_FASTMOVU -DHAVE_CFLUSH " \
464                      "-DHAVE_AVX -DHAVE_FMA4 -DHAVE_FMA3"
465 #define LIBNAME   "excavator"
466 #define CORENAME  "EXCAVATOR"
467 #endif
468
469
470 #ifdef FORCE_SSE_GENERIC
471 #define FORCE
472 #define FORCE_INTEL
473 #define ARCHITECTURE    "X86"
474 #define SUBARCHITECTURE "GENERIC"
475 #define ARCHCONFIG   "-DGENERIC " \
476                      "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=64 " \
477                      "-DL2_SIZE=524288 -DL2_LINESIZE=64 " \
478                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 " \
479                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2"
480 #define LIBNAME   "generic"
481 #define CORENAME  "GENERIC"
482 #endif
483
484 #ifdef FORCE_VIAC3
485 #define FORCE
486 #define FORCE_INTEL
487 #define ARCHITECTURE    "X86"
488 #define SUBARCHITECTURE "VIAC3"
489 #define ARCHCONFIG   "-DVIAC3 " \
490                      "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
491                      "-DL2_SIZE=65536 -DL2_LINESIZE=32 " \
492                      "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 " \
493                      "-DHAVE_MMX -DHAVE_SSE "
494 #define LIBNAME   "viac3"
495 #define CORENAME  "VIAC3"
496 #endif
497
498 #ifdef FORCE_NANO
499 #define FORCE
500 #define FORCE_INTEL
501 #define ARCHITECTURE    "X86"
502 #define SUBARCHITECTURE "NANO"
503 #define ARCHCONFIG   "-DNANO " \
504                      "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
505                      "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
506                      "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 " \
507                      "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3"
508 #define LIBNAME   "nano"
509 #define CORENAME  "NANO"
510 #endif
511
512 #ifdef FORCE_POWER3
513 #define FORCE
514 #define ARCHITECTURE    "POWER"
515 #define SUBARCHITECTURE "POWER3"
516 #define SUBDIRNAME      "power"
517 #define ARCHCONFIG   "-DPOWER3 " \
518                      "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=128 " \
519                      "-DL2_SIZE=2097152 -DL2_LINESIZE=128 " \
520                      "-DDTB_DEFAULT_ENTRIES=256 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
521 #define LIBNAME   "power3"
522 #define CORENAME  "POWER3"
523 #endif
524
525 #ifdef FORCE_POWER4
526 #define FORCE
527 #define ARCHITECTURE    "POWER"
528 #define SUBARCHITECTURE "POWER4"
529 #define SUBDIRNAME      "power"
530 #define ARCHCONFIG   "-DPOWER4 " \
531                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
532                      "-DL2_SIZE=1509949 -DL2_LINESIZE=128 " \
533                      "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=6 "
534 #define LIBNAME   "power4"
535 #define CORENAME  "POWER4"
536 #endif
537
538 #ifdef FORCE_POWER5
539 #define FORCE
540 #define ARCHITECTURE    "POWER"
541 #define SUBARCHITECTURE "POWER5"
542 #define SUBDIRNAME      "power"
543 #define ARCHCONFIG   "-DPOWER5 " \
544                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
545                      "-DL2_SIZE=1509949 -DL2_LINESIZE=128 " \
546                      "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=6 "
547 #define LIBNAME   "power5"
548 #define CORENAME  "POWER5"
549 #endif
550
551 #if defined(FORCE_POWER6) || defined(FORCE_POWER7) || defined(FORCE_POWER8)
552 #define FORCE
553 #define ARCHITECTURE    "POWER"
554 #define SUBARCHITECTURE "POWER6"
555 #define SUBDIRNAME      "power"
556 #define ARCHCONFIG   "-DPOWER6 " \
557                      "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=128 " \
558                      "-DL2_SIZE=4194304 -DL2_LINESIZE=128 " \
559                      "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
560 #define LIBNAME   "power6"
561 #define CORENAME  "POWER6"
562 #endif
563
564 #ifdef FORCE_PPCG4
565 #define FORCE
566 #define ARCHITECTURE    "POWER"
567 #define SUBARCHITECTURE "PPCG4"
568 #define SUBDIRNAME      "power"
569 #define ARCHCONFIG   "-DPPCG4 " \
570                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
571                      "-DL2_SIZE=262144 -DL2_LINESIZE=32 " \
572                      "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
573 #define LIBNAME   "ppcg4"
574 #define CORENAME  "PPCG4"
575 #endif
576
577 #ifdef FORCE_PPC970
578 #define FORCE
579 #define ARCHITECTURE    "POWER"
580 #define SUBARCHITECTURE "PPC970"
581 #define SUBDIRNAME      "power"
582 #define ARCHCONFIG   "-DPPC970 " \
583                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
584                      "-DL2_SIZE=512488 -DL2_LINESIZE=128 " \
585                      "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
586 #define LIBNAME   "ppc970"
587 #define CORENAME  "PPC970"
588 #endif
589
590 #ifdef FORCE_PPC970MP
591 #define FORCE
592 #define ARCHITECTURE    "POWER"
593 #define SUBARCHITECTURE "PPC970"
594 #define SUBDIRNAME      "power"
595 #define ARCHCONFIG   "-DPPC970 " \
596                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
597                      "-DL2_SIZE=1024976 -DL2_LINESIZE=128 " \
598                      "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
599 #define LIBNAME   "ppc970mp"
600 #define CORENAME  "PPC970"
601 #endif
602
603 #ifdef FORCE_PPC440
604 #define FORCE
605 #define ARCHITECTURE    "POWER"
606 #define SUBARCHITECTURE "PPC440"
607 #define SUBDIRNAME      "power"
608 #define ARCHCONFIG   "-DPPC440 " \
609                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
610                      "-DL2_SIZE=16384 -DL2_LINESIZE=128 " \
611                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=16 "
612 #define LIBNAME   "ppc440"
613 #define CORENAME  "PPC440"
614 #endif
615
616 #ifdef FORCE_PPC440FP2
617 #define FORCE
618 #define ARCHITECTURE    "POWER"
619 #define SUBARCHITECTURE "PPC440FP2"
620 #define SUBDIRNAME      "power"
621 #define ARCHCONFIG   "-DPPC440FP2 " \
622                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
623                      "-DL2_SIZE=16384 -DL2_LINESIZE=128 " \
624                      "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=16 "
625 #define LIBNAME   "ppc440FP2"
626 #define CORENAME  "PPC440FP2"
627 #endif
628
629 #ifdef FORCE_CELL
630 #define FORCE
631 #define ARCHITECTURE    "POWER"
632 #define SUBARCHITECTURE "CELL"
633 #define SUBDIRNAME      "power"
634 #define ARCHCONFIG   "-DCELL " \
635                      "-DL1_DATA_SIZE=262144 -DL1_DATA_LINESIZE=128 " \
636                      "-DL2_SIZE=512488 -DL2_LINESIZE=128 " \
637                      "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
638 #define LIBNAME   "cell"
639 #define CORENAME  "CELL"
640 #endif
641
642 #ifdef FORCE_SICORTEX
643 #define FORCE
644 #define ARCHITECTURE    "MIPS"
645 #define SUBARCHITECTURE "SICORTEX"
646 #define SUBDIRNAME      "mips"
647 #define ARCHCONFIG   "-DSICORTEX " \
648                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
649                      "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
650                      "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
651 #define LIBNAME   "mips"
652 #define CORENAME  "sicortex"
653 #endif
654
655
656 #ifdef FORCE_LOONGSON3A
657 #define FORCE
658 #define ARCHITECTURE    "MIPS"
659 #define SUBARCHITECTURE "LOONGSON3A"
660 #define SUBDIRNAME      "mips64"
661 #define ARCHCONFIG   "-DLOONGSON3A " \
662        "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
663        "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
664        "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 "
665 #define LIBNAME   "loongson3a"
666 #define CORENAME  "LOONGSON3A"
667 #else
668 #endif
669
670 #ifdef FORCE_LOONGSON3B
671 #define FORCE
672 #define ARCHITECTURE    "MIPS"
673 #define SUBARCHITECTURE "LOONGSON3B"
674 #define SUBDIRNAME      "mips64"
675 #define ARCHCONFIG   "-DLOONGSON3B " \
676        "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
677        "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
678        "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 "
679 #define LIBNAME   "loongson3b"
680 #define CORENAME  "LOONGSON3B"
681 #else
682 #endif
683
684 #ifdef FORCE_ITANIUM2
685 #define FORCE
686 #define ARCHITECTURE    "IA64"
687 #define SUBARCHITECTURE "ITANIUM2"
688 #define SUBDIRNAME      "ia64"
689 #define ARCHCONFIG   "-DITANIUM2 " \
690                      "-DL1_DATA_SIZE=262144 -DL1_DATA_LINESIZE=128 " \
691                      "-DL2_SIZE=1572864 -DL2_LINESIZE=128 -DDTB_SIZE=16384 -DDTB_DEFAULT_ENTRIES=128 "
692 #define LIBNAME   "itanium2"
693 #define CORENAME  "itanium2"
694 #endif
695
696 #ifdef FORCE_SPARC
697 #define FORCE
698 #define ARCHITECTURE    "SPARC"
699 #define SUBARCHITECTURE "SPARC"
700 #define SUBDIRNAME      "sparc"
701 #define ARCHCONFIG   "-DSPARC -DV9 " \
702                      "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
703                      "-DL2_SIZE=1572864 -DL2_LINESIZE=64 -DDTB_SIZE=8192 -DDTB_DEFAULT_ENTRIES=64 "
704 #define LIBNAME   "sparc"
705 #define CORENAME  "sparc"
706 #endif
707
708 #ifdef FORCE_SPARCV7
709 #define FORCE
710 #define ARCHITECTURE    "SPARC"
711 #define SUBARCHITECTURE "SPARC"
712 #define SUBDIRNAME      "sparc"
713 #define ARCHCONFIG   "-DSPARC -DV7 " \
714                      "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
715                      "-DL2_SIZE=1572864 -DL2_LINESIZE=64 -DDTB_SIZE=8192 -DDTB_DEFAULT_ENTRIES=64 "
716 #define LIBNAME   "sparcv7"
717 #define CORENAME  "sparcv7"
718 #endif
719
720 #ifdef FORCE_GENERIC
721 #define FORCE
722 #define ARCHITECTURE    "GENERIC"
723 #define SUBARCHITECTURE "GENERIC"
724 #define SUBDIRNAME      "generic"
725 #define ARCHCONFIG   "-DGENERIC " \
726                      "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
727                      "-DL2_SIZE=512488 -DL2_LINESIZE=128 " \
728                      "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
729 #define LIBNAME   "generic"
730 #define CORENAME  "generic"
731 #endif
732
733 #ifdef FORCE_ARMV7
734 #define FORCE
735 #define ARCHITECTURE    "ARM"
736 #define SUBARCHITECTURE "ARMV7"
737 #define SUBDIRNAME      "arm"
738 #define ARCHCONFIG   "-DARMV7 " \
739        "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
740        "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
741        "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 " \
742        "-DHAVE_VFPV3 -DHAVE_VFP"
743 #define LIBNAME   "armv7"
744 #define CORENAME  "ARMV7"
745 #else
746 #endif
747
748 #ifdef FORCE_CORTEXA9
749 #define FORCE
750 #define ARCHITECTURE    "ARM"
751 #define SUBARCHITECTURE "CORTEXA9"
752 #define SUBDIRNAME      "arm"
753 #define ARCHCONFIG   "-DCORTEXA9 " \
754        "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
755        "-DL2_SIZE=1048576 -DL2_LINESIZE=32 " \
756        "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 " \
757        "-DHAVE_VFPV3 -DHAVE_VFP -DHAVE_NEON"
758 #define LIBNAME   "cortexa9"
759 #define CORENAME  "CORTEXA9"
760 #else
761 #endif
762
763 #ifdef FORCE_CORTEXA15
764 #define FORCE
765 #define ARCHITECTURE    "ARM"
766 #define SUBARCHITECTURE "CORTEXA15"
767 #define SUBDIRNAME      "arm"
768 #define ARCHCONFIG   "-DCORTEXA15 " \
769        "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
770        "-DL2_SIZE=1048576 -DL2_LINESIZE=32 " \
771        "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 " \
772        "-DHAVE_VFPV3 -DHAVE_VFP -DHAVE_NEON"
773 #define LIBNAME   "cortexa15"
774 #define CORENAME  "CORTEXA15"
775 #else
776 #endif
777
778 #ifdef FORCE_ARMV6
779 #define FORCE
780 #define ARCHITECTURE    "ARM"
781 #define SUBARCHITECTURE "ARMV6"
782 #define SUBDIRNAME      "arm"
783 #define ARCHCONFIG   "-DARMV6 " \
784        "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
785        "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
786        "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 " \
787        "-DHAVE_VFP"
788 #define LIBNAME   "armv6"
789 #define CORENAME  "ARMV6"
790 #else
791 #endif
792
793 #ifdef FORCE_ARMV5
794 #define FORCE
795 #define ARCHITECTURE    "ARM"
796 #define SUBARCHITECTURE "ARMV5"
797 #define SUBDIRNAME      "arm"
798 #define ARCHCONFIG   "-DARMV5 " \
799        "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
800        "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
801        "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 " \
802        "-DHAVE_VFP"
803 #define LIBNAME   "armv5"
804 #define CORENAME  "ARMV5"
805 #else
806 #endif
807
808
809 #ifdef FORCE_ARMV8
810 #define FORCE
811 #define ARCHITECTURE    "ARM64"
812 #define SUBARCHITECTURE "ARMV8"
813 #define SUBDIRNAME      "arm64"
814 #define ARCHCONFIG   "-DARMV8 " \
815        "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
816        "-DL2_SIZE=262144 -DL2_LINESIZE=64 " \
817        "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=32 " 
818 #define LIBNAME   "armv8"
819 #define CORENAME  "XGENE1"
820 #else
821 #endif
822
823
824 #ifndef FORCE
825
826 #if defined(__powerpc__) || defined(__powerpc) || defined(powerpc) || \
827     defined(__PPC__) || defined(PPC) || defined(_POWER) || defined(__POWERPC__)
828 #ifndef POWER
829 #define POWER
830 #endif
831 #define OPENBLAS_SUPPORTED
832 #endif
833
834 #if defined(__i386__) || (__x86_64__)
835 #include "cpuid_x86.c"
836 #define OPENBLAS_SUPPORTED
837 #endif
838
839 #ifdef __ia64__
840 #include "cpuid_ia64.c"
841 #define OPENBLAS_SUPPORTED
842 #endif
843
844 #ifdef __alpha
845 #include "cpuid_alpha.c"
846 #define OPENBLAS_SUPPORTED
847 #endif
848
849 #ifdef POWER
850 #include "cpuid_power.c"
851 #define OPENBLAS_SUPPORTED
852 #endif
853
854 #ifdef sparc
855 #include "cpuid_sparc.c"
856 #define OPENBLAS_SUPPORTED
857 #endif
858
859 #ifdef __mips__
860 #include "cpuid_mips.c"
861 #define OPENBLAS_SUPPORTED
862 #endif
863
864 #ifdef __arm__
865 #include "cpuid_arm.c"
866 #define OPENBLAS_SUPPORTED
867 #endif
868
869 #ifdef __aarch64__
870 #include "cpuid_arm64.c"
871 #define OPENBLAS_SUPPORTED
872 #endif
873
874
875 #ifndef OPENBLAS_SUPPORTED
876 #error "This arch/CPU is not supported by OpenBLAS."
877 #endif
878
879 #else
880
881 #endif
882
883 static int get_num_cores(void) {
884
885 #ifdef OS_WINDOWS
886   SYSTEM_INFO sysinfo;
887 #elif defined(__FreeBSD__) || defined(__APPLE__)
888   int m[2], count;
889   size_t len;
890 #endif
891
892 #ifdef linux
893   //returns the number of processors which are currently online
894   return sysconf(_SC_NPROCESSORS_ONLN);
895
896 #elif defined(OS_WINDOWS)
897
898   GetSystemInfo(&sysinfo);
899   return sysinfo.dwNumberOfProcessors;
900
901 #elif defined(__FreeBSD__) || defined(__APPLE__)
902   m[0] = CTL_HW;
903   m[1] = HW_NCPU;
904   len = sizeof(int);
905   sysctl(m, 2, &count, &len, NULL, 0);
906
907   return count;
908 #else
909   return 2;
910 #endif
911 }
912
913 int main(int argc, char *argv[]){
914
915 #ifdef FORCE
916   char buffer[8192], *p, *q;
917   int length;
918 #endif
919
920   if (argc == 1) return 0;
921
922   switch (argv[1][0]) {
923
924   case '0' : /* for Makefile */
925
926 #ifdef FORCE
927     printf("CORE=%s\n", CORENAME);
928 #else
929 #if defined(__i386__) || defined(__x86_64__) || defined(POWER) || defined(__mips__) || defined(__arm__) || defined(__aarch64__)
930     printf("CORE=%s\n", get_corename());
931 #endif
932 #endif
933
934 #ifdef FORCE
935     printf("LIBCORE=%s\n", LIBNAME);
936 #else
937     printf("LIBCORE=");
938     get_libname();
939     printf("\n");
940 #endif
941
942     printf("NUM_CORES=%d\n", get_num_cores());
943
944 #if defined(__arm__) && !defined(FORCE)
945         get_features();
946 #endif
947
948
949 #if defined(__i386__) || defined(__x86_64__)
950 #ifndef FORCE
951     get_sse();
952 #else
953
954     sprintf(buffer, "%s", ARCHCONFIG);
955
956     p = &buffer[0];
957
958     while (*p) {
959       if ((*p == '-') && (*(p + 1) == 'D')) {
960         p += 2;
961
962         while ((*p != ' ') && (*p != '\0')) {
963
964           if (*p == '=') {
965             printf("=");
966             p ++;
967             while ((*p != ' ') && (*p != '\0')) {
968               printf("%c", *p);
969               p ++;
970             }
971           } else {
972             printf("%c", *p);
973             p ++;
974             if ((*p == ' ') || (*p =='\0')) printf("=1");
975           }
976         }
977
978         printf("\n");
979       } else p ++;
980     }
981 #endif
982 #endif
983
984 #if NO_PARALLEL_MAKE==1
985     printf("MAKE += -j 1\n");
986 #else
987 #ifndef OS_WINDOWS
988     printf("MAKE += -j %d\n", get_num_cores());
989 #endif
990 #endif
991
992     break;
993
994   case '1' : /* For config.h */
995 #ifdef FORCE
996     sprintf(buffer, "%s -DCORE_%s\n", ARCHCONFIG, CORENAME);
997
998     p = &buffer[0];
999     while (*p) {
1000       if ((*p == '-') && (*(p + 1) == 'D')) {
1001         p += 2;
1002         printf("#define ");
1003
1004         while ((*p != ' ') && (*p != '\0')) {
1005
1006           if (*p == '=') {
1007             printf(" ");
1008             p ++;
1009             while ((*p != ' ') && (*p != '\0')) {
1010               printf("%c", *p);
1011               p ++;
1012             }
1013           } else {
1014             printf("%c", *p);
1015             p ++;
1016           }
1017         }
1018
1019         printf("\n");
1020       } else p ++;
1021     }
1022 #else
1023     get_cpuconfig();
1024 #endif
1025
1026 #ifdef FORCE
1027     printf("#define CHAR_CORENAME \"%s\"\n", CORENAME);
1028 #else
1029 #if defined(__i386__) || defined(__x86_64__) || defined(POWER) || defined(__mips__) || defined(__arm__) || defined(__aarch64__)
1030     printf("#define CHAR_CORENAME \"%s\"\n", get_corename());
1031 #endif
1032 #endif
1033
1034  break;
1035
1036   case '2' : /* SMP */
1037     if (get_num_cores() > 1) printf("SMP=1\n");
1038     break;
1039   }
1040
1041   fflush(stdout);
1042
1043   return 0;
1044 }
1045