Revision 16b54d61 host/lib/convert/gen_convert_general.py
| b/host/lib/convert/gen_convert_general.py | ||
|---|---|---|
| 74 | 74 |
} |
| 75 | 75 |
} |
| 76 | 76 |
""" |
| 77 |
TMPL_CONV_TO_FROM_ITEM16_1 = """ |
|
| 78 |
DECLARE_CONVERTER(convert_$(cpu_type)_1_to_item16_1_$(swap), PRIORITY_GENERAL){
|
|
| 79 |
const $(cpu_type)_t *input = reinterpret_cast<const $(cpu_type)_t *>(inputs[0]); |
|
| 80 |
item16_t *output = reinterpret_cast<item16_t *>(outputs[0]); |
|
| 81 |
|
|
| 82 |
for (size_t i = 0; i < nsamps; i++){
|
|
| 83 |
output[i] = $(swap_fcn)($(cpu_type)_to_item16(input[i], float(scale_factor))); |
|
| 84 |
} |
|
| 85 |
} |
|
| 86 |
|
|
| 87 |
DECLARE_CONVERTER(convert_item16_1_to_$(cpu_type)_1_$(swap), PRIORITY_GENERAL){
|
|
| 88 |
const item16_t *input = reinterpret_cast<const item16_t *>(inputs[0]); |
|
| 89 |
$(cpu_type)_t *output = reinterpret_cast<$(cpu_type)_t *>(outputs[0]); |
|
| 90 |
|
|
| 91 |
for (size_t i = 0; i < nsamps; i++){
|
|
| 92 |
output[i] = item16_to_$(cpu_type)($(swap_fcn)(input[i]), float(scale_factor)); |
|
| 93 |
} |
|
| 94 |
} |
|
| 95 |
""" |
|
| 96 |
TMPL_CONV_TO_FROM_ITEM16_X = """ |
|
| 97 |
DECLARE_CONVERTER(convert_$(cpu_type)_$(width)_to_item16_1_$(swap), PRIORITY_GENERAL){
|
|
| 98 |
#for $w in range($width) |
|
| 99 |
const $(cpu_type)_t *input$(w) = reinterpret_cast<const $(cpu_type)_t *>(inputs[$(w)]); |
|
| 100 |
#end for |
|
| 101 |
item16_t *output = reinterpret_cast<item16_t *>(outputs[0]); |
|
| 102 |
|
|
| 103 |
for (size_t i = 0, j = 0; i < nsamps; i++){
|
|
| 104 |
#for $w in range($width) |
|
| 105 |
output[j++] = $(swap_fcn)($(cpu_type)_to_item16(input$(w)[i], float(scale_factor))); |
|
| 106 |
#end for |
|
| 107 |
} |
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
DECLARE_CONVERTER(convert_item16_1_to_$(cpu_type)_$(width)_$(swap), PRIORITY_GENERAL){
|
|
| 111 |
const item16_t *input = reinterpret_cast<const item16_t *>(inputs[0]); |
|
| 112 |
#for $w in range($width) |
|
| 113 |
$(cpu_type)_t *output$(w) = reinterpret_cast<$(cpu_type)_t *>(outputs[$(w)]); |
|
| 114 |
#end for |
|
| 115 |
|
|
| 116 |
for (size_t i = 0, j = 0; i < nsamps; i++){
|
|
| 117 |
#for $w in range($width) |
|
| 118 |
output$(w)[i] = item16_to_$(cpu_type)($(swap_fcn)(input[j++]), float(scale_factor)); |
|
| 119 |
#end for |
|
| 120 |
} |
|
| 121 |
} |
|
| 122 |
""" |
|
| 77 | 123 |
|
| 78 | 124 |
def parse_tmpl(_tmpl_text, **kwargs): |
| 79 | 125 |
from Cheetah.Template import Template |
| ... | ... | |
| 90 | 136 |
TMPL_CONV_TO_FROM_ITEM32_1 if width == 1 else TMPL_CONV_TO_FROM_ITEM32_X, |
| 91 | 137 |
width=width, swap=swap, swap_fcn=swap_fcn, cpu_type=cpu_type |
| 92 | 138 |
) |
| 139 |
output += parse_tmpl( |
|
| 140 |
TMPL_CONV_TO_FROM_ITEM16_1 if width == 1 else TMPL_CONV_TO_FROM_ITEM16_X, |
|
| 141 |
width=width, swap=swap, swap_fcn=swap_fcn, cpu_type=cpu_type |
|
| 142 |
) |
|
| 93 | 143 |
open(sys.argv[1], 'w').write(output) |
Also available in: Unified diff