numexpr 2.10.2__cp313-cp313-win32.whl

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