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 3

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

Line No. Rev Author Line
1 3 jamey.hick
package FIFO_2;
2
export FIFO_2(..);
3
 
4
export mkFIFO2;
5
 
6
import FIFOF::*;
7
import RWire::*;
8
import List::*;
9
import Monad::*;
10
 
11
interface FIFO_2 #(type t);
12
    method Bool has1i();
13
    method Bool has2i();
14
    method Bool space1i();
15
    method Bool space2i();
16
    method Action enq_1(t x1);
17
    method Action enq_2(t x1);
18
    method t first_1();
19
    method t first_2();
20
    method Action deq_1();
21
    method Action deq_2();
22
    method Action clear();
23
endinterface: FIFO_2
24
 
25
 
26
module mkFIFO2(FIFO_2#(t))
27
  provisos (Bits#(t, bt));
28
 
29
  function Bool pokeRWire(RWire#(z) x);
30
    begin
31
      case (x.wget) matches
32
           tagged Valid {.a}:  return(True);
33
           tagged Invalid  :  return(False);
34
      endcase
35
    end
36
  endfunction: pokeRWire
37
 
38
  List#(RWire#(t)) enq;
39
  enq <- mapM (constFn(mkRWire), upto(0, 1));
40
 
41
  List#(RWire#(Bit#(0))) deq;
42
  deq <- mapM (constFn(mkRWire), upto(0, 1));
43
 
44
  List#(FIFOF#(t)) fifos;
45
  fifos <- mapM (constFn(mkFIFOF), upto(0, 1));
46
 
47
  List#(RWire#(t)) fifosr;
48
  fifosr <- mapM (constFn(mkRWire), upto(0, 1));
49
 
50
  Reg#(Bit#(1)) head();
51
  mkReg#(0) the_head(head);
52
 
53
  Reg#(Bit#(1)) tail();
54
  mkReg#(0) the_tail(tail);
55
 
56
  rule doEnq (True);
57
     let predVals = map(pokeRWire, enq);
58
     Bit#(1) offset;
59
     function Bit#(1) foldfunc (Bit#(1) o, Bool x);
60
         return (x ? o+1 : o);
61
     endfunction: foldfunc
62
 
63
     offset = foldl(foldfunc, 0, predVals);
64
 
65
     function Action tryEnqr(RWire#(t) rf, RWire#(t) r);
66
       action
67
         case (r.wget) matches
68
              tagged Invalid : noAction;
69
              tagged Valid .v : rf.wset(v);
70
         endcase
71
       endaction
72
     endfunction: tryEnqr
73
 
74
     let efifo1r =  select(fifosr, ((Bit#(1))'(0)));
75
     let efifo2r =  select(fifosr, ((Bit#(1))'(1)));
76
 
77
     match {.enq1,.enq2} = tuple2(select(enq, tail + 0), select(enq, tail + 1));
78
 
79
     tryEnqr(efifo1r, enq1);
80
     tryEnqr(efifo2r, enq2);
81
 
82
     tail <= tail + offset;
83
 
84
  endrule: doEnq
85
 
86
  rule enq1(True);
87
    action
88
       let fifo1  = select(fifos , ((Bit#(1))'(0)));
89
       let fifo1r = select(fifosr, ((Bit#(1))'(0)));
90
       case (fifo1r.wget) matches
91
            tagged Invalid : noAction;
92
            tagged Valid .v : fifo1.enq (v);
93
       endcase
94
    endaction
95
  endrule: enq1
96
 
97
  rule enq2(True);
98
    action
99
       let fifo2  = select(fifos , ((Bit#(1))'(1)));
100
       let fifo2r = select(fifosr, ((Bit#(1))'(1)));
101
       case (fifo2r.wget) matches
102
            tagged Invalid : noAction;
103
            tagged Valid .v : fifo2.enq (v);
104
       endcase
105
    endaction
106
  endrule: enq2
107
 
108
  rule handle_Dequeues (True);
109
     let predVals =  map(pokeRWire, deq);
110
     Bit#(1) offset;
111
 
112
     function Bit#(1) foldfunc (Bit#(1) o, Bool x);
113
         return (x ? o+1 : o);
114
     endfunction: foldfunc
115
 
116
     offset = foldl(foldfunc, 0, predVals);
117
 
118
     function Action tryDeq(FIFOF#(t) f, RWire#(Bit#(0)) r);
119
       action
120
         case (r.wget) matches
121
              tagged Invalid : noAction;
122
              tagged Valid .a : f.deq();
123
        endcase
124
       endaction
125
     endfunction: tryDeq
126
 
127
     let dfifo1 =  select(fifos, ((Bit#(1))'(0)));
128
     let dfifo2 =  select(fifos, ((Bit#(1))'(1)));
129
 
130
     match {.deq1,.deq2} = tuple2(select(deq, head + 0), select(deq, head + 1));
131
 
132
     tryDeq(dfifo1, deq1);
133
     tryDeq(dfifo2, deq2);
134
 
135
     head <= head + offset;
136
  endrule: handle_Dequeues
137
 
138
  method enq_1(v) if (((select(fifos,0)).notFull) ||
139
                      ((select(fifos,1)).notFull)) ;
140
    action
141
      let enq1 = select(enq, ((Bit#(1))'(0)));
142
      enq1.wset(v);
143
    endaction
144
 
145
  endmethod: enq_1
146
 
147
  method enq_2(v) if (((select(fifos,0)).notFull) && ((select(fifos,1)).notFull)) ;
148
    action
149
      let enq2 =  select(enq, ((Bit#(1))'(1)));
150
      enq2.wset(v);
151
    endaction
152
  endmethod: enq_2
153
 
154
  method deq_1() if (((select(fifos,0)).notEmpty) || ((select(fifos,1)).notEmpty)) ;
155
    action
156
      let deq1 =  select(deq, ((Bit#(1))'(0)));
157
      deq1.wset(?); // PrimUnit;
158
    endaction
159
  endmethod: deq_1
160
 
161
  method deq_2() if (((select(fifos,0)).notEmpty) && ((select(fifos,1)).notEmpty)) ;
162
    action
163
      let deq2 =  select(deq, ((Bit#(1))'(1)));
164
      deq2.wset (?); // Unit;
165
    endaction
166
  endmethod: deq_2
167
 
168
  method clear() ;
169
    action
170
      function Action clearfifo(FIFOF#(t) f);
171
        action
172
          f.clear();
173
        endaction
174
      endfunction: clearfifo
175
      List#(Action) lact;
176
 
177
      lact = map(clearfifo, fifos);
178
      head <= 0;
179
      tail <= 0;
180
      joinActions(lact);
181
    endaction
182
  endmethod: clear
183
 
184
  method first_1() if ((select(fifos, ((Bit#(1))'(0)))).notEmpty ||
185
                       (select(fifos, ((Bit#(1))'(1)))).notEmpty) ;
186
      let dfifo1 =  select(fifos, head + 0);
187
      return (dfifo1.first);
188
  endmethod: first_1
189
 
190
  method first_2() if ((select(fifos, ((Bit#(1))'(0)))).notEmpty &&
191
                      (select(fifos, ((Bit#(1))'(1)))).notEmpty) ;
192
      let dfifo2 =  select(fifos, head + 1);
193
      return (dfifo2.first);
194
  endmethod: first_2
195
 
196
  method has1i() ;
197
      return ((select(fifos, ((Bit#(1))'(0)))).notEmpty ||
198
              (select(fifos, ((Bit#(1))'(1)))).notEmpty);
199
  endmethod: has1i
200
 
201
  method has2i() ;
202
      return ((select(fifos, ((Bit#(1))'(0)))).notEmpty &&
203
              (select(fifos, ((Bit#(1))'(1)))).notEmpty);
204
  endmethod: has2i
205
 
206
  method space1i() ;
207
      return ((select(fifos, ((Bit#(1))'(0)))).notFull ||
208
              (select(fifos, ((Bit#(1))'(1)))).notFull);
209
  endmethod: space1i
210
 
211
  method space2i() ;
212
      return ((select(fifos, ((Bit#(1))'(0)))).notFull &&
213
              (select(fifos, ((Bit#(1))'(1)))).notFull);
214
  endmethod: space2i
215
 
216
endmodule: mkFIFO2
217
 
218
 
219
module mkTest(FIFO_2#(Bit#(2)));
220
  FIFO_2#(Bit#(2)) f();
221
  mkFIFO2 the_f(f);
222
 
223
  method enq_1();
224
     return (f.enq_1);
225
  endmethod: enq_1
226
 
227
  method enq_2();
228
     return (f.enq_2);
229
  endmethod: enq_2
230
 
231
  method first_1();
232
     return (f.first_1);
233
  endmethod: first_1
234
 
235
  method first_2();
236
     return (f.first_2);
237
  endmethod: first_2
238
 
239
  method deq_1();
240
     return (f.deq_1);
241
  endmethod: deq_1
242
 
243
  method deq_2();
244
     return (f.deq_2);
245
  endmethod: deq_2
246
 
247
  method clear();
248
     return (f.clear);
249
  endmethod: clear
250
 
251
  method has1i();
252
     return (f.has1i);
253
  endmethod: has1i
254
 
255
  method has2i();
256
     return (f.has2i);
257
  endmethod: has2i
258
 
259
  method space1i();
260
     return (f.space1i);
261
  endmethod: space1i
262
 
263
  method space2i();
264
     return (f.space2i);
265
  endmethod: space2i
266
endmodule: mkTest
267
 
268
endpackage: FIFO_2
269
 

powered by: WebSVN 2.1.0

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