xref: /aosp_15_r20/external/angle/src/common/base/anglebase/sys_byteorder.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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 #include <cstdlib>
12 
13 namespace angle
14 {
15 
16 namespace base
17 {
18 
19 // Returns a value with all bytes in |x| swapped, i.e. reverses the endianness.
ByteSwap(uint16_t x)20 inline uint16_t ByteSwap(uint16_t x)
21 {
22 #if defined(_MSC_VER)
23     return _byteswap_ushort(x);
24 #else
25     return __builtin_bswap16(x);
26 #endif
27 }
28 
ByteSwap(uint32_t x)29 inline uint32_t ByteSwap(uint32_t x)
30 {
31 #if defined(_MSC_VER)
32     return _byteswap_ulong(x);
33 #else
34     return __builtin_bswap32(x);
35 #endif
36 }
37 
ByteSwap(uint64_t x)38 inline uint64_t ByteSwap(uint64_t x)
39 {
40 #if defined(_MSC_VER)
41     return _byteswap_uint64(x);
42 #else
43     return __builtin_bswap64(x);
44 #endif
45 }
46 
47 }  // namespace base
48 
49 }  // namespace angle
50 
51 #endif  // ANGLEBASE_SYS_BYTEORDER_H_
52