abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
miniaig.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

Go to the source code of this file.

Data Structures

struct  Mini_Aig_t_
 

Macros

#define MINI_AIG_NULL   (0x7FFFFFFF)
 INCLUDES ///. More...
 
#define MINI_AIG_START_SIZE   (0x000000FF)
 
#define MINI_AIG_ALLOC(type, num)   ((type *) malloc(sizeof(type) * (num)))
 MACRO DEFINITIONS ///. More...
 
#define MINI_AIG_CALLOC(type, num)   ((type *) calloc((num), sizeof(type)))
 
#define MINI_AIG_FALLOC(type, num)   ((type *) memset(malloc(sizeof(type) * (num)), 0xff, sizeof(type) * (num)))
 
#define MINI_AIG_FREE(obj)   ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
 
#define MINI_AIG_REALLOC(type, obj, num)
 
#define Mini_AigForEachPi(p, i)   for (i = 1; i < Mini_AigNodeNum(p); i++) if ( !Mini_AigNodeIsPi(p, i) ) {} else
 
#define Mini_AigForEachPo(p, i)   for (i = 1; i < Mini_AigNodeNum(p); i++) if ( !Mini_AigNodeIsPo(p, i) ) {} else
 
#define Mini_AigForEachAnd(p, i)   for (i = 1; i < Mini_AigNodeNum(p); i++) if ( !Mini_AigNodeIsAnd(p, i) ) {} else
 

Typedefs

typedef struct Mini_Aig_t_ Mini_Aig_t
 BASIC TYPES ///. More...
 

Functions

static void Mini_AigGrow (Mini_Aig_t *p, int nCapMin)
 
static void Mini_AigPush (Mini_Aig_t *p, int Lit0, int Lit1)
 
static int Mini_AigNodeFanin0 (Mini_Aig_t *p, int Id)
 
static int Mini_AigNodeFanin1 (Mini_Aig_t *p, int Id)
 
static int Mini_AigVar2Lit (int Var, int fCompl)
 
static int Mini_AigLit2Var (int Lit)
 
static int Mini_AigLitIsCompl (int Lit)
 
static int Mini_AigLitNot (int Lit)
 
static int Mini_AigLitNotCond (int Lit, int c)
 
static int Mini_AigLitRegular (int Lit)
 
static int Mini_AigLitConst0 ()
 
static int Mini_AigLitConst1 ()
 
static int Mini_AigLitIsConst0 (int Lit)
 
static int Mini_AigLitIsConst1 (int Lit)
 
static int Mini_AigLitIsConst (int Lit)
 
static int Mini_AigNodeNum (Mini_Aig_t *p)
 
static int Mini_AigNodeIsConst (Mini_Aig_t *p, int Id)
 
static int Mini_AigNodeIsPi (Mini_Aig_t *p, int Id)
 
static int Mini_AigNodeIsPo (Mini_Aig_t *p, int Id)
 
static int Mini_AigNodeIsAnd (Mini_Aig_t *p, int Id)
 
static int Mini_AigRegNum (Mini_Aig_t *p)
 
static void Mini_AigSetRegNum (Mini_Aig_t *p, int n)
 
static Mini_Aig_tMini_AigStart ()
 
static void Mini_AigStop (Mini_Aig_t *p)
 
static void Mini_AigPrintStats (Mini_Aig_t *p)
 
static void Mini_AigDump (Mini_Aig_t *p, char *pFileName)
 
static Mini_Aig_tMini_AigLoad (char *pFileName)
 
static int Mini_AigCreatePi (Mini_Aig_t *p)
 
static int Mini_AigCreatePo (Mini_Aig_t *p, int Lit0)
 
static int Mini_AigAnd (Mini_Aig_t *p, int Lit0, int Lit1)
 
static int Mini_AigOr (Mini_Aig_t *p, int Lit0, int Lit1)
 
static int Mini_AigMux (Mini_Aig_t *p, int LitC, int Lit1, int Lit0)
 
static int Mini_AigXor (Mini_Aig_t *p, int Lit0, int Lit1)
 
static int Mini_AigCheck (Mini_Aig_t *p)
 

Macro Definition Documentation

#define MINI_AIG_ALLOC (   type,
  num 
)    ((type *) malloc(sizeof(type) * (num)))

MACRO DEFINITIONS ///.

Definition at line 58 of file miniaig.h.

#define MINI_AIG_CALLOC (   type,
  num 
)    ((type *) calloc((num), sizeof(type)))

Definition at line 59 of file miniaig.h.

