





































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






































1 Introduction
The performance of pipelined processors is limited by data dependencies and branch instruction. In order to achieve the high performance, mechanisms must exist to alleviate the effects of data dependencies and branch instructions. Both hardware and software solutions exist to the data dependency problem. Software solutions use code scheduling techniques (combined with a large set of registers) to increase the distance between dependent instructions and to provide interlocks. Most hardware solutions are based on Tomasulo’s algorithm. R. M. Tomasulo published his algorithm while working for IBM in 1967. In his article titled, “An Efficient Algorithm for Exploiting Multiple Arithmetic Units,” he introduced the concept of reservation stations where an instruction can wait for its operands and allow subsequent instructions to proceed, thereby allowing out-of- order execution. In his approach the common data bus and register tagging scheme which permits simultaneous execution independent instructions while preserving the essential precedence inherent in the instruction stream. The common data bus improves performance by efficiently utilizing the execution units without requiring specially optimized code. Presently the reservation stations form the core of a dependency- resolution mechanism that must exist in order to preserve program dependencies. In addition the completion file to Tomasulo’s algorithm takes care of the three data dependencies RAW, WAW, and WAR, both in normal operation and during exceptions such as page faults and addition overflow etc. it has taken care of control dependencies during branching.
In this project I implemented the two instructions per clock instruction dispatch unit which efficiently handles the data hazards, control hazards and structural hazards using completion file. This project is basically further extension of 3rd^ project in which we need to replace the simple register file with the completion file. This project will have a bus for each arithmetic unit. Each arithmetic unit will also have two reservation stations feeding it sources for computation. There are few additional signals included for exception handling from and to the completion file. I implemented the whole system in Verilog and used Mentor Graphics’ ModelSim tool to simulate it.
The rest of this project report is organized as follows. The brief overview of different dependences and hazards are explained in section 2, and section 3 will describe the dynamic scheduling and Tomasulo’s algorithm. The top level design is described in section 4 and section 5 will go into a detailed explanation of the design, listing out signals and presenting block diagrams of individual module. Section 6 will discuss the verification methodologies and the test cases used to show the implementation met the specifications. The simulation snapshots and the Verilog code can be found in Appendix A and Appendix B respectively.
2 Concept of Dependences and Hazards
All processor since about 1985 use pipelining to overlap the execution of instructions and improve performance. The CPI(cycle per instruction) for a pipelined processor is the sum of the base CPI and all contributions from stalls.
Pipeline CPI = Ideal pipeline CPI+ Structural stalls + Data hazards stalls + Control stalls
The ideal pipeline CPI is a measure of maximum performance attainable by the implementation. By reducing each of the terms of the right-hand side, one minimizes the overall pipeline CPI.
To exploit the instruction-level parallelism one must determine which instruction can be executed in parallel. If two instructions are parallel, they can execute simultaneously in a pipeline without causing any stalls, assuming the pipeline has sufficient resources so that no structural hazards exist. If two instructions are dependent, they are not parallel and must be executed in order. So, it is very important to determine whether an instruction is dependent on another.
There are three different types of dependences: data dependences (also called true data dependences), name dependences and control dependences.
An instruction j is data dependent on instruction i if either of the following holds:
Name dependence occurs when two instructions use the same register or memory location, called a name , but there is no flow of data between the instructions associated with that name. There are two types of name dependences between an instruction i that precedes instruction j in program order:
When instruction j tries to write an operand before it is written by i. The writes end up being performed in the wrong order, leaving the value written by i rather than the value written by j in the destination. This hazard corresponds to output dependence. WAW hazards are present only in pipelines that write in more than one pipe stage or allow an instruction to proceed even when a previous instruction is stalled.
Control hazard arise from pipelining of branches and other instructions that changes the program counter.. The effects of these instructions can't be exactly determined until late in the pipeline. The following types of instructions can introduce control hazards:
There are following solution to handle the control hazards:
a) Pipeline stall cycles: Freeze the pipeline until the branch outcome and target are known, and then proceed with fetch. Thus, every branch instruction incurs a penalty equal to the number of stall cycles. This solution is unsatisfactory if the instruction mix contains many branch instructions, and/or the pipeline is very deep. b) Branch prediction: The outcome and target of conditional branches are predicted using some heuristic. Instructions are speculatively fetched and executed down the predicted path, but results are not written back to the register file until the branch is executed and the prediction is verified. When a branch is predicted, the processor enters a speculative mode in which results are written to completion file that mirrors the architected register file. Branch predictors can't be 100% accurate, so there is still a penalty for branches that is based on the branch misprediction rate. If the prediction is right then normal execution is continue and in case of wrong prediction it removes the instruction after that, get the correct address and load the program counter and start execution.
3 Dynamic Scheduling using Thomasulo’s Approach
A major limitation of simple pipelining techniques is that they use in-order instruction issue and execution. Instructions are issued in program order and if an instruction is stalled in the pipeline, no later instruction can proceed. Thus if there is a dependence between two closely spaced instructions in the pipeline, this will lead to a hazard and a stall will result. If there are multiple functional units, these units could lie idle. No new instructions are fetched or issued until the dependence is cleared. It reduces the overall performance. In dynamic scheduling, the hardware rearranges the instruction execution to reduce the stalls while maintaining data flow and exception behavior. It will use in-order instruction issue but out-of-order execution (an instruction begins execution as soon as its data operands are available). All instructions pass through the issue stage in-order. However, they can be stalled or bypass in the second stage and thus enter execution out of order. Out-of-order execution introduces the possibility of WAR and WAW hazards. Dynamic scheduling offers following advantages:
Fig1: The basic structure of floating units using Thomasulo’s algorithm
The most sophisticated algorithm to allow out-of-order execution is invented by Robert Thomasulo while working for IBM in 1967. In this scheme, it tracks when operand for
4 Top Level Design
This section will describe the top level design of instruction dispatch unit based on Thomasulo’s algorithm. The top level block diagram is shown in below figure 2. The salient features of the top level design are following:
New requirements needed for a completion file.
Instruction dispathch control unit
Multiplier reservation station
Instruction queue
Adder reservation station
Adder Multiplier
Completion file
Fetch reservation station
Write reservation station
Cache
Instruction line Adder line Fetch line Multiplier line
Data operands Test Bench
Dec-inst
Dec_inst
inst0 inst
Sel
Figure 2: High level design view.
In order to get maximum work done in a single clock cycle as well as to make the clock cycle as short as possible, two phased clocking is used. 3 shows how a single clock signal can provide two phased clocking. On the positive cycle the output from Logic B is latched, while on the negative cycle the output from Logic A is latched. Thus more work can be done in a single clock cycle versus doing single phased clocking.
This architecture currently supports two data transfer instructions for fetching/writing from/to memory. Currently it supports only direct mapped load and store instructions. The first 4 most significant bits (MSB) represent opcode for load and store operation. Then next 4 bits represent source/destination register id for store /load instruction and last 8 bits represent the absolute address of memory location. Please see the below figure and table for detail understanding.
Figure 5: Load/Store instruction set.
Field Bits Description Opcode 15:12 Opcode for different data transfer operation LOAD:= STORE:= src/dst 11:8 Source/destination register for store/load instruction respectively Mem addr 7:0 Memory location
Table2: Load/Store instruction fields.
The architecture currently supports one branch instruction of 16-bits wide. The first 4 most significant bits represents the branch opcode. Then next 4 bits represent condition field and last 8 bit represent branch address. Please see the below figure and table for detail understanding.
Figure 6: Branch instruction.
Field Bits Description Opcode 15:12 Opcode for different data transfer operation BRANCH:= Condition 11:8 Condition for branching Branch addr 7:0 Branch location
Table3: Branch instruction fields.
The instruction queue holds the different instructions loaded by the testbench. It includes arithmetic and data transfer instruction as mentioned in previous section. It will issue two instructions per clock to instruction dispatch unit in-order fashion. It holds the instruction incase there is a structural hazard and dispatch control unit unable to decode the instruction. It gets select signal from dispatch control unit to implement this feature. The dispatch unit to rename these registers as it sees fit to decouple the programmer’s view of registers from the actual hardware.
The program counter (PC) will tell the instruction queue what instruction is next to be dispatched. The PC will be a simple counter that will update according to feedback given by the dispatch logic select signal. The dispatch logic may dispatch both, one, or none of the instructions, and thus the instruction queue’s PC must update accordingly. The response will happen every positive clock cycle. Figure 6 shows the feedback connection from a top level perspective and the implementation of each stage of queue. In this design it handles the case of wrong branch prediction using completion file. During wrong branch prediction it removes the later content of completion register and also removes the content instruction queue. Then predict the correct address and fetch the instruction and load the queue again. The signal ‘reset_queue’ is responsible for remove the instruction queue contents.
Figure 7: Dispatch unit and instruction queue interface.
the data value and the tag onto the bus. The waiting reservation will see the tag on the bus and fill in its source information. Additionally the other operand might have already been filled as soon as the register file saw that the instruction needed the R2 value for the second instruction’s source. Also, register file added the tag of reservation station A1 and A2 to R1 and R0 registers respectively which indicates this register waits for the result of A1 and A2 reservation stations. Please see the below figure for RAW example.
Figure 8: RAW example.
The WAW and WAR dependency will be resolved by register renaming. The register renaming is provided by reservation stations as shown in below figure.
Figure 9: WAW example.
Figure 10: WAR example. In previous project, the register file was unable to keep track of values at certain PC values during exceptions. The completion file fixes this by keeping state across PC. Figure 10 shows the WAR dependency with register R2. It is first read in the first instruction and written to in the second instruction. The hazard can occur when the first instruction causes an exception. The second instruction may complete before a fully system halt can occur. Thus, when the registers are presented to the programmer after execution the R2 value will be the incorrect value—the second instruction. The completion file deals with this data dependency and control hazard. More on this in the section 4.8 describing the completion file.
A structural hazard is the case where reservation stations are completely filled up for a given sequence of instructions. Take for instance the scenario where three additions are sent back-to-back and there are two reservation stations for addition. After the first two additions, both reservation stations will be fill, most likely waiting for certain tags to have the data filled in. When this happens, the hardware will stall for 3rd^ addition due to unavailable of resource and then dispatch control unit notifies the instruction queue about stall.
The reservation station is a place where a single instruction waits for sources to be ready. In this design there will be four types of reservation stations: adder reservation station, multiplier reservation station, fetch reservation station and write reservation station. The reservation stations first read an operation on the bus designated for it, store the tags for the sources, get the data for each associated tag, and be ready to feed the data into the functional unit when the functional unit is ready.
There will be two adder reservation stations which will buffer two addition operations that need to be performed. The reservation station will monitor the dispatch instruction
Set as soon as operand1 is available Valid 2 24 Valid bit for operant 2 Set as soon as operand2 is available Source1 Tag 23:20 Tag for operand Source1 Data 19:12 Data field of operand 1 Source 2 Tag 11:8 Tag for operand Source 2 Data 7:0 Data field of operand 2 Table 3: Multiplier reservation station fields
There will be two fetch reservation stations which will buffer two fetch operations that need to be performed. The reservation station will monitor the dispatch instruction buses and if it finds an instruction for that reservation station then it loads memory address for fetch operation. In this design, there are two fetch reservation stations F1 and F2. For simplicity I used absolute addressing and assume that cache hit during memory fetch operation. Please see the different fields of reservation stations in below figure and brief description in given table.
Figure 12: Fetch reservation stations.
Field Bits Description Valid 16 Valid bit for operand 1 Address 15:8 Absolute memory address Data 7:0 Fetch data Table 3: Fetch reservation station fields
There will be two write reservation stations which will buffer two write operations that need to be performed. The reservation station will monitor the dispatch instruction buses and if it finds an instruction for that reservation station then it stores the tags for store operation. Then it waits for the data from different functional unit with matching tag then it loads the data and sends it to memory. In this design, there are two write reservation stations W1 and W2. For simplicity I used absolute addressing and assume that cache hit during memory write operation. Please see the different fields of reservation stations in below figure and brief description in the table.
Figure 13: Write reservation stations.
Field Bits Description Valid 16 Valid bit for operand 1 Address 15:8 Absolute memory address Tag 11:8 Tag of required writing data Data 7:0 Writing data Table 3: Write reservation station fields
The functional units are responsible for actual arithmetic operation such as addition and multiplication or data transfer operation such as fetch or write operation. The goal of the reservation stations is to keep both units as busy as possible and maximize throughput.
The arithmetic units have pipelined architecture to get maximum throughput. The latency of adder and multiplier are 3 and 5 clock cycles respectively. The conceptual diagram of arithmetic unit is shown in below figure. It will receive two sources and the source of the reservation station from both reservation stations. The reason there are four inputs for data is because there are two reservation stations in charge of feeding the arithmetic units data. The unit will pick from which ever is available first. The clear bit will indicate to the reservation station that the data was chosen and the line can be cleared for new input. The results are broadcasts along with reservation station tag. So that different units waiting for this data can strobe it.