Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame^] | 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 WriteUint32(unsigned char* buffer, unsigned int offset, uint32_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 | } |
| 25 | |
| 26 | void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value) |
| 27 | { |
| 28 | BOOST_ASSERT(buffer != nullptr); |
| 29 | |
| 30 | buffer[offset] = static_cast<unsigned char>(value & 0xFF); |
| 31 | buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF); |
| 32 | } |
| 33 | |
| 34 | uint32_t ReadUint32(const unsigned char* buffer, unsigned int offset) |
| 35 | { |
| 36 | BOOST_ASSERT(buffer); |
| 37 | |
| 38 | uint32_t value = 0; |
| 39 | value = static_cast<uint32_t>(buffer[offset]); |
| 40 | value |= static_cast<uint32_t>(buffer[offset + 1]) << 8; |
| 41 | value |= static_cast<uint32_t>(buffer[offset + 2]) << 16; |
| 42 | value |= static_cast<uint32_t>(buffer[offset + 3]) << 24; |
| 43 | return value; |
| 44 | } |
| 45 | |
| 46 | uint16_t ReadUint16(const unsigned char* buffer, unsigned int offset) |
| 47 | { |
| 48 | BOOST_ASSERT(buffer); |
| 49 | |
| 50 | uint32_t value = 0; |
| 51 | value = static_cast<uint32_t>(buffer[offset]); |
| 52 | value |= static_cast<uint32_t>(buffer[offset + 1]) << 8; |
| 53 | return static_cast<uint16_t>(value); |
| 54 | } |
| 55 | |
| 56 | } // namespace profiling |
| 57 | |
| 58 | } // namespace armnn |