diff --git a/include/boost/gil/channel.hpp b/include/boost/gil/channel.hpp index d073a3761..84ed48bf8 100644 --- a/include/boost/gil/channel.hpp +++ b/include/boost/gil/channel.hpp @@ -344,7 +344,7 @@ protected: static const num_value_t num_values = static_cast< num_value_t >( 1 ) << NumBits ; static const max_value_t max_val = static_cast< max_value_t >( num_values - 1 ); -#ifdef GIL_NONWORD_POINTER_ALIGNMENT_SUPPORTED +#if defined(BOOST_GIL_CONFIG_HAS_UNALIGNED_ACCESS) const bitfield_t& get_data() const { return *static_cast(_data_ptr); } void set_data(const bitfield_t& val) const { *static_cast< bitfield_t*>(_data_ptr) = val; } #else diff --git a/include/boost/gil/gil_config.hpp b/include/boost/gil/gil_config.hpp index a005e8a26..70fa1eeb0 100644 --- a/include/boost/gil/gil_config.hpp +++ b/include/boost/gil/gil_config.hpp @@ -1,6 +1,7 @@ /* Copyright 2005-2007 Adobe Systems Incorporated - + Copyright 2018 Mateusz Loskot + Use, modification and distribution are subject to 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). @@ -14,7 +15,7 @@ #define GIL_CONFIG_HPP //////////////////////////////////////////////////////////////////////////////////////// -/// \file +/// \file /// \brief GIL configuration file /// \author Lubomir Bourdev and Hailin Jin \n /// Adobe Systems Incorporated @@ -22,13 +23,40 @@ //////////////////////////////////////////////////////////////////////////////////////// #include +#include #define GIL_VERSION "2.1.2" -// Enable GIL_NONWORD_POINTER_ALIGNMENT_SUPPORTED if your platform supports dereferencing on non-word memory boundary. -// Enabling the flag results in performance improvement -#if !defined(__hpux) && !defined(sun) && !defined(__sun) && !defined(__osf__) - #define GIL_NONWORD_POINTER_ALIGNMENT_SUPPORTED +#if defined(BOOST_GIL_DOXYGEN_ONLY) +/// \def BOOST_GIL_CONFIG_HAS_UNALIGNED_ACCESS +/// \brief Define to allow unaligned memory access +/// Theoretically (or historically?) on platforms which support dereferencing on +/// non-word memory boundary, unaligned access may result in performance improvement. +/// \warning Unfortunately, this optimization may be a C/C++ strict aliasing rules +/// violation, if accessed data buffer has effective type that cannot be aliased +/// without leading to undefined behaviour. +#define BOOST_GIL_CONFIG_HAS_UNALIGNED_ACCESS #endif +#if defined(BOOST_GIL_CONFIG_HAS_UNALIGNED_ACCESS) +#if defined(sun) || defined(__sun) || \ // SunOS + defined(__osf__) || defined(__osf) || \ // Tru64 + defined(_hpux) || defined(hpux) || \ // HP-UX + defined(__arm__) || defined(__ARM_ARCH) || \ // ARM + defined(_AIX) // AIX +#error Unaligned access strictly disabled for some UNIX platforms or ARM architecture +#elif defined(__i386__) || defined(__x86_64__) || defined(__vax__) + // The check for little-endian architectures that tolerate unaligned memory + // accesses is just an optimization. Nothing will break if it fails to detect + // a suitable architecture. + // + // Unfortunately, this optimization may be a C/C++ strict aliasing rules violation + // if accessed data buffer has effective type that cannot be aliased + // without leading to undefined behaviour. +BOOST_PRAGMA_MESSAGE("CAUTION: Unaligned access tolerated on little-endian may cause undefined behaviour") +#else +#error Unaligned access disabled for unknown platforms and architectures +#endif +#endif // defined(BOOST_GIL_CONFIG_HAS_UNALIGNED_ACCESS) + #endif