Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62064 - in sandbox/SOC/2010/bit_masks: boost/integer lib/integer/test
From: bbartmanboost_at_[hidden]
Date: 2010-05-17 09:06:25


Author: bbartman
Date: 2010-05-17 09:06:21 EDT (Mon, 17 May 2010)
New Revision: 62064
URL: http://svn.boost.org/trac/boost/changeset/62064

Log:
working on testing runtime support functions for bitwise operators
Added:
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitwise_high_bits_testing.cpp
      - copied, changed from r62063, /sandbox/SOC/2010/bit_masks/lib/integer/test/bitwise_high_bits_test.cpp
Removed:
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitwise_high_bits_test.cpp
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/high_low_bits.hpp | 71 ++++++++++++++++++++++++++++++++++++++++
   sandbox/SOC/2010/bit_masks/lib/integer/test/Jamfile.v2 | 2 +
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitwise_high_bits_testing.cpp | 56 +++++++++++++++++++++++++++++++
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitwise_low_bits_testing.cpp | 56 +++++++++++++++++++++++++++++++
   4 files changed, 185 insertions(+), 0 deletions(-)

Modified: sandbox/SOC/2010/bit_masks/boost/integer/high_low_bits.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/high_low_bits.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/high_low_bits.hpp 2010-05-17 09:06:21 EDT (Mon, 17 May 2010)
@@ -28,6 +28,8 @@
     BOOST_STATIC_CONSTANT(unsigned int, width = Width);
 };
 
+
+
 /** Creates a mask of the supplied width in side type T, from the lower portion
  * of the integer starting from the left most bit moving towards the right.
  */
@@ -42,6 +44,75 @@
 };
 
 
