/**CFile**************************************************************** FileName [vecBit.h] SystemName [ABC: Logic synthesis and verification system.] PackageName [Resizable arrays.] Synopsis [Resizable arrays of bits.] Author [Alan Mishchenko] Affiliation [UC Berkeley] Date [Ver. 1.0. Started - June 20, 2005.] Revision [$Id: vecBit.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $] ***********************************************************************/ #ifndef ABC__misc__vec__vecBit_h #define ABC__misc__vec__vecBit_h //////////////////////////////////////////////////////////////////////// /// INCLUDES /// //////////////////////////////////////////////////////////////////////// #include ABC_NAMESPACE_HEADER_START //////////////////////////////////////////////////////////////////////// /// PARAMETERS /// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /// BASIC TYPES /// //////////////////////////////////////////////////////////////////////// typedef struct Vec_Bit_t_ Vec_Bit_t; struct Vec_Bit_t_ { int nCap; int nSize; int * pArray; }; //////////////////////////////////////////////////////////////////////// /// MACRO DEFINITIONS /// //////////////////////////////////////////////////////////////////////// #define Vec_BitForEachEntry( vVec, Entry, i ) \ for ( i = 0; (i < Vec_BitSize(vVec)) && (((Entry) = Vec_BitEntry(vVec, i)), 1); i++ ) #define Vec_BitForEachEntryStart( vVec, Entry, i, Start ) \ for ( i = Start; (i < Vec_BitSize(vVec)) && (((Entry) = Vec_BitEntry(vVec, i)), 1); i++ ) #define Vec_BitForEachEntryStop( vVec, Entry, i, Stop ) \ for ( i = 0; (i < Stop) && (((Entry) = Vec_BitEntry(vVec, i)), 1); i++ ) #define Vec_BitForEachEntryStartStop( vVec, Entry, i, Start, Stop ) \ for ( i = Start; (i < Stop) && (((Entry) = Vec_BitEntry(vVec, i)), 1); i++ ) #define Vec_BitForEachEntryReverse( vVec, pEntry, i ) \ for ( i = Vec_BitSize(vVec) - 1; (i >= 0) && (((pEntry) = Vec_BitEntry(vVec, i)), 1); i-- ) //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// /**Function************************************************************* Synopsis [Allocates a vector with the given capacity.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ static inline Vec_Bit_t * Vec_BitAlloc( int nCap ) { Vec_Bit_t * p; nCap = (nCap >> 5) + ((nCap & 31) > 0); p = ABC_ALLOC( Vec_Bit_t, 1 ); p->nSize = 0; p->nCap = nCap * 32; p->pArray = nCap? ABC_ALLOC( int, nCap ) : NULL; return p; } /**Function************************************************************* Synopsis [Allocates a vector with the given size and cleans it.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ static inline Vec_Bit_t * Vec_BitStart( int nSize ) { Vec_Bit_t * p; nSize = (nSize >> 5) + ((nSize & 31) > 0); p = Vec_BitAlloc( nSize * 32 ); p->nSize = nSize * 32; memset( p->pArray, 0, sizeof(int) * nSize ); return p; } /**Function************************************************************* Synopsis [Allocates a vector with the given size and cleans it.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ static inline Vec_Bit_t * Vec_BitStartFull( int nSize ) { Vec_Bit_t * p; nSize = (nSize >> 5) + ((nSize & 31) > 0); p = Vec_BitAlloc( nSize ); p->nSize = nSize * 32; memset( p->pArray, 0xff, sizeof(int) * nSize ); return p; } /**Function************************************************************* Synopsis [Duplicates the integer array.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ static inline Vec_Bit_t * Vec_BitDup( Vec_Bit_t * pVec ) { Vec_Bit_t * p; assert( (pVec->nSize & 31) == 0 ); p = ABC_ALLOC( Vec_Bit_t, 1 ); p->nSize = pVec->nSize; p->nCap = pVec->nSize; p->pArray = p->nCap? ABC_ALLOC( int, p->nCap >> 5 ) : NULL; memcpy( p->pArray, pVec->pArray, sizeof(int) * (p->nCap >> 5) ); return p; } /**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ static inline void Vec_BitFree( Vec_Bit_t * p ) { ABC_
// ===================================================================
//
// Copyright (c) 2005, Intel Corp.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
//   * Redistributions of source code must retain the above copyright
//     notice, this list of conditions and the following disclaimer.
//   * Redistributions in binary form must reproduce the above
//     copyright notice, this list of conditions and the following
//     disclaimer in the documentation and/or other materials provided
//     with the distribution.
//   * Neither the name of Intel Corporation nor the names of its
//     contributors may be used to endorse or promote products derived
//     from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
// ===================================================================
//
// vtpm_lock.h Provided controlled sync around access to vtpm structures
//
// ===================================================================

#ifndef __VTPM_LOCK_H__
#define __VTPM_LOCK_H__

void vtpm_lock_init();
ze & 31));
    else if ( Entry == 0 )
        p->pArray[p->nSize >> 5] &= ~(1 << (p->nSize & 31));
    else assert( 0 );
    p->nSize++;
}

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

  Synopsis    [Returns the last entry and removes it from the list.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline int Vec_BitPop( Vec_Bit_t * p )
{
    int Entry;
    assert( p->nSize > 0 );
    Entry = Vec_BitEntryLast( p );
    p->nSize--;
    return Entry;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline int Vec_BitCountWord( unsigned uWord )
{
    uWord = (uWord & 0x55555555) + ((uWord>>1) & 0x55555555);
    uWord = (uWord & 0x33333333) + ((uWord>>2) & 0x33333333);
    uWord = (uWord & 0x0F0F0F0F) + ((uWord>>4) & 0x0F0F0F0F);
    uWord = (uWord & 0x00FF00FF) + ((uWord>>8) & 0x00FF00FF);
    return  (uWord & 0x0000FFFF) + (uWord>>16);
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline int Vec_BitCount( Vec_Bit_t * p ) 
{
    unsigned * pArray = (unsigned *)p->pArray;
    int nWords = (p->nSize >> 5) + ((p->nSize & 31) > 0);
    int i, Counter = 0;
    if ( p->nSize & 31 )
    {
        assert( nWords > 0 );
        for ( i = 0; i < nWords-1; i++ )
            Counter += Vec_BitCountWord( pArray[i] );
        Counter += Vec_BitCountWord( pArray[i] & ~(~0 << (p->nSize & 31)) );
    }
    else
    {
        for ( i = 0; i < nWords; i++ )
            Counter += Vec_BitCountWord( pArray[i] );
    }
    return Counter;
}

ABC_NAMESPACE_HEADER_END

#endif

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