-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstants.py
More file actions
102 lines (83 loc) · 2.49 KB
/
Copy pathconstants.py
File metadata and controls
102 lines (83 loc) · 2.49 KB
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
import textwrap
def data(name, size, value, idx=0):
print 'DATA {name}<>+0x{idx:02x}(SB)/{size}, $({value})'.format(
name=name, idx=idx, size=size, value=value)
def header(name, doc):
print
assert doc.startswith(name)
assert doc[-1] == '.'
lines = textwrap.wrap(doc, width=78, initial_indent='// ', subsequent_indent='// ')
print '\n'.join(lines)
def declare(name, length):
print 'GLOBL {name}<>(SB), (RODATA+NOPTR), ${length}'.format(
name=name, length=length)
def output_float(name, doc, value):
"""
Output golang assembly DATA section for the given float value.
"""
header(name=name, doc=doc)
data(name=name, size=8, value='{:.18f}'.format(value))
declare(name=name, length=8)
def output_byte_array(name, doc, array):
"""
Output golang assembly DATA section for the given byte array.
"""
header(name=name, doc=doc)
for i, b in enumerate(array):
data(name=name, idx=i, size=1, value=b)
declare(name=name, length=len(array))
# Generated header.
print '// Generated by {filename}. DO NOT EDIT.'.format(
filename=__file__,
)
# Byte shuffle value for the byte stage of the interleaving.
shuf128 = [
0, 128, 1, 128, 2, 128, 3, 128,
8, 128, 9, 128, 10, 128, 11, 128,
]
output_byte_array(
'spreadbyte',
'spreadbyte is the VPSHUFB input required to spread bytes in each word.',
shuf128 * 2,
)
# "Lookup table" to perform spread operation on nibbles.
def spread(x):
s = 0
i = 0
while x:
s |= (x&1)<<i
x >>= 1
i += 2
return s
output_byte_array(
'spreadnibblelut',
'spreadnibblelut is a lookup table to perform 4-bit spread operations with VPSHUFB.',
list(map(spread, range(16))) * 2,
)
# Nibble masks.
output_byte_array(
'lonibblemask',
'lonibblemask selects the low nibble of each byte in a 64-bit word.',
[0x0f]*8,
)
output_byte_array(
'hinibblemask',
'hinibblemask selects the high nibble of each byte in a 64-bit word.',
[0xf0]*8,
)
# Floating point constants.
output_float(
'reciprocal180',
'reciprocal180 is the float 1/180.0 for quantization.',
1/180.0,
)
output_float(
'reciprocal360',
'reciprocal360 is the float 1/360.0 for quantization.',
1/360.0,
)
output_float(
'onepointfive',
'onepointfive is the float value 1.5 needed for quantization.',
1.5,
)