1/* 2 * Port on Texas Instruments TMS320C6x architecture 3 * 4 * Copyright (C) 2004, 2009, 2010 Texas Instruments Incorporated 5 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com) 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 */ 11#ifndef _ASM_C6X_BITOPS_H 12#define _ASM_C6X_BITOPS_H 13 14#ifdef __KERNEL__ 15 16#include <linux/bitops.h> 17#include <asm/byteorder.h> 18#include <asm/barrier.h> 19 20/* 21 * We are lucky, DSP is perfect for bitops: do it in 3 cycles 22 */ 23 24/** 25 * __ffs - find first bit in word. 26 * @word: The word to search 27 * 28 * Undefined if no bit exists, so code should check against 0 first. 29 * Note __ffs(0) = undef, __ffs(1) = 0, __ffs(0x80000000) = 31. 30 * 31 */ 32static inline unsigned long __ffs(unsigned long x) 33{ 34 asm (" bitr .M1 %0,%0\n" 35 " nop\n" 36 " lmbd .L1 1,%0,%0\n" 37 : "+a"(x)); 38 39 return x; 40} 41 42/* 43 * ffz - find first zero in word. 44 * @word: The word to search 45 * 46 * Undefined if no zero exists, so code should check against ~0UL first. 47 */ 48#define ffz(x) __ffs(~(x)) 49 50/** 51 * fls - find last (most-significant) bit set 52 * @x: the word to search 53 * 54 * This is defined the same way as ffs. 55 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. 56 */ 57static inline int fls(unsigned int x) 58{ 59 if (!x) 60 return 0; 61 62 asm (" lmbd .L1 1,%0,%0\n" : "+a"(x)); 63 64 return 32 - x; 65} 66 67/** 68 * ffs - find first bit set 69 * @x: the word to search 70 * 71 * This is defined the same way as 72 * the libc and compiler builtin ffs routines, therefore 73 * differs in spirit from the above ffz (man ffs). 74 * Note ffs(0) = 0, ffs(1) = 1, ffs(0x80000000) = 32. 75 */ 76static inline int ffs(int x) 77{ 78 if (!x) 79 return 0; 80 81 return __ffs(x) + 1; 82} 83 84#include <asm-generic/bitops/__fls.h> 85#include <asm-generic/bitops/fls64.h> 86#include <asm-generic/bitops/find.h> 87 88#include <asm-generic/bitops/sched.h> 89#include <asm-generic/bitops/hweight.h> 90#include <asm-generic/bitops/lock.h> 91 92#include <asm-generic/bitops/atomic.h> 93#include <asm-generic/bitops/non-atomic.h> 94#include <asm-generic/bitops/le.h> 95#include <asm-generic/bitops/ext2-atomic.h> 96 97#endif /* __KERNEL__ */ 98#endif /* _ASM_C6X_BITOPS_H */ 99