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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [mw/] [src/] [demos/] [nxscribble/] [bitvector.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
 
2
/***********************************************************************
3
 
4
bitvector.c - some routines for dealing with bitvectors
5
 
6
Copyright (C) 1991 Dean Rubine
7
 
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License. See ../COPYING for
10
the full agreement.
11
 
12
 **********************************************************************/
13
 
14
/*LINTLIBRARY*/
15
 
16
#include "util.h"
17
#undef  BITS_PER_VECTOR
18
#define BITS_PER_VECTOR 128
19
#include "bitvector.h"
20
/* ari -- for strlen */
21
#include <string.h>  
22
 
23
int
24
bitcount(max, bv)
25
int max;
26
BitVector bv;
27
{
28
        register int i, count;
29
 
30
        for(count = i = 0; i < max; i++)
31
                if(IS_SET(i, bv))
32
                        count++;
33
        return count;
34
}
35
 
36
char *
37
BitVectorToString(max, bv)
38
BitVector bv;
39
{
40
        char *string = tempstring();
41
        register int i;
42
 
43
        for(i = 0; i < max; i++)
44
                string[i] = IS_SET(i, bv) ? (i % 10) + '0' : '-' ;
45
        string[i] = '\0';
46
        return string;
47
}
48
 
49
 
50
void
51
StringToBitVector(string, max, bv)
52
char *string;
53
int max;
54
BitVector bv;
55
{
56
        register int i;
57
 
58
/* ari -- strlen returns a size_t, which depends on which OS you've got */
59
        if((int) strlen(string) != max) {
60
                error("StringToBitVector: strlen(%s)=%d != %d",
61
                        string, (int) strlen(string), max);
62
                return;
63
            }
64
 
65
        for(i = 0; i < max; i++)
66
                if(string[i] != '-')
67
                        BIT_SET(i, bv);
68
                else
69
                        BIT_CLEAR(i, bv);
70
}
71
 
72
 
73
void
74
SetBitVector(v)
75
register BitVector v;
76
{
77
        register int nints = INTS_PER_VECTOR;
78
 
79
        while(--nints >= 0)
80
                *v++ = -1;
81
}
82
 
83
 
84
void
85
ClearBitVector(nints, v)
86
register int nints;
87
register BitVector v;
88
{
89
 
90
        while(--nints >= 0)
91
                *v++ = 0;
92
}
93
 
94
void
95
AssignBitVector(nints, v1, v2)
96
register int nints;
97
register BitVector v1, v2;
98
{
99
 
100
        while(--nints >= 0)
101
                *v1++ = *v2++;
102
}
103
 
104
int
105
BitVectorDeQ(max, v)
106
register int max;
107
register BitVector v;
108
{
109
        register int i;
110
        for(i = 0; i < max; i++)
111
                if(IS_SET(i, v)) {
112
                        BIT_CLEAR(i, v);
113
                        return i;
114
                }
115
        return -1;
116
 
117
}
118
 
119
int *
120
BitVectorOr(v, v1, v2, ipv)
121
int *v;
122
register int *v1, *v2;
123
register int ipv;
124
{
125
        int *vv = v;
126
        do
127
                *vv++ = *v1++ | *v2++;
128
        while(--ipv > 0);
129
        return v;
130
}
131
 
132
int *
133
BitVectorAnd(v, v1, v2, ipv)
134
int *v;
135
register int *v1, *v2;
136
register int ipv;
137
{
138
        int *vv = v;
139
        do
140
                *vv++ = *v1++ & *v2++;
141
        while(--ipv > 0);
142
        return v;
143
}
144
 
145
int
146
BitVectorNoBitsSet(v, ipv)
147
register int *v;
148
register int ipv;
149
{
150
        do
151
                if(*v++) return 0;
152
        while(--ipv > 0);
153
        return 1;
154
}

powered by: WebSVN 2.1.0

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