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
14 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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_ATHLON */
  91. /* #define FORCE_OPTERON */
  92. /* #define FORCE_OPTERON_SSE3 */
  93. /* #define FORCE_BARCELONA */
  94. /* #define FORCE_SHANGHAI */
  95. /* #define FORCE_ISTANBUL */
  96. /* #define FORCE_BULLDOZER */
  97. /* #define FORCE_BOBCAT */
  98. /* #define FORCE_SSE_GENERIC */
  99. /* #define FORCE_VIAC3 */
  100. /* #define FORCE_NANO */
  101. /* #define FORCE_POWER3 */
  102. /* #define FORCE_POWER4 */
  103. /* #define FORCE_POWER5 */
  104. /* #define FORCE_POWER6 */
  105. /* #define FORCE_PPCG4 */
  106. /* #define FORCE_PPC970 */
  107. /* #define FORCE_PPC970MP */
  108. /* #define FORCE_PPC440 */
  109. /* #define FORCE_PPC440FP2 */
  110. /* #define FORCE_CELL */
  111. /* #define FORCE_SICORTEX */
  112. /* #define FORCE_LOONGSON3A */
  113. /* #define FORCE_LOONGSON3B */
  114. /* #define FORCE_ITANIUM2 */
  115. /* #define FORCE_GENERIC */
  116. /* #define FORCE_SPARC */
  117. /* #define FORCE_SPARCV7 */
  118. #ifdef FORCE_P2
  119. #define FORCE
  120. #define FORCE_INTEL
  121. #define ARCHITECTURE "X86"
  122. #define SUBARCHITECTURE "PENTIUM2"
  123. #define ARCHCONFIG "-DPENTIUM2 " \
  124. "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=32 " \
  125. "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
  126. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
  127. "-DHAVE_CMOV -DHAVE_MMX"
  128. #define LIBNAME "p2"
  129. #define CORENAME "P5"
  130. #endif
  131. #ifdef FORCE_COPPERMINE
  132. #define FORCE
  133. #define FORCE_INTEL
  134. #define ARCHITECTURE "X86"
  135. #define SUBARCHITECTURE "PENTIUM3"
  136. #define ARCHCONFIG "-DPENTIUM3 " \
  137. "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=32 " \
  138. "-DL2_SIZE=262144 -DL2_LINESIZE=32 " \
  139. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
  140. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE "
  141. #define LIBNAME "coppermine"
  142. #define CORENAME "COPPERMINE"
  143. #endif
  144. #ifdef FORCE_KATMAI
  145. #define FORCE
  146. #define FORCE_INTEL
  147. #define ARCHITECTURE "X86"
  148. #define SUBARCHITECTURE "PENTIUM3"
  149. #define ARCHCONFIG "-DPENTIUM3 " \
  150. "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=32 " \
  151. "-DL2_SIZE=524288 -DL2_LINESIZE=32 " \
  152. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
  153. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE "
  154. #define LIBNAME "katmai"
  155. #define CORENAME "KATMAI"
  156. #endif
  157. #ifdef FORCE_NORTHWOOD
  158. #define FORCE
  159. #define FORCE_INTEL
  160. #define ARCHITECTURE "X86"
  161. #define SUBARCHITECTURE "PENTIUM4"
  162. #define ARCHCONFIG "-DPENTIUM4 " \
  163. "-DL1_DATA_SIZE=8192 -DL1_DATA_LINESIZE=64 " \
  164. "-DL2_SIZE=524288 -DL2_LINESIZE=64 " \
  165. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 " \
  166. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 "
  167. #define LIBNAME "northwood"
  168. #define CORENAME "NORTHWOOD"
  169. #endif
  170. #ifdef FORCE_PRESCOTT
  171. #define FORCE
  172. #define FORCE_INTEL
  173. #define ARCHITECTURE "X86"
  174. #define SUBARCHITECTURE "PENTIUM4"
  175. #define ARCHCONFIG "-DPENTIUM4 " \
  176. "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=64 " \
  177. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  178. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 " \
  179. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3"
  180. #define LIBNAME "prescott"
  181. #define CORENAME "PRESCOTT"
  182. #endif
  183. #ifdef FORCE_BANIAS
  184. #define FORCE
  185. #define FORCE_INTEL
  186. #define ARCHITECTURE "X86"
  187. #define SUBARCHITECTURE "BANIAS"
  188. #define ARCHCONFIG "-DPENTIUMM " \
  189. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  190. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  191. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
  192. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 "
  193. #define LIBNAME "banias"
  194. #define CORENAME "BANIAS"
  195. #endif
  196. #ifdef FORCE_YONAH
  197. #define FORCE
  198. #define FORCE_INTEL
  199. #define ARCHITECTURE "X86"
  200. #define SUBARCHITECTURE "YONAH"
  201. #define ARCHCONFIG "-DPENTIUMM " \
  202. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  203. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  204. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
  205. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 "
  206. #define LIBNAME "yonah"
  207. #define CORENAME "YONAH"
  208. #endif
  209. #ifdef FORCE_CORE2
  210. #define FORCE
  211. #define FORCE_INTEL
  212. #define ARCHITECTURE "X86"
  213. #define SUBARCHITECTURE "CONRORE"
  214. #define ARCHCONFIG "-DCORE2 " \
  215. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  216. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  217. "-DDTB_DEFAULT_ENTRIES=256 -DDTB_SIZE=4096 " \
  218. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3"
  219. #define LIBNAME "core2"
  220. #define CORENAME "CORE2"
  221. #endif
  222. #ifdef FORCE_PENRYN
  223. #define FORCE
  224. #define FORCE_INTEL
  225. #define ARCHITECTURE "X86"
  226. #define SUBARCHITECTURE "PENRYN"
  227. #define ARCHCONFIG "-DPENRYN " \
  228. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  229. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  230. "-DDTB_DEFAULT_ENTRIES=256 -DDTB_SIZE=4096 " \
  231. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 -DHAVE_SSE4_1"
  232. #define LIBNAME "penryn"
  233. #define CORENAME "PENRYN"
  234. #endif
  235. #ifdef FORCE_DUNNINGTON
  236. #define FORCE
  237. #define FORCE_INTEL
  238. #define ARCHITECTURE "X86"
  239. #define SUBARCHITECTURE "DUNNINGTON"
  240. #define ARCHCONFIG "-DDUNNINGTON " \
  241. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  242. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  243. "-DL3_SIZE=16777216 -DL3_LINESIZE=64 " \
  244. "-DDTB_DEFAULT_ENTRIES=256 -DDTB_SIZE=4096 " \
  245. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 -DHAVE_SSE4_1"
  246. #define LIBNAME "dunnington"
  247. #define CORENAME "DUNNINGTON"
  248. #endif
  249. #ifdef FORCE_NEHALEM
  250. #define FORCE
  251. #define FORCE_INTEL
  252. #define ARCHITECTURE "X86"
  253. #define SUBARCHITECTURE "NEHALEM"
  254. #define ARCHCONFIG "-DNEHALEM " \
  255. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  256. "-DL2_SIZE=262144 -DL2_LINESIZE=64 " \
  257. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
  258. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 -DHAVE_SSE4_1 -DHAVE_SSE4_2"
  259. #define LIBNAME "nehalem"
  260. #define CORENAME "NEHALEM"
  261. #endif
  262. #ifdef FORCE_SANDYBRIDGE
  263. #define FORCE
  264. #define FORCE_INTEL
  265. #define ARCHITECTURE "X86"
  266. #define SUBARCHITECTURE "SANDYBRIDGE"
  267. #define ARCHCONFIG "-DSANDYBRIDGE " \
  268. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  269. "-DL2_SIZE=262144 -DL2_LINESIZE=64 " \
  270. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 " \
  271. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 -DHAVE_SSE4_1 -DHAVE_SSE4_2 -DHAVE_AVX"
  272. #define LIBNAME "sandybridge"
  273. #define CORENAME "SANDYBRIDGE"
  274. #endif
  275. #ifdef FORCE_ATOM
  276. #define FORCE
  277. #define FORCE_INTEL
  278. #define ARCHITECTURE "X86"
  279. #define SUBARCHITECTURE "ATOM"
  280. #define ARCHCONFIG "-DATOM " \
  281. "-DL1_DATA_SIZE=24576 -DL1_DATA_LINESIZE=64 " \
  282. "-DL2_SIZE=524288 -DL2_LINESIZE=64 " \
  283. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 " \
  284. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3"
  285. #define LIBNAME "atom"
  286. #define CORENAME "ATOM"
  287. #endif
  288. #ifdef FORCE_ATHLON
  289. #define FORCE
  290. #define FORCE_INTEL
  291. #define ARCHITECTURE "X86"
  292. #define SUBARCHITECTURE "ATHLON"
  293. #define ARCHCONFIG "-DATHLON " \
  294. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  295. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  296. "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 -DHAVE_3DNOW " \
  297. "-DHAVE_3DNOWEX -DHAVE_MMX -DHAVE_SSE "
  298. #define LIBNAME "athlon"
  299. #define CORENAME "ATHLON"
  300. #endif
  301. #ifdef FORCE_OPTERON
  302. #define FORCE
  303. #define FORCE_INTEL
  304. #define ARCHITECTURE "X86"
  305. #define SUBARCHITECTURE "OPTERON"
  306. #define ARCHCONFIG "-DOPTERON " \
  307. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  308. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  309. "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 -DHAVE_3DNOW " \
  310. "-DHAVE_3DNOWEX -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 "
  311. #define LIBNAME "opteron"
  312. #define CORENAME "OPTERON"
  313. #endif
  314. #ifdef FORCE_OPTERON_SSE3
  315. #define FORCE
  316. #define FORCE_INTEL
  317. #define ARCHITECTURE "X86"
  318. #define SUBARCHITECTURE "OPTERON"
  319. #define ARCHCONFIG "-DOPTERON " \
  320. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  321. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  322. "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 -DHAVE_3DNOW " \
  323. "-DHAVE_3DNOWEX -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3"
  324. #define LIBNAME "opteron"
  325. #define CORENAME "OPTERON"
  326. #endif
  327. #if defined(FORCE_BARCELONA) || defined(FORCE_SHANGHAI) || defined(FORCE_ISTANBUL) || defined (FORCE_BULLDOZER)
  328. #define FORCE
  329. #define FORCE_INTEL
  330. #define ARCHITECTURE "X86"
  331. #define SUBARCHITECTURE "BARCELONA"
  332. #define ARCHCONFIG "-DBARCELONA " \
  333. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  334. "-DL2_SIZE=524288 -DL2_LINESIZE=64 -DL3_SIZE=2097152 " \
  335. "-DDTB_DEFAULT_ENTRIES=48 -DDTB_SIZE=4096 " \
  336. "-DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 " \
  337. "-DHAVE_SSE4A -DHAVE_MISALIGNSSE -DHAVE_128BITFPU -DHAVE_FASTMOVU"
  338. #define LIBNAME "barcelona"
  339. #define CORENAME "BARCELONA"
  340. #endif
  341. #if defined(FORCE_BOBCAT)
  342. #define FORCE
  343. #define FORCE_INTEL
  344. #define ARCHITECTURE "X86"
  345. #define SUBARCHITECTURE "BOBCAT"
  346. #define ARCHCONFIG "-DBOBCAT " \
  347. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=64 " \
  348. "-DL2_SIZE=524288 -DL2_LINESIZE=64 " \
  349. "-DDTB_DEFAULT_ENTRIES=40 -DDTB_SIZE=4096 " \
  350. "-DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3 " \
  351. "-DHAVE_SSE4A -DHAVE_MISALIGNSSE -DHAVE_CFLUSH -DHAVE_CMOV"
  352. #define LIBNAME "bobcat"
  353. #define CORENAME "BOBCAT"
  354. #endif
  355. #ifdef FORCE_SSE_GENERIC
  356. #define FORCE
  357. #define FORCE_INTEL
  358. #define ARCHITECTURE "X86"
  359. #define SUBARCHITECTURE "GENERIC"
  360. #define ARCHCONFIG "-DGENERIC " \
  361. "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=64 " \
  362. "-DL2_SIZE=524288 -DL2_LINESIZE=64 " \
  363. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 " \
  364. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2"
  365. #define LIBNAME "generic"
  366. #define CORENAME "GENERIC"
  367. #endif
  368. #ifdef FORCE_VIAC3
  369. #define FORCE
  370. #define FORCE_INTEL
  371. #define ARCHITECTURE "X86"
  372. #define SUBARCHITECTURE "VIAC3"
  373. #define ARCHCONFIG "-DVIAC3 " \
  374. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
  375. "-DL2_SIZE=65536 -DL2_LINESIZE=32 " \
  376. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 " \
  377. "-DHAVE_MMX -DHAVE_SSE "
  378. #define LIBNAME "viac3"
  379. #define CORENAME "VIAC3"
  380. #endif
  381. #ifdef FORCE_NANO
  382. #define FORCE
  383. #define FORCE_INTEL
  384. #define ARCHITECTURE "X86"
  385. #define SUBARCHITECTURE "NANO"
  386. #define ARCHCONFIG "-DNANO " \
  387. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  388. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  389. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 " \
  390. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3"
  391. #define LIBNAME "nano"
  392. #define CORENAME "NANO"
  393. #endif
  394. #ifdef FORCE_POWER3
  395. #define FORCE
  396. #define ARCHITECTURE "POWER"
  397. #define SUBARCHITECTURE "POWER3"
  398. #define SUBDIRNAME "power"
  399. #define ARCHCONFIG "-DPOWER3 " \
  400. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=128 " \
  401. "-DL2_SIZE=2097152 -DL2_LINESIZE=128 " \
  402. "-DDTB_DEFAULT_ENTRIES=256 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  403. #define LIBNAME "power3"
  404. #define CORENAME "POWER3"
  405. #endif
  406. #ifdef FORCE_POWER4
  407. #define FORCE
  408. #define ARCHITECTURE "POWER"
  409. #define SUBARCHITECTURE "POWER4"
  410. #define SUBDIRNAME "power"
  411. #define ARCHCONFIG "-DPOWER4 " \
  412. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  413. "-DL2_SIZE=1509949 -DL2_LINESIZE=128 " \
  414. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=6 "
  415. #define LIBNAME "power4"
  416. #define CORENAME "POWER4"
  417. #endif
  418. #ifdef FORCE_POWER5
  419. #define FORCE
  420. #define ARCHITECTURE "POWER"
  421. #define SUBARCHITECTURE "POWER5"
  422. #define SUBDIRNAME "power"
  423. #define ARCHCONFIG "-DPOWER5 " \
  424. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  425. "-DL2_SIZE=1509949 -DL2_LINESIZE=128 " \
  426. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=6 "
  427. #define LIBNAME "power5"
  428. #define CORENAME "POWER5"
  429. #endif
  430. #ifdef FORCE_POWER6
  431. #define FORCE
  432. #define ARCHITECTURE "POWER"
  433. #define SUBARCHITECTURE "POWER6"
  434. #define SUBDIRNAME "power"
  435. #define ARCHCONFIG "-DPOWER6 " \
  436. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=128 " \
  437. "-DL2_SIZE=4194304 -DL2_LINESIZE=128 " \
  438. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  439. #define LIBNAME "power6"
  440. #define CORENAME "POWER6"
  441. #endif
  442. #ifdef FORCE_PPCG4
  443. #define FORCE
  444. #define ARCHITECTURE "POWER"
  445. #define SUBARCHITECTURE "PPCG4"
  446. #define SUBDIRNAME "power"
  447. #define ARCHCONFIG "-DPPCG4 " \
  448. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
  449. "-DL2_SIZE=262144 -DL2_LINESIZE=32 " \
  450. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  451. #define LIBNAME "ppcg4"
  452. #define CORENAME "PPCG4"
  453. #endif
  454. #ifdef FORCE_PPC970
  455. #define FORCE
  456. #define ARCHITECTURE "POWER"
  457. #define SUBARCHITECTURE "PPC970"
  458. #define SUBDIRNAME "power"
  459. #define ARCHCONFIG "-DPPC970 " \
  460. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  461. "-DL2_SIZE=512488 -DL2_LINESIZE=128 " \
  462. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  463. #define LIBNAME "ppc970"
  464. #define CORENAME "PPC970"
  465. #endif
  466. #ifdef FORCE_PPC970MP
  467. #define FORCE
  468. #define ARCHITECTURE "POWER"
  469. #define SUBARCHITECTURE "PPC970"
  470. #define SUBDIRNAME "power"
  471. #define ARCHCONFIG "-DPPC970 " \
  472. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  473. "-DL2_SIZE=1024976 -DL2_LINESIZE=128 " \
  474. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  475. #define LIBNAME "ppc970mp"
  476. #define CORENAME "PPC970"
  477. #endif
  478. #ifdef FORCE_PPC440
  479. #define FORCE
  480. #define ARCHITECTURE "POWER"
  481. #define SUBARCHITECTURE "PPC440"
  482. #define SUBDIRNAME "power"
  483. #define ARCHCONFIG "-DPPC440 " \
  484. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
  485. "-DL2_SIZE=16384 -DL2_LINESIZE=128 " \
  486. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=16 "
  487. #define LIBNAME "ppc440"
  488. #define CORENAME "PPC440"
  489. #endif
  490. #ifdef FORCE_PPC440FP2
  491. #define FORCE
  492. #define ARCHITECTURE "POWER"
  493. #define SUBARCHITECTURE "PPC440FP2"
  494. #define SUBDIRNAME "power"
  495. #define ARCHCONFIG "-DPPC440FP2 " \
  496. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
  497. "-DL2_SIZE=16384 -DL2_LINESIZE=128 " \
  498. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=16 "
  499. #define LIBNAME "ppc440FP2"
  500. #define CORENAME "PPC440FP2"
  501. #endif
  502. #ifdef FORCE_CELL
  503. #define FORCE
  504. #define ARCHITECTURE "POWER"
  505. #define SUBARCHITECTURE "CELL"
  506. #define SUBDIRNAME "power"
  507. #define ARCHCONFIG "-DCELL " \
  508. "-DL1_DATA_SIZE=262144 -DL1_DATA_LINESIZE=128 " \
  509. "-DL2_SIZE=512488 -DL2_LINESIZE=128 " \
  510. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  511. #define LIBNAME "cell"
  512. #define CORENAME "CELL"
  513. #endif
  514. #ifdef FORCE_SICORTEX
  515. #define FORCE
  516. #define ARCHITECTURE "MIPS"
  517. #define SUBARCHITECTURE "SICORTEX"
  518. #define SUBDIRNAME "mips"
  519. #define ARCHCONFIG "-DSICORTEX " \
  520. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
  521. "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
  522. "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  523. #define LIBNAME "mips"
  524. #define CORENAME "sicortex"
  525. #endif
  526. #ifdef FORCE_LOONGSON3A
  527. #define FORCE
  528. #define ARCHITECTURE "MIPS"
  529. #define SUBARCHITECTURE "LOONGSON3A"
  530. #define SUBDIRNAME "mips64"
  531. #define ARCHCONFIG "-DLOONGSON3A " \
  532. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
  533. "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
  534. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 "
  535. #define LIBNAME "loongson3a"
  536. #define CORENAME "LOONGSON3A"
  537. #else
  538. #endif
  539. #ifdef FORCE_LOONGSON3B
  540. #define FORCE
  541. #define ARCHITECTURE "MIPS"
  542. #define SUBARCHITECTURE "LOONGSON3B"
  543. #define SUBDIRNAME "mips64"
  544. #define ARCHCONFIG "-DLOONGSON3B " \
  545. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
  546. "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
  547. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 "
  548. #define LIBNAME "loongson3b"
  549. #define CORENAME "LOONGSON3B"
  550. #else
  551. #endif
  552. #ifdef FORCE_ITANIUM2
  553. #define FORCE
  554. #define ARCHITECTURE "IA64"
  555. #define SUBARCHITECTURE "ITANIUM2"
  556. #define SUBDIRNAME "ia64"
  557. #define ARCHCONFIG "-DITANIUM2 " \
  558. "-DL1_DATA_SIZE=262144 -DL1_DATA_LINESIZE=128 " \
  559. "-DL2_SIZE=1572864 -DL2_LINESIZE=128 -DDTB_SIZE=16384 -DDTB_DEFAULT_ENTRIES=128 "
  560. #define LIBNAME "itanium2"
  561. #define CORENAME "itanium2"
  562. #endif
  563. #ifdef FORCE_SPARC
  564. #define FORCE
  565. #define ARCHITECTURE "SPARC"
  566. #define SUBARCHITECTURE "SPARC"
  567. #define SUBDIRNAME "sparc"
  568. #define ARCHCONFIG "-DSPARC -DV9 " \
  569. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  570. "-DL2_SIZE=1572864 -DL2_LINESIZE=64 -DDTB_SIZE=8192 -DDTB_DEFAULT_ENTRIES=64 "
  571. #define LIBNAME "sparc"
  572. #define CORENAME "sparc"
  573. #endif
  574. #ifdef FORCE_SPARCV7
  575. #define FORCE
  576. #define ARCHITECTURE "SPARC"
  577. #define SUBARCHITECTURE "SPARC"
  578. #define SUBDIRNAME "sparc"
  579. #define ARCHCONFIG "-DSPARC -DV7 " \
  580. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  581. "-DL2_SIZE=1572864 -DL2_LINESIZE=64 -DDTB_SIZE=8192 -DDTB_DEFAULT_ENTRIES=64 "
  582. #define LIBNAME "sparcv7"
  583. #define CORENAME "sparcv7"
  584. #endif
  585. #ifdef FORCE_GENERIC
  586. #define FORCE
  587. #define ARCHITECTURE "GENERIC"
  588. #define SUBARCHITECTURE "GENERIC"
  589. #define SUBDIRNAME "generic"
  590. #define ARCHCONFIG "-DGENERIC " \
  591. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  592. "-DL2_SIZE=512488 -DL2_LINESIZE=128 " \
  593. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  594. #define LIBNAME "generic"
  595. #define CORENAME "generic"
  596. #endif
  597. #ifndef FORCE
  598. #if defined(__powerpc__) || defined(__powerpc) || defined(powerpc) || \
  599. defined(__PPC__) || defined(PPC) || defined(_POWER) || defined(__POWERPC__)
  600. #ifndef POWER
  601. #define POWER
  602. #endif
  603. #define OPENBLAS_SUPPORTED
  604. #endif
  605. #if defined(__i386__) || (__x86_64__)
  606. #include "cpuid_x86.c"
  607. #define OPENBLAS_SUPPORTED
  608. #endif
  609. #ifdef __ia64__
  610. #include "cpuid_ia64.c"
  611. #define OPENBLAS_SUPPORTED
  612. #endif
  613. #ifdef __alpha
  614. #include "cpuid_alpha.c"
  615. #define OPENBLAS_SUPPORTED
  616. #endif
  617. #ifdef POWER
  618. #include "cpuid_power.c"
  619. #define OPENBLAS_SUPPORTED
  620. #endif
  621. #ifdef sparc
  622. #include "cpuid_sparc.c"
  623. #define OPENBLAS_SUPPORTED
  624. #endif
  625. #ifdef __mips__
  626. #include "cpuid_mips.c"
  627. #define OPENBLAS_SUPPORTED
  628. #endif
  629. #ifndef OPENBLAS_SUPPORTED
  630. #error "This arch/CPU is not supported by OpenBLAS."
  631. #endif
  632. #else
  633. #endif
  634. static int get_num_cores(void) {
  635. #ifdef OS_WINDOWS
  636. SYSTEM_INFO sysinfo;
  637. #elif defined(__FreeBSD__) || defined(__APPLE__)
  638. int m[2], count;
  639. size_t len;
  640. #endif
  641. #ifdef linux
  642. return get_nprocs();
  643. #elif defined(OS_WINDOWS)
  644. GetSystemInfo(&sysinfo);
  645. return sysinfo.dwNumberOfProcessors;
  646. #elif defined(__FreeBSD__) || defined(__APPLE__)
  647. m[0] = CTL_HW;
  648. m[1] = HW_NCPU;
  649. len = sizeof(int);
  650. sysctl(m, 2, &count, &len, NULL, 0);
  651. return count;
  652. #else
  653. return 2;
  654. #endif
  655. }
  656. int main(int argc, char *argv[]){
  657. #ifdef FORCE
  658. char buffer[8192], *p, *q;
  659. int length;
  660. #endif
  661. if (argc == 1) return 0;
  662. switch (argv[1][0]) {
  663. case '0' : /* for Makefile */
  664. #ifdef FORCE
  665. printf("CORE=%s\n", CORENAME);
  666. #else
  667. #if defined(__i386__) || defined(__x86_64__) || defined(POWER) || defined(__mips__)
  668. printf("CORE=%s\n", get_corename());
  669. #endif
  670. #endif
  671. #ifdef FORCE
  672. printf("LIBCORE=%s\n", LIBNAME);
  673. #else
  674. printf("LIBCORE=");
  675. get_libname();
  676. printf("\n");
  677. #endif
  678. printf("NUM_CORES=%d\n", get_num_cores());
  679. #if defined(__i386__) || defined(__x86_64__)
  680. #ifndef FORCE
  681. get_sse();
  682. #else
  683. sprintf(buffer, "%s", ARCHCONFIG);
  684. p = &buffer[0];
  685. while (*p) {
  686. if ((*p == '-') && (*(p + 1) == 'D')) {
  687. p += 2;
  688. while ((*p != ' ') && (*p != '\0')) {
  689. if (*p == '=') {
  690. printf("=");
  691. p ++;
  692. while ((*p != ' ') && (*p != '\0')) {
  693. printf("%c", *p);
  694. p ++;
  695. }
  696. } else {
  697. printf("%c", *p);
  698. p ++;
  699. if ((*p == ' ') || (*p =='\0')) printf("=1");
  700. }
  701. }
  702. printf("\n");
  703. } else p ++;
  704. }
  705. #endif
  706. #endif
  707. #ifndef OS_WINDOWS
  708. printf("MAKE += -j %d\n", get_num_cores());
  709. #endif
  710. break;
  711. case '1' : /* For config.h */
  712. #ifdef FORCE
  713. sprintf(buffer, "%s -DCORE_%s\n", ARCHCONFIG, CORENAME);
  714. p = &buffer[0];
  715. while (*p) {
  716. if ((*p == '-') && (*(p + 1) == 'D')) {
  717. p += 2;
  718. printf("#define ");
  719. while ((*p != ' ') && (*p != '\0')) {
  720. if (*p == '=') {
  721. printf(" ");
  722. p ++;
  723. while ((*p != ' ') && (*p != '\0')) {
  724. printf("%c", *p);
  725. p ++;
  726. }
  727. } else {
  728. printf("%c", *p);
  729. p ++;
  730. }
  731. }
  732. printf("\n");
  733. } else p ++;
  734. }
  735. #else
  736. get_cpuconfig();
  737. #endif
  738. break;
  739. case '2' : /* SMP */
  740. if (get_num_cores() > 1) printf("SMP=1\n");
  741. break;
  742. }
  743. fflush(stdout);
  744. return 0;
  745. }