Pipeline Document
Pipeline Document
Overview
The MIPS Pipeline Simulator models the execution of MIPS instructions using a 5-stage
pipeline:
- Instruction Fetch (IF)
- Instruction Decode (ID)
- Execution (EX)
- Memory Access (MEM)
- Write Back (WB)
The program reads instructions from a binary file and processes them through these stages. It
handles hazards, controls signals, and simulates clock cycles.
1. Latches
- if_id_latch: Holds the instruction and program counter (PC) between the IF and ID
stages.
- id_ex_latch: Holds control signals and operands between the ID and EX stages.
- ex_mem_latch: Holds ALU results and control signals between the EX and MEM
stages.
- mem_wb_latch: Holds data to be written back to registers between the MEM and WB
stages.
Hazard Unit
hu: Manages forwarding and stalling signals to handle data hazards.
Instruction Information
Function Descriptions
- AluCalc(int opnd1, int opnd2, int E, int control): Performs ALU operations based on
control signals.
- setConSig(int op, int funct): Sets control signals based on the opcode and function
code.
The main function sets up the simulation environment and enters an infinite loop to simulate
the pipeline stages:
- File Handling: Opens the binary file containing MIPS instructions. If no file is
specified, it defaults to "input4.bin".
- Load Instructions: Loads instructions from the file into memory using
load_instruction.
- Initialize: Initializes registers and memory using initialize.
- Simulation Loop: Continuously processes instructions through the pipeline stages:
- Write Back: Calls write_back to write results to registers.
- Memory Access: Calls memory_access to handle memory operations.
- Execution: Calls execution to perform ALU operations.
- Instruction Decode: Calls instruction_decode to decode instructions.
- Instruction Fetch: Calls instruction_fetch to fetch the next instruction.
- Clock Cycle Update: Advances the clock cycle and updates timing information.
- Hazard Detection and Stalling: Handles hazards and potential stalls between stages.
- Program Termination: Ends when the program counter reaches the end of the
instruction memory or encounters an error.
^Single Cycle^
vPipelinedv
Personal Feelings and Experience
Implementing pipelined MIPS is indeed very difficult as there are many objectives
that need to be completed, such as data dependency and branch problems. During the period
that this assignment was open, I had a very hard time completing the assignment. Even
though I can understand most of the stuff that is taught inside the classroom, Implementing it
is way harder than I thought. Therefore, I decided to use ChatGPT for help on some functions
and implementations that are very confusing and things that didn’t come to mind(labelled
inside the code). But since even ChatGPT is confusing at times, I also asked my seniors for
help in bigger parts(labelled in the code). Problems such as hazard detection and stalling
became very confusing as I was writing the code, and they helped me with the understanding
of what it is, and gave me example codes in which I can follow and implement to make my
own version. They also helped me to put loops inside of the code.
Even if the concept of pipelined MIPS is only partly different from a single cycle,
there are so many things that I have to keep in mind to make the program run smoothly. Last
time, before data dependency and branch predictions, my code did not run, and if it did, it
would have problems regarding the registers that are used and it is obvious that there were
many mistakes since these two things were not implemented yet. I started this project earlier
than when I started the single cycle project, and since there were no exams in the middle, I
had more time to do this project and more time to ask around about how I can implement it
and ask for help regarding the project. Therefore, this project feels more relaxed even though
it isn’t.