Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64725 - in sandbox/SOC/2010/bit_masks: boost/integer/detail/bitfield_vector lib/integer/test/bitfield_vector_testing
From: bbartmanboost_at_[hidden]
Date: 2010-08-10 11:27:20


Author: bbartman
Date: 2010-08-10 11:27:18 EDT (Tue, 10 Aug 2010)
New Revision: 64725
URL: http://svn.boost.org/trac/boost/changeset/64725

Log:
still working on debugging my bitfield_vector proxy_reference_type this has become much harder then originally anticipated.
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp | 34 ++++++++++++++++++---
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/proxy_reference_test.cpp | 61 +++++++++++++++++++++++++++++++++++++--
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/test_utility.hpp | 44 ++++++++++++++++++++++++----
   3 files changed, 122 insertions(+), 17 deletions(-)

Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp 2010-08-10 11:27:18 EDT (Tue, 10 Aug 2010)
@@ -18,9 +18,19 @@
 #include <boost/integer/bit_width.hpp>
 #include <iostream>
 #include <iomanip>
+#include <sstream>
+#include <bitset>
 
 namespace boost { namespace detail {
 
+template <typename T>
+std::string to_binary_2(T x) {
+ std::stringstream ss(std::stringstream::in|std::stringstream::out);
+ ss << std::setfill('0') << std::setw(boost::bit_width<T>::value)
+ << std::bitset< boost::bit_width<T>::value >(x).to_string();
+ return std::string(ss.str());
+}
+
 template <std::size_t Width, bool = bool((Width%8) > 0)>
 struct next_allocation_size;
 
@@ -102,12 +112,12 @@
     //@{
 
     /** Copy Constructor. */
- proxy_reference_type(_self const& x)
+ explicit proxy_reference_type(_self const& x)
         :_ptr(x._ptr), _mask(x._mask )
     { }
 
     /** pointer, offset constructor. */
- proxy_reference_type(storage_type* ptr, offset_type offset)
+ explicit proxy_reference_type(storage_type* ptr, offset_type offset)
         :_ptr(ptr), _mask(get_mask_detail<Width>(offset) )
     { }
     //@}
@@ -152,12 +162,12 @@
     //@{
 
     /** Copy Constructor. */
- proxy_reference_type(_self const& x)
+ explicit proxy_reference_type(_self const& x)
         :_ptr(x._ptr), _mask(x._mask)
     { }
 
     /** pointer, offset constructor. */
- proxy_reference_type(storage_type* ptr, offset_type offset)
+ explicit proxy_reference_type(storage_type* ptr, offset_type offset)
         :_ptr(ptr), _mask(get_mask_detail<Width>(offset))
         
     { }
@@ -218,6 +228,7 @@
         if(_mask._size == 1) {
             storage_t previous_values = *_ptr & ~_mask._first_byte;
             storage_t new_value = low_bits_mask<value_type, width>::value & x;
+
             new_value <<= _mask._last_shift;
             previous_values |= new_value;
             *_ptr = previous_values;
@@ -230,11 +241,22 @@
         storage_ptr_t byte_ptr = _ptr;
 
         if(_mask._size == 2) {
+ // std::cout << "Mask width 2 retrieval" << std::endl;
+ // std::cout << "First Mask" << std::endl;
             bits_in_mask = 8 - _mask._offset;
             mask = (~(~value_type(0) << bits_in_mask))
                 << (width - bits_in_mask - 1);
- to_be_stored = storage_t((mask&x)>>(width - bits_in_mask - 1));
- *byte_ptr = (*byte_ptr & ~_mask._first_byte) | to_be_stored;
+ // std::cout << "Value of x: " << to_binary_2(x) << std::endl;
+ // std::cout << "First extraction mask: " << to_binary_2(mask) << std::endl;
+ // to_be_stored = storage_t((mask&x)>>(width - bits_in_mask - 1));
+ // std::cout << "Value to_be_stored: " << to_binary_2(to_be_stored) << std::endl;
+ // std::cout << "Value at storage location: " << to_binary_2(*byte_ptr) << std::endl;
+ // std::cout << "~_mask._first_byte: " << to_binary_2( _mask._first_byte ) << std::endl;
+ // std::cout << "~_mask._first_byte: " << to_binary_2( ~_mask._first_byte ) << std::endl;
+ // std::cout << "*byte_ptr & (~_mask._first_byte)): " << to_binary_2(*byte_ptr & (~_mask._first_byte) ) << std::endl;
+ // std::cout << "new value to assign to storage location: "<< to_binary_2(storage_t(((*byte_ptr) & (~_mask._first_byte)) | to_be_stored)) << std::endl;
+ *byte_ptr = ((*byte_ptr) & (~_mask._first_byte)) | to_be_stored;
+
             ++byte_ptr;
             bits_in_mask = width - bits_in_mask;
             mask = ~(~value_type(0) << bits_in_mask);

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/proxy_reference_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/proxy_reference_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/proxy_reference_test.cpp 2010-08-10 11:27:18 EDT (Tue, 10 Aug 2010)
@@ -228,7 +228,8 @@
         std::cout << "0 offset" << std::endl;
         std::cout << "-----------------------------------------" << std::endl;
         proxy_reference_type<unsigned long long, 63> t7(ptr,0);
- std::memset(ptr,0,4);
+ std::memset(ptr,0,20);
+
         // 1
         *ptr = 0xFF;
         ++ptr;
@@ -254,6 +255,7 @@
         *ptr = 0xFE;
         ++ptr;
         ptr = storage;
+
         print_type_and_value(t7);
         print_mask_details(t7);
         BOOST_TEST(t7 == 0x7fffffffffffffff );
@@ -333,7 +335,6 @@
         storage_ptr ptr = storage;
         std::memset(ptr,0,20);
 
-
         std::cout << "-----------------------------------------" << std::endl;
         std::cout << " Testing type: " << typestr<test_type_1>() <<std::endl;
         std::cout << "-----------------------------------------" << std::endl;
@@ -380,24 +381,76 @@
 
         test_type_2 t1(ptr,0);
         test_type_2 t2(ptr,7);
+ ++ptr;
         test_type_2 t3(ptr,6);
         ++ptr;
         test_type_2 t4(ptr,5);
+ ++ptr;
         test_type_2 t5(ptr,4);
+ ++ptr;
         test_type_2 t6(ptr,3);
         ++ptr;
         test_type_2 t7(ptr,2);
+ ++ptr;
         test_type_2 t8(ptr,1);
+#define ASSIGN_MONITOR(P1,P2) \
+ std::cout << "before: "; \
+ print_storage_for_reference(P1); \
+ P1 = P2;\
+ std::cout << "after: ";\
+ print_storage_for_reference(P1);\
+ std::cout << std::endl << std::endl;
 
- t1 = 0;
+ ASSIGN_MONITOR(t1,7)
+
+ std::cout << "before: ";
+ print_storage_for_reference(t2);
         t2 = 1;
+ std::cout << "after: ";
+ print_storage_for_reference(t2);
+ std::cout << std::endl << std::endl;
+
+ std::cout << "before: ";
+ print_storage_for_reference(t3);
         t3 = 2;
+ std::cout << "after: ";
+ print_storage_for_reference(t3);
+ std::cout << std::endl << std::endl;
+
+ std::cout << "before: ";
+ print_storage_for_reference(t4);
         t4 = 3;
+ std::cout << "after: ";
+ print_storage_for_reference(t4);
+ std::cout << std::endl << std::endl;
+
+ std::cout << "before: ";
+ print_storage_for_reference(t5);
         t5 = 5;
+ std::cout << "after: ";
+ print_storage_for_reference(t5);
+ std::cout << std::endl << std::endl;
+
+ std::cout << "before: ";
+ print_storage_for_reference(t6);
         t6 = 6;
+ std::cout << "after: ";
+ print_storage_for_reference(t6);
+ std::cout << std::endl << std::endl;
+
+ std::cout << "before: ";
+ print_storage_for_reference(t7);
         t7 = 7;
+ std::cout << "after: ";
+ print_storage_for_reference(t7);
+ std::cout << std::endl << std::endl;
+
+ std::cout << "Before: ";
+ print_storage_for_reference(t8);
         t8 = 9;
-
+ std::cout << "After: ";
+ print_storage_for_reference(t8);
+ // print_from_to(storage, 7);
 
         BOOST_PRINT_ON_TEST_FAILURE_2(t1, 1);
         BOOST_PRINT_ON_TEST_FAILURE_2(t2, 2);

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/test_utility.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/test_utility.hpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/test_utility.hpp 2010-08-10 11:27:18 EDT (Tue, 10 Aug 2010)
@@ -10,6 +10,9 @@
 #include <string>
 #include <typeinfo>
 #include <cstring>
+#include <bitset>
+#include <boost/integer/bit_width.hpp>
+#include <sstream>
 
 #if defined(__GNUC__)
 #include <cxxabi.h>
@@ -69,17 +72,44 @@
 }
 
 template <typename T>
+std::string to_binary(T x) {
+ typedef unsigned long long ullt;
+ std::stringstream ss(std::stringstream::in|std::stringstream::out);
+ ss << std::setfill('0') << std::setw(boost::bit_width<T>::value)
+ << std::bitset< boost::bit_width<T>::value >(ullt(x)).to_string();
+ return std::string(ss.str());
+}
+
+void print_from_to(unsigned char* ptr, std::size_t to) {
+ for(std::size_t i =1;i< to + 1;++i) {
+ std::cout << std::dec << std::setw(8) << i*8 << " ";
+ }
+ std::cout << std::endl;
+
+ for(std::size_t i = 0; i < to; ++i) {
+ std::cout << to_binary(ptr[i]) << " ";
+ }
+ std::cout << std::endl;
+}
+
+template <typename T>
 void print_mask_details( T const& x) {
     typedef unsigned long long ulltype;
     std::cout << "Mask detail for the following class" << std::endl;
     std::cout << "Type: " << typestr<T>() << std::endl;
- std::cout << "Mask Values" << std::endl;
- std::cout << "size:" << x._mask._size << std::endl;
- std::cout << "offset:" << x._mask._offset << std::endl;
- std::cout << "first_byte:" << std::hex << ulltype(x._mask._first_byte) << std::endl;
- std::cout << "last_byte:" << std::hex << ulltype(x._mask._last_byte) << std::endl;
- std::cout << "last_shift:" << x._mask._last_shift << std::endl << std::endl;
-
+ std::cout << "Mask Values " << std::endl;
+ std::cout << "size: " << x._mask._size << std::endl;
+ std::cout << "offset: " << x._mask._offset << std::endl;
+ std::cout << "first_byte: " << std::hex << ulltype(x._mask._first_byte) << std::endl;
+ std::cout << "first_byte in binary: " << to_binary(x._mask._first_byte) << std::endl;
+ std::cout << "last_byte: " << std::hex << ulltype(x._mask._last_byte) << std::endl;
+ std::cout << "last_byte in binary: " << to_binary(x._mask._last_byte) << std::endl;
+ std::cout << "last_shift: " << x._mask._last_shift << std::endl << std::endl;
+}
+template<typename T>
+void print_storage_for_reference(T const& x) {
+ std::cout << "Storage For Reference Type" << std::endl;
+ print_from_to(x._ptr, x._mask._size);
 }
 
 #endif


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