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

Subversion Repositories bluespec-80211atransmitter

[/] [bluespec-80211atransmitter/] [trunk/] [Pipelines.bsv] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ndave
// The MIT License
2
//
3
// Copyright (c) 2006 Nirav Dave (ndave@csail.mit.edu)
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included in
13
// all copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
// THE SOFTWARE.
22
 
23
 
24
 
25
 
26
//////////////////////////////////////////////////////////////////////////////////
27
 
28
// Copyright (c) 2006 Nirav Dave (ndave@csail.mit.edu)
29
 
30
// Permission is hereby granted, free of charge, to any person obtaining
31
// a copy of this software and associated documentation files (the
32
// "Software"), to deal in the Software without restriction, including
33
// without limitation the rights to use, copy, modify, merge, publish,
34
// distribute, sublicense, and/or sell copies of the Software, and to
35
// permit persons to whom the Software is furnished to do so, subject to
36
// the following conditions:
37
 
38
// The above copyright notice and this permission notice shall be
39
// included in all copies or substantial portions of the Software.
40
 
41
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
42
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
44
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
45
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
46
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
47
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48
 
49
//////////////////////////////////////////////////////////////////////////////////
50
 
51
import FIFO::*;
52
import FIFOF::*;
53
import Vector::*;
54
 
55
interface Pipeline#(type alpha);
56
  method Action put(alpha x);
57
  method ActionValue#(alpha) get();
58
endinterface
59
 
60
function alpha repeatFN(Bit#(b) reps, function alpha f(Bit#(b) stage, alpha fx), Bit#(b) stage, alpha in);
61
  alpha new_in = f(stage, in);
62
  return (reps == 0) ? in : repeatFN(reps - 1, f, stage+1, new_in);
63
endfunction
64
 
65
module mkPipeline_Circ#(Bit#(b) numstages,
66
                        Bit#(b) step,
67
                        function alpha sf(Bit#(b) s, alpha x))
68
       (Pipeline#(alpha))
69
    provisos
70
       (Bits#(alpha, asz));
71
 
72
  // input queue
73
  FIFOF#(alpha)       inputQ <- mkLFIFOF();
74
 
75
  // internal state
76
  Reg#(Bit#(b))          stage <- mkReg(0);
77
  Reg#(alpha)             s <- mkRegU;
78
 
79
  // output queue
80
  FIFO#(alpha)        outputQ <- mkLFIFO();
81
 
82
  rule compute(True);
83
   // get input (implicitly stalls if no input)
84
 
85
   alpha s_in = s; // default is from register
86
   if (stage == 0)
87
     begin
88
       s_in = inputQ.first();
89
       inputQ.deq();
90
     end
91
 
92
   //do stage
93
   let s_out = repeatFN(step, sf, stage, s_in);
94
 
95
   // store output
96
   stage <= (stage + step == numstages) ? 0 : stage + step;
97
 
98
   if(stage + step == numstages)
99
     outputQ.enq(s_out);
100
   else
101
     s <= s_out;
102
  endrule
103
 
104
  // The Interface
105
 
106
  method Action put(alpha x);
107
    inputQ.enq(x);
108
  endmethod
109
 
110
  method ActionValue#(alpha) get();
111
    outputQ.deq();
112
    return outputQ.first();
113
  endmethod
114
 
115
endmodule
116
 
117
module mkPipeline_Sync#(Bit#(b) numstages,
118
                        Bit#(b) step,
119
                        function alpha sf(Bit#(b) s, alpha x))
120
       (Pipeline#(alpha))
121
    provisos
122
       (Bits#(alpha, asz),Add#(b,k,32));
123
 
124
  // input queue
125
  FIFOF#(alpha)       inputQ <- mkLFIFOF();
126
 
127
  // internal state
128
  // This is an over estimate of the space we need
129
  // we're artificially restricted because there is no
130
  // "reasonable way to pass a "static" parameter.
131
  // We will only create/initialize the used registers though.
132
 
133
  Vector#(TExp#(b), Reg#(Maybe#(alpha))) piperegs = newVector();
134
 
135
  for(Bit#(b) i = 0; i < numstages; i = i + step)
136
   begin
137
     let pipereg <- mkReg(Nothing);
138
     piperegs[i] = pipereg;
139
   end
140
 
141
  // output queue
142
  FIFO#(alpha)        outputQ <- mkLFIFO();
143
 
144
  rule compute(True);
145
    for(Bit#(b) stage = 0; stage < numstages; stage = stage + step)
146
      begin
147
        //Determine Inputs
148
 
149
        Maybe#(alpha) in = Nothing; // Default Value Is Nothing
150
 
151
        if (stage != 0)                         // Not-First Stage takes from reg
152
           in = (piperegs[stage - step])._read;
153
        else if(inputQ.notEmpty) // take from queue at stage 0
154
          begin
155
            in = Just(inputQ.first());
156
            inputQ.deq();
157
          end
158
        alpha s_in = fromMaybe(?,in);
159
 
160
        //do stage
161
 
162
        alpha s_out = repeatFN(step, sf, stage, s_in);
163
 
164
        //deal with outputs
165
        if (stage + step < numstages) // it's not the last stage
166
          (piperegs[stage]) <= isJust(in) ? Just(s_out): Nothing;
167
        else if(isValid(in)) // && stage == 2
168
          outputQ.enq(s_out);
169
        else
170
          noAction;
171
        end
172
  endrule
173
 
174
  // The Interface
175
  method Action put(alpha x);
176
    inputQ.enq(x);
177
  endmethod
178
 
179
  method ActionValue#(alpha) get();
180
    outputQ.deq();
181
    return outputQ.first();
182
  endmethod
183
 
184
endmodule
185
 
186
 
187
module mkPipeline_Comb#(Bit#(b) numstages,
188
                        Bit#(b) step,
189
                        function alpha sf(Bit#(b) s, alpha x))
190
       (Pipeline#(alpha))
191
    provisos
192
       (Bits#(alpha, asz));
193
 
194
  // input queue
195
  FIFOF#(alpha)       inputQ <- mkLFIFOF();
196
 
197
  // output queue
198
  FIFO#(alpha)        outputQ <- mkLFIFO();
199
 
200
  rule compute(True);
201
    alpha  stage_in, stage_out;
202
 
203
    stage_in = inputQ.first();
204
    inputQ.deq();
205
 
206
    for(Bit#(b) stage = 0; stage < numstages; stage = stage + step)
207
      begin
208
        //do stage
209
        stage_out = repeatFN(step, sf, stage, stage_in);
210
 
211
        //deal with outputs
212
        stage_in = stage_out;
213
      end
214
 
215
    outputQ.enq(stage_out);
216
  endrule
217
 
218
  // The Interface
219
  method Action put(alpha x);
220
    inputQ.enq(x);
221
  endmethod
222
 
223
  method ActionValue#(alpha) get();
224
    outputQ.deq();
225
    return outputQ.first();
226
  endmethod
227
 
228
endmodule
229
 
230
 
231
 
232
 
233
 
234
 
235
 
236
 
237
 
238
 
239
 
240
 
241
 
242
 
243
 
244
 
245
 
246
 
247
 
248
 
249
 
250
 
251
 
252
 
253
 
254
 
255
 
256
 
257
 
258
 
259
 
260
 
261
 
262
 
263
 
264
 
265
 
266
 
267
 
268
 
269
 
270
 
271
 
272
 
273
 
274
 
275
 
276
 
277
 
278
 
279
 
280
 
281
 
282
 
283
 
284
 
285
 
286
 
287
 
288
 
289
 
290
 
291
 
292
 
293
 

powered by: WebSVN 2.1.0

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