[RFC] Define/use pad() and pad_mask() instead of open coding it

Peter Hutterer peter.hutterer at who-t.net
Thu Mar 11 17:05:14 PST 2010


On Thu, Mar 11, 2010 at 07:33:30PM -0500, Matt Turner wrote:
> à la the Linux Kernel's ALIGN and __ALIGN_MASK macros.
> 
> Not even compile tested, some files might need to include "misc.h".
> 
> CC: Peter Hutterer <peter.hutterer at who-t.net>
> Signed-off-by: Matt Turner <mattst88 at gmail.com>

ACK in principle, not tested either. :)

> diff --git a/include/misc.h b/include/misc.h
> index 62d813e..98d39bd 100644
> --- a/include/misc.h
> +++ b/include/misc.h
> @@ -200,6 +200,16 @@ bytes_to_int32(const int bytes) {
>      return (((bytes) + 3) >> 2);
>  }

+ /** 
+  * please comment on what I'm supposed to be doing 
+  */

>  
> +static inline int
> +pad_mask(const int bytes, const int mask) {
> +	return (((bytes) + mask) & ~mask);

you don't need the () around bytes, this isn't a macro.
which, looking at the context goes for bytes_to_int32 as well :)

> +}
> +
> +static inline int
> +pad(const int bytes, const int mask) {

shouldn't the second arg be called alignment or something, not mask?
otherwise, it's a bit confusing why both pad() and pad_mask() take a mask
argument.

> +	return pad_mask(bytes, mask - 1);
> +}
> +

Cheers,
  Peter



More information about the xorg-devel mailing list