abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mpmTruth.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [mpmTruth.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Configurable technology mapper.]
8 
9  Synopsis [Truth table manipulation.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 1, 2013.]
16 
17  Revision [$Id: mpmTruth.c,v 1.00 2013/06/01 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "mpmInt.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 //#define MPM_TRY_NEW
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 /**Function*************************************************************
37 
38  Synopsis [Unifies variable order.]
39 
40  Description []
41 
42  SideEffects []
43 
44  SeeAlso []
45 
46 ***********************************************************************/
47 static inline void Mpm_TruthStretch( word * pTruth, Mpm_Cut_t * pCut, Mpm_Cut_t * pCut0, int nLimit )
48 {
49  int i, k;
50  for ( i = (int)pCut->nLeaves - 1, k = (int)pCut0->nLeaves - 1; i >= 0 && k >= 0; i-- )
51  {
52  if ( pCut0->pLeaves[k] < pCut->pLeaves[i] )
53  continue;
54  assert( pCut0->pLeaves[k] == pCut->pLeaves[i] );
55  if ( k < i )
56  Abc_TtSwapVars( pTruth, nLimit, k, i );
57  k--;
58  }
59 }
60 
61 /**Function*************************************************************
62 
63  Synopsis [Performs truth table support minimization.]
64 
65  Description []
66 
67  SideEffects []
68 
69  SeeAlso []
70 
71 ***********************************************************************/
72 static inline int Mpm_CutTruthMinimize6( Mpm_Man_t * p, Mpm_Cut_t * pCut )
73 {
74  unsigned uSupport;
75  int i, k, nSuppSize;
76  // compute the support of the cut's function
77  word t = *Mpm_CutTruth( p, Abc_Lit2Var(pCut->iFunc) );
78  uSupport = Abc_Tt6SupportAndSize( t, Mpm_CutLeafNum(pCut), &nSuppSize );
79  if ( nSuppSize == Mpm_CutLeafNum(pCut) )
80  return 0;
81  p->nSmallSupp += (int)(nSuppSize < 2);
82  // update leaves and signature
83  for ( i = k = 0; i < Mpm_CutLeafNum(pCut); i++ )
84  {
85  if ( ((uSupport >> i) & 1) )
86  {
87  if ( k < i )
88  {
89  pCut->pLeaves[k] = pCut->pLeaves[i];
90  Abc_TtSwapVars( &t, p->nLutSize, k, i );
91  }
92  k++;
93  }
94  }
95  assert( k == nSuppSize );
96  pCut->nLeaves = nSuppSize;
97  assert( nSuppSize == Abc_TtSupportSize(&t, 6) );
98  // save the result
99  pCut->iFunc = Abc_Var2Lit( Vec_MemHashInsert(p->vTtMem, &t), Abc_LitIsCompl(pCut->iFunc) );
100  return 1;
101 }
102 static inline int Mpm_CutTruthMinimize7( Mpm_Man_t * p, Mpm_Cut_t * pCut )
103 {
104  unsigned uSupport;
105  int i, k, nSuppSize;
106  // compute the support of the cut's function
107  word * pTruth = Mpm_CutTruth( p, Abc_Lit2Var(pCut->iFunc) );
108  uSupport = Abc_TtSupportAndSize( pTruth, Mpm_CutLeafNum(pCut), &nSuppSize );
109  if ( nSuppSize == Mpm_CutLeafNum(pCut) )
110  return 0;
111  p->nSmallSupp += (int)(nSuppSize < 2);
112  // update leaves and signature
113  Abc_TtCopy( p->Truth, pTruth, p->nTruWords, 0 );
114  for ( i = k = 0; i < Mpm_CutLeafNum(pCut); i++ )
115  {
116  if ( ((uSupport >> i) & 1) )
117  {
118  if ( k < i )
119  {
120  pCut->pLeaves[k] = pCut->pLeaves[i];
121  Abc_TtSwapVars( p->Truth, p->nLutSize, k, i );
122  }
123  k++;
124  }
125  }
126  assert( k == nSuppSize );
127  assert( nSuppSize == Abc_TtSupportSize(p->Truth, Mpm_CutLeafNum(pCut)) );
128  pCut->nLeaves = nSuppSize;
129  // save the result
131  return 1;
132 }
133 
134 /**Function*************************************************************
135 
136  Synopsis [Performs truth table computation.]
137 
138  Description []
139 
140  SideEffects []
141 
142  SeeAlso []
143 
144 ***********************************************************************/
145 static inline int Mpm_CutComputeTruth6( Mpm_Man_t * p, Mpm_Cut_t * pCut, Mpm_Cut_t * pCut0, Mpm_Cut_t * pCut1, Mpm_Cut_t * pCutC, int fCompl0, int fCompl1, int fComplC, int Type )
146 {
147  word * pTruth0 = Mpm_CutTruth( p, Abc_Lit2Var(pCut0->iFunc) );
148  word * pTruth1 = Mpm_CutTruth( p, Abc_Lit2Var(pCut1->iFunc) );
149  word * pTruthC = NULL;
150  word t0 = (fCompl0 ^ pCut0->fCompl ^ Abc_LitIsCompl(pCut0->iFunc)) ? ~*pTruth0 : *pTruth0;
151  word t1 = (fCompl1 ^ pCut1->fCompl ^ Abc_LitIsCompl(pCut1->iFunc)) ? ~*pTruth1 : *pTruth1;
152  word tC = 0, t = 0;
153  Mpm_TruthStretch( &t0, pCut, pCut0, p->nLutSize );
154  Mpm_TruthStretch( &t1, pCut, pCut1, p->nLutSize );
155  if ( pCutC )
156  {
157  pTruthC = Mpm_CutTruth( p, Abc_Lit2Var(pCutC->iFunc) );
158  tC = (fComplC ^ pCutC->fCompl ^ Abc_LitIsCompl(pCutC->iFunc)) ? ~*pTruthC : *pTruthC;
159  Mpm_TruthStretch( &tC, pCut, pCutC, p->nLutSize );
160  }
161  assert( p->nLutSize <= 6 );
162  if ( Type == 1 )
163  t = t0 & t1;
164  else if ( Type == 2 )
165  t = t0 ^ t1;
166  else if ( Type == 3 )
167  t = (tC & t1) | (~tC & t0);
168  else assert( 0 );
169  // save the result
170  if ( t & 1 )
171  {
172  t = ~t;
173  pCut->iFunc = Abc_Var2Lit( Vec_MemHashInsert( p->vTtMem, &t ), 1 );
174  }
175  else
176  pCut->iFunc = Abc_Var2Lit( Vec_MemHashInsert( p->vTtMem, &t ), 0 );
177  if ( p->pPars->fCutMin )
178  return Mpm_CutTruthMinimize6( p, pCut );
179  return 1;
180 }
181 static inline int Mpm_CutComputeTruth7( Mpm_Man_t * p, Mpm_Cut_t * pCut, Mpm_Cut_t * pCut0, Mpm_Cut_t * pCut1, Mpm_Cut_t * pCutC, int fCompl0, int fCompl1, int fComplC, int Type )
182 {
183  word * pTruth0 = Mpm_CutTruth( p, Abc_Lit2Var(pCut0->iFunc) );
184  word * pTruth1 = Mpm_CutTruth( p, Abc_Lit2Var(pCut1->iFunc) );
185  word * pTruthC = NULL;
186  Abc_TtCopy( p->Truth0, pTruth0, p->nTruWords, fCompl0 ^ pCut0->fCompl ^ Abc_LitIsCompl(pCut0->iFunc) );
187  Abc_TtCopy( p->Truth1, pTruth1, p->nTruWords, fCompl1 ^ pCut1->fCompl ^ Abc_LitIsCompl(pCut1->iFunc) );
188  Mpm_TruthStretch( p->Truth0, pCut, pCut0, p->nLutSize );
189  Mpm_TruthStretch( p->Truth1, pCut, pCut1, p->nLutSize );
190  if ( pCutC )
191  {
192  pTruthC = Mpm_CutTruth( p, Abc_Lit2Var(pCutC->iFunc) );
193  Abc_TtCopy( p->TruthC, pTruthC, p->nTruWords, fComplC ^ pCutC->fCompl ^ Abc_LitIsCompl(pCutC->iFunc) );
194  Mpm_TruthStretch( p->TruthC, pCut, pCutC, p->nLutSize );
195  }
196  if ( Type == 1 )
197  Abc_TtAnd( p->Truth, p->Truth0, p->Truth1, p->nTruWords, 0 );
198  else if ( Type == 2 )
199  Abc_TtXor( p->Truth, p->Truth0, p->Truth1, p->nTruWords, 0 );
200  else if ( Type == 3 )
201  Abc_TtMux( p->Truth, p->TruthC, p->Truth1, p->Truth0, p->nTruWords );
202  else assert( 0 );
203  // save the result
204  if ( p->Truth[0] & 1 )
205  {
206  Abc_TtNot( p->Truth, p->nTruWords );
207  pCut->iFunc = Abc_Var2Lit( Vec_MemHashInsert( p->vTtMem, p->Truth ), 1 );
208  }
209  else
210  pCut->iFunc = Abc_Var2Lit( Vec_MemHashInsert( p->vTtMem, p->Truth ), 0 );
211  if ( p->pPars->fCutMin )
212  return Mpm_CutTruthMinimize7( p, pCut );
213  return 1;
214 }
215 int Mpm_CutComputeTruth( Mpm_Man_t * p, Mpm_Cut_t * pCut, Mpm_Cut_t * pCut0, Mpm_Cut_t * pCut1, Mpm_Cut_t * pCutC, int fCompl0, int fCompl1, int fComplC, int Type )
216 {
217  int RetValue;
218  if ( p->nLutSize <= 6 )
219  RetValue = Mpm_CutComputeTruth6( p, pCut, pCut0, pCut1, pCutC, fCompl0, fCompl1, fComplC, Type );
220  else
221  RetValue = Mpm_CutComputeTruth7( p, pCut, pCut0, pCut1, pCutC, fCompl0, fCompl1, fComplC, Type );
222 #ifdef MPM_TRY_NEW
223  {
224  extern unsigned Abc_TtCanonicize( word * pTruth, int nVars, char * pCanonPerm );
225  char pCanonPerm[16];
226  memcpy( p->Truth0, p->Truth, sizeof(word) * p->nTruWords );
227  Abc_TtCanonicize( p->Truth0, pCut->nLimit, pCanonPerm );
228  }
229 #endif
230  return RetValue;
231 }
232 
233 ////////////////////////////////////////////////////////////////////////
234 /// END OF FILE ///
235 ////////////////////////////////////////////////////////////////////////
236 
237 
239 
Mpm_Par_t * pPars
Definition: mpmInt.h:98
int fCutMin
Definition: mpm.h:66
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Mpm_CutLeafNum(Mpm_Cut_t *pCut)
Definition: mpmInt.h:182
static int Mpm_CutComputeTruth7(Mpm_Man_t *p, Mpm_Cut_t *pCut, Mpm_Cut_t *pCut0, Mpm_Cut_t *pCut1, Mpm_Cut_t *pCutC, int fCompl0, int fCompl1, int fComplC, int Type)
Definition: mpmTruth.c:181
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
unsigned fCompl
Definition: mpmInt.h:66
char * memcpy()
Vec_Mem_t * vTtMem
Definition: mpmInt.h:124
int nSmallSupp
Definition: mpmInt.h:157
static ABC_NAMESPACE_IMPL_START void Mpm_TruthStretch(word *pTruth, Mpm_Cut_t *pCut, Mpm_Cut_t *pCut0, int nLimit)
DECLARATIONS ///.
Definition: mpmTruth.c:47
word Truth0[(1<< ((MPM_VAR_MAX)-6))]
Definition: mpmInt.h:127
int Mpm_CutComputeTruth(Mpm_Man_t *p, Mpm_Cut_t *pCut, Mpm_Cut_t *pCut0, Mpm_Cut_t *pCut1, Mpm_Cut_t *pCutC, int fCompl0, int fCompl1, int fComplC, int Type)
Definition: mpmTruth.c:215
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
static int Mpm_CutComputeTruth6(Mpm_Man_t *p, Mpm_Cut_t *pCut, Mpm_Cut_t *pCut0, Mpm_Cut_t *pCut1, Mpm_Cut_t *pCutC, int fCompl0, int fCompl1, int fComplC, int Type)
Definition: mpmTruth.c:145
static void Abc_TtCopy(word *pOut, word *pIn, int nWords, int fCompl)
Definition: utilTruth.h:221
int nTruWords
Definition: mpmInt.h:102
word TruthC[(1<< ((MPM_VAR_MAX)-6))]
Definition: mpmInt.h:129
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
word Truth[(1<< ((MPM_VAR_MAX)-6))]
Definition: mpmInt.h:130
static int Abc_TtSupportAndSize(word *t, int nVars, int *pSuppSize)
Definition: utilTruth.h:994
static word * Mpm_CutTruth(Mpm_Man_t *p, int iFunc)
Definition: mpmInt.h:183
static int Abc_Tt6SupportAndSize(word t, int nVars, int *pSuppSize)
Definition: utilTruth.h:1003
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Mpm_CutTruthMinimize7(Mpm_Man_t *p, Mpm_Cut_t *pCut)
Definition: mpmTruth.c:102
static void Abc_TtMux(word *pOut, word *pCtrl, word *pIn1, word *pIn0, int nWords)
Definition: utilTruth.h:263
word Truth1[(1<< ((MPM_VAR_MAX)-6))]
Definition: mpmInt.h:128
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
static int Abc_TtSupportSize(word *t, int nVars)
Definition: utilTruth.h:986
unsigned Abc_TtCanonicize(word *pTruth, int nVars, char *pCanonPerm)
FUNCTION DECLARATIONS ///.
Definition: dauCanon.c:895
static int Vec_MemHashInsert(Vec_Mem_t *p, word *pEntry)
Definition: vecMem.h:351
int pLeaves[1]
Definition: mpmInt.h:69
#define assert(ex)
Definition: util_old.h:213
unsigned nLeaves
Definition: mpmInt.h:68
static void Abc_TtSwapVars(word *pTruth, int nVars, int iVar, int jVar)
Definition: utilTruth.h:1228
static void Abc_TtAnd(word *pOut, word *pIn1, word *pIn2, int nWords, int fCompl)
Definition: utilTruth.h:231
int nLutSize
Definition: mpmInt.h:100
static int Mpm_CutTruthMinimize6(Mpm_Man_t *p, Mpm_Cut_t *pCut)
Definition: mpmTruth.c:72
unsigned iFunc
Definition: mpmInt.h:65
static void Abc_TtXor(word *pOut, word *pIn1, word *pIn2, int nWords, int fCompl)
Definition: utilTruth.h:253
static void Abc_TtNot(word *pOut, int nWords)
Definition: utilTruth.h:215