[PING] Re: Where to put ALIGN_UP and ALIGN_DOWN macros?

Carlos O'Donell carlos@systemhalted.org
Mon Feb 18 16:04:00 GMT 2013


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.



More information about the Libc-alpha mailing list