| 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 24 matching lines...) Expand all Loading... |
| 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) | 39 #if COMPILER(MSVC) |
| 40 #include <stdlib.h> | 40 #include <stdlib.h> |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 namespace WTF { | 43 namespace WTF { |
| 44 | 44 |
| 45 inline uint32_t wswap32(uint32_t x) { return ((x & 0xffff0000) >> 16) | ((x & 0x
0000ffff) << 16); } | 45 inline uint32_t wswap32(uint32_t x) { |
| 46 return ((x & 0xffff0000) >> 16) | ((x & 0x0000ffff) << 16); |
| 47 } |
| 46 | 48 |
| 47 #if COMPILER(MSVC) | 49 #if COMPILER(MSVC) |
| 48 | 50 |
| 49 ALWAYS_INLINE uint64_t bswap64(uint64_t x) { return _byteswap_uint64(x); } | 51 ALWAYS_INLINE uint64_t bswap64(uint64_t x) { |
| 50 ALWAYS_INLINE uint32_t bswap32(uint32_t x) { return _byteswap_ulong(x); } | 52 return _byteswap_uint64(x); |
| 51 ALWAYS_INLINE uint16_t bswap16(uint16_t x) { return _byteswap_ushort(x); } | 53 } |
| 54 ALWAYS_INLINE uint32_t bswap32(uint32_t x) { |
| 55 return _byteswap_ulong(x); |
| 56 } |
| 57 ALWAYS_INLINE uint16_t bswap16(uint16_t x) { |
| 58 return _byteswap_ushort(x); |
| 59 } |
| 52 | 60 |
| 53 #else | 61 #else |
| 54 | 62 |
| 55 ALWAYS_INLINE uint64_t bswap64(uint64_t x) { return __builtin_bswap64(x); } | 63 ALWAYS_INLINE uint64_t bswap64(uint64_t x) { |
| 56 ALWAYS_INLINE uint32_t bswap32(uint32_t x) { return __builtin_bswap32(x); } | 64 return __builtin_bswap64(x); |
| 57 ALWAYS_INLINE uint16_t bswap16(uint16_t x) { return __builtin_bswap16(x); } | 65 } |
| 66 ALWAYS_INLINE uint32_t bswap32(uint32_t x) { |
| 67 return __builtin_bswap32(x); |
| 68 } |
| 69 ALWAYS_INLINE uint16_t bswap16(uint16_t x) { |
| 70 return __builtin_bswap16(x); |
| 71 } |
| 58 | 72 |
| 59 #endif | 73 #endif |
| 60 | 74 |
| 61 #if CPU(64BIT) | 75 #if CPU(64BIT) |
| 62 | 76 |
| 63 ALWAYS_INLINE size_t bswapuintptrt(size_t x) { return bswap64(x); } | 77 ALWAYS_INLINE size_t bswapuintptrt(size_t x) { |
| 78 return bswap64(x); |
| 79 } |
| 64 | 80 |
| 65 #else | 81 #else |
| 66 | 82 |
| 67 ALWAYS_INLINE size_t bswapuintptrt(size_t x) { return bswap32(x); } | 83 ALWAYS_INLINE size_t bswapuintptrt(size_t x) { |
| 84 return bswap32(x); |
| 85 } |
| 68 | 86 |
| 69 #endif | 87 #endif |
| 70 | 88 |
| 71 } // namespace WTF | 89 } // namespace WTF |
| 72 | 90 |
| 73 #endif // WTF_ByteSwap_h | 91 #endif // WTF_ByteSwap_h |
| OLD | NEW |