blob: 71944b0f09de7e1cf52a5b08eeb0fe16bd9605e4 [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
10#include <linux/config.h>
11#include <linux/compiler.h>
12#include <asm/byteorder.h>
13
14extern int test_and_set_bit(unsigned long nr, volatile unsigned long *addr);
15extern int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr);
16extern int test_and_change_bit(unsigned long nr, volatile unsigned long *addr);
17extern void set_bit(unsigned long nr, volatile unsigned long *addr);
18extern void clear_bit(unsigned long nr, volatile unsigned long *addr);
19extern void change_bit(unsigned long nr, volatile unsigned long *addr);
20
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080021#include <asm-generic/bitops/non-atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#ifdef CONFIG_SMP
David S. Miller4f071182005-08-29 12:46:22 -070024#define smp_mb__before_clear_bit() membar_storeload_loadload()
25#define smp_mb__after_clear_bit() membar_storeload_storestore()
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#else
27#define smp_mb__before_clear_bit() barrier()
28#define smp_mb__after_clear_bit() barrier()
29#endif
30
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080031#include <asm-generic/bitops/ffz.h>
32#include <asm-generic/bitops/__ffs.h>
33#include <asm-generic/bitops/fls.h>
34#include <asm-generic/bitops/fls64.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36#ifdef __KERNEL__
37
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080038#include <asm-generic/bitops/sched.h>
39#include <asm-generic/bitops/ffs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41/*
42 * hweightN: returns the hamming weight (i.e. the number
43 * of bits set) of a N-bit word
44 */
45
46#ifdef ULTRA_HAS_POPULATION_COUNT
47
David S. Miller6593eae2005-07-24 19:35:28 -070048static inline unsigned int hweight64(unsigned long w)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
50 unsigned int res;
51
52 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w));
53 return res;
54}
55
David S. Miller6593eae2005-07-24 19:35:28 -070056static inline unsigned int hweight32(unsigned int w)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
58 unsigned int res;
59
60 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffffffff));
61 return res;
62}
63
David S. Miller6593eae2005-07-24 19:35:28 -070064static inline unsigned int hweight16(unsigned int w)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
66 unsigned int res;
67
68 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffff));
69 return res;
70}
71
David S. Miller6593eae2005-07-24 19:35:28 -070072static inline unsigned int hweight8(unsigned int w)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
74 unsigned int res;
75
76 __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xff));
77 return res;
78}
79
80#else
81
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080082#include <asm-generic/bitops/hweight.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84#endif
85#endif /* __KERNEL__ */
86
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080087#include <asm-generic/bitops/find.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89#ifdef __KERNEL__
90
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080091#include <asm-generic/bitops/ext2-non-atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#define ext2_set_bit_atomic(lock,nr,addr) \
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080094 test_and_set_bit((nr) ^ 0x38,(unsigned long *)(addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#define ext2_clear_bit_atomic(lock,nr,addr) \
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080096 test_and_clear_bit((nr) ^ 0x38,(unsigned long *)(addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Akinobu Mita2d78d4b2006-03-26 01:39:40 -080098#include <asm-generic/bitops/minix.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100#endif /* __KERNEL__ */
101
102#endif /* defined(_SPARC64_BITOPS_H) */