30.04.2013 Views

BSV by Example - Computation Structures Group

BSV by Example - Computation Structures Group

BSV by Example - Computation Structures Group

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ule r2;<br />

let v1 = f1.first;<br />

f1.deq;<br />

$display (" v1 = %0h", v1);<br />

f2.enq (v1+1);<br />

endrule<br />

rule r3;<br />

let v2 = f2.first;<br />

f2.deq;<br />

$display (" v2 = %0h", v2);<br />

f3.enq (v2+1);<br />

endrule<br />

rule r4;<br />

let v3 = f3.first;<br />

f3.deq;<br />

$display (" v3 = %0h", v3);<br />

f4.enq (v3+1);<br />

endrule<br />

The rules r2, r3, and r4 may or may not fire together. Each rule fires whenever its input FIFO<br />

has data available (implicit condition of first and deq) and its output FIFO has space available<br />

(implicit condition of enq).<br />

The Action method send enqueues a value a into FIFO f1. This method is only enabled if f1 has<br />

space available. Thus the implicit condition of f1.enq becomes the implicit condition of this send<br />

method and becomes part of the enabling condition of the rule fill in the testbench, i.e., that rule<br />

cannot fire unless the implicit conditions of f1.enq are met.<br />

method Action send (int a);<br />

f1.enq (a);<br />

endmethod<br />

The ActionValue method receive reads the first int element v4 of FIFO f4, dequeues FIFO f4 and<br />

returns v4. This method is only enabled when f4 has data available (implicit condition of first<br />

and deq). Thus the implicit conditions of f4.first and f4.deq become the implicit condition of<br />

the receive method, which in turn becomes part of the enabling condition of rule drain in the<br />

testbench. That is, the rule drain cannot fire until all these conditions are true.<br />

method ActionValue#(int) receive ();<br />

let v4 = f4.first;<br />

$display (" v4 = %0h", v4);<br />

f4.deq;<br />

return v4;<br />

endmethod<br />

When executed, you can observe the pipeline behavior. However, the outputs from the $displays<br />

in different rules that execute in the same cycle may be unpredictable.<br />

48

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!