Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84176 - in trunk: boost/log/detail libs/log/src
From: andrey.semashev_at_[hidden]
Date: 2013-05-06 16:48:55


Author: andysem
Date: 2013-05-06 16:48:52 EDT (Mon, 06 May 2013)
New Revision: 84176
URL: http://svn.boost.org/trac/boost/changeset/84176

Log:
Fixed incorrect target buffer alignment and filling.
Added:
   trunk/boost/log/detail/intptr_t.hpp (contents, props changed)
Text files modified:
   trunk/libs/log/src/dump_avx2.cpp | 17 +++++++++--------
   trunk/libs/log/src/dump_ssse3.cpp | 17 +++++++++--------
   2 files changed, 18 insertions(+), 16 deletions(-)

Added: trunk/boost/log/detail/intptr_t.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/log/detail/intptr_t.hpp 2013-05-06 16:48:52 EDT (Mon, 06 May 2013)
@@ -0,0 +1,64 @@
+/*
+ * Copyright Andrey Semashev 2007 - 2013.
+ * 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)
+ */
+/*!
+ * \file intptr_t.hpp
+ * \author Andrey Semashev
+ * \date 06.05.2013
+ *
+ * \brief This header is the Boost.Log library implementation, see the library documentation
+ * at http://www.boost.org/libs/log/doc/log.html.
+ */
+
+#ifndef BOOST_LOG_DETAIL_INTPTR_T_HPP_INCLUDED_
+#define BOOST_LOG_DETAIL_INTPTR_T_HPP_INCLUDED_
+
+#include <boost/cstdint.hpp>
+#include <boost/log/detail/config.hpp>
+#include <boost/log/detail/header.hpp>
+
+#ifdef BOOST_LOG_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+namespace boost {
+
+BOOST_LOG_OPEN_NAMESPACE
+
+namespace aux {
+
+// PGI seems to not support intptr_t/uintptr_t properly. BOOST_HAS_STDINT_H is not defined for this compiler by Boost.Config.
+#if !defined(__PGIC__)
+
+#if (defined(BOOST_WINDOWS) && !defined(_WIN32_WCE)) \
+ || (defined(_XOPEN_UNIX) && (_XOPEN_UNIX+0 > 0) && !defined(__UCLIBC__)) \
+ || defined(__CYGWIN__) \
+ || defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) \
+ || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+
+typedef ::intptr_t intptr_t;
+typedef ::uintptr_t uintptr_t;
+#define BOOST_LOG_HAS_INTPTR_T
+
+#elif (defined(__GNUC__) || defined(__clang__)) && defined(__INTPTR_TYPE__) && defined(__UINTPTR_TYPE__)
+
+typedef __INTPTR_TYPE__ intptr_t;
+typedef __UINTPTR_TYPE__ uintptr_t;
+#define BOOST_LOG_HAS_INTPTR_T
+
+#endif
+
+#endif
+
+} // namespace aux
+
+BOOST_LOG_CLOSE_NAMESPACE // namespace log
+
+} // namespace boost
+
+#include <boost/log/detail/footer.hpp>
+
+#endif // BOOST_LOG_DETAIL_INTPTR_T_HPP_INCLUDED_

Modified: trunk/libs/log/src/dump_avx2.cpp
==============================================================================
--- trunk/libs/log/src/dump_avx2.cpp (original)
+++ trunk/libs/log/src/dump_avx2.cpp 2013-05-06 16:48:52 EDT (Mon, 06 May 2013)
@@ -20,6 +20,7 @@
 #include <immintrin.h>
 #include <boost/cstdint.hpp>
 #include <boost/log/detail/config.hpp>
