Revision 20c18678 host/lib/convert/gen_convert_general.py

b/host/lib/convert/gen_convert_general.py
28 28
using namespace uhd::convert;
29 29
"""
30 30

  
31
TMPL_CONV_TO_FROM_ITEM32_1 = """
31
TMPL_CONV_GEN2_COMPLEX = """
32 32
DECLARE_CONVERTER($(cpu_type), 1, sc16_item32_$(end), 1, PRIORITY_GENERAL){
33 33
    const $(cpu_type)_t *input = reinterpret_cast<const $(cpu_type)_t *>(inputs[0]);
34 34
    item32_t *output = reinterpret_cast<item32_t *>(outputs[0]);
35 35

  
36 36
    for (size_t i = 0; i < nsamps; i++){
37
        output[i] = $(to_wire)($(cpu_type)_to_item32(input[i], float(scale_factor)));
37
        output[i] = $(to_wire)($(cpu_type)_to_item32(input[i], scale_factor));
38 38
    }
39 39
}
40 40

  
......
43 43
    $(cpu_type)_t *output = reinterpret_cast<$(cpu_type)_t *>(outputs[0]);
44 44

  
45 45
    for (size_t i = 0; i < nsamps; i++){
46
        output[i] = item32_to_$(cpu_type)($(to_host)(input[i]), float(scale_factor));
46
        output[i] = item32_to_$(cpu_type)($(to_host)(input[i]), scale_factor);
47 47
    }
48 48
}
49 49
"""
50
TMPL_CONV_TO_FROM_ITEM32_X = """
51
DECLARE_CONVERTER($(cpu_type), $(width), sc16_item32_$(end), 1, PRIORITY_GENERAL){
50

  
51
TMPL_CONV_USRP1_COMPLEX = """
52
DECLARE_CONVERTER($(cpu_type), $(width), sc16_item16_usrp1, 1, PRIORITY_GENERAL){
52 53
    #for $w in range($width)
53 54
    const $(cpu_type)_t *input$(w) = reinterpret_cast<const $(cpu_type)_t *>(inputs[$(w)]);
54 55
    #end for
55
    item32_t *output = reinterpret_cast<item32_t *>(outputs[0]);
56
    boost::uint16_t *output = reinterpret_cast<boost::uint16_t *>(outputs[0]);
57

  
58
    if (scale_factor == 0){} //avoids unused warning
56 59

  
57 60
    for (size_t i = 0, j = 0; i < nsamps; i++){
58 61
        #for $w in range($width)
59
        output[j++] = $(to_wire)($(cpu_type)_to_item32(input$(w)[i], float(scale_factor)));
62
        output[j++] = $(to_wire)(boost::int16_t(input$(w)[i].real()$(do_scale)));
63
        output[j++] = $(to_wire)(boost::int16_t(input$(w)[i].imag()$(do_scale)));
60 64
        #end for
61 65
    }
62 66
}
63 67

  
64
DECLARE_CONVERTER(sc16_item32_$(end), 1, $(cpu_type), $(width), PRIORITY_GENERAL){
65
    const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]);
