ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
kitPla.c File Reference
#include "kit.h"
#include "aig/aig/aig.h"
Include dependency graph for kitPla.c:

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START int Kit_PlaIsConst0 (char *pSop)
 DECLARATIONS ///.
 
int Kit_PlaIsConst1 (char *pSop)
 
int Kit_PlaIsBuf (char *pSop)
 
int Kit_PlaIsInv (char *pSop)
 
int Kit_PlaGetVarNum (char *pSop)
 
int Kit_PlaGetCubeNum (char *pSop)
 
int Kit_PlaIsComplement (char *pSop)
 
void Kit_PlaComplement (char *pSop)
 
char * Kit_PlaStart (void *p, int nCubes, int nVars)
 
char * Kit_PlaCreateFromIsop (void *p, int nVars, Vec_Int_t *vCover)
 
void Kit_PlaToIsop (char *pSop, Vec_Int_t *vCover)
 
char * Kit_PlaStoreSop (void *p, char *pSop)
 
char * Kit_PlaFromTruth (void *p, unsigned *pTruth, int nVars, Vec_Int_t *vCover)
 
char * Kit_PlaFromIsop (Vec_Str_t *vStr, int nVars, Vec_Int_t *vCover)
 
char * Kit_PlaFromTruthNew (unsigned *pTruth, int nVars, Vec_Int_t *vCover, Vec_Str_t *vStr)
 
ABC_UINT64_T Kit_PlaToTruth6 (char *pSop, int nVars)
 
void Kit_PlaToTruth (char *pSop, int nVars, Vec_Ptr_t *vVars, unsigned *pTemp, unsigned *pTruth)
 

Function Documentation

◆ Kit_PlaComplement()

void Kit_PlaComplement ( char * pSop)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 181 of file kitPla.c.

182{
183 char * pCur;
184 for ( pCur = pSop; *pCur; pCur++ )
185 if ( *pCur == '\n' )
186 {
187 if ( *(pCur - 1) == '0' )
188 *(pCur - 1) = '1';
189 else if ( *(pCur - 1) == '1' )
190 *(pCur - 1) = '0';
191 else if ( *(pCur - 1) == 'x' )
192 *(pCur - 1) = 'n';
193 else if ( *(pCur - 1) == 'n' )
194 *(pCur - 1) = 'x';
195 else
196 assert( 0 );
197 }
198}
#define assert(ex)
Definition util_old.h:213
Here is the caller graph for this function:

◆ Kit_PlaCreateFromIsop()

char * Kit_PlaCreateFromIsop ( void * p,
int nVars,
Vec_Int_t * vCover )

Function*************************************************************

Synopsis [Creates the cover from the ISOP computed from TT.]

Description []

SideEffects []

SeeAlso []

Definition at line 243 of file kitPla.c.

244{
245 Aig_MmFlex_t * pMan = (Aig_MmFlex_t *)p;
246 char * pSop, * pCube;
247 int i, k, Entry, Literal;
248 assert( Vec_IntSize(vCover) > 0 );
249 if ( Vec_IntSize(vCover) == 0 )
250 return NULL;
251 // start the cover
252 pSop = Kit_PlaStart( pMan, Vec_IntSize(vCover), nVars );
253 // create cubes
254 Vec_IntForEachEntry( vCover, Entry, i )
255 {
256 pCube = pSop + i * (nVars + 3);
257 for ( k = 0; k < nVars; k++ )
258 {
259 Literal = 3 & (Entry >> (k << 1));
260 if ( Literal == 1 )
261 pCube[k] = '0';
262 else if ( Literal == 2 )
263 pCube[k] = '1';
264 else if ( Literal != 0 )
265 assert( 0 );
266 }
267 }
268 return pSop;
269}
struct Aig_MmFlex_t_ Aig_MmFlex_t
Definition aig.h:53
Cube * p
Definition exorList.c:222
char * Kit_PlaStart(void *p, int nCubes, int nVars)
Definition kitPla.c:211
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Kit_PlaFromIsop()

char * Kit_PlaFromIsop ( Vec_Str_t * vStr,
int nVars,
Vec_Int_t * vCover )

Function*************************************************************

Synopsis [Creates the cover from the ISOP computed from TT.]

Description []

SideEffects []

SeeAlso []

Definition at line 366 of file kitPla.c.

367{
368 int i, k, Entry, Literal;
369 assert( Vec_IntSize(vCover) > 0 );
370 if ( Vec_IntSize(vCover) == 0 )
371 return NULL;
372 Vec_StrClear( vStr );
373 Vec_IntForEachEntry( vCover, Entry, i )
374 {
375 for ( k = 0; k < nVars; k++ )
376 {
377 Literal = 3 & (Entry >> (k << 1));
378 if ( Literal == 1 )
379 Vec_StrPush( vStr, '0' );
380 else if ( Literal == 2 )
381 Vec_StrPush( vStr, '1' );
382 else if ( Literal == 0 )
383 Vec_StrPush( vStr, '-' );
384 else
385 assert( 0 );
386 }
387 Vec_StrPush( vStr, ' ' );
388 Vec_StrPush( vStr, '1' );
389 Vec_StrPush( vStr, '\n' );
390 }
391 Vec_StrPush( vStr, '\0' );
392 return Vec_StrArray( vStr );
393}
Here is the caller graph for this function:

