summaryrefslogtreecommitdiff
path: root/linux/drivers/media/common/ir-functions.c
diff options
context:
space:
mode:
authorTrent Piepho <xyzzy@speakeasy.org>2007-07-11 16:28:44 -0700
committerTrent Piepho <xyzzy@speakeasy.org>2007-07-11 16:28:44 -0700
commit4d682b8babdcf28093b5530d773d0e464b69dc12 (patch)
treec6800a433a7c38ce39a205f0aeb2c69eff7e9fcb /linux/drivers/media/common/ir-functions.c
parent067e32311ef23bc9b26a4b6c8add961bcec34ded (diff)
downloadmediapointer-dvb-s2-4d682b8babdcf28093b5530d773d0e464b69dc12.tar.gz
mediapointer-dvb-s2-4d682b8babdcf28093b5530d773d0e464b69dc12.tar.bz2
ir-common: optimize bit extract function
From: Trent Piepho <xyzzy@speakeasy.org> 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 <xyzzy@speakeasy.org>
Diffstat (limited to 'linux/drivers/media/common/ir-functions.c')
-rw-r--r--linux/drivers/media/common/ir-functions.c23
1 files changed, 11 insertions, 12 deletions
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;
}