diff options
author | Marcus Müller <mmueller@gnuradio.org> | 2020-06-20 23:36:33 +0200 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2020-08-14 16:21:04 -0400 |
commit | ed972766296683b671f59eca1e83c947f88060f4 (patch) | |
tree | a7f735a20bd16bf363a03a32a90356f0187805d1 /gr-blocks | |
parent | 17071332b1603878d05f139131d163d08efbae5a (diff) |
blocks: remove log2_const
Was not standards-compliant (assert(0) in constexpr)
Only used in packed_to_unpacked to get the log2(number of bits(type)) in
packed_to_unpacked<type>.
Was not wrapped to python nor public API.
To little surprise, a static method compiles faster, and gets
compile-time-calculated by a modern compiler, too.
Diffstat (limited to 'gr-blocks')
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/log2_const.h | 90 | ||||
-rw-r--r-- | gr-blocks/lib/packed_to_unpacked_impl.cc | 20 | ||||
-rw-r--r-- | gr-blocks/lib/packed_to_unpacked_impl.h | 3 | ||||
-rw-r--r-- | gr-blocks/python/blocks/bindings/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/python/blocks/bindings/docstrings/log2_const_pydoc_template.h | 48 | ||||
-rw-r--r-- | gr-blocks/python/blocks/bindings/log2_const_python.cc | 43 | ||||
-rw-r--r-- | gr-blocks/python/blocks/bindings/python_bindings.cc | 2 |
8 files changed, 18 insertions, 190 deletions
diff --git a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt index 4721618ed7..e7d6789683 100644 --- a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt +++ b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt @@ -27,7 +27,6 @@ install(FILES integrate.h lfsr_15_1_0.h lfsr_32k.h - log2_const.h max_blk.h min_blk.h moving_average.h diff --git a/gr-blocks/include/gnuradio/blocks/log2_const.h b/gr-blocks/include/gnuradio/blocks/log2_const.h deleted file mode 100644 index 34d7b86bd1..0000000000 --- a/gr-blocks/include/gnuradio/blocks/log2_const.h +++ /dev/null @@ -1,90 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - - -/* - * a bit of template hackery... - */ -#ifndef INCLUDED_BLOCKS_LOG2_CONST_H -#define INCLUDED_BLOCKS_LOG2_CONST_H - -#include <gnuradio/blocks/api.h> -#include <assert.h> - -namespace gr { -namespace blocks { - -template <unsigned int k> -static inline constexpr int log2_const() -{ - assert(0); - return 0; -} - -template <> -inline constexpr int log2_const<1>() -{ - return 0; -} -template <> -inline constexpr int log2_const<2>() -{ - return 1; -} -template <> -inline constexpr int log2_const<4>() -{ - return 2; -} -template <> -inline constexpr int log2_const<8>() -{ - return 3; -} -template <> -inline constexpr int log2_const<16>() -{ - return 4; -} -template <> -inline constexpr int log2_const<32>() -{ - return 5; -} -template <> -inline constexpr int log2_const<64>() -{ - return 6; -} -template <> -inline constexpr int log2_const<128>() -{ - return 7; -} -template <> -inline constexpr int log2_const<256>() -{ - return 8; -} -template <> -inline constexpr int log2_const<512>() -{ - return 9; -} -template <> -inline constexpr int log2_const<1024>() -{ - return 10; -} - -} /* namespace blocks */ -} /* namespace gr */ - -#endif /* INCLUDED_BLOCKS_LOG2_CONST_H */ diff --git a/gr-blocks/lib/packed_to_unpacked_impl.cc b/gr-blocks/lib/packed_to_unpacked_impl.cc index 03a80aa44c..f516f1a8a3 100644 --- a/gr-blocks/lib/packed_to_unpacked_impl.cc +++ b/gr-blocks/lib/packed_to_unpacked_impl.cc @@ -63,10 +63,24 @@ void packed_to_unpacked_impl<T>::forecast(int noutput_items, } template <class T> +unsigned int packed_to_unpacked_impl<T>::log2_l_type() +{ + unsigned int val = sizeof(T); + if (!val || (val & (val - 1))) { + return 0; + } + unsigned int ld = 0; + while (val >>= 1) { + ld++; + } + return ld + 3; +}; + +template <class T> unsigned int packed_to_unpacked_impl<T>::get_bit_le(const T* in_vector, unsigned int bit_addr) { - const T x = in_vector[bit_addr >> this->d_log2_l_type]; + const T x = in_vector[bit_addr >> this->log2_l_type()]; return (x >> (bit_addr & (this->d_bits_per_type - 1))) & 1; } @@ -74,7 +88,7 @@ template <class T> unsigned int packed_to_unpacked_impl<T>::get_bit_be(const T* in_vector, unsigned int bit_addr) { - const T x = in_vector[bit_addr >> this->d_log2_l_type]; + const T x = in_vector[bit_addr >> this->log2_l_type()]; return (x >> ((this->d_bits_per_type - 1) - (bit_addr & (this->d_bits_per_type - 1)))) & 1; @@ -129,7 +143,7 @@ int packed_to_unpacked_impl<T>::general_work(int noutput_items, } d_index = index_tmp; - this->consume_each(d_index >> this->d_log2_l_type); + this->consume_each(d_index >> this->log2_l_type()); d_index = d_index & (this->d_bits_per_type - 1); // printf("got to end\n"); return noutput_items; diff --git a/gr-blocks/lib/packed_to_unpacked_impl.h b/gr-blocks/lib/packed_to_unpacked_impl.h index 4de1866429..1cf86d246d 100644 --- a/gr-blocks/lib/packed_to_unpacked_impl.h +++ b/gr-blocks/lib/packed_to_unpacked_impl.h @@ -12,7 +12,6 @@ #ifndef PACKED_TO_UNPACKED_IMPL_H #define PACKED_TO_UNPACKED_IMPL_H -#include <gnuradio/blocks/log2_const.h> #include <gnuradio/blocks/packed_to_unpacked.h> namespace gr { @@ -26,7 +25,7 @@ private: const endianness_t d_endianness; unsigned int d_index; static constexpr unsigned int d_bits_per_type = sizeof(T) * 8; - static constexpr unsigned int d_log2_l_type = log2_const<sizeof(T) * 8>(); + static unsigned int log2_l_type(); unsigned int get_bit_le(const T* in_vector, unsigned int bit_addr); unsigned int get_bit_be(const T* in_vector, unsigned int bit_addr); diff --git a/gr-blocks/python/blocks/bindings/CMakeLists.txt b/gr-blocks/python/blocks/bindings/CMakeLists.txt index bc3d284b94..976e12d180 100644 --- a/gr-blocks/python/blocks/bindings/CMakeLists.txt +++ b/gr-blocks/python/blocks/bindings/CMakeLists.txt @@ -73,7 +73,6 @@ list(APPEND blocks_python_files lfsr_15_1_0_python.cc lfsr_32k_python.cc lfsr_32k_source_s_python.cc - # log2_const_python.cc magphase_to_complex_python.cc max_blk_python.cc message_debug_python.cc diff --git a/gr-blocks/python/blocks/bindings/docstrings/log2_const_pydoc_template.h b/gr-blocks/python/blocks/bindings/docstrings/log2_const_pydoc_template.h deleted file mode 100644 index e31bf5582e..0000000000 --- a/gr-blocks/python/blocks/bindings/docstrings/log2_const_pydoc_template.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2020 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ -#include "pydoc_macros.h" -#define D(...) DOC(gr, blocks, __VA_ARGS__) -/* - This file contains placeholders for docstrings for the Python bindings. - Do not edit! These were automatically extracted during the binding process - and will be overwritten during the build process - */ - - -static const char* __doc_gr_blocks_log2_const_0 = R"doc()doc"; - - -static const char* __doc_gr_blocks_log2_const_0 = R"doc()doc"; - - -static const char* __doc_gr_blocks_log2_const_0 = R"doc()doc"; - - -static const char* __doc_gr_blocks_log2_const_0 = R"doc()doc"; - - -static const char* __doc_gr_blocks_log2_const_0 = R"doc()doc"; - - -static const char* __doc_gr_blocks_log2_const_0 = R"doc()doc"; - - -static const char* __doc_gr_blocks_log2_const_0 = R"doc()doc"; - - -static const char* __doc_gr_blocks_log2_const_0 = R"doc()doc"; - - -static const char* __doc_gr_blocks_log2_const_0 = R"doc()doc"; - - -static const char* __doc_gr_blocks_log2_const_0 = R"doc()doc"; - - -static const char* __doc_gr_blocks_log2_const_0 = R"doc()doc"; diff --git a/gr-blocks/python/blocks/bindings/log2_const_python.cc b/gr-blocks/python/blocks/bindings/log2_const_python.cc deleted file mode 100644 index 3c8327eaf8..0000000000 --- a/gr-blocks/python/blocks/bindings/log2_const_python.cc +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2020 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -/***********************************************************************************/ -/* This file is automatically generated using bindtool and can be manually edited */ -/* The following lines can be configured to regenerate this file during cmake */ -/* If manual edits are made, the following tags should be modified accordingly. */ -/* BINDTOOL_GEN_AUTOMATIC(0) */ -/* BINDTOOL_USE_PYGCCXML(0) */ -/* BINDTOOL_HEADER_FILE(log2_const.h) */ -/* BINDTOOL_HEADER_FILE_HASH(f4afb8807dd68b6561896201a8489a0c) */ -/***********************************************************************************/ - -#include <pybind11/complex.h> -#include <pybind11/pybind11.h> -#include <pybind11/stl.h> - -namespace py = pybind11; - -#include <gnuradio/blocks/log2_const.h> - -void bind_log2_const(py::module& m) -{ - - - m.def("log2_const", &gr::blocks::log2_const); - m.def("log2_const", &gr::blocks::log2_const); - m.def("log2_const", &gr::blocks::log2_const); - m.def("log2_const", &gr::blocks::log2_const); - m.def("log2_const", &gr::blocks::log2_const); - m.def("log2_const", &gr::blocks::log2_const); - m.def("log2_const", &gr::blocks::log2_const); - m.def("log2_const", &gr::blocks::log2_const); - m.def("log2_const", &gr::blocks::log2_const); - m.def("log2_const", &gr::blocks::log2_const); - m.def("log2_const", &gr::blocks::log2_const); -} diff --git a/gr-blocks/python/blocks/bindings/python_bindings.cc b/gr-blocks/python/blocks/bindings/python_bindings.cc index 32dd5d657d..8cbec6d7fd 100644 --- a/gr-blocks/python/blocks/bindings/python_bindings.cc +++ b/gr-blocks/python/blocks/bindings/python_bindings.cc @@ -84,7 +84,6 @@ void bind_keep_one_in_n(py::module&); void bind_lfsr_15_1_0(py::module&); void bind_lfsr_32k(py::module&); void bind_lfsr_32k_source_s(py::module&); -// void bind_log2_const(py::module&); void bind_magphase_to_complex(py::module&); void bind_max_blk(py::module&); void bind_message_debug(py::module&); @@ -266,7 +265,6 @@ PYBIND11_MODULE(blocks_python, m) bind_lfsr_15_1_0(m); bind_lfsr_32k(m); bind_lfsr_32k_source_s(m); - // bind_log2_const(m); bind_magphase_to_complex(m); bind_max_blk(m); bind_message_debug(m); |