DebugServer2
Loading...
Searching...
No Matches
SwapEndian.h
1//
2// Copyright (c) 2014-present, Facebook, Inc.
3// All rights reserved.
4//
5// This source code is licensed under the University of Illinois/NCSA Open
6// Source License found in the LICENSE file in the root directory of this
7// source tree. An additional grant of patent rights can be found in the
8// PATENTS file in the same directory.
9//
10
11#pragma once
12
13#include <cstdint>
14
15namespace ds2 {
16
17static constexpr uint16_t Swap16(uint16_t x) { return (x >> 8) | (x << 8); }
18
19static constexpr uint32_t Swap32(uint32_t x) {
20 return Swap16(x >> 16) | (Swap16(x & 0xffff) << 16);
21}
22
23static constexpr uint64_t Swap64(uint64_t x) {
24 return Swap32(x >> 32) |
25 (static_cast<uint64_t>(Swap32(x & 0xffffffff)) << 32);
26}
27} // namespace ds2