From e244ea2932382a882641db397a68f5fade54a1ef Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Mon, 31 Mar 2014 17:18:22 +0900 Subject: [PATCH] add c++1y rightmost bit manipurations --- sprout/bit/bit_length.hpp | 80 ++++++++++++++++++++ sprout/bit/bit_reverse.hpp | 90 +++++++++++++++++++++++ sprout/bit/count.hpp | 22 ++++++ sprout/bit/{rotate.hpp => isols0b.hpp} | 26 ++----- sprout/bit/isols1b.hpp | 28 +++++++ sprout/bit/length.hpp | 68 +---------------- sprout/bit/maskt0.hpp | 28 +++++++ sprout/bit/maskt0ls1b.hpp | 28 +++++++ sprout/bit/maskt1.hpp | 28 +++++++ sprout/bit/maskt1ls0b.hpp | 28 +++++++ sprout/bit/operation.hpp | 25 +++---- sprout/bit/parity.hpp | 51 +++++++++++++ sprout/bit/reverse.hpp | 81 +------------------- sprout/bit/rightmost.hpp | 23 ++++++ sprout/bit/rstls1b.hpp | 28 +++++++ sprout/bit/rstt1.hpp | 28 +++++++ sprout/bit/setls0b.hpp | 28 +++++++ sprout/bit/sett0.hpp | 28 +++++++ sprout/bit/shift.hpp | 19 +++++ sprout/numeric/fft/fixed/bitrev_table.hpp | 4 +- sprout/utility/pack.hpp | 2 +- 21 files changed, 560 insertions(+), 183 deletions(-) create mode 100644 sprout/bit/bit_length.hpp create mode 100644 sprout/bit/bit_reverse.hpp create mode 100644 sprout/bit/count.hpp rename sprout/bit/{rotate.hpp => isols0b.hpp} (55%) create mode 100644 sprout/bit/isols1b.hpp create mode 100644 sprout/bit/maskt0.hpp create mode 100644 sprout/bit/maskt0ls1b.hpp create mode 100644 sprout/bit/maskt1.hpp create mode 100644 sprout/bit/maskt1ls0b.hpp create mode 100644 sprout/bit/parity.hpp create mode 100644 sprout/bit/rightmost.hpp create mode 100644 sprout/bit/rstls1b.hpp create mode 100644 sprout/bit/rstt1.hpp create mode 100644 sprout/bit/setls0b.hpp create mode 100644 sprout/bit/sett0.hpp create mode 100644 sprout/bit/shift.hpp diff --git a/sprout/bit/bit_length.hpp b/sprout/bit/bit_length.hpp new file mode 100644 index 00000000..aab36ed6 --- /dev/null +++ b/sprout/bit/bit_length.hpp @@ -0,0 +1,80 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_BIT_LENGTH_HPP +#define SPROUT_BIT_BIT_LENGTH_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace detail { + SPROUT_STATIC_CONSTEXPR std::size_t bit_len_8_table[std::size_t(UCHAR_MAX) + 1] = { + 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 + }; + template + struct bit_len { + private: + SPROUT_STATIC_CONSTEXPR std::size_t next_size = Size - 1; + SPROUT_STATIC_CONSTEXPR std::size_t shift_bits = next_size * CHAR_BIT; + private: + template + SPROUT_CONSTEXPR Integral + impl(Integral x, unsigned char i) const { + return bit_len_8_table[i] + ? bit_len_8_table[i] + next_size * CHAR_BIT + : sprout::detail::bit_len().template operator()(x) + ; + } + public: + template + SPROUT_CONSTEXPR Integral + operator()(Integral x) const { + return impl(x, static_cast((x >> shift_bits) & UCHAR_MAX)); + } + }; + template<> + struct bit_len<1> { + public: + template + SPROUT_CONSTEXPR Integral + operator()(Integral x) const { + return bit_len_8_table[static_cast(x & UCHAR_MAX)]; + } + }; + } // namespace detail + // + // bit_length + // + template + inline SPROUT_CONSTEXPR typename std::enable_if< + std::is_integral::value, + Integral + >::type + bit_length(Integral x) { + return sprout::detail::bit_len().template operator()(x); + } +} // namespace sprout + +#endif // #ifndef SPROUT_BIT_BIT_LENGTH_HPP diff --git a/sprout/bit/bit_reverse.hpp b/sprout/bit/bit_reverse.hpp new file mode 100644 index 00000000..e38c5963 --- /dev/null +++ b/sprout/bit/bit_reverse.hpp @@ -0,0 +1,90 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_BIT_REVERSE_HPP +#define SPROUT_BIT_BIT_REVERSE_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace detail { + SPROUT_STATIC_CONSTEXPR unsigned char bit_rev_8_table[std::size_t(UCHAR_MAX) + 1] = { + 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, 8, 136, 72, 200, + 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, 4, 132, 68, 196, 36, 164, 100, 228, + 20, 148, 84, 212, 52, 180, 116, 244, 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, + 60, 188, 124, 252, 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, + 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, 6, 134, 70, 198, + 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246, 14, 142, 78, 206, 46, 174, 110, 238, + 30, 158, 94, 222, 62, 190, 126, 254, 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, + 49, 177, 113, 241, 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, + 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, 13, 141, 77, 205, + 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, 3, 131, 67, 195, 35, 163, 99, 227, + 19, 147, 83, 211, 51, 179, 115, 243, 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, + 59, 187, 123, 251, 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, + 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255 + }; + template + struct bit_rev { + private: + SPROUT_STATIC_CONSTEXPR std::size_t next_size = Size / 2; + SPROUT_STATIC_CONSTEXPR std::size_t shift_bits = next_size * CHAR_BIT; + public: + template + SPROUT_CONSTEXPR Integral + operator()(Integral x) const { + return (sprout::detail::bit_rev().template operator()(x) << shift_bits) + | (sprout::detail::bit_rev().template operator()(x >> shift_bits)) + ; + } + }; + template<> + struct bit_rev<1> { + public: + template + SPROUT_CONSTEXPR Integral + operator()(Integral x) const { + return sprout::detail::bit_rev_8_table[static_cast(x & UCHAR_MAX)]; + } + }; + } // namespace detail + // + // bit_reverse + // + template + SPROUT_CONSTEXPR typename std::enable_if< + std::is_integral::value, + Integral + >::type + bit_reverse(Integral x) { + typedef typename std::make_unsigned::type unsigned_type; + return static_cast( + sprout::detail::bit_rev().template operator()(x) + ); + } + // + // bit_reverse_in + // + template + inline SPROUT_CONSTEXPR typename std::enable_if< + std::is_integral::value, + Integral + >::type + bit_reverse_in(Integral x, int length) { + typedef typename std::make_unsigned::type unsigned_type; + return SPROUT_ASSERT(length <= sizeof(Integral) * CHAR_BIT), + static_cast( + sprout::detail::bit_rev().template operator()(x) + >> (sizeof(Integral) * CHAR_BIT - length) + ) + ; + } +} // namespace sprout + +#endif // #ifndef SPROUT_BIT_BIT_REVERSE_HPP diff --git a/sprout/bit/count.hpp b/sprout/bit/count.hpp new file mode 100644 index 00000000..1315e329 --- /dev/null +++ b/sprout/bit/count.hpp @@ -0,0 +1,22 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_COUNT_HPP +#define SPROUT_BIT_COUNT_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_BIT_COUNT_HPP diff --git a/sprout/bit/rotate.hpp b/sprout/bit/isols0b.hpp similarity index 55% rename from sprout/bit/rotate.hpp rename to sprout/bit/isols0b.hpp index 6c5230fe..01699c58 100644 --- a/sprout/bit/rotate.hpp +++ b/sprout/bit/isols0b.hpp @@ -5,38 +5,24 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#ifndef SPROUT_BIT_ROTATE_HPP -#define SPROUT_BIT_ROTATE_HPP +#ifndef SPROUT_BIT_ISOLS0B_HPP +#define SPROUT_BIT_RSTLS0B_HPP #include #include -#include -#include namespace sprout { // - // left_rotate + // isols0b // template inline SPROUT_CONSTEXPR typename std::enable_if< std::is_integral::value, Integral >::type - left_rotate(Integral x, int s) { - return sprout::rotl(x, s); - } - - // - // right_rotate - // - template - inline SPROUT_CONSTEXPR typename std::enable_if< - std::is_integral::value, - Integral - >::type - right_rotate(Integral x, int s) { - return sprout::rotr(x, s); + isols0b(Integral x) SPROUT_NOEXCEPT { + return ~x & (x + 1); } } // namespace sprout -#endif // #ifndef SPROUT_BIT_ROTATE_HPP +#endif // #ifndef SPROUT_BIT_RSTLS0B_HPP diff --git a/sprout/bit/isols1b.hpp b/sprout/bit/isols1b.hpp new file mode 100644 index 00000000..d0d7ba45 --- /dev/null +++ b/sprout/bit/isols1b.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_ISOLS1B_HPP +#define SPROUT_BIT_RSTLS1B_HPP + +#include +#include + +namespace sprout { + // + // isols1b + // + template + inline SPROUT_CONSTEXPR typename std::enable_if< + std::is_integral::value, + Integral + >::type + isols1b(Integral x) SPROUT_NOEXCEPT { + return x & -x; + } +} // namespace sprout + +#endif // #ifndef SPROUT_BIT_RSTLS1B_HPP diff --git a/sprout/bit/length.hpp b/sprout/bit/length.hpp index 7798d584..1289be24 100644 --- a/sprout/bit/length.hpp +++ b/sprout/bit/length.hpp @@ -8,73 +8,7 @@ #ifndef SPROUT_BIT_LENGTH_HPP #define SPROUT_BIT_LENGTH_HPP -#include -#include -#include #include - -namespace sprout { - namespace detail { - SPROUT_STATIC_CONSTEXPR std::size_t bit_len_8_table[std::size_t(UCHAR_MAX) + 1] = { - 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 - }; - template - struct bit_len { - private: - SPROUT_STATIC_CONSTEXPR std::size_t next_size = Size - 1; - SPROUT_STATIC_CONSTEXPR std::size_t shift_bits = next_size * CHAR_BIT; - private: - template - SPROUT_CONSTEXPR IntType - impl(IntType x, unsigned char i) const { - return bit_len_8_table[i] - ? bit_len_8_table[i] + next_size * CHAR_BIT - : sprout::detail::bit_len().template operator()(x) - ; - } - public: - template - SPROUT_CONSTEXPR IntType - operator()(IntType x) const { - return impl(x, static_cast((x >> shift_bits) & UCHAR_MAX)); - } - }; - template<> - struct bit_len<1> { - public: - template - SPROUT_CONSTEXPR IntType - operator()(IntType x) const { - return bit_len_8_table[static_cast(x & UCHAR_MAX)]; - } - }; - } // namespace detail - // - // bit_length - // - template - inline SPROUT_CONSTEXPR typename std::enable_if< - std::is_integral::value, - IntType - >::type - bit_length(IntType x) { - return sprout::detail::bit_len().template operator()(x); - } -} // namespace sprout +#include #endif // #ifndef SPROUT_BIT_LENGTH_HPP diff --git a/sprout/bit/maskt0.hpp b/sprout/bit/maskt0.hpp new file mode 100644 index 00000000..13e43b19 --- /dev/null +++ b/sprout/bit/maskt0.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_MASKT0_HPP +#define SPROUT_BIT_MASKT0_HPP + +#include +#include + +namespace sprout { + // + // maskt0 + // + template + inline SPROUT_CONSTEXPR typename std::enable_if< + std::is_integral::value, + Integral + >::type + maskt0(Integral x) SPROUT_NOEXCEPT { + return ~x & (x - 1); + } +} // namespace sprout + +#endif // #ifndef SPROUT_BIT_MASKT0_HPP diff --git a/sprout/bit/maskt0ls1b.hpp b/sprout/bit/maskt0ls1b.hpp new file mode 100644 index 00000000..12f5a39c --- /dev/null +++ b/sprout/bit/maskt0ls1b.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_MASKT0LS1B_HPP +#define SPROUT_BIT_MASKT0LS1B_HPP + +#include +#include + +namespace sprout { + // + // maskt0ls1b + // + template + inline SPROUT_CONSTEXPR typename std::enable_if< + std::is_integral::value, + Integral + >::type + maskt0ls1b(Integral x) SPROUT_NOEXCEPT { + return (x - 1) ^ x; + } +} // namespace sprout + +#endif // #ifndef SPROUT_BIT_MASKT0LS1B_HPP diff --git a/sprout/bit/maskt1.hpp b/sprout/bit/maskt1.hpp new file mode 100644 index 00000000..c797f43c --- /dev/null +++ b/sprout/bit/maskt1.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_MASKT1_HPP +#define SPROUT_BIT_MASKT1_HPP + +#include +#include + +namespace sprout { + // + // maskt1 + // + template + inline SPROUT_CONSTEXPR typename std::enable_if< + std::is_integral::value, + Integral + >::type + maskt1(Integral x) SPROUT_NOEXCEPT { + return ~(~x | (x + 1)); + } +} // namespace sprout + +#endif // #ifndef SPROUT_BIT_MASKT1_HPP diff --git a/sprout/bit/maskt1ls0b.hpp b/sprout/bit/maskt1ls0b.hpp new file mode 100644 index 00000000..9099afc8 --- /dev/null +++ b/sprout/bit/maskt1ls0b.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_MASKT0LS0B_HPP +#define SPROUT_BIT_MASKT0LS0B_HPP + +#include +#include + +namespace sprout { + // + // maskt1ls0b + // + template + inline SPROUT_CONSTEXPR typename std::enable_if< + std::is_integral::value, + Integral + >::type + maskt1ls0b(Integral x) SPROUT_NOEXCEPT { + return x ^ (x + 1); + } +} // namespace sprout + +#endif // #ifndef SPROUT_BIT_MASKT0LS0B_HPP diff --git a/sprout/bit/operation.hpp b/sprout/bit/operation.hpp index 0c544ca0..ecd94370 100644 --- a/sprout/bit/operation.hpp +++ b/sprout/bit/operation.hpp @@ -9,22 +9,17 @@ #define SPROUT_BIT_OPERATION_HPP #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include +//#include +//#include +//#include +//#include +//#include +//#include +//#include #include #endif // #ifndef SPROUT_BIT_OPERATION_HPP diff --git a/sprout/bit/parity.hpp b/sprout/bit/parity.hpp new file mode 100644 index 00000000..7a3985f7 --- /dev/null +++ b/sprout/bit/parity.hpp @@ -0,0 +1,51 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_PARITY_HPP +#define SPROUT_BIT_PARITY_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace detail { +# if SPROUT_USE_BUILTIN_BIT_OPERATION + inline SPROUT_CONSTEXPR int + parity(unsigned x) { + return __builtin_parity(x); + } + inline SPROUT_CONSTEXPR int + parity(unsigned long x) { + return __builtin_parityl(x); + } + inline SPROUT_CONSTEXPR int + parity(unsigned long long x) { + return __builtin_parityll(x); + } +# endif + template + inline SPROUT_CONSTEXPR int + parity(Integral x) { + return sprout::popcount(x) & 1; + } + } // namespace detail + // + // parity + // + template + inline SPROUT_CONSTEXPR typename std::enable_if< + std::is_integral::value, + int + >::type + parity(Integral x) { + return sprout::detail::parity(x); + } +} // namespace sprout + +#endif // #ifndef SPROUT_BIT_PARITY_HPP diff --git a/sprout/bit/reverse.hpp b/sprout/bit/reverse.hpp index 6e598446..507d3633 100644 --- a/sprout/bit/reverse.hpp +++ b/sprout/bit/reverse.hpp @@ -8,84 +8,9 @@ #ifndef SPROUT_BIT_REVERSE_HPP #define SPROUT_BIT_REVERSE_HPP -#include -#include -#include #include -#include - -namespace sprout { - namespace detail { - SPROUT_STATIC_CONSTEXPR unsigned char bit_rev_8_table[std::size_t(UCHAR_MAX) + 1] = { - 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, 8, 136, 72, 200, - 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, 4, 132, 68, 196, 36, 164, 100, 228, - 20, 148, 84, 212, 52, 180, 116, 244, 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, - 60, 188, 124, 252, 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, - 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, 6, 134, 70, 198, - 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246, 14, 142, 78, 206, 46, 174, 110, 238, - 30, 158, 94, 222, 62, 190, 126, 254, 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, - 49, 177, 113, 241, 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, - 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, 13, 141, 77, 205, - 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, 3, 131, 67, 195, 35, 163, 99, 227, - 19, 147, 83, 211, 51, 179, 115, 243, 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, - 59, 187, 123, 251, 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, - 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255 - }; - template - struct bit_rev { - private: - SPROUT_STATIC_CONSTEXPR std::size_t next_size = Size / 2; - SPROUT_STATIC_CONSTEXPR std::size_t shift_bits = next_size * CHAR_BIT; - public: - template - SPROUT_CONSTEXPR IntType - operator()(IntType x) const { - return (sprout::detail::bit_rev().template operator()(x) << shift_bits) - | (sprout::detail::bit_rev().template operator()(x >> shift_bits)) - ; - } - }; - template<> - struct bit_rev<1> { - public: - template - SPROUT_CONSTEXPR IntType - operator()(IntType x) const { - return sprout::detail::bit_rev_8_table[static_cast(x & UCHAR_MAX)]; - } - }; - } // namespace detail - // - // bit_reverse - // - template - SPROUT_CONSTEXPR typename std::enable_if< - std::is_integral::value, - IntType - >::type - bit_reverse(IntType x) { - typedef typename std::make_unsigned::type unsigned_type; - return static_cast( - sprout::detail::bit_rev().template operator()(x) - ); - } - // - // bit_reverse_in - // - template - inline SPROUT_CONSTEXPR typename std::enable_if< - std::is_integral::value, - IntType - >::type - bit_reverse_in(IntType x, std::size_t length) { - typedef typename std::make_unsigned::type unsigned_type; - return SPROUT_ASSERT(length <= sizeof(IntType) * CHAR_BIT), - static_cast( - sprout::detail::bit_rev().template operator()(x) - >> (sizeof(IntType) * CHAR_BIT - length) - ) - ; - } -} // namespace sprout +//#include +//#include +#include #endif // #ifndef SPROUT_BIT_REVERSE_HPP diff --git a/sprout/bit/rightmost.hpp b/sprout/bit/rightmost.hpp new file mode 100644 index 00000000..8b1a12d8 --- /dev/null +++ b/sprout/bit/rightmost.hpp @@ -0,0 +1,23 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_RIGHTMOTS_HPP +#define SPROUT_BIT_RIGHTMOTS_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_BIT_RIGHTMOTS_HPP diff --git a/sprout/bit/rstls1b.hpp b/sprout/bit/rstls1b.hpp new file mode 100644 index 00000000..14f5dce5 --- /dev/null +++ b/sprout/bit/rstls1b.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_RSTLS1B_HPP +#define SPROUT_BIT_RSTLS1B_HPP + +#include +#include + +namespace sprout { + // + // rstls1b + // + template + inline SPROUT_CONSTEXPR typename std::enable_if< + std::is_integral::value, + Integral + >::type + rstls1b(Integral x) SPROUT_NOEXCEPT { + return x & (x - 1); + } +} // namespace sprout + +#endif // #ifndef SPROUT_BIT_RSTLS1B_HPP diff --git a/sprout/bit/rstt1.hpp b/sprout/bit/rstt1.hpp new file mode 100644 index 00000000..14fc566c --- /dev/null +++ b/sprout/bit/rstt1.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_RSTT1_HPP +#define SPROUT_BIT_RSTT1_HPP + +#include +#include + +namespace sprout { + // + // rstt1 + // + template + inline SPROUT_CONSTEXPR typename std::enable_if< + std::is_integral::value, + Integral + >::type + rstt1(Integral x) SPROUT_NOEXCEPT { + return x & (x + 1); + } +} // namespace sprout + +#endif // #ifndef SPROUT_BIT_RSTT1_HPP diff --git a/sprout/bit/setls0b.hpp b/sprout/bit/setls0b.hpp new file mode 100644 index 00000000..c7a6aac4 --- /dev/null +++ b/sprout/bit/setls0b.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_RSTLS0B_HPP +#define SPROUT_BIT_RSTLS0B_HPP + +#include +#include + +namespace sprout { + // + // setls0b + // + template + inline SPROUT_CONSTEXPR typename std::enable_if< + std::is_integral::value, + Integral + >::type + setls0b(Integral x) SPROUT_NOEXCEPT { + return x | (x + 1); + } +} // namespace sprout + +#endif // #ifndef SPROUT_BIT_RSTLS0B_HPP diff --git a/sprout/bit/sett0.hpp b/sprout/bit/sett0.hpp new file mode 100644 index 00000000..982d502c --- /dev/null +++ b/sprout/bit/sett0.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_SETT0_HPP +#define SPROUT_BIT_SETT0_HPP + +#include +#include + +namespace sprout { + // + // sett0 + // + template + inline SPROUT_CONSTEXPR typename std::enable_if< + std::is_integral::value, + Integral + >::type + sett0(Integral x) SPROUT_NOEXCEPT { + return x | (x - 1); + } +} // namespace sprout + +#endif // #ifndef SPROUT_BIT_SETT0_HPP diff --git a/sprout/bit/shift.hpp b/sprout/bit/shift.hpp new file mode 100644 index 00000000..6c37d55d --- /dev/null +++ b/sprout/bit/shift.hpp @@ -0,0 +1,19 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_BIT_SHIFT_HPP +#define SPROUT_BIT_SHIFT_HPP + +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_BIT_SHIFT_HPP diff --git a/sprout/numeric/fft/fixed/bitrev_table.hpp b/sprout/numeric/fft/fixed/bitrev_table.hpp index 7d6ebe6a..fd1a795a 100644 --- a/sprout/numeric/fft/fixed/bitrev_table.hpp +++ b/sprout/numeric/fft/fixed/bitrev_table.hpp @@ -17,8 +17,8 @@ #include #include #include -#include -#include +#include +#include namespace sprout { namespace fixed { diff --git a/sprout/utility/pack.hpp b/sprout/utility/pack.hpp index 925a169b..378762dc 100644 --- a/sprout/utility/pack.hpp +++ b/sprout/utility/pack.hpp @@ -69,7 +69,7 @@ namespace sprout { // template inline SPROUT_CONSTEXPR Head&& - head_get(Head&& head, Tail&&... tail) { + head_get(Head&& head, Tail&&...) { return SPROUT_FORWARD(Head, head); } } // namespace sprout