#define MINI_AIG_FALLOC (   type,
  num 
)    ((type *) memset(malloc(sizeof(type) * (num)), 0xff, sizeof(type) * (num)))

Definition at line 60 of file miniaig.h.

#define MINI_AIG_FREE (   obj)    ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)

Definition at line 61 of file miniaig.h.

#define MINI_AIG_NULL   (0x7FFFFFFF)

INCLUDES ///.

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

FileName [miniaig.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Minimalistic AIG package.]

Synopsis [External declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - September 29, 2012.]

Revision [

Id:
miniaig.h,v 1.00 2012/09/29 00:00:00 alanmi Exp

]PARAMETERS ///

Definition at line 37 of file miniaig.h.

#define MINI_AIG_REALLOC (   type,
  obj,
  num 
)
Value:
((obj) ? ((type *) realloc((char *)(obj), sizeof(type) * (num))) : \
((type *) malloc(sizeof(type) * (num))))
char * malloc()
char * realloc()

Definition at line 62 of file miniaig.h.

#define MINI_AIG_START_SIZE   (0x000000FF)

Definition at line 38 of file miniaig.h.

#define Mini_AigForEachAnd (   p,
 
)    for (i = 1; i < Mini_AigNodeNum(p); i++) if ( !Mini_AigNodeIsAnd(p, i) ) {} else

Definition at line 127 of file miniaig.h.

#define Mini_AigForEachPi (   p,
 
)    for (i = 1; i < Mini_AigNodeNum(p); i++) if ( !Mini_AigNodeIsPi(p, i) ) {} else

Definition at line 125 of file miniaig.h.

#define Mini_AigForEachPo (   p,
 
)    for (i = 1; i < Mini_AigNodeNum(p); i++) if ( !Mini_AigNodeIsPo(p, i) ) {} else

Definition at line 126 of file miniaig.h.

Typedef Documentation

typedef struct Mini_Aig_t_ Mini_Aig_t

BASIC TYPES ///.

Definition at line 44 of file miniaig.h.

Function Documentation

static int Mini_AigAnd ( Mini_Aig_t p,
int  Lit0,
int  Lit1 
)
static

Definition at line 215 of file miniaig.h.

216 {
217  int Lit = p->nSize;
218  assert( Lit0 >= 0 && Lit0 < Lit );
219  assert( Lit1 >= 0 && Lit1 < Lit );
220  Mini_AigPush( p, Lit0, Lit1 );
221  return Lit;
222 }
int nSize
Definition: miniaig.h:48
#define assert(ex)
Definition: util_old.h:213
static void Mini_AigPush(Mini_Aig_t *p, int Lit0, int Lit1)
Definition: miniaig.h:75
static int Mini_AigCheck ( Mini_Aig_t p)
static

Definition at line 239 of file miniaig.h.

240 {
241  int status = 1;
242  int i, iFaninLit0, iFaninLit1;
243  Mini_AigForEachAnd( p, i )
244  {
245  // get the fanin literals of this AND node
246  iFaninLit0 = Mini_AigNodeFanin0( p, i );
247  iFaninLit1 = Mini_AigNodeFanin1( p, i );
248  // compare the fanin literals with the literal of the current node (2 * i)
249  if ( iFaninLit0 >= 2 * i )
250  printf( "Fanin0 of AND node %d is not in a topological order.\n", i ), status = 0;
251  if ( iFaninLit1 >= 2 * i )
252  printf( "Fanin0 of AND node %d is not in a topological order.\n", i ), status = 0;
253  }
254  Mini_AigForEachPo( p, i )
255  {
256  // get the fanin literal of this PO node
257  iFaninLit0 = Mini_AigNodeFanin0( p, i );
258  // compare the fanin literal with the literal of the current node (2 * i)
259  if ( iFaninLit0 >= 2 * i )
260  printf( "Fanin0 of PO node %d is not in a topological order.\n", i ), status = 0;
261  }
262  return status;
263 }
#define Mini_AigForEachPo(p, i)
Definition: miniaig.h:126
static int Mini_AigNodeFanin0(Mini_Aig_t *p, int Id)
Definition: miniaig.h:89
static int Mini_AigNodeFanin1(Mini_Aig_t *p, int Id)
Definition: miniaig.h:94
#define Mini_AigForEachAnd(p, i)
Definition: miniaig.h:127
static int Mini_AigCreatePi ( Mini_Aig_t p)
static

Definition at line 200 of file miniaig.h.

