diff options
| author | 勤为本 <[email protected]> | 2017-10-23 17:10:48 +0800 |
|---|---|---|
| committer | 勤为本 <[email protected]> | 2017-10-23 17:10:48 +0800 |
| commit | 51d02f98d6992a8a2db7c8aa20abfbff5cc3a8e3 (patch) | |
| tree | fa9db046047f6dce43e174731d25e9b45b7649e3 /bsp/ls1cdev/libraries/ls1c_public.c | |
| parent | b2fbe4df011edc3ae1679ede87ce06b5744ac771 (diff) | |
增加龙芯1c的硬件SPI相关接口
Diffstat (limited to 'bsp/ls1cdev/libraries/ls1c_public.c')
| -rw-r--r-- | bsp/ls1cdev/libraries/ls1c_public.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/bsp/ls1cdev/libraries/ls1c_public.c b/bsp/ls1cdev/libraries/ls1c_public.c index a04f68a877..3e57e9a50a 100644 --- a/bsp/ls1cdev/libraries/ls1c_public.c +++ b/bsp/ls1cdev/libraries/ls1c_public.c @@ -137,3 +137,46 @@ int ls1c_ffs(int x) } +/* + * 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. + */ +int ls1c_fls(int x) +{ + int r = 32; + + if (!x) + return 0; + if (!(x & 0xffff0000u)) + { + x <<= 16; + r -= 16; + } + if (!(x & 0xff000000u)) + { + x <<= 8; + r -= 8; + } + if (!(x & 0xf0000000u)) + { + x <<= 4; + r -= 4; + } + if (!(x & 0xc0000000u)) + { + x <<= 2; + r -= 2; + } + if (!(x & 0x80000000u)) + { + x <<= 1; + r -= 1; + } + + return r; +} + + |
