Skip to content

Commit

Permalink
Merge pull request #78 from yy665/exn
Browse files Browse the repository at this point in the history
Exn
  • Loading branch information
yy665 authored Oct 25, 2023
2 parents 7935064 + 6cc3a76 commit 1b0f426
Show file tree
Hide file tree
Showing 272 changed files with 3,492 additions and 208 deletions.
4 changes: 2 additions & 2 deletions bin/runbsc
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ case "$CMD" in
#Run simulation in Bluesim
"$BSC" $ARGS -sim $BPATH "$TOP".bsv
"$BSC" $ARGS $BPATH -sim -o "$TB".bexe -e "$TB" "$TB".ba
timeout "$TOUT"s ./"$TB".bexe | grep -v "WARNING" > "$SIMOUT"
timeout "$TOUT"s ./"$TB".bexe | grep -v "WARNING" | grep -v "\$finish" > "$SIMOUT"
;;
"s")
#Run simulation in Verilog
"$BSC" $ARGS $BPATH $VPATH $VSIM -vdir $VDIR -simdir $SDIR -u "$TOP".bsv
"$BSC" $ARGS $VPATH $VSIM -verilog -vdir $VDIR -simdir $SDIR -o "$TB".bexe -e "$TB" "$VDIR"/"$TB".v
timeout "$TOUT"s ./"$TB".bexe | grep -v "WARNING" > "$SIMOUT"
timeout "$TOUT"s ./"$TB".bexe | grep -v "WARNING" | grep -v "\$finish" > "$SIMOUT"
;;
"c")
rm -f *.bi *.bo *.ba
Expand Down
1 change: 1 addition & 0 deletions bscRuntime/libs/BypassRF.v
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// BypassRF.v
`ifdef BSV_ASSIGNMENT_DELAY
`else
`define BSV_ASSIGNMENT_DELAY
Expand Down
1 change: 1 addition & 0 deletions bscRuntime/libs/Ehr.bsv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Ehr.bsv

// Copyright (c) 2017 Massachusetts Institute of Technology
//
Expand Down
1 change: 1 addition & 0 deletions bscRuntime/libs/Memories.bsv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Memories.bsv
package Memories;

import GetPut :: *;
Expand Down
1 change: 1 addition & 0 deletions bscRuntime/libs/Named.bsv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Named.bsv
package Named;

import Memories :: *;
Expand Down
1 change: 1 addition & 0 deletions bscRuntime/libs/NamedEhr.bsv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// NamedEhr.bsv
package Named;

import RegFile :: *;
Expand Down
Empty file removed bscRuntime/libs/PdlFifo.bsv
Empty file.
1 change: 1 addition & 0 deletions bscRuntime/libs/PrioFifo.bsv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// PrioFifo.bsv
package PrioFifo;

import FIFOF :: *;
Expand Down
1 change: 1 addition & 0 deletions bscRuntime/libs/Speculation.bsv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Speculation.bsv
package Speculation;

import Vector :: *;
Expand Down
1 change: 1 addition & 0 deletions bscRuntime/libs/nametb.bsv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nametb.bsv
import Named::*;
import FIFO::*;

Expand Down
1 change: 1 addition & 0 deletions bscRuntime/libs/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.6.2
1 change: 1 addition & 0 deletions bscRuntime/libs/tb.bsv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tb.bsv
import Memories :: *;
import Connectable :: *;

Expand Down
1 change: 1 addition & 0 deletions bscRuntime/memories/Ehr.bsv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Ehr.bsv

// Copyright (c) 2017 Massachusetts Institute of Technology
//
Expand Down
35 changes: 35 additions & 0 deletions bscRuntime/memories/Interrupt.bsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package Interrupt;

import FIFOF :: *;
import Ehr :: *;

interface TimingInterruptController#(numeric type addr);
method ActionValue#(Bool) req(Int#(addr) a);
method Action ack(Int#(addr) a);
endinterface

module mkTimingInterruptController(TimingInterruptController#(addr) _unused_);

Reg#(Bool) status <- mkReg(False);
Reg#(UInt#(10)) timer <- mkReg(0);
Wire#(Int#(addr)) getAck <- mkWire();

// rule to update timer and set status to True every 1000 cycle
rule updateTimer;
timer <= timer + 1;
if (timer == 999) begin
timer <= 0;
status <= True;
end
endrule

method ActionValue#(Bool) req(Int#(addr) p);
return status;
endmethod

method Action ack(Int#(addr) a);
status <= False;
endmethod
endmodule

endpackage
5 changes: 3 additions & 2 deletions bscRuntime/memories/Locks.bsv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Locks.bsv
package Locks;

import FIFOF :: *;
Expand Down Expand Up @@ -158,8 +159,8 @@ module mkCheckpointQueueLock(Put#(winfo) mem, CheckpointQueueLock#(LockId#(d), L

method Action abort();
nextId[0] <= 0;
owner <= 0;
empty <= True;
owner <= 0;
empty <= True;
wdata <= tagged Invalid;
endmethod

Expand Down
2 changes: 1 addition & 1 deletion bscRuntime/memories/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BSC=bsc -no-show-timestamps -no-show-version --aggressive-conditions
TOBUILD=Ehr.bo Locks.bo Memories.bo Speculation.bo SpecialQueues.bo
TOBUILD=Ehr.bo Locks.bo Memories.bo Speculation.bo SpecialQueues.bo Interrupt.bo

## Default simulator is iverilog
VSIM = -vsim iverilog
Expand Down
67 changes: 63 additions & 4 deletions bscRuntime/memories/Memories.bsv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Memories.bsv
package Memories;

import GetPut :: *;
Expand All @@ -21,6 +22,7 @@ export AsyncMem(..);
export AsyncMem2(..);
export QueueLockCombMem(..);
export CheckpointQueueLockCombMem(..);
export CheckpointQueueLockAsyncMem(..);
export QueueLockAsyncMem(..);
export QueueLockAsyncMem2(..);
export BypassLockCombMem(..);
Expand All @@ -37,6 +39,7 @@ export mkAsyncMem;
export mkAsyncMem2;
export mkQueueLockCombMem;
export mkCheckpointQueueLockCombMem;
export mkCheckpointQueueLockAsyncMem;
export mkQueueLockAsyncMem;
export mkQueueLockAsyncMem2;
export mkFAAddrLockCombMem;
Expand All @@ -61,6 +64,14 @@ function Bool isNewer(UInt#(sz) a, UInt#(sz) b, UInt#(sz) h);
return !isOlder(a, b, h);
endfunction

function Put#(Tuple3#(Bit#(nsz), addr, elem)) asyncMemToPut (AsyncMem#(addr, elem, MemId#(inflight), nsz) amem);
return (interface Put;
method Action put(Tuple3#(Bit#(nsz), addr, elem) x);
amem.silentReq1(tpl_2(x), tpl_3(x), tpl_1(x));
endmethod
endinterface);
endfunction

function Put#(Tuple2#(addr, elem)) rfToPut (RegFile#(addr, elem) rf);
return (interface Put;
method Action put(Tuple2#(addr, elem) x);
Expand All @@ -83,6 +94,7 @@ endinterface

interface AsyncMem#(type addr, type elem, type mid, numeric type nsz);
method ActionValue#(mid) req1(addr a, elem b, Bit#(nsz) wmask);
method Action silentReq1(addr a, elem b, Bit#(nsz) wmask);
method elem peekResp1(mid a);
method Bool checkRespId1(mid a);
method Action resp1(mid a);
Expand Down Expand Up @@ -129,6 +141,14 @@ interface CheckpointQueueLockCombMem#(type addr, type elem, type id, type cid);
method Action atom_w(addr a, elem b);
endinterface

interface CheckpointQueueLockAsyncMem#(type addr, type elem, type rid, numeric type nsz, type id, type cid);
interface AsyncMem#(addr, elem, rid, nsz) mem;
interface CheckpointQueueLock#(id, cid, Tuple3#(Bit#(nsz), addr, elem)) lock;
method Action write(addr a, elem b, Bit#(nsz) wmask);
method Bool canAtom1(addr a);
method ActionValue#(rid) atom_req1(addr a, elem b, Bit#(nsz) wmask);
endinterface

interface QueueLockAsyncMem#(type addr, type elem, type rid, numeric type nsz, type lid);
interface AsyncMem#(addr, elem, rid, nsz) mem;
interface QueueLock#(lid) lock;
Expand Down Expand Up @@ -242,14 +262,15 @@ module mkBramPort#(parameter Bool init, parameter String file)(BramPort#(addr, e
interface Server bram_server;
interface Put request;
method Action put (Tuple3#(Bit#(nsz), addr, elem) req);
// $display("Sending request %t", $time());
//$display("Sending request %t %d %d ", $time(), tpl_1(req), tpl_3(req));
p.put(tpl_1(req), tpl_2(req), tpl_3(req));
doRead <= True;
endmethod
endinterface

interface Get response;
method ActionValue#(elem) get();
//$display("Returning data %t %d", nextData);
return nextData;
endmethod
endinterface
Expand Down Expand Up @@ -331,6 +352,8 @@ module mkAsyncMem(AsyncMem#(addr, elem, MemId#(inflight), n) _unused_)
Wire#(Tuple3#(Bit#(n), addr, elem)) toMem <- mkWire();
Wire#(elem) fromMem <- mkWire();

RWire#(Bool) doClear <- mkRWireSBR();

//this must be at least size 2 to work correctly (safe bet)
Vector#(inflight, Ehr#(2, elem)) outData <- replicateM( mkEhr(unpack(0)) );
Vector#(inflight, Ehr#(2, Bool)) valid <- replicateM( mkEhr(False) );
Expand All @@ -348,17 +371,24 @@ module mkAsyncMem(AsyncMem#(addr, elem, MemId#(inflight), n) _unused_)
valid[idx][0] <= True;
endrule

(*conflict_free = "freeResp, doClearRule"*)
(*fire_when_enabled*)
rule freeResp;
valid[freeEntry][1] <= False;
endrule

method Action clear();
(*no_implicit_conditions*)
rule doClearRule (doClear.wget() matches tagged Valid.d);
//$display("Memory Cleared");
head <= 0;
for (Integer i = 0; i < valueOf(inflight); i = i + 1) begin
MemId#(inflight) ent = fromInteger(i);
valid[ent][1] <= False;
MemId#(inflight) ent = fromInteger(i);
valid[ent][1] <= False;
end
endrule

method Action clear();
doClear.wset(True);
endmethod

method ActionValue#(MemId#(inflight)) req1(addr a, elem b, Bit#(n) wmask) if (okToRequest);
Expand All @@ -368,6 +398,11 @@ module mkAsyncMem(AsyncMem#(addr, elem, MemId#(inflight), n) _unused_)
return head;
endmethod

method Action silentReq1(addr a, elem b, Bit#(n) wmask) if (okToRequest);
toMem <= tuple3(wmask, a, b);
head <= head + 1;
endmethod

method elem peekResp1(MemId#(inflight) a);
return outData[a][1];
endmethod
Expand Down Expand Up @@ -671,6 +706,30 @@ module mkDMAddrLockCombMem(RegFile#(addr, elem) rf, AddrLockCombMem#(addr, elem,
interface lock = l;
endmodule

module mkCheckpointQueueLockAsyncMem(AsyncMem#(addr, elem, MemId#(inflight), nsz) amem, CheckpointQueueLockAsyncMem#(addr, elem, MemId#(inflight), nsz, LockId#(d), LockId#(d)) _unused_)
provisos(Bits#(Tuple3#(Bit#(nsz), addr, elem), tuplsz));

Put#(Tuple3#(Bit#(nsz), addr, elem)) doWrite = asyncMemToPut(amem);
CheckpointQueueLock#(LockId#(d), LockId#(d), Tuple3#(Bit#(nsz), addr, elem)) l <- mkCheckpointQueueLock(doWrite);

interface lock = l;
interface mem = amem;

method Action write(addr a, elem b, Bit#(nsz) wmask);
l.write(tuple3(wmask, a, b));
endmethod

method Bool canAtom1(addr a);
return l.isEmpty;
endmethod

method ActionValue#(MemId#(inflight)) atom_req1(addr a, elem b, Bit#(nsz) wmask);
let r <- amem.req1(a, b, wmask);
return r;
endmethod

endmodule

module mkQueueLockAsyncMem(AsyncMem#(addr, elem, MemId#(inflight), n) amem, QueueLockAsyncMem#(addr, elem, MemId#(inflight), n, LockId#(d)) _unused_)
provisos(Bits#(addr, szAddr), Bits#(elem, szElem));

Expand Down
25 changes: 13 additions & 12 deletions bscRuntime/memories/SpecialQueues.bsv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SpecialQueues.bsv
package SpecialQueues;

import Ehr :: *;
Expand Down Expand Up @@ -57,26 +58,26 @@ module mkNBFIFOF(FIFOF#(dtyp)) provisos (Bits#(dtyp, szdtyp));
FIFOF#(dtyp) f <- mkFIFOF();
//allow multiple writes in the same cycle
RWire#(dtyp) enq_data <- mkRWireSBR();
RWire#(Bool) doClear <- mkRWireSBR();

//Make sure no enq could happen during clear (takes 2 cycles)
Reg#(Bool) clearCalled <- mkReg(False);

rule doClear(clearCalled);
f.clear();
clearCalled <= False;
endrule

(*conflict_free = "doEnqRule, doClearRule"*)
(*fire_when_enabled*)
rule doEnq (enq_data.wget() matches tagged Valid.d);
rule doEnqRule (enq_data.wget() matches tagged Valid.d);
f.enq(d);
endrule

//reset to the initial state
(*no_implicit_conditions*)
rule doClearRule (doClear.wget() matches tagged Valid.d);
f.clear();
endrule

//only allow the LAST enq each cycle to work, drop the others
method Action enq(dtyp a) if (f.notFull() && !clearCalled);
method Action enq(dtyp a) if (f.notFull());
enq_data.wset(a);
endmethod

method Action deq() if (!clearCalled);
method Action deq();
f.deq();
endmethod

Expand All @@ -93,7 +94,7 @@ module mkNBFIFOF(FIFOF#(dtyp)) provisos (Bits#(dtyp, szdtyp));
endmethod

method Action clear();
clearCalled <= True;
doClear.wset(True);
endmethod

endmodule
Expand Down
44 changes: 29 additions & 15 deletions bscRuntime/memories/Speculation.bsv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Speculation.bsv
package Speculation;

import Vector :: *;
Expand Down Expand Up @@ -41,30 +42,43 @@ module mkSpecTable(SpecTable#(SpecId#(entries), bypassCnt));
$display("Head: %d", head);
for (Integer i = 0; i < valueOf(entries); i = i + 1)
begin
$display("Idx %d, InUse: %b", i, inUse[fromInteger(i)]);
$display("Idx %d, Status: %b", i, specStatus[fromInteger(i)]);
$display("Idx %d, InUse: %b", i, inUse[fromInteger(i)]);
$display("Idx %d, Status: %b", i, specStatus[fromInteger(i)][0]);
end
endrule
*/

*/
//Make sure no enq could happen during clear (takes 2 cycles)

RWire#(Bool) doAlloc <- mkRWireSBR();
RWire#(Bool) doClear <- mkRWireSBR();

/*
Reg#(Bool) enabled <- mkReg(True);
*/
(*conflict_free = "doAllocRule, doClearRule"*)
(*fire_when_enabled*)
rule doAllocRule (doAlloc.wget() matches tagged Valid.d);
head <= head + 1;
inUse[head] <= True;
specStatus[head][valueOf(bypassCnt)-1] <= tagged Invalid;
head <= head + 1;
inUse[head] <= True;
specStatus[head][valueOf(bypassCnt)-1] <= tagged Invalid;
endrule

//reset to the initial state
(*no_implicit_conditions*)
rule doClearRule (doClear.wget() matches tagged Valid.d);
//$display("SpecTable Cleared");
head <= 0;
for (Integer i = 0; i < valueOf(entries); i = i + 1) begin
SpecId#(entries) lv = fromInteger(i);
specStatus[lv][0] <= tagged Invalid;
inUse[lv] <= False;
end
endrule

method Action clear();
head <= 0;
for (Integer i = 0; i < valueOf(entries); i = i + 1) begin
SpecId#(entries) lv = fromInteger(i);
specStatus[lv][0] <= tagged Invalid;
inUse[lv] <= False;
end
doClear.wset(True);
endmethod

//allocate a new entry in the table to track speculation. do this in a nonblocking way
//and just assume that only 1 client calls per cycle
method ActionValue#(SpecId#(entries)) alloc() if (!full);
Expand Down
Loading

0 comments on commit 1b0f426

Please sign in to comment.