vi_gamma_sqrt.v 13.9 KB
/**************************************************************************
 *                                                                        *
 *               Copyright (C) 1994, Silicon Graphics, Inc.               *
 *                                                                        *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright  law.  They  may not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *                                                                        *
 *************************************************************************/

// $Id: vi_gamma_sqrt.v,v 1.1 2002/03/28 00:26:14 berndt Exp $

////////////////////////////////////////////////////////////////////////
//
// Project Reality
//
// module:	vi_gamma_sqrt
// description:	Square root for gamma correction for video interface.
//
// designer:	Phil Gossett
// date:	10/6/94
//
////////////////////////////////////////////////////////////////////////

module vi_gamma_sqrt (a, q);

input [13:0] a;	// 8 bits linear signal + 6 bits dither

output [6:0] q;	// 7 bits gamma corrected (pre-compensated)

wire   [6:1] qn;
wire [12:11] ca;
wire [13:11] c0b;
wire [13:11] c1b;
wire [10: 9] cb;
wire [13: 9] c0c;
wire [13: 9] c1c;
wire [ 8: 7] cc;
wire [13: 7] c0d;
wire [13: 7] c1d;
wire [ 6: 5] cd;
wire [13: 5] c0e;
wire [13: 5] c1e;
wire [ 4: 3] ce;
wire [13: 3] c0f;
wire [13: 3] c1f;
wire [ 2: 1] cf;
wire         rx;
wire [13:11] ra;
wire [13:11] r0b;
wire [13:11] r1b;
wire [13: 9] rb;
wire [13: 9] r0c;
wire [13: 9] r1c;
wire [13: 7] rc;
wire [13: 7] r0d;
wire [13: 7] r1d;
wire [13: 5] rd;
wire [13: 5] r0e;
wire [13: 5] r1e;
wire [13: 3] re;

// 6
xn02d2  rx13  ( .a1( a[13]), .a2(  a[12]),               .zn( rx));
or02d2  cx13  (	.a1( a[13]), .a2(  a[12]),                .z(  q[ 6]));
in01d4  inx   (  .i( q[ 6]),                             .zn( qn[ 6]));

// 5
xn02d2  ra11  (	.a1( a[11]), .a2(  a[10]),               .zn( ra[11]));
nr02d2  ca11  (	.a1( a[11]), .a2(  a[10]),               .zn( ca[11]));
xo02d2  ra12  ( .a1( a[12]), .a2( ca[11]),                .z( ra[12]));
nr02d2  ca12  (	.a1( a[12]), .a2( ca[11]),               .zn( ca[12]));
ad01d1h ra13  (	 .a( q[ 6]),  .b( rx    ), .ci( ca[12]),  .s( ra[13]),
						         .co(  q[ 5]));
in01d4  ina   (  .i( q[ 5]),                             .zn( qn[ 5]));

// 4
xn02d2  rb9   (	.a1( a[ 9]), .a2(  a[ 8]),               .zn( rb[ 9]));
nr02d2  cb9   (	.a1( a[ 9]), .a2(  a[ 8]),               .zn( cb[ 9]));
xo02d2  rb10  ( .a1( a[10]),               .a2( cb[ 9]),  .z( rb[10]));
nr02d2  cb10  (	.a1( a[10]),               .a2( cb[ 9]), .zn( cb[10]));
ad01d1h r0b11 (	 .a( q[ 6]),  .b( ra[11]), .ci( cb[10]),  .s(r0b[11]),
						         .co(c0b[11]));
xo02d2  r0b12 (              .a1( ra[12]), .a2(c0b[11]),  .z(r0b[12]));
xo02d2  r0b13 (              .a1( ra[13]), .a2(c0b[12]),  .z(r0b[13]));
an02d2  c0b12 (              .a1( ra[12]), .a2(c0b[11]),  .z(c0b[12]));
an03d2  c0b13 (	.a1(ra[13]), .a2( ra[12]), .a3(c0b[11]),  .z(c0b[13]));
ad01d1h r1b11 (	 .a(qn[ 6]),  .b( ra[11]), .ci( cb[10]),  .s(r1b[11]),
						         .co(c1b[11]));
