1 of 54

William Stallings �Computer Organization �and Architecture�10th Edition

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

+

2 of 54

Chapter 14

Processor Structure and Function

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

​

​

​

​

​

+

3 of 54

Processor Organization

  • Fetch instruction
    • The processor reads an instruction from memory (register, cache, main memory)
  • Interpret instruction
    • The instruction is decoded to determine what action is required
  • Fetch data
    • The execution of an instruction may require reading data from memory or an I/O module
  • Process data
    • The execution of an instruction may require performing some arithmetic or logical operation on data
  • Write data
    • The results of an execution may require writing data to memory or an I/O module
  • In order to do these things the processor needs to store some data temporarily and therefore needs a small internal memory

Processor Requirements:

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

+

4 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

5 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

6 of 54

Register Organization

  • Enable the machine or assembly language programmer to minimize main memory references by optimizing use of registers
  • Used by the control unit to control the operation of the processor and by privileged operating system programs to control the execution of programs

User-Visible Registers

Control and Status Registers

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

  • Within the processor there is a set of registers that function as a level of memory above main memory and cache in the hierarchy
  • The registers in the processor perform two roles:

+

7 of 54

User-Visible Registers

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Referenced by means of the machine language that the processor executes

    • General purpose
      • Can be assigned to a variety of functions by the programmer
    • Data
      • May be used only to hold data and cannot be employed in the calculation of an operand address
    • Address
      • May be somewhat general purpose or may be devoted to a particular addressing mode
      • Examples: segment pointers, index registers, stack pointer
    • Condition codes
      • Also referred to as flags
      • Bits set by the processor hardware as the result of operations

Categories:

8 of 54

Table 14.1�Condition Codes

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

9 of 54

Control and Status Registers

  • Program counter (PC)
    • Contains the address of an instruction to be fetched
  • Instruction register (IR)
    • Contains the instruction most recently fetched
  • Memory address register (MAR)
    • Contains the address of a location in memory
  • Memory buffer register (MBR)
    • Contains a word of data to be written to memory or the word most recently read

Four registers are essential to instruction execution:

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

+

10 of 54

Program Status Word (PSW)

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Register or set of registers that contain status information

Common fields or flags include:

    • Sign
    • Zero
    • Carry
    • Equal
    • Overflow
    • Interrupt Enable/Disable
    • Supervisor

+

11 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

12 of 54

Instruction Cycle

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Includes the following stages:

Fetch

Read the next instruction from memory into the processor

Execute

Interpret the opcode and perform the indicated operation

Interrupt

If interrupts are enabled and an interrupt has occurred, save the current process state and service the interrupt

13 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

14 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

15 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

16 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

17 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

18 of 54

Pipelining Strategy

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Similar to the use of an assembly line in a manufacturing plant

New inputs are accepted at one end before previously accepted inputs appear as outputs at the other end

To apply this concept to instruction execution we must recognize that an instruction has a number of stages

19 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

20 of 54

Additional Stages

  • Fetch instruction (FI)
    • Read the next expected instruction into a buffer
  • Decode instruction (DI)
    • Determine the opcode and the operand specifiers
  • Calculate operands (CO)
    • Calculate the effective address of each source operand
    • This may involve displacement, register indirect, indirect, or other forms of address calculation
  • Fetch operands (FO)
    • Fetch each operand from memory
    • Operands in registers need not be fetched
  • Execute instruction (EI)
    • Perform the indicated operation and store the result, if any, in the specified destination operand location
  • Write operand (WO)
    • Store the result in memory

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

+

21 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

22 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

23 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

24 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

25 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

26 of 54

Pipeline Hazards

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Occur when the pipeline, or some portion of the pipeline, must stall because conditions do not permit continued execution

Also referred to as a pipeline bubble

There are three types of hazards:

    • Resource
    • Data
    • Control

27 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

28 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

29 of 54

Types of Data Hazard

  • Read after write (RAW), or true dependency
    • An instruction modifies a register or memory location
    • Succeeding instruction reads data in memory or register location
    • Hazard occurs if the read takes place before write operation is complete
  • Write after read (WAR), or antidependency
    • An instruction reads a register or memory location
    • Succeeding instruction writes to the location
    • Hazard occurs if the write operation completes before the read operation takes place
  • Write after write (WAW), or output dependency
    • Two instructions both write to the same location
    • Hazard occurs if the write operations take place in the reverse order of the intended sequence

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

+

30 of 54

Control Hazard

  • Also known as a branch hazard
  • Occurs when the pipeline makes the wrong decision on a branch prediction
  • Brings instructions into the pipeline that must subsequently be discarded
  • Dealing with Branches:
    • Multiple streams
    • Prefetch branch target
    • Loop buffer
    • Branch prediction
    • Delayed branch

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

+

31 of 54

Multiple Streams

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

A simple pipeline suffers a penalty for a branch instruction because it must choose one of two instructions to fetch next and may make the wrong choice

A brute-force approach is to replicate the initial portions of the pipeline and allow the pipeline to fetch both instructions, making use of two streams

