Path: blob/master/arch/blackfin/include/asm/bitops.h
15126 views
/*1* Copyright 2004-2009 Analog Devices Inc.2*3* Licensed under the GPL-2 or later.4*/56#ifndef _BLACKFIN_BITOPS_H7#define _BLACKFIN_BITOPS_H89#include <linux/compiler.h>1011#include <asm-generic/bitops/__ffs.h>12#include <asm-generic/bitops/ffz.h>13#include <asm-generic/bitops/fls.h>14#include <asm-generic/bitops/__fls.h>15#include <asm-generic/bitops/fls64.h>16#include <asm-generic/bitops/find.h>1718#ifndef _LINUX_BITOPS_H19#error only <linux/bitops.h> can be included directly20#endif2122#include <asm-generic/bitops/sched.h>23#include <asm-generic/bitops/ffs.h>24#include <asm-generic/bitops/const_hweight.h>25#include <asm-generic/bitops/lock.h>2627#include <asm-generic/bitops/ext2-atomic.h>2829#ifndef CONFIG_SMP30#include <linux/irqflags.h>3132/*33* clear_bit may not imply a memory barrier34*/35#ifndef smp_mb__before_clear_bit36#define smp_mb__before_clear_bit() smp_mb()37#define smp_mb__after_clear_bit() smp_mb()38#endif39#include <asm-generic/bitops/atomic.h>40#include <asm-generic/bitops/non-atomic.h>41#else4243#include <asm/byteorder.h> /* swab32 */44#include <linux/linkage.h>4546asmlinkage int __raw_bit_set_asm(volatile unsigned long *addr, int nr);4748asmlinkage int __raw_bit_clear_asm(volatile unsigned long *addr, int nr);4950asmlinkage int __raw_bit_toggle_asm(volatile unsigned long *addr, int nr);5152asmlinkage int __raw_bit_test_set_asm(volatile unsigned long *addr, int nr);5354asmlinkage int __raw_bit_test_clear_asm(volatile unsigned long *addr, int nr);5556asmlinkage int __raw_bit_test_toggle_asm(volatile unsigned long *addr, int nr);5758asmlinkage int __raw_bit_test_asm(const volatile unsigned long *addr, int nr);5960static inline void set_bit(int nr, volatile unsigned long *addr)61{62volatile unsigned long *a = addr + (nr >> 5);63__raw_bit_set_asm(a, nr & 0x1f);64}6566static inline void clear_bit(int nr, volatile unsigned long *addr)67{68volatile unsigned long *a = addr + (nr >> 5);69__raw_bit_clear_asm(a, nr & 0x1f);70}7172static inline void change_bit(int nr, volatile unsigned long *addr)73{74volatile unsigned long *a = addr + (nr >> 5);75__raw_bit_toggle_asm(a, nr & 0x1f);76}7778static inline int test_bit(int nr, const volatile unsigned long *addr)79{80volatile const unsigned long *a = addr + (nr >> 5);81return __raw_bit_test_asm(a, nr & 0x1f) != 0;82}8384static inline int test_and_set_bit(int nr, volatile unsigned long *addr)85{86volatile unsigned long *a = addr + (nr >> 5);87return __raw_bit_test_set_asm(a, nr & 0x1f);88}8990static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)91{92volatile unsigned long *a = addr + (nr >> 5);93return __raw_bit_test_clear_asm(a, nr & 0x1f);94}9596static inline int test_and_change_bit(int nr, volatile unsigned long *addr)97{98volatile unsigned long *a = addr + (nr >> 5);99return __raw_bit_test_toggle_asm(a, nr & 0x1f);100}101102/*103* clear_bit() doesn't provide any barrier for the compiler.104*/105#define smp_mb__before_clear_bit() barrier()106#define smp_mb__after_clear_bit() barrier()107108#define test_bit __skip_test_bit109#include <asm-generic/bitops/non-atomic.h>110#undef test_bit111112#endif /* CONFIG_SMP */113114/* Needs to be after test_bit and friends */115#include <asm-generic/bitops/le.h>116117/*118* hweightN: returns the hamming weight (i.e. the number119* of bits set) of a N-bit word120*/121122static inline unsigned int __arch_hweight32(unsigned int w)123{124unsigned int res;125126__asm__ ("%0.l = ONES %1;"127"%0 = %0.l (Z);"128: "=d" (res) : "d" (w));129return res;130}131132static inline unsigned int __arch_hweight64(__u64 w)133{134return __arch_hweight32((unsigned int)(w >> 32)) +135__arch_hweight32((unsigned int)w);136}137138static inline unsigned int __arch_hweight16(unsigned int w)139{140return __arch_hweight32(w & 0xffff);141}142143static inline unsigned int __arch_hweight8(unsigned int w)144{145return __arch_hweight32(w & 0xff);146}147148#endif /* _BLACKFIN_BITOPS_H */149150151