Subversion Repositories Kolibri OS

Rev

Rev 2967 | Rev 5270 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2967 Rev 5056
Line 86... Line 86...
86
 
86
 
87
/*
87
/*
88
 * lib/bitmap.c provides these functions:
88
 * lib/bitmap.c provides these functions:
Line 89... Line 89...
89
 */
89
 */
90
 
90
 
91
extern int __bitmap_empty(const unsigned long *bitmap, int bits);
91
extern int __bitmap_empty(const unsigned long *bitmap, unsigned int nbits);
92
extern int __bitmap_full(const unsigned long *bitmap, int bits);
92
extern int __bitmap_full(const unsigned long *bitmap, unsigned int nbits);
93
extern int __bitmap_equal(const unsigned long *bitmap1,
93
extern int __bitmap_equal(const unsigned long *bitmap1,
94
                	const unsigned long *bitmap2, int bits);
94
			  const unsigned long *bitmap2, unsigned int nbits);
95
extern void __bitmap_complement(unsigned long *dst, const unsigned long *src,
95
extern void __bitmap_complement(unsigned long *dst, const unsigned long *src,
96
			int bits);
96
			unsigned int nbits);
97
extern void __bitmap_shift_right(unsigned long *dst,
97
extern void __bitmap_shift_right(unsigned long *dst,
98
                        const unsigned long *src, int shift, int bits);
98
                        const unsigned long *src, int shift, int bits);
99
extern void __bitmap_shift_left(unsigned long *dst,
99
extern void __bitmap_shift_left(unsigned long *dst,
100
                        const unsigned long *src, int shift, int bits);
100
                        const unsigned long *src, int shift, int bits);
101
extern int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
101
extern int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
102
			const unsigned long *bitmap2, int bits);
102
			const unsigned long *bitmap2, unsigned int nbits);
103
extern void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
103
extern void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
104
			const unsigned long *bitmap2, int bits);
104
			const unsigned long *bitmap2, unsigned int nbits);
105
extern void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
105
extern void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
106
			const unsigned long *bitmap2, int bits);
106
			const unsigned long *bitmap2, unsigned int nbits);
107
extern int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
107
extern int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
108
			const unsigned long *bitmap2, int bits);
108
			const unsigned long *bitmap2, unsigned int nbits);
109
extern int __bitmap_intersects(const unsigned long *bitmap1,
109
extern int __bitmap_intersects(const unsigned long *bitmap1,
110
			const unsigned long *bitmap2, int bits);
110
			const unsigned long *bitmap2, unsigned int nbits);
111
extern int __bitmap_subset(const unsigned long *bitmap1,
111
extern int __bitmap_subset(const unsigned long *bitmap1,
Line 112... Line 112...
112
			const unsigned long *bitmap2, int bits);
112
			const unsigned long *bitmap2, unsigned int nbits);
113
extern int __bitmap_weight(const unsigned long *bitmap, int bits);
113
extern int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits);
114
 
114
 
115
extern void bitmap_set(unsigned long *map, int i, int len);
115
extern void bitmap_set(unsigned long *map, unsigned int start, int len);
116
extern void bitmap_clear(unsigned long *map, int start, int nr);
116
extern void bitmap_clear(unsigned long *map, unsigned int start, int len);
117
extern unsigned long bitmap_find_next_zero_area(unsigned long *map,
117
extern unsigned long bitmap_find_next_zero_area(unsigned long *map,
118
					 unsigned long size,
118
					 unsigned long size,
Line 138... Line 138...
138
		const unsigned long *old, const unsigned long *new, int bits);
138
		const unsigned long *old, const unsigned long *new, int bits);
139
extern void bitmap_onto(unsigned long *dst, const unsigned long *orig,
139
extern void bitmap_onto(unsigned long *dst, const unsigned long *orig,
140
		const unsigned long *relmap, int bits);
140
		const unsigned long *relmap, int bits);
