1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
"""Classes for describing settings and groups of settings."""
# noqa
=
# noqa
pass
"""
A named setting variable that can be configured externally to Cranelift.
Settings are normally not named when they are created. They get their name
from the `extract_names` method.
"""
# type: (str) -> None
= None # type: str # Assigned later by `extract_names()`.
=
# Offset of byte in settings vector containing this setting.
= None # type: int
# Index into the generated DESCRIPTORS table.
= None # type: int
=
# type: () -> str
return
# type: () -> int
# type: (Any) -> int
"""Get the setting byte value that corresponds to `value`"""
# type: () -> int
"""Get a mask of bits in our byte that are relevant to this setting."""
# Only BoolSetting has a different mask.
return 0xff
"""
A named setting with a boolean on/off value.
:param doc: Documentation string.
:param default: The default value of this setting.
"""
# type: (str, bool) -> None
=
= None # type: int
# type: () -> int
"""
Get the default value of this setting, as a byte that can be bitwise
or'ed with the other booleans sharing the same byte.
"""
return 1 <<
return 0
# type: (Any) -> int
return 1 <<
return 0
# type: () -> int
return 1 <<
# type: () -> SettingGroup
"""
Return the context where this setting can be evaluated as a (leaf)
predicate.
"""
return
# type: () -> PredKey
assert ,
return
# type: (Set[PredLeaf]) -> None
# type: (int) -> str
"""
Return the Rust code to compute the value of this setting.
The emitted code assumes that the setting group exists as a local
variable.
"""
return
"""
A named setting with an integral value in the range 0--255.
:param doc: Documentation string.
:param default: The default value of this setting.
"""
# type: (str, int) -> None
assert ==
assert >= 0 and <= 255
=
# type: () -> int
return
# type: (Any) -> int
assert ,
assert >= 0 and <= 255
return
"""
A named setting with an enumerated set of possible values.
The default value is always the first enumerator.
:param doc: Documentation string.
:param args: Tuple of unique strings representing the possible values.
"""
# type: (str, *str) -> None
assert > 0,
=
=
# type: () -> int
return 0
# type: (Any) -> int
return
"""
A group of settings.
Whenever a :class:`Setting` object is created, it is added to the currently
open group. A setting group must be closed explicitly before another can be
opened.
:param name: Short mnemonic name for setting group.
:param parent: Parent settings group.
"""
# The currently open setting group.
= None # type: SettingGroup
# type: (str, SettingGroup) -> None
=
=
= # type: List[Setting]
# Named predicates computed from settings in this group or its
# parents.
= # type: OrderedDict[str, Predicate] # noqa
# All boolean predicates that can be accessed by number. This includes:
# - All boolean settings in this group.
# - All named predicates.
# - Added anonymous predicates, see `number_predicate()`.
# - Added parent predicates that are replicated in this group.
# Maps predicate -> number.
= # type: OrderedDict[PredNode, int] # noqa
= # type: List[Preset]
# Fully qualified Rust module name. See gen_settings.py.
= None # type: str
# type: () -> None
"""
Open this setting group such that future new settings are added to this
group.
"""
assert is None,
=
# type: (Dict[str, Any]) -> None
"""
Close this setting group. This function must be called before opening
another setting group.
:param globs: Pass in `globals()` to run `extract_names` on all
settings defined in the module.
"""
assert is ,
= None
assert is None,
=
=
assert is None,
=
# type: (Setting) -> SettingGroup
=
assert ,
return
# type: (Preset) -> SettingGroup
=
assert ,
return
# type: (PredNode) -> int
"""
Make sure that `pred` has an assigned number, and will be included in
this group's bit vector.
The numbered predicates include:
- `BoolSetting` settings that belong to this group.
- `Predicate` instances in `named_predicates`.
- `Predicate` instances without a name.
- Settings or computed predicates that belong to the parent group, but
need to be accessible by number in this group.
The numbered predicates are referenced by the encoding tables as ISA
predicates. See the `isap` field on `Encoding`.
:returns: The assigned predicate number in this group.
"""
return
=
=
return
# type: () -> None
"""
Compute the layout of the byte vector used to represent this settings
group.
The byte vector contains the following entries in order:
1. Byte-sized settings like `NumSetting` and `EnumSetting`.
2. `BoolSetting` settings.
3. Precomputed named predicates.
4. Other numbered predicates, including anonymous predicates and parent
predicates that need to be accessible by number.
Set `self.settings_size` to the length of the byte vector prefix that
contains the settings. All bytes after that are computed, not
configured.
Set `self.boolean_offset` to the beginning of the numbered predicates,
2. in the list above.
Assign `byte_offset` and `bit_offset` fields in all settings.
After calling this method, no more settings can be added, but
additional predicates can be made accessible with `number_predicate()`.
"""
assert == 0,
# Assign the non-boolean settings.
= 0
=
+= 1
# Then the boolean settings.
=
=
= + // 8
= % 8
# This is the end of the settings. Round up to a whole number of bytes.
=
=
# Now assign numbers to all our named predicates.
# type: () -> int
"""
Compute the number of bytes required to hold all settings and
precomputed predicates.
This is the size of the byte-sized settings plus all the numbered
predcate bits rounded up to a whole number of bytes.
"""
return + // 8
"""
A collection of setting values that are applied at once.
A `Preset` represents a shorthand notation for applying a number of
settings at once. Example:
nehalem = Preset(has_sse41, has_cmov, has_avx=0)
Enabling the `nehalem` setting is equivalent to enabling `has_sse41` and
`has_cmov` while disabling the `has_avx` setting.
"""
# type: (*BoolOrPresetOrDict) -> None
= None # type: str # Assigned later by `SettingGroup`.
# Each tuple provides the value for a setting.
= # type: List[Tuple[Setting, Any]]
# Any presets in args are immediately expanded.
# A dictionary of key: value pairs.
# A BoolSetting to enable.
assert
=
# Index into the generated DESCRIPTORS table.
= None # type: int
# type: () -> List[Tuple[int, int]]
"""
Compute a list of (mask, byte) pairs that incorporate all values in
this preset.
The list will have an entry for each setting byte in the settings
group.
"""
= *
# Apply setting values in order.
=
=
=
assert == 0
, =
# Accumulated mask of modified bits.
|=
# Overwrite the relevant bits with the new value.
= |
=
return