int main(int argc, char* argv[]) { if (argc !=4) usage(); string hostsFile=argv[1]; ifstream diff(argv[2]); port = (unsigned short)atoi(argv[3]); if (diff.fail()) { cerr << "error: open diff file" << endl; usage(); } if (verbose) cout << "Reading diff..." << endl; assert(readChanges(diff)); if (verbose) cout << "Reading core info..." << endl; assert(getCores(hostsFile)); diff.close(); if (verbose) cout << "Getting addresses..."<<endl; errcheck(getAddrs()); if (verbose) cout << "Constructing stage data..."<<endl; errcheck(makeStages()); if (verbose) cout << "Opening connections..." << endl; errcheck(initConnections()); if (verbose) cout << "Transferring stage data..." << endl; errcheck(sendStages()); int i; for (i=0;i<3;i++) { if (verbose) cout << "Doing stage " << i << "..."<<endl; errcheck(doStage(i)); } if (verbose) cout << "Closing connections..." <<endl; errcheck(finishConnections()); if (verbose) cout<<"Reassign complete."<<endl; }
int main(int argc, char *argv[]) { InstInfo curInst[5]; InstInfo newInst; InstInfo * saved; int instnum = 0; int maxpc; int count=0; int cycles; // total cycles in the pipeline int needsFetch = 1; // fetching flag, 1 to fetch, 0 not to fetch int stall = 0; // stall flag, 1 to stall, 0 not to stall int isTaken = 0; int i=0; int j=0; FILE *program; if (argc != 2) { printf("Usage: sim filename\n"); exit(0); } maxpc = load(argv[1]); cycles = maxpc + 4;//**************************change to + 4 for REAL output if(debug)printf("cycles : %d \n" , cycles); if(debug)printLoad(maxpc); // initialize 5 instructions with 0 for(i=0; i<5; i++){ pipelineInsts[i]= &curInst[i]; pipelineInsts[i]->inst=0; if(debug)printf("DEBUG: pipelineInsts[%d]: %d\n", i, pipelineInsts[i]->inst); } do{ doStage(needsFetch, &stall, &cycles, &count); // doStage calls stage functions saved = pipelineInsts[4]; // save the unused pointer for reuse // setting needsFetch flag if(count < maxpc) needsFetch = 1; else needsFetch = 0; if(debug)printf("DEBUG: stall value: %d\n", stall); // if stall is not being set if(!stall){ if(debug)printf("DEBUG: no stall\n"); if(debug)printf("DEBUG: not stall before, pipelineInst[0] ----> %d, %s\n", pipelineInsts[0]->inst, pipelineInsts[0]->string); printP2(pipelineInsts[0], pipelineInsts[1], pipelineInsts[2], pipelineInsts[3], pipelineInsts[4], count); //shift down 4 instructions for(i=4; i>0; i--){ pipelineInsts[i]=pipelineInsts[i-1]; } //printf("DEBUG: no stall, swap....\n"); //printP2(pipelineInsts[0], pipelineInsts[1], pipelineInsts[2], pipelineInsts[3], pipelineInsts[4], count); //saved->inst = 0; // reset inst = 0 pipelineInsts[0] = saved; // reuse the unused inst pointer clearInst(pipelineInsts[0]); if(debug)printf("DEBUG: not stall after, pipelineInst[0] ----> %d, %s\n", pipelineInsts[0]->inst, pipelineInsts[0]->string); } // if stall is being set else{ if(debug)printf("DEBUG: stall before, pipelineInst[0] ----> %d, %s\n", pipelineInsts[0]->inst, pipelineInsts[0]->string); if(debug)printf("DEBUG: stalls\n"); printP2(pipelineInsts[0], pipelineInsts[1], pipelineInsts[2], pipelineInsts[3], pipelineInsts[4], count); pipelineInsts[4] = pipelineInsts[3]; // shift down memory stage pipelineInsts[3] = pipelineInsts[2]; // shitf down execute stage saved->inst = 0; // reset the unused inst to be 0 pipelineInsts[2] = saved; // stall the execute stage clearInst(pipelineInsts[2]); stall = 0; // reset stall flag cycles++; if(debug)printf("DEBUG: stall after, pipelineInst[0] ----> %d, %s\n", pipelineInsts[0]->inst, pipelineInsts[0]->string); //printf("DEBUG: stall, swap....\n"); //printP2(pipelineInsts[0], pipelineInsts[1], pipelineInsts[2], pipelineInsts[3], pipelineInsts[4], count); } count++; // increment count for cycles }while(count < cycles); // put in your own variables printf("Cycles: %d\n", count); printf("Instructions Executed: %d\n", maxpc); exit(0); }