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

15 years ago
15 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  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_ATOM
  261. #define FORCE
  262. #define FORCE_INTEL
  263. #define ARCHITECTURE "X86"
  264. #define SUBARCHITECTURE "ATOM"
  265. #define ARCHCONFIG "-DATOM " \
  266. "-DL1_DATA_SIZE=24576 -DL1_DATA_LINESIZE=64 " \
  267. "-DL2_SIZE=524288 -DL2_LINESIZE=64 " \
  268. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 " \
  269. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3"
  270. #define LIBNAME "atom"
  271. #define CORENAME "ATOM"
  272. #endif
  273. #ifdef FORCE_ATHLON
  274. #define FORCE
  275. #define FORCE_INTEL
  276. #define ARCHITECTURE "X86"
  277. #define SUBARCHITECTURE "ATHLON"
  278. #define ARCHCONFIG "-DATHLON " \
  279. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  280. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  281. "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 -DHAVE_3DNOW " \
  282. "-DHAVE_3DNOWEX -DHAVE_MMX -DHAVE_SSE "
  283. #define LIBNAME "athlon"
  284. #define CORENAME "ATHLON"
  285. #endif
  286. #ifdef FORCE_OPTERON
  287. #define FORCE
  288. #define FORCE_INTEL
  289. #define ARCHITECTURE "X86"
  290. #define SUBARCHITECTURE "OPTERON"
  291. #define ARCHCONFIG "-DOPTERON " \
  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 -DHAVE_SSE2 "
  296. #define LIBNAME "opteron"
  297. #define CORENAME "OPTERON"
  298. #endif
  299. #ifdef FORCE_OPTERON_SSE3
  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 -DHAVE_SSE3"
  309. #define LIBNAME "opteron"
  310. #define CORENAME "OPTERON"
  311. #endif
  312. #if defined(FORCE_BARCELONA) || defined(FORCE_SHANGHAI) || defined(FORCE_ISTANBUL)
  313. #define FORCE
  314. #define FORCE_INTEL
  315. #define ARCHITECTURE "X86"
  316. #define SUBARCHITECTURE "BARCELONA"
  317. #define ARCHCONFIG "-DBARCELONA " \
  318. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  319. "-DL2_SIZE=524288 -DL2_LINESIZE=64 -DL3_SIZE=2097152 " \
  320. "-DDTB_DEFAULT_ENTRIES=48 -DDTB_SIZE=4096 -DHAVE_3DNOW " \
  321. "-DHAVE_3DNOWEX -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 " \
  322. "-DHAVE_SSE4A -DHAVE_MISALIGNSSE -DHAVE_128BITFPU -DHAVE_FASTMOVU"
  323. #define LIBNAME "barcelona"
  324. #define CORENAME "BARCELONA"
  325. #endif
  326. #ifdef FORCE_SSE_GENERIC
  327. #define FORCE
  328. #define FORCE_INTEL
  329. #define ARCHITECTURE "X86"
  330. #define SUBARCHITECTURE "GENERIC"
  331. #define ARCHCONFIG "-DGENERIC " \
  332. "-DL1_DATA_SIZE=16384 -DL1_DATA_LINESIZE=64 " \
  333. "-DL2_SIZE=524288 -DL2_LINESIZE=64 " \
  334. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 " \
  335. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2"
  336. #define LIBNAME "generic"
  337. #define CORENAME "GENERIC"
  338. #endif
  339. #ifdef FORCE_VIAC3
  340. #define FORCE
  341. #define FORCE_INTEL
  342. #define ARCHITECTURE "X86"
  343. #define SUBARCHITECTURE "VIAC3"
  344. #define ARCHCONFIG "-DVIAC3 " \
  345. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
  346. "-DL2_SIZE=65536 -DL2_LINESIZE=32 " \
  347. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 " \
  348. "-DHAVE_MMX -DHAVE_SSE "
  349. #define LIBNAME "viac3"
  350. #define CORENAME "VIAC3"
  351. #endif
  352. #ifdef FORCE_NANO
  353. #define FORCE
  354. #define FORCE_INTEL
  355. #define ARCHITECTURE "X86"
  356. #define SUBARCHITECTURE "NANO"
  357. #define ARCHCONFIG "-DNANO " \
  358. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  359. "-DL2_SIZE=1048576 -DL2_LINESIZE=64 " \
  360. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 " \
  361. "-DHAVE_CMOV -DHAVE_MMX -DHAVE_SSE -DHAVE_SSE2 -DHAVE_SSE3 -DHAVE_SSSE3"
  362. #define LIBNAME "nano"
  363. #define CORENAME "NANO"
  364. #endif
  365. #ifdef FORCE_POWER3
  366. #define FORCE
  367. #define ARCHITECTURE "POWER"
  368. #define SUBARCHITECTURE "POWER3"
  369. #define SUBDIRNAME "power"
  370. #define ARCHCONFIG "-DPOWER3 " \
  371. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=128 " \
  372. "-DL2_SIZE=2097152 -DL2_LINESIZE=128 " \
  373. "-DDTB_DEFAULT_ENTRIES=256 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  374. #define LIBNAME "power3"
  375. #define CORENAME "POWER3"
  376. #endif
  377. #ifdef FORCE_POWER4
  378. #define FORCE
  379. #define ARCHITECTURE "POWER"
  380. #define SUBARCHITECTURE "POWER4"
  381. #define SUBDIRNAME "power"
  382. #define ARCHCONFIG "-DPOWER4 " \
  383. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  384. "-DL2_SIZE=1509949 -DL2_LINESIZE=128 " \
  385. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=6 "
  386. #define LIBNAME "power4"
  387. #define CORENAME "POWER4"
  388. #endif
  389. #ifdef FORCE_POWER5
  390. #define FORCE
  391. #define ARCHITECTURE "POWER"
  392. #define SUBARCHITECTURE "POWER5"
  393. #define SUBDIRNAME "power"
  394. #define ARCHCONFIG "-DPOWER5 " \
  395. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  396. "-DL2_SIZE=1509949 -DL2_LINESIZE=128 " \
  397. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=6 "
  398. #define LIBNAME "power5"
  399. #define CORENAME "POWER5"
  400. #endif
  401. #ifdef FORCE_POWER6
  402. #define FORCE
  403. #define ARCHITECTURE "POWER"
  404. #define SUBARCHITECTURE "POWER6"
  405. #define SUBDIRNAME "power"
  406. #define ARCHCONFIG "-DPOWER6 " \
  407. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=128 " \
  408. "-DL2_SIZE=4194304 -DL2_LINESIZE=128 " \
  409. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  410. #define LIBNAME "power6"
  411. #define CORENAME "POWER6"
  412. #endif
  413. #ifdef FORCE_PPCG4
  414. #define FORCE
  415. #define ARCHITECTURE "POWER"
  416. #define SUBARCHITECTURE "PPCG4"
  417. #define SUBDIRNAME "power"
  418. #define ARCHCONFIG "-DPPCG4 " \
  419. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
  420. "-DL2_SIZE=262144 -DL2_LINESIZE=32 " \
  421. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  422. #define LIBNAME "ppcg4"
  423. #define CORENAME "PPCG4"
  424. #endif
  425. #ifdef FORCE_PPC970
  426. #define FORCE
  427. #define ARCHITECTURE "POWER"
  428. #define SUBARCHITECTURE "PPC970"
  429. #define SUBDIRNAME "power"
  430. #define ARCHCONFIG "-DPPC970 " \
  431. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  432. "-DL2_SIZE=512488 -DL2_LINESIZE=128 " \
  433. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  434. #define LIBNAME "ppc970"
  435. #define CORENAME "PPC970"
  436. #endif
  437. #ifdef FORCE_PPC970MP
  438. #define FORCE
  439. #define ARCHITECTURE "POWER"
  440. #define SUBARCHITECTURE "PPC970"
  441. #define SUBDIRNAME "power"
  442. #define ARCHCONFIG "-DPPC970 " \
  443. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  444. "-DL2_SIZE=1024976 -DL2_LINESIZE=128 " \
  445. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  446. #define LIBNAME "ppc970mp"
  447. #define CORENAME "PPC970"
  448. #endif
  449. #ifdef FORCE_PPC440
  450. #define FORCE
  451. #define ARCHITECTURE "POWER"
  452. #define SUBARCHITECTURE "PPC440"
  453. #define SUBDIRNAME "power"
  454. #define ARCHCONFIG "-DPPC440 " \
  455. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
  456. "-DL2_SIZE=16384 -DL2_LINESIZE=128 " \
  457. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=16 "
  458. #define LIBNAME "ppc440"
  459. #define CORENAME "PPC440"
  460. #endif
  461. #ifdef FORCE_PPC440FP2
  462. #define FORCE
  463. #define ARCHITECTURE "POWER"
  464. #define SUBARCHITECTURE "PPC440FP2"
  465. #define SUBDIRNAME "power"
  466. #define ARCHCONFIG "-DPPC440FP2 " \
  467. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
  468. "-DL2_SIZE=16384 -DL2_LINESIZE=128 " \
  469. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=16 "
  470. #define LIBNAME "ppc440FP2"
  471. #define CORENAME "PPC440FP2"
  472. #endif
  473. #ifdef FORCE_CELL
  474. #define FORCE
  475. #define ARCHITECTURE "POWER"
  476. #define SUBARCHITECTURE "CELL"
  477. #define SUBDIRNAME "power"
  478. #define ARCHCONFIG "-DCELL " \
  479. "-DL1_DATA_SIZE=262144 -DL1_DATA_LINESIZE=128 " \
  480. "-DL2_SIZE=512488 -DL2_LINESIZE=128 " \
  481. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  482. #define LIBNAME "cell"
  483. #define CORENAME "CELL"
  484. #endif
  485. #ifdef FORCE_SICORTEX
  486. #define FORCE
  487. #define ARCHITECTURE "MIPS"
  488. #define SUBARCHITECTURE "SICORTEX"
  489. #define SUBDIRNAME "mips"
  490. #define ARCHCONFIG "-DSICORTEX " \
  491. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
  492. "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
  493. "-DDTB_DEFAULT_ENTRIES=32 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  494. #define LIBNAME "mips"
  495. #define CORENAME "sicortex"
  496. #endif
  497. #ifdef FORCE_LOONGSON3A
  498. #define FORCE
  499. #define ARCHITECTURE "MIPS"
  500. #define SUBARCHITECTURE "LOONGSON3A"
  501. #define SUBDIRNAME "mips64"
  502. #define ARCHCONFIG "-DLOONGSON3A " \
  503. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
  504. "-DL2_SIZE=512488 -DL2_LINESIZE=32 " \
  505. "-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 "
  506. #define LIBNAME "loongson3a"
  507. #define CORENAME "LOONGSON3A"
  508. #else
  509. #endif
  510. #ifdef FORCE_LOONGSON3B
  511. #define FORCE
  512. #define ARCHITECTURE "MIPS"
  513. #define SUBARCHITECTURE "LOONGSON3B"
  514. #define SUBDIRNAME "mips64"
  515. #define ARCHCONFIG "-DLOONGSON3B " \
  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 "loongson3b"
  520. #define CORENAME "LOONGSON3B"
  521. #else
  522. #endif
  523. #ifdef FORCE_ITANIUM2
  524. #define FORCE
  525. #define ARCHITECTURE "IA64"
  526. #define SUBARCHITECTURE "ITANIUM2"
  527. #define SUBDIRNAME "ia64"
  528. #define ARCHCONFIG "-DITANIUM2 " \
  529. "-DL1_DATA_SIZE=262144 -DL1_DATA_LINESIZE=128 " \
  530. "-DL2_SIZE=1572864 -DL2_LINESIZE=128 -DDTB_SIZE=16384 -DDTB_DEFAULT_ENTRIES=128 "
  531. #define LIBNAME "itanium2"
  532. #define CORENAME "itanium2"
  533. #endif
  534. #ifdef FORCE_SPARC
  535. #define FORCE
  536. #define ARCHITECTURE "SPARC"
  537. #define SUBARCHITECTURE "SPARC"
  538. #define SUBDIRNAME "sparc"
  539. #define ARCHCONFIG "-DSPARC -DV9 " \
  540. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  541. "-DL2_SIZE=1572864 -DL2_LINESIZE=64 -DDTB_SIZE=8192 -DDTB_DEFAULT_ENTRIES=64 "
  542. #define LIBNAME "sparc"
  543. #define CORENAME "sparc"
  544. #endif
  545. #ifdef FORCE_SPARCV7
  546. #define FORCE
  547. #define ARCHITECTURE "SPARC"
  548. #define SUBARCHITECTURE "SPARC"
  549. #define SUBDIRNAME "sparc"
  550. #define ARCHCONFIG "-DSPARC -DV7 " \
  551. "-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
  552. "-DL2_SIZE=1572864 -DL2_LINESIZE=64 -DDTB_SIZE=8192 -DDTB_DEFAULT_ENTRIES=64 "
  553. #define LIBNAME "sparcv7"
  554. #define CORENAME "sparcv7"
  555. #endif
  556. #ifdef FORCE_GENERIC
  557. #define FORCE
  558. #define ARCHITECTURE "GENERIC"
  559. #define SUBARCHITECTURE "GENERIC"
  560. #define SUBDIRNAME "generic"
  561. #define ARCHCONFIG "-DGENERIC " \
  562. "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=128 " \
  563. "-DL2_SIZE=512488 -DL2_LINESIZE=128 " \
  564. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
  565. #define LIBNAME "generic"
  566. #define CORENAME "generic"
  567. #endif
  568. #ifndef FORCE
  569. #if defined(__powerpc__) || defined(__powerpc) || defined(powerpc) || \
  570. defined(__PPC__) || defined(PPC) || defined(_POWER) || defined(__POWERPC__)
  571. #ifndef POWER
  572. #define POWER
  573. #endif
  574. #define OPENBLAS_SUPPORTED
  575. #endif
  576. #if defined(__i386__) || (__x86_64__)
  577. #include "cpuid_x86.c"
  578. #define OPENBLAS_SUPPORTED
  579. #endif
  580. #ifdef __ia64__
  581. #include "cpuid_ia64.c"
  582. #define OPENBLAS_SUPPORTED
  583. #endif
  584. #ifdef __alpha
  585. #include "cpuid_alpha.c"
  586. #define OPENBLAS_SUPPORTED
  587. #endif
  588. #ifdef POWER
  589. #include "cpuid_power.c"
  590. #define OPENBLAS_SUPPORTED
  591. #endif
  592. #ifdef sparc
  593. #include "cpuid_sparc.c"
  594. #define OPENBLAS_SUPPORTED
  595. #endif
  596. #ifdef __mips__
  597. #include "cpuid_mips.c"
  598. #define OPENBLAS_SUPPORTED
  599. #endif
  600. #ifndef OPENBLAS_SUPPORTED
  601. #error "This arch/CPU is not supported by OpenBLAS."
  602. #endif
  603. #else
  604. #endif
  605. static int get_num_cores(void) {
  606. #ifdef OS_WINDOWS
  607. SYSTEM_INFO sysinfo;
  608. #elif defined(__FreeBSD__) || defined(__APPLE__)
  609. int m[2], count;
  610. size_t len;
  611. #endif
  612. #ifdef linux
  613. return get_nprocs();
  614. #elif defined(OS_WINDOWS)
  615. GetSystemInfo(&sysinfo);
  616. return sysinfo.dwNumberOfProcessors;
  617. #elif defined(__FreeBSD__) || defined(__APPLE__)
  618. m[0] = CTL_HW;
  619. m[1] = HW_NCPU;
  620. len = sizeof(int);
  621. sysctl(m, 2, &count, &len, NULL, 0);
  622. return count;
  623. #else
  624. return 2;
  625. #endif
  626. }
  627. int main(int argc, char *argv[]){
  628. #ifdef FORCE
  629. char buffer[8192], *p, *q;
  630. int length;
  631. #endif
  632. if (argc == 1) return 0;
  633. switch (argv[1][0]) {
  634. case '0' : /* for Makefile */
  635. #ifdef FORCE
  636. printf("CORE=%s\n", CORENAME);
  637. #else
  638. #if defined(__i386__) || defined(__x86_64__) || defined(POWER) || defined(__mips__)
  639. printf("CORE=%s\n", get_corename());
  640. #endif
  641. #endif
  642. #ifdef FORCE
  643. printf("LIBCORE=%s\n", LIBNAME);
  644. #else
  645. printf("LIBCORE=");
  646. get_libname();
  647. printf("\n");
  648. #endif
  649. printf("NUM_CORES=%d\n", get_num_cores());
  650. #if defined(__i386__) || defined(__x86_64__)
  651. #ifndef FORCE
  652. get_sse();
  653. #else
  654. sprintf(buffer, "%s", ARCHCONFIG);
  655. p = &buffer[0];
  656. while (*p) {
  657. if ((*p == '-') && (*(p + 1) == 'D')) {
  658. p += 2;
  659. while ((*p != ' ') && (*p != '\0')) {
  660. if (*p == '=') {
  661. printf("=");
  662. p ++;
  663. while ((*p != ' ') && (*p != '\0')) {
  664. printf("%c", *p);
  665. p ++;
  666. }
  667. } else {
  668. printf("%c", *p);
  669. p ++;
  670. if ((*p == ' ') || (*p =='\0')) printf("=1");
  671. }
  672. }
  673. printf("\n");
  674. } else p ++;
  675. }
  676. #endif
  677. #endif
  678. #ifndef OS_WINDOWS
  679. printf("MAKE += -j %d\n", get_num_cores());
  680. #endif
  681. break;
  682. case '1' : /* For config.h */
  683. #ifdef FORCE
  684. sprintf(buffer, "%s -DCORE_%s\n", ARCHCONFIG, CORENAME);
  685. p = &buffer[0];
  686. while (*p) {
  687. if ((*p == '-') && (*(p + 1) == 'D')) {
  688. p += 2;
  689. printf("#define ");
  690. while ((*p != ' ') && (*p != '\0')) {
  691. if (*p == '=') {
  692. printf(" ");
  693. p ++;
  694. while ((*p != ' ') && (*p != '\0')) {
  695. printf("%c", *p);
  696. p ++;
  697. }
  698. } else {
  699. printf("%c", *p);
  700. p ++;
  701. }
  702. }
  703. printf("\n");
  704. } else p ++;
  705. }
  706. #else
  707. get_cpuconfig();
  708. #endif
  709. break;
  710. case '2' : /* SMP */
  711. if (get_num_cores() > 1) printf("SMP=1\n");
  712. break;
  713. }
  714. fflush(stdout);
  715. return 0;
  716. }