All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Andres Salomon <dilinger@queued.net>
Cc: jordan.crouse@amd.com, linux-fbdev-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, adaplas@gmail.com,
	info-linux@geode.amd.com
Subject: Re: [PATCH 1/6] gxfb: create DC/VP/FP-specific handlers rather than using readl/writel
Date: Mon, 10 Mar 2008 14:48:42 -0700	[thread overview]
Message-ID: <20080310144842.593d1b80.akpm@linux-foundation.org> (raw)
In-Reply-To: <20080310173544.171183fc@ephemeral>

On Mon, 10 Mar 2008 17:35:44 -0400
Andres Salomon <dilinger@queued.net> wrote:

> On Mon, 10 Mar 2008 14:24:05 -0700
> Andrew Morton <akpm@linux-foundation.org> wrote:
> 
> > On Sat, 8 Mar 2008 20:48:26 -0500
> > Andres Salomon <dilinger@queued.net> wrote:
> > 
> > > +#define read_dc(reg)		readl(par->dc_regs + (reg))
> > > +#define write_dc(reg, val)	writel((val), par->dc_regs + (reg))
> > > +
> > > +#define read_vp(reg)		readl(par->vid_regs + (reg))
> > > +#define write_vp(reg, val)	writel((uint32_t) (val), \
> > > +					par->vid_regs + (reg))
> > > +
> > > +#define read_fp(reg)		readl(par->vid_regs + (reg))
> > > +#define write_fp(reg, val)	writel((uint32_t) (val), \
> > > +					par->vid_regs + (reg))
> > > +
> > 
> > Not very nice, sorry.  They're macros, and macros rather suck.  And they
> > implicitly rely upon the caller having some variable called "par" in scope.
> > 
> > It would be much nicer to do
> > 
> > /*
> >  * documentation goes here
> >  */
> > static inline u32 read_dc(struct geodefb_par *par, int reg)
> > {
> > 	return readl(par->dc_regs, reg);
> > }
> > 
> > no?
> 
> I can change it if you'd like (although.. sigh.)
> 
> However, it's a lot of extra passing around of the 'par' without any
> good reason.  Normal I prefer inline functions to macros as well, but
> I don't see the point here.
>  

It'll generate the same (or similar) code in both versions.

Code is written once and is read thousands of times, so we should optimise
for readers, not writers.  And I do think that being conventional here
helps readability, even if it does add a bit more source code.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

WARNING: multiple messages have this Message-ID (diff)
From: Andrew Morton <akpm@linux-foundation.org>
To: Andres Salomon <dilinger@queued.net>
Cc: adaplas@gmail.com, linux-kernel@vger.kernel.org,
	linux-fbdev-devel@lists.sourceforge.net,
	info-linux@geode.amd.com, jordan.crouse@amd.com
Subject: Re: [PATCH 1/6] gxfb: create DC/VP/FP-specific handlers rather than using readl/writel
Date: Mon, 10 Mar 2008 14:48:42 -0700	[thread overview]
Message-ID: <20080310144842.593d1b80.akpm@linux-foundation.org> (raw)
In-Reply-To: <20080310173544.171183fc@ephemeral>

On Mon, 10 Mar 2008 17:35:44 -0400
Andres Salomon <dilinger@queued.net> wrote:

> On Mon, 10 Mar 2008 14:24:05 -0700
> Andrew Morton <akpm@linux-foundation.org> wrote:
> 
> > On Sat, 8 Mar 2008 20:48:26 -0500
> > Andres Salomon <dilinger@queued.net> wrote:
> > 
> > > +#define read_dc(reg)		readl(par->dc_regs + (reg))
> > > +#define write_dc(reg, val)	writel((val), par->dc_regs + (reg))
> > > +
> > > +#define read_vp(reg)		readl(par->vid_regs + (reg))
> > > +#define write_vp(reg, val)	writel((uint32_t) (val), \
> > > +					par->vid_regs + (reg))
> > > +
> > > +#define read_fp(reg)		readl(par->vid_regs + (reg))
> > > +#define write_fp(reg, val)	writel((uint32_t) (val), \
> > > +					par->vid_regs + (reg))
> > > +
> > 
> > Not very nice, sorry.  They're macros, and macros rather suck.  And they
> > implicitly rely upon the caller having some variable called "par" in scope.
> > 
> > It would be much nicer to do
> > 
> > /*
> >  * documentation goes here
> >  */
> > static inline u32 read_dc(struct geodefb_par *par, int reg)
> > {
> > 	return readl(par->dc_regs, reg);
> > }
> > 
> > no?
> 
> I can change it if you'd like (although.. sigh.)
> 
> However, it's a lot of extra passing around of the 'par' without any
> good reason.  Normal I prefer inline functions to macros as well, but
> I don't see the point here.
>  

It'll generate the same (or similar) code in both versions.

Code is written once and is read thousands of times, so we should optimise
for readers, not writers.  And I do think that being conventional here
helps readability, even if it does add a bit more source code.


  reply	other threads:[~2008-03-10 21:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-09  1:48 [PATCH 1/6] gxfb: create DC/VP/FP-specific handlers rather than using readl/writel Andres Salomon
2008-03-09  1:48 ` Andres Salomon
2008-03-10 21:24 ` Andrew Morton
2008-03-10 21:35   ` Andres Salomon
2008-03-10 21:35     ` Andres Salomon
2008-03-10 21:48     ` Andrew Morton [this message]
2008-03-10 21:48       ` Andrew Morton
  -- strict thread matches above, loose matches on Subject: below --
2008-03-11 22:13 Andres Salomon
2008-03-11 22:13 ` Andres Salomon

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=20080310144842.593d1b80.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=adaplas@gmail.com \
    --cc=dilinger@queued.net \
    --cc=info-linux@geode.amd.com \
    --cc=jordan.crouse@amd.com \
    --cc=linux-fbdev-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.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.