Warning, file /include/root/Byteswap.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef ROOT_Byteswap
0012 #define ROOT_Byteswap
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 #include <cstdint>
0041
0042 #ifndef R__USEASMSWAP
0043 #if (defined(__linux) || defined(__APPLE__)) && \
0044 (defined(__i386__) || defined(__x86_64__)) && \
0045 (defined(__GNUC__))
0046 # define R__USEASMSWAP
0047 #endif
0048
0049 #if defined(_WIN32) && (_MSC_VER >= 1300)
0050 # include <stdlib.h>
0051 # pragma intrinsic(_byteswap_ushort,_byteswap_ulong,_byteswap_uint64)
0052 # define R__USEASMSWAP
0053 #endif
0054 #endif
0055
0056
0057 #define R__bswap_constant_16(x) \
0058 ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
0059
0060 #if defined(R__USEASMSWAP)
0061 # if defined(__GNUC__)
0062 # define R__bswap_16(x) __builtin_bswap16(x)
0063 # elif defined(_MSC_VER)
0064 # define R__bswap_16(x) _byteswap_ushort(x)
0065 # endif
0066 #else
0067 # define R__bswap_16(x) R__bswap_constant_16(x)
0068 #endif
0069
0070
0071 #define R__bswap_constant_32(x) \
0072 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
0073 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
0074
0075 #if defined(R__USEASMSWAP)
0076 # if defined(__GNUC__)
0077 # define R__bswap_32(x) __builtin_bswap32(x)
0078 # elif defined(_MSC_VER)
0079 # define R__bswap_32(x) _byteswap_ulong(x)
0080 # endif
0081 #else
0082 # define R__bswap_32(x) R__bswap_constant_32(x)
0083 #endif
0084
0085
0086 static inline uint64_t R__bswap_constant_64(uint64_t x) {
0087 x = ((x & 0x00000000ffffffff) << 32) | ((x & 0xffffffff00000000) >> 32);
0088 x = ((x & 0x0000ffff0000ffff) << 16) | ((x & 0xffff0000ffff0000) >> 16);
0089 x = ((x & 0x00ff00ff00ff00ff) << 8) | ((x & 0xff00ff00ff00ff00) >> 8);
0090 return x;
0091 }
0092
0093 #if defined(R__USEASMSWAP)
0094 # if defined(__GNUC__)
0095 # define R__bswap_64(x) __builtin_bswap64(x)
0096 # elif defined(_MSC_VER)
0097 # define R__bswap_64(x) _byteswap_uint64(x)
0098 # endif
0099 #else
0100 # define R__bswap_64(x) R__bswap_constant_64(x)
0101 #endif
0102
0103
0104
0105 #define Rbswap_16(x) R__bswap_16(x)
0106
0107
0108 #define Rbswap_32(x) R__bswap_32(x)
0109
0110
0111 #define Rbswap_64(x) R__bswap_64(x)
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 template <unsigned N>
0124 struct RByteSwap {
0125 };
0126
0127 template <>
0128 struct RByteSwap<2> {
0129
0130 using value_type = std::uint16_t;
0131 static value_type bswap(value_type x) { return Rbswap_16(x); }
0132 };
0133
0134 template <>
0135 struct RByteSwap<4> {
0136 using value_type = std::uint32_t;
0137 static value_type bswap(value_type x) { return Rbswap_32(x); }
0138 };
0139
0140 template <>
0141 struct RByteSwap<8> {
0142 using value_type = std::uint64_t;
0143 static value_type bswap(value_type x) { return Rbswap_64(x); }
0144 };
0145
0146 #endif