Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | #pragma once |
| 6 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 7 | #include <cstdint> |
| 8 | #include <string> |
| 9 | #include <ostream> |
| 10 | #include <sstream> |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 11 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 12 | namespace armnn |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 13 | { |
| 14 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 15 | namespace profiling |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 16 | { |
| 17 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 18 | constexpr inline uint32_t EncodeVersion(uint32_t major, uint32_t minor, uint32_t patch) |
| 19 | { |
| 20 | return (major << 22) | (minor << 12) | patch; |
| 21 | } |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 22 | |
| 23 | // Encodes a semantic version https://semver.org/ into a 32 bit integer in the following fashion |
| 24 | // |
| 25 | // bits 22:31 major: Unsigned 10-bit integer. Major component of the schema version number. |
| 26 | // bits 12:21 minor: Unsigned 10-bit integer. Minor component of the schema version number. |
| 27 | // bits 0:11 patch: Unsigned 12-bit integer. Patch component of the schema version number. |
| 28 | // |
| 29 | class Version |
| 30 | { |
| 31 | public: |
| 32 | Version(uint32_t encodedValue) |
| 33 | { |
| 34 | m_Major = (encodedValue >> 22) & 1023; |
| 35 | m_Minor = (encodedValue >> 12) & 1023; |
| 36 | m_Patch = encodedValue & 4095; |
| 37 | } |
| 38 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 39 | Version(uint32_t major, uint32_t minor, uint32_t patch) : |
| 40 | m_Major(major), |
| 41 | m_Minor(minor), |
| 42 | m_Patch(patch) |
| 43 | {} |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 44 | |
| 45 | uint32_t GetEncodedValue() |
| 46 | { |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 47 | return EncodeVersion(m_Major, m_Minor, m_Patch); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 48 | } |
| 49 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 50 | uint32_t GetMajor() { return m_Major; } |
| 51 | uint32_t GetMinor() { return m_Minor; } |
| 52 | uint32_t GetPatch() { return m_Patch; } |
| 53 | |
| 54 | bool operator==(const Version& other) const |
| 55 | { |
| 56 | return m_Major == other.m_Major && m_Minor == other.m_Minor && m_Patch == other.m_Patch; |
| 57 | } |
| 58 | |
| 59 | std::string ToString() const |
| 60 | { |
| 61 | constexpr char separator = '.'; |
| 62 | |
| 63 | std::stringstream stringStream; |
| 64 | stringStream << m_Major << separator << m_Minor << separator << m_Patch; |
| 65 | |
| 66 | return stringStream.str(); |
| 67 | } |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 68 | |
| 69 | private: |
| 70 | uint32_t m_Major; |
| 71 | uint32_t m_Minor; |
| 72 | uint32_t m_Patch; |
| 73 | }; |
| 74 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 75 | inline std::ostream& operator<<(std::ostream& os, const Version& version) |
| 76 | { |
| 77 | os << version.ToString(); |
| 78 | return os; |
| 79 | } |
| 80 | |
| 81 | } // namespace profiling |
| 82 | |
| 83 | } // namespace armnn |