All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [RFC 4/4] drm/i915/registers: define field values using FIELD_PREP()
Date: Thu, 27 Sep 2018 15:44:50 +0300	[thread overview]
Message-ID: <87bm8jrtx9.fsf@intel.com> (raw)
In-Reply-To: <87efdfrwa1.fsf@intel.com>

On Thu, 27 Sep 2018, Jani Nikula <jani.nikula@intel.com> wrote:
> On Thu, 27 Sep 2018, Chris Wilson <chris@chris-wilson.co.uk> wrote:
>> Quoting Jani Nikula (2018-09-27 10:40:23)
>>> Slightly verbose, but does away with hand rolled shifts and provides
>>> static checking that the values fit the mask.
>>> 
>>> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
>>> ---
>>> @@ -4650,11 +4650,11 @@ enum {
>>>  #define _PP_ON_DELAYS                  0x61208
>>>  #define PP_ON_DELAYS(pps_idx)          _MMIO_PPS(pps_idx, _PP_ON_DELAYS)
>>>  #define  PANEL_PORT_SELECT_MASK                GENMASK(31, 30)
>>> -#define  PANEL_PORT_SELECT_LVDS                (0 << 30)
>>> -#define  PANEL_PORT_SELECT_DPA         (1 << 30)
>>> -#define  PANEL_PORT_SELECT_DPC         (2 << 30)
>>> -#define  PANEL_PORT_SELECT_DPD         (3 << 30)
>>> -#define  PANEL_PORT_SELECT_VLV(port)   ((port) << 30)
>>> +#define  PANEL_PORT_SELECT_LVDS                FIELD_PREP(PANEL_PORT_SELECT_MASK, 0)
>>> +#define  PANEL_PORT_SELECT_DPA         FIELD_PREP(PANEL_PORT_SELECT_MASK, 1)
>>> +#define  PANEL_PORT_SELECT_DPC         FIELD_PREP(PANEL_PORT_SELECT_MASK, 2)
>>> +#define  PANEL_PORT_SELECT_DPD         FIELD_PREP(PANEL_PORT_SELECT_MASK, 3)
>>> +#define  PANEL_PORT_SELECT_VLV(port)   FIELD_PREP(PANEL_PORT_SELECT_MASK, port)
>>
>> Maybe verbose, but it reads far better as giving each field a distinct
>> name ties together all the individual options.
>>
>> Before seeing this I was sceptical about FIELD_PREP, no longer.
>>
>> Under this construct we aren't using masks per se, but giving a name to
>> a group of bits within the register (a field). So I think
>>
>> #define PANEL_PORT_SELECT	GENMASK(31, 30)
>> #define PANEL_PORT_SELECT_LVDS	FIELD_PREP(PANEL_PORT_SELECT, 0)
>
> Argh, I've screwed up. I must have failed to build after adding the last
> patch. You know, RFC and all. This results in:
>
> drivers/gpu/drm/i915/intel_display.c: In function ‘assert_panel_unlocked’:
> drivers/gpu/drm/i915/intel_display.c:1219:3: error: case label does not reduce to an integer constant
>    case PANEL_PORT_SELECT_LVDS:
>
> Fail.
>
> However, taking just the mask&shift part from FIELD_PREP works:
>
> 	(((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask))
>
> But then we'll lose the static checks, unless we come up with something
> ingenious ourselves.

If my grep-fu serves me right, we have 186 macros defined in i915_reg.h
that are used as case labels, and almost all of them would be candidates
for FIELD_PREP().

Is an alternative FIELD_PREP() worth it without the static checks?

BR,
Jani.


>
> BR,
> Jani.
>
>
>>
>> is intuitive. Did you do a quick bloatometer to see if gcc code
>> generation is affected?
>> -Chris

-- 
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2018-09-27 12:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-27  9:40 [RFC 0/4] drm/i915/registers: use standard bits.h and bitfield.h macros Jani Nikula
2018-09-27  9:40 ` [RFC 1/4] drm/i915/registers: prefer GENMASK() over hand rolled masks Jani Nikula
2018-09-28  8:34   ` Mika Kuoppala
2018-09-27  9:40 ` [RFC 2/4] drm/i915/registers: prefer BIT() for single bits Jani Nikula
2018-09-27  9:40 ` [RFC 3/4] drm/i915/registers: deprecate _SHIFT in favor of FIELD_GET() and _MASK Jani Nikula
2018-09-27  9:40 ` [RFC 4/4] drm/i915/registers: define field values using FIELD_PREP() Jani Nikula
2018-09-27 10:35   ` Chris Wilson
2018-09-27 11:53     ` Jani Nikula
2018-09-27 12:44       ` Jani Nikula [this message]
2018-09-27 12:02     ` Joonas Lahtinen
2018-09-27  9:44 ` [RFC 0/4] drm/i915/registers: use standard bits.h and bitfield.h macros Jani Nikula
2018-09-27 11:09 ` Michal Wajdeczko
2018-09-27 11:22   ` Jani Nikula
2018-09-27 11:44     ` Jani Nikula
2018-09-27 14:20 ` ✗ Fi.CI.BAT: failure for " 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=87bm8jrtx9.fsf@intel.com \
    --to=jani.nikula@intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.