/**CFile**************************************************************** FileName [gia.c] SystemName [ABC: Logic synthesis and verification system.] PackageName [Scalable AIG package.] Synopsis [] Author [Alan Mishchenko] Affiliation [UC Berkeley] Date [Ver. 1.0. Started - June 20, 2005.] Revision [$Id: gia.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] ***********************************************************************/ #include "gia.h" #include "map/if/if.h" ABC_NAMESPACE_IMPL_START //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// /**Function************************************************************* Synopsis [Sorts the pins in the decreasing order of delays.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Gia_LutDelayTraceSortPins( Gia_Man_t * p, int iObj, int * pPinPerm, float * pPinDelays ) { int iFanin, i, j, best_i, temp; assert( Gia_ObjIsLut(p, iObj) ); // start the trivial permutation and collect pin delays Gia_LutForEachFanin( p, iObj, iFanin, i ) { pPinPerm[i] = i; pPinDelays[i] = Gia_ObjTimeArrival(p, iFanin); } // selection sort the pins in the decreasible order of delays // this order will match the increasing order of LUT input pins for ( i = 0; i < Gia_ObjLutSize(p, iObj)-1; i++ ) { best_i = i; for ( j = i+1; j < Gia_ObjLutSize(p, iObj); j++ ) if ( pPinDelays[pPinPerm[j]] > pPinDelays[pPinPerm[best_i]] ) best_i = j; if ( best_i == i ) continue; temp = pPinPerm[i]; pPinPerm[i] = pPinPerm[best_i]; pPinPerm[best_i] = temp; } // verify assert( Gia_ObjLutSize(p, iObj) == 0 || pPinPerm[0] < Gia_ObjLutSize(p, iObj) ); for ( i = 1; i < Gia_ObjLutSize(p, iObj); i++ ) { assert( pPinPerm[i] < Gia_ObjLutSize(p, iObj) ); assert( pPinDelays[pPinPerm[i-1]] >= pPinDelays[pPinPerm[i]] ); } } /**Function************************************************************* Synopsis [Sorts the pins in the decreasing order of delays.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Gia_LutWhereIsPin( Gia_Man_t * p, int iFanout, int iFanin, int * pPinPerm ) { int i; for ( i = 0; i < Gia_ObjLutSize(p, iFanout); i++ ) if ( Gia_ObjLutFanin(p, iFanout, pPinPerm[i]) == iFanin ) return i; return -1; } /**Function************************************************************* Synopsis [Computes the arrival times for the given object.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ float Gia_ObjComputeArrival( Gia_Man_t * p, int iObj, int fUseSorting ) { If_LibLut_t * pLutLib = (If_LibLut_t *)p->pLutLib; Gia_Obj_t * pObj = Gia_ManObj( p, iObj ); int k, iFanin, pPinPerm[32]; float pPinDelays[32]; float tArrival, * pDelays; if ( Gia_ObjIsCi(pObj) ) return Gia_ObjTimeArrival(p, iObj); if ( Gia_ObjIsCo(pObj) ) return Gia_ObjTimeArrival(p, Gia_ObjFaninId0p(p, pObj) ); assert( Gia_ObjIsLut(p, iObj) ); tArrival = -TIM_ETERNITY; if ( pLutLib == NULL ) { Gia_LutForEachFanin( p, iObj, iFanin, k ) if ( tArrival < Gia_ObjTimeArrival(p, iFanin) + 1.0 ) tArrival = Gia_ObjTimeArrival(p, iFanin) + 1.0; } else if ( !pLutLib->fVarPinDelays ) { pDelays = pLutLib->pLutDelays[Gia_ObjLutSize(p, iObj)]; Gia_LutForEachFanin( p, iObj, iFanin, k ) if ( tArrival < Gia_ObjTimeArrival(p, iFanin) + pDelays[0] ) tArrival = Gia_ObjTimeArrival(p, iFanin) + pDelays[0]; } else { pDelays = pLutLib->pLutDelays[Gia_ObjLutSize(p, iObj)]; if ( fUseSorting ) { Gia_LutDelayTraceSortPins( p, iObj, pPinPerm, pPinDelays ); Gia_LutForEachFanin( p, iObj, iFanin, k ) if ( tArrival < Gia_ObjTimeArrival( p, Gia_ObjLutFanin(p,iObj,pPinPerm[k])) + pDelays[k] ) tArrival = Gia_ObjTimeArrival( p, Gia_ObjLutFanin(p,iObj,pPinPerm[k])) + pDelays[k]; } else { Gia_LutForEachFanin( p, iObj, iFanin, k ) if ( tArrival < Gia_ObjTimeArrival(p, iFanin) + pDelays[k] ) tArrival = Gia_ObjTimeArrival(p, iFanin) + pDelays[k]; } } if ( Gia_ObjLutSize(p, iObj) == 0 ) tArrival = 0.0; return tArrival; } /**Function************************************************************* Synopsis [Propagates the required times through the given node.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ float Gia_ObjPropagateRequired( Gia_Man_t * p, int iObj, int fUseSorting ) { If_LibLut_t * pLutLib = (If_LibLut_t *)p->pLutLib; int k, iFanin, pPinPerm[32]; float pPinDelays[32]; float tRequired = 0.0; // Suppress "might be used uninitialized" float * pDelays; assert( Gia_ObjIsLut(p, iObj) ); if ( pLutLib == NULL ) { tRequired = Gia_ObjTimeRequired( p, iObj) - (float)1.0; Gia_LutForEachFanin( p, iObj, iFanin, k ) if ( Gia_ObjTimeRequired(p, iFanin) > tRequired ) Gia_ObjSetTimeRequired( p, iFanin, tRequired ); } else if ( !pLutLib->fVarPinDelays ) { pDelays = pLutLib->pLutDelays[Gia_ObjLutSize(p, iObj)]; tRequired = Gia_ObjTimeRequired(p, iObj) - pDelays[0]; Gia_LutForEachFanin( p, iObj, iFanin, k ) if ( Gia_ObjTimeRequired(p, iFa
//-----------------------------------------------------
// This is FSM demo program using function
// Design Name : fsm_using_function
// File Name   : fsm_using_function.v
//-----------------------------------------------------
module fsm_using_function (
clock      , // clock
reset      , // Active high, syn reset
req_0      , // Request 0
req_1      , // Request 1
gnt_0      , // Grant 0
gnt_1      
);
//-------------Input Ports-----------------------------
input   clock,reset,req_0,req_1;
 //-------------Output Ports----------------------------
