Messages in this thread | | | Subject | ALIGN via ilog2 without gccisms (Re: [PATCH] Fix get_order()) | Date | Wed, 7 Mar 2007 17:02:53 +0100 | From | Oleg Verych <> |
| |
> From: David Howells > Newsgroups: gmane.linux.kernel > Subject: Re: [PATCH] Fix get_order() > Date: Wed, 07 Mar 2007 11:43:06 +0000 > [] > Various archs (including i386, x86_64, powerpc and frv) have instructions that > can be used to calculate integer log2(N). > Probably it can be used to get rid of gccisms and "type fluff" due to bitwise arithmetics in ALIGN? Here:
#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
like that:
#define ALIGN(x,y) __ALIGN_MASK(x,ilog2(y)) #define __ALIGN_MASK(x,bits) (((((x) >> (bits)) << 1) + 2) << (bits - 1))
Note side effect, that this one always yields even result. Maybe this is good, due to avoidance of misaligned access.
____ - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |