Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
abc
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
abc
Commits
6df122bd
Commit
6df122bd
authored
Jul 20, 2012
by
Alan Mishchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated code for lazy man's synthesis (memory optimization).
parent
6c9b59bf
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
372 additions
and
59 deletions
+372
-59
abclib.dsp
+4
-0
src/aig/gia/giaHash.c
+1
-1
src/aig/gia/giaMan.c
+5
-5
src/base/abci/abcRec2.c
+72
-53
src/misc/vec/vecMem.h
+290
-0
No files found.
abclib.dsp
View file @
6df122bd
...
@@ -2539,6 +2539,10 @@ SOURCE=.\src\misc\vec\vecInt.h
...
@@ -2539,6 +2539,10 @@ SOURCE=.\src\misc\vec\vecInt.h
# End Source File
# End Source File
# Begin Source File
# Begin Source File
SOURCE=.\src\misc\vec\vecMem.h
# End Source File
# Begin Source File
SOURCE=.\src\misc\vec\vecPtr.h
SOURCE=.\src\misc\vec\vecPtr.h
# End Source File
# End Source File
# Begin Source File
# Begin Source File
...
...
src/aig/gia/giaHash.c
View file @
6df122bd
...
@@ -109,7 +109,7 @@ int Gia_ManHashLookup( Gia_Man_t * p, Gia_Obj_t * p0, Gia_Obj_t * p1 )
...
@@ -109,7 +109,7 @@ int Gia_ManHashLookup( Gia_Man_t * p, Gia_Obj_t * p0, Gia_Obj_t * p1 )
void
Gia_ManHashAlloc
(
Gia_Man_t
*
p
)
void
Gia_ManHashAlloc
(
Gia_Man_t
*
p
)
{
{
assert
(
p
->
pHTable
==
NULL
);
assert
(
p
->
pHTable
==
NULL
);
p
->
nHTable
=
Abc_PrimeCudd
(
p
->
nObjsAlloc
);
p
->
nHTable
=
Abc_PrimeCudd
(
Gia_ManAndNum
(
p
)
?
Gia_ManAndNum
(
p
)
+
1000
:
p
->
nObjsAlloc
);
p
->
pHTable
=
ABC_CALLOC
(
int
,
p
->
nHTable
);
p
->
pHTable
=
ABC_CALLOC
(
int
,
p
->
nHTable
);
}
}
...
...
src/aig/gia/giaMan.c
View file @
6df122bd
...
@@ -52,8 +52,8 @@ Gia_Man_t * Gia_ManStart( int nObjsMax )
...
@@ -52,8 +52,8 @@ Gia_Man_t * Gia_ManStart( int nObjsMax )
p
->
pObjs
=
ABC_CALLOC
(
Gia_Obj_t
,
nObjsMax
);
p
->
pObjs
=
ABC_CALLOC
(
Gia_Obj_t
,
nObjsMax
);
p
->
pObjs
->
iDiff0
=
p
->
pObjs
->
iDiff1
=
GIA_NONE
;
p
->
pObjs
->
iDiff0
=
p
->
pObjs
->
iDiff1
=
GIA_NONE
;
p
->
nObjs
=
1
;
p
->
nObjs
=
1
;
p
->
vCis
=
Vec_IntAlloc
(
nObjsMax
/
1
0
);
p
->
vCis
=
Vec_IntAlloc
(
nObjsMax
/
2
0
);
p
->
vCos
=
Vec_IntAlloc
(
nObjsMax
/
1
0
);
p
->
vCos
=
Vec_IntAlloc
(
nObjsMax
/
2
0
);
return
p
;
return
p
;
}
}
...
@@ -414,10 +414,10 @@ void Gia_ManPrintStats( Gia_Man_t * p, int fTents, int fSwitch )
...
@@ -414,10 +414,10 @@ void Gia_ManPrintStats( Gia_Man_t * p, int fTents, int fSwitch )
if
(
Gia_ManRegNum
(
p
)
)
if
(
Gia_ManRegNum
(
p
)
)
printf
(
" ff =%7d"
,
Gia_ManRegNum
(
p
)
);
printf
(
" ff =%7d"
,
Gia_ManRegNum
(
p
)
);
printf
(
" and =%8d"
,
Gia_ManAndNum
(
p
)
);
printf
(
" and =%8d"
,
Gia_ManAndNum
(
p
)
);
printf
(
" lev =%5d"
,
Gia_ManLevelNum
(
p
)
);
printf
(
" lev =%5d"
,
Gia_ManLevelNum
(
p
)
);
Vec_IntFreeP
(
&
p
->
vLevels
);
printf
(
" cut =%5d"
,
Gia_ManCrossCut
(
p
)
);
printf
(
" cut =%5d"
,
Gia_ManCrossCut
(
p
)
);
printf
(
" mem =%5.2f MB"
,
1
.
0
*
(
sizeof
(
Gia_Obj_t
)
*
p
->
nObjs
+
sizeof
(
int
)
*
(
Vec_IntSize
(
p
->
vCis
)
+
Vec_IntSize
(
p
->
vCos
)))
/
(
1
<<
20
)
);
//
printf( " mem =%5.2f MB", 1.0*(sizeof(Gia_Obj_t)*p->nObjs + sizeof(int)*(Vec_IntSize(p->vCis) + Vec_IntSize(p->vCos)))/(1<<20) );
//
printf( " mem =%5.2f MB", 1.0*(sizeof(Gia_Obj_t)*p->nObjsAlloc + sizeof(int)*(Vec_IntCap(p->vCis) + Vec_IntCap(p->vCos)))/(1<<20) );
printf
(
" mem =%5.2f MB"
,
1
.
0
*
(
sizeof
(
Gia_Obj_t
)
*
p
->
nObjsAlloc
+
sizeof
(
int
)
*
(
Vec_IntCap
(
p
->
vCis
)
+
Vec_IntCap
(
p
->
vCos
)))
/
(
1
<<
20
)
);
if
(
Gia_ManHasDangling
(
p
)
)
if
(
Gia_ManHasDangling
(
p
)
)
printf
(
" ch =%5d"
,
Gia_ManEquivCountClasses
(
p
)
);
printf
(
" ch =%5d"
,
Gia_ManEquivCountClasses
(
p
)
);
if
(
fSwitch
)
if
(
fSwitch
)
...
...
src/base/abci/abcRec2.c
View file @
6df122bd
...
@@ -22,16 +22,19 @@
...
@@ -22,16 +22,19 @@
#include "map/if/if.h"
#include "map/if/if.h"
#include "bool/kit/kit.h"
#include "bool/kit/kit.h"
#include "aig/gia/giaAig.h"
#include "aig/gia/giaAig.h"
#include "misc/vec/vecMem.h"
ABC_NAMESPACE_IMPL_START
ABC_NAMESPACE_IMPL_START
//#define LibOut
//#define LibOut
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
#define IF_BIG_CHAR 120
#define IF_BIG_CHAR 120
#define REC_EMPTY_ID -1
#define REC_EMPTY_ID -1
typedef
struct
Abc_ManRec_t_2
Abc_ManRec_t2
;
typedef
struct
Abc_ManRec_t_2
Abc_ManRec_t2
;
typedef
struct
Rec_Obj_t_2
Rec_Obj_t2
;
typedef
struct
Rec_Obj_t_2
Rec_Obj_t2
;
...
@@ -54,14 +57,14 @@ struct Rec_Obj_t_2
...
@@ -54,14 +57,14 @@ struct Rec_Obj_t_2
char
pinToPinDelay
[
0
];
// structure's pin-to-pin delay
char
pinToPinDelay
[
0
];
// structure's pin-to-pin delay
};
};
struct
Abc_ManRec_t_2
struct
Abc_ManRec_t_2
{
{
Gia_Man_t
*
pGia
;
// the record
Gia_Man_t
*
pGia
;
// the record
Vec_Ptr_t
*
vTtElems
;
// the elementary truth tables
Vec_Ptr_t
*
vTtNodes
;
// the node truth tables
Vec_Str_t
*
vInputs
;
// the input number of nodes
Vec_Str_t
*
vInputs
;
// the input number of nodes
Mem_Fixed_t
*
pMmTruth
;
// memory manager for truth tables
Vec_Ptr_t
*
vTtElems
;
// the elementary truth tables
// Vec_Ptr_t * vTtNodes; // the node truth tables
// Mem_Fixed_t * pMmTruth; // memory manager for truth tables
Vec_Mem_t
*
vTtMem
;
// memory for truth tables of primary outputs
int
*
pBins
;
// hash table mapping truth tables into nodes
int
*
pBins
;
// hash table mapping truth tables into nodes
int
nBins
;
// the number of allocated bins
int
nBins
;
// the number of allocated bins
int
nVars
;
// the number of variables
int
nVars
;
// the number of variables
...
@@ -74,13 +77,11 @@ struct Abc_ManRec_t_2
...
@@ -74,13 +77,11 @@ struct Abc_ManRec_t_2
char
*
pRecObjs
;
char
*
pRecObjs
;
int
nRecObjs
;
int
nRecObjs
;
int
nRecObjsAlloc
;
int
nRecObjsAlloc
;
// temporaries
// temporaries
int
*
pBytes
;
// temporary storage for minterms
int
*
pBytes
;
// temporary storage for minterms
int
*
pMints
;
// temporary storage for minterm counters
int
*
pMints
;
// temporary storage for minterm counters
unsigned
*
pTemp1
;
// temporary truth table
unsigned
*
pTemp1
;
// temporary truth table
unsigned
*
pTemp2
;
// temporary truth table
unsigned
*
pTemp2
;
// temporary truth table
Vec_Ptr_t
*
vNodes
;
// the temporary nodes
Vec_Ptr_t
*
vNodes
;
// the temporary nodes
Vec_Ptr_t
*
vTtTemps
;
// the truth tables for the internal nodes of the cut
Vec_Ptr_t
*
vTtTemps
;
// the truth tables for the internal nodes of the cut
Vec_Ptr_t
*
vLabels
;
// temporary storage for AIG node labels
Vec_Ptr_t
*
vLabels
;
// temporary storage for AIG node labels
...
@@ -129,19 +130,19 @@ static Abc_ManRec_t2 * s_pMan = NULL;
...
@@ -129,19 +130,19 @@ static Abc_ManRec_t2 * s_pMan = NULL;
static
inline
void
Abc_ObjSetMax2
(
Vec_Str_t
*
p
,
Gia_Man_t
*
pGia
,
Gia_Obj_t
*
pObj
,
char
Value
)
{
Vec_StrWriteEntry
(
p
,
Gia_ObjId
(
pGia
,
pObj
),
Value
);
}
static
inline
void
Abc_ObjSetMax2
(
Vec_Str_t
*
p
,
Gia_Man_t
*
pGia
,
Gia_Obj_t
*
pObj
,
char
Value
)
{
Vec_StrWriteEntry
(
p
,
Gia_ObjId
(
pGia
,
pObj
),
Value
);
}
//static inline void Abc_ObjClearMax( Gia_Obj_t * pObj ) { pObj->Value = (pObj->Value & 0xff); }
//static inline void Abc_ObjClearMax( Gia_Obj_t * pObj ) { pObj->Value = (pObj->Value & 0xff); }
static
inline
int
Abc_ObjGetMax2
(
Vec_Str_t
*
p
,
Gia_Man_t
*
pGia
,
Gia_Obj_t
*
pObj
)
{
return
Vec_StrEntry
(
p
,
Gia_ObjId
(
pGia
,
pObj
));
}
static
inline
int
Abc_ObjGetMax2
(
Vec_Str_t
*
p
,
Gia_Man_t
*
pGia
,
Gia_Obj_t
*
pObj
)
{
return
Vec_StrEntry
(
p
,
Gia_ObjId
(
pGia
,
pObj
));
}
static
inline
int
Rec_ObjID
(
Abc_ManRec_t2
*
p
,
Rec_Obj_t2
*
pRecObj
)
static
inline
int
Rec_ObjID
(
Abc_ManRec_t2
*
p
,
Rec_Obj_t2
*
pRecObj
)
{
char
*
pObj
=
(
char
*
)
pRecObj
;
{
char
*
pObj
=
(
char
*
)
pRecObj
;
assert
(
p
->
pRecObjs
<=
pObj
&&
pObj
<
p
->
pRecObjs
+
p
->
nRecObjs
*
p
->
recObjSize
);
assert
(
p
->
pRecObjs
<=
pObj
&&
pObj
<
p
->
pRecObjs
+
p
->
nRecObjs
*
p
->
recObjSize
);
return
(
pObj
-
p
->
pRecObjs
)
/
p
->
recObjSize
;
return
(
pObj
-
p
->
pRecObjs
)
/
p
->
recObjSize
;
}
}
static
inline
Rec_Obj_t2
*
Rec_Obj
(
Abc_ManRec_t2
*
p
,
int
v
)
static
inline
Rec_Obj_t2
*
Rec_Obj
(
Abc_ManRec_t2
*
p
,
int
v
)
{
{
assert
(
v
<
p
->
nRecObjs
);
assert
(
v
<
p
->
nRecObjs
);
return
(
Rec_Obj_t2
*
)(
p
->
pRecObjs
+
v
*
p
->
recObjSize
);
return
(
Rec_Obj_t2
*
)(
p
->
pRecObjs
+
v
*
p
->
recObjSize
);
}
}
static
inline
unsigned
*
Rec_MemReadEntry
(
Abc_ManRec_t2
*
p
,
int
i
)
{
return
(
unsigned
*
)
Vec_MemReadEntry
(
p
->
vTtMem
,
i
);
}
static
inline
void
Rec_MemSetEntry
(
Abc_ManRec_t2
*
p
,
int
i
,
unsigned
*
pEntry
)
{
Vec_MemSetEntry
(
p
->
vTtMem
,
i
,
(
word
*
)
pEntry
);
}
/**Function*************************************************************
/**Function*************************************************************
...
@@ -628,7 +629,8 @@ static int * Abc_NtkRecTableLookup2(Abc_ManRec_t2* p, int * pBins, int nBins, u
...
@@ -628,7 +629,8 @@ static int * Abc_NtkRecTableLookup2(Abc_ManRec_t2* p, int * pBins, int nBins, u
int
*
ppSpot
,
pEntry
;
int
*
ppSpot
,
pEntry
;
ppSpot
=
pBins
+
Abc_NtkRecTableHash
(
pTruth
,
nVars
,
nBins
,
s_Primes
);
ppSpot
=
pBins
+
Abc_NtkRecTableHash
(
pTruth
,
nVars
,
nBins
,
s_Primes
);
for
(
pEntry
=
*
ppSpot
;
pEntry
!=
REC_EMPTY_ID
;
ppSpot
=
&
(
Rec_Obj
(
p
,
pEntry
)
->
pCopy
),
pEntry
=
Rec_Obj
(
p
,
pEntry
)
->
pCopy
)
for
(
pEntry
=
*
ppSpot
;
pEntry
!=
REC_EMPTY_ID
;
ppSpot
=
&
(
Rec_Obj
(
p
,
pEntry
)
->
pCopy
),
pEntry
=
Rec_Obj
(
p
,
pEntry
)
->
pCopy
)
if
(
Kit_TruthIsEqualWithPhase
((
unsigned
*
)
Vec_PtrEntry
(
p
->
vTtNodes
,
pEntry
),
pTruth
,
nVars
)
)
// if ( Kit_TruthIsEqualWithPhase((unsigned *)Vec_PtrEntry(p->vTtNodes, pEntry), pTruth, nVars) )
if
(
Kit_TruthIsEqualWithPhase
(
Rec_MemReadEntry
(
p
,
pEntry
),
pTruth
,
nVars
)
)
return
ppSpot
;
return
ppSpot
;
return
ppSpot
;
return
ppSpot
;
}
}
...
@@ -651,7 +653,7 @@ static void Abc_NtkRecResizeHash2(Abc_ManRec_t2* p)
...
@@ -651,7 +653,7 @@ static void Abc_NtkRecResizeHash2(Abc_ManRec_t2* p)
int
nBinsNew
,
Counter
,
i
;
int
nBinsNew
,
Counter
,
i
;
int
clk
=
clock
();
int
clk
=
clock
();
// get the new table size
// get the new table size
nBinsNew
=
Cudd_Prime
(
3
*
p
->
nBins
);
nBinsNew
=
Cudd_Prime
(
2
*
p
->
nBins
);
printf
(
"Hash table resize from %d to %d.
\n
"
,
p
->
nBins
,
nBinsNew
);
printf
(
"Hash table resize from %d to %d.
\n
"
,
p
->
nBins
,
nBinsNew
);
// allocate a new array
// allocate a new array
pBinsNew
=
ABC_ALLOC
(
int
,
nBinsNew
);
pBinsNew
=
ABC_ALLOC
(
int
,
nBinsNew
);
...
@@ -662,7 +664,8 @@ static void Abc_NtkRecResizeHash2(Abc_ManRec_t2* p)
...
@@ -662,7 +664,8 @@ static void Abc_NtkRecResizeHash2(Abc_ManRec_t2* p)
for
(
pEntry
=
p
->
pBins
[
i
];
pEntry
!=
REC_EMPTY_ID
;)
for
(
pEntry
=
p
->
pBins
[
i
];
pEntry
!=
REC_EMPTY_ID
;)
{
{
pTemp
=
Rec_Obj
(
p
,
pEntry
)
->
pCopy
;
pTemp
=
Rec_Obj
(
p
,
pEntry
)
->
pCopy
;
ppSpot
=
Abc_NtkRecTableLookup2
(
p
,
pBinsNew
,
nBinsNew
,
(
unsigned
*
)
Vec_PtrEntry
(
p
->
vTtNodes
,
pEntry
),
p
->
nVars
);
// ppSpot = Abc_NtkRecTableLookup2(p, pBinsNew, nBinsNew, (unsigned *)Vec_PtrEntry(p->vTtNodes, pEntry), p->nVars);
ppSpot
=
Abc_NtkRecTableLookup2
(
p
,
pBinsNew
,
nBinsNew
,
Rec_MemReadEntry
(
p
,
pEntry
),
p
->
nVars
);
assert
(
*
ppSpot
==
REC_EMPTY_ID
);
assert
(
*
ppSpot
==
REC_EMPTY_ID
);
*
ppSpot
=
pEntry
;
*
ppSpot
=
pEntry
;
Rec_Obj
(
p
,
pEntry
)
->
pCopy
=
REC_EMPTY_ID
;
Rec_Obj
(
p
,
pEntry
)
->
pCopy
=
REC_EMPTY_ID
;
...
@@ -886,7 +889,8 @@ void Abc_NtkRecInsertToLookUpTable2(Abc_ManRec_t2* p, int* ppSpot, Gia_Obj_t* pP
...
@@ -886,7 +889,8 @@ void Abc_NtkRecInsertToLookUpTable2(Abc_ManRec_t2* p, int* ppSpot, Gia_Obj_t* pP
}
}
hasRealloced
=
Rec_AppendObj
(
p
,
&
pRecObj
);
hasRealloced
=
Rec_AppendObj
(
p
,
&
pRecObj
);
if
(
hasRealloced
)
if
(
hasRealloced
)
ppSpot
=
Abc_NtkRecTableLookup2
(
p
,
p
->
pBins
,
p
->
nBins
,
(
unsigned
*
)
Vec_PtrEntry
(
p
->
vTtNodes
,
Gia_ObjCioId
(
pPO
)),
p
->
nVars
);
// ppSpot = Abc_NtkRecTableLookup2(p, p->pBins, p->nBins, (unsigned *)Vec_PtrEntry( p->vTtNodes, Gia_ObjCioId(pPO)), p->nVars );
ppSpot
=
Abc_NtkRecTableLookup2
(
p
,
p
->
pBins
,
p
->
nBins
,
Rec_MemReadEntry
(
p
,
Gia_ObjCioId
(
pPO
)),
p
->
nVars
);
assert
(
Rec_ObjID
(
p
,
pRecObj
)
==
Gia_ObjCioId
(
pPO
));
assert
(
Rec_ObjID
(
p
,
pRecObj
)
==
Gia_ObjCioId
(
pPO
));
if
(
fTrim
)
if
(
fTrim
)
{
{
...
@@ -992,7 +996,7 @@ void Abc_NtkRecInsertToLookUpTable2(Abc_ManRec_t2* p, int* ppSpot, Gia_Obj_t* pP
...
@@ -992,7 +996,7 @@ void Abc_NtkRecInsertToLookUpTable2(Abc_ManRec_t2* p, int* ppSpot, Gia_Obj_t* pP
}
}
/*
int Abc_NtkRecComputeTruth2( Gia_Obj_t * pObj, Vec_Ptr_t * vTtNodes, int nVars )
int Abc_NtkRecComputeTruth2( Gia_Obj_t * pObj, Vec_Ptr_t * vTtNodes, int nVars )
{
{
unsigned * pTruth, * pTruth0, * pTruth1;
unsigned * pTruth, * pTruth0, * pTruth1;
...
@@ -1010,13 +1014,13 @@ int Abc_NtkRecComputeTruth2( Gia_Obj_t * pObj, Vec_Ptr_t * vTtNodes, int nVars )
...
@@ -1010,13 +1014,13 @@ int Abc_NtkRecComputeTruth2( Gia_Obj_t * pObj, Vec_Ptr_t * vTtNodes, int nVars )
//RetValue = ((pTruth[0] & 1) == pObj->fPhase);
//RetValue = ((pTruth[0] & 1) == pObj->fPhase);
return 1;
return 1;
}
}
*/
void
Abc_NtkRecStart2
(
Gia_Man_t
*
pGia
,
int
nVars
,
int
nCuts
,
int
fTrim
)
void
Abc_NtkRecStart2
(
Gia_Man_t
*
pGia
,
int
nVars
,
int
nCuts
,
int
fTrim
)
{
{
Abc_ManRec_t2
*
p
;
Abc_ManRec_t2
*
p
;
Gia_Obj_t
*
pObj
,
*
pFanin
;
Gia_Obj_t
*
pObj
,
*
pFanin
;
int
*
ppSpot
;
int
*
ppSpot
;
unsigned
*
pTruth
Dst
,
*
pTruthSrc
,
*
pTruth
;
unsigned
*
pTruth
Src
,
*
pTruth
;
//, * pTruthDst
;
int
i
,
j
=
0
;
int
i
,
j
=
0
;
int
clkTotal
=
clock
(),
clk
,
timeInsert
;
int
clkTotal
=
clock
(),
clk
,
timeInsert
;
...
@@ -1044,16 +1048,19 @@ void Abc_NtkRecStart2( Gia_Man_t * pGia, int nVars, int nCuts, int fTrim )
...
@@ -1044,16 +1048,19 @@ void Abc_NtkRecStart2( Gia_Man_t * pGia, int nVars, int nCuts, int fTrim )
if
(
Gia_ManPiNum
(
pGia
)
>
nVars
)
if
(
Gia_ManPiNum
(
pGia
)
>
nVars
)
printf
(
"The starting record has %d inputs (warning only).
\n
"
,
Gia_ManPiNum
(
pGia
)
);
printf
(
"The starting record has %d inputs (warning only).
\n
"
,
Gia_ManPiNum
(
pGia
)
);
}
}
Gia_ManHashStart
(
pGia
);
// Gia_ManHashStart( pGia );
// move this to rec_add2, because if the library is never used for adding new structures
// structural hashing is not needed
if
(
pGia
->
pHTable
!=
NULL
)
Gia_ManHashStop
(
pGia
);
// create the primary inputs
// create the primary inputs
for
(
i
=
Gia_ManPiNum
(
pGia
);
i
<
nVars
;
i
++
)
for
(
i
=
Gia_ManPiNum
(
pGia
);
i
<
nVars
;
i
++
)
{
Gia_ManAppendCi
(
pGia
);
Gia_ManAppendCi
(
pGia
);
}
p
=
ABC_ALLOC
(
Abc_ManRec_t2
,
1
);
p
=
ABC_
C
ALLOC
(
Abc_ManRec_t2
,
1
);
s_pMan
=
p
;
s_pMan
=
p
;
memset
(
p
,
0
,
sizeof
(
Abc_ManRec_t2
)
);
// memset( p, 0, sizeof(Abc_ManRec_t2) ); // no need for this if we use ABC_CALLOC
p
->
pGia
=
pGia
;
p
->
pGia
=
pGia
;
p
->
nVars
=
Gia_ManPiNum
(
pGia
);
p
->
nVars
=
Gia_ManPiNum
(
pGia
);
p
->
nWords
=
Kit_TruthWordNum
(
p
->
nVars
);
p
->
nWords
=
Kit_TruthWordNum
(
p
->
nVars
);
...
@@ -1073,13 +1080,13 @@ void Abc_NtkRecStart2( Gia_Man_t * pGia, int nVars, int nCuts, int fTrim )
...
@@ -1073,13 +1080,13 @@ void Abc_NtkRecStart2( Gia_Man_t * pGia, int nVars, int nCuts, int fTrim )
p
->
vTtElems
->
nCap
=
p
->
nVars
;
p
->
vTtElems
->
nCap
=
p
->
nVars
;
p
->
vTtElems
->
pArray
=
(
void
**
)
Extra_TruthElementary
(
p
->
nVars
);
p
->
vTtElems
->
pArray
=
(
void
**
)
Extra_TruthElementary
(
p
->
nVars
);
p
->
vTtNodes
=
Vec_PtrAlloc
(
1000
);
p
->
vInputs
=
Vec_StrStart
(
1
<<
16
);
p
->
vInputs
=
Vec_StrStart
(
1
<<
16
);
p
->
pMmTruth
=
Mem_FixedStart
(
sizeof
(
unsigned
)
*
p
->
nWords
);
p
->
vUselessPos
=
Vec_IntAlloc
(
1
<<
16
);
p
->
vUselessPos
=
Vec_IntAlloc
(
1
<<
16
);
// p->vTtNodes = Vec_PtrAlloc( 1000 );
for
(
i
=
0
;
i
<
Gia_ManPoNum
(
pGia
);
i
++
)
// p->pMmTruth = Mem_FixedStart( sizeof(unsigned)*p->nWords );
Vec_PtrPush
(
p
->
vTtNodes
,
Mem_FixedEntryFetch
(
p
->
pMmTruth
)
);
// for ( i = 0; i < Gia_ManPoNum(pGia); i++ )
// Vec_PtrPush( p->vTtNodes, Mem_FixedEntryFetch(p->pMmTruth) );
p
->
vTtMem
=
Vec_MemAlloc
(
p
->
nWords
/
2
,
12
);
// 32 KB/page for 6-var functions
// create hash table
// create hash table
//p->nBins = 50011;
//p->nBins = 50011;
...
@@ -1091,8 +1098,9 @@ clk = clock();
...
@@ -1091,8 +1098,9 @@ clk = clock();
Gia_ManForEachPo
(
pGia
,
pObj
,
i
)
Gia_ManForEachPo
(
pGia
,
pObj
,
i
)
{
{
pTruthSrc
=
Gia_ObjComputeTruthTable
(
pGia
,
pObj
);
pTruthSrc
=
Gia_ObjComputeTruthTable
(
pGia
,
pObj
);
pTruthDst
=
(
unsigned
*
)
Vec_PtrEntry
(
p
->
vTtNodes
,
Gia_ObjCioId
(
pObj
)
);
// pTruthDst = (unsigned *)Vec_PtrEntry( p->vTtNodes, Gia_ObjCioId(pObj) );
Kit_TruthCopy
(
pTruthDst
,
pTruthSrc
,
p
->
nVars
);
// Kit_TruthCopy(pTruthDst, pTruthSrc, p->nVars);
Rec_MemSetEntry
(
p
,
Gia_ObjCioId
(
pObj
),
pTruthSrc
);
}
}
p
->
timeTruth
+=
clock
()
-
clk
;
p
->
timeTruth
+=
clock
()
-
clk
;
...
@@ -1106,7 +1114,8 @@ timeInsert = clock();
...
@@ -1106,7 +1114,8 @@ timeInsert = clock();
// mark the nodes with CO fanout.
// mark the nodes with CO fanout.
assert
(
pFanin
->
fMark1
==
0
);
assert
(
pFanin
->
fMark1
==
0
);
pFanin
->
fMark1
=
1
;
pFanin
->
fMark1
=
1
;
pTruth
=
(
unsigned
*
)
Vec_PtrEntry
(
p
->
vTtNodes
,
Gia_ObjCioId
(
pObj
)
);
// pTruth = (unsigned *)Vec_PtrEntry( p->vTtNodes, Gia_ObjCioId(pObj) );
pTruth
=
Rec_MemReadEntry
(
p
,
Gia_ObjCioId
(
pObj
)
);
// add the resulting truth table to the hash table
// add the resulting truth table to the hash table
if
(
p
->
nAddedFuncs
>
2
*
p
->
nBins
)
if
(
p
->
nAddedFuncs
>
2
*
p
->
nBins
)
Abc_NtkRecResizeHash2
(
p
);
Abc_NtkRecResizeHash2
(
p
);
...
@@ -1163,7 +1172,8 @@ for ( i = 0; i < p->nBins; i++ )
...
@@ -1163,7 +1172,8 @@ for ( i = 0; i < p->nBins; i++ )
for
(
entry
=
p
->
pBins
[
i
];
entry
!=
REC_EMPTY_ID
;
entry
=
Rec_Obj
(
p
,
entry
)
->
pCopy
)
for
(
entry
=
p
->
pBins
[
i
];
entry
!=
REC_EMPTY_ID
;
entry
=
Rec_Obj
(
p
,
entry
)
->
pCopy
)
{
{
int
tmp
=
0
;
int
tmp
=
0
;
pTruth
=
(
unsigned
*
)
Vec_PtrEntry
(
p
->
vTtNodes
,
entry
);
// pTruth = (unsigned*)Vec_PtrEntry(p->vTtNodes, entry);
pTruth
=
Rec_MemReadEntry
(
p
,
entry
);
/*if ( (int)Kit_TruthSupport(pTruth, nVars) != (1<<nVars)-1 )
/*if ( (int)Kit_TruthSupport(pTruth, nVars) != (1<<nVars)-1 )
continue;*/
continue;*/
Extra_PrintHex
(
pFile
,
pTruth
,
nVars
);
Extra_PrintHex
(
pFile
,
pTruth
,
nVars
);
...
@@ -1449,7 +1459,7 @@ int Abc_NtkRecAddCut2( If_Man_t * pIfMan, If_Obj_t * pRoot, If_Cut_t * pCut )
...
@@ -1449,7 +1459,7 @@ int Abc_NtkRecAddCut2( If_Man_t * pIfMan, If_Obj_t * pRoot, If_Cut_t * pCut )
Vec_Ptr_t
*
vNodes
=
s_pMan
->
vNodes
;
Vec_Ptr_t
*
vNodes
=
s_pMan
->
vNodes
;
unsigned
*
pInOut
=
s_pMan
->
pTemp1
;
unsigned
*
pInOut
=
s_pMan
->
pTemp1
;
unsigned
*
pTemp
=
s_pMan
->
pTemp2
;
unsigned
*
pTemp
=
s_pMan
->
pTemp2
;
unsigned
*
pTruthSrc
,
*
pTruthDst
;
unsigned
*
pTruthSrc
;
//
, *pTruthDst;
int
objectID
=
0
;
int
objectID
=
0
;
int
i
,
RetValue
,
nNodes
,
nNodesBeg
,
nInputs
=
s_pMan
->
nVars
,
nLeaves
=
If_CutLeaveNum
(
pCut
);
int
i
,
RetValue
,
nNodes
,
nNodesBeg
,
nInputs
=
s_pMan
->
nVars
,
nLeaves
=
If_CutLeaveNum
(
pCut
);
unsigned
uCanonPhase
;
unsigned
uCanonPhase
;
...
@@ -1581,13 +1591,15 @@ s_pMan->timeBuild += clock() - timeBuild;
...
@@ -1581,13 +1591,15 @@ s_pMan->timeBuild += clock() - timeBuild;
assert
(
pObj
->
fMark1
==
0
);
assert
(
pObj
->
fMark1
==
0
);
pObj
->
fMark1
=
1
;
pObj
->
fMark1
=
1
;
if
(
Vec_PtrSize
(
s_pMan
->
vTtNodes
)
<=
Gia_ManPoNum
(
pAig
)
)
// if ( Vec_PtrSize(s_pMan->vTtNodes) <= Gia_ManPoNum(pAig) )
{
// {
while
(
Vec_PtrSize
(
s_pMan
->
vTtNodes
)
<=
Gia_ObjCioId
(
pPO
)
)
// while ( Vec_PtrSize(s_pMan->vTtNodes) <= Gia_ObjCioId(pPO) )
Vec_PtrPush
(
s_pMan
->
vTtNodes
,
Mem_FixedEntryFetch
(
s_pMan
->
pMmTruth
)
);
// Vec_PtrPush( s_pMan->vTtNodes, Mem_FixedEntryFetch(s_pMan->pMmTruth) );
}
// }
pTruthDst
=
(
unsigned
*
)
Vec_PtrEntry
(
s_pMan
->
vTtNodes
,
Gia_ObjCioId
(
pPO
));
Kit_TruthCopy
(
pTruthDst
,
pTruthSrc
,
s_pMan
->
nVars
);
// pTruthDst = (unsigned *)Vec_PtrEntry( s_pMan->vTtNodes, Gia_ObjCioId(pPO));
// Kit_TruthCopy(pTruthDst, pTruthSrc, s_pMan->nVars);
Rec_MemSetEntry
(
s_pMan
,
Gia_ObjCioId
(
pPO
),
pTruthSrc
);
// add the resulting truth table to the hash table
// add the resulting truth table to the hash table
timeInsert
=
clock
();
timeInsert
=
clock
();
...
@@ -1619,7 +1631,11 @@ void Abc_NtkRecAdd2( Abc_Ntk_t * pNtk, int fUseSOPB)
...
@@ -1619,7 +1631,11 @@ void Abc_NtkRecAdd2( Abc_Ntk_t * pNtk, int fUseSOPB)
int
clk
=
clock
();
int
clk
=
clock
();
if
(
Abc_NtkGetChoiceNum
(
pNtk
)
)
if
(
Abc_NtkGetChoiceNum
(
pNtk
)
)
printf
(
"Performing renoding with choices.
\n
"
);
printf
(
"Performing recoding structures with choices.
\n
"
);
// create hash table if not available
if
(
s_pMan
->
pGia
->
pHTable
==
NULL
)
Gia_ManHashStart
(
s_pMan
->
pGia
);
// set defaults
// set defaults
memset
(
pPars
,
0
,
sizeof
(
If_Par_t
)
);
memset
(
pPars
,
0
,
sizeof
(
If_Par_t
)
);
...
@@ -1868,7 +1884,8 @@ int If_CutDelayRecCost2(If_Man_t* p, If_Cut_t* pCut, If_Obj_t * pObj)
...
@@ -1868,7 +1884,8 @@ int If_CutDelayRecCost2(If_Man_t* p, If_Cut_t* pCut, If_Obj_t * pObj)
}
}
s_pMan
->
nFunsFound
++
;
s_pMan
->
nFunsFound
++
;
// make sure the truth table is the same
// make sure the truth table is the same
pTruthRec
=
(
unsigned
*
)
Vec_PtrEntry
(
s_pMan
->
vTtNodes
,
Rec_ObjID
(
s_pMan
,
pCandMin
)
);
// pTruthRec = (unsigned*)Vec_PtrEntry( s_pMan->vTtNodes, Rec_ObjID(s_pMan, pCandMin) );
pTruthRec
=
Rec_MemReadEntry
(
s_pMan
,
Rec_ObjID
(
s_pMan
,
pCandMin
)
);
if
(
!
Kit_TruthIsEqualWithPhase
(
pTruthRec
,
pInOut
,
nLeaves
)
)
if
(
!
Kit_TruthIsEqualWithPhase
(
pTruthRec
,
pInOut
,
nLeaves
)
)
{
{
assert
(
0
);
assert
(
0
);
...
@@ -2045,13 +2062,13 @@ void Abc_NtkRecStop2()
...
@@ -2045,13 +2062,13 @@ void Abc_NtkRecStop2()
assert
(
s_pMan
!=
NULL
);
assert
(
s_pMan
!=
NULL
);
// Abc_NtkRecDumpTruthTables( s_pMan );
// Abc_NtkRecDumpTruthTables( s_pMan );
if
(
s_pMan
->
pGia
)
if
(
s_pMan
->
pGia
)
{
Gia_ManHashStop
(
s_pMan
->
pGia
);
Gia_ManStop
(
s_pMan
->
pGia
);
Gia_ManStop
(
s_pMan
->
pGia
);
}
// Vec_PtrFreeFree( s_pMan->vTtNodes );
// Vec_PtrFreeFree( s_pMan->vTtNodes );
Mem_FixedStop
(
s_pMan
->
pMmTruth
,
0
);
Vec_PtrFree
(
s_pMan
->
vTtNodes
);
// Mem_FixedStop( s_pMan->pMmTruth, 0 );
// Vec_PtrFree( s_pMan->vTtNodes );
Vec_MemFreeP
(
&
s_pMan
->
vTtMem
);
Vec_StrFree
(
s_pMan
->
vInputs
);
Vec_StrFree
(
s_pMan
->
vInputs
);
Vec_PtrFree
(
s_pMan
->
vTtElems
);
Vec_PtrFree
(
s_pMan
->
vTtElems
);
ABC_FREE
(
s_pMan
->
pBins
);
ABC_FREE
(
s_pMan
->
pBins
);
...
@@ -2162,7 +2179,6 @@ void Abc_NtkRecCutTruthFromLib2( Gia_Man_t * pGia2, Vec_Ptr_t * vNodes, int nLea
...
@@ -2162,7 +2179,6 @@ void Abc_NtkRecCutTruthFromLib2( Gia_Man_t * pGia2, Vec_Ptr_t * vNodes, int nLea
assert
(
Kit_TruthSupport
(
pSims
,
nInputs
)
==
Kit_BitMask
(
nLeaves
)
);
assert
(
Kit_TruthSupport
(
pSims
,
nInputs
)
==
Kit_BitMask
(
nLeaves
)
);
}
}
/**Function*************************************************************
/**Function*************************************************************
Synopsis [Adds the cut function to the internal storage.]
Synopsis [Adds the cut function to the internal storage.]
...
@@ -2183,7 +2199,7 @@ void Abc_NtkRecAddFromLib2( Gia_Man_t * pGia2, Gia_Obj_t * pRoot, int nVars )
...
@@ -2183,7 +2199,7 @@ void Abc_NtkRecAddFromLib2( Gia_Man_t * pGia2, Gia_Obj_t * pRoot, int nVars )
Vec_Ptr_t
*
vNodes
=
s_pMan
->
vNodes
;
Vec_Ptr_t
*
vNodes
=
s_pMan
->
vNodes
;
unsigned
*
pInOut
=
s_pMan
->
pTemp1
;
unsigned
*
pInOut
=
s_pMan
->
pTemp1
;
//unsigned * pTemp = s_pMan->pTemp2;
//unsigned * pTemp = s_pMan->pTemp2;
unsigned
*
pTruthSrc
,
*
pTruthDst
;
unsigned
*
pTruthSrc
;
//
, *pTruthDst;
int
objectID
;
int
objectID
;
int
i
,
nNodes
,
nNodesBeg
,
nInputs
=
s_pMan
->
nVars
,
nLeaves
=
nVars
;
int
i
,
nNodes
,
nNodesBeg
,
nInputs
=
s_pMan
->
nVars
,
nLeaves
=
nVars
;
assert
(
nInputs
<=
16
);
assert
(
nInputs
<=
16
);
...
@@ -2241,13 +2257,16 @@ void Abc_NtkRecAddFromLib2( Gia_Man_t * pGia2, Gia_Obj_t * pRoot, int nVars )
...
@@ -2241,13 +2257,16 @@ void Abc_NtkRecAddFromLib2( Gia_Man_t * pGia2, Gia_Obj_t * pRoot, int nVars )
assert
(
pObj
->
fMark1
==
0
);
assert
(
pObj
->
fMark1
==
0
);
pObj
->
fMark1
=
1
;
pObj
->
fMark1
=
1
;
if
(
Vec_PtrSize
(
s_pMan
->
vTtNodes
)
<=
Gia_ManPoNum
(
pGia
)
)
// if ( Vec_PtrSize(s_pMan->vTtNodes) <= Gia_ManPoNum(pGia) )
{
// {
while
(
Vec_PtrSize
(
s_pMan
->
vTtNodes
)
<=
Gia_ObjCioId
(
pPO
)
)
// while ( Vec_PtrSize(s_pMan->vTtNodes) <= Gia_ObjCioId(pPO) )
Vec_PtrPush
(
s_pMan
->
vTtNodes
,
Mem_FixedEntryFetch
(
s_pMan
->
pMmTruth
)
);
// Vec_PtrPush( s_pMan->vTtNodes, Mem_FixedEntryFetch(s_pMan->pMmTruth) );
}
// }
pTruthDst
=
(
unsigned
*
)
Vec_PtrEntry
(
s_pMan
->
vTtNodes
,
Gia_ObjCioId
(
pPO
));
Kit_TruthCopy
(
pTruthDst
,
pTruthSrc
,
s_pMan
->
nVars
);
// pTruthDst = (unsigned *)Vec_PtrEntry( s_pMan->vTtNodes, Gia_ObjCioId(pPO));
// Kit_TruthCopy(pTruthDst, pTruthSrc, s_pMan->nVars);
Rec_MemSetEntry
(
s_pMan
,
Gia_ObjCioId
(
pPO
),
pTruthSrc
);
// add the resulting truth table to the hash table
// add the resulting truth table to the hash table
Abc_NtkRecInsertToLookUpTable2
(
s_pMan
,
ppSpot
,
pPO
,
nLeaves
,
s_pMan
->
fTrim
);
Abc_NtkRecInsertToLookUpTable2
(
s_pMan
,
ppSpot
,
pPO
,
nLeaves
,
s_pMan
->
fTrim
);
return
;
return
;
...
...
src/misc/vec/vecMem.h
0 → 100644
View file @
6df122bd
/**CFile****************************************************************
FileName [vecMem.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Resizable arrays.]
Synopsis [Resizable array of memory pieces.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - July 20, 2012.]
Revision [$Id: vecMem.h,v 1.00 2012/07/20 00:00:00 alanmi Exp $]
***********************************************************************/
#ifndef ABC__misc__vec__vecMem_h
#define ABC__misc__vec__vecMem_h
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include <stdio.h>
ABC_NAMESPACE_HEADER_START
/*
This vector stores pieces of memory of the given size.
It is useful for representing truth tables and any other objects
of the fixed size. It is better that Extra_MmFixed because the
entry IDs can be used as handles to retrieve memory pieces without
the need for an array of pointers from entry IDs into memory pieces
(this can save 8(4) bytes per object on a 64(32)-bit platform).
*/
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// BASIC TYPES ///
////////////////////////////////////////////////////////////////////////
typedef
struct
Vec_Mem_t_
Vec_Mem_t
;
struct
Vec_Mem_t_
{
int
nEntrySize
;
// entry size (in terms of 8-byte words)
int
nEntries
;
// number of entries currently used
int
LogPageSze
;
// log2 of page size (in terms of entries)
int
PageMask
;
// page mask
int
nPageAlloc
;
// number of pages currently allocated
int
iPage
;
// the number of a page currently used
word
**
ppPages
;
// memory pages
};
////////////////////////////////////////////////////////////////////////
/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
#define Vec_MemForEachEntry( vVec, pEntry, i ) \
for ( i = 0; (i < Vec_MemEntryNum(vVec)) && ((pEntry) = Vec_MemReadEntry(vVec, i)); i++ )
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Allocates a memory vector.]
Description [Entry size is in terms of 8-byte words. Page size is log2
of the number of entries on one page.]
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
Vec_Mem_t
*
Vec_MemAlloc
(
int
nEntrySize
,
int
LogPageSze
)
{
Vec_Mem_t
*
p
;
p
=
ABC_CALLOC
(
Vec_Mem_t
,
1
);
p
->
nEntrySize
=
nEntrySize
;
p
->
LogPageSze
=
LogPageSze
;
p
->
PageMask
=
(
1
<<
p
->
LogPageSze
)
-
1
;
p
->
iPage
=
-
1
;
return
p
;
}
static
inline
void
Vec_MemFree
(
Vec_Mem_t
*
p
)
{
int
i
;
for
(
i
=
0
;
i
<=
p
->
iPage
;
i
++
)
ABC_FREE
(
p
->
ppPages
[
i
]
);
ABC_FREE
(
p
->
ppPages
);
ABC_FREE
(
p
);
}
static
inline
void
Vec_MemFreeP
(
Vec_Mem_t
**
p
)
{
if
(
*
p
==
NULL
)
return
;
Vec_MemFree
(
*
p
);
*
p
=
NULL
;
}
static
inline
Vec_Mem_t
*
Vec_MemDup
(
Vec_Mem_t
*
pVec
)
{
Vec_Mem_t
*
p
=
NULL
;
return
p
;
}
/**Function*************************************************************
Synopsis [Duplicates the integer array.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
void
Vec_MemFill
(
Vec_Mem_t
*
pVec
,
int
nEntries
)
{
}
static
inline
void
Vec_MemClean
(
Vec_Mem_t
*
pVec
,
int
nEntries
)
{
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
int
Vec_MemEntrySize
(
Vec_Mem_t
*
p
)
{
return
p
->
nEntrySize
;
}
static
inline
int
Vec_MemEntryNum
(
Vec_Mem_t
*
p
)
{
return
p
->
nEntries
;
}
static
inline
int
Vec_MemPageSize
(
Vec_Mem_t
*
p
)
{
return
p
->
LogPageSze
;
}
static
inline
int
Vec_MemPageNum
(
Vec_Mem_t
*
p
)
{
return
p
->
iPage
+
1
;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
double
Vec_MemMemory
(
Vec_Mem_t
*
p
)
{
return
(
double
)
sizeof
(
word
)
*
p
->
nEntrySize
*
(
1
<<
p
->
LogPageSze
)
*
(
p
->
iPage
+
1
)
+
(
double
)
sizeof
(
word
*
)
*
p
->
nPageAlloc
+
(
double
)
sizeof
(
Vec_Mem_t
);
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
word
*
Vec_MemReadEntry
(
Vec_Mem_t
*
p
,
int
i
)
{
assert
(
i
>=
0
&&
i
<
p
->
nEntries
);
return
p
->
ppPages
[
i
>>
p
->
LogPageSze
]
+
p
->
nEntrySize
*
(
i
&
p
->
PageMask
);
}
static
inline
word
*
Vec_MemReadEntryLast
(
Vec_Mem_t
*
p
)
{
assert
(
p
->
nEntries
>
0
);
return
Vec_MemReadEntry
(
p
,
p
->
nEntries
-
1
);
}
static
inline
void
Vec_MemWriteEntry
(
Vec_Mem_t
*
p
,
int
i
,
word
*
pEntry
)
{
word
*
pPlace
=
Vec_MemReadEntry
(
p
,
i
);
memmove
(
pPlace
,
pEntry
,
sizeof
(
word
)
*
p
->
nEntrySize
);
}
static
inline
word
*
Vec_MemGetEntry
(
Vec_Mem_t
*
p
,
int
i
)
{
assert
(
i
>=
0
);
if
(
i
>=
p
->
nEntries
)
{
int
k
,
iPageNew
=
(
i
>>
p
->
LogPageSze
);
if
(
p
->
iPage
<
iPageNew
)
{
// realloc page pointers if needed
if
(
iPageNew
>=
p
->
nPageAlloc
)
p
->
ppPages
=
ABC_REALLOC
(
word
*
,
p
->
ppPages
,
(
p
->
nPageAlloc
=
p
->
nPageAlloc
?
2
*
p
->
nPageAlloc
:
iPageNew
+
32
)
);
// allocate new pages if needed
for
(
k
=
p
->
iPage
+
1
;
k
<=
iPageNew
;
k
++
)
p
->
ppPages
[
k
]
=
ABC_ALLOC
(
word
,
p
->
nEntrySize
*
(
1
<<
p
->
LogPageSze
)
);
// update page counter
p
->
iPage
=
iPageNew
;
}
// update entry counter
p
->
nEntries
=
i
+
1
;
}
return
Vec_MemReadEntry
(
p
,
i
);
}
static
inline
void
Vec_MemSetEntry
(
Vec_Mem_t
*
p
,
int
i
,
word
*
pEntry
)
{
word
*
pPlace
=
Vec_MemGetEntry
(
p
,
i
);
memmove
(
pPlace
,
pEntry
,
sizeof
(
word
)
*
p
->
nEntrySize
);
}
static
inline
void
Vec_MemPush
(
Vec_Mem_t
*
p
,
word
*
pEntry
)
{
word
*
pPlace
=
Vec_MemGetEntry
(
p
,
p
->
nEntries
);
memmove
(
pPlace
,
pEntry
,
sizeof
(
word
)
*
p
->
nEntrySize
);
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
void
Vec_MemShrink
(
Vec_Mem_t
*
p
,
int
nEntriesNew
)
{
int
i
,
iPageOld
=
p
->
iPage
;
assert
(
nEntriesNew
<=
p
->
nEntries
);
p
->
nEntries
=
nEntriesNew
;
p
->
iPage
=
(
nEntriesNew
>>
p
->
LogPageSze
);
for
(
i
=
p
->
iPage
+
1
;
i
<=
iPageOld
;
i
++
)
ABC_FREE
(
p
->
ppPages
[
i
]
);
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
void
Vec_MemPrint
(
Vec_Mem_t
*
vVec
)
{
word
*
pEntry
;
int
i
;
printf
(
"Memory vector has %d entries: "
,
Vec_MemEntryNum
(
vVec
)
);
Vec_MemForEachEntry
(
vVec
,
pEntry
,
i
)
{
printf
(
"%3d : "
,
i
);
// add printout here
printf
(
"
\n
"
);
}
}
ABC_NAMESPACE_HEADER_END
#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment