Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58748 - sandbox/memory/boost/memory
From: xushiweizh_at_[hidden]
Date: 2010-01-06 03:57:40


Author: xushiwei
Date: 2010-01-06 03:57:39 EST (Wed, 06 Jan 2010)
New Revision: 58748
URL: http://svn.boost.org/trac/boost/changeset/58748

Log:
boost memory: log2 debug
Text files modified:
   sandbox/memory/boost/memory/pools.hpp | 35 ++++++++++++++++++++++++++++++++++-
   1 files changed, 34 insertions(+), 1 deletions(-)

Modified: sandbox/memory/boost/memory/pools.hpp
==============================================================================
--- sandbox/memory/boost/memory/pools.hpp (original)
+++ sandbox/memory/boost/memory/pools.hpp 2010-01-06 03:57:39 EST (Wed, 06 Jan 2010)
@@ -43,21 +43,53 @@
         };
 }
 
+#define BOOST_MEMORY_LOG2(val) NS_BOOST_MEMORY::detail::log2(val)
+
 #if _MSC_VER > 1200
 #pragma warning(pop)
 #endif
 
 #elif defined(__GNUG__) || defined(__GNUC__) // g++/gcc
 
+#if (1)
+
 __forceinline unsigned int log2(unsigned int val)
 {
         BOOST_MEMORY_ASSERT(val != 0);
         unsigned int result;
         __asm__("bsr %0, %%eax"::"m"(val));
         __asm__("movl %%eax, %0":"=m"(result));
+#if (1)
+ unsigned int base = (1 << result);
+ if (val < base || val >= (base << 1))
+ {
+ printf("WARN: log2 algorithm failed!\n");
+ }
+#endif
         return result;
 }
 
+#define BOOST_MEMORY_LOG2(val) NS_BOOST_MEMORY::detail::log2(val)
+
+#else
+
+#define BOOST_MEMORY_LOG2(val) \
+({ \
+ unsigned int const boost_memory_val_ = (val); \
+ unsigned int boost_memory_result_; \
+ BOOST_MEMORY_ASSERT(boost_memory_val_ != 0); \
+ __asm__("bsr %0, %%eax"::"m"(boost_memory_val_)); \
+ __asm__("movl %%eax, %0":"=m"(boost_memory_result_)); \
+ unsigned int base = (1 << boost_memory_result_); \
+ if (boost_memory_val_ < base || boost_memory_val_ >= (base << 1)) \
+ { \
+ printf("WARN: log2 algorithm failed!\n"); \
+ } \
+ boost_memory_result_; \
+})
+
+#endif
+
 #else
 
 __forceinline unsigned int log2(unsigned int val)
@@ -77,6 +109,7 @@
         }
 }
 
+#define BOOST_MEMORY_LOG2(val) NS_BOOST_MEMORY::detail::log2(val)
 #pragma message("Warning: unknown compiler and use a slow log2 algorithm!"
 
 #endif
@@ -168,7 +201,7 @@
                 BOOST_MEMORY_ASSERT(!has_pool1(cb));
                 BOOST_MEMORY_ASSERT(has_pool(cb));
 
- const size_type index = detail::log2(cb + (PADDING2 - 1)) + (NPOOL1 - (MIN_BITS2 - 1));
+ const size_type index = BOOST_MEMORY_LOG2(cb + (PADDING2 - 1)) + (NPOOL1 - (MIN_BITS2 - 1));
                 pool_type* p = m_pools[index];
                 if (p == NULL)
                 {


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