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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [gfx/] [mw/] [v2_0/] [src/] [demos/] [nxscribble/] [bitvector.h] - Blame information for rev 27

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

Line No. Rev Author Line
1 27 unneback
/***********************************************************************
2
 
3
bitvector.h - some macros for dealing with bitvectors
4
 
5
Copyright (C) 1991 Dean Rubine
6
 
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License. See ../COPYING for
9
the full agreement.
10
 
11
 **********************************************************************/
12
 
13
/*
14
  Bit vector package
15
 
16
  Used so that it's easier when we need more than 8*sizeof(int) bits
17
  in a the vector.
18
 
19
  Usage:
20
        Before including this file define the identifier BITS_PER_VECTOR
21
 
22
        BITS_PER_VECTOR must be one of the following values:
23
 
24
                16
25
                32
26
                64
27
                128
28
 
29
        The high tech preprocessor hacking is sure to be nonportable.  The
30
        use of include in this file is not to include files, it is to
31
        print out error messages.  Ugly, I know, but what can I do?
32
 
33
        You may include this file more than one in a single C file!
34
        By default, when this file is included it defines a type
35
        BitVector.  You may change the name of this type (necessary
36
        to avoid redefinitions when included more than one) by defining:
37
 
38
        #define BV_TYPE_NAME    MyBitVectorTypeName
39
 
40
        The usual sequence for including this file is thus:
41
 
42
        #undef BV_TYPE_NAME
43
        #undef BITS_PER_VECTOR
44
        #define BV_TYPE_NAME    BVTypeName
45
        #define BITS_PER_VECTOR how-many-bits-per-vector
46
 
47
        WARNING: Once the file is re-included do not attempt to manipulate any
48
        other vectors besides the newest type for the rest of the file or until
49
        the file is included again.
50
*/
51
 
52
/*
53
  -------------     check BITS_PER_VECTOR     -----------------
54
 */
55
#ifndef BITS_PER_VECTOR
56
#       define  BITS_PER_VECTOR  32
57
#endif
58
 
59
#if (BITS_PER_VECTOR != 16) && (BITS_PER_VECTOR != 32) && (BITS_PER_VECTOR != 64) && (BITS_PER_VECTOR != 128)
60
 
61
#       include "****** illegal value for BITS_PER_VECTOR  ******"
62
 
63
#endif
64
 
65
/*
66
  -------------      machine dependent stuff     -----------------
67
 */
68
 
69
#ifndef BITS_PER_INT
70
 
71
 
72
#       ifdef unix
73
#               define BITS_PER_INT     32
74
#       else
75
#               define BITS_PER_INT     16  /* IBM XT Lattice C */
76
#       endif
77
 
78
#       define  BV_CHECK_MACHINE_ASSUMPTIONS() \
79
                if(BITS_PER_INT != 8*sizeof(int)) \
80
                        error("BV_CHECK_ASSUMPTIONS");
81
 
82
#endif
83
 
84
/*
85
  ---- If this file has been included already, redefine everything ----
86
 */
87
 
88
#       undef   BV_INDEX_MASK
89
#       undef   BV_INDEX_SHIFT
90
#       undef   INTS_PER_VECTOR
91
#       undef   VECTOR_SIZE_CHECK
92
#       undef   SET_BIT_VECTOR
93
#       undef   IS_SET
94
#       undef   ASSIGN_BIT_VECTOR
95
#       undef   CLEAR_BIT_VECTOR
96
#       undef   BIT_SET
97
#       undef   BIT_CLEAR
98
 
99
/*
100
  --------------- round up to int size -------------------
101
 */
102
 
103
#if BITS_PER_VECTOR < BITS_PER_INT
104
#       undef   BITS_PER_VECTOR
105
#       define  BITS_PER_VECTOR BITS_PER_INT
106
#endif
107
 
108
/*
109
  ------------- Compute index shift and mask to avoid division -----
110
 */
111
 
112
#define BV_INDEX_MASK   (BITS_PER_INT - 1)
113
 
114
#if BITS_PER_INT==16
115
#       define  BV_INDEX_SHIFT  4
116
#endif
117
 
118
#if BITS_PER_INT==32
119
#       define  BV_INDEX_SHIFT  5
120
#endif
121
 
122
#ifndef BV_INDEX_SHIFT
123
#       include "****** bad value for BITS_PER_INT  ******"
124
#endif
125
 
126
/*
127
 ------------- Compute INTS_PER_VECTOR ------------------
128
 */
129
 
