abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaAigerExt.c File Reference
#include "gia.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START
Gia_Rpr_t
Gia_AigerReadEquivClasses (unsigned char **ppPos, int nSize)
 DECLARATIONS ///. More...
 
unsigned char * Gia_WriteEquivClassesInt (Gia_Man_t *p, int *pEquivSize)
 
Vec_Str_tGia_WriteEquivClasses (Gia_Man_t *p)
 
static unsigned Gia_AigerReadDiffValue (unsigned char **ppPos, int iPrev)
 
int * Gia_AigerReadMapping (unsigned char **ppPos, int nSize)
 
static int Gia_AigerWriteDiffValue (unsigned char *pPos, int iPos, int iPrev, int iThis)
 
unsigned char * Gia_AigerWriteMappingInt (Gia_Man_t *p, int *pMapSize)
 
Vec_Str_tGia_AigerWriteMapping (Gia_Man_t *p)
 
int * Gia_AigerReadMappingSimple (unsigned char **ppPos, int nSize)
 
Vec_Str_tGia_AigerWriteMappingSimple (Gia_Man_t *p)
 
Vec_Int_tGia_AigerReadMappingDoc (unsigned char **ppPos, int nObjs)
 
Vec_Str_tGia_AigerWriteMappingDoc (Gia_Man_t *p)
 
Vec_Int_tGia_AigerReadPacking (unsigned char **ppPos, int nSize)
 
Vec_Str_tGia_WritePacking (Vec_Int_t *vPacking)
 

Function Documentation

static unsigned Gia_AigerReadDiffValue ( unsigned char **  ppPos,
int  iPrev 
)
inlinestatic

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

Synopsis [Read/write mapping information.]

Description []

SideEffects []

SeeAlso []

Definition at line 136 of file giaAigerExt.c.

137 {
138  int Item = Gia_AigerReadUnsigned( ppPos );
139  if ( Item & 1 )
140  return iPrev + (Item >> 1);
141  return iPrev - (Item >> 1);
142 }
static unsigned Gia_AigerReadUnsigned(unsigned char **ppPos)
Definition: gia.h:840
ABC_NAMESPACE_IMPL_START Gia_Rpr_t* Gia_AigerReadEquivClasses ( unsigned char **  ppPos,
int  nSize 
)

DECLARATIONS ///.

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

FileName [giaAigerExt.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Scalable AIG package.]