xn02d2  r1b12 (              .a1( ra[12]), .a2(c1b[11]), .zn(r1b[12]));
xn02d2  r1b13 (              .a1( ra[13]), .a2(c1b[12]), .zn(r1b[13]));
or02d2  c1b12 (              .a1( ra[12]), .a2(c1b[11]),  .z(c1b[12]));
or03d2  c1b13 ( .a1(ra[13]), .a2( ra[12]), .a3(c1b[11]),  .z(c1b[13]));
mx21d1h mxb11 (  .s(qn[ 5]), .i0(r1b[11]), .i1(r0b[11]),  .z( rb[11]));
mx21d1h mxb12 (  .s(qn[ 5]), .i0(r1b[12]), .i1(r0b[12]),  .z( rb[12]));
mx21d1h mxb13 (  .s(qn[ 5]), .i0(r1b[13]), .i1(r0b[13]),  .z( rb[13]));
mx21d1h mxb   (  .s(qn[ 5]), .i0(c1b[13]), .i1(c0b[13]),  .z(  q[ 4]));
in01d4  inb   (	 .i( q[ 4]),                             .zn( qn[ 4]));

// 3
xn02d2  rc7   (	.a1( a[ 7]), .a2(  a[ 6]),               .zn( rc[ 7]));
nr02d2  cc7   (	.a1( a[ 7]), .a2(  a[ 6]),               .zn( cc[ 7]));
xo02d2  rc8   ( .a1( a[ 8]),               .a2( cc[ 7]),  .z( rc[ 8]));
nr02d2  cc8   (	.a1( a[ 8]),               .a2( cc[ 7]), .zn( cc[ 8]));
ad01d1h r0c9  (	 .a( q[ 5]),  .b( rb[ 9]), .ci( cc[ 8]),  .s(r0c[ 9]),
						         .co(c0c[ 9]));
ad01d1h r0c10 (	 .a( q[ 6]),  .b( rb[10]), .ci(c0c[ 9]),  .s(r0c[10]),
						         .co(c0c[10]));
xo02d2  r0c11 (              .a1( rb[11]), .a2(c0c[10]),  .z(r0c[11]));
xo02d2  r0c12 (              .a1( rb[12]), .a2(c0c[11]),  .z(r0c[12]));
xo02d2  r0c13 (              .a1( rb[13]), .a2(c0c[12]),  .z(r0c[13]));
an02d2  c0c11 (                            .a1( rb[11]),
					   .a2(c0c[10]),  .z(c0c[11]));
an03d2  c0c12 (              .a1( rb[12]), .a2( rb[11]),
					   .a3(c0c[10]),  .z(c0c[12]));
an04d2  c0c13 ( .a1(rb[13]), .a2( rb[12]), .a3( rb[11]),
					   .a4(c0c[10]),  .z(c0c[13]));
ad01d1h r1c9  (	 .a(qn[ 5]),  .b( rb[ 9]), .ci( cc[ 8]),  .s(r1c[ 9]),
						         .co(c1c[ 9]));
ad01d1h r1c10 (	 .a(qn[ 6]),  .b( rb[10]), .ci(c1c[ 9]),  .s(r1c[10]),
						         .co(c1c[10]));
xn02d2  r1c11 (              .a1( rb[11]), .a2(c1c[10]), .zn(r1c[11]));
xn02d2  r1c12 (              .a1( rb[12]), .a2(c1c[11]), .zn(r1c[12]));
xn02d2  r1c13 (              .a1( rb[13]), .a2(c1c[12]), .zn(r1c[13]));
or02d2  c1c11 (                            .a1( rb[11]), 
					   .a2(c1c[10]),  .z(c1c[11]));
