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

Go to the source code of this file.

Classes

struct  Ivy_Dec_t_
 

Typedefs

typedef struct Ivy_Dec_t_ Ivy_Dec_t
 

Enumerations

enum  Ivy_DecType_t {
  IVY_DEC_PI , IVY_DEC_CONST1 , IVY_DEC_BUF , IVY_DEC_AND ,
  IVY_DEC_EXOR , IVY_DEC_MUX , IVY_DEC_MAJ , IVY_DEC_PRIME
}
 DECLARATIONS ///. More...
 

Functions

int Ivy_TruthDsd (unsigned uTruth, Vec_Int_t *vTree)
 FUNCTION DEFINITIONS ///.
 
unsigned Ivy_TruthDsdCompute_rec (int iNode, Vec_Int_t *vTree)
 
unsigned Ivy_TruthDsdCompute (Vec_Int_t *vTree)
 
void Ivy_TruthDsdPrint_rec (FILE *pFile, int iNode, Vec_Int_t *vTree)
 
void Ivy_TruthDsdPrint (FILE *pFile, Vec_Int_t *vTree)
 
Ivy_Obj_tIvy_ManDsdConstruct_rec (Ivy_Man_t *p, Vec_Int_t *vFront, int iNode, Vec_Int_t *vTree)
 
Ivy_Obj_tIvy_ManDsdConstruct (Ivy_Man_t *p, Vec_Int_t *vFront, Vec_Int_t *vTree)
 
void Ivy_TruthDsdComputePrint (unsigned uTruth)
 
void Ivy_TruthTestOne (unsigned uTruth)
 

Typedef Documentation

◆ Ivy_Dec_t

typedef struct Ivy_Dec_t_ Ivy_Dec_t

Definition at line 42 of file ivyDsd.c.

Enumeration Type Documentation

◆ Ivy_DecType_t

DECLARATIONS ///.

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

