This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/2 v4] libc-internal.h: add ALIGN helper macros


I think we should be using inlines rather than macros any time we don't
have a strong reason to use macros.

> +/* Align a value by rounding down to closest size.
> +   e.g. Using size of 4096, we get this behavior:
> +	{4095, 4096, 4097} = {0, 4096, 4096}.  */
> +#define ALIGN_DOWN(base, size)	((base) & ~((size) - 1))

We usually use & -size nowadays.  Obviously it doesn't matter for
constants, but it's cheaper on some machines when it's not a constant
(and it's always less typing ;-).

> +/* Align a value by rounding up to closest size.
> +   e.g. Using size of 4096, we get this behavior:
> +	{4095, 4096, 4097} = {4096, 4096, 8192}.  */
> +#define ALIGN_UP(base, size)	ALIGN_DOWN((base) + (size) - 1, (size))

Space before paren in rhs.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]