~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arc/include/asm/bitops.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/arc/include/asm/bitops.h (Architecture alpha) and /arch/ppc/include/asm-ppc/bitops.h (Architecture ppc)


  1 /* SPDX-License-Identifier: GPL-2.0-only */         1 
  2 /*                                                
  3  * Copyright (C) 2004, 2007-2010, 2011-2012 Sy    
  4  */                                               
  5                                                   
  6 #ifndef _ASM_BITOPS_H                             
  7 #define _ASM_BITOPS_H                             
  8                                                   
  9 #ifndef _LINUX_BITOPS_H                           
 10 #error only <linux/bitops.h> can be included d    
 11 #endif                                            
 12                                                   
 13 #ifndef __ASSEMBLY__                              
 14                                                   
 15 #include <linux/types.h>                          
 16 #include <linux/compiler.h>                       
 17                                                   
 18 #ifdef CONFIG_ISA_ARCOMPACT                       
 19                                                   
 20 /*                                                
 21  * Count the number of zeros, starting from MS    
 22  * Helper for fls( ) friends                      
 23  * This is a pure count, so (1-32) or (0-31) d    
 24  * It could be 0 to 32, based on num of 0's in    
 25  * clz(0x8000_0000) = 0, clz(0xFFFF_FFFF)=0, c    
 26  */                                               
 27 static inline __attribute__ ((const)) int clz(    
 28 {                                                 
 29         unsigned int res;                         
 30                                                   
 31         __asm__ __volatile__(                     
 32         "       norm.f  %0, %1          \n"       
 33         "       mov.n   %0, 0           \n"       
 34         "       add.p   %0, %0, 1       \n"       
 35         : "=r"(res)                               
 36         : "r"(x)                                  
 37         : "cc");                                  
 38                                                   
 39         return res;                               
 40 }                                                 
 41                                                   
 42 static inline int constant_fls(unsigned int x)    
 43 {                                                 
 44         int r = 32;                               
 45                                                   
 46         if (!x)                                   
 47                 return 0;                         
 48         if (!(x & 0xffff0000u)) {                 
 49                 x <<= 16;                         
 50                 r -= 16;                          
 51         }                                         
 52         if (!(x & 0xff000000u)) {                 
 53                 x <<= 8;                          
 54                 r -= 8;                           
 55         }                                         
 56         if (!(x & 0xf0000000u)) {                 
 57                 x <<= 4;                          
 58                 r -= 4;                           
 59         }                                         
 60         if (!(x & 0xc0000000u)) {                 
 61                 x <<= 2;                          
 62                 r -= 2;                           
 63         }                                         
 64         if (!(x & 0x80000000u))                   
 65                 r -= 1;                           
 66         return r;                                 
 67 }                                                 
 68                                                   
 69 /*                                                
 70  * fls = Find Last Set in word                    
 71  * @result: [1-32]                                
 72  * fls(1) = 1, fls(0x80000000) = 32, fls(0) =     
 73  */                                               
 74 static inline __attribute__ ((const)) int fls(    
 75 {                                                 
 76         if (__builtin_constant_p(x))              
 77                return constant_fls(x);            
 78                                                   
 79         return 32 - clz(x);                       
 80 }                                                 
 81                                                   
 82 /*                                                
 83  * __fls: Similar to fls, but zero based (0-31    
 84  */                                               
 85 static inline __attribute__ ((const)) unsigned    
 86 {                                                 
 87         if (!x)                                   
 88                 return 0;                         
 89         else                                      
 90                 return fls(x) - 1;                
 91 }                                                 
 92                                                   
 93 /*                                                
 94  * ffs = Find First Set in word (LSB to MSB)      
 95  * @result: [1-32], 0 if all 0's                  
 96  */                                               
 97 #define ffs(x)  ({ unsigned long __t = (x); fl    
 98                                                   
 99 /*                                                
100  * __ffs: Similar to ffs, but zero based (0-31    
101  */                                               
102 static inline __attribute__ ((const)) unsigned    
103 {                                                 
104         if (!word)                                
105                 return word;                      
106                                                   
107         return ffs(word) - 1;                     
108 }                                                 
109                                                   
110 #else   /* CONFIG_ISA_ARCV2 */                    
111                                                   
112 /*                                                
113  * fls = Find Last Set in word                    
114  * @result: [1-32]                                
115  * fls(1) = 1, fls(0x80000000) = 32, fls(0) =     
116  */                                               
117 static inline __attribute__ ((const)) int fls(    
118 {                                                 
119         int n;                                    
120                                                   
121         asm volatile(                             
122         "       fls.f   %0, %1          \n"  /    
123         "       add.nz  %0, %0, 1       \n"  /    
124         : "=r"(n)       /* Early clobber not n    
125         : "r"(x)                                  
126         : "cc");                                  
127                                                   
128         return n;                                 
129 }                                                 
130                                                   
131 /*                                                
132  * __fls: Similar to fls, but zero based (0-31    
133  */                                               
134 static inline __attribute__ ((const)) unsigned    
135 {                                                 
136         /* FLS insn has exactly same semantics    
137         return  __builtin_arc_fls(x);             
138 }                                                 
139                                                   
140 /*                                                
141  * ffs = Find First Set in word (LSB to MSB)      
142  * @result: [1-32], 0 if all 0's                  
143  */                                               
144 static inline __attribute__ ((const)) int ffs(    
145 {                                                 
146         int n;                                    
147                                                   
148         asm volatile(                             
149         "       ffs.f   %0, %1          \n"  /    
150         "       add.nz  %0, %0, 1       \n"  /    
151         "       mov.z   %0, 0           \n"  /    
152         : "=r"(n)       /* Early clobber not n    
153         : "r"(x)                                  
154         : "cc");                                  
155                                                   
156         return n;                                 
157 }                                                 
158                                                   
159 /*                                                
160  * __ffs: Similar to ffs, but zero based (0-31    
161  */                                               
162 static inline __attribute__ ((const)) unsigned    
163 {                                                 
164         unsigned long n;                          
165                                                   
166         asm volatile(                             
167         "       ffs.f   %0, %1          \n"  /    
168         "       mov.z   %0, 0           \n"  /    
169         : "=r"(n)                                 
170         : "r"(x)                                  
171         : "cc");                                  
172                                                   
173         return n;                                 
174                                                   
175 }                                                 
176                                                   
177 #endif  /* CONFIG_ISA_ARCOMPACT */                
178                                                   
179 /*                                                
180  * ffz = Find First Zero in word.                 
181  * @return:[0-31], 32 if all 1's                  
182  */                                               
183 #define ffz(x)  __ffs(~(x))                       
184                                                   
185 #include <asm-generic/bitops/hweight.h>           
186 #include <asm-generic/bitops/fls64.h>             
187 #include <asm-generic/bitops/sched.h>             
188 #include <asm-generic/bitops/lock.h>              
189 #include <asm-generic/bitops/atomic.h>            
190 #include <asm-generic/bitops/non-atomic.h>        
191                                                   
192 #include <asm-generic/bitops/le.h>                
193 #include <asm-generic/bitops/ext2-atomic-setbi    
194                                                   
195 #endif /* !__ASSEMBLY__ */                        
196                                                   
197 #endif                                            
198                                                   

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php