diff options
author | Trent Piepho <xyzzy@speakeasy.org> | 2007-07-11 19:28:44 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2007-07-18 13:24:42 -0400 |
commit | d67be61ebe5efaf9c4c11bf168781d678854c966 (patch) | |
tree | 42da70f931f36b01e3cc8e516eb260212b8a650e /drivers/media | |
parent | ba2cf98249795f03792d1409a3b6aaa589ea0745 (diff) |
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>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/common/ir-functions.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/drivers/media/common/ir-functions.c b/drivers/media/common/ir-functions.c index fcb194135627..fe447a06e24e 100644 --- a/drivers/media/common/ir-functions.c +++ b/drivers/media/common/ir-functions.c | |||
@@ -107,21 +107,20 @@ void ir_input_keydown(struct input_dev *dev, struct ir_input_state *ir, | |||
107 | } | 107 | } |
108 | 108 | ||
109 | /* -------------------------------------------------------------------------- */ | 109 | /* -------------------------------------------------------------------------- */ |
110 | 110 | /* extract mask bits out of data and pack them into the result */ | |
111 | u32 ir_extract_bits(u32 data, u32 mask) | 111 | u32 ir_extract_bits(u32 data, u32 mask) |
112 | { | 112 | { |
113 | int mbit, vbit; | 113 | u32 vbit = 1, value = 0; |
114 | u32 value; | 114 | |
115 | do { | ||
116 | if (mask&1) { | ||
117 | if (data&1) | ||
118 | value |= vbit; | ||
119 | vbit<<=1; | ||
120 | } | ||
121 | data>>=1; | ||
122 | } while (mask>>=1); | ||
115 | 123 | ||
116 | value = 0; | ||
117 | vbit = 0; | ||
118 | for (mbit = 0; mbit < 32; mbit++) { | ||
119 | if (!(mask & ((u32)1 << mbit))) | ||
120 | continue; | ||
121 | if (data & ((u32)1 << mbit)) | ||
122 | value |= (1 << vbit); | ||
123 | vbit++; | ||
124 | } | ||
125 | return value; | 124 | return value; |
126 | } | 125 | } |
127 | 126 | ||