mfbt/tests/TestEndian.cpp

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "mozilla/Assertions.h"
michael@0 6 #include "mozilla/Endian.h"
michael@0 7
michael@0 8 #include <stddef.h>
michael@0 9
michael@0 10 using mozilla::BigEndian;
michael@0 11 using mozilla::LittleEndian;
michael@0 12 using mozilla::NativeEndian;
michael@0 13
michael@0 14 template<typename T>
michael@0 15 void
michael@0 16 TestSingleSwap(T value, T swappedValue)
michael@0 17 {
michael@0 18 #if MOZ_LITTLE_ENDIAN
michael@0 19 MOZ_RELEASE_ASSERT(NativeEndian::swapToBigEndian(value) == swappedValue);
michael@0 20 MOZ_RELEASE_ASSERT(NativeEndian::swapFromBigEndian(value) == swappedValue);
michael@0 21 MOZ_RELEASE_ASSERT(NativeEndian::swapToNetworkOrder(value) == swappedValue);
michael@0 22 MOZ_RELEASE_ASSERT(NativeEndian::swapFromNetworkOrder(value) == swappedValue);
michael@0 23 #else
michael@0 24 MOZ_RELEASE_ASSERT(NativeEndian::swapToLittleEndian(value) == swappedValue);
michael@0 25 MOZ_RELEASE_ASSERT(NativeEndian::swapFromLittleEndian(value) == swappedValue);
michael@0 26 #endif
michael@0 27 }
michael@0 28
michael@0 29 template<typename T>
michael@0 30 void
michael@0 31 TestSingleNoSwap(T value, T notSwappedValue)
michael@0 32 {
michael@0 33 #if MOZ_LITTLE_ENDIAN
michael@0 34 MOZ_RELEASE_ASSERT(NativeEndian::swapToLittleEndian(value) == notSwappedValue);
michael@0 35 MOZ_RELEASE_ASSERT(NativeEndian::swapFromLittleEndian(value) == notSwappedValue);
michael@0 36 #else
michael@0 37 MOZ_RELEASE_ASSERT(NativeEndian::swapToBigEndian(value) == notSwappedValue);
michael@0 38 MOZ_RELEASE_ASSERT(NativeEndian::swapFromBigEndian(value) == notSwappedValue);
michael@0 39 MOZ_RELEASE_ASSERT(NativeEndian::swapToNetworkOrder(value) == notSwappedValue);
michael@0 40 MOZ_RELEASE_ASSERT(NativeEndian::swapFromNetworkOrder(value) == notSwappedValue);
michael@0 41 #endif
michael@0 42 }
michael@0 43
michael@0 44 // Endian.h functions are declared as protected in an base class and
michael@0 45 // then re-exported as public in public derived classes. The
michael@0 46 // standardese around explicit instantiation of templates is not clear
michael@0 47 // in such cases. Provide these wrappers to make things more explicit.
michael@0 48 // For your own enlightenment, you may wish to peruse:
michael@0 49 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56152 and subsequently
michael@0 50 // http://j.mp/XosS6S .
michael@0 51 #define WRAP_COPYTO(NAME) \
michael@0 52 template<typename T> \
michael@0 53 void \
michael@0 54 NAME(void* dst, const T* src, size_t count) \
michael@0 55 { \
michael@0 56 NativeEndian::NAME<T>(dst, src, count); \
michael@0 57 }
michael@0 58
michael@0 59 WRAP_COPYTO(copyAndSwapToLittleEndian)
michael@0 60 WRAP_COPYTO(copyAndSwapToBigEndian)
michael@0 61 WRAP_COPYTO(copyAndSwapToNetworkOrder)
michael@0 62
michael@0 63 #define WRAP_COPYFROM(NAME) \
michael@0 64 template<typename T> \
michael@0 65 void \
michael@0 66 NAME(T* dst, const void* src, size_t count) \
michael@0 67 { \
michael@0 68 NativeEndian::NAME<T>(dst, src, count); \
michael@0 69 }
michael@0 70
michael@0 71 WRAP_COPYFROM(copyAndSwapFromLittleEndian)
michael@0 72 WRAP_COPYFROM(copyAndSwapFromBigEndian)
michael@0 73 WRAP_COPYFROM(copyAndSwapFromNetworkOrder)
michael@0 74
michael@0 75 #define WRAP_IN_PLACE(NAME) \
michael@0 76 template<typename T> \
michael@0 77 void \
michael@0 78 NAME(T* p, size_t count) \
michael@0 79 { \
michael@0 80 NativeEndian::NAME<T>(p, count); \
michael@0 81 }
michael@0 82 WRAP_IN_PLACE(swapToLittleEndianInPlace)
michael@0 83 WRAP_IN_PLACE(swapFromLittleEndianInPlace)
michael@0 84 WRAP_IN_PLACE(swapToBigEndianInPlace)
michael@0 85 WRAP_IN_PLACE(swapFromBigEndianInPlace)
michael@0 86 WRAP_IN_PLACE(swapToNetworkOrderInPlace)
michael@0 87 WRAP_IN_PLACE(swapFromNetworkOrderInPlace)
michael@0 88
michael@0 89 enum SwapExpectation {
michael@0 90 Swap,
michael@0 91 NoSwap
michael@0 92 };
michael@0 93
michael@0 94 template<typename T, size_t Count>
michael@0 95 void
michael@0 96 TestBulkSwapToSub(enum SwapExpectation expectSwap,
michael@0 97 const T (&values)[Count],
michael@0 98 void (*swapperFunc)(void*, const T*, size_t),
michael@0 99 T (*readerFunc)(const void*))
michael@0 100 {
michael@0 101 const size_t arraySize = 2 * Count;
michael@0 102 const size_t bufferSize = arraySize * sizeof(T);
michael@0 103 static uint8_t buffer[bufferSize];
michael@0 104 const uint8_t fillValue = 0xa5;
michael@0 105 static uint8_t checkBuffer[bufferSize];
michael@0 106
michael@0 107 MOZ_RELEASE_ASSERT(bufferSize > 2 * sizeof(T));
michael@0 108
michael@0 109 memset(checkBuffer, fillValue, bufferSize);
michael@0 110
michael@0 111 for (size_t startPosition = 0; startPosition < sizeof(T); ++startPosition) {
michael@0 112 for (size_t nValues = 0; nValues < Count; ++nValues) {
michael@0 113 memset(buffer, fillValue, bufferSize);
michael@0 114 swapperFunc(buffer + startPosition, values, nValues);
michael@0 115
michael@0 116 MOZ_RELEASE_ASSERT(memcmp(buffer, checkBuffer, startPosition) == 0);
michael@0 117 size_t valuesEndPosition = startPosition + sizeof(T) * nValues;
michael@0 118 MOZ_RELEASE_ASSERT(memcmp(buffer + valuesEndPosition,
michael@0 119 checkBuffer + valuesEndPosition,
michael@0 120 bufferSize - valuesEndPosition) == 0);
michael@0 121 if (expectSwap == NoSwap) {
michael@0 122 MOZ_RELEASE_ASSERT(memcmp(buffer + startPosition, values,
michael@0 123 nValues * sizeof(T)) == 0);
michael@0 124 }
michael@0 125 for (size_t i = 0; i < nValues; ++i) {
michael@0 126 MOZ_RELEASE_ASSERT(readerFunc(buffer + startPosition + sizeof(T) * i) ==
michael@0 127 values[i]);
michael@0 128 }
michael@0 129 }
michael@0 130 }
michael@0 131 }
michael@0 132
michael@0 133 template<typename T, size_t Count>
michael@0 134 void
michael@0 135 TestBulkSwapFromSub(enum SwapExpectation expectSwap,
michael@0 136 const T (&values)[Count],
michael@0 137 void (*swapperFunc)(T*, const void*, size_t),
michael@0 138 T (*readerFunc)(const void*))
michael@0 139 {
michael@0 140 const size_t arraySize = 2 * Count;
michael@0 141 const size_t bufferSize = arraySize * sizeof(T);
michael@0 142 static T buffer[arraySize];
michael@0 143 const uint8_t fillValue = 0xa5;
michael@0 144 static T checkBuffer[arraySize];
michael@0 145
michael@0 146 memset(checkBuffer, fillValue, bufferSize);
michael@0 147
michael@0 148 for (size_t startPosition = 0; startPosition < Count; ++startPosition) {
michael@0 149 for (size_t nValues = 0; nValues < (Count - startPosition); ++nValues) {
michael@0 150 memset(buffer, fillValue, bufferSize);
michael@0 151 swapperFunc(buffer + startPosition, values, nValues);
michael@0 152
michael@0 153 MOZ_RELEASE_ASSERT(memcmp(buffer, checkBuffer, startPosition * sizeof(T)) == 0);
michael@0 154 size_t valuesEndPosition = startPosition + nValues;
michael@0 155 MOZ_RELEASE_ASSERT(memcmp(buffer + valuesEndPosition,
michael@0 156 checkBuffer + valuesEndPosition,
michael@0 157 (arraySize - valuesEndPosition) * sizeof(T)) == 0);
michael@0 158 if (expectSwap == NoSwap) {
michael@0 159 MOZ_RELEASE_ASSERT(memcmp(buffer + startPosition, values,
michael@0 160 nValues * sizeof(T)) == 0);
michael@0 161 }
michael@0 162 for (size_t i = 0; i < nValues; ++i)
michael@0 163 MOZ_RELEASE_ASSERT(readerFunc(buffer + startPosition + i) == values[i]);
michael@0 164 }
michael@0 165 }
michael@0 166 }
michael@0 167
michael@0 168
michael@0 169 template<typename T, size_t Count>
michael@0 170 void
michael@0 171 TestBulkInPlaceSub(enum SwapExpectation expectSwap,
michael@0 172 const T (&values)[Count],
michael@0 173 void (*swapperFunc)(T* p, size_t),
michael@0 174 T (*readerFunc)(const void*))
michael@0 175 {
michael@0 176 const size_t bufferCount = 4 * Count;
michael@0 177 const size_t bufferSize = bufferCount * sizeof(T);
michael@0 178 static T buffer[bufferCount];
michael@0 179 const T fillValue = 0xa5;
michael@0 180 static T checkBuffer[bufferCount];
michael@0 181
michael@0 182 MOZ_RELEASE_ASSERT(bufferSize > 2 * sizeof(T));
michael@0 183
michael@0 184 memset(checkBuffer, fillValue, bufferSize);
michael@0 185
michael@0 186 for (size_t startPosition = 0; startPosition < Count; ++startPosition) {
michael@0 187 for (size_t nValues = 0; nValues < Count; ++nValues) {
michael@0 188 memset(buffer, fillValue, bufferSize);
michael@0 189 memcpy(buffer + startPosition, values, nValues * sizeof(T));
michael@0 190 swapperFunc(buffer + startPosition, nValues);
michael@0 191
michael@0 192 MOZ_RELEASE_ASSERT(memcmp(buffer, checkBuffer, startPosition * sizeof(T)) == 0);
michael@0 193 size_t valuesEndPosition = startPosition + nValues;
michael@0 194 MOZ_RELEASE_ASSERT(memcmp(buffer + valuesEndPosition,
michael@0 195 checkBuffer + valuesEndPosition,
michael@0 196 bufferSize - valuesEndPosition * sizeof(T)) == 0);
michael@0 197 if (expectSwap == NoSwap) {
michael@0 198 MOZ_RELEASE_ASSERT(memcmp(buffer + startPosition, values,
michael@0 199 nValues * sizeof(T)) == 0);
michael@0 200 }
michael@0 201 for (size_t i = 0; i < nValues; ++i)
michael@0 202 MOZ_RELEASE_ASSERT(readerFunc(buffer + startPosition + i) == values[i]);
michael@0 203 }
michael@0 204 }
michael@0 205 }
michael@0 206
michael@0 207 template<typename T>
michael@0 208 struct Reader
michael@0 209 {
michael@0 210 };
michael@0 211
michael@0 212 #define SPECIALIZE_READER(TYPE, READ_FUNC) \
michael@0 213 template<> \
michael@0 214 struct Reader<TYPE> \
michael@0 215 { \
michael@0 216 static TYPE readLE(const void* p) { return LittleEndian::READ_FUNC(p); } \
michael@0 217 static TYPE readBE(const void* p) { return BigEndian::READ_FUNC(p); } \
michael@0 218 };
michael@0 219
michael@0 220 SPECIALIZE_READER(uint16_t, readUint16)
michael@0 221 SPECIALIZE_READER(uint32_t, readUint32)
michael@0 222 SPECIALIZE_READER(uint64_t, readUint64)
michael@0 223 SPECIALIZE_READER(int16_t, readInt16)
michael@0 224 SPECIALIZE_READER(int32_t, readInt32)
michael@0 225 SPECIALIZE_READER(int64_t, readInt64)
michael@0 226
michael@0 227 template<typename T, size_t Count>
michael@0 228 void
michael@0 229 TestBulkSwap(const T (&bytes)[Count])
michael@0 230 {
michael@0 231 #if MOZ_LITTLE_ENDIAN
michael@0 232 TestBulkSwapToSub(Swap, bytes, copyAndSwapToBigEndian<T>, Reader<T>::readBE);
michael@0 233 TestBulkSwapFromSub(Swap, bytes, copyAndSwapFromBigEndian<T>, Reader<T>::readBE);
michael@0 234 TestBulkSwapToSub(Swap, bytes, copyAndSwapToNetworkOrder<T>, Reader<T>::readBE);
michael@0 235 TestBulkSwapFromSub(Swap, bytes, copyAndSwapFromNetworkOrder<T>, Reader<T>::readBE);
michael@0 236 #else
michael@0 237 TestBulkSwapToSub(Swap, bytes, copyAndSwapToLittleEndian<T>, Reader<T>::readLE);
michael@0 238 TestBulkSwapFromSub(Swap, bytes, copyAndSwapFromLittleEndian<T>, Reader<T>::readLE);
michael@0 239 #endif
michael@0 240 }
michael@0 241
michael@0 242 template<typename T, size_t Count>
michael@0 243 void
michael@0 244 TestBulkNoSwap(const T (&bytes)[Count])
michael@0 245 {
michael@0 246 #if MOZ_LITTLE_ENDIAN
michael@0 247 TestBulkSwapToSub(NoSwap, bytes, copyAndSwapToLittleEndian<T>, Reader<T>::readLE);
michael@0 248 TestBulkSwapFromSub(NoSwap, bytes, copyAndSwapFromLittleEndian<T>, Reader<T>::readLE);
michael@0 249 #else
michael@0 250 TestBulkSwapToSub(NoSwap, bytes, copyAndSwapToBigEndian<T>, Reader<T>::readBE);
michael@0 251 TestBulkSwapFromSub(NoSwap, bytes, copyAndSwapFromBigEndian<T>, Reader<T>::readBE);
michael@0 252 TestBulkSwapToSub(NoSwap, bytes, copyAndSwapToNetworkOrder<T>, Reader<T>::readBE);
michael@0 253 TestBulkSwapFromSub(NoSwap, bytes, copyAndSwapFromNetworkOrder<T>, Reader<T>::readBE);
michael@0 254 #endif
michael@0 255 }
michael@0 256
michael@0 257 template<typename T, size_t Count>
michael@0 258 void
michael@0 259 TestBulkInPlaceSwap(const T (&bytes)[Count])
michael@0 260 {
michael@0 261 #if MOZ_LITTLE_ENDIAN
michael@0 262 TestBulkInPlaceSub(Swap, bytes, swapToBigEndianInPlace<T>, Reader<T>::readBE);
michael@0 263 TestBulkInPlaceSub(Swap, bytes, swapFromBigEndianInPlace<T>, Reader<T>::readBE);
michael@0 264 TestBulkInPlaceSub(Swap, bytes, swapToNetworkOrderInPlace<T>, Reader<T>::readBE);
michael@0 265 TestBulkInPlaceSub(Swap, bytes, swapFromNetworkOrderInPlace<T>, Reader<T>::readBE);
michael@0 266 #else
michael@0 267 TestBulkInPlaceSub(Swap, bytes, swapToLittleEndianInPlace<T>, Reader<T>::readLE);
michael@0 268 TestBulkInPlaceSub(Swap, bytes, swapFromLittleEndianInPlace<T>, Reader<T>::readLE);
michael@0 269 #endif
michael@0 270 }
michael@0 271
michael@0 272 template<typename T, size_t Count>
michael@0 273 void
michael@0 274 TestBulkInPlaceNoSwap(const T (&bytes)[Count])
michael@0 275 {
michael@0 276 #if MOZ_LITTLE_ENDIAN
michael@0 277 TestBulkInPlaceSub(NoSwap, bytes, swapToLittleEndianInPlace<T>, Reader<T>::readLE);
michael@0 278 TestBulkInPlaceSub(NoSwap, bytes, swapFromLittleEndianInPlace<T>, Reader<T>::readLE);
michael@0 279 #else
michael@0 280 TestBulkInPlaceSub(NoSwap, bytes, swapToBigEndianInPlace<T>, Reader<T>::readBE);
michael@0 281 TestBulkInPlaceSub(NoSwap, bytes, swapFromBigEndianInPlace<T>, Reader<T>::readBE);
michael@0 282 TestBulkInPlaceSub(NoSwap, bytes, swapToNetworkOrderInPlace<T>, Reader<T>::readBE);
michael@0 283 TestBulkInPlaceSub(NoSwap, bytes, swapFromNetworkOrderInPlace<T>, Reader<T>::readBE);
michael@0 284 #endif
michael@0 285 }
michael@0 286
michael@0 287 int
michael@0 288 main()
michael@0 289 {
michael@0 290 static const uint8_t unsigned_bytes[16] = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8,
michael@0 291 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8 };
michael@0 292 static const int8_t signed_bytes[16] = { -0x0f, -0x0e, -0x0d, -0x0c, -0x0b, -0x0a, -0x09, -0x08,
michael@0 293 -0x0f, -0x0e, -0x0d, -0x0c, -0x0b, -0x0a, -0x09, -0x08 };
michael@0 294 static const uint16_t uint16_values[8] = { 0x102, 0x304, 0x506, 0x708, 0x102, 0x304, 0x506, 0x708 };
michael@0 295 static const int16_t int16_values[8] = { int16_t(0xf1f2), int16_t(0xf3f4), int16_t(0xf5f6), int16_t(0xf7f8),
michael@0 296 int16_t(0xf1f2), int16_t(0xf3f4), int16_t(0xf5f6), int16_t(0xf7f8) };
michael@0 297 static const uint32_t uint32_values[4] = { 0x1020304, 0x5060708, 0x1020304, 0x5060708 };
michael@0 298 static const int32_t int32_values[4] = { int32_t(0xf1f2f3f4), int32_t(0xf5f6f7f8),
michael@0 299 int32_t(0xf1f2f3f4), int32_t(0xf5f6f7f8) };
michael@0 300 static const uint64_t uint64_values[2] = { 0x102030405060708, 0x102030405060708 };
michael@0 301 static const int64_t int64_values[2] = { int64_t(0xf1f2f3f4f5f6f7f8),
michael@0 302 int64_t(0xf1f2f3f4f5f6f7f8) };
michael@0 303 uint8_t buffer[8];
michael@0 304
michael@0 305 MOZ_RELEASE_ASSERT(LittleEndian::readUint16(&unsigned_bytes[0]) == 0x201);
michael@0 306 MOZ_RELEASE_ASSERT(BigEndian::readUint16(&unsigned_bytes[0]) == 0x102);
michael@0 307
michael@0 308 MOZ_RELEASE_ASSERT(LittleEndian::readUint32(&unsigned_bytes[0]) == 0x4030201U);
michael@0 309 MOZ_RELEASE_ASSERT(BigEndian::readUint32(&unsigned_bytes[0]) == 0x1020304U);
michael@0 310
michael@0 311 MOZ_RELEASE_ASSERT(LittleEndian::readUint64(&unsigned_bytes[0]) == 0x807060504030201ULL);
michael@0 312 MOZ_RELEASE_ASSERT(BigEndian::readUint64(&unsigned_bytes[0]) == 0x102030405060708ULL);
michael@0 313
michael@0 314 LittleEndian::writeUint16(&buffer[0], 0x201);
michael@0 315 MOZ_RELEASE_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint16_t)) == 0);
michael@0 316 BigEndian::writeUint16(&buffer[0], 0x102);
michael@0 317 MOZ_RELEASE_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint16_t)) == 0);
michael@0 318
michael@0 319 LittleEndian::writeUint32(&buffer[0], 0x4030201U);
michael@0 320 MOZ_RELEASE_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint32_t)) == 0);
michael@0 321 BigEndian::writeUint32(&buffer[0], 0x1020304U);
michael@0 322 MOZ_RELEASE_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint32_t)) == 0);
michael@0 323
michael@0 324 LittleEndian::writeUint64(&buffer[0], 0x807060504030201ULL);
michael@0 325 MOZ_RELEASE_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint64_t)) == 0);
michael@0 326 BigEndian::writeUint64(&buffer[0], 0x102030405060708ULL);
michael@0 327 MOZ_RELEASE_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint64_t)) == 0);
michael@0 328
michael@0 329 MOZ_RELEASE_ASSERT(LittleEndian::readInt16(&signed_bytes[0]) == int16_t(0xf2f1));
michael@0 330 MOZ_RELEASE_ASSERT(BigEndian::readInt16(&signed_bytes[0]) == int16_t(0xf1f2));
michael@0 331
michael@0 332 MOZ_RELEASE_ASSERT(LittleEndian::readInt32(&signed_bytes[0]) == int32_t(0xf4f3f2f1));
michael@0 333 MOZ_RELEASE_ASSERT(BigEndian::readInt32(&signed_bytes[0]) == int32_t(0xf1f2f3f4));
michael@0 334
michael@0 335 MOZ_RELEASE_ASSERT(LittleEndian::readInt64(&signed_bytes[0]) == int64_t(0xf8f7f6f5f4f3f2f1LL));
michael@0 336 MOZ_RELEASE_ASSERT(BigEndian::readInt64(&signed_bytes[0]) == int64_t(0xf1f2f3f4f5f6f7f8LL));
michael@0 337
michael@0 338 LittleEndian::writeInt16(&buffer[0], 0xf2f1);
michael@0 339 MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int16_t)) == 0);
michael@0 340 BigEndian::writeInt16(&buffer[0], 0xf1f2);
michael@0 341 MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int16_t)) == 0);
michael@0 342
michael@0 343 LittleEndian::writeInt32(&buffer[0], 0xf4f3f2f1);
michael@0 344 MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int32_t)) == 0);
michael@0 345 BigEndian::writeInt32(&buffer[0], 0xf1f2f3f4);
michael@0 346 MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int32_t)) == 0);
michael@0 347
michael@0 348 LittleEndian::writeInt64(&buffer[0], 0xf8f7f6f5f4f3f2f1LL);
michael@0 349 MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int64_t)) == 0);
michael@0 350 BigEndian::writeInt64(&buffer[0], 0xf1f2f3f4f5f6f7f8LL);
michael@0 351 MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int64_t)) == 0);
michael@0 352
michael@0 353 TestSingleSwap(uint16_t(0xf2f1), uint16_t(0xf1f2));
michael@0 354 TestSingleSwap(uint32_t(0xf4f3f2f1), uint32_t(0xf1f2f3f4));
michael@0 355 TestSingleSwap(uint64_t(0xf8f7f6f5f4f3f2f1), uint64_t(0xf1f2f3f4f5f6f7f8));
michael@0 356
michael@0 357 TestSingleSwap(int16_t(0xf2f1), int16_t(0xf1f2));
michael@0 358 TestSingleSwap(int32_t(0xf4f3f2f1), int32_t(0xf1f2f3f4));
michael@0 359 TestSingleSwap(int64_t(0xf8f7f6f5f4f3f2f1), int64_t(0xf1f2f3f4f5f6f7f8));
michael@0 360
michael@0 361 TestSingleNoSwap(uint16_t(0xf2f1), uint16_t(0xf2f1));
michael@0 362 TestSingleNoSwap(uint32_t(0xf4f3f2f1), uint32_t(0xf4f3f2f1));
michael@0 363 TestSingleNoSwap(uint64_t(0xf8f7f6f5f4f3f2f1), uint64_t(0xf8f7f6f5f4f3f2f1));
michael@0 364
michael@0 365 TestSingleNoSwap(int16_t(0xf2f1), int16_t(0xf2f1));
michael@0 366 TestSingleNoSwap(int32_t(0xf4f3f2f1), int32_t(0xf4f3f2f1));
michael@0 367 TestSingleNoSwap(int64_t(0xf8f7f6f5f4f3f2f1), int64_t(0xf8f7f6f5f4f3f2f1));
michael@0 368
michael@0 369 TestBulkSwap(uint16_values);
michael@0 370 TestBulkSwap(int16_values);
michael@0 371 TestBulkSwap(uint32_values);
michael@0 372 TestBulkSwap(int32_values);
michael@0 373 TestBulkSwap(uint64_values);
michael@0 374 TestBulkSwap(int64_values);
michael@0 375
michael@0 376 TestBulkNoSwap(uint16_values);
michael@0 377 TestBulkNoSwap(int16_values);
michael@0 378 TestBulkNoSwap(uint32_values);
michael@0 379 TestBulkNoSwap(int32_values);
michael@0 380 TestBulkNoSwap(uint64_values);
michael@0 381 TestBulkNoSwap(int64_values);
michael@0 382
michael@0 383 TestBulkInPlaceSwap(uint16_values);
michael@0 384 TestBulkInPlaceSwap(int16_values);
michael@0 385 TestBulkInPlaceSwap(uint32_values);
michael@0 386 TestBulkInPlaceSwap(int32_values);
michael@0 387 TestBulkInPlaceSwap(uint64_values);
michael@0 388 TestBulkInPlaceSwap(int64_values);
michael@0 389
michael@0 390 TestBulkInPlaceNoSwap(uint16_values);
michael@0 391 TestBulkInPlaceNoSwap(int16_values);
michael@0 392 TestBulkInPlaceNoSwap(uint32_values);
michael@0 393 TestBulkInPlaceNoSwap(int32_values);
michael@0 394 TestBulkInPlaceNoSwap(uint64_values);
michael@0 395 TestBulkInPlaceNoSwap(int64_values);
michael@0 396
michael@0 397 return 0;
michael@0 398 }

mercurial