Merge remote-tracking branch 'upstream/master' into yosys-experimental

This commit is contained in:
Miodrag Milanovic 2022-07-04 16:02:44 +02:00
commit 163af36fee
117 changed files with 12005 additions and 377 deletions

View File

@ -1,39 +0,0 @@
version: '{build}'
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2017"
VCVARS_SCRIPT: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat"
VCVARS_PLATFORM: x86
init:
- cmd: '"%VCVARS_SCRIPT%" %VCVARS_PLATFORM%'
build_script:
- cmd: |
sed -i 's#ABC_USE_PTHREADS"#ABC_DONT_USE_PTHREADS" /D "_XKEYCHECK_H"#g' *.dsp
awk 'BEGIN { del=0; } /# Begin Group "uap"/ { del=1; } /# End Group/ { if( del > 0 ) {del=0; next;} } del==0 {print;} ' abclib.dsp > tmp.dsp
copy tmp.dsp abclib.dsp
del tmp.dsp
unix2dos *.dsp
- cmd: |
appveyor PushArtifact abcspace.dsw
appveyor PushArtifact abclib.dsp
appveyor PushArtifact abcexe.dsp
- cmd: |
devenv abcspace.dsw /upgrade || dir
appveyor PushArtifact UpgradeLog.htm
msbuild abcspace.sln /m /nologo /p:Configuration=Release
- cmd: |
_TEST\abc.exe -c "r i10.aig; b; ps; b; rw -l; rw -lz; b; rw -lz; b; ps; cec"
- cmd: |
appveyor PushArtifact _TEST/abc.exe

62
.github/workflows/build-posix-cmake.yml vendored Normal file
View File

@ -0,0 +1,62 @@
on: [push]
jobs:
build-posix:
strategy:
matrix:
os: [macos-latest, ubuntu-latest]
use_namespace: [false, true]
runs-on: ${{ matrix.os }}
env:
CMAKE_ARGS: ${{ matrix.use_namespace && '-DABC_USE_NAMESPACE=xxx' || '' }}
DEMO_ARGS: ${{ matrix.use_namespace && '-DABC_NAMESPACE=xxx' || '' }}
DEMO_GCC: ${{ matrix.use_namespace && 'g++ -x c++' || 'gcc' }}
steps:
- name: Git Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Install brew dependencies
run: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install readline ninja
if: ${{ contains(matrix.os, 'macos') }}
- name: Install APT dependencies
run: |
sudo apt install -y libreadline-dev ninja-build
if: ${{ !contains(matrix.os, 'macos') }}
- name: Configure CMake
run: |
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ${CMAKE_ARGS} -B build
- name: Build CMake
run: |
cmake --build build
- name: Test Executable
run: |
./build/abc -c "r i10.aig; b; ps; b; rw -l; rw -lz; b; rw -lz; b; ps; cec"
- name: Test Library
run: |
${DEMO_GCC} ${DEMO_ARGS} -Wall -c src/demo.c -o demo.o
g++ -o demo demo.o build/libabc.a -lm -ldl -lreadline -lpthread
./demo i10.aig
- name: Stage Executable
run: |
mkdir staging
cp build/abc build/libabc.a staging/
- name: Upload pacakge artifact
uses: actions/upload-artifact@v1
with:
name: package
path: staging/

62
.github/workflows/build-posix.yml vendored Normal file
View File

@ -0,0 +1,62 @@
on: [push]
jobs:
build-posix:
strategy:
matrix:
os: [macos-latest, ubuntu-latest]
use_namespace: [false, true]
runs-on: ${{ matrix.os }}
env:
MAKE_ARGS: ${{ matrix.use_namespace && 'ABC_USE_NAMESPACE=xxx' || '' }}
DEMO_ARGS: ${{ matrix.use_namespace && '-DABC_NAMESPACE=xxx' || '' }}
DEMO_GCC: ${{ matrix.use_namespace && 'g++ -x c++' || 'gcc' }}
steps:
- name: Git Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Install brew dependencies
run: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install readline
if: ${{ contains(matrix.os, 'macos') }}
- name: Install APT dependencies
run: |
sudo apt install -y libreadline-dev
if: ${{ !contains(matrix.os, 'macos') }}
- name: Build Executable
run: |
make -j3 ${MAKE_ARGS} abc
- name: Test Executable
run: |
./abc -c "r i10.aig; b; ps; b; rw -l; rw -lz; b; rw -lz; b; ps; cec"
- name: Build Library
run: |
make -j3 ${MAKE_ARGS} libabc.a
- name: Test Library
run: |
${DEMO_GCC} ${DEMO_ARGS} -Wall -c src/demo.c -o demo.o
g++ -o demo demo.o libabc.a -lm -ldl -lreadline -lpthread
./demo i10.aig
- name: Stage Executable
run: |
mkdir staging
cp abc libabc.a staging/
- name: Upload pacakge artifact
uses: actions/upload-artifact@v1
with:
name: package
path: staging/

48
.github/workflows/build-windows.yml vendored Normal file
View File

@ -0,0 +1,48 @@
on: [push]
jobs:
build-windows:
runs-on: windows-2019
steps:
- name: Git Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Process project files to compile on Github Actions
run: |
sed -i 's#ABC_USE_PTHREADS\"#ABC_DONT_USE_PTHREADS\" /D \"_ALLOW_KEYWORD_MACROS=1\"#g' *.dsp
awk 'BEGIN { del=0; } /# Begin Group "uap"/ { del=1; } /# End Group/ { if( del > 0 ) {del=0; next;} } del==0 {print;} ' abclib.dsp > tmp.dsp
copy tmp.dsp abclib.dsp
del tmp.dsp
unix2dos *.dsp
- name: Prepare MSVC
uses: bus1/cabuild/action/msdevshell@v1
with:
architecture: x86
- name: Upgrade project files to latest Visual Studio, ignoring upgrade errors, and build
run: |
devenv abcspace.dsw /upgrade ; if (-not $? ) { cat UpgradeLog.htm }
msbuild abcspace.sln /m /nologo /p:Configuration=Release /p:PlatformTarget=x86
- name: Test Executable
run: |
_TEST\abc.exe -c "r i10.aig; b; ps; b; rw -l; rw -lz; b; rw -lz; b; ps; cec"
- name: Stage Executable
run: |
mkdir staging
copy _TEST/abc.exe staging/
copy UpgradeLog.htm staging/
- name: Upload pacakge artifact
uses: actions/upload-artifact@v1
with:
name: package
path: staging/

View File

@ -1,36 +0,0 @@
language: cpp
matrix:
include:
- os: linux
addons:
apt:
packages:
- libreadline-dev
- os: linux
addons:
apt:
packages:
- libreadline-dev
env:
MAKE_ARGS: ABC_USE_NAMESPACE=xxx
DEMO_ARGS: -DABC_NAMESPACE=xxx
- os: osx
osx_image: xcode10
addons:
homebrew:
packages:
- readline
script:
- make ${MAKE_ARGS} -j2 abc
- ./abc -c "r i10.aig; b; ps; b; rw -l; rw -lz; b; rw -lz; b; ps; cec"
- make ${MAKE_ARGS} libabc.a
- g++ ${DEMO_ARGS} -Wall -c src/demo.c -o demo.o
- g++ -o demo demo.o libabc.a -lm -ldl -lreadline -lpthread
- ./demo i10.aig

View File

