public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tursulin@ursulin.net>
To: Intel-gfx@lists.freedesktop.org
Cc: Jani Nikula <jani.nikula@intel.com>
Subject: [PATCH 3/3] drm/i915: Number the platform enum strategically
Date: Thu,  8 Dec 2016 09:49:59 +0000	[thread overview]
Message-ID: <1481190599-1217-4-git-send-email-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <1481190599-1217-1-git-send-email-tvrtko.ursulin@linux.intel.com>

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

If we use only power of two values for the platform enum
values we can let the compiler optimize some common
checks to a single conditional.

For example code like this:

	if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))

Goes from this:

   5c3c5:       8b 83 d8 06 00 00       mov    0x6d8(%rbx),%eax
   5c3cb:       83 f8 12                cmp    $0x12,%eax
   5c3ce:       0f 84 f3 00 00 00       je     5c4c7 <fw_domain_init+0x1a7>
   5c3d4:       83 f8 15                cmp    $0x15,%eax
   5c3d7:       0f 84 ea 00 00 00       je     5c4c7 <fw_domain_init+0x1a7>

To this:

   5c1d5:       f7 83 d8 06 00 00 00    testl  $0x240000,0x6d8(%rbx)
   5c1dc:       00 24 00
   5c1df:       0f 85 da 00 00 00       jne    5c2bf <fw_domain_init+0x18f>

It is not much but there is value in this that as long as we
have to have conditions like the above sprinkled troughout the
code, we can at least have the generate binary a bit smarter.

