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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uClinux-2.0.x/] [include/] [asm-m68k/] [bitops.h] - Blame information for rev 1775

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
#ifndef _M68K_BITOPS_H
2
#define _M68K_BITOPS_H
3
/*
4
 * Copyright 1992, Linus Torvalds.
5
 *
6
 * This file is subject to the terms and conditions of the GNU General Public
7
 * License.  See the file COPYING in the main directory of this archive
8
 * for more details.
9
 */
10
 
11
/*
12
 * Require 68020 or better.
13
 *
14
 * They use the standard big-endian m680x0 bit ordering.
15
 */
16
 
17
extern __inline__ int set_bit(int nr,void * vaddr)
18
{
19
        char retval;
20
 
21
        __asm__ __volatile__ ("bfset %2@{%1:#1}; sne %0"
22
             : "=d" (retval) : "d" (nr^31), "a" (vaddr));
23
 
24
        return retval;
25
}
26
 
27
extern __inline__ int clear_bit(int nr, void * vaddr)
28
{
29
        char retval;
30
 
31
        __asm__ __volatile__ ("bfclr %2@{%1:#1}; sne %0"
32
             : "=d" (retval) : "d" (nr^31), "a" (vaddr));
33
 
34
        return retval;
35
}
36
 
37
extern __inline__ int change_bit(int nr, void * vaddr)
38
{
39
        char retval;
40
 
41
        __asm__ __volatile__ ("bfchg %2@{%1:#1}; sne %0"
42
             : "=d" (retval) : "d" (nr^31), "a" (vaddr));
43
 
44
        return retval;
45
}
46
 
47
extern __inline__ int test_bit(int nr, const void * vaddr)
48
{
49
        return ((1UL << (nr & 31)) & (((const unsigned int *) vaddr)[nr >> 5])) != 0;
50
}
51
 
52
extern __inline__ int find_first_zero_bit(void * vaddr, unsigned size)
53
{
54
        unsigned long *p = vaddr, *addr = vaddr;
55
        unsigned long allones = ~0UL;
56
        int res;
57
        unsigned long num;
58
 
59
        if (!size)
60
                return 0;
61
 
62
        while (*p++ == allones)
63
        {
64
                if (size <= 32)
65
                        return (p - addr) << 5;
66
                size -= 32;
67
        }
68
 
69
        num = ~*--p;
70
        __asm__ __volatile__ ("bfffo %1{#0,#0},%0"
71
                              : "=d" (res) : "d" (num & -num));
72
        return ((p - addr) << 5) + (res ^ 31);
73
}
74
 
75
extern __inline__ int find_next_zero_bit (void *vaddr, int size,
76
                                      int offset)
77
{
78
        unsigned long *addr = vaddr;
79
        unsigned long *p = addr + (offset >> 5);
80
        int set = 0, bit = offset & 31UL, res;
81
 
82
        if (offset >= size)
83
                return size;
84
 
85
        if (bit) {
86
                unsigned long num = ~*p & (~0UL << bit);
87
 
88
                /* Look for zero in first longword */
89
                __asm__ __volatile__ ("bfffo %1{#0,#0},%0"
90
                                      : "=d" (res) : "d" (num & -num));
91
                if (res < 32)
92
                        return (offset & ~31UL) + (res ^ 31);
93
                set = 32 - bit;
94
                p++;
95
        }
96
        /* No zero yet, search remaining full bytes for a zero */
97
        res = find_first_zero_bit (p, size - 32 * (p - addr));
98
        return (offset + set + res);
99
}
100
 
101
/*
102
 * ffz = Find First Zero in word. Undefined if no zero exists,
103
 * so code should check against ~0UL first..
104
 */
105
extern __inline__ unsigned long ffz(unsigned long word)
106
{
107
        int res;
108
 
109
        __asm__ __volatile__ ("bfffo %1{#0,#0},%0"
110
                              : "=d" (res) : "d" (~word & -~word));
111
        return res ^ 31;
112
}
113
 
114
/* Bitmap functions for the minix filesystem */
115
 