output  gnt_0,gnt_1;
//-------------Input ports Data Type-------------------
wire    clock,reset,req_0,req_1;
//-------------Output Ports Data Type------------------
reg     gnt_0,gnt_1;
//-------------Internal Constants--------------------------
parameter SIZE = 3           ;
parameter IDLE  = 3'b001,GNT0 = 3'b010,GNT1 = 3'b100 ;
//-------------Internal Variables---------------------------
reg   [SIZE-1:0]          state        ;// Seq part of the FSM
wire  [SIZE-1:0]          next_state   ;// combo part of FSM
//----------Code startes Here------------------------
assign next_state = fsm_function(state, req_0, req_1);
//----------Function for Combo Logic-----------------
function [SIZE-1:0] fsm_function;
  input  [SIZE-1:0]  state ;	
  input    req_0 ;
  input    req_1 ;
  case(state)
   IDLE : if (req_0 == 1'b1) begin
                fsm_function = GNT0;
              end else if (req_1 == 1'b1) begin
                fsm_function= GNT1;
              end else begin
                fsm_function = IDLE;
              end
   GNT0 : if (req_0 == 1'b1) begin
                fsm_function = GNT0;
              end else begin
                fsm_function = IDLE;
              end
   GNT1 : if (req_1 == 1'b1) begin
                fsm_function = GNT1;
          end else begin
                fsm_function = IDLE;
              end
   default : fsm_function = IDLE;
  endcase
endfunction
//----------Seq Logic-----------------------------
always @ (posedge clock)
begin : FSM_SEQ
  if (reset == 1'b1) begin
    state <= #1 IDLE;
  end else begin
    state <= #1 next_state;
  end
end
//----------Output Logic-----------------------------
always @ (posedge clock)
begin : OUTPUT_LOGIC
if (reset == 1'b1) begin
  gnt_0 <= #1 1'b0;
  gnt_1 <= #1 1'b0;
end
else begin
  case(state)
    IDLE : begin
                  gnt_0 <= #1 1'b0;
                  gnt_1 <= #1 1'b0;
               end
   GNT0 : begin
                   gnt_0 <= #1 1'b1;
                   gnt_1 <= #1 1'b0;
                end
   GNT1 : begin
                   gnt_0 <= #1 1'b0;
                   gnt_1 <= #1 1'b1;
                end
   default : begin
                    gnt_0 <= #1 1'b0;
                    gnt_1 <= #1 1'b0;
                  end
  endcase
end
end // End Of Block OUTPUT_LOGIC

endmodule // End of Module arbiter
// count the total number of timing critical second-generation nodes Vec_IntClear( vTimeCries ); if ( nTimeCris ) { Gia_LutForEachFanin( p, iObj, iFanin, k ) if ( !Gia_ObjIsCi(Gia_ManObj(p, iFanin)) && (puTCEdges[iObj] & (1< Degree) ) if ( (Vec_IntSize(vTimeCries) == 0 || Vec_IntSize(vTimeCries) > Degree) ) continue; CounterRes++; // collect second generation nodes Vec_IntClear( vTimeFanins ); Gia_LutForEachFanin( p, iObj, iFanin, k ) { if ( Gia_ObjIsCi(Gia_ManObj(p, iFanin)) ) Vec_IntPushUnique( vTimeFanins, iFanin ); else Gia_LutForEachFanin( p, iFanin, iFanin2, k2 ) Vec_IntPushUnique( vTimeFanins, iFanin2 ); } // print the results if ( fVeryVerbose ) { printf( "%5d Node %5d : %d %2d %2d ", Counter, iObj, nTimeCris, Vec_IntSize(vTimeCries), Vec_IntSize(vTimeFanins) ); Gia_LutForEachFanin( p, iObj, iFanin, k ) printf( "%d(%.2f)%s ", iFanin, Gia_ObjTimeSlack(p, iFanin), (puTCEdges[iObj] & (1< Degree ) continue; // order the fanins in the increasing order of criticalily if ( Vec_IntSize(vTimeCries) > 1 ) { iFanin = Vec_IntEntry( vTimeCries, 0 ); iFanin2 = Vec_IntEntry( vTimeCries, 1 ); if ( Gia_ObjTimeSlack(p, iFanin) < Gia_ObjTimeSlack(p, iFanin2) ) { Vec_IntWriteEntry( vTimeCries, 0, iFanin2 ); Vec_IntWriteEntry( vTimeCries, 1, iFanin ); } } if ( Vec_IntSize(vTimeCries) > 2 ) { iFanin = Vec_IntEntry( vTimeCries, 1 ); iFanin2 = Vec_IntEntry( vTimeCries, 2 ); if ( Gia_ObjTimeSlack(p, iFanin) < Gia_ObjTimeSlack(p, iFanin2) ) { Vec_IntWriteEntry( vTimeCries, 1, iFanin2 ); Vec_IntWriteEntry( vTimeCries, 2, iFanin ); } iFanin = Vec_IntEntry( vTimeCries, 0 ); iFanin2 = Vec_IntEntry( vTimeCries, 1 ); if ( Gia_ObjTimeSlack(p, iFanin) < Gia_ObjTimeSlack(p, iFanin2) ) { Vec_IntWriteEntry( vTimeCries, 0, iFanin2 ); Vec_IntWriteEntry( vTimeCries, 1, iFanin ); } } // add choice Gia_ManSpeedupObj( pNew, p, Gia_ManObj(p,iObj), vTimeFanins, vTimeCries ); // quit if the number of nodes is large if ( Gia_ManObjNum(pNew) > nNodesNew - 100 ) { printf( "Speedup stopped adding choices because there was too many to add.\n" ); break; } } Gia_ManTimeStop( p ); Vec_IntFree( vTimeCries ); Vec_IntFree( vTimeFanins ); ABC_FREE( puTCEdges ); if ( fVerbose ) printf( "Nodes: Total = %7d. 0-slack = %7d. Workable = %7d. Ratio = %4.2f\n", Gia_ManLutNum(p), Counter, CounterRes, Counter? 1.0*CounterRes/Counter : 0.0 ); if ( pTempTim ) { Tim_ManStop( (Tim_Man_t *)p->pManTime ); p->pManTime = pTempTim; } // derive AIG with choices //Gia_ManPrintStats( pNew, 0 ); pTemp = Gia_ManEquivToChoices( pNew, 1 ); Gia_ManStop( pNew ); //Gia_ManPrintStats( pTemp, 0 ); // pNew = Gia_ManDupOrderDfsChoices( pTemp ); // Gia_ManStop( pTemp ); //Gia_ManPrintStats( pNew, 0 ); // return pNew; return pTemp; } //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// ABC_NAMESPACE_IMPL_END