From dd782308940e4b206e798eb2f0fa203b6e8c7f07 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 12 Nov 2011 15:45:52 -0800 Subject: convert: made conversion functions into classes so they can keep state --- host/lib/convert/convert_common.hpp | 26 +++++++++++++------------- host/lib/convert/convert_impl.cpp | 4 ++-- host/lib/convert/gen_convert_general.py | 10 ---------- 3 files changed, 15 insertions(+), 25 deletions(-) (limited to 'host/lib/convert') diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp index 34fb848c3..ce82f6216 100644 --- a/host/lib/convert/convert_common.hpp +++ b/host/lib/convert/convert_common.hpp @@ -21,30 +21,30 @@ #include #include #include +#include #include -#define _DECLARE_CONVERTER(fcn, in_form, num_in, out_form, num_out, prio) \ - static void fcn( \ - const uhd::convert::input_type &inputs, \ - const uhd::convert::output_type &outputs, \ - const size_t nsamps, const double scale_factor \ - ); \ - UHD_STATIC_BLOCK(__register_##fcn##_##prio){ \ +#define _DECLARE_CONVERTER(name, in_form, num_in, out_form, num_out, prio) \ + struct name : public uhd::convert::converter{ \ + static sptr make(void){return sptr(new name());} \ + double scale_factor; \ + void set_scalar(const double s){scale_factor = s;} \ + void operator()(const input_type&, const output_type&, const size_t); \ + }; \ + UHD_STATIC_BLOCK(__register_##name##_##prio){ \ uhd::convert::id_type id; \ id.input_format = #in_form; \ id.num_inputs = num_in; \ id.output_format = #out_form; \ id.num_outputs = num_out; \ - uhd::convert::register_converter(id, fcn, prio); \ + uhd::convert::register_converter(id, boost::bind(&name::make), prio); \ } \ - static void fcn( \ - const uhd::convert::input_type &inputs, \ - const uhd::convert::output_type &outputs, \ - const size_t nsamps, const double scale_factor \ + void name::operator()( \ + const input_type &inputs, const output_type &outputs, const size_t nsamps \ ) #define DECLARE_CONVERTER(in_form, num_in, out_form, num_out, prio) \ - _DECLARE_CONVERTER(__convert_##in_form##_##num_in##_##out_form##_##num_out, in_form, num_in, out_form, num_out, prio) + _DECLARE_CONVERTER(__convert_##in_form##_##num_in##_##out_form##_##num_out##_##prio, in_form, num_in, out_form, num_out, prio) /*********************************************************************** * Typedefs diff --git a/host/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp index f05be6ada..12ad54486 100644 --- a/host/lib/convert/convert_impl.cpp +++ b/host/lib/convert/convert_impl.cpp @@ -69,8 +69,8 @@ UHD_SINGLETON_FCN(fcn_table_type, get_table); **********************************************************************/ void uhd::convert::register_converter( const id_type &id, - function_type fcn, - priority_type prio + const function_type &fcn, + const priority_type prio ){ //get a reference to the function table fcn_table_type &table = get_table(); diff --git a/host/lib/convert/gen_convert_general.py b/host/lib/convert/gen_convert_general.py index 52b4212b4..a1bc7aaaf 100644 --- a/host/lib/convert/gen_convert_general.py +++ b/host/lib/convert/gen_convert_general.py @@ -33,8 +33,6 @@ DECLARE_CONVERTER(item32, 1, sc16_item32_$(end), 1, PRIORITY_GENERAL){ const item32_t *input = reinterpret_cast(inputs[0]); item32_t *output = reinterpret_cast(outputs[0]); - if (scale_factor == 0){} //avoids unused warning - for (size_t i = 0; i < nsamps; i++){ output[i] = $(to_wire)(input[i]); } @@ -44,8 +42,6 @@ DECLARE_CONVERTER(sc16_item32_$(end), 1, item32, 1, PRIORITY_GENERAL){ const item32_t *input = reinterpret_cast(inputs[0]); item32_t *output = reinterpret_cast(outputs[0]); - if (scale_factor == 0){} //avoids unused warning - for (size_t i = 0; i < nsamps; i++){ output[i] = $(to_host)(input[i]); } @@ -103,8 +99,6 @@ DECLARE_CONVERTER($(cpu_type), $(width), sc16_item16_usrp1, 1, PRIORITY_GENERAL) #end for boost::uint16_t *output = reinterpret_cast(outputs[0]); - if (scale_factor == 0){} //avoids unused warning - for (size_t i = 0, j = 0; i < nsamps; i++){ #for $w in range($width) output[j++] = $(to_wire)(boost::int16_t(input$(w)[i].real()$(do_scale))); @@ -119,8 +113,6 @@ DECLARE_CONVERTER(sc16_item16_usrp1, 1, $(cpu_type), $(width), PRIORITY_GENERAL) $(cpu_type)_t *output$(w) = reinterpret_cast<$(cpu_type)_t *>(outputs[$(w)]); #end for - if (scale_factor == 0){} //avoids unused warning - for (size_t i = 0, j = 0; i < nsamps; i++){ #for $w in range($width) output$(w)[i] = $(cpu_type)_t( @@ -138,8 +130,6 @@ DECLARE_CONVERTER(sc8_item16_usrp1, 1, $(cpu_type), $(width), PRIORITY_GENERAL){ $(cpu_type)_t *output$(w) = reinterpret_cast<$(cpu_type)_t *>(outputs[$(w)]); #end for - if (scale_factor == 0){} //avoids unused warning - for (size_t i = 0, j = 0; i < nsamps; i++){ #for $w in range($width) { -- cgit v1.2.3 From f31afff6dd03ee500ba48e81e0caf26bc61e430d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 12 Nov 2011 16:33:26 -0800 Subject: convert: added table conversion routine for sc16 to floats --- host/lib/convert/CMakeLists.txt | 1 + host/lib/convert/convert_common.hpp | 3 +- host/lib/convert/convert_with_tables.cpp | 139 +++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 host/lib/convert/convert_with_tables.cpp (limited to 'host/lib/convert') diff --git a/host/lib/convert/CMakeLists.txt b/host/lib/convert/CMakeLists.txt index 4cc421884..1fe92d93a 100644 --- a/host/lib/convert/CMakeLists.txt +++ b/host/lib/convert/CMakeLists.txt @@ -117,5 +117,6 @@ LIBUHD_PYTHON_GEN_SOURCE( ) LIBUHD_APPEND_SOURCES( + ${CMAKE_CURRENT_SOURCE_DIR}/convert_with_tables.cpp ${CMAKE_CURRENT_SOURCE_DIR}/convert_impl.cpp ) diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp index ce82f6216..f963e29ee 100644 --- a/host/lib/convert/convert_common.hpp +++ b/host/lib/convert/convert_common.hpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #define _DECLARE_CONVERTER(name, in_form, num_in, out_form, num_out, prio) \ @@ -37,7 +36,7 @@ id.num_inputs = num_in; \ id.output_format = #out_form; \ id.num_outputs = num_out; \ - uhd::convert::register_converter(id, boost::bind(&name::make), prio); \ + uhd::convert::register_converter(id, &name::make, prio); \ } \ void name::operator()( \ const input_type &inputs, const output_type &outputs, const size_t nsamps \ diff --git a/host/lib/convert/convert_with_tables.cpp b/host/lib/convert/convert_with_tables.cpp new file mode 100644 index 000000000..b3702e6ea --- /dev/null +++ b/host/lib/convert/convert_with_tables.cpp @@ -0,0 +1,139 @@ +// +// Copyright 2011 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#include "convert_common.hpp" +#include +#include + +using namespace uhd::convert; + +static const size_t sc16_table_len = size_t(1 << 16); + +#ifdef BOOST_BIG_ENDIAN +# define ITEM32_BE_TO_R16(x) boost::uint16_t(x >> 16) +# define ITEM32_BE_TO_I16(x) boost::uint16_t(x) +# define ITEM32_LE_TO_R16(x) boost::uint16_t(x) +# define ITEM32_LE_TO_I16(x) boost::uint16_t(x >> 16) +#else +# define ITEM32_BE_TO_R16(x) boost::uint16_t(x) +# define ITEM32_BE_TO_I16(x) boost::uint16_t(x >> 16) +# define ITEM32_LE_TO_R16(x) boost::uint16_t(x >> 16) +# define ITEM32_LE_TO_I16(x) boost::uint16_t(x) +#endif + +/*********************************************************************** + * Implementation for sc16 be lookup table + **********************************************************************/ +template class convert_sc16_item32_be_1_to_fcxx_1 : public converter{ +public: + convert_sc16_item32_be_1_to_fcxx_1(void): _table(sc16_table_len){} + + void set_scalar(const double scalar){ + for (size_t i = 0; i < sc16_table_len; i++){ + const boost::int16_t val = uhd::ntohx(boost::uint16_t(i & 0xffff)); + _table[i] = type(val*scalar); + } + } + + void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps){ + const item32_t *input = reinterpret_cast(inputs[0]); + std::complex *output = reinterpret_cast *>(outputs[0]); + + for (size_t i = 0; i < nsamps; i++){ + const item32_t item_be = input[i]; + output[i] = std::complex( + _table[ITEM32_BE_TO_R16(item_be)], + _table[ITEM32_BE_TO_I16(item_be)] + ); + } + } + +private: + std::vector _table; +}; + +/*********************************************************************** + * Implementation for sc16 le lookup table + **********************************************************************/ +template class convert_sc16_item32_le_1_to_fcxx_1 : public converter{ +public: + convert_sc16_item32_le_1_to_fcxx_1(void): _table(sc16_table_len){} + + void set_scalar(const double scalar){ + for (size_t i = 0; i < sc16_table_len; i++){ + const boost::int16_t val = uhd::wtohx(boost::uint16_t(i & 0xffff)); + _table[i] = type(val*scalar); + } + } + + void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps){ + const item32_t *input = reinterpret_cast(inputs[0]); + std::complex *output = reinterpret_cast *>(outputs[0]); + + for (size_t i = 0; i < nsamps; i++){ + const item32_t item_le = input[i]; + output[i] = std::complex( + _table[ITEM32_LE_TO_R16(item_le)], + _table[ITEM32_LE_TO_I16(item_le)] + ); + } + } + +private: + std::vector _table; +}; + +/*********************************************************************** + * Factory functions and registration + **********************************************************************/ +static converter::sptr make_convert_sc16_item32_be_1_to_fc32_1(void){ + return converter::sptr(new convert_sc16_item32_be_1_to_fcxx_1()); +} + +static converter::sptr make_convert_sc16_item32_be_1_to_fc64_1(void){ + return converter::sptr(new convert_sc16_item32_be_1_to_fcxx_1()); +} + +static converter::sptr make_convert_sc16_item32_le_1_to_fc32_1(void){ + return converter::sptr(new convert_sc16_item32_le_1_to_fcxx_1()); +} + +static converter::sptr make_convert_sc16_item32_le_1_to_fc64_1(void){ + return converter::sptr(new convert_sc16_item32_le_1_to_fcxx_1()); +} + +UHD_STATIC_BLOCK(register_convert_sc16_item32_1_to_fcxx_1){ + uhd::convert::id_type id; + id.num_inputs = 1; + id.num_outputs = 1; + + id.output_format = "fc32"; + id.input_format = "sc16_item32_be"; + uhd::convert::register_converter(id, &make_convert_sc16_item32_be_1_to_fc32_1, PRIORITY_TABLE); + + id.output_format = "fc64"; + id.input_format = "sc16_item32_be"; + uhd::convert::register_converter(id, &make_convert_sc16_item32_be_1_to_fc64_1, PRIORITY_TABLE); + + id.output_format = "fc32"; + id.input_format = "sc16_item32_le"; + uhd::convert::register_converter(id, &make_convert_sc16_item32_le_1_to_fc32_1, PRIORITY_TABLE); + + id.output_format = "fc64"; + id.input_format = "sc16_item32_le"; + uhd::convert::register_converter(id, &make_convert_sc16_item32_le_1_to_fc64_1, PRIORITY_TABLE); +} -- cgit v1.2.3 From 4c5db96c36a3f1e245d6a42d09f612b9c016709c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 12 Nov 2011 16:52:03 -0800 Subject: convert: simplify table conversion with templates --- host/lib/convert/convert_with_tables.cpp | 77 +++++++++++--------------------- 1 file changed, 25 insertions(+), 52 deletions(-) (limited to 'host/lib/convert') diff --git a/host/lib/convert/convert_with_tables.cpp b/host/lib/convert/convert_with_tables.cpp index b3702e6ea..00bec95af 100644 --- a/host/lib/convert/convert_with_tables.cpp +++ b/host/lib/convert/convert_with_tables.cpp @@ -23,28 +23,19 @@ using namespace uhd::convert; static const size_t sc16_table_len = size_t(1 << 16); -#ifdef BOOST_BIG_ENDIAN -# define ITEM32_BE_TO_R16(x) boost::uint16_t(x >> 16) -# define ITEM32_BE_TO_I16(x) boost::uint16_t(x) -# define ITEM32_LE_TO_R16(x) boost::uint16_t(x) -# define ITEM32_LE_TO_I16(x) boost::uint16_t(x >> 16) -#else -# define ITEM32_BE_TO_R16(x) boost::uint16_t(x) -# define ITEM32_BE_TO_I16(x) boost::uint16_t(x >> 16) -# define ITEM32_LE_TO_R16(x) boost::uint16_t(x >> 16) -# define ITEM32_LE_TO_I16(x) boost::uint16_t(x) -#endif +typedef boost::uint16_t (*tohost16_type)(boost::uint16_t); /*********************************************************************** - * Implementation for sc16 be lookup table + * Implementation for sc16 lookup table **********************************************************************/ -template class convert_sc16_item32_be_1_to_fcxx_1 : public converter{ +template +class convert_sc16_item32_1_to_fcxx_1 : public converter{ public: - convert_sc16_item32_be_1_to_fcxx_1(void): _table(sc16_table_len){} + convert_sc16_item32_1_to_fcxx_1(void): _table(sc16_table_len){} void set_scalar(const double scalar){ for (size_t i = 0; i < sc16_table_len; i++){ - const boost::int16_t val = uhd::ntohx(boost::uint16_t(i & 0xffff)); + const boost::int16_t val = tohost(boost::uint16_t(i & 0xffff)); _table[i] = type(val*scalar); } } @@ -54,10 +45,10 @@ public: std::complex *output = reinterpret_cast *>(outputs[0]); for (size_t i = 0; i < nsamps; i++){ - const item32_t item_be = input[i]; + const item32_t item = input[i]; output[i] = std::complex( - _table[ITEM32_BE_TO_R16(item_be)], - _table[ITEM32_BE_TO_I16(item_be)] + _table[boost::uint16_t(item >> real_shift)], + _table[boost::uint16_t(item >> imag_shift)] ); } } @@ -67,53 +58,35 @@ private: }; /*********************************************************************** - * Implementation for sc16 le lookup table + * Factory functions and registration **********************************************************************/ -template class convert_sc16_item32_le_1_to_fcxx_1 : public converter{ -public: - convert_sc16_item32_le_1_to_fcxx_1(void): _table(sc16_table_len){} - - void set_scalar(const double scalar){ - for (size_t i = 0; i < sc16_table_len; i++){ - const boost::int16_t val = uhd::wtohx(boost::uint16_t(i & 0xffff)); - _table[i] = type(val*scalar); - } - } - - void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps){ - const item32_t *input = reinterpret_cast(inputs[0]); - std::complex *output = reinterpret_cast *>(outputs[0]); - for (size_t i = 0; i < nsamps; i++){ - const item32_t item_le = input[i]; - output[i] = std::complex( - _table[ITEM32_LE_TO_R16(item_le)], - _table[ITEM32_LE_TO_I16(item_le)] - ); - } - } - -private: - std::vector _table; -}; +#ifdef BOOST_BIG_ENDIAN +# define ITEM32_BE_TO_R16 16 +# define ITEM32_BE_TO_I16 0 +# define ITEM32_LE_TO_R16 0 +# define ITEM32_LE_TO_I16 16 +#else +# define ITEM32_BE_TO_R16 0 +# define ITEM32_BE_TO_I16 16 +# define ITEM32_LE_TO_R16 16 +# define ITEM32_LE_TO_I16 0 +#endif -/*********************************************************************** - * Factory functions and registration - **********************************************************************/ static converter::sptr make_convert_sc16_item32_be_1_to_fc32_1(void){ - return converter::sptr(new convert_sc16_item32_be_1_to_fcxx_1()); + return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); } static converter::sptr make_convert_sc16_item32_be_1_to_fc64_1(void){ - return converter::sptr(new convert_sc16_item32_be_1_to_fcxx_1()); + return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); } static converter::sptr make_convert_sc16_item32_le_1_to_fc32_1(void){ - return converter::sptr(new convert_sc16_item32_le_1_to_fcxx_1()); + return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); } static converter::sptr make_convert_sc16_item32_le_1_to_fc64_1(void){ - return converter::sptr(new convert_sc16_item32_le_1_to_fcxx_1()); + return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); } UHD_STATIC_BLOCK(register_convert_sc16_item32_1_to_fcxx_1){ -- cgit v1.2.3 From ff49029e395e5c78c7ad76e9ff2d7370e5503e7f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 12 Nov 2011 17:13:13 -0800 Subject: convert: added table conversion routines for sc8 --- host/lib/convert/convert_with_tables.cpp | 112 ++++++++++++++++++++++++++----- 1 file changed, 95 insertions(+), 17 deletions(-) (limited to 'host/lib/convert') diff --git a/host/lib/convert/convert_with_tables.cpp b/host/lib/convert/convert_with_tables.cpp index 00bec95af..ac12b4440 100644 --- a/host/lib/convert/convert_with_tables.cpp +++ b/host/lib/convert/convert_with_tables.cpp @@ -27,16 +27,17 @@ typedef boost::uint16_t (*tohost16_type)(boost::uint16_t); /*********************************************************************** * Implementation for sc16 lookup table + * - Lookup the real and imaginary parts individually **********************************************************************/ -template +template class convert_sc16_item32_1_to_fcxx_1 : public converter{ public: convert_sc16_item32_1_to_fcxx_1(void): _table(sc16_table_len){} void set_scalar(const double scalar){ for (size_t i = 0; i < sc16_table_len; i++){ - const boost::int16_t val = tohost(boost::uint16_t(i & 0xffff)); - _table[i] = type(val*scalar); + const boost::uint16_t val = tohost(boost::uint16_t(i & 0xffff)); + _table[i] = type(boost::int16_t(val)*scalar); } } @@ -47,8 +48,8 @@ public: for (size_t i = 0; i < nsamps; i++){ const item32_t item = input[i]; output[i] = std::complex( - _table[boost::uint16_t(item >> real_shift)], - _table[boost::uint16_t(item >> imag_shift)] + _table[boost::uint16_t(item >> lo_shift)], + _table[boost::uint16_t(item >> hi_shift)] ); } } @@ -57,36 +58,97 @@ private: std::vector _table; }; +/*********************************************************************** + * Implementation for sc8 lookup table + * - Lookup the real and imaginary parts together + **********************************************************************/ +template +class convert_sc8_item32_1_to_fcxx_1 : public converter{ +public: + convert_sc8_item32_1_to_fcxx_1(void): _table(sc16_table_len){} + + void set_scalar(const double scalar){ + for (size_t i = 0; i < sc16_table_len; i++){ + const boost::uint16_t val = tohost(boost::uint16_t(i & 0xffff)); + _table[i] = std::complex(boost::int8_t(val >> 8)*scalar, boost::int8_t(val >> 0)*scalar); + } + } + + void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps){ + const item32_t *input = reinterpret_cast(size_t(inputs[0]) & ~0x3); + std::complex *output = reinterpret_cast *>(outputs[0]); + + size_t num_samps = nsamps; + + if ((size_t(inputs[0]) & 0x3) != 0){ + const item32_t item0 = *input++; + *output++ = _table[boost::uint16_t(item0 >> hi_shift)]; + num_samps--; + } + + const size_t num_pairs = num_samps/2; + for (size_t i = 0, j = 0; i < num_pairs; i++, j+=2){ + const item32_t item_i = (input[i]); + output[j] = _table[boost::uint16_t(item_i >> lo_shift)]; + output[j + 1] = _table[boost::uint16_t(item_i >> hi_shift)]; + } + + if (num_samps != num_pairs*2){ + const item32_t item_n = input[num_pairs]; + output[num_samps-1] = _table[boost::uint16_t(item_n >> lo_shift)]; + } + } + +private: + std::vector > _table; +}; + /*********************************************************************** * Factory functions and registration **********************************************************************/ #ifdef BOOST_BIG_ENDIAN -# define ITEM32_BE_TO_R16 16 -# define ITEM32_BE_TO_I16 0 -# define ITEM32_LE_TO_R16 0 -# define ITEM32_LE_TO_I16 16 +# define BE_LO_SHIFT 16 +# define BE_HI_SHIFT 0 +# define LE_LO_SHIFT 0 +# define LE_HI_SHIFT 16 #else -# define ITEM32_BE_TO_R16 0 -# define ITEM32_BE_TO_I16 16 -# define ITEM32_LE_TO_R16 16 -# define ITEM32_LE_TO_I16 0 +# define BE_LO_SHIFT 0 +# define BE_HI_SHIFT 16 +# define LE_LO_SHIFT 16 +# define LE_HI_SHIFT 0 #endif static converter::sptr make_convert_sc16_item32_be_1_to_fc32_1(void){ - return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); + return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); } static converter::sptr make_convert_sc16_item32_be_1_to_fc64_1(void){ - return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); + return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); } static converter::sptr make_convert_sc16_item32_le_1_to_fc32_1(void){ - return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); + return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); } static converter::sptr make_convert_sc16_item32_le_1_to_fc64_1(void){ - return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); + return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); +} + +static converter::sptr make_convert_sc8_item32_be_1_to_fc32_1(void){ + return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); +} + +static converter::sptr make_convert_sc8_item32_be_1_to_fc64_1(void){ + return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); +} + +static converter::sptr make_convert_sc8_item32_le_1_to_fc32_1(void){ + return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); +} + +static converter::sptr make_convert_sc8_item32_le_1_to_fc64_1(void){ + return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); } UHD_STATIC_BLOCK(register_convert_sc16_item32_1_to_fcxx_1){ @@ -109,4 +171,20 @@ UHD_STATIC_BLOCK(register_convert_sc16_item32_1_to_fcxx_1){ id.output_format = "fc64"; id.input_format = "sc16_item32_le"; uhd::convert::register_converter(id, &make_convert_sc16_item32_le_1_to_fc64_1, PRIORITY_TABLE); + + id.output_format = "fc32"; + id.input_format = "sc8_item32_be"; + uhd::convert::register_converter(id, &make_convert_sc8_item32_be_1_to_fc32_1, PRIORITY_TABLE); + + id.output_format = "fc64"; + id.input_format = "sc8_item32_be"; + uhd::convert::register_converter(id, &make_convert_sc8_item32_be_1_to_fc64_1, PRIORITY_TABLE); + + id.output_format = "fc32"; + id.input_format = "sc8_item32_le"; + uhd::convert::register_converter(id, &make_convert_sc8_item32_le_1_to_fc32_1, PRIORITY_TABLE); + + id.output_format = "fc64"; + id.input_format = "sc8_item32_le"; + uhd::convert::register_converter(id, &make_convert_sc8_item32_le_1_to_fc64_1, PRIORITY_TABLE); } -- cgit v1.2.3 From 7a1bd6135ad7201f4a23ee71d929ae15de26a103 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 13 Nov 2011 17:11:15 -0800 Subject: uhd: fixed sc8 table conversion, and simplified shifts --- host/lib/convert/convert_with_tables.cpp | 34 ++++++++++++++------------------ 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'host/lib/convert') diff --git a/host/lib/convert/convert_with_tables.cpp b/host/lib/convert/convert_with_tables.cpp index ac12b4440..bcb7ec2c7 100644 --- a/host/lib/convert/convert_with_tables.cpp +++ b/host/lib/convert/convert_with_tables.cpp @@ -29,7 +29,7 @@ typedef boost::uint16_t (*tohost16_type)(boost::uint16_t); * Implementation for sc16 lookup table * - Lookup the real and imaginary parts individually **********************************************************************/ -template +template class convert_sc16_item32_1_to_fcxx_1 : public converter{ public: convert_sc16_item32_1_to_fcxx_1(void): _table(sc16_table_len){} @@ -48,8 +48,8 @@ public: for (size_t i = 0; i < nsamps; i++){ const item32_t item = input[i]; output[i] = std::complex( - _table[boost::uint16_t(item >> lo_shift)], - _table[boost::uint16_t(item >> hi_shift)] + _table[boost::uint16_t(item >> re_shift)], + _table[boost::uint16_t(item >> im_shift)] ); } } @@ -108,47 +108,43 @@ private: **********************************************************************/ #ifdef BOOST_BIG_ENDIAN -# define BE_LO_SHIFT 16 -# define BE_HI_SHIFT 0 -# define LE_LO_SHIFT 0 -# define LE_HI_SHIFT 16 +# define SHIFT_PAIR0 16, 0 +# define SHIFT_PAIR1 0, 16 #else -# define BE_LO_SHIFT 0 -# define BE_HI_SHIFT 16 -# define LE_LO_SHIFT 16 -# define LE_HI_SHIFT 0 +# define SHIFT_PAIR0 0, 16 +# define SHIFT_PAIR1 16, 0 #endif static converter::sptr make_convert_sc16_item32_be_1_to_fc32_1(void){ - return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); + return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); } static converter::sptr make_convert_sc16_item32_be_1_to_fc64_1(void){ - return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); + return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); } static converter::sptr make_convert_sc16_item32_le_1_to_fc32_1(void){ - return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); + return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); } static converter::sptr make_convert_sc16_item32_le_1_to_fc64_1(void){ - return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); + return converter::sptr(new convert_sc16_item32_1_to_fcxx_1()); } static converter::sptr make_convert_sc8_item32_be_1_to_fc32_1(void){ - return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); + return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); } static converter::sptr make_convert_sc8_item32_be_1_to_fc64_1(void){ - return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); + return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); } static converter::sptr make_convert_sc8_item32_le_1_to_fc32_1(void){ - return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); + return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); } static converter::sptr make_convert_sc8_item32_le_1_to_fc64_1(void){ - return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); + return converter::sptr(new convert_sc8_item32_1_to_fcxx_1()); } UHD_STATIC_BLOCK(register_convert_sc16_item32_1_to_fcxx_1){ -- cgit v1.2.3 From 986f6f8d0b14c4e56468c1c8887fadb2dc4e1463 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 13 Nov 2011 17:22:49 -0800 Subject: convert: msvc warning fixes for sc8 table gen --- host/lib/convert/convert_with_tables.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'host/lib/convert') diff --git a/host/lib/convert/convert_with_tables.cpp b/host/lib/convert/convert_with_tables.cpp index bcb7ec2c7..c45415d5d 100644 --- a/host/lib/convert/convert_with_tables.cpp +++ b/host/lib/convert/convert_with_tables.cpp @@ -70,7 +70,9 @@ public: void set_scalar(const double scalar){ for (size_t i = 0; i < sc16_table_len; i++){ const boost::uint16_t val = tohost(boost::uint16_t(i & 0xffff)); - _table[i] = std::complex(boost::int8_t(val >> 8)*scalar, boost::int8_t(val >> 0)*scalar); + const type real = type(boost::int8_t(val >> 8)*scalar); + const type imag = type(boost::int8_t(val >> 0)*scalar); + _table[i] = std::complex(real, imag); } } -- cgit v1.2.3 From aed619727e47bf2353164ac1788a6e3479b2fe16 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 15 Nov 2011 06:12:28 +0000 Subject: convert: move priorities to implementation, different for arm --- host/include/uhd/convert.hpp | 17 ++--------------- host/lib/convert/CMakeLists.txt | 6 +----- host/lib/convert/convert_common.hpp | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 20 deletions(-) (limited to 'host/lib/convert') diff --git a/host/include/uhd/convert.hpp b/host/include/uhd/convert.hpp index 6cc729819..f906ff0e9 100644 --- a/host/include/uhd/convert.hpp +++ b/host/include/uhd/convert.hpp @@ -50,21 +50,8 @@ namespace uhd{ namespace convert{ //! Conversion factory function typedef typedef boost::function function_type; - /*! - * Describe the priority of a converter function. - * A higher priority function takes precedence. - * The general case function are the lowest. - * Next comes the liborc implementations. - * Custom intrinsics implementations are highest. - */ - enum priority_type{ - PRIORITY_GENERAL = 0, - PRIORITY_LIBORC = 1, - PRIORITY_SIMD = 2, - PRIORITY_TABLE = 3, - PRIORITY_CUSTOM = 4, - PRIORITY_EMPTY = -1, - }; + //! Priority of conversion routines + typedef int priority_type; //! Identify a conversion routine in the registry struct id_type : boost::equality_comparable{ diff --git a/host/lib/convert/CMakeLists.txt b/host/lib/convert/CMakeLists.txt index 1fe92d93a..98907dc29 100644 --- a/host/lib/convert/CMakeLists.txt +++ b/host/lib/convert/CMakeLists.txt @@ -91,11 +91,7 @@ IF(CMAKE_COMPILER_IS_GNUCXX) UNSET(CMAKE_REQUIRED_FLAGS) ENDIF(CMAKE_COMPILER_IS_GNUCXX) -IF(HAVE_ARM_NEON_H AND ENABLE_ORC) - #prefer orc support, its faster than the current intrinsic implementations - MESSAGE(STATUS "Enabled conversion support with ORC.") -ELSEIF(HAVE_ARM_NEON_H) - MESSAGE(STATUS "Enabled conversion support with NEON intrinsics.") +IF(HAVE_ARM_NEON_H) SET_SOURCE_FILES_PROPERTIES( ${CMAKE_CURRENT_SOURCE_DIR}/convert_with_neon.cpp PROPERTIES COMPILE_FLAGS "${NEON_FLAGS}" diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp index f963e29ee..cc287114a 100644 --- a/host/lib/convert/convert_common.hpp +++ b/host/lib/convert/convert_common.hpp @@ -45,6 +45,22 @@ #define DECLARE_CONVERTER(in_form, num_in, out_form, num_out, prio) \ _DECLARE_CONVERTER(__convert_##in_form##_##num_in##_##out_form##_##num_out##_##prio, in_form, num_in, out_form, num_out, prio) +/*********************************************************************** + * Setup priorities + **********************************************************************/ +static const int PRIORITY_GENERAL = 0; +static const int PRIORITY_EMPTY = -1; + +#ifdef __ARM_NEON__ +static const int PRIORITY_LIBORC = 3; +static const int PRIORITY_SIMD = 1; //neon conversions could be implemented better, orc wins +static const int PRIORITY_TABLE = 2; //tables require large cache, so they are slower on arm +#else +static const int PRIORITY_LIBORC = 1; +static const int PRIORITY_SIMD = 2; +static const int PRIORITY_TABLE = 3; +#endif + /*********************************************************************** * Typedefs **********************************************************************/ -- cgit v1.2.3