diff options
Diffstat (limited to 'src/misc/extra/extraUtilMacc.c')
-rw-r--r-- | src/misc/extra/extraUtilMacc.c | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/src/misc/extra/extraUtilMacc.c b/src/misc/extra/extraUtilMacc.c index 5a7a8164..67515aa7 100644 --- a/src/misc/extra/extraUtilMacc.c +++ b/src/misc/extra/extraUtilMacc.c @@ -49,6 +49,22 @@ ABC_NAMESPACE_IMPL_START SeeAlso [] ***********************************************************************/ +void Macc_ConstMultSpecOne2( FILE * pFile, int n, int nBits, int nWidth ) +{ + int nTotal = nWidth+nBits; + int Bound = 1 << (nBits-1); + assert( -Bound <= n && n < Bound ); + fprintf( pFile, "// %d-bit multiplier-accumulator with constant %d generated by ABC on %s\n", nTotal, n, Extra_TimeStamp() ); + fprintf( pFile, "module mulacc%03d%s (\n", Abc_AbsInt(n), n < 0 ? "_neg" : "_pos" ); + fprintf( pFile, " input [%d:0] i,\n", nTotal-1 ); + fprintf( pFile, " input [%d:0] s,\n", nTotal-1 ); + fprintf( pFile, " output [%d:0] o\n", nTotal-1 ); + fprintf( pFile, ");\n" ); + fprintf( pFile, " wire [%d:0] c = %d\'h%x;\n", nTotal-1, nTotal, Abc_AbsInt(n) ); + fprintf( pFile, " wire [%d:0] m = i * c;\n", nTotal-1 ); + fprintf( pFile, " assign o = s %c m;\n", n < 0 ? '-' : '+' ); + fprintf( pFile, "endmodule\n\n" ); +} void Macc_ConstMultSpecOne( FILE * pFile, int n, int nBits, int nWidth ) { int nTotal = nWidth+nBits; @@ -76,9 +92,9 @@ void Macc_ConstMultSpecTest() FILE * pFile; for ( i = -Bound; i < Bound; i++ ) { - sprintf( Buffer, "const_mul//spec%03d.v", 0xFF & i ); + sprintf( Buffer, "const_mul//macc_spec_%03d.v", 0xFF & i ); pFile = fopen( Buffer, "wb" ); - Macc_ConstMultSpecOne( pFile, i, nBits, nWidth ); + Macc_ConstMultSpecOne2( pFile, i, nBits, nWidth ); fclose( pFile ); } } @@ -272,6 +288,28 @@ void Macc_ConstMultGenMacc( FILE * pFile, unsigned * p, int n, int nBits, int nW } fprintf( pFile, "endmodule\n\n" ); } +void Macc_ConstMultGenMacc2( FILE * pFile, unsigned * p, int n, int nBits, int nWidth ) +{ + int nTotal = nWidth+nBits; + int Bound = 1 << (nBits-1); + char Sign = n < 0 ? 'N' : 'n'; + assert( -Bound <= n && n < Bound ); + fprintf( pFile, "// %d-bit multiplier-accumulator by constant %d generated by ABC on %s\n", nTotal, n, Extra_TimeStamp() ); + fprintf( pFile, "module macc%03d%s (\n", Abc_AbsInt(n), n < 0 ? "_neg" : "_pos" ); + fprintf( pFile, " input [%d:0] i,\n", nTotal-1 ); + fprintf( pFile, " input [%d:0] s,\n", nTotal-1 ); + fprintf( pFile, " output [%d:0] o\n", nTotal-1 ); + fprintf( pFile, ");\n" ); + if ( n == 0 ) + fprintf( pFile, " assign o = s;\n" ); + else + { + fprintf( pFile, " wire [%d:0] n1 = i;\n", nTotal-1 ); + Macc_ConstMultGenOne_rec( pFile, p, n, nBits, nWidth ); + fprintf( pFile, " assign o = s + %c%d;\n", Sign, Abc_AbsInt(n) ); + } + fprintf( pFile, "endmodule\n\n" ); +} void Macc_ConstMultGenTest() { int nBits = 8; @@ -285,7 +323,7 @@ void Macc_ConstMultGenTest() { sprintf( Buffer, "const_mul//macc%03d.v", 0xFF & i ); pFile = fopen( Buffer, "wb" ); - Macc_ConstMultGenMacc( pFile, p, i, nBits, nWidth ); + Macc_ConstMultGenMacc2( pFile, p, i, nBits, nWidth ); fclose( pFile ); } ABC_FREE( p ); |