On 5/29/2024 12:59, Tong Ho wrote:> Add inlined functions to obtain a mask of changed bits. 3 flavors > are added: toggled, changed to 1, changed to 0. > > These newly added utilities aid common device behaviors where > actions are taken only when a register's bit(s) are changed. > > Signed-off-by: Tong Ho <tong...@amd.com> > --- > include/qemu/bitops.h | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h > index 2c0a2fe751..7a701474ea 100644 > --- a/include/qemu/bitops.h > +++ b/include/qemu/bitops.h > @@ -148,6 +148,39 @@ static inline int test_bit(long nr, const unsigned long > *addr) > return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); > } > > +/** > + * find_bits_changed - Returns a mask of bits changed. > + * @ref_bits: the reference bits against which the test is made. > + * @chk_bits: the bits to be checked. > + */ > +static inline unsigned long find_bits_changed(unsigned long ref_bits, > + unsigned long chk_bits) > +{ > + return ref_bits ^ chk_bits; > +} > + > +/** > + * find_bits_to_1 - Returns a mask of bits changed from 0 to 1. > + * @ref_bits: the reference bits against which the test is made. > + * @chk_bits: the bits to be checked. > + */ > +static inline unsigned long find_bits_to_1(unsigned long ref_bits, > + unsigned long chk_bits) > +{ > + return find_bits_changed(ref_bits, chk_bits) & chk_bits; > +} > + > +/** > + * find_bits_to_0 - Returns a mask of bits changed from 1 to 0. > + * @ref_bits: the reference bits against which the test is made. > + * @chk_bits: the bits to be checked. > + */ > +static inline unsigned long find_bits_to_0(unsigned long ref_bits, > + unsigned long chk_bits) > +{ > + return find_bits_to_1(chk_bits, ref_bits); > +} > + > /** > * find_last_bit - find the last set bit in a memory region > * @addr: The address to start the search at
Reviewed-by: Lei Wang <lei4.w...@intel.com>