Skip to content

Commit 290d0c6

Browse files
committed
Annotate bus_t::find_device control-flow paths with [un]likely
1 parent 2f9fce3 commit 290d0c6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

riscv/devices.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,25 @@ reg_t bus_t::size()
6969

7070
std::pair<reg_t, abstract_device_t*> bus_t::find_device(reg_t addr, size_t len)
7171
{
72-
if (!len || addr + len - 1 < addr)
72+
if (unlikely(!len || addr + len - 1 < addr))
7373
return std::make_pair(0, nullptr);
7474

7575
// Obtain iterator to device immediately after the one that might match
7676
auto it_after = devices.upper_bound(addr);
7777
reg_t base, size;
78-
if (it_after != devices.begin()) {
78+
if (likely(it_after != devices.begin())) {
7979
// Obtain iterator to device that might match
8080
auto it = std::prev(it_after);
8181
base = it->first;
8282
size = it->second->size();
83-
if (addr - base + len - 1 < size) {
83+
if (likely(addr - base + len - 1 < size)) {
8484
// it fully contains [addr, addr + len)
8585
return std::make_pair(it->first, it->second);
8686
}
8787
}
8888

89-
if ((it_after != devices.end() && addr + len - 1 >= it_after->first)
90-
|| (it_after != devices.begin() && addr - base < size)) {
89+
if (unlikely((it_after != devices.end() && addr + len - 1 >= it_after->first)
90+
|| (it_after != devices.begin() && addr - base < size))) {
9191
// it_after or it contains part of, but not all of, [addr, add + len)
9292
return std::make_pair(0, nullptr);
9393
}

0 commit comments

Comments
 (0)