import java.util.*;
/*********************************
* AMP Pracs-1
* --------------------------------------
* TITLE : SuperScalar Architecture
* Simulate U & V pipelines
* of Pentium processor -
*---------------------------------------
* (DEPENDENT Instructions
* considered)
*
* @author Rohit Iyer 09-221
* SEM 6 Vidyalankar Institute of Technology
* Mumbai University
*
* @date 03/02/2012
*********************************/
class PipelineExp
{
public static void main(String args[]) throws Exception
{
Scanner src=new Scanner(System.in);
System.out.println("Enter no of instructions:");
int n=src.nextInt();
int U[]=new int[5]; // 5 Stages Fetch,Decode1,Decode2,Execute,Write back
int V[]=new int[5];
int umax,vmax;
if(n%2==1)
{
umax=n; //umax=Max instruction number in U pipeline
vmax=n-1; //vmax=Max instruction number in V pipeline
}
else
{
vmax=n;
umax=n-1;
}
int x=n;
int p=1;
if(n%2==1)
x=x+1;
x=((x-2)/2)+5; //x=Number of T-states required for n instructions
int j=1;
for(int i=1;i<=x;i++)
{
p=1;
U[4]=U[3];
U[3]=U[2];
U[2]=U[1];
if(U[1]!=0 && V[1]!=0)
{
System.out.println("Are instructions I"+U[1]+"and I"+V[1]+" pairable?? (1-YES/0-NO)");
p=src.nextInt(); //p=1-->Pairable p=0-->NotPairable
if(p==0)
x++; //Penalty of 1 T-state since instructions not pairable
}
if(p==0)
U[1]=V[1]; //****D1 of V comes in D1 of U*****
if((U[1]==0) || p==1)
U[1]=U[0];
if(i<3 || p==1)
U[0]=j++;
V[4]=V[3]; //E goes to W
V[3]=V[2]; //D2 goes to E
if(p==1 || V[1]==0)
{
V[2]=V[1]; //D1 goes to D2
V[1]=V[0]; //F goes to D1
}
else
{
V[2]=0; //V-pipeline STALLED in D1 stage
V[1]=0;
}
if(p==1)
V[0]=j++;
for(int k=0;k<4;k++)
{
if(U[k]>umax)
U[k]=0;
if(V[k]>vmax)
V[k]=0;
}
System.out.println("\n\nPipeline U status\n\n");
if(U[0]!=0)
System.out.println("Fetch Stage: I"+U[0]);
if(U[1]!=0)
System.out.println("Decode1 Stage: I"+U[1]);
if(U[2]!=0)
System.out.println("Decode2 Stage: I"+U[2]);
if(U[3]!=0)
System.out.println("Execute Stage: I"+U[3]);
if(U[4]!=0)
System.out.println("Writeback Stage: I"+U[4]);
System.out.println("\n\nPipeline V status\n\n");
if(V[0]!=0)
System.out.println("Fetch Stage: I"+V[0]);
if(V[1]!=0)
System.out.println("Decode1 Stage: I"+V[1]);
if(V[2]!=0)
System.out.println("Decode2 Stage: I"+V[2]);
if(V[3]!=0)
System.out.println("Execute Stage: I"+V[3]);
if(V[4]!=0)
System.out.println("Writeback Stage: I"+V[4]);
System.in.read();
}
}
}

No comments:
Post a Comment