blob: 982ce8992b91fcae6a2d9e790235b718d7cfa1b1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: bitops.h,v 1.39 2002/01/30 01:40:00 davem Exp $
2 * bitops.h: Bit string operations on the V9.
3 *
4 * Copyright 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef _SPARC64_BITOPS_H
8#define _SPARC64_BITOPS_H
9
Jiri Slaby06245172007-10-18 23:40:26 -070010#ifndef _LINUX_BITOPS_H
11#error only <linux/bitops.h> can be included directly
12#endif
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/compiler.h>
15#include <asm/byteorder.h>
16
17extern int test_and_set_bit(unsigned long nr, volatile unsigned long *addr);
18extern int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr);
19extern int test_and_change_bit(unsigned long nr, volatile unsigned long *addr);
20extern void set_bit(unsigned long nr, volatile unsigned long *addr);
21extern void clear_bit(unsigned long nr, volatile unsigned long *addr);
22extern void change_bit(unsigned long nr, volatile unsigned long *addr);
23
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080024#include <asm-generic/bitops/non-atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#ifdef CONFIG_SMP
David S. Miller4f071182005-08-29 12:46:22 -070027#define smp_mb__before_clear_bit() membar_storeload_loadload()
28#define smp_mb__after_clear_bit() membar_storeload_storestore()
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#else
30#define smp_mb__before_clear_bit() barrier()
31#define smp_mb__after_clear_bit() barrier()
32#endif
33
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080034#include <asm-generic/bitops/ffz.h>
35#include <asm-generic/bitops/__ffs.h>
36#include <asm-generic/bitops/fls.h>
37#include <asm-generic/bitops/fls64.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#ifdef __KERNEL__
40
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080041#include <asm-generic/bitops/sched.h>
42#include <asm-generic/bitops/ffs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44/*
45 * hweightN: returns the hamming weight (i.e. the number
46 * of bits set) of a N-bit word
47 */
48
49#ifdef ULTRA_HAS_POPULATION_COUNT
50
David S. Miller6593eae2005-07-24 19:35:28 -070051static inline unsigned int hweight64(unsigned long w)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
53 unsigned int res;
54
55 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w));
56 return res;
57}
58
David S. Miller6593eae2005-07-24 19:35:28 -070059static inline unsigned int hweight32(unsigned int w)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 unsigned int res;
62
63 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffffffff));
64 return res;
65}
66
David S. Miller6593eae2005-07-24 19:35:28 -070067static inline unsigned int hweight16(unsigned int w)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 unsigned int res;
70
71 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffff));
72 return res;
73}
74
David S. Miller6593eae2005-07-24 19:35:28 -070075static inline unsigned int hweight8(unsigned int w)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
77 unsigned int res;
78
79 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xff));
80 return res;
81}
82
83#else
84
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080085#include <asm-generic/bitops/hweight.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87#endif
Nick Piggin26333572007-10-18 03:06:39 -070088#include <asm-generic/bitops/lock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#endif /* __KERNEL__ */
90
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080091#include <asm-generic/bitops/find.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93#ifdef __KERNEL__
94
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080095#include <asm-generic/bitops/ext2-non-atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#define ext2_set_bit_atomic(lock,nr,addr) \
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080098 test_and_set_bit((nr) ^ 0x38,(unsigned long *)(addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#define ext2_clear_bit_atomic(lock,nr,addr) \
Akinobu Mita2d78d4b2006-03-26 01:39:40 -0800100 test_and_clear_bit((nr) ^ 0x38,(unsigned long *)(addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Akinobu Mita2d78d4b2006-03-26 01:39:40 -0800102#include <asm-generic/bitops/minix.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104#endif /* __KERNEL__ */
105
106#endif /* defined(_SPARC64_BITOPS_H) */