xsatMemory.h 5.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/**CFile****************************************************************

  FileName    [xsatMemory.h]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [xSAT - A SAT solver written in C.
               Read the license file for more info.]

  Synopsis    [Memory management implementation.]

  Author      [Bruno Schmitt <boschmitt@inf.ufrgs.br>]

  Affiliation [UC Berkeley / UFRGS]

  Date        [Ver. 1.0. Started - November 10, 2016.]

  Revision    []

***********************************************************************/
#ifndef ABC__sat__xSAT__xsatMemory_h
#define ABC__sat__xSAT__xsatMemory_h

////////////////////////////////////////////////////////////////////////
///                          INCLUDES                                ///
////////////////////////////////////////////////////////////////////////
#include "misc/util/abc_global.h"

#include "xsatClause.h"

ABC_NAMESPACE_HEADER_START

////////////////////////////////////////////////////////////////////////
///                    STRUCTURE DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////
typedef struct xSAT_Mem_t_ xSAT_Mem_t;
struct xSAT_Mem_t_
{
39 40 41 42
    unsigned   nSize;
    unsigned   nCap;
    unsigned   nWasted;
    unsigned * pData;
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
};

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DECLARATIONS                        ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline xSAT_Clause_t *  xSAT_MemClauseHand( xSAT_Mem_t * p, int h )
{
61
    return h != 0xFFFFFFFF ? ( xSAT_Clause_t * )( p->pData + h ) : NULL;
62 63 64 65 66 67 68 69 70 71 72 73 74
}

/**Function*************************************************************

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
75
static inline void xSAT_MemGrow( xSAT_Mem_t * p, unsigned nCap )
76
{
77
    unsigned nPrevCap = p->nCap;
78 79 80 81
    if ( p->nCap >= nCap )
        return;
    while (p->nCap < nCap)
    {
82
        unsigned delta = ( ( p->nCap >> 1 ) + ( p->nCap >> 3 ) + 2 ) & ~1;
83 84 85 86
        p->nCap += delta;
        assert(p->nCap >= nPrevCap);
    }
    assert(p->nCap > 0);
87
    p->pData = ABC_REALLOC( unsigned, p->pData, p->nCap );
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
}

/**Function*************************************************************

  Synopsis    [Allocating vector.]

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline xSAT_Mem_t * xSAT_MemAlloc( int nCap )
{
    xSAT_Mem_t * p;
    p = ABC_CALLOC( xSAT_Mem_t, 1 );
    if (nCap <= 0)
        nCap = 1024*1024;

    xSAT_MemGrow(p, nCap);
    return p;
}

/**Function*************************************************************

  Synopsis    [Resetting vector.]

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void xSAT_MemRestart( xSAT_Mem_t * p )
{
    p->nSize = 0;
    p->nWasted = 0;
}

/**Function*************************************************************

  Synopsis    [Freeing vector.]

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void xSAT_MemFree( xSAT_Mem_t * p )
{
    ABC_FREE( p->pData );
    ABC_FREE( p );
}

/**Function*************************************************************

  Synopsis    [Creates new clause.]

  Description [The resulting clause is fully initialized.]

  SideEffects []

  SeeAlso     []

***********************************************************************/
157
static inline unsigned xSAT_MemAppend( xSAT_Mem_t * p, int nSize )
158
{
159
    unsigned nPrevSize;
160
    assert(nSize > 0);
161
    xSAT_MemGrow( p, p->nSize + nSize );
162
    nPrevSize = p->nSize;
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    p->nSize += nSize;
    assert(p->nSize > nPrevSize);
    return nPrevSize;
}

/**Function*************************************************************

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
179
static inline unsigned xSAT_MemCRef( xSAT_Mem_t * p, unsigned * pC )
180
{
181
    return ( unsigned )( pC - &(p->pData[0]) );
182 183 184 185 186 187 188 189 190 191 192 193 194
}

/**Function*************************************************************

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
195
static inline unsigned xSAT_MemCap( xSAT_Mem_t * p )
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
{
    return p->nCap;
}

/**Function*************************************************************

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
211
static inline unsigned xSAT_MemWastedCap( xSAT_Mem_t * p )
212 213 214 215 216 217 218 219 220 221 222
{
    return p->nWasted;
}

ABC_NAMESPACE_HEADER_END

#endif

////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////