68
DECLARE_CONVERTER(sc16_item16_usrp1, 1, $(cpu_type), $(width), PRIORITY_GENERAL){
69
    const boost::uint16_t *input = reinterpret_cast<const boost::uint16_t *>(inputs[0]);
66 70
    #for $w in range($width)
67 71
    $(cpu_type)_t *output$(w) = reinterpret_cast<$(cpu_type)_t *>(outputs[$(w)]);
68 72
    #end for
69 73

  
74
    if (scale_factor == 0){} //avoids unused warning
75

  
70 76
    for (size_t i = 0, j = 0; i < nsamps; i++){
71 77
        #for $w in range($width)
72
        output$(w)[i] = item32_to_$(cpu_type)($(to_host)(input[j++]), float(scale_factor));
78
        output$(w)[i] = $(cpu_type)_t(
79
            boost::int16_t($(to_host)(input[j+0]))$(do_scale),
80
            boost::int16_t($(to_host)(input[j+1]))$(do_scale)
81
        );
82
        j += 2;
83
        #end for
84
    }
85
}
86

  
87
DECLARE_CONVERTER($(cpu_type), $(width), sc8_item16_usrp1, 1, PRIORITY_GENERAL){
88
    #for $w in range($width)
89
    const $(cpu_type)_t *input$(w) = reinterpret_cast<const $(cpu_type)_t *>(inputs[$(w)]);
90
    #end for
91
    boost::uint16_t *output = reinterpret_cast<boost::uint16_t *>(outputs[0]);
92

  
93
    if (scale_factor == 0){} //avoids unused warning
94

  
95
    for (size_t i = 0, j = 0; i < nsamps; i++){
96
        #for $w in range($width)
97
        {
98
        const boost::uint8_t real = boost::int8_t(input$(w)[i].real()$(do_scale));
99
        const boost::uint8_t imag = boost::int8_t(input$(w)[i].imag()$(do_scale));
100
        output[j++] = $(to_wire)((boost::uint16_t(imag) << 8) | real);
101
        }
102
        #end for
103
    }
104
}
105

  
106
DECLARE_CONVERTER(sc8_item16_usrp1, 1, $(cpu_type), $(width), PRIORITY_GENERAL){
107
    const boost::uint16_t *input = reinterpret_cast<const boost::uint16_t *>(inputs[0]);
108
    #for $w in range($width)
109
    $(cpu_type)_t *output$(w) = reinterpret_cast<$(cpu_type)_t *>(outputs[$(w)]);
110
    #end for
111

  
112
    if (scale_factor == 0){} //avoids unused warning
113

  
114
    for (size_t i = 0, j = 0; i < nsamps; i++){
115
        #for $w in range($width)
116
        {
117
        const boost::uint16_t num = $(to_host)(input[j++]);
118
        output$(w)[i] = $(cpu_type)_t(
119
            boost::int8_t(num)$(do_scale),
120
            boost::int8_t(num >> 8)$(do_scale)
121
        );
122
        }
73 123
        #end for
74 124
    }
75 125
}
......
83 133
    import sys, os
84 134
    file = os.path.basename(__file__)
85 135
    output = parse_tmpl(TMPL_HEADER, file=file)
86
    for width in 1, 2, 3, 4:
87
        for end, to_host, to_wire in (
88
            ('be', 'uhd::ntohx', 'uhd::htonx'),
89
            ('le', 'uhd::wtohx', 'uhd::htowx'),
136

  
137
    #generate complex converters for all gen2 platforms
138
    for end, to_host, to_wire in (
139
        ('be', 'uhd::ntohx', 'uhd::htonx'),
140
        ('le', 'uhd::wtohx', 'uhd::htowx'),
141
    ):
142
        for cpu_type in 'fc64', 'fc32', 'sc16':
143
            output += parse_tmpl(
144
                TMPL_CONV_GEN2_COMPLEX,
145
                end=end, to_host=to_host, to_wire=to_wire, cpu_type=cpu_type
146
            )
147

  
148
    #generate complex converters for usrp1 format
149
    for width in 1, 2, 4:
150
        for cpu_type, do_scale in (
151
            ('fc64', '*scale_factor'),
152
            ('fc32', '*float(scale_factor)'),
153
            ('sc16', ''),
90 154
        ):
91
            for cpu_type in 'fc64', 'fc32', 'sc16':
92
                output += parse_tmpl(
93
                    TMPL_CONV_TO_FROM_ITEM32_1 if width == 1 else TMPL_CONV_TO_FROM_ITEM32_X,
94
                    width=width, end=end, to_host=to_host, to_wire=to_wire, cpu_type=cpu_type
95
                )
155
            output += parse_tmpl(
156
                TMPL_CONV_USRP1_COMPLEX,
157
                width=width, to_host='uhd::wtohx', to_wire='uhd::htowx',
158
                cpu_type=cpu_type, do_scale=do_scale
159
            )
96 160
    open(sys.argv[1], 'w').write(output)

Also available in: Unified diff