+#include <boost/log/detail/intptr_t.hpp>
 #include <boost/log/detail/header.hpp>
 
 namespace boost {
@@ -132,7 +133,7 @@
 
     char_type buf_storage[stride * 3u + 16u];
     // Align the temporary buffer at 16 bytes
- char_type* const buf = buf_storage + (16u - ((std::size_t)(char_type*)buf_storage & 15u));
+ char_type* const buf = reinterpret_cast< char_type* >((uint8_t*)buf_storage + (16u - (((uintptr_t)(char_type*)buf_storage) & 15u)));
     char_type* buf_begin = buf + 1u; // skip the first space of the first chunk
     char_type* buf_end = buf + stride * 3u;
 
@@ -144,7 +145,7 @@
 
     // First, check the input alignment
     const uint8_t* p = static_cast< const uint8_t* >(data);
- if (const std::size_t prealign_size = ((16u - ((std::size_t)p & 15u)) & 15u))
+ if (const std::size_t prealign_size = ((16u - ((uintptr_t)p & 15u)) & 15u))
     {
         __m128i mm_input = _mm_lddqu_si128(reinterpret_cast< const __m128i* >(p));
         __m128i mm_output1, mm_output2, mm_output3;
@@ -169,9 +170,9 @@
             __m128i mm_input = _mm_load_si128(reinterpret_cast< const __m128i* >(p));
             __m128i mm_output1, mm_output2, mm_output3;
             dump_pack(mm_char_10_to_a, mm_input, mm_output1, mm_output2, mm_output3);
- store_characters(mm_output1, buf);
- store_characters(mm_output2, buf + 16u);
- store_characters(mm_output3, buf + 32u);
+ store_characters(mm_output1, b);
+ store_characters(mm_output2, b + 16u);
+ store_characters(mm_output3, b + 32u);
         }
 
         strm.write(buf_begin, buf_end - buf_begin);
@@ -186,9 +187,9 @@
             __m128i mm_input = _mm_load_si128(reinterpret_cast< const __m128i* >(p));
             __m128i mm_output1, mm_output2, mm_output3;
             dump_pack(mm_char_10_to_a, mm_input, mm_output1, mm_output2, mm_output3);
- store_characters(mm_output1, buf);
- store_characters(mm_output2, buf + 16u);
- store_characters(mm_output3, buf + 32u);
+ store_characters(mm_output1, b);
+ store_characters(mm_output2, b + 16u);
+ store_characters(mm_output3, b + 32u);
             b += 3u * 16u;
             p += 16u;
             tail_size -= 16u;

Modified: trunk/libs/log/src/dump_ssse3.cpp
==============================================================================
--- trunk/libs/log/src/dump_ssse3.cpp (original)
+++ trunk/libs/log/src/dump_ssse3.cpp 2013-05-06 16:48:52 EDT (Mon, 06 May 2013)
@@ -20,6 +20,7 @@
 #include <tmmintrin.h>
 #include <boost/cstdint.hpp>
 #include <boost/log/detail/config.hpp>
+#include <boost/log/detail/intptr_t.hpp>
 #include <boost/log/detail/header.hpp>
 
 namespace boost {
@@ -132,7 +133,7 @@
 
     char_type buf_storage[stride * 3u + 16u];
     // Align the temporary buffer at 16 bytes
- char_type* const buf = buf_storage + (16u - ((std::size_t)(char_type*)buf_storage & 15u));
+ char_type* const buf = reinterpret_cast< char_type* >((uint8_t*)buf_storage + (16u - (((uintptr_t)(char_type*)buf_storage) & 15u)));
     char_type* buf_begin = buf + 1u; // skip the first space of the first chunk
     char_type* buf_end = buf + stride * 3u;
 
@@ -144,7 +145,7 @@
 
     // First, check the input alignment
     const uint8_t* p = static_cast< const uint8_t* >(data);
- if (const std::size_t prealign_size = ((16u - ((std::size_t)p & 15u)) & 15u))
+ if (const std::size_t prealign_size = ((16u - ((uintptr_t)p & 15u)) & 15u))
     {
         __m128i mm_input = _mm_lddqu_si128(reinterpret_cast< const __m128i* >(p));
         __m128i mm_output1, mm_output2, mm_output3;
@@ -169,9 +170,9 @@
             __m128i mm_input = _mm_load_si128(reinterpret_cast< const __m128i* >(p));
             __m128i mm_output1, mm_output2, mm_output3;
             dump_pack(mm_char_10_to_a, mm_input, mm_output1, mm_output2, mm_output3);
- store_characters(mm_output1, buf);
- store_characters(mm_output2, buf + 16u);
- store_characters(mm_output3, buf + 32u);
+ store_characters(mm_output1, b);
+ store_characters(mm_output2, b + 16u);
+ store_characters(mm_output3, b + 32u);
         }
 
         strm.write(buf_begin, buf_end - buf_begin);
@@ -186,9 +187,9 @@
             __m128i mm_input = _mm_load_si128(reinterpret_cast< const __m128i* >(p));
             __m128i mm_output1, mm_output2, mm_output3;
             dump_pack(mm_char_10_to_a, mm_input, mm_output1, mm_output2, mm_output3);
- store_characters(mm_output1, buf);
- store_characters(mm_output2, buf + 16u);
- store_characters(mm_output3, buf + 32u);
+ store_characters(mm_output1, b);
+ store_characters(mm_output2, b + 16u);
+ store_characters(mm_output3, b + 32u);
             b += 3u * 16u;
             p += 16u;
             tail_size -= 16u;


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