38 #ifndef BLOCXX_BYTE_SWAP_HPP_ 39 #define BLOCXX_BYTE_SWAP_HPP_ 40 #include "blocxx/BLOCXX_config.h" 43 #if !defined(BLOCXX_WORDS_BIGENDIAN) && defined(BLOCXX_HAVE_BYTESWAP_H) && !defined(BLOCXX_DEBUG_MEMORY) 51 #ifndef BLOCXX_WORDS_BIGENDIAN 52 #if defined(BLOCXX_HAVE_BYTESWAP_H) && !defined(BLOCXX_DEBUG_MEMORY) 59 inline UInt16
hton16(UInt16 v) {
return __bswap_16(v); }
65 inline UInt32
hton32(UInt32 v) {
return __bswap_32(v); }
71 inline UInt64
hton64(UInt64 v) {
return __bswap_64(v); }
77 inline UInt16
ntoh16(UInt16 v) {
return __bswap_16(v); }
83 inline UInt32
ntoh32(UInt32 v) {
return __bswap_32(v); }
89 inline UInt64
ntoh64(UInt64 v) {
return __bswap_64(v); }
94 (reinterpret_cast<unsigned char*>(&rval))[1] = (reinterpret_cast<unsigned char*>(&v))[0];
95 (reinterpret_cast<unsigned char*>(&rval))[0] = (reinterpret_cast<unsigned char*>(&v))[1];
101 (reinterpret_cast<unsigned char*>(&rval))[3] = (reinterpret_cast<unsigned char*>(&v))[0];
102 (reinterpret_cast<unsigned char*>(&rval))[2] = (reinterpret_cast<unsigned char*>(&v))[1];
103 (reinterpret_cast<unsigned char*>(&rval))[1] = (reinterpret_cast<unsigned char*>(&v))[2];
104 (reinterpret_cast<unsigned char*>(&rval))[0] = (reinterpret_cast<unsigned char*>(&v))[3];
110 (reinterpret_cast<unsigned char*>(&rval))[7] = (reinterpret_cast<unsigned char*>(&v))[0];
111 (reinterpret_cast<unsigned char*>(&rval))[6] = (reinterpret_cast<unsigned char*>(&v))[1];
112 (reinterpret_cast<unsigned char*>(&rval))[5] = (reinterpret_cast<unsigned char*>(&v))[2];
113 (reinterpret_cast<unsigned char*>(&rval))[4] = (reinterpret_cast<unsigned char*>(&v))[3];
114 (reinterpret_cast<unsigned char*>(&rval))[3] = (reinterpret_cast<unsigned char*>(&v))[4];
115 (reinterpret_cast<unsigned char*>(&rval))[2] = (reinterpret_cast<unsigned char*>(&v))[5];
116 (reinterpret_cast<unsigned char*>(&rval))[1] = (reinterpret_cast<unsigned char*>(&v))[6];
117 (reinterpret_cast<unsigned char*>(&rval))[0] = (reinterpret_cast<unsigned char*>(&v))[7];
133 #else // we're big-endian, just pass-thru 134 inline UInt16
hton16(UInt16 v) {
return v; }
135 inline UInt32
hton32(UInt32 v) {
return v; }
136 inline UInt64
hton64(UInt64 v) {
return v; }
137 inline UInt16
ntoh16(UInt16 v) {
return v; }
138 inline UInt32
ntoh32(UInt32 v) {
return v; }
139 inline UInt64
ntoh64(UInt64 v) {
return v; }