On 6/3/24 08:10, Zhenzhong Duan wrote: > This helper get the highest 1 bit position of the upper bound. > > If the range is empty or upper bound is zero, -1 is returned. > > Suggested-by: Cédric Le Goater <c...@redhat.com> > Signed-off-by: Zhenzhong Duan <zhenzhong.d...@intel.com> Reviewed-by: Eric Auger <eric.au...@redhat.com> Eric > --- > include/qemu/range.h | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/include/qemu/range.h b/include/qemu/range.h > index 205e1da76d..4ce694a398 100644 > --- a/include/qemu/range.h > +++ b/include/qemu/range.h > @@ -20,6 +20,8 @@ > #ifndef QEMU_RANGE_H > #define QEMU_RANGE_H > > +#include "qemu/bitops.h" > + > /* > * Operations on 64 bit address ranges. > * Notes: > @@ -217,6 +219,15 @@ static inline int ranges_overlap(uint64_t first1, > uint64_t len1, > return !(last2 < first1 || last1 < first2); > } > > +/* Get highest non-zero bit position of a range */ > +static inline int range_get_last_bit(Range *range) > +{ > + if (range_is_empty(range)) { > + return -1; > + } > + return 63 - clz64(range->upb); > +} > + > /* > * Return -1 if @a < @b, 1 @a > @b, and 0 if they touch or overlap. > * Both @a and @b must not be empty.
- [PATCH v6 02/19] vfio/container: Introduce TYPE_HOST_IOM... Zhenzhong Duan
- [PATCH v6 12/19] vfio: Introduce VFIOIOMMUClass::hiod_ty... Zhenzhong Duan
- [PATCH v6 11/19] backends/iommufd: Implement HostIOMMUDe... Zhenzhong Duan
- Re: [PATCH v6 11/19] backends/iommufd: Implement Ho... Eric Auger
- Re: [PATCH v6 11/19] backends/iommufd: Implemen... Cédric Le Goater
- RE: [PATCH v6 11/19] backends/iommufd: Impl... Duan, Zhenzhong
- [PATCH v6 09/19] vfio/iommufd: Implement HostIOMMUDevice... Zhenzhong Duan
- Re: [PATCH v6 09/19] vfio/iommufd: Implement HostIO... Eric Auger
- RE: [PATCH v6 09/19] vfio/iommufd: Implement Ho... Duan, Zhenzhong
- [PATCH v6 06/19] range: Introduce range_get_last_bit() Zhenzhong Duan
- Re: [PATCH v6 06/19] range: Introduce range_get_las... Eric Auger
- [PATCH v6 15/19] hw/pci: Introduce pci_device_[set|unset... Zhenzhong Duan
- [PATCH v6 08/19] backends/iommufd: Introduce helper func... Zhenzhong Duan
- [PATCH v6 16/19] vfio/pci: Pass HostIOMMUDevice to vIOMM... Zhenzhong Duan
- [PATCH v6 04/19] vfio/iommufd: Introduce TYPE_HOST_IOMMU... Zhenzhong Duan
- [PATCH v6 03/19] backends/iommufd: Introduce abstract TY... Zhenzhong Duan
- Re: [PATCH v6 03/19] backends/iommufd: Introduce ab... Eric Auger
- RE: [PATCH v6 03/19] backends/iommufd: Introduc... Duan, Zhenzhong
- [PATCH v6 10/19] vfio/container: Implement HostIOMMUDevi... Zhenzhong Duan