This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 1/2 v4] libc-internal.h: add ALIGN helper macros
- From: Roland McGrath <roland at hack dot frob dot com>
- To: Mike Frysinger <vapier at gentoo dot org>
- Cc: libc-alpha at sourceware dot org
- Date: Mon, 3 Jun 2013 12:12:05 -0700 (PDT)
- Subject: Re: [PATCH 1/2 v4] libc-internal.h: add ALIGN helper macros
- References: <1369327649-906-1-git-send-email-vapier at gentoo dot org> <1370070444-911-1-git-send-email-vapier at gentoo dot org>
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.