-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathcompile.futil
43 lines (39 loc) · 1.04 KB
/
compile.futil
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
/// Represents an undefined value. Should never appear in the output of a program.
primitive undef<"share"=1>[WIDTH]() -> (out: WIDTH) {
assign out = 'x;
}
/// Constants
comb primitive std_const<"share"=1>[WIDTH, VALUE]() -> (out: WIDTH) {
assign out = VALUE;
}
/// Combinational wire to forward values
comb primitive std_wire<"share"=1>[WIDTH](@data in: WIDTH) -> (out: WIDTH) {
assign out = in;
}
/// Add two numbers.
comb primitive std_add<"share"=1>[WIDTH](@data left: WIDTH, @data right: WIDTH) -> (out: WIDTH) {
assign out = left + right;
}
/// Standard register with a one-cycle latency.
// ANCHOR: std_reg_def
primitive std_reg<"state_share"=1>[WIDTH](
@write_together(1) @data in: WIDTH,
@write_together(1) @static(1) @go write_en: 1,
@clk clk: 1,
@reset reset: 1
) -> (
@stable out: WIDTH,
@done done: 1
)
// ANCHOR_END: std_reg_def
{
always_ff @(posedge clk) begin
if (reset) begin
out <= 0;
done <= 0;
end else if (write_en) begin
out <= in;
done <= 1'd1;
end else done <= 1'd0;
end
}