Re: [KERNEL]: Avoid divide in IS_ALIGN

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Joe Perches
Date: Tuesday, November 20, 2007 - 11:17 am

On Tue, 2007-11-20 at 21:56 +0800, Herbert Xu wrote:

Perhaps this should use is_power_of_2?

#define IS_ALIGNED(x, a) 				\
	({ typeof(x) _a = (typeof(x))(a); 		\
	   is_power_of_2(_a) ? (((x) & (_a - 1)) == 0)	\
			     : (((x) % _a == 0); })

gcc -o2/oS seems to do the right thing.

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[KERNEL]: Avoid divide in IS_ALIGN, Herbert Xu, (Tue Nov 20, 6:56 am)
Re: [KERNEL]: Avoid divide in IS_ALIGN, Joe Perches, (Tue Nov 20, 11:17 am)
Re: [KERNEL]: Avoid divide in IS_ALIGN, Andrew Morton, (Tue Nov 20, 1:22 pm)
Re: [KERNEL]: Avoid divide in IS_ALIGN, linux-os (Dick Johnson), (Tue Nov 20, 2:43 pm)
Re: [KERNEL]: Avoid divide in IS_ALIGN, linux-os (Dick Johnson), (Wed Nov 21, 6:06 am)
Re: [KERNEL]: Avoid divide in IS_ALIGN, Andreas Schwab, (Wed Nov 21, 6:35 am)