[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231012230449.2109078-1-visitorckw@gmail.com>
Date: Fri, 13 Oct 2023 07:04:49 +0800
From: Kuan-Wei Chiu <visitorckw@...il.com>
To: zhenyuw@...ux.intel.com, zhi.a.wang@...el.com
Cc: jani.nikula@...ux.intel.com, joonas.lahtinen@...ux.intel.com,
rodrigo.vivi@...el.com, tvrtko.ursulin@...ux.intel.com,
airlied@...il.com, daniel@...ll.ch,
intel-gvt-dev@...ts.freedesktop.org,
intel-gfx@...ts.freedesktop.org, dri-devel@...ts.freedesktop.org,
linux-kernel@...r.kernel.org, Kuan-Wei Chiu <visitorckw@...il.com>
Subject: [PATCH] drm/i915/gvt: Optimize mmio_offset_compare() for efficiency
The original code used conditional branching in the mmio_offset_compare
function to compare two values and return -1, 1, or 0 based on the
result. However, the list_sort comparison function only needs results
<0, >0, or =0. This patch optimizes the code to make the comparison
branchless, improving efficiency and reducing code size. This change
reduces the number of comparison operations from 1-2 to a single
subtraction operation, thereby saving the number of instructions.
Signed-off-by: Kuan-Wei Chiu <visitorckw@...il.com>
---
drivers/gpu/drm/i915/gvt/debugfs.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/i915/gvt/debugfs.c b/drivers/gpu/drm/i915/gvt/debugfs.c
index baccbf1761b7..998d82a259c8 100644
--- a/drivers/gpu/drm/i915/gvt/debugfs.c
+++ b/drivers/gpu/drm/i915/gvt/debugfs.c
@@ -48,11 +48,7 @@ static int mmio_offset_compare(void *priv,
ma = container_of(a, struct diff_mmio, node);
mb = container_of(b, struct diff_mmio, node);
- if (ma->offset < mb->offset)
- return -1;
- else if (ma->offset > mb->offset)
- return 1;
- return 0;
+ return ma->offset - mb->offset;
}
static inline int mmio_diff_handler(struct intel_gvt *gvt,
--
2.25.1
Powered by blists - more mailing lists