diff options
author | Gabe Black <gblack@eecs.umich.edu> | 2006-10-26 20:25:22 -0400 |
---|---|---|
committer | Gabe Black <gblack@eecs.umich.edu> | 2006-10-26 20:25:22 -0400 |
commit | f88b90dd564f59ca0f045df6f12c87185cbef687 (patch) | |
tree | 18c3d18197f75c279111b30d4bdf4e41705de331 /src/base | |
parent | d1b30102fdaa79b9937e9405aeade54a72685746 (diff) | |
download | gem5-f88b90dd564f59ca0f045df6f12c87185cbef687.tar.xz |
Added a few functions to stuff values into bitfields in an instruction.
--HG--
extra : convert_revision : 507d7e13fd6276acf36b75eba31dff5e8080113f
Diffstat (limited to 'src/base')
-rw-r--r-- | src/base/bitfield.hh | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/base/bitfield.hh b/src/base/bitfield.hh index 879780d56..177279678 100644 --- a/src/base/bitfield.hh +++ b/src/base/bitfield.hh @@ -69,4 +69,28 @@ sext(uint64_t val) return sign_bit ? (val | ~mask(N)) : val; } +/** + * Return val with bits first to last set to bit_val + */ +template <class T, class B> +inline +T +insertBits(T val, int first, int last, B bit_val) +{ + T bmask = mask(first - last + 1) << last; + return ((bit_val << last) & bmask) | (val & ~bmask); +} + +/** + * A convenience function to replace bits first to last of val with bit_val + * in place. + */ +template <class T, class B> +inline +void +replaceBits(T& val, int first, int last, B bit_val) +{ + val = insertBits(val, first, last, bit_val); +} + #endif // __BASE_BITFIELD_HH__ |