[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v7 05/17] range: Introduce range_get_last_bit()
From: |
Zhenzhong Duan |
Subject: |
[PATCH v7 05/17] range: Introduce range_get_last_bit() |
Date: |
Wed, 5 Jun 2024 16:30:31 +0800 |
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 <clg@redhat.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
---
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.
--
2.34.1
- [PATCH v7 00/17] Add a host IOMMU device abstraction to check with vIOMMU, Zhenzhong Duan, 2024/06/05
- [PATCH v7 01/17] backends: Introduce HostIOMMUDevice abstract, Zhenzhong Duan, 2024/06/05
- [PATCH v7 02/17] backends/host_iommu_device: Introduce HostIOMMUDeviceCaps, Zhenzhong Duan, 2024/06/05
- [PATCH v7 03/17] vfio/container: Introduce TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO device, Zhenzhong Duan, 2024/06/05
- [PATCH v7 04/17] backends/iommufd: Introduce TYPE_HOST_IOMMU_DEVICE_IOMMUFD[_VFIO] devices, Zhenzhong Duan, 2024/06/05
- [PATCH v7 05/17] range: Introduce range_get_last_bit(),
Zhenzhong Duan <=
- [PATCH v7 06/17] vfio/container: Implement HostIOMMUDeviceClass::realize() handler, Zhenzhong Duan, 2024/06/05
- [PATCH v7 07/17] backends/iommufd: Introduce helper function iommufd_backend_get_device_info(), Zhenzhong Duan, 2024/06/05
- [PATCH v7 08/17] vfio/iommufd: Implement HostIOMMUDeviceClass::realize() handler, Zhenzhong Duan, 2024/06/05
- [PATCH v7 09/17] vfio/container: Implement HostIOMMUDeviceClass::get_cap() handler, Zhenzhong Duan, 2024/06/05
- [PATCH v7 10/17] backends/iommufd: Implement HostIOMMUDeviceClass::get_cap() handler, Zhenzhong Duan, 2024/06/05
- [PATCH v7 11/17] vfio: Create host IOMMU device instance, Zhenzhong Duan, 2024/06/05
- [PATCH v7 12/17] hw/pci: Introduce helper function pci_device_get_iommu_bus_devfn(), Zhenzhong Duan, 2024/06/05
- [PATCH v7 13/17] hw/pci: Introduce pci_device_[set|unset]_iommu_device(), Zhenzhong Duan, 2024/06/05
- [PATCH v7 14/17] vfio/pci: Pass HostIOMMUDevice to vIOMMU, Zhenzhong Duan, 2024/06/05
- [PATCH v7 15/17] intel_iommu: Extract out vtd_cap_init() to initialize cap/ecap, Zhenzhong Duan, 2024/06/05