Skip to content

Commit

Permalink
V4L/DVB (5832): ir-common: optimize bit extract function
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
  • Loading branch information
Trent Piepho authored and Mauro Carvalho Chehab committed Jul 18, 2007
1 parent ba2cf98 commit d67be61
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions drivers/media/common/ir-functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,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;
}

Expand Down

0 comments on commit d67be61

Please sign in to comment.