V4L/DVB (5832): ir-common: optimize bit extract function
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>
This commit is contained in:
Родитель
ba2cf98249
Коммит
d67be61ebe
|
@ -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)
|
u32 ir_extract_bits(u32 data, u32 mask)
|
||||||
{
|
{
|
||||||
int mbit, vbit;
|
u32 vbit = 1, value = 0;
|
||||||
u32 value;
|
|
||||||
|
|
||||||
value = 0;
|
do {
|
||||||
vbit = 0;
|
if (mask&1) {
|
||||||
for (mbit = 0; mbit < 32; mbit++) {
|
if (data&1)
|
||||||
if (!(mask & ((u32)1 << mbit)))
|
value |= vbit;
|
||||||
continue;
|
vbit<<=1;
|
||||||
if (data & ((u32)1 << mbit))
|
|
||||||
value |= (1 << vbit);
|
|
||||||
vbit++;
|
|
||||||
}
|
}
|
||||||
|
data>>=1;
|
||||||
|
} while (mask>>=1);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче