-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The VectorFIFOF module has a FIFOF interface for enqueuing and dequeuing data. It also provides a method, which returns a Vector of Maybe entries, to access all entries in the queue simultaneously.
- Loading branch information
1 parent
154d564
commit 001feaf
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
|
||
package VectorFIFOF; | ||
|
||
// This package implements a fifo like module with a parameterized | ||
// depth and standard FIFOF interface. The module also provides | ||
// parallel access to all items in the fifo, for example, to allow | ||
// searching for hazards before enqueueing new items. | ||
|
||
import FIFOF ::*; | ||
import Vector ::*; | ||
|
||
interface VectorFIFOF#(numeric type depth, type t); | ||
interface FIFOF#(t) fifo; | ||
interface Vector#(depth, Maybe#(t)) vector; | ||
endinterface | ||
|
||
module mkVectorFIFOF(VectorFIFOF#(depth, t)) | ||
provisos( | ||
Bits#(t, a__) | ||
); | ||
|
||
Vector#(depth, Reg#(t)) vr_data <- replicateM(mkRegU); | ||
Array#(Reg#(UInt#(TLog#(TAdd#(depth,1))))) r_count <- mkCReg(3, 0); | ||
|
||
Wire#(t) w_enq <- mkWire; | ||
PulseWire pw_deq <- mkPulseWire; | ||
PulseWire pw_clear <- mkPulseWire; | ||
|
||
function Bool notFull; | ||
return r_count[0] < fromInteger(valueOf(depth)); | ||
endfunction | ||
|
||
function Bool notEmpty; | ||
return r_count[0] != 0; | ||
endfunction | ||
|
||
rule rl_enq; | ||
vr_data[r_count[1]] <= w_enq; | ||
r_count[1] <= r_count[1] + 1; | ||
endrule | ||
|
||
rule rl_deq(pw_deq); | ||
for (Integer i = 0; i < fromInteger(valueOf(depth)) - 1; i = i + 1) | ||
vr_data[i] <= vr_data[i + 1]; | ||
|
||
r_count[0] <= r_count[0] - 1; | ||
endrule | ||
|
||
rule rl_clear(pw_clear); | ||
r_count[2] <= 0; | ||
endrule | ||
|
||
function Maybe#(t) valid(Integer x, t a); | ||
if (fromInteger(x) < r_count[0]) | ||
return tagged Valid a; | ||
else | ||
return tagged Invalid; | ||
endfunction | ||
|
||
interface FIFOF fifo; | ||
method Action enq(t x) if (notFull); | ||
w_enq <= x; | ||
endmethod | ||
|
||
method Action deq if (notEmpty); | ||
pw_deq.send; | ||
endmethod | ||
|
||
method t first if (r_count[0] > 0); | ||
return vr_data[0]; | ||
endmethod | ||
|
||
method Action clear; | ||
pw_clear.send; | ||
endmethod | ||
|
||
method Bool notFull; | ||
return notFull; | ||
endmethod | ||
|
||
method Bool notEmpty; | ||
return notEmpty; | ||
endmethod | ||
endinterface | ||
|
||
interface Vector vector = zipWith(valid, genVector, readVReg(vr_data)); | ||
|
||
endmodule | ||
|
||
endpackage |