| 1 | // |
| 2 | // Copyright 2017 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // sys_byteorder.h: Compatiblity hacks for importing Chromium's base/SHA1. |
| 7 | |
| 8 | #ifndef ANGLEBASE_SYS_BYTEORDER_H_ |
| 9 | #define ANGLEBASE_SYS_BYTEORDER_H_ |
| 10 | |
| 11 | namespace angle |
| 12 | { |
| 13 | |
| 14 | namespace base |
| 15 | { |
| 16 | |
| 17 | // Returns a value with all bytes in |x| swapped, i.e. reverses the endianness. |
| 18 | inline uint16_t ByteSwap(uint16_t x) |
| 19 | { |
| 20 | #if defined(_MSC_VER) |
| 21 | return _byteswap_ushort(x); |
| 22 | #else |
| 23 | return __builtin_bswap16(x); |
| 24 | #endif |
| 25 | } |
| 26 | |
| 27 | inline uint32_t ByteSwap(uint32_t x) |
| 28 | { |
| 29 | #if defined(_MSC_VER) |
| 30 | return _byteswap_ulong(x); |
| 31 | #else |
| 32 | return __builtin_bswap32(x); |
| 33 | #endif |
| 34 | } |
| 35 | |
| 36 | inline uint64_t ByteSwap(uint64_t x) |
| 37 | { |
| 38 | #if defined(_MSC_VER) |
| 39 | return _byteswap_uint64(x); |
| 40 | #else |
| 41 | return __builtin_bswap64(x); |
| 42 | #endif |
| 43 | } |
| 44 | |
| 45 | } // namespace base |
| 46 | |
| 47 | } // namespace angle |
| 48 | |
| 49 | #endif // ANGLEBASE_SYS_BYTEORDER_H_ |