Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/build/pkgs/atlas/enums.py
8815 views
1
"""
2
Verify that the ATLAS enums are in sync with the spkg-install enums
3
4
TESTS::
5
6
sage: check_enums(sample_print_enums_output)
7
"""
8
9
from __future__ import print_function
10
11
# constants from src/ATLAS/CONFIG/include/atlconf.h
12
# Note: must be lists, not tuples, for Python-2.4 support
13
14
ATLAS_OSTYPE = ( # static char *osnam
15
'UNKNOWN', 'Linux', 'SunOS', 'SunOS4', 'OSF1',
16
'IRIX', 'AIX', 'Win9x', 'WinNT', 'Win64',
17
'HPUX', 'FreeBSD', 'OSX')
18
19
ATLAS_MACHTYPE = ( # static char *machnam
20
'UNKNOWN', 'POWER3', 'POWER4', 'POWER5', 'PPCG4', 'PPCG5',
21
'POWER6', 'POWER7', 'IBMz9', 'IBMz10', 'IBMz196',
22
'x86x87', 'x86SSE1', 'x86SSE2', 'x86SSE3',
23
'P5', 'P5MMX', 'PPRO', 'PII', 'PIII', 'PM', 'CoreSolo',
24
'CoreDuo', 'Core2Solo', 'Core2', 'Corei1', 'Corei2', 'Atom', 'P4', 'P4E',
25
'Efficeon', 'K7', 'HAMMER', 'AMD64K10h', 'AMDDOZER', 'UNKNOWNx86',
26
'IA64Itan', 'IA64Itan2',
27
'USI', 'USII', 'USIII', 'USIV', 'UST2', 'UnknownUS',
28
'MIPSR1xK', 'MIPSICE9', 'ARMv7')
29
30
ATLAS_ISAEXT = ( # static char *ISAXNAM
31
'None', 'VSX', 'AltiVec', 'AVXMAC', 'AVXFMA4', 'AVX', 'SSE3', 'SSE2', 'SSE1',
32
'3DNow', 'NEON' )
33
34
35
36
# for doctesting purposes
37
sample_print_enums_output = \
38
"""
39
Architectural enums (Config's enum MACHTYPE):
40
0 = 'UNKNOWN'
41
1 = 'POWER3'
42
2 = 'POWER4'
43
3 = 'POWER5'
44
4 = 'PPCG4'
45
5 = 'PPCG5'
46
6 = 'POWER6'
47
7 = 'POWER7'
48
8 = 'IBMz9'
49
9 = 'IBMz10'
50
10 = 'IBMz196'
51
11 = 'x86x87'
52
12 = 'x86SSE1'
53
13 = 'x86SSE2'
54
14 = 'x86SSE3'
55
15 = 'P5'
56
16 = 'P5MMX'
57
17 = 'PPRO'
58
18 = 'PII'
59
19 = 'PIII'
60
20 = 'PM'
61
21 = 'CoreSolo'
62
22 = 'CoreDuo'
63
23 = 'Core2Solo'
64
24 = 'Core2'
65
25 = 'Corei1'
66
26 = 'Corei2'
67
27 = 'Atom'
68
28 = 'P4'
69
29 = 'P4E'
70
30 = 'Efficeon'
71
31 = 'K7'
72
32 = 'HAMMER'
73
33 = 'AMD64K10h'
74
34 = 'AMDDOZER'
75
35 = 'UNKNOWNx86'
76
36 = 'IA64Itan'
77
37 = 'IA64Itan2'
78
38 = 'USI'
79
39 = 'USII'
80
40 = 'USIII'
81
41 = 'USIV'
82
42 = 'UST2'
83
43 = 'UnknownUS'
84
44 = 'MIPSR1xK'
85
45 = 'MIPSICE9'
86
46 = 'ARMv7'
87
88
Operating System enums (Config's enum OSTYPE):
89
0 = 'UNKNOWN'
90
1 = 'Linux'
91
2 = 'SunOS'
92
3 = 'SunOS4'
93
4 = 'OSF1'
94
5 = 'IRIX'
95
6 = 'AIX'
96
7 = 'Win9x'
97
8 = 'WinNT'
98
9 = 'Win64'
99
10 = 'HPUX'
100
11 = 'FreeBSD'
101
12 = 'OSX'
102
103
Compiler integer defines:
104
0 = 'ICC'
105
1 = 'SMC'
106
2 = 'DMC'
107
3 = 'SKC'
108
4 = 'DKC'
109
5 = 'XCC'
110
6 = 'GCC'
111
7 = 'F77'
112
113
114
ISA extensions are combined by adding their values together (bitvector):
115
none: 1
116
VSX: 2
117
AltiVec: 4
118
AVXMAC: 8
119
AVXFMA4: 16
120
AVX: 32
121
SSE3: 64
122
SSE2: 128
123
SSE1: 256
124
3DNow: 512
125
NEON: 1024
126
127
"""
128
129
130
def check_enums(print_enums_output):
131
"""
132
Verify that the output of ATLAS print_enums matches our enums
133
134
INPUT:
135
136
- ``print_enums_output`` -- string. The output of the ATLAS
137
print_enums utility.
138
"""
139
lines = print_enums_output.splitlines()
140
found_MACHTYPE = found_OSTYPE = found_ISAEXT = False
141
while len(lines) > 0:
142
line = lines.pop(0)
143
if line.startswith('Architectural enums'):
144
check_enums_ATLAS_MACHTYPE(lines)
145
found_MACHTYPE = True
146
if line.startswith('Operating System enums'):
147
check_enums_ATLAS_OSTYPE(lines)
148
found_OSTYPE = True
149
if line.startswith('ISA extensions'):
150
check_enums_ATLAS_ISAEXT(lines)
151
found_ISAEXT = True
152
if not (found_MACHTYPE and found_OSTYPE and found_ISAEXT):
153
raise RuntimeError('failed to parse the output of print_enums')
154
155
156
def check_enums_ATLAS_MACHTYPE(lines):
157
for i, mach_type in enumerate(ATLAS_MACHTYPE):
158
got = lines.pop(0).strip()
159
expect = "{0} = '{1}'".format(i, mach_type)
160
if got != expect:
161
raise RuntimeError('ATLAS_MACHTYPE mismatch at position '+str(i)+
162
': got >>'+got+'<<, expected >>'+expect+'<<')
163
164
def check_enums_ATLAS_OSTYPE(lines):
165
for i, os_type in enumerate(ATLAS_OSTYPE):
166
got = lines.pop(0).strip()
167
expect = "{0} = '{1}'".format(i, os_type)
168
if got != expect:
169
raise RuntimeError('ATLAS_OSTYPE mismatch at position '+str(i)+
170
': got >>'+got+'<<, expected >>'+expect+'<<')
171
172
def check_enums_ATLAS_ISAEXT(lines):
173
for i, isaext in enumerate(ATLAS_ISAEXT):
174
got = lines.pop(0).strip()
175
if i == 0:
176
expect = 'none: 1'
177
else:
178
expect = "{0}: {1}".format(isaext, 1 << i)
179
if got != expect:
180
raise RuntimeError('ATLAS_ISAEXT mismatch at position '+str(i)+
181
': got >>'+got+'<<, expected >>'+expect+'<<')
182
183
184
def make_check_enums():
185
"""
186
Build the print_enums utility and check its output against our
187
enums
188
189
You can only call this function when you are in the atlas build
190
directory, and only after configuring atlas.
191
"""
192
from subprocess import check_output
193
output = check_output('make xprint_enums ; ./xprint_enums', shell=True)
194
print(output)
195
check_enums(output)
196
197
198