-
Notifications
You must be signed in to change notification settings - Fork 2
/
Mult.bsv
40 lines (33 loc) · 873 Bytes
/
Mult.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
37
38
39
40
import StmtFSM :: *;
interface Mult#(numeric type maximumValue);
method Action placeOperands(Int#(TLog#(maximumValue)) a,
Int#(TLog#(maximumValue)) b);
method Int#(64) getResult();
endinterface
module mkMult(Mult#(maximumValue))
provisos(
Log#(maximumValue, operandsBits),
Add#(operandsBits, operandsBits, resultBits),
Add#(resultBits, x, 64)
);
Reg#(Int#(resultBits)) result <- mkReg(0);
method Action placeOperands(Int#(operandsBits) a,
Int#(operandsBits) b);
Int#(resultBits) aE = extend(a);
Int#(resultBits) bE = extend(b);
result <= aE * bE;
endmethod
method Int#(64) getResult();
return extend(result);
endmethod
endmodule
module mkTB(Empty);
Mult#(128) uut <- mkMult();
Stmt fsm = {
seq
uut.placeOperands(23, 2);
$display("result: 23*2 = %d", uut.getResult());
endseq
};
mkAutoFSM(fsm);
endmodule