summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-01-12 15:41:32 -0800
committerJosh Blum <josh@joshknows.com>2011-01-12 15:41:32 -0800
commit6f814f04c4af020a627f6772f7f9b14083d312f4 (patch)
tree586e9d103371d3840cc19477c323e37bfa8da086 /host
parent4f28afe2479856f1e0696983a206f05939b2edbf (diff)
downloaduhd-6f814f04c4af020a627f6772f7f9b14083d312f4.tar.gz
uhd-6f814f04c4af020a627f6772f7f9b14083d312f4.tar.bz2
uhd-6f814f04c4af020a627f6772f7f9b14083d312f4.zip
uhd: changed convert routines to return the function pointer
changed the vrt packet handler to get the function pointer (once), this may be a minor performance help
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/convert.hpp34
-rw-r--r--host/lib/convert/convert_impl.cpp26
-rw-r--r--host/lib/transport/vrt_packet_handler.hpp39
-rw-r--r--host/test/convert_test.cpp36
4 files changed, 65 insertions, 70 deletions
diff --git a/host/include/uhd/convert.hpp b/host/include/uhd/convert.hpp
index 488cba98e..bfe8c8267 100644
--- a/host/include/uhd/convert.hpp
+++ b/host/include/uhd/convert.hpp
@@ -58,37 +58,31 @@ namespace uhd{ namespace convert{
);
/*!
- * Convert IO samples to OWT samples:
- *
+ * 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 input_buffs input buffers to read samples
- * \param output_buffs output buffers to write samples
- * \param nsamps_per_io_buff samples per IO buffer
+ * \param num_input_buffs the number of inputs
+ * \param num_output_buffs the number of outputs
*/
- UHD_API void io_type_to_otw_type(
+ UHD_API const function_type &get_converter_cpu_to_otw(
const io_type_t &io_type,
const otw_type_t &otw_type,
- input_type &input_buffs,
- output_type &output_buffs,
- size_t nsamps_per_io_buff
+ size_t num_input_buffs,
+ size_t num_output_buffs
);
/*!
- * Convert OTW samples to IO samples:
- *
- * \param io_type the type of the output samples
- * \param otw_type the type of the input samples
- * \param input_buffs input buffers to read samples
- * \param output_buffs output buffers to write samples
- * \param nsamps_per_io_buff samples per IO buffer
+ * 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
*/
- UHD_API void otw_type_to_io_type(
+ UHD_API const function_type &get_converter_otw_to_cpu(
const io_type_t &io_type,
const otw_type_t &otw_type,
- input_type &input_buffs,
- output_type &output_buffs,
- size_t nsamps_per_io_buff
+ size_t num_input_buffs,
+ size_t num_output_buffs
);
}} //namespace
diff --git a/host/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp
index 74837cc51..6a5a1465d 100644
--- a/host/lib/convert/convert_impl.cpp
+++ b/host/lib/convert/convert_impl.cpp
@@ -90,28 +90,22 @@ void uhd::convert::register_converter(
/***********************************************************************
* The converter functions
**********************************************************************/
-void uhd::convert::io_type_to_otw_type(
+const convert::function_type &convert::get_converter_cpu_to_otw(
const io_type_t &io_type,
const otw_type_t &otw_type,
- input_type &input_buffs,
- output_type &output_buffs,
- size_t nsamps_per_io_buff
+ size_t num_input_buffs,
+ size_t num_output_buffs
){
- pred_type pred = make_pred(io_type, otw_type, input_buffs.size(), output_buffs.size());
- fcn_table_type table = get_cpu_to_otw_table();
- function_type fcn = table.at(pred).fcn;
- fcn(input_buffs, output_buffs, nsamps_per_io_buff);
+ pred_type pred = make_pred(io_type, otw_type, num_input_buffs, num_output_buffs);
+ return get_cpu_to_otw_table().at(pred).fcn;
}
-void uhd::convert::otw_type_to_io_type(
+const convert::function_type &convert::get_converter_otw_to_cpu(
const io_type_t &io_type,
const otw_type_t &otw_type,
- input_type &input_buffs,
- output_type &output_buffs,
- size_t nsamps_per_io_buff
+ size_t num_input_buffs,
+ size_t num_output_buffs
){
- pred_type pred = make_pred(io_type, otw_type, input_buffs.size(), output_buffs.size());
- fcn_table_type table = get_otw_to_cpu_table();
- function_type fcn = table.at(pred).fcn;
- fcn(input_buffs, output_buffs, nsamps_per_io_buff);
+ pred_type pred = make_pred(io_type, otw_type, num_input_buffs, num_output_buffs);
+ return get_otw_to_cpu_table().at(pred).fcn;
}
diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp
index ab58e3416..0507ae328 100644
--- a/host/lib/transport/vrt_packet_handler.hpp
+++ b/host/lib/transport/vrt_packet_handler.hpp
@@ -35,6 +35,9 @@
namespace vrt_packet_handler{
+//this may change in the future but its a constant for now
+static const size_t OTW_BYTES_PER_SAMP = sizeof(boost::uint32_t);
+
template <typename T> UHD_INLINE T get_context_code(
const boost::uint32_t *vrt_hdr,
const uhd::transport::vrt::if_packet_info_t &if_packet_info
@@ -145,8 +148,7 @@ template <typename T> UHD_INLINE T get_context_code(
size_t offset_bytes,
size_t total_samps,
uhd::rx_metadata_t &metadata,
- const uhd::io_type_t &io_type,
- const uhd::otw_type_t &otw_type,
+ uhd::convert::function_type &converter,
double tick_rate,
const vrt_unpacker_t &vrt_unpacker,
const get_recv_buffs_t &get_recv_buffs,
@@ -184,7 +186,7 @@ template <typename T> UHD_INLINE T get_context_code(
}
//extract the number of samples available to copy
- size_t bytes_per_item = otw_type.get_sample_size();
+ size_t bytes_per_item = OTW_BYTES_PER_SAMP;
size_t nsamps_available = state.size_of_copy_buffs/bytes_per_item;
size_t nsamps_to_copy = std::min(total_samps*chans_per_otw_buff, nsamps_available);
size_t bytes_to_copy = nsamps_to_copy*bytes_per_item;
@@ -200,9 +202,7 @@ template <typename T> UHD_INLINE T get_context_code(
//copy-convert the samples from the recv buffer
uhd::convert::input_type otw_buffs(1, state.copy_buffs[i]);
- uhd::convert::otw_type_to_io_type(
- io_type, otw_type, otw_buffs, io_buffs, nsamps_to_copy_per_io_buff
- );
+ converter(otw_buffs, io_buffs, nsamps_to_copy_per_io_buff);
//update the rx copy buffer to reflect the bytes copied
state.copy_buffs[i] += bytes_to_copy;
@@ -236,6 +236,11 @@ template <typename T> UHD_INLINE T get_context_code(
size_t vrt_header_offset_words32 = 0,
size_t chans_per_otw_buff = 1
){
+ uhd::convert::function_type converter(
+ uhd::convert::get_converter_otw_to_cpu(
+ io_type, otw_type, 1, buffs.size()
+ ));
+
switch(recv_mode){
////////////////////////////////////////////////////////////////
@@ -246,7 +251,7 @@ template <typename T> UHD_INLINE T get_context_code(
buffs, 0,
total_num_samps,
metadata,
- io_type, otw_type,
+ converter,
tick_rate,
vrt_unpacker,
get_recv_buffs,
@@ -267,7 +272,7 @@ template <typename T> UHD_INLINE T get_context_code(
buffs, accum_num_samps*io_type.size,
total_num_samps - accum_num_samps,
(accum_num_samps == 0)? metadata : tmp_md, //only the first metadata gets kept
- io_type, otw_type,
+ converter,
tick_rate,
vrt_unpacker,
get_recv_buffs,
@@ -311,15 +316,14 @@ template <typename T> UHD_INLINE T get_context_code(
const size_t offset_bytes,
const size_t num_samps,
uhd::transport::vrt::if_packet_info_t &if_packet_info,
- const uhd::io_type_t &io_type,
- const uhd::otw_type_t &otw_type,
+ uhd::convert::function_type &converter,
const vrt_packer_t &vrt_packer,
const get_send_buffs_t &get_send_buffs,
const size_t vrt_header_offset_words32,
const size_t chans_per_otw_buff
){
//load the rest of the if_packet_info in here
- if_packet_info.num_payload_words32 = (num_samps*chans_per_otw_buff*otw_type.get_sample_size())/sizeof(boost::uint32_t);
+ if_packet_info.num_payload_words32 = (num_samps*chans_per_otw_buff*OTW_BYTES_PER_SAMP)/sizeof(boost::uint32_t);
if_packet_info.packet_count = state.next_packet_seq;
//get send buffers for each channel
@@ -340,9 +344,7 @@ template <typename T> UHD_INLINE T get_context_code(
//copy-convert the samples into the send buffer
uhd::convert::output_type otw_buffs(1, otw_mem);
- uhd::convert::io_type_to_otw_type(
- io_type, otw_type, io_buffs, otw_buffs, num_samps
- );
+ converter(io_buffs, otw_buffs, num_samps);
//commit the samples to the zero-copy interface
size_t num_bytes_total = (vrt_header_offset_words32+if_packet_info.num_packet_words32)*sizeof(boost::uint32_t);
@@ -370,6 +372,11 @@ template <typename T> UHD_INLINE T get_context_code(
size_t vrt_header_offset_words32 = 0,
size_t chans_per_otw_buff = 1
){
+ uhd::convert::function_type converter(
+ uhd::convert::get_converter_cpu_to_otw(
+ io_type, otw_type, buffs.size(), 1
+ ));
+
//translate the metadata to vrt if packet info
uhd::transport::vrt::if_packet_info_t if_packet_info;
if_packet_info.has_sid = false;
@@ -405,7 +412,7 @@ template <typename T> UHD_INLINE T get_context_code(
buffs_, 0,
std::min(total_num_samps_, max_samples_per_packet),
if_packet_info,
- io_type, otw_type,
+ converter,
vrt_packer,
get_send_buffs,
vrt_header_offset_words32,
@@ -438,7 +445,7 @@ template <typename T> UHD_INLINE T get_context_code(
buffs, total_num_samps_sent*io_type.size,
std::min(total_num_samps_unsent, max_samples_per_packet),
if_packet_info,
- io_type, otw_type,
+ converter,
vrt_packer,
get_send_buffs,
vrt_header_offset_words32,
diff --git a/host/test/convert_test.cpp b/host/test/convert_test.cpp
index ca1f039aa..5f2aaf3d1 100644
--- a/host/test/convert_test.cpp
+++ b/host/test/convert_test.cpp
@@ -52,14 +52,14 @@ template <typename Range> static void loopback(
convert::output_type output0(1, &interm[0]), output1(1, &output[0]);
//convert to intermediate type
- convert::io_type_to_otw_type(
- io_type, otw_type, input0, output0, nsamps
- );
+ convert::get_converter_cpu_to_otw(
+ io_type, otw_type, input0.size(), output0.size()
+ )(input0, output0, nsamps);
//convert back to host type
- convert::otw_type_to_io_type(
- io_type, otw_type, input1, output1, nsamps
- );
+ convert::get_converter_otw_to_cpu(
+ io_type, otw_type, input1.size(), output1.size()
+ )(input1, output1, nsamps);
}
/***********************************************************************
@@ -177,14 +177,14 @@ BOOST_AUTO_TEST_CASE(test_convert_types_fc32_to_sc16){
convert::output_type output0(1, &interm[0]), output1(1, &output[0]);
//convert float to intermediate
- convert::io_type_to_otw_type(
- io_type_in, otw_type, input0, output0, nsamps
- );
+ convert::get_converter_cpu_to_otw(
+ io_type_in, otw_type, input0.size(), output0.size()
+ )(input0, output0, nsamps);
//convert intermediate to short
- convert::otw_type_to_io_type(
- io_type_out, otw_type, input1, output1, nsamps
- );
+ convert::get_converter_otw_to_cpu(
+ io_type_out, otw_type, input1.size(), output1.size()
+ )(input1, output1, nsamps);
//test that the inputs and outputs match
for (size_t i = 0; i < nsamps; i++){
@@ -217,14 +217,14 @@ BOOST_AUTO_TEST_CASE(test_convert_types_sc16_to_fc32){
convert::output_type output0(1, &interm[0]), output1(1, &output[0]);
//convert short to intermediate
- convert::io_type_to_otw_type(
- io_type_in, otw_type, input0, output0, nsamps
- );
+ convert::get_converter_cpu_to_otw(
+ io_type_in, otw_type, input0.size(), output0.size()
+ )(input0, output0, nsamps);
//convert intermediate to float
- convert::otw_type_to_io_type(
- io_type_out, otw_type, input1, output1, nsamps
- );
+ convert::get_converter_otw_to_cpu(
+ io_type_out, otw_type, input1.size(), output1.size()
+ )(input1, output1, nsamps);
//test that the inputs and outputs match
for (size_t i = 0; i < nsamps; i++){