or03d2  c1c12 (              .a1( rb[12]), .a2( rb[11]),
					   .a3(c1c[10]),  .z(c1c[12]));
or04d2  c1c13 ( .a1(rb[13]), .a2( rb[12]), .a3( rb[11]),
					   .a4(c1c[10]),  .z(c1c[13]));
mx21d1h mxc9  (  .s(qn[ 4]), .i0(r1c[ 9]), .i1(r0c[ 9]),  .z( rc[ 9]));
mx21d1h mxc10 (  .s(qn[ 4]), .i0(r1c[10]), .i1(r0c[10]),  .z( rc[10]));
mx21d1h mxc11 (  .s(qn[ 4]), .i0(r1c[11]), .i1(r0c[11]),  .z( rc[11]));
mx21d1h mxc12 (  .s(qn[ 4]), .i0(r1c[12]), .i1(r0c[12]),  .z( rc[12]));
mx21d1h mxc13 (  .s(qn[ 4]), .i0(r1c[13]), .i1(r0c[13]),  .z( rc[13]));
mx21d1h mxc   (  .s(qn[ 4]), .i0(c1c[13]), .i1(c0c[13]),  .z(  q[ 3]));
in01d4  inc   (	 .i( q[ 3]),                             .zn( qn[ 3]));

// 2
xn02d2  rd5   (	.a1( a[ 5]), .a2(  a[ 4]),               .zn( rd[ 5]));
nr02d2  cd5   (	.a1( a[ 5]), .a2(  a[ 4]),               .zn( cd[ 5]));
xo02d2  rd6   ( .a1( a[ 6]),               .a2( cd[ 5]),  .z( rd[ 6]));
nr02d2  cd6   (	.a1( a[ 6]),               .a2( cd[ 5]), .zn( cd[ 6]));
ad01d1h r0d7  (	 .a( q[ 4]),  .b( rc[ 7]), .ci( cd[ 6]),  .s(r0d[ 7]),
						         .co(c0d[ 7]));
ad01d1h r0d8  (	 .a( q[ 5]),  .b( rc[ 8]), .ci(c0d[ 7]),  .s(r0d[ 8]),
						         .co(c0d[ 8]));
ad01d1h r0d9  (	 .a( q[ 6]),  .b( rc[ 9]), .ci(c0d[ 8]),  .s(r0d[ 9]),
						         .co(c0d[ 9]));
xo02d2  r0d10 (              .a1( rc[10]), .a2(c0d[ 9]),  .z(r0d[10]));
xo02d2  r0d11 (              .a1( rc[11]), .a2(c0d[10]),  .z(r0d[11]));
xo02d2  r0d12 (              .a1( rc[12]), .a2(c0d[11]),  .z(r0d[12]));
xo02d2  r0d13 (              .a1( rc[13]), .a2(c0d[12]),  .z(r0d[13]));
an02d2  c0d10 (                                          .a1( rc[10]),
					   .a2(c0d[ 9]),  .z(c0d[10]));
an03d2  c0d11 (                            .a1( rc[11]), .a2( rc[10]),
					   .a3(c0d[ 9]),  .z(c0d[11]));
an04d2  c0d12 (              .a1( rc[12]), .a2( rc[11]), .a3( rc[10]),
					   .a4(c0d[ 9]),  .z(c0d[12]));
an05d2  c0d13 ( .a1(rc[13]), .a2( rc[12]), .a3( rc[11]), .a4( rc[10]),
					   .a5(c0d[ 9]),  .z(c0d[13]));
ad01d1h r1d7  (	 .a(qn[ 4]),  .b( rc[ 7]), .ci( cd[ 6]),  .s(r1d[ 7]),
						         .co(c1d[ 7]));
ad01d1h r1d8  (	 .a(qn[ 5]),  .b( rc[ 8]), .ci(c1d[ 7]),  .s(r1d[ 8]),
						         .co(c1d[ 8]));
ad01d1h r1d9  (	 .a(qn[ 6]),  .b( rc[ 9]), .ci(c1d[ 8]),  .s(r1d[ 9]),
						         .co(c1d[ 9]));
