public void Init() { clocks = 0; originalInstructions = instructionUnit.GetCurrentInstructions(); issueClocks = new int[100]; executeClocks = new int[100]; writeClocks = new int[100]; for (int i = 0; i < 100; i++) { issueClocks[i] = -1; executeClocks[i] = -1; writeClocks[i] = -1; } loadStation = new ReservationStation(3, ReservationStation.RSType.Load); storeStation = new ReservationStation(3, ReservationStation.RSType.Store); addStation = new ReservationStation(3, ReservationStation.RSType.Add); multiplyStation = new ReservationStation(2, ReservationStation.RSType.Multiply); branchStation = new ReservationStation(5, ReservationStation.RSType.Multiply); floatRegs = new FloatingPointRegisters(30); for (int i = 0; i < 30; i++) { floatRegs.Set(WaitInfo.WaitState.Avail, i + 1, i); } intRegs = new IntegerRegisters(30); memLocs = new FloatingPointMemoryArrary(64); for (int i = 0; i < 64; i++) { memLocs.Set(i + 1, i); } UpdateInstructionQueueBox(); UpdateIssuedInstructionsBox(); UpdateReservationStationBoxes(); UpdateFPRegisterBox(); UpdateIntRegisterBox(); UpdateClockCountBox(); }
private void Issue() { // If empty. if (instructionUnit.GetCurrentInstructions().Length == 0) { return; } int bufNum; Instruction instruction = instructionUnit.PeekAtInstruction(); Operand jReg, kReg; WaitInfo wsJ, wsK; // Get Source Regs. jReg = new Operand(instruction.j); kReg = new Operand(instruction.k); wsJ = FindRegister(instruction.j); wsK = FindRegister(instruction.k); switch (instruction.instType) { case Instruction.InstructionType.Add: if ((bufNum = addStation.GetFreeBuffer()) != -1) { new Operand(instruction.j); // Put in Reservation Station. issuedInstructions.Add(instruction); issueClocks[numIssued++] = clocks; addStation.PutInBuffer(instructionUnit.GetInstruction(), bufNum, jReg, kReg, wsJ, wsK); addStation.instrNum[bufNum] = issuedInstructions.Count - 1; // Set Dest Reg. if (instruction.dest.Substring(0, 1) == "F") { // Float. floatRegs.Set(WaitInfo.WaitState.AddStation, bufNum, Int32.Parse(instruction.dest.Substring(1))); } else { // Int. intRegs.Set(WaitInfo.WaitState.AddStation, bufNum, Int32.Parse(instruction.dest.Substring(1))); } floatRegs.Set(WaitInfo.WaitState.AddStation, bufNum, Int32.Parse(instruction.dest.Substring(1))); } else { Console.WriteLine("Stalling due to a structural hazard."); } break; case Instruction.InstructionType.Multiply: if ((bufNum = multiplyStation.GetFreeBuffer()) != -1) { // Issue. issuedInstructions.Add(instruction); issueClocks[numIssued++] = clocks; multiplyStation.PutInBuffer(instructionUnit.GetInstruction(), bufNum, jReg, kReg, wsJ, wsK); multiplyStation.instrNum[bufNum] = issuedInstructions.Count - 1; // Set Dest Reg. if (instruction.dest.Substring(0, 1) == "F") { floatRegs.Set(WaitInfo.WaitState.MultStation, bufNum, Int32.Parse(instruction.dest.Substring(1))); } else { intRegs.Set(WaitInfo.WaitState.MultStation, bufNum, Int32.Parse(instruction.dest.Substring(1))); } } else { Console.WriteLine("Stalling due to a structural hazard."); } break; case Instruction.InstructionType.Load: if ((bufNum = loadStation.GetFreeBuffer()) != -1) { // Issue. issuedInstructions.Add(instruction); issueClocks[numIssued++] = clocks; loadStation.PutInBuffer(instructionUnit.GetInstruction(), bufNum, jReg, kReg, wsJ, wsK); loadStation.instrNum[bufNum] = issuedInstructions.Count - 1; // Set Dest Reg. if (instruction.dest.Substring(0, 1) == "F") { floatRegs.Set(WaitInfo.WaitState.LoadStation, bufNum, Int32.Parse(instruction.dest.Substring(1))); } else { intRegs.Set(WaitInfo.WaitState.LoadStation, bufNum, Int32.Parse(instruction.dest.Substring(1))); } } else { Console.WriteLine("Stalling due to a structural hazard."); } break; case Instruction.InstructionType.Store: if ((bufNum = storeStation.GetFreeBuffer()) != -1) { // Issue. issuedInstructions.Add(instruction); issueClocks[numIssued++] = clocks; storeStation.PutInBuffer(instructionUnit.GetInstruction(), bufNum, jReg, kReg, wsJ, wsK); storeStation.instrNum[bufNum] = issuedInstructions.Count - 1; } else { Console.WriteLine("Stalling due to a structural hazard."); } break; case Instruction.InstructionType.Branch: if ((bufNum = branchStation.GetFreeBuffer()) != -1) { // Issue. issuedInstructions.Add(instruction); issueClocks[numIssued++] = clocks; branchStation.PutInBuffer(instructionUnit.GetInstruction(), bufNum, jReg, kReg, wsJ, wsK); branchStation.instrNum[bufNum] = issuedInstructions.Count - 1; } else { Console.WriteLine("Stalling due to a structural hazard."); } break; } }