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/lib/packed_to_unpacked_impl.cc | |
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/lib/packed_to_unpacked_impl.cc')
-rw-r--r-- | gr-blocks/lib/packed_to_unpacked_impl.cc | 20 |
1 files changed, 17 insertions, 3 deletions
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; |