OpenCores
URL https://opencores.org/ocsvn/bluespec-h264/bluespec-h264/trunk

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src_fpga/] [FIFO_2.bsv] - Blame information for rev 100

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 83 jamey.hick
 
2
// The MIT License
3
 
4
// Copyright (c) 2006-2007 Massachusetts Institute of Technology
5
 
6
// Permission is hereby granted, free of charge, to any person obtaining a copy
7
// of this software and associated documentation files (the "Software"), to deal
8
// in the Software without restriction, including without limitation the rights
9
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
// copies of the Software, and to permit persons to whom the Software is
11
// furnished to do so, subject to the following conditions:
12
 
13
// The above copyright notice and this permission notice shall be included in
14
// all copies or substantial portions of the Software.
15
 
16
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
// THE SOFTWARE.
23
 
24 3 jamey.hick
package FIFO_2;
25
export FIFO_2(..);
26
 
27
export mkFIFO2;
28
 
29
import FIFOF::*;
30
import RWire::*;
31
import List::*;
32
import Monad::*;
33
 
34
interface FIFO_2 #(type t);
35
    method Bool has1i();
36
    method Bool has2i();
37
    method Bool space1i();
38
    method Bool space2i();
39
    method Action enq_1(t x1);
40
    method Action enq_2(t x1);
41
    method t first_1();
42
    method t first_2();
43
    method Action deq_1();
44
    method Action deq_2();
45
    method Action clear();
46
endinterface: FIFO_2
47
 
48
 