◆ Kit_PlaFromTruth()

char * Kit_PlaFromTruth ( void * p,
unsigned * pTruth,
int nVars,
Vec_Int_t * vCover )

Function*************************************************************

Synopsis [Transforms truth table into the SOP.]

Description []

SideEffects []

SeeAlso []

Definition at line 337 of file kitPla.c.

338{
339 Aig_MmFlex_t * pMan = (Aig_MmFlex_t *)p;
340 char * pSop;
341 int RetValue;
342 if ( Kit_TruthIsConst0(pTruth, nVars) )
343 return Kit_PlaStoreSop( pMan, " 0\n" );
344 if ( Kit_TruthIsConst1(pTruth, nVars) )
345 return Kit_PlaStoreSop( pMan, " 1\n" );
346 RetValue = Kit_TruthIsop( pTruth, nVars, vCover, 0 ); // 1 );
347 assert( RetValue == 0 || RetValue == 1 );
348 pSop = Kit_PlaCreateFromIsop( pMan, nVars, vCover );
349 if ( RetValue )
350 Kit_PlaComplement( pSop );
351 return pSop;
352}
void Kit_PlaComplement(char *pSop)
Definition kitPla.c:181
char * Kit_PlaCreateFromIsop(void *p, int nVars, Vec_Int_t *vCover)
Definition kitPla.c:243
char * Kit_PlaStoreSop(void *p, char *pSop)
Definition kitPla.c:317
int Kit_TruthIsop(unsigned *puTruth, int nVars, Vec_Int_t *vMemory, int fTryBoth)
Definition kitIsop.c:134
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Kit_PlaFromTruthNew()

char * Kit_PlaFromTruthNew ( unsigned * pTruth,
int nVars,
Vec_Int_t * vCover,
Vec_Str_t * vStr )

Function*************************************************************

Synopsis [Creates the SOP from TT.]

Description []

SideEffects []

SeeAlso []

Definition at line 406 of file kitPla.c.

407{
408 char * pResult;
409 // transform truth table into the SOP
410 int RetValue = Kit_TruthIsop( pTruth, nVars, vCover, 1 );
411 assert( RetValue == 0 || RetValue == 1 );
412 // check the case of constant cover
413 if ( Vec_IntSize(vCover) == 0 || (Vec_IntSize(vCover) == 1 && Vec_IntEntry(vCover,0) == 0) )
414 {
415 assert( RetValue == 0 );
416 Vec_StrClear( vStr );
417 Vec_StrAppend( vStr, (Vec_IntSize(vCover) == 0) ? " 0\n" : " 1\n" );
418 Vec_StrPush( vStr, '\0' );
419 return Vec_StrArray( vStr );
420 }
421 pResult = Kit_PlaFromIsop( vStr, nVars, vCover );
422 if ( RetValue )
423 Kit_PlaComplement( pResult );
424 if ( nVars < 6 )
425 assert( pTruth[0] == (unsigned)Kit_PlaToTruth6(pResult, nVars) );
426 else if ( nVars == 6 )
427 assert( *((ABC_UINT64_T*)pTruth) == Kit_PlaToTruth6(pResult, nVars) );
428 return pResult;
429}
ABC_UINT64_T Kit_PlaToTruth6(char *pSop, int nVars)
Definition kitPla.c:442
char * Kit_PlaFromIsop(Vec_Str_t *vStr, int nVars, Vec_Int_t *vCover)
Definition kitPla.c:366
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Kit_PlaGetCubeNum()

int Kit_PlaGetCubeNum ( char * pSop)

Function*************************************************************

