summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--host/include/uhd/convert.hpp59
-rw-r--r--host/lib/convert/CMakeLists.txt11
-rw-r--r--host/lib/convert/convert_common.hpp27
-rw-r--r--host/lib/convert/convert_fc32_with_sse2.cpp8
-rw-r--r--host/lib/convert/convert_fc64_with_sse2.cpp8
-rw-r--r--host/lib/convert/convert_impl.cpp117
-rw-r--r--host/lib/convert/gen_convert_general.py23
-rw-r--r--host/lib/convert/gen_convert_pred.py185
8 files changed, 146 insertions, 292 deletions
diff --git a/host/include/uhd/convert.hpp b/host/include/uhd/convert.hpp
index 99f1860ae..a0b502ab0 100644
--- a/host/include/uhd/convert.hpp
+++ b/host/include/uhd/convert.hpp
@@ -19,17 +19,18 @@
#define INCLUDED_UHD_CONVERT_HPP
#include <uhd/config.hpp>
-#include <uhd/types/io_type.hpp>
-#include <uhd/types/otw_type.hpp>
#include <uhd/types/ref_vector.hpp>
#include <boost/function.hpp>
+#include <boost/operators.hpp>
#include <string>
namespace uhd{ namespace convert{
typedef uhd::ref_vector<void *> output_type;
typedef uhd::ref_vector<const void *> input_type;
- typedef boost::function<void(const input_type&, const output_type&, size_t, double)> function_type;
+
+ //! input vectors, output vectors, num samples, scale factor
+ typedef boost::function<void(const input_type&, const output_type&, const size_t, const double)> function_type;
/*!
* Describe the priority of a converter function.
@@ -45,46 +46,50 @@ namespace uhd{ namespace convert{
PRIORITY_EMPTY = -1,
};
+ //! Identify a conversion routine in the registry
+ struct id_type : boost::equality_comparable<id_type>{
+ std::string input_markup;
+ size_t num_inputs;
+ std::string output_markup;
+ size_t num_outputs;
+ std::string args;
+ std::string to_pp_string(void) const;
+ };
+
+ //! Implement equality_comparable interface
+ UHD_API bool operator==(const id_type &, const id_type &);
+
/*!
- * Register a converter function that converts cpu type to/from otw type.
- * \param markup representing the signature
+ * Register a converter function.
+ * \param id identify the conversion
* \param fcn a pointer to the converter
* \param prio the function priority
*/
UHD_API void register_converter(
- const std::string &markup,
+ const id_type &id,
function_type fcn,
priority_type prio
);
/*!
- * Get a converter function that converts cpu to otw.
- * \param io_type the type of the input samples
- * \param otw_type the type of the output samples
- * \param num_input_buffs the number of inputs
- * \param num_output_buffs the number of outputs
+ * Get a converter function.
+ * \param id identify the conversion
+ * \return the converter function
*/
- UHD_API const function_type &get_converter_cpu_to_otw(
- const io_type_t &io_type,
- const otw_type_t &otw_type,
- size_t num_input_buffs,
- size_t num_output_buffs
- );
+ UHD_API function_type get_converter(const id_type &id);
/*!
- * Get a converter function that converts otw to cpu.
- * \param io_type the type of the input samples
- * \param otw_type the type of the output samples
- * \param num_input_buffs the number of inputs
- * \param num_output_buffs the number of outputs
+ * Register the size of a particular item.
+ * \param markup the item markup
+ * \param size the size in bytes
*/
- UHD_API const function_type &get_converter_otw_to_cpu(
- const io_type_t &io_type,
- const otw_type_t &otw_type,
- size_t num_input_buffs,
- size_t num_output_buffs
+ UHD_API void register_bytes_per_item(
+ const std::string &markup, const size_t size
);
+ //! Convert an item markup to a size in bytes
+ UHD_API size_t get_bytes_per_item(const std::string &markup);
+
}} //namespace
#endif /* INCLUDED_UHD_CONVERT_HPP */
diff --git a/host/lib/convert/CMakeLists.txt b/host/lib/convert/CMakeLists.txt
index b260cb247..4cc421884 100644
--- a/host/lib/convert/CMakeLists.txt
+++ b/host/lib/convert/CMakeLists.txt
@@ -112,17 +112,6 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
LIBUHD_PYTHON_GEN_SOURCE(
- ${CMAKE_CURRENT_SOURCE_DIR}/gen_convert_pred.py
- ${CMAKE_CURRENT_BINARY_DIR}/convert_pred.hpp
-)
-
-INCLUDE(AddFileDependencies)
-ADD_FILE_DEPENDENCIES(
- ${CMAKE_CURRENT_SOURCE_DIR}/convert_impl.cpp
- ${CMAKE_CURRENT_BINARY_DIR}/convert_pred.hpp
-)
-
-LIBUHD_PYTHON_GEN_SOURCE(
${CMAKE_CURRENT_SOURCE_DIR}/gen_convert_general.py
${CMAKE_CURRENT_BINARY_DIR}/convert_general.cpp
)
diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp
index 7f513b124..8c8cc88b0 100644
--- a/host/lib/convert/convert_common.hpp
+++ b/host/lib/convert/convert_common.hpp
@@ -23,28 +23,45 @@
#include <boost/cstdint.hpp>
#include <complex>
-#define DECLARE_CONVERTER(fcn, prio) \
+#define _DECLARE_CONVERTER(fcn, in_mark, num_in, out_mark, num_out, prio) \
static void fcn( \
const uhd::convert::input_type &inputs, \
const uhd::convert::output_type &outputs, \
- size_t nsamps, double scale_factor \
+ const size_t nsamps, \
+ const double scale_factor \
); \
- UHD_STATIC_BLOCK(register_##fcn##_##prio){ \
- uhd::convert::register_converter(#fcn, fcn, prio); \
+ UHD_STATIC_BLOCK(__register_##fcn##_##prio){ \
+ uhd::convert::id_type id; \
+ id.input_markup = #in_mark; \
+ id.num_inputs = num_in; \
+ id.output_markup = #out_mark; \
+ id.num_outputs = num_out; \
+ uhd::convert::register_converter(id, fcn, prio); \
} \
static void fcn( \
const uhd::convert::input_type &inputs, \
const uhd::convert::output_type &outputs, \
- size_t nsamps, double scale_factor \
+ const size_t nsamps, \
+ const double scale_factor \
)
+#define DECLARE_CONVERTER(in_mark, num_in, out_mark, num_out, prio) \
+ _DECLARE_CONVERTER(__convert_##in_mark##_##num_in##_##out_mark##_##num_out, in_mark, num_in, out_mark, num_out, prio)
+
/***********************************************************************
* Typedefs
**********************************************************************/
typedef std::complex<double> fc64_t;
typedef std::complex<float> fc32_t;
+typedef std::complex<boost::int32_t> sc32_t;
typedef std::complex<boost::int16_t> sc16_t;
typedef std::complex<boost::int8_t> sc8_t;
+typedef double f64_t;
+typedef float f32_t;
+typedef boost::int32_t s32_t;
+typedef boost::int16_t s16_t;
+typedef boost::int8_t s8_t;
+
typedef boost::uint32_t item32_t;
/***********************************************************************
diff --git a/host/lib/convert/convert_fc32_with_sse2.cpp b/host/lib/convert/convert_fc32_with_sse2.cpp
index 676e1561c..34c85db80 100644
--- a/host/lib/convert/convert_fc32_with_sse2.cpp
+++ b/host/lib/convert/convert_fc32_with_sse2.cpp
@@ -21,7 +21,7 @@
using namespace uhd::convert;
-DECLARE_CONVERTER(convert_fc32_1_to_item32_1_nswap, PRIORITY_CUSTOM){
+DECLARE_CONVERTER(fc32, 1, sc16_item32_le, 1, PRIORITY_CUSTOM){
const fc32_t *input = reinterpret_cast<const fc32_t *>(inputs[0]);
item32_t *output = reinterpret_cast<item32_t *>(outputs[0]);
@@ -64,7 +64,7 @@ DECLARE_CONVERTER(convert_fc32_1_to_item32_1_nswap, PRIORITY_CUSTOM){
}
}
-DECLARE_CONVERTER(convert_fc32_1_to_item32_1_bswap, PRIORITY_CUSTOM){
+DECLARE_CONVERTER(fc32, 1, sc16_item32_be, 1, PRIORITY_CUSTOM){
const fc32_t *input = reinterpret_cast<const fc32_t *>(inputs[0]);
item32_t *output = reinterpret_cast<item32_t *>(outputs[0]);
@@ -106,7 +106,7 @@ DECLARE_CONVERTER(convert_fc32_1_to_item32_1_bswap, PRIORITY_CUSTOM){
}
}
-DECLARE_CONVERTER(convert_item32_1_to_fc32_1_nswap, PRIORITY_CUSTOM){
+DECLARE_CONVERTER(sc16_item32_le, 1, fc32, 1, PRIORITY_CUSTOM){
const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]);
fc32_t *output = reinterpret_cast<fc32_t *>(outputs[0]);
@@ -151,7 +151,7 @@ DECLARE_CONVERTER(convert_item32_1_to_fc32_1_nswap, PRIORITY_CUSTOM){
}
}
-DECLARE_CONVERTER(convert_item32_1_to_fc32_1_bswap, PRIORITY_CUSTOM){
+DECLARE_CONVERTER(sc16_item32_be, 1, fc32, 1, PRIORITY_CUSTOM){
const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]);
fc32_t *output = reinterpret_cast<fc32_t *>(outputs[0]);
diff --git a/host/lib/convert/convert_fc64_with_sse2.cpp b/host/lib/convert/convert_fc64_with_sse2.cpp
index 4d28396a4..2093cf476 100644
--- a/host/lib/convert/convert_fc64_with_sse2.cpp
+++ b/host/lib/convert/convert_fc64_with_sse2.cpp
@@ -21,7 +21,7 @@
using namespace uhd::convert;
-DECLARE_CONVERTER(convert_fc64_1_to_item32_1_nswap, PRIORITY_CUSTOM){
+DECLARE_CONVERTER(fc64, 1, sc16_item32_le, 1, PRIORITY_CUSTOM){
const fc64_t *input = reinterpret_cast<const fc64_t *>(inputs[0]);
item32_t *output = reinterpret_cast<item32_t *>(outputs[0]);
@@ -68,7 +68,7 @@ DECLARE_CONVERTER(convert_fc64_1_to_item32_1_nswap, PRIORITY_CUSTOM){
}
}
-DECLARE_CONVERTER(convert_fc64_1_to_item32_1_bswap, PRIORITY_CUSTOM){
+DECLARE_CONVERTER(fc64, 1, sc16_item32_be, 1, PRIORITY_CUSTOM){
const fc64_t *input = reinterpret_cast<const fc64_t *>(inputs[0]);
item32_t *output = reinterpret_cast<item32_t *>(outputs[0]);
@@ -114,7 +114,7 @@ DECLARE_CONVERTER(convert_fc64_1_to_item32_1_bswap, PRIORITY_CUSTOM){
}
}
-DECLARE_CONVERTER(convert_item32_1_to_fc64_1_nswap, PRIORITY_CUSTOM){
+DECLARE_CONVERTER(sc16_item32_le, 1, fc64, 1, PRIORITY_CUSTOM){
const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]);
fc64_t *output = reinterpret_cast<fc64_t *>(outputs[0]);
@@ -163,7 +163,7 @@ DECLARE_CONVERTER(convert_item32_1_to_fc64_1_nswap, PRIORITY_CUSTOM){
}
}
-DECLARE_CONVERTER(convert_item32_1_to_fc64_1_bswap, PRIORITY_CUSTOM){
+DECLARE_CONVERTER(sc16_item32_be, 1, fc64, 1, PRIORITY_CUSTOM){
const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]);
fc64_t *output = reinterpret_cast<fc64_t *>(outputs[0]);
diff --git a/host/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp
index 9b2cdcdc9..2ead2f5b4 100644
--- a/host/lib/convert/convert_impl.cpp
+++ b/host/lib/convert/convert_impl.cpp
@@ -18,11 +18,40 @@
#include <uhd/convert.hpp>
#include <uhd/utils/log.hpp>
#include <uhd/utils/static.hpp>
+#include <uhd/types/dict.hpp>
#include <uhd/exception.hpp>
+#include <boost/cstdint.hpp>
+#include <boost/format.hpp>
+#include <complex>
using namespace uhd;
-#include "convert_pred.hpp"
+bool convert::operator==(const convert::id_type &lhs, const convert::id_type &rhs){
+ return
+ (lhs.input_markup == rhs.input_markup) and
+ (lhs.num_inputs == rhs.num_inputs) and
+ (lhs.output_markup == rhs.output_markup) and
+ (lhs.num_outputs == rhs.num_outputs) and
+ (lhs.args == rhs.args)
+ ;
+}
+
+std::string convert::id_type::to_pp_string(void) const{
+ return str(boost::format(
+ "conversion ID\n"
+ " Input markup: %s\n"
+ " Num inputs: %d\n"
+ " Output markup: %s\n"
+ " Num outputs: %d\n"
+ " Optional args: %s\n"
+ )
+ % this->input_markup
+ % this->num_inputs
+ % this->output_markup
+ % this->num_outputs
+ % this->args
+ );
+}
/***********************************************************************
* Define types for the function tables
@@ -30,56 +59,34 @@ using namespace uhd;
struct fcn_table_entry_type{
convert::priority_type prio;
convert::function_type fcn;
- fcn_table_entry_type(void)
- : prio(convert::PRIORITY_EMPTY), fcn(NULL){
- /* NOP */
- }
};
-typedef std::vector<fcn_table_entry_type> fcn_table_type;
/***********************************************************************
* Setup the table registry
**********************************************************************/
-UHD_SINGLETON_FCN(fcn_table_type, get_cpu_to_otw_table);
-UHD_SINGLETON_FCN(fcn_table_type, get_otw_to_cpu_table);
-
-fcn_table_type &get_table(dir_type dir){
- switch(dir){
- case DIR_OTW_TO_CPU: return get_otw_to_cpu_table();
- case DIR_CPU_TO_OTW: return get_cpu_to_otw_table();
- }
- UHD_THROW_INVALID_CODE_PATH();
-}
+typedef uhd::dict<convert::id_type, fcn_table_entry_type> fcn_table_type;
+UHD_SINGLETON_FCN(fcn_table_type, get_table);
/***********************************************************************
* The registry functions
**********************************************************************/
void uhd::convert::register_converter(
- const std::string &markup,
+ const id_type &id,
function_type fcn,
priority_type prio
){
- //extract the predicate and direction from the markup
- dir_type dir;
- pred_type pred = make_pred(markup, dir);
-
//get a reference to the function table
- fcn_table_type &table = get_table(dir);
-
- //resize the table so that its at least pred+1
- if (table.size() <= pred) table.resize(pred+1);
+ fcn_table_type &table = get_table();
//register the function if higher priority
- if (table[pred].prio < prio){
- table[pred].fcn = fcn;
- table[pred].prio = prio;
+ if (not table.has_key(id) or table[id].prio < prio){
+ table[id].fcn = fcn;
+ table[id].prio = prio;
}
//----------------------------------------------------------------//
- UHD_LOGV(always) << "register_converter: " << markup << std::endl
+ UHD_LOGV(always) << "register_converter: " << id.to_pp_string() << std::endl
<< " prio: " << prio << std::endl
- << " pred: " << pred << std::endl
- << " dir: " << dir << std::endl
<< std::endl
;
//----------------------------------------------------------------//
@@ -88,22 +95,40 @@ void uhd::convert::register_converter(
/***********************************************************************
* The converter functions
**********************************************************************/
-const convert::function_type &convert::get_converter_cpu_to_otw(
- const io_type_t &io_type,
- const otw_type_t &otw_type,
- size_t num_input_buffs,
- size_t num_output_buffs
-){
- pred_type pred = make_pred(io_type, otw_type, num_input_buffs, num_output_buffs);
- return get_cpu_to_otw_table().at(pred).fcn;
+convert::function_type convert::get_converter(const id_type &id){
+ if (get_table().has_key(id)) return get_table()[id].fcn;
+ throw uhd::key_error("Cannot find a conversion routine for " + id.to_pp_string());
}
-const convert::function_type &convert::get_converter_otw_to_cpu(
- const io_type_t &io_type,
- const otw_type_t &otw_type,
- size_t num_input_buffs,
- size_t num_output_buffs
+/***********************************************************************
+ * Mappings for item markup to byte size for all items we can
+ **********************************************************************/
+typedef uhd::dict<std::string, size_t> item_size_type;
+UHD_SINGLETON_FCN(item_size_type, get_item_size_table);
+
+void register_bytes_per_item(
+ const std::string &markup, const size_t size
){
- pred_type pred = make_pred(io_type, otw_type, num_input_buffs, num_output_buffs);
- return get_otw_to_cpu_table().at(pred).fcn;
+ get_item_size_table()[markup] = size;
+}
+
+size_t convert::get_bytes_per_item(const std::string &markup){
+ if (get_item_size_table().has_key(markup)) return get_item_size_table()[markup];
+ throw uhd::key_error("Cannot find an item size " + markup);
+}
+
+UHD_STATIC_BLOCK(convert_register_item_sizes){
+ //register standard complex types
+ get_item_size_table()["fc64"] = sizeof(std::complex<double>);
+ get_item_size_table()["fc32"] = sizeof(std::complex<float>);
+ get_item_size_table()["sc32"] = sizeof(std::complex<boost::int32_t>);
+ get_item_size_table()["sc16"] = sizeof(std::complex<boost::int16_t>);
+ get_item_size_table()["sc8"] = sizeof(std::complex<boost::int8_t>);
+
+ //register standard real types
+ get_item_size_table()["f64"] = sizeof(double);
+ get_item_size_table()["f32"] = sizeof(float);
+ get_item_size_table()["s32"] = sizeof(boost::int32_t);
+ get_item_size_table()["s16"] = sizeof(boost::int16_t);
+ get_item_size_table()["s8"] = sizeof(boost::int8_t);
}
diff --git a/host/lib/convert/gen_convert_general.py b/host/lib/convert/gen_convert_general.py
index 8c3138bda..0d68a4dd3 100644
--- a/host/lib/convert/gen_convert_general.py
+++ b/host/lib/convert/gen_convert_general.py
@@ -29,26 +29,26 @@ using namespace uhd::convert;
"""
TMPL_CONV_TO_FROM_ITEM32_1 = """
-DECLARE_CONVERTER(convert_$(cpu_type)_1_to_item32_1_$(swap), PRIORITY_GENERAL){
+DECLARE_CONVERTER($(cpu_type), 1, sc16_item32_$(end), 1, PRIORITY_GENERAL){
const $(cpu_type)_t *input = reinterpret_cast<const $(cpu_type)_t *>(inputs[0]);
item32_t *output = reinterpret_cast<item32_t *>(outputs[0]);
for (size_t i = 0; i < nsamps; i++){
- output[i] = $(swap_fcn)($(cpu_type)_to_item32(input[i], float(scale_factor)));
+ output[i] = $(to_wire)($(cpu_type)_to_item32(input[i], float(scale_factor)));
}
}
-DECLARE_CONVERTER(convert_item32_1_to_$(cpu_type)_1_$(swap), PRIORITY_GENERAL){
+DECLARE_CONVERTER(sc16_item32_$(end), 1, $(cpu_type), 1, PRIORITY_GENERAL){
const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]);
$(cpu_type)_t *output = reinterpret_cast<$(cpu_type)_t *>(outputs[0]);
for (size_t i = 0; i < nsamps; i++){
- output[i] = item32_to_$(cpu_type)($(swap_fcn)(input[i]), float(scale_factor));
+ output[i] = item32_to_$(cpu_type)($(to_host)(input[i]), float(scale_factor));
}
}
"""
TMPL_CONV_TO_FROM_ITEM32_X = """
-DECLARE_CONVERTER(convert_$(cpu_type)_$(width)_to_item32_1_$(swap), PRIORITY_GENERAL){
+DECLARE_CONVERTER($(cpu_type), $(width), sc16_item32_$(end), 1, PRIORITY_GENERAL){
#for $w in range($width)
const $(cpu_type)_t *input$(w) = reinterpret_cast<const $(cpu_type)_t *>(inputs[$(w)]);
#end for
@@ -56,12 +56,12 @@ DECLARE_CONVERTER(convert_$(cpu_type)_$(width)_to_item32_1_$(swap), PRIORITY_GEN
for (size_t i = 0, j = 0; i < nsamps; i++){
#for $w in range($width)
- output[j++] = $(swap_fcn)($(cpu_type)_to_item32(input$(w)[i], float(scale_factor)));
+ output[j++] = $(to_wire)($(cpu_type)_to_item32(input$(w)[i], float(scale_factor)));
#end for
}
}
-DECLARE_CONVERTER(convert_item32_1_to_$(cpu_type)_$(width)_$(swap), PRIORITY_GENERAL){
+DECLARE_CONVERTER(sc16_item32_$(end), 1, $(cpu_type), $(width), PRIORITY_GENERAL){
const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]);
#for $w in range($width)
$(cpu_type)_t *output$(w) = reinterpret_cast<$(cpu_type)_t *>(outputs[$(w)]);
@@ -69,7 +69,7 @@ DECLARE_CONVERTER(convert_item32_1_to_$(cpu_type)_$(width)_$(swap), PRIORITY_GEN
for (size_t i = 0, j = 0; i < nsamps; i++){
#for $w in range($width)
- output$(w)[i] = item32_to_$(cpu_type)($(swap_fcn)(input[j++]), float(scale_factor));
+ output$(w)[i] = item32_to_$(cpu_type)($(to_host)(input[j++]), float(scale_factor));
#end for
}
}
@@ -84,10 +84,13 @@ if __name__ == '__main__':
file = os.path.basename(__file__)
output = parse_tmpl(TMPL_HEADER, file=file)
for width in 1, 2, 3, 4:
- for swap, swap_fcn in (('nswap', ''), ('bswap', 'uhd::byteswap')):
+ for end, to_host, to_wire in (
+ ('be', 'uhd::ntohx', 'uhd::htonx'),
+ ('le', 'uhd::wtohx', 'uhd::htowx'),
+ ):
for cpu_type in 'fc64', 'fc32', 'sc16':
output += parse_tmpl(
TMPL_CONV_TO_FROM_ITEM32_1 if width == 1 else TMPL_CONV_TO_FROM_ITEM32_X,
- width=width, swap=swap, swap_fcn=swap_fcn, cpu_type=cpu_type
+ width=width, end=end, to_host=to_host, to_wire=to_wire, cpu_type=cpu_type
)
open(sys.argv[1], 'w').write(output)
diff --git a/host/lib/convert/gen_convert_pred.py b/host/lib/convert/gen_convert_pred.py
deleted file mode 100644
index 360fbcf44..000000000
--- a/host/lib/convert/gen_convert_pred.py
+++ /dev/null
@@ -1,185 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2011-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 <http://www.gnu.org/licenses/>.
-#
-
-TMPL_TEXT = """
-#import time
-/***********************************************************************
- * This file was generated by $file on $time.strftime("%c")
- **********************************************************************/
-\#include <uhd/exception.hpp>
-\#include <boost/tokenizer.hpp>
-\#include <boost/lexical_cast.hpp>
-\#include <boost/detail/endian.hpp>
-\#include <boost/cstdint.hpp>
-\#include <string>
-\#include <vector>
-
-typedef size_t pred_type;
-typedef std::vector<pred_type> pred_vector_type;
-
-enum dir_type{
- DIR_OTW_TO_CPU = 0,
- DIR_CPU_TO_OTW = 1
-};
-
-struct pred_error : uhd::value_error{
- pred_error(const std::string &what):
- uhd::value_error("convert::make_pred: " + what)
- {
- /* NOP */
- }
-};
-
-pred_type make_pred(const std::string &markup, dir_type &dir){
- pred_type pred = 0;
-
- try{
- boost::tokenizer<boost::char_separator<char> > tokenizer(markup, boost::char_separator<char>("_"));
- std::vector<std::string> tokens(tokenizer.begin(), tokenizer.end());
- //token 0 is <convert>
- std::string inp_type = tokens.at(1);
- std::string num_inps = tokens.at(2);
- //token 3 is <to>
- std::string out_type = tokens.at(4);
- std::string num_outs = tokens.at(5);
- std::string swap_type = tokens.at(6);
-
- std::string cpu_type, otw_type;
- if (inp_type.find("item") == std::string::npos){
- cpu_type = inp_type;
- otw_type = out_type;
- dir = DIR_CPU_TO_OTW;
- }
- else{
- cpu_type = out_type;
- otw_type = inp_type;
- dir = DIR_OTW_TO_CPU;
- }
-
- if (cpu_type == "fc64") pred |= $ph.fc64_p;
- else if (cpu_type == "fc32") pred |= $ph.fc32_p;
- else if (cpu_type == "sc16") pred |= $ph.sc16_p;
- else if (cpu_type == "sc8") pred |= $ph.sc8_p;
- else throw pred_error("unhandled io type " + cpu_type);
-
- if (otw_type == "item32") pred |= $ph.item32_p;
- else throw pred_error("unhandled otw type " + otw_type);
-
- int num_inputs = boost::lexical_cast<int>(num_inps);
- int num_outputs = boost::lexical_cast<int>(num_outs);
-
- switch(num_inputs*num_outputs){ //FIXME treated as one value
- case 1: pred |= $ph.chan1_p; break;
- case 2: pred |= $ph.chan2_p; break;
- case 3: pred |= $ph.chan3_p; break;
- case 4: pred |= $ph.chan4_p; break;
- default: throw pred_error("unhandled number of channels");
- }
-
- if (swap_type == "bswap") pred |= $ph.bswap_p;
- else if (swap_type == "nswap") pred |= $ph.nswap_p;
- else throw pred_error("unhandled swap type");
-
- }
- catch(...){
- throw pred_error("could not parse markup: " + markup);
- }
-
- return pred;
-}
-
-#define pred_table_wildcard pred_type(~0)
-#define pred_table_max_size size_t(128)
-#define pred_table_index(e) (pred_type(e) & 0x7f)
-
-static pred_vector_type get_pred_byte_order_table(void){
- pred_vector_type table(pred_table_max_size, pred_table_wildcard);
- \#ifdef BOOST_BIG_ENDIAN
- table[pred_table_index(otw_type_t::BO_BIG_ENDIAN)] = $ph.nswap_p;
- table[pred_table_index(otw_type_t::BO_LITTLE_ENDIAN)] = $ph.bswap_p;
- \#else
- table[pred_table_index(otw_type_t::BO_BIG_ENDIAN)] = $ph.bswap_p;
- table[pred_table_index(otw_type_t::BO_LITTLE_ENDIAN)] = $ph.nswap_p;
- \#endif
- table[pred_table_index(otw_type_t::BO_NATIVE)] = $ph.nswap_p;
- return table;
-}
-
-static pred_vector_type get_pred_io_type_table(void){
- pred_vector_type table(pred_table_max_size, pred_table_wildcard);
- table[pred_table_index(io_type_t::COMPLEX_FLOAT64)] = $ph.fc64_p;
- table[pred_table_index(io_type_t::COMPLEX_FLOAT32)] = $ph.fc32_p;
- table[pred_table_index(io_type_t::COMPLEX_INT16)] = $ph.sc16_p;
- return table;
-}
-
-static pred_vector_type get_pred_num_io_table(void){
- pred_vector_type table(pred_table_max_size, pred_table_wildcard);
- table[1] = $ph.chan1_p;
- table[2] = $ph.chan2_p;
- table[3] = $ph.chan3_p;
- table[4] = $ph.chan4_p;
- return table;
-}
-
-UHD_INLINE pred_type make_pred(
- const io_type_t &io_type,
- const otw_type_t &otw_type,
- size_t num_inputs,
- size_t num_outputs
-){
- pred_type pred = $ph.item32_p; //only item32 supported as of now
-
- static const pred_vector_type pred_byte_order_table(get_pred_byte_order_table());
- pred |= pred_byte_order_table[pred_table_index(otw_type.byteorder)];
-
- static const pred_vector_type pred_io_type_table(get_pred_io_type_table());
- pred |= pred_io_type_table[pred_table_index(io_type.tid)];
-
- static const pred_vector_type pred_num_io_table(get_pred_num_io_table());
- pred |= pred_num_io_table[pred_table_index(num_inputs*num_outputs)];
-
- if (pred == pred_table_wildcard) throw pred_error(
- "unhanded input combination for make_pred()"
- );
-
- return pred;
-}
-"""
-
-def parse_tmpl(_tmpl_text, **kwargs):
- from Cheetah.Template import Template
- return str(Template(_tmpl_text, kwargs))
-
-class ph:
- bswap_p = 0b00001
- nswap_p = 0b00000
- item32_p = 0b00000
- sc8_p = 0b00000
- sc16_p = 0b00010
- fc32_p = 0b00100
- fc64_p = 0b00110
- chan1_p = 0b00000
- chan2_p = 0b01000
- chan3_p = 0b10000
- chan4_p = 0b11000
-
-if __name__ == '__main__':
- import sys, os
- file = os.path.basename(__file__)
- open(sys.argv[1], 'w').write(parse_tmpl(TMPL_TEXT, file=file, ph=ph))