Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:45:24

0001 //  endian/detail/intrinsic.hpp  -------------------------------------------------------//
0002 
0003 //  Copyright (C) 2012 David Stone
0004 //  Copyright Beman Dawes 2013
0005 
0006 //  Distributed under the Boost Software License, Version 1.0.
0007 //  http://www.boost.org/LICENSE_1_0.txt
0008 
0009 #ifndef BOOST_ENDIAN_INTRINSIC_HPP
0010 #define BOOST_ENDIAN_INTRINSIC_HPP
0011 
0012 //  Allow user to force BOOST_ENDIAN_NO_INTRINSICS in case they aren't available for a
0013 //  particular platform/compiler combination. Please report such platform/compiler
0014 //  combinations to the Boost mailing list.
0015 #ifndef BOOST_ENDIAN_NO_INTRINSICS
0016 
0017 #ifndef __has_builtin         // Optional of course
0018   #define __has_builtin(x) 0  // Compatibility with non-clang compilers
0019 #endif
0020 
0021 #if defined(_MSC_VER) && ( !defined(__clang__) || defined(__c2__) )
0022 //  Microsoft documents these as being compatible since Windows 95 and specifically
0023 //  lists runtime library support since Visual Studio 2003 (aka 7.1).
0024 //  Clang/c2 uses the Microsoft rather than GCC intrinsics, so we check for
0025 //  defined(_MSC_VER) before defined(__clang__)
0026 # define BOOST_ENDIAN_INTRINSIC_MSG "cstdlib _byteswap_ushort, etc."
0027 # include <cstdlib>
0028 # define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x) _byteswap_ushort(x)
0029 # define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x) _byteswap_ulong(x)
0030 # define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x) _byteswap_uint64(x)
0031 
0032 //  GCC and Clang recent versions provide intrinsic byte swaps via builtins
0033 #elif (defined(__clang__) && __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)) \
0034   || (defined(__GNUC__ ) && \
0035   (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
0036 # define BOOST_ENDIAN_INTRINSIC_MSG "__builtin_bswap16, etc."
0037 // prior to 4.8, gcc did not provide __builtin_bswap16 on some platforms so we emulate it
0038 // see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624
0039 // Clang has a similar problem, but their feature test macros make it easier to detect
0040 # if (defined(__clang__) && __has_builtin(__builtin_bswap16)) \
0041   || (defined(__GNUC__) &&(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))
0042 #   define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x) __builtin_bswap16(x)
0043 # else
0044 #   define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x) __builtin_bswap32((x) << 16)
0045 # endif
0046 # define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x) __builtin_bswap32(x)
0047 # define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x) __builtin_bswap64(x)
0048 
0049 # define BOOST_ENDIAN_CONSTEXPR_INTRINSICS
0050 
0051 //  Linux systems provide the byteswap.h header, with
0052 #elif defined(__linux__)
0053 //  don't check for obsolete forms defined(linux) and defined(__linux) on the theory that
0054 //  compilers that predefine only these are so old that byteswap.h probably isn't present.
0055 # define BOOST_ENDIAN_INTRINSIC_MSG "byteswap.h bswap_16, etc."
0056 # include <byteswap.h>
0057 # define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x) bswap_16(x)
0058 # define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x) bswap_32(x)
0059 # define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x) bswap_64(x)
0060 
0061 #else
0062 # define BOOST_ENDIAN_NO_INTRINSICS
0063 # define BOOST_ENDIAN_INTRINSIC_MSG "no byte swap intrinsics"
0064 #endif
0065 
0066 #elif !defined(BOOST_ENDIAN_INTRINSIC_MSG)
0067 # define BOOST_ENDIAN_INTRINSIC_MSG "no byte swap intrinsics"
0068 #endif  // BOOST_ENDIAN_NO_INTRINSICS
0069 #endif  // BOOST_ENDIAN_INTRINSIC_HPP