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.hpp292
-rw-r--r--host/lib/convert/convert_fc32_item32.cpp116
-rw-r--r--host/lib/convert/convert_impl.cpp131
-rw-r--r--host/lib/convert/convert_item32.cpp26
-rw-r--r--host/lib/convert/convert_pack_sc12.cpp151
-rw-r--r--host/lib/convert/convert_pack_sc12.hpp64
-rw-r--r--host/lib/convert/convert_unpack_sc12.cpp147
-rw-r--r--host/lib/convert/convert_unpack_sc12.hpp80
-rw-r--r--host/lib/convert/convert_with_neon.cpp122
-rw-r--r--host/lib/convert/convert_with_tables.cpp3
-rw-r--r--host/lib/convert/ssse3_pack_sc12.cpp180
-rw-r--r--host/lib/convert/ssse3_unpack_sc12.cpp136
12 files changed, 785 insertions, 663 deletions
diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp
index 0de344b75..6ee9a651a 100644
--- a/host/lib/convert/convert_common.hpp
+++ b/host/lib/convert/convert_common.hpp
@@ -13,24 +13,31 @@
#include <stdint.h>
#include <complex>
-#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;} \
+#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, &name::make, prio); \
- } \
- void name::operator()( \
- const input_type &inputs, const output_type &outputs, const size_t nsamps \
- )
+ }; \
+ 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, &name::make, prio); \
+ } \
+ void name::operator()( \
+ const input_type& inputs, const output_type& outputs, const size_t nsamps)
/*! Convenience macro to declare a single-function converter
*
@@ -41,76 +48,83 @@
* which runs the conversion. Available parameters in this function block
* are:
* - `inputs`: Vector of pointers to the input data. Size of the vector == `num_in`
- * - `outputs`: Vector of pointers to where the output data goes. Size of the vector == `num_out`
+ * - `outputs`: Vector of pointers to where the output data goes. Size of the vector ==
+ * `num_out`
* - `nsamps`: Number of items per input buffer to convert
* - `scale_factor`: Scaling factor for float conversions
*/
-#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)
+#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;
+static const int PRIORITY_EMPTY = -1;
#ifdef __ARM_NEON__
static const int PRIORITY_SIMD = 2;
-static const int PRIORITY_TABLE = 1; //tables require large cache, so they are slower on arm
+static const int PRIORITY_TABLE =
+ 1; // tables require large cache, so they are slower on arm
#else
// We used to have ORC, too, so SIMD is 3
-static const int PRIORITY_SIMD = 3;
+static const int PRIORITY_SIMD = 3;
static const int PRIORITY_TABLE = 1;
#endif
/***********************************************************************
* Typedefs
**********************************************************************/
-typedef std::complex<double> fc64_t;
-typedef std::complex<float> fc32_t;
+typedef std::complex<double> fc64_t;
+typedef std::complex<float> fc32_t;
typedef std::complex<int32_t> sc32_t;
typedef std::complex<int16_t> sc16_t;
-typedef std::complex<int8_t> sc8_t;
-typedef double f64_t;
-typedef float f32_t;
-typedef int32_t s32_t;
-typedef int16_t s16_t;
-typedef int8_t s8_t;
-typedef uint8_t u8_t;
+typedef std::complex<int8_t> sc8_t;
+typedef double f64_t;
+typedef float f32_t;
+typedef int32_t s32_t;
+typedef int16_t s16_t;
+typedef int8_t s8_t;
+typedef uint8_t u8_t;
-typedef uint32_t item32_t;
+typedef uint32_t item32_t;
typedef item32_t (*xtox_t)(item32_t);
/***********************************************************************
* Convert xx to items32 sc16 buffer
**********************************************************************/
-template <typename T> UHD_INLINE item32_t xx_to_item32_sc16_x1(
- const std::complex<T> &num, const double scale_factor
-){
- uint16_t real = int16_t(num.real()*float(scale_factor));
- uint16_t imag = int16_t(num.imag()*float(scale_factor));
+template <typename T>
+UHD_INLINE item32_t xx_to_item32_sc16_x1(
+ const std::complex<T>& num, const double scale_factor)
+{
+ uint16_t real = int16_t(num.real() * float(scale_factor));
+ uint16_t imag = int16_t(num.imag() * float(scale_factor));
return (item32_t(real) << 16) | (item32_t(imag) << 0);
}
-template <> UHD_INLINE item32_t xx_to_item32_sc16_x1(
- const sc16_t &num, const double
-){
+template <>
+UHD_INLINE item32_t xx_to_item32_sc16_x1(const sc16_t& num, const double)
+{
uint16_t real = int16_t(num.real());
uint16_t imag = int16_t(num.imag());
return (item32_t(real) << 16) | (item32_t(imag) << 0);
}
template <xtox_t to_wire, typename T>
-UHD_INLINE void xx_to_item32_sc16(
- const std::complex<T> *input,
- item32_t *output,
+UHD_INLINE void xx_to_item32_sc16(const std::complex<T>* input,
+ item32_t* output,
const size_t nsamps,
- const double scale_factor
-){
- for (size_t i = 0; i < nsamps; i++){
+ const double scale_factor)
+{
+ for (size_t i = 0; i < nsamps; i++) {
const item32_t item = xx_to_item32_sc16_x1(input[i], scale_factor);
- output[i] = to_wire(item);
+ output[i] = to_wire(item);
}
}
@@ -137,33 +151,29 @@ UHD_FORCE_INLINE void xx_to_chdr_sc16(const std::complex<T>* input,
/***********************************************************************
* Convert items32 sc16 buffer to xx
**********************************************************************/
-template <typename T> UHD_INLINE std::complex<T> item32_sc16_x1_to_xx(
- const item32_t item, const double scale_factor
-){
- return std::complex<T>(
- T(int16_t(item >> 16)*float(scale_factor)),
- T(int16_t(item >> 0)*float(scale_factor))
- );
+template <typename T>
+UHD_INLINE std::complex<T> item32_sc16_x1_to_xx(
+ const item32_t item, const double scale_factor)
+{
+ return std::complex<T>(T(int16_t(item >> 16) * float(scale_factor)),
+ T(int16_t(item >> 0) * float(scale_factor)));
}
-template <> UHD_INLINE sc16_t item32_sc16_x1_to_xx(
- const item32_t item, const double
-){
- return sc16_t(
- int16_t(item >> 16), int16_t(item >> 0)
- );
+template <>
+UHD_INLINE sc16_t item32_sc16_x1_to_xx(const item32_t item, const double)
+{
+ return sc16_t(int16_t(item >> 16), int16_t(item >> 0));
}
template <xtox_t to_host, typename T>
-UHD_INLINE void item32_sc16_to_xx(
- const item32_t *input,
- std::complex<T> *output,
+UHD_INLINE void item32_sc16_to_xx(const item32_t* input,
+ std::complex<T>* output,
const size_t nsamps,
- const double scale_factor
-){
- for (size_t i = 0; i < nsamps; i++){
+ const double scale_factor)
+{
+ for (size_t i = 0; i < nsamps; i++) {
const item32_t item_i = to_host(input[i]);
- output[i] = item32_sc16_x1_to_xx<T>(item_i, scale_factor);
+ output[i] = item32_sc16_x1_to_xx<T>(item_i, scale_factor);
}
}
@@ -189,60 +199,56 @@ UHD_FORCE_INLINE void chdr_sc16_to_xx(const sc16_t* input,
/***********************************************************************
* Convert xx to items32 sc8 buffer
**********************************************************************/
-template <typename T> UHD_INLINE item32_t xx_to_item32_sc8_x1(
- const std::complex<T> &in0, const std::complex<T> &in1, const double scale_factor
-){
- uint8_t real1 = int8_t(in0.real()*float(scale_factor));
- uint8_t imag1 = int8_t(in0.imag()*float(scale_factor));
- uint8_t real0 = int8_t(in1.real()*float(scale_factor));
- uint8_t imag0 = int8_t(in1.imag()*float(scale_factor));
- return
- (item32_t(real0) << 8) | (item32_t(imag0) << 0) |
- (item32_t(real1) << 24) | (item32_t(imag1) << 16)
- ;
+template <typename T>
+UHD_INLINE item32_t xx_to_item32_sc8_x1(
+ const std::complex<T>& in0, const std::complex<T>& in1, const double scale_factor)
+{
+ uint8_t real1 = int8_t(in0.real() * float(scale_factor));
+ uint8_t imag1 = int8_t(in0.imag() * float(scale_factor));
+ uint8_t real0 = int8_t(in1.real() * float(scale_factor));
+ uint8_t imag0 = int8_t(in1.imag() * float(scale_factor));
+ return (item32_t(real0) << 8) | (item32_t(imag0) << 0) | (item32_t(real1) << 24)
+ | (item32_t(imag1) << 16);
}
-template <> UHD_INLINE item32_t xx_to_item32_sc8_x1(
- const sc16_t &in0, const sc16_t &in1, const double
-){
+template <>
+UHD_INLINE item32_t xx_to_item32_sc8_x1(
+ const sc16_t& in0, const sc16_t& in1, const double)
+{
uint8_t real1 = int8_t(in0.real());
uint8_t imag1 = int8_t(in0.imag());
uint8_t real0 = int8_t(in1.real());
uint8_t imag0 = int8_t(in1.imag());
- return
- (item32_t(real0) << 8) | (item32_t(imag0) << 0) |
- (item32_t(real1) << 24) | (item32_t(imag1) << 16)
- ;
+ return (item32_t(real0) << 8) | (item32_t(imag0) << 0) | (item32_t(real1) << 24)
+ | (item32_t(imag1) << 16);
}
-template <> UHD_INLINE item32_t xx_to_item32_sc8_x1(
- const sc8_t &in0, const sc8_t &in1, const double
-){
+template <>
+UHD_INLINE item32_t xx_to_item32_sc8_x1(const sc8_t& in0, const sc8_t& in1, const double)
+{
uint8_t real1 = int8_t(in0.real());
uint8_t imag1 = int8_t(in0.imag());
uint8_t real0 = int8_t(in1.real());
uint8_t imag0 = int8_t(in1.imag());
- return
- (item32_t(real0) << 8) | (item32_t(imag0) << 0) |
- (item32_t(real1) << 24) | (item32_t(imag1) << 16)
- ;
+ return (item32_t(real0) << 8) | (item32_t(imag0) << 0) | (item32_t(real1) << 24)
+ | (item32_t(imag1) << 16);
}
template <xtox_t to_wire, typename T>
-UHD_INLINE void xx_to_item32_sc8(
- const std::complex<T> *input,
- item32_t *output,
+UHD_INLINE void xx_to_item32_sc8(const std::complex<T>* input,
+ item32_t* output,
const size_t nsamps,
- const double scale_factor
-){
- const size_t num_pairs = nsamps/2;
- for (size_t i = 0, j = 0; i < num_pairs; i++, j+=2){
- const item32_t item = xx_to_item32_sc8_x1(input[j], input[j+1], scale_factor);
- output[i] = to_wire(item);
+ const double scale_factor)
+{
+ const size_t num_pairs = nsamps / 2;
+ for (size_t i = 0, j = 0; i < num_pairs; i++, j += 2) {
+ const item32_t item = xx_to_item32_sc8_x1(input[j], input[j + 1], scale_factor);
+ output[i] = to_wire(item);
}
- if (nsamps != num_pairs*2){
- const item32_t item = xx_to_item32_sc8_x1(input[nsamps-1], std::complex<T>(0), scale_factor);
+ if (nsamps != num_pairs * 2) {
+ const item32_t item =
+ xx_to_item32_sc8_x1(input[nsamps - 1], std::complex<T>(0), scale_factor);
output[num_pairs] = to_wire(item);
}
}
@@ -250,71 +256,59 @@ UHD_INLINE void xx_to_item32_sc8(
/***********************************************************************
* Convert items32 sc8 buffer to xx
**********************************************************************/
-template <typename T> UHD_INLINE void item32_sc8_x1_to_xx(
- const item32_t item, std::complex<T> &out0, std::complex<T> &out1, const double scale_factor
-){
- out1 = std::complex<T>(
- T(int8_t(item >> 8)*float(scale_factor)),
- T(int8_t(item >> 0)*float(scale_factor))
- );
- out0 = std::complex<T>(
- T(int8_t(item >> 24)*float(scale_factor)),
- T(int8_t(item >> 16)*float(scale_factor))
- );
+template <typename T>
+UHD_INLINE void item32_sc8_x1_to_xx(const item32_t item,
+ std::complex<T>& out0,
+ std::complex<T>& out1,
+ const double scale_factor)
+{
+ out1 = std::complex<T>(T(int8_t(item >> 8) * float(scale_factor)),
+ T(int8_t(item >> 0) * float(scale_factor)));
+ out0 = std::complex<T>(T(int8_t(item >> 24) * float(scale_factor)),
+ T(int8_t(item >> 16) * float(scale_factor)));
}
-template <> UHD_INLINE void item32_sc8_x1_to_xx(
- const item32_t item, sc16_t &out0, sc16_t &out1, const double
-){
- out1 = sc16_t(
- int16_t(int8_t(item >> 8)),
- int16_t(int8_t(item >> 0))
- );
- out0 = sc16_t(
- int16_t(int8_t(item >> 24)),
- int16_t(int8_t(item >> 16))
- );
+template <>
+UHD_INLINE void item32_sc8_x1_to_xx(
+ const item32_t item, sc16_t& out0, sc16_t& out1, const double)
+{
+ out1 = sc16_t(int16_t(int8_t(item >> 8)), int16_t(int8_t(item >> 0)));
+ out0 = sc16_t(int16_t(int8_t(item >> 24)), int16_t(int8_t(item >> 16)));
}
-template <> UHD_INLINE void item32_sc8_x1_to_xx(
- const item32_t item, sc8_t &out0, sc8_t &out1, const double
-){
- out1 = sc8_t(
- int8_t(int8_t(item >> 8)),
- int8_t(int8_t(item >> 0))
- );
- out0 = sc8_t(
- int8_t(int8_t(item >> 24)),
- int8_t(int8_t(item >> 16))
- );
+template <>
+UHD_INLINE void item32_sc8_x1_to_xx(
+ const item32_t item, sc8_t& out0, sc8_t& out1, const double)
+{
+ out1 = sc8_t(int8_t(int8_t(item >> 8)), int8_t(int8_t(item >> 0)));
+ out0 = sc8_t(int8_t(int8_t(item >> 24)), int8_t(int8_t(item >> 16)));
}
template <xtox_t to_host, typename T>
-UHD_INLINE void item32_sc8_to_xx(
- const item32_t *input,
- std::complex<T> *output,
+UHD_INLINE void item32_sc8_to_xx(const item32_t* input,
+ std::complex<T>* output,
const size_t nsamps,
- const double scale_factor
-){
- input = reinterpret_cast<const item32_t *>(size_t(input) & ~0x3);
+ const double scale_factor)
+{
+ input = reinterpret_cast<const item32_t*>(size_t(input) & ~0x3);
std::complex<T> dummy;
size_t num_samps = nsamps;
- if ((size_t(input) & 0x3) != 0){
+ if ((size_t(input) & 0x3) != 0) {
const item32_t item0 = to_host(*input++);
item32_sc8_x1_to_xx(item0, dummy, *output++, scale_factor);
num_samps--;
}
- const size_t num_pairs = num_samps/2;
- for (size_t i = 0, j = 0; i < num_pairs; i++, j+=2){
+ 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 = to_host(input[i]);
- item32_sc8_x1_to_xx(item_i, output[j], output[j+1], scale_factor);
+ item32_sc8_x1_to_xx(item_i, output[j], output[j + 1], scale_factor);
}
- if (num_samps != num_pairs*2){
+ if (num_samps != num_pairs * 2) {
const item32_t item_n = to_host(input[num_pairs]);
- item32_sc8_x1_to_xx(item_n, output[num_samps-1], dummy, scale_factor);
+ item32_sc8_x1_to_xx(item_n, output[num_samps - 1], dummy, scale_factor);
}
}
diff --git a/host/lib/convert/convert_fc32_item32.cpp b/host/lib/convert/convert_fc32_item32.cpp
index b119fd877..713f565f5 100644
--- a/host/lib/convert/convert_fc32_item32.cpp
+++ b/host/lib/convert/convert_fc32_item32.cpp
@@ -18,9 +18,9 @@ typedef uint32_t (*to32_type)(uint32_t);
template <typename type, to32_type tohost>
struct convert_fc32_item32_1_to_star_1 : public converter
{
- convert_fc32_item32_1_to_star_1(void):_scalar(0.0)
+ convert_fc32_item32_1_to_star_1(void) : _scalar(0.0)
{
- //NOP
+ // NOP
}
void set_scalar(const double scalar)
@@ -28,19 +28,20 @@ struct convert_fc32_item32_1_to_star_1 : public converter
_scalar = scalar;
}
- void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps)
+ void operator()(
+ const input_type& inputs, const output_type& outputs, const size_t nsamps)
{
- const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]);
- std::complex<type> *output = reinterpret_cast<std::complex<type> *>(outputs[0]);
+ const item32_t* input = reinterpret_cast<const item32_t*>(inputs[0]);
+ std::complex<type>* output = reinterpret_cast<std::complex<type>*>(outputs[0]);
size_t i = 0;
- for (size_t o = 0; o < nsamps; o++)
- {
- const item32_t i32 = tohost(input[i++]);
- const item32_t q32 = tohost(input[i++]);
- const float *i_f32p = reinterpret_cast<const float *>(&i32);
- const float *q_f32p = reinterpret_cast<const float *>(&q32);
- output[o] = std::complex<type>(type((*i_f32p)*_scalar), type((*q_f32p)*_scalar));
+ for (size_t o = 0; o < nsamps; o++) {
+ const item32_t i32 = tohost(input[i++]);
+ const item32_t q32 = tohost(input[i++]);
+ const float* i_f32p = reinterpret_cast<const float*>(&i32);
+ const float* q_f32p = reinterpret_cast<const float*>(&q32);
+ output[o] =
+ std::complex<type>(type((*i_f32p) * _scalar), type((*q_f32p) * _scalar));
}
}
@@ -50,9 +51,9 @@ struct convert_fc32_item32_1_to_star_1 : public converter
template <typename type, to32_type towire>
struct convert_star_1_to_fc32_item32_1 : public converter
{
- convert_star_1_to_fc32_item32_1(void):_scalar(0.0)
+ convert_star_1_to_fc32_item32_1(void) : _scalar(0.0)
{
- //NOP
+ // NOP
}
void set_scalar(const double scalar)
@@ -60,45 +61,66 @@ struct convert_star_1_to_fc32_item32_1 : public converter
_scalar = scalar;
}
- void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps)
+ void operator()(
+ const input_type& inputs, const output_type& outputs, const size_t nsamps)
{
- const std::complex<type> *input = reinterpret_cast<const std::complex<type> *>(inputs[0]);
- item32_t *output = reinterpret_cast<item32_t *>(outputs[0]);
+ const std::complex<type>* input =
+ reinterpret_cast<const std::complex<type>*>(inputs[0]);
+ item32_t* output = reinterpret_cast<item32_t*>(outputs[0]);
size_t o = 0;
- for (size_t i = 0; i < nsamps; i++)
- {
- const float i_f32 = type(input[i].real()*_scalar);
- const float q_f32 = type(input[i].imag()*_scalar);
- const item32_t *i32p = reinterpret_cast<const item32_t *>(&i_f32);
- const item32_t *q32p = reinterpret_cast<const item32_t *>(&q_f32);
- output[o++] = towire(*i32p);
- output[o++] = towire(*q32p);
+ for (size_t i = 0; i < nsamps; i++) {
+ const float i_f32 = type(input[i].real() * _scalar);
+ const float q_f32 = type(input[i].imag() * _scalar);
+ const item32_t* i32p = reinterpret_cast<const item32_t*>(&i_f32);
+ const item32_t* q32p = reinterpret_cast<const item32_t*>(&q_f32);
+ output[o++] = towire(*i32p);
+ output[o++] = towire(*q32p);
}
}
double _scalar;
};
-#define __make_registrations(itype, otype, fcn, type, conv) \
-static converter::sptr make_convert_ ## itype ## _1_ ## otype ## _1(void) \
-{ \
- return converter::sptr(new fcn<type, conv>()); \
-} \
-UHD_STATIC_BLOCK(register_convert_ ## itype ## _1_ ## otype ## _1) \
-{ \
- uhd::convert::id_type id; \
- id.num_inputs = 1; id.num_outputs = 1; \
- id.input_format = #itype; id.output_format = #otype; \
- uhd::convert::register_converter(id, &make_convert_ ## itype ## _1_ ## otype ## _1, PRIORITY_GENERAL); \
-}
-
-__make_registrations(fc32_item32_le, fc32, convert_fc32_item32_1_to_star_1, float, uhd::wtohx)
-__make_registrations(fc32_item32_be, fc32, convert_fc32_item32_1_to_star_1, float, uhd::ntohx)
-__make_registrations(fc32_item32_le, fc64, convert_fc32_item32_1_to_star_1, double, uhd::wtohx)
-__make_registrations(fc32_item32_be, fc64, convert_fc32_item32_1_to_star_1, double, uhd::ntohx)
-
-__make_registrations(fc32, fc32_item32_le, convert_star_1_to_fc32_item32_1, float, uhd::wtohx)
-__make_registrations(fc32, fc32_item32_be, convert_star_1_to_fc32_item32_1, float, uhd::ntohx)
-__make_registrations(fc64, fc32_item32_le, convert_star_1_to_fc32_item32_1, double, uhd::wtohx)
-__make_registrations(fc64, fc32_item32_be, convert_star_1_to_fc32_item32_1, double, uhd::ntohx)
+#define __make_registrations(itype, otype, fcn, type, conv) \
+ static converter::sptr make_convert_##itype##_1_##otype##_1(void) \
+ { \
+ return converter::sptr(new fcn<type, conv>()); \
+ } \
+ UHD_STATIC_BLOCK(register_convert_##itype##_1_##otype##_1) \
+ { \
+ uhd::convert::id_type id; \
+ id.num_inputs = 1; \
+ id.num_outputs = 1; \
+ id.input_format = #itype; \
+ id.output_format = #otype; \
+ uhd::convert::register_converter( \
+ id, &make_convert_##itype##_1_##otype##_1, PRIORITY_GENERAL); \
+ }
+
+__make_registrations(
+ fc32_item32_le, fc32, convert_fc32_item32_1_to_star_1, float, uhd::wtohx)
+ __make_registrations(
+ fc32_item32_be, fc32, convert_fc32_item32_1_to_star_1, float, uhd::ntohx)
+ __make_registrations(
+ fc32_item32_le, fc64, convert_fc32_item32_1_to_star_1, double, uhd::wtohx)
+ __make_registrations(
+ fc32_item32_be, fc64, convert_fc32_item32_1_to_star_1, double, uhd::ntohx)
+
+ __make_registrations(fc32,
+ fc32_item32_le,
+ convert_star_1_to_fc32_item32_1,
+ float,
+ uhd::wtohx) __make_registrations(fc32,
+ fc32_item32_be,
+ convert_star_1_to_fc32_item32_1,
+ float,
+ uhd::ntohx) __make_registrations(fc64,
+ fc32_item32_le,
+ convert_star_1_to_fc32_item32_1,
+ double,
+ uhd::wtohx) __make_registrations(fc64,
+ fc32_item32_be,
+ convert_star_1_to_fc32_item32_1,
+ double,
+ uhd::ntohx)
diff --git a/host/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp
index 6385965f0..228f15552 100644
--- a/host/lib/convert/convert_impl.cpp
+++ b/host/lib/convert/convert_impl.cpp
@@ -6,91 +6,84 @@
//
#include <uhd/convert.hpp>
+#include <uhd/exception.hpp>
+#include <uhd/types/dict.hpp>
#include <uhd/utils/log.hpp>
#include <uhd/utils/static.hpp>
-#include <uhd/types/dict.hpp>
-#include <uhd/exception.hpp>
#include <stdint.h>
#include <boost/format.hpp>
#include <complex>
using namespace uhd;
-convert::converter::~converter(void){
+convert::converter::~converter(void)
+{
/* NOP */
}
-bool convert::operator==(const convert::id_type &lhs, const convert::id_type &rhs){
- return true
- and (lhs.input_format == rhs.input_format)
- and (lhs.num_inputs == rhs.num_inputs)
- and (lhs.output_format == rhs.output_format)
- and (lhs.num_outputs == rhs.num_outputs)
- ;
+bool convert::operator==(const convert::id_type& lhs, const convert::id_type& rhs)
+{
+ return true and (lhs.input_format == rhs.input_format)
+ and (lhs.num_inputs == rhs.num_inputs)
+ and (lhs.output_format == rhs.output_format)
+ and (lhs.num_outputs == rhs.num_outputs);
}
-std::string convert::id_type::to_pp_string(void) const{
- return str(boost::format(
- "conversion ID\n"
- " Input format: %s\n"
- " Num inputs: %d\n"
- " Output format: %s\n"
- " Num outputs: %d\n"
- )
- % this->input_format
- % this->num_inputs
- % this->output_format
- % this->num_outputs
- );
+std::string convert::id_type::to_pp_string(void) const
+{
+ return str(boost::format("conversion ID\n"
+ " Input format: %s\n"
+ " Num inputs: %d\n"
+ " Output format: %s\n"
+ " Num outputs: %d\n")
+ % this->input_format % this->num_inputs % this->output_format
+ % this->num_outputs);
}
-std::string convert::id_type::to_string(void) const{
- return str(boost::format("%s (%d) -> %s (%d)")
- % this->input_format
- % this->num_inputs
- % this->output_format
- % this->num_outputs
- );
+std::string convert::id_type::to_string(void) const
+{
+ return str(boost::format("%s (%d) -> %s (%d)") % this->input_format % this->num_inputs
+ % this->output_format % this->num_outputs);
}
/***********************************************************************
* Setup the table registry
**********************************************************************/
-typedef uhd::dict<convert::id_type, uhd::dict<convert::priority_type, convert::function_type> > fcn_table_type;
+typedef uhd::dict<convert::id_type,
+ uhd::dict<convert::priority_type, convert::function_type>>
+ fcn_table_type;
UHD_SINGLETON_FCN(fcn_table_type, get_table);
/***********************************************************************
* The registry functions
**********************************************************************/
void uhd::convert::register_converter(
- const id_type &id,
- const function_type &fcn,
- const priority_type prio
-){
+ const id_type& id, const function_type& fcn, const priority_type prio)
+{
get_table()[id][prio] = fcn;
//----------------------------------------------------------------//
- //UHD_LOG_TRACE("CONVERT", boost::format("register_converter: %s prio: %s") % id.to_string() % prio)
+ // UHD_LOG_TRACE("CONVERT", boost::format("register_converter: %s prio: %s") %
+ // id.to_string() % prio)
//----------------------------------------------------------------//
}
/***********************************************************************
* The converter functions
**********************************************************************/
-convert::function_type convert::get_converter(
- const id_type &id,
- const priority_type prio
-){
- if (not get_table().has_key(id)) throw uhd::key_error(
- "Cannot find a conversion routine for " + id.to_pp_string());
-
- //find a matching priority
+convert::function_type convert::get_converter(const id_type& id, const priority_type prio)
+{
+ if (not get_table().has_key(id))
+ throw uhd::key_error("Cannot find a conversion routine for " + id.to_pp_string());
+
+ // find a matching priority
priority_type best_prio = -1;
- for(priority_type prio_i: get_table()[id].keys()){
+ for (priority_type prio_i : get_table()[id].keys()) {
if (prio_i == prio) {
//----------------------------------------------------------------//
- UHD_LOGGER_DEBUG("CONVERT") << "get_converter: For converter ID: " << id.to_pp_string()
- << " Using prio: " << prio;
+ UHD_LOGGER_DEBUG("CONVERT")
+ << "get_converter: For converter ID: " << id.to_pp_string()
+ << " Using prio: " << prio;
;
//----------------------------------------------------------------//
return get_table()[id][prio];
@@ -98,16 +91,18 @@ convert::function_type convert::get_converter(
best_prio = std::max(best_prio, prio_i);
}
- //wanted a specific prio, didnt find
- if (prio != -1) throw uhd::key_error(
- "Cannot find a conversion routine [with prio] for " + id.to_pp_string());
+ // wanted a specific prio, didnt find
+ if (prio != -1)
+ throw uhd::key_error(
+ "Cannot find a conversion routine [with prio] for " + id.to_pp_string());
//----------------------------------------------------------------//
- UHD_LOGGER_DEBUG("CONVERT") << "get_converter: For converter ID: " << id.to_pp_string()
- << " Using prio: " << best_prio;
+ UHD_LOGGER_DEBUG("CONVERT")
+ << "get_converter: For converter ID: " << id.to_pp_string()
+ << " Using prio: " << best_prio;
//----------------------------------------------------------------//
- //otherwise, return best prio
+ // otherwise, return best prio
return get_table()[id][best_prio];
}
@@ -117,29 +112,31 @@ convert::function_type convert::get_converter(
typedef uhd::dict<std::string, size_t> item_size_type;
UHD_SINGLETON_FCN(item_size_type, get_item_size_table);
-void convert::register_bytes_per_item(
- const std::string &format, const size_t size
-){
+void convert::register_bytes_per_item(const std::string& format, const size_t size)
+{
get_item_size_table()[format] = size;
}
-size_t convert::get_bytes_per_item(const std::string &format){
- if (get_item_size_table().has_key(format)) return get_item_size_table()[format];
+size_t convert::get_bytes_per_item(const std::string& format)
+{
+ if (get_item_size_table().has_key(format))
+ return get_item_size_table()[format];
- //OK. I am sorry about this.
- //We didnt find a match, so lets find a match for the first term.
- //This is partially a hack because of the way I append strings.
- //But as long as life is kind, we can keep this.
+ // OK. I am sorry about this.
+ // We didnt find a match, so lets find a match for the first term.
+ // This is partially a hack because of the way I append strings.
+ // But as long as life is kind, we can keep this.
const size_t pos = format.find("_");
- if (pos != std::string::npos){
+ if (pos != std::string::npos) {
return get_bytes_per_item(format.substr(0, pos));
}
throw uhd::key_error("[convert] Cannot find an item size for: `" + format + "'");
}
-UHD_STATIC_BLOCK(convert_register_item_sizes){
- //register standard complex types
+UHD_STATIC_BLOCK(convert_register_item_sizes)
+{
+ // register standard complex types
convert::register_bytes_per_item("fc64", sizeof(std::complex<double>));
convert::register_bytes_per_item("fc32", sizeof(std::complex<float>));
convert::register_bytes_per_item("sc64", sizeof(std::complex<int64_t>));
@@ -147,7 +144,7 @@ UHD_STATIC_BLOCK(convert_register_item_sizes){
convert::register_bytes_per_item("sc16", sizeof(std::complex<int16_t>));
convert::register_bytes_per_item("sc8", sizeof(std::complex<int8_t>));
- //register standard real types
+ // register standard real types
convert::register_bytes_per_item("f64", sizeof(double));
convert::register_bytes_per_item("f32", sizeof(float));
convert::register_bytes_per_item("s64", sizeof(int64_t));
@@ -156,6 +153,6 @@ UHD_STATIC_BLOCK(convert_register_item_sizes){
convert::register_bytes_per_item("s8", sizeof(int8_t));
convert::register_bytes_per_item("u8", sizeof(uint8_t));
- //register VITA types
+ // register VITA types
convert::register_bytes_per_item("item32", sizeof(int32_t));
}
diff --git a/host/lib/convert/convert_item32.cpp b/host/lib/convert/convert_item32.cpp
index 142a842bb..5d8361079 100644
--- a/host/lib/convert/convert_item32.cpp
+++ b/host/lib/convert/convert_item32.cpp
@@ -8,23 +8,25 @@
#include "convert_common.hpp"
#include <uhd/utils/byteswap.hpp>
-#define __DECLARE_ITEM32_CONVERTER(cpu_type, wire_type, xe, htoxx, xxtoh) \
- DECLARE_CONVERTER(cpu_type, 1, wire_type ## _item32_ ## xe, 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]); \
- xx_to_item32_ ## wire_type<htoxx>(input, output, nsamps, scale_factor); \
- } \
- DECLARE_CONVERTER(wire_type ## _item32_ ## xe, 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]); \
- item32_ ## wire_type ## _to_xx<xxtoh>(input, output, nsamps, scale_factor); \
+#define __DECLARE_ITEM32_CONVERTER(cpu_type, wire_type, xe, htoxx, xxtoh) \
+ DECLARE_CONVERTER(cpu_type, 1, wire_type##_item32_##xe, 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]); \
+ xx_to_item32_##wire_type<htoxx>(input, output, nsamps, scale_factor); \
+ } \
+ DECLARE_CONVERTER(wire_type##_item32_##xe, 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]); \
+ item32_##wire_type##_to_xx<xxtoh>(input, output, nsamps, scale_factor); \
}
-#define _DECLARE_ITEM32_CONVERTER(cpu_type, wire_type) \
+#define _DECLARE_ITEM32_CONVERTER(cpu_type, wire_type) \
__DECLARE_ITEM32_CONVERTER(cpu_type, wire_type, be, uhd::htonx, uhd::ntohx) \
__DECLARE_ITEM32_CONVERTER(cpu_type, wire_type, le, uhd::htowx, uhd::wtohx)
-#define DECLARE_ITEM32_CONVERTER(cpu_type) \
+#define DECLARE_ITEM32_CONVERTER(cpu_type) \
_DECLARE_ITEM32_CONVERTER(cpu_type, sc8) \
_DECLARE_ITEM32_CONVERTER(cpu_type, sc16)
diff --git a/host/lib/convert/convert_pack_sc12.cpp b/host/lib/convert/convert_pack_sc12.cpp
index 97a4af206..ee28e00cd 100644
--- a/host/lib/convert/convert_pack_sc12.cpp
+++ b/host/lib/convert/convert_pack_sc12.cpp
@@ -12,9 +12,9 @@ using namespace uhd::convert;
template <typename type, towire32_type towire>
struct convert_star_1_to_sc12_item32_1 : public converter
{
- convert_star_1_to_sc12_item32_1(void):_scalar(0.0)
+ convert_star_1_to_sc12_item32_1(void) : _scalar(0.0)
{
- //NOP
+ // NOP
}
void set_scalar(const double scalar)
@@ -22,74 +22,99 @@ struct convert_star_1_to_sc12_item32_1 : public converter
_scalar = scalar;
}
- void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps)
+ void operator()(
+ const input_type& inputs, const output_type& outputs, const size_t nsamps)
{
- const std::complex<type> *input = reinterpret_cast<const std::complex<type> *>(inputs[0]);
+ const std::complex<type>* input =
+ reinterpret_cast<const std::complex<type>*>(inputs[0]);
/*
- * Effectively outputs will point to a managed_buffer instance. These buffers are 32 bit aligned.
- * For a detailed description see comments in 'convert_unpack_sc12.cpp'.
+ * Effectively outputs will point to a managed_buffer instance. These buffers are
+ * 32 bit aligned. For a detailed description see comments in
+ * 'convert_unpack_sc12.cpp'.
*/
const size_t head_samps = size_t(outputs[0]) & 0x3;
int enable;
size_t rewind = 0;
- switch(head_samps)
- {
- case 0: break;
- case 1: rewind = 9; break;
- case 2: rewind = 6; break;
- case 3: rewind = 3; break;
+ switch (head_samps) {
+ case 0:
+ break;
+ case 1:
+ rewind = 9;
+ break;
+ case 2:
+ rewind = 6;
+ break;
+ case 3:
+ rewind = 3;
+ break;
}
- item32_sc12_3x *output = reinterpret_cast<item32_sc12_3x *>(size_t(outputs[0]) - rewind);
+ item32_sc12_3x* output =
+ reinterpret_cast<item32_sc12_3x*>(size_t(outputs[0]) - rewind);
- //helper variables
+ // helper variables
size_t i = 0, o = 0;
- //handle the head case
- switch (head_samps)
- {
- case 0:
- break; //no head
- case 1:
- enable = CONVERT12_LINE2;
- convert_star_4_to_sc12_item32_3<type, towire>(0, 0, 0, input[0], enable, output[o++], _scalar);
- break;
- case 2:
- enable = CONVERT12_LINE2 | CONVERT12_LINE1;
- convert_star_4_to_sc12_item32_3<type, towire>(0, 0, input[0], input[1], enable, output[o++], _scalar);
- break;
- case 3:
- enable = CONVERT12_LINE2 | CONVERT12_LINE1 | CONVERT12_LINE0;
- convert_star_4_to_sc12_item32_3<type, towire>(0, input[0], input[1], input[2], enable, output[o++], _scalar);
- break;
+ // handle the head case
+ switch (head_samps) {
+ case 0:
+ break; // no head
+ case 1:
+ enable = CONVERT12_LINE2;
+ convert_star_4_to_sc12_item32_3<type, towire>(
+ 0, 0, 0, input[0], enable, output[o++], _scalar);
+ break;
+ case 2:
+ enable = CONVERT12_LINE2 | CONVERT12_LINE1;
+ convert_star_4_to_sc12_item32_3<type, towire>(
+ 0, 0, input[0], input[1], enable, output[o++], _scalar);
+ break;
+ case 3:
+ enable = CONVERT12_LINE2 | CONVERT12_LINE1 | CONVERT12_LINE0;
+ convert_star_4_to_sc12_item32_3<type, towire>(
+ 0, input[0], input[1], input[2], enable, output[o++], _scalar);
+ break;
}
i += head_samps;
- //convert the body
- while (i+3 < nsamps)
- {
- convert_star_4_to_sc12_item32_3<type, towire>(input[i+0], input[i+1], input[i+2], input[i+3], CONVERT12_LINE_ALL, output[o], _scalar);
- o++; i += 4;
+ // convert the body
+ while (i + 3 < nsamps) {
+ convert_star_4_to_sc12_item32_3<type, towire>(input[i + 0],
+ input[i + 1],
+ input[i + 2],
+ input[i + 3],
+ CONVERT12_LINE_ALL,
+ output[o],
+ _scalar);
+ o++;
+ i += 4;
}
- //handle the tail case
+ // handle the tail case
const size_t tail_samps = nsamps - i;
- switch (tail_samps)
- {
- case 0:
- break; //no tail
- case 1:
- enable = CONVERT12_LINE0;
- convert_star_4_to_sc12_item32_3<type, towire>(input[i+0], 0, 0, 0, enable, output[o], _scalar);
- break;
- case 2:
- enable = CONVERT12_LINE0 | CONVERT12_LINE1;
- convert_star_4_to_sc12_item32_3<type, towire>(input[i+0], input[i+1], 0, 0, enable, output[o], _scalar);
- break;
- case 3:
- enable = CONVERT12_LINE0 | CONVERT12_LINE1 | CONVERT12_LINE2;
- convert_star_4_to_sc12_item32_3<type, towire>(input[i+0], input[i+1], input[i+2], 0, enable, output[o], _scalar);
- break;
+ switch (tail_samps) {
+ case 0:
+ break; // no tail
+ case 1:
+ enable = CONVERT12_LINE0;
+ convert_star_4_to_sc12_item32_3<type, towire>(
+ input[i + 0], 0, 0, 0, enable, output[o], _scalar);
+ break;
+ case 2:
+ enable = CONVERT12_LINE0 | CONVERT12_LINE1;
+ convert_star_4_to_sc12_item32_3<type, towire>(
+ input[i + 0], input[i + 1], 0, 0, enable, output[o], _scalar);
+ break;
+ case 3:
+ enable = CONVERT12_LINE0 | CONVERT12_LINE1 | CONVERT12_LINE2;
+ convert_star_4_to_sc12_item32_3<type, towire>(input[i + 0],
+ input[i + 1],
+ input[i + 2],
+ 0,
+ enable,
+ output[o],
+ _scalar);
+ break;
}
}
@@ -118,21 +143,25 @@ static converter::sptr make_convert_sc16_1_to_sc12_item32_be_1(void)
UHD_STATIC_BLOCK(register_convert_pack_sc12)
{
- //uhd::convert::register_bytes_per_item("sc12", 3/*bytes*/); //registered in unpack
+ // uhd::convert::register_bytes_per_item("sc12", 3/*bytes*/); //registered in unpack
uhd::convert::id_type id;
- id.num_inputs = 1;
+ id.num_inputs = 1;
id.num_outputs = 1;
- id.input_format = "fc32";
+ id.input_format = "fc32";
id.output_format = "sc12_item32_le";
- uhd::convert::register_converter(id, &make_convert_fc32_1_to_sc12_item32_le_1, PRIORITY_GENERAL);
+ uhd::convert::register_converter(
+ id, &make_convert_fc32_1_to_sc12_item32_le_1, PRIORITY_GENERAL);
id.output_format = "sc12_item32_be";
- uhd::convert::register_converter(id, &make_convert_fc32_1_to_sc12_item32_be_1, PRIORITY_GENERAL);
+ uhd::convert::register_converter(
+ id, &make_convert_fc32_1_to_sc12_item32_be_1, PRIORITY_GENERAL);
- id.input_format = "sc16";
+ id.input_format = "sc16";
id.output_format = "sc12_item32_le";
- uhd::convert::register_converter(id, &make_convert_sc16_1_to_sc12_item32_le_1, PRIORITY_GENERAL);
+ uhd::convert::register_converter(
+ id, &make_convert_sc16_1_to_sc12_item32_le_1, PRIORITY_GENERAL);
id.output_format = "sc12_item32_be";
- uhd::convert::register_converter(id, &make_convert_sc16_1_to_sc12_item32_be_1, PRIORITY_GENERAL);
+ uhd::convert::register_converter(
+ id, &make_convert_sc16_1_to_sc12_item32_be_1, PRIORITY_GENERAL);
}
diff --git a/host/lib/convert/convert_pack_sc12.hpp b/host/lib/convert/convert_pack_sc12.hpp
index 053236e6f..08ec98b10 100644
--- a/host/lib/convert/convert_pack_sc12.hpp
+++ b/host/lib/convert/convert_pack_sc12.hpp
@@ -5,9 +5,9 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
-#include <type_traits>
-#include <uhd/utils/byteswap.hpp>
#include "convert_common.hpp"
+#include <uhd/utils/byteswap.hpp>
+#include <type_traits>
using namespace uhd::convert;
@@ -26,9 +26,9 @@ struct item32_sc12_3x
};
enum item32_sc12_3x_enable {
- CONVERT12_LINE0 = 0x01,
- CONVERT12_LINE1 = 0x02,
- CONVERT12_LINE2 = 0x04,
+ CONVERT12_LINE0 = 0x01,
+ CONVERT12_LINE1 = 0x02,
+ CONVERT12_LINE2 = 0x04,
CONVERT12_LINE_ALL = 0x07,
};
@@ -48,10 +48,10 @@ enum item32_sc12_3x_enable {
* 31 0
*/
template <towire32_type towire>
-void pack(item32_sc12_3x &output, int enable, const int32_t iq[8])
+void pack(item32_sc12_3x& output, int enable, const int32_t iq[8])
{
if (enable & CONVERT12_LINE0)
- output.line0 = towire(iq[0] << 20 | iq[1] << 8 | iq[2] >> 4);
+ output.line0 = towire(iq[0] << 20 | iq[1] << 8 | iq[2] >> 4);
if (enable & CONVERT12_LINE1)
output.line1 = towire(iq[2] << 28 | iq[3] << 16 | iq[4] << 4 | iq[5] >> 8);
if (enable & CONVERT12_LINE2)
@@ -59,46 +59,40 @@ void pack(item32_sc12_3x &output, int enable, const int32_t iq[8])
}
template <typename type, towire32_type towire>
-void convert_star_4_to_sc12_item32_3
-(
- const std::complex<type> &in0,
- const std::complex<type> &in1,
- const std::complex<type> &in2,
- const std::complex<type> &in3,
+void convert_star_4_to_sc12_item32_3(const std::complex<type>& in0,
+ const std::complex<type>& in1,
+ const std::complex<type>& in2,
+ const std::complex<type>& in3,
const int enable,
- item32_sc12_3x &output,
+ item32_sc12_3x& output,
const double scalar,
- typename std::enable_if<std::is_floating_point<type>::value>::type* = NULL
-)
+ typename std::enable_if<std::is_floating_point<type>::value>::type* = NULL)
{
- int32_t iq[8] {
- int32_t(in0.real()*scalar) & 0xfff,
- int32_t(in0.imag()*scalar) & 0xfff,
- int32_t(in1.real()*scalar) & 0xfff,
- int32_t(in1.imag()*scalar) & 0xfff,
+ int32_t iq[8]{
+ int32_t(in0.real() * scalar) & 0xfff,
+ int32_t(in0.imag() * scalar) & 0xfff,
+ int32_t(in1.real() * scalar) & 0xfff,
+ int32_t(in1.imag() * scalar) & 0xfff,
- int32_t(in2.real()*scalar) & 0xfff,
- int32_t(in2.imag()*scalar) & 0xfff,
- int32_t(in3.real()*scalar) & 0xfff,
- int32_t(in3.imag()*scalar) & 0xfff,
+ int32_t(in2.real() * scalar) & 0xfff,
+ int32_t(in2.imag() * scalar) & 0xfff,
+ int32_t(in3.real() * scalar) & 0xfff,
+ int32_t(in3.imag() * scalar) & 0xfff,
};
pack<towire>(output, enable, iq);
}
template <typename type, towire32_type towire>
-void convert_star_4_to_sc12_item32_3
-(
- const std::complex<type> &in0,
- const std::complex<type> &in1,
- const std::complex<type> &in2,
- const std::complex<type> &in3,
+void convert_star_4_to_sc12_item32_3(const std::complex<type>& in0,
+ const std::complex<type>& in1,
+ const std::complex<type>& in2,
+ const std::complex<type>& in3,
const int enable,
- item32_sc12_3x &output,
+ item32_sc12_3x& output,
const double,
- typename std::enable_if<std::is_same<type, short>::value>::type* = NULL
-)
+ typename std::enable_if<std::is_same<type, short>::value>::type* = NULL)
{
- int32_t iq[8] {
+ int32_t iq[8]{
int32_t(in0.real() >> 4) & 0xfff,
int32_t(in0.imag() >> 4) & 0xfff,
int32_t(in1.real() >> 4) & 0xfff,
diff --git a/host/lib/convert/convert_unpack_sc12.cpp b/host/lib/convert/convert_unpack_sc12.cpp
index 9f0a14a77..9ec43a5c3 100644
--- a/host/lib/convert/convert_unpack_sc12.cpp
+++ b/host/lib/convert/convert_unpack_sc12.cpp
@@ -12,25 +12,27 @@ using namespace uhd::convert;
template <typename type, tohost32_type tohost>
struct convert_sc12_item32_1_to_star_1 : public converter
{
- convert_sc12_item32_1_to_star_1(void):_scalar(0.0)
+ convert_sc12_item32_1_to_star_1(void) : _scalar(0.0)
{
- //NOP
+ // NOP
}
void set_scalar(const double scalar)
{
const int unpack_growth = 16;
- _scalar = scalar/unpack_growth;
+ _scalar = scalar / unpack_growth;
}
/*
- * This converter takes in 24 bits complex samples, 12 bits I and 12 bits Q, and converts them to type 'std::complex<type>'.
- * 'type' is usually 'float'.
- * For the converter to work correctly the used managed_buffer which holds all samples of one packet has to be 32 bits aligned.
- * We assume 32 bits to be one line. This said the converter must be aware where it is supposed to start within 3 lines.
+ * This converter takes in 24 bits complex samples, 12 bits I and 12 bits Q, and
+ * converts them to type 'std::complex<type>'. 'type' is usually 'float'. For the
+ * converter to work correctly the used managed_buffer which holds all samples of one
+ * packet has to be 32 bits aligned. We assume 32 bits to be one line. This said the
+ * converter must be aware where it is supposed to start within 3 lines.
*
*/
- void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps)
+ void operator()(
+ const input_type& inputs, const output_type& outputs, const size_t nsamps)
{
/*
* Looking at the line structure above we can identify 4 cases.
@@ -39,67 +41,102 @@ struct convert_sc12_item32_1_to_star_1 : public converter
* Then the number of bytes the converter has to rewind are calculated.
*/
const size_t head_samps = size_t(inputs[0]) & 0x3;
- size_t rewind = 0;
- switch(head_samps)
- {
- case 0: break;
- case 1: rewind = 9; break;
- case 2: rewind = 6; break;
- case 3: rewind = 3; break;
+ size_t rewind = 0;
+ switch (head_samps) {
+ case 0:
+ break;
+ case 1:
+ rewind = 9;
+ break;
+ case 2:
+ rewind = 6;
+ break;
+ case 3:
+ rewind = 3;
+ break;
}
/*
* The pointer *input now points to the head of a 3 line block.
*/
- const item32_sc12_3x *input = reinterpret_cast<const item32_sc12_3x *>(size_t(inputs[0]) - rewind);
- std::complex<type> *output = reinterpret_cast<std::complex<type> *>(outputs[0]);
+ const item32_sc12_3x* input =
+ reinterpret_cast<const item32_sc12_3x*>(size_t(inputs[0]) - rewind);
+ std::complex<type>* output = reinterpret_cast<std::complex<type>*>(outputs[0]);
- //helper variables
+ // helper variables
std::complex<type> dummy0, dummy1, dummy2;
size_t i = 0, o = 0;
/*
* handle the head case
* head_samps holds the number of samples left in a block.
- * The 3 line converter is called for the whole block and already processed samples are dumped.
- * We don't run into the risk of a SIGSEGV because input will always point to valid memory within a managed_buffer.
- * Furthermore the bytes in a buffer remain unchanged after they have been copied into it.
+ * The 3 line converter is called for the whole block and already processed
+ * samples are dumped. We don't run into the risk of a SIGSEGV because input will
+ * always point to valid memory within a managed_buffer. Furthermore the bytes in
+ * a buffer remain unchanged after they have been copied into it.
*/
- switch (head_samps)
- {
- case 0: break; //no head
- case 1: convert_sc12_item32_3_to_star_4<type, tohost>(input[i++], dummy0, dummy1, dummy2, output[0], _scalar); break;
- case 2: convert_sc12_item32_3_to_star_4<type, tohost>(input[i++], dummy0, dummy1, output[0], output[1], _scalar); break;
- case 3: convert_sc12_item32_3_to_star_4<type, tohost>(input[i++], dummy0, output[0], output[1], output[2], _scalar); break;
+ switch (head_samps) {
+ case 0:
+ break; // no head
+ case 1:
+ convert_sc12_item32_3_to_star_4<type, tohost>(
+ input[i++], dummy0, dummy1, dummy2, output[0], _scalar);
+ break;
+ case 2:
+ convert_sc12_item32_3_to_star_4<type, tohost>(
+ input[i++], dummy0, dummy1, output[0], output[1], _scalar);
+ break;
+ case 3:
+ convert_sc12_item32_3_to_star_4<type, tohost>(
+ input[i++], dummy0, output[0], output[1], output[2], _scalar);
+ break;
}
o += head_samps;
- //convert the body
- while (o+3 < nsamps)
- {
- convert_sc12_item32_3_to_star_4<type, tohost>(input[i], output[o+0], output[o+1], output[o+2], output[o+3], _scalar);
- i++; o += 4;
+ // convert the body
+ while (o + 3 < nsamps) {
+ convert_sc12_item32_3_to_star_4<type, tohost>(input[i],
+ output[o + 0],
+ output[o + 1],
+ output[o + 2],
+ output[o + 3],
+ _scalar);
+ i++;
+ o += 4;
}
/*
* handle the tail case
* The converter can be called with any number of samples to be converted.
* This can end up in only a part of a block to be converted in one call.
- * We never have to worry about SIGSEGVs here as long as we end in the middle of a managed_buffer.
- * If we are at the end of managed_buffer there are 2 precautions to prevent SIGSEGVs.
- * Firstly only a read operation is performed.
- * Secondly managed_buffers allocate a fixed size memory which is always larger than the actually used size.
- * e.g. The current sample maximum is 2000 samples in a packet over USB.
- * With sc12 samples a packet consists of 6000kb but managed_buffers allocate 16kb each.
- * Thus we don't run into problems here either.
+ * We never have to worry about SIGSEGVs here as long as we end in the middle of a
+ * managed_buffer. If we are at the end of managed_buffer there are 2 precautions
+ * to prevent SIGSEGVs. Firstly only a read operation is performed. Secondly
+ * managed_buffers allocate a fixed size memory which is always larger than the
+ * actually used size. e.g. The current sample maximum is 2000 samples in a packet
+ * over USB. With sc12 samples a packet consists of 6000kb but managed_buffers
+ * allocate 16kb each. Thus we don't run into problems here either.
*/
const size_t tail_samps = nsamps - o;
- switch (tail_samps)
- {
- case 0: break; //no tail
- case 1: convert_sc12_item32_3_to_star_4<type, tohost>(input[i], output[o+0], dummy0, dummy1, dummy2, _scalar); break;
- case 2: convert_sc12_item32_3_to_star_4<type, tohost>(input[i], output[o+0], output[o+1], dummy1, dummy2, _scalar); break;
- case 3: convert_sc12_item32_3_to_star_4<type, tohost>(input[i], output[o+0], output[o+1], output[o+2], dummy2, _scalar); break;
+ switch (tail_samps) {
+ case 0:
+ break; // no tail
+ case 1:
+ convert_sc12_item32_3_to_star_4<type, tohost>(
+ input[i], output[o + 0], dummy0, dummy1, dummy2, _scalar);
+ break;
+ case 2:
+ convert_sc12_item32_3_to_star_4<type, tohost>(
+ input[i], output[o + 0], output[o + 1], dummy1, dummy2, _scalar);
+ break;
+ case 3:
+ convert_sc12_item32_3_to_star_4<type, tohost>(input[i],
+ output[o + 0],
+ output[o + 1],
+ output[o + 2],
+ dummy2,
+ _scalar);
+ break;
}
}
@@ -128,20 +165,24 @@ static converter::sptr make_convert_sc12_item32_be_1_to_sc16_1(void)
UHD_STATIC_BLOCK(register_convert_unpack_sc12)
{
- uhd::convert::register_bytes_per_item("sc12", 3/*bytes*/);
+ uhd::convert::register_bytes_per_item("sc12", 3 /*bytes*/);
uhd::convert::id_type id;
- id.num_inputs = 1;
+ id.num_inputs = 1;
id.num_outputs = 1;
id.output_format = "fc32";
- id.input_format = "sc12_item32_le";
- uhd::convert::register_converter(id, &make_convert_sc12_item32_le_1_to_fc32_1, PRIORITY_GENERAL);
+ id.input_format = "sc12_item32_le";
+ uhd::convert::register_converter(
+ id, &make_convert_sc12_item32_le_1_to_fc32_1, PRIORITY_GENERAL);
id.input_format = "sc12_item32_be";
- uhd::convert::register_converter(id, &make_convert_sc12_item32_be_1_to_fc32_1, PRIORITY_GENERAL);
+ uhd::convert::register_converter(
+ id, &make_convert_sc12_item32_be_1_to_fc32_1, PRIORITY_GENERAL);
id.output_format = "sc16";
- id.input_format = "sc12_item32_le";
- uhd::convert::register_converter(id, &make_convert_sc12_item32_le_1_to_sc16_1, PRIORITY_GENERAL);
+ id.input_format = "sc12_item32_le";
+ uhd::convert::register_converter(
+ id, &make_convert_sc12_item32_le_1_to_sc16_1, PRIORITY_GENERAL);
id.input_format = "sc12_item32_be";
- uhd::convert::register_converter(id, &make_convert_sc12_item32_be_1_to_sc16_1, PRIORITY_GENERAL);
+ uhd::convert::register_converter(
+ id, &make_convert_sc12_item32_be_1_to_sc16_1, PRIORITY_GENERAL);
}
diff --git a/host/lib/convert/convert_unpack_sc12.hpp b/host/lib/convert/convert_unpack_sc12.hpp
index e612b035d..26e5f5d79 100644
--- a/host/lib/convert/convert_unpack_sc12.hpp
+++ b/host/lib/convert/convert_unpack_sc12.hpp
@@ -5,9 +5,9 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
-#include <type_traits>
-#include <uhd/utils/byteswap.hpp>
#include "convert_common.hpp"
+#include <uhd/utils/byteswap.hpp>
+#include <type_traits>
using namespace uhd::convert;
@@ -37,38 +37,35 @@ struct item32_sc12_3x
* The numbers mark the position of one complex sample.
*/
template <typename type, tohost32_type tohost>
-void convert_sc12_item32_3_to_star_4
-(
- const item32_sc12_3x &input,
- std::complex<type> &out0,
- std::complex<type> &out1,
- std::complex<type> &out2,
- std::complex<type> &out3,
+void convert_sc12_item32_3_to_star_4(const item32_sc12_3x& input,
+ std::complex<type>& out0,
+ std::complex<type>& out1,
+ std::complex<type>& out2,
+ std::complex<type>& out3,
const double scalar,
- typename std::enable_if<std::is_floating_point<type>::value>::type* = NULL
-)
+ typename std::enable_if<std::is_floating_point<type>::value>::type* = NULL)
{
- //step 0: extract the lines from the input buffer
- const item32_t line0 = tohost(input.line0);
- const item32_t line1 = tohost(input.line1);
- const item32_t line2 = tohost(input.line2);
+ // step 0: extract the lines from the input buffer
+ const item32_t line0 = tohost(input.line0);
+ const item32_t line1 = tohost(input.line1);
+ const item32_t line2 = tohost(input.line2);
const uint64_t line01 = (uint64_t(line0) << 32) | line1;
const uint64_t line12 = (uint64_t(line1) << 32) | line2;
- //step 1: shift out and mask off the individual numbers
- const type i0 = type(int16_t((line0 >> 16) & 0xfff0)*scalar);
- const type q0 = type(int16_t((line0 >> 4) & 0xfff0)*scalar);
+ // step 1: shift out and mask off the individual numbers
+ const type i0 = type(int16_t((line0 >> 16) & 0xfff0) * scalar);
+ const type q0 = type(int16_t((line0 >> 4) & 0xfff0) * scalar);
- const type i1 = type(int16_t((line01 >> 24) & 0xfff0)*scalar);
- const type q1 = type(int16_t((line1 >> 12) & 0xfff0)*scalar);
+ const type i1 = type(int16_t((line01 >> 24) & 0xfff0) * scalar);
+ const type q1 = type(int16_t((line1 >> 12) & 0xfff0) * scalar);
- const type i2 = type(int16_t((line1 >> 0) & 0xfff0)*scalar);
- const type q2 = type(int16_t((line12 >> 20) & 0xfff0)*scalar);
+ const type i2 = type(int16_t((line1 >> 0) & 0xfff0) * scalar);
+ const type q2 = type(int16_t((line12 >> 20) & 0xfff0) * scalar);
- const type i3 = type(int16_t((line2 >> 8) & 0xfff0)*scalar);
- const type q3 = type(int16_t((line2 << 4) & 0xfff0)*scalar);
+ const type i3 = type(int16_t((line2 >> 8) & 0xfff0) * scalar);
+ const type q3 = type(int16_t((line2 << 4) & 0xfff0) * scalar);
- //step 2: load the outputs
+ // step 2: load the outputs
out0 = std::complex<type>(i0, q0);
out1 = std::complex<type>(i1, q1);
out2 = std::complex<type>(i2, q2);
@@ -76,27 +73,24 @@ void convert_sc12_item32_3_to_star_4
}
template <typename type, tohost32_type tohost>
-void convert_sc12_item32_3_to_star_4
-(
- const item32_sc12_3x &input,
- std::complex<type> &out0,
- std::complex<type> &out1,
- std::complex<type> &out2,
- std::complex<type> &out3,
+void convert_sc12_item32_3_to_star_4(const item32_sc12_3x& input,
+ std::complex<type>& out0,
+ std::complex<type>& out1,
+ std::complex<type>& out2,
+ std::complex<type>& out3,
const double,
- typename std::enable_if<std::is_integral<type>::value>::type* = NULL
-)
+ typename std::enable_if<std::is_integral<type>::value>::type* = NULL)
{
- //step 0: extract the lines from the input buffer
- const item32_t line0 = tohost(input.line0);
- const item32_t line1 = tohost(input.line1);
- const item32_t line2 = tohost(input.line2);
+ // step 0: extract the lines from the input buffer
+ const item32_t line0 = tohost(input.line0);
+ const item32_t line1 = tohost(input.line1);
+ const item32_t line2 = tohost(input.line2);
const uint64_t line01 = (uint64_t(line0) << 32) | line1;
const uint64_t line12 = (uint64_t(line1) << 32) | line2;
- //step 1: extract and load the outputs
- out0 = std::complex<type>(line0 >> 16 & 0xfff0, line0 >> 4 & 0xfff0);
- out1 = std::complex<type>(line01 >> 24 & 0xfff0, line1 >> 12 & 0xfff0);
- out2 = std::complex<type>(line1 >> 0 & 0xfff0, line12 >> 20 & 0xfff0);
- out3 = std::complex<type>(line2 >> 8 & 0xfff0, line2 << 4 & 0xfff0);
+ // step 1: extract and load the outputs
+ out0 = std::complex<type>(line0 >> 16 & 0xfff0, line0 >> 4 & 0xfff0);
+ out1 = std::complex<type>(line01 >> 24 & 0xfff0, line1 >> 12 & 0xfff0);
+ out2 = std::complex<type>(line1 >> 0 & 0xfff0, line12 >> 20 & 0xfff0);
+ out3 = std::complex<type>(line2 >> 8 & 0xfff0, line2 << 4 & 0xfff0);
}
diff --git a/host/lib/convert/convert_with_neon.cpp b/host/lib/convert/convert_with_neon.cpp
index 8a3bd29d5..9aec68bab 100644
--- a/host/lib/convert/convert_with_neon.cpp
+++ b/host/lib/convert/convert_with_neon.cpp
@@ -10,119 +10,123 @@
#include <arm_neon.h>
extern "C" {
-void neon_item32_sc16_swap_16n(void *, void *, int iter);
+void neon_item32_sc16_swap_16n(void*, void*, int iter);
}
static const int SIMD_WIDTH = 16;
using namespace uhd::convert;
-DECLARE_CONVERTER(fc32, 1, sc16_item32_le, 1, PRIORITY_SIMD){
- const fc32_t *input = reinterpret_cast<const fc32_t *>(inputs[0]);
- item32_t *output = reinterpret_cast<item32_t *>(outputs[0]);
+DECLARE_CONVERTER(fc32, 1, sc16_item32_le, 1, PRIORITY_SIMD)
+{
+ const fc32_t* input = reinterpret_cast<const fc32_t*>(inputs[0]);
+ item32_t* output = reinterpret_cast<item32_t*>(outputs[0]);
size_t i;
float32x4_t Q0 = vdupq_n_f32(float(scale_factor));
- for (i=0; i < (nsamps & ~0x0f); i+=8) {
- float32x4_t Q1 = vld1q_f32(reinterpret_cast<const float *>(&input[i]));
- float32x4_t Q4 = vld1q_f32(reinterpret_cast<const float *>(&input[i+2]));
- float32x4_t Q7 = vld1q_f32(reinterpret_cast<const float *>(&input[i+4]));
- float32x4_t Q10 = vld1q_f32(reinterpret_cast<const float *>(&input[i+6]));
+ for (i = 0; i < (nsamps & ~0x0f); i += 8) {
+ float32x4_t Q1 = vld1q_f32(reinterpret_cast<const float*>(&input[i]));
+ float32x4_t Q4 = vld1q_f32(reinterpret_cast<const float*>(&input[i + 2]));
+ float32x4_t Q7 = vld1q_f32(reinterpret_cast<const float*>(&input[i + 4]));
+ float32x4_t Q10 = vld1q_f32(reinterpret_cast<const float*>(&input[i + 6]));
float32x4_t Q2 = vmulq_f32(Q1, Q0);
- int32x4_t Q3 = vcvtq_s32_f32(Q2);
- int16x4_t D8 = vmovn_s32(Q3);
- int16x4_t D9 = vrev32_s16(D8);
- vst1_s16((reinterpret_cast<int16_t *>(&output[i])), D9);
+ int32x4_t Q3 = vcvtq_s32_f32(Q2);
+ int16x4_t D8 = vmovn_s32(Q3);
+ int16x4_t D9 = vrev32_s16(D8);
+ vst1_s16((reinterpret_cast<int16_t*>(&output[i])), D9);
float32x4_t Q5 = vmulq_f32(Q4, Q0);
- int32x4_t Q6 = vcvtq_s32_f32(Q5);
- int16x4_t D10 = vmovn_s32(Q6);
- int16x4_t D11 = vrev32_s16(D10);
- vst1_s16((reinterpret_cast<int16_t *>(&output[i+2])), D11);
+ int32x4_t Q6 = vcvtq_s32_f32(Q5);
+ int16x4_t D10 = vmovn_s32(Q6);
+ int16x4_t D11 = vrev32_s16(D10);
+ vst1_s16((reinterpret_cast<int16_t*>(&output[i + 2])), D11);
float32x4_t Q8 = vmulq_f32(Q7, Q0);
- int32x4_t Q9 = vcvtq_s32_f32(Q8);
- int16x4_t D12 = vmovn_s32(Q9);
- int16x4_t D13 = vrev32_s16(D12);
- vst1_s16((reinterpret_cast<int16_t *>(&output[i+4])), D13);
+ int32x4_t Q9 = vcvtq_s32_f32(Q8);
+ int16x4_t D12 = vmovn_s32(Q9);
+ int16x4_t D13 = vrev32_s16(D12);
+ vst1_s16((reinterpret_cast<int16_t*>(&output[i + 4])), D13);
float32x4_t Q11 = vmulq_f32(Q10, Q0);
- int32x4_t Q13 = vcvtq_s32_f32(Q11);
- int16x4_t D14 = vmovn_s32(Q13);
- int16x4_t D15 = vrev32_s16(D14);
- vst1_s16((reinterpret_cast<int16_t *>(&output[i+6])), D15);
+ int32x4_t Q13 = vcvtq_s32_f32(Q11);
+ int16x4_t D14 = vmovn_s32(Q13);
+ int16x4_t D15 = vrev32_s16(D14);
+ vst1_s16((reinterpret_cast<int16_t*>(&output[i + 6])), D15);
}
- xx_to_item32_sc16<uhd::htowx>(input+i, output+i, nsamps-i, scale_factor);
+ xx_to_item32_sc16<uhd::htowx>(input + i, output + i, nsamps - i, scale_factor);
}
-DECLARE_CONVERTER(sc16_item32_le, 1, fc32, 1, PRIORITY_SIMD){
- const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]);
- fc32_t *output = reinterpret_cast<fc32_t *>(outputs[0]);
+DECLARE_CONVERTER(sc16_item32_le, 1, fc32, 1, PRIORITY_SIMD)
+{
+ const item32_t* input = reinterpret_cast<const item32_t*>(inputs[0]);
+ fc32_t* output = reinterpret_cast<fc32_t*>(outputs[0]);
size_t i;
float32x4_t Q1 = vdupq_n_f32(float(scale_factor));
- for (i=0; i < (nsamps & ~0xf); i+=8) {
- int16x4_t D0 = vld1_s16(reinterpret_cast<const int16_t *>(&input[i]));
- int16x4_t D2 = vld1_s16(reinterpret_cast<const int16_t *>(&input[i+2]));
- int16x4_t D4 = vld1_s16(reinterpret_cast<const int16_t *>(&input[i+4]));
- int16x4_t D6 = vld1_s16(reinterpret_cast<const int16_t *>(&input[i+6]));
-
- int16x4_t D1 = vrev32_s16(D0);
- int32x4_t Q2 = vmovl_s16(D1);
+ for (i = 0; i < (nsamps & ~0xf); i += 8) {
+ int16x4_t D0 = vld1_s16(reinterpret_cast<const int16_t*>(&input[i]));
+ int16x4_t D2 = vld1_s16(reinterpret_cast<const int16_t*>(&input[i + 2]));
+ int16x4_t D4 = vld1_s16(reinterpret_cast<const int16_t*>(&input[i + 4]));
+ int16x4_t D6 = vld1_s16(reinterpret_cast<const int16_t*>(&input[i + 6]));
+
+ int16x4_t D1 = vrev32_s16(D0);
+ int32x4_t Q2 = vmovl_s16(D1);
float32x4_t Q3 = vcvtq_f32_s32(Q2);
float32x4_t Q4 = vmulq_f32(Q3, Q1);
- vst1q_f32((reinterpret_cast<float *>(&output[i])), Q4);
+ vst1q_f32((reinterpret_cast<float*>(&output[i])), Q4);
- int16x4_t D3 = vrev32_s16(D2);
- int32x4_t Q5 = vmovl_s16(D3);
+ int16x4_t D3 = vrev32_s16(D2);
+ int32x4_t Q5 = vmovl_s16(D3);
float32x4_t Q6 = vcvtq_f32_s32(Q5);
float32x4_t Q7 = vmulq_f32(Q6, Q1);
- vst1q_f32((reinterpret_cast<float *>(&output[i+2])), Q7);
+ vst1q_f32((reinterpret_cast<float*>(&output[i + 2])), Q7);
- int16x4_t D5 = vrev32_s16(D4);
- int32x4_t Q8 = vmovl_s16(D5);
- float32x4_t Q9 = vcvtq_f32_s32(Q8);
+ int16x4_t D5 = vrev32_s16(D4);
+ int32x4_t Q8 = vmovl_s16(D5);
+ float32x4_t Q9 = vcvtq_f32_s32(Q8);
float32x4_t Q10 = vmulq_f32(Q9, Q1);
- vst1q_f32((reinterpret_cast<float *>(&output[i+4])), Q10);
+ vst1q_f32((reinterpret_cast<float*>(&output[i + 4])), Q10);
- int16x4_t D7 = vrev32_s16(D6);
- int32x4_t Q11 = vmovl_s16(D7);
+ int16x4_t D7 = vrev32_s16(D6);
+ int32x4_t Q11 = vmovl_s16(D7);
float32x4_t Q12 = vcvtq_f32_s32(Q11);
float32x4_t Q13 = vmulq_f32(Q12, Q1);
- vst1q_f32((reinterpret_cast<float *>(&output[i+6])), Q13);
+ vst1q_f32((reinterpret_cast<float*>(&output[i + 6])), Q13);
}
- item32_sc16_to_xx<uhd::htowx>(input+i, output+i, nsamps-i, scale_factor);
+ item32_sc16_to_xx<uhd::htowx>(input + i, output + i, nsamps - i, scale_factor);
}
-DECLARE_CONVERTER(sc16, 1, sc16_item32_le, 1, PRIORITY_SIMD){
- const sc16_t *input = reinterpret_cast<const sc16_t *>(inputs[0]);
- item32_t *output = reinterpret_cast<item32_t *>(outputs[0]);
+DECLARE_CONVERTER(sc16, 1, sc16_item32_le, 1, PRIORITY_SIMD)
+{
+ const sc16_t* input = reinterpret_cast<const sc16_t*>(inputs[0]);
+ item32_t* output = reinterpret_cast<item32_t*>(outputs[0]);
size_t i = nsamps / SIMD_WIDTH;
if (i)
- neon_item32_sc16_swap_16n((void *) input, (void *) output, i);
+ neon_item32_sc16_swap_16n((void*)input, (void*)output, i);
i *= SIMD_WIDTH;
- xx_to_item32_sc16<uhd::htowx>(input+i, output+i, nsamps-i, scale_factor);
+ xx_to_item32_sc16<uhd::htowx>(input + i, output + i, nsamps - i, scale_factor);
}
-DECLARE_CONVERTER(sc16_item32_le, 1, sc16, 1, PRIORITY_SIMD){
- const item32_t *input = reinterpret_cast<const item32_t *>(inputs[0]);
- sc16_t *output = reinterpret_cast<sc16_t *>(outputs[0]);
+DECLARE_CONVERTER(sc16_item32_le, 1, sc16, 1, PRIORITY_SIMD)
+{
+ const item32_t* input = reinterpret_cast<const item32_t*>(inputs[0]);
+ sc16_t* output = reinterpret_cast<sc16_t*>(outputs[0]);
size_t i = nsamps / SIMD_WIDTH;
if (i)
- neon_item32_sc16_swap_16n((void *) input, (void *) output, i);
+ neon_item32_sc16_swap_16n((void*)input, (void*)output, i);
i *= SIMD_WIDTH;
- item32_sc16_to_xx<uhd::wtohx>(input+i, output+i, nsamps-i, scale_factor);
+ item32_sc16_to_xx<uhd::wtohx>(input + i, output + i, nsamps - i, scale_factor);
}
diff --git a/host/lib/convert/convert_with_tables.cpp b/host/lib/convert/convert_with_tables.cpp
index 5c9248052..86637171a 100644
--- a/host/lib/convert/convert_with_tables.cpp
+++ b/host/lib/convert/convert_with_tables.cpp
@@ -20,7 +20,8 @@ typedef uint16_t (*tohost16_type)(uint16_t);
* Implementation for sc16 to sc8 lookup table
* - Lookup the real and imaginary parts individually
**********************************************************************/
-template <bool swap> class convert_sc16_1_to_sc8_item32_1 : public converter
+template <bool swap>
+class convert_sc16_1_to_sc8_item32_1 : public converter
{
public:
convert_sc16_1_to_sc8_item32_1(void) : _table(sc16_table_len) {}
diff --git a/host/lib/convert/ssse3_pack_sc12.cpp b/host/lib/convert/ssse3_pack_sc12.cpp
index e71c2288b..4ba14db3b 100644
--- a/host/lib/convert/ssse3_pack_sc12.cpp
+++ b/host/lib/convert/ssse3_pack_sc12.cpp
@@ -5,8 +5,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
-#include <tmmintrin.h>
#include "convert_pack_sc12.hpp"
+#include <tmmintrin.h>
/*
* Shuffle Orderings - Single 128-bit SSE register
@@ -44,24 +44,21 @@
* -----------------------
* 31 0
*/
-#define SC12_SHIFT_MASK 0xfff0fff0, 0xfff0fff0, 0x0fff0fff, 0x0fff0fff
-#define SC12_PACK_SHUFFLE1 13,12,9,8,5,4,1,0,15,14,11,10,7,6,3,2
-#define SC12_PACK_SHUFFLE2 9,8,0,11,10,2,13,12,4,15,14,6,0,0,0,0
-#define SC12_PACK_SHUFFLE3 8,1,8,8,3,8,8,5,8,8,7,8,8,8,8,8
+#define SC12_SHIFT_MASK 0xfff0fff0, 0xfff0fff0, 0x0fff0fff, 0x0fff0fff
+#define SC12_PACK_SHUFFLE1 13, 12, 9, 8, 5, 4, 1, 0, 15, 14, 11, 10, 7, 6, 3, 2
+#define SC12_PACK_SHUFFLE2 9, 8, 0, 11, 10, 2, 13, 12, 4, 15, 14, 6, 0, 0, 0, 0
+#define SC12_PACK_SHUFFLE3 8, 1, 8, 8, 3, 8, 8, 5, 8, 8, 7, 8, 8, 8, 8, 8
template <typename type>
-inline void convert_star_4_to_sc12_item32_3
-(
- const std::complex<type> *in,
- item32_sc12_3x &output,
+inline void convert_star_4_to_sc12_item32_3(const std::complex<type>* in,
+ item32_sc12_3x& output,
const double scalar,
- typename std::enable_if<std::is_same<type, float>::value>::type* = NULL
-)
+ typename std::enable_if<std::is_same<type, float>::value>::type* = NULL)
{
__m128 m0, m1, m2;
m0 = _mm_set1_ps(scalar);
- m1 = _mm_loadu_ps((const float *) &in[0]);
- m2 = _mm_loadu_ps((const float *) &in[2]);
+ m1 = _mm_loadu_ps((const float*)&in[0]);
+ m2 = _mm_loadu_ps((const float*)&in[2]);
m1 = _mm_mul_ps(m1, m0);
m2 = _mm_mul_ps(m2, m0);
m0 = _mm_shuffle_ps(m1, m2, _MM_SHUFFLE(2, 0, 2, 0));
@@ -84,17 +81,14 @@ inline void convert_star_4_to_sc12_item32_3
m6 = _mm_or_si128(m6, m7);
m6 = _mm_shuffle_epi32(m6, _MM_SHUFFLE(0, 1, 2, 3));
- _mm_storeu_si128((__m128i*) &output, m6);
+ _mm_storeu_si128((__m128i*)&output, m6);
}
template <typename type>
-static void convert_star_4_to_sc12_item32_3
-(
- const std::complex<type> *in,
- item32_sc12_3x &output,
+static void convert_star_4_to_sc12_item32_3(const std::complex<type>* in,
+ item32_sc12_3x& output,
const double,
- typename std::enable_if<std::is_same<type, short>::value>::type* = NULL
-)
+ typename std::enable_if<std::is_same<type, short>::value>::type* = NULL)
{
__m128i m0, m1, m2, m3, m4, m5;
m0 = _mm_set_epi32(SC12_SHIFT_MASK);
@@ -102,7 +96,7 @@ static void convert_star_4_to_sc12_item32_3
m2 = _mm_set_epi8(SC12_PACK_SHUFFLE2);
m3 = _mm_set_epi8(SC12_PACK_SHUFFLE3);
- m4 = _mm_loadu_si128((__m128i*) in);
+ m4 = _mm_loadu_si128((__m128i*)in);
m4 = _mm_shuffle_epi8(m4, m1);
m5 = _mm_srli_epi16(m4, 4);
m4 = _mm_shuffle_epi32(m4, _MM_SHUFFLE(0, 0, 3, 2));
@@ -115,57 +109,66 @@ static void convert_star_4_to_sc12_item32_3
m3 = _mm_or_si128(m4, m5);
m3 = _mm_shuffle_epi32(m3, _MM_SHUFFLE(0, 1, 2, 3));
- _mm_storeu_si128((__m128i*) &output, m3);
+ _mm_storeu_si128((__m128i*)&output, m3);
}
template <typename type, towire32_type towire>
struct convert_star_1_to_sc12_item32_2 : public converter
{
- convert_star_1_to_sc12_item32_2(void):_scalar(0.0)
- {
- }
+ convert_star_1_to_sc12_item32_2(void) : _scalar(0.0) {}
void set_scalar(const double scalar)
{
_scalar = scalar;
}
- void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps)
+ void operator()(
+ const input_type& inputs, const output_type& outputs, const size_t nsamps)
{
- const std::complex<type> *input = reinterpret_cast<const std::complex<type> *>(inputs[0]);
+ const std::complex<type>* input =
+ reinterpret_cast<const std::complex<type>*>(inputs[0]);
const size_t head_samps = size_t(outputs[0]) & 0x3;
int enable;
size_t rewind = 0;
- switch(head_samps)
- {
- case 0: break;
- case 1: rewind = 9; break;
- case 2: rewind = 6; break;
- case 3: rewind = 3; break;
+ switch (head_samps) {
+ case 0:
+ break;
+ case 1:
+ rewind = 9;
+ break;
+ case 2:
+ rewind = 6;
+ break;
+ case 3:
+ rewind = 3;
+ break;
}
- item32_sc12_3x *output = reinterpret_cast<item32_sc12_3x *>(size_t(outputs[0]) - rewind);
+ item32_sc12_3x* output =
+ reinterpret_cast<item32_sc12_3x*>(size_t(outputs[0]) - rewind);
- //helper variables
+ // helper variables
size_t i = 0, o = 0;
- //handle the head case
- switch (head_samps)
- {
- case 0:
- break; //no head
- case 1:
- enable = CONVERT12_LINE2;
- convert_star_4_to_sc12_item32_3<type, towire>(0, 0, 0, input[0], enable, output[o++], _scalar);
- break;
- case 2:
- enable = CONVERT12_LINE2 | CONVERT12_LINE1;
- convert_star_4_to_sc12_item32_3<type, towire>(0, 0, input[0], input[1], enable, output[o++], _scalar);
- break;
- case 3:
- enable = CONVERT12_LINE2 | CONVERT12_LINE1 | CONVERT12_LINE0;
- convert_star_4_to_sc12_item32_3<type, towire>(0, input[0], input[1], input[2], enable, output[o++], _scalar);
- break;
+ // handle the head case
+ switch (head_samps) {
+ case 0:
+ break; // no head
+ case 1:
+ enable = CONVERT12_LINE2;
+ convert_star_4_to_sc12_item32_3<type, towire>(
+ 0, 0, 0, input[0], enable, output[o++], _scalar);
+ break;
+ case 2:
+ enable = CONVERT12_LINE2 | CONVERT12_LINE1;
+ convert_star_4_to_sc12_item32_3<type, towire>(
+ 0, 0, input[0], input[1], enable, output[o++], _scalar);
+ break;
+ case 3:
+ enable = CONVERT12_LINE2 | CONVERT12_LINE1 | CONVERT12_LINE0;
+ convert_star_4_to_sc12_item32_3<type, towire>(
+ 0, input[0], input[1], input[2], enable, output[o++], _scalar);
+ break;
}
i += head_samps;
@@ -174,34 +177,47 @@ struct convert_star_1_to_sc12_item32_2 : public converter
// subsequent samples to be converted (writes will simply happen
// twice). So set the conversion loop to force a tail case on the
// final 4 or fewer samples.
- while (i+4 < nsamps)
- {
+ while (i + 4 < nsamps) {
convert_star_4_to_sc12_item32_3<type>(&input[i], output[o], _scalar);
- o++; i += 4;
+ o++;
+ i += 4;
}
- //handle the tail case
+ // handle the tail case
const size_t tail_samps = nsamps - i;
- switch (tail_samps)
- {
- case 0:
- break; //no tail
- case 1:
- enable = CONVERT12_LINE0;
- convert_star_4_to_sc12_item32_3<type, towire>(input[i+0], 0, 0, 0, enable, output[o], _scalar);
- break;
- case 2:
- enable = CONVERT12_LINE0 | CONVERT12_LINE1;
- convert_star_4_to_sc12_item32_3<type, towire>(input[i+0], input[i+1], 0, 0, enable, output[o], _scalar);
- break;
- case 3:
- enable = CONVERT12_LINE0 | CONVERT12_LINE1 | CONVERT12_LINE2;
- convert_star_4_to_sc12_item32_3<type, towire>(input[i+0], input[i+1], input[i+2], 0, enable, output[o], _scalar);
- break;
- case 4:
- enable = CONVERT12_LINE_ALL;
- convert_star_4_to_sc12_item32_3<type, towire>(input[i+0], input[i+1], input[i+2], input[i+3], enable, output[o], _scalar);
- break;
+ switch (tail_samps) {
+ case 0:
+ break; // no tail
+ case 1:
+ enable = CONVERT12_LINE0;
+ convert_star_4_to_sc12_item32_3<type, towire>(
+ input[i + 0], 0, 0, 0, enable, output[o], _scalar);
+ break;
+ case 2:
+ enable = CONVERT12_LINE0 | CONVERT12_LINE1;
+ convert_star_4_to_sc12_item32_3<type, towire>(
+ input[i + 0], input[i + 1], 0, 0, enable, output[o], _scalar);
+ break;
+ case 3:
+ enable = CONVERT12_LINE0 | CONVERT12_LINE1 | CONVERT12_LINE2;
+ convert_star_4_to_sc12_item32_3<type, towire>(input[i + 0],
+ input[i + 1],
+ input[i + 2],
+ 0,
+ enable,
+ output[o],
+ _scalar);
+ break;
+ case 4:
+ enable = CONVERT12_LINE_ALL;
+ convert_star_4_to_sc12_item32_3<type, towire>(input[i + 0],
+ input[i + 1],
+ input[i + 2],
+ input[i + 3],
+ enable,
+ output[o],
+ _scalar);
+ break;
}
}
@@ -221,14 +237,16 @@ static converter::sptr make_convert_sc16_1_to_sc12_item32_le_1(void)
UHD_STATIC_BLOCK(register_sse_pack_sc12)
{
uhd::convert::id_type id;
- id.num_inputs = 1;
+ id.num_inputs = 1;
id.num_outputs = 1;
- id.input_format = "fc32";
+ id.input_format = "fc32";
id.output_format = "sc12_item32_le";
- uhd::convert::register_converter(id, &make_convert_fc32_1_to_sc12_item32_le_1, PRIORITY_SIMD);
+ uhd::convert::register_converter(
+ id, &make_convert_fc32_1_to_sc12_item32_le_1, PRIORITY_SIMD);
- id.input_format = "sc16";
+ id.input_format = "sc16";
id.output_format = "sc12_item32_le";
- uhd::convert::register_converter(id, &make_convert_sc16_1_to_sc12_item32_le_1, PRIORITY_SIMD);
+ uhd::convert::register_converter(
+ id, &make_convert_sc16_1_to_sc12_item32_le_1, PRIORITY_SIMD);
}
diff --git a/host/lib/convert/ssse3_unpack_sc12.cpp b/host/lib/convert/ssse3_unpack_sc12.cpp
index a6e147142..5494e0fd7 100644
--- a/host/lib/convert/ssse3_unpack_sc12.cpp
+++ b/host/lib/convert/ssse3_unpack_sc12.cpp
@@ -59,23 +59,20 @@ using namespace uhd::convert;
* | 127 0 |
*
*/
-#define SC12_SHIFT_MASK 0x0fff0fff, 0x0fff0fff, 0xfff0fff0, 0xfff0fff0
-#define SC12_PACK_SHUFFLE1 5,4,8,7,11,10,14,13,6,5,9,8,12,11,15,14
-#define SC12_PACK_SHUFFLE2 15,14,7,6,13,12,5,4,11,10,3,2,9,8,1,0
+#define SC12_SHIFT_MASK 0x0fff0fff, 0x0fff0fff, 0xfff0fff0, 0xfff0fff0
+#define SC12_PACK_SHUFFLE1 5, 4, 8, 7, 11, 10, 14, 13, 6, 5, 9, 8, 12, 11, 15, 14
+#define SC12_PACK_SHUFFLE2 15, 14, 7, 6, 13, 12, 5, 4, 11, 10, 3, 2, 9, 8, 1, 0
template <typename type, tohost32_type tohost>
-inline void convert_sc12_item32_3_to_star_4
-(
- const item32_sc12_3x &input,
- std::complex<type> *out,
+inline void convert_sc12_item32_3_to_star_4(const item32_sc12_3x& input,
+ std::complex<type>* out,
double scalar,
- typename std::enable_if<std::is_same<type, float>::value>::type* = NULL
-)
+ typename std::enable_if<std::is_same<type, float>::value>::type* = NULL)
{
__m128i m0, m1, m2, m3, m4;
m0 = _mm_set_epi32(SC12_SHIFT_MASK);
m1 = _mm_set_epi8(SC12_PACK_SHUFFLE1);
- m2 = _mm_loadu_si128((__m128i*) &input);
+ m2 = _mm_loadu_si128((__m128i*)&input);
m2 = _mm_shuffle_epi32(m2, _MM_SHUFFLE(0, 1, 2, 3));
m3 = _mm_shuffle_epi8(m2, m1);
m3 = _mm_and_si128(m3, m0);
@@ -88,7 +85,7 @@ inline void convert_sc12_item32_3_to_star_4
m4 = _mm_unpackhi_epi32(m1, m2);
__m128 m5, m6, m7;
- m5 = _mm_set_ps1(scalar/(1 << 16));
+ m5 = _mm_set_ps1(scalar / (1 << 16));
m6 = _mm_cvtepi32_ps(m3);
m7 = _mm_cvtepi32_ps(m4);
m6 = _mm_mul_ps(m6, m5);
@@ -99,20 +96,17 @@ inline void convert_sc12_item32_3_to_star_4
}
template <typename type, tohost32_type tohost>
-inline void convert_sc12_item32_3_to_star_4
-(
- const item32_sc12_3x &input,
- std::complex<type> *out,
+inline void convert_sc12_item32_3_to_star_4(const item32_sc12_3x& input,
+ std::complex<type>* out,
double,
- typename std::enable_if<std::is_same<type, short>::value>::type* = NULL
-)
+ typename std::enable_if<std::is_same<type, short>::value>::type* = NULL)
{
__m128i m0, m1, m2, m3;
m0 = _mm_set_epi32(SC12_SHIFT_MASK);
m1 = _mm_set_epi8(SC12_PACK_SHUFFLE1);
m2 = _mm_set_epi8(SC12_PACK_SHUFFLE2);
- m3 = _mm_loadu_si128((__m128i*) &input);
+ m3 = _mm_loadu_si128((__m128i*)&input);
m3 = _mm_shuffle_epi32(m3, _MM_SHUFFLE(0, 1, 2, 3));
m3 = _mm_shuffle_epi8(m3, m1);
m3 = _mm_and_si128(m3, m0);
@@ -122,62 +116,92 @@ inline void convert_sc12_item32_3_to_star_4
m0 = _mm_unpackhi_epi64(m1, m0);
m1 = _mm_shuffle_epi8(m0, m2);
- _mm_storeu_si128((__m128i*) out, m1);
+ _mm_storeu_si128((__m128i*)out, m1);
}
template <typename type, tohost32_type tohost>
struct convert_sc12_item32_1_to_star_2 : public converter
{
- convert_sc12_item32_1_to_star_2(void):_scalar(0.0)
+ convert_sc12_item32_1_to_star_2(void) : _scalar(0.0)
{
- //NOP
+ // NOP
}
void set_scalar(const double scalar)
{
const int unpack_growth = 16;
- _scalar = scalar/unpack_growth;
+ _scalar = scalar / unpack_growth;
}
- void operator()(const input_type &inputs, const output_type &outputs, const size_t nsamps)
+ void operator()(
+ const input_type& inputs, const output_type& outputs, const size_t nsamps)
{
const size_t head_samps = size_t(inputs[0]) & 0x3;
- size_t rewind = 0;
- switch(head_samps)
- {
- case 0: break;
- case 1: rewind = 9; break;
- case 2: rewind = 6; break;
- case 3: rewind = 3; break;
+ size_t rewind = 0;
+ switch (head_samps) {
+ case 0:
+ break;
+ case 1:
+ rewind = 9;
+ break;
+ case 2:
+ rewind = 6;
+ break;
+ case 3:
+ rewind = 3;
+ break;
}
- const item32_sc12_3x *input = reinterpret_cast<const item32_sc12_3x *>(size_t(inputs[0]) - rewind);
- std::complex<type> *output = reinterpret_cast<std::complex<type> *>(outputs[0]);
+ const item32_sc12_3x* input =
+ reinterpret_cast<const item32_sc12_3x*>(size_t(inputs[0]) - rewind);
+ std::complex<type>* output = reinterpret_cast<std::complex<type>*>(outputs[0]);
std::complex<type> dummy;
size_t i = 0, o = 0;
- switch (head_samps)
- {
- case 0: break; //no head
- case 1: convert_sc12_item32_3_to_star_4<type, tohost>(input[i++], dummy, dummy, dummy, output[0], _scalar); break;
- case 2: convert_sc12_item32_3_to_star_4<type, tohost>(input[i++], dummy, dummy, output[0], output[1], _scalar); break;
- case 3: convert_sc12_item32_3_to_star_4<type, tohost>(input[i++], dummy, output[0], output[1], output[2], _scalar); break;
+ switch (head_samps) {
+ case 0:
+ break; // no head
+ case 1:
+ convert_sc12_item32_3_to_star_4<type, tohost>(
+ input[i++], dummy, dummy, dummy, output[0], _scalar);
+ break;
+ case 2:
+ convert_sc12_item32_3_to_star_4<type, tohost>(
+ input[i++], dummy, dummy, output[0], output[1], _scalar);
+ break;
+ case 3:
+ convert_sc12_item32_3_to_star_4<type, tohost>(
+ input[i++], dummy, output[0], output[1], output[2], _scalar);
+ break;
}
o += head_samps;
- //convert the body
- while (o+3 < nsamps)
- {
- convert_sc12_item32_3_to_star_4<type, tohost>(input[i], &output[o], _scalar);
- i += 1; o += 4;
+ // convert the body
+ while (o + 3 < nsamps) {
+ convert_sc12_item32_3_to_star_4<type, tohost>(input[i], &output[o], _scalar);
+ i += 1;
+ o += 4;
}
const size_t tail_samps = nsamps - o;
- switch (tail_samps)
- {
- case 0: break; //no tail
- case 1: convert_sc12_item32_3_to_star_4<type, tohost>(input[i], output[o+0], dummy, dummy, dummy, _scalar); break;
- case 2: convert_sc12_item32_3_to_star_4<type, tohost>(input[i], output[o+0], output[o+1], dummy, dummy, _scalar); break;
- case 3: convert_sc12_item32_3_to_star_4<type, tohost>(input[i], output[o+0], output[o+1], output[o+2], dummy, _scalar); break;
+ switch (tail_samps) {
+ case 0:
+ break; // no tail
+ case 1:
+ convert_sc12_item32_3_to_star_4<type, tohost>(
+ input[i], output[o + 0], dummy, dummy, dummy, _scalar);
+ break;
+ case 2:
+ convert_sc12_item32_3_to_star_4<type, tohost>(
+ input[i], output[o + 0], output[o + 1], dummy, dummy, _scalar);
+ break;
+ case 3:
+ convert_sc12_item32_3_to_star_4<type, tohost>(input[i],
+ output[o + 0],
+ output[o + 1],
+ output[o + 2],
+ dummy,
+ _scalar);
+ break;
}
}
@@ -197,13 +221,15 @@ static converter::sptr make_convert_sc12_item32_le_1_to_sc16_1(void)
UHD_STATIC_BLOCK(register_sse_unpack_sc12)
{
uhd::convert::id_type id;
- id.num_inputs = 1;
- id.num_outputs = 1;
+ id.num_inputs = 1;
+ id.num_outputs = 1;
id.output_format = "fc32";
- id.input_format = "sc12_item32_le";
- uhd::convert::register_converter(id, &make_convert_sc12_item32_le_1_to_fc32_1, PRIORITY_SIMD);
+ id.input_format = "sc12_item32_le";
+ uhd::convert::register_converter(
+ id, &make_convert_sc12_item32_le_1_to_fc32_1, PRIORITY_SIMD);
id.output_format = "sc16";
- id.input_format = "sc12_item32_le";
- uhd::convert::register_converter(id, &make_convert_sc12_item32_le_1_to_sc16_1, PRIORITY_SIMD);
+ id.input_format = "sc12_item32_le";
+ uhd::convert::register_converter(
+ id, &make_convert_sc12_item32_le_1_to_sc16_1, PRIORITY_SIMD);
}