Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/41433 )
Change subject: base: Minor optimization in the bits() function.
......................................................................
base: Minor optimization in the bits() function.
This small optimization masks off the bits above the range of interest
and then shifts, where the old code shifted and then masked. The
difference is that in the new version, the size of the mask only depends
on the "first" bit index, not the difference between it and "last".
To ensure the shifting doesn't bring in any sign bits or right shift a
signed value which is undefined behvior, this change also converts "val"
into a uint64_t before operating on it.
Change-Id: Idb38a82702a57586253fd611312bd4c72f2f726a
---
M src/base/bitfield.hh
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/base/bitfield.hh b/src/base/bitfield.hh
index 98a93d4..e7ed229 100644
--- a/src/base/bitfield.hh
+++ b/src/base/bitfield.hh
@@ -74,9 +74,10 @@
T
bits(T val, int first, int last)
{
- int nbits = first - last + 1;
assert((first - last) >= 0);
- return (val >> last) & mask(nbits);
+ uint64_t u_val = val;
+ u_val &= mask(first + 1);
+ return u_val >> last;
}
/**
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/41433
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Idb38a82702a57586253fd611312bd4c72f2f726a
Gerrit-Change-Number: 41433
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s