OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [include/] [asm-sparc64/] [bitops.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1276 phoenix
/* $Id: bitops.h,v 1.1.1.1 2004-04-15 03:00:53 phoenix 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 <asm/byteorder.h>
11
 
12
extern long ___test_and_set_bit(unsigned long nr, volatile void *addr);
13
extern long ___test_and_clear_bit(unsigned long nr, volatile void *addr);
14
extern long ___test_and_change_bit(unsigned long nr, volatile void *addr);
15
 
16
#define test_and_set_bit(nr,addr)       ({___test_and_set_bit(nr,addr)!=0;})
17
#define test_and_clear_bit(nr,addr)     ({___test_and_clear_bit(nr,addr)!=0;})
18
#define test_and_change_bit(nr,addr)    ({___test_and_change_bit(nr,addr)!=0;})
19
#define set_bit(nr,addr)                ((void)___test_and_set_bit(nr,addr))
20
#define clear_bit(nr,addr)              ((void)___test_and_clear_bit(nr,addr))
21
#define change_bit(nr,addr)             ((void)___test_and_change_bit(nr,addr))
22
 
23
/* "non-atomic" versions... */
24
#define __set_bit(X,Y)                                  \
25
do {    unsigned long __nr = (X);                       \
26
        long *__m = ((long *) (Y)) + (__nr >> 6);       \
27
        *__m |= (1UL << (__nr & 63));                   \
28
} while (0)
29
#define __clear_bit(X,Y)                                \
30
do {    unsigned long __nr = (X);                       \
31
        long *__m = ((long *) (Y)) + (__nr >> 6);       \
32
        *__m &= ~(1UL << (__nr & 63));                  \
33
} while (0)
34
#define __change_bit(X,Y)                               \
35
do {    unsigned long __nr = (X);                       \
36
        long *__m = ((long *) (Y)) + (__nr >> 6);       \
37
        *__m ^= (1UL << (__nr & 63));                   \
38
} while (0)
39
#define __test_and_set_bit(X,Y)                         \
40
({      unsigned long __nr = (X);                       \
41
        long *__m = ((long *) (Y)) + (__nr >> 6);       \
42
        long __old = *__m;                              \
43
        long __mask = (1UL << (__nr & 63));             \
44
        *__m = (__old | __mask);                        \
45
        ((__old & __mask) != 0);                 \
46
})
47
#define __test_and_clear_bit(X,Y)                       \
48
({      unsigned long __nr = (X);                       \
49
        long *__m = ((long *) (Y)) + (__nr >> 6);       \
50
        long __old = *__m;                              \
51
        long __mask = (1UL << (__nr & 63));             \
52
        *__m = (__old & ~__mask);                       \
53
        ((__old & __mask) != 0);                 \
54
})
55
#define __test_and_change_bit(X,Y)                      \
56
({      unsigned long __nr = (X);                       \
57
        long *__m = ((long *) (Y)) + (__nr >> 6);       \
58
        long __old = *__m;                              \
59
        long __mask = (1UL << (__nr & 63));             \
60
        *__m = (__old ^ __mask);                        \
61
        ((__old & __mask) != 0);                 \
62
})
63
 
64
#define smp_mb__before_clear_bit()      do { } while(0)
65
#define smp_mb__after_clear_bit()       do { } while(0)
66
 
67
extern __inline__ int test_bit(int nr, __const__ void *addr)
68
{
69
        return (1UL & (((__const__ long *) addr)[nr >> 6] >> (nr & 63))) != 0UL;
70
}
71
 
72
/* The easy/cheese version for now. */
73
extern __inline__ unsigned long ffz(unsigned long word)
74
{
75
        unsigned long result;
76
 
77
#ifdef ULTRA_HAS_POPULATION_COUNT       /* Thanks for nothing Sun... */
78
        __asm__ __volatile__(
79
"       brz,pn  %0, 1f\n"
80
"        neg    %0, %%g1\n"
81
"       xnor    %0, %%g1, %%g2\n"
82
"       popc    %%g2, %0\n"
83
"1:     " : "=&r" (result)
84
          : "0" (word)
85
          : "g1", "g2");
86
#else
87
#if 1 /* def EASY_CHEESE_VERSION */
88
        result = 0;
89
        while(word & 1) {
90
                result++;
91
                word >>= 1;
92
        }
93
#else
94
        unsigned long tmp;
95
 
96
        result = 0;
97
        tmp = ~word & -~word;
98
        if (!(unsigned)tmp) {
99
                tmp >>= 32;
100
                result = 32;
101
        }
102
        if (!(unsigned short)tmp) {
103
                tmp >>= 16;
104
                result += 16;
105
        }
106
        if (!(unsigned char)tmp) {
107
                tmp >>= 8;
108
                result += 8;
109
        }
110
        if (tmp & 0xf0) result += 4;
111
        if (tmp & 0xcc) result += 2;
112
        if (tmp & 0xaa) result ++;
113
#endif
114
#endif
115
        return result;
116
}
117
 
118
#ifdef __KERNEL__
119
 
120
/*
121
 * ffs: find first bit set. This is defined the same way as
122
 * the libc and compiler builtin ffs routines, therefore
123
 * differs in spirit from the above ffz (man ffs).
124
 */
125
 
126
#define ffs(x) generic_ffs(x)
127
 
128
/*
129
 * hweightN: returns the hamming weight (i.e. the number
130
 * of bits set) of a N-bit word
131
 */
132
 
133
#ifdef ULTRA_HAS_POPULATION_COUNT
134
 
135
extern __inline__ unsigned int hweight32(unsigned int w)
136
{
137
        unsigned int res;
138
 
139
        __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffffffff));