Synopsis [Reads the number of cubes in the cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 138 of file kitPla.c.

139{
140 char * pCur;
141 int nCubes = 0;
142 if ( pSop == NULL )
143 return 0;
144 for ( pCur = pSop; *pCur; pCur++ )
145 nCubes += (*pCur == '\n');
146 return nCubes;
147}
Here is the caller graph for this function:

◆ Kit_PlaGetVarNum()

int Kit_PlaGetVarNum ( char * pSop)

Function*************************************************************

Synopsis [Reads the number of variables in the cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 118 of file kitPla.c.

119{
120 char * pCur;
121 for ( pCur = pSop; *pCur != '\n'; pCur++ )
122 if ( *pCur == 0 )
123 return -1;
124 return pCur - pSop - 2;
125}
Here is the caller graph for this function:

◆ Kit_PlaIsBuf()

int Kit_PlaIsBuf ( char * pSop)

Function*************************************************************

Synopsis [Checks if the cover is a buffer.]

Description []

SideEffects []

SeeAlso []

Definition at line 78 of file kitPla.c.

79{
80 if ( pSop[4] != 0 )
81 return 0;
82 if ( (pSop[0] == '1' && pSop[2] == '1') || (pSop[0] == '0' && pSop[2] == '0') )
83 return 1;
84 return 0;
85}

◆ Kit_PlaIsComplement()

int Kit_PlaIsComplement ( char * pSop)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 160 of file kitPla.c.

161{
162 char * pCur;
163 for ( pCur = pSop; *pCur; pCur++ )
164 if ( *pCur == '\n' )
165 return (int)(*(pCur - 1) == '0' || *(pCur - 1) == 'n');
166 assert( 0 );
167 return 0;
168}
Here is the caller graph for this function:

◆ Kit_PlaIsConst0()

ABC_NAMESPACE_IMPL_START int Kit_PlaIsConst0 ( char * pSop)

DECLARATIONS ///.

CFile****************************************************************

FileName [kitPla.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Computation kit.]

Synopsis [Manipulating SOP in the form of a C-string.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - Dec 6, 2006.]

Revision [

Id
kitPla.c,v 1.00 2006/12/06 00:00:00 alanmi Exp

] FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Checks if the cover is constant 0.]

Description []

SideEffects []

SeeAlso []

Definition at line 46 of file kitPla.c.

47{
48 return pSop[0] == ' ' && pSop[1] == '0';
49}
Here is the caller graph for this function:

◆ Kit_PlaIsConst1()

int Kit_PlaIsConst1 ( char * pSop)

Function*************************************************************

Synopsis [Checks if the cover is constant 1.]

Description []

SideEffects []

SeeAlso []

Definition at line 62 of file kitPla.c.

63{
64 return pSop[0] == ' ' && pSop[1] == '1';
65}

◆ Kit_PlaIsInv()

int Kit_PlaIsInv ( char * pSop)

Function*************************************************************

Synopsis [Checks if the cover is an inverter.]

Description []

SideEffects []

SeeAlso []

Definition at line 98 of file kitPla.c.

99{
100 if ( pSop[4] != 0 )
101 return 0;
102 if ( (pSop[0] == '0' && pSop[2] == '1') || (pSop[0] == '1' && pSop[2] == '0') )
103 return 1;
104 return 0;
105}

◆ Kit_PlaStart()

char * Kit_PlaStart ( void * p,
int nCubes,
int nVars )

Function*************************************************************

Synopsis [Creates the constant 1 cover with the given number of variables and cubes.]

Description []

SideEffects []

SeeAlso []

Definition at line 211 of file kitPla.c.

212{
213 Aig_MmFlex_t * pMan = (Aig_MmFlex_t *)p;
214 char * pSopCover, * pCube;
215 int i, Length;
216
217 Length = nCubes * (nVars + 3);
218 pSopCover = Aig_MmFlexEntryFetch( pMan, Length + 1 );
219 memset( pSopCover, '-', (size_t)Length );
220 pSopCover[Length] = 0;
221
222 for ( i = 0; i < nCubes; i++ )
223 {
224 pCube = pSopCover + i * (nVars + 3);
225 pCube[nVars + 0] = ' ';
226 pCube[nVars + 1] = '1';
227 pCube[nVars + 2] = '\n';
228 }
229 return pSopCover;
230}
char * Aig_MmFlexEntryFetch(Aig_MmFlex_t *p, int nBytes)
Definition aigMem.c:366
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Kit_PlaStoreSop()

char * Kit_PlaStoreSop ( void * p,
char * pSop )

Function*************************************************************

Synopsis [Allocates memory and copies the SOP into it.]

Description []

SideEffects []

SeeAlso []

Definition at line 317 of file kitPla.c.

318{
319 Aig_MmFlex_t * pMan = (Aig_MmFlex_t *)p;
320 char * pStore;
321 pStore = Aig_MmFlexEntryFetch( pMan, strlen(pSop) + 1 );
322 strcpy( pStore, pSop );
323 return pStore;
324}
int strlen()
char * strcpy()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Kit_PlaToIsop()

void Kit_PlaToIsop ( char * pSop,
Vec_Int_t * vCover )

Function*************************************************************

Synopsis [Creates the cover from the ISOP computed from TT.]

Description []

SideEffects []

SeeAlso []

Definition at line 282 of file kitPla.c.

283{
284 char * pCube;
285 int k, nVars, Entry;
286 nVars = Kit_PlaGetVarNum( pSop );
287 assert( nVars > 0 );
288 // create cubes
289 Vec_IntClear( vCover );
290 for ( pCube = pSop; *pCube; pCube += nVars + 3 )
291 {
292 Entry = 0;
293 for ( k = nVars - 1; k >= 0; k-- )
294 if ( pCube[k] == '0' )
295 Entry = (Entry << 2) | 1;
296 else if ( pCube[k] == '1' )
297 Entry = (Entry << 2) | 2;
298 else if ( pCube[k] == '-' )
299 Entry = (Entry << 2);
300 else
301 assert( 0 );
302 Vec_IntPush( vCover, Entry );
303 }
304}
int Kit_PlaGetVarNum(char *pSop)
Definition kitPla.c:118
Here is the call graph for this function:

◆ Kit_PlaToTruth()

void Kit_PlaToTruth ( char * pSop,
int nVars,
Vec_Ptr_t * vVars,
unsigned * pTemp,
unsigned * pTruth )

Fnction*************************************************************

Synopsis [Converting SOP into a truth table.]

Description [The SOP is represented as a C-string, as documented in file "bblif.h". The truth table is returned as a bit-string composed of 2^nVars bits. For functions of less than 6 variables, the full machine word is returned. (The truth table looks as if the function had 5 variables.) The use of this procedure should be limited to Boolean functions with no more than 16 inputs.]

SideEffects []

SeeAlso []

Definition at line 496 of file kitPla.c.

497{
498 int v, c, nCubes, fCompl = 0;
499 assert( pSop != NULL );
500 assert( nVars >= 0 );
501 if ( strlen(pSop) % (nVars + 3) != 0 )
502 {
503 printf( "Kit_PlaToTruth(): SOP is represented incorrectly.\n" );
504 return;
505 }
506 // iterate through the cubes
507 Kit_TruthClear( pTruth, nVars );
508 nCubes = strlen(pSop) / (nVars + 3);
509 for ( c = 0; c < nCubes; c++ )
510 {
511 fCompl = (pSop[nVars+1] == '0');
512 Kit_TruthFill( pTemp, nVars );
513 // iterate through the literals of the cube
514 for ( v = 0; v < nVars; v++ )
515 if ( pSop[v] == '1' )
516 Kit_TruthAnd( pTemp, pTemp, (unsigned *)Vec_PtrEntry(vVars, v), nVars );
517 else if ( pSop[v] == '0' )
518 Kit_TruthSharp( pTemp, pTemp, (unsigned *)Vec_PtrEntry(vVars, v), nVars );
519 // add cube to storage
520 Kit_TruthOr( pTruth, pTruth, pTemp, nVars );
521 // go to the next cube
522 pSop += (nVars + 3);
523 }
524 if ( fCompl )
525 Kit_TruthNot( pTruth, pTruth, nVars );
526}
Here is the call graph for this function:

◆ Kit_PlaToTruth6()

ABC_UINT64_T Kit_PlaToTruth6 ( char * pSop,
int nVars )

Function*************************************************************

Synopsis [Converts SOP into a truth table.]

Description []

SideEffects []

SeeAlso []

Definition at line 442 of file kitPla.c.

443{
444 static ABC_UINT64_T Truth[8] = {
445 ABC_CONST(0xAAAAAAAAAAAAAAAA),
446 ABC_CONST(0xCCCCCCCCCCCCCCCC),
447 ABC_CONST(0xF0F0F0F0F0F0F0F0),
448 ABC_CONST(0xFF00FF00FF00FF00),
449 ABC_CONST(0xFFFF0000FFFF0000),
450 ABC_CONST(0xFFFFFFFF00000000),
451 ABC_CONST(0x0000000000000000),
452 ABC_CONST(0xFFFFFFFFFFFFFFFF)
453 };
454 ABC_UINT64_T valueAnd, valueOr = Truth[6];
455 int v, lit = 0;
456 assert( nVars < 7 );
457 do {
458 valueAnd = Truth[7];
459 for ( v = 0; v < nVars; v++, lit++ )
460 {
461 if ( pSop[lit] == '1' )
462 valueAnd &= Truth[v];
463 else if ( pSop[lit] == '0' )
464 valueAnd &= ~Truth[v];
465 else if ( pSop[lit] != '-' )
466 assert( 0 );
467 }
468 valueOr |= valueAnd;
469 assert( pSop[lit] == ' ' );
470 lit++;
471 lit++;
472 assert( pSop[lit] == '\n' );
473 lit++;
474 } while ( pSop[lit] );
475 if ( Kit_PlaIsComplement(pSop) )
476 valueOr = ~valueOr;
477 return valueOr;
478}
#define ABC_CONST(number)
PARAMETERS ///.
Definition abc_global.h:240
int Kit_PlaIsComplement(char *pSop)
Definition kitPla.c:160
int lit
Definition satVec.h:130
Here is the call graph for this function:
Here is the caller graph for this function: