-
Notifications
You must be signed in to change notification settings - Fork 2
/
Ehr.bsv
executable file
·36 lines (30 loc) · 1.32 KB
/
Ehr.bsv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Ehr.bsv
// CM for Ehr#(2,t) ehr:
//
// | ehr[0]._read ehr[0]._write ehr[1]._read ehr[1]._write
// -----------------+---------------------------------------------------------------
// ehr[0]._read | CF < CF <
// ehr[0]._write | > C < <
// ehr[1]._read | CF > CF <
// ehr[1]._write | > > > C
import Vector::*;
import RWire::*;
import RevertingVirtualReg::*;
typedef Vector#(n, Reg#(t)) Ehr#(numeric type n, type t);
module mkEhr#(t reset_val)(Ehr#(n, t)) provisos (Bits#(t, tSz));
Array#(Reg#(t)) _m <- mkCReg(valueOf(n), reset_val);
Vector#(n, Reg#(Bool)) double_write_error <- replicateM(mkRevertingVirtualReg(True));
Vector#(n, Reg#(t)) _ifc;
for (Integer i = 0 ; i < valueOf(n) ; i = i+1) begin
_ifc[i] = interface Reg;
method t _read;
return _m[i];
endmethod
method Action _write(t x) if (double_write_error[i]);
double_write_error[i] <= False;
_m[i] <= x;
endmethod
endinterface;
end
return _ifc;
endmodule