From 967be2a4e82b1a125b26bb72a60318a4fb2b50c4 Mon Sep 17 00:00:00 2001 From: Brent Stapleton Date: Mon, 14 Jan 2019 10:35:25 -0800 Subject: uhd: mpm: apply clang-format to all files Applying formatting changes to all .cpp and .hpp files in the following directories: ``` find host/examples/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/tests/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/dboard/neon/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/dboard/magnesium/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/device3/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/mpmd/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/lib/usrp/x300/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find host/utils/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file find mpm/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file ``` Also formatted host/include/, except Cpp03 was used as a the language standard instead of Cpp11. ``` sed -i 's/ Cpp11/ Cpp03/g' .clang-format find host/include/ -iname *.hpp -o -iname *.cpp | \ xargs clang-format -i -style=file ``` Formatting style was designated by the .clang-format file. --- host/utils/converter_benchmark.cpp | 278 +++++++++++++++++-------------------- 1 file changed, 130 insertions(+), 148 deletions(-) (limited to 'host/utils/converter_benchmark.cpp') diff --git a/host/utils/converter_benchmark.cpp b/host/utils/converter_benchmark.cpp index cb8cce519..07aec9170 100644 --- a/host/utils/converter_benchmark.cpp +++ b/host/utils/converter_benchmark.cpp @@ -5,32 +5,30 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include -#include #include #include -#include +#include +#include +#include +#include #include -#include #include -#include -#include +#include +#include +#include #include +#include #include -#include -#include namespace po = boost::program_options; using namespace uhd::convert; -enum buf_init_t { - RANDOM, INC -}; +enum buf_init_t { RANDOM, INC }; // Convert `sc16_item32_le' -> `sc16' // Finds the first _ in format and returns the string // until then. Returns the entire string if no _ is found. -std::string format_to_type(const std::string &format) +std::string format_to_type(const std::string& format) { std::string ret_val = ""; for (size_t i = 0; i < format.length(); i++) { @@ -44,10 +42,8 @@ std::string format_to_type(const std::string &format) } void configure_conv( - converter::sptr conv, - const std::string &in_type, - const std::string &out_type -) { + converter::sptr conv, const std::string& in_type, const std::string& out_type) +{ if (in_type == "sc16") { if (out_type == "fc32") { std::cout << "Setting scalar to 32767." << std::endl; @@ -68,21 +64,19 @@ void configure_conv( } template -void init_random_vector_complex_float(std::vector &buf_ptr, const size_t n_items) +void init_random_vector_complex_float(std::vector& buf_ptr, const size_t n_items) { - std::complex * const buf = reinterpret_cast * const>(&buf_ptr[0]); + std::complex* const buf = reinterpret_cast* const>(&buf_ptr[0]); for (size_t i = 0; i < n_items; i++) { buf[i] = std::complex( - T(std::rand()/(RAND_MAX/2.0) - 1), - T(std::rand()/(RAND_MAX/2.0) - 1) - ); + T(std::rand() / (RAND_MAX / 2.0) - 1), T(std::rand() / (RAND_MAX / 2.0) - 1)); } } template -void init_random_vector_complex_int(std::vector &buf_ptr, const size_t n_items) +void init_random_vector_complex_int(std::vector& buf_ptr, const size_t n_items) { - std::complex * const buf = reinterpret_cast * const>(&buf_ptr[0]); + std::complex* const buf = reinterpret_cast* const>(&buf_ptr[0]); for (size_t i = 0; i < n_items; i++) { buf[i] = std::complex(T(std::rand()), T(std::rand())); } @@ -96,45 +90,45 @@ struct item32_sc12_3x }; template -void init_random_vector_complex_sc12(std::vector &buf_ptr, const size_t n_items) +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(""); + 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; + 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) +void init_random_vector_real_int(std::vector& buf_ptr, size_t n_items) { - T * const buf = reinterpret_cast(&buf_ptr[0]); + T* const buf = reinterpret_cast(&buf_ptr[0]); for (size_t i = 0; i < n_items; i++) { buf[i] = T(std::rand()); } } // Fill a buffer with increasing numbers -template -void init_inc_vector(std::vector &buf_ptr, size_t n_items) +template void init_inc_vector(std::vector& buf_ptr, size_t n_items) { - T * const buf = reinterpret_cast(&buf_ptr[0]); + T* const buf = reinterpret_cast(&buf_ptr[0]); for (size_t i = 0; i < n_items; i++) { buf[i] = T(i); } } -void init_buffers( - std::vector< std::vector > &buf, - const std::string &type, - size_t bytes_per_item, - buf_init_t buf_seed_mode -) { +void init_buffers(std::vector>& buf, + const std::string& type, + size_t bytes_per_item, + buf_init_t buf_seed_mode) +{ if (buf.empty()) { return; } @@ -144,26 +138,25 @@ void init_buffers( if (buf_seed_mode == INC) { for (size_t i = 0; i < buf.size(); i++) { if (type == "sc8") { - init_inc_vector< std::complex >(buf[i], n_items); + init_inc_vector>(buf[i], n_items); } else if (type == "sc16") { - init_inc_vector< std::complex >(buf[i], n_items); + init_inc_vector>(buf[i], n_items); } else if (type == "sc32") { - init_inc_vector< std::complex >(buf[i], n_items); + init_inc_vector>(buf[i], n_items); } else if (type == "fc32") { - init_inc_vector< std::complex >(buf[i], n_items); + init_inc_vector>(buf[i], n_items); } else if (type == "fc64") { - init_inc_vector< std::complex >(buf[i], n_items); + init_inc_vector>(buf[i], n_items); } else if (type == "s8") { - init_inc_vector< int8_t >(buf[i], n_items); + init_inc_vector(buf[i], n_items); } else if (type == "s16") { - init_inc_vector< int16_t >(buf[i], n_items); + init_inc_vector(buf[i], n_items); } else if (type == "item32") { - init_inc_vector< uint32_t >(buf[i], n_items); + init_inc_vector(buf[i], n_items); init_random_vector_real_int(buf[i], n_items); } else { - throw uhd::runtime_error(str( - boost::format("Cannot handle data type: %s") % type - )); + throw uhd::runtime_error( + str(boost::format("Cannot handle data type: %s") % type)); } } @@ -193,21 +186,19 @@ void init_buffers( } else if (type == "item32") { init_random_vector_real_int(buf[i], n_items); } else { - throw uhd::runtime_error(str( - boost::format("Cannot handle data type: %s") % type - )); + throw uhd::runtime_error( + str(boost::format("Cannot handle data type: %s") % type)); } } } // Returns time elapsed -double run_benchmark( - converter::sptr conv, - const std::vector &input_buf_refs, - const std::vector &output_buf_refs, - size_t n_items, - size_t iterations -) { +double run_benchmark(converter::sptr conv, + const std::vector& input_buf_refs, + const std::vector& output_buf_refs, + size_t n_items, + size_t iterations) +{ boost::timer benchmark_timer; for (size_t i = 0; i < iterations; i++) { conv->conv(input_buf_refs, output_buf_refs, n_items); @@ -215,71 +206,58 @@ double run_benchmark( return benchmark_timer.elapsed(); } -template -std::string void_ptr_to_hexstring(const void *v_ptr, size_t index) +template std::string void_ptr_to_hexstring(const void* v_ptr, size_t index) { - const T *ptr = reinterpret_cast(v_ptr); + const T* ptr = reinterpret_cast(v_ptr); return str(boost::format("%X") % ptr[index]); } -std::string item_to_hexstring( - const void *v_ptr, - size_t index, - const std::string &type -) { +std::string item_to_hexstring(const void* v_ptr, size_t index, const std::string& type) +{ if (type == "fc32") { return void_ptr_to_hexstring(v_ptr, index); - } - else if (type == "sc16" || type == "item32") { + } else if (type == "sc16" || type == "item32") { return void_ptr_to_hexstring(v_ptr, index); - } - else if (type == "sc8" || type == "s16") { + } else if (type == "sc8" || type == "s16") { return void_ptr_to_hexstring(v_ptr, index); - } - else if (type == "u8") { + } else if (type == "u8") { return void_ptr_to_hexstring(v_ptr, index); - } - else { + } else { return str(boost::format("") % type); } } std::string item_to_string( - const void *v_ptr, - size_t index, - const std::string &type, - const bool print_hex -) { + const void* v_ptr, size_t index, const std::string& type, const bool print_hex) +{ if (print_hex) { return item_to_hexstring(v_ptr, index, type); } if (type == "sc16") { - const std::complex *ptr = reinterpret_cast *>(v_ptr); + const std::complex* ptr = + reinterpret_cast*>(v_ptr); return boost::lexical_cast(ptr[index]); - } - else if (type == "sc8") { - const std::complex *ptr = reinterpret_cast *>(v_ptr); + } else if (type == "sc8") { + const std::complex* ptr = + reinterpret_cast*>(v_ptr); return boost::lexical_cast(ptr[index]); - } - else if (type == "fc32") { - const std::complex *ptr = reinterpret_cast *>(v_ptr); + } else if (type == "fc32") { + const std::complex* ptr = + reinterpret_cast*>(v_ptr); return boost::lexical_cast(ptr[index]); - } - else if (type == "item32") { - const uint32_t *ptr = reinterpret_cast(v_ptr); + } else if (type == "item32") { + const uint32_t* ptr = reinterpret_cast(v_ptr); return boost::lexical_cast(ptr[index]); - } - else if (type == "s16") { - const int16_t *ptr = reinterpret_cast(v_ptr); + } else if (type == "s16") { + const int16_t* ptr = reinterpret_cast(v_ptr); return boost::lexical_cast(ptr[index]); - } - else { + } else { return str(boost::format("") % type); } } -int UHD_SAFE_MAIN(int argc, char *argv[]) +int UHD_SAFE_MAIN(int argc, char* argv[]) { std::string in_format, out_format; std::string priorities; @@ -311,15 +289,19 @@ int UHD_SAFE_MAIN(int argc, char *argv[]) po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); - //print the help message - if (vm.count("help")){ - std::cout << boost::format("UHD Converter Benchmark Tool %s") % desc << std::endl << std::endl; - std::cout << " Use this to benchmark or debug converters." << std::endl - << " When using as a benchmark tool, it will output the execution time\n" - " for every conversion run in CSV format to stdout. Every line between\n" - " the output delimiters {{{ }}} is of the format: ,