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
6345832d
Commit
6345832d
authored
Feb 03, 2022
by
Alan Mishchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improving truth table handling.
parent
faa59472
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
166 additions
and
21 deletions
+166
-21
src/base/abc/abc.h
+3
-0
src/base/abc/abcNtk.c
+46
-0
src/base/abc/abcSop.c
+67
-2
src/base/io/io.c
+24
-19
src/base/wln/wlnRtl.c
+26
-0
No files found.
src/base/abc/abc.h
View file @
6345832d
...
...
@@ -784,6 +784,7 @@ extern ABC_DLL Abc_Ntk_t * Abc_NtkCreateMffc( Abc_Ntk_t * pNtk, Abc_Obj_t
extern
ABC_DLL
Abc_Ntk_t
*
Abc_NtkCreateTarget
(
Abc_Ntk_t
*
pNtk
,
Vec_Ptr_t
*
vRoots
,
Vec_Int_t
*
vValues
);
extern
ABC_DLL
Abc_Ntk_t
*
Abc_NtkCreateFromNode
(
Abc_Ntk_t
*
pNtk
,
Abc_Obj_t
*
pNode
);
extern
ABC_DLL
Abc_Ntk_t
*
Abc_NtkCreateWithNode
(
char
*
pSop
);
extern
ABC_DLL
Abc_Ntk_t
*
Abc_NtkCreateWithNodes
(
Vec_Ptr_t
*
vSops
);
extern
ABC_DLL
void
Abc_NtkDelete
(
Abc_Ntk_t
*
pNtk
);
extern
ABC_DLL
void
Abc_NtkFixNonDrivenNets
(
Abc_Ntk_t
*
pNtk
);
extern
ABC_DLL
void
Abc_NtkMakeComb
(
Abc_Ntk_t
*
pNtk
,
int
fRemoveLatches
);
...
...
@@ -920,6 +921,8 @@ extern ABC_DLL int Abc_SopIsExorType( char * pSop );
extern
ABC_DLL
int
Abc_SopCheck
(
char
*
pSop
,
int
nFanins
);
extern
ABC_DLL
char
*
Abc_SopFromTruthBin
(
char
*
pTruth
);
extern
ABC_DLL
char
*
Abc_SopFromTruthHex
(
char
*
pTruth
);
extern
ABC_DLL
Vec_Ptr_t
*
Abc_SopFromTruthsBin
(
char
*
pTruth
);
extern
ABC_DLL
Vec_Ptr_t
*
Abc_SopFromTruthsHex
(
char
*
pTruth
);
extern
ABC_DLL
char
*
Abc_SopEncoderPos
(
Mem_Flex_t
*
pMan
,
int
iValue
,
int
nValues
);
extern
ABC_DLL
char
*
Abc_SopEncoderLog
(
Mem_Flex_t
*
pMan
,
int
iBit
,
int
nValues
);
extern
ABC_DLL
char
*
Abc_SopDecoderPos
(
Mem_Flex_t
*
pMan
,
int
nValues
);
...
...
src/base/abc/abcNtk.c
View file @
6345832d
...
...
@@ -1272,6 +1272,52 @@ Abc_Ntk_t * Abc_NtkCreateWithNode( char * pSop )
/**Function*************************************************************
Synopsis [Creates the network composed of one node with the given SOP.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Abc_Ntk_t
*
Abc_NtkCreateWithNodes
(
Vec_Ptr_t
*
vSop
)
{
Abc_Ntk_t
*
pNtkNew
;
Abc_Obj_t
*
pFanin
,
*
pNode
,
*
pNodePo
;
Vec_Ptr_t
*
vNames
;
int
i
,
k
,
nVars
;
char
Buffer
[
10
];
char
*
pSop
=
(
char
*
)
Vec_PtrEntry
(
vSop
,
0
);
// start the network
pNtkNew
=
Abc_NtkAlloc
(
ABC_NTK_LOGIC
,
ABC_FUNC_SOP
,
1
);
pNtkNew
->
pName
=
Extra_UtilStrsav
(
"ex"
);
// create PIs
Vec_PtrPush
(
pNtkNew
->
vObjs
,
NULL
);
nVars
=
Abc_SopGetVarNum
(
pSop
);
vNames
=
Abc_NodeGetFakeNames
(
nVars
);
for
(
i
=
0
;
i
<
nVars
;
i
++
)
Abc_ObjAssignName
(
Abc_NtkCreatePi
(
pNtkNew
),
(
char
*
)
Vec_PtrEntry
(
vNames
,
i
),
NULL
);
Abc_NodeFreeNames
(
vNames
);
// create the node, add PIs as fanins, set the function
Vec_PtrForEachEntry
(
char
*
,
vSop
,
pSop
,
i
)
{
pNode
=
Abc_NtkCreateNode
(
pNtkNew
);
Abc_NtkForEachPi
(
pNtkNew
,
pFanin
,
k
)
Abc_ObjAddFanin
(
pNode
,
pFanin
);
pNode
->
pData
=
Abc_SopRegister
(
(
Mem_Flex_t
*
)
pNtkNew
->
pManFunc
,
pSop
);
// create the only PO
pNodePo
=
Abc_NtkCreatePo
(
pNtkNew
);
Abc_ObjAddFanin
(
pNodePo
,
pNode
);
sprintf
(
Buffer
,
"F%d"
,
i
);
Abc_ObjAssignName
(
pNodePo
,
Buffer
,
NULL
);
}
if
(
!
Abc_NtkCheck
(
pNtkNew
)
)
fprintf
(
stdout
,
"Abc_NtkCreateWithNode(): Network check has failed.
\n
"
);
return
pNtkNew
;
}
/**Function*************************************************************
Synopsis [Deletes the Ntk.]
Description []
...
...
src/base/abc/abcSop.c
View file @
6345832d
...
...
@@ -907,6 +907,41 @@ int Abc_SopCheck( char * pSop, int nFanins )
return
1
;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int
Abc_SopCheckReadTruth
(
Vec_Ptr_t
*
vRes
,
char
*
pToken
,
int
fHex
)
{
char
*
pBase
;
int
nVars
;
int
Log2
=
Abc_Base2Log
(
strlen
(
pToken
)
);
if
(
(
1
<<
Log2
)
!=
(
int
)
strlen
(
pToken
)
)
{
printf
(
"The truth table length (%d) is not power-of-2.
\n
"
,
strlen
(
pToken
)
);
Vec_PtrFreeData
(
vRes
);
Vec_PtrShrink
(
vRes
,
0
);
return
0
;
}
if
(
Vec_PtrSize
(
vRes
)
==
0
)
return
1
;
pBase
=
(
char
*
)
Vec_PtrEntry
(
vRes
,
0
);
nVars
=
Abc_SopGetVarNum
(
pBase
);
if
(
nVars
!=
Log2
+
2
*
fHex
)
{
printf
(
"Truth table #1 has %d vars while truth table #%d has %d vars.
\n
"
,
nVars
,
Vec_PtrSize
(
vRes
)
+
1
,
Log2
+
2
*
fHex
);
Vec_PtrFreeData
(
vRes
);
Vec_PtrShrink
(
vRes
,
0
);
return
0
;
}
return
1
;
}
/**Function*************************************************************
...
...
@@ -964,8 +999,8 @@ char * Abc_SopFromTruthBin( char * pTruth )
{
pCube
=
pSopCover
+
i
*
(
nVars
+
3
);
for
(
b
=
0
;
b
<
nVars
;
b
++
)
if
(
Mint
&
(
1
<<
(
nVars
-
1
-
b
))
)
//
if ( Mint & (1 << b) )
//
if ( Mint & (1 << (nVars-1-b)) )
if
(
Mint
&
(
1
<<
b
)
)
pCube
[
b
]
=
'1'
;
else
pCube
[
b
]
=
'0'
;
...
...
@@ -976,6 +1011,21 @@ char * Abc_SopFromTruthBin( char * pTruth )
Vec_IntFree
(
vMints
);
return
pSopCover
;
}
Vec_Ptr_t
*
Abc_SopFromTruthsBin
(
char
*
pTruth
)
{
Vec_Ptr_t
*
vRes
=
Vec_PtrAlloc
(
10
);
char
*
pCopy
=
Abc_UtilStrsav
(
pTruth
);
char
*
pToken
=
strtok
(
pCopy
,
"
\r\n\t
|"
);
while
(
pToken
)
{
if
(
!
Abc_SopCheckReadTruth
(
vRes
,
pToken
,
0
)
)
break
;
Vec_PtrPush
(
vRes
,
Abc_SopFromTruthBin
(
pToken
)
);
pToken
=
strtok
(
NULL
,
"
\r\n\t
|"
);
}
ABC_FREE
(
pCopy
);
return
vRes
;
}
/**Function*************************************************************
...
...
@@ -1058,6 +1108,21 @@ char * Abc_SopFromTruthHex( char * pTruth )
Vec_IntFree
(
vMints
);
return
pSopCover
;
}
Vec_Ptr_t
*
Abc_SopFromTruthsHex
(
char
*
pTruth
)
{
Vec_Ptr_t
*
vRes
=
Vec_PtrAlloc
(
10
);
char
*
pCopy
=
Abc_UtilStrsav
(
pTruth
);
char
*
pToken
=
strtok
(
pCopy
,
"
\r\n\t
|"
);
while
(
pToken
)
{
if
(
!
Abc_SopCheckReadTruth
(
vRes
,
pToken
,
1
)
)
break
;
Vec_PtrPush
(
vRes
,
Abc_SopFromTruthHex
(
pToken
)
);
pToken
=
strtok
(
NULL
,
"
\r\n\t
|"
);
}
ABC_FREE
(
pCopy
);
return
vRes
;
}
/**Function*************************************************************
...
...
src/base/io/io.c
View file @
6345832d
...
...
@@ -1115,7 +1115,7 @@ int IoCommandReadTruth( Abc_Frame_t * pAbc, int argc, char ** argv )
{
Abc_Ntk_t
*
pNtk
;
char
*
pStr
=
NULL
;
char
*
pSopCover
;
Vec_Ptr_t
*
vSops
;
int
fHex
=
1
;
int
fFile
=
0
;
int
c
;
...
...
@@ -1145,25 +1145,23 @@ int IoCommandReadTruth( Abc_Frame_t * pAbc, int argc, char ** argv )
pStr
=
Extra_FileReadContents
(
argv
[
globalUtilOptind
]
);
else
pStr
=
argv
[
globalUtilOptind
];
while
(
pStr
[
strlen
(
pStr
)
-
1
]
==
'\n'
||
pStr
[
strlen
(
pStr
)
-
1
]
==
'\r'
)
pStr
[
strlen
(
pStr
)
-
1
]
=
'\0'
;
// convert truth table to SOP
if
(
fHex
)
pSopCover
=
Abc_SopFromTruth
Hex
(
pStr
);
vSops
=
Abc_SopFromTruths
Hex
(
pStr
);
else
pSopCover
=
Abc_SopFromTruth
Bin
(
pStr
);
vSops
=
Abc_SopFromTruths
Bin
(
pStr
);
if
(
fFile
)
ABC_FREE
(
pStr
);
if
(
pSopCover
==
NULL
||
pSopCover
[
0
]
==
0
)
if
(
Vec_PtrSize
(
vSops
)
==
0
)
{
ABC_FREE
(
pSopCover
);
Vec_PtrFreeFree
(
vSops
);
fprintf
(
pAbc
->
Err
,
"Reading truth table has failed.
\n
"
);
return
1
;
}
pNtk
=
Abc_NtkCreateWithNode
(
pSopCover
);
ABC_FREE
(
pSopCover
);
pNtk
=
Abc_NtkCreateWithNode
s
(
vSops
);
Vec_PtrFreeFree
(
vSops
);
if
(
pNtk
==
NULL
)
{
fprintf
(
pAbc
->
Err
,
"Deriving the network has failed.
\n
"
);
...
...
@@ -1176,9 +1174,9 @@ int IoCommandReadTruth( Abc_Frame_t * pAbc, int argc, char ** argv )
usage:
fprintf
(
pAbc
->
Err
,
"usage: read_truth [-xfh] <truth> <file>
\n
"
);
fprintf
(
pAbc
->
Err
,
"
\t
creates network with node
having given truth table
\n
"
);
fprintf
(
pAbc
->
Err
,
"
\t
-x : toggles between bin and hex
represen
tation [default = %s]
\n
"
,
fHex
?
"hex"
:
"bin"
);
fprintf
(
pAbc
->
Err
,
"
\t
-f : toggles reading truth table from file [default = %s]
\n
"
,
fFile
?
"yes"
:
"no"
);
fprintf
(
pAbc
->
Err
,
"
\t
creates network with node
(s) having given truth table(s)
\n
"
);
fprintf
(
pAbc
->
Err
,
"
\t
-x : toggles between bin and hex
no
tation [default = %s]
\n
"
,
fHex
?
"hex"
:
"bin"
);
fprintf
(
pAbc
->
Err
,
"
\t
-f : toggles reading truth table
(s)
from file [default = %s]
\n
"
,
fFile
?
"yes"
:
"no"
);
fprintf
(
pAbc
->
Err
,
"
\t
-h : prints the command summary
\n
"
);
fprintf
(
pAbc
->
Err
,
"
\t
truth : truth table with most signficant bit first (e.g. 1000 for AND(a,b))
\n
"
);
fprintf
(
pAbc
->
Err
,
"
\t
file : file name with the truth table
\n
"
);
...
...
@@ -3250,19 +3248,23 @@ int IoCommandWriteTruths( Abc_Frame_t * pAbc, int argc, char **argv )
word
*
pTruth
;
int
nBytes
;
int
fReverse
=
0
;
int
fBinary
=
0
;
int
fHex
=
1
;
int
fBinaryFile
=
0
;
int
c
,
i
;
Extra_UtilGetoptReset
();
while
(
(
c
=
Extra_UtilGetopt
(
argc
,
argv
,
"rbh"
)
)
!=
EOF
)
while
(
(
c
=
Extra_UtilGetopt
(
argc
,
argv
,
"r
x
bh"
)
)
!=
EOF
)
{
switch
(
c
)
{
case
'r'
:
fReverse
^=
1
;
break
;
case
'x'
:
fHex
^=
1
;
break
;
case
'b'
:
fBinary
^=
1
;
fBinary
File
^=
1
;
break
;
case
'h'
:
goto
usage
;
...
...
@@ -3300,19 +3302,22 @@ int IoCommandWriteTruths( Abc_Frame_t * pAbc, int argc, char **argv )
Gia_ManForEachCo
(
pAbc
->
pGia
,
pObj
,
i
)
{
pTruth
=
Gia_ObjComputeTruthTable
(
pAbc
->
pGia
,
pObj
);
if
(
fBinary
)
if
(
fBinary
File
)
fwrite
(
pTruth
,
nBytes
,
1
,
pFile
);
else
else
if
(
fHex
)
Extra_PrintHex
(
pFile
,
(
unsigned
*
)
pTruth
,
Gia_ManPiNum
(
pAbc
->
pGia
)
),
fprintf
(
pFile
,
"
\n
"
);
else
Extra_PrintBinary
(
pFile
,
(
unsigned
*
)
pTruth
,
1
<<
Gia_ManPiNum
(
pAbc
->
pGia
)
),
fprintf
(
pFile
,
"
\n
"
);
}
fclose
(
pFile
);
return
0
;
usage
:
fprintf
(
pAbc
->
Err
,
"usage: &write_truths [-rbh] <file>
\n
"
);
fprintf
(
pAbc
->
Err
,
"usage: &write_truths [-r
x
bh] <file>
\n
"
);
fprintf
(
pAbc
->
Err
,
"
\t
writes truth tables of each PO of GIA manager into a file
\n
"
);
fprintf
(
pAbc
->
Err
,
"
\t
-r : toggle reversing bits in the truth table [default = %s]
\n
"
,
fReverse
?
"yes"
:
"no"
);
fprintf
(
pAbc
->
Err
,
"
\t
-b : toggle using binary format [default = %s]
\n
"
,
fBinary
?
"yes"
:
"no"
);
fprintf
(
pAbc
->
Err
,
"
\t
-x : toggle writing in the hex notation [default = %s]
\n
"
,
fHex
?
"yes"
:
"no"
);
fprintf
(
pAbc
->
Err
,
"
\t
-b : toggle using binary file format [default = %s]
\n
"
,
fBinaryFile
?
"yes"
:
"no"
);
fprintf
(
pAbc
->
Err
,
"
\t
-h : print the help massage
\n
"
);
fprintf
(
pAbc
->
Err
,
"
\t
file : the name of the file to write
\n
"
);
return
1
;
...
...
src/base/wln/wlnRtl.c
View file @
6345832d
...
...
@@ -77,6 +77,32 @@ void Rtl_NtkCleanFile( char * pFileName )
fclose
(
pFile2
);
}
void
Rtl_NtkCleanFile2
(
char
*
pFileName
)
{
char
*
pBuffer
,
*
pFileName2
=
"_temp__.v"
;
FILE
*
pFile
=
fopen
(
pFileName
,
"rb"
);
FILE
*
pFile2
;
if
(
pFile
==
NULL
)
{
printf
(
"Cannot open file
\"
%s
\"
for reading.
\n
"
,
pFileName
);
return
;
}
pFile2
=
fopen
(
pFileName2
,
"wb"
);
if
(
pFile2
==
NULL
)
{
fclose
(
pFile
);
printf
(
"Cannot open file
\"
%s
\"
for writing.
\n
"
,
pFileName2
);
return
;
}
pBuffer
=
ABC_ALLOC
(
char
,
MAX_LINE
);
while
(
fgets
(
pBuffer
,
MAX_LINE
,
pFile
)
!=
NULL
)
if
(
!
strstr
(
pBuffer
,
"//"
)
)
fputs
(
pBuffer
,
pFile2
);
ABC_FREE
(
pBuffer
);
fclose
(
pFile
);
fclose
(
pFile2
);
}
char
*
Wln_GetYosysName
()
{
char
*
pYosysName
=
NULL
;
...
...
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