00001
00002
00003
00004
00005 #if defined (ACE_HAS_INTRINSIC_BYTESWAP)
00006
00007
00008 # pragma intrinsic (_byteswap_ushort, _byteswap_ulong, _byteswap_uint64)
00009 #endif
00010
00011 #if defined (ACE_HAS_BSWAP_16) || defined (ACE_HAS_BSWAP_32) || defined (ACE_HAS_BSWAP_32)
00012 # include "ace/os_include/os_byteswap.h"
00013 #endif
00014
00015 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 ACE_INLINE void
00066 ACE_CDR::swap_2 (const char *orig, char* target)
00067 {
00068 #if defined (ACE_HAS_INTRINSIC_BYTESWAP)
00069
00070
00071 *reinterpret_cast<unsigned short *> (target) =
00072 _byteswap_ushort (*reinterpret_cast<unsigned short const *> (orig));
00073 #elif defined (ACE_HAS_BSWAP_16)
00074 *reinterpret_cast<unsigned short *> (target) =
00075 bswap_16 (*reinterpret_cast<unsigned short const *> (orig));
00076 #elif defined(ACE_HAS_INTEL_ASSEMBLY)
00077 unsigned short a =
00078 *reinterpret_cast<const unsigned short*> (orig);
00079 asm( "rolw $8, %0" : "=r" (a) : "0" (a) );
00080 *reinterpret_cast<unsigned short*> (target) = a;
00081 #elif defined (ACE_HAS_PENTIUM) \
00082 && (defined(_MSC_VER) || defined(__BORLANDC__)) \
00083 && !defined(ACE_LACKS_INLINE_ASSEMBLY)
00084 __asm mov ebx, orig;
00085 __asm mov ecx, target;
00086 __asm mov ax, [ebx];
00087 __asm rol ax, 8;
00088 __asm mov [ecx], ax;
00089 #else
00090 register ACE_UINT16 usrc = * reinterpret_cast<const ACE_UINT16*> (orig);
00091 register ACE_UINT16* udst = reinterpret_cast<ACE_UINT16*> (target);
00092 *udst = (usrc << 8) | (usrc >> 8);
00093 #endif
00094 }
00095
00096 ACE_INLINE void
00097 ACE_CDR::swap_4 (const char* orig, char* target)
00098 {
00099 #if defined (ACE_HAS_INTRINSIC_BYTESWAP)
00100
00101
00102 *reinterpret_cast<unsigned long *> (target) =
00103 _byteswap_ulong (*reinterpret_cast<unsigned long const *> (orig));
00104 #elif defined (ACE_HAS_BSWAP_32)
00105 *reinterpret_cast<unsigned int *> (target) =
00106 bswap_32 (*reinterpret_cast<unsigned int const *> (orig));
00107 #elif defined(ACE_HAS_INTEL_ASSEMBLY)
00108
00109 register unsigned int j =
00110 *reinterpret_cast<const unsigned int*> (orig);
00111 asm ("bswap %1" : "=r" (j) : "0" (j));
00112 *reinterpret_cast<unsigned int*> (target) = j;
00113 #elif defined(ACE_HAS_PENTIUM) \
00114 && (defined(_MSC_VER) || defined(__BORLANDC__)) \
00115 && !defined(ACE_LACKS_INLINE_ASSEMBLY)
00116 __asm mov ebx, orig;
00117 __asm mov ecx, target;
00118 __asm mov eax, [ebx];
00119 __asm bswap eax;
00120 __asm mov [ecx], eax;
00121 #else
00122 register ACE_UINT32 x = * reinterpret_cast<const ACE_UINT32*> (orig);
00123 x = (x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24);
00124 * reinterpret_cast<ACE_UINT32*> (target) = x;
00125 #endif
00126 }
00127
00128 ACE_INLINE void
00129 ACE_CDR::swap_8 (const char* orig, char* target)
00130 {
00131 #if defined (ACE_HAS_INTRINSIC_BYTESWAP)
00132
00133
00134 *reinterpret_cast<unsigned __int64 *> (target) =
00135 _byteswap_uint64 (*reinterpret_cast<unsigned __int64 const *> (orig));
00136 #elif defined (ACE_HAS_BSWAP_64)
00137 *reinterpret_cast<unsigned long long *> (target) =
00138 bswap_64 (*reinterpret_cast<unsigned long long const *> (orig));
00139 #elif (defined (__amd64__) || defined (__x86_64__)) && defined(__GNUG__)
00140 register unsigned long x =
00141 * reinterpret_cast<const unsigned long*> (orig);
00142 asm ("bswapq %1" : "=r" (x) : "0" (x));
00143 *reinterpret_cast<unsigned long*> (target) = x;
00144 #elif defined(ACE_HAS_PENTIUM) && defined(__GNUG__)
00145 register unsigned int i =
00146 *reinterpret_cast<const unsigned int*> (orig);
00147 register unsigned int j =
00148 *reinterpret_cast<const unsigned int*> (orig + 4);
00149 asm ("bswap %1" : "=r" (i) : "0" (i));
00150 asm ("bswap %1" : "=r" (j) : "0" (j));
00151 *reinterpret_cast<unsigned int*> (target + 4) = i;
00152 *reinterpret_cast<unsigned int*> (target) = j;
00153 #elif defined(ACE_HAS_PENTIUM) \
00154 && (defined(_MSC_VER) || defined(__BORLANDC__)) \
00155 && !defined(ACE_LACKS_INLINE_ASSEMBLY)
00156 __asm mov ecx, orig;
00157 __asm mov edx, target;
00158 __asm mov eax, [ecx];
00159 __asm mov ebx, 4[ecx];
00160 __asm bswap eax;
00161 __asm bswap ebx;
00162 __asm mov 4[edx], eax;
00163 __asm mov [edx], ebx;
00164 #elif ACE_SIZEOF_LONG == 8
00165
00166 register unsigned long x =
00167 * reinterpret_cast<const unsigned long*> (orig);
00168 register unsigned long x84 = (x & 0x000000ff000000ffUL) << 24;
00169 register unsigned long x73 = (x & 0x0000ff000000ff00UL) << 8;
00170 register unsigned long x62 = (x & 0x00ff000000ff0000UL) >> 8;
00171 register unsigned long x51 = (x & 0xff000000ff000000UL) >> 24;
00172 x = (x84 | x73 | x62 | x51);
00173 x = (x << 32) | (x >> 32);
00174 *reinterpret_cast<unsigned long*> (target) = x;
00175 #else
00176 register ACE_UINT32 x =
00177 * reinterpret_cast<const ACE_UINT32*> (orig);
00178 register ACE_UINT32 y =
00179 * reinterpret_cast<const ACE_UINT32*> (orig + 4);
00180 x = (x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24);
00181 y = (y << 24) | ((y & 0xff00) << 8) | ((y & 0xff0000) >> 8) | (y >> 24);
00182 * reinterpret_cast<ACE_UINT32*> (target) = y;
00183 * reinterpret_cast<ACE_UINT32*> (target + 4) = x;
00184 #endif
00185 }
00186
00187 ACE_INLINE void
00188 ACE_CDR::swap_16 (const char* orig, char* target)
00189 {
00190 swap_8 (orig + 8, target);
00191 swap_8 (orig, target + 8);
00192 }
00193
00194 ACE_INLINE size_t
00195 ACE_CDR::first_size (size_t minsize)
00196 {
00197 if (minsize == 0)
00198 return ACE_CDR::DEFAULT_BUFSIZE;
00199
00200 size_t newsize = ACE_CDR::DEFAULT_BUFSIZE;
00201 while (newsize < minsize)
00202 {
00203 if (newsize < ACE_CDR::EXP_GROWTH_MAX)
00204 {
00205
00206
00207
00208
00209
00210
00211 newsize <<= 1;
00212 }
00213 else
00214 {
00215
00216
00217
00218 newsize += ACE_CDR::LINEAR_GROWTH_CHUNK;
00219 }
00220 }
00221 return newsize;
00222 }
00223
00224 ACE_INLINE size_t
00225 ACE_CDR::next_size (size_t minsize)
00226 {
00227 size_t newsize = ACE_CDR::first_size (minsize);
00228
00229 if (newsize == minsize)
00230 {
00231
00232 if (newsize < ACE_CDR::EXP_GROWTH_MAX)
00233
00234
00235
00236 newsize <<= 1;
00237 else
00238 newsize += ACE_CDR::LINEAR_GROWTH_CHUNK;
00239 }
00240
00241 return newsize;
00242 }
00243
00244 ACE_END_VERSIONED_NAMESPACE_DECL
00245
00246