cpuinfo.py 22 KB

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