2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "ProfilingUtils.hpp"
8 #include <boost/assert.hpp>
16 void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value)
20 buffer[offset] = static_cast<unsigned char>(value & 0xFF);
21 buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
22 buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF);
23 buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF);
24 buffer[offset + 4] = static_cast<unsigned char>((value >> 32) & 0xFF);
25 buffer[offset + 5] = static_cast<unsigned char>((value >> 40) & 0xFF);
26 buffer[offset + 6] = static_cast<unsigned char>((value >> 48) & 0xFF);
27 buffer[offset + 7] = static_cast<unsigned char>((value >> 56) & 0xFF);
30 void WriteUint32(unsigned char* buffer, unsigned int offset, uint32_t value)
34 buffer[offset] = static_cast<unsigned char>(value & 0xFF);
35 buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
36 buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF);
37 buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF);
40 void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value)
42 BOOST_ASSERT(buffer != nullptr);
44 buffer[offset] = static_cast<unsigned char>(value & 0xFF);
45 buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
48 uint64_t ReadUint64(const unsigned char* buffer, unsigned int offset)
53 value = static_cast<uint64_t>(buffer[offset]);
54 value |= static_cast<uint64_t>(buffer[offset + 1]) << 8;
55 value |= static_cast<uint64_t>(buffer[offset + 2]) << 16;
56 value |= static_cast<uint64_t>(buffer[offset + 3]) << 24;
57 value |= static_cast<uint64_t>(buffer[offset + 4]) << 32;
58 value |= static_cast<uint64_t>(buffer[offset + 5]) << 40;
59 value |= static_cast<uint64_t>(buffer[offset + 6]) << 48;
60 value |= static_cast<uint64_t>(buffer[offset + 7]) << 56;
65 uint32_t ReadUint32(const unsigned char* buffer, unsigned int offset)
70 value = static_cast<uint32_t>(buffer[offset]);
71 value |= static_cast<uint32_t>(buffer[offset + 1]) << 8;
72 value |= static_cast<uint32_t>(buffer[offset + 2]) << 16;
73 value |= static_cast<uint32_t>(buffer[offset + 3]) << 24;
77 uint16_t ReadUint16(const unsigned char* buffer, unsigned int offset)
82 value = static_cast<uint32_t>(buffer[offset]);
83 value |= static_cast<uint32_t>(buffer[offset + 1]) << 8;
84 return static_cast<uint16_t>(value);
87 } // namespace profiling