-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_spec1D.py
executable file
·98 lines (70 loc) · 2.47 KB
/
gen_spec1D.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
#!/usr/bin/python
from utils import *
print inc_header
print sep
print"// 1D specialization for integers by casting to Fix16, generated by script "
print sep
print
print
print "#ifndef _interpol1d_spec_h"
print "#define _interpol1d_spec_h"
print
## TODO: check if the fix16_lerp routines may be faster.
def getCast( from_tp, to_tp ):
head = ""
tail = ""
if from_tp == to_tp:
return head, tail
head = "static_cast<"+to_tp+">("
tail = ")"
if to_tp == "Fix16":
# uint16_t must be casted to float before it can be casted to Fix16
if from_tp == "uint16_t":
head += "static_cast<float>("
tail += ")"
elif from_tp == "uint8_t" or from_tp == "int8_t":
head += "static_cast<int16_t>("
tail += ")"
if from_tp == "Fix16":
# uint16_t must be casted to float before it can be casted to Fix16
if to_tp == "uint16_t":
head += "static_cast<float>("
tail += ")"
elif to_tp == "uint8_t" or to_tp == "int8_t":
head += "static_cast<int16_t>("
tail += ")"
return head, tail
for X in ["int8_t", "uint8_t", "int16_t", "uint16_t", "Fix16" ]:
for Y in ["int8_t", "uint8_t", "int16_t", "uint16_t", "Fix16", "float", "double"]:
if X == "Fix16" and Y == "Fix16":
break # no casting exercise required, so no specialisation either.
interpol_tp = Y
if interpol_tp in ["int8_t", "uint8_t", "int16_t", "uint16_t"]:
interpol_tp = "Fix16"
print"template<>"
print"inline " + Y, "interpolate(", X, "x,", X,"x_1,", X, "x_2,"
print" ", Y, "y_1,", Y, "y_2 )"
print"{"
rhead,rtail = getCast(interpol_tp, Y)
print"#ifdef DEBUG"
print" " + interpol_tp + " retval = ("
print"#else"
print" return " + rhead
print"#endif"
prcx,pocx = getCast(X,interpol_tp)
prcy,pocy = getCast(Y,interpol_tp)
print" interpolate( " + prcx + "x" + pocx + ","
print" " + prcx + "x_1" + pocx + ","
print" " + prcx + "x_2" + pocx + ","
print" " + prcy + "y_1" + pocy + ","
print" " + prcy + "y_2" + pocy + " )"
print
print"#ifndef DEBUG"
print" " + rtail +";"
print"#else"
print" return " + rhead + "retval" + rtail +";"
print"#endif"
print"}"
print
print
print "#endif"