← All problems

Multiply-Accumulate

Medium · Sequential · SystemVerilog · VHDL

Design a pipelined multiply-accumulate (MAC) unit.

A MAC unit multiplies a pair of operands each cycle and adds the product to a running sum; it is the inner loop of dot products and FIR filters. Pipelining puts the multiply and the add in different cycles, so each can be short, at the cost of every product reaching the sum later.

A cycle with valid_in high presents a sample, the unsigned operands A and B. Two cycles after a sample, valid_out is high and result has taken the sample's product A × B: added to the sum, or, if accum_clr was high with the sample, in place of it, which restarts the sum. In every other cycle valid_out is low and result may take any value. accum_clr has no effect in a cycle with valid_in low. result keeps the low ACC_WIDTH bits of the sum.

rst_n is a synchronous, active-low reset: it sets result to 0 and valid_out low, and discards any sample still in the pipeline.

  • Arithmetic

Open this challenge in the editor →