[PATCH 37/49] drm/i915/cmdparser: Use BSEARCH generator

Chris Wilson chris at chris-wilson.co.uk
Fri Nov 11 20:40:06 UTC 2016


Use the new BSEARCH macro from linux/bsearch.h to generate the type
specific register descriptor binary search routine.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_cmd_parser.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_cmd_parser.c b/drivers/gpu/drm/i915/i915_cmd_parser.c
index f5039f4f988f..872af6fce083 100644
--- a/drivers/gpu/drm/i915/i915_cmd_parser.c
+++ b/drivers/gpu/drm/i915/i915_cmd_parser.c
@@ -25,6 +25,8 @@
  *
  */
 
+#include <linux/bsearch.h>
+
 #include "i915_drv.h"
 
 /**
@@ -920,21 +922,16 @@ find_cmd(struct intel_engine_cs *engine,
 	return default_desc;
 }
 
+static inline int
+__cmp_reg(u32 addr, const struct drm_i915_reg_descriptor *entry)
+{
+	return addr - i915_mmio_reg_offset(entry->addr);
+}
+
 static const struct drm_i915_reg_descriptor *
 __find_reg(const struct drm_i915_reg_descriptor *table, int count, u32 addr)
 {
-	int start = 0, end = count;
-	while (start < end) {
-		int mid = start + (end - start) / 2;
-		int ret = addr - i915_mmio_reg_offset(table[mid].addr);
-		if (ret < 0)
-			end = mid;
-		else if (ret > 0)
-			start = mid + 1;
-		else
-			return &table[mid];
-	}
-	return NULL;
+	return BSEARCH(addr, table, count, __cmp_reg);
 }
 
 static const struct drm_i915_reg_descriptor *
-- 
2.10.2



More information about the Intel-gfx-trybot mailing list