-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPipe.bsv
More file actions
executable file
·60 lines (46 loc) · 1.15 KB
/
Pipe.bsv
File metadata and controls
executable file
·60 lines (46 loc) · 1.15 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package Pipe;
// Simple (naive) binary multiplier
import Multiplier::*;
(* synthesize *)
module mkPipe( Multiplier_IFC );
typedef struct{
Reg#(32) m1;
Reg#(16) m2;
Reg#(32) parsum;
Reg(#1) valid;
}Pipetype;
Pipetype pipe[16];
function Bit#(32) mulpipe(Tin x,Tin y);
pipe[0].m1=x;
pipe[0].m2=y;
pipe[0].valid=1;
pipe[0].parsum=0;
for(Integer i=1;i<16;i=i+1)
begin
pipe[i].m1 <= pipe[i-1].m1<<1;
pipe[i].m2 <= pipe[i-1].m2;
pipe[i].valid <= pipe[i-1].valid;
if(pipe[i-1].m2[i]==0)
pipe[i].parsum <= pipe[i-1].parsum;
else
pipe[i].parsum <= pipe[i-1].parsum+pipe[i].m1
end
return pipe[15].parsum;
endfunction
Reg#(Bit#(10)) indicator <- mkReg(0);
Reg#(Bool) present <- mkReg(True);
Reg#(Tout) product <- mkReg(?);
method Action start(Tin p, Tin q) if (present && (indicator == 0));
present <= False;
product <= multiply(p,q);
indicator <= 1;
endmethod
method Tout result() if (indicator == 1);
return product;
endmethod
method Action acknowledge() if ((indicator == 1) && !present);
present <= True;
indicator <= 0;
endmethod
endmodule : mkPipe
endpackage : Pipe