This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PING] Re: Where to put ALIGN_UP and ALIGN_DOWN macros?
- From: "Carlos O'Donell" <carlos at systemhalted dot org>
- To: Ondřej Bílka <neleai at seznam dot cz>
- Cc: libc-alpha at sourceware dot org
- Date: Mon, 18 Feb 2013 11:04:05 -0500
- Subject: Re: [PING] Re: Where to put ALIGN_UP and ALIGN_DOWN macros?
- References: <20120916183856.GB13487@lios><20130218155705.GA31534@domone.kolej.mff.cuni.cz>
On Mon, Feb 18, 2013 at 10:57 AM, OndÅej BÃlka <neleai@seznam.cz> wrote:
> I encountered situation where align_up/down would be handly.
>
> What is status?
I was using something like this in my current patch:
+/* Align VALUE down by ALIGN bytes. */
+#define ALIGN_DOWN(value, align) \
+ ALIGN_DOWN_M1(value, align - 1)
+/* Align VALUE down by ALIGN_M1 + 1 bytes.
+ Useful if you have precomputed ALIGN - 1. */
+#define ALIGN_DOWN_M1(value, align_m1) \
+ (void *)((uintptr_t)(value) \
+ & ~(uintptr_t)(align_m1))
+
+/* Align VALUE up by ALIGN bytes. */
+#define ALIGN_UP(value, align) \
+ ALIGN_UP_M1(value, align - 1)
+/* Align VALUE up by ALIGN_M1 + 1 bytes.
+ Useful if you have precomputed ALIGN - 1. */
+#define ALIGN_UP_M1(value, align_m1) \
+ (void *)(((uintptr_t)(value) + (uintptr_t)(align_m1)) \
+ & ~(uintptr_t)(align_m1))
Next steps:
- Put them into libc-internal.h
- Add tests for them to make sure they work correctly.
- Start using them to replace all the custom ways we round stuff.
I'd be happy to review such a patch.
Cheers,
CArlos.