-
Notifications
You must be signed in to change notification settings - Fork 18
/
vector_signatures_generator.py
executable file
·130 lines (109 loc) · 3.79 KB
/
vector_signatures_generator.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
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
#! /usr/bin/python
"""
Generate the .cc file with the signatures
of the vector functions.
"""
RESTRICT="__restrict__"
FUNCTIONS_LIST=["asin",
"atan",
"atan2",
"acos",
"cos",
"exp",
"inv",
"log",
"sin",
"isqrt",
"tan",
"identity",
"identity2D",
"fast_asin",
"fast_acos",
"fast_atan",
"fast_atan2",
"fast_cos",
"fast_exp",
"fast_inv",
"fast_approx_inv",
"fast_log",
"fast_sin",
"fast_isqrt",
"fast_approx_isqrt",
"fast_tan"]
VDT_VECTOR_HEADER='vdtMath.h'
VDT_VECTOR_IMPL='vdtMath_vector.cc'
#------------------------------------------------------------------
def create_vector_signature(fcn_name,is_double=False,is_impl=False):
# For single precision
suffix="fv"
float_suffix="f"
type="float"
if is_double:
suffix="v"
type="double"
float_suffix=""
prefix=""
vfcn_name="%s%s" %(fcn_name,suffix)
in_data_type="%s const * %s" %(type, RESTRICT)
out_data_type="%s* %s" %(type, RESTRICT)
new_fcn_name="%s%s" %(prefix,fcn_name)
code = "void %s%s(const uint32_t size, %s iarray, %s oarray)" %(new_fcn_name,suffix,in_data_type,out_data_type)
# " %s *al_iarray = (%s*) __builtin_assume_aligned(iarray, 16);\n"%(type,type) +\
# " %s *al_oarray = (%s*) __builtin_assume_aligned(oarray, 16);\n"%(type,type) +\
# Special case
if "atan2" in fcn_name or "identity2D" in fcn_name:
code = "void %s%s(const uint32_t size, %s iarray1, %s iarray2, %s oarray)" %(new_fcn_name,suffix,in_data_type,in_data_type,out_data_type)
if is_impl:
impl_code = "{\n"+\
" for (uint32_t i=0;i<size;++i)\n"+\
" oarray[i]=%s%s(iarray[i]);\n" %(new_fcn_name,float_suffix)+\
"}\n\n"
if "atan2" in fcn_name or "identity2D" in fcn_name:
impl_code = "{\n"+\
" for (uint32_t i=0;i<size;++i)\n"+\
" oarray[i]=%s%s(iarray1[i],iarray2[i]);\n" %(new_fcn_name,float_suffix)+\
"}\n\n"
code+=impl_code
else:
code += ";\n"
return code
#------------------------------------------------------------------
def create_vector_signatures(is_impl=False):
code="namespace vdt{\n"
for is_double in (True,False):
for fcn_name in sorted(FUNCTIONS_LIST):
code+=create_vector_signature(fcn_name,is_double,is_impl)
code += "} // end of vdt namespace"
return code
#------------------------------------------------------------------
def get_header_file():
code= "// Automatically generated\n"\
'#ifndef __VDT_VECTOR__\n'\
'#define __VDT_VECTOR__\n'\
'#include "%"\n' %VDT_VECTOR_HEADER+\
'#include "inttypes.h"\n'+\
create_vector_signatures(is_impl=False)+\
'\n'\
'#endif'
return code
#------------------------------------------------------------------
def get_impl_file():
code= "// Automatically generated\n"+\
'#include "%s"\n' %VDT_VECTOR_HEADER+\
create_vector_signatures(is_impl=True)+\
"\n"# the final newline
return code
#------------------------------------------------------------------
def create_header():
ofile=file(VDT_VECTOR_HEADER,'w')
ofile.write(get_header_file())
ofile.close()
#------------------------------------------------------------------
def create_impl():
ofile=file(VDT_VECTOR_IMPL,'w')
ofile.write(get_impl_file())
ofile.close()
#------------------------------------------------------------------
if __name__ == "__main__":
#create_header()
create_impl()