Drawbacks:

    • With multiple pipelines there are contention delays for access to the registers and to memory
    • Additional branch instructions may enter the pipeline before the original branch decision is resolved

32 of 54

Prefetch Branch Target

  • When a conditional branch is recognized, the target of the branch is prefetched, in addition to the instruction following the branch
  • Target is then saved until the branch instruction is executed
  • If the branch is taken, the target has already been prefetched
  • IBM 360/91 uses this approach

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

+

33 of 54

Loop Buffer

  • Small, very-high speed memory maintained by the instruction fetch stage of the pipeline and containing the n most recently fetched instructions, in sequence
  • Benefits:
    • Instructions fetched in sequence will be available without the usual memory access time
    • If a branch occurs to a target just a few locations ahead of the address of the branch instruction, the target will already be in the buffer
    • This strategy is particularly well suited to dealing with loops
    • Similar in principle to a cache dedicated to instructions
    • Differences:
      • The loop buffer only retains instructions in sequence
      • Is much smaller in size and hence lower in cost

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

+

34 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

35 of 54

Branch Prediction

  • Various techniques can be used to predict whether a branch will be taken:

​

    • Predict never taken
    • Predict always taken
    • Predict by opcode

​

​

    • Taken/not taken switch
    • Branch history table

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

    • These approaches are static
    • They do not depend on the execution history up to the time of the conditional branch instruction
    • These approaches are dynamic
    • They depend on the execution history

+

36 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

37 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

38 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

39 of 54

Intel 80486 Pipelining

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Write back

Updates registers and status flags modified during the preceding execute stage

Execute

Stage includes ALU operations, cache access, and register update

Decode stage 2

Expands each opcode into control signals for the ALU

Also controls the computation of the more complex addressing modes

Decode stage 1

All opcode and addressing-mode information is decoded in the D1 stage

3 bytes of instruction are passed to the D1 stage from the prefetch buffers

D1 decoder can then direct the D2 stage to capture the rest of the instruction

Fetch

Objective is to fill the prefetch buffers with new data as soon as the old data have been consumed by the instruction decoder

Operates independently of the other stages to keep the prefetch buffers full

40 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

41 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Table 14.2

​

x86

Processor

Registers

42 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

43 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

44 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

45 of 54

Interrupt Processing

  • Interrupts
    • Generated by a signal from hardware and it may occur at random times during the execution of a program
    • Maskable
    • Nonmaskable
  • Exceptions
    • Generated from software and is provoked by the execution of an instruction
    • Processor detected
    • Programmed
  • Interrupt vector table
    • Every type of interrupt is assigned a number
    • Number is used to index into the interrupt vector table

Interrupts and Exceptions

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

+

46 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Unshaded: exceptions

Shaded: interrupts

​

Table 14.3

​

x86 Exception and Interrupt Vector Table

47 of 54

The ARM Processor

  • Moderate array of uniform registers
  • A load/store model of data processing in which operations only perform on operands in registers and not directly in memory
  • A uniform fixed-length instruction of 32 bits for the standard set and 16 bits for the Thumb instruction set
  • Separate arithmetic logic unit (ALU) and shifter units
  • A small number of addressing modes with all load/store addresses determined from registers and instruction fields
  • Auto-increment and auto-decrement addressing modes are used to improve the operation of program loops
  • Conditional execution of instructions minimizes the need for conditional branch instructions, thereby improving pipeline efficiency, because pipeline flushing is reduced

ARM is primarily a RISC system with the following attributes:

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

+

48 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

49 of 54

Processor Modes

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

ARM architecture supports seven execution modes

Most application programs execute in user mode

    • While the processor is in user mode the program being executed is unable to access protected system resources or to change mode, other than by causing an exception to occur

Remaining six execution modes are referred to as privileged modes

    • These modes are used to run system software

Advantages to defining so many different privileged modes

    • The OS can tailor the use of system software to a variety of circumstances
    • Certain registers are dedicated for use for each of the privileged modes, allows swifter changes in context

50 of 54

Exception Modes

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Have full access to system resources and can change modes freely

Entered when specific exceptions occur

Exception modes:

    • Supervisor mode
    • Abort mode
    • Undefined mode
    • Fast interrupt mode
    • Interrupt mode

System mode:

    • Not entered by any exception and uses the same registers available in User mode
    • Is used for running certain privileged operating system tasks
    • May be interrupted by any of the five exception categories

51 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

52 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

53 of 54

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Table 14.4

​

ARM

Interrupt

Vector

54 of 54

Summary

  • Processor organization
  • Register organization
    • User-visible registers
    • Control and status registers
  • Instruction cycle
    • The indirect cycle
    • Data flow
  • The x86 processor family
    • Register organization
    • Interrupt processing
  • Instruction pipelining
    • Pipelining strategy
    • Pipeline performance
    • Pipeline hazards
    • Dealing with branches
    • Intel 80486 pipelining
  • The Arm processor
    • Processor organization
    • Processor modes
    • Register organization
    • Interrupt processing

​

​

Chapter 14

​

Processor Structure and Function

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

+