Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

This exercise explores how exception handling affects pipeline design. The first three problems in this exercise refer to the following two instructions:

Instruction 1

Instruction 2

BNE R1,R2, Label

LW R1,0(R1)

4.17.1 Which exceptions can each of these instructions trigger? For each of these exceptions, specify the pipeline stage in which it is detected.

4.17.2 If there is a separate handler address for each exception, show how the pipeline organization must be changed to be able to handle this exception. You can assume that the addresses of these handlers are known when the processor is designed.

4.17.3 If the second instruction is fetched right after the first instruction, describe what happens in the pipeline when the first instruction causes the first exception you listed in 4.17.1. Show the pipeline execution diagram from the time the first instruction is fetched until the time the first instruction of the exception handler is completed.

4.17.4 In vectored exception handling, the table of exception handler

addresses is in data memory at a known (fixed) address. Change the pipeline to implement this exception handling mechanism. Repeat 4.17.3 using this modified pipeline and vectored exception handling.

4.17.5 We want to emulate vectored exception handling (described in 4.17.4) on a machine that has only one fixed handler address. Write the code that should be at that fixed address. Hint: this code should identify the exception, get the right address from the exception vector table, and transfer execution to that handler.

Short Answer

Expert verified

4.17.1

Instructions

Exception

BNE R1,R2,Label

Invalid Target Address(EX)

LW R1, 0(R1)

Invalid Data Address(MEM)

4.17.2

The Multiplexor will select the next program counter where the inputs have to be added. Each input will have a constant address of an exception handler. For the appropriate pipeline stage, exception detectors must be added and the output of the detectors must be used to control the pre-PC Mux, and also to convert the NOP instructions.

4.17.3

Instructions

BNE R1,R2, Label

IF

ID

MEM

EXE

WB

Exception

NOP

NOP

NOP

NOP

NOP

Exception

NOP

NOP

NOP

NOP

NOP

LW R1, 0(R1)

IF

ID

MEM

EXE

WB

4.17.4

The address of the handler must be fetched in this method. The code of exception must be added to the address of the exception vector table and the handler’s address for the memory is read to jump to that address. Handle this as a special instruction that compute address in EX, loads the handlers’ address and sets PC in WB.

Instructions

BNE R1,R2, Label

IF

ID

MEM

EXE

WB

Exception

NOP

NOP

NOP

NOP

NOP

vectored exception

IF

ID

MEM

EXE

WB

LW R1, 0(R1)

IF

ID

MEM

EXE

WB

4.17.5

A special instruction is required to change the value from the cause register to the general-purpose register. General-purpose register is saved first, then the cause register gets loaded and the address of the vector table will be added to it. Use the result and jump to the handler.

Step by step solution

01

Determine Exception in pipeline.

Exception occurs when the there occurs error in the instruction execution. When the invalid address is specified there occurs the exception. When the exception occurs in the first instruction, the further instructions in the pipeline will become NOP. After the exception is handled then the instructions in the pipeline gets executed.

02

Determine the exceptions occurred in the given instructions.

4.17.1

Instructions

Exception

BNE R1,R2,Label

Invalid Target Address(EX)

LW R1, 0(R1)

Invalid Data Address(MEM)

In the instrcution 1, it will jump to the label if the register values are not equal. Here the Label target is not specified, so the invalid target address exception will occur.

In the instruction 2, the load word has noe data address specified, so the exception occurs.

03

Determine the changes in the pipeline.

4.17.2

The Multiplexor will select the next program counter where the inputs have to be added. Each input will have a constant address of an exception handler. For the appropriate pipeline stage, exception detectors must be added and the output of the detectors must be used to control the pre-PC Mux, and also to convert the NOP instructions.

04

Determine the pipeline stages.

4.17.3

Until the exception occurs, instructions will be fetced normally. At the time of exception detection, all instructions in the pipleline next to the first will be ocnverted as NOPs. Because of this the second instruction will not be completed and this will never affect the state of the pipeline. In a cycle in which the exception is dectectedm the processor will fetch the first instruction of the exception handler.

Instructions

BNE R1,R2, Label

IF

ID

MEM

EXE

WB

Exception

NOP

NOP

NOP

NOP

NOP

Exception

NOP

NOP

NOP

NOP

NOP

LW R1, 0(R1)

IF

ID

MEM

EXE

WB

05

Determine the vectored exception handling mechanism.

4.17.4

The address of the handler must be fetched in this method. The code of exception must be added to the address of the exception vector table and the handler’s address for the memory is read to jump to that address. Handle this as a special instruction that compute address in EX, loads the handlers’ address and sets PC in WB.

Instructions

BNE R1,R2, Label

IF

ID

MEM

EXE

WB

Exception

NOP

NOP

NOP

NOP

NOP

vectored exception

