|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r64734 - 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 18:25:01
Author: bbartman
Date: 2010-08-10 18:25:00 EDT (Tue, 10 Aug 2010)
New Revision: 64734
URL: http://svn.boost.org/trac/boost/changeset/64734
Log:
all courner cases tested and now working for bitfield_vector
Text files modified:
sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp | 108 +++++++++++++------
sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/proxy_reference_test.cpp | 218 ++++++++++++++++++++++++---------------
sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/test_utility.hpp | 8 +
3 files changed, 210 insertions(+), 124 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 18:25:00 EDT (Tue, 10 Aug 2010)
@@ -184,22 +184,48 @@
/** Implicit Conversion Operator*/
operator value_type() const {
if(_mask._size == 1) {
+ // std::cout << "mask size_one decoding" << std::endl;
return (value_type( _mask._first_byte & *_ptr ) >>
- (8 - (_mask._offset + width)));
+ _mask._last_shift);
}
value_type ret = 0;
storage_ptr_t byte_ptr = _ptr;
if(_mask._size == 2) {
- ret = value_type(_mask._first_byte & *byte_ptr) <<
- _mask._last_shift;
+ std::cout << "Byte pointer informantion" << std::endl;
+ std::cout << std::hex << "First byte: " << std::size_t(*byte_ptr) << std::endl;
+ ++byte_ptr;
+ std::cout << std::hex << "second byte: " << std::size_t(*byte_ptr) << std::endl;
+ byte_ptr = _ptr;
+ // getting first bits.
+ ret = value_type(_mask._first_byte & *byte_ptr) << ( 8 - _mask._last_shift );
+ // std::cout << "value of ret(Retrieved data from first mask):" << to_binary_2(ret) << std::endl;
++byte_ptr;
- ret += value_type( _mask._last_byte & *byte_ptr) >>
- (8 - _mask._last_shift);
- if( _mask._last_byte != 0xFF) {
- ret >>= _mask._last_shift - 1;
+ //std::cout << "Value returned from mask applied to last byte: " << to_binary_2(value_type( _mask._last_byte & *byte_ptr) >>
+ // (8 - _mask._last_shift)) << std::endl;
+
+ //std::cout << "Mask to be applied to storage: " << to_binary_2(value_type( _mask._last_byte))<<std::endl;
+ // std::cout << "Value of last byte: " << to_binary_2(*byte_ptr) << std::endl;
+ value_type retrieved_value;
+
+ // std::cout << "value of ret(Added data from second mask): " << to_binary_2(ret) << std::endl;
+ // std::cout << ret << std::endl;
+ if( _mask._last_byte == 0xFF) {
+ // std::cout <<"helllooooo"<< std::endl;
+ // std::cout << std::hex << "ret entering loop: " << ret << std::endl;
+ ret <<= 8;
+ // std::cout << std::hex << "ret after shift: " << ret << std::endl;
+ // std::cout << std::hex << "second byte: " << std::size_t(*byte_ptr) << std::endl;
+ ret += value_type(*byte_ptr);
+ // std::cout << std::hex << "ref after value added to it: " << ret << std::endl;
+ }else{
+ retrieved_value = (value_type( _mask._last_byte) & value_type(*byte_ptr));
+ // std::cout << "value returned from applying mask to pointer pre-shift: " << to_binary_2(retrieved_value) << std::endl;
+ retrieved_value >>= _mask._last_shift;
+ // std::cout << "value of ret(preformed last shift): " << to_binary_2(ret) << std::endl;
+ ret += retrieved_value;
}
return ret;
}
@@ -217,9 +243,13 @@
++byte_ptr;
}
// shifting bits
-
- ret <<= 8 - _mask._last_shift;
- ret += value_type( *byte_ptr & _mask._last_byte ) >> ( _mask._last_shift);
+ if(_mask._last_byte == 0xFF) {
+ ret <<= 8;
+ ret += value_type(*byte_ptr & _mask._last_byte);
+ }else{
+ ret <<= 8 - _mask._last_shift;
+ ret += value_type( *byte_ptr & _mask._last_byte ) >> ( _mask._last_shift);
+ }
return ret;
}
@@ -228,7 +258,6 @@
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;
@@ -241,20 +270,10 @@
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);
- // 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;
+ << (width - bits_in_mask);
+ to_be_stored = storage_t((mask&x)>>(width - bits_in_mask));
*byte_ptr = ((*byte_ptr) & (~_mask._first_byte)) | to_be_stored;
++byte_ptr;
@@ -264,6 +283,7 @@
*byte_ptr = (*byte_ptr & ~_mask._last_byte) | to_be_stored;
return *this;
}
+ std::size_t touch_bytes = 0;
// calculate the offset of the first bit within x
// and creating a mask to extract the fist bits from within x
bits_in_mask = 8 - _mask._offset;
@@ -271,33 +291,47 @@
mask <<= width - bits_in_mask;
typedef unsigned long long ullt;
- std::cout << "First byte value: " << std::hex <<
- ullt(_mask._first_byte) << std::endl;
- std::cout << "First mask value: " << std::hex <<
- ullt(mask) << std::endl;
+ //std::cout << "First byte value: " << std::hex <<
+ // ullt(_mask._first_byte) << std::endl;
+ //std::cout << "First mask value: " << std::hex <<
+ // ullt(mask) << std::endl;
// store first byte.
*byte_ptr = (*byte_ptr & ~_mask._first_byte) | ((x & mask ) >> (width - bits_in_mask));
- std::cout << "stored value 1: " << std::hex <<
- ullt(*byte_ptr) << std::endl;
+ // std::cout << "stored value 1: " << std::hex <<
+ // ullt(*byte_ptr) << std::endl;
++byte_ptr;
+ touch_bytes +=1;
mask = 0xFF;
mask <<= width - bits_in_mask - 8;
- std::cout << "mask before loop: " << std::hex <<
- ullt(mask) << std::endl;
+ // std::cout << "mask before loop: " << std::hex <<
+ // ullt(mask) << std::endl;
for(std::size_t index = 0; index < _mask._size - 2;++index) {
*byte_ptr = (mask & x) >> (width - (bits_in_mask + (8 * index))- 8);
- std::cout << "right shift in size of loop:"<<(width - (bits_in_mask + (8 * index) ) - 8)<<std::endl;
+ // std::cout << "right shift in size of loop:"<<(width - (bits_in_mask + (8 * index) ) - 8)<<std::endl;
mask >>= 8;
++byte_ptr;
+ touch_bytes +=1;
}
// now calculating the last bytes information, retrieving it and then
// storing the data within the array.
- mask = _mask._last_byte >> _mask._last_shift;
- std::cout << "last value of mask: " << std::hex <<
- ullt(mask) << std::endl;
- *byte_ptr = (*byte_ptr & ~_mask._last_byte) |
- ((mask & x) << (_mask._last_shift));
+ // std::cout << "last value of mask: " << std::hex <<
+ // ullt(mask) << std::endl;
+
+ // std::cout << "Value of storage before value writen: " << std::hex << ullt(*byte_ptr) << std::endl;
+ // std::cout << "Value of x in binary: " << to_binary_2(x) << std::endl;
+ // std::cout << "Value returned from appling mask to x: " << to_binary_2(_mask._last_byte & x) << std::endl;
+ // touch_bytes +=1;
+ if(_mask._last_byte == 0xFF) {
+
+ // std::cout << "Value returned from appling mask to x: " << to_binary_2(_mask._last_byte & x) << std::endl;
+ *byte_ptr = _mask._last_byte & x;
+ }else{
+ mask = _mask._last_byte >> _mask._last_shift;
+ *byte_ptr = (*byte_ptr & ~_mask._last_byte) |
+ ((mask & x) << (_mask._last_shift));
+ }
+ // std::cout << "Value of storage after value writen: " << std::hex << ullt(*byte_ptr) << std::endl;
return *this;
}
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 18:25:00 EDT (Tue, 10 Aug 2010)
@@ -27,7 +27,7 @@
typedef proxy_reference_type<long long, 17> test_type_9;
typedef proxy_reference_type<long long, 50> test_type_10;
-
+bool display_debug = false;
/*
test_type_1;
test_type_2;
@@ -164,15 +164,17 @@
std::cout << "-----------------------------------------" << std::endl;
std::cout << "2 byte mask. 0x1 and 0xFF" << std::endl;
std::cout << "-----------------------------------------" << std::endl;
+ ptr = storage;
proxy_reference_type<unsigned int, 9> t4(ptr,7);
- std::memset(ptr,0,3);
+ std::memset(ptr,0,5);
*ptr = 0x01;
++ptr;
*ptr = 0xFF;
- --ptr;
+ ptr = storage;
+ print_from_to(ptr,5);
print_type_and_value(t4);
print_mask_details(t4);
- BOOST_TEST(t4 == 0x1FF);
+ BOOST_PRINT_ON_TEST_FAILURE(t4,0x1FF);
// testing multi byte > 2
std::cout << "-----------------------------------------" << std::endl;
@@ -219,8 +221,11 @@
print_type_and_value(t6);
print_mask_details(t6);
typedef unsigned long long ullt;
- BOOST_TEST(t6 == ullt(0xFFFFFFFFFF));
-
+ ullt temp(0);
+ temp = ~temp;
+ temp <<=16;
+ temp >>=16;
+ BOOST_PRINT_ON_TEST_FAILURE(t6,temp);
// testing multi byte > 2 and ending with 0xFF
std::cout << "-----------------------------------------" << std::endl;
@@ -323,6 +328,22 @@
BOOST_TEST(t4 == 17);
}
{
+ display_debug = false;
+#define ASSIGN_MONITOR(P1,P2) \
+ if(display_debug) {\
+ print_mask_details(P1);\
+ std::cout << #P2 << " Binary_value: " << to_binary(P2) << std::endl;\
+ std::cout << #P1 << " = " << #P2 << std::endl;\
+ std::cout << "before: "; \
+ print_storage_for_reference(P1);\
+ }\
+ P1 = P2;\
+ if(display_debug){\
+ std::cout << "after: "; \
+ print_storage_for_reference(P1);\
+ std::cout << std::endl << std::endl;\
+ }
+
std::cout << "-----------------------------------------" << std::endl;
std::cout << "memory corruption testing." << std::endl;
std::cout << "-----------------------------------------" << std::endl
@@ -349,27 +370,37 @@
test_type_1 t7(ptr,2);
test_type_1 t8(ptr,5);
- t1 = 0;
- t2 = 1;
- t3 = 2;
- t4 = 3;
- t5 = 5;
- t6 = 6;
- t7 = 7;
- t8 = 0;
-
- BOOST_PRINT_ON_TEST_FAILURE_2(t1, 1);
- BOOST_PRINT_ON_TEST_FAILURE_2(t2, 2);
- BOOST_PRINT_ON_TEST_FAILURE_2(t3, 3);
- BOOST_PRINT_ON_TEST_FAILURE_2(t4, 4);
- BOOST_PRINT_ON_TEST_FAILURE_2(t5, 5);
- BOOST_PRINT_ON_TEST_FAILURE_2(t6, 6);
- BOOST_PRINT_ON_TEST_FAILURE_2(t7, 7);
- BOOST_PRINT_ON_TEST_FAILURE_2(t8, 0);
+ ASSIGN_MONITOR(t1,0)
+ ASSIGN_MONITOR(t2,1);
+ ASSIGN_MONITOR(t3,2);
+ ASSIGN_MONITOR(t4,3);
+ ASSIGN_MONITOR(t5,4);
+ if(display_debug) {
+ std::cout << "=================================="<< std::endl;
+ print_from_to(storage,4);
+ }
+ ASSIGN_MONITOR(t6,5);
+ if(display_debug) {
+ print_from_to(storage,4);
+ std::cout << "=================================="<< std::endl;
+ std::cout << std::endl<< std::endl;
+ }
+ ASSIGN_MONITOR(t7,6);
+ ASSIGN_MONITOR(t8,7);
+
+ BOOST_PRINT_ON_TEST_FAILURE_2(t1, 0);
+ BOOST_PRINT_ON_TEST_FAILURE_2(t2, 1);
+ BOOST_PRINT_ON_TEST_FAILURE_2(t3, 2);
+ BOOST_PRINT_ON_TEST_FAILURE_2(t4, 3);
+ BOOST_PRINT_ON_TEST_FAILURE_2(t5, 4);
+ BOOST_PRINT_ON_TEST_FAILURE_2(t6, 5);
+ BOOST_PRINT_ON_TEST_FAILURE_2(t7, 6);
+ BOOST_PRINT_ON_TEST_FAILURE_2(t8, 7);
}
{
+ display_debug = false;
std::cout << "-----------------------------------------" << std::endl;
std::cout << " Testing type: " << typestr<test_type_2>() <<std::endl;
std::cout << "-----------------------------------------" << std::endl;
@@ -393,76 +424,89 @@
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;
- 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);
+ ASSIGN_MONITOR(t1,7)
+ ASSIGN_MONITOR(t2,1);
+ ASSIGN_MONITOR(t3,2);
+ ASSIGN_MONITOR(t4,3);
+ ASSIGN_MONITOR(t5,4);
+ ASSIGN_MONITOR(t6,5);
+ ASSIGN_MONITOR(t7,6);
+ ASSIGN_MONITOR(t8,7);
+
+ BOOST_PRINT_ON_TEST_FAILURE_2(t1, 7);
+ BOOST_PRINT_ON_TEST_FAILURE_2(t2, 1);
+ BOOST_PRINT_ON_TEST_FAILURE_2(t3, 2);
+ BOOST_PRINT_ON_TEST_FAILURE_2(t4, 3);
+ BOOST_PRINT_ON_TEST_FAILURE_2(t5, 4);
+ BOOST_PRINT_ON_TEST_FAILURE_2(t6, 5);
+ BOOST_PRINT_ON_TEST_FAILURE_2(t7, 6);
+ BOOST_PRINT_ON_TEST_FAILURE_2(t8, 7);
- BOOST_PRINT_ON_TEST_FAILURE_2(t1, 1);
- BOOST_PRINT_ON_TEST_FAILURE_2(t2, 2);
- BOOST_PRINT_ON_TEST_FAILURE_2(t3, 3);
- BOOST_PRINT_ON_TEST_FAILURE_2(t4, 4);
- BOOST_PRINT_ON_TEST_FAILURE_2(t5, 5);
- BOOST_PRINT_ON_TEST_FAILURE_2(t6, 6);
- BOOST_PRINT_ON_TEST_FAILURE_2(t7, 7);
- BOOST_PRINT_ON_TEST_FAILURE_2(t8, 9);
+ print_from_to(storage,10);
+ }
+ {
+ display_debug = false;
+ std::cout << "-----------------------------------------" << std::endl;
+ std::cout << " Testing type: " << typestr<test_type_2>() <<std::endl;
+ std::cout << "-----------------------------------------" << std::endl;
+ typedef unsigned char storage_type;
+ typedef storage_type* storage_ptr;
+ storage_type storage[20];
+ storage_ptr ptr = storage;
+ std::memset(ptr,0,20);
+// index | multiple of 17 | byte index | offset
+// 0 17 0 0
+// 1 34 2 1
+// 2 51 4 2
+// 3 68 6 3
+// 4 85 8 4
+// 5 102 10 5
+// 6 119 12 6
+// 7 136 14 7
+
+ test_type_4 t1(ptr,0);
+ ptr += 2;
+ test_type_4 t2(ptr,1);
+ ptr += 2;
+ test_type_4 t3(ptr,2);
+ ptr += 2;
+ test_type_4 t4(ptr,3);
+ ptr += 2;
+ test_type_4 t5(ptr,4);
+ ptr += 2;
+ test_type_4 t6(ptr,5);
+ ptr += 2;
+ test_type_4 t7(ptr,6);
+ ptr += 2;
+ test_type_4 t8(ptr,7);
+
+
+ t1 = 30204;
+ t2 = 14140;
+ t3 = 59713;
+ t4 = 60100;
+ t5 = 99999;
+ t6 = 10210;
+ t7 = 41740;
+ t8 = 10129;
+ BOOST_PRINT_ON_TEST_FAILURE_3(t1, 30204);
+ BOOST_PRINT_ON_TEST_FAILURE_3(t2, 14140);
+ BOOST_PRINT_ON_TEST_FAILURE_3(t3, 59713);
+ BOOST_PRINT_ON_TEST_FAILURE_3(t4, 60100);
+ BOOST_PRINT_ON_TEST_FAILURE_3(t5, 99999);
+ BOOST_PRINT_ON_TEST_FAILURE_3(t6, 10210);
+ BOOST_PRINT_ON_TEST_FAILURE_3(t7, 41740);
+ BOOST_PRINT_ON_TEST_FAILURE_3(t8, 10129);
+ unsigned long long temp = t8;
+ std::cout << to_binary(temp) << std::endl;
+ // 0 0000 10011 1100 10001
+ print_storage_for_reference(t8);
+ print_from_to(storage,17);
/*
typedef proxy_reference_type<unsigned int, 3> test_type_1;
typedef proxy_reference_type<unsigned char, 7> test_type_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 18:25:00 EDT (Tue, 10 Aug 2010)
@@ -57,6 +57,14 @@
BOOST_TEST( P1 == P2);
+#define BOOST_PRINT_ON_TEST_FAILURE_3(P1, P2) \
+ if(P1 != P2 ) { \
+ std::cout << #P1 << ": " << std::dec << std::size_t(P1) << std::endl; \
+ std::cout << #P2 << ": " << std::dec << std::size_t(P2) << std::endl; \
+ print_mask_details(P1);\
+ }\
+ BOOST_TEST( P1 == P2);
+
struct print_mpl_values {
template<typename T>
void operator()(T x) {
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