Codiode

Two Stage Datapath

EasyVerilog / SystemVerilogBuildFree8 solved

Putting a register in the middle of a long calculation halves the logic between flip-flops, so the clock can run faster. The cost is one extra cycle of latency.

The datapath takes two 8-bit data inputs and a 3-bit shift amount. In the first stage, the two 8-bit inputs are added together. In the second stage, the resulting sum is logically shifted left by the specified shift amount to produce the final output. Crucially, the shift amount must also be delayed by one clock cycle so that the correct shift amount is applied to the corresponding sum.

  • Clock edge: posedge clk
  • Reset type: asynchronous
  • Reset polarity: active-low (rst_n)
  • On reset, all internal pipeline registers and the output d_out must evaluate to 0.

Cycle 1: rst_n=0 → d_out=0, internal registers=0
Cycle 2: rst_n=1, d_in_a=2, d_in_b=3, d_in_shift=1 → Stage 1 computes sum=5 and stores shift=1. d_out=0
Cycle 3: d_in_a=4, d_in_b=4, d_in_shift=2 → Stage 1 computes sum=8 and stores shift=2. Stage 2 computes 5 << 1. d_out=10
Cycle 4: d_in_a=0, d_in_b=0, d_in_shift=0 → Stage 1 computes sum=0 and stores shift=0. Stage 2 computes 8 << 2. d_out=32

Signal Direction Width Description
clk input 1 Positive-edge triggered clock
rst_n input 1 Asynchronous active-low reset; all registers go to 0
d_in_a input 8 First operand for the addition stage
d_in_b input 8 Second operand for the addition stage
d_in_shift input 3 Amount to left-shift the sum in the second stage
d_out output 8 Final registered output of the datapath

Constraints

  • The addition in the first stage must silently discard any overflow beyond 8 bits.
  • The shift in the second stage must be a logical left shift.
  • The output d_out must be registered; it cannot be a combinational output driven directly by the shift logic.
  • The d_in_shift signal must be pipelined (registered) in the first stage so it aligns with the delayed sum in the second stage.

Topics

ArithmeticRegistersPipelining

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

Free to solve. A Codiode account keeps your progress.

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Part of Pipelining

Problem 1 of 20 in the Pipelining track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.