| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef WTF_ByteSwap_h | 31 #ifndef WTF_ByteSwap_h |
| 32 #define WTF_ByteSwap_h | 32 #define WTF_ByteSwap_h |
| 33 | 33 |
| 34 #include "wtf/CPU.h" | 34 #include "wtf/CPU.h" |
| 35 #include "wtf/Compiler.h" | 35 #include "wtf/Compiler.h" |
| 36 | 36 |
| 37 #include <stdint.h> | 37 #include <stdint.h> |
| 38 | 38 |
| 39 #if COMPILER(MSVC) | |
| 40 #include <stdlib.h> | |
| 41 #endif | |
| 42 | |
| 43 namespace WTF { | 39 namespace WTF { |
| 44 | 40 |
| 45 inline uint32_t wswap32(uint32_t x) { return ((x & 0xffff0000) >> 16) | ((x & 0x
0000ffff) << 16); } | 41 inline uint32_t wswap32(uint32_t x) { return ((x & 0xffff0000) >> 16) | ((x & 0x
0000ffff) << 16); } |
| 46 | 42 |
| 47 #if COMPILER(MSVC) | |
| 48 | |
| 49 ALWAYS_INLINE uint64_t bswap64(uint64_t x) { return _byteswap_uint64(x); } | |
| 50 ALWAYS_INLINE uint32_t bswap32(uint32_t x) { return _byteswap_ulong(x); } | |
| 51 ALWAYS_INLINE uint16_t bswap16(uint16_t x) { return _byteswap_ushort(x); } | |
| 52 | |
| 53 #else | |
| 54 | |
| 55 ALWAYS_INLINE uint64_t bswap64(uint64_t x) { return __builtin_bswap64(x); } | 43 ALWAYS_INLINE uint64_t bswap64(uint64_t x) { return __builtin_bswap64(x); } |
| 56 ALWAYS_INLINE uint32_t bswap32(uint32_t x) { return __builtin_bswap32(x); } | 44 ALWAYS_INLINE uint32_t bswap32(uint32_t x) { return __builtin_bswap32(x); } |
| 57 // GCC 4.6 lacks __builtin_bswap16. Newer versions have it but we support 4.6. | 45 // GCC 4.6 lacks __builtin_bswap16. Newer versions have it but we support 4.6. |
| 58 #if COMPILER(CLANG) | 46 #if COMPILER(CLANG) |
| 59 ALWAYS_INLINE uint16_t bswap16(uint16_t x) { return __builtin_bswap16(x); } | 47 ALWAYS_INLINE uint16_t bswap16(uint16_t x) { return __builtin_bswap16(x); } |
| 60 #else | 48 #else |
| 61 inline uint16_t bswap16(uint16_t x) { return ((x & 0xff00) >> 8) | ((x & 0x00ff)
<< 8); } | 49 inline uint16_t bswap16(uint16_t x) { return ((x & 0xff00) >> 8) | ((x & 0x00ff)
<< 8); } |
| 62 #endif | 50 #endif |
| 63 | 51 |
| 64 #endif | |
| 65 | |
| 66 #if CPU(64BIT) | 52 #if CPU(64BIT) |
| 67 | 53 |
| 68 ALWAYS_INLINE size_t bswapuintptrt(size_t x) { return bswap64(x); } | 54 ALWAYS_INLINE size_t bswapuintptrt(size_t x) { return bswap64(x); } |
| 69 | 55 |
| 70 #else | 56 #else |
| 71 | 57 |
| 72 ALWAYS_INLINE size_t bswapuintptrt(size_t x) { return bswap32(x); } | 58 ALWAYS_INLINE size_t bswapuintptrt(size_t x) { return bswap32(x); } |
| 73 | 59 |
| 74 #endif | 60 #endif |
| 75 | 61 |
| 76 } // namespace WTF | 62 } // namespace WTF |
| 77 | 63 |
| 78 #endif // WTF_ByteSwap_h | 64 #endif // WTF_ByteSwap_h |
| OLD | NEW |