aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/convert
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/convert')
-rw-r--r--host/lib/convert/convert_common.hpp25
-rw-r--r--host/lib/convert/gen_convert_general.py2
-rw-r--r--host/lib/convert/gen_convert_pred.py91
3 files changed, 82 insertions, 36 deletions
diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp
index 1a653a56f..c6ba1fcf9 100644
--- a/host/lib/convert/convert_common.hpp
+++ b/host/lib/convert/convert_common.hpp
@@ -41,8 +41,10 @@
/***********************************************************************
* Typedefs
**********************************************************************/
+typedef std::complex<double> fc64_t;
typedef std::complex<float> fc32_t;
typedef std::complex<boost::int16_t> sc16_t;
+typedef std::complex<boost::int8_t> sc8_t;
typedef boost::uint32_t item32_t;
/***********************************************************************
@@ -87,4 +89,27 @@ static UHD_INLINE fc32_t item32_to_fc32(item32_t item){
);
}
+/***********************************************************************
+ * Convert complex double buffer to items32 (no swap)
+ **********************************************************************/
+static const double shorts_per_double = double(32767);
+
+static UHD_INLINE item32_t fc64_to_item32(fc64_t num){
+ boost::uint16_t real = boost::int16_t(num.real()*shorts_per_double);
+ boost::uint16_t imag = boost::int16_t(num.imag()*shorts_per_double);
+ return (item32_t(real) << 16) | (item32_t(imag) << 0);
+}
+
+/***********************************************************************
+ * Convert items32 buffer to complex double
+ **********************************************************************/
+static const double doubles_per_short = double(1.0/shorts_per_double);
+
+static UHD_INLINE fc64_t item32_to_fc64(item32_t item){
+ return fc64_t(
+ float(boost::int16_t(item >> 16)*doubles_per_short),
+ float(boost::int16_t(item >> 0)*doubles_per_short)
+ );
+}
+
#endif /* INCLUDED_LIBUHD_CONVERT_COMMON_HPP */
diff --git a/host/lib/convert/gen_convert_general.py b/host/lib/convert/gen_convert_general.py
index 47c4cd7d0..f03448047 100644
--- a/host/lib/convert/gen_convert_general.py
+++ b/host/lib/convert/gen_convert_general.py
@@ -85,7 +85,7 @@ if __name__ == '__main__':
output = parse_tmpl(TMPL_HEADER, file=file)
for width in 1, 2, 3, 4:
for swap, swap_fcn in (('nswap', ''), ('bswap', 'uhd::byteswap')):
- for cpu_type in 'fc32', 'sc16':
+ 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
diff --git a/host/lib/convert/gen_convert_pred.py b/host/lib/convert/gen_convert_pred.py
index 1d573bf1a..d2f90bf41 100644
--- a/host/lib/convert/gen_convert_pred.py
+++ b/host/lib/convert/gen_convert_pred.py
@@ -21,8 +21,6 @@ TMPL_TEXT = """
/***********************************************************************
* This file was generated by $file on $time.strftime("%c")
**********************************************************************/
-typedef size_t pred_type;
-
\#include <boost/tokenizer.hpp>
\#include <boost/lexical_cast.hpp>
\#include <boost/detail/endian.hpp>
@@ -31,6 +29,9 @@ typedef size_t pred_type;
\#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
@@ -69,8 +70,10 @@ pred_type make_pred(const std::string &markup, dir_type &dir){
dir = DIR_OTW_TO_CPU;
}
- if (cpu_type == "fc32") pred |= $ph.fc32_p;
+ 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;
@@ -99,44 +102,60 @@ pred_type make_pred(const std::string &markup, dir_type &dir){
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 = 0;
+ pred_type pred = $ph.item32_p; //only item32 supported as of now
- switch(otw_type.byteorder){
- \#ifdef BOOST_BIG_ENDIAN
- case otw_type_t::BO_BIG_ENDIAN: pred |= $ph.nswap_p; break;
- case otw_type_t::BO_LITTLE_ENDIAN: pred |= $ph.bswap_p; break;
- \#else
- case otw_type_t::BO_BIG_ENDIAN: pred |= $ph.bswap_p; break;
- case otw_type_t::BO_LITTLE_ENDIAN: pred |= $ph.nswap_p; break;
- \#endif
- case otw_type_t::BO_NATIVE: pred |= $ph.nswap_p; break;
- default: throw pred_error("unhandled otw byteorder type");
- }
+ 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)];
- switch(otw_type.get_sample_size()){
- case sizeof(boost::uint32_t): pred |= $ph.item32_p; break;
- default: throw pred_error("unhandled otw sample size");
- }
+ 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)];
- switch(io_type.tid){
- case io_type_t::COMPLEX_FLOAT32: pred |= $ph.fc32_p; break;
- case io_type_t::COMPLEX_INT16: pred |= $ph.sc16_p; break;
- default: throw pred_error("unhandled io type id");
- }
+ 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)];
- 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 (pred == pred_table_wildcard) throw pred_error(
+ "unhanded input combination for make_pred()"
+ );
return pred;
}
@@ -150,12 +169,14 @@ class ph:
bswap_p = 0b00001
nswap_p = 0b00000
item32_p = 0b00000
+ sc8_p = 0b00000
sc16_p = 0b00010
- fc32_p = 0b00000
+ fc32_p = 0b00100
+ fc64_p = 0b00110
chan1_p = 0b00000
- chan2_p = 0b00100
- chan3_p = 0b01000
- chan4_p = 0b01100
+ chan2_p = 0b01000
+ chan3_p = 0b10000
+ chan4_p = 0b11000
if __name__ == '__main__':
import sys, os