Saturation.v

This module implements combinational arithmetic saturation of a signed word. It has two modes: the first saturates to a bit width less that the input width; the second saturates to a maximum magnitude. The parameter mag determines which mode is instantiated: the first when zero, the second when nonzero.

Ports

clkinputThe clock input used with the registered="yes" option.
ininputThe input.
outoutput  The output.

Parameters

wIn16The bit width of the input port in.
wOut15The bit width of the output port out.
widwInThe bit width of the input. A synonym of wIn.
satwIn-wOut+1In the first mode, the number of bits of saturation. In this mode, the output has sat-1 bits less width than the input. It should be zero when the module is used in the second mode, where mag is nonzero. When the default is overridden, sat's value as per these rules take precedence over wOut.
mag0In the second mode, the value at which to saturate the output. The first mode is selected by mag = 0 and sat = 0 .
registered"no"To register the output, use "yes". A clock input must be provided.

Notes

Example instantiation in Verilog:

wire	[14:0]	sig;
wire	[11:0]	sig_sat;
Saturation #(.wid(15), .sat(4)) sat_inst (.in(sig), .out(sig_sat));
wire	[12:0]	sig;
wire	[12:0]	sig_sat;
Saturation
    #(.wid(13), .sat(0), .mag(1187))
    sat_inst (.in(sig), .out(sig_sat));