From 4d682b8babdcf28093b5530d773d0e464b69dc12 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Wed, 11 Jul 2007 16:28:44 -0700 Subject: ir-common: optimize bit extract function From: Trent Piepho New code is simpler, shorter, compiles to about half the size, and is 2 to 4 times faster depending on how many bits in the mask are set. Signed-off-by: Trent Piepho --- linux/drivers/media/common/ir-functions.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'linux/drivers/media/common/ir-functions.c') diff --git a/linux/drivers/media/common/ir-functions.c b/linux/drivers/media/common/ir-functions.c index a15f5f34e..52b216fe6 100644 --- a/linux/drivers/media/common/ir-functions.c +++ b/linux/drivers/media/common/ir-functions.c @@ -115,21 +115,20 @@ void ir_input_keydown(struct input_dev *dev, struct ir_input_state *ir, } /* -------------------------------------------------------------------------- */ - +/* extract mask bits out of data and pack them into the result */ u32 ir_extract_bits(u32 data, u32 mask) { - int mbit, vbit; - u32 value; + u32 vbit = 1, value = 0; + + do { + if (mask&1) { + if (data&1) + value |= vbit; + vbit<<=1; + } + data>>=1; + } while (mask>>=1); - value = 0; - vbit = 0; - for (mbit = 0; mbit < 32; mbit++) { - if (!(mask & ((u32)1 << mbit))) - continue; - if (data & ((u32)1 << mbit)) - value |= (1 << vbit); - vbit++; - } return value; } -- cgit v1.2.3