0001
0002
0003
0004
0005
0006 #ifndef _ASM_BITOPS_H
0007 #define _ASM_BITOPS_H
0008
0009 #ifndef _LINUX_BITOPS_H
0010 #error only <linux/bitops.h> can be included directly
0011 #endif
0012
0013 #ifndef __ASSEMBLY__
0014
0015 #include <linux/types.h>
0016 #include <linux/compiler.h>
0017
0018 #ifdef CONFIG_ISA_ARCOMPACT
0019
0020
0021
0022
0023
0024
0025
0026
0027 static inline __attribute__ ((const)) int clz(unsigned int x)
0028 {
0029 unsigned int res;
0030
0031 __asm__ __volatile__(
0032 " norm.f %0, %1 \n"
0033 " mov.n %0, 0 \n"
0034 " add.p %0, %0, 1 \n"
0035 : "=r"(res)
0036 : "r"(x)
0037 : "cc");
0038
0039 return res;
0040 }
0041
0042 static inline int constant_fls(unsigned int x)
0043 {
0044 int r = 32;
0045
0046 if (!x)
0047 return 0;
0048 if (!(x & 0xffff0000u)) {
0049 x <<= 16;
0050 r -= 16;
0051 }
0052 if (!(x & 0xff000000u)) {
0053 x <<= 8;
0054 r -= 8;
0055 }
0056 if (!(x & 0xf0000000u)) {
0057 x <<= 4;
0058 r -= 4;
0059 }
0060 if (!(x & 0xc0000000u)) {
0061 x <<= 2;
0062 r -= 2;
0063 }
0064 if (!(x & 0x80000000u))
0065 r -= 1;
0066 return r;
0067 }
0068
0069
0070
0071
0072
0073
0074 static inline __attribute__ ((const)) int fls(unsigned int x)
0075 {
0076 if (__builtin_constant_p(x))
0077 return constant_fls(x);
0078
0079 return 32 - clz(x);
0080 }
0081
0082
0083
0084
0085 static inline __attribute__ ((const)) int __fls(unsigned long x)
0086 {
0087 if (!x)
0088 return 0;
0089 else
0090 return fls(x) - 1;
0091 }
0092
0093
0094
0095
0096
0097 #define ffs(x) ({ unsigned long __t = (x); fls(__t & -__t); })
0098
0099
0100
0101
0102 static inline __attribute__ ((const)) unsigned long __ffs(unsigned long word)
0103 {
0104 if (!word)
0105 return word;
0106
0107 return ffs(word) - 1;
0108 }
0109
0110 #else
0111
0112
0113
0114
0115
0116
0117 static inline __attribute__ ((const)) int fls(unsigned int x)
0118 {
0119 int n;
0120
0121 asm volatile(
0122 " fls.f %0, %1 \n"
0123 " add.nz %0, %0, 1 \n"
0124 : "=r"(n)
0125 : "r"(x)
0126 : "cc");
0127
0128 return n;
0129 }
0130
0131
0132
0133
0134 static inline __attribute__ ((const)) int __fls(unsigned long x)
0135 {
0136
0137 return __builtin_arc_fls(x);
0138 }
0139
0140
0141
0142
0143
0144 static inline __attribute__ ((const)) int ffs(unsigned int x)
0145 {
0146 int n;
0147
0148 asm volatile(
0149 " ffs.f %0, %1 \n"
0150 " add.nz %0, %0, 1 \n"
0151 " mov.z %0, 0 \n"
0152 : "=r"(n)
0153 : "r"(x)
0154 : "cc");
0155
0156 return n;
0157 }
0158
0159
0160
0161
0162 static inline __attribute__ ((const)) unsigned long __ffs(unsigned long x)
0163 {
0164 unsigned long n;
0165
0166 asm volatile(
0167 " ffs.f %0, %1 \n"
0168 " mov.z %0, 0 \n"
0169 : "=r"(n)
0170 : "r"(x)
0171 : "cc");
0172
0173 return n;
0174
0175 }
0176
0177 #endif
0178
0179
0180
0181
0182
0183 #define ffz(x) __ffs(~(x))
0184
0185 #include <asm-generic/bitops/hweight.h>
0186 #include <asm-generic/bitops/fls64.h>
0187 #include <asm-generic/bitops/sched.h>
0188 #include <asm-generic/bitops/lock.h>
0189 #include <asm-generic/bitops/atomic.h>
0190 #include <asm-generic/bitops/non-atomic.h>
0191
0192 #include <asm-generic/bitops/le.h>
0193 #include <asm-generic/bitops/ext2-atomic-setbit.h>
0194
0195 #endif
0196
0197 #endif