@ -47,9 +47,14 @@ if(ABC_USE_NAMESPACE)
set(ABC_USE_NAMESPACE_FLAGS "ABC_USE_NAMESPACE=${ABC_USE_NAMESPACE}")
endif()
if( APPLE )
set(make_env ${CMAKE_COMMAND} -E env SDKROOT=${CMAKE_OSX_SYSROOT})
endif()
# run make to extract compiler options, linker options and list of source files
execute_process(
COMMAND
${make_env}
make
${ABC_READLINE_FLAGS}
${ABC_USE_NAMESPACE_FLAGS}

View File

@ -61,9 +61,9 @@ ifneq ($(findstring arm,$(shell uname -m)),)
CFLAGS += -DABC_MEMALIGN=4
endif
# compile ABC using the C++ comipler and put everything in the namespace $(ABC_NAMESPACE)
# compile ABC using the C++ compiler and put everything in the namespace $(ABC_NAMESPACE)
ifdef ABC_USE_NAMESPACE
CFLAGS += -DABC_NAMESPACE=$(ABC_USE_NAMESPACE) -fpermissive
CFLAGS += -DABC_NAMESPACE=$(ABC_USE_NAMESPACE) -fpermissive -x c++
CC := $(CXX)
$(info $(MSG_PREFIX)Compiling in namespace $(ABC_NAMESPACE))
endif

View File

@ -1,5 +1,6 @@
[![Build Status](https://travis-ci.org/berkeley-abc/abc.svg?branch=master)](https://travis-ci.org/berkeley-abc/abc)
[![Build status](https://ci.appveyor.com/api/projects/status/7q8gopidgvyos00d?svg=true)](https://ci.appveyor.com/project/berkeley-abc/abc)
[![.github/workflows/build-posix.yml](https://github.com/berkeley-abc/abc/actions/workflows/build-posix.yml/badge.svg)](https://github.com/berkeley-abc/abc/actions/workflows/build-posix.yml)
[![.github/workflows/build-windows.yml](https://github.com/berkeley-abc/abc/actions/workflows/build-windows.yml/badge.svg)](https://github.com/berkeley-abc/abc/actions/workflows/build-windows.yml)
[![.github/workflows/build-posix-cmake.yml](https://github.com/berkeley-abc/abc/actions/workflows/build-posix-cmake.yml/badge.svg)](https://github.com/berkeley-abc/abc/actions/workflows/build-posix-cmake.yml)
# ABC: System for Sequential Logic Synthesis and Formal Verification

2
abc.rc
View File

@ -132,7 +132,9 @@ alias src_rw "st; rw -l; rwz -l; rwz -l"
alias src_rs "st; rs -K 6 -N 2 -l; rs -K 9 -N 2 -l; rs -K 12 -N 2 -l"
alias src_rws "st; rw -l; rs -K 6 -N 2 -l; rwz -l; rs -K 9 -N 2 -l; rwz -l; rs -K 12 -N 2 -l"
alias resyn2rs "b; rs -K 6; rw; rs -K 6 -N 2; rf; rs -K 8; b; rs -K 8 -N 2; rw; rs -K 10; rwz; rs -K 10 -N 2; b; rs -K 12; rfz; rs -K 12 -N 2; rwz; b"
alias r2rs "b; rs -K 6; rw; rs -K 6 -N 2; rf; rs -K 8; b; rs -K 8 -N 2; rw; rs -K 10; rwz; rs -K 10 -N 2; b; rs -K 12; rfz; rs -K 12 -N 2; rwz; b"
alias compress2rs "b -l; rs -K 6 -l; rw -l; rs -K 6 -N 2 -l; rf -l; rs -K 8 -l; b -l; rs -K 8 -N 2 -l; rw -l; rs -K 10 -l; rwz -l; rs -K 10 -N 2 -l; b -l; rs -K 12 -l; rfz -l; rs -K 12 -N 2 -l; rwz -l; b -l"
alias c2rs "b -l; rs -K 6 -l; rw -l; rs -K 6 -N 2 -l; rf -l; rs -K 8 -l; b -l; rs -K 8 -N 2 -l; rw -l; rs -K 10 -l; rwz -l; rs -K 10 -N 2 -l; b -l; rs -K 12 -l; rfz -l; rs -K 12 -N 2 -l; rwz -l; b -l"
# use this script to convert 1-valued and DC-valued flops for an AIG
alias fix_aig "logic; undc; strash; zero"

View File

@ -88,6 +88,10 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\src\aig\gia\giaSif.c
# End Source File
# Begin Source File
SOURCE=.\src\base\main\main.c
# End Source File
# End Group

View File

@ -1127,6 +1127,18 @@ SOURCE=.\src\base\wln\wln.h
# End Source File
# Begin Source File
SOURCE=.\src\base\wln\wlnBlast.c
# End Source File
# Begin Source File
SOURCE=.\src\base\wln\wlnCom.c
# End Source File
# Begin Source File
SOURCE=.\src\base\wln\wlnGuide.c
# End Source File
# Begin Source File
SOURCE=.\src\base\wln\wlnMem.c
# End Source File
# Begin Source File
@ -1143,10 +1155,18 @@ SOURCE=.\src\base\wln\wlnObj.c
# End Source File
# Begin Source File
SOURCE=.\src\base\wln\wlnRead.c
# End Source File
# Begin Source File
SOURCE=.\src\base\wln\wlnRetime.c
# End Source File
# Begin Source File
SOURCE=.\src\base\wln\wlnRtl.c
# End Source File
# Begin Source File
SOURCE=.\src\base\wln\wlnWlc.c
# End Source File
# Begin Source File
@ -4911,6 +4931,14 @@ SOURCE=.\src\aig\gia\giaCSatOld.c
# End Source File
# Begin Source File
SOURCE=.\src\aig\gia\giaCSatP.c
# End Source File
# Begin Source File
SOURCE=.\src\aig\gia\giaCSatP.h
# End Source File
# Begin Source File
SOURCE=.\src\aig\gia\giaCTas.c
# End Source File
# Begin Source File
@ -5127,6 +5155,10 @@ SOURCE=.\src\aig\gia\giaResub3.c
# End Source File
# Begin Source File
SOURCE=.\src\aig\gia\giaResub6.c
# End Source File
# Begin Source File
SOURCE=.\src\aig\gia\giaRetime.c
# End Source File
# Begin Source File
@ -5183,6 +5215,10 @@ SOURCE=.\src\aig\gia\giaShrink7.c
# End Source File
# Begin Source File
SOURCE=.\src\aig\gia\giaSif.c
# End Source File
# Begin Source File
SOURCE=.\src\aig\gia\giaSim.c
# End Source File
# Begin Source File
@ -5567,6 +5603,10 @@ SOURCE=.\src\proof\cec\cecSatG2.c
# End Source File
# Begin Source File
SOURCE=.\src\proof\cec\cecSatG3.c
# End Source File
# Begin Source File
SOURCE=.\src\proof\cec\cecSeq.c
# End Source File
# Begin Source File

View File

@ -1154,7 +1154,7 @@ Aig_Man_t * Aig_ManDupOneOutput( Aig_Man_t * p, int iPoNum, int fAddRegs )
Aig_Man_t * pNew;
Aig_Obj_t * pObj = NULL;
int i;
assert( Aig_ManRegNum(p) > 0 );
//assert( Aig_ManRegNum(p) > 0 );
assert( iPoNum < Aig_ManCoNum(p)-Aig_ManRegNum(p) );
// create the new manager
pNew = Aig_ManStart( Aig_ManObjNumMax(p) );

View File

@ -1333,7 +1333,7 @@ void Aig_ManCounterExampleValueStart( Aig_Man_t * pAig, Abc_Cex_t * pCex )
pAig->pData2 = ABC_CALLOC( unsigned, Abc_BitWordNum( (pCex->iFrame + 1) * Aig_ManObjNumMax(pAig) ) );
// the register values in the counter-example should be zero
Saig_ManForEachLo( pAig, pObj, k )
assert( Abc_InfoHasBit(pCex->pData, iBit++) == 0 );
assert( Abc_InfoHasBit(pCex->pData, iBit) == 0 ), iBit++;
// iterate through the timeframes
nObjs = Aig_ManObjNumMax(pAig);
for ( i = 0; i <= pCex->iFrame; i++ )

View File

@ -1312,6 +1312,8 @@ extern Gia_Man_t * Gia_ManDupLastPis( Gia_Man_t * p, int nLastPis );
extern Gia_Man_t * Gia_ManDupFlip( Gia_Man_t * p, int * pInitState );
extern Gia_Man_t * Gia_ManDupCycled( Gia_Man_t * pAig, Abc_Cex_t * pCex, int nFrames );
extern Gia_Man_t * Gia_ManDup( Gia_Man_t * p );
extern Gia_Man_t * Gia_ManDupNoBuf( Gia_Man_t * p );
extern Gia_Man_t * Gia_ManDupMap( Gia_Man_t * p, Vec_Int_t * vMap );
extern Gia_Man_t * Gia_ManDup2( Gia_Man_t * p1, Gia_Man_t * p2 );
extern Gia_Man_t * Gia_ManDupWithAttributes( Gia_Man_t * p );
extern Gia_Man_t * Gia_ManDupRemovePis( Gia_Man_t * p, int nRemPis );
@ -1351,6 +1353,7 @@ extern Gia_Man_t * Gia_ManPermuteInputs( Gia_Man_t * p, int nPpis, int n
extern Gia_Man_t * Gia_ManDupDfsClasses( Gia_Man_t * p );
extern Gia_Man_t * Gia_ManDupTopAnd( Gia_Man_t * p, int fVerbose );
extern Gia_Man_t * Gia_ManMiter( Gia_Man_t * pAig0, Gia_Man_t * pAig1, int nInsDup, int fDualOut, int fSeq, int fImplic, int fVerbose );
extern Gia_Man_t * Gia_ManMiterInverse( Gia_Man_t * pBot, Gia_Man_t * pTop, int fDualOut, int fVerbose );
extern Gia_Man_t * Gia_ManDupAndOr( Gia_Man_t * p, int nOuts, int fUseOr, int fCompl );
extern Gia_Man_t * Gia_ManDupZeroUndc( Gia_Man_t * p, char * pInit, int nNewPis, int fGiaSimple, int fVerbose );
extern Gia_Man_t * Gia_ManMiter2( Gia_Man_t * p, char * pInit, int fVerbose );

View File

@ -611,6 +611,27 @@ Gia_Man_t * Gia_ManCompress2( Gia_Man_t * p, int fUpdateLevel, int fVerbose )
SeeAlso []
***********************************************************************/
int Gia_ManTestChoices( Gia_Man_t * p )
{
Gia_Obj_t * pObj; int i;
Vec_Int_t * vPointed = Vec_IntStart( Gia_ManObjNum(p) );
Gia_ManForEachAnd( p, pObj, i )
if ( Gia_ObjSibl(p, i) )
Vec_IntWriteEntry( vPointed, Gia_ObjSibl(p, i), 1 );
Gia_ManCreateRefs( p );
Gia_ManForEachAnd( p, pObj, i )
if ( Vec_IntEntry(vPointed, i) && Gia_ObjRefNumId(p, i) > 0 )
{
printf( "Gia_ManCheckChoices: Member %d", i );
printf( " of a choice node has %d fanouts.\n", Gia_ObjRefNumId(p, i) );
ABC_FREE( p->pRefs );
Vec_IntFree( vPointed );
return 0;
}
ABC_FREE( p->pRefs );
Vec_IntFree( vPointed );
return 1;
}
Gia_Man_t * Gia_ManPerformDch( Gia_Man_t * p, void * pPars )
{
int fUseMapping = 0;
@ -628,6 +649,11 @@ Gia_Man_t * Gia_ManPerformDch( Gia_Man_t * p, void * pPars )
// pGia = Gia_ManFromAig( pNew );
pGia = Gia_ManFromAigChoices( pNew );
Aig_ManStop( pNew );
if ( !p->pManTime && !Gia_ManTestChoices(pGia) )
{
Gia_ManStop( pGia );
pGia = Gia_ManDup( p );
}
Gia_ManTransferTiming( pGia, p );
return pGia;
}

1209
src/aig/gia/giaCSatP.c Normal file

File diff suppressed because it is too large Load Diff

117
src/aig/gia/giaCSatP.h Normal file
View File

@ -0,0 +1,117 @@
#ifndef ABC__aig__gia__giaCSatP_h
#define ABC__aig__gia__giaCSatP_h
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include "gia.h"
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_HEADER_START
typedef struct CbsP_Par_t_ CbsP_Par_t;
struct CbsP_Par_t_
{
// conflict limits
int nBTLimit; // limit on the number of conflicts
int nJustLimit; // limit on the size of justification queue
// current parameters
int nBTThis; // number of conflicts
int nBTThisNc; // number of conflicts
int nJustThis; // max size of the frontier
int nBTTotal; // total number of conflicts
int nJustTotal; // total size of the frontier
// decision heuristics
int fUseHighest; // use node with the highest ID
int fUseLowest; // use node with the highest ID
int fUseMaxFF; // use node with the largest fanin fanout
// other
int fVerbose;
int fUseProved;
// statistics
int nJscanThis;
int nRscanThis;
int nPropThis;
int maxJscanUndec;
int maxRscanUndec;
int maxPropUndec;
int maxJscanSolved;
int maxRscanSolved;
int maxPropSolved;
int nSat, nUnsat, nUndec;
long accJscanSat;
long accJscanUnsat;
long accJscanUndec;
long accRscanSat;
long accRscanUnsat;
long accRscanUndec;
long accPropSat;
long accPropUnsat;
long accPropUndec;
// other limits
int nJscanLimit;
int nRscanLimit;
int nPropLimit;
};
typedef struct CbsP_Que_t_ CbsP_Que_t;
struct CbsP_Que_t_
{
int iHead; // beginning of the queue
int iTail; // end of the queue
int nSize; // allocated size
Gia_Obj_t ** pData; // nodes stored in the queue
};
typedef struct CbsP_Man_t_ CbsP_Man_t;
struct CbsP_Man_t_
{
CbsP_Par_t Pars; // parameters
Gia_Man_t * pAig; // AIG manager
CbsP_Que_t pProp; // propagation queue
CbsP_Que_t pJust; // justification queue
CbsP_Que_t pClauses; // clause queue
Gia_Obj_t ** pIter; // iterator through clause vars
Vec_Int_t * vLevReas; // levels and decisions
Vec_Int_t * vValue;
Vec_Int_t * vModel; // satisfying assignment
Vec_Ptr_t * vTemp; // temporary storage
// SAT calls statistics
int nSatUnsat; // the number of proofs
int nSatSat; // the number of failure
int nSatUndec; // the number of timeouts
int nSatTotal; // the number of calls
// conflicts
int nConfUnsat; // conflicts in unsat problems
int nConfSat; // conflicts in sat problems
int nConfUndec; // conflicts in undec problems
// runtime stats
abctime timeSatUnsat; // unsat
abctime timeSatSat; // sat
abctime timeSatUndec; // undecided
abctime timeTotal; // total runtime
};
CbsP_Man_t * CbsP_ManAlloc( Gia_Man_t * pGia );
void CbsP_ManStop( CbsP_Man_t * p );
void CbsP_ManSatPrintStats( CbsP_Man_t * p );
void CbsP_PrintRecord( CbsP_Par_t * pPars );
int CbsP_ManSolve2( CbsP_Man_t * p, Gia_Obj_t * pObj, Gia_Obj_t * pObj2 );
#define CBS_UNSAT 1
#define CBS_SAT 0
#define CBS_UNDEC -1
ABC_NAMESPACE_HEADER_END
#endif

View File

@ -195,7 +195,7 @@ void Gia_ManCounterExampleValueStart( Gia_Man_t * pGia, Abc_Cex_t * pCex )
pGia->pData2 = ABC_CALLOC( unsigned, Abc_BitWordNum( (pCex->iFrame + 1) * Gia_ManObjNum(pGia) ) );
// the register values in the counter-example should be zero
Gia_ManForEachRo( pGia, pObj, k )
assert( Abc_InfoHasBit(pCex->pData, iBit++) == 0 );
assert( Abc_InfoHasBit(pCex->pData, iBit) == 0 ), iBit++;
// iterate through the timeframes
nObjs = Gia_ManObjNum(pGia);
for ( i = 0; i <= pCex->iFrame; i++ )

View File

@ -811,6 +811,55 @@ Gia_Man_t * Gia_ManDupRemovePis( Gia_Man_t * p, int nRemPis )
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
return pNew;
}
Gia_Man_t * Gia_ManDupNoBuf( Gia_Man_t * p )
{
Gia_Man_t * pNew;
Gia_Obj_t * pObj;
int i;
pNew = Gia_ManStart( Gia_ManObjNum(p) );
pNew->pName = Abc_UtilStrsav( p->pName );
pNew->pSpec = Abc_UtilStrsav( p->pSpec );
Gia_ManConst0(p)->Value = 0;
Gia_ManForEachObj1( p, pObj, i )
{
if ( Gia_ObjIsBuf(pObj) )
pObj->Value = Gia_ObjFanin0Copy(pObj);
else if ( Gia_ObjIsAnd(pObj) )
pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
else if ( Gia_ObjIsCi(pObj) )
pObj->Value = Gia_ManAppendCi( pNew );
else if ( Gia_ObjIsCo(pObj) )
pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
}
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
return pNew;
}
Gia_Man_t * Gia_ManDupMap( Gia_Man_t * p, Vec_Int_t * vMap )
{
Gia_Man_t * pNew, * pTemp;
Gia_Obj_t * pObj;
int i;
pNew = Gia_ManStart( Gia_ManObjNum(p) );
pNew->pName = Abc_UtilStrsav( p->pName );
pNew->pSpec = Abc_UtilStrsav( p->pSpec );
Gia_ManConst0(p)->Value = 0;
Gia_ManHashAlloc( pNew );
Gia_ManForEachObj1( p, pObj, i )
{
if ( Vec_IntEntry(vMap, i) >= 0 )
pObj->Value = Gia_ManObj( p, Vec_IntEntry(vMap, i) )->Value;
else if ( Gia_ObjIsAnd(pObj) )
pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
else if ( Gia_ObjIsCi(pObj) )
pObj->Value = Gia_ManAppendCi( pNew );
else if ( Gia_ObjIsCo(pObj) )
pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
}
pNew = Gia_ManCleanup( pTemp = pNew );
Gia_ManStop( pTemp );
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
return pNew;
}
/**Function*************************************************************
@ -865,7 +914,9 @@ Gia_Man_t * Gia_ManDupPerm( Gia_Man_t * p, Vec_Int_t * vPiPerm )
// Vec_IntFree( vPiPermInv );
Gia_ManForEachObj1( p, pObj, i )
{
if ( Gia_ObjIsAnd(pObj) )
if ( Gia_ObjIsBuf(pObj) )
pObj->Value = Gia_ManAppendBuf( pNew, Gia_ObjFanin0Copy(pObj) );
else if ( Gia_ObjIsAnd(pObj) )
pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
else if ( Gia_ObjIsCi(pObj) )
{
@ -1086,6 +1137,23 @@ Gia_Man_t * Gia_ManDupAppendNew( Gia_Man_t * pOne, Gia_Man_t * pTwo )
Gia_ManSetRegNum( pNew, Gia_ManRegNum(pOne) + Gia_ManRegNum(pTwo) );
return pNew;
}
void Gia_ManDupRebuild( Gia_Man_t * pNew, Gia_Man_t * p, Vec_Int_t * vLits, int fBufs )
{
Gia_Obj_t * pObj; int i;
assert( Vec_IntSize(vLits) == Gia_ManCiNum(p) );
Gia_ManConst0(p)->Value = 0;
Gia_ManForEachCi( p, pObj, i )
pObj->Value = Vec_IntEntry(vLits, i);
Gia_ManForEachAnd( p, pObj, i )
if ( fBufs && Gia_ObjIsBuf(pObj) )
pObj->Value = Gia_ManAppendBuf( pNew, Gia_ObjFanin0Copy(pObj) );
else
pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
Vec_IntClear( vLits );
Gia_ManForEachCo( p, pObj, i )
Vec_IntPush( vLits, Gia_ObjFanin0Copy(pObj) );
assert( Vec_IntSize(vLits) == Gia_ManCoNum(p) );
}
/**Function*************************************************************
@ -2932,6 +3000,92 @@ Gia_Man_t * Gia_ManMiter( Gia_Man_t * p0, Gia_Man_t * p1, int nInsDup, int fDual
return pNew;
}
/**Function*************************************************************
Synopsis [Creates miter of two designs.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Gia_Man_t * Gia_ManMiterInverse( Gia_Man_t * pBot, Gia_Man_t * pTop, int fDualOut, int fVerbose )
{
Gia_Man_t * pNew, * pTemp;
Gia_Obj_t * pObj;
int i, iLit;
int nInputs1 = Gia_ManCiNum(pTop) - Gia_ManCoNum(pBot);
int nInputs2 = Gia_ManCiNum(pBot) - Gia_ManCoNum(pTop);
if ( nInputs1 == nInputs2 )
printf( "Assuming that the circuits have %d shared inputs, ordered first.\n", nInputs1 );
else
{
printf( "The number of inputs and outputs does not match.\n" );
return NULL;
}
pNew = Gia_ManStart( Gia_ManObjNum(pBot) + Gia_ManObjNum(pTop) );
pNew->pName = Abc_UtilStrsav( "miter" );
Gia_ManFillValue( pBot );
Gia_ManFillValue( pTop );
Gia_ManConst0(pBot)->Value = 0;
Gia_ManConst0(pTop)->Value = 0;
Gia_ManHashAlloc( pNew );
Gia_ManForEachCi( pBot, pObj, i )
pObj->Value = Gia_ManAppendCi( pNew );
// Gia_ManForEachCo( pBot, pObj, i )
// Gia_ManMiter_rec( pNew, pBot, Gia_ObjFanin0(pObj) );
Gia_ManForEachAnd( pBot, pObj, i )
{
if ( Gia_ObjIsBuf(pObj) )
pObj->Value = Gia_ManAppendBuf( pNew, Gia_ObjFanin0Copy(pObj) );
else if ( Gia_ObjIsAnd(pObj) )
pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
}
Gia_ManForEachCo( pBot, pObj, i )
pObj->Value = Gia_ObjFanin0Copy(pObj);
Gia_ManForEachCi( pTop, pObj, i )
if ( i < nInputs1 )
pObj->Value = Gia_ManCi(pBot, i)->Value;
else
pObj->Value = Gia_ManCo(pBot, i-nInputs1)->Value;
// Gia_ManForEachCo( pTop, pObj, i )
// Gia_ManMiter_rec( pNew, pTop, Gia_ObjFanin0(pObj) );
Gia_ManForEachAnd( pTop, pObj, i )
{
if ( Gia_ObjIsBuf(pObj) )
pObj->Value = Gia_ManAppendBuf( pNew, Gia_ObjFanin0Copy(pObj) );
else if ( Gia_ObjIsAnd(pObj) )
pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
}
Gia_ManForEachCo( pTop, pObj, i )
{
if ( fDualOut )
{
Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
Gia_ManAppendCo( pNew, Gia_ManCi(pBot, i+nInputs1)->Value );
}
else
{
iLit = Gia_ManHashXor( pNew, Gia_ObjFanin0Copy(pObj), Gia_ManCi(pBot, i+nInputs1)->Value );
Gia_ManAppendCo( pNew, iLit );
}
}
Gia_ManHashStop( pNew );
pNew = Gia_ManCleanup( pTemp = pNew );
Gia_ManStop( pTemp );
assert( (pBot->vBarBufs == NULL) == (pTop->vBarBufs == NULL) );
if ( pBot->vBarBufs )
{
pNew->vBarBufs = Vec_IntAlloc( 1000 );
Vec_IntAppend( pNew->vBarBufs, pBot->vBarBufs );
Vec_IntAppend( pNew->vBarBufs, pTop->vBarBufs );
//printf( "Miter has %d buffers (%d groups).\n", pNew->nBufs, Vec_IntSize(pNew->vBarBufs) );
}
return pNew;
}
/**Function*************************************************************
Synopsis [Computes the AND of all POs.]
@ -5067,6 +5221,171 @@ Gia_Man_t * Gia_ManDupAddPis( Gia_Man_t * p, int nMulti )
return pNew;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Int_t * Gia_ManDupUifBoxTypes( Vec_Int_t * vBarBufs )
{
Vec_Int_t * vTypes = Vec_IntAlloc( 10 );
int i, Entry;
Vec_IntForEachEntry( vBarBufs, Entry, i )
if ( Vec_IntFind(vTypes, Entry & 0xFFFE) < 0 )
Vec_IntPush( vTypes, Entry & 0xFFFE );
return vTypes;
}
Vec_Wec_t ** Gia_ManDupUifBuildMap( Gia_Man_t * p )
{
Vec_Int_t * vTypes = Gia_ManDupUifBoxTypes( p->vBarBufs );
Vec_Wec_t ** pvMap = ABC_ALLOC( Vec_Wec_t *, 2*Vec_IntSize(vTypes) );
Vec_Int_t * vBufs = Vec_IntAlloc( p->nBufs );
Gia_Obj_t * pObj; int i, Item, j, k = 0;
Gia_ManForEachObj1( p, pObj, i )
if ( Gia_ObjIsBuf(pObj) )
Vec_IntPush( vBufs, i );
assert( p->nBufs == Vec_IntSize(vBufs) );
for ( i = 0; i < 2*Vec_IntSize(vTypes); i++ )
pvMap[i] = Vec_WecAlloc( 10 );
Vec_IntForEachEntry( p->vBarBufs, Item, i )
{
int Type = Vec_IntFind( vTypes, Item & 0xFFFE );
Vec_Int_t * vVec = Vec_WecPushLevel(pvMap[2*Type + (Item&1)]);
for ( j = 0; j < (Item >> 16); j++ )
Vec_IntPush( vVec, Vec_IntEntry(vBufs, k++) );
}
assert( p->nBufs == k );
for ( i = 0; i < Vec_IntSize(vTypes); i++ )
assert( Vec_WecSize(pvMap[2*i+0]) == Vec_WecSize(pvMap[2*i+1]) );
Vec_IntFree( vTypes );
Vec_IntFree( vBufs );
return pvMap;
}
int Gia_ManDupUifConstrOne( Gia_Man_t * pNew, Gia_Man_t * p, Vec_Int_t * vVec0, Vec_Int_t * vVec1 )
{
Vec_Int_t * vTemp = Vec_IntAlloc( Vec_IntSize(vVec0) );
int i, o0, o1, iRes;
Vec_IntForEachEntryTwo( vVec0, vVec1, o0, o1, i )
Vec_IntPush( vTemp, Gia_ManHashXor(pNew, Gia_ManObj(p, o0)->Value, Abc_LitNot(Gia_ManObj(p, o1)->Value)) );
iRes = Gia_ManHashAndMulti( pNew, vTemp );
Vec_IntFree( vTemp );
return iRes;
}
int Gia_ManDupUifConstr( Gia_Man_t * pNew, Gia_Man_t * p, Vec_Wec_t ** pvMap, int nTypes )
{
int t, i, k, iUif = 1;
for ( t = 0; t < nTypes; t++ )
{
assert( Vec_WecSize(pvMap[2*t+0]) == Vec_WecSize(pvMap[2*t+1]) );
for ( i = 0; i < Vec_WecSize(pvMap[2*t+0]); i++ )
for ( k = i + 1; k < Vec_WecSize(pvMap[2*t+0]); k++ )
{
int iCond1 = Gia_ManDupUifConstrOne( pNew, p, Vec_WecEntry(pvMap[2*t+0], i), Vec_WecEntry(pvMap[2*t+0], k) );
int iCond2 = Gia_ManDupUifConstrOne( pNew, p, Vec_WecEntry(pvMap[2*t+1], i), Vec_WecEntry(pvMap[2*t+1], k) );
int iRes = Gia_ManHashOr( pNew, Abc_LitNot(iCond1), iCond2 );
iUif = Gia_ManHashAnd( pNew, iUif, iRes );
}
}
return iUif;
}
Gia_Man_t * Gia_ManDupUif( Gia_Man_t * p )
{
Vec_Int_t * vTypes = Gia_ManDupUifBoxTypes( p->vBarBufs );
Vec_Wec_t ** pvMap = Gia_ManDupUifBuildMap( p );
Gia_Man_t * pNew, * pTemp; Gia_Obj_t * pObj;
int i, iUif = 0;
pNew = Gia_ManStart( Gia_ManObjNum(p) );
pNew->pName = Abc_UtilStrsav( p->pName );
pNew->pSpec = Abc_UtilStrsav( p->pSpec );
Gia_ManConst0(p)->Value = 0;
Gia_ManHashAlloc( pNew );
Gia_ManForEachObj1( p, pObj, i )
{
if ( Gia_ObjIsBuf(pObj) )
pObj->Value = Gia_ManAppendBuf( pNew, Gia_ObjFanin0Copy(pObj) );
else if ( Gia_ObjIsAnd(pObj) )
pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
else if ( Gia_ObjIsCi(pObj) )
pObj->Value = Gia_ManAppendCi( pNew );
else if ( Gia_ObjIsCo(pObj) )
pObj->Value = Gia_ObjFanin0Copy(pObj);
}
iUif = Gia_ManDupUifConstr( pNew, p, pvMap, Vec_IntSize(vTypes) );
Gia_ManForEachCo( p, pObj, i )
Gia_ManAppendCo( pNew, Gia_ManHashAnd(pNew, pObj->Value, iUif) );
pNew = Gia_ManCleanup( pTemp = pNew );
Gia_ManStop( pTemp );
for ( i = 0; i < 2*Vec_IntSize(vTypes); i++ )
Vec_WecFree( pvMap[i] );
ABC_FREE( pvMap );
if ( p->vBarBufs )
pNew->vBarBufs = Vec_IntDup( p->vBarBufs );
printf( "Added UIF constraints for %d type%s of boxes.\n", Vec_IntSize(vTypes), Vec_IntSize(vTypes) > 1 ? "s" :"" );
Vec_IntFree( vTypes );
return pNew;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Int_t * Gia_ManDupBlackBoxBuildMap( Gia_Man_t * p )
{
Vec_Int_t * vMap = Vec_IntAlloc( p->nBufs ); int i, Item;
Vec_IntForEachEntry( p->vBarBufs, Item, i )
Vec_IntFillExtra( vMap, Vec_IntSize(vMap) + (Item >> 16), Item & 1 );
assert( p->nBufs == Vec_IntSize(vMap) );
return vMap;
}
Gia_Man_t * Gia_ManDupBlackBox( Gia_Man_t * p )
{
Vec_Int_t * vMap = Gia_ManDupBlackBoxBuildMap( p );
Gia_Man_t * pNew, * pTemp;
Gia_Obj_t * pObj;
int i, k = 0, iCi = 0, nCis = Gia_ManCiNum(p) + Vec_IntSum(vMap);
pNew = Gia_ManStart( Gia_ManObjNum(p) );
pNew->pName = Abc_UtilStrsav( p->pName );
pNew->pSpec = Abc_UtilStrsav( p->pSpec );
Gia_ManConst0(p)->Value = 0;
for ( i = 0; i < nCis; i++ )
Gia_ManAppendCi( pNew );
Gia_ManHashAlloc( pNew );
Gia_ManForEachObj1( p, pObj, i )
{
if ( Gia_ObjIsBuf(pObj) )
{
if ( Vec_IntEntry(vMap, k++) ) // out
pObj->Value = Gia_ManCiLit(pNew, iCi++);
else
pObj->Value = Gia_ObjFanin0Copy(pObj);
}
else if ( Gia_ObjIsAnd(pObj) )
pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
else if ( Gia_ObjIsCi(pObj) )
pObj->Value = Gia_ManCiLit(pNew, iCi++);
else if ( Gia_ObjIsCo(pObj) )
pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
}
assert( k == p->nBufs && iCi == nCis );
pNew = Gia_ManCleanup( pTemp = pNew );
Gia_ManStop( pTemp );
Vec_IntFree( vMap );
return pNew;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////

View File

@ -539,7 +539,7 @@ void Gia_ManPrintStats( Gia_Man_t * p, Gps_Par_t * pPars )
Abc_Print( 1, " %s =%8d", p->pMuxes? "nod" : "and", Gia_ManAndNum(p) );
SetConsoleTextAttribute( hConsole, 13 ); // magenta
Abc_Print( 1, " lev =%5d", Gia_ManLevelNum(p) );
Abc_Print( 1, " (%.2f)", Gia_ManLevelAve(p) );
Abc_Print( 1, " (%7.2f)", Gia_ManLevelAve(p) );
SetConsoleTextAttribute( hConsole, 7 ); // normal
}
#else

View File

@ -182,13 +182,56 @@ void * Abc_FrameGiaOutputMiniAig( Abc_Frame_t * pAbc )
SeeAlso []
***********************************************************************/
void Gia_ManReadMiniAigNames( char * pFileName, Gia_Man_t * pGia )
{
char * filename3 = Abc_UtilStrsavTwo( pFileName, ".ilo" );
FILE * pFile = fopen( filename3, "rb" );
if ( pFile )
{
char Buffer[5000], * pName; int i, iLines = 0;
Vec_Ptr_t * vTemp = Vec_PtrAlloc( Gia_ManRegNum(pGia) );
assert( pGia->vNamesIn == NULL );
pGia->vNamesIn = Vec_PtrAlloc( Gia_ManCiNum(pGia) );
assert( pGia->vNamesOut == NULL );
pGia->vNamesOut = Vec_PtrAlloc( Gia_ManCoNum(pGia) );
while ( fgets(Buffer, 5000, pFile) )
{
if ( Buffer[strlen(Buffer)-1] == '\n' )
Buffer[strlen(Buffer)-1] = 0;
if ( iLines < Gia_ManPiNum(pGia) )
Vec_PtrPush( pGia->vNamesIn, Abc_UtilStrsav(Buffer) );
else if ( iLines < Gia_ManCiNum(pGia) )
Vec_PtrPush( vTemp, Abc_UtilStrsav(Buffer) );
else
Vec_PtrPush( pGia->vNamesOut, Abc_UtilStrsav(Buffer) );
iLines++;
}
Vec_PtrForEachEntry( char *, vTemp, pName, i )
{
Vec_PtrPush( pGia->vNamesIn, Abc_UtilStrsav(pName) );
Vec_PtrPush( pGia->vNamesOut, Abc_UtilStrsavTwo(pName, "_in") );
}
Vec_PtrFreeFree( vTemp );
fclose( pFile );
printf( "Read ILO names into file \"%s\".\n", filename3 );
}
ABC_FREE( filename3 );
}
Gia_Man_t * Gia_ManReadMiniAig( char * pFileName, int fGiaSimple )
{
Mini_Aig_t * p = Mini_AigLoad( pFileName );
Gia_Man_t * pGia = Gia_ManFromMiniAig( p, NULL, fGiaSimple );
Gia_Man_t * pTemp, * pGia = Gia_ManFromMiniAig( p, NULL, fGiaSimple );
ABC_FREE( pGia->pName );
pGia->pName = Extra_FileNameGeneric( pFileName );
Mini_AigStop( p );
Gia_ManReadMiniAigNames( pFileName, pGia );
if ( !Gia_ManIsNormalized(pGia) )
{
pGia = Gia_ManDupNormalize( pTemp = pGia, 0 );
ABC_SWAP( Vec_Ptr_t *, pTemp->vNamesIn, pGia->vNamesIn );
ABC_SWAP( Vec_Ptr_t *, pTemp->vNamesOut, pGia->vNamesOut );
Gia_ManStop( pTemp );
}
return pGia;
}
void Gia_ManWriteMiniAig( Gia_Man_t * pGia, char * pFileName )
@ -764,7 +807,10 @@ int * Abc_FrameReadMiniAigEquivClasses( Abc_Frame_t * pAbc )
if ( pAbc->pGia2 == NULL )
printf( "Internal GIA with equivalence classes is not available.\n" );
if ( pAbc->pGia2->pReprs == NULL )
{
printf( "Equivalence classes of internal GIA are not available.\n" );
return NULL;
}
if ( Gia_ManObjNum(pAbc->pGia2) != Gia_ManObjNum(pAbc->pGiaMiniAig) )
printf( "Internal GIA with equivalence classes is not directly derived from MiniAig.\n" );
// derive the set of equivalent node pairs

View File

@ -147,6 +147,73 @@ Gia_Man_t * Gia_ManDupMuxes( Gia_Man_t * p, int Limit )
return pNew;
}
/**Function*************************************************************
Synopsis [Creates AIG with XORs.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Gia_Man_t * Gia_ManCreateXors( Gia_Man_t * p )
{
Gia_Man_t * pNew; Gia_Obj_t * pObj, * pFan0, * pFan1;
Vec_Int_t * vRefs = Vec_IntStart( Gia_ManObjNum(p) );
int i, iLit0, iLit1, nXors = 0, nObjs = 0;
Gia_ManForEachObj( p, pObj, i )
pObj->fMark0 = 0;
Gia_ManForEachAnd( p, pObj, i )
{
if ( Gia_ObjRecognizeExor(pObj, &pFan0, &pFan1) )
{
Vec_IntAddToEntry( vRefs, Gia_ObjId(p, Gia_Regular(pFan0)), 1 );
Vec_IntAddToEntry( vRefs, Gia_ObjId(p, Gia_Regular(pFan1)), 1 );
pObj->fMark0 = 1;
nXors++;
}
else
{
Vec_IntAddToEntry( vRefs, Gia_ObjFaninId0(pObj, i), 1 );
Vec_IntAddToEntry( vRefs, Gia_ObjFaninId1(pObj, i), 1 );
}
}
Gia_ManForEachCo( p, pObj, i )
Vec_IntAddToEntry( vRefs, Gia_ObjFaninId0p(p, pObj), 1 );
Gia_ManForEachAnd( p, pObj, i )
nObjs += Vec_IntEntry(vRefs, i) > 0;
pNew = Gia_ManStart( 1 + Gia_ManCiNum(p) + Gia_ManCoNum(p) + nObjs );
pNew->pName = Abc_UtilStrsav( p->pName );
pNew->pSpec = Abc_UtilStrsav( p->pSpec );
Gia_ManConst0(p)->Value = 0;
Gia_ManForEachObj1( p, pObj, i )
{
if ( Gia_ObjIsCi(pObj) )
pObj->Value = Gia_ManAppendCi( pNew );
else if ( Gia_ObjIsCo(pObj) )
pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
else if ( Gia_ObjIsBuf(pObj) )
pObj->Value = Gia_ManAppendBuf( pNew, Gia_ObjFanin0Copy(pObj) );
else if ( pObj->fMark0 )
{
Gia_ObjRecognizeExor(pObj, &pFan0, &pFan1);
iLit0 = Abc_LitNotCond( Gia_Regular(pFan0)->Value, Gia_IsComplement(pFan0) );
iLit1 = Abc_LitNotCond( Gia_Regular(pFan1)->Value, Gia_IsComplement(pFan1) );
pObj->Value = Gia_ManAppendXorReal( pNew, iLit0, iLit1 );
}
else if ( Vec_IntEntry(vRefs, i) > 0 )
pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
}
assert( pNew->nObjs == pNew->nObjsAlloc );
pNew->pMuxes = ABC_CALLOC( unsigned, pNew->nObjs );
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
Vec_IntFree( vRefs );
//printf( "Created %d XORs.\n", nXors );
return pNew;
}
/**Function*************************************************************
Synopsis [Derives GIA without MUXes.]

View File

@ -346,7 +346,7 @@ void Min_LitMinimize( Min_Man_t * p, int iLit, Vec_Int_t * vLits )
Min_ObjMarkValL( p, Abc_Lit2Var(iLit1) );
else if ( Val0 == 4 && Val1 != 4 )
Min_ObjMarkValL( p, Abc_Lit2Var(iLit0) );
else if ( Val1 == 4 && Val1 != 4 )
else if ( Val1 == 4 && Val0 != 4 )
Min_ObjMarkValL( p, Abc_Lit2Var(iLit1) );
else if ( Abc_Random(0) & 1 )
Min_ObjMarkValL( p, Abc_Lit2Var(iLit0) );
@ -890,6 +890,8 @@ int Min_ManCountSize( Vec_Wec_t * vCexes, int iFirst, int iLimit )
}
Vec_Wec_t * Min_ManComputeCexes( Gia_Man_t * p, Vec_Int_t * vOuts0, int nMaxTries, int nMinCexes, Vec_Int_t * vStats[3], int fUseSim, int fUseSat, int fVerbose )
{
int fUseSynthesis = 1;
abctime clkSim = Abc_Clock(), clkSat = Abc_Clock();
Vec_Int_t * vOuts = vOuts0 ? vOuts0 : Vec_IntStartNatural( Gia_ManCoNum(p) );
Min_Man_t * pNew = Min_ManFromGia( p, vOuts );
Vec_Wec_t * vCexes = Vec_WecStart( Vec_IntSize(vOuts) * nMinCexes );
@ -945,6 +947,7 @@ Vec_Wec_t * Min_ManComputeCexes( Gia_Man_t * p, Vec_Int_t * vOuts0, int nMaxTrie
assert( Vec_IntSize(vOuts) == Vec_IntSize(vStats[0]) );
assert( Vec_IntSize(vOuts) == Vec_IntSize(vStats[1]) );
assert( Vec_IntSize(vOuts) == Vec_IntSize(vStats[2]) );
clkSim = Abc_Clock() - clkSim;
if ( fUseSat )
Gia_ManForEachCoVec( vOuts, p, pObj, i )
@ -952,11 +955,13 @@ Vec_Wec_t * Min_ManComputeCexes( Gia_Man_t * p, Vec_Int_t * vOuts0, int nMaxTrie
if ( Vec_IntEntry(vStats[2], i) >= nMinCexes || Vec_IntEntry(vStats[1], i) > 10*Vec_IntEntry(vStats[2], i) )
continue;
{
abctime clk = Abc_Clock();
int iObj = Min_ManCo(pNew, i);
int Index = Gia_ObjCioId(pObj);
Vec_Int_t * vMap = Vec_IntAlloc( 100 );
Gia_Man_t * pCon = Gia_ManDupCones2( p, &Index, 1, vMap );
Cnf_Dat_t * pCnf = (Cnf_Dat_t *)Mf_ManGenerateCnf( pCon, 8, 0, 0, 0, 0 );
Gia_Man_t * pCon1= fUseSynthesis ? Gia_ManAigSyn2( pCon, 0, 1, 0, 100, 0, 0, 0 ) : NULL;
Cnf_Dat_t * pCnf = (Cnf_Dat_t *)Mf_ManGenerateCnf( fUseSynthesis ? pCon1 : pCon, 8, 0, 0, 0, 0 );
sat_solver* pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, 1, 0 );
int Lit = Abc_Var2Lit( 1, 0 );
int status = sat_solver_addclause( pSat, &Lit, &Lit+1 );
@ -972,8 +977,11 @@ Vec_Wec_t * Min_ManComputeCexes( Gia_Man_t * p, Vec_Int_t * vOuts0, int nMaxTrie
while ( nAllCalls++ < 100 )
{
int v, iVar = pCnf->nVars - Gia_ManPiNum(pCon), nVars = Gia_ManPiNum(pCon);
sat_solver_randomize( pSat, iVar, nVars );
if ( nAllCalls > 1 )
sat_solver_randomize( pSat, iVar, nVars );
status = sat_solver_solve( pSat, NULL, NULL, 0, 0, 0, 0 );
if ( status != l_True )
break;
assert( status == l_True );
Vec_IntClear( vLits );
for ( v = 0; v < nVars; v++ )
@ -1004,11 +1012,22 @@ Vec_Wec_t * Min_ManComputeCexes( Gia_Man_t * p, Vec_Int_t * vOuts0, int nMaxTrie
sat_solver_delete( pSat );
Cnf_DataFree( pCnf );
Gia_ManStop( pCon );
Gia_ManStopP( &pCon1 );
Vec_IntFree( vMap );
if ( fVerbose )
{
printf( "SAT solving for output %3d (cexes = %5d) : ", i, nCurrCexes );
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
}
}
}
clkSat = Abc_Clock() - clkSat - clkSim;
if ( fVerbose )
printf( "Used simulation for %d and SAT for %d outputs (out of %d).\n", nSimOuts, nSatOuts, nOuts );
if ( fVerbose )
Abc_PrintTime( 1, "Simulation time ", clkSim );
if ( fVerbose )
Abc_PrintTime( 1, "SAT solving time ", clkSat );
//Vec_WecPrint( vCexes, 0 );
if ( vOuts != vOuts0 )
Vec_IntFreeP( &vOuts );
@ -1076,7 +1095,7 @@ Vec_Ptr_t * Min_ReloadCexes( Vec_Wec_t * vCexes, int nMinCexes )
Vec_Wrd_t * Min_ManBitPack( Gia_Man_t * p, int nWords0, Vec_Wec_t * vCexes, int fRandom, int nMinCexes, Vec_Int_t * vScores, int fVerbose )
{
abctime clk = Abc_Clock();
int fVeryVerbose = 0;
//int fVeryVerbose = 0;
Vec_Wrd_t * vSimsPi = NULL;
Vec_Int_t * vLevel;
int w, nBits, nTotal = 0, fFailed = ABC_INFINITY;
@ -1259,39 +1278,51 @@ Vec_Wrd_t * Gia_ManCollectSims( Gia_Man_t * pSwp, int nWords, Vec_Int_t * vOuts,
Vec_Int_t * vMap = Vec_IntAlloc( 100 );
Gia_Man_t * pSwp2 = Gia_ManDupCones2( pSwp, Vec_IntArray(vOuts), Vec_IntSize(vOuts), vMap );
Vec_Wec_t * vCexes = Min_ManComputeCexes( pSwp2, NULL, nMaxTries, nMinCexes, vStats, fUseSim, fUseSat, fVerbose );
Vec_Wrd_t * vSimsPi = Min_ManBitPack( pSwp2, nWords, vCexes, 1, nMinCexes, vStats[0], fVerbose );
Vec_Wrd_t * vSimsPo = Gia_ManSimPatSimOut( pSwp2, vSimsPi, 1 );
Vec_Int_t * vCounts = Patt_ManOutputErrorCoverage( vSimsPo, Vec_IntSize(vOuts) );
if ( fVerbose )
Patt_ManProfileErrorsOne( vSimsPo, Vec_IntSize(vOuts) );
if ( fVeryVerbose )
if ( Vec_IntSum(vStats[2]) == 0 )
{
printf( "Unsolved = %4d ", Vec_IntSize(vOuts) );
Gia_ManPrintStats( pSwp2, NULL );
Vec_IntForEachEntry( vOuts, iObj, i )
{
printf( "%4d : ", i );
printf( "Out = %5d ", Vec_IntEntry(vMap, i) );
printf( "SimAll =%8d ", Vec_IntEntry(vStats[0], i) );
printf( "SimGood =%8d ", Vec_IntEntry(vStats[1], i) );
printf( "PatsAll =%8d ", Vec_IntEntry(vStats[2], i) );
printf( "Count = %5d ", Vec_IntEntry(vCounts, i) );
printf( "\n" );
if ( i == 20 )
break;
}
for ( i = 0; i < 3; i++ )
Vec_IntFree( vStats[i] );
Vec_IntFree( vMap );
Gia_ManStop( pSwp2 );
Vec_WecFree( vCexes );
return NULL;
}
else
{
Vec_Wrd_t * vSimsPi = Min_ManBitPack( pSwp2, nWords, vCexes, 1, nMinCexes, vStats[0], fVerbose );
Vec_Wrd_t * vSimsPo = Gia_ManSimPatSimOut( pSwp2, vSimsPi, 1 );
Vec_Int_t * vCounts = Patt_ManOutputErrorCoverage( vSimsPo, Vec_IntSize(vOuts) );
if ( fVerbose )
Patt_ManProfileErrorsOne( vSimsPo, Vec_IntSize(vOuts) );
if ( fVeryVerbose )
{
printf( "Unsolved = %4d ", Vec_IntSize(vOuts) );
Gia_ManPrintStats( pSwp2, NULL );
Vec_IntForEachEntry( vOuts, iObj, i )
{
printf( "%4d : ", i );
printf( "Out = %5d ", Vec_IntEntry(vMap, i) );
printf( "SimAll =%8d ", Vec_IntEntry(vStats[0], i) );
printf( "SimGood =%8d ", Vec_IntEntry(vStats[1], i) );
printf( "PatsAll =%8d ", Vec_IntEntry(vStats[2], i) );
printf( "Count = %5d ", Vec_IntEntry(vCounts, i) );
printf( "\n" );
if ( i == 20 )
break;
}
}
for ( i = 0; i < 3; i++ )
Vec_IntFree( vStats[i] );
Vec_IntFree( vCounts );
Vec_WrdFree( vSimsPo );
Vec_WecFree( vCexes );
Gia_ManStop( pSwp2 );
//printf( "Compressing inputs: %5d -> %5d\n", Gia_ManCiNum(pSwp), Vec_IntSize(vMap) );
vSimsPi = Min_ManRemapSims( Gia_ManCiNum(pSwp), vMap, vSimsPo = vSimsPi );
Vec_WrdFree( vSimsPo );
Vec_IntFree( vMap );
return vSimsPi;
}
for ( i = 0; i < 3; i++ )
Vec_IntFree( vStats[i] );
Vec_IntFree( vCounts );
Vec_WrdFree( vSimsPo );
Vec_WecFree( vCexes );
Gia_ManStop( pSwp2 );
//printf( "Compressing inputs: %5d -> %5d\n", Gia_ManCiNum(pSwp), Vec_IntSize(vMap) );
vSimsPi = Min_ManRemapSims( Gia_ManCiNum(pSwp), vMap, vSimsPo = vSimsPi );
Vec_WrdFree( vSimsPo );
Vec_IntFree( vMap );
return vSimsPi;
}
Vec_Wrd_t * Min_ManCollect( Gia_Man_t * p, int nConf, int nConf2, int nMaxTries, int nMinCexes, int fUseSim, int fUseSat, int fVerbose, int fVeryVerbose )
{

451
src/aig/gia/giaResub6.c Normal file
View File

@ -0,0 +1,451 @@
/**CFile****************************************************************
FileName [giaResub6.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Scalable AIG package.]
Synopsis [Resubstitution.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: giaResub6.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "gia.h"
#include "misc/util/utilTruth.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
#define MAX_NODE 100
typedef struct Res6_Man_t_ Res6_Man_t;
struct Res6_Man_t_
{
int nIns; // inputs
int nDivs; // divisors
int nDivsA; // divisors alloc
int nOuts; // outputs
int nPats; // patterns
int nWords; // words
Vec_Wrd_t vIns; // input sim data
Vec_Wrd_t vOuts; // input sim data
word ** ppLits; // literal sim info
word ** ppSets; // set sim info
Vec_Int_t vSol; // current solution
Vec_Int_t vSolBest; // best solution
Vec_Int_t vTempBest;// current best solution
};
extern void Dau_DsdPrintFromTruth2( word * pTruth, int nVarsInit );
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline Res6_Man_t * Res6_ManStart( int nIns, int nNodes, int nOuts, int nPats )
{
Res6_Man_t * p; int i;
p = ABC_CALLOC( Res6_Man_t, 1 );
p->nIns = nIns;
p->nDivs = 1 + nIns + nNodes;
p->nDivsA = p->nDivs + MAX_NODE;
p->nOuts = nOuts;
p->nPats = nPats;
p->nWords =(nPats + 63)/64;
Vec_WrdFill( &p->vIns, 2*p->nDivsA*p->nWords, 0 );
Vec_WrdFill( &p->vOuts, (1 << nOuts)*p->nWords, 0 );
p->ppLits = ABC_CALLOC( word *, 2*p->nDivsA );
p->ppSets = ABC_CALLOC( word *, 1 << nOuts );
for ( i = 0; i < 2*p->nDivsA; i++ )
p->ppLits[i] = Vec_WrdEntryP( &p->vIns, i*p->nWords );
for ( i = 0; i < (1 << nOuts); i++ )
p->ppSets[i] = Vec_WrdEntryP( &p->vOuts, i*p->nWords );
Abc_TtFill( p->ppLits[1], p->nWords );
Vec_IntGrow( &p->vSol, 2*MAX_NODE+nOuts );
Vec_IntGrow( &p->vSolBest, 2*MAX_NODE+nOuts );
Vec_IntGrow( &p->vTempBest, 2*MAX_NODE+nOuts );
return p;
}
static inline void Res6_ManStop( Res6_Man_t * p )
{
Vec_WrdErase( &p->vIns );
Vec_WrdErase( &p->vOuts );
Vec_IntErase( &p->vSol );
Vec_IntErase( &p->vSolBest );
Vec_IntErase( &p->vTempBest );
ABC_FREE( p->ppLits );
ABC_FREE( p->ppSets );
ABC_FREE( p );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Res6_Man_t * Res6_ManRead( char * pFileName )
{
Res6_Man_t * p = NULL;
FILE * pFile = fopen( pFileName, "rb" );
if ( pFile == NULL )
printf( "Cannot open input file \"%s\".\n", pFileName );
else
{
int i, k, nIns, nNodes, nOuts, nPats;
char Temp[100], Buffer[100];
char * pLine = fgets( Buffer, 100, pFile );
if ( pLine == NULL )
{
printf( "Cannot read the header line of input file \"%s\".\n", pFileName );
return NULL;
}
if ( 5 != sscanf(pLine, "%s %d %d %d %d", Temp, &nIns, &nNodes, &nOuts, &nPats) )
{
printf( "Cannot read the parameters from the header of input file \"%s\".\n", pFileName );
return NULL;
}
p = Res6_ManStart( nIns, nNodes, nOuts, nPats );
pLine = ABC_ALLOC( char, nPats + 100 );
for ( i = 1; i < p->nDivs; i++ )
{
char * pNext = fgets( pLine, nPats + 100, pFile );
if ( pNext == NULL )
{
printf( "Cannot read line %d of input file \"%s\".\n", i, pFileName );
Res6_ManStop( p );
ABC_FREE( pLine );
fclose( pFile );
return NULL;
}
for ( k = 0; k < p->nPats; k++ )
if ( pNext[k] == '0' )
Abc_TtSetBit( p->ppLits[2*i+1], k );
else if ( pNext[k] == '1' )
Abc_TtSetBit( p->ppLits[2*i], k );
}
for ( i = 0; i < (1 << p->nOuts); i++ )
{
char * pNext = fgets( pLine, nPats + 100, pFile );
if ( pNext == NULL )
{
printf( "Cannot read line %d of input file \"%s\".\n", i, pFileName );
Res6_ManStop( p );
ABC_FREE( pLine );
fclose( pFile );
return NULL;
}
for ( k = 0; k < p->nPats; k++ )
if ( pNext[k] == '1' )
Abc_TtSetBit( p->ppSets[i], k );
}
ABC_FREE( pLine );
fclose( pFile );
}
return p;
}
void Res6_ManWrite( char * pFileName, Res6_Man_t * p )
{
FILE * pFile = fopen( pFileName, "wb" );
if ( pFile == NULL )
printf( "Cannot open output file \"%s\".\n", pFileName );
else
{
int i, k;
fprintf( pFile, "resyn %d %d %d %d\n", p->nIns, p->nDivs - p->nIns - 1, p->nOuts, p->nPats );
for ( i = 1; i < p->nDivs; i++, fputc('\n', pFile) )
for ( k = 0; k < p->nPats; k++ )
if ( Abc_TtGetBit(p->ppLits[2*i+1], k) )
fputc( '0', pFile );
else if ( Abc_TtGetBit(p->ppLits[2*i], k) )
fputc( '1', pFile );
else
fputc( '-', pFile );
for ( i = 0; i < (1 << p->nOuts); i++, fputc('\n', pFile) )
for ( k = 0; k < p->nPats; k++ )
fputc( '0' + Abc_TtGetBit(p->ppSets[i], k), pFile );
fclose( pFile );
}
}
void Res6_ManPrintProblem( Res6_Man_t * p, int fVerbose )
{
int i, nInputs = (p->nIns && p->nIns < 6) ? p->nIns : 6;
printf( "Problem: In = %d Div = %d Out = %d Pattern = %d\n", p->nIns, p->nDivs - p->nIns - 1, p->nOuts, p->nPats );
if ( !fVerbose )
return;
printf( "%02d : %s\n", 0, "const0" );
printf( "%02d : %s\n", 1, "const1" );
for ( i = 1; i < p->nDivs; i++ )
{
if ( nInputs < 6 )
{
*p->ppLits[2*i+0] = Abc_Tt6Stretch( *p->ppLits[2*i+0], nInputs );
*p->ppLits[2*i+1] = Abc_Tt6Stretch( *p->ppLits[2*i+1], nInputs );
}
printf("%02d : ", 2*i+0), Dau_DsdPrintFromTruth2(p->ppLits[2*i+0], nInputs), printf( "\n" );
printf("%02d : ", 2*i+1), Dau_DsdPrintFromTruth2(p->ppLits[2*i+1], nInputs), printf( "\n" );
}
for ( i = 0; i < (1 << p->nOuts); i++ )
{
if ( nInputs < 6 )
*p->ppSets[i] = Abc_Tt6Stretch( *p->ppSets[i], nInputs );
printf("%02d : ", i), Dau_DsdPrintFromTruth2(p->ppSets[i], nInputs), printf( "\n" );
}
}
static inline Vec_Int_t * Res6_ManReadSol( char * pFileName )
{
Vec_Int_t * vRes = NULL; int Num;
FILE * pFile = fopen( pFileName, "rb" );
if ( pFile == NULL )
printf( "Cannot open input file \"%s\".\n", pFileName );
else
{
while ( fgetc(pFile) != '\n' );
vRes = Vec_IntAlloc( 10 );
while ( fscanf(pFile, "%d", &Num) == 1 )
Vec_IntPush( vRes, Num );
fclose ( pFile );
}
return vRes;
}
static inline void Res6_ManWriteSol( char * pFileName, Vec_Int_t * p )
{
FILE * pFile = fopen( pFileName, "wb" );
if ( pFile == NULL )
printf( "Cannot open output file \"%s\".\n", pFileName );
else
{
int i, iLit;
Vec_IntForEachEntry( p, iLit, i )
fprintf( pFile, "%d ", iLit );
fclose ( pFile );
}
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline int Res6_LitSign( int iLit )
{
return Abc_LitIsCompl(iLit) ? '~' : ' ';
}
static inline int Res6_LitChar( int iLit, int nDivs )
{
return Abc_Lit2Var(iLit) < nDivs ? (nDivs < 28 ? 'a'+Abc_Lit2Var(iLit)-1 : 'd') : 'x';
}
static inline void Res6_LitPrint( int iLit, int nDivs )
{
if ( iLit < 2 )
printf( "%d", iLit );
else
{
printf( "%c%c", Res6_LitSign(iLit), Res6_LitChar(iLit, nDivs) );
if ( Abc_Lit2Var(iLit) >= nDivs || nDivs >= 28 )
printf( "%d", Abc_Lit2Var(iLit) );
}
}
Vec_Int_t * Res6_FindSupport( Vec_Int_t * vSol, int nDivs )
{
int i, iLit;
Vec_Int_t * vSupp = Vec_IntAlloc( 10 );
Vec_IntForEachEntry( vSol, iLit, i )
if ( iLit >= 2 && iLit < 2*nDivs )
Vec_IntPushUnique( vSupp, Abc_Lit2Var(iLit) );
return vSupp;
}
void Res6_PrintSuppSims( Vec_Int_t * vSol, word ** ppLits, int nWords, int nDivs )
{
Vec_Int_t * vSupp = Res6_FindSupport( vSol, nDivs );
int i, k, iObj;
Vec_IntForEachEntry( vSupp, iObj, i )
{
for ( k = 0; k < 64*nWords; k++ )
if ( Abc_TtGetBit(ppLits[2*iObj+1], k) )
printf( "0" );
else if ( Abc_TtGetBit(ppLits[2*iObj], k) )
printf( "1" );
else
printf( "-" );
printf( "\n" );
}
for ( k = 0; k < 64*nWords; k++ )
{
Vec_IntForEachEntry( vSupp, iObj, i )
if ( Abc_TtGetBit(ppLits[2*iObj+1], k) )
printf( "0" );
else if ( Abc_TtGetBit(ppLits[2*iObj+0], k) )
printf( "1" );
else
printf( "-" );
printf( "\n" );
if ( k == 9 )
break;
}
Vec_IntFree( vSupp );
}
int Res6_FindSupportSize( Vec_Int_t * vSol, int nDivs )
{
Vec_Int_t * vSupp = Res6_FindSupport( vSol, nDivs );
int Res = Vec_IntSize(vSupp);
Vec_IntFree( vSupp );
return Res;
}
void Res6_PrintSolution( Vec_Int_t * vSol, int nDivs )
{
int iNode, nNodes = Vec_IntSize(vSol)/2-1;
assert( Vec_IntSize(vSol) % 2 == 0 );
printf( "Solution: In = %d Div = %d Node = %d Out = %d\n", Res6_FindSupportSize(vSol, nDivs), nDivs-1, nNodes, 1 );
for ( iNode = 0; iNode <= nNodes; iNode++ )
{
int * pLits = Vec_IntEntryP( vSol, 2*iNode );
printf( "x%-2d = ", nDivs + iNode );
Res6_LitPrint( pLits[0], nDivs );
if ( pLits[0] != pLits[1] )
{
printf( " %c ", pLits[0] < pLits[1] ? '&' : '^' );
Res6_LitPrint( pLits[1], nDivs );
}
printf( "\n" );
}
}
int Res6_FindGetCost( Res6_Man_t * p, int iDiv )
{
int w, Cost = 0;
//printf( "DivLit = %d\n", iDiv );
//Abc_TtPrintBinary1( stdout, p->ppLits[iDiv], p->nIns ); printf( "\n" );
//printf( "Set0\n" );
//Abc_TtPrintBinary1( stdout, p->ppSets[0], p->nIns ); printf( "\n" );
//printf( "Set1\n" );
//Abc_TtPrintBinary1( stdout, p->ppSets[1], p->nIns ); printf( "\n" );
for ( w = 0; w < p->nWords; w++ )
Cost += Abc_TtCountOnes( (p->ppLits[iDiv][w] & p->ppSets[0][w]) | (p->ppLits[iDiv^1][w] & p->ppSets[1][w]) );
return Cost;
}
int Res6_FindBestDiv( Res6_Man_t * p, int * pCost )
{
int d, dBest = -1, CostBest = ABC_INFINITY;
for ( d = 0; d < 2*p->nDivs; d++ )
{
int Cost = Res6_FindGetCost( p, d );
printf( "Div = %d Cost = %d\n", d, Cost );
if ( CostBest >= Cost )
CostBest = Cost, dBest = d;
}
if ( pCost )
*pCost = CostBest;
return dBest;
}
int Res6_FindBestEval( Res6_Man_t * p, Vec_Int_t * vSol, int Start )
{
int i, iLit0, iLit1;
assert( Vec_IntSize(vSol) % 2 == 0 );
Vec_IntForEachEntryDoubleStart( vSol, iLit0, iLit1, i, 2*Start )
{
if ( iLit0 > iLit1 )
{
Abc_TtXor( p->ppLits[2*p->nDivs+i+0], p->ppLits[iLit0], p->ppLits[iLit1], p->nWords, 0 );
Abc_TtXor( p->ppLits[2*p->nDivs+i+1], p->ppLits[iLit0], p->ppLits[iLit1], p->nWords, 1 );
}
else
{
Abc_TtAnd( p->ppLits[2*p->nDivs+i+0], p->ppLits[iLit0], p->ppLits[iLit1], p->nWords, 0 );
Abc_TtOr ( p->ppLits[2*p->nDivs+i+1], p->ppLits[iLit0^1], p->ppLits[iLit1^1], p->nWords );
}
//printf( "Node %d\n", i/2 );
//Abc_TtPrintBinary1( stdout, p->ppLits[2*p->nDivs+i+0], 6 ); printf( "\n" );
//Abc_TtPrintBinary1( stdout, p->ppLits[2*p->nDivs+i+1], 6 ); printf( "\n" );
}
return Res6_FindGetCost( p, Vec_IntEntryLast(vSol) );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Res6_ManResubVerify( Res6_Man_t * p, Vec_Int_t * vSol )
{
int Cost = Res6_FindBestEval( p, vSol, 0 );
if ( Cost == 0 )
printf( "Verification successful.\n" );
else
printf( "Verification FAILED with %d errors on %d patterns.\n", Cost, p->nPats );
}
void Res6_ManResubCheck( char * pFileNameRes, char * pFileNameSol, int fVerbose )
{
char FileNameSol[1000];
if ( pFileNameSol )
strcpy( FileNameSol, pFileNameSol );
else
{
strcpy( FileNameSol, pFileNameRes );
strcpy( FileNameSol + strlen(FileNameSol) - strlen(".resub"), ".sol" );
}
{
Res6_Man_t * p = Res6_ManRead( pFileNameRes );
Vec_Int_t * vSol = Res6_ManReadSol( FileNameSol );
if ( p == NULL || vSol == NULL )
return;
if ( fVerbose )
Res6_ManPrintProblem( p, 0 );
if ( fVerbose )
Res6_PrintSolution( vSol, p->nDivs );
//if ( fVerbose )
// Res6_PrintSuppSims( vSol, p->ppLits, p->nWords, p->nDivs );
Res6_ManResubVerify( p, vSol );
Vec_IntFree( vSol );
Res6_ManStop( p );
}
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END

257
src/aig/gia/giaSif.c Normal file
View File

@ -0,0 +1,257 @@
/**CFile****************************************************************
FileName [giaSif.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Scalable AIG package.]
Synopsis []
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: giaSif.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "gia.h"
#include "misc/util/utilTruth.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void Gia_ManCutMerge( int * pCut, int * pCut1, int * pCut2, int nSize )
{
int * pBeg = pCut+1;
int * pBeg1 = pCut1+1;
int * pBeg2 = pCut2+1;
int * pEnd1 = pBeg1 + pCut1[0];
int * pEnd2 = pBeg2 + pCut2[0];
while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
{
if ( pBeg == pCut+nSize )
{
pCut[0] = -1;
return;
}
if ( *pBeg1 == *pBeg2 )
*pBeg++ = *pBeg1++, pBeg2++;
else if ( *pBeg1 < *pBeg2 )
*pBeg++ = *pBeg1++;
else
*pBeg++ = *pBeg2++;
}
while ( pBeg1 < pEnd1 )
{
if ( pBeg == pCut+nSize )
{
pCut[0] = -1;
return;
}
*pBeg++ = *pBeg1++;
}
while ( pBeg2 < pEnd2 )
{
if ( pBeg == pCut+nSize )
{
pCut[0] = -1;
return;
}
*pBeg++ = *pBeg2++;
}
pCut[0] = pBeg-(pCut+1);
assert( pCut[0] < nSize );
}
static inline int Gia_ManCutChoice( Gia_Man_t * p, int Level, int iObj, int iSibl, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nSize )
{
int * pCut = Vec_IntEntryP( vCuts, iObj*nSize );
int * pCut2 = Vec_IntEntryP( vCuts, iSibl*nSize );
int Level2 = Vec_IntEntry( vTimes, iSibl ); int i;
assert( iObj > iSibl );
if ( Level < Level2 || (Level == Level2 && pCut[0] <= pCut2[0]) )
return Level;
for ( i = 0; i <= pCut2[0]; i++ )
pCut[i] = pCut2[i];
return Level2;
}
static inline int Gia_ManCutOne( Gia_Man_t * p, int iObj, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nSize )
{
Gia_Obj_t * pObj = Gia_ManObj( p, iObj );
int iFan0 = Gia_ObjFaninId0(pObj, iObj);
int iFan1 = Gia_ObjFaninId1(pObj, iObj);
int Cut0[2] = { 1, iFan0 };
int Cut1[2] = { 1, iFan1 };
int * pCut = Vec_IntEntryP( vCuts, iObj*nSize );
int * pCut0 = Vec_IntEntryP( vCuts, iFan0*nSize );
int * pCut1 = Vec_IntEntryP( vCuts, iFan1*nSize );
int Level_ = Vec_IntEntry( vTimes, iObj );
int Level0 = Vec_IntEntry( vTimes, iFan0 );
int Level1 = Vec_IntEntry( vTimes, iFan1 );
int Level = Abc_MaxInt( Level0, Level1 );
if ( Level == 0 )
Level = 1;
if ( Level0 == Level1 )
Gia_ManCutMerge( pCut, pCut0, pCut1, nSize );
else if ( Level0 > Level1 )
Gia_ManCutMerge( pCut, pCut0, Cut1, nSize );
else //if ( Level0 < Level1 )
Gia_ManCutMerge( pCut, pCut1, Cut0, nSize );
if ( pCut[0] == -1 )
{
pCut[0] = 2;
pCut[1] = iFan0;
pCut[2] = iFan1;
Level++;
}
if ( Gia_ObjSibl(p, iObj) )
Level = Gia_ManCutChoice( p, Level, iObj, Gia_ObjSibl(p, iObj), vCuts, vTimes, nSize );
assert( pCut[0] > 0 && pCut[0] < nSize );
Vec_IntUpdateEntry( vTimes, iObj, Level );
return Level > Level_;
}
int Gia_ManCheckIter( Gia_Man_t * p, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nLutSize, int Period )
{
int i, fChange = 0, nSize = nLutSize+1;
Gia_Obj_t * pObj, * pObjRi, * pObjRo;
Gia_ManForEachRiRo( p, pObjRi, pObjRo, i )
Vec_IntWriteEntry( vTimes, Gia_ObjId(p, pObjRo), Vec_IntEntry(vTimes, Gia_ObjId(p, pObjRi)) - Period );
Gia_ManForEachAnd( p, pObj, i )
fChange |= Gia_ManCutOne( p, i, vCuts, vTimes, nSize );
Gia_ManForEachRi( p, pObj, i )
Vec_IntWriteEntry( vTimes, Gia_ObjId(p, pObj), Vec_IntEntry(vTimes, Gia_ObjFaninId0p(p, pObj)) );
return fChange;
}
int Gia_ManCheckPeriod( Gia_Man_t * p, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nLutSize, int Period, int * pIters )
{
Gia_Obj_t * pObj; int i;
assert( Gia_ManRegNum(p) > 0 );
Vec_IntFill( vTimes, Gia_ManObjNum(p), -ABC_INFINITY );
Vec_IntWriteEntry( vTimes, 0, 0 );
Gia_ManForEachPi( p, pObj, i )
Vec_IntWriteEntry( vTimes, Gia_ObjId(p, pObj), 0 );
for ( *pIters = 0; *pIters < 100; (*pIters)++ )
{
if ( !Gia_ManCheckIter(p, vCuts, vTimes, nLutSize, Period) )
return 1;
Gia_ManForEachPo( p, pObj, i )
if ( Vec_IntEntry(vTimes, Gia_ObjFaninId0p(p, pObj)) > Period )
return 0;
}
return 0;
}
static inline void Gia_ManPrintCutOne( Gia_Man_t * p, int iObj, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nSize )
{
int i, * pCut = Vec_IntEntryP( vCuts, iObj*nSize );
printf( "Obj %4d : Depth %d CutSize %d Cut {", iObj, Vec_IntEntry(vTimes, iObj), pCut[0] );
for ( i = 1; i <= pCut[0]; i++ )
printf( " %d", pCut[i] );
printf( " }\n" );
}
int Gia_ManTestMapComb( Gia_Man_t * p, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nLutSize )
{
Gia_Obj_t * pObj; int i, Id, Res = 0, nSize = nLutSize+1;
Vec_IntFill( vTimes, Gia_ManObjNum(p), 0 );
Gia_ManForEachCiId( p, Id, i )
Vec_IntWriteEntry( vCuts, Id*nSize, 1 );
Gia_ManForEachCiId( p, Id, i )
Vec_IntWriteEntry( vCuts, Id*nSize+1, Id );
Gia_ManForEachAnd( p, pObj, i )
Gia_ManCutOne( p, i, vCuts, vTimes, nSize );
Gia_ManForEachCo( p, pObj, i )
Res = Abc_MaxInt( Res, Vec_IntEntry(vTimes, Gia_ObjFaninId0p(p, pObj)) );
//Gia_ManForEachAnd( p, pObj, i )
// Gia_ManPrintCutOne( p, i, vCuts, vTimes, nSize );
return Res;
}
void Gia_ManPrintTimes( Gia_Man_t * p, Vec_Int_t * vTimes, int Period )
{
int Pos[16] = {0};
int Neg[16] = {0};
Gia_Obj_t * pObj; int i;
Gia_ManForEachAnd( p, pObj, i )
{
int Time = Vec_IntEntry(vTimes, i)-Period;
Time = Abc_MinInt( Time, 10*Period );
Time = Abc_MaxInt( Time, -10*Period );
if ( Time >= 0 )
Pos[(Time + Period-1)/Period]++;
else
Neg[(-Time + Period-1)/Period]++;
}
printf( "Statistics: " );
for ( i = 15; i > 0; i-- )
if ( Neg[i] )
printf( " -%d=%d", i, Neg[i] );
for ( i = 0; i < 16; i++ )
if ( Pos[i] )
printf( " %d=%d", i, Pos[i] );
printf( "\n" );
}
Gia_Man_t * Gia_ManTestSif( Gia_Man_t * p, int nLutSize, int fVerbose )
{
int nIters, nSize = nLutSize+1; // (2+1+nSize)*4=40 bytes/node
abctime clk = Abc_Clock();
Vec_Int_t * vCuts = Vec_IntStart( Gia_ManObjNum(p) * nSize );
Vec_Int_t * vTimes = Vec_IntAlloc( Gia_ManObjNum(p) );
int Lower = 0;
int Upper = Gia_ManTestMapComb( p, vCuts, vTimes, nLutSize );
if ( fVerbose && Gia_ManRegNum(p) )
printf( "Clock period %2d is %s\n", Lower, 0 ? "Yes" : "No " );
if ( fVerbose && Gia_ManRegNum(p) )
printf( "Clock period %2d is %s\n", Upper, 1 ? "Yes" : "No " );
while ( Gia_ManRegNum(p) > 0 && Upper - Lower > 1 )
{
int Middle = (Upper + Lower) / 2;
int Status = Gia_ManCheckPeriod( p, vCuts, vTimes, nLutSize, Middle, &nIters );
if ( Status )
Upper = Middle;
else
Lower = Middle;
if ( fVerbose )
printf( "Clock period %2d is %s after %d iterations\n", Middle, Status ? "Yes" : "No ", nIters );
}
if ( fVerbose )
printf( "Clock period = %2d ", Upper );
if ( fVerbose )
printf( "LUT size = %d ", nLutSize );
if ( fVerbose )
printf( "Memory usage = %.2f MB ", 4.0*(2+1+nSize)*Gia_ManObjNum(p)/(1 << 20) );
if ( fVerbose )
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
//Gia_ManCheckPeriod( p, vCuts, vTimes, nLutSize, Upper, &nIters );
//Gia_ManPrintTimes( p, vTimes, Upper );
Vec_IntFree( vCuts );
Vec_IntFree( vTimes );
return NULL;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END

View File

@ -750,7 +750,7 @@ void Gia_ManSimProfile( Gia_Man_t * pGia )
Vec_Wrd_t * vSims = Gia_ManSimPatSim( pGia );
int nWords = Vec_WrdSize(vSims) / Gia_ManObjNum(pGia);
int nC0s = 0, nC1s = 0, nUnique = Gia_ManSimPatHashPatterns( pGia, nWords, vSims, &nC0s, &nC1s );
printf( "Simulating %d patterns leads to %d unique objects (%.2f %% out of %d), Const0 = %d. Const1 = %d.\n",
printf( "Simulating %d patterns leads to %d unique objects (%.2f %% out of %d). Const0 = %d. Const1 = %d.\n",
64*nWords, nUnique, 100.0*nUnique/Gia_ManCandNum(pGia), Gia_ManCandNum(pGia), nC0s, nC1s );
Vec_WrdFree( vSims );
}
@ -2485,15 +2485,21 @@ void Gia_ManSimGen( Gia_Man_t * pGia )
SeeAlso []
***********************************************************************/
int Gia_ManSimTwo( Gia_Man_t * p0, Gia_Man_t * p1, int nWords, int nRounds, int fVerbose )
int Gia_ManSimTwo( Gia_Man_t * p0, Gia_Man_t * p1, int nWords, int nRounds, int TimeLimit, int fVerbose )
{
Vec_Wrd_t * vSim0, * vSim1, * vSim2;
abctime clk = Abc_Clock();
int n, i, RetValue = 1;
int TimeStop = TimeLimit ? TimeLimit * CLOCKS_PER_SEC + Abc_Clock() : 0; // in CPU ticks
printf( "Simulating %d round with %d machine words.\n", nRounds, nWords );
Abc_RandomW(0);
for ( n = 0; RetValue && n < nRounds; n++ )
{
if ( TimeStop && Abc_Clock() > TimeStop )
{
printf( "Computation timed out after %d seconds and %d rounds.\n", TimeLimit, n );
break;
}
vSim0 = Vec_WrdStartRandom( Gia_ManCiNum(p0) * nWords );
p0->vSimsPi = vSim0;
p1->vSimsPi = vSim0;
@ -2700,6 +2706,77 @@ Vec_Ptr_t * Gia_ManPtrWrdReadBin( char * pFileName, int fVerbose )
return p;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManCompareSims( Gia_Man_t * pHie, Gia_Man_t * pFlat, int nWords, int fVerbose )
{
abctime clk = Abc_Clock();
Vec_Wrd_t * vSims = pFlat->vSimsPi = pHie->vSimsPi = Vec_WrdStartRandom( Gia_ManCiNum(pFlat) * nWords );
Vec_Wrd_t * vSims0 = Gia_ManSimPatSim( pFlat );
Vec_Wrd_t * vSims1 = Gia_ManSimPatSim( pHie );
Gia_Obj_t * pObj; int * pSpot, * pSpot2, i, nC0s = 0, nC1s = 0, nUnique = 0, nFound[3] = {0}, nBoundary = 0, nMatched = 0;
Vec_Mem_t * vStore = Vec_MemAlloc( nWords, 12 ); // 2^12 N-word entries per page
pFlat->vSimsPi = NULL;
pHie->vSimsPi = NULL;
Vec_WrdFree( vSims );
printf( "Comparing two AIGs using %d simulation words.\n", nWords );
printf( "Hierarchical: " ); Gia_ManPrintStats( pHie, NULL );
printf( "Flat: " ); Gia_ManPrintStats( pFlat, NULL );
Vec_MemHashAlloc( vStore, 1 << 12 );
Gia_ManForEachCand( pFlat, pObj, i )
{
word * pSim = Vec_WrdEntryP(vSims0, i*nWords);
nC0s += Abc_TtIsConst0(pSim, nWords);
nC1s += Abc_TtIsConst1(pSim, nWords);
Vec_MemHashInsert( vStore, pSim );
}
nUnique = Vec_MemEntryNum( vStore );
printf( "Simulating %d patterns through the second (flat) AIG leads to %d unique objects (%.2f %% out of %d). Const0 = %d. Const1 = %d.\n",
64*nWords, nUnique, 100.0*nUnique/Gia_ManCandNum(pFlat), Gia_ManCandNum(pFlat), nC0s, nC1s );
assert( Gia_ManCiNum(pFlat) == Gia_ManCiNum(pHie) );
Gia_ManForEachCand( pHie, pObj, i )
{
word * pSim = Vec_WrdEntryP(vSims1, i*nWords);
pSpot = Vec_MemHashLookup( vStore, pSim );
Abc_TtNot( pSim, nWords );
pSpot2 = Vec_MemHashLookup( vStore, pSim );
Abc_TtNot( pSim, nWords );
nBoundary += Gia_ObjIsBuf(pObj);
if ( *pSpot != -1 || *pSpot2 != -1 )
{
nMatched++;
continue;
}
//Extra_PrintBinary( stdout, (unsigned *)pSim, 64*nWords ); printf("\n");
nFound[1] += Gia_ObjIsBuf(pObj);
nFound[2]++;
//if ( Gia_ObjIsBuf(pObj) )
// printf( "%d(%d) ", i, nBoundary-1 );
}
Vec_MemHashFree( vStore );
Vec_MemFree( vStore );
Vec_WrdFree( vSims0 );
Vec_WrdFree( vSims1 );
printf( "The first (hierarchical) AIG has %d (%.2f %%) matches, %d (%.2f %%) mismatches, including %d (%.2f %%) on the boundary. ",
nMatched, 100.0*nMatched /Abc_MaxInt(1, Gia_ManCandNum(pHie)),
nFound[2], 100.0*nFound[2]/Abc_MaxInt(1, Gia_ManCandNum(pHie)),
nFound[1], 100.0*nFound[1]/Abc_MaxInt(1, nBoundary) );
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////

View File

@ -46,6 +46,7 @@ struct Supp_Man_t_
Gia_Man_t * pGia; // used for object names
// computed data
Vec_Wrd_t * vDivs[2]; // simulation values
Vec_Wrd_t * vDivsC[2]; // simulation values
Vec_Wrd_t * vPats[2]; // simulation values
Vec_Ptr_t * vMatrix; // simulation values
Vec_Wrd_t * vMask; // simulation values
@ -138,13 +139,15 @@ int Supp_DeriveLines( Supp_Man_t * p )
{
int n, i, iObj, nWords = p->nWords;
int nDivWords = Abc_Bit6WordNum( Vec_IntSize(p->vCands) );
//Vec_IntPrint( p->vCands );
for ( n = 0; n < 2; n++ )
{
p->vDivs[n] = Vec_WrdStart( 64*nWords*nDivWords );
p->vPats[n] = Vec_WrdStart( 64*nWords*nDivWords );
//p->vDivsC[n] = Vec_WrdStart( 64*nWords*nDivWords );
if ( p->vSimsC )
Vec_IntForEachEntry( p->vCands, iObj, i )
Abc_TtAndSharp( Vec_WrdEntryP(p->vDivs[n], i*nWords), Vec_WrdEntryP(p->vSimsC, iObj*nWords), Vec_WrdEntryP(p->vSims, iObj*nWords), nWords, !n );
Abc_TtAndSharp( Vec_WrdEntryP(p->vDivsC[n], i*nWords), Vec_WrdEntryP(p->vSimsC, iObj*nWords), Vec_WrdEntryP(p->vSims, iObj*nWords), nWords, !n );
else
Vec_IntForEachEntry( p->vCands, iObj, i )
Abc_TtCopy( Vec_WrdEntryP(p->vDivs[n], i*nWords), Vec_WrdEntryP(p->vSims, iObj*nWords), nWords, !n );
@ -194,6 +197,8 @@ void Supp_ManDelete( Supp_Man_t * p )
Supp_ManCleanMatrix( p );
Vec_WrdFreeP( &p->vDivs[0] );
Vec_WrdFreeP( &p->vDivs[1] );
Vec_WrdFreeP( &p->vDivsC[0] );
Vec_WrdFreeP( &p->vDivsC[1] );
Vec_WrdFreeP( &p->vPats[0] );
Vec_WrdFreeP( &p->vPats[1] );
Vec_PtrFreeP( &p->vMatrix );
@ -656,6 +661,110 @@ int Supp_ManReconstruct( Supp_Man_t * p, int fVerbose )
return Supp_ManRandomSolution( p, iSet, fVerbose );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static int s_Counter = 0;
void Supp_DeriveDumpSims( FILE * pFile, Vec_Wrd_t * vDivs, int nWords )
{
int i, k, nDivs = Vec_WrdSize(vDivs)/nWords;
for ( i = 0; i < nDivs; i++ )
{
word * pSim = Vec_WrdEntryP(vDivs, i*nWords);
for ( k = 0; k < 64*nWords; k++ )
fprintf( pFile, "%c", '0'+Abc_TtGetBit(pSim, k) );
fprintf( pFile, "\n" );
}
}
void Supp_DeriveDumpSimsC( FILE * pFile, Vec_Wrd_t * vDivs[2], int nWords )
{
int i, k, nDivs = Vec_WrdSize(vDivs[0])/nWords;
for ( i = 0; i < nDivs; i++ )
{
word * pSim0 = Vec_WrdEntryP(vDivs[0], i*nWords);
word * pSim1 = Vec_WrdEntryP(vDivs[1], i*nWords);
for ( k = 0; k < 64*nWords; k++ )
if ( Abc_TtGetBit(pSim0, k) )
fprintf( pFile, "0" );
else if ( Abc_TtGetBit(pSim1, k) )
fprintf( pFile, "1" );
else
fprintf( pFile, "-" );
fprintf( pFile, "\n" );
}
}
void Supp_DeriveDumpProb( Vec_Wrd_t * vIsfs, Vec_Wrd_t * vDivs, int nWords )
{
char Buffer[100]; int nDivs = Vec_WrdSize(vDivs)/nWords;
int RetValue = sprintf( Buffer, "%02d.resub", s_Counter );
FILE * pFile = fopen( Buffer, "wb" );
if ( pFile == NULL )
printf( "Cannot open output file.\n" );
fprintf( pFile, "resyn %d %d %d %d\n", 0, nDivs, 1, 64*nWords );
//fprintf( pFile, "%d %d %d %d\n", 0, nDivs, 1, 64*nWords );
Supp_DeriveDumpSims( pFile, vDivs, nWords );
Supp_DeriveDumpSims( pFile, vIsfs, nWords );
fclose ( pFile );
RetValue = 0;
}
void Supp_DeriveDumpProbC( Vec_Wrd_t * vIsfs, Vec_Wrd_t * vDivs[2], int nWords )
{
char Buffer[100]; int nDivs = Vec_WrdSize(vDivs[0])/nWords;
int RetValue = sprintf( Buffer, "%02d.resub", s_Counter );
FILE * pFile = fopen( Buffer, "wb" );
if ( pFile == NULL )
printf( "Cannot open output file.\n" );
fprintf( pFile, "resyn %d %d %d %d\n", 0, nDivs, 1, 64*nWords );
//fprintf( pFile, "%d %d %d %d\n", 0, nDivs, 1, 64*nWords );
Supp_DeriveDumpSimsC( pFile, vDivs, nWords );
Supp_DeriveDumpSims( pFile, vIsfs, nWords );
fclose ( pFile );
RetValue = 0;
}
void Supp_DeriveDumpSol( Vec_Int_t * vSet, Vec_Int_t * vRes, int nDivs )
{
char Buffer[100];
int RetValue = sprintf( Buffer, "%02d.sol", s_Counter );
int i, iLit, iLitRes = -1, nSupp = Vec_IntSize(vSet);
FILE * pFile = fopen( Buffer, "wb" );
if ( pFile == NULL )
printf( "Cannot open output file.\n" );
fprintf( pFile, "sol name aig %d\n", Vec_IntSize(vRes)/2 );
//Vec_IntPrint( vSet );
//Vec_IntPrint( vRes );
Vec_IntForEachEntry( vRes, iLit, i )
{
assert( iLit != 2 && iLit != 3 );
if ( iLit < 2 )
iLitRes = iLit;
else if ( iLit-4 < 2*nSupp )
{
int iDiv = Vec_IntEntry(vSet, Abc_Lit2Var(iLit-4));
assert( iDiv >= 0 && iDiv < nDivs );
iLitRes = Abc_Var2Lit(1+iDiv, Abc_LitIsCompl(iLit));
}
else
iLitRes = iLit + 2*((nDivs+1)-(nSupp+2));
fprintf( pFile, "%d ", iLitRes );
}
if ( Vec_IntSize(vRes) & 1 )
fprintf( pFile, "%d ", iLitRes );
fprintf( pFile, "\n" );
fclose( pFile );
RetValue = 0;
printf( "Dumped solution info file \"%s\".\n", Buffer );
}
/**Function*************************************************************
Synopsis []
@ -705,6 +814,10 @@ Vec_Int_t * Supp_ManFindBestSolution( Supp_Man_t * p, Vec_Wec_t * vSols, int fVe
Vec_IntForEachEntry( vSet, iObj, i )
Vec_IntPush( *pvDivs, Vec_IntEntry(p->vCands, iObj) );
}
//Supp_DeriveDumpProbC( p->vIsfs, p->vDivsC, p->nWords );
//Supp_DeriveDumpProb( p->vIsfs, p->vDivs[1], p->nWords );
//Supp_DeriveDumpSol( vSet, vRes, Vec_WrdSize(p->vDivs[1])/p->nWords );
//s_Counter++;
}
return vRes;
}
@ -802,11 +915,38 @@ Vec_Int_t * Supp_ManCompute( Vec_Wrd_t * vIsfs, Vec_Int_t * vCands, Vec_Int_t *
Supp_PrintOne( p, iBest );
}
vRes = Supp_ManFindBestSolution( p, p->vSolutions, fVerbose, pvDivs );
//Vec_IntPrint( vRes );
Supp_ManDelete( p );
// if ( vRes && Vec_IntSize(vRes) == 0 )
// Vec_IntFreeP( &vRes );
return vRes;
}
void Supp_ManComputeTest( Gia_Man_t * p )
{
Vec_Wrd_t * vSimsPi = Vec_WrdStartTruthTables( Gia_ManCiNum(p) );
Vec_Wrd_t * vSims = Gia_ManSimPatSimOut( p, vSimsPi, 0 );
int i, iPoId, nWords = Vec_WrdSize(vSimsPi) / Gia_ManCiNum(p);
Vec_Wrd_t * vIsfs = Vec_WrdStart( 2*nWords );
Vec_Int_t * vCands = Vec_IntAlloc( 4 );
Vec_Int_t * vRes;
// for ( i = 0; i < Gia_ManCiNum(p)+5; i++ )
for ( i = 0; i < Gia_ManCiNum(p); i++ )
Vec_IntPush( vCands, 1+i );
iPoId = Gia_ObjId(p, Gia_ManPo(p, 0));
Abc_TtCopy( Vec_WrdEntryP(vIsfs, 0*nWords), Vec_WrdEntryP(vSims, iPoId*nWords), nWords, 1 );
Abc_TtCopy( Vec_WrdEntryP(vIsfs, 1*nWords), Vec_WrdEntryP(vSims, iPoId*nWords), nWords, 0 );
vRes = Supp_ManCompute( vIsfs, vCands, NULL, vSims, NULL, nWords, p, NULL, 1, 1, 0 );
Vec_IntPrint( vRes );
Vec_WrdFree( vSimsPi );
Vec_WrdFree( vSims );
Vec_WrdFree( vIsfs );
Vec_IntFree( vCands );
Vec_IntFree( vRes );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///

View File

@ -795,6 +795,14 @@ float Gia_ManComputeSwitching( Gia_Man_t * p, int nFrames, int nPref, int fProbO
Gia_ManForEachAnd( p, pObj, i )
SwiTotal += pSwi[Gia_ObjFaninId0(pObj, i)] + pSwi[Gia_ObjFaninId1(pObj, i)];
}
if ( 0 )
{
Gia_ManForEachObj( p, pObj, i )
{
printf( "Switch %6.2f ", pSwi[i] );
Gia_ObjPrint( p, pObj );
}
}
Vec_IntFree( vSwitching );
return SwiTotal;
}

View File

@ -3080,7 +3080,55 @@ Gia_Man_t * Gia_ManTransformCond( Gia_Man_t * p )
Abc_PrintTime( 0, "Time", Abc_Clock() - clk );
return NULL;
}
void Gia_ManWriteSol( Gia_Man_t * p, char * pFileName )
{
char * pBasicName = Extra_FileNameGeneric( pFileName );
char * pFileName2 = Abc_UtilStrsavTwo( pBasicName, ".sol" );
FILE * pFile = fopen( pFileName2, "wb" );
ABC_FREE( pBasicName );
if ( pFile == NULL )
printf( "Cannot open output file \"%s\".\n", pFileName2 );
else
{
Gia_Obj_t * pObj; int i;
Gia_ManForEachAnd( p, pObj, i )
fprintf( pFile, "%d %d ", Gia_ObjFaninLit0(pObj, i), Gia_ObjFaninLit1(pObj, i) );
Gia_ManForEachCo( p, pObj, i )
fprintf( pFile, "%d %d ", Gia_ObjFaninLit0p(p, pObj), Gia_ObjFaninLit0p(p, pObj) );
fclose( pFile );
printf( "Finished writing solution file \"%s\".\n", pFileName2 );
}
ABC_FREE( pFileName2 );
}
void Gia_ManWriteResub( Gia_Man_t * p, char * pFileName )
{
FILE * pFile = fopen( pFileName, "wb" );
if ( pFile == NULL )
printf( "Cannot open output file \"%s\".\n", pFileName );
else
{
Vec_Wrd_t * vSimsPi = Vec_WrdStartTruthTables( Gia_ManCiNum(p) );
Vec_Wrd_t * vSimsPo = Gia_ManSimPatSimOut( p, vSimsPi, 1 );
int i, k, nWords = Vec_WrdSize(vSimsPi) / Gia_ManCiNum(p);
word * pTemp = ABC_ALLOC( word, nWords );
fprintf( pFile, "%d %d %d %d\n", Gia_ManCiNum(p), 0, Gia_ManCoNum(p), 1 << Gia_ManCiNum(p) );
for ( i = 0; i < Gia_ManCiNum(p); i++ )
Abc_TtPrintBinary1( pFile, Vec_WrdEntryP(vSimsPi, i*nWords), Gia_ManCiNum(p) ), fprintf(pFile, "\n");
for ( i = 0; i < (1 << Gia_ManCoNum(p)); i++ )
{
Abc_TtFill( pTemp, nWords );
for ( k = 0; k < Gia_ManCoNum(p); k++ )
Abc_TtAndCompl( pTemp, pTemp, 0, Vec_WrdEntryP(vSimsPo, k*nWords), !((i>>k)&1), nWords );
Abc_TtPrintBinary1( pFile, pTemp, Gia_ManCiNum(p) ), fprintf(pFile, "\n");
}
ABC_FREE( pTemp );
fclose( pFile );
Vec_WrdFree( vSimsPi );
Vec_WrdFree( vSimsPo );
printf( "Finished writing resub file \"%s\".\n", pFileName );
Gia_ManWriteSol( p, pFileName );
}
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///

View File

@ -15,6 +15,7 @@ SRC += src/aig/gia/giaAig.c \
src/aig/gia/giaCSat.c \
src/aig/gia/giaCSat2.c \
src/aig/gia/giaCSat3.c \
src/aig/gia/giaCSatP.c \
src/aig/gia/giaCTas.c \
src/aig/gia/giaCut.c \
src/aig/gia/giaDecs.c \
@ -68,6 +69,7 @@ SRC += src/aig/gia/giaAig.c \
src/aig/gia/giaResub.c \
src/aig/gia/giaResub2.c \
src/aig/gia/giaResub3.c \
src/aig/gia/giaResub6.c \
src/aig/gia/giaRetime.c \
src/aig/gia/giaRex.c \
src/aig/gia/giaSatEdge.c \
@ -82,6 +84,7 @@ SRC += src/aig/gia/giaAig.c \
src/aig/gia/giaShrink.c \
src/aig/gia/giaShrink6.c \
src/aig/gia/giaShrink7.c \
src/aig/gia/giaSif.c \
src/aig/gia/giaSim.c \
src/aig/gia/giaSim2.c \
src/aig/gia/giaSimBase.c \

View File

@ -438,7 +438,7 @@ Aig_Man_t * Ioa_ReadAiger( char * pFileName, int fCheck )
// read the file into the buffer
nFileSize = Ioa_FileSize( pFileName );
pFile = fopen( pFileName, "rb" );
pContents = ABC_ALLOC( char, nFileSize );
pContents = ABC_CALLOC( char, nFileSize+1 );
RetValue = fread( pContents, nFileSize, 1, pFile );
fclose( pFile );

View File

@ -226,6 +226,10 @@ static inline const char * Abc_OperName( int Type )
if ( Type == ABC_OPER_ZEROPAD ) return "zPad";
if ( Type == ABC_OPER_SIGNEXT ) return "sExt";
if ( Type == ABC_OPER_BIT_MUX ) return "mux";
if ( Type == ABC_OPER_SEL_NMUX ) return "nmux";
if ( Type == ABC_OPER_SEL_SEL ) return "pmux";
if ( Type == ABC_OPER_CONST ) return "const";
if ( Type == ABC_OPER_TABLE ) return "table";
if ( Type == ABC_OPER_LUT ) return "lut";

View File

@ -30,7 +30,9 @@
#include <string.h>
#include <assert.h>
#ifndef _VERIFIC_DATABASE_H_
ABC_NAMESPACE_HEADER_START
#endif
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
@ -92,13 +94,13 @@ static void Mini_AigPush( Mini_Aig_t * p, int Lit0, int Lit1 )
static int Mini_AigNodeFanin0( Mini_Aig_t * p, int Id )
{
assert( Id >= 0 && 2*Id < p->nSize );
assert( p->pArray[2*Id] == 0x7FFFFFFF || p->pArray[2*Id] < 2*Id );
assert( p->pArray[2*Id] == MINI_AIG_NULL || p->pArray[2*Id] < 2*Id );
return p->pArray[2*Id];
}
static int Mini_AigNodeFanin1( Mini_Aig_t * p, int Id )
{
assert( Id >= 0 && 2*Id < p->nSize );
assert( p->pArray[2*Id+1] == 0x7FFFFFFF || p->pArray[2*Id+1] < 2*Id );
assert( p->pArray[2*Id+1] == MINI_AIG_NULL || p->pArray[2*Id+1] < 2*Id );
return p->pArray[2*Id+1];
}
@ -170,7 +172,7 @@ static int Mini_AigAndNum( Mini_Aig_t * p )
}
static void Mini_AigPrintStats( Mini_Aig_t * p )
{
printf( "PI = %d. PO = %d. Node = %d.\n", Mini_AigPiNum(p), Mini_AigPoNum(p), Mini_AigAndNum(p) );
printf( "MiniAIG stats: PI = %d PO = %d FF = %d AND = %d\n", Mini_AigPiNum(p), Mini_AigPoNum(p), Mini_AigRegNum(p), Mini_AigAndNum(p) );
}
// serialization
@ -233,7 +235,10 @@ static int Mini_AigAnd( Mini_Aig_t * p, int Lit0, int Lit1 )
int Lit = p->nSize;
assert( Lit0 >= 0 && Lit0 < Lit );
assert( Lit1 >= 0 && Lit1 < Lit );
Mini_AigPush( p, Lit0, Lit1 );
if ( Lit0 < Lit1 )
Mini_AigPush( p, Lit0, Lit1 );
else
Mini_AigPush( p, Lit1, Lit0 );
return Lit;
}
static int Mini_AigOr( Mini_Aig_t * p, int Lit0, int Lit1 )
@ -250,6 +255,61 @@ static int Mini_AigXor( Mini_Aig_t * p, int Lit0, int Lit1 )
{
return Mini_AigMux( p, Lit0, Mini_AigLitNot(Lit1), Lit1 );
}
static int Mini_AigXorSpecial( Mini_Aig_t * p, int Lit0, int Lit1 )
{
int Lit = p->nSize;
assert( Lit0 >= 0 && Lit0 < Lit );
assert( Lit1 >= 0 && Lit1 < Lit );
if ( Lit0 > Lit1 )
Mini_AigPush( p, Lit0, Lit1 );
else
Mini_AigPush( p, Lit1, Lit0 );
return Lit;
}
static int Mini_AigAndMulti( Mini_Aig_t * p, int * pLits, int nLits )
{
int i;
assert( nLits > 0 );
while ( nLits > 1 )
{
for ( i = 0; i < nLits/2; i++ )
pLits[i] = Mini_AigAnd(p, pLits[2*i], pLits[2*i+1]);
if ( nLits & 1 )
pLits[i++] = pLits[nLits-1];
nLits = i;
}
return pLits[0];
}
static int Mini_AigMuxMulti( Mini_Aig_t * p, int * pCtrl, int nCtrl, int * pData, int nData )
{
int i, c;
assert( nData > 0 );
if ( nCtrl == 0 )
return pData[0];
assert( nData <= (1 << nCtrl) );
for ( c = 0; c < nCtrl; c++ )
{
for ( i = 0; i < nData/2; i++ )
pData[i] = Mini_AigMux( p, pCtrl[c], pData[2*i+1], pData[2*i] );
if ( nData & 1 )
pData[i++] = Mini_AigMux( p, pCtrl[c], 0, pData[nData-1] );
nData = i;
}
assert( nData == 1 );
return pData[0];
}
static int Mini_AigMuxMulti_rec( Mini_Aig_t * p, int * pCtrl, int * pData, int nData )
{
int Res0, Res1;
assert( nData > 0 );
if ( nData == 1 )
return pData[0];
assert( nData % 2 == 0 );
Res0 = Mini_AigMuxMulti_rec( p, pCtrl+1, pData, nData/2 );
Res1 = Mini_AigMuxMulti_rec( p, pCtrl+1, pData+nData/2, nData/2 );
return Mini_AigMux( p, pCtrl[0], Res1, Res0 );
}
static unsigned s_MiniTruths5[5] = {
0xAAAAAAAA,
@ -308,6 +368,20 @@ static inline int Mini_AigTruth( Mini_Aig_t * p, int * pVarLits, int nVars, unsi
Lit1 = Mini_AigTruth( p, pVarLits, Var, Mini_AigTt5Cofactor1(Truth, Var) );
return Mini_AigMuxProp( p, pVarLits[Var], Lit1, Lit0 );
}
static char * Mini_AigPhase( Mini_Aig_t * p )
{
char * pRes = MINI_AIG_CALLOC( char, Mini_AigNodeNum(p) );
int i;
Mini_AigForEachAnd( p, i )
{
int iFaninLit0 = Mini_AigNodeFanin0( p, i );
int iFaninLit1 = Mini_AigNodeFanin1( p, i );
int Phase0 = pRes[Mini_AigLit2Var(iFaninLit0)] ^ Mini_AigLitIsCompl(iFaninLit0);
int Phase1 = pRes[Mini_AigLit2Var(iFaninLit1)] ^ Mini_AigLitIsCompl(iFaninLit1);
pRes[i] = Phase0 & Phase1;
}
return pRes;
}
// procedure to check the topological order during AIG construction
static int Mini_AigCheck( Mini_Aig_t * p )
@ -340,11 +414,11 @@ static int Mini_AigCheck( Mini_Aig_t * p )
static void Mini_AigDumpVerilog( char * pFileName, char * pModuleName, Mini_Aig_t * p )
{
int i, k, iFaninLit0, iFaninLit1, Length = strlen(pModuleName), nPos = Mini_AigPoNum(p);
Vec_Bit_t * vObjIsPi = Vec_BitStart( Mini_AigNodeNum(p) );
char * pObjIsPi = MINI_AIG_CALLOC( char, Mini_AigNodeNum(p) );
FILE * pFile = fopen( pFileName, "wb" );
if ( pFile == NULL ) { printf( "Cannot open output file %s\n", pFileName ); return; }
if ( pFile == NULL ) { printf( "Cannot open output file %s\n", pFileName ); MINI_AIG_FREE( pObjIsPi ); return; }
// write interface
fprintf( pFile, "// This MiniAIG dump was produced by ABC on %s\n\n", Extra_TimeStamp() );
//fprintf( pFile, "// This MiniAIG dump was produced by ABC on %s\n\n", Extra_TimeStamp() );
fprintf( pFile, "module %s (\n", pModuleName );
if ( Mini_AigPiNum(p) > 0 )
{
@ -354,7 +428,7 @@ static void Mini_AigDumpVerilog( char * pFileName, char * pModuleName, Mini_Aig_
{
if ( k++ % 12 == 0 ) fprintf( pFile, "\n%*s", Length+10, "" );
fprintf( pFile, "i%d, ", i );
Vec_BitWriteEntry( vObjIsPi, i, 1 );
pObjIsPi[i] = 1;
}
}
fprintf( pFile, "\n%*soutput wire", Length+10, "" );
@ -371,9 +445,9 @@ static void Mini_AigDumpVerilog( char * pFileName, char * pModuleName, Mini_Aig_
iFaninLit0 = Mini_AigNodeFanin0( p, i );
iFaninLit1 = Mini_AigNodeFanin1( p, i );
fprintf( pFile, " assign n%d = ", i );
fprintf( pFile, "%s%c%d", (iFaninLit0 & 1) ? "~":"", Vec_BitEntry(vObjIsPi, iFaninLit0 >> 1) ? 'i':'n', iFaninLit0 >> 1 );
fprintf( pFile, "%s%c%d", (iFaninLit0 & 1) ? "~":"", pObjIsPi[iFaninLit0 >> 1] ? 'i':'n', iFaninLit0 >> 1 );
fprintf( pFile, " & " );
fprintf( pFile, "%s%c%d", (iFaninLit1 & 1) ? "~":"", Vec_BitEntry(vObjIsPi, iFaninLit1 >> 1) ? 'i':'n', iFaninLit1 >> 1 );
fprintf( pFile, "%s%c%d", (iFaninLit1 & 1) ? "~":"", pObjIsPi[iFaninLit1 >> 1] ? 'i':'n', iFaninLit1 >> 1 );
fprintf( pFile, ";\n" );
}
// write assigns
@ -382,19 +456,205 @@ static void Mini_AigDumpVerilog( char * pFileName, char * pModuleName, Mini_Aig_
{
iFaninLit0 = Mini_AigNodeFanin0( p, i );
fprintf( pFile, " assign o%d = ", i );
fprintf( pFile, "%s%c%d", (iFaninLit0 & 1) ? "~":"", Vec_BitEntry(vObjIsPi, iFaninLit0 >> 1) ? 'i':'n', iFaninLit0 >> 1 );
fprintf( pFile, "%s%c%d", (iFaninLit0 & 1) ? "~":"", pObjIsPi[iFaninLit0 >> 1] ? 'i':'n', iFaninLit0 >> 1 );
fprintf( pFile, ";\n" );
}
fprintf( pFile, "\nendmodule // %s \n\n\n", pModuleName );
Vec_BitFree( vObjIsPi );
MINI_AIG_FREE( pObjIsPi );
fclose( pFile );
}
// checks if MiniAIG is normalized (first inputs, then internal nodes, then outputs)
static int Mini_AigIsNormalized( Mini_Aig_t * p )
{
int nCiNum = Mini_AigPiNum(p);
int nCoNum = Mini_AigPoNum(p);
int i, nOffset = 1;
for ( i = 0; i < nCiNum; i++ )
if ( !Mini_AigNodeIsPi( p, nOffset+i ) )
return 0;
nOffset = Mini_AigNodeNum(p) - nCoNum;
for ( i = 0; i < nCoNum; i++ )
if ( !Mini_AigNodeIsPo( p, nOffset+i ) )
return 0;
return 1;
}
////////////////////////////////////////////////////////////////////////
/// MiniAIG reading from / write into AIGER ///
////////////////////////////////////////////////////////////////////////
static unsigned Mini_AigerReadUnsigned( FILE * pFile )
{
unsigned x = 0, i = 0;
unsigned char ch;
while ((ch = fgetc(pFile)) & 0x80)
x |= (ch & 0x7f) << (7 * i++);
return x | (ch << (7 * i));
}
static void Mini_AigerWriteUnsigned( FILE * pFile, unsigned x )
{
unsigned char ch;
while (x & ~0x7f)
{
ch = (x & 0x7f) | 0x80;
fputc( ch, pFile );
x >>= 7;
}
ch = x;
fputc( ch, pFile );
}
static int * Mini_AigerReadInt( char * pFileName, int * pnObjs, int * pnIns, int * pnLatches, int * pnOuts, int * pnAnds )
{
int i, Temp, nTotal, nObjs, nIns, nLatches, nOuts, nAnds, * pObjs;
FILE * pFile = fopen( pFileName, "rb" );
if ( pFile == NULL )
{
fprintf( stdout, "Mini_AigerRead(): Cannot open the output file \"%s\".\n", pFileName );
return NULL;
}
if ( fgetc(pFile) != 'a' || fgetc(pFile) != 'i' || fgetc(pFile) != 'g' )
{
fprintf( stdout, "Mini_AigerRead(): Can only read binary AIGER.\n" );
fclose( pFile );
return NULL;
}
if ( fscanf(pFile, "%d %d %d %d %d", &nTotal, &nIns, &nLatches, &nOuts, &nAnds) != 5 )
{
fprintf( stdout, "Mini_AigerRead(): Cannot read the header line.\n" );
fclose( pFile );
return NULL;
}
if ( nTotal != nIns + nLatches + nAnds )
{
fprintf( stdout, "The number of objects does not match.\n" );
fclose( pFile );
return NULL;
}
nObjs = 1 + nIns + 2*nLatches + nOuts + nAnds;
pObjs = MINI_AIG_CALLOC( int, nObjs * 2 );
for ( i = 0; i <= nIns + nLatches; i++ )
pObjs[2*i] = pObjs[2*i+1] = MINI_AIG_NULL;
// read flop input literals
for ( i = 0; i < nLatches; i++ )
{
while ( fgetc(pFile) != '\n' );
fscanf( pFile, "%d", &Temp );
pObjs[2*(nObjs-nLatches+i)+0] = Temp;
pObjs[2*(nObjs-nLatches+i)+1] = MINI_AIG_NULL;
}
// read output literals
for ( i = 0; i < nOuts; i++ )
{
while ( fgetc(pFile) != '\n' );
fscanf( pFile, "%d", &Temp );
pObjs[2*(nObjs-nOuts-nLatches+i)+0] = Temp;
pObjs[2*(nObjs-nOuts-nLatches+i)+1] = MINI_AIG_NULL;
}
// read the binary part
while ( fgetc(pFile) != '\n' );
for ( i = 0; i < nAnds; i++ )
{
int uLit = 2*(1+nIns+nLatches+i);
int uLit1 = uLit - Mini_AigerReadUnsigned( pFile );
int uLit0 = uLit1 - Mini_AigerReadUnsigned( pFile );
pObjs[uLit+0] = uLit0;
pObjs[uLit+1] = uLit1;
}
fclose( pFile );
if ( pnObjs ) *pnObjs = nObjs;
if ( pnIns ) *pnIns = nIns;
if ( pnLatches ) *pnLatches = nLatches;
if ( pnOuts ) *pnOuts = nOuts;
if ( pnAnds ) *pnAnds = nAnds;
return pObjs;
}
static Mini_Aig_t * Mini_AigerRead( char * pFileName, int fVerbose )
{
Mini_Aig_t * p;
int nObjs, nIns, nLatches, nOuts, nAnds, * pObjs = Mini_AigerReadInt( pFileName, &nObjs, &nIns, &nLatches, &nOuts, &nAnds );
if ( pObjs == NULL )
return NULL;
p = MINI_AIG_CALLOC( Mini_Aig_t, 1 );
p->nCap = 2*nObjs;
p->nSize = 2*nObjs;
p->nRegs = nLatches;
p->pArray = pObjs;
if ( fVerbose )
printf( "Loaded MiniAIG from the AIGER file \"%s\".\n", pFileName );
return p;
}
static void Mini_AigerWriteInt( char * pFileName, int * pObjs, int nObjs, int nIns, int nLatches, int nOuts, int nAnds )
{
FILE * pFile = fopen( pFileName, "wb" ); int i;
if ( pFile == NULL )
{
fprintf( stdout, "Mini_AigerWrite(): Cannot open the output file \"%s\".\n", pFileName );
return;
}
fprintf( pFile, "aig %d %d %d %d %d\n", nIns + nLatches + nAnds, nIns, nLatches, nOuts, nAnds );
for ( i = 0; i < nLatches; i++ )
fprintf( pFile, "%d\n", pObjs[2*(nObjs-nLatches+i)+0] );
for ( i = 0; i < nOuts; i++ )
fprintf( pFile, "%d\n", pObjs[2*(nObjs-nOuts-nLatches+i)+0] );
for ( i = 0; i < nAnds; i++ )
{
int uLit = 2*(1+nIns+nLatches+i);
int uLit0 = pObjs[uLit+0];
int uLit1 = pObjs[uLit+1];
Mini_AigerWriteUnsigned( pFile, uLit - uLit1 );
Mini_AigerWriteUnsigned( pFile, uLit1 - uLit0 );
}
fprintf( pFile, "c\n" );
fclose( pFile );
}
static void Mini_AigerWrite( char * pFileName, Mini_Aig_t * p, int fVerbose )
{
int i, nIns = 0, nOuts = 0, nAnds = 0;
assert( Mini_AigIsNormalized(p) );
for ( i = 1; i < Mini_AigNodeNum(p); i++ )
{
if ( Mini_AigNodeIsPi(p, i) )
nIns++;
else if ( Mini_AigNodeIsPo(p, i) )
nOuts++;
else
nAnds++;
}
Mini_AigerWriteInt( pFileName, p->pArray, p->nSize/2, nIns - p->nRegs, p->nRegs, nOuts - p->nRegs, nAnds );
if ( fVerbose )
printf( "Written MiniAIG into the AIGER file \"%s\".\n", pFileName );
}
static void Mini_AigerTest( char * pFileNameIn, char * pFileNameOut )
{
Mini_Aig_t * p = Mini_AigerRead( pFileNameIn, 1 );
if ( p == NULL )
return;
printf( "Finished reading input file \"%s\".\n", pFileNameIn );
Mini_AigerWrite( pFileNameOut, p, 1 );
printf( "Finished writing output file \"%s\".\n", pFileNameOut );
Mini_AigStop( p );
}
/*
int main( int argc, char ** argv )
{
if ( argc != 3 )
return 0;
Mini_AigerTest( argv[1], argv[2] );
return 1;
}
*/
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
#ifndef _VERIFIC_DATABASE_H_
ABC_NAMESPACE_HEADER_END
#endif
#endif

View File

@ -559,7 +559,7 @@ extern ABC_DLL Abc_Obj_t * Abc_AigOr( Abc_Aig_t * pMan, Abc_Obj_t * p0, A
extern ABC_DLL Abc_Obj_t * Abc_AigXor( Abc_Aig_t * pMan, Abc_Obj_t * p0, Abc_Obj_t * p1 );
extern ABC_DLL Abc_Obj_t * Abc_AigMux( Abc_Aig_t * pMan, Abc_Obj_t * pC, Abc_Obj_t * p1, Abc_Obj_t * p0 );
extern ABC_DLL Abc_Obj_t * Abc_AigMiter( Abc_Aig_t * pMan, Vec_Ptr_t * vPairs, int fImplic );
extern ABC_DLL void Abc_AigReplace( Abc_Aig_t * pMan, Abc_Obj_t * pOld, Abc_Obj_t * pNew, int fUpdateLevel );
extern ABC_DLL int Abc_AigReplace( Abc_Aig_t * pMan, Abc_Obj_t * pOld, Abc_Obj_t * pNew, int fUpdateLevel );
extern ABC_DLL void Abc_AigDeleteNode( Abc_Aig_t * pMan, Abc_Obj_t * pOld );
extern ABC_DLL void Abc_AigRehash( Abc_Aig_t * pMan );
extern ABC_DLL int Abc_AigNodeHasComplFanoutEdge( Abc_Obj_t * pNode );
@ -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 );

View File

@ -847,7 +847,7 @@ Abc_Obj_t * Abc_AigMiter2( Abc_Aig_t * pMan, Vec_Ptr_t * vPairs )
SeeAlso []
***********************************************************************/
void Abc_AigReplace( Abc_Aig_t * pMan, Abc_Obj_t * pOld, Abc_Obj_t * pNew, int fUpdateLevel )
int Abc_AigReplace( Abc_Aig_t * pMan, Abc_Obj_t * pOld, Abc_Obj_t * pNew, int fUpdateLevel )
{
assert( Vec_PtrSize(pMan->vStackReplaceOld) == 0 );
assert( Vec_PtrSize(pMan->vStackReplaceNew) == 0 );
@ -859,6 +859,8 @@ void Abc_AigReplace( Abc_Aig_t * pMan, Abc_Obj_t * pOld, Abc_Obj_t * pNew, int f
{
pOld = (Abc_Obj_t *)Vec_PtrPop( pMan->vStackReplaceOld );
pNew = (Abc_Obj_t *)Vec_PtrPop( pMan->vStackReplaceNew );
if ( Abc_ObjFanoutNum(pOld) == 0 )
return 0;
Abc_AigReplace_int( pMan, pOld, pNew, fUpdateLevel );
}
if ( fUpdateLevel )
@ -867,6 +869,7 @@ void Abc_AigReplace( Abc_Aig_t * pMan, Abc_Obj_t * pOld, Abc_Obj_t * pNew, int f
if ( pMan->pNtkAig->vLevelsR )
Abc_AigUpdateLevelR_int( pMan );
}
return 1;
}
/**Function*************************************************************

View File

@ -177,7 +177,10 @@ int Abc_NtkDoCheck( Abc_Ntk_t * pNtk )
// check the nodes
if ( Abc_NtkIsStrash(pNtk) )
Abc_AigCheck( (Abc_Aig_t *)pNtk->pManFunc );
{
if ( !Abc_AigCheck( (Abc_Aig_t *)pNtk->pManFunc ) )
return 0;
}
else
{
Abc_NtkForEachNode( pNtk, pNode, i )

View File

@ -113,6 +113,7 @@ int Abc_NodeMinimumBase( Abc_Obj_t * pNode )
DdNode * bTemp, ** pbVars;
Vec_Str_t * vSupport;
int i, nVars, j, iFanin, iFanin2, k = 0;
int ddSize, fDupFanins = 0;
assert( Abc_NtkIsBddLogic(pNode->pNtk) );
assert( Abc_ObjIsNode(pNode) );
@ -126,8 +127,14 @@ int Abc_NodeMinimumBase( Abc_Obj_t * pNode )
return 0;
}
// remove unused fanins
pbVars = ABC_CALLOC( DdNode *, Abc_ObjFaninNum(pNode) );
// remove unused fanins.
// By default, every BDD variable stays equivalent to itself.
ddSize = Cudd_ReadSize( dd );
pbVars = ABC_CALLOC( DdNode *, ddSize );
for (i = 0; i < ddSize; i += 1 ) {
pbVars[i] = Cudd_bddIthVar( dd, i );
}
Vec_IntForEachEntry( &pNode->vFanins, iFanin, i )
{
Abc_Obj_t * pFanin = Abc_NtkObj( pNode->pNtk, iFanin );
@ -140,19 +147,29 @@ int Abc_NodeMinimumBase( Abc_Obj_t * pNode )
Vec_IntForEachEntryStop( &pNode->vFanins, iFanin2, j, k )
if ( iFanin == iFanin2 )
break;
fDupFanins |= (int)(j < k);
if ( j == k )
Vec_IntWriteEntry( &pNode->vFanins, k++, iFanin );
else if ( !Vec_IntRemove( &pFanin->vFanouts, pNode->Id ) )
printf( "The obj %d is not found among the fanouts of obj %d ...\n", pNode->Id, iFanin );
// i-th variable becomes equivalent to j-th variable (can be itself)
pbVars[i] = Cudd_bddIthVar( dd, j );
}
Vec_IntShrink( &pNode->vFanins, k );
// update the function of the node
pNode->pData = Cudd_bddVectorCompose( dd, bTemp = (DdNode *)pNode->pData, pbVars ); Cudd_Ref( (DdNode *)pNode->pData );
Cudd_RecursiveDeref( dd, bTemp );
if ( ! Cudd_IsConstant((DdNode *) pNode->pData ) ) {
pNode->pData = Cudd_bddVectorCompose( dd, bTemp = (DdNode *)pNode->pData, pbVars );
Cudd_Ref( (DdNode *)pNode->pData );
Cudd_RecursiveDeref( dd, bTemp );
}
Vec_StrFree( vSupport );
ABC_FREE( pbVars );
// try again if node had duplicated fanins
if ( fDupFanins )
Abc_NodeMinimumBase( pNode );
return 1;
}

View File

@ -1270,6 +1270,52 @@ Abc_Ntk_t * Abc_NtkCreateWithNode( char * pSop )
return pNtkNew;
}
/**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.]

View File

@ -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", (int)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*************************************************************

File diff suppressed because it is too large Load Diff

View File

@ -658,6 +658,33 @@ Abc_Ntk_t * Abc_NtkFromAigPhase( Aig_Man_t * pMan )
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_NtkFromGiaCollapse( Gia_Man_t * pGia )
{
Aig_Man_t * pMan = Gia_ManToAig( pGia, 0 ); int Res;
Abc_Ntk_t * pNtk = Abc_NtkFromAigPhase( pMan ), * pTemp;
//pNtk->pName = Extra_UtilStrsav(pGia->pName);
Aig_ManStop( pMan );
// collapse the network
pNtk = Abc_NtkCollapse( pTemp = pNtk, 10000, 0, 1, 0, 0, 0 );
Abc_NtkDelete( pTemp );
if ( pNtk == NULL )
return 0;
Res = Abc_NtkGetBddNodeNum( pNtk );
Abc_NtkDelete( pNtk );
return Res == 0;
}
/**Function*************************************************************
@ -1204,7 +1231,11 @@ Abc_Ntk_t * Abc_NtkFromDarChoices( Abc_Ntk_t * pNtkOld, Aig_Man_t * pMan )
Aig_ManForEachCo( pMan, pObj, i )
Abc_ObjAddFanin( Abc_NtkCo(pNtkNew, i), (Abc_Obj_t *)Aig_ObjChild0Copy(pObj) );
if ( !Abc_NtkCheck( pNtkNew ) )
Abc_Print( 1, "Abc_NtkFromDar(): Network check has failed.\n" );
{
Abc_Print( 1, "Abc_NtkFromDar(): Network check has failed. Returning original network.\n" );
Abc_NtkDelete( pNtkNew );
pNtkNew = Abc_NtkDup( pNtkOld );
}
// verify topological order
if ( 0 )
@ -2271,7 +2302,7 @@ Abc_Ntk_t * Abc_NtkDarLcorr( Abc_Ntk_t * pNtk, int nFramesP, int nConfMax, int f
SeeAlso []
***********************************************************************/
Abc_Ntk_t * Abc_NtkDarLcorrNew( Abc_Ntk_t * pNtk, int nVarsMax, int nConfMax, int fVerbose )
Abc_Ntk_t * Abc_NtkDarLcorrNew( Abc_Ntk_t * pNtk, int nVarsMax, int nConfMax, int nLimitMax, int fVerbose )
{
Ssw_Pars_t Pars, * pPars = &Pars;
Aig_Man_t * pMan, * pTemp;
@ -2283,6 +2314,7 @@ Abc_Ntk_t * Abc_NtkDarLcorrNew( Abc_Ntk_t * pNtk, int nVarsMax, int nConfMax, in
pPars->fLatchCorrOpt = 1;
pPars->nBTLimit = nConfMax;
pPars->nSatVarMax = nVarsMax;
pPars->nLimitMax = nLimitMax;
pPars->fVerbose = fVerbose;
pMan = Ssw_SignalCorrespondence( pTemp = pMan, pPars );
Aig_ManStop( pTemp );

View File

@ -1034,7 +1034,7 @@ static word * Ses_ManDeriveTruth( Ses_Man_t * pSes, char * pSol, int fInvert )
for ( i = 0; i < nGates; ++i )
{
f = *p++;
assert( *p++ == 2 );
assert( *p == 2 ), p++;
j = *p++;
k = *p++;

View File

@ -208,6 +208,8 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose )
pAlgoName = "adjustable algorithm (exact) ";
else if ( NpnType == 11 )
pAlgoName = "new cost-aware exact algorithm ";
else if ( NpnType == 12 )
pAlgoName = "new hybrid fast (P) ";
assert( p->nVars <= 16 );
if ( pAlgoName )
@ -356,6 +358,17 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose )
}
Abc_TtHieManStop(pMan);
}
else if ( NpnType == 12 )
{
for ( i = 0; i < p->nFuncs; i++ )
{
if ( fVerbose )
printf( "%7d : ", i );
uCanonPhase = Abc_TtCanonicizePerm( p->pFuncs[i], p->nVars, pCanonPerm );
if ( fVerbose )
Extra_PrintHex( stdout, (unsigned *)p->pFuncs[i], p->nVars ), Abc_TruthNpnPrint(pCanonPerm, uCanonPhase, p->nVars), printf( "\n" );
}
}
else assert( 0 );
clk = Abc_Clock() - clk;
printf( "Classes =%9d ", Abc_TruthNpnCountUnique(p) );
@ -419,7 +432,7 @@ int Abc_NpnTest( char * pFileName, int NpnType, int nVarNum, int fDumpRes, int f
{
if ( fVerbose )
printf( "Using truth tables from file \"%s\"...\n", pFileName );
if ( NpnType >= 0 && NpnType <= 11 )
if ( NpnType >= 0 && NpnType <= 12 )
Abc_TruthNpnTest( pFileName, NpnType, nVarNum, fDumpRes, fBinary, fVerbose );
else
printf( "Unknown canonical form value (%d).\n", NpnType );

View File

@ -237,7 +237,8 @@ Abc_Obj_t * Abc_NodeBddToMuxes_rec( DdManager * dd, DdNode * bFunc, Abc_Ntk_t *
{
Abc_Obj_t * pNodeNew, * pNodeNew0, * pNodeNew1, * pNodeNewC;
assert( !Cudd_IsComplement(bFunc) );
if ( bFunc == b1 || bFunc == a1 )
assert( b1 == a1 );
if ( bFunc == a1 )
return Abc_NtkCreateNodeConst1(pNtkNew);
if ( bFunc == a0 )
return Abc_NtkCreateNodeConst0(pNtkNew);

View File

@ -325,7 +325,7 @@ void Abc_NtkManRefPrintStats( Abc_ManRef_t * p )
***********************************************************************/
int Abc_NtkRefactor( Abc_Ntk_t * pNtk, int nNodeSizeMax, int nConeSizeMax, int fUpdateLevel, int fUseZeros, int fUseDcs, int fVerbose )
{
extern void Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
extern int Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
ProgressBar * pProgress;
Abc_ManRef_t * pManRef;
Abc_ManCut_t * pManCut;
@ -333,7 +333,7 @@ int Abc_NtkRefactor( Abc_Ntk_t * pNtk, int nNodeSizeMax, int nConeSizeMax, int f
Vec_Ptr_t * vFanins;
Abc_Obj_t * pNode;
abctime clk, clkStart = Abc_Clock();
int i, nNodes;
int i, nNodes, RetValue = 1;
assert( Abc_NtkIsStrash(pNtk) );
// cleanup the AIG
@ -377,7 +377,12 @@ pManRef->timeRes += Abc_Clock() - clk;
continue;
// acceptable replacement found, update the graph
clk = Abc_Clock();
Dec_GraphUpdateNetwork( pNode, pFForm, fUpdateLevel, pManRef->nLastGain );
if ( !Dec_GraphUpdateNetwork( pNode, pFForm, fUpdateLevel, pManRef->nLastGain ) )
{
Dec_GraphFree( pFForm );
RetValue = -1;
break;
}
pManRef->timeNtk += Abc_Clock() - clk;
Dec_GraphFree( pFForm );
}
@ -394,18 +399,21 @@ pManRef->timeTotal = Abc_Clock() - clkStart;
// put the nodes into the DFS order and reassign their IDs
Abc_NtkReassignIds( pNtk );
// Abc_AigCheckFaninOrder( pNtk->pManFunc );
// fix the levels
if ( fUpdateLevel )
Abc_NtkStopReverseLevels( pNtk );
else
Abc_NtkLevel( pNtk );
// check
if ( !Abc_NtkCheck( pNtk ) )
if ( RetValue != -1 )
{
printf( "Abc_NtkRefactor: The network check has failed.\n" );
return 0;
// fix the levels
if ( fUpdateLevel )
Abc_NtkStopReverseLevels( pNtk );
else
Abc_NtkLevel( pNtk );
// check
if ( !Abc_NtkCheck( pNtk ) )
{
printf( "Abc_NtkRefactor: The network check has failed.\n" );
return 0;
}
}
return 1;
return RetValue;
}

View File

@ -105,7 +105,7 @@ static void Abc_NtkManRstPrintStats( Abc_ManRst_t * p );
***********************************************************************/
int Abc_NtkRestructure( Abc_Ntk_t * pNtk, int nCutMax, int fUpdateLevel, int fUseZeros, int fVerbose )
{
extern void Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
extern int Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
ProgressBar * pProgress;
Abc_ManRst_t * pManRst;
Cut_Man_t * pManCut;

View File

@ -136,7 +136,7 @@ extern abctime s_ResubTime;
***********************************************************************/
int Abc_NtkResubstitute( Abc_Ntk_t * pNtk, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose )
{
extern void Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
extern int Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
ProgressBar * pProgress;
Abc_ManRes_t * pManRes;
Abc_ManCut_t * pManCut;

View File

@ -60,14 +60,14 @@ extern void Abc_PlaceUpdate( Vec_Ptr_t * vAddedCells, Vec_Ptr_t * vUpdatedNets
***********************************************************************/
int Abc_NtkRewrite( Abc_Ntk_t * pNtk, int fUpdateLevel, int fUseZeros, int fVerbose, int fVeryVerbose, int fPlaceEnable )
{
extern void Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
extern int Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
ProgressBar * pProgress;
Cut_Man_t * pManCut;
Rwr_Man_t * pManRwr;
Abc_Obj_t * pNode;
// Vec_Ptr_t * vAddedCells = NULL, * vUpdatedNets = NULL;
Dec_Graph_t * pGraph;
int i, nNodes, nGain, fCompl;
int i, nNodes, nGain, fCompl, RetValue = 1;
abctime clk, clkStart = Abc_Clock();
assert( Abc_NtkIsStrash(pNtk) );
@ -138,7 +138,11 @@ Rwr_ManAddTimeCuts( pManRwr, Abc_Clock() - clk );
// complement the FF if needed
if ( fCompl ) Dec_GraphComplement( pGraph );
clk = Abc_Clock();
Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
if ( !Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain ) )
{
RetValue = -1;
break;
}
Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
if ( fCompl ) Dec_GraphComplement( pGraph );
@ -175,17 +179,20 @@ Rwr_ManAddTimeTotal( pManRwr, Abc_Clock() - clkStart );
}
// Abc_AigCheckFaninOrder( pNtk->pManFunc );
// fix the levels
if ( fUpdateLevel )
Abc_NtkStopReverseLevels( pNtk );
else
Abc_NtkLevel( pNtk );
// check
if ( !Abc_NtkCheck( pNtk ) )
if ( RetValue >= 0 )
{
printf( "Abc_NtkRewrite: The network check has failed.\n" );
return 0;
if ( fUpdateLevel )
Abc_NtkStopReverseLevels( pNtk );
else
Abc_NtkLevel( pNtk );
// check
if ( !Abc_NtkCheck( pNtk ) )
{
printf( "Abc_NtkRewrite: The network check has failed.\n" );
return 0;
}
}
return 1;
return RetValue;
}

View File

@ -397,10 +397,7 @@ int Abc_NtkRRUpdate( Abc_Ntk_t * pNtk, Abc_Obj_t * pNode, Abc_Obj_t * pFanin, Ab
else assert( 0 );
// replace
if ( pFanout == NULL )
{
Abc_AigReplace( (Abc_Aig_t *)pNtk->pManFunc, pNode, pNodeNew, 1 );
return 1;
}
return Abc_AigReplace( (Abc_Aig_t *)pNtk->pManFunc, pNode, pNodeNew, 1 );
// find the fanout after redundancy removal
if ( pNode == Abc_ObjFanin0(pFanout) )
pFanoutNew = Abc_AigAnd( (Abc_Aig_t *)pNtk->pManFunc, Abc_ObjNotCond(pNodeNew,Abc_ObjFaninC0(pFanout)), Abc_ObjChild1(pFanout) );

View File

@ -608,7 +608,7 @@ void Abc_ManTimeDup( Abc_Ntk_t * pNtkOld, Abc_Ntk_t * pNtkNew )
}
if ( pNtkOld->pManTime->tOutLoad )
{
pNtkNew->pManTime->tOutLoad = ABC_ALLOC( Abc_Time_t, Abc_NtkCiNum(pNtkOld) );
pNtkNew->pManTime->tOutLoad = ABC_ALLOC( Abc_Time_t, Abc_NtkCoNum(pNtkOld) );
memcpy( pNtkNew->pManTime->tOutLoad, pNtkOld->pManTime->tOutLoad, sizeof(Abc_Time_t) * Abc_NtkCoNum(pNtkOld) );
}

View File

@ -466,7 +466,7 @@ Gia_Man_t * Acb_NtkGiaDeriveMiter( Gia_Man_t * pOne, Gia_Man_t * pTwo, int Type
***********************************************************************/
void Acb_OutputFile( char * pFileName, Acb_Ntk_t * pNtkF, int * pModel )
{
char * pFileName0 = pFileName? pFileName : "output";
const char * pFileName0 = pFileName? pFileName : "output";
FILE * pFile = fopen( pFileName0, "wb" );
if ( pFile == NULL )
{

View File

@ -1161,7 +1161,7 @@ int CmdCommandScanDir( Abc_Frame_t * pAbc, int argc, char **argv )
struct _finddata_t c_file;
char * pDirStr = NULL;
char* pDirCur = NULL;
long hFile;
ABC_PTRINT_T hFile;
char c;
Extra_UtilGetoptReset();
@ -1354,7 +1354,7 @@ void CnfDupFileUnzip( char * pOldName )
int CmdCommandRenameFiles( Abc_Frame_t * pAbc, int argc, char **argv )
{
struct _finddata_t c_file;
long hFile;
ABC_PTRINT_T hFile;
char pNewName[1000];
char * pDirStr = NULL;
char * pDirCur = NULL;
@ -1515,7 +1515,7 @@ usage:
int CmdCommandLs( Abc_Frame_t * pAbc, int argc, char **argv )
{
struct _finddata_t c_file;
long hFile;
ABC_PTRINT_T hFile;
int fLong = 0;
int fOnlyBLIF = 0;
char Buffer[25];
@ -1618,7 +1618,7 @@ usage:
int CmdCommandScrGen( Abc_Frame_t * pAbc, int argc, char **argv )
{
struct _finddata_t c_file;
long hFile;
ABC_PTRINT_T hFile;
FILE * pFile = NULL;
char * pFileStr = "test.s";
char * pDirStr = NULL;

View File

@ -114,7 +114,8 @@ Vec_Ptr_t * CmdCollectFileNames()
{
Vec_Ptr_t * vFileNames;
struct _finddata_t c_file;
long hFile;
//long hFile;
ABC_PTRINT_T hFile;
if( (hFile = _findfirst( "*.exe", &c_file )) == -1L )
{
// Abc_Print( 0, "No files with extention \"%s\" in the current directory.\n", "exe" );

View File

@ -20,6 +20,7 @@
#include "base/abc/abc.h"
#include "base/main/mainInt.h"
#include "misc/util/utilSignal.h"
#include "cmdInt.h"
#include <ctype.h>
@ -462,7 +463,7 @@ FILE * CmdFileOpen( Abc_Frame_t * pAbc, char *sFileName, char *sMode, char **pFi
else
{
// print the path/name of the resource file 'abc.rc' that is being loaded
if ( !silent && strlen(sRealName) >= 6 && strcmp( sRealName + strlen(sRealName) - 6, "abc.rc" ) == 0 )
if ( !silent && strlen(sRealName) >= 6 && strcmp( sRealName + strlen(sRealName) - 6, "abc.rc" ) == 0 )
Abc_Print( 1, "Loading resource file \"%s\".\n", sRealName );
}
}
@ -752,6 +753,90 @@ void CmdPrintTable( st__table * tTable, int fAliases )
ABC_FREE( ppNames );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManKissatCall( Abc_Frame_t * pAbc, char * pFileName, char * pArgs, int nConfs, int nTimeLimit, int fSat, int fUnsat, int fPrintCex, int fVerbose )
{
char Command[1000], Buffer[100];
char * pNameWin = "kissat.exe";
char * pNameUnix = "kissat";
char * pKissatName = NULL;
//FILE * pFile = NULL;
// get the names from the resource file
if ( Cmd_FlagReadByName(pAbc, "kissatwin") )
pNameWin = Cmd_FlagReadByName(pAbc, "kissatwin");
if ( Cmd_FlagReadByName(pAbc, "kissatunix") )
pNameUnix = Cmd_FlagReadByName(pAbc, "kissatunix");
/*
// check if the binary is available
if ( (pFile = fopen( pNameWin, "r" )) )
pKissatName = pNameWin;
else if ( (pFile = fopen( pNameUnix, "r" )) )
pKissatName = pNameUnix;
else if ( pFile == NULL )
{
fprintf( stdout, "Cannot find Kissat binary \"%s\" or \"%s\" in the current directory.\n", pNameWin, pNameUnix );
return;
}
fclose( pFile );
*/
#ifdef _WIN32
pKissatName = pNameWin;
#else
pKissatName = pNameUnix;
#endif
sprintf( Command, "%s", pKissatName );
if ( pArgs )
{
strcat( Command, " " );
strcat( Command, pArgs );
}
if ( !pArgs || (strcmp(pArgs, "-h") && strcmp(pArgs, "--help")) )
{
if ( !fVerbose )
strcat( Command, " -q" );
if ( !fPrintCex )
strcat( Command, " -n" );
if ( fSat )
strcat( Command, " --sat" );
if ( fUnsat )
strcat( Command, " --unsat" );
if ( nConfs )
{
sprintf( Buffer, " --conflicts=%d", nConfs );
strcat( Command, Buffer );
}
if ( nTimeLimit )
{
sprintf( Buffer, " --time=%d", nTimeLimit );
strcat( Command, Buffer );
}
strcat( Command, " " );
strcat( Command, pFileName );
}
if ( fVerbose )
printf( "Running command: %s\n", Command );
if ( Util_SignalSystem( Command ) == -1 )
{
fprintf( stdout, "The following command has returned a strange exit status:\n" );
fprintf( stdout, "\"%s\"\n", Command );
}
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////

View File

@ -85,6 +85,7 @@ static int IoCommandWriteTruths ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteStatus ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteSmv ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteJson ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteResub ( Abc_Frame_t * pAbc, int argc, char **argv );
extern void Abc_FrameCopyLTLDataBase( Abc_Frame_t *pAbc, Abc_Ntk_t * pNtk );
@ -157,6 +158,7 @@ void Io_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "I/O", "write_status", IoCommandWriteStatus, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_smv", IoCommandWriteSmv, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_json", IoCommandWriteJson, 0 );
Cmd_CommandAdd( pAbc, "I/O", "&write_resub", IoCommandWriteResub, 0 );
}
/**Function*************************************************************
@ -1402,7 +1404,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;
@ -1429,28 +1431,36 @@ int IoCommandReadTruth( Abc_Frame_t * pAbc, int argc, char ** argv )
goto usage;
if ( fFile )
{
FILE * pFile = fopen( argv[globalUtilOptind], "rb" );
if ( pFile == NULL )
{
printf( "The file \"%s\" cannot be found.\n", argv[globalUtilOptind] );
return 1;
}
else
fclose( pFile );
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_SopFromTruthHex(pStr);
vSops = Abc_SopFromTruthsHex(pStr);
else
pSopCover = Abc_SopFromTruthBin(pStr);
vSops = Abc_SopFromTruthsBin(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_NtkCreateWithNodes( vSops );
Vec_PtrFreeFree( vSops );
if ( pNtk == NULL )
{
fprintf( pAbc->Err, "Deriving the network has failed.\n" );
@ -1463,9 +1473,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 representation [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 notation [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, "\ttruth : truth table with most signficant bit first (e.g. 1000 for AND(a,b))\n" );
fprintf( pAbc->Err, "\tfile : file name with the truth table\n" );
@ -3582,19 +3592,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, "rxbh" ) ) != EOF )
{
switch ( c )
{
case 'r':
fReverse ^= 1;
break;
case 'x':
fHex ^= 1;
break;
case 'b':
fBinary ^= 1;
fBinaryFile ^= 1;
break;
case 'h':
goto usage;
@ -3632,19 +3646,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 ( fBinaryFile )
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 [-rxbh] <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, "\tfile : the name of the file to write\n" );
return 1;
@ -3797,6 +3814,57 @@ usage:
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int IoCommandWriteResub( Abc_Frame_t * pAbc, int argc, char **argv )
{
extern void Gia_ManWriteResub( Gia_Man_t * p, char * pFileName );
char * pFileName;
int c;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
{
switch ( c )
{
case 'h':
goto usage;
default:
goto usage;
}
}
if ( argc != globalUtilOptind + 1 )
goto usage;
pFileName = argv[globalUtilOptind];
if ( pAbc->pGia == NULL )
{
Abc_Print( -1, "IoCommandWriteResub(): There is no AIG.\n" );
return 1;
}
if ( Gia_ManCiNum(pAbc->pGia) > 20 )
{
Abc_Print( -1, "IoCommandWriteResub(): The number of inputs is wrong.\n" );
return 1;
}
Gia_ManWriteResub( pAbc->pGia, pFileName );
return 0;
usage:
fprintf( pAbc->Err, "usage: &write_resub [-ch] <file>\n" );
fprintf( pAbc->Err, "\t write the network in resub format\n" );
fprintf( pAbc->Err, "\t-h : print the help message\n" );
fprintf( pAbc->Err, "\tfile : the name of the file to write (extension .json)\n" );
return 1;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////

View File

@ -61,6 +61,18 @@ void Io_WriteGml( Abc_Ntk_t * pNtk, char * pFileName )
fprintf( pFile, "# GML for \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
fprintf( pFile, "graph [\n" );
// output constant node in the AIG if it has fanouts
if ( Abc_NtkIsStrash(pNtk) )
{
pObj = Abc_AigConst1( pNtk );
if ( Abc_ObjFanoutNum(pObj) > 0 )
{
fprintf( pFile, "\n" );
fprintf( pFile, " node [ id %5d label \"%s\"\n", pObj->Id, Abc_ObjName(pObj) );
fprintf( pFile, " graphics [ type \"ellipse\" fill \"#CCCCFF\" ]\n" ); // grey
fprintf( pFile, " ]\n" );
}
}
// output the POs
fprintf( pFile, "\n" );
Abc_NtkForEachPo( pNtk, pObj, i )

View File

@ -49,6 +49,8 @@ extern void Scl_Init( Abc_Frame_t * pAbc );
extern void Scl_End( Abc_Frame_t * pAbc );
extern void Wlc_Init( Abc_Frame_t * pAbc );
extern void Wlc_End( Abc_Frame_t * pAbc );
extern void Wln_Init( Abc_Frame_t * pAbc );
extern void Wln_End( Abc_Frame_t * pAbc );
extern void Bac_Init( Abc_Frame_t * pAbc );
extern void Bac_End( Abc_Frame_t * pAbc );
extern void Cba_Init( Abc_Frame_t * pAbc );
@ -116,6 +118,7 @@ void Abc_FrameInit( Abc_Frame_t * pAbc )
Load_Init( pAbc );
Scl_Init( pAbc );
Wlc_Init( pAbc );
Wln_Init( pAbc );
Bac_Init( pAbc );
Cba_Init( pAbc );
Pla_Init( pAbc );
@ -156,6 +159,7 @@ void Abc_FrameEnd( Abc_Frame_t * pAbc )
Load_End( pAbc );
Scl_End( pAbc );
Wlc_End( pAbc );
Wln_End( pAbc );
Bac_End( pAbc );
Cba_End( pAbc );
Pla_End( pAbc );

View File

@ -145,6 +145,7 @@ struct Abc_Frame_t_
void * pAbc85Delay;
void * pAbcWlc;
Vec_Int_t * pAbcWlcInv;
void * pAbcRtl;
void * pAbcBac;
void * pAbcCba;
void * pAbcPla;

View File

@ -1930,9 +1930,9 @@ Gia_Man_t * Wlc_NtkBitBlast( Wlc_Ntk_t * p, Wlc_BstPar_t * pParIn )
// create combinational outputs in the normal manager
pFans0 = Wlc_ObjFaninNum(pObj) > 0 ? Vec_IntEntryP( vBits, Wlc_ObjCopy(p, Wlc_ObjFaninId0(pObj)) ) : NULL;
pFans1 = Wlc_ObjFaninNum(pObj) > 1 ? Vec_IntEntryP( vBits, Wlc_ObjCopy(p, Wlc_ObjFaninId1(pObj)) ) : NULL;
pFans2 = Wlc_ObjFaninNum(pObj) > 2 ? Vec_IntEntryP( vBits, Wlc_ObjCopy(p, Wlc_ObjFaninId2(pObj)) ) : NULL;
pFans3 = Wlc_ObjFaninNum(pObj) > 3 ? Vec_IntEntryP( vBits, Wlc_ObjCopy(p, Wlc_ObjFaninId(pObj,3)) ) : NULL;
pFans1 = Wlc_ObjFaninNum(pObj) > 2 ? Vec_IntEntryP( vBits, Wlc_ObjCopy(p, Wlc_ObjFaninId(pObj,2)) ) : NULL; // reset
pFans2 = Wlc_ObjFaninNum(pObj) > 3 ? Vec_IntEntryP( vBits, Wlc_ObjCopy(p, Wlc_ObjFaninId(pObj,3)) ) : NULL; // set
pFans3 = Wlc_ObjFaninNum(pObj) > 4 ? Vec_IntEntryP( vBits, Wlc_ObjCopy(p, Wlc_ObjFaninId(pObj,4)) ) : NULL; // enable
for ( k = 0; k < nRange; k++ )
Gia_ManAppendCo( pNew, pFans0[k] );
Gia_ManAppendCo( pNew, pFans1[0] );
@ -2588,6 +2588,50 @@ Gia_Man_t * Wlc_BlastArray( char * pFileName )
return pNew;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Int_t * Wlc_ComputePerm( Wlc_Ntk_t * pNtk, int nPis )
{
Vec_Int_t * vPerm = Vec_IntAlloc( 100 );
Vec_Int_t * vSizes = Vec_IntAlloc( 100 );
Vec_Int_t * vOffs = Vec_IntAlloc( 100 );
Wlc_Obj_t * pObj;
int i, k, First, Size, nBitCis = 0, fChange = 1;
Wlc_NtkForEachPi( pNtk, pObj, i )
{
Vec_IntPush( vOffs, nBitCis );
Vec_IntPush( vSizes, Wlc_ObjRange(pObj) );
nBitCis += Wlc_ObjRange(pObj);
}
for ( k = 0; fChange; k++ )
{
fChange = 0;
Vec_IntForEachEntryTwo( vOffs, vSizes, First, Size, i )
if ( k < Size )
{
Vec_IntPush( vPerm, First+k );
fChange = 1;
}
}
assert( Vec_IntSize(vPerm) == nBitCis );
Vec_IntFree( vOffs );
Vec_IntFree( vSizes );
Vec_IntReverseOrder( vPerm );
for ( i = Vec_IntSize(vPerm); i < nPis; i++ )
Vec_IntPush( vPerm, i );
//Vec_IntPrint( vPerm );
return vPerm;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////

View File

@ -21,7 +21,7 @@
#include "wlc.h"
#include "base/wln/wln.h"
#include "base/main/mainInt.h"
#include "aig/miniaig/ndr.h"
//#include "aig/miniaig/ndr.h"
ABC_NAMESPACE_IMPL_START
@ -88,7 +88,7 @@ void Wlc_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "Word level", "%memabs2", Abc_CommandMemAbs2, 0 );
Cmd_CommandAdd( pAbc, "Word level", "%blast", Abc_CommandBlast, 0 );
Cmd_CommandAdd( pAbc, "Word level", "%blastmem", Abc_CommandBlastMem, 0 );
Cmd_CommandAdd( pAbc, "Word level", "%graft", Abc_CommandGraft, 0 );
// Cmd_CommandAdd( pAbc, "Word level", "%graft", Abc_CommandGraft, 0 );
Cmd_CommandAdd( pAbc, "Word level", "%retime", Abc_CommandRetime, 0 );
Cmd_CommandAdd( pAbc, "Word level", "%profile", Abc_CommandProfile, 0 );
Cmd_CommandAdd( pAbc, "Word level", "%short_names", Abc_CommandShortNames, 0 );
@ -295,7 +295,6 @@ usage:
return 1;
}
/**Function********************************************************************
Synopsis []
@ -1032,12 +1031,12 @@ int Abc_CommandBlast( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern void Wlc_NtkPrintInputInfo( Wlc_Ntk_t * pNtk );
Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
Gia_Man_t * pNew = NULL; int c, fMiter = 0, fDumpNames = 0, fPrintInputInfo = 0;
Gia_Man_t * pNew = NULL; int c, fMiter = 0, fDumpNames = 0, fPrintInputInfo = 0, fReorder = 0;
Wlc_BstPar_t Par, * pPar = &Par;
Wlc_BstParDefault( pPar );
pPar->nOutputRange = 2;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "ORAMcombqaydestnizvh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "ORAMcombqaydestrnizvh" ) ) != EOF )
{
switch ( c )
{
@ -1119,6 +1118,9 @@ int Abc_CommandBlast( Abc_Frame_t * pAbc, int argc, char ** argv )
pPar->fCreateMiter ^= 1;
fMiter ^= 1;
break;
case 'r':
fReorder ^= 1;
break;
case 'n':
fDumpNames ^= 1;
break;
@ -1198,10 +1200,19 @@ int Abc_CommandBlast( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Print( 1, "Finished dumping file \"pio_name_map.txt\" containing PI/PO name mapping.\n" );
}
}
if ( fReorder )
{
extern Vec_Int_t * Wlc_ComputePerm( Wlc_Ntk_t * pNtk, int nPis );
Vec_Int_t * vPiPerm = Wlc_ComputePerm( pNtk, Gia_ManPiNum(pNew) );
Gia_Man_t * pTemp = Gia_ManDupPerm( pNew, vPiPerm );
Vec_IntFree( vPiPerm );
Gia_ManStop( pNew );
pNew = pTemp;
}
Abc_FrameUpdateGia( pAbc, pNew );
return 0;
usage:
Abc_Print( -2, "usage: %%blast [-ORAM num] [-combqaydestnizvh]\n" );
Abc_Print( -2, "usage: %%blast [-ORAM num] [-combqaydestrnizvh]\n" );
Abc_Print( -2, "\t performs bit-blasting of the word-level design\n" );
Abc_Print( -2, "\t-O num : zero-based index of the first word-level PO to bit-blast [default = %d]\n", pPar->iOutput );
Abc_Print( -2, "\t-R num : the total number of word-level POs to bit-blast [default = %d]\n", pPar->nOutputRange );
@ -1218,6 +1229,7 @@ usage:
Abc_Print( -2, "\t-e : toggle creating miter with output word bits combined [default = %s]\n", pPar->fCreateWordMiter? "yes": "no" );
Abc_Print( -2, "\t-s : toggle creating decoded MUXes [default = %s]\n", pPar->fDecMuxes? "yes": "no" );
Abc_Print( -2, "\t-t : toggle creating regular multi-output miter [default = %s]\n", fMiter? "yes": "no" );
Abc_Print( -2, "\t-r : toggle using interleaved variable ordering [default = %s]\n", fReorder? "yes": "no" );
Abc_Print( -2, "\t-n : toggle dumping signal names into a text file [default = %s]\n", fDumpNames? "yes": "no" );
Abc_Print( -2, "\t-i : toggle to print input names after blasting [default = %s]\n", fPrintInputInfo ? "yes": "no" );
Abc_Print( -2, "\t-z : toggle saving flop names after blasting [default = %s]\n", pPar->fSaveFfNames ? "yes": "no" );

View File

@ -800,7 +800,7 @@ void Wlc_NtkTrace_rec( Wlc_Ntk_t * p, Wlc_Obj_t * pObj, int iFrame, Vec_Int_t *
{
int Index = 3*(iFrame*Vec_IntSize(vMemObjs) + iNum);
int Value = (int)Vec_WrdEntry( vValues, Index );
assert( Value == 0 && Value == 1 );
assert( Value == 0 || Value == 1 );
Wlc_NtkTrace_rec( p, Value ? Wlc_ObjFanin2(p, pObj) : Wlc_ObjFanin1(p, pObj), iFrame, vMemObjs, vValues, ValueA, vRes );
Vec_IntPush( vRes, (iObj << 11) | (iFrame << 1) | Value );
}

View File

@ -1,8 +1,13 @@
SRC += src/base/wln/wln.c \
src/base/wln/wlnBlast.c \
src/base/wln/wlnCom.c \
src/base/wln/wlnGuide.c \
src/base/wln/wlnMem.c \
src/base/wln/wlnNdr.c \
src/base/wln/wlnNtk.c \
src/base/wln/wlnObj.c \
src/base/wln/wlnRead.c \
src/base/wln/wlnRetime.c \
src/base/wln/wlnRtl.c \
src/base/wln/wlnWlc.c \
src/base/wln/wlnWriteVer.c

View File

@ -251,6 +251,10 @@ extern void Wln_NtkRetimeCreateDelayInfo( Wln_Ntk_t * pNtk );
/*=== wlcWriteVer.c ========================================================*/
extern void Wln_WriteVer( Wln_Ntk_t * p, char * pFileName );
/*=== wlcRead.c ========================================================*/
typedef struct Rtl_Lib_t_ Rtl_Lib_t;
extern Rtl_Lib_t * Rtl_LibReadFile( char * pFileName, char * pFileSpec );
extern void Rtl_LibFree( Rtl_Lib_t * p );
ABC_NAMESPACE_HEADER_END

388
src/base/wln/wlnBlast.c Normal file
View File

@ -0,0 +1,388 @@
/**CFile****************************************************************
FileName [wlnBlast.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Word-level network.]
Synopsis []
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - September 23, 2018.]
Revision [$Id: wlnBlast.c,v 1.00 2018/09/23 00:00:00 alanmi Exp $]
***********************************************************************/
#include "wln.h"
#include "base/wlc/wlc.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Rtl_VecExtend( Vec_Int_t * p, int nRange, int fSigned )
{
Vec_IntFillExtra( p, nRange, fSigned ? Vec_IntEntryLast(p) : 0 );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Rtl_NtkBlastNode( Gia_Man_t * pNew, int Type, int nIns, Vec_Int_t * vDatas, int nRange, int fSign0, int fSign1 )
{
extern void Wlc_BlastMinus( Gia_Man_t * pNew, int * pNum, int nNum, Vec_Int_t * vRes );
extern int Wlc_BlastReduction( Gia_Man_t * pNew, int * pFans, int nFans, int Type );
extern int Wlc_BlastLess( Gia_Man_t * pNew, int * pArg0, int * pArg1, int nBits );
extern int Wlc_BlastLessSigned( Gia_Man_t * pNew, int * pArg0, int * pArg1, int nBits );
extern void Wlc_BlastShiftRight( Gia_Man_t * pNew, int * pNum, int nNum, int * pShift, int nShift, int fSticky, Vec_Int_t * vRes );
extern void Wlc_BlastShiftLeft( Gia_Man_t * pNew, int * pNum, int nNum, int * pShift, int nShift, int fSticky, Vec_Int_t * vRes );
extern int Wlc_BlastAdder( Gia_Man_t * pNew, int * pAdd0, int * pAdd1, int nBits, int Carry ); // result is in pAdd0
extern void Wlc_BlastSubtract( Gia_Man_t * pNew, int * pAdd0, int * pAdd1, int nBits, int Carry ); // result is in pAdd0
extern int Wlc_NtkCountConstBits( int * pArray, int nSize );
extern void Wlc_BlastBooth( Gia_Man_t * pNew, int * pArgA, int * pArgB, int nArgA, int nArgB, Vec_Int_t * vRes, int fSigned, int fCla, Vec_Wec_t ** pvProds );
extern void Wlc_BlastMultiplier3( Gia_Man_t * pNew, int * pArgA, int * pArgB, int nArgA, int nArgB, Vec_Int_t * vRes, int fSigned, int fCla, Vec_Wec_t ** pvProds );
extern void Wlc_BlastZeroCondition( Gia_Man_t * pNew, int * pDiv, int nDiv, Vec_Int_t * vRes );
extern void Wlc_BlastDivider( Gia_Man_t * pNew, int * pNum, int nNum, int * pDiv, int nDiv, int fQuo, Vec_Int_t * vRes );
extern void Wlc_BlastDividerSigned( Gia_Man_t * pNew, int * pNum, int nNum, int * pDiv, int nDiv, int fQuo, Vec_Int_t * vRes );
extern void Wlc_BlastPower( Gia_Man_t * pNew, int * pNum, int nNum, int * pExp, int nExp, Vec_Int_t * vTemp, Vec_Int_t * vRes );
int k, iLit, iLit0, iLit1;
if ( nIns == 1 )
{
Vec_Int_t * vArg = vDatas;
Vec_Int_t * vRes = vDatas+3;
assert( Vec_IntSize(vRes) == 0 );
if ( Type == ABC_OPER_BIT_INV ) // Y = ~A $not
{
assert( Vec_IntSize(vArg) == nRange );
Vec_IntForEachEntry( vArg, iLit, k )
Vec_IntPush( vRes, Abc_LitNot(iLit) );
return;
}
if ( Type == ABC_OPER_BIT_BUF ) // Y = +A $pos
{
assert( Vec_IntSize(vArg) == nRange );
Vec_IntForEachEntry( vArg, iLit, k )
Vec_IntPush( vRes, iLit );
return;
}
if ( Type == ABC_OPER_ARI_MIN ) // Y = -A $neg
{
assert( Vec_IntSize(vArg) == nRange );
Wlc_BlastMinus( pNew, Vec_IntArray(vArg), Vec_IntSize(vArg), vRes );
return;
}
if ( Type == ABC_OPER_RED_AND ) // Y = &A $reduce_and
{
assert( nRange == 1 );
Vec_IntPush( vRes, Wlc_BlastReduction( pNew, Vec_IntArray(vArg), Vec_IntSize(vArg), WLC_OBJ_REDUCT_AND ) );
for ( k = 1; k < nRange; k++ )
Vec_IntPush( vRes, 0 );
return;
}
if ( Type == ABC_OPER_RED_OR ) // Y = |A $reduce_or $reduce_bool
{
assert( nRange == 1 );
Vec_IntPush( vRes, Wlc_BlastReduction( pNew, Vec_IntArray(vArg), Vec_IntSize(vArg), WLC_OBJ_REDUCT_OR ) );
for ( k = 1; k < nRange; k++ )
Vec_IntPush( vRes, 0 );
return;
}
if ( Type == ABC_OPER_RED_XOR ) // Y = ^A $reduce_xor
{
assert( nRange == 1 );
Vec_IntPush( vRes, Wlc_BlastReduction( pNew, Vec_IntArray(vArg), Vec_IntSize(vArg), WLC_OBJ_REDUCT_XOR ) );
for ( k = 1; k < nRange; k++ )
Vec_IntPush( vRes, 0 );
return;
}
if ( Type == ABC_OPER_RED_NXOR ) // Y = ~^A $reduce_xnor
{
assert( nRange == 1 );
Vec_IntPush( vRes, Wlc_BlastReduction( pNew, Vec_IntArray(vArg), Vec_IntSize(vArg), WLC_OBJ_REDUCT_NXOR ) );
for ( k = 1; k < nRange; k++ )
Vec_IntPush( vRes, 0 );
return;
}
if ( Type == ABC_OPER_LOGIC_NOT ) // Y = !A $logic_not
{
int iLit = Wlc_BlastReduction( pNew, Vec_IntArray(vArg), Vec_IntSize(vArg), WLC_OBJ_REDUCT_OR );
assert( nRange == 1 );
Vec_IntFill( vRes, 1, Abc_LitNot(iLit) );
for ( k = 1; k < nRange; k++ )
Vec_IntPush( vRes, 0 );
return;
}
assert( 0 );
return;
}
if ( nIns == 2 )
{
Vec_Int_t * vArg0 = vDatas;
Vec_Int_t * vArg1 = vDatas+1;
Vec_Int_t * vRes = vDatas+3;
int nRangeMax = Abc_MaxInt( nRange, Abc_MaxInt(Vec_IntSize(vArg0), Vec_IntSize(vArg1)) );
int nSizeArg0 = Vec_IntSize(vArg0);
int nSizeArg1 = Vec_IntSize(vArg1);
Rtl_VecExtend( vArg0, nRangeMax, fSign0 );
Rtl_VecExtend( vArg1, nRangeMax, fSign1 );
assert( Vec_IntSize(vArg0) == Vec_IntSize(vArg1) );
assert( Vec_IntSize(vRes) == 0 );
if ( Type == ABC_OPER_LOGIC_AND ) // Y = A && B $logic_and
{
int iLit0 = Wlc_BlastReduction( pNew, Vec_IntArray(vArg0), Vec_IntSize(vArg0), WLC_OBJ_REDUCT_OR );
int iLit1 = Wlc_BlastReduction( pNew, Vec_IntArray(vArg1), Vec_IntSize(vArg1), WLC_OBJ_REDUCT_OR );
assert( 1 == nRange );
Vec_IntFill( vRes, 1, Gia_ManHashAnd(pNew, iLit0, iLit1) );
for ( k = 1; k < nRange; k++ )
Vec_IntPush( vRes, 0 );
return;
}
if ( Type == ABC_OPER_LOGIC_OR ) // Y = A || B $logic_or
{
int iLit0 = Wlc_BlastReduction( pNew, Vec_IntArray(vArg0), Vec_IntSize(vArg0), WLC_OBJ_REDUCT_OR );
int iLit1 = Wlc_BlastReduction( pNew, Vec_IntArray(vArg1), Vec_IntSize(vArg1), WLC_OBJ_REDUCT_OR );
assert( 1 == nRange );
Vec_IntFill( vRes, 1, Gia_ManHashOr(pNew, iLit0, iLit1) );
for ( k = 1; k < nRange; k++ )
Vec_IntPush( vRes, 0 );
return;
}
if ( Type == ABC_OPER_BIT_AND ) // Y = A & B $and
{
Vec_IntForEachEntryTwo( vArg0, vArg1, iLit0, iLit1, k )
Vec_IntPush( vRes, Gia_ManHashAnd(pNew, iLit0, iLit1) );
Vec_IntShrink( vRes, nRange );
return;
}
if ( Type == ABC_OPER_BIT_OR ) // Y = A | B $or
{
Vec_IntForEachEntryTwo( vArg0, vArg1, iLit0, iLit1, k )
Vec_IntPush( vRes, Gia_ManHashOr(pNew, iLit0, iLit1) );
Vec_IntShrink( vRes, nRange );
return;
}
if ( Type == ABC_OPER_BIT_XOR ) // Y = A ^ B $xor
{
Vec_IntForEachEntryTwo( vArg0, vArg1, iLit0, iLit1, k )
Vec_IntPush( vRes, Gia_ManHashXor(pNew, iLit0, iLit1) );
Vec_IntShrink( vRes, nRange );
return;
}
if ( Type == ABC_OPER_BIT_NXOR ) // Y = A ~^ B $xnor
{
assert( Vec_IntSize(vArg0) == nRange );
Vec_IntForEachEntryTwo( vArg0, vArg1, iLit0, iLit1, k )
Vec_IntPush( vRes, Abc_LitNot(Gia_ManHashXor(pNew, iLit0, iLit1)) );
Vec_IntShrink( vRes, nRange );
return;
}
/*
if ( !strcmp(pType, "$lt") ) return ABC_OPER_COMP_LESS; // Y = A < B $lt
if ( !strcmp(pType, "$le") ) return ABC_OPER_COMP_LESSEQU; // Y = A <= B $le
if ( !strcmp(pType, "$ge") ) return ABC_OPER_COMP_MOREEQU; // Y = A >= B $ge
if ( !strcmp(pType, "$gt") ) return ABC_OPER_COMP_MORE; // Y = A > B $gt
if ( !strcmp(pType, "$eq") ) return ABC_OPER_COMP_EQU; // Y = A == B $eq
if ( !strcmp(pType, "$ne") ) return ABC_OPER_COMP_NOTEQU; // Y = A != B $ne
*/
if ( Type == ABC_OPER_COMP_EQU || Type == ABC_OPER_COMP_NOTEQU )
{
iLit = 0;
assert( nRange == 1 );
Vec_IntForEachEntryTwo( vArg0, vArg1, iLit0, iLit1, k )
iLit = Gia_ManHashOr( pNew, iLit, Gia_ManHashXor(pNew, iLit0, iLit1) );
Vec_IntFill( vRes, 1, Abc_LitNotCond(iLit, Type == ABC_OPER_COMP_EQU) );
for ( k = 1; k < nRange; k++ )
Vec_IntPush( vRes, 0 );
return;
}
if ( Type == ABC_OPER_COMP_LESS || Type == ABC_OPER_COMP_LESSEQU ||
Type == ABC_OPER_COMP_MORE || Type == ABC_OPER_COMP_MOREEQU )
{
int fSigned = fSign0 && fSign1;
int fSwap = (Type == ABC_OPER_COMP_MORE || Type == ABC_OPER_COMP_LESSEQU);
int fCompl = (Type == ABC_OPER_COMP_MOREEQU || Type == ABC_OPER_COMP_LESSEQU);
assert( Vec_IntSize(vArg0) == Vec_IntSize(vArg1) );
assert( nRange == 1 );
if ( fSwap )
ABC_SWAP( Vec_Int_t, *vArg0, *vArg1 )
if ( fSigned )
iLit = Wlc_BlastLessSigned( pNew, Vec_IntArray(vArg0), Vec_IntArray(vArg1), Vec_IntSize(vArg0) );
else
iLit = Wlc_BlastLess( pNew, Vec_IntArray(vArg0), Vec_IntArray(vArg1), Vec_IntSize(vArg0) );
iLit = Abc_LitNotCond( iLit, fCompl );
Vec_IntFill( vRes, 1, iLit );
for ( k = 1; k < nRange; k++ )
Vec_IntPush( vRes, 0 );
return;
}
/*
if ( !strcmp(pType, "$shl") ) return ABC_OPER_SHIFT_L; // Y = A << B $shl
if ( !strcmp(pType, "$shr") ) return ABC_OPER_SHIFT_R; // Y = A >> B $shr
if ( !strcmp(pType, "$sshl") ) return ABC_OPER_SHIFT_LA; // Y = A <<< B $sshl
if ( !strcmp(pType, "$sshr") ) return ABC_OPER_SHIFT_RA; // Y = A >>> B $sshr
*/
if ( Type == ABC_OPER_SHIFT_R || Type == ABC_OPER_SHIFT_RA ||
Type == ABC_OPER_SHIFT_L || Type == ABC_OPER_SHIFT_LA )
{
Vec_IntShrink( vArg1, nSizeArg1 );
if ( Type == ABC_OPER_SHIFT_R || Type == ABC_OPER_SHIFT_RA )
Wlc_BlastShiftRight( pNew, Vec_IntArray(vArg0), nRangeMax, Vec_IntArray(vArg1), nSizeArg1, fSign0 && Type == ABC_OPER_SHIFT_RA, vRes );
else
Wlc_BlastShiftLeft( pNew, Vec_IntArray(vArg0), nRangeMax, Vec_IntArray(vArg1), nSizeArg1, 0, vRes );
Vec_IntShrink( vRes, nRange );
return;
}
/*
if ( !strcmp(pType, "$add") ) return ABC_OPER_ARI_ADD; // Y = A + B $add
if ( !strcmp(pType, "$sub") ) return ABC_OPER_ARI_SUB; // Y = A - B $sub
if ( !strcmp(pType, "$mul") ) return ABC_OPER_ARI_MUL; // Y = A * B $mul
if ( !strcmp(pType, "$div") ) return ABC_OPER_ARI_DIV; // Y = A / B $div
if ( !strcmp(pType, "$mod") ) return ABC_OPER_ARI_MOD; // Y = A % B $mod
if ( !strcmp(pType, "$pow") ) return ABC_OPER_ARI_POW; // Y = A ** B $pow
*/
if ( Type == ABC_OPER_ARI_ADD || Type == ABC_OPER_ARI_SUB )
{
//Vec_IntPrint( vArg0 );
//Vec_IntPrint( vArg1 );
Vec_IntAppend( vRes, vArg0 );
if ( Type == ABC_OPER_ARI_ADD )
Wlc_BlastAdder( pNew, Vec_IntArray(vRes), Vec_IntArray(vArg1), nRangeMax, 0 ); // result is in pFan0 (vRes)
else
Wlc_BlastSubtract( pNew, Vec_IntArray(vRes), Vec_IntArray(vArg1), nRangeMax, 1 ); // result is in pFan0 (vRes)
Vec_IntShrink( vRes, nRange );
return;
}
if ( Type == ABC_OPER_ARI_MUL )
{
int fBooth = 1;
int fCla = 0;
int fSigned = fSign0 && fSign1;
Vec_IntShrink( vArg0, nSizeArg0 );
Vec_IntShrink( vArg1, nSizeArg1 );
if ( Wlc_NtkCountConstBits(Vec_IntArray(vArg0), Vec_IntSize(vArg0)) < Wlc_NtkCountConstBits(Vec_IntArray(vArg1), Vec_IntSize(vArg1)) )
ABC_SWAP( Vec_Int_t, *vArg0, *vArg1 )
if ( fBooth )
Wlc_BlastBooth( pNew, Vec_IntArray(vArg0), Vec_IntArray(vArg1), Vec_IntSize(vArg0), Vec_IntSize(vArg1), vRes, fSigned, fCla, NULL );
else
Wlc_BlastMultiplier3( pNew, Vec_IntArray(vArg0), Vec_IntArray(vArg1), Vec_IntSize(vArg0), Vec_IntSize(vArg1), vRes, fSigned, fCla, NULL );
if ( nRange > Vec_IntSize(vRes) )
Vec_IntFillExtra( vRes, nRange, fSigned ? Vec_IntEntryLast(vRes) : 0 );
else
Vec_IntShrink( vRes, nRange );
assert( Vec_IntSize(vRes) == nRange );
return;
}
if ( Type == ABC_OPER_ARI_DIV || Type == ABC_OPER_ARI_MOD )
{
int fDivBy0 = 1; // correct with 1
int fSigned = fSign0 && fSign1;
if ( fSigned )
Wlc_BlastDividerSigned( pNew, Vec_IntArray(vArg0), nRangeMax, Vec_IntArray(vArg1), nRangeMax, Type == ABC_OPER_ARI_DIV, vRes );
else
Wlc_BlastDivider( pNew, Vec_IntArray(vArg0), nRangeMax, Vec_IntArray(vArg1), nRangeMax, Type == ABC_OPER_ARI_DIV, vRes );
Vec_IntShrink( vRes, nRange );
if ( !fDivBy0 )
Wlc_BlastZeroCondition( pNew, Vec_IntArray(vArg1), nRange, vRes );
return;
}
if ( Type == ABC_OPER_ARI_POW )
{
Vec_Int_t * vTemp = vDatas+4;
Vec_IntGrow( vTemp, nRangeMax );
Vec_IntGrow( vRes, nRangeMax );
Vec_IntShrink( vArg1, nSizeArg1 );
Wlc_BlastPower( pNew, Vec_IntArray(vArg0), nRangeMax, Vec_IntArray(vArg1), Vec_IntSize(vArg1), vTemp, vRes );
Vec_IntShrink( vRes, nRange );
return;
}
}
if ( nIns == 3 )
{
if ( Type == ABC_OPER_SEL_NMUX ) // $mux
{
Vec_Int_t * vArg0 = vDatas;
Vec_Int_t * vArg1 = vDatas+1;
Vec_Int_t * vArgS = vDatas+2;
Vec_Int_t * vRes = vDatas+3;
int iCtrl = Vec_IntEntry(vArgS, 0);
//Vec_IntPrint( vArg0 );
//Vec_IntPrint( vArg1 );
//Vec_IntPrint( vArgS );
assert( Vec_IntSize(vArg0) == Vec_IntSize(vArg1) );
assert( Vec_IntSize(vArg0) == nRange );
assert( Vec_IntSize(vArgS) == 1 );
assert( Vec_IntSize(vRes) == 0 );
Vec_IntForEachEntryTwo( vArg0, vArg1, iLit0, iLit1, k )
Vec_IntPush( vRes, Gia_ManHashMux(pNew, iCtrl, iLit1, iLit0) );
return;
}
if ( Type == ABC_OPER_SEL_SEL ) // $pmux
{
int i, k, iLit;
Vec_Int_t * vArgA = vDatas;
Vec_Int_t * vArgB = vDatas+1;
Vec_Int_t * vArgS = vDatas+2;
Vec_Int_t * vRes = vDatas+3;
Vec_Int_t * vTemp = vDatas+4;
assert( Vec_IntSize(vArgA) == nRange ); // widthA = widthY
assert( Vec_IntSize(vArgB) == Vec_IntSize(vArgA)*Vec_IntSize(vArgS) ); // widthB == widthA*widthS
assert( Vec_IntSize(vRes) == 0 );
for ( i = 0; i < nRange; i++ )
{
int iCond = 1;
Vec_IntClear( vTemp );
Vec_IntForEachEntry( vArgS, iLit, k ) // iLit = S[i]
{
//Vec_IntPush( vTemp, Abc_LitNot( Gia_ManHashAnd(pNew, iLit, Vec_IntEntry(vArgB, nRange*(Vec_IntSize(vArgS)-1-k)+i)) ) ); // B[widthA*k+i]
Vec_IntPush( vTemp, Abc_LitNot( Gia_ManHashAnd(pNew, iLit, Vec_IntEntry(vArgB, nRange*k+i)) ) ); // B[widthA*k+i]
iCond = Gia_ManHashAnd( pNew, iCond, Abc_LitNot(iLit) );
}
Vec_IntPush( vTemp, Abc_LitNot( Gia_ManHashAnd(pNew, iCond, Vec_IntEntry(vArgA, i)) ) );
Vec_IntPush( vRes, Abc_LitNot( Gia_ManHashAndMulti(pNew, vTemp) ) );
}
return;
}
}
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END

532
src/base/wln/wlnCom.c Normal file
View File

@ -0,0 +1,532 @@
/**CFile****************************************************************
FileName [wlnCom.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Word-level network.]
Synopsis []
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - September 23, 2018.]
Revision [$Id: wlnCom.c,v 1.00 2018/09/23 00:00:00 alanmi Exp $]
***********************************************************************/
#include "wln.h"
#include "base/main/mainInt.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
static int Abc_CommandYosys ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandGraft ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandHierarchy ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandCollapse ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandSolve ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandPrint ( Abc_Frame_t * pAbc, int argc, char ** argv );
static inline Rtl_Lib_t * Wln_AbcGetRtl( Abc_Frame_t * pAbc ) { return (Rtl_Lib_t *)pAbc->pAbcRtl; }
static inline void Wln_AbcFreeRtl( Abc_Frame_t * pAbc ) { if ( pAbc->pAbcRtl ) Rtl_LibFree(Wln_AbcGetRtl(pAbc)); }
static inline void Wln_AbcUpdateRtl( Abc_Frame_t * pAbc, Rtl_Lib_t * pLib ) { Wln_AbcFreeRtl(pAbc); pAbc->pAbcRtl = pLib; }
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Wln_Init( Abc_Frame_t * pAbc )
{
Cmd_CommandAdd( pAbc, "Word level", "%yosys", Abc_CommandYosys, 0 );
Cmd_CommandAdd( pAbc, "Word level", "%graft", Abc_CommandGraft, 0 );
Cmd_CommandAdd( pAbc, "Word level", "%hierarchy", Abc_CommandHierarchy, 0 );
Cmd_CommandAdd( pAbc, "Word level", "%collapse", Abc_CommandCollapse, 0 );
//Cmd_CommandAdd( pAbc, "Word level", "%solve", Abc_CommandSolve, 0 );
Cmd_CommandAdd( pAbc, "Word level", "%print", Abc_CommandPrint, 0 );
}
/**Function********************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
******************************************************************************/
void Wln_End( Abc_Frame_t * pAbc )
{
Wln_AbcUpdateRtl( pAbc, NULL );
}
/**Function********************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
******************************************************************************/
int Abc_CommandYosys( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern Gia_Man_t * Wln_BlastSystemVerilog( char * pFileName, char * pTopModule, int fSkipStrash, int fInvert, int fTechMap, int fVerbose );
extern Rtl_Lib_t * Wln_ReadSystemVerilog( char * pFileName, char * pTopModule, int fCollapse, int fVerbose );
FILE * pFile;
char * pFileName = NULL;
char * pTopModule= NULL;
int fBlast = 0;
int fInvert = 0;
int fTechMap = 1;
int fSkipStrash = 0;
int fCollapse = 0;
int c, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "Tbismcvh" ) ) != EOF )
{
switch ( c )
{
case 'T':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-T\" should be followed by a file name.\n" );
goto usage;
}
pTopModule = argv[globalUtilOptind];
globalUtilOptind++;
break;
case 'b':
fBlast ^= 1;
break;
case 'i':
fInvert ^= 1;
break;
case 's':
fSkipStrash ^= 1;
break;
case 'm':
fTechMap ^= 1;
break;
case 'c':
fCollapse ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
if ( argc != globalUtilOptind + 1 )
{
printf( "Abc_CommandReadWlc(): Input file name should be given on the command line.\n" );
return 0;
}
// get the file name
pFileName = argv[globalUtilOptind];
if ( (pFile = fopen( pFileName, "r" )) == NULL )
{
Abc_Print( 1, "Cannot open input file \"%s\". ", pFileName );
if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".v", ".sv", NULL, NULL, NULL )) )
Abc_Print( 1, "Did you mean \"%s\"?", pFileName );
Abc_Print( 1, "\n" );
return 0;
}
fclose( pFile );
// perform reading
if ( fBlast )
{
Gia_Man_t * pNew = NULL;
if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) )
pNew = Wln_BlastSystemVerilog( pFileName, pTopModule, fSkipStrash, fInvert, fTechMap, fVerbose );
else if ( !strcmp( Extra_FileNameExtension(pFileName), "sv" ) )
pNew = Wln_BlastSystemVerilog( pFileName, pTopModule, fSkipStrash, fInvert, fTechMap, fVerbose );
else if ( !strcmp( Extra_FileNameExtension(pFileName), "rtlil" ) )
pNew = Wln_BlastSystemVerilog( pFileName, pTopModule, fSkipStrash, fInvert, fTechMap, fVerbose );
else
{
printf( "Abc_CommandYosys(): Unknown file extension.\n" );
return 0;
}
Abc_FrameUpdateGia( pAbc, pNew );
}
else
{
Rtl_Lib_t * pLib = NULL;
if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) )
pLib = Wln_ReadSystemVerilog( pFileName, pTopModule, fCollapse, fVerbose );
else if ( !strcmp( Extra_FileNameExtension(pFileName), "sv" ) )
pLib = Wln_ReadSystemVerilog( pFileName, pTopModule, fCollapse, fVerbose );
else if ( !strcmp( Extra_FileNameExtension(pFileName), "rtlil" ) )
pLib = Wln_ReadSystemVerilog( pFileName, pTopModule, fCollapse, fVerbose );
else
{
printf( "Abc_CommandYosys(): Unknown file extension.\n" );
return 0;
}
Wln_AbcUpdateRtl( pAbc, pLib );
}
return 0;
usage:
Abc_Print( -2, "usage: %%yosys [-T <module>] [-bismcvh] <file_name>\n" );
Abc_Print( -2, "\t reads Verilog or SystemVerilog using Yosys\n" );
Abc_Print( -2, "\t-T : specify the top module name (default uses \"-auto-top\"\n" );
Abc_Print( -2, "\t-b : toggle bit-blasting the design into an AIG using Yosys [default = %s]\n", fBlast? "yes": "no" );
Abc_Print( -2, "\t-i : toggle interting the outputs (useful for miters) [default = %s]\n", fInvert? "yes": "no" );
Abc_Print( -2, "\t-s : toggle no structural hashing during bit-blasting [default = %s]\n", fSkipStrash? "no strash": "strash" );
Abc_Print( -2, "\t-m : toggle using \"techmap\" to blast operators [default = %s]\n", fTechMap? "yes": "no" );
Abc_Print( -2, "\t-c : toggle collapsing design hierarchy using Yosys [default = %s]\n", fCollapse? "yes": "no" );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
}
/**Function********************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
******************************************************************************/
int Abc_CommandGraft( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern void Wln_LibGraftOne( Rtl_Lib_t * p, char ** pModules, int nModules, int fInv, int fVerbose );
Rtl_Lib_t * pLib = Wln_AbcGetRtl(pAbc);
char ** pArgvNew; int nArgcNew;
int c, fInv = 0, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "ivh" ) ) != EOF )
{
switch ( c )
{
case 'i':
fInv ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
if ( pLib == NULL )
{
printf( "The design is not entered.\n" );
return 1;
}
pArgvNew = argv + globalUtilOptind;
nArgcNew = argc - globalUtilOptind;
if ( nArgcNew != 0 && nArgcNew != 2 )
{
Abc_Print( -1, "Abc_CommandGraft(): This command expects one AIG file name on the command line.\n" );
return 1;
}
Wln_LibGraftOne( pLib, pArgvNew, nArgcNew, fInv, fVerbose );
return 0;
usage:
Abc_Print( -2, "usage: %%graft [-ivh] <module1_name> <module2_name>\n" );
Abc_Print( -2, "\t replace instances of module1 by those of module2\n" );
Abc_Print( -2, "\t-i : toggle using inverse grafting [default = %s]\n", fInv? "yes": "no" );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
}
/**Function********************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
******************************************************************************/
int Abc_CommandHierarchy( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern void Wln_LibMarkHierarchy( Rtl_Lib_t * p, char ** ppModule, int nModules, int fVerbose );
Rtl_Lib_t * pLib = Wln_AbcGetRtl(pAbc);
char ** pArgvNew; int nArgcNew;
int c, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
{
switch ( c )
{
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
if ( pLib == NULL )
{
printf( "The design is not entered.\n" );
return 1;
}
pArgvNew = argv + globalUtilOptind;
nArgcNew = argc - globalUtilOptind;
if ( nArgcNew < 0 )
{
Abc_Print( -1, "Abc_CommandHierarchy(): This command expects one AIG file name on the command line.\n" );
return 1;
}
Wln_LibMarkHierarchy( pLib, pArgvNew, nArgcNew, fVerbose );
return 0;
usage:
Abc_Print( -2, "usage: %%hierarchy [-vh] <module_name>\n" );
Abc_Print( -2, "\t marks the module whose instances may later be treated as black boxes\n" );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
}
/**Function********************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
******************************************************************************/
int Abc_CommandCollapse( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern Gia_Man_t * Rtl_LibCollapse( Rtl_Lib_t * p, char * pTopModule, int fVerbose );
Gia_Man_t * pNew = NULL;
Rtl_Lib_t * pLib = Wln_AbcGetRtl(pAbc);
char * pTopModule = NULL;
int c, fInv = 0, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "Tcvh" ) ) != EOF )
{
switch ( c )
{
case 'T':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-T\" should be followed by a file name.\n" );
goto usage;
}
pTopModule = argv[globalUtilOptind];
globalUtilOptind++;
break;
case 'c':
fInv ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
if ( pLib == NULL )
{
printf( "The design is not entered.\n" );
return 1;
}
pNew = Rtl_LibCollapse( pLib, pTopModule, fVerbose );
if ( fInv )
Gia_ManInvertPos( pNew );
Abc_FrameUpdateGia( pAbc, pNew );
return 0;
usage:
Abc_Print( -2, "usage: %%collapse [-T <module>] [-cvh] <file_name>\n" );
Abc_Print( -2, "\t collapse hierarchical design into an AIG\n" );
Abc_Print( -2, "\t-T : specify the top module of the design [default = none]\n" );
Abc_Print( -2, "\t-c : toggle complementing miter outputs after collapsing [default = %s]\n", fInv? "yes": "no" );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
}
/**Function********************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
******************************************************************************/
int Abc_CommandPrint( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern void Rtl_LibPrintStats( Rtl_Lib_t * p );
extern void Rtl_LibPrintHieStats( Rtl_Lib_t * p );
extern void Rtl_LibPrint( char * pFileName, Rtl_Lib_t * p );
Rtl_Lib_t * pLib = Wln_AbcGetRtl(pAbc);
int c, fHie = 0, fDesign = 0, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "pdvh" ) ) != EOF )
{
switch ( c )
{
case 'p':
fHie ^= 1;
break;
case 'd':
fDesign ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
if ( pLib == NULL )
{
printf( "The design is not entered.\n" );
return 1;
}
Rtl_LibPrintStats( pLib );
if ( fHie )
Rtl_LibPrintHieStats( pLib );
if ( fDesign )
Rtl_LibPrint( NULL, pLib );
return 0;
usage:
Abc_Print( -2, "usage: %%print [-pdvh]\n" );
Abc_Print( -2, "\t print statistics about the hierarchical design\n" );
Abc_Print( -2, "\t-p : toggle printing of the hierarchy [default = %s]\n", fHie? "yes": "no" );
Abc_Print( -2, "\t-d : toggle printing of the design [default = %s]\n", fDesign? "yes": "no" );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
Abc_Print( -2, "\t<file> : text file name with guidance for solving\n");
return 1;
}
/**Function********************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
******************************************************************************/
int Abc_CommandSolve( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern void Rtl_LibBlast( Rtl_Lib_t * pLib );
extern void Rtl_LibBlast2( Rtl_Lib_t * pLib, Vec_Int_t * vRoots, int fInv );
extern void Rtl_LibSolve( Rtl_Lib_t * pLib, void * pNtk );
extern void Rtl_LibPreprocess( Rtl_Lib_t * pLib );
extern void Wln_SolveWithGuidance( char * pFileName, Rtl_Lib_t * p );
Rtl_Lib_t * pLib = Wln_AbcGetRtl(pAbc);
int c, fOldBlast = 0, fPrepro = 0, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "opvh" ) ) != EOF )
{
switch ( c )
{
case 'o':
fOldBlast ^= 1;
break;
case 'p':
fPrepro ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
if ( pLib == NULL )
{
printf( "The design is not entered.\n" );
return 1;
}
if ( argc == globalUtilOptind + 1 )
{
char * pFileName = argv[globalUtilOptind];
FILE * pFile = fopen( pFileName, "r" );
if ( pFile == NULL )
{
Abc_Print( -1, "Cannot open file \"%s\" with the input test patterns.\n", pFileName );
return 0;
}
fclose( pFile );
printf( "Using guidance from file \"%s\".\n", pFileName );
Wln_SolveWithGuidance( pFileName, pLib );
}
else
{
printf( "Solving the miter without guidance.\n" );
if ( fOldBlast )
Rtl_LibBlast( pLib );
else
Rtl_LibBlast2( pLib, NULL, 0 );
if ( fPrepro )
Rtl_LibPreprocess( pLib );
Rtl_LibSolve( pLib, NULL );
}
return 0;
usage:
Abc_Print( -2, "usage: %%solve [-opvh] <file>\n" );
Abc_Print( -2, "\t solving properties for the hierarchical design\n" );
Abc_Print( -2, "\t-o : toggle using old bit-blasting procedure [default = %s]\n", fOldBlast? "yes": "no" );
Abc_Print( -2, "\t-p : toggle preprocessing for verification [default = %s]\n", fPrepro? "yes": "no" );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
Abc_Print( -2, "\t<file> : text file name with guidance for solving\n");
return 1;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END

95
src/base/wln/wlnGuide.c Normal file
View File

@ -0,0 +1,95 @@
/**CFile****************************************************************
FileName [wln.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Word-level network.]
Synopsis []
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - September 23, 2018.]
Revision [$Id: wln.c,v 1.00 2018/09/23 00:00:00 alanmi Exp $]
***********************************************************************/
#include "wln.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Wln_ReadFindToken( char * pToken, Abc_Nam_t * p )
{
char * pBuffer = Abc_UtilStrsavTwo( "\\", pToken );
int RetValue = Abc_NamStrFindOrAdd( p, pBuffer, NULL );
ABC_FREE( pBuffer );
return RetValue;
}
void Wln_PrintGuidance( Vec_Wec_t * vGuide, Abc_Nam_t * p )
{
Vec_Int_t * vLevel; int i, k, Obj;
Vec_WecForEachLevel( vGuide, vLevel, i )
{
Vec_IntForEachEntry( vLevel, Obj, k )
printf( "%s ", Obj >= 0 ? Abc_NamStr(p, Obj) : "[unknown]" );
printf( "\n" );
}
}
Vec_Wec_t * Wln_ReadGuidance( char * pFileName, Abc_Nam_t * p )
{
char * pBuffer = ABC_CALLOC( char, 10000 ), * pToken;
Vec_Wec_t * vTokens = Vec_WecAlloc( 100 ); Vec_Int_t * vLevel;
FILE * pFile = fopen( pFileName, "rb" );
while ( fgets( pBuffer, 10000, pFile ) )
{
if ( pBuffer[0] == '#' )
continue;
vLevel = Vec_WecPushLevel( vTokens );
pToken = strtok( pBuffer, " \t\r\n" );
while ( pToken )
{
Vec_IntPush( vLevel, Vec_IntSize(vLevel) < 2 ? Abc_NamStrFindOrAdd(p, pToken, NULL) : Wln_ReadFindToken(pToken, p) );
pToken = strtok( NULL, " \t\r\n" );
}
if ( Vec_IntSize(vLevel) % 4 == 3 ) // account for "property"
Vec_IntPush( vLevel, -1 );
assert( Vec_IntSize(vLevel) % 4 == 0 );
}
fclose( pFile );
if ( Vec_WecSize(vTokens) == 0 )
printf( "Guidance is empty.\n" );
//Wln_PrintGuidance( vTokens, p );
ABC_FREE( pBuffer );
return vTokens;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END

2866
src/base/wln/wlnRead.c Normal file

File diff suppressed because it is too large Load Diff

211
src/base/wln/wlnRtl.c Normal file
View File

@ -0,0 +1,211 @@
/**CFile****************************************************************
FileName [wlnRtl.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Word-level network.]
Synopsis [Constructing WLN network from Rtl data structure.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - September 23, 2018.]
Revision [$Id: wlnRtl.c,v 1.00 2018/09/23 00:00:00 alanmi Exp $]
***********************************************************************/
#include "wln.h"
#include "base/main/main.h"
#ifdef WIN32
#include <process.h>
#define unlink _unlink
#else
#include <unistd.h>
#endif
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
#define MAX_LINE 1000000
void Rtl_NtkCleanFile( char * pFileName )
{
char * pBuffer, * pFileName2 = "_temp__.rtlil";
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, "attribute \\src") )
fputs( pBuffer, pFile2 );
ABC_FREE( pBuffer );
fclose( pFile );
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;
char * pYosysNameWin = "yosys.exe";
char * pYosysNameUnix = "yosys";
if ( Abc_FrameReadFlag("yosyswin") )
pYosysNameWin = Abc_FrameReadFlag("yosyswin");
if ( Abc_FrameReadFlag("yosysunix") )
pYosysNameUnix = Abc_FrameReadFlag("yosysunix");
#ifdef WIN32
pYosysName = pYosysNameWin;
#else
pYosysName = pYosysNameUnix;
#endif
return pYosysName;
}
int Wln_ConvertToRtl( char * pCommand, char * pFileTemp )
{
FILE * pFile;
if ( system( pCommand ) == -1 )
{
fprintf( stdout, "Cannot execute \"%s\".\n", pCommand );
return 0;
}
if ( (pFile = fopen(pFileTemp, "r")) == NULL )
{
fprintf( stdout, "Cannot open intermediate file \"%s\".\n", pFileTemp );
return 0;
}
fclose( pFile );
return 1;
}
Rtl_Lib_t * Wln_ReadSystemVerilog( char * pFileName, char * pTopModule, int fCollapse, int fVerbose )
{
Rtl_Lib_t * pNtk = NULL;
char Command[1000];
char * pFileTemp = "_temp_.rtlil";
int fSVlog = strstr(pFileName, ".sv") != NULL;
if ( strstr(pFileName, ".rtl") )
return Rtl_LibReadFile( pFileName, pFileName );
sprintf( Command, "%s -qp \"read_verilog %s%s; hierarchy %s%s; %sproc; write_rtlil %s\"",
Wln_GetYosysName(), fSVlog ? "-sv ":"", pFileName,
pTopModule ? "-top " : "",
pTopModule ? pTopModule : "",
fCollapse ? "flatten; " : "",
pFileTemp );
if ( fVerbose )
printf( "%s\n", Command );
if ( !Wln_ConvertToRtl(Command, pFileTemp) )
return NULL;
pNtk = Rtl_LibReadFile( pFileTemp, pFileName );
if ( pNtk == NULL )
{
printf( "Dumped the design into file \"%s\".\n", pFileTemp );
return NULL;
}
Rtl_NtkCleanFile( pFileTemp );
unlink( pFileTemp );
return pNtk;
}
Gia_Man_t * Wln_BlastSystemVerilog( char * pFileName, char * pTopModule, int fSkipStrash, int fInvert, int fTechMap, int fVerbose )
{
Gia_Man_t * pGia = NULL;
char Command[1000];
char * pFileTemp = "_temp_.aig";
int fRtlil = strstr(pFileName, ".rtl") != NULL;
int fSVlog = strstr(pFileName, ".sv") != NULL;
sprintf( Command, "%s -qp \"%s%s%s; hierarchy %s%s; flatten; proc; %saigmap; write_aiger %s\"",
Wln_GetYosysName(),
fRtlil ? "read_rtlil" : "read_verilog",
fSVlog ? " -sv ":" ",
pFileName,
pTopModule ? "-top " : "-auto-top",
pTopModule ? pTopModule : "",
fTechMap ? "techmap; setundef -zero; " : "", pFileTemp );
if ( fVerbose )
printf( "%s\n", Command );
if ( !Wln_ConvertToRtl(Command, pFileTemp) )
return NULL;
pGia = Gia_AigerRead( pFileTemp, 0, fSkipStrash, 0 );
if ( pGia == NULL )
{
printf( "Converting to AIG has failed.\n" );
return NULL;
}
ABC_FREE( pGia->pName );
pGia->pName = pTopModule ? Abc_UtilStrsav(pTopModule) :
Extra_FileNameGeneric( Extra_FileNameWithoutPath(pFileName) );
unlink( pFileTemp );
// complement the outputs
if ( fInvert )
{
Gia_Obj_t * pObj; int i;
Gia_ManForEachPo( pGia, pObj, i )
Gia_ObjFlipFaninC0( pObj );
}
return pGia;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END

View File

@ -359,6 +359,22 @@ Cudd_addCmpl(
} /* end of Cudd_addCmpl */
#ifdef USE_CASH_DUMMY
/**Function********************************************************************
Synopsis We need to declare a function passed to cuddCacheLookup2 as a key
that can be casted to DD_CTFP.
******************************************************************************/
static DdNode *
Cudd_addLeq_dummy(DdManager * dd, DdNode * f, DdNode * g)
{
assert(0);
return 0;
}
#endif
/**Function********************************************************************
Synopsis [Determines whether f is less than or equal to g.]
@ -394,7 +410,11 @@ Cudd_addLeq(
if (g == DD_MINUS_INFINITY(dd)) return(0); /* since f != g */
/* Check cache. */
#ifdef USE_CASH_DUMMY
tmp = cuddCacheLookup2(dd,(DD_CTFP)Cudd_addLeq_dummy,f,g);
#else
tmp = cuddCacheLookup2(dd,(DD_CTFP)Cudd_addLeq,f,g);
#endif
if (tmp != NULL) {
return(tmp == DD_ONE(dd));
}
@ -416,8 +436,13 @@ Cudd_addLeq(
res = Cudd_addLeq(dd,fvn,gvn) && Cudd_addLeq(dd,fv,gv);
/* Store result in cache and return. */
#ifdef USE_CASH_DUMMY
cuddCacheInsert2(dd,(DD_CTFP) Cudd_addLeq_dummy,f,g,
Cudd_NotCond(DD_ONE(dd),res==0));
#else
cuddCacheInsert2(dd,(DD_CTFP) Cudd_addLeq,f,g,
Cudd_NotCond(DD_ONE(dd),res==0));
#endif
return(res);
} /* end of Cudd_addLeq */

View File

@ -226,6 +226,22 @@ cuddAddNegateRecur(
} /* end of cuddAddNegateRecur */
#ifdef USE_CASH_DUMMY
/**Function********************************************************************
Synopsis We need to declare a function passed to cuddCacheLookup1 that can
be casted to DD_CTFP.
******************************************************************************/
static DdNode *
Cudd_addRoundOff_dummy(DdManager * dd, DdNode * f)
{
assert(0);
return 0;
}
#endif
/**Function********************************************************************
Synopsis [Implements the recursive step of Cudd_addRoundOff.]
@ -253,7 +269,11 @@ cuddAddRoundOffRecur(
res = cuddUniqueConst(dd,n);
return(res);
}
#ifdef USE_CASH_DUMMY
cacheOp = (DD_CTFP1) Cudd_addRoundOff_dummy;
#else
cacheOp = (DD_CTFP1) Cudd_addRoundOff;
#endif
res = cuddCacheLookup1(dd,cacheOp,f);
if (res != NULL) {
return(res);

View File

@ -266,6 +266,21 @@ Cudd_bddBooleanDiff(
} /* end of Cudd_bddBooleanDiff */
#ifdef USE_CASH_DUMMY
/**Function********************************************************************
Synopsis We need to declare a function passed to cuddCacheLookup2 that can
be casted to DD_CTFP.
******************************************************************************/
static DdNode *
Cudd_bddVarIsDependent_dummy(DdManager *dd, DdNode *f, DdNode *var)
{
assert(0);
return 0;
}
#endif
/**Function********************************************************************
Synopsis [Checks whether a variable is dependent on others in a
@ -305,7 +320,11 @@ Cudd_bddVarIsDependent(
return(0);
}
#ifdef USE_CASH_DUMMY
cacheOp = (DD_CTFP) Cudd_bddVarIsDependent_dummy;
#else
cacheOp = (DD_CTFP) Cudd_bddVarIsDependent;
#endif
res = cuddCacheLookup2(dd,cacheOp,f,var);
if (res != NULL) {
return(res != zero);

View File

@ -520,6 +520,22 @@ Cudd_bddXnor(
} /* end of Cudd_bddXnor */
#ifdef USE_CASH_DUMMY
/**Function********************************************************************
Synopsis We need to declare a function passed to cuddCacheLookup2 that can
be casted to DD_CTFP.
******************************************************************************/
static DdNode *
Cudd_bddLeq_dummy(DdManager * dd, DdNode * f, DdNode * g)
{
assert(0);
return 0;
}
#endif
/**Function********************************************************************
Synopsis [Determines whether f is less than or equal to g.]
@ -573,7 +589,11 @@ Cudd_bddLeq(
/* Here neither f nor g is constant. */
/* Check cache. */
#ifdef USE_CASH_DUMMY
tmp = cuddCacheLookup2(dd,(DD_CTFP)Cudd_bddLeq_dummy,f,g);
#else
tmp = cuddCacheLookup2(dd,(DD_CTFP)Cudd_bddLeq,f,g);
#endif
if (tmp != NULL) {
return(tmp == one);
}
@ -605,7 +625,11 @@ Cudd_bddLeq(
res = Cudd_bddLeq(dd,fvn,gvn) && Cudd_bddLeq(dd,fv,gv);
/* Store result in cache and return. */
#ifdef USE_CASH_DUMMY
cuddCacheInsert2(dd,(DD_CTFP)Cudd_bddLeq_dummy,f,g,(res ? one : zero));
#else
cuddCacheInsert2(dd,(DD_CTFP)Cudd_bddLeq,f,g,(res ? one : zero));
#endif
return(res);
} /* end of Cudd_bddLeq */

View File

@ -250,6 +250,34 @@ cuddBddClippingAndAbstract(
/*---------------------------------------------------------------------------*/
/* Definition of static functions */
/*---------------------------------------------------------------------------*/
#ifdef USE_CASH_DUMMY
/**Function********************************************************************
Synopsis We need to declare a function passed to cuddCacheLookup2 that can
be casted to DD_CTFP.
******************************************************************************/
static DdNode *
Cudd_bddClippingAnd_dummy(DdManager *dd, DdNode *f, DdNode *g)
{
assert(0);
return 0;
}
/**Function********************************************************************
Synopsis We need to declare a function passed to cuddCacheLookup2 that can
be casted to DD_CTFP.
******************************************************************************/
static DdNode *
cuddBddClippingAnd_dummy(DdManager *dd, DdNode *f, DdNode *g)
{
assert(0);
return 0;
}
#endif
/**Function********************************************************************
@ -309,8 +337,12 @@ cuddBddClippingAndRecur(
}
F = Cudd_Regular(f);
G = Cudd_Regular(g);
#ifdef USE_CASH_DUMMY
cacheOp = (DD_CTFP) (direction ? Cudd_bddClippingAnd_dummy : cuddBddClippingAnd_dummy);
#else
cacheOp = (DD_CTFP)
(direction ? Cudd_bddClippingAnd : cuddBddClippingAnd);
#endif
if (F->ref != 1 || G->ref != 1) {
r = cuddCacheLookup2(manager, cacheOp, f, g);
if (r != NULL) return(r);

View File

@ -319,6 +319,23 @@ Cudd_addOuterSum(
/* Definition of static functions */
/*---------------------------------------------------------------------------*/
#ifdef USE_CASH_DUMMY
/**Function********************************************************************
Synopsis We need to declare a function passed to cuddCacheLookup2 that can
be casted to DD_CTFP.
******************************************************************************/
static DdNode *
addMMRecur_dummy(DdManager * dd, DdNode * A, DdNode * B)
{
assert(0);
return 0;
}
#endif
/**Function********************************************************************
Synopsis [Performs the recursive step of Cudd_addMatrixMultiply.]
@ -393,7 +410,11 @@ addMMRecur(
topA = cuddI(dd,A->index); topB = cuddI(dd,B->index);
topV = ddMin(topA,topB);
#ifdef USE_CASH_DUMMY
cacheOp = (DD_CTFP) addMMRecur_dummy;
#else
cacheOp = (DD_CTFP) addMMRecur;
#endif
res = cuddCacheLookup2(dd,cacheOp,A,B);
if (res != NULL) {
/* If the result is 0, there is no need to normalize.

View File

@ -1571,6 +1571,22 @@ cuddCProjectionRecur(
} /* end of cuddCProjectionRecur */
#ifdef USE_CASH_DUMMY
/**Function********************************************************************
Synopsis We need to declare a function passed to cuddCacheLookup2 that can
be casted to DD_CTFP.
******************************************************************************/
DdNode *
Cudd_bddClosestCube_dummy(DdManager *dd, DdNode *f, DdNode *g)
{
assert(0);
return 0;
}
#endif
/**Function********************************************************************
Synopsis [Performs the recursive step of Cudd_bddClosestCube.]
@ -1667,7 +1683,11 @@ cuddBddClosestCube(
F = Cudd_Regular(f);
G = Cudd_Regular(g);
if (F->ref != 1 || G->ref != 1) {
#ifdef USE_CASH_DUMMY
res = cuddCacheLookup2(dd,(DD_CTFP) Cudd_bddClosestCube_dummy, f, g);
#else
res = cuddCacheLookup2(dd,(DD_CTFP) Cudd_bddClosestCube, f, g);
#endif
if (res != NULL) return(res);
}
@ -1817,7 +1837,11 @@ cuddBddClosestCube(
/* Only cache results that are different from azero to avoid
** storing results that depend on the value of the bound. */
if ((F->ref != 1 || G->ref != 1) && res != azero)
#ifdef USE_CASH_DUMMY
cuddCacheInsert2(dd,(DD_CTFP) Cudd_bddClosestCube_dummy, f, g, res);
#else
cuddCacheInsert2(dd,(DD_CTFP) Cudd_bddClosestCube, f, g, res);
#endif
cuddDeref(res);
return(res);

View File

@ -390,6 +390,22 @@ Cudd_ShortestLength(
} /* end of Cudd_ShortestLength */
#ifdef USE_CASH_DUMMY
/**Function********************************************************************
Synopsis We need to declare a function passed to cuddCacheLookup2 that can
be casted to DD_CTFP.
******************************************************************************/
static DdNode *
Cudd_Decreasing_dummy(DdManager * dd, DdNode * f, DdNode * g)
{
assert(0);
return 0;
}
#endif
/**Function********************************************************************
Synopsis [Determines whether a BDD is negative unate in a
@ -434,7 +450,11 @@ Cudd_Decreasing(
/* From now on, f is not constant. */
/* Check cache. */
#ifdef USE_CASH_DUMMY
cacheOp = (DD_CTFP) Cudd_Decreasing_dummy;
#else
cacheOp = (DD_CTFP) Cudd_Decreasing;
#endif
res = cuddCacheLookup2(dd,cacheOp,f,dd->vars[i]);
if (res != NULL) {
return(res);
@ -768,6 +788,22 @@ Cudd_bddLeqUnless(
} /* end of Cudd_bddLeqUnless */
#ifdef USE_CASH_DUMMY
/**Function********************************************************************
Synopsis We need to declare a function passed to cuddCacheLookup2 that can
be casted to DD_CTFP.
******************************************************************************/
static DdNode *
Cudd_EqualSupNorm_dummy(DdManager * dd, DdNode * f, DdNode * g)
{
assert(0);
return 0;
}
#endif
/**Function********************************************************************
Synopsis [Compares two ADDs for equality within tolerance.]
@ -817,7 +853,11 @@ Cudd_EqualSupNorm(
/* We only insert the result in the cache if the comparison is
** successful. Therefore, if we hit we return 1. */
#ifdef USE_CASH_DUMMY
r = cuddCacheLookup2(dd,(DD_CTFP)Cudd_EqualSupNorm_dummy,f,g);
#else
r = cuddCacheLookup2(dd,(DD_CTFP)Cudd_EqualSupNorm,f,g);
#endif
if (r != NULL) {
return(1);
}
@ -832,7 +872,11 @@ Cudd_EqualSupNorm(
if (!Cudd_EqualSupNorm(dd,fv,gv,tolerance,pr)) return(0);
if (!Cudd_EqualSupNorm(dd,fvn,gvn,tolerance,pr)) return(0);
#ifdef USE_CASH_DUMMY
cuddCacheInsert2(dd,(DD_CTFP)Cudd_EqualSupNorm_dummy,f,g,DD_ONE(dd));
#else
cuddCacheInsert2(dd,(DD_CTFP)Cudd_EqualSupNorm,f,g,DD_ONE(dd));
#endif
return(1);

View File

@ -219,6 +219,22 @@ Cudd_MakeBddFromZddCover(
/*---------------------------------------------------------------------------*/
#ifdef USE_CASH_DUMMY
/**Function********************************************************************
Synopsis We need to declare a function passed to cuddCacheLookup2 that can
be casted to DD_CTFP.
******************************************************************************/
static DdNode *
cuddZddIsop_dummy(DdManager * dd, DdNode * L, DdNode * U)
{
assert(0);
return 0;
}
#endif
/**Function********************************************************************
Synopsis [Performs the recursive step of Cudd_zddIsop.]
@ -273,7 +289,11 @@ cuddZddIsop(
** Hence we need a double hit in the cache to terminate the
** recursion. Clearly, collisions may evict only one of the two
** results. */
#ifdef USE_CASH_DUMMY
cacheOp = (DD_CTFP) cuddZddIsop_dummy;
#else
cacheOp = (DD_CTFP) cuddZddIsop;
#endif
r = cuddCacheLookup2(dd, cuddBddIsop, L, U);
if (r) {
*zdd_I = cuddCacheLookup2Zdd(dd, cacheOp, L, U);

View File

@ -237,20 +237,21 @@ int Dec_GraphToNetworkCount( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int NodeMa
SeeAlso []
***********************************************************************/
void Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain )
int Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain )
{
extern Abc_Obj_t * Dec_GraphToNetwork( Abc_Ntk_t * pNtk, Dec_Graph_t * pGraph );
Abc_Obj_t * pRootNew;
Abc_Ntk_t * pNtk = pRoot->pNtk;
int nNodesNew, nNodesOld;
int nNodesNew, nNodesOld, RetValue;
nNodesOld = Abc_NtkNodeNum(pNtk);
// create the new structure of nodes
pRootNew = Dec_GraphToNetwork( pNtk, pGraph );
// remove the old nodes
Abc_AigReplace( (Abc_Aig_t *)pNtk->pManFunc, pRoot, pRootNew, fUpdateLevel );
RetValue = Abc_AigReplace( (Abc_Aig_t *)pNtk->pManFunc, pRoot, pRootNew, fUpdateLevel );
// compare the gains
nNodesNew = Abc_NtkNodeNum(pNtk);
//assert( nGain <= nNodesOld - nNodesNew );
return RetValue;
}

View File

@ -2497,7 +2497,7 @@ void Kit_DsdVerify( Kit_DsdNtk_t * pNtk, unsigned * pTruth, int nVars )
p = Kit_DsdManAlloc( nVars, Kit_DsdNtkObjNum(pNtk)+2 );
pTruthC = Kit_DsdTruthCompute( p, pNtk );
if ( !Extra_TruthIsEqual( pTruth, pTruthC, nVars ) )
printf( "Verification failed.\n" );
printf( "Verification failed for gate with %d inputs.\n", nVars );
Kit_DsdManFree( p );
}

View File

@ -126,41 +126,52 @@ void Amap_RemoveComments( char * pBuffer, int * pnDots, int * pnLines )
// (in the BLIF file, comments are lines starting with "#")
nDots = nLines = 0;
for ( pCur = pBuffer; *pCur; pCur++ )
{
{
// if this is the beginning of comment
// clean it with spaces until the new line statement
if ( *pCur == '#' )
while ( *pCur != '\n' )
*pCur++ = ' ';
if ( *pCur == '#' ) {
while ( *pCur != '\n' ) {
*pCur++ = ' ';
}
}
// count the number of new lines and dots
if ( *pCur == '\n' ) {
if (*(pCur-1)=='\r') {
// DOS(R) file support
if (*(pCur-2)!='\\') nLines++;
else {
// rewind to backslash and overwrite with a space
*(pCur-2) = ' ';
*(pCur-1) = ' ';
*pCur = ' ';
if (pCur > pBuffer) {
if (*(pCur - 1) == '\r') {
// DOS(R) file support
if (pCur > (pBuffer + 1)) {
if (*(pCur - 2)!='\\') {
nLines++;
}
else {
// rewind to backslash and overwrite with a space
*(pCur - 2) = ' ';
*(pCur - 1) = ' ';
*pCur = ' ';
}
}
} else {
// UNIX(TM) file support
if (*(pCur - 1) != '\\') {
nLines++;
}
else {
// rewind to backslash and overwrite with a space
*(pCur-1) = ' ';
*pCur = ' ';
}
}
}
}
} else {
// UNIX(TM) file support
if (*(pCur-1)!='\\') nLines++;
else {
// rewind to backslash and overwrite with a space
*(pCur-1) = ' ';
*pCur = ' ';
else if ( *pCur == '.' ) {
nDots++;
}
}
}
else if ( *pCur == '.' )
nDots++;
}
}
if ( pnDots )
*pnDots = nDots;
*pnDots = nDots;
if ( pnLines )
*pnLines = nLines;
*pnLines = nLines;
}
/**Function*************************************************************
@ -491,4 +502,3 @@ Amap_Lib_t * Amap_LibReadFile( char * pFileName, int fVerbose )
ABC_NAMESPACE_IMPL_END

View File

@ -278,15 +278,14 @@ Abc_Lit2Var(iFan2), (Abc_LitIsCompl(iFan2)?'-':'+') );
int ** Amap_LibLookupTableAlloc( Vec_Ptr_t * vVec, int fVerbose )
{
Vec_Int_t * vOne;
int ** pRes, * pBuffer;
int ** pRes;
int i, k, nTotal, nSize, nEntries, Value;
// count the total size
nEntries = nSize = Vec_PtrSize( vVec );
Vec_PtrForEachEntry( Vec_Int_t *, vVec, vOne, i )
nEntries += Vec_IntSize(vOne);
pBuffer = ABC_ALLOC( int, nSize * sizeof(void *) + nEntries );
pRes = (int **)pBuffer;
pRes[0] = pBuffer + nSize * sizeof(void *);
pRes = (int **)ABC_ALLOC( char, nSize * sizeof(void *) + nEntries * sizeof(int) );
pRes[0] = (int *)((char *)pRes + nSize * sizeof(void *));
nTotal = 0;
Vec_PtrForEachEntry( Vec_Int_t *, vVec, vOne, i )
{

View File

@ -275,6 +275,8 @@ struct If_Man_t_
void * pUserMan;
Vec_Int_t * vDump;
int pDumpIns[16];
Vec_Str_t * vMarks;
Vec_Int_t * vVisited2;
// timing manager
Tim_Man_t * pManTim;
@ -564,7 +566,7 @@ extern If_DsdMan_t * If_DsdManAlloc( int nVars, int nLutSize );
extern void If_DsdManAllocIsops( If_DsdMan_t * p, int nLutSize );
extern void If_DsdManPrint( If_DsdMan_t * p, char * pFileName, int Number, int Support, int fOccurs, int fTtDump, int fVerbose );
extern void If_DsdManTune( If_DsdMan_t * p, int LutSize, int fFast, int fAdd, int fSpec, int fVerbose );
extern void Id_DsdManTuneStr( If_DsdMan_t * p, char * pStruct, int nConfls, int nProcs, int fVerbose );
extern void Id_DsdManTuneStr( If_DsdMan_t * p, char * pStruct, int nConfls, int nProcs, int nInputs, int fVerbose );
extern void If_DsdManFree( If_DsdMan_t * p, int fVerbose );
extern void If_DsdManSave( If_DsdMan_t * p, char * pFileName );
extern If_DsdMan_t * If_DsdManLoad( char * pFileName );

View File

@ -106,6 +106,8 @@ int If_ManPerformMappingComb( If_Man_t * p )
If_Obj_t * pObj;
abctime clkTotal = Abc_Clock();
int i;
//p->vVisited2 = Vec_IntAlloc( 100 );
//p->vMarks = Vec_StrStart( If_ManObjNum(p) );
// set arrival times and fanout estimates
If_ManForEachCi( p, pObj, i )

View File

@ -1494,6 +1494,68 @@ int If_CutCountTotalFanins( If_Man_t * p )
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int If_CutFilter2_rec( If_Man_t * p, If_Obj_t * pObj, int LevelMin )
{
char * pVisited = Vec_StrEntryP(p->vMarks, pObj->Id);
if ( *pVisited )
return *pVisited;
Vec_IntPush( p->vVisited2, pObj->Id );
if ( (int)pObj->Level <= LevelMin )
return (*pVisited = 1);
if ( If_CutFilter2_rec( p, pObj->pFanin0, LevelMin ) == 1 )
return (*pVisited = 1);
if ( If_CutFilter2_rec( p, pObj->pFanin1, LevelMin ) == 1 )
return (*pVisited = 1);
return (*pVisited = 2);
}
int If_CutFilter2( If_Man_t * p, If_Obj_t * pNode, If_Cut_t * pCut )
{
If_Obj_t * pLeaf, * pTemp; int i, Count = 0;
// printf( "Considering node %d and cut {", pNode->Id );
// If_CutForEachLeaf( p, pCut, pLeaf, i )
// printf( " %d", pLeaf->Id );
// printf( " }\n" );
If_CutForEachLeaf( p, pCut, pLeaf, i )
{
int k, iObj, RetValue, nLevelMin = ABC_INFINITY;
Vec_IntClear( p->vVisited2 );
If_CutForEachLeaf( p, pCut, pTemp, k )
{
if ( pTemp == pLeaf )
continue;
nLevelMin = Abc_MinInt( nLevelMin, (int)pTemp->Level );
assert( Vec_StrEntry(p->vMarks, pTemp->Id) == 0 );
Vec_StrWriteEntry( p->vMarks, pTemp->Id, 2 );
Vec_IntPush( p->vVisited2, pTemp->Id );
}
RetValue = If_CutFilter2_rec( p, pLeaf, nLevelMin );
Vec_IntForEachEntry( p->vVisited2, iObj, k )
Vec_StrWriteEntry( p->vMarks, iObj, 0 );
if ( RetValue == 2 )
{
Count++;
pCut->nLeaves--;
for ( k = i; k < (int)pCut->nLeaves; k++ )
pCut->pLeaves[k] = pCut->pLeaves[k+1];
i--;
}
}
//if ( Count )
// printf( "%d", Count );
return 0;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////

View File

@ -2554,7 +2554,7 @@ void Id_DsdManTuneStr1( If_DsdMan_t * p, char * pStruct, int nConfls, int fVerbo
***********************************************************************/
#ifndef ABC_USE_PTHREADS
void Id_DsdManTuneStr( If_DsdMan_t * p, char * pStruct, int nConfls, int nProcs, int fVerbose )
void Id_DsdManTuneStr( If_DsdMan_t * p, char * pStruct, int nConfls, int nProcs, int nInputs, int fVerbose )
{
Id_DsdManTuneStr1( p, pStruct, nConfls, fVerbose );
}
@ -2600,7 +2600,7 @@ void * Ifn_WorkerThread( void * pArg )
assert( 0 );
return NULL;
}
void Id_DsdManTuneStr( If_DsdMan_t * p, char * pStruct, int nConfls, int nProcs, int fVerbose )
void Id_DsdManTuneStr( If_DsdMan_t * p, char * pStruct, int nConfls, int nProcs, int nInputs, int fVerbose )
{
int fVeryVerbose = 0;
ProgressBar * pProgress = NULL;
@ -2703,8 +2703,8 @@ void Id_DsdManTuneStr( If_DsdMan_t * p, char * pStruct, int nConfls, int nProcs,
Extra_ProgressBarUpdate( pProgress, k, NULL );
pObj = If_DsdVecObj( &p->vObjs, k );
nVars = If_DsdObjSuppSize(pObj);
//if ( nVars <= LutSize )
// continue;
if ( nInputs && nVars < nInputs )
continue;
clk = Abc_Clock();
If_DsdManComputeTruthPtr( p, Abc_Var2Lit(k, 0), NULL, ThData[i].pTruth );
clkUsed += Abc_Clock() - clk;

View File

@ -273,6 +273,8 @@ void If_ManStop( If_Man_t * p )
Vec_IntFreeP( &p->vPairRes );
Vec_StrFreeP( &p->vPairPerms );
Vec_PtrFreeP( &p->vVisited );
Vec_StrFreeP( &p->vMarks );
Vec_IntFreeP( &p->vVisited2 );
if ( p->vPairHash )
Hash_IntManStop( p->vPairHash );
for ( i = 6; i <= Abc_MaxInt(6,p->pPars->nLutSize); i++ )

View File

@ -734,37 +734,48 @@ void Io_ReadFileRemoveComments( char * pBuffer, int * pnDots, int * pnLines )
// (in the BLIF file, comments are lines starting with "#")
nDots = nLines = 0;
for ( pCur = pBuffer; *pCur; pCur++ )
{
{
// if this is the beginning of comment
// clean it with spaces until the new line statement
if ( *pCur == '#' )
while ( *pCur != '\n' )
*pCur++ = ' ';
if ( *pCur == '#' ) {
while ( *pCur != '\n' ) {
*pCur++ = ' ';
}
}
// count the number of new lines and dots
if ( *pCur == '\n' ) {
if (*(pCur-1)=='\r') {
// DOS(R) file support
if (*(pCur-2)!='\\') nLines++;
else {
// rewind to backslash and overwrite with a space
*(pCur-2) = ' ';
*(pCur-1) = ' ';
*pCur = ' ';
if (pCur > pBuffer) {
if (*(pCur - 1) == '\r') {
// DOS(R) file support
if (pCur > (pBuffer + 1)) {
if (*(pCur - 2) != '\\') {
nLines++;
}
else {
// rewind to backslash and overwrite with a space
*(pCur - 2) = ' ';
*(pCur - 1) = ' ';
*pCur = ' ';
}
}
} else {
// UNIX(TM) file support
if (*(pCur - 1) != '\\') {
nLines++;
}
else {
// rewind to backslash and overwrite with a space
*(pCur - 1) = ' ';
*pCur = ' ';
}
}
}
}
} else {
// UNIX(TM) file support
if (*(pCur-1)!='\\') nLines++;
else {
// rewind to backslash and overwrite with a space
*(pCur-1) = ' ';
*pCur = ' ';
else if ( *pCur == '.' ) {
nDots++;
}
}
}
else if ( *pCur == '.' )
nDots++;
}
}
if ( pnDots )
*pnDots = nDots;
if ( pnLines )

View File

@ -224,6 +224,7 @@ void Mio_WritePin( FILE * pFile, Mio_Pin_t * pPin, int NameLen, int fAllPins )
***********************************************************************/
void Mio_WriteGate( FILE * pFile, Mio_Gate_t * pGate, int GateLen, int NameLen, int FormLen, int fPrintSops, int fAllPins )
{
//Vec_Int_t * vCover = Vec_IntAlloc( 1 << 10 ); int nLits;
char Buffer[5000];
Mio_Pin_t * pPin;
assert( NameLen+FormLen+2 < 5000 );
@ -239,7 +240,11 @@ void Mio_WriteGate( FILE * pFile, Mio_Gate_t * pGate, int GateLen, int NameLen,
else // different pins
Mio_GateForEachPin( pGate, pPin )
Mio_WritePin( pFile, pPin, NameLen, 0 );
//nLits = 2*Kit_TruthLitNum((unsigned*)&pGate->uTruth, Mio_GateReadPinNum(pGate), vCover);
//if ( nLits != Mio_GateReadArea(pGate) )
// printf( " # %d ", nLits );
fprintf( pFile, "\n" );
//Vec_IntFree( vCover );
}
/**Function*************************************************************

View File

@ -955,6 +955,8 @@ int Scl_LibertyReadPinDirection( Scl_Tree_t * p, Scl_Item_t * pPin )
return 0;
if ( !strcmp(pToken, "output") )
return 1;
if ( !strcmp(pToken, "internal") )
return 2;
break;
}
return -1;
@ -1525,7 +1527,7 @@ Vec_Str_t * Scl_LibertyReadSclStr( Scl_Tree_t * p, int fVerbose, int fVeryVerbos
float CapOne, CapRise, CapFall;
if ( Scl_LibertyReadPinFormula(p, pPin) != NULL ) // skip output pin
continue;
assert( Scl_LibertyReadPinDirection(p, pPin) == 0 );
assert( Scl_LibertyReadPinDirection(p, pPin) == 0 || Scl_LibertyReadPinDirection(p, pPin) == 2);
pName = Scl_LibertyReadString(p, pPin->Head);
Vec_PtrPush( vNameIns, Abc_UtilStrsav(pName) );
Vec_StrPutS_( vOut, pName );
@ -1546,6 +1548,8 @@ Vec_Str_t * Scl_LibertyReadSclStr( Scl_Tree_t * p, int fVerbose, int fVeryVerbos
{
if ( !Scl_LibertyReadPinFormula(p, pPin) ) // skip input pin
continue;
if (Scl_LibertyReadPinDirection(p, pPin) == 2) // skip internal pin
continue;
assert( Scl_LibertyReadPinDirection(p, pPin) == 1 );
pName = Scl_LibertyReadString(p, pPin->Head);
Vec_StrPutS_( vOut, pName );

View File

@ -1290,7 +1290,7 @@ void Extra_TruthExpand( int nVars, int nWords, unsigned * puTruth, unsigned uPha
{ 0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF },
{ 0x00000000,0x00000000,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF }
};
static char Cases[256] = {
static signed char Cases[256] = {
0, // 00000000
0, // 00000001
1, // 00000010

View File

@ -1471,6 +1471,24 @@ static inline void Abc_TtPrintBinary( word * pTruth, int nVars )
printf( "%d", Abc_InfoHasBit( (unsigned *)pThis, k ) );
printf( "\n" );
}
static inline void Abc_TtPrintBinary1( FILE * pFile, word * pTruth, int nVars )
{
word * pThis, * pLimit = pTruth + Abc_TtWordNum(nVars);
int k, Limit = Abc_MinInt( 64, (1 << nVars) );
assert( nVars >= 2 );
for ( pThis = pTruth; pThis < pLimit; pThis++ )
for ( k = 0; k < Limit; k++ )
fprintf( pFile, "%d", Abc_InfoHasBit( (unsigned *)pThis, k ) );
}
static inline void Abc_TtPrintBinary2( FILE * pFile, word * pTruth, int nVars )
{
word * pThis;
int k, Limit = Abc_MinInt( 64, (1 << nVars) );
assert( nVars >= 2 );
for ( pThis = pTruth + Abc_TtWordNum(nVars) - 1; pThis >= pTruth; pThis-- )
for ( k = Limit-1; k >= 0; k-- )
fprintf( pFile, "%d", Abc_InfoHasBit( (unsigned *)pThis, k ) );
}
/**Function*************************************************************

View File

@ -61,6 +61,8 @@ struct Vec_Int_t_
for ( i = Start; (i < Stop) && (((Entry) = Vec_IntEntry(vVec, i)), 1); i++ )
#define Vec_IntForEachEntryReverse( vVec, pEntry, i ) \
for ( i = Vec_IntSize(vVec) - 1; (i >= 0) && (((pEntry) = Vec_IntEntry(vVec, i)), 1); i-- )
#define Vec_IntForEachEntryReverseStart( vVec, pEntry, i, Start ) \
for ( i = Start; (i >= 0) && (((pEntry) = Vec_IntEntry(vVec, i)), 1); i-- )
#define Vec_IntForEachEntryTwo( vVec1, vVec2, Entry1, Entry2, i ) \
for ( i = 0; (i < Vec_IntSize(vVec1)) && (((Entry1) = Vec_IntEntry(vVec1, i)), 1) && (((Entry2) = Vec_IntEntry(vVec2, i)), 1); i++ )
#define Vec_IntForEachEntryTwoStart( vVec1, vVec2, Entry1, Entry2, i, Start ) \

View File

@ -195,6 +195,14 @@ static inline Vec_Wrd_t * Vec_WrdStartTruthTables( int nVars )
}
return p;
}
static inline int Vec_WrdShiftOne( Vec_Wrd_t * p, int nWords )
{
int i, nObjs = p->nSize/nWords;
assert( nObjs * nWords == p->nSize );
for ( i = 0; i < nObjs; i++ )
p->pArray[i*nWords] <<= 1;
return nObjs;
}
/**Function*************************************************************

View File

@ -1027,7 +1027,7 @@ int Abc_TtCofactorPerm( word * pTruth, int i, int nWords, int fSwapOnly, char *
SeeAlso []
***********************************************************************/
#define CANON_VERIFY
//#define CANON_VERIFY
unsigned Abc_TtCanonicize( word * pTruth, int nVars, char * pCanonPerm )
{
int pStoreIn[17];

View File

@ -21,6 +21,7 @@
#include "acecInt.h"
#include "misc/vec/vecWec.h"
#include "misc/extra/extra.h"
#include "misc/util/utilTruth.h"
ABC_NAMESPACE_IMPL_START
@ -207,6 +208,82 @@ void Acec_DetectBoothTest( Gia_Man_t * p )
}
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManResubTest4()
{
Vec_Int_t * vRes = Vec_IntAlloc( 100 );
unsigned T = 0xF335ACC0;
int a, b, c;
int i, k, f, y;
int Count = 0;
for ( a = 0; a < 2; a++ )
{
unsigned A = s_Truths5[a];
for ( b = 0; b < 3; b++ )
{
unsigned B = s_Truths5[2+b];
for ( c = 0; c < 3; c++ ) if ( c != b )
{
unsigned C = s_Truths5[2+c];
Vec_IntPush( vRes, A & B & C );
Vec_IntPush( vRes, A & B & ~C );
}
}
}
printf( "Size = %d.\n", Vec_IntSize(vRes) );
for ( i = 0; i < (1 << Vec_IntSize(vRes)); i++ )
{
unsigned F[7] = {0};
unsigned Y[3] = {0};
if ( Abc_TtCountOnes( (word)i ) >= 8 )
continue;
for ( f = k = 0; k < Vec_IntSize(vRes); k++ )
if ( ((i >> k) & 1) )
F[f++] = Vec_IntEntry(vRes, k);
{
unsigned S1 = (F[0] & F[1]) | (F[0] & F[2]) | (F[1] & F[2]);
unsigned C1 = F[0] ^ F[1] ^ F[2];
unsigned S2 = (F[3] & F[4]) | (F[3] & F[5]) | (F[4] & F[5]);
unsigned C2 = F[3] ^ F[4] ^ F[5];
unsigned S3 = (F[6] & S1) | (F[6] & S2) | (S1 & S2);
unsigned C3 = F[6] ^ S1 ^ S2;
unsigned S4 = (C1 & C2) | (C1 & C3) | (C2 & C3);
unsigned C4 = C1 ^ C2 ^ C3;
Y[0] = S3;
Y[1] = S4;
Y[2] = C4;
}
for ( y = 0; y < 3; y++ )
if ( Y[y] == T )
printf( "Found!\n" );
Count++;
}
printf( "Tried = %d.\n", Count );
Vec_IntFree( vRes );
}
void Gia_ManResubTest5()
{
unsigned T = 0xF335ACC0;
int i;
for ( i = 0; i < 4; i++ )
{
unsigned x = i%2 ? Abc_Tt5Cofactor1(T, 0) : Abc_Tt5Cofactor0(T, 0);
unsigned y = i/2 ? Abc_Tt5Cofactor1(x, 1) : Abc_Tt5Cofactor0(x, 1);
word F = y;
F |= F << 32;
//Dau_DsdPrintFromTruth2( &F, 6 ); printf( "\n" );
}
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////

View File

@ -21,6 +21,7 @@
#include "acecInt.h"
#include "misc/vec/vecWec.h"
#include "misc/extra/extra.h"
#include "misc/util/utilTruth.h"
ABC_NAMESPACE_IMPL_START
@ -425,6 +426,49 @@ Acec_Box_t * Acec_ProduceBox( Gia_Man_t * p, int fVerbose )
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManTestXor( Gia_Man_t * p )
{
Vec_Wrd_t * vSimsPi = Vec_WrdStartTruthTables( Gia_ManCiNum(p) );
Vec_Wrd_t * vSims = Gia_ManSimPatSimOut( p, vSimsPi, 1 );
int n, i, nWords = Vec_WrdSize(vSimsPi) / Gia_ManCiNum(p);
Gia_Obj_t * pObj; Vec_Wrd_t * vSims2;
Gia_ManForEachAnd( p, pObj, i )
{
Gia_Obj_t Obj = *pObj;
for ( n = 0; n < 2; n++ )
{
if ( n )
{
pObj->iDiff1 = pObj->iDiff0;
pObj->fCompl1 = pObj->fCompl0;
}
else
{
pObj->iDiff0 = pObj->iDiff1;
pObj->fCompl0 = pObj->fCompl1;
}
vSims2 = Gia_ManSimPatSimOut( p, vSimsPi, 1 );
printf( "%2d %2d : %5d\n", i, n, Abc_TtCountOnesVecXor(Vec_WrdArray(vSims), Vec_WrdArray(vSims2), Vec_WrdSize(vSims2)) );
Vec_WrdFree( vSims2 );
*pObj = Obj;
}
}
Vec_WrdFree( vSimsPi );
Vec_WrdFree( vSims );
nWords = 0;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////

View File

@ -149,6 +149,7 @@ struct Cec_ParCor_t_
int nBTLimit; // conflict limit at a node
int nLevelMax; // (scorr only) the max number of levels
int nStepsMax; // (scorr only) the max number of induction steps
int nLimitMax; // (scorr only) stop after this many iterations if little or no improvement
int fLatchCorr; // consider only latch outputs
int fConstCorr; // consider only constants
int fUseRings; // use rings
@ -206,6 +207,7 @@ struct Cec_ParSeq_t_
/*=== cecCec.c ==========================================================*/
extern int Cec_ManVerify( Gia_Man_t * p, Cec_ParCec_t * pPars );
extern int Cec_ManVerifyTwo( Gia_Man_t * p0, Gia_Man_t * p1, int fVerbose );
extern int Cec_ManVerifyTwoInv( Gia_Man_t * p0, Gia_Man_t * p1, int fVerbose );
extern int Cec_ManVerifySimple( Gia_Man_t * p );
/*=== cecChoice.c ==========================================================*/
extern Gia_Man_t * Cec_ManChoiceComputation( Gia_Man_t * pAig, Cec_ParChc_t * pPars );

View File

@ -465,6 +465,21 @@ int Cec_ManVerifyTwo( Gia_Man_t * p0, Gia_Man_t * p1, int fVerbose )
Gia_ManStop( pMiter );
return RetValue;
}
int Cec_ManVerifyTwoInv( Gia_Man_t * p0, Gia_Man_t * p1, int fVerbose )
{
Cec_ParCec_t ParsCec, * pPars = &ParsCec;
Gia_Man_t * pMiter;
int RetValue;
Cec_ManCecSetDefaultParams( pPars );
pPars->fVerbose = fVerbose;
pMiter = Gia_ManMiterInverse( p0, p1, 1, pPars->fVerbose );
if ( pMiter == NULL )
return -1;
RetValue = Cec_ManVerify( pMiter, pPars );
p0->pCexComb = pMiter->pCexComb; pMiter->pCexComb = NULL;
Gia_ManStop( pMiter );
return RetValue;
}
/**Function*************************************************************

View File

@ -756,6 +756,21 @@ void Cec_ManRefinedClassPrintStats( Gia_Man_t * p, Vec_Str_t * vStatus, int iIte
Abc_Print( 1, "%c ", Gia_ObjIsConst( p, Gia_ObjFaninId0p(p, Gia_ManPo(p, 0)) ) ? '+' : '-' );
Abc_PrintTime( 1, "T", Time );
}
int Cec_ManCountLits( Gia_Man_t * p )
{
int i, CounterX = 0, Counter0 = 0, Counter = 0;
for ( i = 1; i < Gia_ManObjNum(p); i++ )
{
if ( Gia_ObjIsNone(p, i) )
CounterX++;
else if ( Gia_ObjIsConst(p, i) )
Counter0++;
else if ( Gia_ObjIsHead(p, i) )
Counter++;
}
CounterX -= Gia_ManCoNum(p);
return Gia_ManCiNum(p) + Gia_ManAndNum(p) - Counter - CounterX;
}
/**Function*************************************************************
@ -777,7 +792,7 @@ void Cec_ManLSCorrespondenceBmc( Gia_Man_t * pAig, Cec_ParCor_t * pPars, int nPr
Vec_Int_t * vCexStore;
Cec_ManSim_t * pSim;
Gia_Man_t * pSrm;
int fChanges, RetValue;
int fChanges, RetValue, i;
// prepare simulation manager
Cec_ManSimSetDefaultParams( pParsSim );
pParsSim->nWords = pPars->nWords;
@ -791,7 +806,7 @@ void Cec_ManLSCorrespondenceBmc( Gia_Man_t * pAig, Cec_ParCor_t * pPars, int nPr
pParsSat->nBTLimit = pPars->nBTLimit;
pParsSat->fVerbose = pPars->fVerbose;
fChanges = 1;
while ( fChanges )
for ( i = 0; fChanges && (!pPars->nLimitMax || i < pPars->nLimitMax); i++ )
{
abctime clkBmc = Abc_Clock();
fChanges = 0;
@ -918,7 +933,7 @@ int Cec_ManLSCorrespondenceClasses( Gia_Man_t * pAig, Cec_ParCor_t * pPars )
Cec_ParSat_t ParsSat, * pParsSat = &ParsSat;
Cec_ManSim_t * pSim;
Gia_Man_t * pSrm;
int r, RetValue;
int r, RetValue, nPrev[4] = {0};
abctime clkTotal = Abc_Clock();
abctime clkSat = 0, clkSim = 0, clkSrm = 0;
abctime clk2, clk = Abc_Clock();
@ -1031,6 +1046,23 @@ int Cec_ManLSCorrespondenceClasses( Gia_Man_t * pAig, Cec_ParCor_t * pPars )
Cec_ManSimStop( pSim );
return 0;
}
if ( pPars->nLimitMax )
{
int nCur = Cec_ManCountLits(pAig);
if ( r > 4 && nPrev[0] - nCur <= 4*pPars->nLimitMax )
{
printf( "Iterative refinement is stopped after iteration %d\n", r );
printf( "because refinement does not proceed quickly.\n" );
Cec_ManSimStop( pSim );
ABC_FREE( pAig->pReprs );
ABC_FREE( pAig->pNexts );
return 0;
}
nPrev[0] = nPrev[1];
nPrev[1] = nPrev[2];
nPrev[2] = nPrev[3];
nPrev[3] = nCur;
}
}
if ( pPars->fVerbose )
Cec_ManRefinedClassPrintStats( pAig, NULL, r+1, Abc_Clock() - clk );

View File

@ -1877,9 +1877,9 @@ void Cec4_ManSimulateTest2( Gia_Man_t * p, int nConfs, int fVerbose )
abctime clk = Abc_Clock();
Cec_ParFra_t ParsFra, * pPars = &ParsFra;
Cec4_ManSetParams( pPars );
Cec4_ManPerformSweeping( p, pPars, NULL, 0 );
pPars->fVerbose = fVerbose;
pPars->nBTLimit = nConfs;
Cec4_ManPerformSweeping( p, pPars, NULL, 0 );
if ( fVerbose )
Abc_PrintTime( 1, "New choice computation time", Abc_Clock() - clk );
}
@ -1912,6 +1912,139 @@ int Cec4_ManSimulateOnlyTest( Gia_Man_t * p, int fVerbose )
return Cec4_ManPerformSweeping( p, pPars, NULL, 1 );
}
/**Function*************************************************************
Synopsis [Internal simulation APIs.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Cec4_ManSimulateTest5Int( Gia_Man_t * p, int nConfs, int fVerbose )
{
abctime clk = Abc_Clock();
Cec_ParFra_t ParsFra, * pPars = &ParsFra;
Cec4_ManSetParams( pPars );
pPars->fVerbose = fVerbose;
pPars->nBTLimit = nConfs;
Cec4_ManPerformSweeping( p, pPars, NULL, 0 );
if ( fVerbose )
Abc_PrintTime( 1, "Equivalence detection time", Abc_Clock() - clk );
}
Gia_Man_t * Gia_ManLocalRehash( Gia_Man_t * p )
{
Gia_Man_t * pNew, * pTemp;
Gia_Obj_t * pObj;
int i;
pNew = Gia_ManStart( Gia_ManObjNum(p) );
Gia_ManHashAlloc( pNew );
Gia_ManConst0(p)->Value = 0;
Gia_ManForEachObj1( p, pObj, i )
{
if ( Gia_ObjIsAnd(pObj) )
pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
else if ( Gia_ObjIsCi(pObj) )
pObj->Value = Gia_ManAppendCi( pNew );
else if ( Gia_ObjIsCo(pObj) )
pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
}
Gia_ManHashStop( pNew );
pNew = Gia_ManCleanup( pTemp = pNew );
Gia_ManForEachObj1( p, pObj, i )
{
int iLitNew = Gia_ManObj(pTemp, Abc_Lit2Var(pObj->Value))->Value;
if ( iLitNew == ~0 )
pObj->Value = iLitNew;
else
pObj->Value = Abc_LitNotCond(iLitNew, Abc_LitIsCompl(pObj->Value));
}
Gia_ManStop( pTemp );
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
return pNew;
}
Vec_Int_t * Cec4_ManComputeMapping( Gia_Man_t * p, Gia_Man_t * pAig, int fVerbose )
{
Gia_Obj_t * pObj;
Vec_Int_t * vReprs = Vec_IntStartFull( Gia_ManObjNum(p) );
int * pAig2Abc = ABC_FALLOC( int, Gia_ManObjNum(pAig) );
int i, nConsts = 0, nReprs = 0;
pAig2Abc[0] = 0;
Gia_ManForEachCand( p, pObj, i )
{
int iLitGia = pObj->Value, iReprGia;
if ( iLitGia == -1 )
continue;
iReprGia = Gia_ObjReprSelf( pAig, Abc_Lit2Var(iLitGia) );
if ( pAig2Abc[iReprGia] == -1 )
pAig2Abc[iReprGia] = i;
else
{
int iLitGia2 = Gia_ManObj(p, pAig2Abc[iReprGia] )->Value;
assert( Gia_ObjReprSelf(pAig, Abc_Lit2Var(iLitGia)) == Gia_ObjReprSelf(pAig, Abc_Lit2Var(iLitGia2)) );
assert( i > pAig2Abc[iReprGia] );
Vec_IntWriteEntry( vReprs, i, pAig2Abc[iReprGia] );
if ( pAig2Abc[iReprGia] == 0 )
nConsts++;
else
nReprs++;
}
}
ABC_FREE( pAig2Abc );
if ( fVerbose )
printf( "Found %d const reprs and %d other reprs.\n", nConsts, nReprs );
return vReprs;
}
void Cec4_ManVerifyEquivs( Gia_Man_t * p, Vec_Int_t * vRes, int fVerbose )
{
int i, iRepr, nWords = 4; word * pSim0, * pSim1;
Vec_Wrd_t * vSimsCi = Vec_WrdStartRandom( Gia_ManCiNum(p) * nWords );
int nObjs = Vec_WrdShiftOne( vSimsCi, nWords ), nFails = 0;
Vec_Wrd_t * vSims = Gia_ManSimPatSimOut( p, vSimsCi, 0 );
assert( Vec_IntSize(vRes) == Gia_ManObjNum(p) );
assert( nObjs == Gia_ManCiNum(p) );
Vec_IntForEachEntry( vRes, iRepr, i )
{
if ( iRepr == -1 )
continue;
assert( i > iRepr );
pSim0 = Vec_WrdEntryP( vSims, nWords*i );
pSim1 = Vec_WrdEntryP( vSims, nWords*iRepr );
if ( (pSim0[0] ^ pSim1[0]) & 1 )
nFails += !Abc_TtOpposite(pSim0, pSim1, nWords);
else
nFails += !Abc_TtEqual(pSim0, pSim1, nWords);
}
Vec_WrdFree( vSimsCi );
Vec_WrdFree( vSims );
if ( nFails )
printf( "Verification failed at %d nodes.\n", nFails );
else if ( fVerbose )
printf( "Verification succeeded for all (%d) nodes.\n", Gia_ManCandNum(p) );
}
void Cec4_ManConvertToLits( Gia_Man_t * p, Vec_Int_t * vRes )
{
Gia_Obj_t * pObj; int i, iRepr;
Gia_ManSetPhase( p );
Gia_ManForEachObj( p, pObj, i )
if ( (iRepr = Vec_IntEntry(vRes, i)) >= 0 )
Vec_IntWriteEntry( vRes, i, Abc_Var2Lit(iRepr, Gia_ManObj(p, iRepr)->fPhase ^ pObj->fPhase) );
}
void Cec4_ManSimulateTest5( Gia_Man_t * p, int nConfs, int fVerbose )
{
Vec_Int_t * vRes = NULL;
Gia_Man_t * pAig = Gia_ManLocalRehash( p );
Cec4_ManSimulateTest5Int( pAig, nConfs, fVerbose );
vRes = Cec4_ManComputeMapping( p, pAig, fVerbose );
Cec4_ManVerifyEquivs( p, vRes, fVerbose );
Cec4_ManConvertToLits( p, vRes );
Vec_IntDumpBin( "_temp_.equiv", vRes, fVerbose );
Vec_IntFree( vRes );
Gia_ManStop( pAig );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////

Some files were not shown because too many files have changed in this diff Show More