2012-02-16 23:23:52 +01:00
|
|
|
/**CFile****************************************************************
|
|
|
|
|
|
|
|
|
|
FileName [vecSet.h]
|
|
|
|
|
|
|
|
|
|
SystemName [ABC: Logic synthesis and verification system.]
|
|
|
|
|
|
|
|
|
|
PackageName [SAT solvers.]
|
|
|
|
|
|
|
|
|
|
Synopsis [Multi-page dynamic array.]
|
|
|
|
|
|
|
|
|
|
Author [Alan Mishchenko]
|
2012-03-21 23:26:09 +01:00
|
|
|
|
2012-02-16 23:23:52 +01:00
|
|
|
Affiliation [UC Berkeley]
|
|
|
|
|
|
|
|
|
|
Date [Ver. 1.0. Started - June 20, 2005.]
|
|
|
|
|
|
|
|
|
|
Revision [$Id: vecSet.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2012-03-21 23:26:09 +01:00
|
|
|
|
2012-02-16 23:23:52 +01:00
|
|
|
#ifndef ABC__sat__bsat__vecSet_h
|
|
|
|
|
#define ABC__sat__bsat__vecSet_h
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// INCLUDES ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
ABC_NAMESPACE_HEADER_START
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// PARAMETERS ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// BASIC TYPES ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
// data-structure for logging entries
|
2012-03-22 01:13:39 +01:00
|
|
|
// memory is allocated in 2^p->nPageSize word-sized pages
|
2012-02-16 23:23:52 +01:00
|
|
|
// the first 'word' of each page is used storing additional data
|
|
|
|
|
// the first 'int' of additional data stores the word limit
|
|
|
|
|
// the second 'int' of the additional data stores the shadow word limit
|
|
|
|
|
|
|
|
|
|
typedef struct Vec_Set_t_ Vec_Set_t;
|
2012-03-21 23:26:09 +01:00
|
|
|
struct Vec_Set_t_
|
2012-02-16 23:23:52 +01:00
|
|
|
{
|
2012-03-22 01:13:39 +01:00
|
|
|
int nPageSize; // page size
|
|
|
|
|
unsigned uPageMask; // page mask
|
2012-02-16 23:23:52 +01:00
|
|
|
int nEntries; // entry count
|
|
|
|
|
int iPage; // current page
|
|
|
|
|
int iPageS; // shadow page
|
|
|
|
|
int nPagesAlloc; // page count allocated
|
|
|
|
|
word ** pPages; // page pointers
|
2012-03-22 01:13:39 +01:00
|
|
|
};
|
2012-02-16 23:23:52 +01:00
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// MACRO DEFINITIONS ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-03-22 01:13:39 +01:00
|
|
|
static inline int Vec_SetHandPage( Vec_Set_t * p, int h ) { return h >> p->nPageSize; }
|
|
|
|
|
static inline int Vec_SetHandShift( Vec_Set_t * p, int h ) { return h & p->uPageMask; }
|
2012-02-17 05:54:41 +01:00
|
|
|
static inline int Vec_SetWordNum( int nSize ) { return (nSize + 1) >> 1; }
|
2012-02-16 23:23:52 +01:00
|
|
|
|
2012-03-22 01:13:39 +01:00
|
|
|
//static inline word * Vec_SetEntry( Vec_Set_t * p, int h ) { assert(Vec_SetHandPage(p, h) >= 0 && Vec_SetHandPage(p, h) <= p->iPage); assert(Vec_SetHandShift(p, h) >= 2 && Vec_SetHandShift(p, h) < (1 << p->nPageSize)); return p->pPages[Vec_SetHandPage(p, h)] + Vec_SetHandShift(p, h); }
|
|
|
|
|
static inline word * Vec_SetEntry( Vec_Set_t * p, int h ) { return p->pPages[Vec_SetHandPage(p, h)] + Vec_SetHandShift(p, h); }
|
2012-02-16 23:23:52 +01:00
|
|
|
static inline int Vec_SetEntryNum( Vec_Set_t * p ) { return p->nEntries; }
|
|
|
|
|
static inline void Vec_SetWriteEntryNum( Vec_Set_t * p, int i){ p->nEntries = i; }
|
|
|
|
|
|
2012-03-22 01:13:39 +01:00
|
|
|
static inline int Vec_SetLimit( word * p ) { return p[0]; }
|
|
|
|
|
static inline int Vec_SetLimitS( word * p ) { return p[1]; }
|
2012-02-16 23:23:52 +01:00
|
|
|
|
2012-03-22 01:13:39 +01:00
|
|
|
static inline int Vec_SetIncLimit( word * p, int nWords ) { return p[0] += nWords; }
|
|
|
|
|
static inline int Vec_SetIncLimitS( word * p, int nWords ) { return p[1] += nWords; }
|
2012-02-16 23:23:52 +01:00
|
|
|
|
2012-03-22 01:13:39 +01:00
|
|
|
static inline void Vec_SetWriteLimit( word * p, int nWords ) { p[0] = nWords; }
|
|
|
|
|
static inline void Vec_SetWriteLimitS( word * p, int nWords ) { p[1] = nWords; }
|
2012-02-16 23:23:52 +01:00
|
|
|
|
2012-03-22 01:13:39 +01:00
|
|
|
static inline int Vec_SetHandCurrent( Vec_Set_t * p ) { return (p->iPage << p->nPageSize) + Vec_SetLimit(p->pPages[p->iPage]); }
|
|
|
|
|
static inline int Vec_SetHandCurrentS( Vec_Set_t * p ) { return (p->iPageS << p->nPageSize) + Vec_SetLimitS(p->pPages[p->iPageS]); }
|
2012-02-16 23:23:52 +01:00
|
|
|
|
2012-03-22 01:13:39 +01:00
|
|
|
static inline int Vec_SetHandMemory( Vec_Set_t * p, int h ) { return Vec_SetHandPage(p, h) * (1 << (p->nPageSize+3)) + Vec_SetHandShift(p, h) * 8; }
|
|
|
|
|
static inline int Vec_SetMemory( Vec_Set_t * p ) { return Vec_SetHandMemory(p, Vec_SetHandCurrent(p)); }
|
|
|
|
|
static inline int Vec_SetMemoryS( Vec_Set_t * p ) { return Vec_SetHandMemory(p, Vec_SetHandCurrentS(p)); }
|
|
|
|
|
static inline int Vec_SetMemoryAll( Vec_Set_t * p ) { return (p->iPage+1) * (1 << (p->nPageSize+3)); }
|
2012-02-16 23:23:52 +01:00
|
|
|
|
|
|
|
|
// Type is the Set type
|
|
|
|
|
// pVec is vector of set
|
|
|
|
|
// nSize should be given by the user
|
|
|
|
|
// pSet is the pointer to the set
|
|
|
|
|
// p (page) and s (shift) are variables used here
|
|
|
|
|
#define Vec_SetForEachEntry( Type, pVec, nSize, pSet, p, s ) \
|
|
|
|
|
for ( p = 0; p <= pVec->iPage; p++ ) \
|
2012-03-21 23:26:09 +01:00
|
|
|
for ( s = 2; s < Vec_SetLimit(pVec->pPages[p]) && ((pSet) = (Type)(pVec->pPages[p] + (s))); s += nSize )
|
2012-02-16 23:23:52 +01:00
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// FUNCTION DEFINITIONS ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Allocating vector.]
|
|
|
|
|
|
|
|
|
|
Description []
|
2012-03-21 23:26:09 +01:00
|
|
|
|
2012-02-16 23:23:52 +01:00
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2012-03-22 01:13:39 +01:00
|
|
|
static inline void Vec_SetAlloc_( Vec_Set_t * p, int nPageSize )
|
2012-02-16 23:23:52 +01:00
|
|
|
{
|
2012-03-22 01:13:39 +01:00
|
|
|
assert( nPageSize > 8 );
|
2012-02-16 23:23:52 +01:00
|
|
|
memset( p, 0, sizeof(Vec_Set_t) );
|
2012-03-22 01:13:39 +01:00
|
|
|
p->nPageSize = nPageSize;
|
|
|
|
|
p->uPageMask = (unsigned)((1 << nPageSize) - 1);
|
2012-02-16 23:23:52 +01:00
|
|
|
p->nPagesAlloc = 256;
|
|
|
|
|
p->pPages = ABC_CALLOC( word *, p->nPagesAlloc );
|
2012-03-22 01:13:39 +01:00
|
|
|
p->pPages[0] = ABC_ALLOC( word, (1 << p->nPageSize) );
|
2012-02-16 23:23:52 +01:00
|
|
|
p->pPages[0][0] = ~0;
|
2012-03-22 01:13:39 +01:00
|
|
|
p->pPages[0][1] = ~0;
|
2012-03-21 23:26:09 +01:00
|
|
|
Vec_SetWriteLimit( p->pPages[0], 2 );
|
2012-02-16 23:23:52 +01:00
|
|
|
}
|
2012-03-22 01:13:39 +01:00
|
|
|
static inline Vec_Set_t * Vec_SetAlloc( int nPageSize )
|
2012-02-16 23:23:52 +01:00
|
|
|
{
|
|
|
|
|
Vec_Set_t * p;
|
|
|
|
|
p = ABC_CALLOC( Vec_Set_t, 1 );
|
2012-03-22 01:13:39 +01:00
|
|
|
Vec_SetAlloc_( p, nPageSize );
|
2012-02-16 23:23:52 +01:00
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Resetting vector.]
|
|
|
|
|
|
|
|
|
|
Description []
|
2012-03-21 23:26:09 +01:00
|
|
|
|
2012-02-16 23:23:52 +01:00
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_SetRestart( Vec_Set_t * p )
|
|
|
|
|
{
|
|
|
|
|
p->nEntries = 0;
|
|
|
|
|
p->iPage = 0;
|
|
|
|
|
p->iPageS = 0;
|
|
|
|
|
p->pPages[0][0] = ~0;
|
2012-03-22 01:13:39 +01:00
|
|
|
p->pPages[0][1] = ~0;
|
2012-03-21 23:26:09 +01:00
|
|
|
Vec_SetWriteLimit( p->pPages[0], 2 );
|
2012-02-16 23:23:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Freeing vector.]
|
|
|
|
|
|
|
|
|
|
Description []
|
2012-03-21 23:26:09 +01:00
|
|
|
|
2012-02-16 23:23:52 +01:00
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_SetFree_( Vec_Set_t * p )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for ( i = 0; i < p->nPagesAlloc; i++ )
|
|
|
|
|
ABC_FREE( p->pPages[i] );
|
|
|
|
|
ABC_FREE( p->pPages );
|
|
|
|
|
}
|
|
|
|
|
static inline void Vec_SetFree( Vec_Set_t * p )
|
|
|
|
|
{
|
|
|
|
|
Vec_SetFree_( p );
|
|
|
|
|
ABC_FREE( p );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Appending entries to vector.]
|
|
|
|
|
|
|
|
|
|
Description []
|
2012-03-21 23:26:09 +01:00
|
|
|
|
2012-02-16 23:23:52 +01:00
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_SetAppend( Vec_Set_t * p, int * pArray, int nSize )
|
|
|
|
|
{
|
2012-02-17 05:54:41 +01:00
|
|
|
int nWords = Vec_SetWordNum( nSize );
|
2012-03-22 01:13:39 +01:00
|
|
|
assert( nWords < (1 << p->nPageSize) );
|
2012-02-16 23:23:52 +01:00
|
|
|
p->nEntries++;
|
2012-03-22 01:13:39 +01:00
|
|
|
if ( Vec_SetLimit( p->pPages[p->iPage] ) + nWords > (1 << p->nPageSize) )
|
2012-02-16 23:23:52 +01:00
|
|
|
{
|
|
|
|
|
if ( ++p->iPage == p->nPagesAlloc )
|
|
|
|
|
{
|
|
|
|
|
p->pPages = ABC_REALLOC( word *, p->pPages, p->nPagesAlloc * 2 );
|
|
|
|
|
memset( p->pPages + p->nPagesAlloc, 0, sizeof(word *) * p->nPagesAlloc );
|
|
|
|
|
p->nPagesAlloc *= 2;
|
|
|
|
|
}
|
|
|
|
|
if ( p->pPages[p->iPage] == NULL )
|
2012-03-22 01:13:39 +01:00
|
|
|
p->pPages[p->iPage] = ABC_ALLOC( word, (1 << p->nPageSize) );
|
2012-03-21 23:26:09 +01:00
|
|
|
Vec_SetWriteLimit( p->pPages[p->iPage], 2 );
|
2012-03-22 01:13:39 +01:00
|
|
|
p->pPages[p->iPage][1] = ~0;
|
2012-02-16 23:23:52 +01:00
|
|
|
}
|
|
|
|
|
if ( pArray )
|
2012-03-22 01:13:39 +01:00
|
|
|
memcpy( p->pPages[p->iPage] + Vec_SetLimit(p->pPages[p->iPage]), pArray, sizeof(int) * nSize );
|
2012-02-16 23:23:52 +01:00
|
|
|
Vec_SetIncLimit( p->pPages[p->iPage], nWords );
|
|
|
|
|
return Vec_SetHandCurrent(p) - nWords;
|
|
|
|
|
}
|
|
|
|
|
static inline int Vec_SetAppendS( Vec_Set_t * p, int nSize )
|
|
|
|
|
{
|
2012-02-17 05:54:41 +01:00
|
|
|
int nWords = Vec_SetWordNum( nSize );
|
2012-03-22 01:13:39 +01:00
|
|
|
assert( nWords < (1 << p->nPageSize) );
|
|
|
|
|
if ( Vec_SetLimitS( p->pPages[p->iPageS] ) + nWords > (1 << p->nPageSize) )
|
2012-03-21 23:26:09 +01:00
|
|
|
Vec_SetWriteLimitS( p->pPages[++p->iPageS], 2 );
|
2012-02-16 23:23:52 +01:00
|
|
|
Vec_SetIncLimitS( p->pPages[p->iPageS], nWords );
|
|
|
|
|
return Vec_SetHandCurrentS(p) - nWords;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Shrinking vector size.]
|
|
|
|
|
|
|
|
|
|
Description []
|
2012-03-21 23:26:09 +01:00
|
|
|
|
2012-02-16 23:23:52 +01:00
|
|
|
SideEffects [This procedure does not update the number of entries.]
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_SetShrink( Vec_Set_t * p, int h )
|
|
|
|
|
{
|
|
|
|
|
assert( h <= Vec_SetHandCurrent(p) );
|
2012-03-22 01:13:39 +01:00
|
|
|
p->iPage = Vec_SetHandPage(p, h);
|
|
|
|
|
Vec_SetWriteLimit( p->pPages[p->iPage], Vec_SetHandShift(p, h) );
|
2012-02-16 23:23:52 +01:00
|
|
|
}
|
2012-03-21 23:26:09 +01:00
|
|
|
static inline void Vec_SetShrinkS( Vec_Set_t * p, int h )
|
|
|
|
|
{
|
2012-02-16 23:23:52 +01:00
|
|
|
assert( h <= Vec_SetHandCurrent(p) );
|
2012-03-22 01:13:39 +01:00
|
|
|
p->iPageS = Vec_SetHandPage(p, h);
|
|
|
|
|
Vec_SetWriteLimitS( p->pPages[p->iPageS], Vec_SetHandShift(p, h) );
|
2012-02-16 23:23:52 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-17 05:54:41 +01:00
|
|
|
static inline void Vec_SetShrinkLimits( Vec_Set_t * p )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for ( i = 0; i <= p->iPage; i++ )
|
|
|
|
|
Vec_SetWriteLimit( p->pPages[i], Vec_SetLimitS(p->pPages[i]) );
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-16 23:23:52 +01:00
|
|
|
|
|
|
|
|
ABC_NAMESPACE_HEADER_END
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// END OF FILE ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|