~ubuntu-branches/ubuntu/precise/linux-lowlatency/precise

« back to all changes in this revision

Viewing changes to tools/perf/util/include/linux/bitops.h

  • Committer: Package Import Robot
  • Author(s): Alessio Igor Bogani
  • Date: 2011-10-26 11:13:05 UTC
  • Revision ID: package-import@ubuntu.com-20111026111305-tz023xykf0i6eosh
Tags: upstream-3.2.0
ImportĀ upstreamĀ versionĀ 3.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _PERF_LINUX_BITOPS_H_
 
2
#define _PERF_LINUX_BITOPS_H_
 
3
 
 
4
#include <linux/kernel.h>
 
5
#include <linux/compiler.h>
 
6
#include <asm/hweight.h>
 
7
 
 
8
#define BITS_PER_LONG __WORDSIZE
 
9
#define BITS_PER_BYTE           8
 
10
#define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
 
11
 
 
12
static inline void set_bit(int nr, unsigned long *addr)
 
13
{
 
14
        addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG);
 
15
}
 
16
 
 
17
static inline void clear_bit(int nr, unsigned long *addr)
 
18
{
 
19
        addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG));
 
20
}
 
21
 
 
22
static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
 
23
{
 
24
        return ((1UL << (nr % BITS_PER_LONG)) &
 
25
                (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
 
26
}
 
27
 
 
28
static inline unsigned long hweight_long(unsigned long w)
 
29
{
 
30
        return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
 
31
}
 
32
 
 
33
#endif