140
        return res;
141
}
142
 
143
extern __inline__ unsigned int hweight16(unsigned int w)
144
{
145
        unsigned int res;
146
 
147
        __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffff));
148
        return res;
149
}
150
 
151
extern __inline__ unsigned int hweight8(unsigned int w)
152
{
153
        unsigned int res;
154
 
155
        __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xff));
156
        return res;
157
}
158
 
159
#else
160
 
161
#define hweight32(x) generic_hweight32(x)
162
#define hweight16(x) generic_hweight16(x)
163
#define hweight8(x) generic_hweight8(x)
164
 
165
#endif
166
#endif /* __KERNEL__ */
167
 
168
/* find_next_zero_bit() finds the first zero bit in a bit string of length
169
 * 'size' bits, starting the search at bit 'offset'. This is largely based
170
 * on Linus's ALPHA routines, which are pretty portable BTW.
171
 */
172
 
173
extern __inline__ unsigned long find_next_zero_bit(void *addr, unsigned long size, unsigned long offset)
174
{
175
        unsigned long *p = ((unsigned long *) addr) + (offset >> 6);
176
        unsigned long result = offset & ~63UL;
177
        unsigned long tmp;
178
 
179
        if (offset >= size)
180
                return size;
181
        size -= result;
182
        offset &= 63UL;
183
        if (offset) {
184
                tmp = *(p++);
185
                tmp |= ~0UL >> (64-offset);
186
                if (size < 64)
187
                        goto found_first;
188
                if (~tmp)
189
                        goto found_middle;
190
                size -= 64;
191
                result += 64;
192
        }
193
        while (size & ~63UL) {
194
                if (~(tmp = *(p++)))
195
                        goto found_middle;
196
                result += 64;
197
                size -= 64;
198
        }
199
        if (!size)
200
                return result;
201
        tmp = *p;
202
 
203
found_first:
204
        tmp |= ~0UL << size;
205
        if (tmp == ~0UL)        /* Are any bits zero? */
206
                return result + size; /* Nope. */
207
found_middle:
208
        return result + ffz(tmp);
209
}
210
 
211
#define find_first_zero_bit(addr, size) \
212
        find_next_zero_bit((addr), (size), 0)
213
 
214
extern long ___test_and_set_le_bit(int nr, volatile void *addr);
215
extern long ___test_and_clear_le_bit(int nr, volatile void *addr);
216
 
217
#define test_and_set_le_bit(nr,addr)    ({___test_and_set_le_bit(nr,addr)!=0;})
218
#define test_and_clear_le_bit(nr,addr)  ({___test_and_clear_le_bit(nr,addr)!=0;})
219
#define set_le_bit(nr,addr)             ((void)___test_and_set_le_bit(nr,addr))
220
#define clear_le_bit(nr,addr)           ((void)___test_and_clear_le_bit(nr,addr))
221
 
222
extern __inline__ int test_le_bit(int nr, __const__ void * addr)
223
{
224
        int                     mask;
225
        __const__ unsigned char *ADDR = (__const__ unsigned char *) addr;
226
 
227
        ADDR += nr >> 3;
228
        mask = 1 << (nr & 0x07);
229
        return ((mask & *ADDR) != 0);
230
}
231
 
232
#define find_first_zero_le_bit(addr, size) \
233
        find_next_zero_le_bit((addr), (size), 0)
234
 
235
extern __inline__ unsigned long find_next_zero_le_bit(void *addr, unsigned long size, unsigned long offset)
236
{
237
        unsigned long *p = ((unsigned long *) addr) + (offset >> 6);
238
        unsigned long result = offset & ~63UL;
239
        unsigned long tmp;
240
 
241
        if (offset >= size)
242
                return size;
243
        size -= result;
244
        offset &= 63UL;
245
        if(offset) {
246
                tmp = __swab64p(p++);
247
                tmp |= (~0UL >> (64-offset));
248
                if(size < 64)
249
                        goto found_first;
250
                if(~tmp)
251
                        goto found_middle;
252
                size -= 64;
253
                result += 64;
254
        }
255
        while(size & ~63) {
256
                if(~(tmp = __swab64p(p++)))
257
                        goto found_middle;
258
                result += 64;
259
                size -= 64;
260
        }
261
        if(!size)
262
                return result;
263
        tmp = __swab64p(p);
264
found_first:
265
        tmp |= (~0UL << size);
266
        if (tmp == ~0UL)        /* Are any bits zero? */
267
                return result + size; /* Nope. */
268
found_middle:
269
        return result + ffz(tmp);
270
}
271
 
272
#ifdef __KERNEL__
273
 
274
#define ext2_set_bit                    test_and_set_le_bit
275
#define ext2_clear_bit                  test_and_clear_le_bit
276
#define ext2_test_bit                   test_le_bit
277
#define ext2_find_first_zero_bit        find_first_zero_le_bit
278
#define ext2_find_next_zero_bit         find_next_zero_le_bit
279
 
280
/* Bitmap functions for the minix filesystem.  */
281
#define minix_test_and_set_bit(nr,addr) test_and_set_bit(nr,addr)
282
#define minix_set_bit(nr,addr) set_bit(nr,addr)
283
#define minix_test_and_clear_bit(nr,addr) test_and_clear_bit(nr,addr)
284
#define minix_test_bit(nr,addr) test_bit(nr,addr)
285
#define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
286
 
287
#endif /* __KERNEL__ */
288
 
289
#endif /* defined(_SPARC64_BITOPS_H) */

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.