You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

getarch.c 26 kB

14 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. /*****************************************************************************
  2. Copyright (c) 2011,2012 Lab of Parallel Software and Computational Science,ISCAS
  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 ISCAS nor the names of its contributors may
  14. be used to endorse or promote products derived from this software
  15. 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 COPYRIGHT OWNER 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. /* Copyright 2009, 2010 The University of Texas at Austin. */
  29. /* All rights reserved. */
  30. /* */
  31. /* Redistribution and use in source and binary forms, with or */
  32. /* without modification, are permitted provided that the following */
  33. /* conditions are met: */
  34. /* */
  35. /* 1. Redistributions of source code must retain the above */
  36. /* copyright notice, this list of conditions and the following */
  37. /* disclaimer. */
  38. /* */
  39. /* 2. Redistributions in binary form must reproduce the above */
  40. /* copyright notice, this list of conditions and the following */
  41. /* disclaimer in the documentation and/or other materials */
  42. /* provided with the distribution. */
  43. /* */
  44. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  45. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  46. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  47. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  48. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  49. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  50. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  51. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  52. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  53. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  54. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  55. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  56. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  57. /* POSSIBILITY OF SUCH DAMAGE. */
  58. /* */
  59. /* The views and conclusions contained in the software and */
  60. /* documentation are those of the authors and should not be */
  61. /* interpreted as representing official policies, either expressed */
  62. /* or implied, of The University of Texas at Austin. */
  63. /*********************************************************************/
  64. #if defined(__WIN32__) || defined(__WIN64__) || defined(__CYGWIN32__) || defined(__CYGWIN64__)
  65. #define OS_WINDOWS
  66. #endif
  67. #include <stdio.h>
  68. #include <string.h>
  69. #ifdef OS_WINDOWS
  70. #include <windows.h>
  71. #endif
  72. #if defined(__FreeBSD__) || defined(__APPLE__)
  73. #include <sys/types.h>
  74. #include <sys/sysctl.h>
  75. #endif
  76. #ifdef linux
  77. #include <sys/sysinfo.h>
  78. #endif
  79. /* #define FORCE_P2 */
  80. /* #define FORCE_KATMAI */
  81. /* #define FORCE_COPPERMINE */
  82. /* #define FORCE_NORTHWOOD */
  83. /* #define FORCE_PRESCOTT */
  84. /* #define FORCE_BANIAS */
  85. /* #define FORCE_YONAH */
  86. /* #define FORCE_CORE2 */
  87. /* #define FORCE_PENRYN */
  88. /* #define FORCE_DUNNINGTON */
  89. /* #define FORCE_NEHALEM */
  90. /* #define FORCE_SANDYBRIDGE */
  91. /* #define FORCE_ATOM */
  92. /* #define FORCE_ATHLON */
  93. /* #define FORCE_OPTERON */
  94. /* #define FORCE_OPTERON_SSE3 */
  95. /* #define FORCE_BARCELONA */
  96. /* #define FORCE_SHANGHAI */
  97. /* #define FORCE_ISTANBUL */
  98. /* #define FORCE_BOBCAT */
  99. /* #define FORCE_BULLDOZER */
  100. /* #define FORCE_SSE_GENERIC */
  101. /* #define FORCE_VIAC3 */
  102. /* #define FORCE_NANO */
  103. /* #define FORCE_POWER3 */
  104. /* #define FORCE_POWER4 */
  105. /* #define FORCE_POWER5 */
  106. /* #define FORCE_POWER6 */
  107. /* #define FORCE_PPCG4 */
  108. /* #define FORCE_PPC970 */
  109. /* #define FORCE_PPC970MP */
  110. /* #define FORCE_PPC440 */
  111. /* #define FORCE_PPC440FP2 */
  112. /* #define FORCE_CELL */
  113. /* #define FORCE_SICORTEX */
  114. /* #define FORCE_LOONGSON3A */
  115. /* #define FORCE_LOONGSON3B */
  116. /* #define FORCE_ITANIUM2 */
  117. /* #define FORCE_SPARC */
  118. /* #define FORCE_SPARCV7 */
  119. /* #define FORCE_GENERIC */
  120. #ifdef FORCE_P2
  121. #define FORCE
  122. #define FORCE_INTEL
  123. #define ARCHITECTURE "X86"
  124. #define SUBARCHITECTURE "PENTIUM2"
  125. #define ARCHCONFIG "-DPENTIUM2 " \
  126. "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=32 " \
  127. "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
  128. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
  129. "-DHAVE_CMOV -DHAVE_MMX"
  130. #define LIBNAME "p2"
  131. #define CORENAME "P5"
  132. #endif
  133. #ifdef FORCE_KATMAI
  134. #define FORCE
  135. #define FORCE_INTEL
  136. #define ARCHITECTURE "X86"
  137. #define SUBARCHITECTURE "PENTIUM3"
  138. #define ARCHCONFIG "-DPENTIUM3 " \
  139. "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=32 " \
  140. "-DL2_SIZE=524288 -DL2_LINESIZE=32 " \
  141. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
  142. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE "
  143. #define LIBNAME "katmai"
  144. #define CORENAME "KATMAI"
  145. #endif
  146. #ifdef FORCE_COPPERMINE
  147. #define FORCE
  148. #define FORCE_INTEL
  149. #define ARCHITECTURE "X86"
  150. #define SUBARCHITECTURE "PENTIUM3"
  151. #define ARCHCONFIG "-DPENTIUM3 " \
  152. "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=32 " \
  153. "-DL2_SIZE=262144 -DL2_LINESIZE=32 " \
  154. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
  155. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE "
  156. #define LIBNAME "coppermine"
  157. #define CORENAME "COPPERMINE"
  158. #endif
  159. #ifdef FORCE_NORTHWOOD
  160. #define FORCE
  161. #define FORCE_INTEL
  162. #define ARCHITECTURE "X86"
  163. #define SUBARCHITECTURE "PENTIUM4"
  164. #define ARCHCONFIG "-DPENTIUM4 " \
  165. "-DL1_DATA_SIZE=8192 -DL1_DATA_LINESIZE=64 " \
  166. "-DL2_SIZE=524288 -DL2_LINESIZE=64 " \
  167. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 " \
  168. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 "
  169. #define LIBNAME "northwood"
  170. #define CORENAME "NORTHWOOD"
  171. #endif
  172. #ifdef FORCE_PRESCOTT
  173. #define FORCE
  174. #define FORCE_INTEL
  175. #define ARCHITECTURE "X86"
  176. #define SUBARCHITECTURE "PENTIUM4"
  177. #define ARCHCONFIG "-DPENTIUM4 " \
  178. "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=64 " \
  179. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  180. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 " \
  181. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3"
  182. #define LIBNAME "prescott"
  183. #define CORENAME "PRESCOTT"
  184. #endif
  185. #ifdef FORCE_BANIAS
  186. #define FORCE
  187. #define FORCE_INTEL
  188. #define ARCHITECTURE "X86"
  189. #define SUBARCHITECTURE "BANIAS"
  190. #define ARCHCONFIG "-DPENTIUMM " \
  191. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  192. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  193. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
  194. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 "
  195. #define LIBNAME "banias"
  196. #define CORENAME "BANIAS"
  197. #endif
  198. #ifdef FORCE_YONAH
  199. #define FORCE
  200. #define FORCE_INTEL
  201. #define ARCHITECTURE "X86"
  202. #define SUBARCHITECTURE "YONAH"
  203. #define ARCHCONFIG "-DPENTIUMM " \
  204. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  205. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  206. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
  207. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 "
  208. #define LIBNAME "yonah"
  209. #define CORENAME "YONAH"
  210. #endif
  211. #ifdef FORCE_CORE2
  212. #define FORCE
  213. #define FORCE_INTEL
  214. #define ARCHITECTURE "X86"
  215. #define SUBARCHITECTURE "CONRORE"
  216. #define ARCHCONFIG "-DCORE2 " \
  217. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  218. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  219. "-DDTB_DEFAULT_ENTRIES=256 -DDTB_SIZE=4096 " \
  220. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3"
  221. #define LIBNAME "core2"
  222. #define CORENAME "CORE2"
  223. #endif
  224. #ifdef FORCE_PENRYN
  225. #define FORCE
  226. #define FORCE_INTEL
  227. #define ARCHITECTURE "X86"
  228. #define SUBARCHITECTURE "PENRYN"
  229. #define ARCHCONFIG "-DPENRYN " \
  230. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  231. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  232. "-DDTB_DEFAULT_ENTRIES=256 -DDTB_SIZE=4096 " \
  233. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 -DHAVE_SSE4_1"
  234. #define LIBNAME "penryn"
  235. #define CORENAME "PENRYN"
  236. #endif
  237. #ifdef FORCE_DUNNINGTON
  238. #define FORCE
  239. #define FORCE_INTEL
  240. #define ARCHITECTURE "X86"
  241. #define SUBARCHITECTURE "DUNNINGTON"
  242. #define ARCHCONFIG "-DDUNNINGTON " \
  243. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  244. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  245. "-DL3_SIZE=16777216 -DL3_LINESIZE=64 " \
  246. "-DDTB_DEFAULT_ENTRIES=256 -DDTB_SIZE=4096 " \
  247. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 -DHAVE_SSE4_1"
  248. #define LIBNAME "dunnington"
  249. #define CORENAME "DUNNINGTON"
  250. #endif
  251. #ifdef FORCE_NEHALEM
  252. #define FORCE
  253. #define FORCE_INTEL
  254. #define ARCHITECTURE "X86"
  255. #define SUBARCHITECTURE "NEHALEM"
  256. #define ARCHCONFIG "-DNEHALEM " \
  257. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  258. "-DL2_SIZE=262144 -DL2_LINESIZE=64 " \
  259. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
  260. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 -DHAVE_SSE4_1 -DHAVE_SSE4_2"
  261. #define LIBNAME "nehalem"
  262. #define CORENAME "NEHALEM"
  263. #endif
  264. #ifdef FORCE_SANDYBRIDGE
  265. #define FORCE
  266. #define FORCE_INTEL
  267. #define ARCHITECTURE "X86"
  268. #define SUBARCHITECTURE "SANDYBRIDGE"
  269. #define ARCHCONFIG "-DSANDYBRIDGE " \
  270. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  271. "-DL2_SIZE=262144 -DL2_LINESIZE=64 " \
  272. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
  273. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 -DHAVE_SSE4_1 -DHAVE_SSE4_2 -DHAVE_AVX"
  274. #define LIBNAME "sandybridge"
  275. #define CORENAME "SANDYBRIDGE"
  276. #endif
  277. #ifdef FORCE_ATOM
  278. #define FORCE
  279. #define FORCE_INTEL
  280. #define ARCHITECTURE "X86"
  281. #define SUBARCHITECTURE "ATOM"
  282. #define ARCHCONFIG "-DATOM " \
  283. "-DL1_DATA_SIZE=24576 -DL1_DATA_LINESIZE=64 " \
  284. "-DL2_SIZE=524288 -DL2_LINESIZE=64 " \
  285. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 " \
  286. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3"
  287. #define LIBNAME "atom"
  288. #define CORENAME "ATOM"
  289. #endif
  290. #ifdef FORCE_ATHLON
  291. #define FORCE
  292. #define FORCE_INTEL
  293. #define ARCHITECTURE "X86"
  294. #define SUBARCHITECTURE "ATHLON"
  295. #define ARCHCONFIG "-DATHLON " \
  296. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  297. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  298. "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 -DHAVE_3DNOW " \
  299. "-DHAVE_3DNOWEX -DHAVE_MMX -DHAVE_SSE "
  300. #define LIBNAME "athlon"
  301. #define CORENAME "ATHLON"
  302. #endif
  303. #ifdef FORCE_OPTERON
  304. #define FORCE
  305. #define FORCE_INTEL
  306. #define ARCHITECTURE "X86"
  307. #define SUBARCHITECTURE "OPTERON"
  308. #define ARCHCONFIG "-DOPTERON " \
  309. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  310. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  311. "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 -DHAVE_3DNOW " \
  312. "-DHAVE_3DNOWEX -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 "
  313. #define LIBNAME "opteron"
  314. #define CORENAME "OPTERON"
  315. #endif
  316. #ifdef FORCE_OPTERON_SSE3
  317. #define FORCE
  318. #define FORCE_INTEL
  319. #define ARCHITECTURE "X86"
  320. #define SUBARCHITECTURE "OPTERON"
  321. #define ARCHCONFIG "-DOPTERON " \
  322. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  323. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  324. "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 -DHAVE_3DNOW " \
  325. "-DHAVE_3DNOWEX -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3"
  326. #define LIBNAME "opteron"
  327. #define CORENAME "OPTERON"
  328. #endif
  329. #if defined(FORCE_BARCELONA) || defined(FORCE_SHANGHAI) || defined(FORCE_ISTANBUL)
  330. #define FORCE
  331. #define FORCE_INTEL
  332. #define ARCHITECTURE "X86"
  333. #define SUBARCHITECTURE "BARCELONA"
  334. #define ARCHCONFIG "-DBARCELONA " \
  335. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  336. "-DL2_SIZE=524288 -DL2_LINESIZE=64 -DL3_SIZE=2097152 " \
  337. "-DDTB_DEFAULT_ENTRIES=48 -DDTB_SIZE=4096 " \
  338. "-DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 " \
  339. "-DHAVE_SSE4A -DHAVE_MISALIGNSSE -DHAVE_128BITFPU -DHAVE_FASTMOVU"
  340. #define LIBNAME "barcelona"
  341. #define CORENAME "BARCELONA"
  342. #endif
  343. #if defined(FORCE_BOBCAT)
  344. #define FORCE
  345. #define FORCE_INTEL
  346. #define ARCHITECTURE "X86"
  347. #define SUBARCHITECTURE "BOBCAT"
  348. #define ARCHCONFIG "-DBOBCAT " \
  349. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  350. "-DL2_SIZE=524288 -DL2_LINESIZE=64 " \
  351. "-DDTB_DEFAULT_ENTRIES=40 -DDTB_SIZE=4096 " \
  352. "-DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 " \
  353. "-DHAVE_SSE4A -DHAVE_MISALIGNSSE -DHAVE_CFLUSH -DHAVE_CMOV"
  354. #define LIBNAME "bobcat"
  355. #define CORENAME "BOBCAT"
  356. #endif
  357. #if defined (FORCE_BULLDOZER)
  358. #define FORCE
  359. #define FORCE_INTEL
  360. #define ARCHITECTURE "X86"
  361. #define SUBARCHITECTURE "BULLDOZER"
  362. #define ARCHCONFIG "-DBULLDOZER " \
  363. "-DL1_DATA_SIZE=49152 -DL1_DATA_LINESIZE=64 " \
  364. "-DL2_SIZE=1024000 -DL2_LINESIZE=64 -DL3_SIZE=16777216 " \
  365. "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 " \
  366. "-DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 " \
  367. "-DHAVE_SSE4A -DHAVE_MISALIGNSSE -DHAVE_128BITFPU -DHAVE_FASTMOVU " \
  368. "-DHAVE_AVX -DHAVE_FMA4"
  369. #define LIBNAME "bulldozer"
  370. #define CORENAME "BULLDOZER"
  371. #endif
  372. #ifdef FORCE_SSE_GENERIC
  373. #define FORCE
  374. #define FORCE_INTEL
  375. #define ARCHITECTURE "X86"
  376. #define SUBARCHITECTURE "GENERIC"
  377. #define ARCHCONFIG "-DGENERIC " \
  378. "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=64 " \
  379. "-DL2_SIZE=524288 -DL2_LINESIZE=64 " \
  380. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 " \
  381. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2"
  382. #define LIBNAME "generic"
  383. #define CORENAME "GENERIC"
  384. #endif
  385. #ifdef FORCE_VIAC3
  386. #define FORCE
  387. #define FORCE_INTEL
  388. #define ARCHITECTURE "X86"
  389. #define SUBARCHITECTURE "VIAC3"
  390. #define ARCHCONFIG "-DVIAC3 " \
  391. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
  392. "-DL2_SIZE=65536 -DL2_LINESIZE=32 " \
  393. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 " \
  394. "-DHAVE_MMX -DHAVE_SSE "
  395. #define LIBNAME "viac3"
  396. #define CORENAME "VIAC3"
  397. #endif
  398. #ifdef FORCE_NANO
  399. #define FORCE
  400. #define FORCE_INTEL
  401. #define ARCHITECTURE "X86"
  402. #define SUBARCHITECTURE "NANO"
  403. #define ARCHCONFIG "-DNANO " \
  404. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  405. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  406. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 " \
  407. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3"
  408. #define LIBNAME "nano"
  409. #define CORENAME "NANO"
  410. #endif
  411. #ifdef FORCE_POWER3
  412. #define FORCE
  413. #define ARCHITECTURE "POWER"
  414. #define SUBARCHITECTURE "POWER3"
  415. #define SUBDIRNAME "power"
  416. #define ARCHCONFIG "-DPOWER3 " \
  417. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=128 " \
  418. "-DL2_SIZE=2097152 -DL2_LINESIZE=128 " \
  419. "-DDTB_DEFAULT_ENTRIES=256 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  420. #define LIBNAME "power3"
  421. #define CORENAME "POWER3"
  422. #endif
  423. #ifdef FORCE_POWER4
  424. #define FORCE
  425. #define ARCHITECTURE "POWER"
  426. #define SUBARCHITECTURE "POWER4"
  427. #define SUBDIRNAME "power"
  428. #define ARCHCONFIG "-DPOWER4 " \
  429. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  430. "-DL2_SIZE=1509949 -DL2_LINESIZE=128 " \
  431. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=6 "
  432. #define LIBNAME "power4"
  433. #define CORENAME "POWER4"
  434. #endif
  435. #ifdef FORCE_POWER5
  436. #define FORCE
  437. #define ARCHITECTURE "POWER"
  438. #define SUBARCHITECTURE "POWER5"
  439. #define SUBDIRNAME "power"
  440. #define ARCHCONFIG "-DPOWER5 " \
  441. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  442. "-DL2_SIZE=1509949 -DL2_LINESIZE=128 " \
  443. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=6 "
  444. #define LIBNAME "power5"
  445. #define CORENAME "POWER5"
  446. #endif
  447. #ifdef FORCE_POWER6
  448. #define FORCE
  449. #define ARCHITECTURE "POWER"
  450. #define SUBARCHITECTURE "POWER6"
  451. #define SUBDIRNAME "power"
  452. #define ARCHCONFIG "-DPOWER6 " \
  453. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=128 " \
  454. "-DL2_SIZE=4194304 -DL2_LINESIZE=128 " \
  455. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  456. #define LIBNAME "power6"
  457. #define CORENAME "POWER6"
  458. #endif
  459. #ifdef FORCE_PPCG4
  460. #define FORCE
  461. #define ARCHITECTURE "POWER"
  462. #define SUBARCHITECTURE "PPCG4"
  463. #define SUBDIRNAME "power"
  464. #define ARCHCONFIG "-DPPCG4 " \
  465. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
  466. "-DL2_SIZE=262144 -DL2_LINESIZE=32 " \
  467. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  468. #define LIBNAME "ppcg4"
  469. #define CORENAME "PPCG4"
  470. #endif
  471. #ifdef FORCE_PPC970
  472. #define FORCE
  473. #define ARCHITECTURE "POWER"
  474. #define SUBARCHITECTURE "PPC970"
  475. #define SUBDIRNAME "power"
  476. #define ARCHCONFIG "-DPPC970 " \
  477. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  478. "-DL2_SIZE=512488 -DL2_LINESIZE=128 " \
  479. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  480. #define LIBNAME "ppc970"
  481. #define CORENAME "PPC970"
  482. #endif
  483. #ifdef FORCE_PPC970MP
  484. #define FORCE
  485. #define ARCHITECTURE "POWER"
  486. #define SUBARCHITECTURE "PPC970"
  487. #define SUBDIRNAME "power"
  488. #define ARCHCONFIG "-DPPC970 " \
  489. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  490. "-DL2_SIZE=1024976 -DL2_LINESIZE=128 " \
  491. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  492. #define LIBNAME "ppc970mp"
  493. #define CORENAME "PPC970"
  494. #endif
  495. #ifdef FORCE_PPC440
  496. #define FORCE
  497. #define ARCHITECTURE "POWER"
  498. #define SUBARCHITECTURE "PPC440"
  499. #define SUBDIRNAME "power"
  500. #define ARCHCONFIG "-DPPC440 " \
  501. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
  502. "-DL2_SIZE=16384 -DL2_LINESIZE=128 " \
  503. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=16 "
  504. #define LIBNAME "ppc440"
  505. #define CORENAME "PPC440"
  506. #endif
  507. #ifdef FORCE_PPC440FP2
  508. #define FORCE
  509. #define ARCHITECTURE "POWER"
  510. #define SUBARCHITECTURE "PPC440FP2"
  511. #define SUBDIRNAME "power"
  512. #define ARCHCONFIG "-DPPC440FP2 " \
  513. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
  514. "-DL2_SIZE=16384 -DL2_LINESIZE=128 " \
  515. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=16 "
  516. #define LIBNAME "ppc440FP2"
  517. #define CORENAME "PPC440FP2"
  518. #endif
  519. #ifdef FORCE_CELL
  520. #define FORCE
  521. #define ARCHITECTURE "POWER"
  522. #define SUBARCHITECTURE "CELL"
  523. #define SUBDIRNAME "power"
  524. #define ARCHCONFIG "-DCELL " \
  525. "-DL1_DATA_SIZE=262144 -DL1_DATA_LINESIZE=128 " \
  526. "-DL2_SIZE=512488 -DL2_LINESIZE=128 " \
  527. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  528. #define LIBNAME "cell"
  529. #define CORENAME "CELL"
  530. #endif
  531. #ifdef FORCE_SICORTEX
  532. #define FORCE
  533. #define ARCHITECTURE "MIPS"
  534. #define SUBARCHITECTURE "SICORTEX"
  535. #define SUBDIRNAME "mips"
  536. #define ARCHCONFIG "-DSICORTEX " \
  537. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
  538. "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
  539. "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  540. #define LIBNAME "mips"
  541. #define CORENAME "sicortex"
  542. #endif
  543. #ifdef FORCE_LOONGSON3A
  544. #define FORCE
  545. #define ARCHITECTURE "MIPS"
  546. #define SUBARCHITECTURE "LOONGSON3A"
  547. #define SUBDIRNAME "mips64"
  548. #define ARCHCONFIG "-DLOONGSON3A " \
  549. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
  550. "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
  551. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 "
  552. #define LIBNAME "loongson3a"
  553. #define CORENAME "LOONGSON3A"
  554. #else
  555. #endif
  556. #ifdef FORCE_LOONGSON3B
  557. #define FORCE
  558. #define ARCHITECTURE "MIPS"
  559. #define SUBARCHITECTURE "LOONGSON3B"
  560. #define SUBDIRNAME "mips64"
  561. #define ARCHCONFIG "-DLOONGSON3B " \
  562. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
  563. "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
  564. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 "
  565. #define LIBNAME "loongson3b"
  566. #define CORENAME "LOONGSON3B"
  567. #else
  568. #endif
  569. #ifdef FORCE_ITANIUM2
  570. #define FORCE
  571. #define ARCHITECTURE "IA64"
  572. #define SUBARCHITECTURE "ITANIUM2"
  573. #define SUBDIRNAME "ia64"
  574. #define ARCHCONFIG "-DITANIUM2 " \
  575. "-DL1_DATA_SIZE=262144 -DL1_DATA_LINESIZE=128 " \
  576. "-DL2_SIZE=1572864 -DL2_LINESIZE=128 -DDTB_SIZE=16384 -DDTB_DEFAULT_ENTRIES=128 "
  577. #define LIBNAME "itanium2"
  578. #define CORENAME "itanium2"
  579. #endif
  580. #ifdef FORCE_SPARC
  581. #define FORCE
  582. #define ARCHITECTURE "SPARC"
  583. #define SUBARCHITECTURE "SPARC"
  584. #define SUBDIRNAME "sparc"
  585. #define ARCHCONFIG "-DSPARC -DV9 " \
  586. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  587. "-DL2_SIZE=1572864 -DL2_LINESIZE=64 -DDTB_SIZE=8192 -DDTB_DEFAULT_ENTRIES=64 "
  588. #define LIBNAME "sparc"
  589. #define CORENAME "sparc"
  590. #endif
  591. #ifdef FORCE_SPARCV7
  592. #define FORCE
  593. #define ARCHITECTURE "SPARC"
  594. #define SUBARCHITECTURE "SPARC"
  595. #define SUBDIRNAME "sparc"
  596. #define ARCHCONFIG "-DSPARC -DV7 " \
  597. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  598. "-DL2_SIZE=1572864 -DL2_LINESIZE=64 -DDTB_SIZE=8192 -DDTB_DEFAULT_ENTRIES=64 "
  599. #define LIBNAME "sparcv7"
  600. #define CORENAME "sparcv7"
  601. #endif
  602. #ifdef FORCE_GENERIC
  603. #define FORCE
  604. #define ARCHITECTURE "GENERIC"
  605. #define SUBARCHITECTURE "GENERIC"
  606. #define SUBDIRNAME "generic"
  607. #define ARCHCONFIG "-DGENERIC " \
  608. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  609. "-DL2_SIZE=512488 -DL2_LINESIZE=128 " \
  610. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  611. #define LIBNAME "generic"
  612. #define CORENAME "generic"
  613. #endif
  614. #ifndef FORCE
  615. #if defined(__powerpc__) || defined(__powerpc) || defined(powerpc) || \
  616. defined(__PPC__) || defined(PPC) || defined(_POWER) || defined(__POWERPC__)
  617. #ifndef POWER
  618. #define POWER
  619. #endif
  620. #define OPENBLAS_SUPPORTED
  621. #endif
  622. #if defined(__i386__) || (__x86_64__)
  623. #include "cpuid_x86.c"
  624. #define OPENBLAS_SUPPORTED
  625. #endif
  626. #ifdef __ia64__
  627. #include "cpuid_ia64.c"
  628. #define OPENBLAS_SUPPORTED
  629. #endif
  630. #ifdef __alpha
  631. #include "cpuid_alpha.c"
  632. #define OPENBLAS_SUPPORTED
  633. #endif
  634. #ifdef POWER
  635. #include "cpuid_power.c"
  636. #define OPENBLAS_SUPPORTED
  637. #endif
  638. #ifdef sparc
  639. #include "cpuid_sparc.c"
  640. #define OPENBLAS_SUPPORTED
  641. #endif
  642. #ifdef __mips__
  643. #include "cpuid_mips.c"
  644. #define OPENBLAS_SUPPORTED
  645. #endif
  646. #ifndef OPENBLAS_SUPPORTED
  647. #error "This arch/CPU is not supported by OpenBLAS."
  648. #endif
  649. #else
  650. #endif
  651. static int get_num_cores(void) {
  652. #ifdef OS_WINDOWS
  653. SYSTEM_INFO sysinfo;
  654. #elif defined(__FreeBSD__) || defined(__APPLE__)
  655. int m[2], count;
  656. size_t len;
  657. #endif
  658. #ifdef linux
  659. return get_nprocs();
  660. #elif defined(OS_WINDOWS)
  661. GetSystemInfo(&sysinfo);
  662. return sysinfo.dwNumberOfProcessors;
  663. #elif defined(__FreeBSD__) || defined(__APPLE__)
  664. m[0] = CTL_HW;
  665. m[1] = HW_NCPU;
  666. len = sizeof(int);
  667. sysctl(m, 2, &count, &len, NULL, 0);
  668. return count;
  669. #else
  670. return 2;
  671. #endif
  672. }
  673. int main(int argc, char *argv[]){
  674. #ifdef FORCE
  675. char buffer[8192], *p, *q;
  676. int length;
  677. #endif
  678. if (argc == 1) return 0;
  679. switch (argv[1][0]) {
  680. case '0' : /* for Makefile */
  681. #ifdef FORCE
  682. printf("CORE=%s\n", CORENAME);
  683. #else
  684. #if defined(__i386__) || defined(__x86_64__) || defined(POWER) || defined(__mips__)
  685. printf("CORE=%s\n", get_corename());
  686. #endif
  687. #endif
  688. #ifdef FORCE
  689. printf("LIBCORE=%s\n", LIBNAME);
  690. #else
  691. printf("LIBCORE=");
  692. get_libname();
  693. printf("\n");
  694. #endif
  695. printf("NUM_CORES=%d\n", get_num_cores());
  696. #if defined(__i386__) || defined(__x86_64__)
  697. #ifndef FORCE
  698. get_sse();
  699. #else
  700. sprintf(buffer, "%s", ARCHCONFIG);
  701. p = &buffer[0];
  702. while (*p) {
  703. if ((*p == '-') && (*(p + 1) == 'D')) {
  704. p += 2;
  705. while ((*p != ' ') && (*p != '\0')) {
  706. if (*p == '=') {
  707. printf("=");
  708. p ++;
  709. while ((*p != ' ') && (*p != '\0')) {
  710. printf("%c", *p);
  711. p ++;
  712. }
  713. } else {
  714. printf("%c", *p);
  715. p ++;
  716. if ((*p == ' ') || (*p =='\0')) printf("=1");
  717. }
  718. }
  719. printf("\n");
  720. } else p ++;
  721. }
  722. #endif
  723. #endif
  724. #if NO_PARALLEL_MAKE==1
  725. printf("MAKE += -j 1\n");
  726. #else
  727. #ifndef OS_WINDOWS
  728. printf("MAKE += -j %d\n", get_num_cores());
  729. #endif
  730. #endif
  731. break;
  732. case '1' : /* For config.h */
  733. #ifdef FORCE
  734. sprintf(buffer, "%s -DCORE_%s\n", ARCHCONFIG, CORENAME);
  735. p = &buffer[0];
  736. while (*p) {
  737. if ((*p == '-') && (*(p + 1) == 'D')) {
  738. p += 2;
  739. printf("#define ");
  740. while ((*p != ' ') && (*p != '\0')) {
  741. if (*p == '=') {
  742. printf(" ");
  743. p ++;
  744. while ((*p != ' ') && (*p != '\0')) {
  745. printf("%c", *p);
  746. p ++;
  747. }
  748. } else {
  749. printf("%c", *p);
  750. p ++;
  751. }
  752. }
  753. printf("\n");
  754. } else p ++;
  755. }
  756. #else
  757. get_cpuconfig();
  758. #endif
  759. break;
  760. case '2' : /* SMP */
  761. if (get_num_cores() > 1) printf("SMP=1\n");
  762. break;
  763. }
  764. fflush(stdout);
  765. return 0;
  766. }