[lkml]   [2007]   [Mar]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectALIGN via ilog2 without gccisms (Re: [PATCH] Fix get_order())
> 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?

#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
More majordomo info at
Please read the FAQ at
 \ /
  Last update: 2007-03-07 16:57    [from the cache]
©2003-2014 Jasper Spaans. hosted at Digital Ocean