From f21874e68a413ad8088bef69e3e8c1ef9c352eca Mon Sep 17 00:00:00 2001 From: Tom Tsou Date: Thu, 6 Jul 2017 17:25:55 -0700 Subject: convert: Add sc12-sc16 converters Create missing sc12-sc16 and sc16-sc12 type converters. To avoid replicating the full sc12 converter class object, overload the converter calls with C++11 std::enable_if metafunctions. When used with std::is_floating and std::is_integral templates, this allow a single template interface with compile time function selection and static type checking. Note the below std::enable_if interface is confusing, but quite effective in this case. typename enable_if::value>::type* = NULL Fixes: #966 Related: #967, #1721 --- host/utils/converter_benchmark.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'host/utils') diff --git a/host/utils/converter_benchmark.cpp b/host/utils/converter_benchmark.cpp index 0f0c72370..ba521441f 100644 --- a/host/utils/converter_benchmark.cpp +++ b/host/utils/converter_benchmark.cpp @@ -98,6 +98,28 @@ void init_random_vector_complex_int(std::vector &buf_ptr, const size_t n_i } } +struct item32_sc12_3x +{ + uint32_t line0; + uint32_t line1; + uint32_t line2; +}; + +template +void init_random_vector_complex_sc12(std::vector &buf_ptr, const size_t n_items) +{ + item32_sc12_3x *const buf = reinterpret_cast(&buf_ptr[0]); + if (n_items % 4) throw std::invalid_argument(""); + + for (size_t i = 0; i < n_items / 4; i++) { + int16_t iq[8]; + for (auto &k : iq) k = rand() & 0xfff; + buf[i].line0 = iq[0] << 20 | iq[1] << 8 | iq[2] >> 4; + buf[i].line1 = iq[2] << 28 | iq[3] << 16 | iq[4] << 4 | iq[5] >> 8; + buf[i].line2 = iq[5] << 24 | iq[6] << 12 | iq[7] << 0; + } +} + template void init_random_vector_real_int(std::vector &buf_ptr, size_t n_items) { @@ -164,6 +186,8 @@ void init_buffers( for (size_t i = 0; i < buf.size(); i++) { if (type == "sc8") { init_random_vector_complex_int(buf[i], n_items); + } else if (type == "sc12") { + init_random_vector_complex_sc12(buf[i], n_items); } else if (type == "sc16") { init_random_vector_complex_int(buf[i], n_items); } else if (type == "sc32") { -- cgit v1.2.3