summaryrefslogtreecommitdiffstats
path: root/src/misc/npn/npnTruth.c
blob: b6be775bc039a260426ae45f354cf246dc38f9eb (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
/**CFile****************************************************************

  FileName    [npnUtil.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName []

  Synopsis    []

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 20, 2005.]

  Revision    [$Id: npnUtil.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

***********************************************************************/

#include "extra.h"
#include "npn.h"
#include "vec.h"

////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFITIONS                           ///
////////////////////////////////////////////////////////////////////////

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

  Synopsis    [Checks if the variable belongs to the support.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Extra_TruthCofactors( int nVars, uint8 * puTruth, uint8 * puElem[][32], 
    uint8 * puTruthCofs0[][32], uint8 * puTruthCofs1[][32] )
{
    int v;
    for ( v = 0; v < nVars; v++ )
    {
        Extra_BitSharp( nVars, puTruth, puElem[v], (uint8 *)puTruthCofs0[v] );
        Extra_BitAnd  ( nVars, puTruth, puElem[v], (uint8 *)puTruthCofs1[v] );
    }
}

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

  Synopsis    [Checks if the variable belongs to the support.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Extra_TruthCountCofactorOnes( int nVars, uint8 * puTruthCofs[][32], int * pCounts )
{
    int v, nBytes;
    nBytes = Extra_BitCharNum( nVars );
    for ( v = 0; v < nVars; v++ )
        pCounts[v] = Extra_CountOnes( puTruthCofs[v], nBytes );
}

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

  Synopsis    [Checks if the variable belongs to the support.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Extra_TruthHasVar( int nVars, uint8 * puTruth, int iVar )
{
    // elementary truth tables
    static uint8 Signs[3] = {
        0xAA,    // 1010 1010
        0xCC,    // 1100 1100
        0xF0     // 1111 0000
    };
    int nChars, nShift, i;
    assert( iVar < nVars );
    nChars = Extra_BitCharNum( nVars );
    if ( iVar < 3 )
    {
        nShift = (1 << iVar);
        for ( i = 0; i < nChars; i++ )
            if ( ((puTruth[i] & Signs[iVar]) >> nShift) != (puTruth[i] & ~Signs[iVar]) )
                return 1;
    }
    else
    {
        nShift = (1 << (iVar-3));
        for ( i = 0; i < nChars; i++, i = (i % nShift)? i : i + nShift )
            if ( puTruth[i] != puTruth[i+nShift] )
                return 1;
    }
    return 0;
}

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

  Synopsis    [Checks if the variable belongs to the support.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Npn_VarsTest( int nVars, uint8 * puTruth )
{
    int v;
    int Counter = 0;
    for ( v = 0; v < nVars; v++ )
        Counter += Extra_TruthHasVar( nVars, puTruth, v );
    return Counter;
}

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