view modules/bluespec/Pygar/lab4/oSFIFO.bsv @ 38:05598d745f99 pygar svn.39

[svn r39] fixed audiocorepipe
author punk
date Tue, 04 May 2010 19:27:38 -0400
parents 74716e9a81cc
children
line wrap: on
line source

2 import FIFO::*;
3 import ConfigReg::*;
4 import RWire::*;
6 import List::*;
7 import Monad::*;
9 interface SFIFO#(type alpha_T, type search_T);
10 method Action enq(alpha_T x);
11 method Action deq();
12 method alpha_T first();
13 method Action clear();
14 method Bool find(search_T x);
15 method Bool find2(search_T x);
16 method Bool notEmpty();
17 method Bool notFull();
18 endinterface
20 module mkSFIFO#(function Bool searchfunc(search_T s, alpha_T x)) (SFIFO#(alpha_T, search_T))
21 provisos
22 (Bits#(alpha_T,asz));
24 Reg#(alpha_T) f0 <- mkConfigRegU;
25 Reg#(alpha_T) f1 <- mkConfigRegU;
27 Reg#(Bool) vf0 <- mkConfigReg(False);
28 Reg#(Bool) vf1 <- mkConfigReg(False);
30 PulseWire edge1 <- mkPulseWire();
32 method Action enq(alpha_T x) if (!(vf0 && vf1));
33 if (edge1 || !vf0)//empty or we're dequeueing
34 begin
35 vf0 <= True; //True
36 vf1 <= False;
37 f0 <= x;
38 end
39 else // !vf1
40 begin
41 vf1 <= True;
42 f1 <= x;
43 end
44 endmethod
46 method Action deq() if (vf0);
47 edge1.send();
48 vf0 <= vf1;
49 f0 <= f1;
50 vf1 <= False;
51 endmethod
53 method alpha_T first() if(vf0);
54 return (f0);
55 endmethod
57 method Action clear();
58 vf0 <= False;
59 vf1 <= False;
60 endmethod
62 method Bool find(search_T sv);
63 Bool nvf0 = edge1 ? False: vf0;
64 Bool nvf1 = vf1;
66 return (nvf0 && searchfunc(sv, f0) ||
67 nvf1 && searchfunc(sv, f1));
68 endmethod
70 method Bool find2(search_T sv);
71 Bool nvf0 = edge1 ? False: vf0;
72 Bool nvf1 = vf1;
74 return (nvf0 && searchfunc(sv, f0) ||
75 nvf1 && searchfunc(sv, f1));
76 endmethod
78 method notEmpty() = vf0._read;
80 method Bool notFull();
81 return !(vf0 && vf1);
82 endmethod
84 endmodule
86 module mkSFIFO1#(function Bool searchfunc(search_T s, alpha_T x)) (SFIFO#(alpha_T, search_T))
87 provisos
88 (Bits#(alpha_T,asz), Eq#(alpha_T));
90 Reg#(alpha_T) f0 <- mkConfigRegU;
92 Reg#(Bool) vf0 <- mkConfigReg(False);
94 PulseWire edge1 <- mkPulseWire();
96 method Action enq(alpha_T x) if (!vf0);
97 vf0 <= True; //True
98 f0 <= x;
99 endmethod
101 method Action deq() if (vf0);
102 edge1.send();
103 vf0 <= False;
104 endmethod
106 method alpha_T first() if(vf0);
107 return (f0);
108 endmethod
110 method Action clear();
111 vf0 <= False;
112 endmethod
114 method Bool find(search_T sv);
115 Bool nvf0 = edge1 ? False: vf0;
117 return (nvf0 && searchfunc(sv, f0));
118 endmethod
120 method Bool find2(search_T sv);
121 Bool nvf0 = edge1 ? False: vf0;
122 return (nvf0 && searchfunc(sv, f0));
123 endmethod
125 method notEmpty() = vf0._read;
127 method Bool notFull();
128 return !vf0;
129 endmethod
131 endmodule
133 module mkSizedSFIFOInternal#(Integer n,
134 function Bool searchfunc1(search_T s, alpha_T x),
135 function Bool searchfunc2(search_T s, alpha_T x)) (SFIFO#(alpha_T, search_T))
137 provisos ( Bits#(alpha_T,alpha_SZ) );
139 List#(Reg#(alpha_T)) registers <- replicateM(n, mkRegU);
140 List#(Reg#(Bool)) valids <- replicateM(n, mkReg(False));
142 function Nat getNextFree (List#(Reg#(Bool)) vs);
144 Nat res = fromInteger(n - 1);
146 for (Integer x = n - 1; x > -1; x = x - 1)
147 res = !vs[x]._read() ? fromInteger(x) : res;
149 return res;
151 endfunction
153 function Bool notFullHelper();
155 Bool full = True;
157 for (Integer x = 0; x < n; x = x + 1)
158 full = full && valids[x]._read();
160 return !full;
162 endfunction
164 method Action enq( alpha_T item ) if ( notFullHelper() );
166 Nat k = getNextFree(valids);
167 select(valids, k)._write(True);
168 select(registers, k)._write(item);
170 endmethod
172 method Action deq() if ( valids[0]._read() );
174 for (Integer x = 0; x < (n-1); x = x + 1)
175 begin
177 (registers[x]) <= registers[x + 1]._read();
178 (valids[x]) <= valids[x + 1]._read();
180 end
181 (valids[n-1]) <= False;
182 endmethod
184 method alpha_T first() if ( valids[0]._read() );
185 return registers[0]._read();
186 endmethod
188 method Bool find(search_T sv);
189 Bool res = False;
191 for (Integer x = 0; x < n; x = x + 1)
192 if ( valids[x]._read() && searchfunc1(sv, registers[x]._read()) )
193 res = True;
195 return res;
197 endmethod
199 method Bool find2(search_T sv);
200 Bool res = False;
202 for (Integer x = 0; x < n; x = x + 1)
203 if ( valids[x]._read() && searchfunc2(sv, registers[x]._read()) )
204 res = True;
206 return res;
208 endmethod
210 method Action clear();
212 for (Integer x = 0; x < n; x = x + 1)
213 (valids[x]) <= False;
215 endmethod
217 method Bool notEmpty();
218 return valids[0]._read();
219 endmethod
221 method Bool notFull();
222 return notFullHelper();
223 endmethod
225 endmodule
227 module mkSizedSFIFO#(Integer n, function Bool searchfunc(search_T s, alpha_T x)) (SFIFO#(alpha_T, search_T))
228 provisos
229 (Bits#(alpha_T,asz));
231 let foo <- mkSizedSFIFOInternal(n, searchfunc, searchfunc);
232 return foo;
234 endmodule