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: [PING] Re: Where to put ALIGN_UP and ALIGN_DOWN macros?


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.


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