Presentation is loading. Please wait.

Presentation is loading. Please wait.

ARM Organization and Implementation

Similar presentations


Presentation on theme: "ARM Organization and Implementation"— Presentation transcript:

1 ARM Organization and Implementation

2 3-stage pipeline ARM organization
The register bank, which stores the processor state. Barrel Shifter, which can shift or rotate one operand by any number of bits. ALU, performs the arithmetic and logic functions required by the instruction set.

3 3-stage pipeline ARM organization
Address register and incrementer, select and hold all memory addresses and generate sequential addresses when required. Data Register, which hold data passing to and from memory.

4 In a single-cycle data processing instruction, two registers operands are accessed, the value on the B bus is shifted and combined with the value on the A bus in the ALU, then the result is written back into the register bank. The program counter value is in the address register, from where it is fed into the incrementer, the incremented value is copied back into r15 in the register bank and also into the address register  to be used as the address for the next instruction fetch if needed.

5 The 3-stage pipeline ARM processors up to the ARM7 employ a simple 3-stage pipeline with the following pipeline stages Fetch Decode Execute Fetch: The instruction is fetched from memory and placed in the instruction pipeline. Decode: The instruction is decoded and the datapath control signals prepared for the next cycle. In this stage, the instruction ”owns” the decode logic but not the datapath Execute: The instruction “owns” the datapath The register bank is read. An operand is shifted. The ALU result is generated, and written back into a destination register. At any one time, three different instructions may occupy each of these stages, so the hardware in each stage has to be capable of independent operation.

6 ARM single-cycle instruction 3-stage pipeline operation
When the processor is executing simple data processing instructions the pipeline enables one instruction to be completed every clock cycle.  An individual instruction takes three clock cycles to complete, so it has three-cycle latency, but the throughput is one instruction per cycle.

7 ARM Multi Cycle instruction
3-stage pipeline operation When a multi-cycle instruction is executed the flow is less regular, as illustrated in Figure. This shows a sequence of single-cycle ADD instructions with a data store instruction, STR, occurring after the first ADD. The cycles that access main memory are shown with light shading so it can be seen that memory is used in every cycle. The datapath is likewise used in every cycle, being involved in all the execute cycles, the address calculation and the data transfer. The decode logic is always generating the control signals for the datapath to use in the next cycle, so in addition to the explicit decode cycles it is also generating the control for the data transfer during the address calculation cycle of the STR.

8 3-stage pipeline operation
When a multi-cycle instruction is executed the flow is less regular, as illustrated in Figure. This shows a sequence of single-cycle ADD instructions with a data store instruction, STR, occurring after the first ADD. The cycle colored in yellow is accessing main memory, so it can be seen that memory is used in every cycle. The datapath is likewise used in every cycle, being involved in all the execute cycles, the address calculation and the data transfer. The decode logic is always generating the control signals for the datapath to use in the next cycle, so in addition to the explicit decode cycles it is also generating the control for the data transfer during the address calculation cycle of the STR.

9 5 stage pipe line ARM organization
The time T, required to execute a given program is given by : Since Ninst is constant for a given program (compiled with a given compiler using a given set of optimizations, and so on) there are only two ways to increase performance.

10 Increase the clock rate, fclk.
This requires the logic in each pipeline stage to be simplified and, therefore, the number of pipeline stages to be increased. Reduce the average number of clock cycles per instruction, CPI. This requires either that instructions which occupy more than one pipeline slot in a 3-stage pipeline ARM are re-implemented to occupy fewer slots, or that pipeline stalls caused by dependencies between instructions are reduced, or a combination of both.

11 Memory Bottleneck A 3-stage ARM core accesses memory on (almost) every clock cycle either to fetch an instruction or to transfer data. Simply tightening up on the few cycles where the memory is not used will yield only a small performance gain. To get a significantly better CPI the memory system must deliver more than one value in each clock cycle either by delivering more than 32 bits per cycle from a single memory or by having separate memories for instruction and data accesses.

12 As a result of the issues, higher performance ARM cores employ a 5-stage pipeline and have separate instruction and data memories. Breaking instruction execution down into five components rather than three reduces the maximum work which must be completed in a clock cycle, and hence allows a higher clock frequency to be used. The separate instruction and data memories allow a significant reduction in the core's CPI.

13 5-Stage Pipeline Organization (1/2)
Fetch The instruction is fetched from memory and placed in the instruction pipeline Decode The instruction is decoded and register operands read from the register files. There are 3 operand read ports in the register file so most ARM instructions can source all their operands in one cycle Execute An operand is shifted and the ALU result generated. If the instruction is a load or store, the memory address is computed in the ALU

