for(int turn=0;turn<turns2+4;turn++) {
for(int turn=0;turn<turns2+1;turn++) {
    private static void createSwitchCodeLinear(FilterTraceNode node, Trace parent, 					       FilterInfo filterInfo, boolean init, boolean primePump, 					       RawTile tile, RawChip rawChip) {	System.err.println("Creating switchcode linear: "+node);	//START Copy Gordo	int mult, sentItems = 0;		//don't cache align if the only source is a file reader	boolean cacheAlignSource = true;	if (node.getPrevious() instanceof InputTraceNode) {	    OffChipBuffer buf = IntraTraceBuffer.getBuffer((InputTraceNode)node.getPrevious(), 							   node).getNonRedundant();	    if (buf != null && buf.getDest() instanceof OutputTraceNode &&		((OutputTraceNode)buf.getDest()).isFileReader())		cacheAlignSource = false;	}		//don't cache align the dest if the true dest is a file writer	boolean cacheAlignDest = true; 	if (node.getNext() instanceof OutputTraceNode) {	    OutputTraceNode output = (OutputTraceNode)node.getNext();	    if (output.oneOutput() && OffChipBuffer.unnecessary(output) &&		output.getSingleEdge().getDest().isFileWriter() &&		OffChipBuffer.unnecessary(output.getSingleEdge().getDest()))		cacheAlignDest = false;	}	      	if (primePump)	    mult = filterInfo.primePump - (filterInfo.push == 0 ? 0 :					   (filterInfo.primePumpItemsNotConsumed() / filterInfo.push));	else if (init)	    mult = filterInfo.initMult;	else 	    mult = filterInfo.steadyMult;	//STOP Copy from Gordo	ComputeNode sourceNode = null;	//int mult;	//if (init)	//mult = filterInfo.initMult;	//else 	//mult = filterInfo.steadyMult;		/* OLD	  if (node.getPrevious().isFilterTrace())	  sourceNode = rawChip.getTile(((FilterTraceNode)node.getPrevious()).getX(),  	  ((FilterTraceNode)node.getPrevious()).getY());	  else {	  if (KjcOptions.magicdram && node.getPrevious() !=  null &&	  node.getPrevious().isInputTrace() &&	  tile.hasIODevice()) 	  sourceNode = tile.getIODevice();	  else { 	  System.err.println("BLAH1");	  return;	  }	  }*/		if (node.getPrevious().isFilterTrace())	    sourceNode = rawChip.getTile(((FilterTraceNode)node.getPrevious()).getX(), 					 ((FilterTraceNode)node.getPrevious()).getY());	else {	    if (KjcOptions.magicdram && node.getPrevious() != null &&		node.getPrevious().isInputTrace() &&		tile.hasIODevice()) 		sourceNode = tile.getIODevice();	    else 		sourceNode = 		    IntraTraceBuffer.getBuffer((InputTraceNode)node.getPrevious(), 					       node).getNonRedundant().getDRAM();	}		SwitchIPort src = rawChip.getIPort(sourceNode, tile);	SwitchIPort src2 = rawChip.getIPort2(sourceNode, tile);	sourceNode = null;	ComputeNode destNode = null;	/* OLD	  if (node.getNext().isFilterTrace())	  destNode = rawChip.getTile(((FilterTraceNode)node.getNext()).getX(),  	  ((FilterTraceNode)node.getNext()).getY());	  else {	  if (KjcOptions.magicdram && node.getNext() !=  null &&	  node.getNext().isOutputTrace() && tile.hasIODevice())	  destNode = tile.getIODevice();	  else {	  System.err.println("BLAH2");	  return;	  }	  }*/	if (node.getNext().isFilterTrace())	    destNode = rawChip.getTile(((FilterTraceNode)node.getNext()).getX(), 				       ((FilterTraceNode)node.getNext()).getY());	else {	    if (KjcOptions.magicdram && node.getNext() != null &&		node.getNext().isOutputTrace() && tile.hasIODevice())		destNode = tile.getIODevice();	    else {		destNode = 		    IntraTraceBuffer.getBuffer(node, (OutputTraceNode)node.getNext()).		    getNonRedundant().getDRAM();	    }	    	}		SwitchOPort dest = rawChip.getOPort(tile, destNode);	SwitchOPort dest2 = rawChip.getOPort2(tile, destNode);	destNode = null;	FilterContent content = node.getFilter();	final int peek = content.getArray().length;	final int pop = content.getPopCount();	final int numPop = peek/pop;	final boolean begin=content.getBegin();	final boolean end=content.getEnd();	System.out.println("SRC: "+src);	System.out.println("DEST: "+dest);	SwitchCodeStore code = tile.getSwitchCode();	System.err.println("Getting HERE!");	code.appendIns(new Comment("HERE!"),init||primePump);	boolean first=true;	for(int i = 0; i<numPop-1; i++)	    for(int j = 0; j<pop; j++) {		FullIns ins = new FullIns(tile, new MoveIns(SwitchReg.R1, src));		/*if (KjcOptions.magicdram && node.getPrevious() != null &&		  node.getPrevious().isInputTrace())		  createMagicDramLoad((InputTraceNode)node.getPrevious(), 		  node, (init || primePump), rawChip);*/		ins.addRoute(src, SwitchOPort.CSTI);		//if(!first) {		if(!end) {		    /*if (KjcOptions.magicdram && node.getPrevious() != null &&		      node.getPrevious().isInputTrace())		      createMagicDramLoad((InputTraceNode)node.getPrevious(), 		      node, (init || primePump), rawChip);		      if (KjcOptions.magicdram && node.getNext() != null &&		      node.getNext().isOutputTrace())		      createMagicDramStore((OutputTraceNode)node.getNext(), 		      node, (init || primePump), rawChip);*/		    ins.addRoute(src,dest);		    //}		}		code.appendIns(ins, init||primePump);		for(int k = i-1; k>= 0; k--) {		    FullIns newIns = new FullIns(tile);		    newIns.addRoute(SwitchReg.R1, SwitchOPort.CSTI);		    code.appendIns(newIns, init||primePump);		}		FullIns newIns=null;		if(!begin) {		    newIns=new FullIns(tile);		    /*if (KjcOptions.magicdram && node.getPrevious() != null &&		      node.getPrevious().isInputTrace())		      createMagicDramLoad((InputTraceNode)node.getPrevious(), 		      node, (init || primePump), rawChip);*/		    newIns.addRoute(src2, SwitchOPort.CSTI2);		    code.appendIns(newIns, init||primePump);		}		/*if(!first) {		  newIns = new FullIns(tile);		  newIns.addRoute(SwitchIPort.CSTO,dest);		  code.appendIns(newIns, init||primePump);		  }		  first=false;*/	    }	final int turns=content.getPos();	for(int turn=0;turn<turns;turn++)	    for(int j = 0; j<pop; j++) {		FullIns ins = new FullIns(tile, new MoveIns(SwitchReg.R1, src));		/*if (KjcOptions.magicdram && node.getPrevious() != null &&		  node.getPrevious().isInputTrace())		  createMagicDramLoad((InputTraceNode)node.getPrevious(), 		  node, (init || primePump), rawChip);*/		ins.addRoute(src, SwitchOPort.CSTI);		if(!first) {		    if(!end) {			/*if (KjcOptions.magicdram && node.getPrevious() != null &&			  node.getPrevious().isInputTrace())			  createMagicDramLoad((InputTraceNode)node.getPrevious(), 			  node, (init || primePump), rawChip);			  if (KjcOptions.magicdram && node.getNext() != null &&			  node.getNext().isOutputTrace())			  createMagicDramStore((OutputTraceNode)node.getNext(), 			  node, (init || primePump), rawChip);*/			ins.addRoute(src,dest);		    }		}		code.appendIns(ins, init||primePump);		for(int k = numPop-2; k>= 0; k--) {		    FullIns newIns = new FullIns(tile);		    newIns.addRoute(SwitchReg.R1, SwitchOPort.CSTI);		    code.appendIns(newIns, init||primePump);		}		FullIns newIns=null;		if(!begin) {		    newIns=new FullIns(tile);		    /*if (KjcOptions.magicdram && node.getPrevious() != null &&		      node.getPrevious().isInputTrace())		      createMagicDramLoad((InputTraceNode)node.getPrevious(), 		      node, (init || primePump), rawChip);*/		    newIns.addRoute(src2, SwitchOPort.CSTI2);		    code.appendIns(newIns, init||primePump);		}		if(!first) {		    newIns = new FullIns(tile);		    /*if (KjcOptions.magicdram && node.getNext() != null &&		      node.getNext().isOutputTrace())		      createMagicDramStore((OutputTraceNode)node.getNext(), 		      node, (init || primePump), rawChip);*/		    newIns.addRoute(SwitchIPort.CSTO,dest2);		    code.appendIns(newIns, init||primePump);		}		first=false;	    }	Label label = code.getFreshLabel();	//code.appendIns(label, init||primePump);	final int numTimes = Linear.getMult(peek);	int pendingSends=0;	int times=0;	FullIns ins=null;	//final int turns2=content.getTotal()-content.getPos()+1;	final int turns2=content.getPos();	//final int turns2=1;	for(int turn=0;turn<turns2+4;turn++) {	    if(turn==turns2)		code.appendIns(label, init||primePump);	    for(int i = 0;i<numTimes;i++) {		for(int j=0;j<pop;j++) {		    if(numPop==1&&j==0)			pendingSends++;		    times++;		    ins = new FullIns(tile, new MoveIns(SwitchReg.R1, src));		    /*if (KjcOptions.magicdram && node.getPrevious() != null &&		      node.getPrevious().isInputTrace())		      createMagicDramLoad((InputTraceNode)node.getPrevious(), 		      node, (init || primePump), rawChip);*/		    ins.addRoute(src, SwitchOPort.CSTI);		    if(!end) {			/*if (KjcOptions.magicdram && node.getPrevious() != null &&			  node.getPrevious().isInputTrace())			  createMagicDramLoad((InputTraceNode)node.getPrevious(), 			  node, (init || primePump), rawChip);			  if (KjcOptions.magicdram && node.getNext() != null &&			  node.getNext().isOutputTrace())			  createMagicDramStore((OutputTraceNode)node.getNext(), 			  node, (init || primePump), rawChip);*/			ins.addRoute(src,dest);		    }		    if(turn>0&&times>1) {			if(!end)			    ins.addRoute(SwitchIPort.CSTO,dest2);			else			    ins.addRoute(SwitchIPort.CSTO,dest);		    }				    /*if(times>2) {		      if(!begin) {		      if (KjcOptions.magicdram && node.getPrevious() != null &&		      node.getPrevious().isInputTrace())		      createMagicDramLoad((InputTraceNode)node.getPrevious(), 		      node, (init || primePump), rawChip);		      ins.addRoute(src2,SwitchOPort.CSTI2);		      }		      pendingSends--;		      }*/		    /*if(turn>1) {		      if(!begin) {		      if (KjcOptions.magicdram && node.getPrevious() != null &&		      node.getPrevious().isInputTrace())		      createMagicDramLoad((InputTraceNode)node.getPrevious(), 		      node, (init || primePump), rawChip);		      ins.addRoute(src2,SwitchOPort.CSTI2);		      }		      }*/		    code.appendIns(ins, init||primePump);		    if(times==4) {			times=0;			if(true||!begin) {			    //if(turn==0)			    //pendingSends++;			    if(pendingSends>0) {				for(int l=0;l<pendingSends;l++) {				    ins=new FullIns(tile);				    if(/*turn>0&&*/!begin) {				/*if (KjcOptions.magicdram && node.getPrevious() != null &&				  node.getPrevious().isInputTrace())				  createMagicDramLoad((InputTraceNode)node.getPrevious(), 				  node, (init || primePump), rawChip);*/					ins.addRoute(src2,SwitchOPort.CSTI2);				    }				    /*if (KjcOptions.magicdram && node.getNext() != null &&				      node.getNext().isOutputTrace())				      createMagicDramStore((OutputTraceNode)node.getNext(), 				      node, (init || primePump), rawChip);*/			    				    if(turn>0&&l<1) {					if(!end)					    ins.addRoute(SwitchIPort.CSTO,dest2);					else					    ins.addRoute(SwitchIPort.CSTO,dest);				    }			    				    //if(!begin)				    code.appendIns(ins,init||primePump);				}				pendingSends=0;			    }			}		    }		    for(int k = 1;k<numPop;k++) {			if(j==0&&k==numPop-1)			    pendingSends++;			times++;			ins=new FullIns(tile);			ins.addRoute(SwitchReg.R1, SwitchOPort.CSTI);			code.appendIns(ins, init||primePump);			if(times==4) {			    times=0;			    if(true||!begin) {				//if(turn==0)				//pendingSends++;				if(pendingSends>0) {				    for(int l=0;l<pendingSends;l++) {					ins=new FullIns(tile);					if(/*turn>0&&*/!begin) {					    /*if (KjcOptions.magicdram && node.getPrevious() != null &&					      node.getPrevious().isInputTrace())					      createMagicDramLoad((InputTraceNode)node.getPrevious(), 					      node, (init || primePump), rawChip);*/					    ins.addRoute(src2,SwitchOPort.CSTI2);					}				/*if (KjcOptions.magicdram && node.getNext() != null &&				  node.getNext().isOutputTrace())				  createMagicDramStore((OutputTraceNode)node.getNext(), 				  node, (init || primePump), rawChip);*/									if(turn>0&&l<1) {					    if(!end)						ins.addRoute(SwitchIPort.CSTO,dest2);					    else						ins.addRoute(SwitchIPort.CSTO,dest);					}				//if(!begin)					code.appendIns(ins,init||primePump);				    }				    pendingSends=0;				}			    }			}		    }		}	    	    }	}	/*for(int i=0;i<numTimes-1;i++) {	  FullIns newIns=new FullIns(tile);	  newIns.addRoute(SwitchIPort.CSTO,dest);	  code.appendIns(newIns,init||primePump);	  }	  FullIns newIns=new FullIns(tile,new JumpIns(label.getLabel()));	  newIns.addRoute(SwitchIPort.CSTO,dest);	  code.appendIns(newIns,init||primePump);*/	//code.appendIns(new JumpIns(label.getLabel()),init||primePump);	ins.setProcessorIns(new JumpIns(label.getLabel()));	//START Copy from Gordo	//now we must take care of the remaining items on the input tape 	//after the initialization phase if the upstream filter produces more than	//we consume in init	if (init && filterInfo.remaining > 0) {	    appendReceiveInstructions(node, 				      filterInfo.remaining * Util.getTypeSize(node.getFilter().getInputType()),				      filterInfo, init, false, tile, rawChip);	}	//we must add some switch instructions to account for the fact	//that we must transfer cacheline sized chunks in the streaming dram	//do it for the init and the steady state, primepump 	//some sanity checks!	/*if (primePump)	  assert (sentItems == (filterInfo.totalItemsSent(init, primePump) - 	  filterInfo.primePumpItemsNotConsumed())) :	  "insane";	  else	  assert (sentItems == filterInfo.totalItemsSent(init, primePump)) :	  "insane";*/	//generate code to fill the remainder of the cache line	if (!KjcOptions.magicdram && node.getNext().isOutputTrace() && 	    cacheAlignDest)	    fillCacheLine(node, init, primePump, sentItems);	if (primePump && filterInfo.push > 0 &&	    filterInfo.primePumpItemsNotConsumed() / filterInfo.push > 0) {	    mult = (filterInfo.primePumpItemsNotConsumed() / filterInfo.push);	    for (int i = 0; i < mult; i++) {		//append the receive code		createReceiveCode(i, node, parent, filterInfo, init, primePump, tile, rawChip);		//append the send code 		createSendCode(i, node, parent, filterInfo, init, primePump, tile, rawChip);	    }	    //handle filling the cache line for the steady buffer of the primepump 	    //stage	    if (!KjcOptions.magicdram && node.getNext().isOutputTrace() && cacheAlignDest)		fillCacheLine(node, init, primePump, 			      filterInfo.primePumpItemsNotConsumed());	}	//because all dram transfers must be multiples of cacheline	//generate code to disregard the remainder of the transfer	if (!KjcOptions.magicdram && node.getPrevious().isInputTrace() && cacheAlignSource)	    handleUnneededInput(node, init, primePump, 				filterInfo.totalItemsReceived(init, primePump));	//STOP Copy From Gordo    }