ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
sfmCnf.c
Go to the documentation of this file.
1
20
21#include "sfmInt.h"
22#include "bool/kit/kit.h"
23
25
26
30
34
46void Sfm_PrintCnf( Vec_Str_t * vCnf )
47{
48 signed char Entry;
49 int i, Lit;
50 Vec_StrForEachEntry( vCnf, Entry, i )
51 {
52 Lit = (int)Entry;
53 if ( Lit == -1 )
54 printf( "\n" );
55 else
56 printf( "%s%d ", Abc_LitIsCompl(Lit) ? "-":"", Abc_Lit2Var(Lit) );
57 }
58}
59
71int Sfm_TruthToCnf( word Truth, word * pTruth, int nVars, Vec_Int_t * vCover, Vec_Str_t * vCnf )
72{
73 int w, nWords = Abc_Truth6WordNum( nVars );
74 Vec_StrClear( vCnf );
75 if ( nVars <= 6 )
76 {
77 if ( Truth == 0 || ~Truth == 0 )
78 {
79 assert( nVars == 0 );
80 Vec_StrPush( vCnf, (char)(Truth == 0) );
81 Vec_StrPush( vCnf, (char)-1 );
82 return 1;
83 }
84 }
85 else
86 {
87 // const0
88 for ( w = 0; w < nWords; w++ )
89 if ( pTruth[w] )
90 break;
91 if ( w == nWords )
92 {
93 Vec_StrPush( vCnf, (char)1 );
94 Vec_StrPush( vCnf, (char)-1 );
95 assert( 0 );
96 return 1;
97 }
98 // const1
99 for ( w = 0; w < nWords; w++ )
100 if ( ~pTruth[w] )
101 break;
102 if ( w == nWords )
103 {
104 Vec_StrPush( vCnf, (char)0 );
105 Vec_StrPush( vCnf, (char)-1 );
106 assert( 0 );
107 return 1;
108 }
109 }
110 {
111 int i, k, c, RetValue, Literal, Cube, nCubes = 0;
112 assert( nVars > 0 );
113
114 Abc_TtFlipVar5( &Truth, nVars );
115 Abc_TtFlipVar5( pTruth, nVars );
116 for ( c = 0; c < 2; c ++ )
117 {
118 if ( nVars <= 6 )
119 {
120 Truth = c ? ~Truth : Truth;
121 RetValue = Kit_TruthIsop( (unsigned *)&Truth, nVars, vCover, 0 );
122 }
123 else
124 {
125 if ( c )
126 for ( k = 0; k < nWords; k++ )
127 pTruth[k] = ~pTruth[k];
128 RetValue = Kit_TruthIsop( (unsigned *)pTruth, nVars, vCover, 0 );
129 if ( c )
130 for ( k = 0; k < nWords; k++ )
131 pTruth[k] = ~pTruth[k];
132 }
133 assert( RetValue == 0 );
134 nCubes += Vec_IntSize( vCover );
135 Vec_IntForEachEntry( vCover, Cube, i )
136 {
137 for ( k = 0; k < nVars; k++ )
138 {
139 Literal = 3 & (Cube >> (k << 1));
140 if ( Literal == 1 ) // '0' -> pos lit
141 Vec_StrPush( vCnf, (char)Abc_Var2Lit(k, 0) );
142 else if ( Literal == 2 ) // '1' -> neg lit
143 Vec_StrPush( vCnf, (char)Abc_Var2Lit(k, 1) );
144 else if ( Literal != 0 )
145 assert( 0 );
146 }
147 Vec_StrPush( vCnf, (char)Abc_Var2Lit(nVars, c) );
148 Vec_StrPush( vCnf, (char)-1 );
149 }
150 }
151 Abc_TtFlipVar5( pTruth, nVars );
152
153 return nCubes;
154 }
155}
156
169{
170 Vec_Wec_t * vCnfs;
171 Vec_Str_t * vCnf, * vCnfBase;
172 word uTruth;
173 int i, nCubes;
174 vCnf = Vec_StrAlloc( 100 );
175 vCnfs = Vec_WecStart( p->nObjs );
176 Vec_WrdForEachEntryStartStop( p->vTruths, uTruth, i, p->nPis, Vec_WrdSize(p->vTruths)-p->nPos )
177 {
178 int Offset = Vec_IntEntry( p->vStarts, i );
179 word * pRes = Vec_WrdSize(p->vTruths2) ? Vec_WrdEntryP( p->vTruths2, Offset ) : NULL;
180 nCubes = Sfm_TruthToCnf( uTruth, pRes, Sfm_ObjFaninNum(p, i), p->vCover, vCnf );
181 vCnfBase = (Vec_Str_t *)Vec_WecEntry( vCnfs, i );
182 Vec_StrGrow( vCnfBase, Vec_StrSize(vCnf) );
183 memcpy( Vec_StrArray(vCnfBase), Vec_StrArray(vCnf), (size_t)Vec_StrSize(vCnf) );
184 vCnfBase->nSize = Vec_StrSize(vCnf);
185 }
186 Vec_StrFree( vCnf );
187 return vCnfs;
188}
189
201void Sfm_TranslateCnf( Vec_Wec_t * vRes, Vec_Str_t * vCnf, Vec_Int_t * vFaninMap, int iPivotVar )
202{
203 Vec_Int_t * vClause;
204 signed char Entry;
205 int i, Lit;
206 assert( Vec_StrEntry(vCnf, 1) != -1 || Vec_IntSize(vFaninMap) == 1 );
207 Vec_WecClear( vRes );
208 vClause = Vec_WecPushLevel( vRes );
209 Vec_StrForEachEntry( vCnf, Entry, i )
210 {
211 if ( (int)Entry == -1 )
212 {
213 vClause = Vec_WecPushLevel( vRes );
214 continue;
215 }
216 Lit = Abc_Lit2LitV( Vec_IntArray(vFaninMap), (int)Entry );
217 Lit = Abc_LitNotCond( Lit, Abc_Lit2Var(Lit) == iPivotVar );
218 Vec_IntPush( vClause, Lit );
219 }
220}
221
225
226
228
int nWords
Definition abcNpn.c:127
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
Cube * p
Definition exorList.c:222
struct cube Cube
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
int Kit_TruthIsop(unsigned *puTruth, int nVars, Vec_Int_t *vMemory, int fTryBoth)
Definition kitIsop.c:134
int Sfm_TruthToCnf(word Truth, word *pTruth, int nVars, Vec_Int_t *vCover, Vec_Str_t *vCnf)
Definition sfmCnf.c:71
void Sfm_TranslateCnf(Vec_Wec_t *vRes, Vec_Str_t *vCnf, Vec_Int_t *vFaninMap, int iPivotVar)
Definition sfmCnf.c:201
ABC_NAMESPACE_IMPL_START void Sfm_PrintCnf(Vec_Str_t *vCnf)
DECLARATIONS ///.
Definition sfmCnf.c:46
Vec_Wec_t * Sfm_CreateCnf(Sfm_Ntk_t *p)
Definition sfmCnf.c:168
typedefABC_NAMESPACE_HEADER_START struct Sfm_Ntk_t_ Sfm_Ntk_t
INCLUDES ///.
Definition sfm.h:41
int nSize
Definition bblif.c:50
#define assert(ex)
Definition util_old.h:213
char * memcpy()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_StrForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecStr.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition vecWec.h:42
#define Vec_WrdForEachEntryStartStop(vVec, Entry, i, Start, Stop)
Definition vecWrd.h:60