201 {
202  int Lit = p->nSize;
204  return Lit;
205 }
int nSize
Definition: miniaig.h:48
static void Mini_AigPush(Mini_Aig_t *p, int Lit0, int Lit1)
Definition: miniaig.h:75
#define MINI_AIG_NULL
INCLUDES ///.
Definition: miniaig.h:37
static int Mini_AigCreatePo ( Mini_Aig_t p,
int  Lit0 
)
static

Definition at line 206 of file miniaig.h.

207 {
208  int Lit = p->nSize;
209  assert( Lit0 >= 0 && Lit0 < Lit );
210  Mini_AigPush( p, Lit0, MINI_AIG_NULL );
211  return Lit;
212 }
int nSize
Definition: miniaig.h:48
#define assert(ex)
Definition: util_old.h:213
static void Mini_AigPush(Mini_Aig_t *p, int Lit0, int Lit1)
Definition: miniaig.h:75
#define MINI_AIG_NULL
INCLUDES ///.
Definition: miniaig.h:37
static void Mini_AigDump ( Mini_Aig_t p,
char *  pFileName 
)
static

Definition at line 161 of file miniaig.h.

162 {
163  FILE * pFile;
164  int RetValue;
165  pFile = fopen( pFileName, "wb" );
166  if ( pFile == NULL )
167  {
168  printf( "Cannot open file for writing \"%s\".\n", pFileName );
169  return;
170  }
171  RetValue = fwrite( &p->nSize, sizeof(int), 1, pFile );
172  RetValue = fwrite( &p->nRegs, sizeof(int), 1, pFile );
173  RetValue = fwrite( p->pArray, sizeof(int), p->nSize, pFile );
174  fclose( pFile );
175 }
int nRegs
Definition: miniaig.h:49
int nSize
Definition: miniaig.h:48
int * pArray
Definition: miniaig.h:50
static void Mini_AigGrow ( Mini_Aig_t p,
int  nCapMin 
)
static

Definition at line 67 of file miniaig.h.

68 {
69  if ( p->nCap >= nCapMin )
70  return;
71  p->pArray = MINI_AIG_REALLOC( int, p->pArray, nCapMin );
72  assert( p->pArray );
73  p->nCap = nCapMin;
74 }
#define MINI_AIG_REALLOC(type, obj, num)
Definition: miniaig.h:62
int * pArray
Definition: miniaig.h:50
int nCap
Definition: miniaig.h:47
#define assert(ex)
Definition: util_old.h:213
static int Mini_AigLit2Var ( int  Lit)
static

Definition at line 102 of file miniaig.h.

102 { return Lit >> 1; }
static int Mini_AigLitConst0 ( )
static

Definition at line 108 of file miniaig.h.

108 { return 0; }
static int Mini_AigLitConst1 ( )
static

Definition at line 109 of file miniaig.h.

109 { return 1; }
static int Mini_AigLitIsCompl ( int  Lit)
static

Definition at line 103 of file miniaig.h.

103 { return Lit & 1; }
static int Mini_AigLitIsConst ( int  Lit)
static

Definition at line 112 of file miniaig.h.

112 { return Lit == 0 || Lit == 1; }
static int Mini_AigLitIsConst0 ( int  Lit)
static

Definition at line 110 of file miniaig.h.

110 { return Lit == 0; }
static int Mini_AigLitIsConst1 ( int  Lit)
static

Definition at line 111 of file miniaig.h.

111 { return Lit == 1; }
static int Mini_AigLitNot ( int  Lit)
static

Definition at line 104 of file miniaig.h.

104 { return Lit ^ 1; }
static int Mini_AigLitNotCond ( int  Lit,
int  c 
)
static

Definition at line 105 of file miniaig.h.

105 { return Lit ^ (int)(c > 0); }
static int Mini_AigLitRegular ( int  Lit)
static

Definition at line 106 of file miniaig.h.

106 { return Lit & ~01; }
static Mini_Aig_t* Mini_AigLoad ( char *  pFileName)
static

Definition at line 176 of file miniaig.h.