Synopsis [Custom AIGER extensions.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
giaAigerExt.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

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

Synopsis [Read/write equivalence classes information.]

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file giaAigerExt.c.

46 {
47  Gia_Rpr_t * pReprs;
48  unsigned char * pStop;
49  int i, Item, fProved, iRepr, iNode;
50  pStop = *ppPos;
51  pStop += Gia_AigerReadInt( *ppPos ); *ppPos += 4;
52  pReprs = ABC_CALLOC( Gia_Rpr_t, nSize );
53  for ( i = 0; i < nSize; i++ )
54  pReprs[i].iRepr = GIA_VOID;
55  iRepr = iNode = 0;
56  while ( *ppPos < pStop )
57  {
58  Item = Gia_AigerReadUnsigned( ppPos );
59  if ( Item & 1 )
60  {
61  iRepr += (Item >> 1);
62  iNode = iRepr;
63  continue;
64  }
65  Item >>= 1;
66  fProved = (Item & 1);
67  Item >>= 1;
68  iNode += Item;
69  pReprs[iNode].fProved = fProved;
70  pReprs[iNode].iRepr = iRepr;
71  assert( iRepr < iNode );
72  }
73  return pReprs;
74 }
unsigned iRepr
Definition: gia.h:58
static int Gia_AigerReadInt(unsigned char *pPos)
Definition: gia.h:827
#define GIA_VOID
Definition: gia.h:45
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
#define assert(ex)
Definition: util_old.h:213
static unsigned Gia_AigerReadUnsigned(unsigned char **ppPos)
Definition: gia.h:840
unsigned fProved
Definition: gia.h:59
Definition: gia.h:56
int* Gia_AigerReadMapping ( unsigned char **  ppPos,
int  nSize 
)

Definition at line 143 of file giaAigerExt.c.

144 {
145  int * pMapping;
146  unsigned char * pStop;
147  int k, j, nFanins, nAlloc, iNode = 0, iOffset = nSize;
148  pStop = *ppPos;
149  pStop += Gia_AigerReadInt( *ppPos ); *ppPos += 4;
150  nAlloc = nSize + pStop - *ppPos;
151  pMapping = ABC_CALLOC( int, nAlloc );
152  while ( *ppPos < pStop )
153  {
154  k = iOffset;
155  pMapping[k++] = nFanins = Gia_AigerReadUnsigned( ppPos );
156  for ( j = 0; j <= nFanins; j++ )
157  pMapping[k++] = iNode = Gia_AigerReadDiffValue( ppPos, iNode );
158  pMapping[iNode] = iOffset;
159  iOffset = k;
160  }
161  assert( iOffset <= nAlloc );
162  return pMapping;
163 }
static unsigned Gia_AigerReadDiffValue(unsigned char **ppPos, int iPrev)
Definition: giaAigerExt.c:136
static int Gia_AigerReadInt(unsigned char *pPos)
Definition: gia.h:827
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
#define assert(ex)
Definition: util_old.h:213
static unsigned Gia_AigerReadUnsigned(unsigned char **ppPos)
Definition: gia.h:840
Vec_Int_t* Gia_AigerReadMappingDoc ( unsigned char **  ppPos,
int  nObjs 
)

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

Synopsis [Read/write mapping information.]

Description []

SideEffects []

SeeAlso []

Definition at line 245 of file giaAigerExt.c.

246 {
247  int * pMapping, nLuts, LutSize, iRoot, nFanins, i, k, nOffset;
248  nLuts = Gia_AigerReadInt( *ppPos ); *ppPos += 4;
249  LutSize = Gia_AigerReadInt( *ppPos ); *ppPos += 4;
250  pMapping = ABC_CALLOC( int, nObjs + (LutSize + 2) * nLuts );
251  nOffset = nObjs;
252  for ( i = 0; i < nLuts; i++ )
253  {
254  iRoot = Gia_AigerReadInt( *ppPos ); *ppPos += 4;
255  nFanins = Gia_AigerReadInt( *ppPos ); *ppPos += 4;
256  pMapping[iRoot] = nOffset;
257  // write one
258  pMapping[ nOffset++ ] = nFanins;
259  for ( k = 0; k < nFanins; k++ )
260  {
261  pMapping[ nOffset++ ] = Gia_AigerReadInt( *ppPos ); *ppPos += 4;
262  }
263  pMapping[ nOffset++ ] = iRoot;
264  }
265  return Vec_IntAllocArray( pMapping, nOffset );
266 }
static Vec_Int_t * Vec_IntAllocArray(int *pArray, int nSize)
Definition: bblif.c:214
static int Gia_AigerReadInt(unsigned char *pPos)
Definition: gia.h:827
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
int* Gia_AigerReadMappingSimple ( unsigned char **  ppPos,
int  nSize 
)

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

Synopsis [Read/write mapping information.]

Description []

SideEffects []

SeeAlso []

Definition at line 219 of file giaAigerExt.c.

220 {
221  int * pMapping = ABC_ALLOC( int, nSize/4 );
222  memcpy( pMapping, *ppPos, nSize );
223  assert( nSize % 4 == 0 );
224  return pMapping;
225 }
char * memcpy()
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define assert(ex)
Definition: util_old.h:213
Vec_Int_t* Gia_AigerReadPacking ( unsigned char **  ppPos,
int  nSize 
)

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

Synopsis [Read/write packing information.]

Description []

SideEffects []

SeeAlso []

Definition at line 302 of file giaAigerExt.c.

303 {
304  Vec_Int_t * vPacking = Vec_IntAlloc( nSize/4 );
305  int i;
306  assert( nSize % 4 == 0 );
307  for ( i = 0; i < nSize/4; i++, *ppPos += 4 )
308  Vec_IntPush( vPacking, Gia_AigerReadInt( *ppPos ) );
309  return vPacking;
310 }
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Gia_AigerReadInt(unsigned char *pPos)
Definition: gia.h:827
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
#define assert(ex)
Definition: util_old.h:213
static int Gia_AigerWriteDiffValue ( unsigned char *  pPos,
int  iPos,
int  iPrev,
int  iThis 
)
inlinestatic

Definition at line 164 of file giaAigerExt.c.

165 {
166  if ( iPrev < iThis )
167  return Gia_AigerWriteUnsignedBuffer( pPos, iPos, Abc_Var2Lit(iThis - iPrev, 1) );
168  return Gia_AigerWriteUnsignedBuffer( pPos, iPos, Abc_Var2Lit(iPrev - iThis, 0) );
169 }
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
static int Gia_AigerWriteUnsignedBuffer(unsigned char *pBuffer, int Pos, unsigned x)
Definition: gia.h:872
Vec_Str_t* Gia_AigerWriteMapping ( Gia_Man_t p)

Definition at line 201 of file giaAigerExt.c.

202 {
203  int nMapSize;
204  unsigned char * pBuffer = Gia_AigerWriteMappingInt( p, &nMapSize );
205  return Vec_StrAllocArray( (char *)pBuffer, nMapSize );
206 }
unsigned char * Gia_AigerWriteMappingInt(Gia_Man_t *p, int *pMapSize)
Definition: giaAigerExt.c:170
static Vec_Str_t * Vec_StrAllocArray(char *pArray, int nSize)
Definition: bblif.c:518
Vec_Str_t* Gia_AigerWriteMappingDoc ( Gia_Man_t p)

Definition at line 267 of file giaAigerExt.c.

268 {
269  unsigned char * pBuffer;
270  int i, k, iFan, nLuts = 0, LutSize = 0, nSize = 2, nSize2 = 0;
271  Gia_ManForEachLut( p, i )
272  {
273  nLuts++;
274  nSize += Gia_ObjLutSize(p, i) + 2;
275  LutSize = Abc_MaxInt( LutSize, Gia_ObjLutSize(p, i) );
276  }
277  pBuffer = ABC_ALLOC( unsigned char, 4 * nSize );
278  Gia_AigerWriteInt( pBuffer + 4 * nSize2++, nLuts );
279  Gia_AigerWriteInt( pBuffer + 4 * nSize2++, LutSize );
280  Gia_ManForEachLut( p, i )
281  {
282  Gia_AigerWriteInt( pBuffer + 4 * nSize2++, i );
283  Gia_AigerWriteInt( pBuffer + 4 * nSize2++, Gia_ObjLutSize(p, i) );
284  Gia_LutForEachFanin( p, i, iFan, k )
285  Gia_AigerWriteInt( pBuffer + 4 * nSize2++, iFan );
286  }
287  assert( nSize2 == nSize );
288  return Vec_StrAllocArray( (char *)pBuffer, 4*nSize );
289 }
static void Gia_AigerWriteInt(unsigned char *pPos, int Value)
Definition: gia.h:834
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
#define Gia_ManForEachLut(p, i)
Definition: gia.h:968
static int Gia_ObjLutSize(Gia_Man_t *p, int Id)
Definition: gia.h:953
#define assert(ex)
Definition: util_old.h:213
#define Gia_LutForEachFanin(p, i, iFan, k)
Definition: gia.h:970
static Vec_Str_t * Vec_StrAllocArray(char *pArray, int nSize)
Definition: bblif.c:518
unsigned char* Gia_AigerWriteMappingInt ( Gia_Man_t p,
int *  pMapSize 
)

Definition at line 170 of file giaAigerExt.c.

171 {
172  unsigned char * pBuffer;
173  int i, k, iPrev, iFan, nItems, iPos = 4;
175  // count the number of entries to be written
176  nItems = 0;
177  Gia_ManForEachLut( p, i )
178  nItems += 2 + Gia_ObjLutSize( p, i );
179  pBuffer = ABC_ALLOC( unsigned char, sizeof(int) * (nItems + 1) );
180  // write non-constant classes
181  iPrev = 0;
182  Gia_ManForEachLut( p, i )
183  {
184 //printf( "\nSize = %d ", Gia_ObjLutSize(p, i) );
185  iPos = Gia_AigerWriteUnsignedBuffer( pBuffer, iPos, Gia_ObjLutSize(p, i) );
186  Gia_LutForEachFanin( p, i, iFan, k )
187  {
188 //printf( "Fan = %d ", iFan );
189  iPos = Gia_AigerWriteDiffValue( pBuffer, iPos, iPrev, iFan );
190  iPrev = iFan;
191  }
192  iPos = Gia_AigerWriteDiffValue( pBuffer, iPos, iPrev, i );
193  iPrev = i;
194 //printf( "Node = %d ", i );
195  }
196 //printf( "\n" );
197  Gia_AigerWriteInt( pBuffer, iPos );
198  *pMapSize = iPos;
199  return pBuffer;
200 }
static void Gia_AigerWriteInt(unsigned char *pPos, int Value)
Definition: gia.h:834
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define Gia_ManForEachLut(p, i)
Definition: gia.h:968
static int Gia_ObjLutSize(Gia_Man_t *p, int Id)
Definition: gia.h:953
static int Gia_ManHasMapping(Gia_Man_t *p)
Definition: gia.h:951
static int Gia_AigerWriteDiffValue(unsigned char *pPos, int iPos, int iPrev, int iThis)
Definition: giaAigerExt.c:164
#define assert(ex)
Definition: util_old.h:213
static int Gia_AigerWriteUnsignedBuffer(unsigned char *pBuffer, int Pos, unsigned x)
Definition: gia.h:872
#define Gia_LutForEachFanin(p, i, iFan, k)
Definition: gia.h:970
Vec_Str_t* Gia_AigerWriteMappingSimple ( Gia_Man_t p)

Definition at line 226 of file giaAigerExt.c.

227 {
228  unsigned char * pBuffer = ABC_ALLOC( unsigned char, 4*Vec_IntSize(p->vMapping) );
229  memcpy( pBuffer, Vec_IntArray(p->vMapping), 4*Vec_IntSize(p->vMapping) );
231  return Vec_StrAllocArray( (char *)pBuffer, 4*Vec_IntSize(p->vMapping) );
232 }
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
char * memcpy()
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define assert(ex)
Definition: util_old.h:213
Vec_Int_t * vMapping
Definition: gia.h:131
static Vec_Str_t * Vec_StrAllocArray(char *pArray, int nSize)
Definition: bblif.c:518
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
Vec_Str_t* Gia_WriteEquivClasses ( Gia_Man_t p)

Definition at line 118 of file giaAigerExt.c.

119 {
120  int nEquivSize;
121  unsigned char * pBuffer = Gia_WriteEquivClassesInt( p, &nEquivSize );
122  return Vec_StrAllocArray( (char *)pBuffer, nEquivSize );
123 }
unsigned char * Gia_WriteEquivClassesInt(Gia_Man_t *p, int *pEquivSize)
Definition: giaAigerExt.c:75
static Vec_Str_t * Vec_StrAllocArray(char *pArray, int nSize)
Definition: bblif.c:518
unsigned char* Gia_WriteEquivClassesInt ( Gia_Man_t p,
int *  pEquivSize 
)

Definition at line 75 of file giaAigerExt.c.

76 {
77  unsigned char * pBuffer;
78  int iRepr, iNode, iPrevRepr, iPrevNode, iLit, nItems, iPos;
79  assert( p->pReprs && p->pNexts );
80  // count the number of entries to be written
81  nItems = 0;
82  for ( iRepr = 1; iRepr < Gia_ManObjNum(p); iRepr++ )
83  {
84  nItems += Gia_ObjIsConst( p, iRepr );
85  if ( !Gia_ObjIsHead(p, iRepr) )
86  continue;
87  Gia_ClassForEachObj( p, iRepr, iNode )
88  nItems++;
89  }
90  pBuffer = ABC_ALLOC( unsigned char, sizeof(int) * (nItems + 10) );
91  // write constant class
92  iPos = Gia_AigerWriteUnsignedBuffer( pBuffer, 4, Abc_Var2Lit(0, 1) );
93  iPrevNode = 0;
94  for ( iNode = 1; iNode < Gia_ManObjNum(p); iNode++ )
95  if ( Gia_ObjIsConst(p, iNode) )
96  {
97  iLit = Abc_Var2Lit( iNode - iPrevNode, Gia_ObjProved(p, iNode) );
98  iPrevNode = iNode;
99  iPos = Gia_AigerWriteUnsignedBuffer( pBuffer, iPos, Abc_Var2Lit(iLit, 0) );
100  }
101  // write non-constant classes
102  iPrevRepr = 0;
103  Gia_ManForEachClass( p, iRepr )
104  {
105  iPos = Gia_AigerWriteUnsignedBuffer( pBuffer, iPos, Abc_Var2Lit(iRepr - iPrevRepr, 1) );
106  iPrevRepr = iPrevNode = iRepr;
107  Gia_ClassForEachObj1( p, iRepr, iNode )
108  {
109  iLit = Abc_Var2Lit( iNode - iPrevNode, Gia_ObjProved(p, iNode) );
110  iPrevNode = iNode;
111  iPos = Gia_AigerWriteUnsignedBuffer( pBuffer, iPos, Abc_Var2Lit(iLit, 0) );
112  }
113  }
114  Gia_AigerWriteInt( pBuffer, iPos );
115  *pEquivSize = iPos;
116  return pBuffer;
117 }
static void Gia_AigerWriteInt(unsigned char *pPos, int Value)
Definition: gia.h:834
int * pNexts
Definition: gia.h:122
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
static int Gia_ObjIsHead(Gia_Man_t *p, int Id)
Definition: gia.h:916
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
for(p=first;p->value< newval;p=p->next)
static int Gia_ObjIsConst(Gia_Man_t *p, int Id)
Definition: gia.h:915
if(last==0)
Definition: sparse_int.h:34
#define Gia_ClassForEachObj1(p, i, iObj)
Definition: gia.h:933
#define Gia_ClassForEachObj(p, i, iObj)
Definition: gia.h:931
#define Gia_ManForEachClass(p, i)
Definition: gia.h:927
static int Gia_ObjProved(Gia_Man_t *p, int Id)
Definition: gia.h:896
Gia_Rpr_t * pReprs
Definition: gia.h:121
#define assert(ex)
Definition: util_old.h:213
static int Gia_AigerWriteUnsignedBuffer(unsigned char *pBuffer, int Pos, unsigned x)
Definition: gia.h:872
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
Vec_Str_t* Gia_WritePacking ( Vec_Int_t vPacking)

Definition at line 311 of file giaAigerExt.c.

312 {
313  unsigned char * pBuffer = ABC_ALLOC( unsigned char, 4*Vec_IntSize(vPacking) );
314  int i, Entry, nSize = 0;
315  Vec_IntForEachEntry( vPacking, Entry, i )
316  Gia_AigerWriteInt( pBuffer + 4 * nSize++, Entry );
317  return Vec_StrAllocArray( (char *)pBuffer, 4*Vec_IntSize(vPacking) );
318 }
static void Gia_AigerWriteInt(unsigned char *pPos, int Value)
Definition: gia.h:834
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
static Vec_Str_t * Vec_StrAllocArray(char *pArray, int nSize)
Definition: bblif.c:518