private ObservableCollection <LoopUnrolInstructionModel> ScheduledUnrolledLoop() { var ScheduledExecutedLoopCode = new ObservableCollection <LoopUnrolInstructionModel>(); var operations = Instructions.OrderBy(item => item.Order).Select(item => item.Operation).Distinct().ToList(); int order = 0; //Get all the operations in order foreach (var op in operations) { //Get the instructions that got this operation var opInstructions = UnrolledInstructions.Where(item => item.Operation == op).ToList(); //Loop throw the instructions and add them foreach (var inst in opInstructions) { var newInstruction = new LoopUnrolInstructionModel { Order = ++order, Operation = inst.Operation, SourceRegistery01 = inst.SourceRegistery01, SourceRegistery02 = inst.SourceRegistery02, TargetRegistery = inst.TargetRegistery, ImmediateValueOrDisplacmnet = inst.ImmediateValueOrDisplacmnet, }; ScheduledExecutedLoopCode.Add(newInstruction); } } UnrolledScheduledExecutedCodeClockCycles = 3; return(ExecuteCode(ScheduledExecutedLoopCode, scheduled: true)); }
private void UnrollAndExecuteCodeLoop() { //If we want to unroll more than the loop counter if (LoopCounter < UnrollLoopTimes) { //Spread the loop up UnrollLoopTimes = LoopCounter; } var integerIncremnt = 4; var displacmentIncrement = 0; int order = 0; UnrolledInstructions = new ObservableCollection <LoopUnrolInstructionModel>(); var leftRegistersForRename = Enum.GetNames(typeof(RegisteriesAndMemory)).Where(item => item.Contains('F')).ToList(); if (SelectedBranchRegistery01 != null) { leftRegistersForRename.Remove(SelectedBranchRegistery01); } //get The left registers that are not used foreach (var item in Instructions) { if (leftRegistersForRename.Contains(item.TargetRegistery)) { leftRegistersForRename.Remove(item.TargetRegistery); } if (leftRegistersForRename.Contains(item.SourceRegistery01)) { leftRegistersForRename.Remove(item.SourceRegistery01); } if (leftRegistersForRename.Contains(item.SourceRegistery02)) { leftRegistersForRename.Remove(item.SourceRegistery02); } } for (int i = 0; i < InstructionNumToLoopTo - 1; i++) { var newInstruction = new LoopUnrolInstructionModel { Order = ++order, Operation = Instructions[i].Operation, SourceRegistery01 = Instructions[i].SourceRegistery01, SourceRegistery02 = Instructions[i].SourceRegistery02, TargetRegistery = Instructions[i].TargetRegistery, ImmediateValueOrDisplacmnet = Instructions[i].ImmediateValueOrDisplacmnet, }; UnrolledInstructions.Add(newInstruction); } for (int i = 0; i < UnrollLoopTimes; i++) { for (int j = InstructionNumToLoopTo - 1; j < Instructions.Count; j++) { var newInstruction = new LoopUnrolInstructionModel { Order = ++order, Operation = Instructions[j].Operation, SourceRegistery01 = Instructions[j].SourceRegistery01, SourceRegistery02 = Instructions[j].SourceRegistery02, TargetRegistery = Instructions[j].TargetRegistery, ImmediateValueOrDisplacmnet = Instructions[j].ImmediateValueOrDisplacmnet, }; //If the instruction is a load ... if (newInstruction.Operation == FunctionsTypes.LD.ToString() || newInstruction.Operation == FunctionsTypes.SD.ToString()) { //Then we need to move the displacment newInstruction.ImmediateValueOrDisplacmnet += displacmentIncrement; } UnrolledInstructions.Add(newInstruction); } displacmentIncrement += integerIncremnt; } //Add left overs for (int i = 0; i < LoopCounter % UnrollLoopTimes; i++) { } var targetRegDic = new Dictionary <string, string>(); for (int i = Instructions.Count; i < UnrolledInstructions.Count; i++) { if (UnrolledInstructions[i].Operation == FunctionsTypes.SD.ToString()) { //If the registery must be renamed if (targetRegDic.TryGetValue(UnrolledInstructions[i].SourceRegistery01 ?? "", out string newSource)) { UnrolledInstructions[i].SourceRegistery01 = newSource; } continue; } //If we went throw a loop if (i % Instructions.Count == 0) { targetRegDic = new Dictionary <string, string>(); } //Get a registery to rename for var renamedReg = leftRegistersForRename.FirstOrDefault(); //Check if any lefy if (renamedReg != null) { try { targetRegDic.Add(UnrolledInstructions[i].TargetRegistery, renamedReg); } catch (Exception) { //MessageBox.Show("Please check code and try agian"); break; } UnrolledInstructions[i].TargetRegistery = renamedReg; leftRegistersForRename.Remove(renamedReg); } else { MessageBox.Show("No more left empty registers!!"); break; } try { //If the registery must be renamed if (targetRegDic.TryGetValue(UnrolledInstructions[i].SourceRegistery01, out string value)) { UnrolledInstructions[i].SourceRegistery01 = value; } //If the registery must be renamed if (targetRegDic.TryGetValue(UnrolledInstructions[i].SourceRegistery02 ?? "", out string value2)) { UnrolledInstructions[i].SourceRegistery02 = value2; } } catch (Exception) { MessageBox.Show("Please check code and try agian"); break; } } }