• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _PERF_LINUX_BITOPS_H_
2 #define _PERF_LINUX_BITOPS_H_
3 
4 /* ANDROID_CHANGE_BEGIN */
5 #if 0
6 #include <linux/kernel.h>
7 #include <linux/compiler.h>
8 #include <asm/hweight.h>
9 #else
10 #include "kernel.h"
11 #include "compiler.h"
12 #include "../asm/hweight.h"
13 #if defined(__BIONIC__) || defined(__APPLE__)
14 #define __WORDSIZE 32
15 #endif
16 #endif
17 /* ANDROID_CHANGE_END */
18 
19 #define BITS_PER_LONG __WORDSIZE
20 #define BITS_PER_BYTE           8
21 #define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
22 
set_bit(int nr,unsigned long * addr)23 static inline void set_bit(int nr, unsigned long *addr)
24 {
25 	addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG);
26 }
27 
clear_bit(int nr,unsigned long * addr)28 static inline void clear_bit(int nr, unsigned long *addr)
29 {
30 	addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG));
31 }
32 
test_bit(unsigned int nr,const unsigned long * addr)33 static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
34 {
35 	return ((1UL << (nr % BITS_PER_LONG)) &
36 		(((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
37 }
38 
hweight_long(unsigned long w)39 static inline unsigned long hweight_long(unsigned long w)
40 {
41 	return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
42 }
43 
44 #endif
45