Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64269 - in sandbox/SOC/2010/bit_masks: . boost/integer/bitfield_tuple boost/integer/detail/bft lib/integer/test/bft_testing
From: bbartmanboost_at_[hidden]
Date: 2010-07-22 16:12:21


Author: bbartman
Date: 2010-07-22 16:12:20 EDT (Thu, 22 Jul 2010)
New Revision: 64269
URL: http://svn.boost.org/trac/boost/changeset/64269

Log:
pointer member completed and tested
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple/pointer.hpp | 4
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parse_impl.hpp | 48 +++++++-----
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parsing_meta_functions.hpp | 24 +----
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_packing_policy.hpp | 153 ++++++++++++++++++++++++++++++++-------
   sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/pointer_member_test.cpp | 99 +++++++++++++++++++++++++
   sandbox/SOC/2010/bit_masks/notes.txt | 30 +------
   6 files changed, 262 insertions(+), 96 deletions(-)

Modified: sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple/pointer.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple/pointer.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple/pointer.hpp 2010-07-22 16:12:20 EDT (Thu, 22 Jul 2010)
@@ -27,8 +27,8 @@
     typename ReturnType,
     typename Name,
     typename Mask = high_bits_mask<
- typename ::boost::detail::pointer_member::get_mask_type<ReturnType>::type,
- bit_width< typename ::boost::detail::pointer_member::get_mask_type<ReturnType>::type >::value - 2
+ typename ::boost::detail::ptr_mask_type,
+ bit_width< typename ::boost::detail::ptr_mask_type >::value - 2
>
>
 struct pointer;

Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parse_impl.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parse_impl.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parse_impl.hpp 2010-07-22 16:12:20 EDT (Thu, 22 Jul 2010)
@@ -430,32 +430,38 @@
     typedef typename mpl::if_c<back_storage_space::value == 0,
     mpl::false_,mpl::true_>::type uses_back_storage;
 
- // getting starting position of pointer for storage inside of
- // bitfield_tuples storage.
+ // calculating mask offset, data offset and the offset for the next field.
     typedef typename mpl::if_<
         uses_front_storage,
+ // calculate offset
         typename mpl::if_<
- typename mpl::less<
- front_storage_space,
- Offset
- >::type,
- // the pointer has been pushed because the user has added leading
- // members to the bitfield_tuple greater then the number of bits
- // the mask allows for them to store directly directly within the
- // pointer. This may need to be a precondition that causes failure.
-
- // TODO: REMOVE THIS LATER ITS ONLY HERE FOR THE MOMENT TO CAUSE
- // FAILURE because I don't know how I should implement this part
- // just yet and thinking about it is hurting my head.
- mpl::size_t<sizeof(mpl::void_)>::type,
- typename mpl::minus<front_storage_space, Offset>::type
+ mpl::less_equal<
+ Offset,
+ front_storage_space
+ >,
+ mpl::size_t<0>,
+ mpl::minus<Offset, front_storage_space>
+ >::type,
+ Offset
+ >::type mask_offset;
+
+
+ // calculating the offset of the value bits inside of the masks.
+ typedef typename mpl::if_<
+ uses_front_storage,
+ typename mpl::if_<
+ mpl::less_equal<
+ Offset,
+ front_storage_space
+ >,
+ front_storage_space,
+ typename mpl::minus<Offset, front_storage_space>::type
>::type,
         Offset
- >::type data_offset;
+ >::type data_offset;
+
+ typedef typename mpl::plus< Offset, size_of_storage>::type offset;
 
- // calculating next offset/width for the next field.
- typedef typename mpl::plus< size_of_storage, data_offset >::type offset;
-
     typedef bitfields::pointer< ReturnType, Name, Mask > param;
 
     // if the offset is greater then then number of storage bits
@@ -484,7 +490,7 @@
     //
     typedef typename mpl::if_<is_aligned,
         bit_shift::none,
- bit_shift::right< mpl::minus<Offset, front_storage_space>::type::value >
+ bit_shift::right< mpl::minus<Offset,front_storage_space>::type::value>
>::type alignment_shift;
 
     typedef StoragePolicy storage_policy;

Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parsing_meta_functions.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parsing_meta_functions.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parsing_meta_functions.hpp 2010-07-22 16:12:20 EDT (Thu, 22 Jul 2010)
@@ -17,18 +17,14 @@
 /** This file contains metafunctions which are used to do complex operations
  * on the Mask provided by the user.
  */