141
extern void bitmap_fold(unsigned long *dst, const unsigned long *orig,
141
extern void bitmap_fold(unsigned long *dst, const unsigned long *orig,
142
		int sz, int bits);
142
		int sz, int bits);
143
extern int bitmap_find_free_region(unsigned long *bitmap, int bits, int order);
143
extern int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order);
144
extern void bitmap_release_region(unsigned long *bitmap, int pos, int order);
144
extern void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order);
145
extern int bitmap_allocate_region(unsigned long *bitmap, int pos, int order);
145
extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order);
146
extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits);
146
extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits);
147
extern int bitmap_ord_to_pos(const unsigned long *bitmap, int n, int bits);
147
extern int bitmap_ord_to_pos(const unsigned long *bitmap, int n, int bits);
Line 148... Line 148...
148
 
148
 
149
#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG))
149
#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG))
Line 186... Line 186...
186
		memcpy(dst, src, len);
186
		memcpy(dst, src, len);
187
	}
187
	}
188
}
188
}
Line 189... Line 189...
189
 
189
 
190
static inline int bitmap_and(unsigned long *dst, const unsigned long *src1,
190
static inline int bitmap_and(unsigned long *dst, const unsigned long *src1,
191
			const unsigned long *src2, int nbits)
191
			const unsigned long *src2, unsigned int nbits)
192
{
192
{
193
	if (small_const_nbits(nbits))
193
	if (small_const_nbits(nbits))
194
		return (*dst = *src1 & *src2) != 0;
194
		return (*dst = *src1 & *src2 & BITMAP_LAST_WORD_MASK(nbits)) != 0;
195
	return __bitmap_and(dst, src1, src2, nbits);
195
	return __bitmap_and(dst, src1, src2, nbits);
Line 196... Line 196...
196
}
196
}
197
 
197
 
198
static inline void bitmap_or(unsigned long *dst, const unsigned long *src1,
198
static inline void bitmap_or(unsigned long *dst, const unsigned long *src1,
199
			const unsigned long *src2, int nbits)
199
			const unsigned long *src2, unsigned int nbits)
200
{
200
{
201
	if (small_const_nbits(nbits))
201
	if (small_const_nbits(nbits))
202
		*dst = *src1 | *src2;
202
		*dst = *src1 | *src2;
203
	else
203
	else
Line 204... Line 204...
204
		__bitmap_or(dst, src1, src2, nbits);
204
		__bitmap_or(dst, src1, src2, nbits);
205
}
205
}
206
 
206
 
207
static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1,
207
static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1,
208
			const unsigned long *src2, int nbits)
208
			const unsigned long *src2, unsigned int nbits)
209
{
209
{
210
	if (small_const_nbits(nbits))
210
	if (small_const_nbits(nbits))
211
		*dst = *src1 ^ *src2;
211
		*dst = *src1 ^ *src2;
Line 212... Line 212...
212
	else
212
	else
213
		__bitmap_xor(dst, src1, src2, nbits);
213
		__bitmap_xor(dst, src1, src2, nbits);
214
}
214
}
215
 
215
 
216
static inline int bitmap_andnot(unsigned long *dst, const unsigned long *src1,
216
static inline int bitmap_andnot(unsigned long *dst, const unsigned long *src1,
217
			const unsigned long *src2, int nbits)
217
			const unsigned long *src2, unsigned int nbits)
