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 27 kB

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