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