116
extern __inline__ int
117
minix_find_first_zero_bit (const void *vaddr, unsigned size)
118
{
119
        const unsigned short *p = vaddr, *addr = vaddr;
120
        int res;
121
        unsigned short num;
122
 
123
        if (!size)
124
                return 0;
125
 
126
        while (*p++ == 0xffff)
127
        {
128
                if (size <= 16)
129
                        return (p - addr) << 4;
130
                size -= 16;
131
        }
132
 
133
        num = ~*--p;
134
        __asm__ __volatile__ ("bfffo %1{#16,#16},%0"
135
                              : "=d" (res) : "d" (num & -num));
136
        return ((p - addr) << 4) + (res ^ 31);
137
}
138
 
139
extern __inline__ int
140
minix_set_bit (int nr, void *vaddr)
141
{
142
        char retval;
143
 
144
        __asm__ __volatile__ ("bfset %2{%1:#1}; sne %0"
145
             : "=d" (retval) : "d" (nr^15), "m" (*(char *)vaddr));
146
 
147
        return retval;
148
}
149
 
150
extern __inline__ int
151
minix_clear_bit (int nr, void *vaddr)
152
{
153
        char retval;
154
 
155
        __asm__ __volatile__ ("bfclr %2{%1:#1}; sne %0"
156
             : "=d" (retval) : "d" (nr^15), "m" (*(char *) vaddr));
157
 
158
        return retval;
159
}
160
 
161
extern __inline__ int
162
minix_test_bit (int nr, const void *vaddr)
163
{
164
        return ((1U << (nr & 15)) & (((const unsigned short *) vaddr)[nr >> 4])) != 0;
165
}
166
 
167
/* Bitmap functions for the ext2 filesystem. */
168
 
169
extern __inline__ int
170
ext2_set_bit (int nr, void *vaddr)
171
{
172
        char retval;
173
 
174
        __asm__ __volatile__ ("bfset %2{%1,#1}; sne %0"
175
             : "=d" (retval) : "d" (nr^7), "m" (*(char *) vaddr));
176
 
177
        return retval;
178
}
179
 
180
extern __inline__ int
181
ext2_clear_bit (int nr, void *vaddr)
182
{
183
        char retval;
184
 
185
        __asm__ __volatile__ ("bfclr %2{%1,#1}; sne %0"
186
             : "=d" (retval) : "d" (nr^7), "m" (*(char *) vaddr));
187
 
188
        return retval;
189
}
190
 
191
extern __inline__ int
192
ext2_test_bit (int nr, const void *vaddr)
193
{
194
        return ((1U << (nr & 7)) & (((const unsigned char *) vaddr)[nr >> 3])) != 0;
195
}
196
 
197
extern __inline__ int
198
ext2_find_first_zero_bit (const void *vaddr, unsigned size)
199
{
200
        const unsigned long *p = vaddr, *addr = vaddr;
201
        int res;
202
 
203
        if (!size)
204
                return 0;
205
 
206
        while (*p++ == ~0UL)
207
        {
208
                if (size <= 32)
209
                        return (p - addr) << 5;
210
                size -= 32;
211
        }
212
 
213
        --p;
214
        for (res = 0; res < 32; res++)
215
                if (!ext2_test_bit (res, p))
216
                        break;
217
        return (p - addr) * 32 + res;
218
}
219
 
220
extern __inline__ int
221
ext2_find_next_zero_bit (const void *vaddr, unsigned size, unsigned offset)
222
{
223
        const unsigned long *addr = vaddr;
224
        const unsigned long *p = addr + (offset >> 5);
225
        int bit = offset & 31UL, res;
226
 
227
        if (offset >= size)
228
                return size;
229
 
230
        if (bit) {
231
                /* Look for zero in first longword */
232
                for (res = bit; res < 32; res++)
233
                        if (!ext2_test_bit (res, p))
234
                                return (p - addr) * 32 + res;
235
                p++;
236
        }
237
        /* No zero yet, search remaining full bytes for a zero */
238
        res = ext2_find_first_zero_bit (p, size - 32 * (p - addr));
239
        return (p - addr) * 32 + res;
240
}
241
 
242
#endif /* _M68K_BITOPS_H */

powered by: WebSVN 2.1.0

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