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

This commit is contained in:
Miodrag Milanovic 2025-09-03 17:27:47 +02:00
commit 8827bafb7f
36 changed files with 3548 additions and 401 deletions

View File

@ -3323,47 +3323,47 @@ SOURCE=.\src\opt\fxu\fxuUpdate.c
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\src\opt\rar\rewire_map.h
SOURCE=.\src\opt\rar\rewireMap.h
# End Source File
# Begin Source File
SOURCE=.\src\opt\rar\rewire_miaig.h
SOURCE=.\src\opt\rar\rewireMiaig.h
# End Source File
# Begin Source File
SOURCE=.\src\opt\rar\rewire_rar.h
SOURCE=.\src\opt\rar\rewireRar.h
# End Source File
# Begin Source File
SOURCE=.\src\opt\rar\rewire_rng.h
SOURCE=.\src\opt\rar\rewireRng.h
# End Source File
# Begin Source File
SOURCE=.\src\opt\rar\rewire_time.h
SOURCE=.\src\opt\rar\rewireTime.h
# End Source File
# Begin Source File
SOURCE=.\src\opt\rar\rewire_tt.h
SOURCE=.\src\opt\rar\rewireTt.h
# End Source File
# Begin Source File
SOURCE=.\src\opt\rar\rewire_vec.h
SOURCE=.\src\opt\rar\rewireVec.h
# End Source File
# Begin Source File
SOURCE=.\src\opt\rar\rewire_map.c
SOURCE=.\src\opt\rar\rewireMap.c
# End Source File
# Begin Source File
SOURCE=.\src\opt\rar\rewire_miaig.cpp
SOURCE=.\src\opt\rar\rewireMiaig.cpp
# End Source File
# Begin Source File
SOURCE=.\src\opt\rar\rewire_rar.c
SOURCE=.\src\opt\rar\rewireRar.c
# End Source File
# Begin Source File
SOURCE=.\src\opt\rar\rewire_rng.c
SOURCE=.\src\opt\rar\rewireRng.c
# End Source File
# End Group
# Begin Group "rwr"
@ -4991,6 +4991,10 @@ SOURCE=.\src\misc\util\utilPth.c
# End Source File
# Begin Source File
SOURCE=.\src\misc\util\utilPrefix.cpp
# End Source File
# Begin Source File
SOURCE=.\src\misc\util\utilSignal.c
# End Source File
# Begin Source File
@ -5755,6 +5759,10 @@ SOURCE=.\src\aig\gia\giaBound.c
# End Source File
# Begin Source File
SOURCE=.\src\aig\gia\giaBsFind.c
# End Source File
# Begin Source File
SOURCE=.\src\aig\gia\giaCCof.c
# End Source File
# Begin Source File

View File

@ -1358,7 +1358,7 @@ extern Gia_Man_t * Gia_ManDupZero( Gia_Man_t * p );
extern Gia_Man_t * Gia_ManDupPerm( Gia_Man_t * p, Vec_Int_t * vPiPerm );
extern Gia_Man_t * Gia_ManDupPermFlop( Gia_Man_t * p, Vec_Int_t * vFfPerm );
extern Gia_Man_t * Gia_ManDupPermFlopGap( Gia_Man_t * p, Vec_Int_t * vFfPerm );
extern void Gia_ManDupAppend( Gia_Man_t * p, Gia_Man_t * pTwo );
extern void Gia_ManDupAppend( Gia_Man_t * p, Gia_Man_t * pTwo, int fShareCis );
extern void Gia_ManDupAppendShare( Gia_Man_t * p, Gia_Man_t * pTwo );
extern Gia_Man_t * Gia_ManDupAppendNew( Gia_Man_t * pOne, Gia_Man_t * pTwo );
extern Gia_Man_t * Gia_ManDupAppendCones( Gia_Man_t * p, Gia_Man_t ** ppCones, int nCones, int fOnlyRegs );

580
src/aig/gia/giaBsFind.c Normal file
View File

