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
6d0214ed
Commit
6d0214ed
authored
Jul 30, 2016
by
Mathias Soeken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract solution into intermediate format.
parent
0b01f5ec
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
163 additions
and
125 deletions
+163
-125
src/base/abci/abcExact.c
+163
-125
No files found.
src/base/abci/abcExact.c
View file @
6d0214ed
...
...
@@ -60,9 +60,9 @@ struct Ses_Man_t_
int
nSpecFunc
;
/* number of functions to synthesize */
int
nRows
;
/* number of rows in the specification (without 0) */
int
nMaxDepth
;
/* maximum depth (-1 if depth is not constrained) */
int
*
pArr
ivalTimes
;
/* arrival times of inputs (NULL if arrival times are ignored) */
int
nArr
ivalDelta
;
/* delta to the original arrival times (arrival times are normalized to have 0 as minimum element) */
int
nArr
ivalMax
;
/* maximum normalized arrival time */
int
*
pArr
TimeProfile
;
/* arrival times of inputs (NULL if arrival times are ignored) */
int
nArr
TimeDelta
;
/* delta to the original arrival times (arrival times are normalized to have 0 as minimum element) */
int
nArr
TimeMax
;
/* maximum normalized arrival time */
int
nBTLimit
;
/* conflict limit */
int
fMakeAIG
;
/* create AIG instead of general network */
int
fVerbose
;
/* be verbose */
...
...
@@ -91,9 +91,9 @@ struct Ses_Man_t_
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
int
NormalizeArrivalTimes
(
int
*
pArr
ivalTimes
,
int
nVars
,
int
*
maxNormalized
)
int
NormalizeArrivalTimes
(
int
*
pArr
TimeProfile
,
int
nVars
,
int
*
maxNormalized
)
{
int
*
p
=
pArr
ivalTimes
,
*
pEnd
=
pArrivalTimes
+
nVars
;
int
*
p
=
pArr
TimeProfile
,
*
pEnd
=
pArrTimeProfile
+
nVars
;
int
delta
=
*
p
;
while
(
++
p
<
pEnd
)
...
...
@@ -101,7 +101,7 @@ int NormalizeArrivalTimes( int * pArrivalTimes, int nVars, int * maxNormalized )
delta
=
*
p
;
*
maxNormalized
=
0
;
p
=
pArr
ivalTimes
;
p
=
pArr
TimeProfile
;
while
(
p
<
pEnd
)
{
*
p
-=
delta
;
...
...
@@ -115,7 +115,7 @@ int NormalizeArrivalTimes( int * pArrivalTimes, int nVars, int * maxNormalized )
return
delta
;
}
static
inline
Ses_Man_t
*
Ses_ManAlloc
(
word
*
pTruth
,
int
nVars
,
int
nFunc
,
int
nMaxDepth
,
int
*
pArr
ivalTimes
,
int
fMakeAIG
,
int
fVerbose
)
static
inline
Ses_Man_t
*
Ses_ManAlloc
(
word
*
pTruth
,
int
nVars
,
int
nFunc
,
int
nMaxDepth
,
int
*
pArr
TimeProfile
,
int
fMakeAIG
,
int
fVerbose
)
{
int
h
,
i
;
...
...
@@ -134,11 +134,11 @@ static inline Ses_Man_t * Ses_ManAlloc( word * pTruth, int nVars, int nFunc, int
p
->
nSpecFunc
=
nFunc
;
p
->
nRows
=
(
1
<<
nVars
)
-
1
;
p
->
nMaxDepth
=
nMaxDepth
;
p
->
pArr
ivalTimes
=
nMaxDepth
>=
0
?
pArrivalTimes
:
NULL
;
if
(
p
->
pArr
ivalTimes
)
p
->
nArr
ivalDelta
=
NormalizeArrivalTimes
(
p
->
pArrivalTimes
,
nVars
,
&
p
->
nArrival
Max
);
p
->
pArr
TimeProfile
=
nMaxDepth
>=
0
?
pArrTimeProfile
:
NULL
;
if
(
p
->
pArr
TimeProfile
)
p
->
nArr
TimeDelta
=
NormalizeArrivalTimes
(
p
->
pArrTimeProfile
,
nVars
,
&
p
->
nArrTime
Max
);
else
p
->
nArr
ivalDelta
=
p
->
nArrival
Max
=
0
;
p
->
nArr
TimeDelta
=
p
->
nArrTime
Max
=
0
;
p
->
fMakeAIG
=
fMakeAIG
;
p
->
nBTLimit
=
nMaxDepth
>=
0
?
50000
:
0
;
p
->
fVerbose
=
fVerbose
;
...
...
@@ -155,9 +155,9 @@ static inline void Ses_ManClean( Ses_Man_t * pSes )
for
(
i
=
0
;
i
<
4
;
++
i
)
pSes
->
pSpec
[(
h
<<
2
)
+
i
]
=
~
(
pSes
->
pSpec
[(
h
<<
2
)
+
i
]
);
if
(
pSes
->
pArr
ivalTimes
)
if
(
pSes
->
pArr
TimeProfile
)
for
(
i
=
0
;
i
<
pSes
->
nSpecVars
;
++
i
)
pSes
->
pArr
ivalTimes
[
i
]
+=
pSes
->
nArrival
Delta
;
pSes
->
pArr
TimeProfile
[
i
]
+=
pSes
->
nArrTime
Delta
;
if
(
pSes
->
pSat
)
sat_solver_delete
(
pSes
->
pSat
);
...
...
@@ -215,9 +215,9 @@ static inline int Ses_ManSelectVar( Ses_Man_t * pSes, int i, int j, int k )
static
inline
int
Ses_ManDepthVar
(
Ses_Man_t
*
pSes
,
int
i
,
int
j
)
{
assert
(
i
<
pSes
->
nGates
);
assert
(
j
<=
pSes
->
nArr
ival
Max
+
i
);
assert
(
j
<=
pSes
->
nArr
Time
Max
+
i
);
return
pSes
->
nDepthOffset
+
i
*
pSes
->
nArr
ival
Max
+
(
(
i
*
(
i
+
1
)
)
/
2
)
+
j
;
return
pSes
->
nDepthOffset
+
i
*
pSes
->
nArr
Time
Max
+
(
(
i
*
(
i
+
1
)
)
/
2
)
+
j
;
}
/**Function*************************************************************
...
...
@@ -241,7 +241,7 @@ static void Ses_ManCreateVars( Ses_Man_t * pSes, int nGates )
pSes
->
nSelectVars
=
0
;
for
(
i
=
pSes
->
nSpecVars
;
i
<
pSes
->
nSpecVars
+
nGates
;
++
i
)
pSes
->
nSelectVars
+=
(
i
*
(
i
-
1
)
)
/
2
;
pSes
->
nDepthVars
=
pSes
->
nMaxDepth
>
0
?
nGates
*
pSes
->
nArr
ival
Max
+
(
nGates
*
(
nGates
+
1
)
)
/
2
:
0
;
pSes
->
nDepthVars
=
pSes
->
nMaxDepth
>
0
?
nGates
*
pSes
->
nArr
Time
Max
+
(
nGates
*
(
nGates
+
1
)
)
/
2
:
0
;
pSes
->
nOutputOffset
=
pSes
->
nSimVars
;
pSes
->
nGateOffset
=
pSes
->
nSimVars
+
pSes
->
nOutputVars
;
...
...
@@ -440,7 +440,7 @@ static void Ses_ManCreateClauses( Ses_Man_t * pSes )
for
(
j
=
0
;
j
<
k
;
++
j
)
{
pLits
[
0
]
=
Abc_Var2Lit
(
Ses_ManSelectVar
(
pSes
,
i
,
pSes
->
nSpecVars
+
j
,
pSes
->
nSpecVars
+
k
),
1
);
for
(
jj
=
0
;
jj
<=
pSes
->
nArr
ival
Max
+
j
;
++
jj
)
for
(
jj
=
0
;
jj
<=
pSes
->
nArr
Time
Max
+
j
;
++
jj
)
{
pLits
[
1
]
=
Abc_Var2Lit
(
Ses_ManDepthVar
(
pSes
,
j
,
jj
),
1
);
pLits
[
2
]
=
Abc_Var2Lit
(
Ses_ManDepthVar
(
pSes
,
i
,
jj
+
1
),
0
);
...
...
@@ -452,7 +452,7 @@ static void Ses_ManCreateClauses( Ses_Man_t * pSes )
for
(
j
=
0
;
j
<
pSes
->
nSpecVars
+
k
;
++
j
)
{
pLits
[
0
]
=
Abc_Var2Lit
(
Ses_ManSelectVar
(
pSes
,
i
,
j
,
pSes
->
nSpecVars
+
k
),
1
);
for
(
kk
=
0
;
kk
<=
pSes
->
nArr
ival
Max
+
k
;
++
kk
)
for
(
kk
=
0
;
kk
<=
pSes
->
nArr
Time
Max
+
k
;
++
kk
)
{
pLits
[
1
]
=
Abc_Var2Lit
(
Ses_ManDepthVar
(
pSes
,
k
,
kk
),
1
);
pLits
[
2
]
=
Abc_Var2Lit
(
Ses_ManDepthVar
(
pSes
,
i
,
kk
+
1
),
0
);
...
...
@@ -461,14 +461,14 @@ static void Ses_ManCreateClauses( Ses_Man_t * pSes )
}
/* propagate depths from arrival times at PIs */
if
(
pSes
->
pArr
ivalTimes
)
if
(
pSes
->
pArr
TimeProfile
)
{
for
(
k
=
1
;
k
<
pSes
->
nSpecVars
+
i
;
++
k
)
for
(
j
=
0
;
j
<
(
(
k
<
pSes
->
nSpecVars
)
?
k
:
pSes
->
nSpecVars
);
++
j
)
{
d
=
pSes
->
pArr
ivalTimes
[
j
];
if
(
k
<
pSes
->
nSpecVars
&&
pSes
->
pArr
ivalTimes
[
k
]
>
d
)
d
=
pSes
->
pArr
ivalTimes
[
k
];
d
=
pSes
->
pArr
TimeProfile
[
j
];
if
(
k
<
pSes
->
nSpecVars
&&
pSes
->
pArr
TimeProfile
[
k
]
>
d
)
d
=
pSes
->
pArr
TimeProfile
[
k
];
pLits
[
0
]
=
Abc_Var2Lit
(
Ses_ManSelectVar
(
pSes
,
i
,
j
,
k
),
1
);
pLits
[
1
]
=
Abc_Var2Lit
(
Ses_ManDepthVar
(
pSes
,
i
,
d
+
1
),
0
);
...
...
@@ -483,7 +483,7 @@ static void Ses_ManCreateClauses( Ses_Man_t * pSes )
}
/* reverse order encoding of depth variables */
for
(
j
=
1
;
j
<=
pSes
->
nArr
ival
Max
+
i
;
++
j
)
for
(
j
=
1
;
j
<=
pSes
->
nArr
Time
Max
+
i
;
++
j
)
{
pLits
[
0
]
=
Abc_Var2Lit
(
Ses_ManDepthVar
(
pSes
,
i
,
j
),
1
);
pLits
[
1
]
=
Abc_Var2Lit
(
Ses_ManDepthVar
(
pSes
,
i
,
j
-
1
),
0
);
...
...
@@ -491,7 +491,7 @@ static void Ses_ManCreateClauses( Ses_Man_t * pSes )
}
/* constrain maximum depth */
if
(
pSes
->
nMaxDepth
<
pSes
->
nArr
ival
Max
+
i
)
if
(
pSes
->
nMaxDepth
<
pSes
->
nArr
Time
Max
+
i
)
for
(
h
=
0
;
h
<
pSes
->
nSpecFunc
;
++
h
)
{
pLits
[
0
]
=
Abc_Var2Lit
(
Ses_ManOutputVar
(
pSes
,
h
,
i
),
1
);
...
...
@@ -548,9 +548,82 @@ static inline int Ses_ManSolve( Ses_Man_t * pSes )
Synopsis [Extract solution.]
***********************************************************************/
static
Abc_Ntk_t
*
Ses_ManExtractNtk
(
Ses_Man_t
*
pSes
)
// char is an array of short integers that stores the synthesized network
// using the following format
// | nvars | nfunc | ngates | gate1 | ... | gaten | func1 | .. | funcm |
// nvars: integer with number of variables
// nfunc: integer with number of functions
// ngates: integer with number of gates
// gate: | op | nfanin | fanin1 | ... | faninl |
// op: integer of gate's truth table (divided by 2, because gate is normal)
// nfanin: integer with number of fanins
// fanin: integer to primary input or other gate
// func: integer as literal to some gate (not primary input), can be complemented
#define ABC_EXACT_SOL_NVARS 0
#define ABC_EXACT_SOL_NFUNC 1
#define ABC_EXACT_SOL_NGATES 2
static
char
*
Ses_ManExtractSolution
(
Ses_Man_t
*
pSes
)
{
int
h
,
i
,
j
,
k
;
int
nSol
,
h
,
i
,
j
,
k
,
nOp
;
char
*
pSol
,
*
p
;
/* compute length of solution, for now all gates have 2 inputs */
nSol
=
3
+
pSes
->
nGates
*
4
+
pSes
->
nSpecFunc
;
p
=
pSol
=
ABC_CALLOC
(
char
,
nSol
);
/* header */
*
p
++
=
pSes
->
nSpecVars
;
*
p
++
=
pSes
->
nSpecFunc
;
*
p
++
=
pSes
->
nGates
;
/* gates */
for
(
i
=
0
;
i
<
pSes
->
nGates
;
++
i
)
{
nOp
=
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManGateVar
(
pSes
,
i
,
0
,
1
)
);
nOp
|=
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManGateVar
(
pSes
,
i
,
1
,
0
)
)
<<
1
;
nOp
|=
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManGateVar
(
pSes
,
i
,
1
,
1
)
)
<<
2
;
*
p
++
=
nOp
;
*
p
++
=
2
;
for
(
k
=
0
;
k
<
pSes
->
nSpecVars
+
i
;
++
k
)
for
(
j
=
0
;
j
<
k
;
++
j
)
if
(
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManSelectVar
(
pSes
,
i
,
j
,
k
)
)
)
{
*
p
++
=
j
;
*
p
++
=
k
;
break
;
}
/* if ( pSes->fVeryVerbose ) */
/* { */
/* if ( pSes->nMaxDepth > 0 ) */
/* { */
/* printf( " and depth vector " ); */
/* for ( j = 0; j <= pSes->nArrTimeMax + i; ++j ) */
/* printf( "%d", sat_solver_var_value( pSes->pSat, Ses_ManDepthVar( pSes, i, j ) ) ); */
/* } */
/* printf( "\n" ); */
/* } */
}
/* outputs */
for
(
h
=
0
;
h
<
pSes
->
nSpecFunc
;
++
h
)
for
(
i
=
0
;
i
<
pSes
->
nGates
;
++
i
)
if
(
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManOutputVar
(
pSes
,
h
,
i
)
)
)
*
p
++
=
Abc_Var2Lit
(
i
,
(
pSes
->
bSpecInv
>>
h
)
&
1
);
/* have we used all the fields? */
assert
(
(
p
-
pSol
)
==
nSol
);
return
pSol
;
}
static
Abc_Ntk_t
*
Ses_ManExtractNtk
(
char
const
*
pSol
)
{
int
h
,
i
;
char
const
*
p
;
Abc_Ntk_t
*
pNtk
;
Abc_Obj_t
*
pObj
;
Vec_Ptr_t
*
pGates
,
*
vNames
;
...
...
@@ -559,14 +632,14 @@ static Abc_Ntk_t * Ses_ManExtractNtk( Ses_Man_t * pSes )
pNtk
=
Abc_NtkAlloc
(
ABC_NTK_LOGIC
,
ABC_FUNC_SOP
,
1
);
pNtk
->
pName
=
Extra_UtilStrsav
(
"exact"
);
pGates
=
Vec_PtrAlloc
(
pS
es
->
nSpecVars
+
pSes
->
nGates
);
pGates
=
Vec_PtrAlloc
(
pS
ol
[
ABC_EXACT_SOL_NVARS
]
+
pSol
[
ABC_EXACT_SOL_NGATES
]
);
pGateTruth
[
3
]
=
'0'
;
pGateTruth
[
4
]
=
'\0'
;
vNames
=
Abc_NodeGetFakeNames
(
pS
es
->
nSpecVars
+
pSes
->
nSpecFunc
);
vNames
=
Abc_NodeGetFakeNames
(
pS
ol
[
ABC_EXACT_SOL_NVARS
]
+
pSol
[
ABC_EXACT_SOL_NFUNC
]
);
/* primary inputs */
Vec_PtrPush
(
pNtk
->
vObjs
,
NULL
);
for
(
i
=
0
;
i
<
pS
es
->
nSpecVars
;
++
i
)
for
(
i
=
0
;
i
<
pS
ol
[
ABC_EXACT_SOL_NVARS
]
;
++
i
)
{
pObj
=
Abc_NtkCreatePi
(
pNtk
);
Abc_ObjAssignName
(
pObj
,
(
char
*
)
Vec_PtrEntry
(
vNames
,
i
),
NULL
);
...
...
@@ -574,16 +647,16 @@ static Abc_Ntk_t * Ses_ManExtractNtk( Ses_Man_t * pSes )
}
/* gates */
for
(
i
=
0
;
i
<
pSes
->
nGates
;
++
i
)
p
=
pSol
+
3
;
for
(
i
=
0
;
i
<
pSol
[
ABC_EXACT_SOL_NGATES
];
++
i
)
{
pGateTruth
[
2
]
=
'0'
+
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManGateVar
(
pSes
,
i
,
0
,
1
)
);
pGateTruth
[
1
]
=
'0'
+
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManGateVar
(
pSes
,
i
,
1
,
0
)
);
pGateTruth
[
0
]
=
'0'
+
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManGateVar
(
pSes
,
i
,
1
,
1
)
);
pGateTruth
[
2
]
=
'0'
+
(
*
p
&
1
);
pGateTruth
[
1
]
=
'0'
+
(
(
*
p
>>
1
)
&
1
);
pGateTruth
[
0
]
=
'0'
+
(
(
*
p
>>
2
)
&
1
);
++
p
;
if
(
pSes
->
fVeryVerbose
)
{
printf
(
"gate %d has truth table %s"
,
pSes
->
nSpecVars
+
i
,
pGateTruth
);
}
assert
(
*
p
==
2
);
/* binary gate */
++
p
;
pSopCover
=
Abc_SopFromTruthBin
(
pGateTruth
);
pObj
=
Abc_NtkCreateNode
(
pNtk
);
...
...
@@ -591,54 +664,19 @@ static Abc_Ntk_t * Ses_ManExtractNtk( Ses_Man_t * pSes )
Vec_PtrPush
(
pGates
,
pObj
);
ABC_FREE
(
pSopCover
);
for
(
k
=
0
;
k
<
pSes
->
nSpecVars
+
i
;
++
k
)
for
(
j
=
0
;
j
<
k
;
++
j
)
if
(
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManSelectVar
(
pSes
,
i
,
j
,
k
)
)
)
{
if
(
pSes
->
fVeryVerbose
)
printf
(
" with children %d and %d"
,
j
,
k
);
Abc_ObjAddFanin
(
pObj
,
(
Abc_Obj_t
*
)
Vec_PtrEntry
(
pGates
,
j
)
);
Abc_ObjAddFanin
(
pObj
,
(
Abc_Obj_t
*
)
Vec_PtrEntry
(
pGates
,
k
)
);
break
;
}
if
(
pSes
->
fVeryVerbose
)
{
if
(
pSes
->
nMaxDepth
>
0
)
{
printf
(
" and depth vector "
);
for
(
j
=
0
;
j
<=
pSes
->
nArrivalMax
+
i
;
++
j
)
printf
(
"%d"
,
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManDepthVar
(
pSes
,
i
,
j
)
)
);
}
printf
(
"
\n
"
);
}
Abc_ObjAddFanin
(
pObj
,
(
Abc_Obj_t
*
)
Vec_PtrEntry
(
pGates
,
*
p
++
)
);
Abc_ObjAddFanin
(
pObj
,
(
Abc_Obj_t
*
)
Vec_PtrEntry
(
pGates
,
*
p
++
)
);
}
/* outputs */
for
(
h
=
0
;
h
<
pS
es
->
nSpecFunc
;
++
h
)
for
(
h
=
0
;
h
<
pS
ol
[
ABC_EXACT_SOL_NFUNC
];
++
h
,
++
p
)
{
pObj
=
Abc_NtkCreatePo
(
pNtk
);
Abc_ObjAssignName
(
pObj
,
(
char
*
)
Vec_PtrEntry
(
vNames
,
pSes
->
nSpecVars
+
h
),
NULL
);
for
(
i
=
0
;
i
<
pSes
->
nGates
;
++
i
)
{
if
(
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManOutputVar
(
pSes
,
h
,
i
)
)
)
{
if
(
pSes
->
fVeryVerbose
)
printf
(
"output %d points to gate %d"
,
h
,
pSes
->
nSpecVars
+
i
);
/* if output has been inverted, we need to add an inverter */
if
(
(
pSes
->
bSpecInv
>>
h
)
&
1
)
{
Abc_ObjAddFanin
(
pObj
,
Abc_NtkCreateNodeInv
(
pNtk
,
(
Abc_Obj_t
*
)
Vec_PtrEntry
(
pGates
,
pSes
->
nSpecVars
+
i
)
)
);
if
(
pSes
->
fVeryVerbose
)
printf
(
" and needs to be inverted"
);
}
Abc_ObjAssignName
(
pObj
,
(
char
*
)
Vec_PtrEntry
(
vNames
,
pSol
[
ABC_EXACT_SOL_NVARS
]
+
h
),
NULL
);
if
(
Abc_LitIsCompl
(
*
p
)
)
Abc_ObjAddFanin
(
pObj
,
Abc_NtkCreateNodeInv
(
pNtk
,
(
Abc_Obj_t
*
)
Vec_PtrEntry
(
pGates
,
pSol
[
ABC_EXACT_SOL_NVARS
]
+
Abc_Lit2Var
(
*
p
)
)
)
);
else
Abc_ObjAddFanin
(
pObj
,
(
Abc_Obj_t
*
)
Vec_PtrEntry
(
pGates
,
pSes
->
nSpecVars
+
i
)
);
if
(
pSes
->
fVeryVerbose
)
printf
(
"
\n
"
);
}
}
Abc_ObjAddFanin
(
pObj
,
(
Abc_Obj_t
*
)
Vec_PtrEntry
(
pGates
,
pSol
[
ABC_EXACT_SOL_NVARS
]
+
Abc_Lit2Var
(
*
p
)
)
);
}
Abc_NodeFreeNames
(
vNames
);
...
...
@@ -647,28 +685,28 @@ static Abc_Ntk_t * Ses_ManExtractNtk( Ses_Man_t * pSes )
if
(
!
Abc_NtkCheck
(
pNtk
)
)
printf
(
"Ses_ManExtractSolution(): Network check has failed.
\n
"
);
return
pNtk
;
}
static
Gia_Man_t
*
Ses_ManExtractGia
(
Ses_Man_t
*
pSes
)
static
Gia_Man_t
*
Ses_ManExtractGia
(
char
const
*
pSol
)
{
int
h
,
i
,
j
,
k
;
int
h
,
i
;
char
const
*
p
;
Gia_Man_t
*
pGia
;
Vec_Int_t
*
pGates
;
Vec_Ptr_t
*
vNames
;
int
nObj
,
nChild1
,
nChild2
,
fChild1Comp
,
fChild2Comp
;
pGia
=
Gia_ManStart
(
pS
es
->
nSpecVars
+
pSes
->
nGates
+
pSes
->
nSpecFunc
+
1
);
pGia
=
Gia_ManStart
(
pS
ol
[
ABC_EXACT_SOL_NVARS
]
+
pSol
[
ABC_EXACT_SOL_NGATES
]
+
pSol
[
ABC_EXACT_SOL_NFUNC
]
+
1
);
pGia
->
nConstrs
=
0
;
pGia
->
pName
=
Extra_UtilStrsav
(
"exact"
);
pGates
=
Vec_IntAlloc
(
pS
es
->
nSpecVars
+
pSes
->
nGates
);
vNames
=
Abc_NodeGetFakeNames
(
pS
es
->
nSpecVars
+
pSes
->
nSpecFunc
);
pGates
=
Vec_IntAlloc
(
pS
ol
[
ABC_EXACT_SOL_NVARS
]
+
pSol
[
ABC_EXACT_SOL_NGATES
]
);
vNames
=
Abc_NodeGetFakeNames
(
pS
ol
[
ABC_EXACT_SOL_NVARS
]
+
pSol
[
ABC_EXACT_SOL_NFUNC
]
);
/* primary inputs */
pGia
->
vNamesIn
=
Vec_PtrStart
(
pS
es
->
nSpecVars
);
for
(
i
=
0
;
i
<
pS
es
->
nSpecVars
;
++
i
)
pGia
->
vNamesIn
=
Vec_PtrStart
(
pS
ol
[
ABC_EXACT_SOL_NVARS
]
);
for
(
i
=
0
;
i
<
pS
ol
[
ABC_EXACT_SOL_NVARS
]
;
++
i
)
{
nObj
=
Gia_ManAppendCi
(
pGia
);
Vec_IntPush
(
pGates
,
nObj
);
...
...
@@ -676,22 +714,20 @@ static Gia_Man_t * Ses_ManExtractGia( Ses_Man_t * pSes )
}
/* gates */
for
(
i
=
0
;
i
<
pSes
->
nGates
;
++
i
)
p
=
pSol
+
3
;
for
(
i
=
0
;
i
<
pSol
[
ABC_EXACT_SOL_NGATES
];
++
i
)
{
for
(
k
=
0
;
k
<
pSes
->
nSpecVars
+
i
;
++
k
)
for
(
j
=
0
;
j
<
k
;
++
j
)
if
(
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManSelectVar
(
pSes
,
i
,
j
,
k
)
)
)
{
nChild1
=
Vec_IntEntry
(
pGates
,
j
);
nChild2
=
Vec_IntEntry
(
pGates
,
k
);
assert
(
p
[
1
]
==
2
);
nChild1
=
Vec_IntEntry
(
pGates
,
p
[
2
]
);
nChild2
=
Vec_IntEntry
(
pGates
,
p
[
3
]
);
fChild1Comp
=
fChild2Comp
=
0
;
if
(
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManGateVar
(
pSes
,
i
,
0
,
1
)
)
)
if
(
*
p
&
1
)
{
nChild1
=
Abc_LitNot
(
nChild1
);
fChild1Comp
=
1
;
}
if
(
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManGateVar
(
pSes
,
i
,
1
,
0
)
)
)
if
(
(
*
p
>>
1
)
&
1
)
{
nChild2
=
Abc_LitNot
(
nChild2
);
fChild2Comp
=
1
;
...
...
@@ -699,32 +735,24 @@ static Gia_Man_t * Ses_ManExtractGia( Ses_Man_t * pSes )
nObj
=
Gia_ManAppendAnd
(
pGia
,
nChild1
,
nChild2
);
if
(
fChild1Comp
&&
fChild2Comp
)
{
assert
(
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManGateVar
(
pSes
,
i
,
1
,
1
)
)
);
assert
(
(
*
p
>>
2
)
&
1
);
nObj
=
Abc_LitNot
(
nObj
);
}
Vec_IntPush
(
pGates
,
nObj
);
break
;
}
p
+=
4
;
}
/* outputs */
pGia
->
vNamesOut
=
Vec_PtrStart
(
pS
es
->
nSpecFunc
);
for
(
h
=
0
;
h
<
pS
es
->
nSpecFunc
;
++
h
)
pGia
->
vNamesOut
=
Vec_PtrStart
(
pS
ol
[
ABC_EXACT_SOL_NFUNC
]
);
for
(
h
=
0
;
h
<
pS
ol
[
ABC_EXACT_SOL_NFUNC
];
++
h
,
++
p
)
{
for
(
i
=
0
;
i
<
pSes
->
nGates
;
++
i
)
{
if
(
sat_solver_var_value
(
pSes
->
pSat
,
Ses_ManOutputVar
(
pSes
,
h
,
i
)
)
)
{
nObj
=
Vec_IntEntry
(
pGates
,
pSes
->
nSpecVars
+
i
);
/* if output has been inverted, we need to add an inverter */
if
(
(
pSes
->
bSpecInv
>>
h
)
&
1
)
nObj
=
Vec_IntEntry
(
pGates
,
pSol
[
ABC_EXACT_SOL_NVARS
]
+
Abc_Lit2Var
(
*
p
)
);
if
(
Abc_LitIsCompl
(
*
p
)
)
nObj
=
Abc_LitNot
(
nObj
);
Gia_ManAppendCo
(
pGia
,
nObj
);
Vec_PtrSetEntry
(
pGia
->
vNamesOut
,
h
,
Extra_UtilStrsav
(
Vec_PtrEntry
(
vNames
,
pSes
->
nSpecVars
+
h
)
)
);
}
}
Vec_PtrSetEntry
(
pGia
->
vNamesOut
,
h
,
Extra_UtilStrsav
(
Vec_PtrEntry
(
vNames
,
pSol
[
ABC_EXACT_SOL_NVARS
]
+
h
)
)
);
}
Abc_NodeFreeNames
(
vNames
);
...
...
@@ -827,17 +855,18 @@ static int Ses_ManFindMinimumSize( Ses_Man_t * pSes )
Synopsis [Find minimum size networks with a SAT solver.]
Description [If nMaxDepth is -1, then depth constraints are ignored.
If nMaxDepth is not -1, one can set pArr
ivalTimes
which should have the length of nVars.
One can ignore pArr
ivalTimes
by setting it to NULL.]
If nMaxDepth is not -1, one can set pArr
TimeProfile
which should have the length of nVars.
One can ignore pArr
TimeProfile
by setting it to NULL.]
SideEffects []
SeeAlso []
***********************************************************************/
Abc_Ntk_t
*
Abc_NtkFindExact
(
word
*
pTruth
,
int
nVars
,
int
nFunc
,
int
nMaxDepth
,
int
*
pArr
ivalTimes
,
int
fVerbose
)
Abc_Ntk_t
*
Abc_NtkFindExact
(
word
*
pTruth
,
int
nVars
,
int
nFunc
,
int
nMaxDepth
,
int
*
pArr
TimeProfile
,
int
fVerbose
)
{
Ses_Man_t
*
pSes
;
char
*
pSol
;
Abc_Ntk_t
*
pNtk
=
NULL
;
abctime
timeStart
;
...
...
@@ -846,12 +875,16 @@ Abc_Ntk_t * Abc_NtkFindExact( word * pTruth, int nVars, int nFunc, int nMaxDepth
timeStart
=
Abc_Clock
();
pSes
=
Ses_ManAlloc
(
pTruth
,
nVars
,
nFunc
,
nMaxDepth
,
pArr
ivalTimes
,
0
,
fVerbose
);
pSes
=
Ses_ManAlloc
(
pTruth
,
nVars
,
nFunc
,
nMaxDepth
,
pArr
TimeProfile
,
0
,
fVerbose
);
if
(
fVerbose
)
Ses_ManPrintFuncs
(
pSes
);
if
(
Ses_ManFindMinimumSize
(
pSes
)
)
pNtk
=
Ses_ManExtractNtk
(
pSes
);
{
pSol
=
Ses_ManExtractSolution
(
pSes
);
pNtk
=
Ses_ManExtractNtk
(
pSol
);
ABC_FREE
(
pSol
);
}
pSes
->
timeTotal
=
Abc_Clock
()
-
timeStart
;
...
...
@@ -864,9 +897,10 @@ Abc_Ntk_t * Abc_NtkFindExact( word * pTruth, int nVars, int nFunc, int nMaxDepth
return
pNtk
;
}
Gia_Man_t
*
Gia_ManFindExact
(
word
*
pTruth
,
int
nVars
,
int
nFunc
,
int
nMaxDepth
,
int
*
pArr
ivalTimes
,
int
fVerbose
)
Gia_Man_t
*
Gia_ManFindExact
(
word
*
pTruth
,
int
nVars
,
int
nFunc
,
int
nMaxDepth
,
int
*
pArr
TimeProfile
,
int
fVerbose
)
{
Ses_Man_t
*
pSes
;
char
*
pSol
;
Gia_Man_t
*
pGia
=
NULL
;
abctime
timeStart
;
...
...
@@ -875,12 +909,16 @@ Gia_Man_t * Gia_ManFindExact( word * pTruth, int nVars, int nFunc, int nMaxDepth
timeStart
=
Abc_Clock
();
pSes
=
Ses_ManAlloc
(
pTruth
,
nVars
,
nFunc
,
nMaxDepth
,
pArr
ivalTimes
,
1
,
fVerbose
);
pSes
=
Ses_ManAlloc
(
pTruth
,
nVars
,
nFunc
,
nMaxDepth
,
pArr
TimeProfile
,
1
,
fVerbose
);
if
(
fVerbose
)
Ses_ManPrintFuncs
(
pSes
);
if
(
Ses_ManFindMinimumSize
(
pSes
)
)
pGia
=
Ses_ManExtractGia
(
pSes
);
{
pSol
=
Ses_ManExtractSolution
(
pSes
);
pGia
=
Ses_ManExtractGia
(
pSol
);
ABC_FREE
(
pSol
);
}
pSes
->
timeTotal
=
Abc_Clock
()
-
timeStart
;
...
...
@@ -920,7 +958,7 @@ void Abc_ExactTestSingleOutput( int fVerbose )
word
pTruth
[
4
]
=
{
0xcafe
,
0
,
0
,
0
};
Abc_Ntk_t
*
pNtk
,
*
pNtk2
,
*
pNtk3
,
*
pNtk4
;
int
pArr
ivalTimes
[
4
]
=
{
6
,
2
,
8
,
5
};
int
pArr
TimeProfile
[
4
]
=
{
6
,
2
,
8
,
5
};
pNtk
=
Abc_NtkFromTruthTable
(
pTruth
,
4
);
...
...
@@ -938,7 +976,7 @@ void Abc_ExactTestSingleOutput( int fVerbose )
assert
(
Abc_NtkLevel
(
pNtk3
)
<=
3
);
Abc_NtkDelete
(
pNtk3
);
pNtk4
=
Abc_NtkFindExact
(
pTruth
,
4
,
1
,
9
,
pArr
ivalTimes
,
fVerbose
);
pNtk4
=
Abc_NtkFindExact
(
pTruth
,
4
,
1
,
9
,
pArr
TimeProfile
,
fVerbose
);
Abc_NtkShortNames
(
pNtk4
);
Abc_NtkCecSat
(
pNtk
,
pNtk4
,
10000
,
0
);
assert
(
pNtk4
);
...
...
@@ -947,7 +985,7 @@ void Abc_ExactTestSingleOutput( int fVerbose )
assert
(
!
Abc_NtkFindExact
(
pTruth
,
4
,
1
,
2
,
NULL
,
fVerbose
)
);
assert
(
!
Abc_NtkFindExact
(
pTruth
,
4
,
1
,
8
,
pArr
ivalTimes
,
fVerbose
)
);
assert
(
!
Abc_NtkFindExact
(
pTruth
,
4
,
1
,
8
,
pArr
TimeProfile
,
fVerbose
)
);
Abc_NtkDelete
(
pNtk
);
}
...
...
@@ -958,7 +996,7 @@ void Abc_ExactTestSingleOutputAIG( int fVerbose )
Abc_Ntk_t
*
pNtk
;
Gia_Man_t
*
pGia
,
*
pGia2
,
*
pGia3
,
*
pGia4
,
*
pMiter
;
Cec_ParCec_t
ParsCec
,
*
pPars
=
&
ParsCec
;
int
pArr
ivalTimes
[
4
]
=
{
6
,
2
,
8
,
5
};
int
pArr
TimeProfile
[
4
]
=
{
6
,
2
,
8
,
5
};
Cec_ManCecSetDefaultParams
(
pPars
);
...
...
@@ -978,7 +1016,7 @@ void Abc_ExactTestSingleOutputAIG( int fVerbose )
Cec_ManVerify
(
pMiter
,
pPars
);
Gia_ManStop
(
pMiter
);
pGia4
=
Gia_ManFindExact
(
pTruth
,
4
,
1
,
9
,
pArr
ivalTimes
,
fVerbose
);
pGia4
=
Gia_ManFindExact
(
pTruth
,
4
,
1
,
9
,
pArr
TimeProfile
,
fVerbose
);
pMiter
=
Gia_ManMiter
(
pGia
,
pGia4
,
0
,
1
,
0
,
0
,
1
);
assert
(
pMiter
);
Cec_ManVerify
(
pMiter
,
pPars
);
...
...
@@ -986,7 +1024,7 @@ void Abc_ExactTestSingleOutputAIG( int fVerbose )
assert
(
!
Gia_ManFindExact
(
pTruth
,
4
,
1
,
2
,
NULL
,
fVerbose
)
);
assert
(
!
Gia_ManFindExact
(
pTruth
,
4
,
1
,
8
,
pArr
ivalTimes
,
fVerbose
)
);
assert
(
!
Gia_ManFindExact
(
pTruth
,
4
,
1
,
8
,
pArr
TimeProfile
,
fVerbose
)
);
Gia_ManStop
(
pGia
);
Gia_ManStop
(
pGia2
);
...
...
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