-namespace boost { namespace detail { namespace pointer_member {
-
-template <typename T>
-struct get_mask_type {
- typedef typename mpl::if_c<
- (4 < sizeof(T*)),
- uint64_t,
- uint32_t
- >::type type;
-};
+namespace boost { namespace detail {
 
+/** This is an integral type which is the same size as a pointer on a 32 or 64
+ * bit system
+ */
+typedef mpl::if_c<(4<sizeof(void*)),uint64_t,uint32_t>::type ptr_mask_type;
 
+namespace pointer_member {
 
 // this is ugly but I would like it for organizational purposes.
 namespace ptr_detail {
@@ -136,14 +132,6 @@
     typedef typename ptr_detail::ctz_helper<Mask>::type type;
 };
 
-
-template <typename Mask, typename Policy>
-struct pointer_member_info {
- typedef Mask mask;
- typedef Policy policy;
-};
-
-
 }}} // end boost::detail::pointer_member
 
 #endif

Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_packing_policy.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_packing_policy.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_packing_policy.hpp 2010-07-22 16:12:20 EDT (Thu, 22 Jul 2010)
@@ -29,14 +29,14 @@
     typename StorageType,
     bool
>
-struct apply_impl_no_shift;
+struct apply_impl;
 
 
 /** Specialization where for the storage type and the size of the mask being
  * the same.
  */
 template <typename Mask, typename Offset, typename ValueType, typename StorageType>
-struct apply_impl_no_shift < Mask, Offset, ValueType, StorageType, true > {
+struct apply_impl < Mask, Offset, ValueType, StorageType, true > {
 
     typedef Mask get_mask;
     typedef integral_constant<
@@ -65,10 +65,11 @@
  * then the type of the mask.
  */
 template <typename Mask, typename Offset, typename ValueType, typename StorageType>
-struct apply_impl_no_shift < Mask, Offset, ValueType, StorageType, false > {
+struct apply_impl < Mask, Offset, ValueType, StorageType, false > {
     typedef ValueType value_type;
     typedef StorageType storage_type;
     typedef Mask mask;
+
     // this is going to be for computers with integral types LARGER then
     // the size of their pointer type.
     typedef mpl::size_t<
@@ -88,7 +89,7 @@
         ~get_mask::value
> set_mask;
 
- static value_type get(storage_type storage ) {
+ static value_type get(storage_type storage) {
         return value_type((storage & get_mask::value) >> shift_amount::value) ;
     }
 
@@ -109,7 +110,7 @@
  * of steps as a 32 bit pointer which is stored within int sized type.
  */
 template <typename Mask, typename ValueType>
-struct apply_impl_no_shift < Mask, mpl::size_t<32>, ValueType, long long, false > {
+struct apply_impl < Mask, mpl::size_t<32>, ValueType, long long, false > {
 
     typedef integral_constant<unsigned long long, Mask::value> get_mask;
     typedef integral_constant<
@@ -139,7 +140,7 @@
  * of steps as a 32 bit pointer which is stored within int sized type.
  */
 template <typename Mask, typename ValueType>
-struct apply_impl_no_shift <
+struct apply_impl <
     Mask,
     mpl::size_t<32>,
     ValueType,
@@ -154,7 +155,7 @@
     typedef ValueType value_type;
     typedef unsigned long long storage_type;
 
- static value_type get(storage_type storage ) {
+ static value_type get(storage_type storage) {
         return value_type(storage & get_mask::value);
     }
 
@@ -167,6 +168,109 @@
     }
 };
 
+template <
+ typename Mask,
+ typename Offset,
+ typename ValueType,
+ typename StorageType,
+ typename MaskShift,
+ bool
+>
+struct apply_shift_impl {
+ typedef Mask mask;
+ typedef Offset offset;
+ typedef ValueType value_type;
+ typedef StorageType storage_type;
+ typedef MaskShift mask_shift_amount;
+
+ typedef typename mpl::shift_right<
+ mask,
+ mask_shift_amount
+ >::type get_mask;
+
+ typedef integral_constant<
+ typename get_mask::value_type,
+ ~get_mask::value
+ > set_mask;
+
+ static value_type get(storage_type storage) {
+ return value_type(
+ (storage & get_mask::value)
+ <<
+ mask_shift_amount::value
+ );
+ }
+
+ static storage_type set(storage_type storage, value_type ptr) {
+ return storage_type(
+ ((typename get_mask::value_type(ptr) & get_mask::value)
+ >>
+ mask_shift_amount::value)
+ |
+ (set_mask::value & storage)
+ );
+ }
+};
+
+template <
+ typename Mask,
+ typename Offset,
+ typename ValueType,
+ typename StorageType,
+ typename MaskShift
+>
+struct apply_shift_impl<Mask,Offset,ValueType,StorageType,MaskShift,false>{
+ typedef Mask mask;
+ typedef Offset offset;
+ typedef ValueType value_type;
+ typedef StorageType storage_type;
+ typedef MaskShift mask_shift_amount;
+
+ // calculating shift for correctly aligning mask
+ // with storage type.
+ typedef typename mpl::minus<
+ typename mpl::minus<
+ bit_width<storage_type>,
+ mask_shift_amount
+ >::type,
+ bit_width<
+ typename mask::value_type
+ >
+ >::type correction_shift_amount;
+
+ typedef typename mpl::shift_left<
+ integral_constant<storage_type, storage_type(mask::value)>,
+ correction_shift_amount
+ >::type get_mask;
+
+ typedef integral_constant<
+ typename get_mask::value_type,
+ typename get_mask::value_type(~get_mask::value)
+ > set_mask;
+
+ static value_type get(storage_type storage ) {
+ return value_type(
+ (storage & get_mask::value)
+ >>
+ correction_shift_amount::value
+ );
+ }
+
+ static storage_type set(storage_type storage, value_type ptr) {
+
+ return storage_type(
+ (storage_type(typename mask::value_type(ptr))
+ <<
+ correction_shift_amount::value)
+ |
+ (set_mask::value & storage)
+ );
+ }
+
+
+};
+
+
 } // end policy_detail
 
 /** Only specilization exist for no shift and shift right however
@@ -198,14 +302,12 @@
     mpl::true_,
     bit_shift::none
> {
-
-
     typedef Mask mask;
     typedef ValueType value_type;
 
     template <typename StorageType>
     struct apply
- :policy_detail::apply_impl_no_shift<
+ :policy_detail::apply_impl<
             Mask,
             Offset,
             ValueType,
@@ -215,9 +317,7 @@
 };
 
 
-
-
-/** Specilization for when the pointer is shifted left. */
+/** Specilization for when the pointer is shifted right. */
 template <
     typename Mask,
     typename ValueType,
@@ -232,25 +332,20 @@
     Width,
     mpl::false_,
     bit_shift::right<ShiftAmount>
->
-{
+> {
     typedef Mask mask;
- typedef Offset offset;
- typedef Width width;
     typedef ValueType value_type;
-
+
     template <typename StorageType>
- struct apply {
- typedef StorageType storage_type;
-
- static value_type get(storage_type storage ) {
- return value_type();
- }
-
- static storage_type set(storage_type storage, value_type ptr) {
- return storage_type();
- }
- };
+ struct apply
+ :policy_detail::apply_shift_impl<
+ Mask,
+ Offset,
+ ValueType,
+ StorageType,
+ mpl::size_t<ShiftAmount>,
+ sizeof(StorageType) == sizeof(typename Mask::value_type)
+ > { };
 
 };
 

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/pointer_member_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/pointer_member_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/pointer_member_test.cpp 2010-07-22 16:12:20 EDT (Thu, 22 Jul 2010)
@@ -6,6 +6,8 @@
 #include <boost/integer/bitfield_tuple.hpp>
 #include <boost/detail/lightweight_test.hpp>
 #include <boost/type_traits/is_same.hpp>
+#include <iostream>
+#include <iomanip>
 
 using namespace boost;
 using namespace boost::bitfields;
@@ -44,6 +46,38 @@
     flag<b2>
> test_type_5;
 #endif
+
+typedef bitfield_tuple<
+ storage<unsigned long long>,
+ filler<2>,
+ pointer<int, rd,
+ bits_mask<
+ detail::ptr_mask_type,
+ 2,
+ bit_width<
+ detail::ptr_mask_type
+ >::value - 4
+ >
+ >,
+ flag<b1>,
+ flag<b2>
+> test_type_6;
+
+typedef bitfield_tuple<
+ storage<unsigned long long>,
+ filler<3>,
+ pointer<int, rd,
+ bits_mask<
+ detail::ptr_mask_type,
+ 2,
+ bit_width<
+ detail::ptr_mask_type
+ >::value - 4
+ >
+ >,
+ flag<b1>,
+ flag<b2>
+> test_type_7;
 int main() {
     {
     test_type_1 t1;
@@ -76,7 +110,7 @@
     // NOTE this test may fail on 64 bit machines but I need to test it
     // either way.
 #if( _LP64 != 1)
- if(sizeof(void*) == 4) {
+ {
         
         test_type_3 t3;
         int i = 30;
@@ -85,7 +119,7 @@
     }
 
     // this test will also fail on 64 bit machines.
- if(sizeof(void*) == 4) {
+ {
         test_type_4 t4;
         int i = 70;
         t4.get<rd>() = &i;
@@ -93,12 +127,71 @@
     }
 
     // this test will also fail on 64 bit machines.
- if(sizeof(void*) == 4) {
+ {
         test_type_5 t5;
         int i = 70;
         t5.get<rd>() = &i;
         BOOST_TEST( *t5.get<rd>() == 70 );
     }
 #endif
+ {
+ test_type_6 t6;
+ int i = 70;
+
+ detail::ptr_mask_type ptr = high_bits_mask<
+ detail::ptr_mask_type,
+ 2
+ >::value
+ &
+ detail::ptr_mask_type(&i);
+
+ std::cout<< "value of &i: " << std::hex << &i << std::endl;
+ std::cout<< "2 bits of &i: " << std::hex << ptr << std::endl;
+
+ t6.get<rd>() = &i;
+
+ int* temp_ptr = t6.get<rd>();
+ std::cout<< "Value of temp_ptr: " << std::hex << temp_ptr << std::endl;
+ detail::ptr_mask_type temp_int = detail::ptr_mask_type(temp_ptr);
+ temp_int |= detail::ptr_mask_type( ptr );
+ typedef int* intptr_t;
+ temp_ptr = intptr_t(temp_int);
+
+ std::cout<< "Value of temp_int: " << std::hex<< temp_int << std::endl;
+ std::cout<< "Value returned from t6.get<rd>(): " << std::hex <<
+ temp_ptr << std::endl;
+
+ BOOST_TEST( * temp_ptr == 70 );
+ }
+ {
+ test_type_7 t7;
+ int i = 70;
+
+ detail::ptr_mask_type ptr = high_bits_mask<
+ detail::ptr_mask_type,
+ 2
+ >::value
+ &
+ detail::ptr_mask_type(&i);
+
+ std::cout<< "value of &i: " << std::hex << &i << std::endl;
+ std::cout<< "2 bits of &i: " << std::hex << ptr << std::endl;
+
+ t7.get<rd>() = &i;
+
+ int* temp_ptr = t7.get<rd>();
+ std::cout<< "Value of temp_ptr: " << std::hex << temp_ptr << std::endl;
+ detail::ptr_mask_type temp_int = detail::ptr_mask_type(temp_ptr);
+ temp_int |= detail::ptr_mask_type( ptr );
+ typedef int* intptr_t;
+ temp_ptr = intptr_t(temp_int);
+
+ std::cout<< "Value of temp_int: " << std::hex<< temp_int << std::endl;
+ std::cout<< "Value returned from t6.get<rd>(): " << std::hex <<
+ temp_ptr << std::endl;
+
+ BOOST_TEST( *temp_ptr == 70 );
+ }
+
     return boost::report_errors();
 }

Modified: sandbox/SOC/2010/bit_masks/notes.txt
==============================================================================
--- sandbox/SOC/2010/bit_masks/notes.txt (original)
+++ sandbox/SOC/2010/bit_masks/notes.txt 2010-07-22 16:12:20 EDT (Thu, 22 Jul 2010)
@@ -13,30 +13,16 @@
     b) Create documentation for how to create your own policy.
     c) This may need additional documentation however it looks good currently.
 
+
 4) pointer_parsing_meta_functions.hpp
- a) think of a better name for this file.
- b) template <typename Mask, typename Policy>
- struct pointer_member_info;
- I ) Do impact analysis for the removal of this structure.
- I don't believe its used or needed any more.
-
- c) template <typename T>
- struct get_mask_type;
- I ) This type needs a new name something like uintptr_t or
- something simple like that.
- II ) This "could" be removed IF there is an unsigned integral type
- which is always the same size as a pointer. There may be
- however I don't know where or what it is currently.
- III ) Consider making this also do short or 16 bit pointers.
- IV ) Why is this a template? I should fix this as a pointer to one
- type is always the same size as another.
+ a) typedef mpl::if_c<(4<sizeof(void*)),uint64_t,uint32_t>::type ptr_mask_type
+ I ) Add support for 16 bit systems. Eventually.
 
- d) Create additional tests for count leading and trailing zero
- meta-functions.
 
 5) pointer_packing_policy.hpp
     a) Adjust the alignment check to check alignment against the 0 bit in stead
         of based on the offset.
+
     b) Change the following specialization so that this isn't needed
         basically this requires a shift from the pointer, when there shouldn't
         be.
@@ -58,17 +44,14 @@
         be all. Unless there there is some issue.
 
 6) name_lookup.hpp
- a) everything is fine here.
-
 7) make_bitfield_tuple.hpp
- a) Everything here has already been fixed.
-
 8) bitfield_tuple_impl.hpp
- a) Everything looks OK here.
+
 
 9) bft_element.hpp
     a) change name to bitfield_element.hpp - eventually.
 
+
 10) arg_parse_impl.hpp
     a) Finish the pointer parsing stuff.
         I ) This includes the pointer shifting stuff as well.
@@ -217,6 +200,7 @@
 --------------------------------------------------------------------------------
 1) !DONE! Add interface test for the interface macros. !DONE!
 2) interface meta-function test suite.
+3) Create additional tests for count leading and trailing zero meta-functions.
 
 --------------------------------------------------------------------------------
 


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