summaryrefslogtreecommitdiffstats
path: root/contrib/src/boost/integer
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/src/boost/integer')
-rw-r--r--contrib/src/boost/integer/integer_log2.hpp112
-rw-r--r--contrib/src/boost/integer/integer_mask.hpp126
-rw-r--r--contrib/src/boost/integer/static_log2.hpp127
3 files changed, 365 insertions, 0 deletions
diff --git a/contrib/src/boost/integer/integer_log2.hpp b/contrib/src/boost/integer/integer_log2.hpp
new file mode 100644
index 0000000..8b34ce7
--- /dev/null
+++ b/contrib/src/boost/integer/integer_log2.hpp
@@ -0,0 +1,112 @@
+// -----------------------------------------------------------
+// integer_log2.hpp
+//
+// Gives the integer part of the logarithm, in base 2, of a
+// given number. Behavior is undefined if the argument is <= 0.
+//
+// Copyright (c) 2003-2004, 2008 Gennaro Prota
+//
+// 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 BOOST_INTEGER_INTEGER_LOG2_HPP
+#define BOOST_INTEGER_INTEGER_LOG2_HPP
+
+#include <assert.h>
+#ifdef __BORLANDC__
+#include <climits>
+#endif
+#include <boost/limits.hpp>
+#include <boost/config.hpp>
+
+
+namespace boost {
+ namespace detail {
+
+ template <typename T>
+ int integer_log2_impl(T x, int n) {
+
+ int result = 0;
+
+ while (x != 1) {
+
+ const T t = static_cast<T>(x >> n);
+ if (t) {
+ result += n;
+ x = t;
+ }
+ n /= 2;
+
+ }
+
+ return result;
+ }
+
+
+
+ // helper to find the maximum power of two
+ // less than p (more involved than necessary,
+ // to avoid PTS)
+ //
+ template <int p, int n>
+ struct max_pow2_less {
+
+ enum { c = 2*n < p };
+
+ BOOST_STATIC_CONSTANT(int, value =
+ c ? (max_pow2_less< c*p, 2*c*n>::value) : n);
+
+ };
+
+ template <>
+ struct max_pow2_less<0, 0> {
+
+ BOOST_STATIC_CONSTANT(int, value = 0);
+ };
+
+ // this template is here just for Borland :(
+ // we could simply rely on numeric_limits but sometimes
+ // Borland tries to use numeric_limits<const T>, because
+ // of its usual const-related problems in argument deduction
+ // - gps
+ template <typename T>
+ struct width {
+
+#ifdef __BORLANDC__
+ BOOST_STATIC_CONSTANT(int, value = sizeof(T) * CHAR_BIT);
+#else
+ BOOST_STATIC_CONSTANT(int, value = (std::numeric_limits<T>::digits));
+#endif
+
+ };
+
+ } // detail
+
+
+ // ---------
+ // integer_log2
+ // ---------------
+ //
+ template <typename T>
+ int integer_log2(T x) {
+
+ assert(x > 0);
+
+ const int n = detail::max_pow2_less<
+ detail::width<T> :: value, 4
+ > :: value;
+
+ return detail::integer_log2_impl(x, n);
+
+ }
+
+
+
+}
+
+
+
+#endif // include guard
diff --git a/contrib/src/boost/integer/integer_mask.hpp b/contrib/src/boost/integer/integer_mask.hpp
new file mode 100644
index 0000000..2acf7f7
--- /dev/null
+++ b/contrib/src/boost/integer/integer_mask.hpp
@@ -0,0 +1,126 @@
+// Boost integer/integer_mask.hpp header file ------------------------------//
+
+// (C) Copyright Daryle Walker 2001.
+// 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)
+
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_INTEGER_INTEGER_MASK_HPP
+#define BOOST_INTEGER_INTEGER_MASK_HPP
+
+#include <boost/integer_fwd.hpp> // self include
+
+#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
+#include <boost/integer.hpp> // for boost::uint_t
+
+#include <climits> // for UCHAR_MAX, etc.
+#include <cstddef> // for std::size_t
+
+#include <boost/limits.hpp> // for std::numeric_limits
+
+//
+// We simply cannot include this header on gcc without getting copious warnings of the kind:
+//
+// boost/integer/integer_mask.hpp:93:35: warning: use of C99 long long integer constant
+//
+// And yet there is no other reasonable implementation, so we declare this a system header
+// to suppress these warnings.
+//
+#if defined(__GNUC__) && (__GNUC__ >= 4)
+#pragma GCC system_header
+#endif
+
+namespace boost
+{
+
+
+// Specified single-bit mask class declaration -----------------------------//
+// (Lowest bit starts counting at 0.)
+
+template < std::size_t Bit >
+struct high_bit_mask_t
+{
+ typedef typename uint_t<(Bit + 1)>::least least;
+ typedef typename uint_t<(Bit + 1)>::fast fast;
+
+ BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << Bit) );
+ BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << Bit) );
+
+ BOOST_STATIC_CONSTANT( std::size_t, bit_position = Bit );
+
+}; // boost::high_bit_mask_t
+
+
+// Specified bit-block mask class declaration ------------------------------//
+// Makes masks for the lowest N bits
+// (Specializations are needed when N fills up a type.)
+
+template < std::size_t Bits >
+struct low_bits_mask_t
+{
+ typedef typename uint_t<Bits>::least least;
+ typedef typename uint_t<Bits>::fast fast;
+
+ BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) );
+ BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) );
+
+ BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits );
+
+}; // boost::low_bits_mask_t
+
+
+#define BOOST_LOW_BITS_MASK_SPECIALIZE( Type ) \
+ template < > struct low_bits_mask_t< std::numeric_limits<Type>::digits > { \
+ typedef std::numeric_limits<Type> limits_type; \
+ typedef uint_t<limits_type::digits>::least least; \
+ typedef uint_t<limits_type::digits>::fast fast; \
+ BOOST_STATIC_CONSTANT( least, sig_bits = (~( least(0u) )) ); \
+ BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); \
+ BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits ); \
+ }
+
+#ifdef BOOST_MSVC
+#pragma warning(push)
+#pragma warning(disable:4245) // 'initializing' : conversion from 'int' to 'const boost::low_bits_mask_t<8>::least', signed/unsigned mismatch
+#endif
+
+BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char );
+
+#if USHRT_MAX > UCHAR_MAX
+BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned short );
+#endif
+
+#if UINT_MAX > USHRT_MAX
+BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int );
+#endif
+
+#if ULONG_MAX > UINT_MAX
+BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long );
+#endif
+
+#if defined(BOOST_HAS_LONG_LONG)
+ #if ((defined(ULLONG_MAX) && (ULLONG_MAX > ULONG_MAX)) ||\
+ (defined(ULONG_LONG_MAX) && (ULONG_LONG_MAX > ULONG_MAX)) ||\
+ (defined(ULONGLONG_MAX) && (ULONGLONG_MAX > ULONG_MAX)) ||\
+ (defined(_ULLONG_MAX) && (_ULLONG_MAX > ULONG_MAX)))
+ BOOST_LOW_BITS_MASK_SPECIALIZE( boost::ulong_long_type );
+ #endif
+#elif defined(BOOST_HAS_MS_INT64)
+ #if 18446744073709551615ui64 > ULONG_MAX
+ BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned __int64 );
+ #endif
+#endif
+
+#ifdef BOOST_MSVC
+#pragma warning(pop)
+#endif
+
+#undef BOOST_LOW_BITS_MASK_SPECIALIZE
+
+
+} // namespace boost
+
+
+#endif // BOOST_INTEGER_INTEGER_MASK_HPP
diff --git a/contrib/src/boost/integer/static_log2.hpp b/contrib/src/boost/integer/static_log2.hpp
new file mode 100644
index 0000000..56c7a00
--- /dev/null
+++ b/contrib/src/boost/integer/static_log2.hpp
@@ -0,0 +1,127 @@
+// -------------- Boost static_log2.hpp header file ----------------------- //
+//
+// Copyright (C) 2001 Daryle Walker.
+// Copyright (C) 2003 Vesa Karvonen.
+// Copyright (C) 2003 Gennaro Prota.
+//
+// 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)
+//
+// ---------------------------------------------------
+// See http://www.boost.org/libs/integer for documentation.
+// ------------------------------------------------------------------------- //
+
+
+#ifndef BOOST_INTEGER_STATIC_LOG2_HPP
+#define BOOST_INTEGER_STATIC_LOG2_HPP
+
+#include "boost/integer_fwd.hpp" // for boost::intmax_t
+
+namespace boost {
+
+ namespace detail {
+
+ namespace static_log2_impl {
+
+ // choose_initial_n<>
+ //
+ // Recursively doubles its integer argument, until it
+ // becomes >= of the "width" (C99, 6.2.6.2p4) of
+ // static_log2_argument_type.
+ //
+ // Used to get the maximum power of two less then the width.
+ //
+ // Example: if on your platform argument_type has 48 value
+ // bits it yields n=32.
+ //
+ // It's easy to prove that, starting from such a value
+ // of n, the core algorithm works correctly for any width
+ // of static_log2_argument_type and that recursion always
+ // terminates with x = 1 and n = 0 (see the algorithm's
+ // invariant).
+
+ typedef boost::static_log2_argument_type argument_type;
+ typedef boost::static_log2_result_type result_type;
+
+ template <result_type n>
+ struct choose_initial_n {
+
+ BOOST_STATIC_CONSTANT(bool, c = (argument_type(1) << n << n) != 0);
+ BOOST_STATIC_CONSTANT(
+ result_type,
+ value = !c*n + choose_initial_n<2*c*n>::value
+ );
+
+ };
+
+ template <>
+ struct choose_initial_n<0> {
+ BOOST_STATIC_CONSTANT(result_type, value = 0);
+ };
+
+
+
+ // start computing from n_zero - must be a power of two
+ const result_type n_zero = 16;
+ const result_type initial_n = choose_initial_n<n_zero>::value;
+
+ // static_log2_impl<>
+ //
+ // * Invariant:
+ // 2n
+ // 1 <= x && x < 2 at the start of each recursion
+ // (see also choose_initial_n<>)
+ //
+ // * Type requirements:
+ //
+ // argument_type maybe any unsigned type with at least n_zero + 1
+ // value bits. (Note: If larger types will be standardized -e.g.
+ // unsigned long long- then the argument_type typedef can be
+ // changed without affecting the rest of the code.)
+ //
+
+ template <argument_type x, result_type n = initial_n>
+ struct static_log2_impl {
+
+ BOOST_STATIC_CONSTANT(bool, c = (x >> n) > 0); // x >= 2**n ?
+ BOOST_STATIC_CONSTANT(
+ result_type,
+ value = c*n + (static_log2_impl< (x>>c*n), n/2 >::value)
+ );
+
+ };
+
+ template <>
+ struct static_log2_impl<1, 0> {
+ BOOST_STATIC_CONSTANT(result_type, value = 0);
+ };
+
+ }
+ } // detail
+
+
+
+ // --------------------------------------
+ // static_log2<x>
+ // ----------------------------------------
+
+ template <static_log2_argument_type x>
+ struct static_log2 {
+
+ BOOST_STATIC_CONSTANT(
+ static_log2_result_type,
+ value = detail::static_log2_impl::static_log2_impl<x>::value
+ );
+
+ };
+
+
+ template <>
+ struct static_log2<0> { };
+
+}
+
+
+
+#endif // include guard