IF

ID

MEM

EXE

WB

LW R1, 0(R1)

IF

ID

MEM

EXE

WB

06

Determine the exception handling mechanism code.

4.17.5

A special instruction is required to change the value from the cause register to the general-purpose register. General-purpose register is saved first, then the cause register gets loaded and the address of the vector table will be added to it. Use the result and jump to the handler.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Question: For the problems in this exercise, assume that there are no pipeline stalls and that the breakdown of executed instructions is as follows: add addi not beq lw sw 20% 20% 0% 25% 25% 10% 4.5.1 [10] In what fraction of all cycles is the data memory used? 4.5.2 [10] In what fraction of all cycles is the input of the sign-extend circuit needed? What is this circuit doing in cycles in which its input is not needed.

This exercise is intended to help you understand the cost/complexity/performance trade-offs of forwarding in a pipelined processor. Problems in this exercise refer to pipelined data paths from Figure 4.45. These problems assume that, of all the instructions executed in a processor, the following fraction of these instructions have a particular type of RAW data dependence. The type of RAW data dependence is identified by the stage that produces the result (EX or MEM) and the instruction that consumes the result (1st instruction that follows the one that produces the result, 2nd instruction that follows, or both). We assume that the register write is done in the first half of the clock cycle and that register reads are done in the second half of the cycle, so “EX to 3rd” and “MEM to 3rd” dependencies are not counted because they cannot result in data hazards. Also, assume that the CPI of the processor is 1 if there are no data hazards.

Ex to 1st only

MEM to 1st only

EX to 2nd only

MEM to 2nd only

EX to 1st and MEM to 2nd

Other RAW Dependences

5%

20%

5%

10%

10%

10%

Assume the following latencies for individual pipeline stages. For the EX stage, latencies are given separately for a processor without forwarding and for a processor with different kinds of forwarding.

IF

ID

EX(no FW)

EX (full FW)

EX(FW from EX/MEM only)

Ex(FW from MEM/WB only)

MEM

WB

150ps

100ps

120ps

150ps

140ps

130ps

120ps

100ps

4.12.1 If we use no forwarding, what fraction of cycles are we stalling due to data hazards?

4.12.2 If we use full forwarding (forward all results that can be forwarded), what fraction of cycles are we staling due to data hazards?

4.12.3 Let us assume that we cannot afford to have three-input Muxes that are needed for full forwarding. We have to decide if it is better to forward only from the EX/MEM pipeline register (next-cycle forwarding) or only from the MEM/WB pipeline register (two-cycle forwarding). Which of the two options results in fewer data stall cycles?

4.12.4 For the given hazard probabilities and pipeline stage latencies, what is the speedup achieved by adding full forwarding to a pipeline that had no forwarding?

4.12.5 What would be the additional speedup (relative to a processor with forwarding) if we added time-travel forwarding that eliminates all data hazards? Assume that the yet-to-be-invented time-travel circuitry adds 100 ps to the latency of the full-forwarding EX stage.

4.12.6 Repeat 4.12.3 but this time determine which of the two options results in a shorter time per instruction.

Question: Consider the following instruction: Instruction: AND Rd,Rs,Rt Interpretation: Reg[Rd] = Reg[Rs] AND Reg[Rt] 4.1.1 [5] What are the values of control signals generated by the control in Figure 4.2 for the above instruction? 4.1.2 [5] Which resources (blocks) perform a useful function for this instruction? 4.1.3 [10] Which resources (blocks) produce outputs, but their outputs are not used for this instruction? Which resources produce no outputs for this instruction?.

Consider the following instruction: Instruction: AND Rd,Rs,Rt Interpretation: Reg[Rd] = Reg[Rs] AND Reg[Rt] 4.1.1 [5] What are the values of control signals generated by the control in Figure 4.2 for the above instruction? 4.1.2 [5] Which resources (blocks) perform a useful function for this instruction? 4.1.3 [10] Which resources (blocks) produce outputs, but their outputs are not used for this instruction? Which resources produce no outputs for this instruction?

Consider the following loop.

loop:lw r1,0(r1)

and r1,r1,r2

lw r1,0(r1)

lw r1,0(r1)

beq r1,r0,loop

Assume that perfect branch prediction is used (no stalls due to control hazards), that there are no delay slots, and that the pipeline has full forwarding support. Also, assume that many iterations of this loop are executed before the loop exits.

4.11.1 Show a pipeline execution diagram for the third iteration of this loop, from the cycle in which we fetch the first instruction of that iteration up to(but not including) the cycle in which we can fetch the first instruction of the next iteration. Show all instructions that are in the pipeline during these cycles (not just those from the third iteration).

4.11.2 How often (as a percentage of all cycles) do we have a cycle in which all five pipeline stages are doing useful work?

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free