xn02d2  r1d10 (              .a1( rc[10]), .a2(c1d[ 9]), .zn(r1d[10]));
xn02d2  r1d11 (              .a1( rc[11]), .a2(c1d[10]), .zn(r1d[11]));
xn02d2  r1d12 (              .a1( rc[12]), .a2(c1d[11]), .zn(r1d[12]));
xn02d2  r1d13 (              .a1( rc[13]), .a2(c1d[12]), .zn(r1d[13]));
or02d2  c1d10 (                                          .a1( rc[10]),
					   .a2(c1d[ 9]),  .z(c1d[10]));
or03d2  c1d11 (                            .a1( rc[11]), .a2( rc[10]),
					   .a3(c1d[ 9]),  .z(c1d[11]));
or04d2  c1d12 (              .a1( rc[12]), .a2( rc[11]), .a3( rc[10]),
					   .a4(c1d[ 9]),  .z(c1d[12]));
or05d2  c1d13 ( .a1(rc[13]), .a2( rc[12]), .a3( rc[11]), .a4( rc[10]),
					   .a5(c1d[ 9]),  .z(c1d[13]));
mx21d1h mxd7  (	 .s(qn[ 3]), .i0(r1d[ 7]), .i1(r0d[ 7]),  .z( rd[ 7]));
mx21d1h mxd8  (	 .s(qn[ 3]), .i0(r1d[ 8]), .i1(r0d[ 8]),  .z( rd[ 8]));
mx21d1h mxd9  (	 .s(qn[ 3]), .i0(r1d[ 9]), .i1(r0d[ 9]),  .z( rd[ 9]));
mx21d1h mxd10 (	 .s(qn[ 3]), .i0(r1d[10]), .i1(r0d[10]),  .z( rd[10]));
mx21d1h mxd11 (	 .s(qn[ 3]), .i0(r1d[11]), .i1(r0d[11]),  .z( rd[11]));
mx21d1h mxd12 (	 .s(qn[ 3]), .i0(r1d[12]), .i1(r0d[12]),  .z( rd[12]));
mx21d1h mxd13 (	 .s(qn[ 3]), .i0(r1d[13]), .i1(r0d[13]),  .z( rd[13]));
mx21d1h mxd   (	 .s(qn[ 3]), .i0(c1d[13]), .i1(c0d[13]),  .z(  q[ 2]));
in01d4  ind   (	 .i( q[ 2]),                             .zn( qn[ 2]));

// 1
xn02d2  re3   (	.a1( a[ 3]), .a2(  a[ 2]),               .zn( re[ 3]));
nr02d2  ce3   (	.a1( a[ 3]), .a2(  a[ 2]),               .zn( ce[ 3]));
xo02d2  re4   ( .a1( a[ 4]),               .a2( ce[ 3]),  .z( re[ 4]));
nr02d2  ce4   (	.a1( a[ 4]),               .a2( ce[ 3]), .zn( ce[ 4]));
ad01d1h r0e5  (	 .a( q[ 3]),  .b( rd[ 5]), .ci( ce[ 4]),  .s(r0e[ 5]),
						         .co(c0e[ 5]));
ad01d1h r0e6  (	 .a( q[ 4]),  .b( rd[ 6]), .ci(c0e[ 5]),  .s(r0e[ 6]),
						         .co(c0e[ 6]));
ad01d1h r0e7  (	 .a( q[ 5]),  .b( rd[ 7]), .ci(c0e[ 6]),  .s(r0e[ 7]),
						         .co(c0e[ 7]));
ad01d1h r0e8  (	 .a( q[ 6]),  .b( rd[ 8]), .ci(c0e[ 7]),  .s(r0e[ 8]),
						         .co(c0e[ 8]));
