From: Kuan-Wei Chiu <visitorckw@gmail.com>
To: ville.syrjala@linux.intel.com, zhenyuw@linux.intel.com,
zhi.a.wang@intel.com
Cc: intel-gvt-dev@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org,
Kuan-Wei Chiu <visitorckw@gmail.com>,
dri-devel@lists.freedesktop.org, daniel@ffwll.ch,
rodrigo.vivi@intel.com, airlied@gmail.com
Subject: [Intel-gfx] [PATCH v2] drm/i915/gvt: Optimize mmio_offset_compare() for efficiency
Date: Fri, 13 Oct 2023 20:13:55 +0800 [thread overview]
Message-ID: <20231013121355.2125824-1-visitorckw@gmail.com> (raw)
In-Reply-To: <ZSkdoVcMxKIbXUOW@intel.com>
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@gmail.com>
---
v1 -> v2:
- Add explicit type cast in case the sizes of u32 and int differ.
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..d85d8a3b5ae5 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 (int)ma->offset - (int)mb->offset;
}
static inline int mmio_diff_handler(struct intel_gvt *gvt,
--
2.25.1
next prev parent reply other threads:[~2023-10-16 16:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-12 23:04 [Intel-gfx] [PATCH] drm/i915/gvt: Optimize mmio_offset_compare() for efficiency Kuan-Wei Chiu
2023-10-13 10:36 ` Ville Syrjälä
2023-10-13 12:13 ` Kuan-Wei Chiu [this message]
2023-10-17 3:33 ` [Intel-gfx] ✓ Fi.CI.BAT: success for drm/i915/gvt: Optimize mmio_offset_compare() for efficiency (rev3) Patchwork
2023-10-17 5:00 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231013121355.2125824-1-visitorckw@gmail.com \
--to=visitorckw@gmail.com \
--cc=airlied@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-gvt-dev@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=ville.syrjala@linux.intel.com \
--cc=zhenyuw@linux.intel.com \
--cc=zhi.a.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox