Build a blend of two pixels that meets both numbers of its brief at once. Each result comes exactly two edges after its input, one per cycle.
Hardware context: A pixel blend y = (a * (16 - w) + b * w) / 16 whose brief fixes latency 2 and one result per cycle, with outputs straight from flops. Design the blend that meets the latency and the throughput of its brief together.
A video scaler blends two pixels with a weight: y = (a * (16 - w) + b * w) / 16. The stage after it expects each result exactly two edges after its input, on outputs that come straight from flops. The line rate needs a new pixel pair on every cycle.
Two earlier versions each met one number. One saved a multiplier and took a pair only every second cycle. The other answered after one edge, from logic. This is an Implement problem: write blend so that it meets the latency and the throughput together.
Brief: rising-edge clk; rst_n asynchronous and active-low, clearing out_valid and every input in flight. An input is taken at each edge where in_valid is 1, with no limit on how many in a row. Its result is on y, with out_valid at 1, after the second edge from there. w is 0 to 16. The division by 16 drops the remainder. Synthesis check: the design must build on the site's synthesis flow with no latch. It also checks that every bit of out_valid and y comes straight from a flop.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
script_lo | 184 | input of each check |
script_hi | 184 | input of each check |
Full specification
module blend (
input logic clk,
input logic rst_n, // asynchronous, active-low
input logic in_valid, // 1: take a, b and w at this edge
input logic [7:0] a, b,
input logic [4:0] w, // weight of b, 0 to 16
output logic out_valid, // 1: y is the result of the input taken two edges ago
output logic [7:0] y
);
// your design
endmodule
| Item | This design |
|---|---|
| latency | exactly 2 edges: the input taken at edge k shows after edge k + 2 |
| throughput | one input per cycle, for any number of cycles in a row |
| outputs | out_valid and y are driven straight by flops (checked in the synthesized netlist), so they change only at a clock edge or on reset |
| out_valid | 1 after edge k + 2 exactly when in_valid was 1 at edge k and no reset came between |
| y | (a * (16 - w) + b * w) >> 4 while out_valid is 1; not checked otherwise |
| reset | out_valid falls at once; inputs still inside the block produce no result |
Each test pulses rst_n, then runs 16 cycles. Inputs change while clk is low. The result holds the set of cycles whose edge left out_valid at 1, and y for each of them in order. moved_between_edges is 1 if an output changed while the clock stood still and no reset was applied.
Examples
Example 1
One Input- Input
cycle 0: no input; cycle 1: a=100 b=200 w=4
- Output
valid_cycles = {2}, y_result0 = 125
The input is taken at the edge of cycle 1. Two edges later, in cycle 3, out_valid is 1 and y is (100 * 12 + 200 * 4) / 16 = 125.
Example 2
A Burst of Seven- Input
cycle 0: a=0 b=255 w=0; cycle 1: a=0 b=255 w=16; cycle 2: a=0 b=255 w=8; cycle 3: a=255 b=0 w=1; cycle 4: a=16 b=32 w=15; cycle 5: a=255 b=255 w=7; cycle 6: a=1 b=2 w=3
- Output
valid_cycles = {1, 2, 3, 4, 5, 6, 7}, y_result1 = 255, y_result2 = 127, y_result3 = 239, y_result4 = 31, y_result5 = 255, y_result6 = 1
Seven inputs in cycles 0 to 6 give seven results in cycles 2 to 8, one per cycle. A design that takes every second input shows fewer.
Example 3
Inputs with Gaps- Input
cycle 0: a=10 b=250 w=12; cycle 1: no input; cycle 2: a=250 b=10 w=12; cycle 3: no input; cycle 4: no input; cycle 5: a=77 b=77 w=16; cycle 6: no input; cycle 7: a=128 b=64 w=5
- Output
valid_cycles = {1, 3, 6, 8}, y_result0 = 190, y_result1 = 70, y_result2 = 77, y_result3 = 108
Each result is two cycles after its input, and out_valid is 0 in between. The values on a, b and w during a gap never reach y with out_valid at 1.
Constraints and Contract
- Inputs are known 0/1 values. When in_valid is 0, the bench drives other values on a, b and w.
- Keep the module name and the ports.
Hints
Hint 1
Count the flops on the way from an input to y. The brief asks for two, and the second one is the output itself.
Hint 2
What sits between the two registers decides the levels of logic, never the latency. Put the two products before the first register or after it, as you like.
Hint 3
out_valid travels with the data: it needs the same number of registers. Only the valid bits need the reset.
What the grader checks: Seven directed and eleven seeded scripts of sixteen cycles hold bursts, gaps, junk on idle inputs and reset pulses. An independent model gives the cycles that show out_valid, and y in each. The outputs are also sampled just before each edge to see that they change only at edges. Zero-delay simulation cannot tell a flop output from logic fed only by flops, so the synthesis check reads the netlist: every bit of out_valid and y must come straight from a flop. Passing shows the latency and the throughput on these scripts, registered outputs and no latch.
The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.
18 checks on Icarus Verilog + Yosys · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 1 steps and the final capstone