Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64670 - in sandbox/SOC/2010/bit_masks: boost/integer/detail/bitfield_vector lib/integer/test/bitfield_vector_testing
From: bbartmanboost_at_[hidden]
Date: 2010-08-07 14:19:25


Author: bbartman
Date: 2010-08-07 14:19:24 EDT (Sat, 07 Aug 2010)
New Revision: 64670
URL: http://svn.boost.org/trac/boost/changeset/64670

Log:
finishing up most of the compile time components of the mask generation code.
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/mask_creator.hpp | 114 +++++++++++++++++++++++++++++++++++----
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/mask_creator_test.cpp | 86 ++++++++++++++++++++++++++++++
   2 files changed, 188 insertions(+), 12 deletions(-)

Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/mask_creator.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/mask_creator.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/mask_creator.hpp 2010-08-07 14:19:24 EDT (Sat, 07 Aug 2010)
@@ -18,7 +18,8 @@
 #include <boost/mpl/has_key.hpp>
 #include <boost/mpl/vector.hpp>
 #include <boost/mpl/integral_c.hpp>
-#include <boost/integer/high_bits_mask.hpp>
+#include <boost/mpl/push_back.hpp>
+#include <boost/mpl/at.hpp>
 #include <cstddef>
 
 namespace boost { namespace detail {
@@ -102,7 +103,7 @@
 template<std::size_t Offset, std::size_t Width>
 struct calc_last_byte {
     typedef typename mpl::if_c<
- bool(mask_size<mpl::size_t<Offset>,mpl::size_t<Width> >::type::value == 1 ),
+ (mask_size<mpl::size_t<Offset>,mpl::size_t<Width> >::type::value == 1 ),
         mpl::size_t<0>,
         typename mpl::if_c<
             (((Offset + Width)%8) == 0),
@@ -113,8 +114,12 @@
 };
 
 template<std::size_t Offset, std::size_t Width>
-struct calc_last_left_shift {
-
+struct calc_last_shift {
+ typedef typename mpl::if_c<
+ bool(mask_size<mpl::size_t<Offset>,mpl::size_t<Width> >::type::value==1),
+ mpl::size_t<std::size_t(8-(Width + Offset))>,
+ mpl::size_t<std::size_t(8-((Offset+Width)%8))>
+ >::type type;
 };
 
 /** This is responsible for storing information about a perticular
@@ -135,8 +140,10 @@
     );
     BOOST_STATIC_CONSTANT(storage_t,
         first_value = (calc_first_byte<offset,width>::type::value));
- // BOOST_STATIC_CONSTANT( std::size_t,);
- // BOOST_STATIC_CONSTANT( storage_t, (last_value = LastIndexValue);
+ BOOST_STATIC_CONSTANT( std::size_t,
+ last_shift =(calc_last_shift<Offset,Width>::type::value));
+ BOOST_STATIC_CONSTANT( storage_t,
+ last_value = (calc_last_byte<Offset,Width>::type::value));
 };
 
 
@@ -176,21 +183,104 @@
     typedef typename valid_offset_helper<Width>::type type;
 };
 
-
-
 /** This will create some structure which will allow for quick retrieval of a
  * all masks for a perticular width.
  */
 template <std::size_t Width>
 struct create_masks {
     typedef typename determine_vaild_offsets<Width>::type indices;
-/*
- typedef typename mpl::if_<
- has_key<indices,mpl::size_t<0> >::type,
-*/
+
+ typedef typename mpl::push_back<
+ mpl::vector<>,
+ typename mpl::if_<
+ typename mpl::has_key<
+ indices,
+ mpl::size_t<0>
+ >::type,
+ mask_info<0,Width>,
+ mpl::void_*
+ >::type
+ >::type step_0;
+
 
+#define BOOST_BUILD_INDEX_VECTOR( PREVIOUS_STEP,N ) \
+ typedef typename mpl::push_back< \
+ step_##PREVIOUS_STEP, \
+ typename mpl::if_< \
+ typename mpl::has_key< \
+ indices, \
+ mpl::size_t<N> \
+ >::type, \
+ mask_info<N,Width>, \
+ mpl::void_* \
+ >::type \
+ >::type step_##N;
+
+ BOOST_BUILD_INDEX_VECTOR(0,1)
+ BOOST_BUILD_INDEX_VECTOR(1,2)
+ BOOST_BUILD_INDEX_VECTOR(2,3)
+ BOOST_BUILD_INDEX_VECTOR(3,4)
+ BOOST_BUILD_INDEX_VECTOR(4,5)
+ BOOST_BUILD_INDEX_VECTOR(5,6)
+ BOOST_BUILD_INDEX_VECTOR(6,7)
+
+#undef BOOST_BUILD_INDEX_VECTOR
+ typedef step_7 type;
 };
 
+/** This is a type constructed over a single mask_info type and is used to
+ * relay some information between compile time and runtime data structures.
+ */
+struct mask_detail {
+ mask_detail()
+ :_offset(0),
+ _size(0),
+ _last_shift(0),
+ _first_byte(0),
+ _last_byte(0)
+ { }
+
+ mask_detail(mask_detail const& x)
+ :_offset(x._offset),
+ _size(x._size),
+ _last_shift(x._last_shift),
+ _first_byte(x._first_byte),
+ _last_byte(x._last_byte)
+ { }
+
+ template <typename MaskInfo>
+ mask_detail(MaskInfo)
+ :_offset(MaskInfo::offset),
+ _size(MaskInfo::size),
+ _last_shift(MaskInfo::last_shift),
+ _first_byte(MaskInfo::first_value),
+ _last_byte(MaskInfo::last_value)
+ { }
+
+ explicit mask_detail(mpl::void_* )
+ :_offset(0),
+ _size(0),
+ _last_shift(0),
+ _first_byte(0),
+ _last_byte(0)
+ { }
+
+ mask_detail& operator=(mask_detail const& x) {
+ _offset = x._offset;
+ _size = x._size;
+ _last_shift = x._last_shift;
+ _first_byte = x._first_byte;
+ _last_byte = x._last_byte;
+ return *this;
+ }
+
+
+ std::size_t _offset;
+ std::size_t _size;
+ std::size_t _last_shift;
+ storage_t _first_byte;
+ storage_t _last_byte;
+};
 
 }} // end booss::detail
 #endif

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/mask_creator_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/mask_creator_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/mask_creator_test.cpp 2010-08-07 14:19:24 EDT (Sat, 07 Aug 2010)
@@ -7,9 +7,38 @@
 #include <boost/integer/detail/bitfield_vector/mask_creator.hpp>
 #include <boost/detail/lightweight_test.hpp>
 #include <boost/mpl/for_each.hpp>
+#include <boost/type_traits/is_same.hpp>
+
+#include <string>
+
+#include <typeinfo>
+
 #include <iostream>
 #include <iomanip>
 
+#if defined(__GNUC__)
+#include <cstring>
+#include <cxxabi.h>
+#endif
+
+template <typename T>
+std::string typestr() {
+#if defined(__GNUC__)
+ std::size_t const BUFSIZE = 8192;
+ std::size_t n = BUFSIZE;
+ char buf[BUFSIZE];
+ abi::__cxa_demangle(typeid(T).name(), buf, &n, 0);
+ return std::string(buf, ::strlen(buf));
+#else
+ return std::string(typeid(T).name());
+#endif
+}
+
+template <typename T>
+inline std::string typestr(T const&)
+{ return typestr<T>(); }
+
+
 #define BOOST_PRINT_ON_TEST_FAILURE(P1, P2) \
     if(P1 != P2 ) { \
         std::cout << #P1 << ": " << std::hex << std::size_t(P1) << std::endl; \
@@ -17,6 +46,10 @@
     }\
     BOOST_TEST( P1 == P2);
 
+
+
+
+
 struct print_set {
     template<typename T>
     void operator()(T x) {
@@ -113,5 +146,58 @@
         BOOST_PRINT_ON_TEST_FAILURE((calc_last_byte<6,50>::type::value), 0xFF );
         BOOST_PRINT_ON_TEST_FAILURE((calc_last_byte<0,50>::type::value), 0xC0);
     }
+
+ // testing calc_last_shift
+ {
+ BOOST_PRINT_ON_TEST_FAILURE((calc_last_shift<7,3>::type::value), 6);
+ BOOST_PRINT_ON_TEST_FAILURE((calc_last_shift<2,3>::type::value), 3);
+ BOOST_PRINT_ON_TEST_FAILURE((calc_last_shift<6,3>::type::value), 7);
+ BOOST_PRINT_ON_TEST_FAILURE((calc_last_shift<0,3>::type::value), 5);
+ BOOST_PRINT_ON_TEST_FAILURE((calc_last_shift<6,50>::type::value), 8);
+ BOOST_PRINT_ON_TEST_FAILURE((calc_last_shift<0,50>::type::value), 6);
+ }
+
+ // testing mask_info
+ {
+
+ BOOST_PRINT_ON_TEST_FAILURE((mask_info<7,3>::offset), 7);
+ BOOST_PRINT_ON_TEST_FAILURE((mask_info<7,3>::width), 3);
+ BOOST_PRINT_ON_TEST_FAILURE((mask_info<7,3>::size), 2);
+ BOOST_PRINT_ON_TEST_FAILURE((mask_info<7,3>::first_value), 0x1);
+ BOOST_PRINT_ON_TEST_FAILURE((mask_info<7,3>::last_value), 0xC0);
+ BOOST_PRINT_ON_TEST_FAILURE((mask_info<7,3>::last_shift), 6);
+
+ }
+ // testing create_masks
+ {
+
+ using namespace boost;
+ typedef create_masks<3>::type mask_vector;
+
+ BOOST_TEST(( is_same<
+ mpl::at< mask_vector, mpl::size_t<0> >::type,
+ mask_info<0,3> >::value ));
+ BOOST_TEST(( is_same<
+ mpl::at< mask_vector, mpl::size_t<1> >::type,
+ mask_info<1,3> >::value ));
+ BOOST_TEST(( is_same<
+ mpl::at< mask_vector, mpl::size_t<2> >::type,
+ mask_info<2,3> >::value ));
+ BOOST_TEST(( is_same<
+ mpl::at< mask_vector, mpl::size_t<3> >::type,
+ mask_info<3,3> >::value ));
+ BOOST_TEST(( is_same<
+ mpl::at< mask_vector, mpl::size_t<4> >::type,
+ mask_info<4,3> >::value ));
+ BOOST_TEST(( is_same<
+ mpl::at< mask_vector, mpl::size_t<5> >::type,
+ mask_info<5,3> >::value ));
+ BOOST_TEST(( is_same<
+ mpl::at< mask_vector, mpl::size_t<6> >::type,
+ mask_info<6,3> >::value ));
+ BOOST_TEST(( is_same<
+ mpl::at< mask_vector, mpl::size_t<7> >::type,
+ mask_info<7,3> >::value ));
+ }
     return boost::report_errors();
 }


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