Skip to content

Commit 9b48529

Browse files
sanpar-qcomeyck
authored andcommitted
core_complex: simplify end range check logics/functions
1 parent a7af558 commit 9b48529

1 file changed

Lines changed: 9 additions & 26 deletions

File tree

src/sysc/core_complex.cpp

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,8 @@ namespace {
8989
iss::debugger::encoder_decoder encdec;
9090
std::array<const char, 4> lvl = {{'U', 'S', 'H', 'M'}};
9191

92-
inline bool is_within_dmi_range(uint64_t start, unsigned length, uint64_t inclusive_end) {
93-
if(length == 0) {
94-
return true;
95-
}
96-
if(start > inclusive_end) {
97-
return false;
98-
}
99-
return static_cast<uint64_t>(length - 1) <= (inclusive_end - start);
100-
}
101-
102-
inline bool is_invalidate_end_covered(uint64_t end, uint64_t inclusive_end) {
103-
if(end <= inclusive_end) {
104-
return true;
105-
}
106-
return inclusive_end != std::numeric_limits<uint64_t>::max() && end == (inclusive_end + 1);
92+
inline bool is_in_end_range(uint64_t end, uint64_t inclusive_range_end) {
93+
return (end <= inclusive_range_end) || ((end >= 0) && ((end - 1) <= inclusive_range_end));
10794
}
10895
} // namespace
10996

@@ -208,22 +195,20 @@ template <unsigned int BUSWIDTH, typename QK> void core_complex<BUSWIDTH, QK>::i
208195
core_complex_if::exec_on_sysc = util::delegate<void(std::function<void(void)>&)>::from<this_class, &this_class::exec_on_sysc<QK>>(this);
209196
ibus.register_invalidate_direct_mem_ptr([this](uint64_t start, uint64_t end) -> void {
210197
auto lut_entry = fetch_lut.getEntry(start);
211-
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE && is_invalidate_end_covered(end, lut_entry.get_end_address())) {
198+
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE && is_in_end_range(end, lut_entry.get_end_address())) {
212199
fetch_lut.removeEntry(lut_entry);
213200
}
214201
});
215202
dbus.register_invalidate_direct_mem_ptr([this](uint64_t start, uint64_t end) -> void {
216203
for(auto& read_lut : dmi_read_luts) {
217204
auto lut_entry = read_lut.getEntry(start);
218-
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE &&
219-
is_invalidate_end_covered(end, lut_entry.get_end_address())) {
205+
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE && is_in_end_range(end, lut_entry.get_end_address())) {
220206
read_lut.removeEntry(lut_entry);
221207
}
222208
}
223209
for(auto& write_lut : dmi_write_luts) {
224210
auto lut_entry = write_lut.getEntry(start);
225-
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE &&
226-
is_invalidate_end_covered(end, lut_entry.get_end_address())) {
211+
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE && is_in_end_range(end, lut_entry.get_end_address())) {
227212
write_lut.removeEntry(lut_entry);
228213
}
229214
}
@@ -415,8 +400,7 @@ bool core_complex<BUSWIDTH, QK>::read_mem(const addr_t& addr, unsigned length, u
415400
bool is_fetch = addr.space == std::numeric_limits<decltype(addr.space)>::max() ? true : false;
416401
auto& dmi_lut = is_fetch ? fetch_lut : get_read_lut(addr.space);
417402
auto lut_entry = dmi_lut.getEntry(addr.val);
418-
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE &&
419-
is_within_dmi_range(addr.val, length, lut_entry.get_end_address())) {
403+
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE && is_in_end_range(addr.val + length, lut_entry.get_end_address())) {
420404
auto offset = addr.val - lut_entry.get_start_address();
421405
std::copy(lut_entry.get_dmi_ptr() + offset, lut_entry.get_dmi_ptr() + offset + length, data);
422406
if(is_fetch)
@@ -470,7 +454,7 @@ bool core_complex<BUSWIDTH, QK>::read_mem(const addr_t& addr, unsigned length, u
470454
gp.set_address(addr.val);
471455
tlm_dmi_ext dmi_data;
472456
if(exec_get_direct_mem_ptr(gp, dmi_data)) {
473-
if(dmi_data.is_read_allowed() && is_within_dmi_range(addr.val, length, dmi_data.get_end_address()))
457+
if(dmi_data.is_read_allowed() && is_in_end_range(addr.val + length, dmi_data.get_end_address()))
474458
dmi_lut.addEntry(dmi_data, dmi_data.get_start_address(), dmi_data.get_end_address() - dmi_data.get_start_address() + 1);
475459
}
476460
}
@@ -481,8 +465,7 @@ bool core_complex<BUSWIDTH, QK>::read_mem(const addr_t& addr, unsigned length, u
481465
template <unsigned int BUSWIDTH, typename QK>
482466
bool core_complex<BUSWIDTH, QK>::write_mem(const addr_t& addr, unsigned length, const uint8_t* const data) {
483467
auto lut_entry = get_write_lut(addr.space).getEntry(addr.val);
484-
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE &&
485-
is_within_dmi_range(addr.val, length, lut_entry.get_end_address())) {
468+
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE && is_in_end_range(addr.val + length, lut_entry.get_end_address())) {
486469
auto offset = addr.val - lut_entry.get_start_address();
487470
std::copy(data, data + length, lut_entry.get_dmi_ptr() + offset);
488471
dbus_inc += lut_entry.get_write_latency() / curr_clk;
@@ -529,7 +512,7 @@ bool core_complex<BUSWIDTH, QK>::write_mem(const addr_t& addr, unsigned length,
529512
gp.set_address(addr.val);
530513
tlm_dmi_ext dmi_data;
531514
if(exec_get_direct_mem_ptr(gp, dmi_data)) {
532-
if(dmi_data.is_write_allowed() && is_within_dmi_range(addr.val, length, dmi_data.get_end_address()))
515+
if(dmi_data.is_write_allowed() && is_in_end_range(addr.val + length, dmi_data.get_end_address()))
533516
get_write_lut(addr.space)
534517
.addEntry(dmi_data, dmi_data.get_start_address(), dmi_data.get_end_address() - dmi_data.get_start_address() + 1);
535518
}

0 commit comments

Comments
 (0)