RTL Studio Open IDE

Arithmetic & Math

Saturating MAC 4x4→8 — L2 Upgrade

Signed Multiply-Accumulate unit with 4-bit inputs, 8-bit output, saturation arithmetic, and a sticky saturation flag.

About this block

Simulate it in the Verilog IDE

Mediumverilogsimsyn

Saturating MAC 4x4→8 — L2 Upgrade is a Verilog reference block in the Arithmetic & Math catalog. Adders, multipliers, dividers, ALUs, and arithmetic datapaths. Marked Medium: more state or a wider datapath, still one workspace in the IDE.

This IP implements a signed Multiply-Accumulate (MAC) unit with saturation arithmetic. It processes 4-bit signed operands and produces an 8-bit signed result. The design includes a sticky saturation flag to detect overflow events.

This IP provides a robust signed MAC with saturation and sticky flagging.

It is suitable for DSP applications requiring overflow protection.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for Saturating MAC 4x4→8 — L2 Upgrade.
  2. Read the Verilog module in the editor. The catalog line for this block: Signed Multiply-Accumulate unit with 4-bit inputs, 8-bit output, saturation arithmetic, and a sticky saturation flag.
  3. Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
  4. Run Yosys in the same IDE for a generic netlist. Sky130 liberty mapping is a separate Pro library option.

RTL Studio is the Verilog simulator and IDE around this block: Slang lint, Verilator, VCD waveforms, and Yosys, in the browser. Simulation guide · Yosys guide.

Features

  • Signed 4-bit input operands: Range -8 to +7.
  • Signed 8-bit output accumulator: Range -128 to +127.
  • Sticky saturation flag: Latches on overflow/underflow and remains set until cleared.
  • Control signals: Asynchronous reset (rst_n) and synchronous clear (clear_sat) for the saturation flag. Enable control (en) to hold previous results when disabled.
  • Arithmetic: Signed multiplication followed by addition with saturation clamping.

Interface

Port NameDirectionWidthDescription
clkInput1Clock input
rst_nInput1Active-low asynchronous reset
clear_satInput1Synchronous clear for sat_flag
enInput1Enable signal for computation
aInput4Signed multiplicand
bInput4Signed multiplier
cInput4Signed accumulator input
sumOutput8Signed saturated product-accumulator sum
sat_flagOutput1Sticky saturation event flag

Architecture

The datapath performs signed multiplication followed by addition. Sign extension is applied to all 4-bit inputs to 8-bit width before operations. The product is 8-bit wide, which fits within the 8-bit accumulator range for most cases. Saturation detection uses a 9-bit intermediate sum to identify overflow conditions.

  • Positive Overflow: Clamps the output to +127 (0x7F).
  • Negative Underflow: Clamps the output to -128 (0x80).
  • Sticky Flag: The sat_flag is registered and remains set until cleared by clear_sat or rst_n.

Verification

The testbench validates basic arithmetic, saturation behavior, and control signals. All eight test cases passed successfully in simulation.

Test CaseDescriptionExpected ResultStatus
TC1Basic Positive MAC (1*1+1)sum=2, sat=0PASS
TC2Basic Negative MAC (-1*-1-1)sum=0, sat=0PASS
TC3Clear Sat Flag SequenceFlag clearedPASS
TC4Enable Hold BehaviorSum holds 30PASS
TC5Reset Behaviorsum=0, sat=0PASS
TC6Max Positive Values (7*7+7)sum=56, sat=0PASS
TC7Min Negative Values (-8*-8-8)sum=56, sat=0PASS
TC8Mixed Sign (-8*7+7)sum=-49, sat=0PASS

More in Arithmetic & Math

All Arithmetic & Math blocks