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

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