Skip to content

Commit 9b6d824

Browse files
move operator==() and hash function of t_rr_switch_inf to physical_types.cpp
1 parent ebf88f0 commit 9b6d824

File tree

3 files changed

+49
-48
lines changed

3 files changed

+49
-48
lines changed

libs/libarchfpga/src/physical_types.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,47 @@ bool t_rr_switch_inf::configurable() const {
7171
return switch_type_is_configurable(type());
7272
}
7373

74+
bool t_rr_switch_inf::operator==(const t_rr_switch_inf& other) const {
75+
return R == other.R &&
76+
Cin == other.Cin &&
77+
Cout == other.Cout &&
78+
Cinternal == other.Cinternal &&
79+
Tdel == other.Tdel &&
80+
mux_trans_size == other.mux_trans_size &&
81+
buf_size == other.buf_size &&
82+
power_buffer_type == other.power_buffer_type &&
83+
power_buffer_size == other.power_buffer_size &&
84+
intra_tile == other.intra_tile &&
85+
type() == other.type();
86+
}
87+
88+
std::size_t t_rr_switch_inf::Hasher::operator()(const t_rr_switch_inf& s) const {
89+
std::size_t seed = 0;
90+
91+
auto hash_combine = [&seed](auto&& val) {
92+
seed ^= std::hash<std::decay_t<decltype(val)>>{}(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
93+
};
94+
95+
hash_combine(s.R);
96+
hash_combine(s.Cin);
97+
hash_combine(s.Cout);
98+
hash_combine(s.Cinternal);
99+
hash_combine(s.Tdel);
100+
hash_combine(s.mux_trans_size);
101+
hash_combine(s.buf_size);
102+
hash_combine(static_cast<int>(s.power_buffer_type));
103+
hash_combine(s.power_buffer_size);
104+
hash_combine(s.intra_tile);
105+
hash_combine(static_cast<int>(s.type()));
106+
107+
return seed;
108+
}
109+
74110
void t_rr_switch_inf::set_type(SwitchType type_val) {
75111
type_ = type_val;
76112
}
77113

114+
78115
static bool switch_type_is_buffered(SwitchType type) {
79116
//Muxes and Tristates isolate their input and output into
80117
//separate DC connected sub-circuits
@@ -360,4 +397,4 @@ const t_physical_tile_port* t_sub_tile::get_port_by_pin(int pin) const {
360397
}
361398

362399
return nullptr;
363-
}
400+
}

libs/libarchfpga/src/physical_types.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,16 +1917,22 @@ struct t_rr_switch_inf {
19171917
bool intra_tile = false;
19181918

19191919
public:
1920-
//Returns the type of switch
1920+
/// Returns the type of switch
19211921
SwitchType type() const;
19221922

1923-
//Returns true if this switch type isolates its input and output into
1924-
//separate DC-connected subcircuits
1923+
/// Returns true if this switch type isolates its input and output into
1924+
/// separate DC-connected subcircuits
19251925
bool buffered() const;
19261926

1927-
//Returns true if this switch type is configurable
1927+
/// Returns true if this switch type is configurable
19281928
bool configurable() const;
19291929

1930+
bool operator==(const t_rr_switch_inf& other) const;
1931+
1932+
struct Hasher {
1933+
std::size_t operator()(const t_rr_switch_inf& s) const;
1934+
};
1935+
19301936
public:
19311937
void set_type(SwitchType type_val);
19321938

libs/librrgraph/src/io/rr_graph_reader.cpp

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -172,55 +172,13 @@ static RREdgeId process_rr_edge_override(const std::string& line,
172172
return edge_id;
173173
}
174174

175-
struct t_rr_switch_inf_hash {
176-
std::size_t operator()(const t_rr_switch_inf& s) const {
177-
std::size_t seed = 0;
178-
179-
// Helper function for hashing
180-
auto hash_combine = [&seed](auto&& val) {
181-
seed ^= std::hash<std::decay_t<decltype(val)>>{}(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
182-
};
183-
184-
// Combine all relevant fields
185-
hash_combine(s.R);
186-
hash_combine(s.Cin);
187-
hash_combine(s.Cout);
188-
hash_combine(s.Cinternal);
189-
hash_combine(s.Tdel);
190-
hash_combine(s.mux_trans_size);
191-
hash_combine(s.buf_size);
192-
hash_combine(static_cast<int>(s.power_buffer_type));
193-
hash_combine(s.power_buffer_size);
194-
hash_combine(s.intra_tile);
195-
hash_combine(static_cast<int>(s.type()));
196-
197-
return seed;
198-
}
199-
};
200-
201-
struct t_rr_switch_inf_equal {
202-
bool operator()(const t_rr_switch_inf& lhs, const t_rr_switch_inf& rhs) const {
203-
return lhs.R == rhs.R &&
204-
lhs.Cin == rhs.Cin &&
205-
lhs.Cout == rhs.Cout &&
206-
lhs.Cinternal == rhs.Cinternal &&
207-
lhs.Tdel == rhs.Tdel &&
208-
lhs.mux_trans_size == rhs.mux_trans_size &&
209-
lhs.buf_size == rhs.buf_size &&
210-
lhs.power_buffer_type == rhs.power_buffer_type &&
211-
lhs.power_buffer_size == rhs.power_buffer_size &&
212-
lhs.intra_tile == rhs.intra_tile &&
213-
lhs.type() == rhs.type();
214-
}
215-
};
216-
217175
void load_rr_edge_delay_overrides(std::string_view filename,
218176
RRGraphBuilder& rr_graph_builder,
219177
const RRGraphView& rr_graph) {
220178
std::ifstream file(filename.data());
221179
VTR_LOGV_ERROR(!file, "Failed to open the RR edge override file: %s\n", filename.data());
222180

223-
std::unordered_map<t_rr_switch_inf, RRSwitchId, t_rr_switch_inf_hash, t_rr_switch_inf_equal> unique_switch_info;
181+
std::unordered_map<t_rr_switch_inf, RRSwitchId, t_rr_switch_inf::Hasher> unique_switch_info;
224182
for (const auto& [rr_sw_idx, sw] : rr_graph.rr_switch().pairs()) {
225183
unique_switch_info.insert({sw, rr_sw_idx});
226184
}

0 commit comments

Comments
 (0)