177 {
178  Mini_Aig_t * p;
179  FILE * pFile;
180  int RetValue, nSize;
181  pFile = fopen( pFileName, "rb" );
182  if ( pFile == NULL )
183  {
184  printf( "Cannot open file for reading \"%s\".\n", pFileName );
185  return NULL;
186  }
187  RetValue = fread( &nSize, sizeof(int), 1, pFile );
188  p = MINI_AIG_CALLOC( Mini_Aig_t, 1 );
189  p->nSize = p->nCap = nSize;
190  p->pArray = MINI_AIG_ALLOC( int, p->nCap );
191  RetValue = fread( &p->nRegs, sizeof(int), 1, pFile );
192  RetValue = fread( p->pArray, sizeof(int), p->nSize, pFile );
193  fclose( pFile );
194  return p;
195 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int nRegs
Definition: miniaig.h:49
#define MINI_AIG_ALLOC(type, num)
MACRO DEFINITIONS ///.
Definition: miniaig.h:58
int nSize
Definition: miniaig.h:48
int * pArray
Definition: miniaig.h:50
#define MINI_AIG_CALLOC(type, num)
Definition: miniaig.h:59
int nCap
Definition: miniaig.h:47
static int Mini_AigMux ( Mini_Aig_t p,
int  LitC,
int  Lit1,
int  Lit0 
)
static

Definition at line 227 of file miniaig.h.

228 {
229  int Res0 = Mini_AigAnd( p, LitC, Lit1 );
230  int Res1 = Mini_AigAnd( p, Mini_AigLitNot(LitC), Lit0 );
231  return Mini_AigOr( p, Res0, Res1 );
232 }
static int Mini_AigAnd(Mini_Aig_t *p, int Lit0, int Lit1)
Definition: miniaig.h:215
static int Mini_AigLitNot(int Lit)
Definition: miniaig.h:104
static int Mini_AigOr(Mini_Aig_t *p, int Lit0, int Lit1)
Definition: miniaig.h:223
static int Mini_AigNodeFanin0 ( Mini_Aig_t p,
int  Id 
)
static

Definition at line 89 of file miniaig.h.

90 {
91  assert( Id >= 0 && 2*Id < p->nSize );
92  return p->pArray[2*Id];
93 }
int * pArray
Definition: miniaig.h:50
#define assert(ex)
Definition: util_old.h:213
static int Mini_AigNodeFanin1 ( Mini_Aig_t p,
int  Id 
)
static

Definition at line 94 of file miniaig.h.

95 {
96  assert( Id >= 0 && 2*Id < p->nSize );
97  return p->pArray[2*Id+1];
98 }
int * pArray
Definition: miniaig.h:50
#define assert(ex)
Definition: util_old.h:213
static int Mini_AigNodeIsAnd ( Mini_Aig_t p,
int  Id 
)
static

Definition at line 118 of file miniaig.h.

118 { assert( Id >= 0 ); return Id > 0 && Mini_AigNodeFanin0( p, Id ) != MINI_AIG_NULL && Mini_AigNodeFanin1( p, Id ) != MINI_AIG_NULL; }
static int Mini_AigNodeFanin0(Mini_Aig_t *p, int Id)
Definition: miniaig.h:89
static int Mini_AigNodeFanin1(Mini_Aig_t *p, int Id)
Definition: miniaig.h:94
#define assert(ex)
Definition: util_old.h:213
#define MINI_AIG_NULL
INCLUDES ///.
Definition: miniaig.h:37
static int Mini_AigNodeIsConst ( Mini_Aig_t p,
int  Id 
)
static

Definition at line 115 of file miniaig.h.

115 { assert( Id >= 0 ); return Id == 0; }
#define assert(ex)
Definition: util_old.h:213
static int Mini_AigNodeIsPi ( Mini_Aig_t p,
int  Id 
)
static

Definition at line 116 of file miniaig.h.

116 { assert( Id >= 0 ); return Id > 0 && Mini_AigNodeFanin0( p, Id ) == MINI_AIG_NULL; }
static int Mini_AigNodeFanin0(Mini_Aig_t *p, int Id)
Definition: miniaig.h:89
#define assert(ex)
Definition: util_old.h:213
#define MINI_AIG_NULL
INCLUDES ///.
Definition: miniaig.h:37
static int Mini_AigNodeIsPo ( Mini_Aig_t p,
int  Id 
)
static

Definition at line 117 of file miniaig.h.

117 { assert( Id >= 0 ); return Id > 0 && Mini_AigNodeFanin0( p, Id ) != MINI_AIG_NULL && Mini_AigNodeFanin1( p, Id ) == MINI_AIG_NULL; }
static int Mini_AigNodeFanin0(Mini_Aig_t *p, int Id)
Definition: miniaig.h:89
static int Mini_AigNodeFanin1(Mini_Aig_t *p, int Id)
Definition: miniaig.h:94
#define assert(ex)
Definition: util_old.h:213
#define MINI_AIG_NULL
INCLUDES ///.
Definition: miniaig.h:37
static int Mini_AigNodeNum ( Mini_Aig_t p)
static

Definition at line 114 of file miniaig.h.

114 { return p->nSize/2; }
int nSize
Definition: miniaig.h:48
static int Mini_AigOr ( Mini_Aig_t p,
int  Lit0,
int  Lit1 
)
static

Definition at line 223 of file miniaig.h.

224 {
225  return Mini_AigLitNot( Mini_AigAnd( p, Mini_AigLitNot(Lit0), Mini_AigLitNot(Lit1) ) );
226 }
static int Mini_AigAnd(Mini_Aig_t *p, int Lit0, int Lit1)
Definition: miniaig.h:215
static int Mini_AigLitNot(int Lit)
Definition: miniaig.h:104
static void Mini_AigPrintStats ( Mini_Aig_t p)
static

Definition at line 145 of file miniaig.h.

146 {
147  int i, nPis, nPos, nNodes;
148  nPis = 0;
149  Mini_AigForEachPi( p, i )
150  nPis++;
151  nPos = 0;
152  Mini_AigForEachPo( p, i )
153  nPos++;
154  nNodes = 0;
155  Mini_AigForEachAnd( p, i )
156  nNodes++;
157  printf( "PI = %d. PO = %d. Node = %d.\n", nPis, nPos, nNodes );
158 }
#define Mini_AigForEachPo(p, i)
Definition: miniaig.h:126
#define Mini_AigForEachPi(p, i)
Definition: miniaig.h:125
#define Mini_AigForEachAnd(p, i)
Definition: miniaig.h:127
static void Mini_AigPush ( Mini_Aig_t p,
int  Lit0,
int  Lit1 
)
static

Definition at line 75 of file miniaig.h.

76 {
77  if ( p->nSize + 2 > p->nCap )
78  {
79  if ( p->nCap < MINI_AIG_START_SIZE )
81  else
82  Mini_AigGrow( p, 2 * p->nCap );
83  }
84  p->pArray[p->nSize++] = Lit0;
85  p->pArray[p->nSize++] = Lit1;
86 }
static void Mini_AigGrow(Mini_Aig_t *p, int nCapMin)
Definition: miniaig.h:67
int nSize
Definition: miniaig.h:48
int * pArray
Definition: miniaig.h:50
int nCap
Definition: miniaig.h:47
#define MINI_AIG_START_SIZE
Definition: miniaig.h:38
static int Mini_AigRegNum ( Mini_Aig_t p)
static

Definition at line 121 of file miniaig.h.

121 { return p->nRegs; }
int nRegs
Definition: miniaig.h:49
static void Mini_AigSetRegNum ( Mini_Aig_t p,
int  n 
)
static

Definition at line 122 of file miniaig.h.

122 { p->nRegs = n; }
int nRegs
Definition: miniaig.h:49
static Mini_Aig_t* Mini_AigStart ( )
static

Definition at line 131 of file miniaig.h.

132 {
133  Mini_Aig_t * p;
134  p = MINI_AIG_CALLOC( Mini_Aig_t, 1 );
136  p->pArray = MINI_AIG_ALLOC( int, p->nCap );
138  return p;
139 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define MINI_AIG_ALLOC(type, num)
MACRO DEFINITIONS ///.
Definition: miniaig.h:58
int * pArray
Definition: miniaig.h:50
#define MINI_AIG_CALLOC(type, num)
Definition: miniaig.h:59
int nCap
Definition: miniaig.h:47
static void Mini_AigPush(Mini_Aig_t *p, int Lit0, int Lit1)
Definition: miniaig.h:75
#define MINI_AIG_NULL
INCLUDES ///.
Definition: miniaig.h:37
#define MINI_AIG_START_SIZE
Definition: miniaig.h:38
static void Mini_AigStop ( Mini_Aig_t p)
static

Definition at line 140 of file miniaig.h.

141 {
142  MINI_AIG_FREE( p->pArray );
143  MINI_AIG_FREE( p );
144 }
int * pArray
Definition: miniaig.h:50
#define MINI_AIG_FREE(obj)
Definition: miniaig.h:61
static int Mini_AigVar2Lit ( int  Var,
int  fCompl 
)
static

Definition at line 101 of file miniaig.h.

101 { return Var + Var + fCompl; }
int Var
Definition: SolverTypes.h:42
static int Mini_AigXor ( Mini_Aig_t p,
int  Lit0,
int  Lit1 
)
static

Definition at line 233 of file miniaig.h.

234 {
235  return Mini_AigMux( p, Lit0, Mini_AigLitNot(Lit1), Lit1 );
236 }
static int Mini_AigLitNot(int Lit)
Definition: miniaig.h:104
static int Mini_AigMux(Mini_Aig_t *p, int LitC, int Lit1, int Lit0)
Definition: miniaig.h:227