ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
mpmTruth.c
Go to the documentation of this file.
1
20
21#include "mpmInt.h"
22
24
25
29
30//#define MPM_TRY_NEW
31
35
47static 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
72static 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}
102static 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
130 pCut->iFunc = Abc_Var2Lit( Vec_MemHashInsert(p->vTtMem, p->Truth), Abc_LitIsCompl(pCut->iFunc) );
131 return 1;
132}
133
145static 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}
181static 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}
215int 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
236
237
239
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
unsigned Abc_TtCanonicize(word *pTruth, int nVars, char *pCanonPerm)
FUNCTION DECLARATIONS ///.
Definition dauCanon.c:1036
Cube * p
Definition exorList.c:222
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
struct Mpm_Man_t_ Mpm_Man_t
Definition mpmInt.h:94
struct Mpm_Cut_t_ Mpm_Cut_t
BASIC TYPES ///.
Definition mpmInt.h:61
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
unsigned fCompl
Definition mpmInt.h:66
unsigned nLeaves
Definition mpmInt.h:68
int pLeaves[1]
Definition mpmInt.h:69
unsigned iFunc
Definition mpmInt.h:65
#define assert(ex)
Definition util_old.h:213
char * memcpy()