Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64177 - in sandbox/SOC/2010/bit_masks: boost/integer/detail/bft lib/integer/test/bft_testing
From: bbartmanboost_at_[hidden]
Date: 2010-07-19 16:58:17


Author: bbartman
Date: 2010-07-19 16:58:16 EDT (Mon, 19 Jul 2010)
New Revision: 64177
URL: http://svn.boost.org/trac/boost/changeset/64177

Log:
working on completing the work for pointer member of bitfield_tuple
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parse_impl.hpp | 26 ++++
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_packing_policy.hpp | 192 ++++++++++++++++++++++++++++++++++-----
   sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/pointer_member_test.cpp | 50 ++++++++++
   3 files changed, 239 insertions(+), 29 deletions(-)

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-19 16:58:16 EDT (Mon, 19 Jul 2010)
@@ -15,6 +15,7 @@
 #include <boost/mpl/find_if.hpp>
 #include <boost/mpl/placeholders.hpp>
 #include <boost/mpl/comparison.hpp>
+#include <boost/mpl/logical.hpp>
 #include <boost/type_traits/add_pointer.hpp>
 
 
@@ -392,6 +393,10 @@
      * to the first 1 within the mask provided.
      */
 
+ // PRECONDTION: type of mask::value_type must be the same size as a pointer.
+ BOOST_STATIC_ASSERT(( sizeof(typename Mask::value_type) == sizeof(void*) ));
+
+
     typedef typename pointer_member::count_leading_zeros<
         Mask>::type front_storage_space;
 
@@ -416,7 +421,7 @@
         (back_storage_space + front_storage_space)
         
 */
-
+
 
     // Logic for determining how to actually store the pointer.
     typedef typename mpl::if_c<front_storage_space::value == 0,
@@ -456,8 +461,23 @@
     // if the offset is greater then then number of storage bits
     // the this pointer is not going to be aligned within storage.
     typedef typename mpl::if_<
- mpl::greater<Offset, front_storage_space>,
- mpl::false_,
+ mpl::greater<
+ Offset,
+ front_storage_space
+ >,
+ typename mpl::if_<
+ mpl::and_<
+ mpl::not_<
+ uses_front_storage
+ >,
+ integral_constant<
+ bool,
+ (Offset::value == 32)
+ >
+ >,
+ mpl::true_,
+ mpl::false_
+ >::type,
         mpl::true_
>::type is_aligned;
 

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-19 16:58:16 EDT (Mon, 19 Jul 2010)
@@ -15,8 +15,160 @@
 struct none;
 
 } // end bit_shift
+// detial's relating to the set and get functions.
+namespace policy_detail {
+
+/** This is specialization deffered because I can't do it completly until this
+ * pointer because I don't have all the infromation so its easiest to do it
+ * here.
+ */
+template <
+ typename Mask,
+ typename Offset,
+ typename ValueType,
+ typename StorageType,
+ bool
+>
+struct apply_impl_no_shift;
+
+
+/** 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 > {
+
+ typedef Mask get_mask;
+ typedef integral_constant<
+ typename get_mask::value_type,
+ ~get_mask::value
+ > set_mask;
+ typedef ValueType value_type;
+ typedef StorageType storage_type;
+
+ static value_type get(storage_type storage ) {
+ return value_type(storage & get_mask::value);
+ }
+
+ static storage_type set(storage_type storage, value_type ptr) {
+ return storage_type(
+ (storage & set_mask::value)
+ |
+ (typename get_mask::value_type(ptr) & get_mask::value)
+ );
+ }
+};
 
 
+/** This specialization is for systems whichs support interal types
+ * larger then their pointer type OR in other words the storage type is larger
+ * 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 > {
+ 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<
+ bit_width<storage_type>::value - bit_width<typename mask::value_type>::value
+ > shift_amount;
+
+ typedef typename mpl::shift_left<
+ integral_constant<
+ typename make_unsigned<storage_type>::type,
+ mask::value
+ >,
+ 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) >> shift_amount::value) ;
+ }
+
+ static storage_type set(storage_type storage, value_type ptr) {
+ return storage_type(
+ (storage & set_mask::value)
+ |
+ (typename get_mask::value_type(ptr) & Mask::value) << shift_amount::value
+ );
+ }
+};
+
+
+/** This specialization is for systems whichs support interal types
+ * larger then their pointer type OR in other words the storage type is larger
+ * then the type of the mask. This specialization is for pointers which are
+ * aligned to a 32 bit boundry meaning they can be accessed in the same number
+ * 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 > {
+
+ typedef integral_constant<unsigned long long, Mask::value> get_mask;
+ typedef integral_constant<
+ unsigned long long,
+ ~ get_mask::value
+ > set_mask;
+ typedef ValueType value_type;
+ typedef long long storage_type;
+
+ static value_type get(storage_type storage ) {
+ return value_type(storage & get_mask::value);
+ }
+
+ static storage_type set(storage_type storage, value_type ptr) {
+ return storage_type(
+ (storage & set_mask::value)
+ |
+ (typename get_mask::value_type(ptr) & Mask::value)
+ );
+ }
+};
+
+/** This specialization is for systems whichs support interal types
+ * larger then their pointer type OR in other words the storage type is larger
+ * then the type of the mask. This specialization is for pointers which are
+ * aligned to a 32 bit boundry meaning they can be accessed in the same number
+ * 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,
+ unsigned long long,
+ false
+> {
+ typedef integral_constant<unsigned long long, Mask::value> get_mask;
+ typedef integral_constant<
+ unsigned long long,
+ ~get_mask::value
+ > set_mask;
+ typedef ValueType value_type;
+ typedef unsigned long long storage_type;
+
+ static value_type get(storage_type storage ) {
+ return value_type(storage & get_mask::value);
+ }
+
+ static storage_type set(storage_type storage, value_type ptr) {
+ return storage_type(
+ (storage & set_mask::value)
+ |
+ (typename get_mask::value_type(ptr) & Mask::value)
+ );
+ }
+};
+
+} // end policy_detail
+
 /** Only specilization exist for no shift and shift right however
  * that doesn't mean that in the future this can't be adapted for preform
  * left shift on the pointer.
@@ -45,41 +197,31 @@
     Width,
     mpl::true_,
     bit_shift::none
->
- {
+> {
 
- /** Masks for retrieving the value and setting the value of the storage.*/
- //@{
- typedef Mask get_mask;
- typedef integral_constant<
- typename get_mask::value_type,
- ~get_mask::value
- > set_mask;
- //@}
 
- typedef Offset offset;
- typedef Width width;
+ typedef Mask mask;
     typedef ValueType value_type;
 
     template <typename StorageType>
- struct apply {
- typedef StorageType storage_type;
+ struct apply
+ :policy_detail::apply_impl_no_shift<
+ Mask,
+ Offset,
+ ValueType,
+ StorageType,
+ sizeof(StorageType) == sizeof(typename mask::value_type)
+ > {
+#if 0
 
- static value_type get(storage_type storage ) {
- return value_type(storage & get_mask::value);
- }
 
- static storage_type set(storage_type storage, value_type ptr) {
- return storage_type(
- (storage & set_mask::value)
- |
- (typename get_mask::value_type(ptr) & get_mask::value)
- );
- }
+#endif
     };
-
 };
 
+
+
+
 /** Specilization for when the pointer is shifted left. */
 template <
     typename Mask,

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-19 16:58:16 EDT (Mon, 19 Jul 2010)
@@ -15,7 +15,31 @@
 
 typedef bitfield_tuple< pointer<int, rd> > test_type_1;
 typedef bitfield_tuple< pointer<int, rd>, flag<b1>, flag<b2> > test_type_2;
-// typedef bitfield_tuple< member<int*,rd, bit_width<int*>::value - 2> > test_type_2;
+// this is first half long long
+typedef bitfield_tuple<
+ storage<long long>,
+ pointer<int, rd>,
+ flag<b1>,
+ flag<b2>
+> test_type_3;
+
+// This is second half long long
+// note this only works on 32 bit systems Need to remove this from the test
+// in the event that its being test on a 64 bit architecture
+typedef bitfield_tuple<
+ storage<long long>,
+ member<int, short, 32>,
+ pointer<int, rd>,
+ flag<b1>,
+ flag<b2>
+> test_type_4;
+typedef bitfield_tuple<
+ storage<unsigned long long>,
+ member<int, short, 32>,
+ pointer<int, rd>,
+ flag<b1>,
+ flag<b2>
+> test_type_5;
 
 int main() {
     {
@@ -46,5 +70,29 @@
     BOOST_TEST(t2.get<b2>() );
     
     }
+ // NOTE this test may fail on 64 bit machines but I need to test it
+ // either way.
+ {
+ test_type_3 t3;
+ int i = 30;
+ t3.get<rd>() = &i;
+ BOOST_TEST(*t3.get<rd>() == 30 );
+ }
+
+ // this test will also fail on 64 bit machines.
+ {
+ test_type_4 t4;
+ int i = 70;
+ t4.get<rd>() = &i;
+ BOOST_TEST( *t4.get<rd>() == 70 );
+ }
+
+ // this test will also fail on 64 bit machines.
+ {
+ test_type_5 t5;
+ int i = 70;
+ t5.get<rd>() = &i;
+ BOOST_TEST( *t5.get<rd>() == 70 );
+ }
     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