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