ARM Pipeline Technology __arm system architecture

Source: Internet
Author: User

ARM Pipeline Technology:

Often in the arm assembly line, a lot of students are very dizzy, and then investigated a bit, most of the students are different familiar with the instructions caused. In order to let everyone better assembly line, here first a simple introduction arm part of the instruction set.

Part of ARM instruction

Before learning arm instruction, know a common sense, is our instruction but directly to arm nuclear execution, each instruction should contain two parts: (1) The execution of the instruction (2) The operation of the data.

Thinking, where do we store the data at this time?

To answer this question, you must know arm nuclear Power direct operation of the storage unit is who ah, oh, is a register. Yes, we put our data in the register, and then arm directly from the register to read data, according to the corresponding instructions, to make the corresponding processing. Of course, ARM can also read the data in memory, this time need to use the LDR instruction.

1. Loading data to Registers

(1) load an immediate count to register

mov register, #立即数

What is the immediate number? Do not study this problem, study this problem does not make sense, if you write not the data is not a legitimate immediate number, the compiler will report an error. However, what can be told is that the data that can be identified with one byte can be considered legitimate immediately.

Another place to note is to add "#" before the immediate number to indicate that the following data is an immediate number.

For example: to R0, the register is assigned a value of 10

Movr0, #10

(2) loading arbitrary data into registers with LDR

LDR Registers, = Data

Just remember to write that, and we'll explain why later.

For example: Load 0x12345678 into the R1 register

LDR r1,=0x12345678

 

(3) write the value of the register to memory

STR registers, [address]

Note that the "[]" here must not be lost.

For example, the value of the register R1 is written to 0x30008000 this address

MOVR1, #100

LDR r2,=0x30008000

STR R,[R2]

(4) loading data from memory into registers

LDR registers, [address]

Note that the "[]" here must not be lost.

For example: Read data from 0x30008000 to R1 registers

ldrr0,=0x30008000

LDRR1,[R0]

2. Add and subtract operation instruction

(1) Addition instruction

Add register, operand 1, operand 2

The registers here are used to store, operand 1, operand 2 The result of addition, where operand 1 must be register, operation 2 can be register also can be immediate number

For example:

Addr2,r0,r1

Equivalent to r2 = r0 + r1

Addr2,r0, #3

Equivalent to r2 = R0 + 3

 

(2) Subtraction instruction

Sub Register, operand 1, operand 2

The registers here are used to store, operand 1 minus the result of operand 2, where operand 1 must be register, operation 2 can be a register or can be an immediate number

For example:

Subr2,r0,r1

Equivalent to r2 = R0-R1

Subr2,r0, #3

Equivalent to r2 = r0-3

3. With, or operator

(1) and Operation

and registers, Operation 1, operand 2

The registers here are used to store, operand 1 and the result of the operand 2, where operand 1 must be a register, operation 2 can be a register or can be an immediate number

For example: Writes the value of the R0 register to the result of the 0x23 on R0

Andr0,r0, #0x23

 

(2) or Operation

Orr Register, Operation 1, Operation number 2

The registers here are used to store, operand 1 or 2 of the result of operand, where operands 1 must be registers, operation 2 can be registers or can be immediate number

For example: Writes the value of the R0 register or the result of the 0x23 to R0

Orrr0,r0, #0x23

4. Jump Instruction

(1) b instruction

The b instruction jumps to the specified address execution program.

For example: Jump to address 0x30008000 address to execute

b 0x30008000

Sometimes, in the assembler, we can set a label that can be skipped directly to the corresponding label by the b instruction.

B Next

....

....

Next

....

Stop

b Stop

 

(2) BL Directive

The BL instruction copies the address of the next instruction to the R14 (LR) Link register before jumping to the specified address execution program.

Here you can think about, the BL directive than the B directive has what advantages?

5. Conditional implementation

all ARM commands can be conditionally executed, and the thumb instruction has only B (jump) instructions that have conditional execution capabilities. If the directive does not indicate a conditional code, it defaults to unconditional (AL) execution.

 

Common conditions:

EQ equal

NE Not Equal

....

There are a lot of oh, just say two first

For example:

Start



Subr0,r0, #1

CMP R0, #3

BEQ Next

BNE Start

 

6. Multi-register load instruction LDM

Multi-register loading enables the transfer of data between a set of registers and a contiguous unit of memory. LDM is loaded with multiple registers;

ldm{cond}< mode > rn{!},reglist{^}

Cond: The condition of the instruction execution;

Mode: Control address growth mode, a total of 8 models;

!: Indicates that the final address is written back into the RN after the operation is completed;

Reglist: Represents a list of registers, can contain multiple registers, they use "," separated, such as {R1,R2,R6-R9}, registers from small to large arrangement;

^: When the suffix is added, data is transferred and the Register list does not contain a PC, the loaded/stored registers are in user mode, not the current mode registers. If used with a PC in the LDM directive and register list, the SPSR is also copied to the CPSR in addition to normal multiple register transfers, which can be used for exception handling returns. Note: This suffix is not allowed to be used in user mode or system mode.

For example:

Ldmia r13!, {R0-R3}

the function of the LDM directive is to load the contents of the corresponding address space into the register, and IA (increase after) means that the address is automatically added 4 after loading

! refers to the addition of an address to write to the R13 register

 

For example: The value of R13 is 0x30000,

After the instruction is executed, the value of the R0 value of 12,R1 is 13,R2, the value of 14,R3 is 15,r13

