Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61745 - in sandbox/SOC/2010/bits_and_ints: boost/integer boost/integer/detail libs/integer/test
From: muriloufg_at_[hidden]
Date: 2010-05-03 15:02:38


Author: murilov
Date: 2010-05-03 15:02:37 EDT (Mon, 03 May 2010)
New Revision: 61745
URL: http://svn.boost.org/trac/boost/changeset/61745

Log:
Adding first draft of bits_and_ints.hpp forwarder with sign_extend.hpp. Testing the environment
Added:
   sandbox/SOC/2010/bits_and_ints/boost/integer/bits_and_ints.hpp (contents, props changed)
   sandbox/SOC/2010/bits_and_ints/boost/integer/detail/sign_extend.hpp (contents, props changed)
   sandbox/SOC/2010/bits_and_ints/libs/integer/test/sign_extend_test.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 | 1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

Added: sandbox/SOC/2010/bits_and_ints/boost/integer/bits_and_ints.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/bits_and_ints.hpp 2010-05-03 15:02:37 EDT (Mon, 03 May 2010)
@@ -0,0 +1,16 @@
+// Boost integer/sign_extend.hpp header file ------------------------------//
+
+// (C) Copyright Murilo Adriano Vasconcelos 2010.
+// 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)
+
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_BITS_AND_INTS
+#define BOOST_BITS_AND_INTS
+
+// sign_extends and static_sign_extends
+#include "detail/sign_extend.hpp"
+
+#endif
\ No newline at end of file

Added: sandbox/SOC/2010/bits_and_ints/boost/integer/detail/sign_extend.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/detail/sign_extend.hpp 2010-05-03 15:02:37 EDT (Mon, 03 May 2010)
@@ -0,0 +1,42 @@
+// Boost integer/sign_extend.hpp header file ------------------------------//
+
+// (C) Copyright Murilo Adriano Vasconcelos 2010.
+// 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)
+
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_SIGN_EXTEND
+#define BOOST_SIGN_EXTEND
+
+#include <boost/cstdint.hpp> // for uintmax_t
+#include <boost/assert.hpp>
+
+namespace boost
+{
+
+typedef intmax_t Raw;
+
+// Extend data represented in 'b' bits to sizeof(T)*8 bits
+template <typename IntegralType>
+inline Raw sign_extend(IntegralType data, unsigned b)
+{
+ data = data & ((Raw(1) << b) - 1);
+ Raw const m = (Raw(1) << (b - 1));
+ return (data ^ m) - m;
+}
+
+// Compile-time version of sign_extend
+template<typename IntegralType, Raw raw, unsigned B>
+struct static_sign_extend
+{
+ typedef IntegralType T;
+ BOOST_STATIC_CONSTANT(Raw,
+ value = ((raw & ((T(1) << B) - 1)) ^ (T(1) << (B - 1))) - (T(1) << (B - 1)) );
+}; // boost::static_sign_extend
+
+
+}
+
+#endif
\ No newline at end of file

Modified: sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 (original)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 2010-05-03 15:02:37 EDT (Mon, 03 May 2010)
@@ -15,6 +15,7 @@
         [ run integer_mask_test.cpp ]
         [ run static_log2_test.cpp ]
         [ run static_min_max_test.cpp ]
+ [ run sign_extend_test.cpp ]
         [ compile cstdint_include_test.cpp ]
         [ compile integer_traits_include_test.cpp ]
         [ compile integer_include_test.cpp ]

Added: sandbox/SOC/2010/bits_and_ints/libs/integer/test/sign_extend_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/sign_extend_test.cpp 2010-05-03 15:02:37 EDT (Mon, 03 May 2010)
@@ -0,0 +1,72 @@
+// Boost sign_extend.hpp test program --------------------------------------//
+
+// (C) Copyright Murilo Adriano Vasconcelos 2010.
+// 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 <boost/detail/lightweight_test.hpp>
+
+#include <boost/cstdlib.hpp> // for boost::exit_success
+#include <boost/integer/bits_and_ints.hpp> // for boost::sign_extend and boost::static_sign_extend
+
+#include <iostream> // for std::cout (std::endl indirectly)
+
+
+// Macros to compact code
+#define SIGN_EXTEND_TEST(d, b, e) \
+ BOOST_TEST(::boost::sign_extend(d, b) == e); \
+ BOOST_TEST((::boost::static_sign_extend<int, d, b>::value) == e)
+
+
+// Main testing function
+int main(int, char* [])
+{
+ std::cout << "Doing tests on sign_extend." << std::endl;
+
+ SIGN_EXTEND_TEST(0, 1, 0);
+ SIGN_EXTEND_TEST(1, 1, -1);
+
+ SIGN_EXTEND_TEST(0, 2, 0);
+ SIGN_EXTEND_TEST(1, 2, 1);
+ SIGN_EXTEND_TEST(2, 2, -2);
+ SIGN_EXTEND_TEST(3, 2, -1);
+
+ SIGN_EXTEND_TEST(0, 3, 0);
+ SIGN_EXTEND_TEST(1, 3, 1);
+ SIGN_EXTEND_TEST(2, 3, 2);
+ SIGN_EXTEND_TEST(3, 3, 3);
+ SIGN_EXTEND_TEST(4, 3, -4);
+ SIGN_EXTEND_TEST(5, 3, -3);
+ SIGN_EXTEND_TEST(6, 3, -2);
+ SIGN_EXTEND_TEST(7, 3, -1);
+
+ SIGN_EXTEND_TEST(0, 4, 0);
+ SIGN_EXTEND_TEST(1, 4, 1);
+ SIGN_EXTEND_TEST(2, 4, 2);
+ SIGN_EXTEND_TEST(3, 4, 3);
+ SIGN_EXTEND_TEST(4, 4, 4);
+ SIGN_EXTEND_TEST(5, 4, 5);
+ SIGN_EXTEND_TEST(6, 4, 6);
+ SIGN_EXTEND_TEST(7, 4, 7);
+ SIGN_EXTEND_TEST(8, 4, -8);
+ SIGN_EXTEND_TEST(9, 4, -7);
+ SIGN_EXTEND_TEST(10, 4, -6);
+ SIGN_EXTEND_TEST(11, 4, -5);
+ SIGN_EXTEND_TEST(12, 4, -4);
+ SIGN_EXTEND_TEST(13, 4, -3);
+ SIGN_EXTEND_TEST(14, 4, -2);
+ SIGN_EXTEND_TEST(15, 4, -1);
+
+ SIGN_EXTEND_TEST(0x40000000, 31, -0x40000000);
+ SIGN_EXTEND_TEST(0x7FFFFFFF, 31, -1);
+
+#ifndef BOOST_NO_INT64_T
+ //SIGN_EXTEND_TEST(0x1000000000000000l, 63, 0x1000000000000000);
+ //SIGN_EXTEND_TEST(0x7FFFFFFFFF, 39, 0xffffffffffffffff);
+#endif
+
+ 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