当前位置:网站首页>jvm-01. Instruction rearrangement

jvm-01. Instruction rearrangement

2022-06-23 05:56:00 CaptainCats

Command rearrangement

The execution of instructions 5 Stages

Almost all von Neumann computers CPU, The execution of an instruction can be divided into 5 Stages :
1、 Take command IF;
2、 Number of decoded and read accesses ( Read operands )ID;
3、 Execution instruction EX;
4、 Memory access ( The calculation results are loaded into memory )MEM;
5、 The result is written back to ( register )WB;
Each of these steps is handled by different hardware ,
The same steps need to wait for the hardware to idle before continuing , That is to say :
 Insert picture description here
Two consecutive instructions need to consume at least 6 A clock unit .

A=B+C, You need to perform 4 An instruction

Java The code in :A=B+C, You need to perform 4 An instruction :
Instructions 1: load B To register R1 in ;
Instructions 2: load C To register R2 in ;
Instructions 3: take R1 And R2 Add up , calculated R3;
Instructions 4: take R3 Assign a value to A.
 Insert picture description here
Instructions 1 And instructions 2 There is no dependency between , Execute in normal order ,
Instructions 3 Depending on the results of the first two instructions ,
Need to wait for instructions 1、2 Load all calculation results into memory (MEM) after , To execute (EX),
Instructions 4 Depending on instructions 3 Result , We also need to wait in a wrong place .
The red circle in the picture indicates that the hardware is idle due to waiting , Called bubbles ,
such 4 The clock unit length of an instruction is not ideal 8, It is 9.

A=B+C; D=E+F;

Take a more complicated example

A=B+C;
D=E+F;

Instructions 1: load B To register R1 in ;
Instructions 2: load C To register R2 in ;
Instructions 3: take R1 And R2 Add up , calculated R3;
Instructions 4: take R3 Assign a value to A.
Instructions 5: load E To register R4 in ;
Instructions 6: load F To register R5 in ;
Instructions 7: take R4 And R5 Add up , calculated R6;
Instructions 8: take R6 Assign a value to D.
 Insert picture description here
This requires 14 A clock unit ,
Is there any way to eliminate these bubbles , Reduce the loss caused by idle hardware ,
The way is to put the instructions 5、6 Line up to the command 2 after ,
Then give the instructions 6 Line up to the command 3 after , Eliminate all bubbles , Make the most of your computer hardware ,
 Insert picture description here
 Insert picture description here

Command rearrangement

The clock unit length ranges from 14 Reduced to 12, This is the purpose of instruction rearrangement .

Disorderly execution

However, instruction rearrangement also brings the problem of out of order execution , If the sequence is out of order, the data will be inconsistent ,
Java How to ensure orderly execution under specific circumstances :jvm-02. Order guarantees .

Impropriety , Please correct .

Reference material :

The road is round Java Memory model and instruction rearrangement
Technical tinkle The meaning of instruction rearrangement
Let nature take its course ~ Detailed explanation of computer instruction execution process

原网站

版权声明
本文为[CaptainCats]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230419071108.html