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
3ba93e3b
Commit
3ba93e3b
authored
Apr 30, 2014
by
Alan Mishchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exploration of functions.
parent
416f300d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
144 additions
and
114 deletions
+144
-114
src/misc/extra/extraUtilEnum.c
+144
-114
No files found.
src/misc/extra/extraUtilEnum.c
View file @
3ba93e3b
...
@@ -426,7 +426,7 @@ void Abc_EnumerateFunctions( int nDecMax )
...
@@ -426,7 +426,7 @@ void Abc_EnumerateFunctions( int nDecMax )
SeeAlso []
SeeAlso []
***********************************************************************/
***********************************************************************/
#define ABC_ENUM_MAX
32
#define ABC_ENUM_MAX
16
static
word
s_Truths6
[
6
]
=
{
static
word
s_Truths6
[
6
]
=
{
ABC_CONST
(
0xAAAAAAAAAAAAAAAA
),
ABC_CONST
(
0xAAAAAAAAAAAAAAAA
),
ABC_CONST
(
0xCCCCCCCCCCCCCCCC
),
ABC_CONST
(
0xCCCCCCCCCCCCCCCC
),
...
@@ -441,6 +441,7 @@ struct Abc_EnuMan_t_
...
@@ -441,6 +441,7 @@ struct Abc_EnuMan_t_
int
nVars
;
// support size
int
nVars
;
// support size
int
nVarsFree
;
// number of PIs used
int
nVarsFree
;
// number of PIs used
int
fVerbose
;
// verbose flag
int
fVerbose
;
// verbose flag
int
fUseXor
;
// using XOR gate
int
nNodeMax
;
// the max number of nodes
int
nNodeMax
;
// the max number of nodes
int
nNodes
;
// current number of gates
int
nNodes
;
// current number of gates
int
nTops
;
// the number of fanoutless gates
int
nTops
;
// the number of fanoutless gates
...
@@ -448,16 +449,14 @@ struct Abc_EnuMan_t_
...
@@ -448,16 +449,14 @@ struct Abc_EnuMan_t_
int
pFans1
[
ABC_ENUM_MAX
];
// fanins
int
pFans1
[
ABC_ENUM_MAX
];
// fanins
int
fCompl0
[
ABC_ENUM_MAX
];
// complements
int
fCompl0
[
ABC_ENUM_MAX
];
// complements
int
fCompl1
[
ABC_ENUM_MAX
];
// complements
int
fCompl1
[
ABC_ENUM_MAX
];
// complements
int
Polar
[
ABC_ENUM_MAX
];
// polarity
int
pRefs
[
ABC_ENUM_MAX
];
// references
int
pRefs
[
ABC_ENUM_MAX
];
// references
int
pLevel
[
ABC_ENUM_MAX
];
// level
word
pTruths
[
ABC_ENUM_MAX
];
// truth tables
word
pTruths
[
ABC_ENUM_MAX
];
// truth tables
word
nTries
;
// attempts to build a gate
word
nTries
;
// attempts to build a gate
word
nBuilds
;
// actually built gates
word
nBuilds
;
// actually built gates
word
nFinished
;
// finished structures
word
nFinished
;
// finished structures
};
};
static
inline
int
Abc_EnumEquiv
(
word
a
,
word
b
)
{
return
a
==
b
||
a
==
~
b
;
}
static
inline
void
Abc_EnumRef
(
Abc_EnuMan_t
*
p
,
int
i
)
static
inline
void
Abc_EnumRef
(
Abc_EnuMan_t
*
p
,
int
i
)
{
{
assert
(
p
->
pRefs
[
i
]
>=
0
);
assert
(
p
->
pRefs
[
i
]
>=
0
);
...
@@ -491,151 +490,182 @@ static inline void Abc_EnumPrintOne( Abc_EnuMan_t * p )
...
@@ -491,151 +490,182 @@ static inline void Abc_EnumPrintOne( Abc_EnuMan_t * p )
int
i
;
int
i
;
Kit_DsdPrintFromTruth
(
(
unsigned
*
)(
p
->
pTruths
+
p
->
nNodes
-
1
),
p
->
nVars
);
Kit_DsdPrintFromTruth
(
(
unsigned
*
)(
p
->
pTruths
+
p
->
nNodes
-
1
),
p
->
nVars
);
for
(
i
=
p
->
nVars
;
i
<
p
->
nNodes
;
i
++
)
for
(
i
=
p
->
nVars
;
i
<
p
->
nNodes
;
i
++
)
printf
(
" %c=%s%c%s%c"
,
'a'
+
i
,
p
->
fCompl0
[
i
]
?
"!"
:
""
,
'a'
+
p
->
pFans0
[
i
],
p
->
fCompl1
[
i
]
?
"!"
:
""
,
'a'
+
p
->
pFans1
[
i
]
);
if
(
p
->
Polar
[
i
]
==
4
)
printf
(
" %c=%c+%c"
,
'a'
+
i
,
'a'
+
p
->
pFans0
[
i
],
'a'
+
p
->
pFans1
[
i
]
);
else
printf
(
" %c=%s%c%s%c"
,
'a'
+
i
,
p
->
fCompl0
[
i
]
?
"!"
:
""
,
'a'
+
p
->
pFans0
[
i
],
p
->
fCompl1
[
i
]
?
"!"
:
""
,
'a'
+
p
->
pFans1
[
i
]
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
void
Abc_EnumerateFuncs_rec
(
Abc_EnuMan_t
*
p
)
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
int
Abc_EnumEquiv
(
word
a
,
word
b
)
{
return
a
==
b
||
a
==
~
b
;
}
static
inline
int
Abc_EnumerateFilter
(
Abc_EnuMan_t
*
p
)
{
{
word
uTruth
;
int
fUseFull
=
1
;
word
*
pTruth
=
p
->
pTruths
;
int
f
=
p
->
nVarsFree
;
int
n
=
p
->
nNodes
;
int
n
=
p
->
nNodes
;
int
i
,
k
,
c0
,
c1
,
t
,
a
,
b
;
int
i
=
p
->
pFans0
[
n
];
p
->
nBuilds
++
;
int
k
=
p
->
pFans1
[
n
],
t
;
// terminate when enough and no new tops
word
*
pTruths
=
p
->
pTruths
;
if
(
n
==
p
->
nNodeMax
&&
p
->
nTops
==
1
)
word
uTruth
=
pTruths
[
n
];
assert
(
i
<
k
);
// skip constants
if
(
Abc_EnumEquiv
(
uTruth
,
0
)
)
return
1
;
// skip equal ones
for
(
t
=
0
;
t
<
n
;
t
++
)
if
(
Abc_EnumEquiv
(
uTruth
,
pTruths
[
t
])
)
return
1
;
if
(
fUseFull
)
{
{
if
(
p
->
fVerbose
)
// skip those that can be derived by any pair
Abc_EnumPrintOne
(
p
);
int
a
,
b
;
p
->
nFinished
++
;
for
(
a
=
0
;
a
<=
i
;
a
++
)
return
;
for
(
b
=
a
+
1
;
b
<=
k
;
b
++
)
{
if
(
a
==
i
&&
b
==
k
)
continue
;
if
(
Abc_EnumEquiv
(
uTruth
,
pTruths
[
a
]
&
pTruths
[
b
])
)
return
1
;
if
(
Abc_EnumEquiv
(
uTruth
,
pTruths
[
a
]
&
~
pTruths
[
b
])
)
return
1
;
if
(
Abc_EnumEquiv
(
uTruth
,
~
pTruths
[
a
]
&
pTruths
[
b
])
)
return
1
;
if
(
Abc_EnumEquiv
(
uTruth
,
~
pTruths
[
a
]
&
~
pTruths
[
b
])
)
return
1
;
if
(
p
->
fUseXor
&&
Abc_EnumEquiv
(
uTruth
,
pTruths
[
a
]
^
pTruths
[
b
])
)
return
1
;
}
}
}
if
(
p
->
nTops
>
p
->
nNodeMax
-
n
+
1
)
else
return
;
assert
(
n
<
p
->
nNodeMax
);
// try new gates with two inputs
if
(
f
>=
2
)
{
{
p
->
pFans0
[
n
]
=
f
-
2
;
// skip those that can be derived by fanin and any other one in the cone
p
->
pFans1
[
n
]
=
f
-
1
;
int
uTruthI
=
p
->
fCompl0
[
n
]
?
~
pTruths
[
i
]
:
pTruths
[
i
];
p
->
fCompl0
[
n
]
=
0
;
int
uTruthK
=
p
->
fCompl1
[
n
]
?
~
pTruths
[
k
]
:
pTruths
[
k
];
p
->
fCompl1
[
n
]
=
0
;
assert
(
p
->
fUseXor
==
0
);
p
->
pTruths
[
n
]
=
pTruth
[
f
-
2
]
&
pTruth
[
f
-
1
];
for
(
t
=
0
;
t
<
k
;
t
++
)
p
->
nVarsFree
-=
2
;
if
(
Abc_EnumEquiv
(
uTruth
,
pTruths
[
t
]
&
uTruthI
)
||
Abc_EnumEquiv
(
uTruth
,
~
pTruths
[
t
]
&
uTruthI
)
)
Abc_EnumRefNode
(
p
,
n
);
return
1
;
Abc_EnumerateFuncs_rec
(
p
);
for
(
t
=
0
;
t
<
i
;
t
++
)
Abc_EnumDerefNode
(
p
,
n
);
if
(
Abc_EnumEquiv
(
uTruth
,
pTruths
[
t
]
&
uTruthK
)
||
Abc_EnumEquiv
(
uTruth
,
~
pTruths
[
t
]
&
uTruthK
)
)
p
->
nVarsFree
+=
2
;
return
1
;
return
;
}
}
// try new gates with one input
return
0
;
if
(
f
>
0
)
}
void
Abc_EnumerateFuncs_rec
(
Abc_EnuMan_t
*
p
,
int
fNew
,
int
iNode1st
)
// the first node on the last level
{
if
(
p
->
nNodes
==
p
->
nNodeMax
)
{
{
for
(
i
=
f
;
i
<
n
;
i
++
)
assert
(
p
->
nTops
==
1
);
for
(
c0
=
0
;
c0
<
2
;
c0
++
)
if
(
p
->
fVerbose
)
{
Abc_EnumPrintOne
(
p
);
uTruth
=
pTruth
[
f
-
1
]
&
(
c0
?
~
pTruth
[
i
]
:
pTruth
[
i
]);
p
->
nFinished
++
;
p
->
pFans0
[
n
]
=
f
-
1
;
p
->
pFans1
[
n
]
=
i
;
p
->
fCompl0
[
n
]
=
0
;
p
->
fCompl1
[
n
]
=
c0
;
p
->
pTruths
[
n
]
=
uTruth
;
p
->
nVarsFree
--
;
Abc_EnumRefNode
(
p
,
n
);
Abc_EnumerateFuncs_rec
(
p
);
Abc_EnumDerefNode
(
p
,
n
);
p
->
nVarsFree
++
;
}
return
;
return
;
}
}
// try new gates without inputs
for
(
i
=
f
;
i
<
n
;
i
++
)
for
(
k
=
i
+
1
;
k
<
n
;
k
++
)
for
(
c0
=
0
;
c0
<
2
;
c0
++
)
for
(
c1
=
0
;
c1
<
2
;
c1
++
)
{
{
uTruth
=
(
c0
?
~
pTruth
[
i
]
:
pTruth
[
i
])
&
(
c1
?
~
pTruth
[
k
]
:
pTruth
[
k
]);
int
i
,
k
,
c
,
cLim
=
4
+
p
->
fUseXor
,
n
=
p
->
nNodes
;
// skip constants
int
nRefedFans
=
p
->
nNodeMax
-
n
+
1
-
p
->
nTops
;
if
(
uTruth
==
0
||
~
uTruth
==
0
)
int
high0
=
fNew
?
iNode1st
:
p
->
pFans1
[
n
-
1
];
continue
;
int
high1
=
fNew
?
n
:
iNode1st
;
// skip equal ones
int
low0
=
fNew
?
0
:
p
->
pFans0
[
n
-
1
];
for
(
t
=
f
;
t
<
n
;
t
++
)
int
c0
=
fNew
?
0
:
p
->
Polar
[
n
-
1
];
if
(
uTruth
==
p
->
pTruths
[
t
]
||
~
uTruth
==
p
->
pTruths
[
t
]
)
int
Level
=
p
->
pLevel
[
high0
];
break
;
assert
(
p
->
nTops
>
0
&&
p
->
nTops
<=
p
->
nNodeMax
-
n
+
1
);
if
(
t
<
n
)
// go through nodes
continue
;
for
(
k
=
high0
;
k
<
high1
;
k
++
)
// skip those that can be derived by fanin and any other one in the cone
{
for
(
a
=
f
;
a
<
i
;
a
++
)
if
(
nRefedFans
==
0
&&
p
->
pRefs
[
k
]
>
0
)
if
(
Abc_EnumEquiv
(
uTruth
,
p
->
pTruths
[
a
]
&
p
->
pTruths
[
k
])
||
Abc_EnumEquiv
(
uTruth
,
~
p
->
pTruths
[
a
]
&
p
->
pTruths
[
k
])
)
break
;
if
(
a
<
i
)
continue
;
for
(
b
=
f
;
b
<
k
;
b
++
)
if
(
Abc_EnumEquiv
(
uTruth
,
p
->
pTruths
[
b
]
&
p
->
pTruths
[
i
])
||
Abc_EnumEquiv
(
uTruth
,
~
p
->
pTruths
[
b
]
&
p
->
pTruths
[
i
])
)
break
;
if
(
b
<
k
)
continue
;
continue
;
if
(
p
->
pRefs
[
k
]
>
0
)
/*
nRefedFans
--
;
// skip those that can be derived by any two in the cone, except the top ones
assert
(
nRefedFans
>=
0
);
for ( a = f; a <= i; a++ )
// try second fanin
for
(
i
=
(
k
==
high0
)
?
low0
:
0
;
i
<
k
;
i
++
)
{
{
word uTemp;
if
(
nRefedFans
==
0
&&
p
->
pRefs
[
i
]
>
0
)
for ( b = a + 1; b <= k; b++ )
continue
;
if
(
Level
==
0
&&
p
->
pRefs
[
i
]
==
0
&&
p
->
pRefs
[
k
]
==
0
&&
(
i
+
1
!=
k
||
(
i
>
0
&&
p
->
pRefs
[
i
-
1
]
==
0
))
)
// NPN
continue
;
if
(
p
->
pLevel
[
k
]
==
0
&&
p
->
pRefs
[
k
]
==
0
&&
p
->
pRefs
[
i
]
!=
0
&&
k
>
0
&&
p
->
pRefs
[
k
-
1
]
==
0
)
// NPN
continue
;
// if ( p->pLevel[i] == 0 && p->pRefs[i] == 0 && p->pRefs[k] != 0 && i > 0 && p->pRefs[i-1] == 0 ) // NPN
// continue;
// try four polarities
for
(
c
=
(
k
==
high0
&&
i
==
low0
&&
!
fNew
)
?
c0
+
1
:
0
;
c
<
cLim
;
c
++
)
{
{
if ( a == i && b == k )
if
(
p
->
pLevel
[
i
]
==
0
&&
p
->
pRefs
[
i
]
==
0
&&
(
c
&
1
)
==
1
)
// NPN
continue
;
if
(
p
->
pLevel
[
k
]
==
0
&&
p
->
pRefs
[
k
]
==
0
&&
(
c
&
2
)
==
2
)
// NPN
continue
;
p
->
nTries
++
;
// create node
assert
(
i
<
k
);
p
->
pFans0
[
n
]
=
i
;
p
->
pFans1
[
n
]
=
k
;
p
->
fCompl0
[
n
]
=
c
&
1
;
p
->
fCompl1
[
n
]
=
(
c
>>
1
)
&
1
;
p
->
Polar
[
n
]
=
c
;
if
(
c
==
4
)
p
->
pTruths
[
n
]
=
p
->
pTruths
[
i
]
^
p
->
pTruths
[
k
];
else
p
->
pTruths
[
n
]
=
((
c
&
1
)
?
~
p
->
pTruths
[
i
]
:
p
->
pTruths
[
i
])
&
((
c
&
2
)
?
~
p
->
pTruths
[
k
]
:
p
->
pTruths
[
k
]);
if
(
Abc_EnumerateFilter
(
p
)
)
continue
;
continue
;
uTemp = p->pTruths[a] & p->pTruths[b];
p
->
nBuilds
++
;
if ( uTruth == uTemp || ~uTruth == uTemp )
assert
(
Level
==
Abc_MaxInt
(
p
->
pLevel
[
i
],
p
->
pLevel
[
k
])
);
break;
p
->
pLevel
[
n
]
=
Level
+
1
;
uTemp = p->pTruths[a] & ~p->pTruths[b];
Abc_EnumRefNode
(
p
,
n
);
if ( uTruth == uTemp || ~uTruth == uTemp )
Abc_EnumerateFuncs_rec
(
p
,
0
,
fNew
?
n
:
iNode1st
);
break;
Abc_EnumDerefNode
(
p
,
n
);
uTemp = ~p->pTruths[a] & p->pTruths[b];
assert
(
n
==
p
->
nNodes
);
if ( uTruth == uTemp || ~uTruth == uTemp )
break;
uTemp = ~p->pTruths[a] & ~p->pTruths[b];
if ( uTruth == uTemp || ~uTruth == uTemp )
break;
}
}
if ( b <= k )
break;
}
}
if ( a <= i )
if
(
p
->
pRefs
[
k
]
>
0
)
continue;
nRefedFans
++
;
*/
}
if
(
fNew
)
p
->
pFans0
[
n
]
=
i
;
return
;
p
->
pFans1
[
n
]
=
k
;
// start a new level
p
->
fCompl0
[
n
]
=
c0
;
Abc_EnumerateFuncs_rec
(
p
,
1
,
iNode1st
);
p
->
fCompl1
[
n
]
=
c1
;
p
->
pTruths
[
n
]
=
uTruth
;
Abc_EnumRefNode
(
p
,
n
);
Abc_EnumerateFuncs_rec
(
p
);
Abc_EnumDerefNode
(
p
,
n
);
}
}
}
}
void
Abc_EnumerateFuncs
(
int
nVars
,
int
nGates
,
int
fVerbose
)
void
Abc_EnumerateFuncs
(
int
nVars
,
int
nGates
,
int
fVerbose
)
{
{
abctime
clk
=
Abc_Clock
();
abctime
clk
=
Abc_Clock
();
Abc_EnuMan_t
P
,
*
p
=
&
P
;
int
i
;
Abc_EnuMan_t
P
,
*
p
=
&
P
;
int
i
,
n
=
nVars
;
if
(
nVars
>
nGates
+
1
)
if
(
nVars
>
nGates
+
1
)
{
{
printf
(
"The gate count %d is not enough to have functions with %d inputs.
\n
"
,
nGates
,
nVars
);
printf
(
"The gate count %d is not enough to have functions with %d inputs.
\n
"
,
nGates
,
nVars
);
return
;
return
;
}
}
assert
(
nVars
>=
3
&&
nVars
<=
6
);
assert
(
nVars
>=
2
&&
nVars
<=
6
);
assert
(
nGates
>
0
&&
nVars
+
nGates
<
16
);
assert
(
nGates
>
0
&&
nVars
+
nGates
<
ABC_ENUM_MAX
);
memset
(
p
,
0
,
sizeof
(
Abc_EnuMan_t
)
);
memset
(
p
,
0
,
sizeof
(
Abc_EnuMan_t
)
);
p
->
fVerbose
=
fVerbose
;
p
->
fVerbose
=
fVerbose
;
p
->
fUseXor
=
1
;
p
->
nVars
=
nVars
;
p
->
nVars
=
nVars
;
p
->
nVarsFree
=
nVars
;
p
->
nNodeMax
=
nVars
+
nGates
;
p
->
nNodeMax
=
nVars
+
nGates
;
p
->
nNodes
=
nVars
;
p
->
nNodes
=
nVars
;
p
->
nTops
=
nVars
;
p
->
nTops
=
nVars
;
for
(
i
=
0
;
i
<
nVars
;
i
++
)
for
(
i
=
0
;
i
<
nVars
;
i
++
)
p
->
pTruths
[
i
]
=
s_Truths6
[
i
];
p
->
pTruths
[
i
]
=
s_Truths6
[
i
];
Abc_EnumerateFuncs_rec
(
p
);
Abc_EnumerateFuncs_rec
(
p
,
1
,
0
);
assert
(
p
->
nNodes
==
nVars
);
assert
(
p
->
nTops
==
nVars
);
// report statistics
printf
(
"Vars = %d. Gates = %d. Tries = %u. Builds = %u. Finished = %d. "
,
printf
(
"Vars = %d. Gates = %d. Tries = %u. Builds = %u. Finished = %d. "
,
nVars
,
nGates
,
(
unsigned
)
p
->
nTries
,
(
unsigned
)
p
->
nBuilds
,
(
unsigned
)
p
->
nFinished
);
nVars
,
nGates
,
(
unsigned
)
p
->
nTries
,
(
unsigned
)
p
->
nBuilds
,
(
unsigned
)
p
->
nFinished
);
Abc_PrintTime
(
1
,
"Time"
,
Abc_Clock
()
-
clk
);
Abc_PrintTime
(
1
,
"Time"
,
Abc_Clock
()
-
clk
);
...
...
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