summaryrefslogtreecommitdiffstats
path: root/src/misc/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc/util')
-rw-r--r--src/misc/util/abc_global.h32
-rw-r--r--src/misc/util/utilSort.c35
-rw-r--r--src/misc/util/utilTruth.h146
3 files changed, 189 insertions, 24 deletions
diff --git a/src/misc/util/abc_global.h b/src/misc/util/abc_global.h
index aac1515b..d7c5bea7 100644
--- a/src/misc/util/abc_global.h
+++ b/src/misc/util/abc_global.h
@@ -480,30 +480,6 @@ static inline int Abc_PrimeCudd( unsigned int p )
} // end of Cudd_Prime
-// Creates a sequence of random numbers.
-// http://www.codeproject.com/KB/recipes/SimpleRNG.aspx
-
-#define NUMBER1 3716960521u
-#define NUMBER2 2174103536u
-
-static inline unsigned Abc_Random( int fReset )
-{
- static unsigned int m_z = NUMBER1;
- static unsigned int m_w = NUMBER2;
- if ( fReset )
- {
- m_z = NUMBER1;
- m_w = NUMBER2;
- }
- m_z = 36969 * (m_z & 65535) + (m_z >> 16);
- m_w = 18000 * (m_w & 65535) + (m_w >> 16);
- return (m_z << 16) + m_w;
-}
-static inline word Abc_RandomW( int fReset )
-{
- return ((word)Abc_Random(fReset) << 32) | ((word)Abc_Random(fReset) << 0);
-}
-
// the returned buffer has 32 unused bytes at the end, filled with zeros
static inline void * Abc_FileReadContents( char * pFileName, int * pnFileSize )
{
@@ -526,6 +502,12 @@ static inline void * Abc_FileReadContents( char * pFileName, int * pnFileSize )
fclose( pFile );
return (void *)pBuffer;
}
+static inline void Abc_ReverseOrder( int * pA, int nA )
+{
+ int i;
+ for ( i = 0; i < nA/2; i++ )
+ ABC_SWAP( int, pA[i], pA[nA-1-i] );
+}
// sorting
@@ -537,6 +519,8 @@ extern void Abc_QuickSort3( word * pData, int nSize, int fDecrease );
extern void Abc_QuickSortCostData( int * pCosts, int nSize, int fDecrease, word * pData, int * pResult );
extern int * Abc_QuickSortCost( int * pCosts, int nSize, int fDecrease );
+extern unsigned Abc_Random( int fReset );
+extern word Abc_RandomW( int fReset );
ABC_NAMESPACE_HEADER_END
diff --git a/src/misc/util/utilSort.c b/src/misc/util/utilSort.c
index 32154a7d..31890503 100644
--- a/src/misc/util/utilSort.c
+++ b/src/misc/util/utilSort.c
@@ -779,6 +779,41 @@ void Abc_QuickSortTest()
ABC_FREE( pData2 );
}
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+
+// Creates a sequence of random numbers.
+// http://www.codeproject.com/KB/recipes/SimpleRNG.aspx
+
+#define NUMBER1 3716960521u
+#define NUMBER2 2174103536u
+
+unsigned Abc_Random( int fReset )
+{
+ static unsigned int m_z = NUMBER1;
+ static unsigned int m_w = NUMBER2;
+ if ( fReset )
+ {
+ m_z = NUMBER1;
+ m_w = NUMBER2;
+ }
+ m_z = 36969 * (m_z & 65535) + (m_z >> 16);
+ m_w = 18000 * (m_w & 65535) + (m_w >> 16);
+ return (m_z << 16) + m_w;
+}
+word Abc_RandomW( int fReset )
+{
+ return ((word)Abc_Random(fReset) << 32) | ((word)Abc_Random(fReset) << 0);
+}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
diff --git a/src/misc/util/utilTruth.h b/src/misc/util/utilTruth.h
index 6fa5e0a3..e0ee1720 100644
--- a/src/misc/util/utilTruth.h
+++ b/src/misc/util/utilTruth.h
@@ -326,6 +326,16 @@ static inline void Abc_TtXor( word * pOut, word * pIn1, word * pIn2, int nWords,
for ( w = 0; w < nWords; w++ )
pOut[w] = pIn1[w] ^ pIn2[w];
}
+static inline void Abc_TtXorMask( word * pOut, word * pIn1, word * pIn2, word * pMask, int nWords, int fCompl )
+{
+ int w;
+ if ( fCompl )
+ for ( w = 0; w < nWords; w++ )
+ pOut[w] = (pIn1[w] ^ pIn2[w]) & ~pMask[w];
+ else
+ for ( w = 0; w < nWords; w++ )
+ pOut[w] = (pIn1[w] ^ pIn2[w]) & pMask[w];
+}
static inline void Abc_TtMux( word * pOut, word * pCtrl, word * pIn1, word * pIn0, int nWords )
{
int w;
@@ -443,6 +453,108 @@ static inline void Abc_TtIthVar( word * pOut, int iVar, int nVars )
/**Function*************************************************************
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline int Abc_TtIsAndCompl( word * pOut, int fCompl, word * pIn1, int fCompl1, word * pIn2, int fCompl2, word * pCare, int nWords )
+{
+ int w;
+ if ( fCompl )
+ {
+ if ( fCompl1 )
+ {
+ if ( fCompl2 )
+ {
+ for ( w = 0; w < nWords; w++ )
+ if ( (~pOut[w] & pCare[w]) != (~pIn1[w] & ~pIn2[w] & pCare[w]) )
+ return 0;
+ }
+ else
+ {
+ for ( w = 0; w < nWords; w++ )
+ if ( (~pOut[w] & pCare[w]) != (~pIn1[w] & pIn2[w] & pCare[w]) )
+ return 0;
+ }
+ }
+ else
+ {
+ if ( fCompl2 )
+ {
+ for ( w = 0; w < nWords; w++ )
+ if ( (~pOut[w] & pCare[w]) != (pIn1[w] & ~pIn2[w] & pCare[w]) )
+ return 0;
+ }
+ else
+ {
+ for ( w = 0; w < nWords; w++ )
+ if ( (~pOut[w] & pCare[w]) != (pIn1[w] & pIn2[w] & pCare[w]) )
+ return 0;
+ }
+ }
+ }
+ else
+ {
+ if ( fCompl1 )
+ {
+ if ( fCompl2 )
+ {
+ for ( w = 0; w < nWords; w++ )
+ if ( (pOut[w] & pCare[w]) != (~pIn1[w] & ~pIn2[w] & pCare[w]) )
+ return 0;
+ }
+ else
+ {
+ for ( w = 0; w < nWords; w++ )
+ if ( (pOut[w] & pCare[w]) != (~pIn1[w] & pIn2[w] & pCare[w]) )
+ return 0;
+ }
+ }
+ else
+ {
+ if ( fCompl2 )
+ {
+ for ( w = 0; w < nWords; w++ )
+ if ( (pOut[w] & pCare[w]) != (pIn1[w] & ~pIn2[w] & pCare[w]) )
+ return 0;
+ }
+ else
+ {
+ for ( w = 0; w < nWords; w++ )
+ if ( (pOut[w] & pCare[w]) != (pIn1[w] & pIn2[w] & pCare[w]) )
+ return 0;
+ }
+ }
+ }
+ return 1;
+}
+
+static inline int Abc_TtIsXorCompl( word * pOut, int fCompl, word * pIn1, word * pIn2, word * pCare, int nWords )
+{
+ int w;
+ if ( fCompl )
+ {
+ for ( w = 0; w < nWords; w++ )
+ if ( (~pOut[w] & pCare[w]) != ((pIn1[w] ^ pIn2[w]) & pCare[w]) )
+ return 0;
+ }
+ else
+ {
+ for ( w = 0; w < nWords; w++ )
+ if ( ( pOut[w] & pCare[w]) != ((pIn1[w] ^ pIn2[w]) & pCare[w]) )
+ return 0;
+ }
+ return 1;
+}
+
+
+/**Function*************************************************************
+
Synopsis [Compares Cof0 and Cof1.]
Description []
@@ -1733,6 +1845,40 @@ static inline int Abc_TtCountOnesVecMask( word * x, word * pMask, int nWords, in
Count += Abc_TtCountOnes( pMask[w] & x[w] );
return Count;
}
+static inline int Abc_TtCountOnesVecMask2( word * x0, word * x1, int fComp0, int fComp1, word * pMask, int nWords )
+{
+ int w, Count = 0;
+ if ( !fComp0 && !fComp1 )
+ for ( w = 0; w < nWords; w++ )
+ Count += Abc_TtCountOnes( pMask[w] & x0[w] & x1[w] );
+ else if ( fComp0 && !fComp1 )
+ for ( w = 0; w < nWords; w++ )
+ Count += Abc_TtCountOnes( pMask[w] & ~x0[w] & x1[w] );
+ else if ( !fComp0 && fComp1 )
+ for ( w = 0; w < nWords; w++ )
+ Count += Abc_TtCountOnes( pMask[w] & x0[w] & ~x1[w] );
+ else
+ for ( w = 0; w < nWords; w++ )
+ Count += Abc_TtCountOnes( pMask[w] & ~x0[w] & ~x1[w] );
+ return Count;
+}
+static inline int Abc_TtCountOnesVecXor( word * x, word * y, int nWords )
+{
+ int w, Count = 0;
+ for ( w = 0; w < nWords; w++ )
+ Count += Abc_TtCountOnes( x[w] ^ y[w] );
+ return Count;
+}
+static inline int Abc_TtAndXorSum( word * pOut, word * pIn1, word * pIn2, int nWords )
+{
+ int w, Count = 0;
+ for ( w = 0; w < nWords; w++ )
+ {
+ pOut[w] &= pIn1[w] ^ pIn2[w];
+ Count += Abc_TtCountOnes( pOut[w] );
+ }
+ return Count;
+}
/**Function*************************************************************