/*
 Signal saturator with parameterized input/output width and saturation MSB
 
 Copyright (c) 2008 Dimtel, Inc., All Rights Reserved

 $Id: sat.v,v 1.2 2009/08/29 19:54:11 dim Exp $
 $Date: 2009/08/29 19:54:11 $
 $Author: dim $
 $Revision: 1.2 $
 $Log: sat.v,v $
 Revision 1.2  2009/08/29 19:54:11  dim
 Added timescale

 Revision 1.1.1.1  2009/02/05 07:20:51  dim
 Initial import


*/

`timescale 1ns/100ps

// Saturation control module
module sat #(parameter imsb=22, parameter omsb=11, parameter owidth=12) (
  input [imsb:0] ins,
  output [owidth-1:0] out,
  output sat
);
  localparam sat_ones={(imsb-omsb+1){1'b1}};

  assign sat = (ins[imsb:omsb] != sat_ones) & 
               (ins[imsb:omsb] != 0);

  assign out = (sat) ? {ins[imsb], {(owidth-1){~ins[imsb]}}} : 
                       ins[omsb:omsb-owidth+1];

endmodule // sat