All right, so much, the purpose of learning these instructions is to enable us to read the foreshadowing of the assembly line, we will spend time alone to explain the instruction set.

Second, arm of the assembly line

The process of executing an instruction

In simple terms, the execution of an instruction must be done at least by means of an indication, decoding, and execution of three steps. It's like the blind are eating, the first step is to use chopsticks to clip out what to eat (take out instructions from memory), the second step is to put the food under the nose to see if you can eat (analyze the instructions), the third step is put into the mouth to eat (carry out instructions).

We assume that blind people have only one hand, and every step takes a second, so the blind man needs at least three seconds to eat one thing, and apparently the method of eating is inefficient. So, if the CPU takes the same approach and executes an instruction like the one above, it means that the CPU consumes 3 instruction cycles to complete an action, which can be seen as inefficient.

In order to make up for this problem, arm adopts a kind of multistage pipelining instruction execution way. For example, a three-level pipelined approach is used in ARM7, as shown in the following illustration:



As shown above, the CPU adopts pipelining, in most cases, it uses three clock cycles to execute three instructions, which greatly improves the efficiency of code operation.

It is as if a helpful scientist, after knowing the story of the Blind Man's meal, made two robots for the Blind man, now that the blind man has three hands, how will he eat? When his first hand put the food into his mouth to eat (instructions), the second hand has put the other foods under the nose to smell ( Analysis instruction), and the third hand is now holding the third thing from the plate. Since then, the efficiency of the blind to eat increased by three times times.

Understand, this is the benefit of the assembly line. Below, to see some of the typical assembly line.

1.ARM7 's three-pole assembly line

To increase the speed of the processor instruction flow, the ARM7 series uses a Level 3 assembly line.

Allows multiple operations to be processed at the same time, rather than sequential execution.

 

The pc points to an instruction that is being taken, not an executing instruction

(1) Best Pipeline Example:

This example executes 6 instructions with 6 clock cycles

All operations are in registers (single cycle execution)

Number of instruction cycles (CPI) = 1

Oh, Cpi=1 is the most ideal assembly line, but in many cases, it is difficult to achieve such an effect. For example, when multiple cycle instructions, jump branching instructions, and interrupts occur, the pipeline blocks, and the adjacent directives may be blocked due to the register conflict, reducing the efficiency of the pipeline.

(2) assembly line with memory access instruction



In this case, 4 instructions were executed with a 6-week period.

Number of instruction cycles (CPI) = 1.5

As you can see from the diagram above, the LDR instruction loads data from memory into registers. So the whole process can be divided into Access memory, and then write registers. Note that both the access memory and the write registers are in the execution unit at this time and still occupy the execution unit. The following instruction cannot use the execution unit, at which point the assembly line is blocked.

(3) assembly line containing branch instructions

The assembly line is blocked.

Note: The kernel runs in arm state

The branch instruction computes the destination of the branch in its first cycle and completes a command prefetch at the current PC. This prefetching must be done under any circumstances, because it is too late to stop prefetching when the address of the judgment is produced.

The second cycle is completed at the target address of the branch, and the return address is stored in R14 if the link bit is set.

The third cycle completes the target address +4 of the finger, refill the line, and if the jump is linked with the modification of R14 (minus 4) in order to simply return, requires three clock cycles to perform, it is the thing to modify the LR value of LR will be less than 4.

(4) Interrupt line

Cycle 1: The kernel is informed of interruptions

IRQ will not be answered until the current instruction has been executed (MUL and ldm/stm directives will have long delays)

Decoding phase: Interrupt is decoded (interrupt has been enabled, set the corresponding flag bit ...) )。 If interrupts are enabled and serviced, normal instructions will not be decoded.

 

Cycle 2: Always enter arm state at this time.

perform interrupts (get the address of the IR vector), save CPSR to SPSR, change the CPSR mode to IRQ mode, and disallow further IRQ interrupt input.

Cycle 3: Save PC (0x800c) in R14_IRQ, fetch from IRQ exception processing vector

Period 4: Decoding the instruction in the vector table, adjusting R14IRQ to 0x8008, subtracting the R14IRQ value by 4

Cycles 4 and 5: No useful instruction is taken, due to the jump of the cycle 6

Cycle 6: Take the first instruction of the exception-handling subroutine; return from subroutine: SUBSPC,LR, #4

This restores the working mode and refers to the next instruction before the response is interrupted

If there are multiple interrupts, you need to save the return address on the stack

2.ARM9 's five-level assembly line



From the above figure can be seen, ARM9 design of the 5-level pipeline, is the three-pole pipeline in the execution unit to do the access memory and register back to write split into two units for implementation.



(1) Ldr interlock

There is only one interlock in the five-level pipeline, that is, register conflict. The read registers are in the decoding phase, and the write registers are in the writeback phase. If the purpose operand register of the current instruction (A) is the same as the source operand register of the next instruction (b), the B instruction needs to be written back before decoding. This is the register conflict in level five pipelining.

In this example, we used 7 clock cycles to execute 6 instructions, CPI = 1.2.

LDR instruction immediately after a data operation instruction, because the use of the same register, will lead to interlock .

(2) The best assembly line



In this example, we used 6 clock cycles to execute 6 instructions, CPI = 1.

LDR directive does not cause pipeline interlock

(3) LDM Mutual Lock 1

Since the ldmia at the time of execution, each time the memory data is loaded into the register, the address value +4 is automatically added, note that this is an addition operation and must occupy the E unit. You can see from the image above the 2,3,4.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.