Until we get to more than 32 platforms there is no downside
to this approach.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Jani Nikula <jani.nikula@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h          |  2 +-
 drivers/gpu/drm/i915/i915_platforms.h    | 50 ++++++++++++++++----------------
 drivers/gpu/drm/i915/intel_device_info.c | 10 ++++---
 3 files changed, 32 insertions(+), 30 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index fb8f4b7cd1ae..347d5c6ffc1b 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2590,7 +2590,7 @@ intel_info(const struct drm_i915_private *dev_priv)
 #define i915_platform(name, id) \
 static inline bool IS_##name(const struct drm_i915_private *dev_priv) \
 { \
-	return (dev_priv)->info.platform == INTEL_##name; \
+	return !!((dev_priv)->info.platform & INTEL_##name); \
 }
 #include "i915_platforms.h"
 #undef i915_platform
diff --git a/drivers/gpu/drm/i915/i915_platforms.h b/drivers/gpu/drm/i915/i915_platforms.h
index b44ea1dd9c15..4118f152eac9 100644
--- a/drivers/gpu/drm/i915/i915_platforms.h
+++ b/drivers/gpu/drm/i915/i915_platforms.h
@@ -7,28 +7,28 @@
  */
 
 i915_platform(UNINITIALIZED,  0)
-i915_platform(I830,	      1)
-i915_platform(I845G,	      2)
-i915_platform(I85X,	      3)
-i915_platform(I865G,	      4)
-i915_platform(I915G,	      5)
-i915_platform(I915GM,	      6)
-i915_platform(I945G,	      7)
-i915_platform(I945GM,	      8)
-i915_platform(G33,	      9)
-i915_platform(PINEVIEW,	     10)
-i915_platform(I965G,	     11)
-i915_platform(I965GM,	     12)
-i915_platform(G45,	     13)
-i915_platform(GM45,	     14)
-i915_platform(IRONLAKE,	     15)
-i915_platform(SANDYBRIDGE,   16)
-i915_platform(IVYBRIDGE,     17)
-i915_platform(VALLEYVIEW,    18)
-i915_platform(HASWELL,	     19)
-i915_platform(BROADWELL,     20)
-i915_platform(CHERRYVIEW,    21)
-i915_platform(SKYLAKE,	     22)
-i915_platform(BROXTON,	     23)
-i915_platform(KABYLAKE,	     24)
-i915_platform(GEMINILAKE,    25)
+i915_platform(I830,	      BIT(1))
+i915_platform(I845G,	      BIT(2))
+i915_platform(I85X,	      BIT(3))
+i915_platform(I865G,	      BIT(4))
+i915_platform(I915G,	      BIT(5))
+i915_platform(I915GM,	      BIT(6))
+i915_platform(I945G,	      BIT(7))
+i915_platform(I945GM,	      BIT(8))
+i915_platform(G33,	      BIT(9))
+i915_platform(PINEVIEW,	     BIT(10))
+i915_platform(I965G,	     BIT(11))
+i915_platform(I965GM,	     BIT(12))
+i915_platform(G45,	     BIT(13))
+i915_platform(GM45,	     BIT(14))
+i915_platform(IRONLAKE,	     BIT(15))
+i915_platform(SANDYBRIDGE,   BIT(16))
+i915_platform(IVYBRIDGE,     BIT(17))
+i915_platform(VALLEYVIEW,    BIT(18))
+i915_platform(HASWELL,	     BIT(19))
+i915_platform(BROADWELL,     BIT(20))
+i915_platform(CHERRYVIEW,    BIT(21))
+i915_platform(SKYLAKE,	     BIT(22))
+i915_platform(BROXTON,	     BIT(23))
+i915_platform(KABYLAKE,	     BIT(24))
+i915_platform(GEMINILAKE,    BIT(25))
diff --git a/drivers/gpu/drm/i915/intel_device_info.c b/drivers/gpu/drm/i915/intel_device_info.c
index 5192d388d10e..26df6363e265 100644
--- a/drivers/gpu/drm/i915/intel_device_info.c
+++ b/drivers/gpu/drm/i915/intel_device_info.c
@@ -25,18 +25,20 @@
 #include "i915_drv.h"
 
 static const char * const platform_names[] = {
-#define i915_platform(name, id) [id] = #name,
+#define i915_platform(name, id) [__builtin_ffs(id)] = #name,
 #include "i915_platforms.h"
 #undef i915_platform
 };
 
 const char *intel_platform_name(enum intel_platform platform)
 {
-	if (WARN_ON_ONCE(platform >= ARRAY_SIZE(platform_names) ||
-			 platform_names[platform] == NULL))
+	unsigned int idx = ffs(platform);
+
+	if (WARN_ON_ONCE(idx >= ARRAY_SIZE(platform_names) ||
+			 platform_names[idx] == NULL))
 		return "<unknown>";
 
-	return platform_names[platform];
+	return platform_names[idx];
 }
 
 void intel_device_info_dump(struct drm_i915_private *dev_priv)
-- 
2.7.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2016-12-08  9:50 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-08  9:49 [PATCH 0/3] Claw back the IS_<platform> optimisation Tvrtko Ursulin
2016-12-08  9:49 ` [PATCH 1/3] drm/i915: Introduct i915_platforms.h Tvrtko Ursulin
2016-12-08 10:41   ` Jani Nikula
2016-12-08 13:16     ` Joonas Lahtinen
2016-12-08 13:21       ` Tvrtko Ursulin
2016-12-08  9:49 ` [PATCH 2/3] drm/i915: Generate all IS_<platform> macros Tvrtko Ursulin
2016-12-08 10:46   ` Jani Nikula
2016-12-08 13:26     ` Tvrtko Ursulin
2016-12-08 13:37       ` Jani Nikula
2016-12-08 13:40         ` Jani Nikula
2016-12-08 13:42         ` Tvrtko Ursulin
2016-12-08 14:00           ` Jani Nikula
2016-12-08 14:10             ` Tvrtko Ursulin
2016-12-08  9:49 ` Tvrtko Ursulin [this message]
2016-12-08 10:04   ` [PATCH 3/3] drm/i915: Number the platform enum strategically Chris Wilson
2016-12-08 13:38     ` [PATCH v2] " Tvrtko Ursulin
2016-12-08 11:54 ` ✓ Fi.CI.BAT: success for Claw back the IS_<platform> optimisation Patchwork
2016-12-08 15:15 ` ✗ Fi.CI.BAT: warning for Claw back the IS_<platform> optimisation (rev2) 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=1481190599-1217-4-git-send-email-tvrtko.ursulin@linux.intel.com \
    --to=tursulin@ursulin.net \
    --cc=Intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@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