Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64155 - in sandbox/SOC/2010/bits_and_ints: boost/integer libs/integer/test
From: muriloufg_at_[hidden]
Date: 2010-07-19 09:01:10


Author: murilov
Date: 2010-07-19 09:01:08 EDT (Mon, 19 Jul 2010)
New Revision: 64155
URL: http://svn.boost.org/trac/boost/changeset/64155

Log:
Added 'Increment Reversed Integer function':
- inc_rev() runtime function in boost/integer/inc_rev.hpp
- static_inc_rev<> and mpl::inc_rev<> metafunctions under boost/integer/static_inc_rev.hpp file
Implemented is_unsigned_constant<> in boost/integer/is_unsigned.hpp
Added:
   sandbox/SOC/2010/bits_and_ints/boost/integer/inc_rev.hpp (contents, props changed)
   sandbox/SOC/2010/bits_and_ints/boost/integer/static_inc_rev.hpp (contents, props changed)
   sandbox/SOC/2010/bits_and_ints/libs/integer/test/inc_rev_test.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2010/bits_and_ints/boost/integer/count_leading_zeros.hpp | 34 +++++++++++++++++++++++++++++++---
   sandbox/SOC/2010/bits_and_ints/boost/integer/ilog2.hpp | 10 +++++-----
   sandbox/SOC/2010/bits_and_ints/boost/integer/is_integral_constant.hpp | 17 ++++++++++-------
   sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 | 1 +
   sandbox/SOC/2010/bits_and_ints/libs/integer/test/ilog2_test.cpp | 2 +-
   5 files changed, 48 insertions(+), 16 deletions(-)

Modified: sandbox/SOC/2010/bits_and_ints/boost/integer/count_leading_zeros.hpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/boost/integer/count_leading_zeros.hpp (original)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/count_leading_zeros.hpp 2010-07-19 09:01:08 EDT (Mon, 19 Jul 2010)
@@ -30,25 +30,53 @@
 #ifdef __GNUC__
 
 template <typename T>
-inline int count_leading_zeros(T value)
+inline int unchecked_count_leading_zeros(T value)
 {
         return __builtin_clz(value) - (32 - (sizeof(T) << 3));
 }
+
+template <typename T>
+inline int count_leading_zeros(T value)
+{
+ return (value != 0) ?
+ __builtin_clz(value) - (32 - (sizeof(T) << 3)) : -1;
+}
 
+inline int unchecked_count_leading_zeros(unsigned int value)
+{
+ return (value != 0) ?
+ __builtin_clz(value) : -1;
+}
+
 inline int count_leading_zeros(unsigned int value)
 {
         return __builtin_clz(value);
 }
         
-inline int count_leading_zeros(unsigned long int value)
+inline int unchecked_count_leading_zeros(unsigned long int value)
 {
         return __builtin_clzl(value);
 }
+
+inline int count_leading_zeros(unsigned long int value)
+{
+ return (value != 0) ?
+ __builtin_clzl(value) : -1;
+}
 
-inline int count_leading_zeros(unsigned long long int value)
+#ifndef BOOST_HAS_NO_INT64_T
+inline int unchecked_count_leading_zeros(unsigned long long int value)
 {
         return __builtin_clzll(value);
 }
+
+
+inline int count_leading_zeros(unsigned long long int value)
+{
+ return (value != 0) ?
+ __builtin_clzll(value) : -1;
+}
+#endif
 
 #else
 

Modified: sandbox/SOC/2010/bits_and_ints/boost/integer/ilog2.hpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/boost/integer/ilog2.hpp (original)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/ilog2.hpp 2010-07-19 09:01:08 EDT (Mon, 19 Jul 2010)
@@ -1,4 +1,4 @@
-// Boost integer/count_leading_zeros.hpp header file ------------------------------//
+// Boost integer/ilog2.hpp header file ------------------------------//
 
 // (C) Copyright Murilo Adriano Vasconcelos 2010.
 // Distributed under the Boost Software License, Version 1.0. (See
@@ -11,6 +11,7 @@
 #define BOOST_ILOG2_INCLUDED
 
 #include <boost/static_assert.hpp>
+#include <boost/utility/enable_if.hpp>
 #include <boost/type_traits/is_unsigned.hpp>
 #include <boost/integer/count_leading_zeros.hpp>
 
@@ -25,10 +26,9 @@
  * `value` must be unsigned.
  */
 template <typename T>
-inline T ilog2(T value)
-{
- BOOST_STATIC_ASSERT((is_unsigned<T>::value));
-
+inline typename enable_if<is_unsigned<T>, T>::type
+ilog2(T value)
+{
         return (sizeof(T) * 8) - count_leading_zeros(value) - 1;
 }
         

Added: sandbox/SOC/2010/bits_and_ints/boost/integer/inc_rev.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/inc_rev.hpp 2010-07-19 09:01:08 EDT (Mon, 19 Jul 2010)
@@ -0,0 +1,32 @@
+// Boost integer/inc_rev.hpp header file ------------------------------//
+
+// (C) Copyright Murilo Adriano Vasconcelos 2010.
+// 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_INC_REV_INCLUDED
+#define BOOST_INC_REV_INCLUDED
+
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_unsigned.hpp>
+#include <boost/integer/bit_reversal.hpp>
+
+namespace boost
+{
+
+template <typename T>
+inline typename enable_if<is_unsigned<T>, T>::type
+inc_rev(T value)
+{
+ value = bit_reversal(value);
+ ++value;
+
+ return bit_reversal(value);
+}
+
+}
+
+#endif

Modified: sandbox/SOC/2010/bits_and_ints/boost/integer/is_integral_constant.hpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/boost/integer/is_integral_constant.hpp (original)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/is_integral_constant.hpp 2010-07-19 09:01:08 EDT (Mon, 19 Jul 2010)
@@ -14,9 +14,9 @@
 #include <boost/mpl/has_xxx.hpp>
 #include <boost/mpl/and.hpp>
 #include <boost/mpl/integral_c.hpp>
-#include <boost/type_traits/integral_constant.hpp>
-#include <boost/type_traits/is_integral.hpp>
 #include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/is_integral.hpp>
+#include <boost/type_traits/is_unsigned.hpp>
 
 namespace boost {
 
@@ -28,23 +28,26 @@
 
 //~ template <typename IC>
 //~ struct is_integral_constant : false_ {};
-
     
-//~ namespace detail {
 BOOST_MPL_HAS_XXX_TRAIT_DEF(tag)
 BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type)
-//~ BOOST_MPL_HAS_XXX_TRAIT_DEF(value)
 BOOST_MPL_HAS_XXX_TRAIT_DEF(type)
-//~ }
+
 template <typename IC>
 struct is_integral_constant : and_<
                 and_< has_tag<IC>, is_same<typename IC::tag, integral_c_tag> >,
                 and_< has_value_type<IC>, is_integral<typename IC::value_type> >,
- //detail_has_value<IC>,
                 has_type<IC>
>
 {};
 
+template <typename IC>
+struct is_unsigned_constant : and_<
+ is_integral_constant<IC>,
+ is_unsigned<typename IC::value_type>
+>
+{};
+
     
     
 template <typename T, T value>

Added: sandbox/SOC/2010/bits_and_ints/boost/integer/static_inc_rev.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/static_inc_rev.hpp 2010-07-19 09:01:08 EDT (Mon, 19 Jul 2010)
@@ -0,0 +1,40 @@
+// Boost integer/inc_rev.hpp header file ------------------------------//
+
+// (C) Copyright Murilo Adriano Vasconcelos 2010.
+// 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_STATIC_INC_REV_INCLUDED
+#define BOOST_STATIC_INC_REV_INCLUDED
+
+#include <boost/mpl/integral_c.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/integer/is_integral_constant.hpp>
+#include <boost/integer/static_bit_reversal.hpp>
+
+namespace boost
+{
+
+namespace mpl {
+
+template <typename IC, class Enable =
+ typename enable_if< is_unsigned_constant<IC> >::type>
+struct inc_rev : integral_c<typename IC::value_type,
+ bit_reversal<
+ typename next< bit_reversal<IC> >::type
+ >
+>
+{};
+
+}
+
+template <typename T, T Value, class Enable = typename is_unsigned<T>::type>
+struct static_inc_rev : mpl::inc_rev< mpl::integral_c<T, Value> >
+{};
+
+}
+
+#endif

Modified: sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 (original)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 2010-07-19 09:01:08 EDT (Mon, 19 Jul 2010)
@@ -28,6 +28,7 @@
                 [ run isign_test.cpp ]
                 [ run count_leading_zeros_test.cpp ]
                 [ run ilog2_test.cpp ]
+ [ run inc_rev_test.cpp ]
                 [ compile cstdint_include_test.cpp ]
                 [ compile integer_traits_include_test.cpp ]
                 [ compile integer_include_test.cpp ]

Modified: sandbox/SOC/2010/bits_and_ints/libs/integer/test/ilog2_test.cpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/libs/integer/test/ilog2_test.cpp (original)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/ilog2_test.cpp 2010-07-19 09:01:08 EDT (Mon, 19 Jul 2010)
@@ -1,4 +1,4 @@
-// Boost count_leading_zeros_test.hpp test program --------------------------------------//
+// Boost ilog2_test.hpp test program --------------------------------------//
 
 // (C) Copyright Murilo Adriano Vasconcelos 2010.
 // Distributed under the Boost Software License, Version 1.0. (See

Added: sandbox/SOC/2010/bits_and_ints/libs/integer/test/inc_rev_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/inc_rev_test.cpp 2010-07-19 09:01:08 EDT (Mon, 19 Jul 2010)
@@ -0,0 +1,44 @@
+// Boost count_leading_zeros_test.hpp test program --------------------------------------//
+
+// (C) Copyright Murilo Adriano Vasconcelos 2010.
+// 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
+
+
+#include <iostream>
+#include <boost/cstdint.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/integer/inc_rev.hpp>
+
+#define INC_REV_TEST(a, b) \
+BOOST_TEST(a == b)
+
+
+int main()
+{
+ using boost::inc_rev;
+ uint8_t c = 0;
+
+ INC_REV_TEST((c = inc_rev(c)), 128);
+ INC_REV_TEST((c = inc_rev(c)), 64);
+ INC_REV_TEST((c = inc_rev(c)), 192);
+ INC_REV_TEST((c = inc_rev(c)), 32);
+ INC_REV_TEST((c = inc_rev(c)), 160);
+ INC_REV_TEST((c = inc_rev(c)), 96);
+ INC_REV_TEST((c = inc_rev(c)), 224);
+ INC_REV_TEST((c = inc_rev(c)), 16);
+ INC_REV_TEST((c = inc_rev(c)), 144);
+ INC_REV_TEST((c = inc_rev(c)), 80);
+ INC_REV_TEST((c = inc_rev(c)), 208);
+ INC_REV_TEST((c = inc_rev(c)), 48);
+ INC_REV_TEST((c = inc_rev(c)), 176);
+ INC_REV_TEST((c = inc_rev(c)), 112);
+ INC_REV_TEST((c = inc_rev(c)), 240);
+ INC_REV_TEST((c = inc_rev(c)), 8);
+ INC_REV_TEST((c = inc_rev(c)), 136);
+ INC_REV_TEST((c = inc_rev(c)), 72);
+ INC_REV_TEST((c = inc_rev(c)), 200);
+
+ return boost::report_errors();
+}
\ No newline at end of file


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk