Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bitops.h
Go to the documentation of this file.
1 /*
2  * Copyright 1992, Linus Torvalds.
3  * Copyright 2010 Tilera Corporation. All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation, version 2.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12  * NON INFRINGEMENT. See the GNU General Public License for
13  * more details.
14  */
15 
16 #ifndef _ASM_TILE_BITOPS_H
17 #define _ASM_TILE_BITOPS_H
18 
19 #include <linux/types.h>
20 
21 #ifndef _LINUX_BITOPS_H
22 #error only <linux/bitops.h> can be included directly
23 #endif
24 
25 #ifdef __tilegx__
26 #include <asm/bitops_64.h>
27 #else
28 #include <asm/bitops_32.h>
29 #endif
30 
37 static inline unsigned long __ffs(unsigned long word)
38 {
39  return __builtin_ctzl(word);
40 }
41 
48 static inline unsigned long ffz(unsigned long word)
49 {
50  return __builtin_ctzl(~word);
51 }
52 
59 static inline unsigned long __fls(unsigned long word)
60 {
61  return (sizeof(word) * 8) - 1 - __builtin_clzl(word);
62 }
63 
75 static inline int ffs(int x)
76 {
77  return __builtin_ffs(x);
78 }
79 
80 static inline int fls64(__u64 w)
81 {
82  return (sizeof(__u64) * 8) - __builtin_clzll(w);
83 }
84 
96 static inline int fls(int x)
97 {
98  return fls64((unsigned int) x);
99 }
100 
101 static inline unsigned int __arch_hweight32(unsigned int w)
102 {
103  return __builtin_popcount(w);
104 }
105 
106 static inline unsigned int __arch_hweight16(unsigned int w)
107 {
108  return __builtin_popcount(w & 0xffff);
109 }
110 
111 static inline unsigned int __arch_hweight8(unsigned int w)
112 {
113  return __builtin_popcount(w & 0xff);
114 }
115 
116 static inline unsigned long __arch_hweight64(__u64 w)
117 {
118  return __builtin_popcountll(w);
119 }
120 
122 #include <asm-generic/bitops/lock.h>
123 #include <asm-generic/bitops/find.h>
126 #include <asm-generic/bitops/le.h>
127 
128 #endif /* _ASM_TILE_BITOPS_H */