MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / ls1c_fls

Function ls1c_fls

bsp/loongson/ls1cdev/libraries/ls1c_public.c:157–190  ·  view source on GitHub ↗

* fls - find last (most-significant) bit set * @x: the word to search * * This is defined the same way as ffs. * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. */

Source from the content-addressed store, hash-verified

155 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
156 */
157int ls1c_fls(int x)
158{
159 int r = 32;
160
161 if (!x)
162 return 0;
163 if (!(x & 0xffff0000u))
164 {
165 x <<= 16;
166 r -= 16;
167 }
168 if (!(x & 0xff000000u))
169 {
170 x <<= 8;
171 r -= 8;
172 }
173 if (!(x & 0xf0000000u))
174 {
175 x <<= 4;
176 r -= 4;
177 }
178 if (!(x & 0xc0000000u))
179 {
180 x <<= 2;
181 r -= 2;
182 }
183 if (!(x & 0x80000000u))
184 {
185 x <<= 1;
186 r -= 1;
187 }
188
189 return r;
190}
191
192

Callers 1

ls1c_spi_get_divFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected