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
49c57999
Commit
49c57999
authored
Aug 25, 2012
by
Alan Mishchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Several improvements to command 'testnpn'.
parent
f85db9dd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
44 deletions
+58
-44
src/base/abci/abc.c
+4
-4
src/base/abci/abcDec.c
+7
-9
src/base/abci/abcNpn.c
+47
-31
No files found.
src/base/abci/abc.c
View file @
49c57999
...
...
@@ -4926,10 +4926,10 @@ usage:
Abc_Print
(
-
2
,
"
\t
testbench for computing semi-canonical forms of Boolean functions
\n
"
);
Abc_Print
(
-
2
,
"
\t
-A <num> : semi-caninical form computation algorithm [default = %d]
\n
"
,
NpnType
);
Abc_Print
(
-
2
,
"
\t
0: none (reading and writing the file)
\n
"
);
Abc_Print
(
-
2
,
"
\t
1:
semi-canonical form by counting 1s in cofactors
\n
"
);
Abc_Print
(
-
2
,
"
\t
2: semi-canonical form by
minimizing truth table value
\n
"
);
Abc_Print
(
-
2
,
"
\t
3:
exact canonical form (work only for 6 variables)
\n
"
);
Abc_Print
(
-
2
,
"
\t
4: h
euristic
canonical form (work only for 6 variables)
\n
"
);
Abc_Print
(
-
2
,
"
\t
1:
exact canonical form (work only for 6 variables)
\n
"
);
Abc_Print
(
-
2
,
"
\t
2: semi-canonical form by
counting 1s in cofactors
\n
"
);
Abc_Print
(
-
2
,
"
\t
3:
semi-canonical form by minimizing truth table value
\n
"
);
Abc_Print
(
-
2
,
"
\t
4: h
ybrid semi-
canonical form (work only for 6 variables)
\n
"
);
Abc_Print
(
-
2
,
"
\t
-v : toggle verbose printout [default = %s]
\n
"
,
fVerbose
?
"yes"
:
"no"
);
Abc_Print
(
-
2
,
"
\t
-h : print the command usage
\n
"
);
return
1
;
...
...
src/base/abci/abcDec.c
View file @
49c57999
...
...
@@ -114,12 +114,10 @@ void Abc_TruthReadHex( word * pTruth, char * pString, int nVars )
void
Abc_TruthWriteHex
(
FILE
*
pFile
,
word
*
pTruth
,
int
nVars
)
{
int
nDigits
,
Digit
,
k
;
// write hexadecimal digits in the reverse order
// (the last symbol in the string is the least significant digit)
nDigits
=
(
1
<<
(
nVars
-
2
));
for
(
k
=
0
;
k
<
nDigits
;
k
++
)
{
Digit
=
Abc_TruthGetHex
(
pTruth
,
nDigits
-
1
-
k
);
Digit
=
Abc_TruthGetHex
(
pTruth
,
k
);
assert
(
Digit
>=
0
&&
Digit
<
16
);
Abc_TruthWriteHexDigit
(
pFile
,
Digit
);
}
...
...
@@ -145,10 +143,11 @@ Abc_TtStore_t * Abc_TruthStoreAlloc( int nVars, int nFuncs )
p
->
nVars
=
nVars
;
p
->
nWords
=
(
nVars
<
7
)
?
1
:
(
1
<<
(
nVars
-
6
));
p
->
nFuncs
=
nFuncs
;
// alloc array of 'nFuncs' pointers to truth tables
p
->
pFuncs
=
(
word
**
)
malloc
(
sizeof
(
word
*
)
*
p
->
nFuncs
);
// alloc storage for 'nFuncs' truth tables as one chunk of memory
p
->
pFuncs
[
0
]
=
(
word
*
)
calloc
(
sizeof
(
word
),
p
->
nFuncs
*
p
->
nWords
);
p
->
pFuncs
=
(
word
**
)
malloc
(
(
sizeof
(
word
*
)
+
sizeof
(
word
)
*
p
->
nWords
)
*
p
->
nFuncs
);
// assign and clean the truth table storage
p
->
pFuncs
[
0
]
=
(
word
*
)(
p
->
pFuncs
+
p
->
nFuncs
);
memset
(
p
->
pFuncs
[
0
],
0
,
sizeof
(
word
)
*
p
->
nWords
*
p
->
nFuncs
);
// split it up into individual truth tables
for
(
i
=
1
;
i
<
p
->
nFuncs
;
i
++
)
p
->
pFuncs
[
i
]
=
p
->
pFuncs
[
i
-
1
]
+
p
->
nWords
;
...
...
@@ -156,7 +155,6 @@ Abc_TtStore_t * Abc_TruthStoreAlloc( int nVars, int nFuncs )
}
void
Abc_TtStoreFree
(
Abc_TtStore_t
*
p
)
{
free
(
p
->
pFuncs
[
0
]
);
free
(
p
->
pFuncs
);
free
(
p
);
}
...
...
@@ -308,7 +306,7 @@ void Abc_TruthStoreRead( char * pFileName, Abc_TtStore_t * p )
SeeAlso []
***********************************************************************/
void
Abc_T
ruth
StoreWrite
(
char
*
pFileName
,
Abc_TtStore_t
*
p
)
void
Abc_T
t
StoreWrite
(
char
*
pFileName
,
Abc_TtStore_t
*
p
)
{
FILE
*
pFile
;
int
i
;
...
...
@@ -380,7 +378,7 @@ void Abc_TtStoreTest( char * pFileName )
return
;
// write into another file
Abc_T
ruth
StoreWrite
(
pFileOutput
,
p
);
Abc_T
t
StoreWrite
(
pFileOutput
,
p
);
// delete data-structure
Abc_TtStoreFree
(
p
);
...
...
src/base/abci/abcNpn.c
View file @
49c57999
...
...
@@ -49,7 +49,7 @@ struct Abc_TtStore_t_
extern
Abc_TtStore_t
*
Abc_TtStoreLoad
(
char
*
pFileName
);
extern
void
Abc_TtStoreFree
(
Abc_TtStore_t
*
p
);
extern
void
Abc_TtStore
Test
(
char
*
pFileName
);
extern
void
Abc_TtStore
Write
(
char
*
pFileName
,
Abc_TtStore_t
*
p
);
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
...
...
@@ -67,20 +67,19 @@ extern void Abc_TtStoreTest( char * pFileName );
***********************************************************************/
int
nWords
=
0
;
// unfortunate global variable
int
Abc_TruthCompare
(
word
*
p1
,
word
*
p2
)
{
return
memcmp
(
p1
,
p2
,
sizeof
(
word
)
*
nWords
);
}
int
Abc_TruthCompare
(
word
*
*
p1
,
word
**
p2
)
{
return
memcmp
(
*
p1
,
*
p2
,
sizeof
(
word
)
*
nWords
);
}
int
Abc_TruthNpnCountUnique
(
Abc_TtStore_t
*
p
)
{
int
i
,
nUnique
;
int
i
,
k
;
// sort them by value
nWords
=
p
->
nWords
;
assert
(
nWords
>
0
);
qsort
(
(
void
*
)
p
->
pFuncs
[
0
],
p
->
nFuncs
,
nWords
*
sizeof
(
word
),
(
int
(
*
)(
const
void
*
,
const
void
*
))
Abc_TruthCompare
);
qsort
(
(
void
*
)
p
->
pFuncs
,
p
->
nFuncs
,
sizeof
(
word
*
),
(
int
(
*
)(
const
void
*
,
const
void
*
))
Abc_TruthCompare
);
// count the number of unqiue functions
nUnique
=
p
->
nFuncs
;
for
(
i
=
1
;
i
<
p
->
nFuncs
;
i
++
)
if
(
!
memcmp
(
p
->
pFuncs
[
i
-
1
],
p
->
pFuncs
[
i
],
sizeof
(
word
)
*
nWords
)
)
nUnique
--
;
return
nUnique
;
for
(
i
=
k
=
1
;
i
<
p
->
nFuncs
;
i
++
)
if
(
memcmp
(
p
->
pFuncs
[
i
-
1
],
p
->
pFuncs
[
i
],
sizeof
(
word
)
*
nWords
)
)
p
->
pFuncs
[
k
++
]
=
p
->
pFuncs
[
i
];
return
(
p
->
nFuncs
=
k
);
}
/**Function*************************************************************
...
...
@@ -104,14 +103,16 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose )
int
i
;
//, nFuncs = 0;
char
*
pAlgoName
=
NULL
;
if
(
NpnType
==
1
)
pAlgoName
=
"counting 1s "
;
if
(
NpnType
==
0
)
pAlgoName
=
"uniqifying "
;
else
if
(
NpnType
==
1
)
pAlgoName
=
"exact NPN "
;
else
if
(
NpnType
==
2
)
pAlgoName
=
"
minimizing TT
"
;
pAlgoName
=
"
counting 1s
"
;
else
if
(
NpnType
==
3
)
pAlgoName
=
"
exact NPN
"
;
pAlgoName
=
"
minimizing TT
"
;
else
if
(
NpnType
==
4
)
pAlgoName
=
"h
euristic NPN
"
;
pAlgoName
=
"h
ybrid NPN
"
;
assert
(
p
->
nVars
<=
16
);
if
(
pAlgoName
)
...
...
@@ -120,29 +121,17 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose )
if
(
fVerbose
)
printf
(
"
\n
"
);
if
(
NpnType
==
1
)
{
for
(
i
=
0
;
i
<
p
->
nFuncs
;
i
++
)
{
if
(
fVerbose
)
printf
(
"%7d : "
,
i
);
Kit_TruthSemiCanonicize
(
(
unsigned
*
)
p
->
pFuncs
[
i
],
pAux
,
p
->
nVars
,
pCanonPerm
,
pStore
);
if
(
fVerbose
)
Extra_PrintHex
(
stdout
,
(
unsigned
*
)
p
->
pFuncs
[
i
],
p
->
nVars
),
printf
(
"
\n
"
);
}
}
else
if
(
NpnType
==
2
)
if
(
NpnType
==
0
)
{
for
(
i
=
0
;
i
<
p
->
nFuncs
;
i
++
)
{
if
(
fVerbose
)
printf
(
"%7d : "
,
i
);
Kit_TruthSemiCanonicize_new
(
(
unsigned
*
)
p
->
pFuncs
[
i
],
pAux
,
p
->
nVars
,
pCanonPerm
);
if
(
fVerbose
)
Extra_PrintHex
(
stdout
,
(
unsigned
*
)
p
->
pFuncs
[
i
],
p
->
nVars
),
printf
(
"
\n
"
);
}
}
else
if
(
NpnType
==
3
)
else
if
(
NpnType
==
1
)
{
int
*
pComp
=
Extra_GreyCodeSchedule
(
p
->
nVars
);
int
*
pPerm
=
Extra_PermSchedule
(
p
->
nVars
);
...
...
@@ -162,6 +151,28 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose )
ABC_FREE
(
pComp
);
ABC_FREE
(
pPerm
);
}
else
if
(
NpnType
==
2
)
{
for
(
i
=
0
;
i
<
p
->
nFuncs
;
i
++
)
{
if
(
fVerbose
)
printf
(
"%7d : "
,
i
);
Kit_TruthSemiCanonicize
(
(
unsigned
*
)
p
->
pFuncs
[
i
],
pAux
,
p
->
nVars
,
pCanonPerm
,
pStore
);
if
(
fVerbose
)
Extra_PrintHex
(
stdout
,
(
unsigned
*
)
p
->
pFuncs
[
i
],
p
->
nVars
),
printf
(
"
\n
"
);
}
}
else
if
(
NpnType
==
3
)
{
for
(
i
=
0
;
i
<
p
->
nFuncs
;
i
++
)
{
if
(
fVerbose
)
printf
(
"%7d : "
,
i
);
Kit_TruthSemiCanonicize_new
(
(
unsigned
*
)
p
->
pFuncs
[
i
],
pAux
,
p
->
nVars
,
pCanonPerm
);
if
(
fVerbose
)
Extra_PrintHex
(
stdout
,
(
unsigned
*
)
p
->
pFuncs
[
i
],
p
->
nVars
),
printf
(
"
\n
"
);
}
}
else
if
(
NpnType
==
4
)
{
if
(
p
->
nVars
==
6
)
...
...
@@ -200,6 +211,7 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose )
void
Abc_TruthNpnTest
(
char
*
pFileName
,
int
NpnType
,
int
fVerbose
)
{
Abc_TtStore_t
*
p
;
char
*
pFileNameOut
;
// read info from file
p
=
Abc_TtStoreLoad
(
pFileName
);
...
...
@@ -209,6 +221,12 @@ void Abc_TruthNpnTest( char * pFileName, int NpnType, int fVerbose )
// consider functions from the file
Abc_TruthNpnPerform
(
p
,
NpnType
,
fVerbose
);
// write the result
pFileNameOut
=
Extra_FileNameGenericAppend
(
pFileName
,
"_out.txt"
);
Abc_TtStoreWrite
(
pFileNameOut
,
p
);
if
(
fVerbose
)
printf
(
"The resulting functions are written into file
\"
%s
\"
.
\n
"
,
pFileNameOut
);
// delete data-structure
Abc_TtStoreFree
(
p
);
// printf( "Finished computing canonical forms for functions from file \"%s\".\n", pFileName );
...
...
@@ -230,9 +248,7 @@ int Abc_NpnTest( char * pFileName, int NpnType, int fVerbose )
{
if
(
fVerbose
)
printf
(
"Using truth tables from file
\"
%s
\"
...
\n
"
,
pFileName
);
if
(
NpnType
==
0
)
Abc_TtStoreTest
(
pFileName
);
else
if
(
NpnType
>=
1
&&
NpnType
<=
4
)
if
(
NpnType
>=
0
&&
NpnType
<=
4
)
Abc_TruthNpnTest
(
pFileName
,
NpnType
,
fVerbose
);
else
printf
(
"Unknown canonical form value (%d).
\n
"
,
NpnType
);
...
...
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