49
module mkFIFO2(FIFO_2#(t))
50
  provisos (Bits#(t, bt));
51
 
52
  function Bool pokeRWire(RWire#(z) x);
53
    begin
54
      case (x.wget) matches
55
           tagged Valid {.a}:  return(True);
56
           tagged Invalid  :  return(False);
57
      endcase
58
    end
59
  endfunction: pokeRWire
60
 
61
  List#(RWire#(t)) enq;
62
  enq <- mapM (constFn(mkRWire), upto(0, 1));
63
 
64
  List#(RWire#(Bit#(0))) deq;
65
  deq <- mapM (constFn(mkRWire), upto(0, 1));
66
 
67
  List#(FIFOF#(t)) fifos;
68
  fifos <- mapM (constFn(mkFIFOF), upto(0, 1));
69
 
70
  List#(RWire#(t)) fifosr;
71
  fifosr <- mapM (constFn(mkRWire), upto(0, 1));
72
 
73
  Reg#(Bit#(1)) head();
74
  mkReg#(0) the_head(head);
75
 
76
  Reg#(Bit#(1)) tail();
77
  mkReg#(0) the_tail(tail);
78
 
79
  rule doEnq (True);
80
     let predVals = map(pokeRWire, enq);
81
     Bit#(1) offset;
82
     function Bit#(1) foldfunc (Bit#(1) o, Bool x);
83
         return (x ? o+1 : o);
84
     endfunction: foldfunc
85
 
86
     offset = foldl(foldfunc, 0, predVals);
87
 
88
     function Action tryEnqr(RWire#(t) rf, RWire#(t) r);
89
       action
90
         case (r.wget) matches
91
              tagged Invalid : noAction;
92
              tagged Valid .v : rf.wset(v);
93
         endcase
94
       endaction
95
     endfunction: tryEnqr
96
 
97
     let efifo1r =  select(fifosr, ((Bit#(1))'(0)));
98
     let efifo2r =  select(fifosr, ((Bit#(1))'(1)));
99
 
100
     match {.enq1,.enq2} = tuple2(select(enq, tail + 0), select(enq, tail + 1));
101
 
102
     tryEnqr(efifo1r, enq1);
103
     tryEnqr(efifo2r, enq2);
104
 
105
     tail <= tail + offset;
106
 
107
  endrule: doEnq
108
 
109
  rule enq1(True);
110
    action
111
       let fifo1  = select(fifos , ((Bit#(1))'(0)));
112
       let fifo1r = select(fifosr, ((Bit#(1))'(0)));
113
       case (fifo1r.wget) matches
114
            tagged Invalid : noAction;
115
            tagged Valid .v : fifo1.enq (v);
116
       endcase
117
    endaction
118
  endrule: enq1
119
 
120
  rule enq2(True);
121
    action
122
       let fifo2  = select(fifos , ((Bit#(1))'(1)));
123
       let fifo2r = select(fifosr, ((Bit#(1))'(1)));
124
       case (fifo2r.wget) matches
125
            tagged Invalid : noAction;
126
            tagged Valid .v : fifo2.enq (v);
127
       endcase
128
    endaction
129
  endrule: enq2
130
 
131
  rule handle_Dequeues (True);
132
     let predVals =  map(pokeRWire, deq);
133
     Bit#(1) offset;
134
 
135
     function Bit#(1) foldfunc (Bit#(1) o, Bool x);
136
         return (x ? o+1 : o);
137
     endfunction: foldfunc
138
 
139
     offset = foldl(foldfunc, 0, predVals);
140
 
141
     function Action tryDeq(FIFOF#(t) f, RWire#(Bit#(0)) r);
142
       action
143
         case (r.wget) matches
144
              tagged Invalid : noAction;
145
              tagged Valid .a : f.deq();
146
        endcase
147
       endaction
148
     endfunction: tryDeq
149
 
150
     let dfifo1 =  select(fifos, ((Bit#(1))'(0)));
151
     let dfifo2 =  select(fifos, ((Bit#(1))'(1)));
152
 
153
     match {.deq1,.deq2} = tuple2(select(deq, head + 0), select(deq, head + 1));
154
 
155
     tryDeq(dfifo1, deq1);
156
     tryDeq(dfifo2, deq2);
157
 
158
     head <= head + offset;
159
  endrule: handle_Dequeues
160
 
161
  method enq_1(v) if (((select(fifos,0)).notFull) ||
162
                      ((select(fifos,1)).notFull)) ;
163
    action
164
      let enq1 = select(enq, ((Bit#(1))'(0)));
165
      enq1.wset(v);
166
    endaction
167
 
168
  endmethod: enq_1
169
 
170
  method enq_2(v) if (((select(fifos,0)).notFull) && ((select(fifos,1)).notFull)) ;
171
    action
172
      let enq2 =  select(enq, ((Bit#(1))'(1)));
173
      enq2.wset(v);
174
    endaction
175
  endmethod: enq_2
176
 
177
  method deq_1() if (((select(fifos,0)).notEmpty) || ((select(fifos,1)).notEmpty)) ;
178
    action
179
      let deq1 =  select(deq, ((Bit#(1))'(0)));
180
      deq1.wset(?); // PrimUnit;
181
    endaction
182
  endmethod: deq_1
183
 
184
  method deq_2() if (((select(fifos,0)).notEmpty) && ((select(fifos,1)).notEmpty)) ;
185
    action
186
      let deq2 =  select(deq, ((Bit#(1))'(1)));
187
      deq2.wset (?); // Unit;
188
    endaction
189
  endmethod: deq_2
190
 
191
  method clear() ;
192
    action
193
      function Action clearfifo(FIFOF#(t) f);
194
        action
195
          f.clear();
196
        endaction
197
      endfunction: clearfifo
198
      List#(Action) lact;
199
 
200
      lact = map(clearfifo, fifos);
201
      head <= 0;
202
      tail <= 0;
203
      joinActions(lact);
204
    endaction
205
  endmethod: clear
206
 
207
  method first_1() if ((select(fifos, ((Bit#(1))'(0)))).notEmpty ||
208
                       (select(fifos, ((Bit#(1))'(1)))).notEmpty) ;
209
      let dfifo1 =  select(fifos, head + 0);
210
      return (dfifo1.first);
211
  endmethod: first_1
212
 
213
  method first_2() if ((select(fifos, ((Bit#(1))'(0)))).notEmpty &&
214
                      (select(fifos, ((Bit#(1))'(1)))).notEmpty) ;
215
      let dfifo2 =  select(fifos, head + 1);
216
      return (dfifo2.first);
217
  endmethod: first_2
218
 
219
  method has1i() ;
220
      return ((select(fifos, ((Bit#(1))'(0)))).notEmpty ||
221
              (select(fifos, ((Bit#(1))'(1)))).notEmpty);
222
  endmethod: has1i
223
 
224
  method has2i() ;
225
      return ((select(fifos, ((Bit#(1))'(0)))).notEmpty &&
226
              (select(fifos, ((Bit#(1))'(1)))).notEmpty);
227
  endmethod: has2i
228
 
229
  method space1i() ;
230
      return ((select(fifos, ((Bit#(1))'(0)))).notFull ||
231
              (select(fifos, ((Bit#(1))'(1)))).notFull);
232
  endmethod: space1i
233
 
234
  method space2i() ;
235
      return ((select(fifos, ((Bit#(1))'(0)))).notFull &&
236
              (select(fifos, ((Bit#(1))'(1)))).notFull);
237
  endmethod: space2i
238
 
239
endmodule: mkFIFO2
240
 
241
 
242
module mkTest(FIFO_2#(Bit#(2)));
243
  FIFO_2#(Bit#(2)) f();
244
  mkFIFO2 the_f(f);
245
 
246
  method enq_1();
247
     return (f.enq_1);
248
  endmethod: enq_1
249
 
250
  method enq_2();
251
     return (f.enq_2);
252
  endmethod: enq_2
253
 
254
  method first_1();
255
     return (f.first_1);
256
  endmethod: first_1
257
 
258
  method first_2();
259
     return (f.first_2);
260
  endmethod: first_2
261
 
262
  method deq_1();
263
     return (f.deq_1);
264
  endmethod: deq_1
265
 
266
  method deq_2();
267
     return (f.deq_2);
268
  endmethod: deq_2
269
 
270
  method clear();
271
     return (f.clear);
272
  endmethod: clear
273
 
274
  method has1i();
275
     return (f.has1i);
276
  endmethod: has1i
277
 
278
  method has2i();
279
     return (f.has2i);
280
  endmethod: has2i
281
 
282
  method space1i();
283
     return (f.space1i);
284
  endmethod: space1i
285
 
286
  method space2i();
287
     return (f.space2i);
288
  endmethod: space2i
289
endmodule: mkTest
290
 
291
endpackage: FIFO_2
292
 

powered by: WebSVN 2.1.0

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