+// Low_bits runtime support functions.
+// Overloads for bitwise and
+template <typename T, unsigned int Width>
+inline T operator&(T t, low_bits<T,Width> ) {
+ return t & low_bits<T,Width>::value;
+}
+
+template <typename T, unsigned int Width>
+inline T operator&(low_bits<T,Width>, T t) {
+ return low_bits<T,Width>::value & t;
+}
+
+// Overloads for bitwise or
+template <typename T, unsigned int Width>
+inline T operator|(T t, low_bits<T,Width>) {
+ return t | low_bits<T,Width>::value;
+}
+
+template <typename T, unsigned int Width>
+inline T operator|(low_bits<T,Width>, T t) {
+ return low_bits<T,Width>::value | t;
+}
+
+// Overloads for bitwise xor
+template <typename T, unsigned int Width>
+inline T operator^(T t, low_bits<T,Width>) {
+ return t ^ low_bits<T,Width>::value;
+}
+
+template <typename T, unsigned int Width>
+inline T operator^(low_bits<T,Width>, T t) {
+ return low_bits<T,Width>::value ^ t;
+}
+
+
+// high_bits runtime support functions.
+// Overloads for bitwise and
+template <typename T, unsigned int Width>
+inline T operator&(T t, high_bits<T,Width> ) {
+ return t & high_bits<T,Width>::value;
+}
+
+template <typename T, unsigned int Width>
+inline T operator&(high_bits<T,Width>, T t) {
+ return high_bits<T,Width>::value & t;
+}
+
+// Overloads for bitwise or
+template <typename T, unsigned int Width>
+inline T operator|(T t, high_bits<T,Width>) {
+ return t | high_bits<T,Width>::value;
+}
+
+template <typename T, unsigned int Width>
+inline T operator|(high_bits<T,Width>, T t) {
+ return high_bits<T,Width>::value | t;
+}
+
+// Overloads for bitwise xor
+template <typename T, unsigned int Width>
+inline T operator^(T t, high_bits<T,Width>) {
+ return t ^ high_bits<T,Width>::value;
+}
+
+template <typename T, unsigned int Width>
+inline T operator^(high_bits<T,Width>, T t) {
+ return high_bits<T,Width>::value ^ t;
+}
+
 
 } // namespace boost
 

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/Jamfile.v2
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/Jamfile.v2 (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/Jamfile.v2 2010-05-17 09:06:21 EDT (Mon, 17 May 2010)
@@ -21,5 +21,7 @@
         [ run bit_width_test.cpp ]
         [ run bitwise_operator_test.cpp ]
         [ run bitwise_integral_mask_testing.cpp ]
+ [ run bitwise_high_bits_testing.cpp ]
+ [ run bitwise_low_bits_testing.cpp ]
     ;
 

Deleted: sandbox/SOC/2010/bit_masks/lib/integer/test/bitwise_high_bits_test.cpp
==============================================================================

Copied: sandbox/SOC/2010/bit_masks/lib/integer/test/bitwise_high_bits_testing.cpp (from r62063, /sandbox/SOC/2010/bit_masks/lib/integer/test/bitwise_high_bits_test.cpp)
==============================================================================
--- /sandbox/SOC/2010/bit_masks/lib/integer/test/bitwise_high_bits_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitwise_high_bits_testing.cpp 2010-05-17 09:06:21 EDT (Mon, 17 May 2010)
@@ -0,0 +1,56 @@
+// Copyright 2010 Brian Bartman.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+
+
+#include "test_type_list.hpp"
+#include <boost/integer/high_low_bits.hpp>
+
+
+
+// Testing for operator overloads.
+using namespace boost;
+
+template <typename T>
+void test_function() {
+
+ // operator &(T, high_bits)
+ T bit_result = T(0) & high_bits<T, 1>();
+
+ // operator &(high_bits, T)
+ bit_result = high_bits<T, 1>() & T(0);
+
+ // operator |(T, high_bits)
+ bit_result = T(0) | high_bits<T, 1>();
+
+ // operator |(high_bits, T)
+ bit_result = T(0) | high_bits<T,1>();
+
+ // operator |(T, high_bits)
+ bit_result = high_bits<T,1>() | T(0);
+
+ // operator ^(high_bits, T)
+ bit_result = T(0) ^ high_bits<T,1>();
+
+ // operator ^(T, high_bits)
+ bit_result = high_bits<T,1>() ^ T(0);
+}
+
+
+struct type_tester {
+ template< typename U >
+ void operator()(U) {
+ test_function<U>();
+ }
+};
+
+
+int main() {
+ mpl::for_each< test_types >( type_tester() );
+ mpl::for_each< test_types_2 >( type_tester() );
+ mpl::for_each< test_types_3 >( type_tester() );
+
+ return 0;
+}

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bitwise_low_bits_testing.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bitwise_low_bits_testing.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitwise_low_bits_testing.cpp 2010-05-17 09:06:21 EDT (Mon, 17 May 2010)
@@ -0,0 +1,56 @@
+// Copyright 2010 Brian Bartman.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+
+
+#include "test_type_list.hpp"
+#include <boost/integer/high_low_bits.hpp>
+
+
+
+// Testing for operator overloads.
+using namespace boost;
+
+template <typename T>
+void test_function() {
+
+ // operator &(T, low_bits)
+ T bit_result = T(0) & low_bits<T, 1>();
+
+ // operator &(low_bits, T)
+ bit_result = low_bits<T, 1>() & T(0);
+
+ // operator |(T, low_bits)
+ bit_result = T(0) | low_bits<T, 1>();
+
+ // operator |(low_bits, T)
+ bit_result = T(0) | low_bits<T,1>();
+
+ // operator |(T, low_bits)
+ bit_result = low_bits<T,1>() | T(0);
+
+ // operator ^(low_bits, T)
+ bit_result = T(0) ^ low_bits<T,1>();
+
+ // operator ^(T, low_bits)
+ bit_result = low_bits<T,1>() ^ T(0);
+}
+
+
+struct type_tester {
+ template< typename U >
+ void operator()(U) {
+ test_function<U>();
+ }
+};
+
+
+int main() {
+ mpl::for_each< test_types >( type_tester() );
+ mpl::for_each< test_types_2 >( type_tester() );
+ mpl::for_each< test_types_3 >( type_tester() );
+
+ return 0;
+}


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