14 5-Stage Pipeline Organization (2/2)
Buffer/Data Data memory is accessed if required. Otherwise the ALU result is simply buffered for one cycle Write back The result generated by the instruction are written back to the register file, including any data loaded from memory

15 Pipeline Hazards There are situations, called hazards, that prevent the next instruction in the instruction stream from being executing during its designated clock cycle. Hazards reduce the performance from the ideal speedup gained by pipelining.

16 Pipeline Hazards There are three classes of hazards:
Structural Hazards: They arise from resource conflicts when the hardware cannot support all possible combinations of instructions in simultaneous overlapped execution. Data Hazards: They arise when an instruction depends on the result of a previous instruction in a way that is exposed by the overlapping of instructions in the pipeline. Control Hazards: They arise from the pipelining of branches and other instructions that change the PC

17 Structural Hazards When a machine is pipelined, the overlapped execution of instructions requires pipelining of functional units and duplication of resources to allow all possible combinations of instructions in the pipeline. If some combination of instructions cannot be accommodated because of a resource conflict, the machine is said to have a structural hazard.

18 Example A machine has shared a single-memory pipeline for data and instructions. As a result, when an instruction contains a data-memory reference (load), it will conflict with the instruction reference for a later instruction (instr 3): Clock cycle number instr 1 2 3 4 5 6 7 8 load IF ID EX MEM WB Instr 1 Instr 2 Instr 3

19 Solution (1/2) To resolve this, we stall the pipeline for one clock cycle when a data-memory access occurs. The effect of the stall is actually to occupy the resources for that instruction slot. The following table shows how the stalls are actually implemented. Clock cycle number instr 1 2 3 4 5 6 7 8 9 load IF ID EX MEM WB Instr 1 Instr 2 Instr 3 stall

20 Solution (2/2) Another solution is to use separate instruction and data memories. ARM used Harvard architecture, so we do not have this hazard

21 Data Hazards Data hazards occur when the pipeline changes the order of read/write accesses to operands so that the order differs from the order seen by sequentially executing instructions on the unpipelined machine. Clock cycle number 1 2 3 4 5 6 7 8 9 ADD R1,R2,R3 IF ID EX MEM WB SUB R4,R5,R1 IDsub AND R6,R1,R7 IDand OR R8,R1,R9 IDor XOR R10,R1,R11 IDxor

22 Forwarding The problem with data hazards, introduced by this sequence of instructions can be solved with a simple hardware technique called forwarding. Clock cycle number 1 2 3 4 5 6 7 ADD R1,R2,R3 IF ID EX MEM WB SUB R4,R5,R1 IDsub AND R6,R1,R7 IDand

23 Forwarding Forwarding involves feeding output data into a previous stage of the pipeline. Forwarding is implemented by feeding back the output of an instruction into the previous stage(s) of the pipeline as soon as the output of that instruction is available. Clock cycle number 1 2 3 4 5 6 7 ADD R1,R2,R3 IF ID EX MEM WB SUB R4,R5,R1 IDsub AND R6,R1,R7 IDand The first forwarding is for value of R1 from EXadd to EXsub. The second forwarding is also for value of R1 from MEMadd to EXand. This code now can be executed without stalls. Forwarding can be generalized to include passing the result directly to the functional unit that requires it A result is forwarded from the output of one unit to the input of another, rather than just from the result of a unit to the input of the same unit.

24 Forwarding Architecture
Forwarding works as follows: The ALU result from the EX/MEM register is always fed back to the ALU input latches. If the forwarding hardware detects that the previous ALU operation has written the register corresponding to the source for the current ALU operation, control logic selects the forwarded result as the ALU input rather than the value read from the register file. forwarding paths

25 Forward Data Clock cycle number 1 2 3 4 5 6 7 ADD R1,R2,R3 IF ID EXadd MEMadd WB SUB R4,R5,R1 EXsub MEM AND R6,R1,R7 EXand The first forwarding is for value of R1 from EXadd to EXsub. The second forwarding is also for value of R1 from MEMadd to EXand. This code now can be executed without stalls. Forwarding can be generalized to include passing the result directly to the functional unit that requires it A result is forwarded from the output of one unit to the input of another, rather than just from the result of a unit to the input of the same unit.

26 Without Forward Clock cycle number 1 2 3 4 5 6 7 8 9 ADD R1,R2,R3 IF
ID EX MEM WB SUB R4,R5,R1 stall IDsub AND R6,R1,R7 IDand

27 Data Forwarding Data dependency arises when an instruction needs to use the result of one of its predecessors before the result has returned to the register file => pipeline hazards Forwarding paths allow results to be passed between stages as soon as they are available 5-stage pipeline requires each of the three source operands to be forwarded from any of the intermediate result registers Still one load stall LDR rN, […] ADD r2,r1,rN ;use rN immediately One stall Compiler rescheduling

