当前位置:网站首页>Instruction rearrangement concept

Instruction rearrangement concept

2022-06-24 19:32:00 Jade label

 

Instruction reordering means that the sequence of source code is different from that of program , Or the program sequence is inconsistent with the execution sequence , Reordering objects are instructions . Instruction reordering is a performance concern for the compiler , Without affecting the program ( Single threaded program ) Reorder under the condition of correctness . Instruction reordering is not inevitable , Reordering instructions can lead to thread safety problems . Instruction reordering is also called processor out of order execution , In this case, although the execution order of the instructions may not be completely in accordance with the program order , However, due to the submission of the execution result of the instruction ( To register and memory ), It's still in procedural order , Therefore, the instruction reordering of the processor will not affect the correctness of single thread . Instruction reordering does not affect the correctness of a single threaded program , But it may lead to unexpected results in multithreaded programs .

Guess execution can result in if The effect that the body of a statement is executed before its conditional statement .

 

Reordering is divided into instruction reordering ( compiler 、 processor ) And storage subsystem reorder ( Memory reordering , For cache , Write buffer )

Storage subsystem reordering : When the processor performs two memory access operations in strict program order , Under the action of the storage subsystem, the perceived order of these two operations by other processors may still be inconsistent with the program order , That is, the execution sequence of the two operations seems to have changed , This phenomenon is storage subsystem reordering . This is just a phenomenon, not an action , It does not really adjust the order of instruction execution , But it just causes a phenomenon that the execution order of instructions seems to have been adjusted , Its reorder object is the result of memory operation . Memory reordering can also cause thread safety problems , Like that one. s0 and s1 Write to write buffer , But the order changes ,P1 Did not read p2 The thread writes to the buffer , Reading is still old , Thread safety occurs It's all a problem .

Reordering is not disorderly, but has certain rules , Statements with data dependencies are not reordered , Only statements that do not have data dependencies are reordered . Seemingly serial , Only from a single thread point of view to ensure that the running results after reordering do not affect the correctness of the program , It does not guarantee the correctness of the program in a multithreaded environment .

 

 

 

 

 

 

原网站

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