Nikhil Raj | 7dcc697 | 2021-04-30 15:44:24 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <stdint.h> |
| 10 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 11 | namespace arm |
Nikhil Raj | 7dcc697 | 2021-04-30 15:44:24 +0100 | [diff] [blame] | 12 | { |
| 13 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 14 | namespace pipe |
Nikhil Raj | 7dcc697 | 2021-04-30 15:44:24 +0100 | [diff] [blame] | 15 | { |
| 16 | |
| 17 | static constexpr uint64_t MIN_STATIC_GUID = 1llu << 63; |
| 18 | |
| 19 | class ProfilingGuid |
| 20 | { |
| 21 | public: |
| 22 | ProfilingGuid() : m_Guid(0) {} |
| 23 | |
| 24 | ProfilingGuid(uint64_t guid) : m_Guid(guid) {} |
| 25 | |
| 26 | operator uint64_t() const { return m_Guid; } |
| 27 | |
| 28 | bool operator==(const ProfilingGuid& other) const |
| 29 | { |
| 30 | return m_Guid == other.m_Guid; |
| 31 | } |
| 32 | |
| 33 | bool operator!=(const ProfilingGuid& other) const |
| 34 | { |
| 35 | return m_Guid != other.m_Guid; |
| 36 | } |
| 37 | |
| 38 | bool operator<(const ProfilingGuid& other) const |
| 39 | { |
| 40 | return m_Guid < other.m_Guid; |
| 41 | } |
| 42 | |
| 43 | bool operator<=(const ProfilingGuid& other) const |
| 44 | { |
| 45 | return m_Guid <= other.m_Guid; |
| 46 | } |
| 47 | |
| 48 | bool operator>(const ProfilingGuid& other) const |
| 49 | { |
| 50 | return m_Guid > other.m_Guid; |
| 51 | } |
| 52 | |
| 53 | bool operator>=(const ProfilingGuid& other) const |
| 54 | { |
| 55 | return m_Guid >= other.m_Guid; |
| 56 | } |
| 57 | |
| 58 | protected: |
| 59 | uint64_t m_Guid; |
| 60 | }; |
| 61 | |
| 62 | /// Strongly typed guids to distinguish between those generated at runtime, and those that are statically defined. |
| 63 | struct ProfilingDynamicGuid : public ProfilingGuid |
| 64 | { |
| 65 | using ProfilingGuid::ProfilingGuid; |
| 66 | }; |
| 67 | |
| 68 | struct ProfilingStaticGuid : public ProfilingGuid |
| 69 | { |
| 70 | using ProfilingGuid::ProfilingGuid; |
| 71 | }; |
| 72 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 73 | } // namespace pipe |
Nikhil Raj | 7dcc697 | 2021-04-30 15:44:24 +0100 | [diff] [blame] | 74 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 75 | } // namespace arm |
Nikhil Raj | 7dcc697 | 2021-04-30 15:44:24 +0100 | [diff] [blame] | 76 | |
| 77 | |
| 78 | |
| 79 | namespace std |
| 80 | { |
| 81 | /// make ProfilingGuid hashable |
| 82 | template <> |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 83 | struct hash<arm::pipe::ProfilingGuid> |
Nikhil Raj | 7dcc697 | 2021-04-30 15:44:24 +0100 | [diff] [blame] | 84 | { |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 85 | std::size_t operator()(arm::pipe::ProfilingGuid const& guid) const noexcept |
Nikhil Raj | 7dcc697 | 2021-04-30 15:44:24 +0100 | [diff] [blame] | 86 | { |
| 87 | return hash<uint64_t>()(uint64_t(guid)); |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | /// make ProfilingDynamicGuid hashable |
| 92 | template <> |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 93 | struct hash<arm::pipe::ProfilingDynamicGuid> |
Nikhil Raj | 7dcc697 | 2021-04-30 15:44:24 +0100 | [diff] [blame] | 94 | { |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 95 | std::size_t operator()(arm::pipe::ProfilingDynamicGuid const& guid) const noexcept |
Nikhil Raj | 7dcc697 | 2021-04-30 15:44:24 +0100 | [diff] [blame] | 96 | { |
| 97 | return hash<uint64_t>()(uint64_t(guid)); |
| 98 | } |
| 99 | }; |
| 100 | |
| 101 | /// make ProfilingStaticGuid hashable |
| 102 | template <> |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 103 | struct hash<arm::pipe::ProfilingStaticGuid> |
Nikhil Raj | 7dcc697 | 2021-04-30 15:44:24 +0100 | [diff] [blame] | 104 | { |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 105 | std::size_t operator()(arm::pipe::ProfilingStaticGuid const& guid) const noexcept |
Nikhil Raj | 7dcc697 | 2021-04-30 15:44:24 +0100 | [diff] [blame] | 106 | { |
| 107 | return hash<uint64_t>()(uint64_t(guid)); |
| 108 | } |
| 109 | }; |
| 110 | |
| 111 | } // namespace std |