130
#if BITS_PER_INT==BITS_PER_VECTOR
131
#       define  INTS_PER_VECTOR 1
132
#else
133
#       if 2*BITS_PER_INT==BITS_PER_VECTOR
134
#               define  INTS_PER_VECTOR 2
135
#       else
136
#               define  INTS_PER_VECTOR (BITS_PER_VECTOR / BITS_PER_INT)
137
#       endif
138
#endif 
139
 
140
 
141
#define BV_SIZE_CHECK(nbits_needed) \
142
        if(nbits_needed > BITS_PER_VECTOR) \
143
                error("%s line %d - %d bits needed, %d is vector size", \
144
                        __FILE__, __LINE__, nbits_needed, BITS_PER_VECTOR);
145
 
146
#ifndef BV_TYPE_NAME
147
#       define  BV_TYPE_NAME    BitVector
148
#endif
149
 
150
/*
151
 ------------- Optimize INTS_PER_VECTOR=1 case
152
 */
153
 
154
#if INTS_PER_VECTOR==1
155
 
156
typedef int BV_TYPE_NAME[1];
157
 
158
#define CLEAR_BIT_VECTOR(v)     ( (v)[0] = 0 )
159
#define SET_BIT_VECTOR(v)       ( (v)[0] = -1 )         /* assumes 2's comp */
160
#define BIT_SET(bit, v)         ( (v)[0] |= (1 << (bit)) )
161
#define BIT_CLEAR(bit, v)       ( (v)[0] &= ~(1 << (bit)) )
162
#define IS_SET(bit, v)          ( ((v)[0] >> (bit)) & 01 )
163
#define ASSIGN_BIT_VECTOR(v1,v2) ( (v1)[0] = (v2)[0] )
164
 
165
#else
166
 
167
/*
168
 ------------- Optimize INTS_PER_VECTOR=2 case -------
169
 */
170
 
171
#if INTS_PER_VECTOR==2
172
 
173
    typedef int BV_TYPE_NAME[2];
174
 
175
#   define      CLEAR_BIT_VECTOR(v) ( (v)[0] = (v)[1] = 0 )
176
#   define      SET_BIT_VECTOR(v)   ( (v)[0] = (v)[1] = -1 ) /* 2's comp */
177
#    define     ASSIGN_BIT_VECTOR(v1,v2) \
178
                                   ( (v1)[0] = (v2)[0], (v1)[1] = (v2)[1] )
179
 
180
#else
181
 
182
/*
183
 ------------- general case -------------------
184
 */
185
 
186
     typedef int BV_TYPE_NAME[INTS_PER_VECTOR];
187
 
188
#    define     CLEAR_BIT_VECTOR(v)     (  ClearBitVector(INTS_PER_VECTOR, v) )
189
#    define     SET_BIT_VECTOR(v)       (  SetBitVector(INTS_PER_VECTOR, v) )
190
#    define     ASSIGN_BIT_VECTOR(v1,v2) \
191
                                   ( AssignBitVector(INTS_PER_VECTOR, v1, v2) )
192
 
193
#endif
194
 
195
 
196
#define BIT_SET(bit, v) \
197
        ( (v[bit>>BV_INDEX_SHIFT]) |= (1 << (bit&BV_INDEX_MASK)) )
198
 
199
#define BIT_CLEAR(bit, v) \
200
        ( (v[bit>>BV_INDEX_SHIFT]) &= ~(1 << (bit&BV_INDEX_MASK)) )
201
 
202
#define IS_SET(bit, v) \
203
        ( ((v[bit>>BV_INDEX_SHIFT]) >> (bit&BV_INDEX_MASK)) & 01 )
204
 
205
#endif
206
 
207
/* TODO: make efficient */
208
 
209
#define OR(v, v1, v2) ( BitVectorOr((v), (v1), (v2), INTS_PER_VECTOR) )
210
#define AND(v, v1, v2) ( BitVectorAnd((v), (v1), (v2), INTS_PER_VECTOR) )
211
#define NO_BITS_SET(v)  ( BitVectorNoBitsSet( (v), INTS_PER_VECTOR ) )
212
 
213
int bitcount(); /* max, bv */
214
char *BitVectorToString(); /* max, bv */
215
void StringToBitVector(); /* string, max, bv */
216
int BitVectorDeQ();       /* element = BitVectorDeQ(max, bv); */
217
 
218
int *BitVectorOr();
219
int *BitVectorAnd();
220
int BitVectorNoBitsSet();

powered by: WebSVN 2.1.0

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