From 5e09cca9640f9a51c42a5364c8d0d4d57cc38d37 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Sat, 9 Aug 2025 14:46:45 -0700 Subject: [PATCH] Handing the case of signed comparators. --- src/aig/gia/giaGen.c | 13 ++++++++++--- src/base/abci/abc.c | 18 +++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/aig/gia/giaGen.c b/src/aig/gia/giaGen.c index 088b64191..c22cb21f8 100644 --- a/src/aig/gia/giaGen.c +++ b/src/aig/gia/giaGen.c @@ -1192,9 +1192,9 @@ Gia_Man_t * Gia_ManGenNeuron( char * pFileName, int nIBits, int nLutSize, int fD SeeAlso [] ***********************************************************************/ -Gia_Man_t * Gia_ManDupGenComp( int nBits, int fInterleave ) +Gia_Man_t * Gia_ManDupGenComp( int nBits, int fInterleave, int fSigned ) { - Gia_Man_t * pNew, * pTemp; int i, iLit = 1; + Gia_Man_t * pNew, * pTemp; int i, iLit = 1, iLitXor = 0, iLitB = 0; Vec_Int_t * vBitsA = Vec_IntAlloc( nBits + 1 ); Vec_Int_t * vBitsB = Vec_IntAlloc( nBits + 1 ); pNew = Gia_ManStart( 6*nBits+10 ); @@ -1211,6 +1211,10 @@ Gia_Man_t * Gia_ManDupGenComp( int nBits, int fInterleave ) for ( i = 0; i < nBits; i++ ) Vec_IntPush( vBitsB, Gia_ManAppendCi(pNew) ); } + if ( fSigned ) { + iLitXor = Gia_ManHashXor( pNew, Vec_IntPop(vBitsA), (iLitB = Vec_IntPop(vBitsB)) ); + nBits--; + } Vec_IntPush( vBitsA, 0 ); Vec_IntPush( vBitsB, 0 ); for ( i = 0; i < nBits; i++ ) { @@ -1227,7 +1231,10 @@ Gia_Man_t * Gia_ManDupGenComp( int nBits, int fInterleave ) int iOrLit = Gia_ManHashOr(pNew, iOrLit0, iOrLit1 ); iLit = Gia_ManHashOr(pNew, Abc_LitNot(iLit), iOrLit ); } - Gia_ManAppendCo( pNew, Abc_LitNotCond(iLit, nBits&1) ); + iLit = Abc_LitNotCond(iLit, nBits&1); + if ( fSigned ) + iLit = Gia_ManHashMux(pNew, iLitXor, iLitB, iLit ); + Gia_ManAppendCo( pNew, iLit ); pNew = Gia_ManCleanup( pTemp = pNew ); Gia_ManStop( pTemp ); Vec_IntFree( vBitsA ); diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index d9b688b9b..8f17275bf 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -56446,11 +56446,11 @@ usage: ***********************************************************************/ int Abc_CommandAbc9GenComp( Abc_Frame_t * pAbc, int argc, char ** argv ) { - extern Gia_Man_t * Gia_ManDupGenComp( int nBits, int fInterleave ); + extern Gia_Man_t * Gia_ManDupGenComp( int nBits, int fInterleave, int fSigned ); Gia_Man_t * pTemp = NULL; - int c, nBits = 0, fInter = 0, fVerbose = 0; + int c, nBits = 4, fInter = 0, fSigned = 0, fVerbose = 0; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "Kivh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "Kisvh" ) ) != EOF ) { switch ( c ) { @@ -56468,6 +56468,9 @@ int Abc_CommandAbc9GenComp( Abc_Frame_t * pAbc, int argc, char ** argv ) case 'i': fInter ^= 1; break; + case 's': + fSigned ^= 1; + break; case 'v': fVerbose ^= 1; break; @@ -56482,17 +56485,18 @@ int Abc_CommandAbc9GenComp( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_Print( -1, "Abc_CommandAbc9GenComp(): The number of inputs should be defined on the command line \"-K num\".\n" ); return 0; } - pTemp = Gia_ManDupGenComp( nBits, fInter ); + pTemp = Gia_ManDupGenComp( nBits, fInter, fSigned ); Abc_FrameUpdateGia( pAbc, pTemp ); if ( fVerbose ) Abc_Print( 1, "Generated %d-bit comparator.\n", nBits ); return 0; usage: - Abc_Print( -2, "usage: &gencomp [-K ] [-ivh]\n" ); - Abc_Print( -2, "\t generates the comparator\n" ); - Abc_Print( -2, "\t-K num : the number of control inputs [default = undefined]\n" ); + Abc_Print( -2, "usage: &gencomp [-K ] [-isvh]\n" ); + Abc_Print( -2, "\t generates the comparator (a > b)\n" ); + Abc_Print( -2, "\t-K num : the bitwidth of the inputs [default = %d]\n", nBits ); Abc_Print( -2, "\t-i : toggles using interleaved variable ordering [default = %s]\n", fInter ? "yes": "no" ); + Abc_Print( -2, "\t-s : toggles generating signed comparator [default = %s]\n", fSigned ? "yes": "no" ); Abc_Print( -2, "\t-v : toggles printing verbose information [default = %s]\n", fVerbose ? "yes": "no" ); Abc_Print( -2, "\t-h : print the command usage\n"); return 1;