Parameterized Saturating Adder
Digital signal processing pipelines for audio and video require saturation arithmetic to prevent harsh clipping artifacts caused by integer wrap around. When two large sample values are added, exceeding the maximum representable range must result in a clamped maximum value rather than rolling over to an inverted sign.
The module computes the sum of two signed, two's-complement integers. If the true mathematical sum exceeds the maximum positive value representable by the bit width, the output clamps to that maximum positive positive value. If the true sum falls below the minimum negative value, the output clamps to that minimum negative value. Otherwise, the output is the exact sum.
The module is purely combinational. There is no clock or reset. The output sum must reflect the saturated addition of inputs a and b at all times. Priority rules do not apply as all inputs are evaluated concurrently.
Worked Trace (WIDTH = 8): • Case 1: a = 8'h32 (50), b = 8'h14 (20) → sum = 8'h46 (70) • Case 2: a = 8'h64 (100), b = 8'h32 (50) → True sum is 150. Clamps to max positive. sum = 8'h7F (127) • Case 3: a = 8'h9C (-100), b = 8'hCE (-50) → True sum is -150. Clamps to min negative. sum = 8'h80 (-128)
| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | WIDTH | integer | 8 | Bit width of the operands and result |
| Signal | Direction | Width | Description | |--------|-----------|-------|-------------| | a | input | WIDTH | First signed operand | | b | input | WIDTH | Second signed operand | | sum | output | WIDTH | Saturated signed sum |
Constraints
- The design must be purely combinational.
- The design must strictly use the
WIDTHparameter to determine saturation boundaries. - Operands and output must be treated as signed two's-complement integers.
- Overflow occurs when two positive numbers yield a negative sum.
- Underflow occurs when two negative numbers yield a positive sum.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against a real testbench — you get the waveform back, not a stored answer.
This problem is part of Codiode Pro. The statement above is free to read.
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.