xo02d2  r0e9  (              .a1( rd[ 9]), .a2(c0e[ 8]),  .z(r0e[ 9]));
xo02d2  r0e10 (              .a1( rd[10]), .a2(c0e[ 9]),  .z(r0e[10]));
xo02d2  r0e11 (              .a1( rd[11]), .a2(c0e[10]),  .z(r0e[11]));
xo02d2  r0e12 (              .a1( rd[12]), .a2(c0e[11]),  .z(r0e[12]));
xo02d2  r0e13 (              .a1( rd[13]), .a2(c0e[12]),  .z(r0e[13]));
an02d2  c0e9  ( .a1(rd[ 9]),		   .a2(c0e[ 8]),  .z(c0e[ 9]));
an03d2  c0e10 (                                          .a1( rd[10]),
		.a2(rd[ 9]),		   .a3(c0e[ 8]),  .z(c0e[10]));
an04d2  c0e11 (                            .a1( rd[11]), .a2( rd[10]),
		.a3(rd[ 9]),		   .a4(c0e[ 8]),  .z(c0e[11]));
an05d2  c0e12 (              .a1( rd[12]), .a2( rd[11]), .a3( rd[10]),
		.a4(rd[ 9]),		   .a5(c0e[ 8]),  .z(c0e[12]));
an06d2  c0e13 ( .a1(rd[13]), .a2( rd[12]), .a3( rd[11]), .a4( rd[10]),
		.a5(rd[ 9]),		   .a6(c0e[ 8]),  .z(c0e[13]));
ad01d1h r1e5  (	 .a(qn[ 3]),  .b( rd[ 5]), .ci( ce[ 4]),  .s(r1e[ 5]),
						         .co(c1e[ 5]));
ad01d1h r1e6  (	 .a(qn[ 4]),  .b( rd[ 6]), .ci(c1e[ 5]),  .s(r1e[ 6]),
						         .co(c1e[ 6]));
ad01d1h r1e7  (	 .a(qn[ 5]),  .b( rd[ 7]), .ci(c1e[ 6]),  .s(r1e[ 7]),
						         .co(c1e[ 7]));
ad01d1h r1e8  (	 .a(qn[ 6]),  .b( rd[ 8]), .ci(c1e[ 7]),  .s(r1e[ 8]),
						         .co(c1e[ 8]));
xn02d2  r1e9  (              .a1( rd[ 9]), .a2(c1e[ 8]), .zn(r1e[ 9]));
xn02d2  r1e10 (              .a1( rd[10]), .a2(c1e[ 9]), .zn(r1e[10]));
xn02d2  r1e11 (              .a1( rd[11]), .a2(c1e[10]), .zn(r1e[11]));
xn02d2  r1e12 (              .a1( rd[12]), .a2(c1e[11]), .zn(r1e[12]));
xn02d2  r1e13 (              .a1( rd[13]), .a2(c1e[12]), .zn(r1e[13]));
or02d2  c1e9  ( .a1(rd[ 9]), 		   .a2(c1e[ 8]),  .z(c1e[ 9]));
or03d2  c1e10 (                                          .a1( rd[10]), 
		.a2(rd[ 9]), 		   .a3(c1e[ 8]),  .z(c1e[10]));
or04d2  c1e11 (                            .a1( rd[11]), .a2( rd[10]), 
		.a3(rd[ 9]), 		   .a4(c1e[ 8]),  .z(c1e[11]));
or05d2  c1e12 (              .a1( rd[12]), .a2( rd[11]), .a3( rd[10]), 
		.a4(rd[ 9]), 		   .a5(c1e[ 8]),  .z(c1e[12]));
or06d2  c1e13 ( .a1(rd[13]), .a2( rd[12]), .a3( rd[11]), .a4( rd[10]), 
		.a5(rd[ 9]), 		   .a6(c1e[ 8]),  .z(c1e[13]));
