final int turns=pos*num;
int turns=pos*num; int excess=bufferSize-popCount*(num+turns); if(excess>0) { System.err.println("WARNING: EXCESS ITEMS ON PEEKBUFFER DETECTED!"); turns+=Math.ceil(((double)excess)/popCount); }
    public JBlock getSteadyBlock() {	JStatement[] body;	if(begin)	    body=new JStatement[array.length+6];	else	    body=new JStatement[array.length+5];	//Filling register with Constants	InlineAssembly inline=new InlineAssembly();	inline.add(".set noat");	inline.add("addiu! "+zeroReg+",\\t"+zeroReg+",\\t"+filterInfo.steadyMult); //Send steadyMult to switch	//TODO: Save registers here	body[0]=inline;	for(int i=0;i<array.length;i++) {	    inline=new InlineAssembly();	    inline.add("lw "+regs[i]+", %0");	    inline.addInput("\"m\"("+getWeight(i)+")");	    body[1+i]=inline;	}	if(begin) {	    inline=new InlineAssembly();	    inline.add("lw "+regs[regs.length-1]+", %0");	    inline.addInput("\"m\"("+getConstant()+")");	    body[body.length-5]=inline;	}	//TEST: Send start	/*if(begin) {	  inline.add("addu $csto, $0, "+regs[0]);	  }*/	//Start Template	inline=new InlineAssembly();	body[body.length-4]=inline;	//Preloop	final int turns=pos*num;	//final int extra=bufferSize-popCount*(turns+num-2); //How many extra before switching from peekbuffer to network	//final int extraTurns=(int)Math.ceil(((double)extra)/popCount)+1;	if(begin) {	    System.out.println("EXTRA: "+bufferSize);	    inline.addInput("\"i\"("+generatedVariables.recvBuffer.getIdent()+")");	    inline.add("la "+tempReg+", %0");	    int index=0;	    //if(turns>0) {		int bufferRemaining=bufferSize; //Use peek buffer while bufferRemaining>0 else use net		for(int i=0;i<=topPopNum;i++)		    for(int j=0;j<popCount;j++)			if(bufferRemaining>0) {			    inline.add("lw    "+tempRegs[0]+",\\t"+index+"("+tempReg+")");			    index+=4;			    for(int k=i;k>=0;k--) {				inline.add("mul.s "+tempRegs[1]+",\\t"+tempRegs[0]+",\\t"+regs[idx[k]+j]);				inline.add("add.s "+getInterReg(false,k,j)+",\\t"+getInterReg(true,k,j)+",\\t"+tempRegs[1]);			    }			    bufferRemaining--;			} else			    for(int k=i;k>=0;k--) {				inline.add("mul.s "+tempRegs[0]+",\\t$csti,\\t"+regs[idx[k]+j]);				inline.add("add.s "+getInterReg(false,k,j)+",\\t"+getInterReg(true,k,j)+",\\t"+tempRegs[0]);			    }		for(int turn=0;turn<turns;turn++) //Last iteration may not be from buffer		    for(int j=0;j<popCount;j++)			if(bufferRemaining>0) {			    //Load value and send to switch			    inline.add("lw!   "+tempRegs[0]+",\\t"+index+"("+tempReg+")");			    index+=4;			    for(int k=topPopNum;k>=0;k--) {				inline.add("mul.s "+tempRegs[1]+",\\t"+tempRegs[0]+",\\t"+regs[idx[k]+j]);				inline.add("add.s "+getInterReg(false,k,j)+",\\t"+getInterReg(true,k,j)+",\\t"+tempRegs[1]);			    }			    bufferRemaining--;			} else			    for(int k=topPopNum;k>=0;k--) {				inline.add("mul.s "+tempRegs[0]+",\\t$csti,\\t"+regs[idx[k]+j]);				inline.add("add.s "+getInterReg(false,k,j)+",\\t"+getInterReg(true,k,j)+",\\t"+tempRegs[0]);			    }		//TODO: Handle Remaining Items				/*} else		  for(int j=0;j<popCount;j++)		  for(int k=topPopNum;k>=0;k--) {		  inline.add("mul.s "+tempRegs[0]+",\\t$csti,\\t"+regs[idx[k]+j]);		  inline.add("add.s "+getInterReg(false,k,j)+",\\t"+getInterReg(true,k,j)+",\\t"+tempRegs[0]);		  }*/	} else {	    for(int i=0;i<=topPopNum;i++)		for(int j=0;j<popCount;j++)		    for(int k=i;k>=0;k--) {			inline.add("mul.s "+tempRegs[0]+",\\t$csti,\\t"+regs[idx[k]+j]);			inline.add("add.s "+getInterReg(false,k,j)+",\\t"+getInterReg(true,k,j)+",\\t"+tempRegs[0]);		    }	    for(int turn=0;turn<turns;turn++)		for(int j=0;j<popCount;j++)		    for(int k=topPopNum;k>=0;k--) {			inline.add("mul.s "+tempRegs[0]+",\\t$csti,\\t"+regs[idx[k]+j]);			inline.add("add.s "+getInterReg(false,k,j)+",\\t"+getInterReg(true,k,j)+",\\t"+tempRegs[0]);		    }	}	//Loop Counter	inline=new InlineAssembly();	body[body.length-3]=inline;	inline.add("addiu "+tempReg+",\\t"+zeroReg+",\\t-"+filterInfo.steadyMult);	//Innerloop	inline=new InlineAssembly();	body[body.length-2]=inline;	final int mult=getMult(array.length);	inline.add(getLabel()+": #LOOP");	int times=0;	int[] oldPopNum=new int[4];	int[] oldElem=new int[4];	for(int i=0;i<mult;i++)	    for(int j=0;j<popCount;j++)		for(int k=topPopNum;k>=0;k--) {		    int offset=idx[k]+j;		    inline.add("mul.s "+tempRegs[times]+",\\t$csti,\\t"+regs[offset]);		    oldPopNum[times]=k;		    oldElem[times]=j;		    times++;		    if(times==4) {			times=0;			for(int l=0;l<4;l++) {			    int popNum=oldPopNum[l];			    int elem=oldElem[l];			    inline.add("add.s "+getInterReg(false,popNum,elem)+",\\t"+getInterReg(true,popNum,elem)+",\\t"+tempRegs[l]);			}		    }		}	inline.add("bnea "+tempReg+",\\t"+zeroReg+",\\t"+getLabel());	//Postloop	inline=new InlineAssembly();	body[body.length-1]=inline;	if(begin) {	    inline.addInput("\"i\"("+generatedVariables.recvBuffer.getIdent()+")");	    inline.add("la "+tempReg+", %0");	}	//TODO: Restore regs 	inline.add(".set at");	return new JBlock(null,body,null);    }