summaryrefslogtreecommitdiffstats
path: root/src/sop/ft/ft.h
blob: 81e1a2dcb06827ff61bfc5d81ac3ec33a259631f (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
/**CFile****************************************************************

  FileName    [ft.h]

  PackageName [MVSIS 2.0: Multi-valued logic synthesis system.]

  Synopsis    [Data structure for algebraic factoring.]

  Author      [MVSIS Group]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - February 1, 2003.]

  Revision    [$Id: ft.h,v 1.1 2003/05/22 19:20:04 alanmi Exp $]

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

#ifndef __FT_H__
#define __FT_H__

////////////////////////////////////////////////////////////////////////
///                          INCLUDES                                ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                         PARAMETERS                               ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                    STRUCTURE DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

typedef struct Ft_Node_t_ Ft_Node_t;
struct Ft_Node_t_
{
    // the first child
    unsigned   fCompl0  :  1;    // complemented attribute
    unsigned   iFanin0  : 11;    // fanin number
    // the second child
    unsigned   fCompl1  :  1;    // complemented attribute
    unsigned   iFanin1  : 11;    // fanin number (1-based)
    // other info
    unsigned   fIntern  :  1;    // marks any node that is not an elementary var
    unsigned   fConst   :  1;    // marks the constant 1 function
    unsigned   fCompl   :  1;    // marks the complement of topmost node
    // printing info
    unsigned   fNodeOr  :  1;    // marks the original OR node
    unsigned   fEdge0   :  1;    // marks the original complemented edge
    unsigned   fEdge1   :  1;    // marks the original complemented edge
    // some bits are unused
};

/*
    The factored form of a SOP is an array (Vec_Int_t) of entries Ft_Node_t.
    If the SOP has n input variables (some of them may not be in the true support)
    the first n entries of the factored form array have 0s. This representation 
    makes it each to translate the factored form into an AIG.

    The node structure contains fanins of the node and their complemented attributes 
    (using AIG semantics). The elementary variable (buffer or interver) are 
    represented as a node with the same fanins. For example: x' = AND( x', x' ).
    The constant node cannot be represented. Constant functions should be detected
    before calling the factoring procedure.
*/

// working with complemented attributes of objects
static inline bool        Ptr_IsComplement( void * p )    { return (bool)(((unsigned)p) & 01);     }
static inline void *      Ptr_Regular( void * p )         { return (void *)((unsigned)(p) & ~01);  }
static inline void *      Ptr_Not( void * p )             { return (void *)((unsigned)(p) ^  01);  }
static inline void *      Ptr_NotCond( void * p, int c )  { return (void *)((unsigned)(p) ^ (c));  }

static inline Ft_Node_t * Ft_NodeRead( Vec_Int_t * vForm, int i )   {  return (Ft_Node_t *)vForm->pArray + i;  }
static inline Ft_Node_t * Ft_NodeReadLast( Vec_Int_t * vForm )      {  return (Ft_Node_t *)vForm->pArray + vForm->nSize - 1;  }
static inline Ft_Node_t * Ft_NodeFanin0( Vec_Int_t * vForm, Ft_Node_t * pNode )   { assert( pNode->fIntern ); return (Ft_Node_t *)vForm->pArray + pNode->iFanin0;  }
static inline Ft_Node_t * Ft_NodeFanin1( Vec_Int_t * vForm, Ft_Node_t * pNode )   { assert( pNode->fIntern ); return (Ft_Node_t *)vForm->pArray + pNode->iFanin1;  }

static inline Ft_Node_t   Ft_Int2Node( int Num  )                   {  return *((Ft_Node_t *)&Num);  }
static inline int         Ft_Node2Int( Ft_Node_t Node )             {  return *((int *)&Node);       }
static inline void        Ft_NodeClean( Ft_Node_t * pNode )         {  *((int *)pNode) = 0;          }

////////////////////////////////////////////////////////////////////////
///                       MACRO DEFITIONS                            ///
////////////////////////////////////////////////////////////////////////

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

/*=== ftFactor.c =====================================================*/
extern void               Ft_FactorStartMan();
extern void               Ft_FactorStopMan();
extern Vec_Int_t *        Ft_Factor( char * pSop );
extern int                Ft_FactorGetNumNodes( Vec_Int_t * vForm );
extern int                Ft_FactorGetNumVars( Vec_Int_t * vForm );
/*=== ftPrint.c =====================================================*/
extern void               Ft_FactorPrint( FILE * pFile, Vec_Int_t * vForm, char * pNamesIn[], char * pNameOut );


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

#endif