00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef CEYLAN_ENDIANNESS_H_
00028 #define CEYLAN_ENDIANNESS_H_
00029
00030
00031
00032
00033
00034 #ifdef CEYLAN_USES_CONFIG_H
00035 #include "CeylanConfig.h"
00036 #endif // CEYLAN_USES_CONFIG_H
00037
00038
00039
00040 extern "C"
00041 {
00042
00043 #ifdef CEYLAN_USES_BYTESWAP_H
00044 #include <byteswap.h>
00045 #endif // CEYLAN_USES_BYTESWAP_H
00046
00047 #ifdef CEYLAN_USES_MACHINE_BSWAP_H
00048 #include <machine/bswap.h>
00049 #endif // CEYLAN_USES_MACHINE_BSWAP_H
00050
00051 }
00052
00053 #include <cstdlib>
00054
00055
00056
00057 #ifdef CEYLAN_USES_BYTESWAP_H
00058
00059
00060 #define ceylan_bswap_16(x) bswap_16(x)
00061
00062 #define ceylan_bswap_32(x) bswap_32(x)
00063
00064 #define ceylan_bswap_64(x) bswap_64(x)
00065
00066
00067
00068 #else // CEYLAN_USES_BYTESWAP_H
00069
00070
00071
00072
00073 #define ceylan_bswap_16(x) \
00074 ((((x) >> 8) & 0xff) \
00075 | (((x) & 0xff) << 8))
00076
00077
00078 #define ceylan_bswap_32(x) \
00079 ((((x) & 0xff000000) >> 24) \
00080 | (((x) & 0x00ff0000) >> 8) \
00081 | (((x) & 0x0000ff00) << 8) \
00082 | (((x) & 0x000000ff) << 24))
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 #ifndef CEYLAN_FAKES_64_BIT_TYPE
00105
00106
00107
00108
00109 #define ceylan_bswap_64(x) \
00110 ((((x) & 0xff00000000000000ull) >> 56) \
00111 | (((x) & 0x00ff000000000000ull) >> 40) \
00112 | (((x) & 0x0000ff0000000000ull) >> 24) \
00113 | (((x) & 0x000000ff00000000ull) >> 8) \
00114 | (((x) & 0x00000000ff000000ull) << 8) \
00115 | (((x) & 0x0000000000ff0000ull) << 24) \
00116 | (((x) & 0x000000000000ff00ull) << 40) \
00117 | (((x) & 0x00000000000000ffull) << 56))
00118
00119
00120
00121 #endif // CEYLAN_FAKES_64_BIT_TYPE
00122
00123
00124
00125
00126 namespace Ceylan
00127 {
00128
00129
00138 inline void byteswap( Ceylan::Uint64 & toSwap )
00139 {
00140
00141 #ifdef CEYLAN_FAKES_64_BIT_TYPE
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 Ceylan::Uint64 res ;
00155
00156 res.hi = ceylan_bswap_32( toSwap.lo ) ;
00157 res.lo = ceylan_bswap_32( toSwap.hi ) ;
00158
00159 toSwap = res ;
00160
00161 #else // CEYLAN_FAKES_64_BIT_TYPE
00162
00163
00164
00165
00166
00167
00168
00169 toSwap = ceylan_bswap_64( toSwap ) ;
00170
00171 #endif // CEYLAN_FAKES_64_BIT_TYPE
00172
00173 }
00174
00175
00176 }
00177
00178
00179 #endif // CEYLAN_USES_BYTESWAP_H
00180
00181
00182
00183 #endif // CEYLAN_ENDIANNESS_H_
00184