-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.py
28 lines (23 loc) · 871 Bytes
/
misc.py
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
def pack(words, wordsize=32):
data = 0
for i, word in enumerate(words):
data = data | ((word & (2**wordsize-1)) << i*wordsize)
return data
def unpack(data, n, wordsize=32):
words = []
for i in range(n):
words.append((data >> i*wordsize) & (2**wordsize-1))
return words
def repack(data, n, wordsize=32):
packed_data = []
for i in range(0, len(data), n):
packed_data.append(pack(data[i:min(i+n, len(data))], wordsize=wordsize))
return packed_data
def get_simulators(module, name, *args, **kwargs):
simulators = []
if hasattr(module, name):
simulators.append(getattr(module, name)(*args, **kwargs))
for _, submodule in module._submodules:
for simulator in get_simulators(submodule, name, *args, **kwargs):
simulators.append(simulator)
return simulators