IVGCVSW-3692 Implement SendPeriodicCounterCapturePacket() function
[platform/upstream/armnn.git] / src / profiling / ProfilingUtils.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "ProfilingUtils.hpp"
7
8 #include <boost/assert.hpp>
9
10 namespace armnn
11 {
12
13 namespace profiling
14 {
15
16 void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value)
17 {
18     BOOST_ASSERT(buffer);
19
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);
28 }
29
30 void WriteUint32(unsigned char* buffer, unsigned int offset, uint32_t value)
31 {
32     BOOST_ASSERT(buffer);
33
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);
38 }
39
40 void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value)
41 {
42     BOOST_ASSERT(buffer != nullptr);
43
44     buffer[offset] = static_cast<unsigned char>(value & 0xFF);
45     buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
46 }
47
48 uint64_t ReadUint64(const unsigned char* buffer, unsigned int offset)
49 {
50     BOOST_ASSERT(buffer);
51
52     uint64_t value = 0;
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;
61
62     return value;
63 }
64
65 uint32_t ReadUint32(const unsigned char* buffer, unsigned int offset)
66 {
67     BOOST_ASSERT(buffer);
68
69     uint32_t value = 0;
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;
74     return value;
75 }
76
77 uint16_t ReadUint16(const unsigned char* buffer, unsigned int offset)
78 {
79     BOOST_ASSERT(buffer);
80
81     uint32_t value = 0;
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);
85 }
86
87 } // namespace profiling
88
89 } // namespace armnn