annotate DEPENDENCIES/generic/include/boost/random/detail/integer_log2.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 /* boost random/detail/integer_log2.hpp header file
Chris@16 2 *
Chris@16 3 * Copyright Steven Watanabe 2011
Chris@16 4 * Distributed under the Boost Software License, Version 1.0. (See
Chris@16 5 * accompanying file LICENSE_1_0.txt or copy at
Chris@16 6 * http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7 *
Chris@16 8 * See http://www.boost.org for most recent version including documentation.
Chris@16 9 *
Chris@101 10 * $Id$
Chris@16 11 *
Chris@16 12 */
Chris@16 13
Chris@16 14 #ifndef BOOST_RANDOM_DETAIL_INTEGER_LOG2_HPP
Chris@16 15 #define BOOST_RANDOM_DETAIL_INTEGER_LOG2_HPP
Chris@16 16
Chris@16 17 #include <boost/config.hpp>
Chris@16 18 #include <boost/limits.hpp>
Chris@16 19 #include <boost/pending/integer_log2.hpp>
Chris@16 20
Chris@16 21 namespace boost {
Chris@16 22 namespace random {
Chris@16 23 namespace detail {
Chris@16 24
Chris@16 25 #if !defined(BOOST_NO_CXX11_CONSTEXPR)
Chris@16 26 #define BOOST_RANDOM_DETAIL_CONSTEXPR constexpr
Chris@16 27 #elif defined(BOOST_MSVC)
Chris@16 28 #define BOOST_RANDOM_DETAIL_CONSTEXPR __forceinline
Chris@16 29 #elif defined(__GNUC__) && __GNUC__ >= 4
Chris@101 30 #define BOOST_RANDOM_DETAIL_CONSTEXPR inline __attribute__((__const__)) __attribute__((__always_inline__))
Chris@16 31 #else
Chris@16 32 #define BOOST_RANDOM_DETAIL_CONSTEXPR inline
Chris@16 33 #endif
Chris@16 34
Chris@16 35 template<int Shift>
Chris@16 36 struct integer_log2_impl
Chris@16 37 {
Chris@16 38 #if defined(BOOST_NO_CXX11_CONSTEXPR)
Chris@16 39 template<class T>
Chris@16 40 BOOST_RANDOM_DETAIL_CONSTEXPR static int apply(T t, int accum)
Chris@16 41 {
Chris@16 42 int update = ((t >> Shift) != 0) * Shift;
Chris@16 43 return integer_log2_impl<Shift / 2>::apply(t >> update, accum + update);
Chris@16 44 }
Chris@16 45 #else
Chris@16 46 template<class T>
Chris@16 47 BOOST_RANDOM_DETAIL_CONSTEXPR static int apply2(T t, int accum, int update)
Chris@16 48 {
Chris@16 49 return integer_log2_impl<Shift / 2>::apply(t >> update, accum + update);
Chris@16 50 }
Chris@16 51
Chris@16 52 template<class T>
Chris@16 53 BOOST_RANDOM_DETAIL_CONSTEXPR static int apply(T t, int accum)
Chris@16 54 {
Chris@16 55 return apply2(t, accum, ((t >> Shift) != 0) * Shift);
Chris@16 56 }
Chris@16 57 #endif
Chris@16 58 };
Chris@16 59
Chris@16 60 template<>
Chris@16 61 struct integer_log2_impl<1>
Chris@16 62 {
Chris@16 63 template<class T>
Chris@16 64 BOOST_RANDOM_DETAIL_CONSTEXPR static int apply(T t, int accum)
Chris@16 65 {
Chris@16 66 return int(t >> 1) + accum;
Chris@16 67 }
Chris@16 68 };
Chris@16 69
Chris@16 70 template<class T>
Chris@16 71 BOOST_RANDOM_DETAIL_CONSTEXPR int integer_log2(T t)
Chris@16 72 {
Chris@16 73 return integer_log2_impl<
Chris@16 74 ::boost::detail::max_pow2_less<
Chris@16 75 ::std::numeric_limits<T>::digits, 4
Chris@16 76 >::value
Chris@16 77 >::apply(t, 0);
Chris@16 78 }
Chris@16 79
Chris@16 80 } // namespace detail
Chris@16 81 } // namespace random
Chris@16 82 } // namespace boost
Chris@16 83
Chris@16 84 #endif // BOOST_RANDOM_DETAIL_INTEGER_LOG2_HPP