Path: blob/master/arch/xtensa/include/asm/bitops.h
15126 views
/*1* include/asm-xtensa/bitops.h2*3* Atomic operations that C can't guarantee us.Useful for resource counting etc.4*5* This file is subject to the terms and conditions of the GNU General Public6* License. See the file "COPYING" in the main directory of this archive7* for more details.8*9* Copyright (C) 2001 - 2007 Tensilica Inc.10*/1112#ifndef _XTENSA_BITOPS_H13#define _XTENSA_BITOPS_H1415#ifdef __KERNEL__1617#ifndef _LINUX_BITOPS_H18#error only <linux/bitops.h> can be included directly19#endif2021#include <asm/processor.h>22#include <asm/byteorder.h>23#include <asm/system.h>2425#ifdef CONFIG_SMP26# error SMP not supported on this architecture27#endif2829#define smp_mb__before_clear_bit() barrier()30#define smp_mb__after_clear_bit() barrier()3132#include <asm-generic/bitops/atomic.h>33#include <asm-generic/bitops/non-atomic.h>3435#if XCHAL_HAVE_NSA3637static inline unsigned long __cntlz (unsigned long x)38{39int lz;40asm ("nsau %0, %1" : "=r" (lz) : "r" (x));41return lz;42}4344/*45* ffz: Find first zero in word. Undefined if no zero exists.46* bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).47*/4849static inline int ffz(unsigned long x)50{51return 31 - __cntlz(~x & -~x);52}5354/*55* __ffs: Find first bit set in word. Return 0 for bit 056*/5758static inline int __ffs(unsigned long x)59{60return 31 - __cntlz(x & -x);61}6263/*64* ffs: Find first bit set in word. This is defined the same way as65* the libc and compiler builtin ffs routines, therefore66* differs in spirit from the above ffz (man ffs).67*/6869static inline int ffs(unsigned long x)70{71return 32 - __cntlz(x & -x);72}7374/*75* fls: Find last (most-significant) bit set in word.76* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.77*/7879static inline int fls (unsigned int x)80{81return 32 - __cntlz(x);82}8384/**85* __fls - find last (most-significant) set bit in a long word86* @word: the word to search87*88* Undefined if no set bit exists, so code should check against 0 first.89*/90static inline unsigned long __fls(unsigned long word)91{92return 31 - __cntlz(word);93}94#else9596/* Use the generic implementation if we don't have the nsa/nsau instructions. */9798# include <asm-generic/bitops/ffs.h>99# include <asm-generic/bitops/__ffs.h>100# include <asm-generic/bitops/ffz.h>101# include <asm-generic/bitops/fls.h>102# include <asm-generic/bitops/__fls.h>103104#endif105106#include <asm-generic/bitops/fls64.h>107#include <asm-generic/bitops/find.h>108#include <asm-generic/bitops/le.h>109110#ifdef __XTENSA_EL__111# define ext2_set_bit_atomic(lock,nr,addr) \112test_and_set_bit((nr), (unsigned long*)(addr))113# define ext2_clear_bit_atomic(lock,nr,addr) \114test_and_clear_bit((nr), (unsigned long*)(addr))115#elif defined(__XTENSA_EB__)116# define ext2_set_bit_atomic(lock,nr,addr) \117test_and_set_bit((nr) ^ 0x18, (unsigned long*)(addr))118# define ext2_clear_bit_atomic(lock,nr,addr) \119test_and_clear_bit((nr) ^ 0x18, (unsigned long*)(addr))120#else121# error processor byte order undefined!122#endif123124#include <asm-generic/bitops/hweight.h>125#include <asm-generic/bitops/lock.h>126#include <asm-generic/bitops/sched.h>127128#endif /* __KERNEL__ */129130#endif /* _XTENSA_BITOPS_H */131132133