FileName [ivyDsd.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [And-Inverter Graph package.]

Synopsis [Disjoint-support decomposition.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - May 11, 2006.]

Revision [

Id
ivyDsd.c,v 1.00 2006/05/11 00:00:00 alanmi Exp

]

Enumerator
IVY_DEC_PI 
IVY_DEC_CONST1 
IVY_DEC_BUF 
IVY_DEC_AND 
IVY_DEC_EXOR 
IVY_DEC_MUX 
IVY_DEC_MAJ 
IVY_DEC_PRIME 

Definition at line 31 of file ivyDsd.c.

31 {
32 IVY_DEC_PI, // 0: var
33 IVY_DEC_CONST1, // 1: CONST1
34 IVY_DEC_BUF, // 2: BUF
35 IVY_DEC_AND, // 3: AND
36 IVY_DEC_EXOR, // 4: EXOR
37 IVY_DEC_MUX, // 5: MUX
38 IVY_DEC_MAJ, // 6: MAJ
39 IVY_DEC_PRIME // 7: undecomposable
Ivy_DecType_t
DECLARATIONS ///.
Definition ivyDsd.c:31
@ IVY_DEC_BUF
Definition ivyDsd.c:34
@ IVY_DEC_EXOR
Definition ivyDsd.c:36
@ IVY_DEC_CONST1
Definition ivyDsd.c:33
@ IVY_DEC_PRIME
Definition ivyDsd.c:39
@ IVY_DEC_MAJ
Definition ivyDsd.c:38
@ IVY_DEC_AND
Definition ivyDsd.c:35
@ IVY_DEC_PI
Definition ivyDsd.c:32
@ IVY_DEC_MUX
Definition ivyDsd.c:37

Function Documentation

◆ Ivy_ManDsdConstruct()

Ivy_Obj_t * Ivy_ManDsdConstruct ( Ivy_Man_t * p,
Vec_Int_t * vFront,
Vec_Int_t * vTree )

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

Synopsis [Implement DSD in the AIG.]

Description []

SideEffects []

SeeAlso []

Definition at line 655 of file ivyDsd.c.

656{
657 int Entry, i;
658 // implement latches on the frontier (TEMPORARY!!!)
659 Vec_IntForEachEntry( vFront, Entry, i )
660 Vec_IntWriteEntry( vFront, i, Ivy_LeafId(Entry) );
661 // recursively construct the tree
662 return Ivy_ManDsdConstruct_rec( p, vFront, Vec_IntSize(vTree)-1, vTree );
663}
Cube * p
Definition exorList.c:222
Ivy_Obj_t * Ivy_ManDsdConstruct_rec(Ivy_Man_t *p, Vec_Int_t *vFront, int iNode, Vec_Int_t *vTree)
Definition ivyDsd.c:586
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
Here is the call graph for this function:

◆ Ivy_ManDsdConstruct_rec()

Ivy_Obj_t * Ivy_ManDsdConstruct_rec ( Ivy_Man_t * p,
Vec_Int_t * vFront,
int iNode,
Vec_Int_t * vTree )

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

Synopsis [Implement DSD in the AIG.]

Description []

SideEffects []

SeeAlso []

Definition at line 586 of file ivyDsd.c.

587{
588 Ivy_Obj_t * pResult, * pChild, * pNodes[16];
589 int Var, i;
590 // get the node
591 Ivy_Dec_t Node = Ivy_IntToDec( Vec_IntEntry(vTree, iNode) );
592 // compute the node function
593 if ( Node.Type == IVY_DEC_CONST1 )
594 return Ivy_NotCond( Ivy_ManConst1(p), Node.fCompl );
595 if ( Node.Type == IVY_DEC_PI )
596 {
597 pResult = Ivy_ManObj( p, Vec_IntEntry(vFront, iNode) );
598 return Ivy_NotCond( pResult, Node.fCompl );
599 }
600 if ( Node.Type == IVY_DEC_BUF )
601 {
602 pResult = Ivy_ManDsdConstruct_rec( p, vFront, Node.Fan0 >> 1, vTree );
603 return Ivy_NotCond( pResult, Node.fCompl );
604 }
605 if ( Node.Type == IVY_DEC_AND || Node.Type == IVY_DEC_EXOR )
606 {
607 for ( i = 0; i < (int)Node.nFans; i++ )
608 {
609 Var = Ivy_DecGetVar( &Node, i );
610 assert( Node.Type == IVY_DEC_AND || (Var & 1) == 0 );
611 pChild = Ivy_ManDsdConstruct_rec( p, vFront, Var >> 1, vTree );
612 pChild = Ivy_NotCond( pChild, (Var & 1) );
613 pNodes[i] = pChild;
614 }
615
616// Ivy_MultiEval( pNodes, Node.nFans, Node.Type == IVY_DEC_AND ? IVY_AND : IVY_EXOR );
617
618 pResult = Ivy_Multi( p, pNodes, Node.nFans, Node.Type == IVY_DEC_AND ? IVY_AND : IVY_EXOR );
619 return Ivy_NotCond( pResult, Node.fCompl );
620 }
621 assert( Node.fCompl == 0 );
622 if ( Node.Type == IVY_DEC_MUX || Node.Type == IVY_DEC_MAJ )
623 {
624 int VarC, Var1, Var0;
625 VarC = Ivy_DecGetVar( &Node, 0 );
626 Var1 = Ivy_DecGetVar( &Node, 1 );
627 Var0 = Ivy_DecGetVar( &Node, 2 );
628 pNodes[0] = Ivy_ManDsdConstruct_rec( p, vFront, VarC >> 1, vTree );
629 pNodes[1] = Ivy_ManDsdConstruct_rec( p, vFront, Var1 >> 1, vTree );
630 pNodes[2] = Ivy_ManDsdConstruct_rec( p, vFront, Var0 >> 1, vTree );
631 assert( Node.Type == IVY_DEC_MAJ || (VarC & 1) == 0 );
632 pNodes[0] = Ivy_NotCond( pNodes[0], (VarC & 1) );
633 pNodes[1] = Ivy_NotCond( pNodes[1], (Var1 & 1) );
634 pNodes[2] = Ivy_NotCond( pNodes[2], (Var0 & 1) );
635 if ( Node.Type == IVY_DEC_MUX )
636 return Ivy_Mux( p, pNodes[0], pNodes[1], pNodes[2] );
637 else
638 return Ivy_Maj( p, pNodes[0], pNodes[1], pNodes[2] );
639 }
640 assert( 0 );
641 return 0;
642}
int Var
Definition exorList.c:228
struct Ivy_Dec_t_ Ivy_Dec_t
Definition ivyDsd.c:42
Ivy_Obj_t * Ivy_Multi(Ivy_Man_t *p, Ivy_Obj_t **pArgs, int nArgs, Ivy_Type_t Type)
Definition ivyOper.c:246
Ivy_Obj_t * Ivy_Mux(Ivy_Man_t *p, Ivy_Obj_t *pC, Ivy_Obj_t *p1, Ivy_Obj_t *p0)
Definition ivyOper.c:158
Ivy_Obj_t * Ivy_Maj(Ivy_Man_t *p, Ivy_Obj_t *pA, Ivy_Obj_t *pB, Ivy_Obj_t *pC)
Definition ivyOper.c:209
struct Ivy_Obj_t_ Ivy_Obj_t
Definition ivy.h:47
@ IVY_AND
Definition ivy.h:58
@ IVY_EXOR
Definition ivy.h:59
unsigned Type
Definition ivyDsd.c:45
unsigned Fan0
Definition ivyDsd.c:48
unsigned fCompl
Definition ivyDsd.c:46
unsigned nFans
Definition ivyDsd.c:47
#define assert(ex)
Definition util_old.h:213
@ Var1
Definition xsatSolver.h:56
@ Var0
Definition xsatSolver.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ivy_TruthDsd()

int Ivy_TruthDsd ( unsigned uTruth,
Vec_Int_t * vTree )

FUNCTION DEFINITIONS ///.

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

Synopsis [Computes DSD of truth table of 5 variables or less.]

Description [Returns 1 if the function is a constant or is fully DSD decomposable using AND/EXOR/MUX gates.]

SideEffects []

SeeAlso []

Definition at line 166 of file ivyDsd.c.

167{
168 Ivy_Dec_t Node;
169 int i, RetValue;
170 // set the PI variables
171 Vec_IntClear( vTree );
172 for ( i = 0; i < 5; i++ )
173 Vec_IntPush( vTree, 0 );
174 // check if it is a constant
175 if ( uTruth == 0 || ~uTruth == 0 )
176 {
177 Ivy_DecClear( &Node );
178 Node.Type = IVY_DEC_CONST1;
179 Node.fCompl = (uTruth == 0);
180 Vec_IntPush( vTree, Ivy_DecToInt(Node) );
181 return 1;
182 }
183 // perform the decomposition
184 RetValue = Ivy_TruthDecompose_rec( uTruth, vTree );
185 if ( RetValue == -1 )
186 return 0;
187 // get the topmost node
188 if ( (RetValue >> 1) < 5 )
189 { // add buffer
190 Ivy_DecClear( &Node );
191 Node.Type = IVY_DEC_BUF;
192 Node.fCompl = (RetValue & 1);
193 Node.Fan0 = ((RetValue >> 1) << 1);
194 Vec_IntPush( vTree, Ivy_DecToInt(Node) );
195 }
196 else if ( RetValue & 1 )
197 { // check if the topmost node has to be complemented
198 Node = Ivy_IntToDec( Vec_IntPop(vTree) );
199 assert( Node.fCompl == 0 );
200 Node.fCompl = (RetValue & 1);
201 Vec_IntPush( vTree, Ivy_DecToInt(Node) );
202 }
203 if ( uTruth != Ivy_TruthDsdCompute(vTree) )
204 printf( "Verification failed.\n" );
205 return 1;
206}
unsigned Ivy_TruthDsdCompute(Vec_Int_t *vTree)
Definition ivyDsd.c:478
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ivy_TruthDsdCompute()

unsigned Ivy_TruthDsdCompute ( Vec_Int_t * vTree)

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

Synopsis [Computes truth table of decomposition tree for verification.]

Description []

SideEffects []

SeeAlso []

Definition at line 478 of file ivyDsd.c.

479{
480 return Ivy_TruthDsdCompute_rec( Vec_IntSize(vTree)-1, vTree );
481}
unsigned Ivy_TruthDsdCompute_rec(int iNode, Vec_Int_t *vTree)
Definition ivyDsd.c:404
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ivy_TruthDsdCompute_rec()

unsigned Ivy_TruthDsdCompute_rec ( int iNode,
Vec_Int_t * vTree )

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

Synopsis [Computes truth table of decomposition tree for verification.]

Description []

SideEffects []

SeeAlso []

Definition at line 404 of file ivyDsd.c.

405{
406 unsigned uTruthChild, uTruthTotal;
407 int Var, i;
408 // get the node
409 Ivy_Dec_t Node = Ivy_IntToDec( Vec_IntEntry(vTree, iNode) );
410 // compute the node function
411 if ( Node.Type == IVY_DEC_CONST1 )
412 return s_Masks[5][ !Node.fCompl ];
413 if ( Node.Type == IVY_DEC_PI )
414 return s_Masks[iNode][ !Node.fCompl ];
415 if ( Node.Type == IVY_DEC_BUF )
416 {
417 uTruthTotal = Ivy_TruthDsdCompute_rec( Node.Fan0 >> 1, vTree );
418 return Node.fCompl? ~uTruthTotal : uTruthTotal;
419 }
420 if ( Node.Type == IVY_DEC_AND )
421 {
422 uTruthTotal = s_Masks[5][1];
423 for ( i = 0; i < (int)Node.nFans; i++ )
424 {
425 Var = Ivy_DecGetVar( &Node, i );
426 uTruthChild = Ivy_TruthDsdCompute_rec( Var >> 1, vTree );
427 uTruthTotal = (Var & 1)? uTruthTotal & ~uTruthChild : uTruthTotal & uTruthChild;
428 }
429 return Node.fCompl? ~uTruthTotal : uTruthTotal;
430 }
431 if ( Node.Type == IVY_DEC_EXOR )
432 {
433 uTruthTotal = 0;
434 for ( i = 0; i < (int)Node.nFans; i++ )
435 {
436 Var = Ivy_DecGetVar( &Node, i );
437 uTruthTotal ^= Ivy_TruthDsdCompute_rec( Var >> 1, vTree );
438 assert( (Var & 1) == 0 );
439 }
440 return Node.fCompl? ~uTruthTotal : uTruthTotal;
441 }
442 assert( Node.fCompl == 0 );
443 if ( Node.Type == IVY_DEC_MUX || Node.Type == IVY_DEC_MAJ )
444 {
445 unsigned uTruthChildC, uTruthChild1, uTruthChild0;
446 int VarC, Var1, Var0;
447 VarC = Ivy_DecGetVar( &Node, 0 );
448 Var1 = Ivy_DecGetVar( &Node, 1 );
449 Var0 = Ivy_DecGetVar( &Node, 2 );
450 uTruthChildC = Ivy_TruthDsdCompute_rec( VarC >> 1, vTree );
451 uTruthChild1 = Ivy_TruthDsdCompute_rec( Var1 >> 1, vTree );
452 uTruthChild0 = Ivy_TruthDsdCompute_rec( Var0 >> 1, vTree );
453 assert( Node.Type == IVY_DEC_MAJ || (VarC & 1) == 0 );
454 uTruthChildC = (VarC & 1)? ~uTruthChildC : uTruthChildC;
455 uTruthChild1 = (Var1 & 1)? ~uTruthChild1 : uTruthChild1;
456 uTruthChild0 = (Var0 & 1)? ~uTruthChild0 : uTruthChild0;
457 if ( Node.Type == IVY_DEC_MUX )
458 return (uTruthChildC & uTruthChild1) | (~uTruthChildC & uTruthChild0);
459 else
460 return (uTruthChildC & uTruthChild1) | (uTruthChildC & uTruthChild0) | (uTruthChild1 & uTruthChild0);
461 }
462 assert( 0 );
463 return 0;
464}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ivy_TruthDsdComputePrint()

void Ivy_TruthDsdComputePrint ( unsigned uTruth)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 678 of file ivyDsd.c.

679{
680 static Vec_Int_t * vTree = NULL;
681 if ( vTree == NULL )
682 vTree = Vec_IntAlloc( 12 );
683 if ( Ivy_TruthDsd( uTruth, vTree ) )
684 Ivy_TruthDsdPrint( stdout, vTree );
685 else
686 printf( "Undecomposable\n" );
687}
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
void Ivy_TruthDsdPrint(FILE *pFile, Vec_Int_t *vTree)
Definition ivyDsd.c:568
int Ivy_TruthDsd(unsigned uTruth, Vec_Int_t *vTree)
FUNCTION DEFINITIONS ///.
Definition ivyDsd.c:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ivy_TruthDsdPrint()

void Ivy_TruthDsdPrint ( FILE * pFile,
Vec_Int_t * vTree )

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

Synopsis [Prints the decomposition tree.]

Description []

SideEffects []

SeeAlso []

Definition at line 568 of file ivyDsd.c.

569{
570 fprintf( pFile, "F = " );
571 Ivy_TruthDsdPrint_rec( pFile, Vec_IntSize(vTree)-1, vTree );
572 fprintf( pFile, "\n" );
573}
void Ivy_TruthDsdPrint_rec(FILE *pFile, int iNode, Vec_Int_t *vTree)
Definition ivyDsd.c:494
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ivy_TruthDsdPrint_rec()

void Ivy_TruthDsdPrint_rec ( FILE * pFile,
int iNode,
Vec_Int_t * vTree )

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

Synopsis [Prints the decomposition tree.]

Description []

SideEffects []

SeeAlso []

Definition at line 494 of file ivyDsd.c.

495{
496 int Var, i;
497 // get the node
498 Ivy_Dec_t Node = Ivy_IntToDec( Vec_IntEntry(vTree, iNode) );
499 // compute the node function
500 if ( Node.Type == IVY_DEC_CONST1 )
501 fprintf( pFile, "Const1%s", (Node.fCompl? "\'" : "") );
502 else if ( Node.Type == IVY_DEC_PI )
503 fprintf( pFile, "%c%s", 'a' + iNode, (Node.fCompl? "\'" : "") );
504 else if ( Node.Type == IVY_DEC_BUF )
505 {
506 Ivy_TruthDsdPrint_rec( pFile, Node.Fan0 >> 1, vTree );
507 fprintf( pFile, "%s", (Node.fCompl? "\'" : "") );
508 }
509 else if ( Node.Type == IVY_DEC_AND )
510 {
511 fprintf( pFile, "AND(" );
512 for ( i = 0; i < (int)Node.nFans; i++ )
513 {
514 Var = Ivy_DecGetVar( &Node, i );
515 Ivy_TruthDsdPrint_rec( pFile, Var >> 1, vTree );
516 fprintf( pFile, "%s", (Var & 1)? "\'" : "" );
517 if ( i != (int)Node.nFans-1 )
518 fprintf( pFile, "," );
519 }
520 fprintf( pFile, ")%s", (Node.fCompl? "\'" : "") );
521 }
522 else if ( Node.Type == IVY_DEC_EXOR )
523 {
524 fprintf( pFile, "EXOR(" );
525 for ( i = 0; i < (int)Node.nFans; i++ )
526 {
527 Var = Ivy_DecGetVar( &Node, i );
528 Ivy_TruthDsdPrint_rec( pFile, Var >> 1, vTree );
529 if ( i != (int)Node.nFans-1 )
530 fprintf( pFile, "," );
531 assert( (Var & 1) == 0 );
532 }
533 fprintf( pFile, ")%s", (Node.fCompl? "\'" : "") );
534 }
535 else if ( Node.Type == IVY_DEC_MUX || Node.Type == IVY_DEC_MAJ )
536 {
537 int VarC, Var1, Var0;
538 assert( Node.fCompl == 0 );
539 VarC = Ivy_DecGetVar( &Node, 0 );
540 Var1 = Ivy_DecGetVar( &Node, 1 );
541 Var0 = Ivy_DecGetVar( &Node, 2 );
542 fprintf( pFile, "%s", (Node.Type == IVY_DEC_MUX)? "MUX(" : "MAJ(" );
543 Ivy_TruthDsdPrint_rec( pFile, VarC >> 1, vTree );
544 fprintf( pFile, "%s", (VarC & 1)? "\'" : "" );
545 fprintf( pFile, "," );
546 Ivy_TruthDsdPrint_rec( pFile, Var1 >> 1, vTree );
547 fprintf( pFile, "%s", (Var1 & 1)? "\'" : "" );
548 fprintf( pFile, "," );
549 Ivy_TruthDsdPrint_rec( pFile, Var0 >> 1, vTree );
550 fprintf( pFile, "%s", (Var0 & 1)? "\'" : "" );
551 fprintf( pFile, ")" );
552 }
553 else assert( 0 );
554}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ivy_TruthTestOne()

void Ivy_TruthTestOne ( unsigned uTruth)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 700 of file ivyDsd.c.

701{
702 static int Counter = 0;
703 static Vec_Int_t * vTree = NULL;
704 // decompose
705 if ( vTree == NULL )
706 vTree = Vec_IntAlloc( 12 );
707
708 if ( !Ivy_TruthDsd( uTruth, vTree ) )
709 {
710// printf( "Undecomposable\n" );
711 }
712 else
713 {
714// nTruthDsd++;
715 printf( "%5d : ", Counter++ );
716 Extra_PrintBinary( stdout, &uTruth, 32 );
717 printf( " " );
718 Ivy_TruthDsdPrint( stdout, vTree );
719 if ( uTruth != Ivy_TruthDsdCompute(vTree) )
720 printf( "Verification failed.\n" );
721 }
722// Vec_IntFree( vTree );
723}
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
Here is the call graph for this function: