Re: [RFC][PATCH 01/10] put alignment macros in align.h

Nikita Danilov
2006-08-30T16:11:44Z

Dave Hansen writes:
>

[...]

> + */
> +#ifndef __ASSEMBLY__
> +#define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))

This evaluates (a) twice. While in all existing call-sites (a) is
probably a constant, it's still safer to do

#define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })

in a generic macro and rely on compiler to optimize temporary variable
out.

Nikita.