1// This test is a distilled version of the bitcoin_8 benchmark.
2// This is a minimal instantiation. It uses two stages.
3
4// Pipeline Stage: Adds 1 to input every clock
5module Stage(clk, in, out);
6  input wire clk;
7  input wire[7:0] in;
8  output reg[7:0] out;
9
10  always @(posedge clk) begin
11    out <= in + 8'b1;
12  end
13endmodule
14
15// Pipeline: DEPTH instances of Stage, chained together, plus a final delay
16module Pipeline #(parameter DEPTH = 8) (clk, in, out);
17  input wire clk;
18  input wire[7:0] in;
19  output reg[7:0] out;
20
21  genvar i;
22  for (i = 0; i < DEPTH; i=i+1) begin : STAGES
23    wire[7:0] temp;
24    if (i == 0) begin
25      Stage s(clk, in, temp);
26    end else begin
27      Stage s(clk, STAGES[i-1].temp, temp);
28    end
29  end
30
31  always @(posedge clk) begin
32    out <= STAGES[DEPTH-1].temp * 2;
33  end
34endmodule
35
36// Main: Stuff zeros in the pipe and wait until something comes out
37localparam[7:0] D = 2;
38reg[7:0] in = 8'b0;
39wire[7:0] out;
40
41Pipeline #(D) p(clock.val, in, out);
42
43reg[7:0] COUNT = 8'b0;
44always @(posedge clock.val) begin
45  $write("%d", COUNT);
46  COUNT <= COUNT + 1;
47  if (out == (D*2)) begin
48    $finish;
49  end
50end
51