gem5  v21.0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MachineID.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 ARM Limited
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #ifndef __MEM_RUBY_COMMON_MACHINEID_HH__
42 #define __MEM_RUBY_COMMON_MACHINEID_HH__
43 
44 #include <iostream>
45 #include <string>
46 
47 #include "base/cprintf.hh"
48 #include "mem/ruby/protocol/MachineType.hh"
49 
50 struct MachineID
51 {
52  MachineID() : type(MachineType_NUM), num(0) { }
53  MachineID(MachineType mach_type, NodeID node_id)
54  : type(mach_type), num(node_id) { }
55 
56  MachineType type;
59 
60  MachineType getType() const { return type; }
61  NodeID getNum() const { return num; }
62 
63  bool isValid() const { return type != MachineType_NUM; }
64 };
65 
66 inline std::string
68 {
69  return csprintf("%s_%d", MachineType_to_string(machine.type), machine.num);
70 }
71 
72 inline bool
73 operator==(const MachineID & obj1, const MachineID & obj2)
74 {
75  return (obj1.type == obj2.type && obj1.num == obj2.num);
76 }
77 
78 inline bool
79 operator!=(const MachineID & obj1, const MachineID & obj2)
80 {
81  return (obj1.type != obj2.type || obj1.num != obj2.num);
82 }
83 
84 namespace std {
85  template<>
86  struct hash<MachineID> {
87  inline size_t operator()(const MachineID& id) const {
88  size_t hval = MachineType_base_level(id.type) << 16 | id.num;
89  return hval;
90  }
91  };
92 }
93 
94 // Output operator declaration
95 std::ostream& operator<<(std::ostream& out, const MachineID& obj);
96 
97 inline std::ostream&
98 operator<<(std::ostream& out, const MachineID& obj)
99 {
100  if ((obj.type < MachineType_NUM) && (obj.type >= MachineType_FIRST)) {
101  out << MachineType_to_string(obj.type);
102  } else {
103  out << "NULL";
104  }
105  out << "-";
106  out << obj.num;
107  out << std::flush;
108  return out;
109 }
110 
111 #endif // __MEM_RUBY_COMMON_MACHINEID_HH__
MachineID::type
MachineType type
Definition: MachineID.hh:56
std::hash< MachineID >::operator()
size_t operator()(const MachineID &id) const
Definition: MachineID.hh:87
MachineID::getType
MachineType getType() const
Definition: MachineID.hh:60
operator!=
bool operator!=(const MachineID &obj1, const MachineID &obj2)
Definition: MachineID.hh:79
MachineID::MachineID
MachineID(MachineType mach_type, NodeID node_id)
Definition: MachineID.hh:53
MachineID
Definition: MachineID.hh:50
MachineID::getNum
NodeID getNum() const
Definition: MachineID.hh:61
cprintf.hh
MachineID::isValid
bool isValid() const
Definition: MachineID.hh:63
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
MachineID::num
NodeID num
range: 0 ... number of this machine's components in system - 1
Definition: MachineID.hh:58
NodeID
unsigned int NodeID
Definition: TypeDefines.hh:34
X86ISA::type
type
Definition: misc.hh:727
operator<<
std::ostream & operator<<(std::ostream &out, const MachineID &obj)
Definition: MachineID.hh:98
MachineIDToString
std::string MachineIDToString(MachineID machine)
Definition: MachineID.hh:67
MachineID::MachineID
MachineID()
Definition: MachineID.hh:52
operator==
bool operator==(const MachineID &obj1, const MachineID &obj2)
Definition: MachineID.hh:73
csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158

Generated on Tue Jun 22 2021 15:28:29 for gem5 by doxygen 1.8.17