218
{
218
{
Line 219... Line 219...
219
	if (small_const_nbits(nbits))
219
	if (small_const_nbits(nbits))
220
		return (*dst = *src1 & ~(*src2)) != 0;
220
		return (*dst = *src1 & ~(*src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
221
	return __bitmap_andnot(dst, src1, src2, nbits);
221
	return __bitmap_andnot(dst, src1, src2, nbits);
222
}
222
}
223
 
223
 
224
static inline void bitmap_complement(unsigned long *dst, const unsigned long *src,
224
static inline void bitmap_complement(unsigned long *dst, const unsigned long *src,
225
			int nbits)
225
			unsigned int nbits)
226
{
226
{
Line 227... Line 227...
227
	if (small_const_nbits(nbits))
227
	if (small_const_nbits(nbits))
228
		*dst = ~(*src) & BITMAP_LAST_WORD_MASK(nbits);
228
		*dst = ~(*src);
229
	else
229
	else
230
		__bitmap_complement(dst, src, nbits);
230
		__bitmap_complement(dst, src, nbits);
231
}
231
}
232
 
232
 
233
static inline int bitmap_equal(const unsigned long *src1,
233
static inline int bitmap_equal(const unsigned long *src1,
234
			const unsigned long *src2, int nbits)
234
			const unsigned long *src2, unsigned int nbits)
Line 235... Line 235...
235
{
235
{
236
	if (small_const_nbits(nbits))
236
	if (small_const_nbits(nbits))
237
		return ! ((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits));
237
		return ! ((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits));
238
	else
238
	else
239
		return __bitmap_equal(src1, src2, nbits);
239
		return __bitmap_equal(src1, src2, nbits);
240
}
240
}
241
 
241
 
242
static inline int bitmap_intersects(const unsigned long *src1,
242
static inline int bitmap_intersects(const unsigned long *src1,
Line 243... Line 243...
243
			const unsigned long *src2, int nbits)
243
			const unsigned long *src2, unsigned int nbits)
244
{
244
{
245
	if (small_const_nbits(nbits))
245
	if (small_const_nbits(nbits))
246
		return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
246
		return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
247
	else
247
	else
248
		return __bitmap_intersects(src1, src2, nbits);
248
		return __bitmap_intersects(src1, src2, nbits);
249
}
249
}
250
 
250
 
Line 251... Line 251...
251
static inline int bitmap_subset(const unsigned long *src1,
251
static inline int bitmap_subset(const unsigned long *src1,
252
			const unsigned long *src2, int nbits)
252
			const unsigned long *src2, unsigned int nbits)
253
{
253
{
254
	if (small_const_nbits(nbits))
254
	if (small_const_nbits(nbits))
255
		return ! ((*src1 & ~(*src2)) & BITMAP_LAST_WORD_MASK(nbits));
255
		return ! ((*src1 & ~(*src2)) & BITMAP_LAST_WORD_MASK(nbits));
256
	else
256
	else
257
		return __bitmap_subset(src1, src2, nbits);
257
		return __bitmap_subset(src1, src2, nbits);
Line 258... Line 258...
258
}
258
}
259
 
259
 
260
static inline int bitmap_empty(const unsigned long *src, int nbits)
260
static inline int bitmap_empty(const unsigned long *src, unsigned nbits)
261
{
261
{
262
	if (small_const_nbits(nbits))
262
	if (small_const_nbits(nbits))
263
		return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
263
		return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
264
	else
264
	else
Line 265... Line 265...
265
		return __bitmap_empty(src, nbits);
265
		return __bitmap_empty(src, nbits);
266
}
266
}
267
 
267
 
268
static inline int bitmap_full(const unsigned long *src, int nbits)
268
static inline int bitmap_full(const unsigned long *src, unsigned int nbits)
269
{
269
{
270
	if (small_const_nbits(nbits))
270
	if (small_const_nbits(nbits))
Line 271... Line 271...
271
		return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits));
271
		return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits));
272
	else
272
	else
273
		return __bitmap_full(src, nbits);
273
		return __bitmap_full(src, nbits);
274
}
274
}
275
 
275
 
276
static inline int bitmap_weight(const unsigned long *src, int nbits)
276
static inline int bitmap_weight(const unsigned long *src, unsigned int nbits)
277
{
277
{
278
	if (small_const_nbits(nbits))
278
	if (small_const_nbits(nbits))
Line 279... Line 279...
279
		return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
279
		return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));