@ -0,0 +1,580 @@
/**CFile****************************************************************
FileName [giaBsFind.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: giaBsFind.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 ///
////////////////////////////////////////////////////////////////////////
// Cost function: sum of squared differences between all pairs
int cost_sum_squares(int* subset, int K, void * pData) {
double cost = 0;
for (int i = 0; i < K - 1; i++) {
for (int j = i + 1; j < K; j++) {
int diff = subset[i] - subset[j];
cost += diff * diff;
}
}
// Normalize to be between 2 and 100
return (int)(2.0 + (cost / (K * K)) * 0.98);
}
// Compare function for qsort - for sorting individual subsets
int compare_ints(const void* a, const void* b) {
return *(int*)a - *(int*)b;
}
// Compare function for qsort - for sorting subsets by cost
// Subset format: [K, element1, element2, ..., elementK, cost]
int compare_subsets_by_cost(const void* a, const void* b) {
const int* subset_a = (const int*)a;
const int* subset_b = (const int*)b;
int K_a = subset_a[0];
int K_b = subset_b[0];
assert( K_a == K_b );
// Cost is at position K+1 (after K and K elements)
return subset_a[K_a + 1] - subset_b[K_b + 1];
}
// Generate a random subset of K numbers from 0 to N-1
// Format: [K, element1, element2, ..., elementK, cost]
void generate_random_subset(int* subset, int K, int N) {
subset[0] = K; // Store K in first position
int count = 0;
// First, generate K unique random numbers
while (count < K) {
int num = rand() % N;
// Check if number already exists in subset
int exists = 0;
for (int i = 0; i < count; i++) {
if (subset[i + 1] == num) {
exists = 1;
break;
}
}
if (!exists) {
subset[count + 1] = num;
count++;
}
}
// Then, sort the subset using bubble sort
for (int i = 1; i < K; i++) {
for (int j = 1; j < K - i + 1; j++) {
if (subset[j] > subset[j + 1]) {
int temp = subset[j];
subset[j] = subset[j + 1];
subset[j + 1] = temp;
}
}
}
}
// Create offspring from two parent subsets
// Uses pre-allocated arrays to avoid repeated memory allocation
void create_offspring(int* parent1, int* parent2, int* offspring, int K, int N,
int* in_offspring, int* in_parent1, int* in_parent2, int* candidates) {
int count = 0;
offspring[0] = K; // Store K in first position
// Mark which numbers are in each parent (skip first element which is K)
for (int i = 1; i <= K; i++) {
in_parent1[parent1[i]] = 1;
in_parent2[parent2[i]] = 1;
}
// First, add numbers that appear in both parents
for (int i = 0; i < N && count < K; i++) {
if (in_parent1[i] && in_parent2[i]) {
offspring[count + 1] = i;
count++;
in_offspring[i] = 1;
}
}
// Create array of numbers that appear in exactly one parent
int num_candidates = 0;
for (int i = 0; i < N; i++) {
if ((in_parent1[i] || in_parent2[i]) && !in_offspring[i]) {
candidates[num_candidates++] = i;
}
}
// Randomly add from candidates until we have K numbers
while (count < K && num_candidates > 0) {
int idx = rand() % num_candidates;
offspring[count + 1] = candidates[idx];
count++;
in_offspring[candidates[idx]] = 1;
// Remove selected candidate
candidates[idx] = candidates[--num_candidates];
}
// Sort the offspring elements (not including the first K value)
qsort(&offspring[1], K, sizeof(int), compare_ints);
// Clean up the intean arrays for next use - only clean used entries
for (int i = 1; i <= K; i++) {
in_parent1[parent1[i]] = 0;
in_parent2[parent2[i]] = 0;
}
for (int i = 1; i <= K; i++) {
in_offspring[offspring[i]] = 0;
}
}
// Count unique subsets in a sorted array of subsets
// Returns the number of unique subsets and prints the percentage
int count_unique_subsets(int* sorted_subsets, int num_subsets, int subset_size, const char* label) {
if (num_subsets == 0) return 0;
int unique_count = 1; // First subset is always unique
int K = sorted_subsets[0]; // Get K from first subset
// Compare each subset with the previous one
for (int i = 1; i < num_subsets; i++) {
int* current = &sorted_subsets[i * subset_size];
int* previous = &sorted_subsets[(i - 1) * subset_size];
// Compare all K elements (skip position 0 which has K, and K+1 which has cost)
int is_different = 0;
for (int j = 1; j <= K; j++) {
if (current[j] != previous[j]) {
is_different = 1;
break;
}
}
if (is_different) {
unique_count++;
}
}
double percentage = (unique_count * 100.0) / num_subsets;
printf("%s: %d unique subsets out of %d (%.1f%%)\n",
label, unique_count, num_subsets, percentage);
return unique_count;
}
// Main genetic algorithm
int genetic_subset_selection(int N, int K, int B, int L,
int verbose,
int (*cost_function)(int*, int, void *),
int** best_subsets_history,
int* iterations_used,
void * pUserData) {
int print_unique = 0;
int M = B * (B - 1) / 2;
int subset_size = K + 2; // K value + K elements + cost
// Allocate arrays
int* current_generation = (int*)malloc(M * subset_size * sizeof(int));
int* next_generation = (int*)malloc(M * subset_size * sizeof(int));
int* all_best_subsets = (int*)calloc(B * L * subset_size, sizeof(int));
// Pre-allocate reusable arrays for create_offspring
int* in_offspring = (int*)calloc(N, sizeof(int));
int* in_parent1 = (int*)calloc(N, sizeof(int));
int* in_parent2 = (int*)calloc(N, sizeof(int));
int* candidates = (int*)malloc(K * 2 * sizeof(int));
// Generate initial population
for (int i = 0; i < M; i++) {
int* subset = &current_generation[i * subset_size];
generate_random_subset(subset, K, N);
// Cost function uses elements starting at position 1
subset[K + 1] = cost_function(&subset[1], K, pUserData);
}
// Sort to get best B subsets
qsort(current_generation, M, subset_size * sizeof(int), compare_subsets_by_cost);
if ( print_unique ) count_unique_subsets(current_generation, M, subset_size, "Initial population");
int best_cost = current_generation[K + 1];
int generation = 0;
int total_best_count = 0;
// Main evolutionary loop
while (generation < L) {
// Store best B subsets from current generation
for (int i = 0; i < B && total_best_count < B * L; i++) {
memcpy(&all_best_subsets[total_best_count * subset_size],
&current_generation[i * subset_size],
subset_size * sizeof(int));
total_best_count++;
}
if ( verbose ) {
printf( "Iter %d\n", generation );
for (int i = 0; i < B; i++ ) {
printf( "Subset %2d : {", i );
for (int k = 0; k < K; k++ )
printf( " %2d", (&current_generation[i * subset_size])[k+1] );
printf( " } " );
printf( "Cost %2d\n", (&current_generation[i * subset_size])[K+1] );
}
}
// Create next generation from pairs of best B subsets
int offspring_idx = 0;
for (int i = 0; i < B; i++) {
for (int j = i + 1; j < B; j++) {
int* parent1 = &current_generation[i * subset_size];
int* parent2 = &current_generation[j * subset_size];
int* offspring = &next_generation[offspring_idx * subset_size];
create_offspring(parent1, parent2, offspring, K, N,
in_offspring, in_parent1, in_parent2, candidates);
offspring[K + 1] = cost_function(&offspring[1], K, pUserData);
offspring_idx++;
}
}
// Sort next generation
qsort(next_generation, M, subset_size * sizeof(int), compare_subsets_by_cost);
if ( print_unique ) count_unique_subsets(next_generation, M, subset_size, "Next generation");
generation++;
// Check for improvement
int new_best_cost = next_generation[K + 1];
if (new_best_cost >= best_cost) {
break; // No improvement
}
best_cost = new_best_cost;
// Swap generations
int* temp = current_generation;
current_generation = next_generation;
next_generation = temp;
}
// Sort all best subsets collected using qsort
qsort(all_best_subsets, total_best_count, subset_size * sizeof(int), compare_subsets_by_cost);
if ( print_unique ) count_unique_subsets(all_best_subsets, total_best_count, subset_size, "All best subsets");
if ( verbose ) {
printf( "Final best\n" );
for (int i = 0; i < B; i++ ) {
printf( "Subset %2d : {", i );
for (int k = 0; k < K; k++ )
printf( " %2d", (&all_best_subsets[i * subset_size])[k+1] );
printf( " } " );
printf( "Cost %2d\n", (&all_best_subsets[i * subset_size])[K+1] );
}
}
// Free pre-allocated arrays
free(in_offspring);
free(in_parent1);
free(in_parent2);
free(candidates);
// Return results
if (best_subsets_history != NULL) {
*best_subsets_history = all_best_subsets;
} else {
free(all_best_subsets);
}
if (iterations_used != NULL) {
*iterations_used = generation + 1;
}
free(current_generation);
free(next_generation);
return best_cost;
}
// Test bench
/*
int bs_find_test() {
srand(time(NULL));
// Test parameters
int N = 30; // Total numbers (0 to 29)
int K = 6; // Subset size
int B = 10; // Number of best subsets to keep
int L = 50; // Maximum iterations
printf("Genetic Algorithm for Subset Selection\n");
printf("======================================\n");
printf("Parameters:\n");
printf(" N (total numbers): %d\n", N);
printf(" K (subset size): %d\n", K);
printf(" B (best subsets): %d\n", B);
printf(" L (max iterations): %d\n", L);
printf("\n");
// Run the algorithm
int* best_subsets_history = NULL;
int iterations_used = 0;
int best_cost = genetic_subset_selection(N, K, B, L, 0,
cost_sum_squares,
&best_subsets_history,
&iterations_used);
printf("Best cost found: %d\n", best_cost);
printf("Iterations until convergence: %d\n\n", iterations_used);
// Display top 5 best subsets
printf("Top 5 best subsets:\n");
int subset_size = K + 2;
for (int i = 0; i < 5 && i < B * L; i++) {
int* subset = &best_subsets_history[i * subset_size];
if (subset[K + 1] == 0) break; // Check if cost is 0 (uninitialized)
printf("Subset %d: {", i + 1);
for (int j = 1; j <= K; j++) {
printf("%d", subset[j]);
if (j < K) printf(", ");
}
printf("} - Cost: %d\n", subset[K + 1]);
}
// Test with different parameters
printf("\n\nTesting with different parameters:\n");
printf("==================================\n");
// Test 1: Smaller problem
N = 20; K = 4; B = 6; L = 30;
free(best_subsets_history);
best_subsets_history = NULL;
iterations_used = 0;
best_cost = genetic_subset_selection(N, K, B, L, 0,
cost_sum_squares,
&best_subsets_history,
&iterations_used);
printf("\nTest 1 - N=%d, K=%d, B=%d, L=%d\n", N, K, B, L);
printf("Best cost: %d\n", best_cost);
printf("Iterations until convergence: %d\n", iterations_used);
printf("Best subset: {");
for (int j = 1; j <= K; j++) {
printf("%d", best_subsets_history[j]);
if (j < K) printf(", ");
}
printf("}\n");
// Test 2: Larger problem
N = 50; K = 8; B = 15; L = 100;
free(best_subsets_history);
best_subsets_history = NULL;
iterations_used = 0;
best_cost = genetic_subset_selection(N, K, B, L, 0,
cost_sum_squares,
&best_subsets_history,
&iterations_used);
printf("\nTest 2 - N=%d, K=%d, B=%d, L=%d\n", N, K, B, L);
printf("Best cost: %d\n", best_cost);
printf("Iterations until convergence: %d\n", iterations_used);
printf("Best subset: {");
for (int j = 1; j <= K; j++) {
printf("%d", best_subsets_history[j]);
if (j < K) printf(", ");
}
printf("}\n");
// Test 3: Test convergence speed with different B values
printf("\n\nConvergence Speed Analysis:\n");
printf("===========================\n");
N = 40; K = 7; L = 100;
for (int B_test = 5; B_test <= 20; B_test += 5) {
free(best_subsets_history);
best_subsets_history = NULL;
iterations_used = 0;
best_cost = genetic_subset_selection(N, K, B_test, L, 0,
cost_sum_squares,
&best_subsets_history,
&iterations_used);
printf("B=%2d: Best cost=%3d, Iterations=%3d\n",
B_test, best_cost, iterations_used);
}
free(best_subsets_history);
return 0;
}
*/
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Wrd_t * Gia_ManBsFindStart( Gia_Man_t * pGia, int nWords )
{
Vec_Wrd_t * vSims = Vec_WrdStartRandom( (Gia_ManCiNum(pGia) + 1) * nWords );
Vec_WrdFillExtra( vSims, Gia_ManObjNum(pGia) * nWords, 0 );
Abc_TtClear( Vec_WrdArray(vSims), nWords );
return vSims;
}
void Gia_ManBsFindNext( Gia_Man_t * pGia, int nWords, Vec_Wrd_t * vSims, Vec_Wrd_t * vSimsOuts, int iMint )
{
Gia_Obj_t * pObj; int i;
word * pSims[2], * pSim;
Gia_ManForEachAnd( pGia, pObj, i ) {
pSim = Vec_WrdEntryP( vSims, i * nWords );
pSims[0] = Vec_WrdEntryP( vSims, Gia_ObjFaninId0(pObj, i) * nWords );
pSims[1] = Vec_WrdEntryP( vSims, Gia_ObjFaninId1(pObj, i) * nWords );
Abc_TtAndCompl( pSim, pSims[0], Gia_ObjFaninC0(pObj), pSims[1], Gia_ObjFaninC1(pObj), nWords );
}
Gia_ManForEachCo( pGia, pObj, i ) {
pSim = Vec_WrdEntryP( vSimsOuts, (iMint * Gia_ManCoNum(pGia) + i) * nWords );
pSims[0] = Vec_WrdEntryP( vSims, Gia_ObjFaninId0p(pGia, pObj) * nWords );
Abc_TtCopy( pSim, pSims[0], nWords, Gia_ObjFaninC0(pObj) );
}
}
int Gia_ManBsFindMyu( Gia_Man_t * p, int nWords, Vec_Wrd_t * vSims, Vec_Wrd_t * vSimsOuts, Vec_Int_t * vVarNums, Vec_Wrd_t * vTemp )
{
int nMints = 1 << Vec_IntSize(vVarNums);
int nWordsAll = Gia_ManCoNum(p) * nWords;
int nMyu = 0, pMyu[256], i, k, Var;
assert( nMints <= 256 );
assert( Vec_WrdSize(vTemp) == nWords * Vec_IntSize(vVarNums) );
assert( Vec_WrdSize(vSimsOuts) == nMints * nWordsAll );
Vec_IntForEachEntry( vVarNums, Var, i )
Abc_TtCopy( Vec_WrdEntryP(vTemp, i * nWords), Vec_WrdEntryP(vSims, Gia_ManCiIdToId(p, Var) * nWords), nWords, 0 );
for ( int m = 0; m < nMints; m++ ) {
Vec_IntForEachEntry( vVarNums, Var, i )
Abc_TtConst( Vec_WrdEntryP(vSims, Gia_ManCiIdToId(p, Var) * nWords), nWords, (m >> i) & 1 );
Gia_ManBsFindNext( p, nWords, vSims, vSimsOuts, m );
}
Vec_IntForEachEntry( vVarNums, Var, i )
Abc_TtCopy( Vec_WrdEntryP(vSims, Gia_ManCiIdToId(p, Var) * nWords), Vec_WrdEntryP(vTemp, i * nWords), nWords, 0 );
for ( i = 0; i < nMints; i++ ) {
word * pSim = Vec_WrdEntryP(vSimsOuts, nWordsAll * i);
for ( k = 0; k < nMyu; k++ )
if ( Abc_TtEqual(pSim, Vec_WrdEntryP(vSimsOuts, nWordsAll * pMyu[k]), nWordsAll) )
break;
if ( k == nMyu )
pMyu[nMyu++] = i;
}
return nMyu;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
typedef struct BsFind_UserData_t_ {
Gia_Man_t * pGia;
int nWords;
Vec_Wrd_t * vSims;
Vec_Wrd_t * vSimsOuts;
Vec_Int_t * vVarNums;
Vec_Wrd_t * vTemp;
} BsFind_UserData_t;
BsFind_UserData_t * Gia_ManBsFindMyuFunctionStart( Gia_Man_t * pGia, int nWords, int nLutSize )
{
BsFind_UserData_t * p = ABC_CALLOC( BsFind_UserData_t, 1 );
p->pGia = pGia;
p->nWords = nWords;
p->vSims = Gia_ManBsFindStart( pGia, nWords );
p->vSimsOuts = Vec_WrdStart( (1 << nLutSize) * Gia_ManCoNum(pGia) * nWords );
p->vVarNums = Vec_IntAlloc( nLutSize );
p->vTemp = Vec_WrdStart( nLutSize * nWords );
return p;
}
int Gia_ManBsFindMyuFunction( int * subset, int K, void * pUserData )
{
BsFind_UserData_t * p = (BsFind_UserData_t *)pUserData;
Vec_IntClear( p->vVarNums );
for ( int i = 0; i < K; i++ )
Vec_IntPush( p->vVarNums, subset[i] );
return Gia_ManBsFindMyu( p->pGia, p->nWords, p->vSims, p->vSimsOuts, p->vVarNums, p->vTemp );
}
void Gia_ManBsFindMyuFunctionStop( BsFind_UserData_t * p )
{
Vec_WrdFree( p->vSims );
Vec_WrdFree( p->vSimsOuts );
Vec_WrdFree( p->vTemp );
Vec_IntFree( p->vVarNums );
ABC_FREE( p );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Gia_ManBsFindBest( Gia_Man_t * pGia, int nWords, int nLutSize, int nBest, int nIterMax, int fVerbose )
{
abctime clk = Abc_Clock();
Abc_Random(1);
BsFind_UserData_t * p = Gia_ManBsFindMyuFunctionStart( pGia, nWords, nLutSize );
int nIters = 0, Res = genetic_subset_selection( Gia_ManCiNum(pGia), nLutSize, nBest, nIterMax, fVerbose, Gia_ManBsFindMyuFunction, NULL, &nIters, (void *)p );
printf( "The best Myu %d was found after considering %d bound-sets in %d iterations. ", Res, nIters*nBest*(nBest-1)/2, nIters );
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
Gia_ManBsFindMyuFunctionStop( p );
return Res;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END

View File

@ -1134,7 +1134,7 @@ Gia_Man_t * Gia_ManDupRandPerm( Gia_Man_t * p )
SeeAlso []
***********************************************************************/
void Gia_ManDupAppend( Gia_Man_t * pNew, Gia_Man_t * pTwo )
void Gia_ManDupAppend( Gia_Man_t * pNew, Gia_Man_t * pTwo, int fShareCis )
{
Gia_Obj_t * pObj;
int i;
@ -1148,7 +1148,7 @@ void Gia_ManDupAppend( Gia_Man_t * pNew, Gia_Man_t * pTwo )
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 );
pObj->Value = fShareCis ? Gia_ManCiLit(pNew, Gia_ObjCioId(pObj)) : Gia_ManAppendCi( pNew );
else if ( Gia_ObjIsCo(pObj) )
pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
}
@ -6041,7 +6041,7 @@ Vec_Wec_t * Gia_ManCollectIntTfos( Gia_Man_t * p, Vec_Int_t * vVarNums )
Gia_Man_t * Gia_ManDupCofs( Gia_Man_t * p, Vec_Int_t * vVarNums )
{
int i, iLit, nMints = 1 << Vec_IntSize(vVarNums);
Vec_Int_t * vOutLits = Vec_IntAlloc( nMints * Gia_ManCoNum(p) );
Vec_Int_t * vOutLits = Vec_IntStartFull( nMints * Gia_ManCoNum(p) );
Vec_Wec_t * vTfos = Gia_ManCollectIntTfos( p, vVarNums );
Gia_Man_t * pNew, * pTemp; Gia_Obj_t * pObj;
assert( Gia_ManRegNum(p) == 0 );
@ -6057,7 +6057,7 @@ Gia_Man_t * Gia_ManDupCofs( Gia_Man_t * p, Vec_Int_t * vVarNums )
Gia_ManForEachAnd( p, pObj, i )
pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
Gia_ManForEachCo( p, pObj, i )
Vec_IntPush( vOutLits, Gia_ObjFanin0Copy(pObj) );
Vec_IntWriteEntry( vOutLits, i, Gia_ObjFanin0Copy(pObj) );
int m, g, x, b = 0;
for ( m = 1; m < nMints; m++ )
{
@ -6067,7 +6067,7 @@ Gia_Man_t * Gia_ManDupCofs( Gia_Man_t * p, Vec_Int_t * vVarNums )
Gia_ManForEachObjVec( vNode, p, pObj, i )
pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
Gia_ManForEachCo( p, pObj, i )
Vec_IntPush( vOutLits, Gia_ObjFanin0Copy(pObj) );
Vec_IntWriteEntry( vOutLits, g * Gia_ManCoNum(p) + i, Gia_ObjFanin0Copy(pObj) );
}
assert( Vec_IntFindMin(vOutLits) >= 0 );
Vec_IntForEachEntry( vOutLits, iLit, i )
@ -6272,6 +6272,40 @@ Gia_Man_t * Gia_ManDupFanouts( Gia_Man_t * p )
return pNew;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManDupChoicesMarkTfi_rec( Gia_Man_t * pGia, int iObj )
{
if ( Gia_ObjIsTravIdCurrentId(pGia, iObj) )
return;
Gia_ObjSetTravIdCurrentId(pGia, iObj);
Gia_Obj_t * pObj = Gia_ManObj(pGia, iObj);
if ( !Gia_ObjIsAnd(pObj) )
return;
Gia_ManDupChoicesMarkTfi_rec( pGia, Gia_ObjFaninId0(pObj, iObj) );
Gia_ManDupChoicesMarkTfi_rec( pGia, Gia_ObjFaninId1(pObj, iObj) );
Gia_Obj_t * pSibl = Gia_ObjSiblObj( pGia, iObj );
if ( pSibl ) Gia_ManDupChoicesMarkTfi_rec( pGia, Gia_ObjId(pGia, pSibl) );
}
int Gia_ManDupChoicesCheckOverlap( Gia_Man_t * pGia, int iObj, int iFan0, int iFan1 )
{
Gia_ManIncrementTravId( pGia );
Gia_ManDupChoicesMarkTfi_rec( pGia, Gia_ObjFaninId0(Gia_ManObj(pGia, iObj), iObj) );
Gia_ManDupChoicesMarkTfi_rec( pGia, Gia_ObjFaninId1(Gia_ManObj(pGia, iObj), iObj) );
if ( Gia_ObjIsTravIdCurrentId(pGia, iFan0) || Gia_ObjIsTravIdCurrentId(pGia, iFan1) )
return 1;
return 0;
}
/**Function*************************************************************
Synopsis [Reorders choice nodes.]
@ -6288,14 +6322,24 @@ void Gia_ManPrintChoices( Gia_Man_t * p )
Gia_Obj_t * pObj; int i;
Gia_ManForEachAnd( p, pObj, i )
if ( p->pSibls[i] )
printf( "%d -> %d\n", i, p->pSibls[i] );
printf( "%d -> %d ", i, p->pSibls[i] );
}
void Gia_ManReorderChoices_rec( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pObj )
{
if ( ~pObj->Value )
return;
assert( Gia_ObjIsAnd(pObj) );
Gia_Obj_t * pSibl = Gia_ObjSiblObj(p, Gia_ObjId(p, pObj));
int ObjId = Gia_ObjId(p, pObj);
Gia_Obj_t * pSibl = Gia_ObjSiblObj(p, ObjId);
if ( pSibl ) {
int SiblId = Gia_ObjId(p, pSibl);
if ( Gia_ManDupChoicesCheckOverlap( p, SiblId, Gia_ObjFaninId0(pObj, ObjId), Gia_ObjFaninId1(pObj, ObjId) ) ) {
assert( p->pSibls[ObjId] == SiblId );
p->pSibls[ObjId] = p->pSibls[SiblId];
Gia_ManReorderChoices_rec( pNew, p, pObj );
return;
}
}
Gia_ManReorderChoices_rec( pNew, p, Gia_ObjFanin0(pObj) );
Gia_ManReorderChoices_rec( pNew, p, Gia_ObjFanin1(pObj) );
if ( pSibl ) Gia_ManReorderChoices_rec( pNew, p, pSibl );

View File

@ -1192,9 +1192,9 @@ Gia_Man_t * Gia_ManGenNeuron( char * pFileName, int nIBits, int nLutSize, int fD
SeeAlso []
***********************************************************************/
Gia_Man_t * Gia_ManDupGenComp( int nBits, int fInterleave )
Gia_Man_t * Gia_ManDupGenComp( int nBits, int fInterleave, int fSigned )
{
Gia_Man_t * pNew, * pTemp; int i, iLit = 1;
Gia_Man_t * pNew, * pTemp; int i, iLit = 1, iLitXor = 0, iLitB = 0;
Vec_Int_t * vBitsA = Vec_IntAlloc( nBits + 1 );
Vec_Int_t * vBitsB = Vec_IntAlloc( nBits + 1 );
pNew = Gia_ManStart( 6*nBits+10 );
@ -1211,6 +1211,10 @@ Gia_Man_t * Gia_ManDupGenComp( int nBits, int fInterleave )
for ( i = 0; i < nBits; i++ )
Vec_IntPush( vBitsB, Gia_ManAppendCi(pNew) );
}
if ( fSigned ) {
iLitXor = Gia_ManHashXor( pNew, Vec_IntPop(vBitsA), (iLitB = Vec_IntPop(vBitsB)) );
nBits--;
}
Vec_IntPush( vBitsA, 0 );
Vec_IntPush( vBitsB, 0 );
for ( i = 0; i < nBits; i++ ) {
@ -1227,7 +1231,10 @@ Gia_Man_t * Gia_ManDupGenComp( int nBits, int fInterleave )
int iOrLit = Gia_ManHashOr(pNew, iOrLit0, iOrLit1 );
iLit = Gia_ManHashOr(pNew, Abc_LitNot(iLit), iOrLit );
}
Gia_ManAppendCo( pNew, Abc_LitNotCond(iLit, nBits&1) );
iLit = Abc_LitNotCond(iLit, nBits&1);
if ( fSigned )
iLit = Gia_ManHashMux(pNew, iLitXor, iLitB, iLit );
Gia_ManAppendCo( pNew, iLit );
pNew = Gia_ManCleanup( pTemp = pNew );
Gia_ManStop( pTemp );
Vec_IntFree( vBitsA );

View File

@ -2373,6 +2373,38 @@ Gia_Man_t * Gia_GenPutOnTop( char ** pFNames, int nFNames )
return pNew;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Gia_Man_t * Gia_ManDupFromArray( int * pObjs, int nObjs, int nIns, int nLatches, int nOuts, int nAnds )
{
Gia_Man_t * pNew = Gia_ManStart( nObjs ); int i;
for ( i = 0; i < nIns + nLatches; i++ )
Gia_ManAppendCi(pNew);
for ( i = 0; i < nAnds; i++ )
{
int uLit = 2*(1+nIns+nLatches+i);
int uLit0 = pObjs[uLit+0];
int uLit1 = pObjs[uLit+1];
int uLit2 = Gia_ManAppendAnd( pNew, uLit0, uLit1 );
assert( uLit2 == uLit );
}
for ( i = 0; i < nOuts + nLatches; i++ )
Gia_ManAppendCo( pNew, pObjs[2*(nObjs-nOuts-nLatches+i)+0] );
Gia_ManSetRegNum(pNew, nLatches);
return pNew;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////

View File

@ -296,7 +296,7 @@ void Gia_ManStochSynthesis( Vec_Ptr_t * vAigs, char * pScript )
SeeAlso []
***********************************************************************/
int Gia_ManFilterPartitions( Gia_Man_t * p, Vec_Ptr_t * vvIns, Vec_Ptr_t * vvNodes, Vec_Ptr_t * vvOuts, Vec_Ptr_t * vWins, Vec_Int_t * vGains )
int Gia_ManFilterPartitions( Gia_Man_t * p, Vec_Ptr_t * vvIns, Vec_Ptr_t * vvNodes, Vec_Ptr_t * vvOuts, Vec_Ptr_t * vWins, Vec_Int_t * vGains, int fDelayOpt )
{
int RetValue = Vec_PtrSize(vvIns);
Vec_Ptr_t * vvInsNew = Vec_PtrAlloc( 10 );
@ -312,8 +312,8 @@ int Gia_ManFilterPartitions( Gia_Man_t * p, Vec_Ptr_t * vvIns, Vec_Ptr_t * vvNod
Vec_PtrPush( vvInsNew, Vec_IntDup((Vec_Int_t *)Vec_PtrEntry(vvIns, iEntry)) );
Vec_PtrPush( vvOutsNew, Vec_IntDup((Vec_Int_t *)Vec_PtrEntry(vvOuts, iEntry)) );
Vec_PtrPush( vvWinsNew, Gia_ManDupDfs((Gia_Man_t *)Vec_PtrEntry(vWins, iEntry)) );
extern void Gia_ManMarkTfiTfo( Vec_Int_t * vOne, Gia_Man_t * pMan );
Gia_ManMarkTfiTfo( (Vec_Int_t *)Vec_PtrEntryLast(vvInsNew), p );
extern void Gia_ManMarkTfiTfo( Vec_Int_t * vOne, Gia_Man_t * pMan, int fDelayOpt );
Gia_ManMarkTfiTfo( (Vec_Int_t *)Vec_PtrEntryLast(vvInsNew), p, fDelayOpt );
Vec_IntForEachEntry( vGains, Gain, i ) {
if ( Gain < 0 )
continue;
@ -556,12 +556,14 @@ void Gia_ManSelectRemove( Vec_Wec_t * vSupps, Vec_Int_t * vOne )
Vec_WecRemoveEmpty( vSupps );
}
// marks TFI/TFO of this one
void Gia_ManMarkTfiTfo( Vec_Int_t * vOne, Gia_Man_t * pMan )
void Gia_ManMarkTfiTfo( Vec_Int_t * vOne, Gia_Man_t * pMan, int fDelayOpt )
{
int i; Gia_Obj_t * pObj;
Gia_ManForEachObjVec( vOne, pMan, pObj, i ) {
//Gia_ObjSetTravIdPrevious(pMan, pObj);
//Gia_ObjDfsMark_rec( pMan, pObj );
if ( fDelayOpt ) {
Gia_ObjSetTravIdPrevious(pMan, pObj);
Gia_ObjDfsMark_rec( pMan, pObj );
}
Gia_ObjSetTravIdPrevious(pMan, pObj);
Gia_ObjDfsMark2_rec( pMan, pObj );
}
@ -632,7 +634,7 @@ Vec_Ptr_t * Gia_ManDeriveWinInsAll( Vec_Wec_t * vSupps, int nSuppMax, Gia_Man_t
}
return vRes;
}
Gia_Man_t * Gia_ManDupFromArrays( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * vAnds, Vec_Int_t * vCos )
Gia_Man_t * Gia_ManDupFromArrays( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * vAnds, Vec_Int_t * vCos, Vec_Int_t * vLevels[2], int nLevels )
{
Gia_Man_t * pNew;
Gia_Obj_t * pObj;
@ -647,23 +649,20 @@ Gia_Man_t * Gia_ManDupFromArrays( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * v
pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
Gia_ManForEachObjVec( vCos, p, pObj, i )
pObj->Value = Gia_ManAppendCo( pNew, pObj->Value );
return pNew;
}
Vec_Ptr_t * Gia_ManDupWindows( Gia_Man_t * pMan, Vec_Ptr_t * vvIns, Vec_Ptr_t * vvNodes, Vec_Ptr_t * vvOuts )
{
Vec_Int_t * vNodes; int i;
Vec_Ptr_t * vWins = Vec_PtrAlloc( Vec_PtrSize(vvIns) );
assert( Vec_PtrSize(vvIns) == Vec_PtrSize(vvNodes) );
assert( Vec_PtrSize(vvOuts) == Vec_PtrSize(vvNodes) );
Gia_ManFillValue( pMan );
Gia_ManCleanMark01( pMan );
Vec_PtrForEachEntry( Vec_Int_t *, vvNodes, vNodes, i ) {
Vec_Int_t * vIns = (Vec_Int_t *)Vec_PtrEntry(vvIns, i);
Vec_Int_t * vOuts = (Vec_Int_t *)Vec_PtrEntry(vvOuts, i);
Gia_Man_t * pNew = Gia_ManDupFromArrays( pMan, vIns, vNodes, vOuts );
Vec_PtrPush( vWins, pNew );
if ( vLevels[0] && vLevels[1] ) {
pNew->vCiArrs = Vec_IntAlloc( Gia_ManCiNum(pNew) );
Gia_ManForEachObjVec( vCis, p, pObj, i ) {
// Vec_IntPush( pNew->vCiArrs, Gia_ObjLevel(p, pObj) );
Vec_IntPush( pNew->vCiArrs, Vec_IntEntry(vLevels[0], Gia_ObjId(p, pObj)) );
}
pNew->vCoReqs = Vec_IntAlloc( Gia_ManCoNum(pNew) );
Gia_ManForEachObjVec( vCos, p, pObj, i ) {
// Vec_IntPush( pNew->vCoReqs, nLevels - Gia_ObjLevel(p, pObj) );
Vec_IntPush( pNew->vCoReqs, nLevels + 1 - Vec_IntEntry(vLevels[1], Gia_ObjId(p, pObj)) );
assert( Gia_ObjIsAnd(pObj) );
}
}
return vWins;
return pNew;
}
int Gia_ManLevelR( Gia_Man_t * pMan )
{
@ -675,7 +674,35 @@ int Gia_ManLevelR( Gia_Man_t * pMan )
Gia_ObjSetLevel( pMan, pNode, 0 );
return LevelMax;
}
Vec_Ptr_t * Gia_ManExtractPartitions( Gia_Man_t * pMan, int Iter, int nSuppMax, Vec_Ptr_t ** pvIns, Vec_Ptr_t ** pvOuts, Vec_Ptr_t ** pvNodes, int fOverlap )
Vec_Ptr_t * Gia_ManDupWindows( Gia_Man_t * pMan, Vec_Ptr_t * vvIns, Vec_Ptr_t * vvNodes, Vec_Ptr_t * vvOuts, int fDelayOpt )
{
// compute direct and reverse level
Vec_Int_t * vLevels[2] = {NULL};
if ( fDelayOpt ) {
int Levels[2];
Levels[0] = Gia_ManLevelNum( pMan );
ABC_SWAP( Vec_Int_t *, vLevels[0], pMan->vLevels );
Levels[1] = Gia_ManLevelRNum( pMan );
ABC_SWAP( Vec_Int_t *, vLevels[1], pMan->vLevels );
assert( (Levels[0] + 1) == Levels[1] );
}
Vec_Int_t * vNodes; int i;
Vec_Ptr_t * vWins = Vec_PtrAlloc( Vec_PtrSize(vvIns) );
assert( Vec_PtrSize(vvIns) == Vec_PtrSize(vvNodes) );
assert( Vec_PtrSize(vvOuts) == Vec_PtrSize(vvNodes) );
Gia_ManFillValue( pMan );
Gia_ManCleanMark01( pMan );
Vec_PtrForEachEntry( Vec_Int_t *, vvNodes, vNodes, i ) {
Vec_Int_t * vIns = (Vec_Int_t *)Vec_PtrEntry(vvIns, i);
Vec_Int_t * vOuts = (Vec_Int_t *)Vec_PtrEntry(vvOuts, i);
Gia_Man_t * pNew = Gia_ManDupFromArrays( pMan, vIns, vNodes, vOuts, vLevels, pMan->nLevels );
Vec_PtrPush( vWins, pNew );
}
Vec_IntFreeP( &vLevels[0] );
Vec_IntFreeP( &vLevels[1] );
return vWins;
}
Vec_Ptr_t * Gia_ManExtractPartitions( Gia_Man_t * pMan, int Iter, int nSuppMax, Vec_Ptr_t ** pvIns, Vec_Ptr_t ** pvOuts, Vec_Ptr_t ** pvNodes, int fOverlap, int fDelayOpt )
{
// if ( Gia_ManCiNum(pMan) <= nSuppMax ) {
// Vec_Ptr_t * vWins = Vec_PtrAlloc( 1 );
@ -695,7 +722,7 @@ Vec_Ptr_t * Gia_ManExtractPartitions( Gia_Man_t * pMan, int Iter, int nSuppMax,
Vec_Ptr_t * vIns = Gia_ManDeriveWinInsAll( vSupps, nSuppMax, pMan, fOverlap );
Vec_Ptr_t * vNodes = Gia_ManDeriveWinNodesAll( pMan, vIns, vStore );
Vec_Ptr_t * vOuts = Gia_ManDeriveWinOutsAll( pMan, vNodes );
Vec_Ptr_t * vWins = Gia_ManDupWindows( pMan, vIns, vNodes, vOuts );
Vec_Ptr_t * vWins = Gia_ManDupWindows( pMan, vIns, vNodes, vOuts, fDelayOpt );
Vec_WecFree( vSupps );
Vec_WecFree( vStore );
*pvIns = vIns;
@ -742,7 +769,7 @@ void Gia_ManCollectNodes( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * vAnds, Ve
Vec_IntForEachEntry( vCos, iObj, i )
Gia_ManCollectNodes_rec( p, iObj, vAnds );
}
Gia_Man_t * Gia_ManDupDivideOne( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * vAnds, Vec_Int_t * vCos )
Gia_Man_t * Gia_ManDupDivideOne( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * vAnds, Vec_Int_t * vCos, Vec_Int_t * vLevels[2], int nLevels )
{
Vec_Int_t * vMapping; int i;
Gia_Man_t * pNew; Gia_Obj_t * pObj;
@ -757,8 +784,16 @@ Gia_Man_t * Gia_ManDupDivideOne( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * vA
Gia_ManForEachObjVec( vCos, p, pObj, i )
Gia_ManAppendCo( pNew, pObj->Value );
assert( Gia_ManCiNum(pNew) > 0 && Gia_ManCoNum(pNew) > 0 );
if ( !Gia_ManHasMapping(p) )
if ( !Gia_ManHasMapping(p) ) {
if ( vLevels[0] == NULL ) return pNew;
pNew->vCiArrs = Vec_IntAlloc( Gia_ManCiNum(pNew) );
Gia_ManForEachObjVec( vCis, p, pObj, i )
Vec_IntPush( pNew->vCiArrs, Gia_ObjLevel(p, pObj) );
pNew->vCoReqs = Vec_IntAlloc( Gia_ManCoNum(pNew) );
Gia_ManForEachObjVec( vCos, p, pObj, i )
Vec_IntPush( pNew->vCoReqs, nLevels - Gia_ObjLevel(p, pObj) );
return pNew;
}
vMapping = Vec_IntAlloc( 4*Gia_ManObjNum(pNew) );
Vec_IntFill( vMapping, Gia_ManObjNum(pNew), 0 );
Gia_ManForEachObjVec( vAnds, p, pObj, i )
@ -776,17 +811,29 @@ Gia_Man_t * Gia_ManDupDivideOne( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * vA
pNew->vMapping = vMapping;
return pNew;
}
Vec_Ptr_t * Gia_ManDupDivide( Gia_Man_t * p, Vec_Wec_t * vCis, Vec_Wec_t * vAnds, Vec_Wec_t * vCos, char * pScript, int nProcs, int TimeOut )
Vec_Ptr_t * Gia_ManDupDivide( Gia_Man_t * p, Vec_Wec_t * vCis, Vec_Wec_t * vAnds, Vec_Wec_t * vCos, char * pScript, int nProcs, int TimeOut, int fDelayOpt )
{
// compute direct and reverse level
Vec_Int_t * vLevels[2] = {NULL};
if ( fDelayOpt ) {
int Levels[2];
Levels[0] = Gia_ManLevelNum( p );
ABC_SWAP( Vec_Int_t *, vLevels[0], p->vLevels );
Levels[1] = Gia_ManLevelRNum( p );
ABC_SWAP( Vec_Int_t *, vLevels[1], p->vLevels );
// assert( Levels[0] == Levels[1] );
}
Vec_Ptr_t * vAigs = Vec_PtrAlloc( Vec_WecSize(vCis) ); int i;
for ( i = 0; i < Vec_WecSize(vCis); i++ )
{
Gia_ManCollectNodes( p, Vec_WecEntry(vCis, i), Vec_WecEntry(vAnds, i), Vec_WecEntry(vCos, i) );
Vec_PtrPush( vAigs, Gia_ManDupDivideOne(p, Vec_WecEntry(vCis, i), Vec_WecEntry(vAnds, i), Vec_WecEntry(vCos, i)) );
Vec_PtrPush( vAigs, Gia_ManDupDivideOne(p, Vec_WecEntry(vCis, i), Vec_WecEntry(vAnds, i), Vec_WecEntry(vCos, i), vLevels, p->nLevels) );
}
//Gia_ManStochSynthesis( vAigs, pScript );
Vec_Int_t * vGains = Gia_StochProcess( vAigs, pScript, nProcs, TimeOut, 0 );
Vec_IntFree( vGains );
Vec_IntFreeP( &vLevels[0] );
Vec_IntFreeP( &vLevels[1] );
return vAigs;
}
Gia_Man_t * Gia_ManDupStitch( Gia_Man_t * p, Vec_Wec_t * vCis, Vec_Wec_t * vAnds, Vec_Wec_t * vCos, Vec_Ptr_t * vAigs, int fHash )
@ -982,7 +1029,7 @@ Vec_Wec_t * Gia_ManStochOutputs( Gia_Man_t * p, Vec_Wec_t * vAnds )
SeeAlso []
***********************************************************************/
void Gia_ManStochSyn( int nSuppMax, int nMaxSize, int nIters, int TimeOut, int Seed, int fVerbose, char * pScript, int nProcs )
void Gia_ManStochSyn( int nSuppMax, int nMaxSize, int nIters, int TimeOut, int Seed, int fVerbose, char * pScript, int nProcs, int fDelayOpt )
{
abctime nTimeToStop = TimeOut ? Abc_Clock() + TimeOut * CLOCKS_PER_SEC : 0;
abctime clkStart = Abc_Clock();
@ -1008,7 +1055,7 @@ void Gia_ManStochSyn( int nSuppMax, int nMaxSize, int nIters, int TimeOut, int S
Vec_Wec_t * vAnds = Gia_ManStochNodes( pGia, nMaxSize, Abc_Random(0) & 0x7FFFFFFF );
Vec_Wec_t * vIns = Gia_ManStochInputs( pGia, vAnds );
Vec_Wec_t * vOuts = Gia_ManStochOutputs( pGia, vAnds );
Vec_Ptr_t * vAigs = Gia_ManDupDivide( pGia, vIns, vAnds, vOuts, pScript, nProcs, TimeOut );
Vec_Ptr_t * vAigs = Gia_ManDupDivide( pGia, vIns, vAnds, vOuts, pScript, nProcs, TimeOut, fDelayOpt );
Gia_Man_t * pNew = Gia_ManDupStitchMap( pGia, vIns, vAnds, vOuts, vAigs );
int fMapped = Gia_ManHasMapping(pGia) && Gia_ManHasMapping(pNew);
Abc_FrameUpdateGia( Abc_FrameGetGlobalFrame(), pNew );
@ -1039,9 +1086,9 @@ void Gia_ManStochSyn( int nSuppMax, int nMaxSize, int nIters, int TimeOut, int S
extern Gia_Man_t * Gia_ManDupInsertWindows( Gia_Man_t * p, Vec_Ptr_t * vvIns, Vec_Ptr_t * vvOuts, Vec_Ptr_t * vAigs );
abctime clk = Abc_Clock();
Gia_Man_t * pGia = Gia_ManDup( Abc_FrameReadGia(Abc_FrameGetGlobalFrame()) ); Gia_ManStaticFanoutStart(pGia);
Vec_Ptr_t * vAigs = Gia_ManExtractPartitions( pGia, i, nSuppMax, &vIns, &vOuts, &vNodes, fOverlap );
Vec_Ptr_t * vAigs = Gia_ManExtractPartitions( pGia, i, nSuppMax, &vIns, &vOuts, &vNodes, fOverlap, fDelayOpt );
Vec_Int_t * vGains = Gia_StochProcess( vAigs, pScript, nProcs, TimeOut, 0 );
int nPartsInit = fOverlap ? Gia_ManFilterPartitions( pGia, vIns, vNodes, vOuts, vAigs, vGains ) : Vec_PtrSize(vIns);
int nPartsInit = fOverlap ? Gia_ManFilterPartitions( pGia, vIns, vNodes, vOuts, vAigs, vGains, fDelayOpt ) : Vec_PtrSize(vIns);
Gia_Man_t * pNew = Gia_ManDupInsertWindows( pGia, vIns, vOuts, vAigs ); Gia_ManStaticFanoutStop(pGia);
Abc_FrameUpdateGia( Abc_FrameGetGlobalFrame(), pNew );
if ( fVerbose )

View File

@ -6,6 +6,7 @@ SRC += src/aig/gia/giaAig.c \
src/aig/gia/giaBalLut.c \
src/aig/gia/giaBalMap.c \
src/aig/gia/giaBidec.c \
src/aig/gia/giaBsFind.c \
src/aig/gia/giaCCof.c \
src/aig/gia/giaCex.c \
src/aig/gia/giaClp.c \

View File

@ -636,11 +636,13 @@ static int Abc_CommandAbc9GenComp ( Abc_Frame_t * pAbc, int argc, cha
static int Abc_CommandAbc9GenSorter ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9GenNeuron ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9GenAdder ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9GenPrefix ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Window ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9FunAbs ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9DsdInfo ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9FunTrace ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9MulFind ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9BsFind ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9AndCare ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Test ( Abc_Frame_t * pAbc, int argc, char ** argv );
@ -1460,12 +1462,14 @@ void Abc_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "ABC9", "&gensorter", Abc_CommandAbc9GenSorter, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&genneuron", Abc_CommandAbc9GenNeuron, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&genadder", Abc_CommandAbc9GenAdder, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&genprefix", Abc_CommandAbc9GenPrefix, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&window", Abc_CommandAbc9Window, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&funabs", Abc_CommandAbc9FunAbs, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&dsdinfo", Abc_CommandAbc9DsdInfo, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&funtrace", Abc_CommandAbc9FunTrace, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&mulfind", Abc_CommandAbc9MulFind, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&andcare", Abc_CommandAbc9AndCare, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&bsfind", Abc_CommandAbc9BsFind, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&andcare", Abc_CommandAbc9AndCare, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&test", Abc_CommandAbc9Test, 0 );
@ -8615,7 +8619,9 @@ int Abc_CommandResubstitute( Abc_Frame_t * pAbc, int argc, char ** argv )
int fUseZeros;
int fVerbose;
int fVeryVerbose;
extern int Abc_NtkResubstitute( Abc_Ntk_t * pNtk, int nCutsMax, int nNodesMax, int nMinSaved, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose );
int Log2Probs;
int Log2Divs;
extern int Abc_NtkResubstitute( Abc_Ntk_t * pNtk, int nCutsMax, int nNodesMax, int nMinSaved, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int Log2Probs, int Log2Divs );
// set defaults
nCutsMax = 8;
@ -8626,8 +8632,10 @@ int Abc_CommandResubstitute( Abc_Frame_t * pAbc, int argc, char ** argv )
fUseZeros = 0;
fVerbose = 0;
fVeryVerbose = 0;
Log2Probs = 0;
Log2Divs = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "KNMFlzvwh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "KNMFlzvwhPDV" ) ) != EOF )
{
switch ( c )
{
@ -8675,6 +8683,41 @@ int Abc_CommandResubstitute( Abc_Frame_t * pAbc, int argc, char ** argv )
if ( nLevelsOdc < 0 )
goto usage;
break;
case 'P':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
goto usage;
}
Log2Probs = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( Log2Probs < 0 )
goto usage;
break;
case 'D':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
goto usage;
}
Log2Divs = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( Log2Divs < 0 )
goto usage;
break;
case 'V':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-V\" should be followed by an integer.\n" );
goto usage;
}
nCutsMax = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nCutsMax < 0 )
goto usage;
break;
case 'l':
fUpdateLevel ^= 1;
break;
@ -8725,7 +8768,7 @@ int Abc_CommandResubstitute( Abc_Frame_t * pAbc, int argc, char ** argv )
}
// modify the current network
if ( !Abc_NtkResubstitute( pNtk, nCutsMax, nNodesMax, nMinSaved, nLevelsOdc, fUpdateLevel, fVerbose, fVeryVerbose ) )
if ( !Abc_NtkResubstitute( pNtk, nCutsMax, nNodesMax, nMinSaved, nLevelsOdc, fUpdateLevel, fVerbose, fVeryVerbose, Log2Probs, Log2Divs ) )
{
Abc_Print( -1, "Refactoring has failed.\n" );
return 1;
@ -8733,7 +8776,7 @@ int Abc_CommandResubstitute( Abc_Frame_t * pAbc, int argc, char ** argv )
return 0;
usage:
Abc_Print( -2, "usage: resub [-KNMF <num>] [-lzvwh]\n" );
Abc_Print( -2, "usage: resub [-KNMF <num>] [-lzvwh] [-PDV <num>]\n" );
Abc_Print( -2, "\t performs technology-independent restructuring of the AIG\n" );
Abc_Print( -2, "\t-K <num> : the max cut size (%d <= num <= %d) [default = %d]\n", RS_CUT_MIN, RS_CUT_MAX, nCutsMax );
Abc_Print( -2, "\t-N <num> : the max number of nodes to add (0 <= num <= 3) [default = %d]\n", nNodesMax );
@ -8743,7 +8786,16 @@ usage:
Abc_Print( -2, "\t-z : toggle using zero-cost replacements [default = %s]\n", fUseZeros? "yes": "no" );
Abc_Print( -2, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-w : toggle verbose printout of ODC computation [default = %s]\n", fVeryVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
Abc_Print( -2, "\t-h : print the command usage\n\n");
Abc_Print( -2, "\t When command line options '-P num', '-D num', and '-V num' are used,\n");
Abc_Print( -2, "\t this command does not perform resubstitution; instead, it dumps a binary file\n");
Abc_Print( -2, "\t containing 2^P resub problems, each containing 2^D-2 divs with support size V,\n");
Abc_Print( -2, "\t while the last two divisors are the offset and the onset of the function\n");
Abc_Print( -2, "\t (by default, the functions are completely specified; to get functions with don't-cares,\n");
Abc_Print( -2, "\t the user has to use command-line option '-F num' to enable the limited ODC computation)\n");
Abc_Print( -2, "\t-P <num> : the log2 of the number of problems to be dumped [default = %d]\n", Log2Probs );
Abc_Print( -2, "\t-D <num> : the log2 of the number of divisors to be collected (4 <= num <= 7) [default = %d]\n", Log2Divs );
Abc_Print( -2, "\t-V <num> : the support size of the function (%d <= num <= %d) [default = %d]\n", RS_CUT_MIN, RS_CUT_MAX, nCutsMax );
return 1;
}
@ -9196,11 +9248,11 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern Abc_Ntk_t * Abc_NtkLutCascadeGen( int nLutSize, int nStages, int nRails, int nShared, int fVerbose );
extern Abc_Ntk_t * Abc_NtkLutCascadeOne( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int nRails, int nIters, int nJRatio, int nZParam, int fXRail, int Seed, int fVerbose, int fVeryVerbose, char * pGuide, int nSubsets, int nBest );
extern void Abc_NtkLutCascadeFile( char * pFileName, int nVarNum, int nLutSize, int nLuts, int nRails, int nIters, int nJRatio, int nZParam, int Seed, int fVerbose, int fVeryVerbose, int fPrintMyu, int fPrintLev, int fXRail, int nSubsets, int nBest );
extern void Abc_NtkLutCascadeFile( char * pFileName, int nVarNum, int nLutSize, int nLuts, int nRails, int nIters, int nJRatio, int nZParam, int Seed, int fVerbose, int fVeryVerbose, int fPrintMyu, int fPrintLev, int fXRail, int nSubsets, int nBest, int fDump );
Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkRes; char * pGuide = NULL, * pFileName = NULL;
int c, nVarNum = -1, nLutSize = 6, nStages = 8, nRails = 1, nShared = 2, Seed = 0, nIters = 10, nJRatio = -1, nZParam = 5, fGen = 0, fPrintMyu = 0, fPrintLev = 0, fXRail = 0, nSubsets = 0, nBest = 0, fVerbose = 0, fVeryVerbose = 0;
int c, nVarNum = -1, nLutSize = 6, nStages = 8, nRails = 1, nShared = 2, Seed = 0, nIters = 10, nJRatio = -1, nZParam = 5, fGen = 0, fPrintMyu = 0, fPrintLev = 0, fXRail = 0, nSubsets = 0, nBest = 0, fDump = 0, fVerbose = 0, fVeryVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "KMRSCIZNGBFgmlxvwh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "KMRSCIZNGBFgmlxdvwh" ) ) != EOF )
{
switch ( c )
{
@ -9344,6 +9396,9 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
case 'x':
fXRail ^= 1;
break;
case 'd':
fDump ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
@ -9363,7 +9418,7 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Print( -1, "The number of variables should be given on the command line using switch \"-N <num>\".\n" );
return 1;
}
Abc_NtkLutCascadeFile( pFileName, nVarNum, nLutSize, nStages, nRails, nIters, nJRatio, nZParam, Seed, fVerbose, fVeryVerbose, fPrintMyu, fPrintLev, fXRail, nSubsets, nBest );
Abc_NtkLutCascadeFile( pFileName, nVarNum, nLutSize, nStages, nRails, nIters, nJRatio, nZParam, Seed, fVerbose, fVeryVerbose, fPrintMyu, fPrintLev, fXRail, nSubsets, nBest, fDump );
return 0;
}
if ( fGen )
@ -9410,7 +9465,7 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
return 0;
usage:
Abc_Print( -2, "usage: lutcasdec [-KMRCSIZNGB <num>] [-F <file>] [-gmlxvwh]\n" );
Abc_Print( -2, "usage: lutcasdec [-KMRCSIZNGB <num>] [-F <file>] [-gmlxdvwh]\n" );
Abc_Print( -2, "\t decomposes the primary output functions into LUT cascades\n" );
Abc_Print( -2, "\t-K <num> : the number of LUT inputs [default = %d]\n", nLutSize );
Abc_Print( -2, "\t-M <num> : the maximum delay (the number of stages) [default = %d]\n", nStages );
@ -9428,6 +9483,7 @@ usage:
Abc_Print( -2, "\t-m : toggle printing column multiplicity statistics [default = %s]\n", fPrintMyu? "yes": "no" );
Abc_Print( -2, "\t-l : toggle printing level counting statistics [default = %s]\n", fPrintLev? "yes": "no" );
Abc_Print( -2, "\t-x : toggle using extended cascade decomposition [default = %s]\n", fXRail? "yes": "no" );
Abc_Print( -2, "\t-d : toggle dumping non-decomposable functions into a file [default = %s]\n", fDump? "yes": "no" );
Abc_Print( -2, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-w : toggle additional verbose printout [default = %s]\n", fVeryVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
@ -10635,14 +10691,14 @@ int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv )
Bmc_EsPar_t Pars, * pPars = &Pars;
Bmc_EsParSetDefault( pPars );
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "INKTFUSYiaorfgvh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "NMKTFUSYiaorfgdvh" ) ) != EOF )
{
switch ( c )
{
case 'I':
case 'N':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
goto usage;
}
pPars->nVars = atoi(argv[globalUtilOptind]);
@ -10650,10 +10706,10 @@ int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv )
if ( pPars->nVars < 0 )
goto usage;
break;
case 'N':
case 'M':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
goto usage;
}
pPars->nNodes = atoi(argv[globalUtilOptind]);
@ -10739,6 +10795,9 @@ int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv )
case 'g':
pPars->fGlucose ^= 1;
break;
case 'd':
pPars->fDumpBlif ^= 1;
break;
case 'v':
pPars->fVerbose ^= 1;
break;
@ -10799,10 +10858,10 @@ int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv )
return 0;
usage:
Abc_Print( -2, "usage: lutexact [-INKTFUS <num>] [-Y string] [-iaorfgvh] <hex>\n" );
Abc_Print( -2, "usage: lutexact [-NMKTFUS <num>] [-Y string] [-iaorfgdvh] <hex>\n" );
Abc_Print( -2, "\t exact synthesis of I-input function using N K-input gates\n" );
Abc_Print( -2, "\t-I <num> : the number of input variables [default = %d]\n", pPars->nVars );
Abc_Print( -2, "\t-N <num> : the number of K-input nodes [default = %d]\n", pPars->nNodes );
Abc_Print( -2, "\t-N <num> : the number of input variables [default = %d]\n", pPars->nVars );
Abc_Print( -2, "\t-M <num> : the number of K-input nodes [default = %d]\n", pPars->nNodes );
Abc_Print( -2, "\t-K <num> : the number of node fanins [default = %d]\n", pPars->nLutSize );
Abc_Print( -2, "\t-T <num> : the runtime limit in seconds [default = %d]\n", pPars->RuntimeLim );
Abc_Print( -2, "\t-F <num> : the number of random functions to try [default = unused]\n" );
@ -10815,6 +10874,7 @@ usage:
Abc_Print( -2, "\t-r : toggle synthesizing a single-rail cascade [default = %s]\n", pPars->fLutCascade ? "yes" : "no" );
Abc_Print( -2, "\t-f : toggle fixing LUT inputs in cascade mapping [default = %s]\n", pPars->fLutInFixed ? "yes" : "no" );
Abc_Print( -2, "\t-g : toggle using Glucose 3.0 by Gilles Audemard and Laurent Simon [default = %s]\n", pPars->fGlucose ? "yes" : "no" );
Abc_Print( -2, "\t-d : toggle dumping decomposed networks into BLIF files [default = %s]\n", pPars->fDumpBlif ? "yes" : "no" );
Abc_Print( -2, "\t-v : toggle verbose printout [default = %s]\n", pPars->fVerbose ? "yes" : "no" );
Abc_Print( -2, "\t-h : print the command usage\n" );
Abc_Print( -2, "\t<hex> : truth table in hex notation\n" );
@ -20931,17 +20991,17 @@ usage:
***********************************************************************/
int Abc_CommandRewire( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern Abc_Ntk_t *Abc_ManRewire(Abc_Ntk_t *pNtk, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int nSeed, int fCheck, int fVerbose);
extern Abc_Ntk_t *Abc_ManRewire(Abc_Ntk_t *pNtk, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int nSeed, int fCheck, int fVerbose);
Abc_Ntk_t *pNtk, *pTemp;
Gia_Man_t *pExc = NULL;
FILE *pFile = NULL;
int c, nIters = 100000, nExpands = 128, nGrowth = 4, nDivs = -1, nFaninMax = 8, nSeed = 1, nTimeOut = 0, nVerbose = 1, nMode = 0, nMappedMode = 0, nDist = 0, fCheck = 0;
int c, nIters = 100000, nExpands = 128, nGrowth = 4, nDivs = -1, nFaninMax = 8, nSeed = 1, nTimeOut = 0, nVerbose = 1, nMode = 0, nMappedMode = 0, nDist = 0, fCheck = 0, fDch = 1, fTiming = 0;
float nLevelGrowRatio = 0;
Extra_UtilGetoptReset();
pNtk = Abc_FrameReadNtk(pAbc);
while ( ( c = Extra_UtilGetopt( argc, argv, "IEGDFSTMALRCVch" ) ) != EOF ) {
while ( ( c = Extra_UtilGetopt( argc, argv, "IEGDFSTMALRCVdtch" ) ) != EOF ) {
switch ( c ) {
case 'I':
if ( globalUtilOptind >= argc )
@ -21070,6 +21130,12 @@ int Abc_CommandRewire( Abc_Frame_t * pAbc, int argc, char ** argv )
case 'c':
fCheck ^= 1;
break;
case 'd':
fDch ^= 1;
break;
case 't':
fTiming ^= 1;
break;
case 'h':
default:
goto usage;
@ -21087,16 +21153,16 @@ int Abc_CommandRewire( Abc_Frame_t * pAbc, int argc, char ** argv )
}
if ( nMode == 0 && !Abc_NtkIsStrash(pNtk) )
{
Abc_Print( -1, "Rewiring works only for the AIG representation (run \"strash\").\n" );
Abc_Print( -1, "Rewiring operates only on specific network representations. Use \"strash\" to apply it to an AIG, or add the \"-M 1\" flag to enable it for a mapped network.\n" );
return 1;
}
if ( nMode >= 1 && Abc_FrameReadLibGen2() == NULL )
if ( nMode == 1 && Abc_FrameReadLibGen2() == NULL )
{
Abc_Print( -1, "Library is not available.\n" );
return 1;
}
pTemp = Abc_ManRewire( pNtk, pExc, nIters, nLevelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, nSeed, fCheck, nVerbose );
pTemp = Abc_ManRewire( pNtk, pExc, nIters, nLevelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, fDch, fTiming, nSeed, fCheck, nVerbose );
if ( pExc )
Gia_ManStop( pExc );
Abc_FrameReplaceCurrentNetwork( pAbc, pTemp );
@ -21111,13 +21177,15 @@ usage:
Abc_Print( -2, "\t-F <num> : the limit on the fanin count at a node [default = %d]\n", nFaninMax);
Abc_Print( -2, "\t-L <num> : localization distances (0: unlimited) [default = %d]\n", nDist);
Abc_Print( -2, "\t-R <num> : level constraint (0: unlimited, 1: preserve level) [default = %g]\n", nLevelGrowRatio);
Abc_Print( -2, "\t-M <num> : optimization target [default = %s]\n", nMode ? "area" : "AIG node" );
Abc_Print( -2, "\t-M <num> : optimization target [default = %s]\n", nMode ? "mapped" : "AIG" );
Abc_Print( -2, "\t-A <num> : mapper (0: amap, 1: &nf, 2: &simap) (experimental) [default = %d]\n", nMappedMode );
Abc_Print( -2, "\t-C <file> : AIGER specifying external cares\n");
Abc_Print( -2, "\t-S <num> : the random seed (0: random, >= 1: user defined) [default = %d]\n", nSeed );
Abc_Print( -2, "\t-T <num> : the timeout in seconds (0: unlimited) [default = %d]\n", nTimeOut );
Abc_Print( -2, "\t-V <num> : the verbosity level [default = %d]\n", nVerbose );
Abc_Print( -2, "\t-c : check the equivalence [default = %s]\n", fCheck ? "yes" : "no" );
Abc_Print( -2, "\t-c : check the equivalence [default = %s]\n", fCheck ? "yes" : "no" );
Abc_Print( -2, "\t-d : toggle perform \"dch\" before mapping [default = %s]\n", fDch ? "yes" : "no" );
Abc_Print( -2, "\t-t : toggle timing-driven rewiring [default = %s]\n", fTiming ? "yes" : "no" );
Abc_Print( -2, "\t-h : prints the command usage\n" );
Abc_Print( -2, "\n\tThis command was contributed by Jiun-Hao Chen from National Taiwan University.\n" );
return 1;
@ -21436,7 +21504,7 @@ int Abc_CommandIf( Abc_Frame_t * pAbc, int argc, char ** argv )
If_ManSetDefaultPars( pPars );
pPars->pLutLib = (If_LibLut_t *)Abc_FrameReadLibLut();
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "KCFAGRNTXYUZDEWSJqaflepmrsdbgxyzuojiktncvh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "KCFAGRNTXYUZDEWSJqalepmrsdbgxyzuojiktncfvh" ) ) != EOF )
{
switch ( c )
{
@ -21647,9 +21715,9 @@ int Abc_CommandIf( Abc_Frame_t * pAbc, int argc, char ** argv )
case 'r':
pPars->fExpRed ^= 1;
break;
case 'f':
pPars->fFancy ^= 1;
break;
//case 'f':
// pPars->fFancy ^= 1;
// break;
case 'l':
pPars->fLatchPaths ^= 1;
break;
@ -21704,6 +21772,9 @@ int Abc_CommandIf( Abc_Frame_t * pAbc, int argc, char ** argv )
case 'c':
pPars->fUseTtPerm ^= 1;
break;
case 'f':
pPars->fDumpFile ^= 1;
break;
case 'v':
pPars->fVerbose ^= 1;
break;
@ -22015,7 +22086,7 @@ usage:
sprintf(LutSize, "library" );
else
sprintf(LutSize, "%d", pPars->nLutSize );
Abc_Print( -2, "usage: if [-KCFAGRNTXYUZ num] [-DEW float] [-SJ str] [-qarlepmsdbgxyuojiktnczvh]\n" );
Abc_Print( -2, "usage: if [-KCFAGRNTXYUZ num] [-DEW float] [-SJ str] [-qarlepmsdbgxyuojiktnczfvh]\n" );
Abc_Print( -2, "\t performs FPGA technology mapping of the network\n" );
Abc_Print( -2, "\t-K num : the number of LUT inputs (2 < num < %d) [default = %s]\n", IF_MAX_LUTSIZE+1, LutSize );
Abc_Print( -2, "\t-C num : the max number of priority cuts (0 < num < 2^12) [default = %d]\n", pPars->nCutsMax );
@ -22056,6 +22127,7 @@ usage:
Abc_Print( -2, "\t-n : toggles computing DSDs of the cut functions [default = %s]\n", pPars->fUseDsd? "yes": "no" );
Abc_Print( -2, "\t-c : toggles computing truth tables in a new way [default = %s]\n", pPars->fUseTtPerm? "yes": "no" );
Abc_Print( -2, "\t-z : toggles deriving LUTs when mapping into LUT structures [default = %s]\n", pPars->fDeriveLuts? "yes": "no" );
Abc_Print( -2, "\t-f : toggles dumping truth tables into a binary file [default = %s]\n", pPars->fDumpFile? "yes": "no" );
Abc_Print( -2, "\t-v : toggles verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : prints the command usage\n");
return 1;
@ -39781,13 +39853,16 @@ int Abc_CommandAbc9Append( Abc_Frame_t * pAbc, int argc, char ** argv )
char * FileName, * pTemp;
char ** pArgvNew;
int nArgcNew;
int c;
int c, fShareCis = 0;
int fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "ivh" ) ) != EOF )
{
switch ( c )
{
case 'i':
fShareCis ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
@ -39827,14 +39902,20 @@ int Abc_CommandAbc9Append( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Print( -1, "Reading AIGER has failed.\n" );
return 0;
}
if ( fShareCis && Gia_ManCiNum(pAbc->pGia) != Gia_ManCiNum(pSecond) )
{
Abc_Print( -1, "The AIGs have different number of combinational inputs.\n" );
return 0;
}
// compute the miter
Gia_ManDupAppend( pAbc->pGia, pSecond );
Gia_ManDupAppend( pAbc->pGia, pSecond, fShareCis );
Gia_ManStop( pSecond );
return 0;
usage:
Abc_Print( -2, "usage: &append [-vh] <file>\n" );
Abc_Print( -2, "usage: &append [-ivh] <file>\n" );
Abc_Print( -2, "\t appends <file> to the current AIG using new PIs and POs\n" );
Abc_Print( -2, "\t-i : toggle sharing combinational inputs [default = %s]\n", fShareCis? "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> : AIGER file with the design to miter\n");
@ -46700,14 +46781,14 @@ usage:
***********************************************************************/
int Abc_CommandAbc9Rewire( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern Gia_Man_t *Gia_ManRewire(Gia_Man_t *pGia, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int nSeed, int fCheck, int fChoices, int fVerbose);
extern Gia_Man_t *Gia_ManRewire(Gia_Man_t *pGia, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int nSeed, int fCheck, int fChoices, int fVerbose);
FILE *pFile = NULL;
Gia_Man_t *pTemp, *pExc = NULL;
int c, nIters = 100000, nExpands = 128, nGrowth = 4, nDivs = -1, nFaninMax = 8, nSeed = 1, nTimeOut = 0, nVerbose = 1, nMode = 0, nMappedMode = 0, nDist = 0, fCheck = 0, fChoices = 0;
int c, nIters = 100000, nExpands = 128, nGrowth = 4, nDivs = -1, nFaninMax = 8, nSeed = 1, nTimeOut = 0, nVerbose = 1, nMode = 0, nMappedMode = 0, nDist = 0, fCheck = 0, fChoices = 0, fDch = 1, fTiming = 0;
float nLevelGrowRatio = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "IEGDFSTMALRCVcsh" ) ) != EOF ) {
while ( ( c = Extra_UtilGetopt( argc, argv, "IEGDFSTMALRCVcsdth" ) ) != EOF ) {
switch ( c ) {
case 'I':
if ( globalUtilOptind >= argc )
@ -46839,6 +46920,12 @@ int Abc_CommandAbc9Rewire( Abc_Frame_t * pAbc, int argc, char ** argv )
case 's':
fChoices ^= 1;
break;
case 'd':
fDch ^= 1;
break;
case 't':
fTiming ^= 1;
break;
case 'h':
default:
goto usage;
@ -46854,13 +46941,13 @@ int Abc_CommandAbc9Rewire( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Print( -1, "Empty GIA network.\n" );
return 1;
}
if ( nMode >= 1 && Abc_FrameReadLibGen2() == NULL )
if ( nMode == 1 && Abc_FrameReadLibGen2() == NULL )
{
Abc_Print( -1, "Library is not available.\n" );
return 1;
}
pTemp = Gia_ManRewire( pAbc->pGia, pExc, nIters, nLevelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, nSeed, fCheck, fChoices, nVerbose );
pTemp = Gia_ManRewire( pAbc->pGia, pExc, nIters, nLevelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, fDch, fTiming, nSeed, fCheck, fChoices, nVerbose );
if ( pExc )
Gia_ManStop( pExc );
Abc_FrameUpdateGia( pAbc, pTemp );
@ -46876,14 +46963,16 @@ usage:
Abc_Print( -2, "\t-F <num> : the limit on the fanin count at a node [default = %d]\n", nFaninMax);
Abc_Print( -2, "\t-L <num> : localization distances (0: unlimited) [default = %d]\n", nDist);
Abc_Print( -2, "\t-R <num> : level constraint (0: unlimited, 1: preserve level) [default = %g]\n", nLevelGrowRatio);
Abc_Print( -2, "\t-M <num> : optimization target [default = %s]\n", nMode ? "area" : "AIG node" );
Abc_Print( -2, "\t-M <num> : optimization target [default = %s]\n", nMode ? "mapped" : "aig" );
Abc_Print( -2, "\t-A <num> : mapper (0: amap, 1: &nf, 2: &simap) (experimental) [default = %d]\n", nMappedMode );
Abc_Print( -2, "\t-C <file> : AIGER specifying external cares\n");
Abc_Print( -2, "\t-S <num> : the random seed (0: random, >= 1: user defined) [default = %d]\n", nSeed );
Abc_Print( -2, "\t-T <num> : the timeout in seconds (0: unlimited) [default = %d]\n", nTimeOut );
Abc_Print( -2, "\t-V <num> : the verbosity level [default = %d]\n", nVerbose );
Abc_Print( -2, "\t-c : check the equivalence [default = %s]\n", fCheck ? "yes" : "no" );
Abc_Print( -2, "\t-s : toggle accumulating structural choices [default = %s]\n", fChoices ? "yes" : "no" );
Abc_Print( -2, "\t-c : check the equivalence [default = %s]\n", fCheck ? "yes" : "no" );
Abc_Print( -2, "\t-s : toggle accumulating structural choices [default = %s]\n", fChoices ? "yes" : "no" );
Abc_Print( -2, "\t-d : toggle using \"dch\" before mapping [default = %s]\n", fDch ? "yes" : "no" );
Abc_Print( -2, "\t-t : toggle timing-driven re-wiring [default = %s]\n", fTiming ? "yes" : "no" );
Abc_Print( -2, "\t-h : prints the command usage\n" );
Abc_Print( -2, "\n\tThis command was contributed by Jiun-Hao Chen from National Taiwan University.\n" );
return 1;
@ -47479,8 +47568,8 @@ usage:
Abc_Print( -2, "\t-f : toggle using lighter logic synthesis [default = %s]\n", pPars->fLightSynth? "yes": "no" );
Abc_Print( -2, "\t-r : toggle skipping choices with redundant support [default = %s]\n", pPars->fSkipRedSupp? "yes": "no" );
Abc_Print( -2, "\t-e : toggle computing and merging equivalences [default = %s]\n", fEquiv? "yes": "no" );
Abc_Print( -2, "\t-m : toggle minimizing logic level after merging equivalences [default = %s]\n", fRandom? "yes": "no" );
Abc_Print( -2, "\t-n : toggle selecting random choices while merging equivalences [default = %s]\n", fMinLevel? "yes": "no" );
Abc_Print( -2, "\t-m : toggle minimizing logic level after merging equivalences [default = %s]\n", fMinLevel? "yes": "no" );
Abc_Print( -2, "\t-n : toggle selecting random choices while merging equivalences [default = %s]\n", fRandom? "yes": "no" );
Abc_Print( -2, "\t-g : toggle using GIA to prove equivalences [default = %s]\n", pPars->fUseGia? "yes": "no" );
Abc_Print( -2, "\t-c : toggle using circuit-based SAT vs. MiniSat [default = %s]\n", pPars->fUseCSat? "yes": "no" );
Abc_Print( -2, "\t-x : toggle using new choice computation [default = %s]\n", pPars->fUseNew? "yes": "no" );
@ -53619,10 +53708,10 @@ usage:
***********************************************************************/
int Abc_CommandAbc9StochSyn( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern void Gia_ManStochSyn( int nSuppMax, int nMaxSize, int nIters, int TimeOut, int Seed, int fVerbose, char * pScript, int nProcs );
int c, nSuppMax = 0, nMaxSize = 1000, nIters = 10, TimeOut = 0, Seed = 0, nProcs = 1, fVerbose = 0; char * pScript;
extern void Gia_ManStochSyn( int nSuppMax, int nMaxSize, int nIters, int TimeOut, int Seed, int fVerbose, char * pScript, int nProcs, int fDelayOpt );
int c, nSuppMax = 0, nMaxSize = 1000, nIters = 10, TimeOut = 0, Seed = 0, nProcs = 1, fDelayOpt = 0, fVerbose = 0; char * pScript;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "NMITSPvh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "NMITSPdvh" ) ) != EOF )
{
switch ( c )
{
@ -53692,6 +53781,9 @@ int Abc_CommandAbc9StochSyn( Abc_Frame_t * pAbc, int argc, char ** argv )
if ( nProcs < 0 )
goto usage;
break;
case 'd':
fDelayOpt ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
@ -53712,19 +53804,20 @@ int Abc_CommandAbc9StochSyn( Abc_Frame_t * pAbc, int argc, char ** argv )
goto usage;
}
pScript = Abc_UtilStrsav( argv[globalUtilOptind] );
Gia_ManStochSyn( nSuppMax, nMaxSize, nIters, TimeOut, Seed, fVerbose, pScript, nProcs );
Gia_ManStochSyn( nSuppMax, nMaxSize, nIters, TimeOut, Seed, fVerbose, pScript, nProcs, fDelayOpt );
ABC_FREE( pScript );
return 0;
usage:
Abc_Print( -2, "usage: &stochsyn [-NMITSP <num>] [-tvh] <script>\n" );
Abc_Print( -2, "\t performs stochastic synthesis\n" );
Abc_Print( -2, "usage: &stochsyn [-NMITSP <num>] [-dvh] <script>\n" );
Abc_Print( -2, "\t performs stochastic synthesis using the given script\n" );
Abc_Print( -2, "\t-N <num> : the max partition support size [default = %d]\n", nSuppMax );
Abc_Print( -2, "\t-M <num> : the max partition size (in AIG nodes or LUTs) [default = %d]\n", nMaxSize );
Abc_Print( -2, "\t-I <num> : the number of iterations [default = %d]\n", nIters );
Abc_Print( -2, "\t-T <num> : the timeout in seconds (0 = no timeout) [default = %d]\n", TimeOut );
Abc_Print( -2, "\t-S <num> : user-specified random seed (0 <= num <= 100) [default = %d]\n", Seed );
Abc_Print( -2, "\t-P <num> : the number of concurrent processes (1 <= num <= 100) [default = %d]\n", nProcs );
Abc_Print( -2, "\t-d : toggle using delay-aware synthesis (if the script supports it) [default = %s]\n", fDelayOpt? "yes": "no" );
Abc_Print( -2, "\t-v : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
Abc_Print( -2, "\t<script> : synthesis script to use for each partition\n");
@ -56447,11 +56540,11 @@ usage:
***********************************************************************/
int Abc_CommandAbc9GenComp( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern Gia_Man_t * Gia_ManDupGenComp( int nBits, int fInterleave );
extern Gia_Man_t * Gia_ManDupGenComp( int nBits, int fInterleave, int fSigned );
Gia_Man_t * pTemp = NULL;
int c, nBits = 0, fInter = 0, fVerbose = 0;
int c, nBits = 4, fInter = 0, fSigned = 0, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "Kivh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "Kisvh" ) ) != EOF )
{
switch ( c )
{
@ -56469,6 +56562,9 @@ int Abc_CommandAbc9GenComp( Abc_Frame_t * pAbc, int argc, char ** argv )
case 'i':
fInter ^= 1;
break;
case 's':
fSigned ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
@ -56483,17 +56579,18 @@ int Abc_CommandAbc9GenComp( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Print( -1, "Abc_CommandAbc9GenComp(): The number of inputs should be defined on the command line \"-K num\".\n" );
return 0;
}
pTemp = Gia_ManDupGenComp( nBits, fInter );
pTemp = Gia_ManDupGenComp( nBits, fInter, fSigned );
Abc_FrameUpdateGia( pAbc, pTemp );
if ( fVerbose )
Abc_Print( 1, "Generated %d-bit comparator.\n", nBits );
return 0;
usage:
Abc_Print( -2, "usage: &gencomp [-K <num>] [-ivh]\n" );
Abc_Print( -2, "\t generates the comparator\n" );
Abc_Print( -2, "\t-K num : the number of control inputs [default = undefined]\n" );
Abc_Print( -2, "usage: &gencomp [-K <num>] [-isvh]\n" );
Abc_Print( -2, "\t generates the comparator (a > b)\n" );
Abc_Print( -2, "\t-K num : the bitwidth of the inputs [default = %d]\n", nBits );
Abc_Print( -2, "\t-i : toggles using interleaved variable ordering [default = %s]\n", fInter ? "yes": "no" );
Abc_Print( -2, "\t-s : toggles generating signed comparator [default = %s]\n", fSigned ? "yes": "no" );
Abc_Print( -2, "\t-v : toggles printing verbose information [default = %s]\n", fVerbose ? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
@ -56704,7 +56801,7 @@ int Abc_CommandAbc9GenAdder( Abc_Frame_t * pAbc, int argc, char ** argv )
return 0;
usage:
Abc_Print( -2, "usage: &genadder [-N <num>] [-sbhcv] <file>\n" );
Abc_Print( -2, "usage: &genadder [-N <num>] [-sbhcv]\n" );
Abc_Print( -2, "\t generates a prefix adder (by default, the ripple carry adder)\n" );
Abc_Print( -2, "\t-N num : the bit-width of the adder [default = undefined]\n" );
Abc_Print( -2, "\t-s : toggles using Sklansky adder [default = %s]\n", fSK ? "yes": "no" );
@ -56715,6 +56812,149 @@ usage:
return 1;
}
#ifdef __cplusplus
extern "C" {
#endif
int* adder_return_array(int width, int mfo, int use_or, int seed, int num_rounds, int delay_relaxation, int fVerbose, int fDumpVer, int fDumpMiter, int* pnObjs, int* pnIns, int* pnLatches, int* pnOuts, int* pnAnds);
#ifdef __cplusplus
}
#endif
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_CommandAbc9GenPrefix( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern Gia_Man_t * Gia_ManDupFromArray( int * pObjs, int nObjs, int nIns, int nLatches, int nOuts, int nAnds );
int c, nBits = 8, nFans = 4, Seed = 0, nIters = 1, DelayRelax = 0, fDumpVer = 0, fDumpMiter = 0, fVerbose = 0, use_or = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "NFSIRdmov" ) ) != EOF )
{
switch ( c )
{
case 'N':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
goto usage;
}
nBits = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nBits < 0 )
goto usage;
break;
case 'F':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
goto usage;
}
nFans = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nFans < 0 )
goto usage;
break;
case 'S':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
goto usage;
}
Seed = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( Seed < 0 )
goto usage;
break;
case 'I':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
goto usage;
}
nIters = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nIters < 0 )
goto usage;
break;
case 'R':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
goto usage;
}
DelayRelax = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( DelayRelax < 0 )
goto usage;
break;
case 'd':
fDumpVer ^= 1;
break;
case 'm':
fDumpMiter ^= 1;
break;
case 'o':
use_or ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
default:
goto usage;
}
}
if ( nBits < 1 )
{
Abc_Print( -1, "Abc_CommandAbc9GenPrefix(): The number of inputs should be defined on the command line \"-N num\".\n" );
return 0;
}
else
{
int nObjs = 0, nIns = 0, nLatches = 0, nOuts = 0, nAnds = 0;
int * pObjs = adder_return_array( nBits, nFans, use_or, Seed, nIters, DelayRelax, fVerbose, fDumpVer, fDumpMiter, &nObjs, &nIns, &nLatches, &nOuts, &nAnds );
if ( pObjs == NULL ) {
printf( "Prefix tree with %d inputs and %d maximum fanout does not exist.\n", nBits, nFans );
} else {
Gia_Man_t * pTemp = Gia_ManDupFromArray( pObjs, nObjs, nIns, nLatches, nOuts, nAnds );
Abc_FrameUpdateGia( pAbc, pTemp );
ABC_FREE( pObjs );
}
}
return 0;
usage:
Abc_Print( -2, "usage: &genprefix [-NFSIR <num>] [-dmov]\n" );
Abc_Print( -2, "\t generates a prefix adder with minimum depth\n" );
Abc_Print( -2, "\t-N num : the bit-width of the adder [default = %d]\n", nBits );
Abc_Print( -2, "\t-F num : the limit on the fanout count [default = %d]\n", nFans );
Abc_Print( -2, "\t-S num : the random seed used to randomize search [default = %d]\n", Seed );
Abc_Print( -2, "\t-I num : the number of iterations to find the smallest prefix tree [default = %d]\n", nIters );
Abc_Print( -2, "\t-R num : the delay relaxation (the max allowed level increase over log2(N)) [default = %d]\n", DelayRelax );
Abc_Print( -2, "\t-d : toggles dumping the adder in Verilog [default = %s]\n", fDumpVer ? "yes": "no" );
Abc_Print( -2, "\t-m : toggles dumping the miter in Verilog [default = %s]\n", fDumpMiter ? "yes": "no" );
Abc_Print( -2, "\t-o : toggles using additional optimization [default = %s]\n", use_or ? "yes": "no" );
Abc_Print( -2, "\t-v : toggles printing verbose information [default = %s]\n\n", fVerbose ? "yes": "no" );
Abc_Print( -2, "\t The code of this command is contributed by Martin Povišer <povik@cutebit.org>\n\n" );
Abc_Print( -2, "\t The implementation is inspired by S. Roy, M. Choudhury, R. Puri, D. Pan,\n" );
Abc_Print( -2, "\t \"Polynomial time algorithm for area and power efficient adder synthesis\n" );
Abc_Print( -2, "\t in high-performance designs\", Proc. ASP-DAC 2015.\n" );
Abc_Print( -2, "\t https://www.cerc.utexas.edu/utda/publications/C166.pdf\n" );
return 1;
}
/**Function*************************************************************
Synopsis []
@ -57257,6 +57497,99 @@ usage:
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_CommandAbc9BsFind( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern int Gia_ManBsFindBest( Gia_Man_t * pGia, int nWords, int nLutSize, int nBest, int nIterMax, int fVerbose );
int c, nWords = 256, nLutSize = 6, nBest = 20, nIterMax = 10, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "WKBIvh" ) ) != EOF )
{
switch ( c )
{
case 'W':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
goto usage;
}
nWords = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nWords < 0 )
goto usage;
break;
case 'K':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
goto usage;
}
nLutSize = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nLutSize < 0 )
goto usage;
break;
case 'B':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
goto usage;
}
nBest = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nBest < 0 )
goto usage;
break;
case 'I':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
goto usage;
}
nIterMax = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nIterMax < 0 )
goto usage;
break;
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
if ( pAbc->pGia == NULL )
{
Abc_Print( -1, "Abc_CommandAbc9MulFind(): There is no AIG.\n" );
return 0;
}
Gia_ManBsFindBest( pAbc->pGia, nWords, nLutSize, nBest, nIterMax, fVerbose );
return 0;
usage:
Abc_Print( -2, "usage: &bsfind [-WKBI num] [-vh]\n" );
Abc_Print( -2, "\t found a good boundset for the multi-output function\n" );
Abc_Print( -2, "\t-W num : the number of simulation words to use [default = %d]\n", nWords );
Abc_Print( -2, "\t-K num : the number of bound-set variables (LUT size) [default = %d]\n", nLutSize );
Abc_Print( -2, "\t-B num : the number of best bound-sets to consider [default = %d]\n", nBest );
Abc_Print( -2, "\t-I num : the number of refinement iterations to perform [default = %d]\n", nIterMax );
Abc_Print( -2, "\t-v : toggles printing verbose information [default = %s]\n", fVerbose ? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
}
/**Function*************************************************************
Synopsis []

View File

@ -1450,11 +1450,13 @@ Vec_Wrd_t * Abc_NtkLutCasReadTruths( char * pFileName, int nVarsOrig )
SeeAlso []
***********************************************************************/
void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int nStages, int nRails, int nIters, int nJRatio, int nZParam, int Seed, int fVerbose, int fVeryVerbose, int fPrintMyu, int fPrintLev, int fXRail, int nSubsets, int nBest )
void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int nStages, int nRails, int nIters, int nJRatio, int nZParam, int Seed, int fVerbose, int fVeryVerbose, int fPrintMyu, int fPrintLev, int fXRail, int nSubsets, int nBest, int fDump )
{
abctime clkStart = Abc_Clock();
int i, nErrors = 0, Sum = 0, nStageCount = 0, MyuMin = 0, nTotalLuts = 0, nWords = Abc_TtWordNum(nVarsOrig);
Vec_Wrd_t * vTruths = NULL;
char pFileNameOut[1000] = {0};
FILE * pFile = NULL;
if ( strstr(pFileName, ".txt") )
vTruths = Abc_NtkLutCasReadTruths( pFileName, nVarsOrig );
else
@ -1501,7 +1503,7 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
word * pLuts = Abc_LutCascadeDec( p, NULL, pTruth, nVarsOrig, vVarIDs, nRails, nLutSize, nStages, (int)(Iter >= 0), nZParam, fXRail, fVeryVerbose, &nStageCount, &MyuMin, nSubsets, nBest );
Vec_IntFree( vVarIDs );
if ( MyuMin < 50 ) MyuStats[MyuMin]++, IterReal++;
if ( MyuMin < 50 && Iter == 0 ) MyuStats[MyuMin]++, IterReal++;
if ( pLuts == NULL ) {
if ( ++Iter < nIters ) {
i--;
@ -1510,6 +1512,16 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
Iter = 0;
if ( fVerbose || fVeryVerbose )
printf( "Not decomposable.\n" );
if ( fDump ) {
if ( pFile == NULL ) {
sprintf( pFileNameOut, "%s_nd", pFileName );
pFile = fopen( pFileNameOut, "wb" );
}
char * pTtStr = ABC_CALLOC( char, (1 << (nVarsOrig-2)) + 1 );
Extra_PrintHexadecimalString( pTtStr, (unsigned *)pTruth, nVarsOrig );
fprintf( pFile, "%s\n", pTtStr );
ABC_FREE( pTtStr );
}
continue;
}
Iter = 0;
@ -1559,6 +1571,10 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
printf( "Finished %d functions (%.2f LUTs / function; %.2f functions / sec). ",
nFuncs, 1.0*nTotalLuts/Sum, 1.0*nFuncs/(((double)(Abc_Clock() - clkStart))/((double)CLOCKS_PER_SEC)) );
Abc_PrintTime( 0, "Total time", Abc_Clock() - clkStart );
if ( pFile ) {
printf( "Finished dumping %d non-decomposable functions into file \"%s\".\n", nFuncs-Sum, pFileNameOut );
fclose( pFile );
}
}
/**Function*************************************************************

View File

@ -20,6 +20,7 @@
#include "base/abc/abc.h"
#include "bool/dec/dec.h"
#include "misc/extra/extra.h"
ABC_NAMESPACE_IMPL_START
@ -37,6 +38,11 @@ struct Abc_ManRes_t_
// paramers
int nLeavesMax; // the max number of leaves in the cone
int nDivsMax; // the max number of divisors in the cone
// resub problem dumping
int Log2Probs;
int Log2Divs;
int nProbs;
FILE * pFile;
// representation of the cone
Abc_Obj_t * pRoot; // the root of the cone
int nLeaves; // the number of leaves
@ -51,6 +57,7 @@ struct Abc_ManRes_t_
unsigned * pInfo; // pointer to simulation info
// observability don't-cares
unsigned * pCareSet;
unsigned * pTempSim;
// internal divisor storage
Vec_Ptr_t * vDivs1UP; // the single-node unate divisors
Vec_Ptr_t * vDivs1UN; // the single-node unate divisors
@ -134,7 +141,7 @@ static int Abc_CutVolumeCheck( Abc_Obj_t * pNode, Vec_Ptr_t * vLeaves
SeeAlso []
***********************************************************************/
int Abc_NtkResubstitute( Abc_Ntk_t * pNtk, int nCutMax, int nStepsMax, int nMinSaved, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose )
int Abc_NtkResubstitute( Abc_Ntk_t * pNtk, int nCutMax, int nStepsMax, int nMinSaved, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int Log2Probs, int Log2Divs )
{
extern int Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
ProgressBar * pProgress;
@ -154,6 +161,21 @@ int Abc_NtkResubstitute( Abc_Ntk_t * pNtk, int nCutMax, int nStepsMax, int nMinS
// start the managers
pManCut = Abc_NtkManCutStart( nCutMax, 100000, 100000, 100000 );
pManRes = Abc_ManResubStart( nCutMax, ABC_RS_DIV1_MAX );
if ( Log2Probs && Log2Divs )
{
pManRes->Log2Probs = Log2Probs;
pManRes->Log2Divs = Log2Divs;
pManRes->nProbs = 0;
char * pName = Extra_FileNameGeneric(Extra_FileNameWithoutPath(pNtk->pName));
char pFileName[100]; sprintf( pFileName, "p%02dd%02dv%02d_%s.bin", Log2Probs, nCutMax, Log2Divs, pName );
ABC_FREE( pName );
pManRes->pFile = fopen( pFileName, "wb" );
if ( pManRes->pFile == NULL ) {
printf( "Cannot open output file \"%s\".\n", pFileName );
return 1;
}
printf( "Collecting resub problems into binary file \"%s\" expected to take %.3f MB...\n", pFileName, 1.0*(1 << Log2Probs)*(1 << Log2Divs)*(1 << (nCutMax-3)) / (1 << 20) );
}
if ( nLevelsOdc > 0 )
pManOdc = Abc_NtkDontCareAlloc( nCutMax, nLevelsOdc, fVerbose, fVeryVerbose );
@ -245,6 +267,16 @@ pManRes->timeTotal = Abc_Clock() - clkStart;
if ( fVerbose )
Abc_ManResubPrint( pManRes );
if ( Log2Probs && Log2Divs )
{
fclose( pManRes->pFile );
pManRes->pFile = NULL;
char pFileName[100]; sprintf( pFileName, "p%02dd%02dv%02d.bin", Log2Probs, nCutMax, Log2Divs );
printf( "Finished writing file \"%s\" containing %d (out of requested %d) resub problems,\n", pFileName, pManRes->nProbs, 1<<Log2Probs );
printf( "each having %d divisors with support size %d (including the on-set and the off-set). ", 1<<Log2Divs, nCutMax );
Abc_PrintTime( 1, "Time", Abc_Clock() - clkStart );
}
// delete the managers
Abc_ManResubStop( pManRes );
Abc_NtkManCutStop( pManCut );
@ -321,6 +353,7 @@ Abc_ManRes_t * Abc_ManResubStart( int nLeavesMax, int nDivsMax )
if ( i & (1 << k) )
pData[i>>5] |= (1 << (i&31));
}
p->pTempSim = ABC_CALLOC( unsigned, p->nWords );
// create the remaining divisors
p->vDivs1UP = Vec_PtrAlloc( p->nDivsMax );
p->vDivs1UN = Vec_PtrAlloc( p->nDivsMax );
@ -356,6 +389,7 @@ void Abc_ManResubStop( Abc_ManRes_t * p )
Vec_PtrFree( p->vDivs2UN0 );
Vec_PtrFree( p->vDivs2UN1 );
Vec_PtrFree( p->vTemp );
ABC_FREE( p->pTempSim );
ABC_FREE( p->pInfo );
ABC_FREE( p );
}
@ -1943,6 +1977,32 @@ clk = Abc_Clock();
Abc_ManResubSimulate( p->vDivs, p->nLeaves, p->vSims, p->nLeavesMax, p->nWords );
p->timeSim += Abc_Clock() - clk;
if ( p->pFile && Vec_PtrSize(vLeaves) != p->nLeavesMax && p->nProbs < (1 << p->Log2Probs) )
{
Abc_Obj_t * pObj; int i, w, Count = 0;
unsigned * pFunc = (unsigned *)pRoot->pData;
int Limit = Abc_MinInt( Vec_PtrSize(p->vDivs), (1 << p->Log2Divs) - 2 );
Vec_PtrForEachEntryStop( Abc_Obj_t *, p->vDivs, pObj, i, Limit )
Count += fwrite( (unsigned *)pObj->pData, 1, sizeof(unsigned) * p->nWords, p->pFile );
// write constant zeros
memset( p->pTempSim, 0, sizeof(unsigned) * p->nWords );
for ( ; i < (1 << p->Log2Divs) - 2; i++ )
Count += fwrite( p->pTempSim, 1, sizeof(unsigned) * p->nWords, p->pFile );
// write offset
for ( w = 0; w < p->nWords; w++ )
p->pTempSim[w] = p->pCareSet[w] & ~pFunc[w];
Count += fwrite( p->pTempSim, 1, sizeof(unsigned) * p->nWords, p->pFile );
// write onset
for ( w = 0; w < p->nWords; w++ )
p->pTempSim[w] = p->pCareSet[w] & pFunc[w];
Count += fwrite( p->pTempSim, 1, sizeof(unsigned) * p->nWords, p->pFile );
assert( Count == (1 << p->Log2Divs) * (1 << (p->nLeavesMax-3)) );
p->nProbs++;
//printf( "Finished dumping node %d. Written %d bytes of data (expected %d bytes).\n", pRoot->Id, Count, (1 << p->Log2Divs) * (1 << (p->nLeavesMax-3)) );
//printf( "%d ", Vec_PtrSize(p->vDivs) );
return NULL;
}
clk = Abc_Clock();
// consider constants
if ( (pGraph = Abc_ManResubQuit( p )) )

View File

@ -72,6 +72,7 @@ static int IoCommandWriteBaf ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteBblif ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteBlif ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteEdgelist( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteNtk ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteBlifMv ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteBench ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteBook ( Abc_Frame_t * pAbc, int argc, char **argv );
@ -162,6 +163,7 @@ void Io_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "I/O", "write_dot", IoCommandWriteDot, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_eqn", IoCommandWriteEqn, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_edgelist",IoCommandWriteEdgelist, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_ntk", IoCommandWriteNtk, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_gml", IoCommandWriteGml, 0 );
// Cmd_CommandAdd( pAbc, "I/O", "write_list", IoCommandWriteList, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_hmetis", IoCommandWriteHMetis, 0 );
@ -3557,6 +3559,77 @@ usage:
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int IoCommandWriteNtk( Abc_Frame_t * pAbc, int argc, char **argv )
{
char * pFileName;
int c;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "Nh" ) ) != EOF )
{
switch ( c )
{
case 'h':
goto usage;
default:
goto usage;
}
}
if ( pAbc->pNtkCur == NULL )
{
fprintf( pAbc->Out, "Empty network.\n" );
return 0;
}
if ( argc != globalUtilOptind + 1 )
goto usage;
else
{
Abc_Obj_t * pObj, * pFanin; int i, k, nIds = 1;
int * pId = ABC_CALLOC( int, Abc_NtkObjNumMax(pAbc->pNtkCur) );
Abc_NtkForEachCi( pAbc->pNtkCur, pObj, i )
pId[pObj->Id] = nIds++;
Abc_NtkForEachNode( pAbc->pNtkCur, pObj, i )
pId[pObj->Id] = nIds++;
Abc_NtkForEachCo( pAbc->pNtkCur, pObj, i )
pId[pObj->Id] = nIds++;
// get the output file name
pFileName = argv[globalUtilOptind];
FILE * pFile = fopen( pFileName, "wb" );
fprintf( pFile, "%d\n", 0 );
Abc_NtkForEachCi( pAbc->pNtkCur, pObj, i )
fprintf( pFile, "%d\n", pId[pObj->Id] );
Abc_NtkForEachNode( pAbc->pNtkCur, pObj, i ) {
fprintf( pFile, "%d", pId[pObj->Id] );
Abc_ObjForEachFanin( pObj, pFanin, k )
fprintf( pFile, " %d", pId[pFanin->Id] );
fprintf( pFile, "\n" );
}
Abc_NtkForEachCo( pAbc->pNtkCur, pObj, i )
fprintf( pFile, "%d %d\n", pId[pObj->Id], pId[Abc_ObjFanin0(pObj)->Id] );
fclose( pFile );
ABC_FREE( pId );
}
return 0;
usage:
fprintf( pAbc->Err, "usage: write_ntk <file>\n" );
fprintf( pAbc->Err, "\t writes the network into a text file\n" );
fprintf( pAbc->Err, "\t-h : print the help massage\n" );
fprintf( pAbc->Err, "\tfile : the name of the file to write\n" );
return 1;
}
/**Function*************************************************************

View File

@ -147,7 +147,7 @@ Rtl_Lib_t * Wln_ReadSystemVerilog( char * pFileName, char * pTopModule, char * p
int fSVlog = strstr(pFileName, ".sv") != NULL;
if ( strstr(pFileName, ".rtl") )
return Rtl_LibReadFile( pFileName, pFileName );
sprintf( Command, "%s -qp \"read_verilog %s%s %s%s; hierarchy %s%s; %sproc; write_rtlil %s\"",
sprintf( Command, "%s -qp \"read_verilog %s%s %s%s; hierarchy %s%s; %sproc; memory -nomap; memory_map; write_rtlil %s\"",
Wln_GetYosysName(),
pDefines ? "-D" : "",
pDefines ? pDefines : "",
@ -178,7 +178,7 @@ Gia_Man_t * Wln_BlastSystemVerilog( char * pFileName, char * pTopModule, char *
char * pFileTemp = "_temp_.aig";
int fRtlil = strstr(pFileName, ".rtl") != NULL;
int fSVlog = strstr(pFileName, ".sv") != NULL;
sprintf( Command, "%s -qp \"%s %s%s %s%s; hierarchy %s%s; flatten; proc; %saigmap; write_aiger %s\"",
sprintf( Command, "%s -qp \"%s %s%s %s%s; hierarchy %s%s; flatten; proc; memory -nomap; memory_map; %saigmap; write_aiger %s\"",
Wln_GetYosysName(),
fRtlil ? "read_rtlil" : "read_verilog",
pDefines ? "-D" : "",
@ -217,7 +217,7 @@ Abc_Ntk_t * Wln_ReadMappedSystemVerilog( char * pFileName, char * pTopModule, ch
char Command[1000];
char * pFileTemp = "_temp_.blif";
int fSVlog = strstr(pFileName, ".sv") != NULL;
sprintf( Command, "%s -qp \"read_liberty -lib %s; read %s %s%s %s; hierarchy %s%s; flatten; proc; write_blif %s%s -impltf -gates %s\"",
sprintf( Command, "%s -qp \"read_liberty -lib %s; read %s %s%s %s; hierarchy %s%s; flatten; proc; memory -nomap; memory_map; write_blif %s%s -impltf -gates %s\"",
Wln_GetYosysName(),
pLibrary,
fSVlog ? "-sv " : "-vlog95",

View File

@ -149,6 +149,7 @@ struct If_Par_t_
int fHashMapping; // perform AIG hashing after mapping
int fUserLutDec; // perform Boolean decomposition during mapping
int fUserLut2D; // perform Boolean decomposition during mapping
int fDumpFile; // dumping truth tables into a file
int fVerbose; // the verbosity flag
int fVerboseTrace; // the verbosity flag
char * pLutStruct; // LUT structure
@ -284,6 +285,8 @@ struct If_Man_t_
int pDumpIns[16];
Vec_Str_t * vMarks;
Vec_Int_t * vVisited2;
Vec_Int_t * vCuts;
Vec_Int_t * vCutCosts;
// timing manager
Tim_Man_t * pManTim;

View File

@ -154,6 +154,10 @@ int If_ManPerformMappingComb( If_Man_t * p )
// area oriented mapping
for ( i = 0; i < p->pPars->nAreaIters; i++ )
{
if ( p->pPars->fDumpFile && p->pPars->nLutSize <= 6 && i == p->pPars->nAreaIters-1 ) {
p->vCuts = Vec_IntAlloc( 1 << 20 );
p->vCutCosts = Vec_IntAlloc( 1 << 16 );
}
If_ManPerformMappingRound( p, p->pPars->nCutsMax, 2, 0, 0, "Area" );
if ( p->pPars->fExpRed )
If_ManImproveMapping( p );

View File

@ -19,6 +19,7 @@
***********************************************************************/
#include "if.h"
#include "misc/extra/extra.h"
ABC_NAMESPACE_IMPL_START
@ -198,6 +199,121 @@ void If_ManRestart( If_Man_t * p )
p->nObjs[IF_CI] = p->nObjs[IF_CO] = p->nObjs[IF_AND] = 0;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void If_ManSimpleSort( int * pArray, int nSize )
{
int temp, i, j, best_i;
for ( i = 0; i < nSize-1; i++ ) {
best_i = i;
for ( j = i+1; j < nSize; j++ )
if ( pArray[j] < pArray[best_i] )
best_i = j;
temp = pArray[i];
pArray[i] = pArray[best_i];
pArray[best_i] = temp;
}
}
void If_ManDumpCut( If_Cut_t * pCut, int nLutSize, Vec_Int_t * vCuts )
{
int i;
for ( i = 0; i < pCut->nLeaves; i++ )
Vec_IntPush( vCuts, pCut->pLeaves[i] );
for ( ; i < nLutSize; i++ )
Vec_IntPush( vCuts, 0 );
}
void If_ManDumpCutsAndCost( If_Man_t * p, If_Obj_t * pObj, Vec_Int_t * vCuts, Vec_Int_t * vCutCosts )
{
If_Cut_t * pCut; int k, nCuts = 0;
while ( nCuts < p->pPars->nCutsMax ) {
If_ObjForEachCut( pObj, pCut, k ) {
If_ManDumpCut( pCut, p->pPars->nLutSize, vCuts );
Vec_IntPush( vCutCosts, (int)pCut->Area );
if ( ++nCuts == p->pPars->nCutsMax )
break;
}
}
}
void If_ManDumpCutsAndCostAdd( int Obj, int nCutsMax, int nLutSize, Vec_Int_t * vCopy, Vec_Int_t * vCuts, Vec_Int_t * vCutCosts, Vec_Int_t * vCutsOut, Vec_Int_t * vCutCostsOut )
{
int i, * pCuts = Vec_IntEntryP( vCuts, Obj * nCutsMax * nLutSize );
for ( i = 0; i < nCutsMax * nLutSize; i++ )
pCuts[i] = Vec_IntEntry(vCopy, pCuts[i]);
for ( i = 0; i < nCutsMax; i++ )
If_ManSimpleSort( pCuts + i*nLutSize, nLutSize );
for ( i = 0; i < nCutsMax * nLutSize; i++ )
Vec_IntPush( vCutsOut, pCuts[i] );
for ( i = 0; i < nCutsMax; i++ )
Vec_IntPush( vCutCostsOut, Vec_IntEntry( vCutCosts, Obj * nCutsMax + i ) );
}
int If_ManDumpData( If_Man_t * p, FILE * pFile )
{
Vec_Int_t * vCopy = Vec_IntStartFull( If_ManObjNum(p) );
Vec_Int_t * vCopy2 = Vec_IntAlloc( If_ManObjNum(p) );
Vec_Int_t * vLevelLims = Vec_IntAlloc( p->nLevelMax + 1 );
Vec_Int_t * vCuts = Vec_IntAlloc( 1 << 20 );
Vec_Int_t * vFanins = Vec_IntAlloc( If_ManCoNum(p) );
Vec_Int_t * vCutCosts = Vec_IntAlloc( 1 << 16 );
Vec_Int_t * vLevel; If_Obj_t * pObj;
int i, k, Obj, nObjs = 0, nBytes = 0;
Vec_Wec_t * vLevels = Vec_WecStart( p->nLevelMax );
If_ManForEachNode( p, pObj, i )
Vec_WecPush( vLevels, pObj->Level, i );
Vec_IntWriteEntry( vCopy, 0, nObjs++ );
If_ManForEachCi( p, pObj, i )
Vec_IntWriteEntry( vCopy, pObj->Id, nObjs++ );
Vec_WecForEachLevelStart( vLevels, vLevel, i, 1 )
Vec_IntForEachEntry( vLevel, Obj, k ) {
Vec_IntWriteEntry( vCopy, Obj, nObjs++ );
Vec_IntPush( vCopy2, Obj - 1 - If_ManCiNum(p) );
}
assert( Vec_IntSize(vCopy2) == If_ManAndNum(p) );
assert( nObjs == 1 + If_ManCiNum(p) + If_ManAndNum(p) );
nObjs = If_ManCiNum(p) + 1;
Vec_WecForEachLevelStart( vLevels, vLevel, i, 1 ) {
Vec_IntPush( vLevelLims, nObjs );
nObjs += Vec_IntSize(vLevel);
}
Vec_IntPush( vLevelLims, nObjs );
assert( Vec_IntSize(vLevelLims) == p->nLevelMax + 1 );
Vec_IntForEachEntry( vCopy2, Obj, i )
If_ManDumpCutsAndCostAdd( Obj, p->pPars->nCutsMax, p->pPars->nLutSize, vCopy, p->vCuts, p->vCutCosts, vCuts, vCutCosts );
assert( Vec_IntSize(vCuts) == If_ManAndNum(p) * p->pPars->nCutsMax * p->pPars->nLutSize );
assert( Vec_IntSize(vCutCosts) == If_ManAndNum(p) * p->pPars->nCutsMax );
If_ManForEachCo( p, pObj, i )
Vec_IntPush( vFanins, Vec_IntEntry(vCopy, pObj->pFanin0->Id) );
nBytes += fwrite( Vec_IntArray(vCuts), 1, sizeof(int)*Vec_IntSize(vCuts), pFile );
nBytes += fwrite( Vec_IntArray(vFanins), 1, sizeof(int)*Vec_IntSize(vFanins), pFile );
nBytes += fwrite( Vec_IntArray(vLevelLims), 1, sizeof(int)*Vec_IntSize(vLevelLims), pFile );
nBytes += fwrite( Vec_IntArray(vCutCosts), 1, sizeof(int)*Vec_IntSize(vCutCosts), pFile );
if ( 0 ) {
Vec_WecPrint( vLevels, 0 );
Vec_IntPrint( vCopy );
Vec_IntPrint( vCopy2 );
Vec_IntPrint( vLevelLims );
Vec_IntPrint( vCuts );
Vec_IntPrint( vFanins );
Vec_IntPrint( vCutCosts );
}
Vec_WecFree( vLevels );
Vec_IntFree( vCopy );
Vec_IntFree( vCopy2 );
Vec_IntFree( vLevelLims );
Vec_IntFree( vCuts );
Vec_IntFree( vFanins );
Vec_IntFree( vCutCosts );
return nBytes;
}
/**Function*************************************************************
Synopsis []
@ -211,6 +327,63 @@ void If_ManRestart( If_Man_t * p )
***********************************************************************/
void If_ManStop( If_Man_t * p )
{
if ( p->pPars->fDumpFile && p->pPars->nLutSize <= 6 )
{
char pFileName[1000] = {0};
// "I15_O20_L32_N256_C16_K6__name.bin"
char * pName = Extra_FileNameGeneric(Extra_FileNameWithoutPath(p->pName));
sprintf( pFileName, "%s__I%d_O%d_L%d_N%d_C%d_K%d.bin", pName, If_ManCiNum(p), If_ManCoNum(p), p->nLevelMax, If_ManAndNum(p), p->pPars->nCutsMax, p->pPars->nLutSize );
ABC_FREE( pName );
FILE * pFile = fopen( pFileName, "wb" );
if ( pFile == NULL )
printf( "Cannot open file \"%s\" for writing.\n", pFileName );
else {
int nBytes = If_ManDumpData( p, pFile );
int nBytes2 = sizeof(int) * (If_ManAndNum(p) * p->pPars->nCutsMax * p->pPars->nLutSize + If_ManCoNum(p) + p->nLevelMax + 1);
nBytes2 += sizeof(int) * (If_ManAndNum(p) * p->pPars->nCutsMax);
assert( nBytes == nBytes2 );
fclose( pFile );
printf( "Finished writing cut information into file \"%s\" (%.3f MB).\n", pFileName, 1.0 * nBytes / (1<<20) );
}
}
else if ( p->pPars->fDumpFile && p->pPars->fTruth )
{
char pFileName[1000] = {0}, pBuffer[100];
int nUnique = 0, nChunks = 0, nChunkSize = 1 << 10, nBytes = 0;
char * pName = Extra_FileNameGeneric(Extra_FileNameWithoutPath(p->pName));
sprintf( pFileName, "%s__", pName );
ABC_FREE( pName );
for ( int i = 7; i <= p->pPars->nLutSize; i++ ) {
nUnique = Vec_MemEntryNum(p->vTtMem[i]);
nChunks = (nUnique + nChunkSize - 1) / nChunkSize;
printf( "LutSize = %2d Unique = %7d Chunks = %7d\n", i, nUnique, nChunks );
sprintf( pBuffer, "%s%02d_%02d", i == 7 ? "":"__", i, nChunks );
strcat( pFileName, pBuffer );
}
strcat( pFileName, ".bin" );
FILE * pFile = fopen( pFileName, "wb" );
if ( pFile == NULL )
printf( "Cannot open file \"%s\" for writing.\n", pFileName );
else {
for ( int i = 7; i <= p->pPars->nLutSize; i++ ) {
nUnique = Vec_MemEntryNum(p->vTtMem[i]);
nChunks = (nUnique + nChunkSize - 1) / nChunkSize;
word * pEntry; int k, Count = 0;
int nEntrySize = Vec_MemEntrySize(p->vTtMem[i]);
Vec_MemForEachEntry( p->vTtMem[i], pEntry, k )
Count += fwrite( (unsigned *)pEntry, 1, sizeof(word) * nEntrySize, pFile );
word * pZeros = ABC_CALLOC( word, nEntrySize );
for ( ; k < nChunks * nChunkSize; k++ )
Count += fwrite( (unsigned *)pZeros, 1, sizeof(word) * nEntrySize, pFile );
ABC_FREE( pZeros );
assert( Count == nChunks * nChunkSize * nEntrySize * sizeof(word) );
nBytes += nChunks * nChunkSize * nEntrySize * sizeof(word);
}
fclose( pFile );
printf( "Finished writing truth tables into file \"%s\" (%.3f MB).\n", pFileName, 1.0 * nBytes / (1<<20) );
}
}
extern void If_ManCacheAnalize( If_Man_t * p );
int i;
if ( p->pPars->fVerbose && p->vCutData )
@ -275,6 +448,8 @@ void If_ManStop( If_Man_t * p )
Vec_PtrFreeP( &p->vVisited );
Vec_StrFreeP( &p->vMarks );
Vec_IntFreeP( &p->vVisited2 );
Vec_IntFreeP( &p->vCuts );
Vec_IntFreeP( &p->vCutCosts );
if ( p->vPairHash )
Hash_IntManStop( p->vPairHash );
for ( i = 6; i <= Abc_MaxInt(6,p->pPars->nLutSize); i++ )

View File

@ -483,6 +483,10 @@ void If_ObjPerformMappingAnd( If_Man_t * p, If_Obj_t * pObj, int Mode, int fPrep
if ( p->pPars->fUserRecLib || p->pPars->fUserSesLib )
assert(If_ObjCutBest(pObj)->Cost < IF_COST_MAX && If_ObjCutBest(pObj)->Delay < ABC_INFINITY);
}
if ( p->vCuts ) {
extern void If_ManDumpCutsAndCost( If_Man_t * p, If_Obj_t * pObj, Vec_Int_t * vCuts, Vec_Int_t * vCutCosts );
If_ManDumpCutsAndCost( p, pObj, p->vCuts, p->vCutCosts );
}
// add the trivial cut to the set
if ( !pObj->fSkipCut && If_ObjCutBest(pObj)->nLeaves > 1 )
{

View File

@ -225,17 +225,17 @@ void If_CutPropagateRequired( If_Man_t * p, If_Obj_t * pObj, If_Cut_t * pCut, fl
if ( p->pPars->fDelayOpt )
{
int Delay = If_CutSopBalancePinDelays( p, pCut, pPerm );
assert( Delay == (int)pCut->Delay );
assert( -Delay > IF_INFINITY/2 || Delay > IF_INFINITY/2 || Delay == (int)pCut->Delay );
}
else if ( p->pPars->fDelayOptLut )
{
int Delay = If_CutLutBalancePinDelays( p, pCut, pPerm );
assert( Delay == (int)pCut->Delay );
assert( -Delay > IF_INFINITY/2 || Delay > IF_INFINITY/2 || Delay == (int)pCut->Delay );
}
else if ( p->pPars->fDsdBalance )
{
int Delay = If_CutDsdBalancePinDelays( p, pCut, pPerm );
assert( Delay == (int)pCut->Delay );
assert( -Delay > IF_INFINITY/2 || Delay > IF_INFINITY/2 || Delay == (int)pCut->Delay );
}
else
pPerm = If_CutPerm(pCut);

View File

@ -77,8 +77,8 @@ static char * pMcncGenlib[] = {
static char * pAndGenlib[] = {
"GATE zero 0 O=CONST0;\n",
"GATE one 0 O=CONST1;\n",
"GATE buf 1 O=a; PIN * NONINV 1 999 1.0 0.0 1.0 0.0\n",
"GATE inv 1 O=!a; PIN * INV 1 999 1.0 0.0 1.0 0.0\n",
"GATE buf 1 O=a; PIN * NONINV 1 999 0.0 0.0 0.0 0.0\n",
"GATE inv 1 O=!a; PIN * INV 1 999 0.0 0.0 0.0 0.0\n",
"GATE and00 1 O=a*b; PIN * NONINV 1 999 1.0 0.0 1.0 0.0\n",
"GATE and01 1 O=a*!b; PIN * NONINV 1 999 1.0 0.0 1.0 0.0\n",
"GATE and10 1 O=!a*b; PIN * NONINV 1 999 1.0 0.0 1.0 0.0\n",

View File

@ -941,11 +941,16 @@ void Scl_LibertyReadLoadUnit( Scl_Tree_t * p, Vec_Str_t * vOut )
char * pHead = Scl_LibertyReadString(p, pItem->Head);
float First = atof(strtok(pHead, " \t\n\r\\\","));
char * pSecond = strtok(NULL, " \t\n\r\\\",");
Vec_StrPutF_( vOut, First );
if ( pSecond && !strcmp(pSecond, "pf") )
if ( pSecond && (!strcmp(pSecond, "pf") || !strcmp(pSecond, "pF")) )
{
Vec_StrPutF_( vOut, First );
Vec_StrPutI_( vOut, 12 );
else if ( pSecond && !strcmp(pSecond, "ff") )
}
else if ( pSecond && (!strcmp(pSecond, "ff") || !strcmp(pSecond, "fF")) )
{
Vec_StrPutF_( vOut, First );
Vec_StrPutI_( vOut, 15 );
}
else break;
return;
}

View File

@ -5,6 +5,7 @@ SRC += src/misc/util/utilBridge.c \
src/misc/util/utilFile.c \
src/misc/util/utilIsop.c \
src/misc/util/utilNam.c \
src/misc/util/utilPrefix.cpp \
src/misc/util/utilPth.c \
src/misc/util/utilSignal.c \
src/misc/util/utilSort.c

1399
src/misc/util/utilPrefix.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
SRC += src/opt/rar/rewire_rng.c \
src/opt/rar/rewire_map.c \
src/opt/rar/rewire_rar.c \
src/opt/rar/rewire_miaig.cpp
SRC += src/opt/rar/rewireRng.c \
src/opt/rar/rewireMap.c \
src/opt/rar/rewireRar.c \
src/opt/rar/rewireMiaig.cpp

View File

@ -1,6 +1,6 @@
/**CFile****************************************************************
FileName [rewire_map.c]
FileName [rewireMap.c]
SystemName [ABC: Logic synthesis and verification system.]
@ -14,16 +14,17 @@
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: rewire_map.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
Revision [$Id: rewireMap.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "rewire_map.h"
#include "rewireMap.h"
ABC_NAMESPACE_IMPL_START
extern Abc_Ntk_t *Abc_NtkFromAigPhase(Aig_Man_t *pMan);
extern Abc_Ntk_t *Abc_NtkDarAmap(Abc_Ntk_t *pNtk, Amap_Par_t *pPars);
extern Abc_Ntk_t * Abc_NtkDch( Abc_Ntk_t * pNtk, Dch_Pars_t * pPars );
extern void *Abc_FrameReadLibGen2();
extern Vec_Int_t * Abc_NtkWriteMiniMapping( Abc_Ntk_t * pNtk );
extern void Abc_NtkPrintMiniMapping( int * pArray );
@ -43,6 +44,28 @@ Abc_Ntk_t *Gia_ManRewirePut(Gia_Man_t *pGia) {
return pNtk;
}
Abc_Ntk_t *Abc_ManRewireDch(Abc_Ntk_t *pNtk) {
Dch_Pars_t Pars, *pPars = &Pars;
Dch_ManSetDefaultParams(pPars);
pNtk = Abc_NtkDch(pNtk, pPars);
if (pNtk == NULL) {
Abc_Print(-1, "Dch compute has failed.\n");
return NULL;
}
return pNtk;
}
Gia_Man_t *Gia_ManRewireDch(Gia_Man_t *pGia) {
Dch_Pars_t Pars, *pPars = &Pars;
Dch_ManSetDefaultParams(pPars);
pGia = Gia_ManPerformDch( pGia, pPars );
if (pGia == NULL) {
Abc_Print(-1, "Dch compute has failed.\n");
return NULL;
}
return pGia;
}
Abc_Ntk_t *Abc_ManRewireMapAmap(Abc_Ntk_t *pNtk) {
Amap_Par_t Pars, *pPars = &Pars;
Amap_ManSetDefaultParams(pPars);
@ -67,6 +90,7 @@ Abc_Ntk_t *Gia_ManRewireMapNf(Gia_Man_t *pGia) {
}
Abc_Ntk_t *Gia_ManRewireMapSimap(Gia_Man_t *pGia, int nBound, int nBTLimit, int nTimeout) {
Abc_Print(-1, "[Warning] Gia_ManRewireMapSimap is SAT-based experimental mode.\n");
if (!Gia_ManSimpleMapping(pGia, nBound, 0, nBTLimit, nTimeout, 0, 0, 0, NULL)) {
// Abc_Print(-1, "Mapping has failed.\n");
return NULL;

View File

@ -1,6 +1,6 @@
/**CFile****************************************************************
FileName [rewire_map.h]
FileName [rewireMap.h]
SystemName [ABC: Logic synthesis and verification system.]
@ -14,7 +14,7 @@
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: rewire_map.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
Revision [$Id: rewireMap.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
@ -24,12 +24,15 @@
#include "base/abc/abc.h"
#include "aig/gia/giaAig.h"
#include "map/amap/amap.h"
#include "proof/dch/dch.h"
#include "map/mio/mio.h"
#include "aig/miniaig/miniaig.h"
ABC_NAMESPACE_HEADER_START
Abc_Ntk_t *Gia_ManRewirePut(Gia_Man_t *pGia);
Abc_Ntk_t *Abc_ManRewireDch(Abc_Ntk_t *pNtk);
Gia_Man_t *Gia_ManRewireDch(Gia_Man_t *pGia);
Abc_Ntk_t *Abc_ManRewireMapAmap(Abc_Ntk_t *pNtk);
Abc_Ntk_t *Gia_ManRewireMapNf(Gia_Man_t *pGia);
Abc_Ntk_t *Gia_ManRewireMapSimap(Gia_Man_t *pGia, int nBound, int nBTLimit, int nTimeout);

View File

@ -1,6 +1,6 @@
/**CFile****************************************************************
FileName [rewire_miaig.cpp]
FileName [rewireMiaig.cpp]
SystemName [ABC: Logic synthesis and verification system.]
@ -14,12 +14,12 @@
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: rewire_miaig.cpp,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
Revision [$Id: rewireMiaig.cpp,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "rewire_rar.h"
#include "rewire_miaig.h"
#include "rewireRar.h"
#include "rewireMiaig.h"
#define USE_OLD_LEVEL_SORTING 0
@ -28,45 +28,71 @@ ABC_NAMESPACE_IMPL_START
#endif // RW_ABC
#ifdef RW_ABC
Gia_Man_t *Gia_ManRewireInt(Gia_Man_t *pGia, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int nSeed, int fCheck, int fChoices, int fVerbose) {
vi *moveVecToVi(Vec_Int_t *v) {
vi *p = (vi *)malloc(sizeof(vi));
p->size = Vec_IntSize(v);
p->cap = Vec_IntCap(v);
p->ptr = Vec_IntArray(v);
free(v);
return p;
}
vi *copyVecToVi(Vec_Int_t *v) {
vi *p = (vi *)malloc(sizeof(vi));
p->size = Vec_IntSize(v);
p->cap = Vec_IntCap(v);
p->ptr = (int *)malloc(sizeof(int) * p->cap);
memcpy(p->ptr, Vec_IntArray(v), sizeof(int) * p->size);
return p;
}
Gia_Man_t *Gia_ManRewireInt(Gia_Man_t *pGia, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int nSeed, int fCheck, int fChoices, int fVerbose) {
Random_Num(nSeed == 0 ? Abc_Random(0) % 10 : nSeed);
Gia_ChMan_t *pChMan = fChoices ? Gia_ManDupChoicesStart(pGia) : NULL;
vi *vCiArrs = (pGia->vCiArrs) ? copyVecToVi(pGia->vCiArrs) : NULL;
vi *vCoReqs = (pGia->vCoReqs) ? copyVecToVi(pGia->vCoReqs) : NULL;
assert(Gia_ManCiNum(pGia) <= 58);
Rewire::Miaig pNtkMiaig(pGia);
if (pExc)
pNtkMiaig.setExc(pExc);
Rewire::Miaig pNew = pNtkMiaig.rewire(nIters, levelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, fCheck, pChMan, fVerbose);
pNtkMiaig.attachTiming(vCiArrs, vCoReqs);
Rewire::Miaig pNew = pNtkMiaig.rewire(nIters, levelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, fDch, fTiming, fCheck, pChMan, fVerbose);
pNew.setName(Gia_ManName(pGia));
if (vCiArrs) Vi_Free(vCiArrs);
if (vCoReqs) Vi_Free(vCoReqs);
return pChMan ? Gia_ManDupChoicesFinish(pChMan) : pNew.toGia();
}
Abc_Ntk_t *Abc_ManRewireInt(Abc_Ntk_t *pNtk, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int nSeed, int fCheck, int fVerbose) {
Abc_Ntk_t *Abc_ManRewireInt(Abc_Ntk_t *pNtk, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int nSeed, int fCheck, int fVerbose) {
Random_Num(nSeed == 0 ? Abc_Random(0) % 10 : nSeed);
assert(Abc_NtkCiNum(pNtk) <= 58);
int fMapped = nMode == 1;
Vec_Int_t *vMapping = (Abc_NtkHasMapping(pNtk)) ? Abc_ManRewireNtkWriteMiniMapping(pNtk) : NULL;
float objectiveValue = (vMapping) ? (fTiming ? Abc_NtkDelayTrace(pNtk, 0, 0, 0) : Abc_NtkGetMappedArea(pNtk)) : 0.0f;
Rewire::Miaig pNtkMiaig(pNtk);
if (vMapping)
pNtkMiaig.setMapped(vMapping, objectiveValue);
if (pExc)
pNtkMiaig.setExc(pExc);
Rewire::Miaig pNew = pNtkMiaig.rewire(nIters, levelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, fMapped, nMappedMode, nDist, fCheck, NULL, fVerbose);
Rewire::Miaig pNew = pNtkMiaig.rewire(nIters, levelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, fDch, fTiming, fCheck, NULL, fVerbose);
pNew.setName(Abc_NtkName(pNtk));
if (nMode > 0) {
pNew.countTransistors(1, nMappedMode);
}
return pNew.toNtk(nMode >= 1);
return pNew.toNtk(fMapped);
}
Mini_Aig_t *MiniAig_ManRewireInt(Mini_Aig_t *pAig, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int nSeed, int fCheck, int fVerbose) {
Mini_Aig_t *MiniAig_ManRewireInt(Mini_Aig_t *pAig, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int nSeed, int fCheck, int fVerbose) {
Random_Num(nSeed == 0 ? Abc_Random(0) % 10 : nSeed);
assert(Mini_AigPiNum(pAig) <= 58);
Rewire::Miaig pNtkMiaig(pAig);
if (pExc)
pNtkMiaig.setExc(pExc);
Rewire::Miaig pNew = pNtkMiaig.rewire(nIters, levelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, fCheck, NULL, fVerbose);
Rewire::Miaig pNew = pNtkMiaig.rewire(nIters, levelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, fDch, fTiming, fCheck, NULL, fVerbose);
return pNew.toMiniAig();
}
@ -94,8 +120,9 @@ void Miaig::create(int nIns, int nOuts, int nObjsAlloc) {
_data->vOrderF = Vi_Alloc(1000);
_data->vOrderF2 = Vi_Alloc(1000);
_data->vTfo = Vi_Alloc(1000);
_data->pvFans = (vi *)calloc(sizeof(vi), _data->nObjsAlloc);
_data->pvFanins = (vi *)calloc(sizeof(vi), _data->nObjsAlloc);
_data->pLevel = nullptr;
_data->pDist = nullptr;
_data->pTable = nullptr;
_data->refcount = 1;
_refcount = &_data->refcount;
@ -115,23 +142,66 @@ void Miaig::setName(char *pName) {
}
}
void Miaig::print(void) {
int i, k, iLit;
printf("\nAIG printout:\n");
printf("Const0\n");
Miaig_ForEachInput(i)
printf("Pi%d\n", i);
Miaig_ForEachNode(i) {
printf("Node%d {", i);
Miaig_ForEachObjFanin(i, iLit, k)
printf(" %d", iLit);
printf(" }\n");
void Miaig::setMapped(Vec_Int_t *vMapping, float objectiveValue) {
if (_data) {
if (_data->pNtkMapped) {
Vi_Free(_data->pNtkMapped);
}
_data->pNtkMapped = moveVecToVi(vMapping);
_data->objectiveValue = objectiveValue;
}
Miaig_ForEachOutput(i) {
printf("Po%d ", i);
}
void Miaig::printNode(int i) {
if (!_data) return;
int iLit, k;
if (i == 0) {
printf("Const0\n");
} else if (i <= nIns()) {
printf("Pi%d", i);
if (!_data->pvFanouts) {
printf("\n"); return;
}
printf(" Fanouts: {");
Miaig_ForEachObjFanout(i, iLit, k)
printf(" %d", iLit); // this is a variable
printf(" }");
if (!_data->pRequire) {
printf("\n"); return;
}
printf(" Require: %d\n", objRequire(i));
} else if (i < nObjs() - nOuts()) {
printf("Node%d Level: %d Fanins: {", i, objLevel(i));
Miaig_ForEachObjFanin(i, iLit, k)
printf(" %d", iLit);
printf("\n");
printf(" %s%d", Rw_LitIsCompl(iLit) ? "~" : "", Rw_Lit2Var(iLit)); // this is a literal
printf(" }");
if (!_data->pvFanouts) {
printf("\n"); return;
}
printf(" Fanouts: {");
Miaig_ForEachObjFanout(i, iLit, k)
printf(" %d", iLit); // this is a variable
printf(" }");
if (!_data->pRequire) {
printf("\n"); return;
}
printf(" Require: %d\n", objRequire(i));
} else {
printf("Po%d ", i - nObjs() + nOuts());
Miaig_ForEachObjFanin(i, iLit, k)
printf(" %s%d", Rw_LitIsCompl(iLit) ? "~" : "", Rw_Lit2Var(iLit));
if (!_data->pRequire) {
printf("\n"); return;
}
printf(" Require: %d\n", objRequire(i));
}
}
void Miaig::print(void) {
int i;
printf("\nAIG printout:\n");
Miaig_ForEachObj(i) {
printNode(i);
}
}
@ -242,15 +312,6 @@ Abc_Ntk_t *Miaig::toNtk(int fMapped) {
return pNtk;
}
vi *moveVecToVi(Vec_Int_t *v) {
vi *p = (vi *)malloc(sizeof(vi));
p->size = Vec_IntSize(v);
p->cap = Vec_IntCap(v);
p->ptr = Vec_IntArray(v);
free(v);
return p;
}
void Miaig::setExc(Gia_Man_t *pExc) {
int i;
assert(Gia_ManCiNum(pExc) == nIns());
@ -271,13 +332,14 @@ void Miaig::setExc(Gia_Man_t *pExc) {
#endif // RW_ABC
// technology mapping
float Miaig::countTransistors(int reset, int nMappedMode) {
if (!reset && _data->nTransistor) return _data->nTransistor;
float Miaig::countMappedArea(int reset, int nMappedMode, int fDch) {
if (!reset && _data->objectiveValue) return _data->objectiveValue;
#ifdef RW_ABC
float area = 0;
Abc_Ntk_t *pNtkMapped = NULL, *pNtkMappedTemp = NULL;
if (nMappedMode == 0) { // amap
Abc_Ntk_t *pNtk = toNtk();
if (fDch) pNtk = Abc_ManRewireDch(pNtk);
pNtkMapped = Abc_ManRewireMapAmap(pNtk);
Abc_NtkDelete(pNtk);
} else if (nMappedMode == 1) { // &nf
@ -306,7 +368,36 @@ float Miaig::countTransistors(int reset, int nMappedMode) {
float area = countAnd2(reset, 0);
#endif // RW_ABC
return _data->nTransistor = area;
return _data->objectiveValue = area;
}
float Miaig::countMappedDelay(int reset, int nMappedMode, int fDch) {
if (!reset && _data->objectiveValue) return _data->objectiveValue;
#ifdef RW_ABC
float delay = 0;
Abc_Ntk_t *pNtkMapped = NULL;
if (nMappedMode == 0) { // amap
Abc_Ntk_t *pNtk = toNtk();
pNtkMapped = Abc_ManRewireMapAmap(pNtk);
Abc_NtkDelete(pNtk);
} else if (nMappedMode == 1) { // &nf
Gia_Man_t *pGia = toGia();
pNtkMapped = Gia_ManRewireMapNf(pGia);
Gia_ManStop(pGia);
} else if (nMappedMode == 2) { // &simap
printf("[Warning] The &simap mode is not supported for delay optimization.\n");
}
if (pNtkMapped) {
delay = Abc_NtkDelayTrace(pNtkMapped, 0, 0, 0);
Vec_Int_t *vMapping = Abc_ManRewireNtkWriteMiniMapping(pNtkMapped);
_data->pNtkMapped = moveVecToVi(vMapping);
Abc_NtkDelete(pNtkMapped);
}
#else
float delay = countLevel(reset, 0);
#endif // RW_ABC
return _data->objectiveValue = delay;
}
// topological collection
@ -340,7 +431,7 @@ int Miaig::initializeLevels_rec(int iObj) {
Miaig_ForEachObjFanin(iObj, iLit, i) {
level = Abc_MaxInt(initializeLevels_rec(Rw_Lit2Var(iLit)), level);
}
return objLevel(iObj) = level + 1;
return objLevel(iObj) = level + objFaninNum(iObj) - 1;
}
void Miaig::initializeLevels(void) {
@ -351,14 +442,28 @@ void Miaig::initializeLevels(void) {
Miaig_ForEachObj(i) {
objLevel(i) = -1;
}
Miaig_ForEachConstInput(i) {
objLevel(i) = 0;
objLevel(0) = 0; // const0 is always at level 0
Miaig_ForEachInput(i) {
objLevel(i) = (_data->vCiArrs) ? Vi_Read(_data->vCiArrs, i - 1) : 0; // modify this from external level if provided
}
Miaig_ForEachOutput(i) {
objLevel(i) = initializeLevels_rec(Rw_Lit2Var(objFanin0(i)));
}
}
void Miaig::updateLevels_rec(int iObj) {
assert(_data->pLevel);
assert(_data->pvFanouts);
int i, iLit, level = -1;
Miaig_ForEachObjFanin(iObj, iLit, i) {
level = Abc_MaxInt(objLevel(Rw_Lit2Var(iLit)), level);
}
objLevel(iObj) = level + objFaninNum(iObj) - 1;
Miaig_ForEachObjFanout(iObj, iLit, i) {
updateLevels_rec(iLit); // this is a variable
}
}
// distance computation
void Miaig::initializeDists(void) {
if (_data->pDist) return;
@ -395,30 +500,72 @@ void Miaig::markDistanceN(int iObj, int n) {
}
}
void Miaig::markCritical(void) {
void Miaig::initializeRequire_rec(int iObj) {
int i, iLit, requireTime = RW_INT_MAX;
if (objIsPo(iObj)) return;
Miaig_ForEachObjFanout(iObj, iLit, i) { // this is a variable
initializeRequire_rec(iLit);
}
Miaig_ForEachObjFanout(iObj, iLit, i) { // this is a variable
requireTime = Rw_MinInt(objRequire(iLit) - (objFaninNum(iLit) - 1), requireTime);
}
objRequire(iObj) = requireTime;
}
void Miaig::initializeRequire(void) {
if (_data->pRequire) return;
_data->pRequire = (int *)malloc(sizeof(int) * nObjs());
memset(_data->pRequire, 0, sizeof(int) * nObjs());
int iObj;
int maxRequire = countLevel(0);
nTravIds()++;
Miaig_ForEachOutput(iObj) {
if (objLevel(iObj) != maxRequire) continue;
markCritical_rec(iObj);
if (_data->vCoReqs) {
Miaig_ForEachOutput(iObj) {
objRequire(iObj) = Vi_Read(_data->vCoReqs, iObj - nObjs() + nOuts());
}
} else {
int maxRequireTime = countLevel();
Miaig_ForEachOutput(iObj) {
objRequire(iObj) = maxRequireTime;
}
}
Miaig_ForEachInput(iObj) {
initializeRequire_rec(iObj);
}
}
void Miaig::markCritical_rec(int iObj) {
objTravId(iObj) = nTravIds();
if (objIsPi(iObj)) return;
int iLit, k;
int maxFaninLevel = objLevel(Rw_Lit2Var(objFanin0(iObj)));
Miaig_ForEachObjFaninStart(iObj, iLit, k, 1) {
maxFaninLevel = Rw_MaxInt(maxFaninLevel, objLevel(Rw_Lit2Var(iLit)));
void Miaig::updateRequire_rec(int iObj) {
assert(_data->pRequire);
assert(_data->pvFanouts);
int i, iLit, requireTime = RW_INT_MAX;
Miaig_ForEachObjFanout(iObj, iLit, i) { // this is a variable
requireTime = Rw_MinInt(objRequire(iLit) - (objFaninNum(iLit) - 1), requireTime);
}
Miaig_ForEachObjFanin(iObj, iLit, k) {
if (objLevel(Rw_Lit2Var(iLit)) != maxFaninLevel) continue;
markCritical_rec(Rw_Lit2Var(iLit));
objRequire(iObj) = requireTime;
Miaig_ForEachObjFanin(iObj, iLit, i) {
updateRequire_rec(Rw_Lit2Var(iLit));
}
}
void Miaig::checkTiming(vi *vCiArrs, vi *vCoReqs) {
if (_data->pLevel) free(_data->pLevel), _data->pLevel = nullptr;
if (_data->pRequire) free(_data->pRequire), _data->pRequire = nullptr;
this->attachTiming(vCiArrs, vCoReqs);
initializeLevels();
initializeRequire();
int iObj;
Miaig_ForEachOutput(iObj) {
if (objLevel(iObj) > objRequire(iObj)) {
printf("Timing error: output %d has arrival %d but require %d.\n", iObj, objLevel(iObj), objRequire(iObj));
exit(1);
}
}
}
void Miaig::initializeFanouts(void) {
if (_data->pvFanouts) return;
_data->pvFanouts = (vi *)calloc(sizeof(vi), _data->nObjsAlloc);
}
// reference counting
void Miaig::refObj(int iObj) {
int k, iLit;
@ -485,9 +632,10 @@ int Miaig::markDfs(void) {
}
// simple duplicator (optionally removes unused nodes)
Miaig Miaig::dup(int fRemDangle, int fMapped) {
// Miaig pNew = Maig_Alloc(nIns(), nOuts(), nObjs());
Miaig Miaig::dup(int fRemDangle, int fFanout, int fMapped) {
Miaig pNew(nIns(), nOuts(), nObjs());
pNew.attachTiming(_data->vCiArrs, _data->vCoReqs);
if (fFanout) pNew.initializeFanouts();
memset(_data->pCopy, 0, sizeof(int) * nObjs());
int i, k, iLit; // obj2obj
if (fRemDangle)
@ -502,8 +650,10 @@ Miaig Miaig::dup(int fRemDangle, int fMapped) {
Miaig_ForEachObjFanin(i, iLit, k)
pNew.appendFanin(objCopy(i), Rw_Lit2LitV(_data->pCopy, iLit));
}
if (_data->pNtkMapped && fMapped)
if (_data->pNtkMapped && fMapped) {
pNew._data->pNtkMapped = Vi_Dup(_data->pNtkMapped);
pNew._data->objectiveValue = _data->objectiveValue;
}
return pNew;
}
@ -528,6 +678,7 @@ void Miaig::dupDfs_rec(Miaig &pNew, int iObj) {
Miaig Miaig::dupDfs(void) {
Miaig pNew(nIns(), nOuts(), nObjsAlloc());
pNew.attachTiming(_data->vCiArrs, _data->vCoReqs);
// 1. the array is filled with -1 to distinct visited nodes from unvisited
memset(_data->pCopy, 0xFF, sizeof(int) * nObjsAlloc());
int i; // obj2obj
@ -642,9 +793,10 @@ int Miaig::buildNodeCascade(Miaig &pNew, vi *vFanins, int fCprop, int fStrash) {
return iLit;
}
Miaig Miaig::dupStrash(int fCprop, int fStrash, int fCascade) {
Miaig Miaig::dupStrash(int fCprop, int fStrash, int fCascade, int fFanout) {
int i, nObjsAlloc = 1 + nIns() + nOuts() + countAnd2();
Miaig pNew(nIns(), nOuts(), nObjsAlloc);
pNew.attachTiming(_data->vCiArrs, _data->vCoReqs);
memset(_data->pCopy, 0, sizeof(int) * nObjs()); // obj2lit
if (fStrash) {
assert(pNew._data->pTable == NULL);
@ -662,7 +814,7 @@ Miaig Miaig::dupStrash(int fCprop, int fStrash, int fCascade) {
}
Miaig_ForEachOutput(i)
pNew.appendFanin(pNew.appendObj(), Rw_Lit2LitL(_data->pCopy, objFanin0(i)));
return pNew.dup(1);
return pNew.dup(1, fFanout, 0);
}
// this duplicator converts two-input-node AIG into multi-input-node AIG
@ -692,12 +844,14 @@ void Miaig::collectSuper_rec(int iLit, int *pStop, vi *vSuper) {
}
}
Miaig Miaig::dupMulti(int nFaninMax_, int nGrowth) {
Miaig Miaig::dupMulti(int nFaninMax, int nGrowth) {
Miaig pNew(nIns(), nOuts(), nObjs());
pNew.attachTiming(_data->vCiArrs, _data->vCoReqs);
pNew.initializeFanouts();
int *pStop = createStops();
int i, k, iLit;
vi *vArray = Vi_Alloc(100);
assert(nFaninMax_ >= 2 && nGrowth >= 1);
assert(nFaninMax >= 2 && nGrowth >= 1);
memset(_data->pCopy, 0, sizeof(int) * nObjs()); // obj2lit
Miaig_ForEachConstInput(i)
objCopy(i) = Rw_Var2Lit(i, 0);
@ -714,9 +868,9 @@ Miaig Miaig::dupMulti(int nFaninMax_, int nGrowth) {
if (Vi_Size(vArray) == 1)
objCopy(i) = Vi_Read(vArray, 0);
else {
int nFaninMaxLocal = 2 + (Random_Num(0) % (nFaninMax_ - 1));
int nFaninMaxLocal = 2 + (Random_Num(0) % (nFaninMax - 1));
int nGrowthLocal = 1 + (Random_Num(0) % nGrowth);
assert(nFaninMaxLocal >= 2 && nFaninMaxLocal <= nFaninMax_);
assert(nFaninMaxLocal >= 2 && nFaninMaxLocal <= nFaninMax);
assert(nGrowthLocal >= 1 && nGrowthLocal <= nGrowth);
if (Vi_Size(vArray) > nFaninMaxLocal)
@ -754,6 +908,29 @@ Miaig Miaig::dupMulti(int nFaninMax_, int nGrowth) {
return pNew;
}
Miaig Miaig::dupExtend(int nFaninMax, int nGrowth) {
Miaig pNew(nIns(), nOuts(), nObjs());
pNew.attachTiming(_data->vCiArrs, _data->vCoReqs);
pNew.initializeFanouts();
memset(_data->pCopy, 0, sizeof(int) * nObjs());
int iObj, k, iLit; // obj2obj
Miaig_ForEachInput(iObj)
objCopy(iObj) = iObj;
Miaig_ForEachNodeOutput(iObj) {
int nFaninMaxLocal = 2 + (Random_Num(0) % (nFaninMax - 1));
int nGrowthLocal = 1 + (Random_Num(0) % nGrowth);
assert(objFaninNum(iObj) > 0);
objCopy(iObj) = pNew.appendObj();
vi *vFanins = pNew.objFanins(iObj);
assert(vFanins->ptr == NULL);
vFanins->cap = nFaninMaxLocal + nGrowthLocal;
vFanins->ptr = (int *)malloc(sizeof(int) * vFanins->cap);
Miaig_ForEachObjFanin(iObj, iLit, k)
pNew.appendFanin(objCopy(iObj), Rw_Lit2LitV(_data->pCopy, iLit));
}
return pNew;
}
// compute truth table of the node
void Miaig::truthSimNode(int i) {
int k, iLit;
@ -965,9 +1142,9 @@ int Miaig::findShared(int nNewNodesMax) {
if (nObjs() + nNewNodesMax > nObjsAlloc()) {
nObjsAlloc() = nObjs() + nNewNodesMax;
_data->pCopy = (int *)realloc((void *)_data->pCopy, sizeof(int) * nObjsAlloc());
_data->pvFans = (vi *)realloc((void *)_data->pvFans, sizeof(vi) * nObjsAlloc());
_data->pvFanins = (vi *)realloc((void *)_data->pvFanins, sizeof(vi) * nObjsAlloc());
memset(_data->pCopy + nObjs(), 0, sizeof(int) * (nObjsAlloc() - nObjs()));
memset(_data->pvFans + nObjs(), 0, sizeof(vi) * (nObjsAlloc() - nObjs()));
memset(_data->pvFanins + nObjs(), 0, sizeof(vi) * (nObjsAlloc() - nObjs()));
}
assert(sizeof(word) == 8);
int i, nWords = (2 * nObjsAlloc() + 63) / 64; // how many words are needed to have a bitstring with one bit for each literal
@ -992,8 +1169,14 @@ int Miaig::findShared(int nNewNodesMax) {
int Miaig::checkConst(int iObj, word *pCare, word *pExc, int fCheck, int fVerbose) {
word *pFunc = objTruth(iObj, 0);
int iLit, i;
if (!Tt_IntersectC(pCare, pFunc, 0, nWords())) {
derefObj_rec(iObj, -1);
if (_data->pvFanouts) {
Miaig_ForEachObjFanin(iObj, iLit, i) {
Vi_Remove(objFanouts(Rw_Lit2Var(iLit)), iObj);
}
}
Vi_Fill(objFanins(iObj), 1, 0); // const0
refObj(iObj);
truthUpdate(_data->vTfo, pExc, fCheck);
@ -1002,6 +1185,11 @@ int Miaig::checkConst(int iObj, word *pCare, word *pExc, int fCheck, int fVerbos
}
if (!Tt_IntersectC(pCare, pFunc, 1, nWords())) {
derefObj_rec(iObj, -1);
if (_data->pvFanouts) {
Miaig_ForEachObjFanin(iObj, iLit, i) {
Vi_Remove(objFanouts(Rw_Lit2Var(iLit)), iObj);
}
}
Vi_Fill(objFanins(iObj), 1, 1); // const1
refObj(iObj);
truthUpdate(_data->vTfo, pExc, fCheck);
@ -1011,7 +1199,49 @@ int Miaig::checkConst(int iObj, word *pCare, word *pExc, int fCheck, int fVerbos
return 0;
}
int Miaig::expandOne(int iObj, int nAddedMax, int nDist, int nExpandableLevel, word *pExc, int fCheck, int fVerbose) {
void Miaig::expandOneHeuristicSort(int *pOrderF, int fTiming) {
std::stable_sort(pOrderF, pOrderF + Vi_Size(_data->vOrderF), [&](int a, int b) {
return objLevel(Rw_Lit2Var(a)) > objLevel(Rw_Lit2Var(b));
});
#if USE_OLD_LEVEL_SORTING
std::stable_sort(pOrderF, pOrderF + Vi_Size(_data->vOrderF), [&](int a, int b) {
if (objLevel(Rw_Lit2Var(a)) == 0 || objLevel(Rw_Lit2Var(b)) == 0) {
return false;
}
return objRef(Rw_Lit2Var(a)) < objRef(Rw_Lit2Var(b));
});
#else
// Sort all literals by objRef except in the case where they refer to a variable on level zero.
// Level zero literals are always sorted before non-level zero literals. Two level zero literals are ordered by their
// objRef to maintain strict weak ordering.
std::stable_sort(pOrderF, pOrderF + Vi_Size(_data->vOrderF), [&](int a, int b) {
bool a_is_level_0 = (objLevel(Rw_Lit2Var(a)) == 0);
bool b_is_level_0 = (objLevel(Rw_Lit2Var(b)) == 0);
// Always sort level 0 literals before the rest.
if (a_is_level_0 && !b_is_level_0) {
return true; // a (level 0) comes before b (non-level 0)
}
if (!a_is_level_0 && b_is_level_0) {
return false; // b (level 0) comes before a (non-level 0)
}
// If both are level 0 or none are level 0, then sort by objRef.
// If both are level 0 the relative ordering (probably?) doesn't matter,
// so we can just order them anyway by objRef such that we maintain the strict weak ordering.
return objRef(Rw_Lit2Var(a)) < objRef(Rw_Lit2Var(b));
});
#endif
if (fTiming) {
std::stable_sort(pOrderF, pOrderF + Vi_Size(_data->vOrderF), [&](int a, int b) {
return (objRequire(Rw_Lit2Var(a)) - objLevel(Rw_Lit2Var(a))) > (objRequire(Rw_Lit2Var(b)) - objLevel(Rw_Lit2Var(b)));
});
}
}
int Miaig::expandOne(int iObj, int nAddedMax, int nDist, int nExpandableLevel, word *pExc, int fTiming, int fCheck, int fVerbose) {
if (fTiming && objRequire(iObj) - objLevel(iObj) < 0) return 0; // skip nodes with slack violations
int i, k, n, iLit, nAdded = 0;
word *pCare = computeCareSet(iObj, pExc);
assert(nAddedMax > 0);
@ -1033,43 +1263,12 @@ int Miaig::expandOne(int iObj, int nAddedMax, int nDist, int nExpandableLevel, w
}
Vi_Randomize(_data->vOrderF);
int *pOrderF = Vi_Array(_data->vOrderF);
std::stable_sort(pOrderF, pOrderF + Vi_Size(_data->vOrderF), [&](int a, int b) {
return objLevel(Rw_Lit2Var(a)) > objLevel(Rw_Lit2Var(b));
});
#if USE_OLD_LEVEL_SORTING
std::stable_sort(pOrderF, pOrderF + Vi_Size(_data->vOrderF), [&](int a, int b) {
if (objLevel(Rw_Lit2Var(a)) == 0 || objLevel(Rw_Lit2Var(b)) == 0) {
return false;
}
return objRef(Rw_Lit2Var(a)) < objRef(Rw_Lit2Var(b));
});
#else
// Sort all literals by objRef except in the case where they refer to a variable on level zero.
// Level zero literals are always sorted before non-level zero literals. Two level zero literals are ordered by their
// objRef to maintain strict weak ordering.
std::stable_sort(pOrderF, pOrderF + Vi_Size(_data->vOrderF), [&](int a, int b) {
bool a_is_level_0 = (objLevel(Rw_Lit2Var(a)) == 0);
bool b_is_level_0 = (objLevel(Rw_Lit2Var(b)) == 0);
// Always sort level 0 literals before the rest.
if (a_is_level_0 && !b_is_level_0) {
return true; // a (level 0) comes before b (non-level 0)
}
if (!a_is_level_0 && b_is_level_0) {
return false; // b (level 0) comes before a (non-level 0)
}
// If both are level 0 or none are level 0, then sort by objRef.
// If both are level 0 the relative ordering (probably?) doesn't matter,
// so we can just order them anyway by objRef such that we maintain the strict weak ordering.
return objRef(Rw_Lit2Var(a)) < objRef(Rw_Lit2Var(b));
});
#endif
this->expandOneHeuristicSort(Vi_Array(_data->vOrderF), fTiming);
// iterate through candidate fanins (nodes that are not in the TFO of iObj)
Vi_ForEachEntry(_data->vOrderF, i, k) {
assert(objTravId(i) != nTravIds());
if (fTiming && Rw_MaxInt(objLevel(iObj), objLevel(i)) + objFaninNum(iObj) > objRequire(iObj)) continue;
// new fanin can be added if its offset does not intersect with the node's onset
for (n = 0; n < 2; n++)
if (!Tt_IntersectC(pOnset, objTruth(i, 0), !n, nWords())) {
@ -1077,18 +1276,59 @@ int Miaig::expandOne(int iObj, int nAddedMax, int nDist, int nExpandableLevel, w
appendFanin(iObj, Rw_Var2Lit(i, n));
objRef(i)++;
nAdded++;
if (fTiming) {
updateLevels_rec(iObj);
updateRequire_rec(iObj);
// checkTiming(_data->vCiArrs, _data->vCoReqs);
}
break;
}
if (nAdded == nAddedMax)
break;
}
//printf( "Updating TFO of node %d: ", iObj ); Vi_Print(_data->vTfo);
truthUpdate(_data->vTfo, pExc, fCheck);
//assert( objFaninNum(iObj) <= nFaninMax );
return nAdded;
}
int Miaig::reduceOne(int iObj, int fOnlyConst, int fOnlyBuffer, int fHeuristic, word *pExc, int fCheck, int fVerbose) {
void Miaig::reduceOneHeuristicSort(int *pOrderF, int fTiming) {
std::stable_sort(pOrderF, pOrderF + Vi_Size(_data->vOrderF), [&](int a, int b) {
return objLevel(Rw_Lit2Var(a)) < objLevel(Rw_Lit2Var(b));
});
#if USE_OLD_LEVEL_SORTING
std::stable_sort(pOrderF, pOrderF + Vi_Size(_data->vOrderF), [&](int a, int b) {
if (objLevel(Rw_Lit2Var(a)) == 0 || objLevel(Rw_Lit2Var(b)) == 0) {
return false;
}
return objRef(Rw_Lit2Var(a)) > objRef(Rw_Lit2Var(b));
});
#else
// Sort all literals by objRef except in the case where they refer to a variable on level zero.
// Level zero literals are always sorted before non-level zero literals. Two level zero literals are ordered by their
// objRef to maintain strict weak ordering.
std::stable_sort(pOrderF, pOrderF + Vi_Size(_data->vOrderF), [&](int a, int b) {
bool a_is_level_0 = (objLevel(Rw_Lit2Var(a)) == 0);
bool b_is_level_0 = (objLevel(Rw_Lit2Var(b)) == 0);
// Always sort level 0 literals before the rest.
if (a_is_level_0 && !b_is_level_0) {
return true; // a (level 0) comes before b (non-level 0)
}
if (!a_is_level_0 && b_is_level_0) {
return false; // b (level 0) comes before a (non-level 0)
}
// If both are level 0 or none are level 0, then sort by objRef.
// If both are level 0 the relative ordering (probably?) doesn't matter,
// so we can just order them anyway by objRef such that we maintain the strict weak ordering.
return objRef(Rw_Lit2Var(a)) < objRef(Rw_Lit2Var(b));
});
#endif
// if (fTiming) {
// }
}
int Miaig::reduceOne(int iObj, int fOnlyConst, int fOnlyBuffer, int fHeuristic, word *pExc, int fTiming, int fCheck, int fVerbose) {
int n, k, iLit, nFans = objFaninNum(iObj);
word *pCare = computeCareSet(iObj, pExc);
if (checkConst(iObj, pCare, pExc, fCheck, fVerbose))
@ -1102,9 +1342,7 @@ int Miaig::reduceOne(int iObj, int fOnlyConst, int fOnlyBuffer, int fHeuristic,
Miaig_ForEachObjFanin(iObj, iLit, k) {
Tt_DupC(_data->pProd, objTruth(Rw_Lit2Var(iLit), 0), Rw_LitIsCompl(iLit), nWords());
if (Tt_EqualOnCare(pCare, pFunc, _data->pProd, nWords())) {
derefObj(iObj);
Vi_Fill(objFanins(iObj), 1, iLit);
refObj(iObj);
setFanin(iObj, iLit);
truthUpdate(_data->vTfo, pExc, fCheck);
if (fVerbose) printf("Reducing node %d fanin count from %d to %d.\n", iObj, nFans, objFaninNum(iObj));
return nFans - 1;
@ -1118,40 +1356,7 @@ int Miaig::reduceOne(int iObj, int fOnlyConst, int fOnlyBuffer, int fHeuristic,
Vi_Randomize(_data->vOrderF);
if (fHeuristic) {
int *pOrderF = Vi_Array(_data->vOrderF);
std::stable_sort(pOrderF, pOrderF + Vi_Size(_data->vOrderF), [&](int a, int b) {
return objLevel(Rw_Lit2Var(a)) < objLevel(Rw_Lit2Var(b));
});
#if USE_OLD_LEVEL_SORTING
std::stable_sort(pOrderF, pOrderF + Vi_Size(_data->vOrderF), [&](int a, int b) {
if (objLevel(Rw_Lit2Var(a)) == 0 || objLevel(Rw_Lit2Var(b)) == 0) {
return false;
}
return objRef(Rw_Lit2Var(a)) > objRef(Rw_Lit2Var(b));
});
#else
// Sort all literals by objRef except in the case where they refer to a variable on level zero.
// Level zero literals are always sorted before non-level zero literals. Two level zero literals are ordered by their
// objRef to maintain strict weak ordering.
std::stable_sort(pOrderF, pOrderF + Vi_Size(_data->vOrderF), [&](int a, int b) {
bool a_is_level_0 = (objLevel(Rw_Lit2Var(a)) == 0);
bool b_is_level_0 = (objLevel(Rw_Lit2Var(b)) == 0);
// Always sort level 0 literals before the rest.
if (a_is_level_0 && !b_is_level_0) {
return true; // a (level 0) comes before b (non-level 0)
}
if (!a_is_level_0 && b_is_level_0) {
return false; // b (level 0) comes before a (non-level 0)
}
// If both are level 0 or none are level 0, then sort by objRef.
// If both are level 0 the relative ordering (probably?) doesn't matter,
// so we can just order them anyway by objRef such that we maintain the strict weak ordering.
return objRef(Rw_Lit2Var(a)) < objRef(Rw_Lit2Var(b));
});
#endif
this->reduceOneHeuristicSort(Vi_Array(_data->vOrderF), fTiming);
}
assert(Vi_Size(_data->vOrderF) == nFans);
@ -1166,9 +1371,19 @@ int Miaig::reduceOne(int iObj, int fOnlyConst, int fOnlyBuffer, int fHeuristic,
// update the node if it is reduced
if (Vi_Size(_data->vOrderF) < nFans) {
derefObj(iObj);
if (_data->pvFanouts) {
int iLit2, i;
Miaig_ForEachObjFanin(iObj, iLit2, i) {
Vi_Remove(objFanouts(Rw_Lit2Var(iLit2)), iObj);
}
}
Vi_Shrink(objFanins(iObj), 0);
Vi_ForEachEntry(_data->vOrderF, iLit, k)
Vi_ForEachEntry(_data->vOrderF, iLit, k) {
if (_data->pvFanouts) {
Vi_PushOrder(objFanouts(Rw_Lit2Var(iLit)), iObj);
}
Vi_PushOrder(objFanins(iObj), iLit);
}
refObj(iObj);
truthUpdate(_data->vTfo, pExc, fCheck);
if (fVerbose) printf("Reducing node %d fanin count from %d to %d.\n", iObj, nFans, objFaninNum(iObj));
@ -1177,9 +1392,9 @@ int Miaig::reduceOne(int iObj, int fOnlyConst, int fOnlyBuffer, int fHeuristic,
return 0;
}
int Miaig::expandThenReduceOne(int iNode, int nFaninAddLimit, int nDist, int nExpandableLevel, word *pExc, int fCheck, int fVerbose) {
expandOne(iNode, std::min(Vi_Space(objFanins(iNode)), nFaninAddLimit), nDist, nExpandableLevel, pExc, fCheck, fVerbose);
reduceOne(iNode, 0, 0, 0, pExc, fCheck, fVerbose);
int Miaig::expandThenReduceOne(int iNode, int nFaninAddLimit, int nDist, int nExpandableLevel, word *pExc, int fTiming, int fCheck, int fVerbose) {
expandOne(iNode, std::min(Vi_Space(objFanins(iNode)), nFaninAddLimit), nDist, nExpandableLevel, pExc, fTiming, fCheck, fVerbose);
reduceOne(iNode, 0, 0, 0, pExc, fTiming, fCheck, fVerbose);
return 0;
}
@ -1192,7 +1407,7 @@ vi *Miaig::createRandomOrder(void) {
return _data->vOrder;
}
Miaig Miaig::expand(int nFaninAddLimitAll, int nDist, int nExpandableLevel, word *pExc, int fCheck, int fVerbose) {
Miaig Miaig::expand(int nFaninAddLimitAll, int nDist, int nExpandableLevel, word *pExc, int fTiming, int fCheck, int fVerbose) {
int i, iNode, nAdded = 0;
assert(nFaninAddLimitAll > 0);
vi *vOrder = createRandomOrder();
@ -1201,8 +1416,9 @@ Miaig Miaig::expand(int nFaninAddLimitAll, int nDist, int nExpandableLevel, word
initializeRefs();
initializeLevels();
if (nDist) initializeDists();
if (fTiming) initializeRequire();
Vi_ForEachEntry(vOrder, iNode, i) {
nAdded += expandOne(iNode, std::min(Vi_Space(objFanins(iNode)), nFaninAddLimitAll - nAdded), nDist, nExpandableLevel, pExc, fCheck, fVerbose);
nAdded += expandOne(iNode, std::min(Vi_Space(objFanins(iNode)), nFaninAddLimitAll - nAdded), nDist, nExpandableLevel, pExc, fTiming, fCheck, fVerbose);
if (nAdded >= nFaninAddLimitAll)
break;
}
@ -1213,7 +1429,7 @@ Miaig Miaig::expand(int nFaninAddLimitAll, int nDist, int nExpandableLevel, word
// perform shared logic extraction
Miaig Miaig::share(int nNewNodesMax) {
Miaig pCopy = dup(0);
Miaig pCopy = dup(0, 0, 0);
int nNewNodes = pCopy.findShared(nNewNodesMax);
if (nNewNodes == 0)
return pCopy;
@ -1224,7 +1440,7 @@ Miaig Miaig::share(int nNewNodesMax) {
return pNew;
}
Miaig Miaig::reduce(word *pExc, int fCheck, int fVerbose) {
Miaig Miaig::reduce(word *pExc, int fTiming, int fCheck, int fVerbose) {
int i, iNode;
vi *vOrder = topoCollect();
@ -1233,13 +1449,12 @@ Miaig Miaig::reduce(word *pExc, int fCheck, int fVerbose) {
initializeLevels();
// works best for final
Vi_ForEachEntry(vOrder, iNode, i)
reduceOne(iNode, 0, 0, 1, pExc, fCheck, fVerbose);
reduceOne(iNode, 0, 0, 1, pExc, fTiming, fCheck, fVerbose);
if (fCheck) verifyRefs();
return dupStrash(1, 1, 1);
return dupStrash(1, 1, !fTiming);
}
Miaig Miaig::expandThenReduce(int nFaninAddLimit, int nDist, int nExpandableLevel, word *pExc, int fCheck, int fVerbose) {
Miaig pTemp;
Miaig Miaig::expandThenReduce(int nFaninAddLimit, int nDist, int nExpandableLevel, word *pExc, int fTiming, int fCheck, int fVerbose) {
int i, iNode;
vi *vOrder = topoCollect();
@ -1247,20 +1462,21 @@ Miaig Miaig::expandThenReduce(int nFaninAddLimit, int nDist, int nExpandableLeve
initializeRefs();
initializeLevels();
if (nDist) initializeDists();
if (fTiming) initializeRequire();
Vi_ForEachEntry(vOrder, iNode, i) {
expandThenReduceOne(iNode, nFaninAddLimit, nDist, nExpandableLevel, pExc, fCheck, fVerbose);
expandThenReduceOne(iNode, nFaninAddLimit, nDist, nExpandableLevel, pExc, fTiming, fCheck, fVerbose);
}
if (fCheck) verifyRefs();
return dupDfs().dupStrash(1, 1, 1);
return dupDfs().dupStrash(1, 1, !fTiming, 1);
}
Miaig Miaig::expandShareReduce(int nFaninAddLimitAll, int nDivs, int nDist, int nExpandableLevel, word *pExc, int fCheck, int nVerbose) {
Miaig Miaig::expandShareReduce(int nFaninAddLimitAll, int nDivs, int nDist, int nExpandableLevel, word *pExc, int fTiming, int fCheck, int nVerbose) {
// expand
Miaig pNew = expand(nFaninAddLimitAll, nDist, nExpandableLevel, pExc, fCheck, nVerbose);
Miaig pNew = expand(nFaninAddLimitAll, nDist, nExpandableLevel, pExc, fTiming, fCheck, nVerbose);
// share
pNew = pNew.share(nDivs == -1 ? pNew.nObjs() : nDivs);
// reduce
pNew = pNew.reduce(pExc, fCheck, nVerbose);
pNew = pNew.reduce(pExc, fTiming, fCheck, nVerbose);
return pNew;
}
@ -1287,63 +1503,67 @@ Miaig randomReadExcept(std::vector<Miaig> &pBests, Miaig &pExcept) {
return (pBests[iNum] == pExcept) ? pBests[(iNum + 1) % pBests.size()] : pBests[iNum];
}
Miaig Miaig::rewire(int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fCheck, Gia_ChMan_t *pChMan, int nVerbose) {
Miaig Miaig::rewire(int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int fCheck, Gia_ChMan_t *pChMan, int nVerbose) {
const int nRootSave = 8;
const int nBestSave = 4;
int iter = 0;
int nRestart = 5000;
std::vector<Miaig> pRoots = {this->dup(0)};
std::vector<Miaig> pBests = {this->dup(0)}; Miaig pInit = pBests[0];
std::vector<Miaig> pRoots = {this->dup(0, 0, 1)};
std::vector<Miaig> pBests = {this->dup(0, 0, 1)}; Miaig pInit = pBests[0];
iword clkStart = Time_Clock();
Miaig pNew;
Miaig pRoot = pRoots[0];
Miaig pBest = this->dup(0); int improved = 0;
float (Miaig::*Miaig_ObjectiveFunction)(int, int) = (nMode == 0) ? &Miaig::countAnd2 : &Miaig::countTransistors;
Miaig pBest = this->dup(0, 0, 1); int improved = 0;
float (Miaig::*Miaig_ObjectiveFunction)(int, int, int) = (nMode == 0) ? (fTiming ? &Miaig::countLevel: &Miaig::countAnd2) : (fTiming ? &Miaig::countMappedDelay : &Miaig::countMappedArea);
int maxLevel = levelGrowRatio != 0 ? this->countLevel() * levelGrowRatio : 0;
int nExpandableLevel = maxLevel ? maxLevel - this->countLevel() : 0;
int fMapped = nMode > 0;
int fMapped = nMode == 1;
word *pExc = _data->pExc;
float PrevBest = ((&pBest)->*Miaig_ObjectiveFunction)(1, nMappedMode);
float initCost = ((&pRoot)->*Miaig_ObjectiveFunction)(0, nMappedMode, fDch);
float bestCost = initCost;
int iterNotImproveAfterRestart = 0;
if (nVerbose && maxLevel) printf("Max level : %5d\n", maxLevel);
if (nVerbose) printf("Initial target : %5g (AND2 = %5g Level = %3d)\n", PrevBest, this->countAnd2(1), this->countLevel());
for (int i = 0; nIters ? i < nIters : 1; i++) {
if (nVerbose) printf("\rIteration %7d(%zu) : %5g -> ", i + 1, pBests.size(), ((&pRoot)->*Miaig_ObjectiveFunction)(0, nMappedMode));
if (nVerbose) printf("Initial target : %5g (AND2 = %5g Level = %3g)\n", bestCost, this->countAnd2(1), this->countLevel());
for (iter = 0; nIters ? iter < nIters : 1; iter++) {
if (nVerbose) printf("\rIteration %7d(%zu) : %5g (AND2 = %5g Level = %3g) -> ", iter + 1, pBests.size(), ((&pRoot)->*Miaig_ObjectiveFunction)(0, nMappedMode, fDch), pRoot.countAnd2(), pRoot.countLevel());
if (nTimeOut && nTimeOut < 1.0 * (Time_Clock() - clkStart) / CLOCKS_PER_SEC) break;
if (PrevBest == 0) break;
pNew = pRoot.dupMulti(nFaninMax, nGrowth);
if (bestCost == 0) break;
pNew = (fTiming) ? pRoot.dupExtend(nFaninMax, nGrowth) : pRoot.dupMulti(nFaninMax, nGrowth);
if (i % 2 == 0) {
pNew = pNew.expandThenReduce(nGrowth, nDist, nExpandableLevel, pExc, fCheck, nVerbose > 1);
if (iter % 2 == 0) {
pNew = pNew.expandThenReduce(nGrowth, nDist, nExpandableLevel, pExc, fTiming, fCheck, nVerbose > 1);
}
pNew = pNew.expandShareReduce(nExpands, nDivs, nDist, nExpandableLevel, pExc, fCheck, nVerbose > 1);
pNew = pNew.expandShareReduce(nExpands, nDivs, nDist, nExpandableLevel, pExc, fTiming, fCheck, nVerbose > 1);
++iterNotImproveAfterRestart;
// report
float rootTarget = ((&pRoot)->*Miaig_ObjectiveFunction)(0, nMappedMode);
float newTarget = ((&pNew)->*Miaig_ObjectiveFunction)(1, nMappedMode);
float rootTarget = ((&pRoot)->*Miaig_ObjectiveFunction)(0, nMappedMode, fDch);
float newTarget = ((&pNew)->*Miaig_ObjectiveFunction)(1, nMappedMode, fDch);
if (maxLevel ? pNew.countLevel() > maxLevel : 0) {
} else if (PrevBest > newTarget) {
if (nVerbose) printf("%5g (AND2 = %5g Level = %3d) ", newTarget, pNew.countAnd2(), pNew.countLevel());
if (nVerbose) Time_PrintEndl("Elapsed time", Time_Clock() - clkStart);
PrevBest = newTarget;
pBests = {pNew.dup(0), pNew.dup(0)};
pBest = pNew.dup(0, fMapped), improved = 1;
iterNotImproveAfterRestart = 0;
} else if (PrevBest == newTarget) {
randomAddBest(pBests, pNew.dup(0), nBestSave, pChMan);
} else if (bestCost >= newTarget) {
if ((bestCost > newTarget) || (fTiming && (pNew.countAnd2() < pBest.countAnd2()))) {
if (nVerbose) printf("%5g (AND2 = %5g Level = %3g) ", newTarget, pNew.countAnd2(), pNew.countLevel());
if (nVerbose) Time_PrintEndl("Elapsed time", Time_Clock() - clkStart);
bestCost = newTarget;
pBests = {pNew.dup(0, 0, fMapped), pNew.dup(0, 0, fMapped)};
pBest = pNew.dup(0, 0, fMapped), improved = 1;
iterNotImproveAfterRestart = 0;
} else if (!fTiming || (fTiming && pNew.countAnd2() <= pBest.countAnd2())) {
randomAddBest(pBests, pNew.dup(0, 0, fMapped), nBestSave, pChMan);
}
}
// compare
if (maxLevel ? pNew.countLevel() > maxLevel : 0) {
} else if (rootTarget < newTarget) {
if (iterNotImproveAfterRestart > nRestart) {
pNew = randomRead(pBests).dupMulti(nFaninMax, nGrowth);
pNew = pNew.expand(nExpands, nDist, nExpandableLevel, pExc, fCheck, nVerbose > 1);
pNew = (fTiming) ? randomRead(pBests).dupExtend(nFaninMax, nGrowth) : randomRead(pBests).dupMulti(nFaninMax, nGrowth);
pNew = pNew.expand(nExpands, nDist, nExpandableLevel, pExc, fTiming, fCheck, nVerbose > 1);
pNew = pNew.share(nDivs == -1 ? pNew.nObjs() : nDivs);
pNew = pNew.dupStrash(1, 1, 0);
pRoots = {pNew};
iterNotImproveAfterRestart = 0;
} else if (rootTarget * 1.05 > newTarget) {
} else if ((!fTiming && (rootTarget * 1.05 > newTarget))) {
pRoots = {pNew};
}
} else if (rootTarget == newTarget) {
@ -1354,6 +1574,7 @@ Miaig Miaig::rewire(int nIters, float levelGrowRatio, int nExpands, int nGrowth,
pRoot = randomRead(pRoots);
}
if (nVerbose) Time_PrintEndl("Total solving time", Time_Clock() - clkStart);
if (nVerbose) printf("Cumulatively reduced %s by %.2f %% (%g -> %g) after %d iterations.\n", fTiming ? "delay" : "area", 100.0*(initCost - bestCost) / (initCost), initCost, bestCost, iter);
return improved ? pBest : randomReadExcept(pBests, pInit);
}

View File

@ -1,6 +1,6 @@
/**CFile****************************************************************
FileName [rewire_miaig.h]
FileName [rewireMiaig.h]
SystemName [ABC: Logic synthesis and verification system.]
@ -14,7 +14,7 @@
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: rewire_miaig.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
Revision [$Id: rewireMiaig.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
@ -26,7 +26,7 @@
#ifdef RW_ABC
#include "base/abc/abc.h"
#include "aig/miniaig/miniaig.h"
#include "rewire_map.h"
#include "rewireMap.h"
#define RW_INT_MAX ABC_INT_MAX
#define Rw_MaxInt Abc_MaxInt
#define Rw_MinInt Abc_MinInt
@ -57,9 +57,9 @@ static inline int Rw_LitNot( int Lit ) { assert(Lit >= 0); return Lit
static inline int Rw_LitNotCond( int Lit, int c ) { assert(Lit >= 0); return Lit ^ (int)(c > 0); }
static inline int Rw_LitRegular( int Lit ) { assert(Lit >= 0); return Lit & ~01; }
#endif // RW_ABC
#include "rewire_vec.h"
#include "rewire_tt.h"
#include "rewire_time.h"
#include "rewireVec.h"
#include "rewireTt.h"
#include "rewireTime.h"
#include <vector>
@ -134,7 +134,7 @@ static inline int RW_XADD(int *addr, int delta) {
#define Miaig_CustomForEachNodeOutput(p, i) for (i = 1 + p->nIns; i < p->nObjs; i++)
#define Miaig_CustomForEachNodeOutputStart(p, i, s) for (i = s; i < p->nObjs; i++)
#define Miaig_CustomForEachObj(p, i) for (i = 0; i < p->nObjs; i++)
#define Miaig_CustomForEachObjFanin(p, i, iLit, k) Vi_ForEachEntry(&p->pvFans[i], iLit, k)
#define Miaig_CustomForEachObjFanin(p, i, iLit, k) Vi_ForEachEntry(&p->pvFanins[i], iLit, k)
#define Miaig_ForEachConstInput(i) for (i = 0; i <= _data->nIns; i++)
#define Miaig_ForEachInput(i) for (i = 1; i <= _data->nIns; i++)
@ -146,8 +146,9 @@ static inline int RW_XADD(int *addr, int delta) {
#define Miaig_ForEachNodeOutput(i) for (i = 1 + _data->nIns; i < _data->nObjs; i++)
#define Miaig_ForEachNodeOutputStart(i, s) for (i = s; i < _data->nObjs; i++)
#define Miaig_ForEachObj(i) for (i = 0; i < _data->nObjs; i++)
#define Miaig_ForEachObjFanin(i, iLit, k) Vi_ForEachEntry(&_data->pvFans[i], iLit, k)
#define Miaig_ForEachObjFaninStart(i, iLit, k, s) Vi_ForEachEntryStart(&_data->pvFans[i], iLit, k, s)
#define Miaig_ForEachObjFanin(i, iLit, k) Vi_ForEachEntry(&_data->pvFanins[i], iLit, k)
#define Miaig_ForEachObjFanout(i, iVar, k) Vi_ForEachEntry(&_data->pvFanouts[i], iVar, k)
#define Miaig_ForEachObjFaninStart(i, iLit, k, s) Vi_ForEachEntryStart(&_data->pvFanins[i], iLit, k, s)
static inline int Rw_Lit2LitV(int *pMapV2V, int Lit) {
assert(Lit >= 0);
@ -171,20 +172,26 @@ struct Miaig_Data {
int *pTravIds; // traversal IDs
int *pCopy; // temp copy
int *pRefs; // reference counters
int minLevel; // minimum level
int *pLevel; // levels
int *pDist; // distances
int *pRequire; // required times
word *pTruths[3]; // truth tables
word *pCare; // careset
word *pProd; // product
word *pExc; // Exc
word *pExc; // Exc
vi *vOrder; // node order
vi *vOrderF; // fanin order
vi *vOrderF2; // fanin order
vi *vTfo; // transitive fanout cone
vi *pvFans; // the array of objects' fanins
vi *pvFanins; // the array of objects' fanins (literal)
vi *pvFanouts; // the array of objects' fanouts (variable)
vi *vCiArrs; // the arrival times of CIs (if provided) not owned
vi *vCoReqs; // the required times of COs (if provided) not owned
vi *vTfoArrs; // the TFO of each
int *pTable; // structural hashing table
int TableSize; // the size of the hash table
float nTransistor; // objective value
float objectiveValue; // objective value
vi *pNtkMapped; // mapped network
};
@ -229,7 +236,9 @@ public:
int objPiIdx(int i); // No check isPi
int objPoIdx(int i); // No check isPo
void print(void);
void printNode(int i);
int appendObj(void);
void setFanin(int i, int iLit);
void appendFanin(int i, int iLit);
int objFaninNum(int i);
int objFanin0(int i);
@ -239,31 +248,39 @@ public:
int &objTravId(int i);
int &objCopy(int i);
int &objDist(int i);
int &objRequire(int i);
int &nTravIds(void);
word *objTruth(int i, int n);
vi *objFanins(int i);
vi *objFanouts(int i);
int objType(int i);
int nWords(void);
void refObj(int iObj);
void derefObj(int iObj);
void derefObj_rec(int iObj, int iLitSkip);
void setName(char *pName);
void setMapped(Vec_Int_t *vMapping, float objectiveValue = 0.0f);
void attachTiming(vi *vCiArrs, vi *vCoReqs);
void checkTiming(vi *vCiArrs, vi *vCoReqs);
private:
int initializeLevels_rec(int iObj);
void updateLevels_rec(int iObj);
void initializeLevels(void);
void initializeRefs(void);
void verifyRefs(void);
void initializeTruth(void);
void initializeDists(void);
void initializeFanouts(void);
void initializeRequire_rec(int iObj);
void updateRequire_rec(int iObj);
void initializeRequire(void);
private:
void markDfs_rec(int iObj);
int markDfs(void);
void markDistanceN_rec(int iObj, int n, int limit);
void markDistanceN(int Obj, int n);
void markCritical(void);
void markCritical_rec(int iObj);
void topoCollect_rec(int iObj);
vi *topoCollect(void);
void reduceFanins(vi *v);
@ -288,10 +305,11 @@ private:
int *hashLookup(int *pTable, int l0, int l1, int TableSize);
public:
float countAnd2(int reset = 0, int fDummy = 0);
float countAnd2(int reset = 0, int fDummy1 = 0, int fDummy2 = 0);
float countLevel(int reset = 0, int fDummy1 = 0, int fDummy2 = 0);
// 0: amap 1: &nf 2: &simap
float countTransistors(int reset = 0, int nMode = 0);
int countLevel(int min = 0);
float countMappedArea(int reset = 0, int nMode = 0, int fDch = 1);
float countMappedDelay(int reset = 0, int nMode = 0, int fDch = 1);
private:
void dupDfs_rec(Miaig &pNew, int iObj);
@ -303,21 +321,24 @@ private:
int buildNodeCascade(Miaig &pNew, vi *vFanins, int fCprop, int fStrash);
private:
int expandOne(int iObj, int nAddedMax, int nDist, int nExpandableLevel, word *pExc, int fCheck, int fVerbose);
int reduceOne(int iObj, int fOnlyConst, int fOnlyBuffer, int fHeuristic, word *pExc, int fCheck, int fVerbose);
int expandThenReduceOne(int iNode, int nFaninAddLimit, int nDist, int nExpandableLevel, word *pExc, int fCheck, int fVerbose);
void expandOneHeuristicSort(int *pOrderF, int fTiming);
void reduceOneHeuristicSort(int *pOrderF, int fTiming);
int expandOne(int iObj, int nAddedMax, int nDist, int nExpandableLevel, word *pExc, int fTiming, int fCheck, int fVerbose);
int reduceOne(int iObj, int fOnlyConst, int fOnlyBuffer, int fHeuristic, word *pExc, int fTiming, int fCheck, int fVerbose);
int expandThenReduceOne(int iNode, int nFaninAddLimit, int nDist, int nExpandableLevel, word *pExc, int fTiming, int fCheck, int fVerbose);
public:
Miaig dup(int fRemDangle, int fMapped = 0);
Miaig dup(int fRemDangle, int fFanout, int fMapped = 0);
Miaig dupDfs(void);
Miaig dupStrash(int fCprop, int fStrash, int fCascade);
Miaig dupMulti(int nFaninMax_, int nGrowth);
Miaig expand(int nFaninAddLimitAll, int nDist, int nExpandableLevel, word *pExc, int fCheck, int nVerbose);
Miaig dupStrash(int fCprop, int fStrash, int fCascade, int fFanout = 0);
Miaig dupMulti(int nFaninMax, int nGrowth);
Miaig dupExtend(int nFaninMax, int nGrowth);
Miaig expand(int nFaninAddLimitAll, int nDist, int nExpandableLevel, word *pExc, int fTiming, int fCheck, int nVerbose);
Miaig share(int nNewNodesMax);
Miaig reduce(word *pExc, int fCheck, int fVerbose);
Miaig expandThenReduce(int nFaninAddLimit, int nDist, int nExpandableLevel, word *pExc, int fCheck, int fVerbose);
Miaig expandShareReduce(int nFaninAddLimitAll, int nDivs, int nDist, int nExpandableLevel, word *pExc, int fCheck, int nVerbose);
Miaig rewire(int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fCheck, Gia_ChMan_t *pChMan, int nVerbose);
Miaig reduce(word *pExc, int fTiming, int fCheck, int fVerbose);
Miaig expandThenReduce(int nFaninAddLimit, int nDist, int nExpandableLevel, word *pExc, int fTiming, int fCheck, int fVerbose);
Miaig expandShareReduce(int nFaninAddLimitAll, int nDivs, int nDist, int nExpandableLevel, word *pExc, int fTiming, int fCheck, int nVerbose);
Miaig rewire(int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int fCheck, Gia_ChMan_t *pChMan, int nVerbose);
#ifdef RW_ABC
Gia_Man_t *toGia(void);
Abc_Ntk_t *toNtk(int fMapped = 0);
@ -390,10 +411,20 @@ inline void Miaig::release(void) {
if (_refcount && RW_XADD(_refcount, -1) == 1) {
if (_data) {
if (_data->pName) free(_data->pName);
for (int i = 0; i < _data->nObjsAlloc; ++i)
if (_data->pvFans[i].ptr)
free(_data->pvFans[i].ptr);
free(_data->pvFans);
for (int i = 0; i < _data->nObjsAlloc; ++i) {
if (_data->pvFanins[i].ptr) {
free(_data->pvFanins[i].ptr);
}
}
free(_data->pvFanins);
if (_data->pvFanouts) {
for (int i = 0; i < _data->nObjsAlloc; ++i) {
if (_data->pvFanouts[i].ptr) {
free(_data->pvFanouts[i].ptr);
}
}
free(_data->pvFanouts);
}
Vi_Free(_data->vOrder);
Vi_Free(_data->vOrderF);
Vi_Free(_data->vOrderF2);
@ -407,6 +438,7 @@ inline void Miaig::release(void) {
if (_data->pExc) free(_data->pExc);
if (_data->pLevel) free(_data->pLevel);
if (_data->pDist) free(_data->pDist);
if (_data->pRequire) free(_data->pRequire);
if (_data->pTable) free(_data->pTable);
if (_data->pNtkMapped) Vi_Free(_data->pNtkMapped);
delete _data;
@ -466,6 +498,22 @@ inline int Miaig::appendObj(void) {
inline void Miaig::appendFanin(int i, int iLit) {
Vi_PushOrder(objFanins(i), iLit);
if (_data->pvFanouts) {
Vi_PushOrder(objFanouts(Rw_Lit2Var(iLit)), i);
}
}
inline void Miaig::setFanin(int iObj, int iLit1) {
derefObj(iObj);
if (_data->pvFanouts) {
int iLit2, i;
Miaig_ForEachObjFanin(iObj, iLit2, i) {
if (Rw_Lit2Var(iLit1) == Rw_Lit2Var(iLit2)) continue;
Vi_Remove(objFanouts(Rw_Lit2Var(iLit2)), iObj);
}
}
Vi_Fill(objFanins(iObj), 1, iLit1);
refObj(iObj);
}
inline int Miaig::objFaninNum(int i) {
@ -501,6 +549,10 @@ inline int &Miaig::objDist(int i) {
return _data->pDist[i];
}
inline int &Miaig::objRequire(int i) {
return _data->pRequire[i];
}
inline int &Miaig::nTravIds(void) {
return _data->nTravIds;
}
@ -509,7 +561,9 @@ inline int Miaig::nWords(void) {
return _data->nWords;
}
inline float Miaig::countAnd2(int reset, int fDummy) {
inline float Miaig::countAnd2(int reset, int fDummy1, int fDummy2) {
(void)fDummy1;
(void)fDummy2;
int i, Counter = 0;
Miaig_ForEachNode(i) {
Counter += objFaninNum(i) - 1;
@ -517,12 +571,13 @@ inline float Miaig::countAnd2(int reset, int fDummy) {
return Counter;
}
inline int Miaig::countLevel(int min) {
inline float Miaig::countLevel(int reset, int fDummy1, int fDummy2) {
(void)fDummy1;
(void)fDummy2;
initializeLevels();
int i, Level = (min) ? RW_INT_MAX : -1;
int (*compareFunc)(int, int) = (min) ? Rw_MinInt : Rw_MaxInt;
int i, Level = -1;
Miaig_ForEachOutput(i) {
Level = compareFunc(Level, objLevel(i));
Level = Rw_MaxInt(Level, objLevel(i));
}
return Level;
}
@ -532,13 +587,25 @@ inline word *Miaig::objTruth(int i, int n) {
}
inline vi *Miaig::objFanins(int i) {
return _data->pvFans + i;
return _data->pvFanins + i;
}
inline vi *Miaig::objFanouts(int i) {
assert(_data->pvFanouts);
return _data->pvFanouts + i;
}
inline int Miaig::objType(int i) {
return objTravId(i) == nTravIds();
}
inline void Miaig::attachTiming(vi *vCiArrs, vi *vCoReqs) {
_data->vCiArrs = vCiArrs;
_data->vCoReqs = vCoReqs;
if (vCiArrs) assert(Vi_Size(vCiArrs) == nIns());
if (vCoReqs) assert(Vi_Size(vCoReqs) == nOuts());
}
} // namespace Rewire
#ifdef RW_ABC

View File

@ -1,6 +1,6 @@
/**CFile****************************************************************
FileName [rewire_rar.c]
FileName [rewireRar.c]
SystemName [ABC: Logic synthesis and verification system.]
@ -14,24 +14,24 @@
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: rewire_rar.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
Revision [$Id: rewireRar.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "rewire_rar.h"
#include "rewireRar.h"
ABC_NAMESPACE_IMPL_START
Gia_Man_t *Gia_ManRewire(Gia_Man_t *pGia, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int nSeed, int fCheck, int fChoices, int fVerbose) {
return Gia_ManRewireInt(pGia, pExc, nIters, levelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, nSeed, fCheck, fChoices, fVerbose);
Gia_Man_t *Gia_ManRewire(Gia_Man_t *pGia, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int nSeed, int fCheck, int fChoices, int fVerbose) {
return Gia_ManRewireInt(pGia, pExc, nIters, levelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, fDch, fTiming, nSeed, fCheck, fChoices, fVerbose);
}
Abc_Ntk_t *Abc_ManRewire(Abc_Ntk_t *pNtk, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int nSeed, int fCheck, int fVerbose) {
return Abc_ManRewireInt(pNtk, pExc, nIters, levelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, nSeed, fCheck, fVerbose);
Abc_Ntk_t *Abc_ManRewire(Abc_Ntk_t *pNtk, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int nSeed, int fCheck, int fVerbose) {
return Abc_ManRewireInt(pNtk, pExc, nIters, levelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, fDch, fTiming, nSeed, fCheck, fVerbose);
}
Mini_Aig_t *MiniAig_ManRewire(Mini_Aig_t *pAig, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int nSeed, int fCheck, int fVerbose) {
return MiniAig_ManRewireInt(pAig, pExc, nIters, levelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, nSeed, fCheck, fVerbose);
Mini_Aig_t *MiniAig_ManRewire(Mini_Aig_t *pAig, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int nSeed, int fCheck, int fVerbose) {
return MiniAig_ManRewireInt(pAig, pExc, nIters, levelGrowRatio, nExpands, nGrowth, nDivs, nFaninMax, nTimeOut, nMode, nMappedMode, nDist, fDch, fTiming, nSeed, fCheck, fVerbose);
}
ABC_NAMESPACE_IMPL_END

View File

@ -1,6 +1,6 @@
/**CFile****************************************************************
FileName [rewire_rar.h]
FileName [rewireRar.h]
SystemName [ABC: Logic synthesis and verification system.]
@ -14,7 +14,7 @@
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: rewire_rar.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
Revision [$Id: rewireRar.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
@ -35,12 +35,12 @@
ABC_NAMESPACE_HEADER_START
Gia_Man_t *Gia_ManRewire(Gia_Man_t *pGia, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int nSeed, int fCheck, int fChoices, int fVerbose);
Gia_Man_t *Gia_ManRewireInt(Gia_Man_t *pGia, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int nSeed, int fCheck, int fChoices, int fVerbose);
Abc_Ntk_t *Abc_ManRewire(Abc_Ntk_t *pNtk, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int nSeed, int fCheck, int fVerbose);
Abc_Ntk_t *Abc_ManRewireInt(Abc_Ntk_t *pNtk, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int nSeed, int fCheck, int fVerbose);
Mini_Aig_t *MiniAig_ManRewire(Mini_Aig_t *pAig, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int nSeed, int fCheck, int fVerbose);
Mini_Aig_t *MiniAig_ManRewireInt(Mini_Aig_t *pAig, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int nSeed, int fCheck, int fVerbose);
Gia_Man_t *Gia_ManRewire(Gia_Man_t *pGia, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int nSeed, int fCheck, int fChoices, int fVerbose);
Gia_Man_t *Gia_ManRewireInt(Gia_Man_t *pGia, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int nSeed, int fCheck, int fChoices, int fVerbose);
Abc_Ntk_t *Abc_ManRewire(Abc_Ntk_t *pNtk, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int nSeed, int fCheck, int fVerbose);
Abc_Ntk_t *Abc_ManRewireInt(Abc_Ntk_t *pNtk, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int nSeed, int fCheck, int fVerbose);
Mini_Aig_t *MiniAig_ManRewire(Mini_Aig_t *pAig, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int nSeed, int fCheck, int fVerbose);
Mini_Aig_t *MiniAig_ManRewireInt(Mini_Aig_t *pAig, Gia_Man_t *pExc, int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fDch, int fTiming, int nSeed, int fCheck, int fVerbose);
ABC_NAMESPACE_HEADER_END

View File

@ -1,6 +1,6 @@
/**CFile****************************************************************
FileName [rewire_rng.c]
FileName [rewireRng.c]
SystemName [ABC: Logic synthesis and verification system.]
@ -14,11 +14,11 @@
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: rewire_rng.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
Revision [$Id: rewireRng.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "rewire_rng.h"
#include "rewireRng.h"
ABC_NAMESPACE_IMPL_START

View File

@ -1,6 +1,6 @@
/**CFile****************************************************************
FileName [rewire_rng.h]
FileName [rewireRng.h]
SystemName [ABC: Logic synthesis and verification system.]
@ -14,7 +14,7 @@
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: rewire_rng.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
Revision [$Id: rewireRng.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/

View File

@ -1,6 +1,6 @@
/**CFile****************************************************************
FileName [rewire_time.h]
FileName [rewireTime.h]
SystemName [ABC: Logic synthesis and verification system.]
@ -14,7 +14,7 @@
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: rewire_time.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
Revision [$Id: rewireTime.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/

View File

@ -1,6 +1,6 @@
/**CFile****************************************************************
FileName [rewire_tt.h]
FileName [rewireTt.h]
SystemName [ABC: Logic synthesis and verification system.]
@ -14,7 +14,7 @@
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: rewire_tt.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
Revision [$Id: rewireTt.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/

View File

@ -1,6 +1,6 @@
/**CFile****************************************************************
FileName [rewire_vec.h]
FileName [rewireVec.h]
SystemName [ABC: Logic synthesis and verification system.]
@ -14,7 +14,7 @@
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: rewire_vec.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
Revision [$Id: rewireVec.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
@ -30,7 +30,7 @@
#include <assert.h>
#include <string.h>
#include "rewire_rng.h"
#include "rewireRng.h"
ABC_NAMESPACE_HEADER_START

View File

@ -69,6 +69,7 @@ struct Bmc_EsPar_t_
int nRandFuncs;
int nMintNum;
int Seed;
int fDumpBlif;
int fVerbose;
char * pTtStr;
char * pSymStr;

View File

@ -1642,21 +1642,40 @@ int Exa3_ManExactSynthesis( Bmc_EsPar_t * pPars )
else if ( status == GLUCOSE_UNDEC )
printf( "The solver timed out after %d sec.\n", pPars->RuntimeLim );
else
printf( "The problem has no solution.\n" );
printf( "The problem has no solution.\n" ), Res = 2;
printf( "Added = %d. Tried = %d. ", p->nUsed[1], p->nUsed[0] );
Abc_PrintTime( 1, "Total runtime", Abc_Clock() - clkTotal );
if ( iMint == -1 )
if ( iMint == -1 && pPars->fDumpBlif )
Exa3_ManDumpBlif( p, fCompl );
if ( pPars->pSymStr )
ABC_FREE( pPars->pTtStr );
Exa3_ManFree( p );
return Res;
}
char * Exa_TimeStamp()
{
static char Buffer[100];
time_t ltime;
struct tm *tm_info;
// Get the current time
time(&ltime);
tm_info = localtime(&ltime);
// Format the time as YYYY_MM_DD__HH_MM_SS
strftime(Buffer, sizeof(Buffer), "%Y_%m_%d__%H_%M_%S", tm_info);
return Buffer;
}
void Exa3_ManExactSynthesisRand( Bmc_EsPar_t * pPars )
{
int i, k, nDecs = 0, nWords = Abc_TtWordNum(pPars->nVars);
abctime clk = Abc_Clock();
int i, k, Status, nDecs[3] = {0}, nWords = Abc_TtWordNum(pPars->nVars);
word * pFun = ABC_ALLOC( word, nWords );
unsigned Rand0 = Abc_Random(1);
Vec_Str_t * vUndec = Vec_StrAlloc( 100 );
for ( i = 0; i < pPars->Seed; i++ )
Rand0 = Abc_Random(0);
for ( i = 0; i < pPars->nRandFuncs; i++ ) {
@ -1680,11 +1699,31 @@ void Exa3_ManExactSynthesisRand( Bmc_EsPar_t * pPars )
printf( "\n" );
if ( pPars->fVerbose )
printf( "Truth table : %s\n", pPars->pTtStr );
nDecs += Exa3_ManExactSynthesis( pPars );
Status = Exa3_ManExactSynthesis( pPars );
nDecs[Status]++;
if ( Status == 0 ) // undecided
Vec_StrPrintF( vUndec, "%s\n", pPars->pTtStr );
ABC_FREE( pPars->pTtStr );
}
printf( "\nDecomposable are %d (out of %d) functions (%.2f %%).\n\n", nDecs, pPars->nRandFuncs, 100.0*nDecs/pPars->nRandFuncs );
printf( "\n" );
printf( "Decomposable are %6d (out of %6d) functions (%6.2f %%).\n", nDecs[1], pPars->nRandFuncs, 100.0*nDecs[1]/pPars->nRandFuncs );
printf( "Non-decomposable are %6d (out of %6d) functions (%6.2f %%).\n", nDecs[2], pPars->nRandFuncs, 100.0*nDecs[2]/pPars->nRandFuncs );
printf( "Undecided are %6d (out of %6d) functions (%6.2f %%).\n", nDecs[0], pPars->nRandFuncs, 100.0*nDecs[0]/pPars->nRandFuncs );
ABC_FREE( pFun );
if ( nDecs[0] > 0 ) {
char filename[1000];
sprintf( filename, "undecided_%d_out_of_F%d_with_N%d_M%d_K%d_U%d_S%d_T%d%s__%s.txt",
nDecs[0], pPars->nRandFuncs, pPars->nVars, pPars->nNodes, pPars->nLutSize,
pPars->nMintNum, pPars->Seed, pPars->RuntimeLim, pPars->fLutCascade ? "_r" : "", Exa_TimeStamp() );
FILE * pFile = fopen( filename, "wb" );
if ( pFile ) {
fwrite( Vec_StrArray(vUndec), 1, Vec_StrSize(vUndec), pFile );
fclose( pFile );
printf( "The resulting undecided functions were written into file \"%s\".\n", filename );
}
}
Abc_PrintTime( 1, "Total time", Abc_Clock() - clk );
Vec_StrFree( vUndec );
}