28 Stalls are required 1 2 3 4 5 6 7 8 LDR IF ID EX MEM WB SUB R4,R1,R5 EXsub AND R6,R1,R7 EXand OR R8,R1,R9 EXE The load instruction has a delay or latency that cannot be eliminated by forwarding alone.

29 The Pipeline with one Stall
1 2 3 4 5 6 7 8 9 LDR IF ID EX MEM WB SUB R4,R1,R5 stall EXsub AND R6,R1,R7 OR R8,R1,R9 The only necessary forwarding is done for R1 from MEM  to EXsub.

30 Control hazards Control hazards can cause a greater performance loss for ARM pipeline than data hazards. When a branch is executed, it may or may not change the PC (program counter) to something other than its current value plus 4. The simplest method of dealing with branches is to stall the pipeline as soon as the branch is detected until we reach the EX stage Branch IF ID EXE MEM WB Branch successor IF (stall) Stall Branch successor+1

31 Data Processing Instructions
A data processing instruction requires two operands, one of which is always a register and the other is either a second register or an immediate value. The second operand is passed through the barrel shifter where it is subject to a general shift operation, then it is combined with the first operand in the ALU using a general ALU operation. Finally, the result from the ALU is written back into the destination register. All these operations take place in a single clock cycle as shown in Figure on. The PC value in the address register is incremented and copied back into both the address register and r15 in the register bank, and the next instruction but one is loaded into the bottom of the instruction pipeline (i. pipe). The immediate value, when required, is extracted from the current instruction at the top of the instruction pipeline. For data processing instructions only the bottom eight bits (bits [7:0]) of the instruction are used in the immediate value.

32 Data Processing Instructions
A data processing instruction requires two operands, one of which is always a register and the other is either a second register or an immediate value. The second operand is passed through the barrel shifter where it is subject to a general shift operation, then it is combined with the first operand in the ALU using a general ALU operation. Finally, the result from the ALU is written back into the destination register. All these operations take place in a single clock cycle as shown in Figure on.

33 Data Processing Instructions
The PC value in the address register is incremented and copied back into both the address register and r15 in the register bank, and the next instruction but one is loaded into the bottom of the instruction pipeline (i. pipe). The immediate value, when required, is extracted from the current instruction at the top of the instruction pipeline. For data processing instructions only the bottom eight bits (bits [7:0]) of the instruction are used in the immediate value.

34 Data Transfer Instructions
STR (store register) datapath activity A data transfer (load or store) instruction computes a memory address in a manner very similar to the way a data processing instruction computes its result. A register is used as the base address, to which is added (or from which is subtracted) an offset which again may be another register or an immediate value. The address is sent to the address register, and in a second cycle the data transfer takes place. Rather than leave the datapath largely idle during the data transfer cycle, the ALU holds the address components from the first cycle and is available to compute an auto-indexing modification to the base register if this is required

35 STR (store register) datapath activity
A data transfer (load or store) instruction computes a memory address in a manner very similar to the way a data processing instruction computes its result. A register is used as the base address, to which is added (or from which is subtracted) an offset which again may be another register or an immediate value. The address is sent to the address register, and in a second cycle the data transfer takes place. Rather than leave the datapath largely idle during the data transfer cycle, the ALU holds the address components from the first cycle and is available to compute an auto-indexing modification to the base register if this is required

36 The first two (of three) cycles of a branch instruction
Branch Instructions The first two (of three) cycles of a branch instruction Branch instructions compute the target address in the first cycle as shown in Figure. A 24-bit immediate field is extracted from the instruction and then shifted left two bit positions to give a word-aligned offset which is added to the PC. The result is issued as an instruction fetch address, and while the instruction pipeline refills the return address is copied into the link register (r14) if this is required (that is, if the instruction is a 'branch with link'). The third cycle, which is required to complete the pipeline refilling, is also used to make a small correction to the value stored in the link register in order that it points directly at the instruction which follows the branch. This is necessary because r15 contains pc + 8 whereas the address of the next instruction is pc + 4.

37 Branch Instructions Branch instructions compute the target address in the first cycle as shown in Figure. A 24-bit immediate field is extracted from the instruction and then shifted left two bit positions to give a word-aligned offset which is added to the PC. The result is issued as an instruction fetch address, and while the instruction pipeline refills the return address is copied into the link register (r14) if this is required (that is, if the instruction is a 'branch with link'). The third cycle, which is required to complete the pipeline refilling, is also used to make a small correction to the value stored in the link register in order that it points directly at the instruction which follows the branch. This is necessary because r15 contains pc + 8 whereas the address of the next instruction is pc + 4.

38

39 THANK YOU


Download ppt "ARM Organization and Implementation"

Similar presentations


Ads by Google