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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [mm0/] [tests/] [idpool_test/] [bit.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#ifndef __LIB_BIT_H__
2
#define __LIB_BIT_H__
3
 
4
/* Minimum excess needed for word alignment */
5
#define SZ_WORD                         sizeof(unsigned int)
6
#define WORD_BITS                       32
7
#define WORD_BITS_LOG2                  5
8
#define BITWISE_GETWORD(x)      ((x) >> WORD_BITS_LOG2) /* Divide by 32 */
9
#define BITWISE_GETBIT(x)       (1 << ((x) % WORD_BITS))
10
 
11
 
12
typedef unsigned int u32;
13
 
14
unsigned int __clz(unsigned int bitvector);
15
int find_and_set_first_free_bit(u32 *word, unsigned int lastbit);
16
int check_and_clear_bit(u32 *word, int bit);
17
 
18
int check_and_clear_contig_bits(u32 *word, int first, int nbits);
19
 
20
int find_and_set_first_free_contig_bits(u32 *word,  unsigned int limit,
21
                                        int nbits);
22
/* Set */
23
static inline void setbit(unsigned int *w, unsigned int flags)
24
{
25
        *w |= flags;
26
}
27
 
28
 
29
/* Clear */
30
static inline void clrbit(unsigned int *w, unsigned int flags)
31
{
32
        *w &= ~flags;
33
}
34
 
35
/* Test */
36
static inline int tstbit(unsigned int *w, unsigned int flags)
37
{
38
        return *w & flags;
39
}
40
 
41
/* Test and clear */
42
static inline int tstclr(unsigned int *w, unsigned int flags)
43
{
44
        int res = tstbit(w, flags);
45
 
46
        clrbit(w, flags);
47
 
48
        return res;
49
}
50
 
51
#endif /* __LIB_BIT_H__ */

powered by: WebSVN 2.1.0

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