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

Mike Frysinger vapier@gentoo.org
Tue Jun 4 03:06:00 GMT 2013


On Monday 03 June 2013 15:12:05 Roland McGrath wrote:
> I think we should be using inlines rather than macros any time we don't
> have a strong reason to use macros.

generally we don't do caps inlines though ?  and using inlines means we now 
have to deal with types.  the current one works with any size and does the 
right thing.  if i wrote an inline, i'd have to pick a type (size_t? int? 
long? uint64_t? uintmax_t?) and then there'd be ugliness with signed vs 
unsigned, implicit casts, implicit truncation, overhead with casting up to 
larger than natural types (like 64bit on a 32bit system), etc...

> > +/* 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 ;-).

hadn't seen that form before.  i do like less typing.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20130604/6f5b3be5/attachment.sig>


More information about the Libc-alpha mailing list