mx21d1h mxe5  (	 .s(qn[ 2]), .i0(r1e[ 5]), .i1(r0e[ 5]),  .z( re[ 5]));
mx21d1h mxe6  (	 .s(qn[ 2]), .i0(r1e[ 6]), .i1(r0e[ 6]),  .z( re[ 6]));
mx21d1h mxe7  (	 .s(qn[ 2]), .i0(r1e[ 7]), .i1(r0e[ 7]),  .z( re[ 7]));
mx21d1h mxe8  (	 .s(qn[ 2]), .i0(r1e[ 8]), .i1(r0e[ 8]),  .z( re[ 8]));
mx21d1h mxe9  (	 .s(qn[ 2]), .i0(r1e[ 9]), .i1(r0e[ 9]),  .z( re[ 9]));
mx21d1h mxe10 (	 .s(qn[ 2]), .i0(r1e[10]), .i1(r0e[10]),  .z( re[10]));
mx21d1h mxe11 (	 .s(qn[ 2]), .i0(r1e[11]), .i1(r0e[11]),  .z( re[11]));
mx21d1h mxe12 (	 .s(qn[ 2]), .i0(r1e[12]), .i1(r0e[12]),  .z( re[12]));
mx21d1h mxe13 (	 .s(qn[ 2]), .i0(r1e[13]), .i1(r0e[13]),  .z( re[13]));
mx21d1h mxe   (	 .s(qn[ 2]), .i0(c1e[13]), .i1(c0e[13]),  .z(  q[ 1]));
in01d4  ine   (	 .i( q[ 1]),                             .zn( qn[ 1]));

// 0
nr02d2  cf1   (	.a1( a[ 1]), .a2(  a[ 0]),               .zn( cf[ 1]));
nr02d2  cf2   (	.a1( a[ 2]),               .a2( cf[ 1]), .zn( cf[ 2]));
ad01d1h c0f3  (	 .a( q[ 2]),  .b( re[ 3]), .ci( cf[ 2]), .co(c0f[ 3]));
ad01d1h c0f4  (	 .a( q[ 3]),  .b( re[ 4]), .ci(c0f[ 3]), .co(c0f[ 4]));
ad01d1h c0f5  (	 .a( q[ 4]),  .b( re[ 5]), .ci(c0f[ 4]), .co(c0f[ 5]));
ad01d1h c0f6  (	 .a( q[ 5]),  .b( re[ 6]), .ci(c0f[ 5]), .co(c0f[ 6]));
ad01d1h c0f7  (	 .a( q[ 6]),  .b( re[ 7]), .ci(c0f[ 6]), .co(c0f[ 7]));
an07d2  c0f13 ( .a1(re[13]), .a2( re[12]), .a3( re[11]), .a4( re[10]),
		.a5(re[ 9]), .a6( re[ 8]), .a7(c0f[ 7]),  .z(c0f[13]));
ad01d1h c1f3  (	 .a(qn[ 2]),  .b( re[ 3]), .ci( cf[ 2]), .co(c1f[ 3]));
ad01d1h c1f4  (	 .a(qn[ 3]),  .b( re[ 4]), .ci(c1f[ 3]), .co(c1f[ 4]));
ad01d1h c1f5  (	 .a(qn[ 4]),  .b( re[ 5]), .ci(c1f[ 4]), .co(c1f[ 5]));
ad01d1h c1f6  (	 .a(qn[ 5]),  .b( re[ 6]), .ci(c1f[ 5]), .co(c1f[ 6]));
ad01d1h c1f7  (	 .a(qn[ 6]),  .b( re[ 7]), .ci(c1f[ 6]), .co(c1f[ 7]));
or07d2  c1f13 ( .a1(re[13]), .a2( re[12]), .a3( re[11]), .a4( re[10]),
		.a5(re[ 9]), .a6( re[ 8]), .a7(c1f[ 7]),  .z(c1f[13]));
mx21d1h mxf   (	 .s(qn[ 1]), .i0(c1f[13]), .i1(c0f[13]),  .z(  q[ 0]));
assign c0f[12:8] = 0;
assign c1f[12:8] = 0;

endmodule // vi_gamma_sqrt