📄 ntknode.c
字号:
/**CFile**************************************************************** FileName [ntkList.c] PackageName [MVSIS 2.0: Multi-valued logic synthesis system.] Synopsis [Various node manipulation utilities.] Author [MVSIS Group] Affiliation [UC Berkeley] Date [Ver. 1.0. Started - February 1, 2003.] Revision [$Id: ntkNode.c,v 1.36 2003/05/27 23:14:23 alanmi Exp $]***********************************************************************/#include "ntkInt.h"/////////////////////////////////////////////////////////////////////////// DECLARATIONS ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// FUNCTION DEFITIONS ////////////////////////////////////////////////////////////////////////////**Function************************************************************* Synopsis [Creates a new node with the given name, of the given type.] Description [] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NodeCreate( Ntk_Network_t * pNet, char * pName, Ntk_NodeType_t Type, int nValues ){ Ntk_Node_t * pNode; // get memory to this node pNode = (Ntk_Node_t *)memManFixedEntryFetch( pNet->pManNode ); // clean the memory memset( pNode, 0, sizeof(Ntk_Node_t) ); // assign the node name and type pNode->Id = 0; pNode->Type = Type; pNode->pName = pName? Ntk_NetworkRegisterNewName( pNet, pName ): NULL; pNode->nValues = nValues; pNode->pNet = pNet; pNode->pF = Fnc_FunctionAlloc(); // do not add the node to the network return pNode;} /**Function************************************************************* Synopsis [Creates the MV constant node.] Description [Creates the MV constant node, using memory avaiable from memory manager of the given network (pNet). The number of values (nValues) and the polarity (Pol) are given by the user. The polarity has the most significant bit coming first. For example to create ternary constant 1, the variables should be set as follows: nValues = 3, Pol = 2 (binary 010).] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NodeCreateConstant( Ntk_Network_t * pNet, int nValues, unsigned Pol ){ Ntk_Node_t * pNode; Fnc_Manager_t * pMan; Mvr_Relation_t * pMvr; // get the node pNode = Ntk_NodeCreate( pNet, NULL, MV_NODE_INT, nValues ); // get the functionality manager pMan = Ntk_NodeReadMan( pNode ); // create the relation pMvr = Mvr_RelationCreateConstant( Fnc_ManagerReadManMvr(pMan), Fnc_ManagerReadManVmx(pMan), Fnc_ManagerReadManVm(pMan), nValues, Pol ); // set the variable map and the relation Ntk_NodeWriteFuncVm( pNode, Mvr_RelationReadVm(pMvr) ); Ntk_NodeWriteFuncMvr( pNode, pMvr ); return pNode;}/**Function************************************************************* Synopsis [Creates the single input MV node.] Description [Creates the single input MV node, using memory avaiable from memory manager of the given network (pNet). The number of input and output values (nValuesIn, nValuesOut) are given by the user. The polarity is specified for each output value independently. The rule are similar to those described in Ntk_NodeCreateConstant(). For example, suppose we would like to create a standard ternary buffer. The variables should be set as follows: nValuesIn = 3, nValuesOut = 3, Pols[0] = 1, Pols[1] = 2, Pols[2] = 4.] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NodeCreateOneInputNode( Ntk_Network_t * pNet, Ntk_Node_t * pFanin, int nValuesIn, int nValuesOut, unsigned Pols[] ){ Ntk_Node_t * pNode; Fnc_Manager_t * pMan; Mvr_Relation_t * pMvr; // get the node pNode = Ntk_NodeCreate( pNet, NULL, MV_NODE_INT, nValuesOut ); // set the fanin (do not connect the fanout to the fanin) assert( pFanin == NULL || pFanin->nValues == nValuesIn ); Ntk_NodeAddFanin( pNode, pFanin ); // get the functionality manager pMan = Ntk_NodeReadMan( pNode ); // create the relation pMvr = Mvr_RelationCreateOneInputOneOutput( Fnc_ManagerReadManMvr(pMan), Fnc_ManagerReadManVmx(pMan), Fnc_ManagerReadManVm(pMan), nValuesIn, nValuesOut, Pols ); // set the variable map and the relation Ntk_NodeWriteFuncVm( pNode, Mvr_RelationReadVm(pMvr) ); Ntk_NodeWriteFuncMvr( pNode, pMvr ); return pNode;}/**Function************************************************************* Synopsis [Creates two-input binary node.] Description [Type is the trouth table of the two-input gate. If Type == 8 (bin=1000), creates two-input AND; if Type == 14 (bin=1110), creates two-input OR. Fanins should be ordered.] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NodeCreateTwoInputBinary( Ntk_Network_t * pNet, Ntk_Node_t * ppFanins[], unsigned TruthTable ){ Ntk_Node_t * pNode; Fnc_Manager_t * pMan; Mvr_Relation_t * pMvr; // get the node pNode = Ntk_NodeCreate( pNet, NULL, MV_NODE_INT, 2 ); // set the fanin (do not connect the fanout to the fanin) Ntk_NodeAddFanin( pNode, ppFanins[0] ); Ntk_NodeAddFanin( pNode, ppFanins[1] ); // get the functionality manager pMan = Ntk_NodeReadMan( pNode ); // create the relation pMvr = Mvr_RelationCreateTwoInputBinary( Fnc_ManagerReadManMvr(pMan), Fnc_ManagerReadManVmx(pMan), Fnc_ManagerReadManVm(pMan), TruthTable ); // set the variable map and the relation Ntk_NodeWriteFuncVm( pNode, Mvr_RelationReadVm(pMvr) ); Ntk_NodeWriteFuncMvr( pNode, pMvr ); return pNode;}/**Function************************************************************* Synopsis [Creates the decode for the two nodes.] Description [Creates a two-input node that works like a decoder for the two nodes. The created node is internal and is not added to the network.] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NodeCreateDecoder( Ntk_Network_t * pNet, Ntk_Node_t * pNode1, Ntk_Node_t * pNode2 ){ Ntk_Node_t * pNode; Fnc_Manager_t * pMan; Mvr_Relation_t * pMvr; // get the node pNode = Ntk_NodeCreate( pNet, NULL, MV_NODE_INT, pNode1->nValues * pNode2->nValues ); // set the fanin (do not connect the fanout to the fanin) Ntk_NodeAddFanin( pNode, pNode1 ); Ntk_NodeAddFanin( pNode, pNode2 ); // get the functionality manager pMan = Ntk_NodeReadMan( pNode ); // create the relation pMvr = Mvr_RelationCreateDecoder( Fnc_ManagerReadManMvr(pMan), Fnc_ManagerReadManVmx(pMan), Fnc_ManagerReadManVm(pMan), pNode1->nValues, pNode2->nValues ); // set the variable map and the relation Ntk_NodeWriteFuncVm( pNode, Mvr_RelationReadVm(pMvr) ); Ntk_NodeWriteFuncMvr( pNode, pMvr ); return pNode;}/**Function************************************************************* Synopsis [Creates the decoder for several binary nodes.] Description [This procedure does not delete or remove these nodes from the network. The resulting node is not in the network.] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t *Ntk_NodeCreateDecoderGeneral( Ntk_Node_t ** ppNodes, // the set of (binary) input nodes int nNodes, // size of the previous array int * pValueAssign, // pValueAssign[i] = j, if the ith value // (spanned by ppNodes) is assigned to output // value j. // pValueAssign[i] = -1, if the ith value is // unused. int nTotalValues, // size of the previous array (= 2^{nNodes}) int nOutputValues) // num of values of the original MV node{ Vm_VarMap_t * pVm; Mvr_Relation_t * pMvr; Ntk_Network_t * pNet; Ntk_Node_t * pNodeDec; int i; // make sure the input parameters are reasonable assert( nNodes > 0 ); assert( (1<<nNodes) == nTotalValues ); assert( nOutputValues <= nTotalValues ); assert( nTotalValues <= 32 ); // make sure the codes are within a proper range for ( i = 0; i < nTotalValues; i++ ) assert( pValueAssign[i] >= -1 && pValueAssign[i] < nOutputValues ); // create the decoder node pNet = ppNodes[0]->pNet; pNodeDec = Ntk_NodeCreate( pNet, NULL, MV_NODE_INT, nOutputValues ); // add fanins for ( i = 0; i < nNodes; i++ ) Ntk_NodeAddFanin( pNodeDec, ppNodes[i] ); // create the relation pMvr = Mvr_RelationCreateDecoderGeneral( Fnc_ManagerReadManMvr(pNet->pMan), Fnc_ManagerReadManVmx(pNet->pMan), Fnc_ManagerReadManVm(pNet->pMan), nNodes, pValueAssign, nTotalValues, nOutputValues ); // get hold of Vm pVm = Mvr_RelationReadVm(pMvr); // set the map and the relation Ntk_NodeWriteFuncVm(pNodeDec, pVm); Ntk_NodeWriteFuncMvr(pNodeDec, pMvr); return pNodeDec;}/**Function************************************************************* Synopsis [Encodes the given MV node using the provided coding.] Description [This procedure takes an MV-output node and derives a set of binary nodes according to the provided coding. The MV node is not deleted or removed from the network. The returned binary nodes are not in the network.] SideEffects [] SeeAlso []***********************************************************************/void Ntk_NodeCreateEncoded( Ntk_Node_t * pNode, // the MV node to be encoded Ntk_Node_t ** ppNodes, // returned binary nodes int nNodes, // size of the previous array int * pValueAssign, // pValueAssign[i] = j, if the ith value // (spanned by ppNodes) is assigned to // output value j. // pValueAssign[i] = -1, if the ith value // is unused. int nTotalValues, // size of the previous array (= 2^{nNodes}) int nOutputValues) // num of values of the original MV node{ Vm_VarMap_t * pVm; Mvr_Relation_t * ppMvrs[10]; Ntk_Network_t * pNet; Ntk_Node_t * pNodeEnc0, * pNodeEnc, * pFanin; Ntk_Pin_t * pPin; int i; // make sure the input parameters are reasonable assert( nNodes > 0 ); assert( (1<<nNodes) == nTotalValues ); assert( nOutputValues <= nTotalValues ); assert( nTotalValues <= 32 ); // make sure the codes are within a proper range for ( i = 0; i < nTotalValues; i++ ) assert( pValueAssign[i] >= -1 && pValueAssign[i] < nOutputValues ); // create the prototype of encoded node pNet = pNode->pNet; pNodeEnc0 = Ntk_NodeCreate( pNet, NULL, MV_NODE_INT, 2 ); // create the same fanins as the original node Ntk_NodeForEachFanin( pNode, pPin, pFanin ) Ntk_NodeAddFanin( pNodeEnc0, pFanin ); // create the relations Mvr_RelationCreateEncoded( Fnc_ManagerReadManMvr(pNet->pMan), Fnc_ManagerReadManVmx(pNet->pMan), Fnc_ManagerReadManVm(pNet->pMan), nNodes, pValueAssign, nTotalValues, nOutputValues, ppMvrs, Ntk_NodeReadFuncMvr(pNode) ); // get hold of Vm pVm = Mvr_RelationReadVm(ppMvrs[0]); // create the encoded nodes for ( i = 0; i < nNodes; i++ ) { // replicate the node (use pNodeEnc0 for the last one) if ( i == nNodes - 1 ) pNodeEnc = pNodeEnc0; else pNodeEnc = Ntk_NodeDup( pNet, pNodeEnc0 ); // set the map and the relation Ntk_NodeWriteFuncVm(pNodeEnc, pVm); Ntk_NodeWriteFuncMvr(pNodeEnc, ppMvrs[i]); // assign the node ppNodes[i] = pNodeEnc; }}/**Function************************************************************* Synopsis [Creates two encoders for the given node.] Description [Creates two single-input encoders, which have the input equal to the given node (pNode) and output values (nValues1 and nValues2). It is assumed that pNode1 encodes less significant bits.] SideEffects [] SeeAlso []***********************************************************************/void Ntk_NodeCreateEncoders( Ntk_Network_t * pNet, Ntk_Node_t * pNode, int nValues1, int nValues2, Ntk_Node_t ** ppNode1, Ntk_Node_t ** ppNode2 ){ unsigned Pols1[32], Pols2[32]; int i; assert( nValues1 * nValues2 == pNode->nValues ); assert( pNode->nValues <= 32 ); // create the polarities of the single-input nodes memset( Pols1, 0, sizeof(unsigned) * nValues1 ); memset( Pols2, 0, sizeof(unsigned) * nValues2 ); for ( i = 0; i < pNode->nValues; i++ ) { Pols1[i / nValues2] |= (1<<i); Pols2[i % nValues2] |= (1<<i); } // create the decoders *ppNode1 = Ntk_NodeCreateOneInputNode( pNet, pNode, pNode->nValues, nValues1, Pols1 ); *ppNode2 = Ntk_NodeCreateOneInputNode( pNet, pNode, pNode->nValues, nValues2, Pols2 );}/**Function*************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -