diff --git a/include/boost/integer/integer_mask.hpp b/include/boost/integer/integer_mask.hpp new file mode 100644 index 0000000..30f6340 --- /dev/null +++ b/include/boost/integer/integer_mask.hpp @@ -0,0 +1,93 @@ +// Boost integer/integer_mask.hpp header file ------------------------------// + +// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or +// implied warranty, and with no claim as to its suitability for any purpose. + +// See http://www.boost.org for updates, documentation, and revision history. + +#ifndef BOOST_INTEGER_INTEGER_MASK_HPP +#define BOOST_INTEGER_INTEGER_MASK_HPP + +#include // self include + +#include // for BOOST_STATIC_CONSTANT +#include // for boost::uint_t + +#include // for UCHAR_MAX, etc. +#include // for std::size_t + +#include // for std::numeric_limits + + +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::least least; + typedef typename uint_t::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::digits > { \ + typedef std::numeric_limits limits_type; \ + typedef uint_t::least least; \ + typedef uint_t::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 ); \ + } + +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 + +#undef BOOST_LOW_BITS_MASK_SPECIALIZE + + +} // namespace boost + + +#endif // BOOST_INTEGER_INTEGER_MASK_HPP diff --git a/include/boost/integer/static_log2.hpp b/include/boost/integer/static_log2.hpp new file mode 100644 index 0000000..436250e --- /dev/null +++ b/include/boost/integer/static_log2.hpp @@ -0,0 +1,91 @@ +// Boost integer/static_log2.hpp header file -------------------------------// + +// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or +// implied warranty, and with no claim as to its suitability for any purpose. + +// See http://www.boost.org for updates, documentation, and revision history. + +#ifndef BOOST_INTEGER_STATIC_LOG2_HPP +#define BOOST_INTEGER_STATIC_LOG2_HPP + +#include // self include + +#include // for BOOST_STATIC_CONSTANT +#include // for std::numeric_limits + + +namespace boost +{ + + +// Implementation details --------------------------------------------------// + +namespace detail +{ + +// Forward declarations +template < unsigned long Val, int Place = 0, int Index + = std::numeric_limits::digits > + struct static_log2_helper_t; + +template < unsigned long Val, int Place > + struct static_log2_helper_t< Val, Place, 1 >; + +// Recursively build the logarithm by examining the upper bits +template < unsigned long Val, int Place, int Index > +struct static_log2_helper_t +{ +private: + BOOST_STATIC_CONSTANT( int, half_place = Index / 2 ); + BOOST_STATIC_CONSTANT( unsigned long, lower_mask = (1ul << half_place) + - 1ul ); + BOOST_STATIC_CONSTANT( unsigned long, upper_mask = ~lower_mask ); + BOOST_STATIC_CONSTANT( bool, do_shift = (Val & upper_mask) != 0ul ); + + BOOST_STATIC_CONSTANT( unsigned long, new_val = do_shift ? (Val + >> half_place) : Val ); + BOOST_STATIC_CONSTANT( int, new_place = do_shift ? (Place + half_place) + : Place ); + BOOST_STATIC_CONSTANT( int, new_index = Index - half_place ); + + typedef static_log2_helper_t next_step_type; + +public: + BOOST_STATIC_CONSTANT( int, value = next_step_type::value ); + +}; // boost::detail::static_log2_helper_t + +// Non-recursive case +template < unsigned long Val, int Place > +struct static_log2_helper_t< Val, Place, 1 > +{ +public: + BOOST_STATIC_CONSTANT( int, value = Place ); + +}; // boost::detail::static_log2_helper_t + +} // namespace detail + + +// Compile-time log-base-2 evaluator class declaration ---------------------// + +template < unsigned long Value > +struct static_log2 +{ + BOOST_STATIC_CONSTANT( int, value + = detail::static_log2_helper_t::value ); +}; + +template < > +struct static_log2< 0ul > +{ + // The logarithm of zero is undefined. +}; + + +} // namespace boost + + +#endif // BOOST_INTEGER_STATIC_LOG2_HPP diff --git a/include/boost/integer/static_min_max.hpp b/include/boost/integer/static_min_max.hpp new file mode 100644 index 0000000..216a3e3 --- /dev/null +++ b/include/boost/integer/static_min_max.hpp @@ -0,0 +1,56 @@ +// Boost integer/static_min_max.hpp header file ----------------------------// + +// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell +// and distribute this software is granted provided this copyright notice +// appears in all copies. This software is provided "as is" without +// express or implied warranty, and with no claim as to its suitability +// for any purpose. + +// See http://www.boost.org for updates, documentation, and revision history. + +#ifndef BOOST_INTEGER_STATIC_MIN_MAX_HPP +#define BOOST_INTEGER_STATIC_MIN_MAX_HPP + +#include // self include + +#include // for BOOST_STATIC_CONSTANT + + +namespace boost +{ + + +// Compile-time extrema class declarations ---------------------------------// +// Get the minimum or maximum of two values, signed or unsigned. + +template < long Value1, long Value2 > +struct static_signed_min +{ + BOOST_STATIC_CONSTANT( long, value = (Value1 > Value2) ? Value2 : Value1 ); +}; + +template < long Value1, long Value2 > +struct static_signed_max +{ + BOOST_STATIC_CONSTANT( long, value = (Value1 < Value2) ? Value2 : Value1 ); +}; + +template < unsigned long Value1, unsigned long Value2 > +struct static_unsigned_min +{ + BOOST_STATIC_CONSTANT( unsigned long, value + = (Value1 > Value2) ? Value2 : Value1 ); +}; + +template < unsigned long Value1, unsigned long Value2 > +struct static_unsigned_max +{ + BOOST_STATIC_CONSTANT( unsigned long, value + = (Value1 < Value2) ? Value2 : Value1 ); +}; + + +} // namespace boost + + +#endif // BOOST_INTEGER_STATIC_MIN_MAX_HPP