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
ecda331a
Commit
ecda331a
authored
Sep 14, 2021
by
Alan Mishchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Various changes.
parent
c5572722
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
180 additions
and
10 deletions
+180
-10
src/aig/gia/gia.h
+9
-1
src/aig/gia/giaResub.c
+126
-0
src/base/acb/acbFunc.c
+16
-9
src/misc/vec/vecInt.h
+6
-0
src/misc/vec/vecWec.h
+23
-0
No files found.
src/aig/gia/gia.h
View file @
ecda331a
...
...
@@ -482,6 +482,8 @@ static inline void Gia_ObjSetValue( Gia_Obj_t * pObj, int i ) {
static
inline
int
Gia_ObjPhase
(
Gia_Obj_t
*
pObj
)
{
return
pObj
->
fPhase
;
}
static
inline
int
Gia_ObjPhaseReal
(
Gia_Obj_t
*
pObj
)
{
return
Gia_Regular
(
pObj
)
->
fPhase
^
Gia_IsComplement
(
pObj
);
}
static
inline
int
Gia_ObjPhaseDiff
(
Gia_Man_t
*
p
,
int
i
,
int
k
)
{
return
Gia_ManObj
(
p
,
i
)
->
fPhase
^
Gia_ManObj
(
p
,
k
)
->
fPhase
;
}
static
inline
char
*
Gia_ObjCiName
(
Gia_Man_t
*
p
,
int
i
)
{
return
p
->
vNamesIn
?
(
char
*
)
Vec_PtrEntry
(
p
->
vNamesIn
,
i
)
:
NULL
;
}
static
inline
char
*
Gia_ObjCoName
(
Gia_Man_t
*
p
,
int
i
)
{
return
p
->
vNamesOut
?
(
char
*
)
Vec_PtrEntry
(
p
->
vNamesOut
,
i
)
:
NULL
;
}
static
inline
char
*
Gia_ObjName
(
Gia_Man_t
*
p
,
int
i
)
{
return
p
->
vNamesNode
?
(
char
*
)
Vec_PtrEntry
(
p
->
vNamesNode
,
i
)
:
NULL
;
}
static
inline
char
*
Gia_ObjNameObj
(
Gia_Man_t
*
p
,
Gia_Obj_t
*
pObj
)
{
return
p
->
vNamesNode
?
(
char
*
)
Vec_PtrEntry
(
p
->
vNamesNode
,
Gia_ObjId
(
p
,
pObj
))
:
NULL
;
}
...
...
@@ -1161,7 +1163,13 @@ static inline int Gia_ObjCellId( Gia_Man_t * p, int iLit ) { re
for ( i = 1; (i < p->nObjs) && ((pObj) = Gia_ManObj(p, i)); i++ )
#define Gia_ManForEachObjVec( vVec, p, pObj, i ) \
for ( i = 0; (i < Vec_IntSize(vVec)) && ((pObj) = Gia_ManObj(p, Vec_IntEntry(vVec,i))); i++ )
#define Gia_ManForEachObjVecReverse( vVec, p, pObj, i ) \
#define Gia_ManForEachObjVecStart( vVec, p, pObj, i, Start ) \
for ( i = Start; (i < Vec_IntSize(vVec)) && ((pObj) = Gia_ManObj(p, Vec_IntEntry(vVec,i))); i++ )
#define Gia_ManForEachObjVecStop( vVec, p, pObj, i, Stop ) \
for ( i = 0; (i < Stop) && ((pObj) = Gia_ManObj(p, Vec_IntEntry(vVec,i))); i++ )
#define Gia_ManForEachObjVecStartStop( vVec, p, pObj, i, Start, Stop ) \
for ( i = Start; (i < Stop) && ((pObj) = Gia_ManObj(p, Vec_IntEntry(vVec,i))); i++ )
#define Gia_ManForEachObjVecReverse( vVec, p, pObj, i ) \
for ( i = Vec_IntSize(vVec) - 1; (i >= 0) && ((pObj) = Gia_ManObj(p, Vec_IntEntry(vVec,i))); i-- )
#define Gia_ManForEachObjVecLit( vVec, p, pObj, fCompl, i ) \
for ( i = 0; (i < Vec_IntSize(vVec)) && ((pObj) = Gia_ManObj(p, Abc_Lit2Var(Vec_IntEntry(vVec,i)))) && (((fCompl) = Abc_LitIsCompl(Vec_IntEntry(vVec,i))),1); i++ )
...
...
src/aig/gia/giaResub.c
View file @
ecda331a
...
...
@@ -1888,6 +1888,132 @@ void Gia_ManTryResub( Gia_Man_t * p )
}
/**Function*************************************************************
Synopsis [Deriving a subset.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int
Gia_ManDeriveShrink
(
Vec_Wrd_t
*
vFuncs
,
int
nWords
)
{
int
i
,
k
=
0
,
nFuncs
=
Vec_WrdSize
(
vFuncs
)
/
nWords
/
2
;
assert
(
2
*
nFuncs
*
nWords
==
Vec_WrdSize
(
vFuncs
)
);
for
(
i
=
0
;
i
<
nFuncs
;
i
++
)
{
word
*
pFunc0
=
Vec_WrdEntryP
(
vFuncs
,
(
2
*
i
+
0
)
*
nWords
);
word
*
pFunc1
=
Vec_WrdEntryP
(
vFuncs
,
(
2
*
i
+
1
)
*
nWords
);
if
(
Abc_TtIsConst0
(
pFunc0
,
nWords
)
||
Abc_TtIsConst0
(
pFunc1
,
nWords
)
)
continue
;
if
(
k
<
i
)
Abc_TtCopy
(
Vec_WrdEntryP
(
vFuncs
,
(
2
*
k
+
0
)
*
nWords
),
pFunc0
,
nWords
,
0
);
if
(
k
<
i
)
Abc_TtCopy
(
Vec_WrdEntryP
(
vFuncs
,
(
2
*
k
+
1
)
*
nWords
),
pFunc1
,
nWords
,
0
);
k
++
;
}
Vec_WrdShrink
(
vFuncs
,
2
*
k
*
nWords
);
return
k
;
}
void
Gia_ManDeriveCounts
(
Vec_Wrd_t
*
vFuncs
,
int
nWords
,
Vec_Int_t
*
vCounts
)
{
int
i
,
nFuncs
=
Vec_WrdSize
(
vFuncs
)
/
nWords
/
2
;
assert
(
2
*
nFuncs
*
nWords
==
Vec_WrdSize
(
vFuncs
)
);
Vec_IntClear
(
vCounts
);
for
(
i
=
0
;
i
<
2
*
nFuncs
;
i
++
)
Vec_IntPush
(
vCounts
,
Abc_TtCountOnesVec
(
Vec_WrdEntryP
(
vFuncs
,
i
*
nWords
),
nWords
)
);
}
int
Gia_ManDeriveCost
(
Vec_Wrd_t
*
vFuncs
,
int
nWords
,
word
*
pMask
,
Vec_Int_t
*
vCounts
)
{
int
i
,
Res
=
0
,
nFuncs
=
Vec_WrdSize
(
vFuncs
)
/
nWords
/
2
;
assert
(
2
*
nFuncs
*
nWords
==
Vec_WrdSize
(
vFuncs
)
);
assert
(
Vec_IntSize
(
vCounts
)
*
nWords
==
Vec_WrdSize
(
vFuncs
)
);
for
(
i
=
0
;
i
<
nFuncs
;
i
++
)
{
int
Total
[
2
]
=
{
Vec_IntEntry
(
vCounts
,
2
*
i
+
0
),
Vec_IntEntry
(
vCounts
,
2
*
i
+
1
)
};
int
This
[
2
]
=
{
Abc_TtCountOnesVecMask
(
Vec_WrdEntryP
(
vFuncs
,
(
2
*
i
+
0
)
*
nWords
),
pMask
,
nWords
,
0
),
Abc_TtCountOnesVecMask
(
Vec_WrdEntryP
(
vFuncs
,
(
2
*
i
+
1
)
*
nWords
),
pMask
,
nWords
,
0
)
};
assert
(
Total
[
0
]
>=
This
[
0
]
&&
Total
[
1
]
>=
This
[
1
]
);
Res
+=
This
[
0
]
*
This
[
1
]
+
(
Total
[
0
]
-
This
[
0
])
*
(
Total
[
1
]
-
This
[
1
]);
}
return
Res
;
}
int
Gia_ManDeriveSimpleCost
(
Vec_Int_t
*
vCounts
)
{
int
i
,
Ent1
,
Ent2
,
Res
=
0
;
Vec_IntForEachEntryDouble
(
vCounts
,
Ent1
,
Ent2
,
i
)
Res
+=
Ent1
*
Ent2
;
return
Res
;
}
void
Gia_ManDeriveNext
(
Vec_Wrd_t
*
vFuncs
,
int
nWords
,
word
*
pMask
)
{
int
i
,
iStop
=
Vec_WrdSize
(
vFuncs
);
word
Data
;
int
nFuncs
=
Vec_WrdSize
(
vFuncs
)
/
nWords
/
2
;
assert
(
2
*
nFuncs
*
nWords
==
Vec_WrdSize
(
vFuncs
)
);
Vec_WrdForEachEntryStop
(
vFuncs
,
Data
,
i
,
iStop
)
Vec_WrdPush
(
vFuncs
,
Data
);
for
(
i
=
0
;
i
<
nFuncs
;
i
++
)
{
word
*
pFunc0n
=
Vec_WrdEntryP
(
vFuncs
,
(
2
*
i
+
0
)
*
nWords
);
word
*
pFunc1n
=
Vec_WrdEntryP
(
vFuncs
,
(
2
*
i
+
1
)
*
nWords
);
word
*
pFunc0p
=
Vec_WrdEntryP
(
vFuncs
,
(
2
*
i
+
0
)
*
nWords
+
iStop
);
word
*
pFunc1p
=
Vec_WrdEntryP
(
vFuncs
,
(
2
*
i
+
1
)
*
nWords
+
iStop
);
Abc_TtAnd
(
pFunc0p
,
pFunc0n
,
pMask
,
nWords
,
0
);
Abc_TtAnd
(
pFunc1p
,
pFunc1n
,
pMask
,
nWords
,
0
);
Abc_TtSharp
(
pFunc0n
,
pFunc0n
,
pMask
,
nWords
);
Abc_TtSharp
(
pFunc1n
,
pFunc1n
,
pMask
,
nWords
);
}
}
Vec_Int_t
*
Gia_ManDeriveSubset
(
Gia_Man_t
*
p
,
Vec_Wrd_t
*
vFuncs
,
Vec_Int_t
*
vObjs
,
Vec_Wrd_t
*
vSims
,
int
nWords
,
int
fVerbose
)
{
int
i
,
k
,
iObj
,
CostBestPrev
,
nFuncs
=
Vec_WrdSize
(
vFuncs
)
/
nWords
;
Vec_Int_t
*
vRes
=
Vec_IntAlloc
(
100
);
Vec_Int_t
*
vCounts
=
Vec_IntAlloc
(
nFuncs
*
2
);
Vec_Wrd_t
*
vFSims
=
Vec_WrdDup
(
vFuncs
);
assert
(
nFuncs
*
nWords
==
Vec_WrdSize
(
vFuncs
)
);
assert
(
Gia_ManObjNum
(
p
)
*
nWords
==
Vec_WrdSize
(
vSims
)
);
assert
(
Vec_IntSize
(
vObjs
)
<=
Gia_ManCandNum
(
p
)
);
nFuncs
=
Gia_ManDeriveShrink
(
vFSims
,
nWords
);
Gia_ManDeriveCounts
(
vFSims
,
nWords
,
vCounts
);
assert
(
Vec_IntSize
(
vCounts
)
*
nWords
==
Vec_WrdSize
(
vFSims
)
);
CostBestPrev
=
Gia_ManDeriveSimpleCost
(
vCounts
);
if
(
fVerbose
)
printf
(
"Processing %d functions and %d objects with cost %d
\n
"
,
nFuncs
,
Vec_IntSize
(
vObjs
),
CostBestPrev
);
for
(
i
=
0
;
nFuncs
>
0
;
i
++
)
{
int
iObjBest
=
-
1
,
CountThis
,
Count0
=
ABC_INFINITY
,
CountBest
=
ABC_INFINITY
;
Vec_IntForEachEntry
(
vObjs
,
iObj
,
k
)
{
if
(
Vec_IntFind
(
vRes
,
iObj
)
>=
0
)
continue
;
CountThis
=
Gia_ManDeriveCost
(
vFSims
,
nWords
,
Vec_WrdEntryP
(
vSims
,
iObj
*
nWords
),
vCounts
);
if
(
CountBest
>
CountThis
)
{
CountBest
=
CountThis
;
iObjBest
=
iObj
;
}
if
(
!
k
)
Count0
=
CountThis
;
}
if
(
Count0
<
CostBestPrev
)
{
CountBest
=
Count0
;
iObjBest
=
Vec_IntEntry
(
vObjs
,
0
);
}
Gia_ManDeriveNext
(
vFSims
,
nWords
,
Vec_WrdEntryP
(
vSims
,
iObjBest
*
nWords
)
);
nFuncs
=
Gia_ManDeriveShrink
(
vFSims
,
nWords
);
Gia_ManDeriveCounts
(
vFSims
,
nWords
,
vCounts
);
assert
(
CountBest
==
Gia_ManDeriveSimpleCost
(
vCounts
)
);
Vec_IntPush
(
vRes
,
iObjBest
);
CostBestPrev
=
CountBest
;
if
(
fVerbose
)
printf
(
"Iter %2d : Funcs = %6d. Object %6d. Cost %6d.
\n
"
,
i
,
nFuncs
,
iObjBest
,
CountBest
);
}
Vec_IntFree
(
vCounts
);
Vec_WrdFree
(
vFSims
);
return
vRes
;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
...
...
src/base/acb/acbFunc.c
View file @
ecda331a
...
...
@@ -472,6 +472,8 @@ Gia_Man_t * Gia_FileSimpleParse( Vec_Int_t * vBuffer, Abc_Nam_t * pNames, int fN
Vec_IntPush
(
vTypes
,
Vec_IntSize
(
vFanins
)
);
vCur
=
vFanins
;
}
else
if
(
pFileW
&&
vCur
==
vWires
&&
Abc_NamStr
(
pNames
,
Token
)[
0
]
==
't'
)
Vec_IntPush
(
vInputs
,
Token
);
else
Vec_IntPush
(
vCur
,
Token
);
}
...
...
@@ -526,7 +528,7 @@ Gia_Man_t * Gia_FileSimpleParse( Vec_Int_t * vBuffer, Abc_Nam_t * pNames, int fN
pNew
->
vNamesOut
=
Vec_PtrAlloc
(
Vec_IntSize
(
vOutputs
)
);
Vec_IntForEachEntry
(
vOutputs
,
Token
,
i
)
Vec_PtrPush
(
pNew
->
vNamesOut
,
Abc_UtilStrsav
(
Abc_NamStr
(
pNames
,
Token
))
);
if
(
pFileW
)
if
(
pFileW
&&
fNames
)
{
extern
Vec_Int_t
*
Acb_ReadWeightMap
(
char
*
pFileName
,
Abc_Nam_t
*
pNames
);
Vec_Int_t
*
vT2W
=
Acb_ReadWeightMap
(
pFileW
,
pNames
);
...
...
@@ -618,7 +620,7 @@ char ** Acb_PrepareNames( Abc_Nam_t * p )
Acb_Ntk_t
*
Acb_VerilogSimpleRead
(
char
*
pFileName
,
char
*
pFileNameW
)
{
extern
Acb_Ntk_t
*
Acb_NtkFromNdr
(
char
*
pFileName
,
void
*
pModule
,
Abc_Nam_t
*
pNames
,
Vec_Int_t
*
vWeights
,
int
nNameIdMax
);
Acb_Ntk_t
*
pNtk
;
//char ** ppNames;
Acb_Ntk_t
*
pNtk
;
Abc_Nam_t
*
pNames
=
Acb_VerilogStartNames
();
Vec_Int_t
*
vBuffer
=
Acb_VerilogSimpleLex
(
pFileName
,
pNames
);
void
*
pModule
=
vBuffer
?
Acb_VerilogSimpleParse
(
vBuffer
,
pNames
)
:
NULL
;
...
...
@@ -633,9 +635,12 @@ Acb_Ntk_t * Acb_VerilogSimpleRead( char * pFileName, char * pFileNameW )
printf
(
"Cannot read weight file
\"
%s
\"
.
\n
"
,
pFileNameW
);
return
NULL
;
}
//ppNames = Acb_PrepareNames(pNames);
//Ndr_WriteVerilog( Extra_FileNameGenericAppend(pFileName, "_ndr.v"), pModule, ppNames, 1 );
//ABC_FREE( ppNames );
if
(
0
)
{
char
**
ppNames
=
Acb_PrepareNames
(
pNames
);
Ndr_WriteVerilog
(
Extra_FileNameGenericAppend
(
pFileName
,
"_ndr.v"
),
pModule
,
ppNames
,
1
);
ABC_FREE
(
ppNames
);
}
pNtk
=
Acb_NtkFromNdr
(
pFileName
,
pModule
,
pNames
,
vWeights
,
Abc_NamObjNumMax
(
pNames
)
);
Ndr_Delete
(
pModule
);
Vec_IntFree
(
vBuffer
);
...
...
@@ -2391,7 +2396,7 @@ Vec_Str_t * Acb_GeneratePatch2( Gia_Man_t * pGia, Vec_Ptr_t * vIns, Vec_Ptr_t *
extern
Vec_Wec_t
*
Abc_GiaSynthesize
(
Vec_Ptr_t
*
vGias
,
Gia_Man_t
*
pMulti
);
Vec_Wec_t
*
vGates
=
Abc_GiaSynthesize
(
NULL
,
pGia
);
Vec_Int_t
*
vGate
;
int
nIns
=
Vec_PtrSize
(
vIns
),
nOuts
=
Vec_PtrSize
(
vOuts
);
char
*
pName
;
int
i
,
k
,
iObj
,
nWires
=
Vec_WecSize
(
vGates
)
-
nIns
-
nOuts
,
fFirst
=
1
;
int
i
,
k
,
iObj
,
nWires
=
Vec_WecSize
(
vGates
)
-
nIns
-
nOuts
,
nTwoIns
=
0
,
fFirst
=
1
;
Vec_Ptr_t
*
vNames
=
Acb_GenerateSignalNames2
(
vGates
,
vIns
,
vOuts
);
Vec_Str_t
*
vStr
=
Vec_StrAlloc
(
100
);
...
...
@@ -2400,7 +2405,7 @@ Vec_Str_t * Acb_GeneratePatch2( Gia_Man_t * pGia, Vec_Ptr_t * vIns, Vec_Ptr_t *
Vec_PtrForEachEntry
(
char
*
,
vOuts
,
pName
,
i
)
Vec_StrPrintF
(
vStr
,
"%s %s"
,
i
?
","
:
""
,
pName
);
Vec_PtrForEachEntry
(
char
*
,
vIns
,
pName
,
i
)
Vec_StrPrintF
(
vStr
,
", %s"
,
pName
);
Vec_StrPrintF
(
vStr
,
", %s
%s"
,
i
?
""
:
"
"
,
pName
);
Vec_StrAppend
(
vStr
,
" );
\n\n
"
);
Vec_StrAppend
(
vStr
,
" output"
);
...
...
@@ -2422,8 +2427,9 @@ Vec_Str_t * Acb_GeneratePatch2( Gia_Man_t * pGia, Vec_Ptr_t * vIns, Vec_Ptr_t *
if
(
!
strncmp
(
pName
,
"ww"
,
2
)
)
Vec_StrPrintF
(
vStr
,
"%s %s"
,
fFirst
?
""
:
","
,
pName
),
fFirst
=
0
;
}
Vec_StrAppend
(
vStr
,
";
\n
\n
"
);
Vec_StrAppend
(
vStr
,
";
\n
"
);
}
Vec_StrAppend
(
vStr
,
"
\n
"
);
// create internal nodes
Vec_WecForEachLevelStartStop
(
vGates
,
vGate
,
i
,
nIns
,
nIns
+
nWires
)
...
...
@@ -2434,6 +2440,7 @@ Vec_Str_t * Acb_GeneratePatch2( Gia_Man_t * pGia, Vec_Ptr_t * vIns, Vec_Ptr_t *
Vec_IntForEachEntryStart
(
vGate
,
iObj
,
k
,
1
)
Vec_StrPrintF
(
vStr
,
"%s %s"
,
k
>
1
?
","
:
""
,
(
char
*
)
Vec_PtrEntry
(
vNames
,
iObj
)
);
Vec_StrAppend
(
vStr
,
" );
\n
"
);
nTwoIns
+=
Vec_IntSize
(
vGate
)
-
3
;
}
else
{
...
...
@@ -2449,7 +2456,7 @@ Vec_Str_t * Acb_GeneratePatch2( Gia_Man_t * pGia, Vec_Ptr_t * vIns, Vec_Ptr_t *
Vec_PtrFreeFree
(
vNames
);
Vec_WecFree
(
vGates
);
printf
(
"Synthesized patch with %d inputs, %d outputs and %d gates
.
\n
"
,
nIns
,
nOuts
,
nWire
s
);
printf
(
"Synthesized patch with %d inputs, %d outputs and %d gates
(including %d two-input gates).
\n
"
,
nIns
,
nOuts
,
nWires
,
nTwoIn
s
);
return
vStr
;
}
void
Acb_GenerateFile2
(
Gia_Man_t
*
pGia
,
Vec_Ptr_t
*
vIns
,
Vec_Ptr_t
*
vOuts
,
char
*
pFileName
,
char
*
pFileNameOut
,
int
fSkipMffc
)
...
...
src/misc/vec/vecInt.h
View file @
ecda331a
...
...
@@ -780,6 +780,12 @@ static inline void Vec_IntPushArray( Vec_Int_t * p, int * pEntries, int nEntries
for
(
i
=
0
;
i
<
nEntries
;
i
++
)
Vec_IntPush
(
p
,
pEntries
[
i
]
);
}
static
inline
void
Vec_IntShift
(
Vec_Int_t
*
p
,
int
Shift
)
{
p
->
nSize
-=
Shift
;
p
->
nCap
-=
Shift
;
p
->
pArray
+=
Shift
;
}
/**Function*************************************************************
...
...
src/misc/vec/vecWec.h
View file @
ecda331a
...
...
@@ -559,6 +559,29 @@ static inline void Vec_WecSortByLastInt( Vec_Wec_t * p, int fReverse )
SeeAlso []
***********************************************************************/
static
inline
void
Vec_WecKeepLevels
(
Vec_Wec_t
*
p
,
int
Limit
)
{
Vec_Int_t
*
vLevel
;
int
i
,
k
=
0
;
Vec_WecForEachLevel
(
p
,
vLevel
,
i
)
if
(
Vec_IntSize
(
vLevel
)
>
Limit
)
{
ABC_SWAP
(
Vec_Int_t
,
Vec_WecArray
(
p
)[
i
],
Vec_WecArray
(
p
)[
k
]
);
k
++
;
}
Vec_WecShrink
(
p
,
k
);
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
void
Vec_WecPrint
(
Vec_Wec_t
*
p
,
int
fSkipSingles
)
{
Vec_Int_t
*
vVec
;
...
...
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