[PATCH] Define/use pad_to_pow_two() instead of open coding it

Mark Kettenis mark.kettenis at xs4all.nl
Wed Mar 24 13:49:21 PDT 2010


> From: Eric Anholt <eric at anholt.net>
> Date: Wed, 24 Mar 2010 13:29:06 -0700
> 
> On Wed, 24 Mar 2010 14:59:04 -0400, Matt Turner <mattst88 at gmail.com> wrote:
> > On Wed, Mar 24, 2010 at 2:56 PM, Mark Kettenis <mark.kettenis at xs4all.nl> wrote:
> > >> From: Matt Turner <mattst88 at gmail.com>
> > >> Date: Wed, 24 Mar 2010 13:57:15 -0400
> > >>
> > >> diff --git a/hw/dmx/dmxpict.c b/hw/dmx/dmxpict.c
> > >> index 072e3a6..51616bb 100644
> > >> --- a/hw/dmx/dmxpict.c
> > >> +++ b/hw/dmx/dmxpict.c
> > >> @@ -674,7 +674,7 @@ static int dmxProcRenderSetPictureFilter(ClientPtr client)
> > >>
> > >>      if (pPictPriv->pict) {
> > >>       filter  = (char *)(stuff + 1);
> > >> -     params  = (XFixed *)(filter + ((stuff->nbytes + 3) & ~3));
> > >> +     params  = (XFixed *)(filter + pad_to_pow_two(stuff->nbytes, 4));
> > >
> > > Sorry, but to me this isn't an improvement.  I probably spend to much
> > > time on kernel hacking, but the origional is immediately obvious to
> > > me, whereas the new line makes me think you're trying to align to a
> > > 16-byte boundary.
> > 
> > Hmm, yes, I see what you're saying. I changed the name to try to make
> > it explicitly obvious that 'alignment' must be a power of two, but I
> > see it is actually a little confusing.
> > 
> > What would you suggest for the name of the function?
> 
> ALIGN, like the kernel.

*The* kernel?

Anyway, ALIGN is probably a poor choice since on OpenBSD (I didn't
check other BSD's) have a one-argument ALIGN macro in <sys/param.h>
that aligns to the machines natural word size instead of some
caller-specified alignment.

However, something with "align" in the name is probably a good idea.


More information about the xorg-devel mailing list