1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #ifndef ZEPHYR_INCLUDE_ARCH_COMMON_FFS_H_
- #define ZEPHYR_INCLUDE_ARCH_COMMON_FFS_H_
- #ifndef _ASMLANGUAGE
- #include <zephyr/types.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- static ALWAYS_INLINE unsigned int find_msb_set(uint32_t op)
- {
- if (op == 0) {
- return 0;
- }
- return 32 - __builtin_clz(op);
- }
- static ALWAYS_INLINE unsigned int find_lsb_set(uint32_t op)
- {
- #ifdef CONFIG_TOOLCHAIN_HAS_BUILTIN_FFS
- return __builtin_ffs(op);
- #else
-
- int bit;
- if (op == 0) {
- return 0;
- }
- for (bit = 0; bit < 32; bit++) {
- if ((op & (1 << bit)) != 0) {
- return (bit + 1);
- }
- }
-
- return 0;
- #endif
- }
- #ifdef __cplusplus
- }
- #endif
- #endif
- #endif
|