cpuinfo.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. #!/usr/bin/env python
  2. """
  3. cpuinfo
  4. Copyright 2002 Pearu Peterson all rights reserved,
  5. Pearu Peterson <pearu@cens.ioc.ee>
  6. Permission to use, modify, and distribute this software is given under the
  7. terms of the NumPy (BSD style) license. See LICENSE.txt that came with
  8. this distribution for specifics.
  9. NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
  10. Pearu Peterson
  11. """
  12. from __future__ import division, absolute_import, print_function
  13. __all__ = ['cpu']
  14. import sys, re, types
  15. import os
  16. if sys.version_info[0] >= 3:
  17. from subprocess import getstatusoutput
  18. else:
  19. from commands import getstatusoutput
  20. import warnings
  21. import platform
  22. from numpy.distutils.compat import get_exception
  23. def getoutput(cmd, successful_status=(0,), stacklevel=1):
  24. try:
  25. status, output = getstatusoutput(cmd)
  26. except EnvironmentError:
  27. e = get_exception()
  28. warnings.warn(str(e), UserWarning, stacklevel=stacklevel)
  29. return False, ""
  30. if os.WIFEXITED(status) and os.WEXITSTATUS(status) in successful_status:
  31. return True, output
  32. return False, output
  33. def command_info(successful_status=(0,), stacklevel=1, **kw):
  34. info = {}
  35. for key in kw:
  36. ok, output = getoutput(kw[key], successful_status=successful_status,
  37. stacklevel=stacklevel+1)
  38. if ok:
  39. info[key] = output.strip()
  40. return info
  41. def command_by_line(cmd, successful_status=(0,), stacklevel=1):
  42. ok, output = getoutput(cmd, successful_status=successful_status,
  43. stacklevel=stacklevel+1)
  44. if not ok:
  45. return
  46. for line in output.splitlines():
  47. yield line.strip()
  48. def key_value_from_command(cmd, sep, successful_status=(0,),
  49. stacklevel=1):
  50. d = {}
  51. for line in command_by_line(cmd, successful_status=successful_status,
  52. stacklevel=stacklevel+1):
  53. l = [s.strip() for s in line.split(sep, 1)]
  54. if len(l) == 2:
  55. d[l[0]] = l[1]
  56. return d
  57. class CPUInfoBase(object):
  58. """Holds CPU information and provides methods for requiring
  59. the availability of various CPU features.
  60. """
  61. def _try_call(self, func):
  62. try:
  63. return func()
  64. except Exception:
  65. pass
  66. def __getattr__(self, name):
  67. if not name.startswith('_'):
  68. if hasattr(self, '_'+name):
  69. attr = getattr(self, '_'+name)
  70. if isinstance(attr, types.MethodType):
  71. return lambda func=self._try_call,attr=attr : func(attr)
  72. else:
  73. return lambda : None
  74. raise AttributeError(name)
  75. def _getNCPUs(self):
  76. return 1
  77. def __get_nbits(self):
  78. abits = platform.architecture()[0]
  79. nbits = re.compile(r'(\d+)bit').search(abits).group(1)
  80. return nbits
  81. def _is_32bit(self):
  82. return self.__get_nbits() == '32'
  83. def _is_64bit(self):
  84. return self.__get_nbits() == '64'
  85. class LinuxCPUInfo(CPUInfoBase):
  86. info = None
  87. def __init__(self):
  88. if self.info is not None:
  89. return
  90. info = [ {} ]
  91. ok, output = getoutput('uname -m')
  92. if ok:
  93. info[0]['uname_m'] = output.strip()
  94. try:
  95. fo = open('/proc/cpuinfo')
  96. except EnvironmentError:
  97. e = get_exception()
  98. warnings.warn(str(e), UserWarning, stacklevel=2)
  99. else:
  100. for line in fo:
  101. name_value = [s.strip() for s in line.split(':', 1)]
  102. if len(name_value) != 2:
  103. continue
  104. name, value = name_value
  105. if not info or name in info[-1]: # next processor
  106. info.append({})
  107. info[-1][name] = value
  108. fo.close()
  109. self.__class__.info = info
  110. def _not_impl(self): pass
  111. # Athlon
  112. def _is_AMD(self):
  113. return self.info[0]['vendor_id']=='AuthenticAMD'
  114. def _is_AthlonK6_2(self):
  115. return self._is_AMD() and self.info[0]['model'] == '2'
  116. def _is_AthlonK6_3(self):
  117. return self._is_AMD() and self.info[0]['model'] == '3'
  118. def _is_AthlonK6(self):
  119. return re.match(r'.*?AMD-K6', self.info[0]['model name']) is not None
  120. def _is_AthlonK7(self):
  121. return re.match(r'.*?AMD-K7', self.info[0]['model name']) is not None
  122. def _is_AthlonMP(self):
  123. return re.match(r'.*?Athlon\(tm\) MP\b',
  124. self.info[0]['model name']) is not None
  125. def _is_AMD64(self):
  126. return self.is_AMD() and self.info[0]['family'] == '15'
  127. def _is_Athlon64(self):
  128. return re.match(r'.*?Athlon\(tm\) 64\b',
  129. self.info[0]['model name']) is not None
  130. def _is_AthlonHX(self):
  131. return re.match(r'.*?Athlon HX\b',
  132. self.info[0]['model name']) is not None
  133. def _is_Opteron(self):
  134. return re.match(r'.*?Opteron\b',
  135. self.info[0]['model name']) is not None
  136. def _is_Hammer(self):
  137. return re.match(r'.*?Hammer\b',
  138. self.info[0]['model name']) is not None
  139. # Alpha
  140. def _is_Alpha(self):
  141. return self.info[0]['cpu']=='Alpha'
  142. def _is_EV4(self):
  143. return self.is_Alpha() and self.info[0]['cpu model'] == 'EV4'
  144. def _is_EV5(self):
  145. return self.is_Alpha() and self.info[0]['cpu model'] == 'EV5'
  146. def _is_EV56(self):
  147. return self.is_Alpha() and self.info[0]['cpu model'] == 'EV56'
  148. def _is_PCA56(self):
  149. return self.is_Alpha() and self.info[0]['cpu model'] == 'PCA56'
  150. # Intel
  151. #XXX
  152. _is_i386 = _not_impl
  153. def _is_Intel(self):
  154. return self.info[0]['vendor_id']=='GenuineIntel'
  155. def _is_i486(self):
  156. return self.info[0]['cpu']=='i486'
  157. def _is_i586(self):
  158. return self.is_Intel() and self.info[0]['cpu family'] == '5'
  159. def _is_i686(self):
  160. return self.is_Intel() and self.info[0]['cpu family'] == '6'
  161. def _is_Celeron(self):
  162. return re.match(r'.*?Celeron',
  163. self.info[0]['model name']) is not None
  164. def _is_Pentium(self):
  165. return re.match(r'.*?Pentium',
  166. self.info[0]['model name']) is not None
  167. def _is_PentiumII(self):
  168. return re.match(r'.*?Pentium.*?II\b',
  169. self.info[0]['model name']) is not None
  170. def _is_PentiumPro(self):
  171. return re.match(r'.*?PentiumPro\b',
  172. self.info[0]['model name']) is not None
  173. def _is_PentiumMMX(self):
  174. return re.match(r'.*?Pentium.*?MMX\b',
  175. self.info[0]['model name']) is not None
  176. def _is_PentiumIII(self):
  177. return re.match(r'.*?Pentium.*?III\b',
  178. self.info[0]['model name']) is not None
  179. def _is_PentiumIV(self):
  180. return re.match(r'.*?Pentium.*?(IV|4)\b',
  181. self.info[0]['model name']) is not None
  182. def _is_PentiumM(self):
  183. return re.match(r'.*?Pentium.*?M\b',
  184. self.info[0]['model name']) is not None
  185. def _is_Prescott(self):
  186. return self.is_PentiumIV() and self.has_sse3()
  187. def _is_Nocona(self):
  188. return self.is_Intel() \
  189. and (self.info[0]['cpu family'] == '6' \
  190. or self.info[0]['cpu family'] == '15' ) \
  191. and (self.has_sse3() and not self.has_ssse3())\
  192. and re.match(r'.*?\blm\b', self.info[0]['flags']) is not None
  193. def _is_Core2(self):
  194. return self.is_64bit() and self.is_Intel() and \
  195. re.match(r'.*?Core\(TM\)2\b', \
  196. self.info[0]['model name']) is not None
  197. def _is_Itanium(self):
  198. return re.match(r'.*?Itanium\b',
  199. self.info[0]['family']) is not None
  200. def _is_XEON(self):
  201. return re.match(r'.*?XEON\b',
  202. self.info[0]['model name'], re.IGNORECASE) is not None
  203. _is_Xeon = _is_XEON
  204. # Varia
  205. def _is_singleCPU(self):
  206. return len(self.info) == 1
  207. def _getNCPUs(self):
  208. return len(self.info)
  209. def _has_fdiv_bug(self):
  210. return self.info[0]['fdiv_bug']=='yes'
  211. def _has_f00f_bug(self):
  212. return self.info[0]['f00f_bug']=='yes'
  213. def _has_mmx(self):
  214. return re.match(r'.*?\bmmx\b', self.info[0]['flags']) is not None
  215. def _has_sse(self):
  216. return re.match(r'.*?\bsse\b', self.info[0]['flags']) is not None
  217. def _has_sse2(self):
  218. return re.match(r'.*?\bsse2\b', self.info[0]['flags']) is not None
  219. def _has_sse3(self):
  220. return re.match(r'.*?\bpni\b', self.info[0]['flags']) is not None
  221. def _has_ssse3(self):
  222. return re.match(r'.*?\bssse3\b', self.info[0]['flags']) is not None
  223. def _has_3dnow(self):
  224. return re.match(r'.*?\b3dnow\b', self.info[0]['flags']) is not None
  225. def _has_3dnowext(self):
  226. return re.match(r'.*?\b3dnowext\b', self.info[0]['flags']) is not None
  227. class IRIXCPUInfo(CPUInfoBase):
  228. info = None
  229. def __init__(self):
  230. if self.info is not None:
  231. return
  232. info = key_value_from_command('sysconf', sep=' ',
  233. successful_status=(0, 1))
  234. self.__class__.info = info
  235. def _not_impl(self): pass
  236. def _is_singleCPU(self):
  237. return self.info.get('NUM_PROCESSORS') == '1'
  238. def _getNCPUs(self):
  239. return int(self.info.get('NUM_PROCESSORS', 1))
  240. def __cputype(self, n):
  241. return self.info.get('PROCESSORS').split()[0].lower() == 'r%s' % (n)
  242. def _is_r2000(self): return self.__cputype(2000)
  243. def _is_r3000(self): return self.__cputype(3000)
  244. def _is_r3900(self): return self.__cputype(3900)
  245. def _is_r4000(self): return self.__cputype(4000)
  246. def _is_r4100(self): return self.__cputype(4100)
  247. def _is_r4300(self): return self.__cputype(4300)
  248. def _is_r4400(self): return self.__cputype(4400)
  249. def _is_r4600(self): return self.__cputype(4600)
  250. def _is_r4650(self): return self.__cputype(4650)
  251. def _is_r5000(self): return self.__cputype(5000)
  252. def _is_r6000(self): return self.__cputype(6000)
  253. def _is_r8000(self): return self.__cputype(8000)
  254. def _is_r10000(self): return self.__cputype(10000)
  255. def _is_r12000(self): return self.__cputype(12000)
  256. def _is_rorion(self): return self.__cputype('orion')
  257. def get_ip(self):
  258. try: return self.info.get('MACHINE')
  259. except Exception: pass
  260. def __machine(self, n):
  261. return self.info.get('MACHINE').lower() == 'ip%s' % (n)
  262. def _is_IP19(self): return self.__machine(19)
  263. def _is_IP20(self): return self.__machine(20)
  264. def _is_IP21(self): return self.__machine(21)
  265. def _is_IP22(self): return self.__machine(22)
  266. def _is_IP22_4k(self): return self.__machine(22) and self._is_r4000()
  267. def _is_IP22_5k(self): return self.__machine(22) and self._is_r5000()
  268. def _is_IP24(self): return self.__machine(24)
  269. def _is_IP25(self): return self.__machine(25)
  270. def _is_IP26(self): return self.__machine(26)
  271. def _is_IP27(self): return self.__machine(27)
  272. def _is_IP28(self): return self.__machine(28)
  273. def _is_IP30(self): return self.__machine(30)
  274. def _is_IP32(self): return self.__machine(32)
  275. def _is_IP32_5k(self): return self.__machine(32) and self._is_r5000()
  276. def _is_IP32_10k(self): return self.__machine(32) and self._is_r10000()
  277. class DarwinCPUInfo(CPUInfoBase):
  278. info = None
  279. def __init__(self):
  280. if self.info is not None:
  281. return
  282. info = command_info(arch='arch',
  283. machine='machine')
  284. info['sysctl_hw'] = key_value_from_command('sysctl hw', sep='=')
  285. self.__class__.info = info
  286. def _not_impl(self): pass
  287. def _getNCPUs(self):
  288. return int(self.info['sysctl_hw'].get('hw.ncpu', 1))
  289. def _is_Power_Macintosh(self):
  290. return self.info['sysctl_hw']['hw.machine']=='Power Macintosh'
  291. def _is_i386(self):
  292. return self.info['arch']=='i386'
  293. def _is_ppc(self):
  294. return self.info['arch']=='ppc'
  295. def __machine(self, n):
  296. return self.info['machine'] == 'ppc%s'%n
  297. def _is_ppc601(self): return self.__machine(601)
  298. def _is_ppc602(self): return self.__machine(602)
  299. def _is_ppc603(self): return self.__machine(603)
  300. def _is_ppc603e(self): return self.__machine('603e')
  301. def _is_ppc604(self): return self.__machine(604)
  302. def _is_ppc604e(self): return self.__machine('604e')
  303. def _is_ppc620(self): return self.__machine(620)
  304. def _is_ppc630(self): return self.__machine(630)
  305. def _is_ppc740(self): return self.__machine(740)
  306. def _is_ppc7400(self): return self.__machine(7400)
  307. def _is_ppc7450(self): return self.__machine(7450)
  308. def _is_ppc750(self): return self.__machine(750)
  309. def _is_ppc403(self): return self.__machine(403)
  310. def _is_ppc505(self): return self.__machine(505)
  311. def _is_ppc801(self): return self.__machine(801)
  312. def _is_ppc821(self): return self.__machine(821)
  313. def _is_ppc823(self): return self.__machine(823)
  314. def _is_ppc860(self): return self.__machine(860)
  315. class SunOSCPUInfo(CPUInfoBase):
  316. info = None
  317. def __init__(self):
  318. if self.info is not None:
  319. return
  320. info = command_info(arch='arch',
  321. mach='mach',
  322. uname_i='uname_i',
  323. isainfo_b='isainfo -b',
  324. isainfo_n='isainfo -n',
  325. )
  326. info['uname_X'] = key_value_from_command('uname -X', sep='=')
  327. for line in command_by_line('psrinfo -v 0'):
  328. m = re.match(r'\s*The (?P<p>[\w\d]+) processor operates at', line)
  329. if m:
  330. info['processor'] = m.group('p')
  331. break
  332. self.__class__.info = info
  333. def _not_impl(self): pass
  334. def _is_i386(self):
  335. return self.info['isainfo_n']=='i386'
  336. def _is_sparc(self):
  337. return self.info['isainfo_n']=='sparc'
  338. def _is_sparcv9(self):
  339. return self.info['isainfo_n']=='sparcv9'
  340. def _getNCPUs(self):
  341. return int(self.info['uname_X'].get('NumCPU', 1))
  342. def _is_sun4(self):
  343. return self.info['arch']=='sun4'
  344. def _is_SUNW(self):
  345. return re.match(r'SUNW', self.info['uname_i']) is not None
  346. def _is_sparcstation5(self):
  347. return re.match(r'.*SPARCstation-5', self.info['uname_i']) is not None
  348. def _is_ultra1(self):
  349. return re.match(r'.*Ultra-1', self.info['uname_i']) is not None
  350. def _is_ultra250(self):
  351. return re.match(r'.*Ultra-250', self.info['uname_i']) is not None
  352. def _is_ultra2(self):
  353. return re.match(r'.*Ultra-2', self.info['uname_i']) is not None
  354. def _is_ultra30(self):
  355. return re.match(r'.*Ultra-30', self.info['uname_i']) is not None
  356. def _is_ultra4(self):
  357. return re.match(r'.*Ultra-4', self.info['uname_i']) is not None
  358. def _is_ultra5_10(self):
  359. return re.match(r'.*Ultra-5_10', self.info['uname_i']) is not None
  360. def _is_ultra5(self):
  361. return re.match(r'.*Ultra-5', self.info['uname_i']) is not None
  362. def _is_ultra60(self):
  363. return re.match(r'.*Ultra-60', self.info['uname_i']) is not None
  364. def _is_ultra80(self):
  365. return re.match(r'.*Ultra-80', self.info['uname_i']) is not None
  366. def _is_ultraenterprice(self):
  367. return re.match(r'.*Ultra-Enterprise', self.info['uname_i']) is not None
  368. def _is_ultraenterprice10k(self):
  369. return re.match(r'.*Ultra-Enterprise-10000', self.info['uname_i']) is not None
  370. def _is_sunfire(self):
  371. return re.match(r'.*Sun-Fire', self.info['uname_i']) is not None
  372. def _is_ultra(self):
  373. return re.match(r'.*Ultra', self.info['uname_i']) is not None
  374. def _is_cpusparcv7(self):
  375. return self.info['processor']=='sparcv7'
  376. def _is_cpusparcv8(self):
  377. return self.info['processor']=='sparcv8'
  378. def _is_cpusparcv9(self):
  379. return self.info['processor']=='sparcv9'
  380. class Win32CPUInfo(CPUInfoBase):
  381. info = None
  382. pkey = r"HARDWARE\DESCRIPTION\System\CentralProcessor"
  383. # XXX: what does the value of
  384. # HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0
  385. # mean?
  386. def __init__(self):
  387. if self.info is not None:
  388. return
  389. info = []
  390. try:
  391. #XXX: Bad style to use so long `try:...except:...`. Fix it!
  392. if sys.version_info[0] >= 3:
  393. import winreg
  394. else:
  395. import _winreg as winreg
  396. prgx = re.compile(r"family\s+(?P<FML>\d+)\s+model\s+(?P<MDL>\d+)"
  397. r"\s+stepping\s+(?P<STP>\d+)", re.IGNORECASE)
  398. chnd=winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, self.pkey)
  399. pnum=0
  400. while True:
  401. try:
  402. proc=winreg.EnumKey(chnd, pnum)
  403. except winreg.error:
  404. break
  405. else:
  406. pnum+=1
  407. info.append({"Processor":proc})
  408. phnd=winreg.OpenKey(chnd, proc)
  409. pidx=0
  410. while True:
  411. try:
  412. name, value, vtpe=winreg.EnumValue(phnd, pidx)
  413. except winreg.error:
  414. break
  415. else:
  416. pidx=pidx+1
  417. info[-1][name]=value
  418. if name=="Identifier":
  419. srch=prgx.search(value)
  420. if srch:
  421. info[-1]["Family"]=int(srch.group("FML"))
  422. info[-1]["Model"]=int(srch.group("MDL"))
  423. info[-1]["Stepping"]=int(srch.group("STP"))
  424. except Exception:
  425. print(sys.exc_info()[1], '(ignoring)')
  426. self.__class__.info = info
  427. def _not_impl(self): pass
  428. # Athlon
  429. def _is_AMD(self):
  430. return self.info[0]['VendorIdentifier']=='AuthenticAMD'
  431. def _is_Am486(self):
  432. return self.is_AMD() and self.info[0]['Family']==4
  433. def _is_Am5x86(self):
  434. return self.is_AMD() and self.info[0]['Family']==4
  435. def _is_AMDK5(self):
  436. return self.is_AMD() and self.info[0]['Family']==5 \
  437. and self.info[0]['Model'] in [0, 1, 2, 3]
  438. def _is_AMDK6(self):
  439. return self.is_AMD() and self.info[0]['Family']==5 \
  440. and self.info[0]['Model'] in [6, 7]
  441. def _is_AMDK6_2(self):
  442. return self.is_AMD() and self.info[0]['Family']==5 \
  443. and self.info[0]['Model']==8
  444. def _is_AMDK6_3(self):
  445. return self.is_AMD() and self.info[0]['Family']==5 \
  446. and self.info[0]['Model']==9
  447. def _is_AMDK7(self):
  448. return self.is_AMD() and self.info[0]['Family'] == 6
  449. # To reliably distinguish between the different types of AMD64 chips
  450. # (Athlon64, Operton, Athlon64 X2, Semperon, Turion 64, etc.) would
  451. # require looking at the 'brand' from cpuid
  452. def _is_AMD64(self):
  453. return self.is_AMD() and self.info[0]['Family'] == 15
  454. # Intel
  455. def _is_Intel(self):
  456. return self.info[0]['VendorIdentifier']=='GenuineIntel'
  457. def _is_i386(self):
  458. return self.info[0]['Family']==3
  459. def _is_i486(self):
  460. return self.info[0]['Family']==4
  461. def _is_i586(self):
  462. return self.is_Intel() and self.info[0]['Family']==5
  463. def _is_i686(self):
  464. return self.is_Intel() and self.info[0]['Family']==6
  465. def _is_Pentium(self):
  466. return self.is_Intel() and self.info[0]['Family']==5
  467. def _is_PentiumMMX(self):
  468. return self.is_Intel() and self.info[0]['Family']==5 \
  469. and self.info[0]['Model']==4
  470. def _is_PentiumPro(self):
  471. return self.is_Intel() and self.info[0]['Family']==6 \
  472. and self.info[0]['Model']==1
  473. def _is_PentiumII(self):
  474. return self.is_Intel() and self.info[0]['Family']==6 \
  475. and self.info[0]['Model'] in [3, 5, 6]
  476. def _is_PentiumIII(self):
  477. return self.is_Intel() and self.info[0]['Family']==6 \
  478. and self.info[0]['Model'] in [7, 8, 9, 10, 11]
  479. def _is_PentiumIV(self):
  480. return self.is_Intel() and self.info[0]['Family']==15
  481. def _is_PentiumM(self):
  482. return self.is_Intel() and self.info[0]['Family'] == 6 \
  483. and self.info[0]['Model'] in [9, 13, 14]
  484. def _is_Core2(self):
  485. return self.is_Intel() and self.info[0]['Family'] == 6 \
  486. and self.info[0]['Model'] in [15, 16, 17]
  487. # Varia
  488. def _is_singleCPU(self):
  489. return len(self.info) == 1
  490. def _getNCPUs(self):
  491. return len(self.info)
  492. def _has_mmx(self):
  493. if self.is_Intel():
  494. return (self.info[0]['Family']==5 and self.info[0]['Model']==4) \
  495. or (self.info[0]['Family'] in [6, 15])
  496. elif self.is_AMD():
  497. return self.info[0]['Family'] in [5, 6, 15]
  498. else:
  499. return False
  500. def _has_sse(self):
  501. if self.is_Intel():
  502. return (self.info[0]['Family']==6 and \
  503. self.info[0]['Model'] in [7, 8, 9, 10, 11]) \
  504. or self.info[0]['Family']==15
  505. elif self.is_AMD():
  506. return (self.info[0]['Family']==6 and \
  507. self.info[0]['Model'] in [6, 7, 8, 10]) \
  508. or self.info[0]['Family']==15
  509. else:
  510. return False
  511. def _has_sse2(self):
  512. if self.is_Intel():
  513. return self.is_Pentium4() or self.is_PentiumM() \
  514. or self.is_Core2()
  515. elif self.is_AMD():
  516. return self.is_AMD64()
  517. else:
  518. return False
  519. def _has_3dnow(self):
  520. return self.is_AMD() and self.info[0]['Family'] in [5, 6, 15]
  521. def _has_3dnowext(self):
  522. return self.is_AMD() and self.info[0]['Family'] in [6, 15]
  523. if sys.platform.startswith('linux'): # variations: linux2,linux-i386 (any others?)
  524. cpuinfo = LinuxCPUInfo
  525. elif sys.platform.startswith('irix'):
  526. cpuinfo = IRIXCPUInfo
  527. elif sys.platform == 'darwin':
  528. cpuinfo = DarwinCPUInfo
  529. elif sys.platform.startswith('sunos'):
  530. cpuinfo = SunOSCPUInfo
  531. elif sys.platform.startswith('win32'):
  532. cpuinfo = Win32CPUInfo
  533. elif sys.platform.startswith('cygwin'):
  534. cpuinfo = LinuxCPUInfo
  535. #XXX: other OS's. Eg. use _winreg on Win32. Or os.uname on unices.
  536. else:
  537. cpuinfo = CPUInfoBase
  538. cpu = cpuinfo()
  539. #if __name__ == "__main__":
  540. #
  541. # cpu.is_blaa()
  542. # cpu.is_Intel()
  543. # cpu.is_Alpha()
  544. #
  545. # print('CPU information:'),
  546. # for name in dir(cpuinfo):
  547. # if name[0]=='_' and name[1]!='_':
  548. # r = getattr(cpu,name[1:])()
  549. # if r:
  550. # if r!=1:
  551. # print('%s=%s' %(name[1:],r))
  552. # else:
  553. # print(name[1:]),
  554. # print()