public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [kj][RFC] roll macro's in bitops.h
@ 2007-02-17  0:02 Darren Jenkins\
  0 siblings, 0 replies; only message in thread
From: Darren Jenkins\ @ 2007-02-17  0:02 UTC (permalink / raw)
  To: kernel Janitors; +Cc: LKML

G'day people,

I was looking at bitops.h and noticed there were a couple of inline roll
functions to operate on 32bit variables. (left and right)

I think that is a little bit dumb as they are constant width (only
32bits) due to it being an inline function, and was wondering if anyone
thought it would be useful to have some (variable sized) roll macros
instead.

I whipped these twp up as examples, but have not tested them yet.

#define RollRight(Data, Distance) \
({      typeof(Data) __a = Data;   \
        typeof(Distance) __b = Distance%(sizeof(__a) * 8); \
	__a = ((__a>>__b) | (__a<<((sizeof(__a) * 8) - __b))) \
	__a; \
})

#define RollLeft(Data, Distance) \
({      typeof(Data) __a = Data;   \
        typeof(Distance) __b = Distance%(sizeof(__a) * 8); \
	__a = ((__a<<__b) | (__a>>((sizeof(__a) * 8) - __b))) \
	__a; \
})

Also if these are useful I was wondering how to handle the existing
functions ? #define them out for the time being ?

#define rol32(a, b) RollLeft(a, b)
#define ror32(a, b) RollRight(a, b)




Darren Jenkins



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-02-17  0:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-17  0:02 [kj][RFC] roll macro's in bitops.h Darren Jenkins\

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox