Instruction control method and device, computer device and storage medium

By generating and using loop execution parameters and recording parameters for loop reconstruction calculations, the problem of wasted storage resources when hardware loop instruction branch instruction prediction fails is solved, thus improving the processor's storage resource utilization efficiency.

CN117008974BActive Publication Date: 2026-08-25TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211292415.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-21
Publication Date
2026-08-25
Estimated Expiration
2042-10-21

AI Technical Summary

Technical Problem

In computer pipeline technology, when the prediction of a branch instruction of a hardware loop instruction fails, existing technology requires backing up the entire hardware loop state record, resulting in a waste of storage resources.

Method used

By generating loop execution parameters and recording parameters, loop restoration calculations are performed, avoiding the need to pre-backup the full record of the hardware loop state, and directly using the loop restoration parameters to re-execute the branch instructions.

Benefits of technology

It reduces the consumption of storage resources and improves the efficiency of processor storage resource utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117008974B_ABST
    Figure CN117008974B_ABST
Patent Text Reader

Abstract

The application relates to an instruction control method and device, a computer device, a storage medium and a computer program product. The method comprises the following steps: performing a loop execution according to a loop execution parameter of a hardware loop instruction and a preset pipeline structure, the loop execution parameter is updated and a corresponding loop record parameter is generated in the process of the loop execution, and the loop record parameter is used for recording the update of the loop execution parameter; when a branch instruction enters a reading instruction stage of the preset pipeline structure, a current loop record parameter is acquired; when the branch instruction prediction fails, a target loop record parameter is acquired; loop restoration calculation is performed based on the current loop record parameter and the target loop record parameter, a loop restoration parameter is obtained, the target loop execution parameter is restored based on the loop restoration parameter, the restored loop execution parameter is obtained, and the branch instruction is re-executed according to the restored loop execution parameter. The method can reduce the storage resource consumption in the instruction control.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to an instruction control method, apparatus, computer equipment, storage medium, and computer program product. Background Technology

[0002] With the development of computer technology, computer pipelining technology emerged. Computer pipelining refers to the execution method of each instruction within a computer processor. Using computer pipelining technology can improve the processor's processing speed. Currently, when processing hardware loop instructions using computer pipelining, if a branch instruction prediction failure occurs during the processing of a hardware loop instruction, the state before the prediction failure is usually retrieved from a pre-backed-up complete record of the hardware loop state. However, saving a complete record of the hardware loop state consumes a large amount of storage resources, resulting in a waste of storage resources. Summary of the Invention

[0003] Therefore, it is necessary to provide an instruction control method, apparatus, computer device, computer-readable storage medium, and computer program product that can reduce storage resource consumption in response to the above-mentioned technical problems.

[0004] Firstly, this application provides an instruction control method. The method includes:

[0005] Obtain the hardware loop instruction, which includes branch instructions, and generate loop execution parameters based on the hardware loop instruction;

[0006] The hardware loop instructions are executed in a loop according to the loop execution parameters and the preset pipeline structure. The loop execution parameters are updated during the loop execution and corresponding loop record parameters are generated. The loop record parameters are used to record the updates of the loop execution parameters.

[0007] When a branch instruction enters the read instruction stage of the preset pipeline structure, the corresponding current loop record parameter is obtained based on the current loop execution parameter corresponding to the branch instruction.

[0008] When a branch instruction prediction failure is detected during the instruction execution phase of the preset pipeline structure, the corresponding target loop record parameters are obtained based on the target loop execution parameters corresponding to the branch instruction during the instruction execution phase of the preset pipeline structure.

[0009] The loop restoration parameters are obtained by performing loop restoration calculations based on the current loop record parameters and the target loop record parameters;

[0010] The target loop execution parameters are restored based on the loop restoration parameters to obtain the restored loop execution parameters, and the branch instructions are re-executed according to the restored loop execution parameters.

[0011] Secondly, this application also provides a command control device. The device includes:

[0012] The instruction acquisition module is used to acquire hardware loop instructions, which include branch instructions, and to generate loop execution parameters based on the hardware loop instructions.

[0013] The parameter generation module is used to execute hardware loop instructions in a loop according to the loop execution parameters and the preset pipeline structure. The loop execution parameters are updated during the loop execution and corresponding loop record parameters are generated. The loop record parameters are used to record the updates of the loop execution parameters.

[0014] The current parameter acquisition module is used to acquire the corresponding current loop record parameters based on the current loop execution parameters corresponding to the branch instruction when the branch instruction enters the read instruction stage of the preset pipeline structure.

[0015] The target parameter acquisition module is used to acquire the corresponding target loop record parameters based on the target loop execution parameters corresponding to the branch instruction in the instruction execution stage of the preset pipeline structure when the branch instruction prediction failure is detected in the instruction execution stage of the preset pipeline structure.

[0016] The restoration parameter calculation module is used to perform loop restoration calculations based on the current loop record parameters and the target loop record parameters to obtain the loop restoration parameters.

[0017] The restore module is used to restore the target loop execution parameters based on the loop restore parameters, obtain the restored loop execution parameters, and re-execute the branch instructions according to the restored loop execution parameters.

[0018] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to perform the following steps:

[0019] Obtain the hardware loop instruction, which includes branch instructions, and generate loop execution parameters based on the hardware loop instruction;

[0020] The hardware loop instructions are executed in a loop according to the loop execution parameters and the preset pipeline structure. The loop execution parameters are updated during the loop execution and corresponding loop record parameters are generated. The loop record parameters are used to record the updates of the loop execution parameters.

[0021] When a branch instruction enters the read instruction stage of the preset pipeline structure, the corresponding current loop record parameter is obtained based on the current loop execution parameter corresponding to the branch instruction.

[0022] When a branch instruction prediction failure is detected during the instruction execution phase of the preset pipeline structure, the corresponding target loop record parameters are obtained based on the target loop execution parameters corresponding to the branch instruction during the instruction execution phase of the preset pipeline structure.

[0023] The loop restoration parameters are obtained by performing loop restoration calculations based on the current loop record parameters and the target loop record parameters;

[0024] The target loop execution parameters are restored based on the loop restoration parameters to obtain the restored loop execution parameters, and the branch instructions are re-executed according to the restored loop execution parameters.

[0025] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, performs the following steps:

[0026] Obtain the hardware loop instruction, which includes branch instructions, and generate loop execution parameters based on the hardware loop instruction;

[0027] The hardware loop instructions are executed in a loop according to the loop execution parameters and the preset pipeline structure. The loop execution parameters are updated during the loop execution and corresponding loop record parameters are generated. The loop record parameters are used to record the updates of the loop execution parameters.

[0028] When a branch instruction enters the read instruction stage of the preset pipeline structure, the corresponding current loop record parameter is obtained based on the current loop execution parameter corresponding to the branch instruction.

[0029] When a branch instruction prediction failure is detected during the instruction execution phase of the preset pipeline structure, the corresponding target loop record parameters are obtained based on the target loop execution parameters corresponding to the branch instruction during the instruction execution phase of the preset pipeline structure.

[0030] The loop restoration parameters are obtained by performing loop restoration calculations based on the current loop record parameters and the target loop record parameters;

[0031] The target loop execution parameters are restored based on the loop restoration parameters to obtain the restored loop execution parameters, and the branch instructions are re-executed according to the restored loop execution parameters.

[0032] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, performs the following steps:

[0033] Obtain the hardware loop instruction, which includes branch instructions, and generate loop execution parameters based on the hardware loop instruction;

[0034] The hardware loop instructions are executed in a loop according to the loop execution parameters and the preset pipeline structure. The loop execution parameters are updated during the loop execution and corresponding loop record parameters are generated. The loop record parameters are used to record the updates of the loop execution parameters.

[0035] When a branch instruction enters the read instruction stage of the preset pipeline structure, the corresponding current loop record parameter is obtained based on the current loop execution parameter corresponding to the branch instruction.

[0036] When a branch instruction prediction failure is detected during the instruction execution phase of the preset pipeline structure, the corresponding target loop record parameters are obtained based on the target loop execution parameters corresponding to the branch instruction during the instruction execution phase of the preset pipeline structure.

[0037] The loop restoration parameters are obtained by performing loop restoration calculations based on the current loop record parameters and the target loop record parameters;

[0038] The target loop execution parameters are restored based on the loop restoration parameters to obtain the restored loop execution parameters, and the branch instructions are re-executed according to the restored loop execution parameters.

[0039] The aforementioned instruction control method, apparatus, computer equipment, storage medium, and computer program product acquire hardware loop instructions, including branch instructions, and generate loop execution parameters based on these instructions. The hardware loop instructions are then executed loop-wise according to the loop execution parameters and a preset pipeline structure. During loop execution, the loop execution parameters are updated, generating corresponding loop record parameters that record these updates. When a branch instruction enters the read instruction stage of the preset pipeline structure, the corresponding current loop record parameters are acquired based on the current loop execution parameters of the branch instruction. When a branch instruction prediction failure is detected during the instruction execution stage of the preset pipeline structure, the corresponding target loop record parameters are acquired based on the target loop execution parameters of the branch instruction during that stage. Loop restoration calculations are performed based on the current and target loop record parameters to obtain loop restoration parameters. The target loop execution parameters are then restored based on the loop restoration parameters to obtain restored loop execution parameters, and the branch instruction is re-executed according to these restored parameters. By generating loop record parameters, then using the current loop record parameters and the target loop record parameters to perform loop restoration calculations, loop restoration parameters are obtained. Finally, restoration is performed using the loop restoration parameters, thus avoiding the need to pre-back up the entire hardware loop state record, thereby greatly reducing the consumption of storage resources. Attached Figure Description

[0040] Figure 1 This is a diagram illustrating the application environment of the instruction control method in one embodiment;

[0041] Figure 2 This is a flowchart illustrating the instruction control method in one embodiment;

[0042] Figure 3 This is a schematic diagram of the hardware loop instruction execution process in one embodiment;

[0043] Figure 4 This is a schematic diagram of a processor pipeline in a specific embodiment;

[0044] Figure 5 This is a schematic diagram illustrating the cyclical execution of parameter updates in a specific embodiment;

[0045] Figure 6 This is a flowchart illustrating the process of obtaining the target loop recording parameters in one embodiment;

[0046] Figure 7 This is a schematic diagram of the process for obtaining the cyclic restoration parameters in one embodiment;

[0047] Figure 8 This is a schematic diagram illustrating the various loop recording parameters obtained in one embodiment;

[0048] Figure 9 This is a schematic diagram of the process for obtaining the cyclic restoration parameters in another embodiment;

[0049] Figure 10 This is a schematic diagram illustrating the calculation of the cyclic restoration parameters in a specific embodiment;

[0050] Figure 11 for Figure 10 A schematic diagram of the cyclic restoration parameters obtained in a specific embodiment;

[0051] Figure 12 This is a schematic diagram illustrating recovery when branch instruction prediction fails in a specific embodiment;

[0052] Figure 13 This is a flowchart illustrating the process of obtaining the cyclic recording parameters in one embodiment;

[0053] Figure 14 This is a schematic diagram of a loop jump unit in a specific embodiment;

[0054] Figure 15 This is a flowchart illustrating the instruction control method in a specific embodiment;

[0055] Figure 16 This is a schematic diagram of the hardware architecture for instruction control in a specific embodiment;

[0056] Figure 17 for Figure 16 A schematic diagram of the update unit in a specific embodiment;

[0057] Figure 18 This is a structural block diagram of the instruction control device in one embodiment;

[0058] Figure 19 This is an internal structural diagram of a computer device in one embodiment;

[0059] Figure 20 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0060] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0061] Artificial intelligence (AI) is the theory, methods, technology, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that attempts to understand the essence of intelligence and produce a new kind of intelligent machine that can react in a way similar to human intelligence. AI studies the design principles and implementation methods of various intelligent machines, enabling them to possess the functions of perception, reasoning, and decision-making.

[0062] Artificial intelligence (AI) is a comprehensive discipline encompassing a wide range of fields, including both hardware and software technologies. Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies primarily include computer vision, speech processing, natural language processing, and machine learning / deep learning.

[0063] Machine Learning (ML) is a multidisciplinary field involving probability theory, statistics, approximation theory, convex analysis, and algorithm complexity theory. It specifically studies how computers can simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to endow computers with intelligence; its applications span all areas of artificial intelligence. Machine learning and deep learning typically include techniques such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and instructional learning.

[0064] The solutions provided in this application relate to technologies such as machine learning in artificial intelligence. Specifically, the hardware loop instructions in this application can be instructions used by machine learning models during training and application. This is illustrated in the following embodiments:

[0065] The instruction control method provided in this application embodiment can be applied to, for example, Figure 1 In the application environment shown, terminal 102 communicates with server 104 via a network. A data storage system can store the data that server 104 needs to process. The data storage system can be integrated onto server 104, or it can be located in the cloud or on another server. Server 104 can obtain the hardware loop instructions to be executed from terminal 102. These hardware loop instructions include branch instructions, and server 104 generates loop execution parameters based on these instructions. The server 104 executes the hardware loop instructions according to the loop execution parameters and a preset pipeline structure. During loop execution, the loop execution parameters are updated, and corresponding loop record parameters are generated to record these updates. When a branch instruction enters the read instruction stage of the preset pipeline structure, server 104 obtains the corresponding current loop record parameters based on the current loop execution parameters of the branch instruction. When a branch instruction prediction failure is detected during the instruction execution stage of the preset pipeline structure, server 104 obtains the corresponding target loop record parameters based on the target loop execution parameters of the branch instruction at that stage. Server 104 performs loop reconstruction calculations based on the current loop record parameters and the target loop record parameters to obtain the loop reconstruction parameters. Server 104 then reconstructs the target loop execution parameters based on the loop reconstruction parameters to obtain the reconstructed loop execution parameters, and re-executes the branch instruction according to the reconstructed loop execution parameters. Finally, when the server obtains the execution result, it returns the result to the terminal for display or other processing. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart in-vehicle devices, etc. Portable wearable devices can include smartwatches, smart bracelets, head-mounted devices, etc. Server 200 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.

[0066] In one embodiment, such as Figure 2 As shown, a command control method is provided, which can be applied to... Figure 1Taking a server as an example, this method can also be applied to a terminal, or to a system including both a terminal and a server, and is implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps:

[0067] Step 202: Obtain the hardware loop instruction, which includes branch instructions, and generate loop execution parameters based on the hardware loop instruction.

[0068] Hardware loop instructions refer to assembly instructions obtained by compiling programs written in high-level programming languages. These instructions are loop instructions, which can loop based on a number of iterations or a condition. Examples include loops like `for`, `if`, and `while`. Hardware loop instructions can have a loop body containing multiple instructions, including branch instructions that allow jumping to other instructions. These instructions can be applied to various scenarios requiring looping. Branch instructions modify the execution flow. When a branch instruction is true, the original instruction is changed; when it is false, no jump is needed. Branch instructions can be compiled from conditional languages. Loop execution parameters are necessary for the hardware loop instruction to execute, including but not limited to loop count, loop start, and loop end parameters. The loop count parameter indicates the number of iterations the hardware loop instruction needs to perform; the hardware loop instruction has a defined total number of iterations. The loop start parameter is used to characterize the parameters when the current loop starts executing, and the loop end parameter is used to characterize the parameters when the current loop ends executing.

[0069] Specifically, the server can obtain hardware loop instructions directly from the database or from the terminal. Alternatively, the server can obtain hardware loop instructions from the service provider offering the business service. The obtained hardware loop instructions include branch instructions, which can be single or multiple, with at least two possible branches. The server then determines the loop count, loop start parameter, and loop end parameter based on the loop condition in the hardware loop instructions, thereby obtaining the loop execution parameters.

[0070] Step 204: The hardware loop instruction is executed in a loop according to the loop execution parameters and the preset pipeline structure. The loop execution parameters are updated during the loop execution and corresponding loop record parameters are generated. The loop record parameters are used to record the updates of the loop execution parameters.

[0071] The pre-defined pipeline structure refers to the pre-configured pipeline structure for executing hardware loop instructions. The pipeline structure can contain multiple stages, which can sequentially include the fetch stage, decode stage, execution stage, and commit stage. The fetch stage retrieves the instruction from the cache based on the instruction pointer (PC). The decode stage decodes the fetched instruction into a machine-readable instruction format. The execution stage executes the decoded instruction, and the commit stage submits the execution result. Loop record parameters are used to record updates to loop execution parameters. These loop record parameters can be stored as a bitmap, a data structure that uses a bit array to store specific data.

[0072] Specifically, the server executes hardware loop instructions cyclically according to loop execution parameters and a preset pipeline structure. In the preset pipeline structure, each instruction within the loop body of the hardware loop instruction can be executed sequentially at its respective stage, and each stage can immediately execute the next instruction after executing the previous one, without needing to wait for the next instruction to finish before executing the next one. This achieves pipelined execution of the hardware loop instruction. Each loop in the hardware loop instruction is executed according to the loop execution parameters, and upon completion of each loop, the loop execution parameters are updated. The updated loop execution parameters are then used to execute the next loop in the hardware loop instruction until the loop ends. Simultaneously, upon obtaining the updated loop execution parameters, corresponding loop record parameters are generated based on the degree of change in the loop execution parameters during the update. Each loop in the hardware loop instruction generates and saves corresponding loop record parameters upon completion; for example, the loop record parameters can be saved in a register in the form of a queue.

[0073] Step 206: When a branch instruction enters the read instruction stage of the preset pipeline structure, the corresponding current loop record parameter is obtained based on the current loop execution parameter corresponding to the branch instruction.

[0074] The instruction fetching stage of the pre-defined pipeline structure refers to the instruction fetching stage, which is the stage where the instruction is retrieved from the cache based on the instruction pointer (PC). The current loop execution parameters refer to the execution parameters corresponding to the currently executing loop when a branch instruction enters the instruction fetching stage; this currently executing loop includes the branch instruction. The current loop record parameters refer to the loop record parameters generated when the loop execution parameters are updated to the current loop execution parameters.

[0075] Specifically, the server detects whether a branch instruction in a hardware loop instruction has entered the fetch instruction stage of a preset pipeline structure. When other instructions in the hardware loop instruction enter the fetch instruction stage of the preset pipeline structure, they are executed normally. When a branch instruction in a hardware loop instruction is detected to have entered the fetch instruction stage of the preset pipeline structure, the server directly retrieves the corresponding current loop record parameters from the register based on the current loop execution parameters corresponding to the branch instruction, and then continues normal execution. That is, branch instruction prediction is performed, the branch instruction is retrieved, and then the subsequent stages are executed. In one embodiment, branch instruction prediction can be performed first, and then the corresponding current loop record parameters can be retrieved from the register based on the current loop execution parameters corresponding to the branch instruction. Finally, the branch instruction is retrieved, and the subsequent stages are executed. Here, branch instruction prediction is used to predict the execution result of the branch instruction, which may include the jump direction and the jump target address of the branch instruction.

[0076] Step 208: When a branch instruction prediction failure is detected during the instruction execution phase of the preset pipeline structure, the corresponding target loop record parameters are obtained based on the target loop execution parameters corresponding to the branch instruction during the instruction execution phase of the preset pipeline structure.

[0077] The instruction execution phase, or execution phase, refers to the stage of executing the decoded instructions. Branch instruction prediction failure occurs when the predicted branch execution result does not match the final execution result determined after the branch instruction is executed. The target loop execution parameters refer to the loop execution parameters corresponding to the loop being executed during the instruction fetch phase of the pipeline during the branch instruction execution phase. The target loop record parameters refer to the loop record parameters generated when the loop execution parameters are updated to the target loop execution parameters.

[0078] Specifically, the server executes branch instructions during the instruction execution phase of the preset pipeline structure, obtains the determined execution result of the branch instruction, and then compares the determined execution result with the predicted execution result. When the results match, the hardware loop instruction is executed normally. When the results do not match, a branch instruction prediction failure is detected. At this point, the pipeline needs to be flushed, and the loop state of the hardware loop instruction needs to be restored to the loop state when the branch instruction first entered the pipeline structure. That is, the server needs to use the target loop execution parameters corresponding to the branch instruction in the instruction execution phase of the preset pipeline structure to obtain the corresponding target loop record parameters from the register.

[0079] Step 210: Perform loop restoration calculation based on the current loop record parameters and the target loop record parameters to obtain the loop restoration parameters.

[0080] Among them, the loop restore parameter is used to restore the parameters of the loop state, so that the loop is restored to the state when the branch instruction just entered the pipeline structure.

[0081] Specifically, the server retrieves all loop record parameters saved from the time period from recording the current loop record parameters to recording the target loop record parameters, based on the current loop record parameters and the target loop record parameters. Then, it calculates the degree of change in the loop execution parameters based on all loop record parameters within that time period, obtaining the change amount corresponding to the loop execution parameters during that time period. This change amount is used as the loop restoration parameter. This time period refers to the period from the start of branch instruction prediction to the detection of branch instruction prediction failure.

[0082] Step 212: Restore the target loop execution parameters based on the loop restoration parameters to obtain the restored loop execution parameters, and re-execute the branch instructions according to the restored loop execution parameters.

[0083] The restored loop execution parameters refer to the loop execution parameters when the branch instruction just enters the pipeline structure.

[0084] Specifically, the server uses the loop restoration parameters and the target loop execution parameters to restore the loop execution parameters. That is, it uses the changes in the target loop execution parameters and the corresponding loop execution parameters to restore the loop execution parameters. Then, according to the restored loop execution parameters, the branch instructions are re-executed through a preset pipeline structure, and the loop execution continues until the loop execution is completed, thus obtaining the execution result of the hardware loop execution.

[0085] The aforementioned instruction control method, apparatus, computer equipment, storage medium, and computer program product acquire hardware loop instructions, including branch instructions, and generate loop execution parameters based on these instructions. The hardware loop instructions are then executed loop-wise according to the loop execution parameters and a preset pipeline structure. During loop execution, the loop execution parameters are updated, generating corresponding loop record parameters that record these updates. When a branch instruction enters the read instruction stage of the preset pipeline structure, the corresponding current loop record parameters are acquired based on the current loop execution parameters of the branch instruction. When a branch instruction prediction failure is detected during the instruction execution stage of the preset pipeline structure, the corresponding target loop record parameters are acquired based on the target loop execution parameters of the branch instruction during that stage. Loop restoration calculations are performed based on the current and target loop record parameters to obtain loop restoration parameters. The target loop execution parameters are then restored based on the loop restoration parameters to obtain restored loop execution parameters, and the branch instruction is re-executed according to these restored parameters. By generating loop record parameters, then using the current loop record parameters and the target loop record parameters to perform loop restoration calculations, loop restoration parameters are obtained. Finally, restoration is performed using the loop restoration parameters, thus avoiding the need to pre-back up the entire hardware loop state record, thereby greatly reducing the consumption of storage resources.

[0086] In one embodiment, such as Figure 3 As shown, in step 204, the hardware loop instructions are executed cyclically according to the loop execution parameters and the preset pipeline structure. The loop execution parameters are updated and corresponding loop record parameters are generated during the loop execution process, including:

[0087] Step 302: Determine the current instruction in the current loop from the hardware loop instructions according to the loop execution parameters.

[0088] The current loop refers to the loop body of a hardware loop instruction that is currently being executed. The current instruction refers to the instruction that needs to be executed in the current loop.

[0089] Specifically, the server retrieves the start and end information of the current loop from the hardware loop instruction according to the loop execution parameters, and then obtains the current instruction in the current loop based on the loop start information. Branch instructions can be the current instruction in any iteration of the hardware loop instruction. Finally, the server determines whether the current loop has finished executing based on the loop end information.

[0090] Step 304: Execute the current instruction according to the preset pipeline structure, and when the current instruction passes through the instruction read stage of the preset pipeline structure, determine the next instruction corresponding to the current instruction from the current loop.

[0091] The next instruction refers to the instruction executed after the current instruction in the current loop. That is, it is executed when the current instruction finishes the fetch phase and enters the next phase. This next instruction enters the value fetch phase of the preset pipeline structure for execution.

[0092] Specifically, when the server determines that there is an instruction being executed in the instruction fetch stage of the preset pipeline structure, the current instruction enters the instruction fetch stage for execution, that is, it retrieves the current instruction from the register. At this time, the server determines the next instruction corresponding to the current instruction in the current loop. If the current instruction is a branch instruction, the predicted next instruction is obtained through the prediction of the branch instruction.

[0093] Step 306: Take the next instruction as the current instruction, and return to execute the current instruction according to the preset pipeline structure. When the current instruction passes through the instruction reading stage of the preset pipeline structure, retrieve the next instruction corresponding to the current instruction from the current loop and execute it until the termination instruction in the current loop is completed. Update the loop execution parameters to obtain the updated loop execution parameters corresponding to the completion of the current loop execution, and generate the corresponding current loop record parameters based on the updated loop execution parameters.

[0094] The completion of the termination instruction in the current loop refers to the completion of the execution of the last instruction in the current loop. For example, when the server detects that the current instruction matches the instruction at the end address of the current loop, it indicates that the current loop has completed execution. Updated loop execution parameters are obtained by updating the loop execution parameters after the current loop has completed execution.

[0095] Specifically, the server treats the next instruction as the current instruction and executes it according to the pipeline structure. That is, it returns to execute the current instruction according to the preset pipeline structure. When the current instruction passes through the instruction fetching stage of the preset pipeline structure, it retrieves the next instruction corresponding to the current instruction from the current loop and executes it until the termination instruction in the current loop is completed. At this point, it indicates that the current loop has completed execution, and the loop execution parameters need to be updated before the next loop can be executed. In other words, the server updates the loop execution parameters to obtain the updated loop execution parameters corresponding to the completion of the current loop, calculates the degree of change of the execution parameters using the loop execution parameters and the updated loop execution parameters, generates the corresponding current loop record parameters based on this degree of change, and saves the current loop record parameters.

[0096] Step 308: Update the loop execution parameters as loop execution parameters, and return to the step of determining the current instruction in the current loop from the hardware loop instructions according to the loop execution parameters, until the hardware loop instructions are executed.

[0097] Among them, "hardware loop instruction execution completion" means that the hardware loop instruction has met the loop completion condition during execution, and has reached the maximum number of loops.

[0098] Specifically, the server determines whether execution is needed based on the updated loop execution parameters. Specifically, it checks if the remaining number of iterations in the updated loop execution parameters is zero. If it is not zero, it means the loop has not yet ended. In this case, the updated loop execution parameters are used as the loop execution parameters, and the server returns to execute the steps of the current instruction in the current loop determined from the hardware loop instructions according to the loop execution parameters. This continues until the hardware loop instructions have been executed completely, i.e., when the remaining number of iterations in the updated loop execution parameters is zero. At this point, the loop execution ends, the hardware loop instructions have been executed, and the corresponding execution result is obtained.

[0099] In a specific embodiment, the server can obtain the for loop statement `for(i = 0; i < 10; i++) {loop_body;}`, where `i` represents the loop count, the total number of loops is 10, and `loop_body` is the loop body, which can contain multiple instructions. After compilation by the compiler, the following assembly instructions can be obtained:

[0100] 1.LOOP START_PC,END_PC,ITERS_NUM

[0101] 2.LOOP_START_PC:

[0102] 3. ADD

[0103] 4. SUB

[0104] 5.MUL

[0105] 6. LOOP_END_PC:

[0106] The first line is a hardware loop instruction, indicating the start PC (program address), end PC, and loop count. The second line is the loop start address. The third to fifth lines are the loop body, and the sixth line is the loop end address. When this hardware loop instruction is executed in the processor's pipeline architecture, as follows... Figure 4The diagram illustrates a processor pipeline, which includes the following stages: fetch, cache, alignment, decode, execution (execute1 and execute2), and commit. Each stage executes one instruction; as one instruction completes in the current stage and moves to the next, the next instruction enters the current stage for execution, continuing this process like a flowing pipeline. A loop controller is included in the fetch stage. When the loop controller detects that the current loop is at its end address but determines that the loop has not yet ended, it jumps to the beginning address of the loop to continue execution. Furthermore, if a branch instruction is fetched, branch instruction prediction is performed. Finally, when all loop iterations are complete, the execution result of the hardware loop instruction is obtained.

[0107] In the above embodiments, the current instruction is executed according to a preset pipeline structure, and when the current instruction passes through the instruction fetching stage of the preset pipeline structure, the next instruction corresponding to the current instruction is determined from the current loop. The next instruction is used as the current instruction and executed iteratively, thereby enabling accurate execution of branch instructions and their next instructions, even when there are branch instructions in the hardware loop instruction. This improves the flexibility and richness of editing hardware loop instructions.

[0108] In one embodiment, the loop execution parameter includes the remaining number of executions for the current loop;

[0109] Step 306: Until the termination instruction in the current loop is completed, update the loop execution parameters to obtain the updated loop execution parameters corresponding to the completion of the current loop, and generate the corresponding current loop record parameters based on the updated loop execution parameters, including:

[0110] When a termination instruction is detected during the read instruction phase of the preset pipeline structure, the remaining execution count of the current loop is updated to obtain the updated remaining execution count. Based on the current remaining execution count and the updated remaining execution count, the current loop record parameters corresponding to the hardware loop instruction are generated.

[0111] The remaining number of iterations in the current loop refers to the number of iterations that still need to be executed in the current loop instruction. The termination instruction is the instruction that ends the current loop, and it can be the address of the end of the current loop.

[0112] Specifically, the server determines the read instruction stage of each instruction that passes through the preset pipeline structure. When it detects that the current instruction after the read instruction stage is a termination instruction, it indicates that the current loop execution is complete. At this point, the remaining execution count of the current loop needs to be updated, i.e., the remaining execution count of the current loop is decremented by 1 to obtain the new remaining execution count of the current loop. Then, based on the current remaining execution count and the updated remaining execution count of the current loop, the current loop record parameters corresponding to the hardware loop instruction are generated.

[0113] In a specific embodiment, such as Figure 5 The diagram illustrates the update of loop execution parameters. Specifically, at time T0, an instruction flows through the fetch stage; this instruction is the termination instruction `end_pc0` for the current loop 0. The server detects that the termination instruction of the current loop 0 has entered the fetch stage of the pipeline. At this time, the loop execution parameter corresponding to the hardware loop instruction is obtained from the loop execution parameter queue as `lp_cnt0 = 4`, meaning that the remaining execution count for the current loop 0 is 4. The remaining execution count for the current loop 0 is then updated by decrementing it by 1, resulting in an updated loop execution parameter of 3. The termination instruction then enters the second pipeline stage for execution at time T1, meaning that at time T1, the remaining execution count for the current loop 0 is 3. Each item in the loop execution parameter queue represents the loop execution parameter corresponding to a hardware loop instruction.

[0114] In the above embodiment, when the current instruction in the instruction fetch phase is detected to be a termination instruction, the remaining execution count of the current loop is updated to obtain the updated remaining execution count of the current loop. Then, based on the current remaining execution count of the current loop and the updated remaining execution count of the current loop, the current loop record parameter corresponding to the hardware loop instruction is generated, thereby ensuring the accuracy of the obtained current loop record parameter.

[0115] In one embodiment, generating the current loop record parameters corresponding to the hardware loop instruction based on the remaining execution count of the current loop and the updated remaining execution count of the current loop includes the following steps:

[0116] The number of loop changes is determined based on the remaining number of executions in the current loop and the updated remaining number of executions in the current loop; bitmap data is generated based on the number of loop changes, and the bitmap data is used as the current loop record parameter corresponding to the hardware loop instruction, and the current loop record parameter is saved.

[0117] The number of cycle changes is used to characterize the amount of change in the cycle. Bitmap data refers to binary data used to characterize the number of cycle changes.

[0118] Specifically, the server determines the number of loop changes based on the remaining number of executions in the current loop and the updated remaining number of executions in the current loop. Then, it generates bitmap data based on the number of loop changes, directly uses the bitmap data as the current loop record parameter corresponding to the hardware loop instruction, and saves the current loop record parameter.

[0119] In one embodiment, when nested hardware loop instructions exist within a hardware loop instruction, the number of nested hardware loop instructions can be obtained. The number of binary bits corresponding to the bitmap data is determined based on this total number of hardware loop instructions. This number of binary bits is the same as the total number of hardware loop instructions, and each bit in the binary data represents the bitmap data corresponding to one hardware loop instruction. Alternatively, the number of binary bits in the bitmap data can be set to a fixed value. When the total number of hardware loop instructions is less than the fixed value, the remaining binary bits are filled with a preset value. When the total number of hardware loop instructions is greater than the fixed value, the number of binary bits in the bitmap data is determined according to the total number of hardware loop instructions. Then, the bitmap data is used as the current loop record parameter corresponding to that hardware loop instruction, and the current loop record parameter is saved. For example, when the total number of hardware loop instructions is 8, the loop record parameter can be obtained using 8 bits of binary data. When the number of iterations of the nested hardware loop instruction remains unchanged and only the number of iterations of the hardware loop instruction is decremented by one, the resulting 8-bit binary data is 000000001. The last bit of the 8-bit binary number is used to represent the change in the number of iterations of the hardware loop instruction. When the number of iterations is decremented by one, the value of the last bit is 1.

[0120] In the above embodiments, by determining the number of cyclic changes, generating bitmap data based on the number of cyclic changes, and then saving the bitmap data, the storage resources consumed can be greatly reduced.

[0121] In one embodiment, step 206, obtaining the corresponding current loop record parameters based on the current loop execution parameters corresponding to the branch instruction, includes:

[0122] The loop record parameter queue is obtained by writing the generated loop record parameters sequentially during the loop execution. The loop record parameter corresponding to the tail position is obtained from the loop record parameter queue to obtain the current loop record parameter corresponding to the current loop execution parameter.

[0123] The loop record parameter queue is obtained by sequentially writing the generated loop record parameters during the loop execution. For example, when the hardware loop instruction has a total of 10 loops, the loop execution parameters will be updated 10 times. Each update of the loop execution parameters will generate corresponding loop record parameters, resulting in 10 loop record parameters, which are then stored in the form of a queue.

[0124] Specifically, the server obtains the saved loop record parameter queue, then retrieves the loop record parameter corresponding to the tail position from the loop record parameter queue, and obtains the current loop record parameter corresponding to the current loop execution parameter.

[0125] In one embodiment, a pointer can be used to indicate the tail position of the circular record parameter queue, and this pointer moves with the instruction flow in the pipeline, that is, its position changes as the number of circular record parameters increases. The pointer can then be used to retrieve the current circular record parameter at the current moment.

[0126] In the above embodiments, by obtaining the loop record parameter corresponding to the tail position from the loop record parameter queue, the efficiency of obtaining the current loop record parameter corresponding to the current loop execution parameter can be improved.

[0127] In one embodiment, such as Figure 6 As shown, step 208, that is, when a branch instruction prediction failure is detected in the instruction execution stage of the preset pipeline structure, obtains the corresponding target loop record parameters based on the target loop execution parameters corresponding to the branch instruction in the instruction execution stage of the preset pipeline structure, including:

[0128] Step 602: Determine the target execution instruction corresponding to the branch instruction during the instruction execution phase of the preset pipeline structure.

[0129] Here, the target instruction refers to the execution result of the branch instruction, which is the next instruction to be executed corresponding to that branch instruction. This next instruction is the instruction in the loop body that follows the branch instruction and is immediately adjacent to it.

[0130] Specifically, the server executes branch instructions during the instruction execution phase of the preset pipeline structure, obtains the execution result, and determines the target execution instruction corresponding to the branch instruction based on the execution result.

[0131] Step 604: Obtain the initial execution instruction predicted during the instruction reading stage of the branch instruction. If the target execution instruction does not match the initial execution instruction, it is determined that the branch instruction prediction has failed.

[0132] The initial execution instruction refers to the next instruction to be executed corresponding to the predicted branch instruction.

[0133] Specifically, the server obtains the initial execution instruction predicted during the instruction fetching phase of the branch instruction. When the target execution instruction matches the initial execution instruction, the branch instruction prediction is considered successful, and the hardware loop instruction continues to execute normally, thereby improving execution efficiency. When the target execution instruction does not match the initial execution instruction, a determination is made that the branch instruction prediction failed.

[0134] Step 606: When the branch instruction prediction fails, obtain the corresponding target loop record parameters based on the target loop execution parameters corresponding to the branch instruction in the instruction execution stage of the preset pipeline structure.

[0135] Specifically, when the server determines that branch instruction prediction has failed, it first flushes the pipeline, that is, deletes all instructions currently being executed in the pipeline. Simultaneously, based on the target loop execution parameters corresponding to the branch instruction in the preset pipeline structure's instruction execution stage, it retrieves the corresponding target loop record parameters and restores them. Finally, it completes the loop execution of the hardware loop instruction according to the loop execution parameters.

[0136] In the above embodiments, by matching the target execution instruction with the initial execution instruction, it is determined whether the branch instruction prediction fails. When the branch instruction prediction fails, the target loop record parameters are obtained, thereby ensuring the accuracy of the obtained target loop record parameters.

[0137] In one embodiment, such as Figure 7 As shown, in step 210, a loop restoration calculation is performed based on the current loop record parameters and the target loop record parameters to obtain the loop restoration parameters, including:

[0138] Step 702: Obtain the loop record parameter queue. The loop record parameter queue is obtained by writing the generated loop record parameters sequentially during the loop execution.

[0139] Step 704: Determine the current queue position of the current loop record parameter and the target queue position of the target loop record parameter from the loop record parameter queue.

[0140] Here, the current queue position refers to the queue position in the loop record parameter queue that stores the current loop record parameter. The target queue position refers to the queue position in the loop record parameter queue that stores the target loop record parameter.

[0141] Specifically, the server retrieves the loop record parameter queue from the database, then matches the current loop record parameter with each loop record parameter in the loop record parameter queue to determine the queue position of the matching loop record parameter, thus obtaining the current queue position. The server then matches the target loop record parameter with each loop record parameter in the loop record parameter queue to determine the queue position of the matching loop record parameter, thus obtaining the target queue position.

[0142] In one embodiment, the current queue position can be determined by a pre-set current pointer, and the target queue position can be determined by a pre-set target pointer. The current pointer is the pointer set when the current loop record parameter is written into the queue, and it points to the position of the current loop record parameter in the queue. The target pointer is the pointer set when the target loop record parameter is written into the queue, and it points to the position of the target loop record parameter in the queue.

[0143] Step 706: Obtain each cycle record parameter from the cycle record parameter queue based on the current queue position and the target queue position;

[0144] Step 708: Perform cyclic restoration calculations based on the parameters of each cyclic record to obtain the cyclic restoration parameters.

[0145] Specifically, the server retrieves all loop record parameters from the current queue position to the target queue position from the loop record parameter queue, starting from the current queue position and ending at the target queue position. Then, it uses each loop record parameter to perform statistical calculations on the degree of change of the loop execution parameters to obtain the loop restoration parameters.

[0146] In a specific embodiment, such as Figure 8 The diagram illustrates the acquisition of various loop record parameters. Specifically: USQ refers to the loop record parameter queue, USQ entry represents an item in the queue, and different items represent different loop record parameters. cur_ptr = 5 refers to the target pointer corresponding to the target loop record parameter, which is the queue position pointed to by the pointer when the branch instruction prediction fails. hist_ptr = 2 refers to the current pointer corresponding to the current loop record parameter, which is the queue position pointed to by the pointer when the branch instruction passes through the instruction fetch stage. This indicates the update status of each loop record parameter during the time from when the branch instruction passes through the instruction fetch stage to when the branch instruction discovers the branch prediction failure during the execution stage. By using a masking unit to mask all loop record parameters other than the current pointer and the target pointer, all loop record parameters between the queue position indicated by the current pointer and the queue position indicated by the target pointer are obtained, resulting in the loop record parameters in the black part of the diagram, including loop record parameter 2, loop record parameter 3, and loop record parameter 4.

[0147] In the above embodiments, each cyclic record parameter is obtained from the cyclic record parameter queue by the current queue position and the target queue position, and cyclic restoration calculation is performed based on each cyclic record parameter to obtain the cyclic restoration parameter, thus ensuring the accuracy of the obtained cyclic restoration parameter.

[0148] In one embodiment, such as Figure 9 As shown, step 708 involves performing a cyclic reconstruction calculation based on the parameters of each cyclic record to obtain the cyclic reconstruction parameters, including:

[0149] Step 902: Determine the loop record parameters to be calculated from each loop record parameter, and divide the loop record parameters to be calculated according to the preset division conditions to obtain each division parameter.

[0150] The loop record parameters to be calculated refer to the loop record parameters that need to be statistically calculated. These loop record parameters are the parameters recorded during the time period from the prediction of a branch instruction to its prediction failure. The preset partitioning conditions refer to the conditions for pre-dividing the loop record parameters. For example, the partitioning conditions can be set based on the number of bits in the loop record parameter, dividing it into groups of four bits. The partitioned parameters are the partial loop record parameters obtained after partitioning. Integrating all partitioned parameters yields the complete loop record parameters. For example, a 16-bit loop record parameter can be divided into four parts, each of which is four bits, resulting in four partitioned parameters. That is, each partitioned parameter is divided into four 4-bit parts.

[0151] Specifically, the server can sequentially treat each loop record parameter as a loop record parameter to be calculated and perform statistical calculations. After determining the loop record parameter to be calculated, the loop record parameter to be calculated is divided according to preset division conditions to obtain the division parameters corresponding to the loop record parameter to be calculated.

[0152] Step 904: Count the number of preset target values ​​in each partitioning parameter to obtain the number of target values ​​for each partitioning parameter, calculate the sum of the number of target values ​​for each partitioning parameter, and obtain the number of target values ​​corresponding to the loop recording parameter to be calculated.

[0153] Here, the preset target value refers to a pre-set value used to characterize the cyclic change. It can be set according to needs; for example, if the loop count decreases by 1, the corresponding preset target value can be 1. When the loop remains unchanged, the value in the loop recording parameter can be 0. The number of target values ​​refers to the number of preset target values ​​present in the partitioning parameter. The number of target values ​​refers to the number of preset target values ​​present in the loop recording parameter to be calculated.

[0154] Specifically, the server counts the number of preset target values ​​in each partitioning parameter to obtain the number of target values ​​for each partition. This can be achieved using an algorithm that counts the number of 1s in the binary representation. Each partitioning parameter has a corresponding number of target values. Then, all the counts of target values ​​are summed to obtain the number of target values ​​corresponding to the parameter to be calculated for the loop record.

[0155] Step 906: Traverse each loop record parameter to obtain the number of target values ​​corresponding to each loop record parameter, calculate the sum of the number of target values ​​corresponding to each loop record parameter, and obtain the loop restoration parameter.

[0156] Specifically, the server iterates through each loop record parameter in turn to obtain the number of target values ​​corresponding to each loop record parameter, and then adds up the number of target values ​​corresponding to each loop record parameter to obtain the loop restoration parameter.

[0157] In a specific embodiment, such as Figure 10 The diagram illustrates the calculation of the cyclic restoration parameters. Specifically, it involves obtaining each cyclic record parameter and sequentially counting the number of preset target values ​​present in each cyclic record parameter. When the cyclic record parameter is a 16-bit number, it can be used... Figure 10 The diagram on the left side of the middle section is used for calculation, specifically counting the number of 1s in a 16-bit number. When the loop recording parameter is an 8-bit number, it can be used... Figure 10 The diagram on the right side of the image shows the calculation, specifically counting the number of 1s in an 8-bit number. Initial encoding is performed using a 4->3 encoder, which encodes a 4-bit number into a 3-bit number. This 3-bit number is then converted to decimal to obtain the encoded result, which is the number of 1s in the 4-bit number. For example, the 4-bit number 1101 is encoded as 3, meaning it contains three "1"s. When calculating the statistical results for a 16-bit cyclic record parameter, a 4:2 compression is first applied (compressing the four numbers into two numbers), resulting in two values. These two values ​​are then added together using a full adder to obtain the final result, which has a bit width of 5 bits. When calculating the statistical results for an 8-bit cyclic record parameter, a full adder is used directly, resulting in a result with a bit width of 4 bits. (Details are as follows...) Figure 11 The diagram illustrates the process of obtaining the loop restoration parameters. It counts the number of "1"s in each channel. The result of the fourth item is 3, indicating that the number of "1"s within the valid range is 3, meaning the loop restoration parameter for the fourth hardware loop instruction is 3. During subsequent restoration, the remaining loop count of the fourth hardware loop instruction needs to be incremented by 3 for the restoration process.

[0158] In the above embodiments, by traversing each loop record parameter, the number of target values ​​corresponding to each loop record parameter is obtained, and the sum of the number of target values ​​corresponding to each loop record parameter is calculated to obtain the loop restoration parameter, thereby improving the accuracy of the obtained loop restoration parameter.

[0159] In one embodiment, step 212, restoring the loop execution parameters corresponding to the branch instruction in the submission stage of the preset pipeline structure based on the loop restoration parameters to obtain the restored loop execution parameters, includes the following steps:

[0160] Obtain the loop record parameter queue corresponding to the branch instruction in the submission stage of the preset pipeline structure, restore the loop record parameter queue based on the loop restoration parameters to obtain the restored loop record parameter queue; use the loop restoration parameters to restore the loop execution parameters corresponding to the branch instruction in the submission stage of the preset pipeline structure to obtain the restored loop execution parameters.

[0161] The restored loop record parameter queue refers to the loop record parameter queue obtained after removing the loop record parameters recorded during the period from branch instruction prediction to branch instruction prediction failure. The restored loop execution parameters refer to the loop execution parameters during branch instruction prediction.

[0162] Specifically, the server retrieves the loop record parameter queue corresponding to the commit phase of the branch instruction in the preset pipeline structure. Then, it uses the loop restoration parameters to restore the loop record parameter queue, obtaining the restored loop record parameter queue. For example, if the loop restoration parameter is 3, it means that the loop record parameter queue generated 3 loop record parameters within the time period from the prediction of the branch instruction to its preset failure. In this case, the 3 loop record parameters generated during this event segment are deleted from the loop record parameter queue, resulting in the restored loop record parameter queue. In one embodiment, when a pointer exists, it is also set to the tail of the restored loop record parameter queue. Then, the loop restoration parameters are used to restore the loop execution parameters corresponding to the commit phase of the branch instruction in the preset pipeline structure, obtaining the restored loop execution parameters. These restored loop execution parameters are the same as the loop execution parameters corresponding to the fetch phase of the preset pipeline structure. That is, the restored loop state is the same as the loop state when the branch instruction first enters the commit phase of the preset pipeline structure.

[0163] In a specific embodiment, such as Figure 12The diagram illustrates the recovery process when a branch instruction prediction fails. Specifically, at time T0, the loop execution parameter is the remaining number of loop iterations, represented by `lp_cut`. The remaining number of iterations for hardware loop instruction 0 is 4, i.e., `lp_cut0 = 4`. The remaining number of iterations for hardware loop instruction 1 is 1, i.e., `lp_cut1 = 1`. The remaining number of iterations for hardware loop instruction 2 is 1, i.e., `lp_cut2 = 1`. The remaining number of iterations for hardware loop instruction 3 is 0, i.e., `lp_cut3 = 0`. Furthermore, the pointer to the loop record parameter queue points to position 2 at the tail of the queue. At this point, the branch instruction has passed through the fetch stage. After 6 pipeline clock cycles, when the branch instruction passes through the commit stage, i.e., at time T6, a branch instruction prediction failure is detected. The pipeline needs to be flushed, and the loop execution parameters and the pointer to the loop record parameter queue are restored, i.e., the loop state is restored to the state of the branch instruction during the fetch stage. At this point, the pointer of the loop recording parameter queue points to the tail position of the queue, which needs to be restored to 2. The remaining number of loop executions is then restored to obtain the same queue of remaining loop executions as at time T0. The final restored result is shown at time T7.

[0164] In the above embodiments, by restoring the loop record parameter queue to obtain the restored loop record parameter queue, and then restoring the loop execution parameters corresponding to the branch instruction in the submission stage of the preset pipeline structure to obtain the restored loop execution parameters, the accuracy of parameter restoration is improved.

[0165] In one embodiment, the hardware loop instruction includes a sub-hardware loop instruction;

[0166] like Figure 13 As shown, step 204, which involves updating and generating corresponding loop record parameters during the loop execution process, includes:

[0167] Step 1302: Count the number of instructions based on hardware loop instructions and sub-hardware loop instructions to obtain the number of loop instructions.

[0168] Here, a sub-hardware loop instruction refers to a hardware loop instruction nested within a hardware loop instruction, and there can be multiple sub-hardware loop instructions. The number of loop instructions refers to the total number of hardware loop instructions, including hardware loop instructions and hardware loop instructions nested within hardware loop instructions.

[0169] Specifically, the server can obtain nested sub-hardware loop instructions from the loop body of the hardware loop instruction, and then count the number of all hardware loop instructions to obtain the number of loop instructions.

[0170] Step 1304: Determine the number of loop record parameters based on the number of loop instructions, and determine the initial loop record parameters based on the number of loop record parameters.

[0171] The initial loop record parameter refers to the initialized loop record parameter, which can be initialized to zero.

[0172] Specifically, the server uses the number of loop instructions as the number of items in the loop record parameter. For example, when the loop record parameter is a binary number, the number of bits in the binary number is determined based on the number of loop instructions. Then, the initial loop record parameter is determined based on the number of items in the loop record parameter.

[0173] Step 1306: During the loop execution process, update the loop execution parameters to obtain the updated loop execution parameters, and determine the values ​​corresponding to each item in the initial loop record parameters based on the updated loop execution parameters to obtain the loop record parameters corresponding to the updated loop execution parameters.

[0174] Updating the loop execution parameters refers to updating the loop execution parameters. Each time the loop corresponding to a hardware loop instruction completes its execution, the corresponding loop execution parameters need to be updated. Different hardware loop instructions correspond to different loop execution parameters.

[0175] Specifically, during the loop execution, the loop execution parameters are updated to obtain the updated loop execution parameters. Based on the updated loop execution parameters, the values ​​corresponding to each item in the initial loop record parameters are determined, resulting in the loop record parameters corresponding to the updated loop execution parameters. Each obtained loop record parameter is based on the initial loop record parameters. For example, when the number of loop instructions is 8, the number of bits in the binary number is 8, so the obtained initial loop record parameters could be 00000000. Each bit is used to represent the loop change of the corresponding hardware loop instruction. When the loop count of the 4th hardware loop instruction decreases by one, the bit corresponding to that hardware loop instruction becomes 1, and the loop counts of other hardware loop instructions remain unchanged, the obtained loop record parameters at this moment are 00010000.

[0176] In one specific embodiment, when the loop body of a hardware loop instruction contains nested hardware loop instructions, during the loop execution process, such as... Figure 14The diagram shows a loop jump unit. `start_pc` represents the loop start address, and `start_pcX` ​​represents the loop start address of hardware loop instruction X, where X is a positive integer from 0 to 7. `lp_cut` represents the remaining execution count of the loop, and `lp_cutX` represents the remaining execution count of hardware loop instruction X. `MUX` refers to the data selector, used to select the loop start address to jump to. The selection priority starts from the innermost hardware loop instruction, which has the highest priority. If the inner loop has finished executing, the jump can be made based on whether the outer loop has finished executing. Specifically: when the current address is detected to be the same as the loop end address of any hardware loop instruction, and the remaining execution count is not 0 or 1, it means that the current loop body has been executed once, and the current loop has not completed its iteration. It needs to continue loop iteration, i.e., it needs to jump to the loop start address to continue execution. At this time, the jump is performed through the data selector to select the starting address to jump to, i.e., obtain the jump address, and then use the jump address to continue loop execution.

[0177] In the above embodiments, the number of loop recording parameters is determined based on the number of loop instructions, the initial loop recording parameters are determined based on the number of loop recording parameters, the loop execution parameters are updated during the loop execution process to obtain the updated loop execution parameters, and the values ​​corresponding to each item in the initial loop recording parameters are determined based on the updated loop execution parameters to obtain the loop recording parameters corresponding to the updated loop execution parameters, thereby improving the accuracy of the obtained loop recording parameters.

[0178] In one embodiment, after step 212, i.e. after restoring the target loop execution parameters based on the loop restoration parameters to obtain the restored loop execution parameters, and re-executing the branch instructions according to the restored loop execution parameters, the method further includes the following steps:

[0179] When the execution of the hardware loop instruction is detected to be complete, the execution result corresponding to the hardware loop instruction is obtained and output.

[0180] Specifically, once the server detects that the hardware loop instruction has been executed, it obtains the execution result corresponding to the hardware loop instruction. Then, it can output the execution result corresponding to the hardware loop instruction, for example, to a display terminal for display, for easy use.

[0181] In a specific embodiment, such as Figure 15 As shown, the instruction control method specifically includes the following steps:

[0182] Step 1502: Obtain the hardware loop instruction, which includes a branch instruction, and generate loop execution parameters based on the hardware loop instruction. The loop execution parameters include the remaining number of executions for the current loop.

[0183] Step 1504: Determine the current instruction in the current loop from the hardware loop instructions according to the loop execution parameters; execute the current instruction according to the preset pipeline structure; and when the current instruction passes through the instruction read stage of the preset pipeline structure, determine the next instruction corresponding to the current instruction from the current loop.

[0184] Step 1506: Take the next instruction as the current instruction, and return to execute the current instruction according to the preset pipeline structure. When the current instruction passes through the instruction read stage of the preset pipeline structure, retrieve the next instruction corresponding to the current instruction from the current loop and execute it. Continue until the current instruction is detected as a termination instruction in the instruction read stage of the preset pipeline structure. Update the remaining number of executions of the current loop to obtain the updated remaining number of executions of the current loop. Based on the updated remaining number of executions of the current loop, obtain the updated loop execution parameters.

[0185] Step 1508: Determine the number of loop changes based on the remaining number of executions of the current loop and the updated remaining number of executions of the current loop; generate bitmap data based on the number of loop changes; use the bitmap data as the current loop record parameter corresponding to the hardware loop instruction; and save the current loop record parameter to the loop record parameter queue.

[0186] Step 1510 involves updating the loop execution parameters as the loop execution parameters and returning to the step of determining the current instruction in the current loop from the hardware loop instructions according to the loop execution parameters. When a branch instruction enters the read instruction stage of the preset pipeline structure, the loop record parameter corresponding to the tail position is obtained from the loop record parameter queue, thus obtaining the current loop record parameter corresponding to the current loop execution parameters.

[0187] Step 1512: Determine the target execution instruction corresponding to the branch instruction in the instruction execution phase of the preset pipeline structure; obtain the initial execution instruction predicted by the branch instruction in the instruction read phase; when the target execution instruction does not match the initial execution instruction, obtain the corresponding target loop record parameter from the loop record parameter queue based on the target loop execution parameter corresponding to the branch instruction in the instruction execution phase of the preset pipeline structure.

[0188] Step 1514: Determine the current queue position of the current loop record parameter and the target queue position of the target loop record parameter from the loop record parameter queue. Based on the current queue position and the target queue position, obtain each loop record parameter from the loop record parameter queue. Determine the loop record parameter to be calculated from each loop record parameter and divide the loop record parameter to be calculated according to the preset division conditions to obtain each division parameter.

[0189] Step 1516: Count the number of preset target values ​​in each partitioning parameter to obtain the number of target values ​​for each partitioning parameter, calculate the sum of the number of target values ​​for each partitioning parameter to obtain the number of target values ​​corresponding to the loop record parameter to be calculated; traverse each loop record parameter to obtain the number of target values ​​corresponding to each loop record parameter, calculate the sum of the number of target values ​​corresponding to each loop record parameter to obtain the loop restoration parameter.

[0190] Step 1518: Obtain the loop record parameter queue corresponding to the submission stage of the branch instruction in the preset pipeline structure; restore the loop record parameter queue corresponding to the submission stage based on the loop restoration parameters to obtain the restored loop record parameter queue; restore the loop execution parameters corresponding to the submission stage of the branch instruction in the preset pipeline structure using the loop restoration parameters to obtain the restored loop execution parameters; and re-execute the branch instruction according to the restored loop execution parameters until the hardware loop instruction is completed, and obtain the execution result corresponding to the hardware loop instruction.

[0191] In a specific embodiment, such as Figure 16The diagram illustrates the hardware architecture for instruction control. Specifically, this architecture includes two queues: the Loop Execution Parameter Queue (LPQ) and the Loop Record Parameter Queue (USQ). The LPQ stores information required for the loop, including the remaining number of executions, the start address, and the end address. The USQ stores loop record parameters, which are bitmap information representing loop updates. The USQ also contains a `cur_ptr` pointer, which indicates the current position at the end of the queue. `cur_ptr` flows through the pipeline with the instruction stream. When a branch instruction enters the fetch stage of the pipeline at time T0, the pointer position at T0 is recorded. When a branch instruction enters the commit stage of the pipeline at time T6, the pointer position at T6 is recorded. Furthermore, if a branch instruction prediction fails at time T6, loop state recovery is performed. In other words, the masking unit determines each loop record parameter from the USQ using the pointer positions at T0 and T6, thus determining the effective area of ​​the USQ (the black area in the diagram). Then, the counting unit uses a pop count strategy (counting how many bits in the binary representation of an integer are 1) to count the values ​​that need to be recovered within the effective time range for each loop record parameter. Specifically, it counts the number of times a 1 appears in each loop record parameter within the black area; this loop record parameter is bitmap data. The result is the value that needs to be recovered for the remaining execution counts of the current loop in the LPQ. The jump unit is used to determine whether the current loop needs to jump and to select the starting address for the jump. The update unit is used to update the LPQ; that is, when the corresponding loop record parameter is generated during the loop process, the loop record parameter is inserted into the LPQ. For example... Figure 17 The diagram illustrates the update unit. It determines whether the current address matches the termination address of any item in the current LPQ, whether the remaining execution count of the current loop is not zero, and whether all inner loops have ended. This indicates that the remaining execution count of the current LPQ needs to be decremented by 1. The resulting loop record parameter indicates whether each hardware loop instruction in the LPQ needs to be updated, and this loop record parameter is inserted into the USQ for backup.

[0192] In a specific embodiment, this instruction control method is applied to an iterative training platform for an artificial intelligence model. Specifically: Iterative training instructions are acquired, including branch instructions, and model iteration parameters are generated based on these instructions. The iterative training instructions are executed iteratively according to the model iteration parameters and a preset pipeline structure. During iterative execution, the model iteration parameters are updated, and corresponding iteration record parameters are generated to record these updates. When a branch instruction enters the read instruction stage of the preset pipeline structure, the corresponding current iteration record parameters are obtained based on the current model iteration parameters of the branch instruction. When a branch instruction fails to predict its prediction during the instruction execution stage of the preset pipeline structure, the corresponding target iteration record parameters are obtained based on the target model iteration parameters of the branch instruction at that stage. Iterative restoration calculations are performed based on the current and target iteration record parameters to obtain iterative restoration parameters. The target model iteration parameters are restored based on these restoration parameters to obtain the restored model iteration parameters. The branch instructions are then re-executed according to the restored model iteration parameters until the model iteration meets the completion conditions, resulting in a trained artificial intelligence model. This artificial intelligence model can be applied to different scenarios, such as face recognition models, image recognition and classification models, video recognition and classification models, text recognition and classification models, etc. Then, by using instruction control methods to iteratively train the artificial intelligence model, the storage resource consumption during the iterative training process can be reduced, and the computation speed of the model iterative training can be increased, thereby improving training efficiency.

[0193] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.

[0194] Based on the same inventive concept, this application also provides an instruction control device for implementing the instruction control method described above. The solution provided by this device is similar to the implementation described in the above method; therefore, the specific limitations in one or more instruction control device embodiments provided below can be found in the limitations of the instruction control method described above, and will not be repeated here.

[0195] In one embodiment, such as Figure 18 As shown, a command control device 1800 is provided, including: a command acquisition module 1802, a parameter generation module 1804, a current parameter acquisition module 1806, a target parameter acquisition module 1808, a restoration parameter calculation module 1810, and a restoration module 1812, wherein:

[0196] The instruction acquisition module 1802 is used to acquire hardware loop instructions, which include branch instructions, and to generate loop execution parameters based on the hardware loop instructions.

[0197] The parameter generation module 1804 is used to execute hardware loop instructions in a loop according to the loop execution parameters and the preset pipeline structure. The loop execution parameters are updated during the loop execution and corresponding loop record parameters are generated. The loop record parameters are used to record the updates of the loop execution parameters.

[0198] The current parameter acquisition module 1806 is used to acquire the corresponding current loop record parameters based on the current loop execution parameters corresponding to the branch instruction when the branch instruction enters the read instruction stage of the preset pipeline structure.

[0199] The target parameter acquisition module 1808 is used to acquire the corresponding target loop record parameters based on the target loop execution parameters corresponding to the branch instruction in the instruction execution stage of the preset pipeline structure when the branch instruction prediction failure is detected in the instruction execution stage of the preset pipeline structure.

[0200] The restoration parameter calculation module 1810 is used to perform cyclic restoration calculations based on the current cyclic record parameters and the target cyclic record parameters to obtain the cyclic restoration parameters.

[0201] The restore module 1812 is used to restore the target loop execution parameters based on the loop restore parameters, obtain the restored loop execution parameters, and re-execute the branch instructions according to the restored loop execution parameters.

[0202] In one embodiment, the parameter generation module 1804 includes:

[0203] The execution unit is used to determine the current instruction in the current loop from the hardware loop instructions according to the loop execution parameters; execute the current instruction according to the preset pipeline structure, and when the current instruction passes through the instruction fetch stage of the preset pipeline structure, determine the next instruction corresponding to the current instruction from the current loop; take the next instruction as the current instruction, and return to execute the current instruction according to the preset pipeline structure, and when the current instruction passes through the instruction fetch stage of the preset pipeline structure, obtain the next instruction corresponding to the current instruction from the current loop, and continue until the termination instruction in the current loop is executed. Then, update the loop execution parameters to obtain the updated loop execution parameters corresponding to the completion of the current loop execution, and generate the corresponding current loop record parameters based on the updated loop execution parameters; take the updated loop execution parameters as the loop execution parameters, and return to execute the step of determining the current instruction in the current loop from the hardware loop instructions according to the loop execution parameters, until the hardware loop instructions are executed.

[0204] In one embodiment, the loop execution parameters include the current remaining number of loop executions; the execution unit is further configured to update the current remaining number of loop executions when the current instruction is detected as a termination instruction during the read instruction stage of the preset pipeline structure, to obtain the updated current remaining number of loop executions; and generate the current loop record parameters corresponding to the hardware loop instruction based on the current remaining number of loop executions and the updated current remaining number of loop executions.

[0205] In one embodiment, the execution unit is further configured to determine the number of loop changes based on the remaining number of executions of the current loop and the updated remaining number of executions of the current loop; generate bitmap data based on the number of loop changes; use the bitmap data as the current loop record parameter corresponding to the hardware loop instruction; and save the current loop record parameter.

[0206] In one embodiment, the current parameter acquisition module 1806 is further used to acquire the loop record parameter queue, which is obtained by writing the generated loop record parameters sequentially during the loop execution; the loop record parameter corresponding to the tail position is obtained from the loop record parameter queue to obtain the current loop record parameter corresponding to the current loop execution parameter.

[0207] In one embodiment, the target parameter acquisition module 1808 is further configured to determine the target execution instruction corresponding to the branch instruction during the instruction execution phase of the preset pipeline structure; acquire the initial execution instruction predicted by the branch instruction during the instruction read phase; determine that the branch instruction prediction has failed when the target execution instruction does not match the initial execution instruction; and acquire the corresponding target loop record parameter based on the target loop execution parameter corresponding to the branch instruction during the instruction execution phase of the preset pipeline structure when the branch instruction prediction fails.

[0208] In one embodiment, the restoration parameter calculation module 1810 is further configured to obtain a loop record parameter queue, which is obtained by writing the generated loop record parameters sequentially during loop execution; determine the current queue position of the current loop record parameter and the target queue position of the target loop record parameter from the loop record parameter queue; obtain each loop record parameter from the loop record parameter queue based on the current queue position and the target queue position; and perform loop restoration calculation based on each loop record parameter to obtain the loop restoration parameters.

[0209] In one embodiment, the restoration parameter calculation module 1810 determines the loop record parameters to be calculated from each loop record parameter, divides the loop record parameters to be calculated according to preset division conditions, and obtains each division parameter; counts the number of preset target values ​​in each division parameter to obtain the number of target values ​​for each division, calculates the sum of the number of target values ​​for each division to obtain the number of target values ​​corresponding to the loop record parameters to be calculated; iterates through each loop record parameter to obtain the number of target values ​​corresponding to each loop record parameter, calculates the sum of the number of target values ​​corresponding to each loop record parameter, and obtains the loop restoration parameters.

[0210] In one embodiment, the restoration module 1812 is further configured to obtain the loop record parameter queue corresponding to the submission stage of the branch instruction in the preset pipeline structure, restore the loop record parameter queue based on the loop restoration parameters to obtain the restored loop record parameter queue, and use the loop restoration parameters to restore the loop execution parameters corresponding to the submission stage of the branch instruction in the preset pipeline structure to obtain the restored loop execution parameters.

[0211] In one embodiment, the hardware loop instruction includes a sub-hardware loop instruction; the parameter generation module 1804 is further configured to perform instruction count based on the hardware loop instruction and the sub-hardware loop instruction to obtain the number of loop instructions; determine the number of loop record parameters based on the number of loop instructions, determine the initial loop record parameters based on the number of loop record parameters; update the loop execution parameters during loop execution to obtain the updated loop execution parameters, and determine the values ​​corresponding to each item in the initial loop record parameters based on the updated loop execution parameters to obtain the loop record parameters corresponding to the updated loop execution parameters.

[0212] In one embodiment, the command control device 1800 further includes:

[0213] The result acquisition module is used to obtain the execution result corresponding to the hardware loop instruction when the execution of the hardware loop instruction is detected to be completed, and to output the execution result corresponding to the hardware loop instruction.

[0214] Each module in the aforementioned instruction control device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0215] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 19 As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media. The database stores loop execution parameters, loop record parameter data, execution results, etc. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communication with external terminals via a network connection. When the computer program is executed by the processor, it implements an instruction control method.

[0216] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 20As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements an instruction control method. The display unit of the computer device is used to form a visually visible image. It can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.

[0217] Those skilled in the art will understand that Figure 19 or Figure 20 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0218] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.

[0219] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above method embodiments.

[0220] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.

[0221] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data shall comply with the relevant laws, regulations and standards of the relevant countries and regions.

[0222] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.

[0223] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0224] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. A command control method, characterized in that, The method includes: Obtain hardware loop instructions, which include branch instructions, and generate loop execution parameters based on the hardware loop instructions, which include the remaining number of executions for the current loop. The hardware loop instruction is executed cyclically according to the loop execution parameters and the preset pipeline structure. The loop execution parameters are updated and corresponding loop record parameters are generated during the loop execution. The loop record parameters are used to record the update of the loop execution parameters, including: determining the number of loop changes based on the current remaining number of loop executions and the updated current remaining number of loop executions, generating bitmap data based on the number of loop changes, and using the bitmap data as the current loop record parameter corresponding to the hardware loop instruction. When the branch instruction enters the read instruction stage of the preset pipeline structure, the corresponding current loop record parameter is obtained based on the current loop execution parameter corresponding to the branch instruction. When the branch instruction detects that the branch instruction prediction has failed during the instruction execution phase of the preset pipeline structure, the corresponding target loop record parameter is obtained based on the target loop execution parameter corresponding to the branch instruction during the instruction execution phase of the preset pipeline structure. Based on the current loop recording parameters and the target loop recording parameters, a loop restoration calculation is performed to obtain loop restoration parameters, including: obtaining all loop recording parameters saved during the time period from recording the current loop recording parameters to recording the target loop recording parameters; calculating the degree of change of loop execution parameters based on all loop recording parameters during the time period; obtaining the change amount corresponding to the loop execution parameters during the time period; and using the change amount as the loop restoration parameters. The target loop execution parameters are restored based on the loop restoration parameters to obtain the restored loop execution parameters, and the branch instructions are re-executed according to the restored loop execution parameters.

2. The method according to claim 1, characterized in that, The hardware loop instruction is executed cyclically according to the loop execution parameters and the preset pipeline structure. The loop execution parameters are updated and corresponding loop record parameters are generated during the loop execution process, including: The current instruction in the current loop is determined from the hardware loop instructions according to the loop execution parameters; The current instruction is executed according to the preset pipeline structure, and when the current instruction passes through the instruction read stage of the preset pipeline structure, the next instruction corresponding to the current instruction is determined from the current loop; The next instruction is taken as the current instruction, and the current instruction is executed according to the preset pipeline structure. When the current instruction passes through the instruction read stage of the preset pipeline structure, the next instruction corresponding to the current instruction is determined from the current loop. The execution continues until the termination instruction in the current loop is completed. The loop execution parameters are updated to obtain the updated loop execution parameters corresponding to the completion of the current loop execution. The corresponding current loop record parameters are generated based on the updated loop execution parameters. The updated loop execution parameters are used as loop execution parameters, and the step of determining the current instruction in the current loop from the hardware loop instructions according to the loop execution parameters is returned to execution until the hardware loop instructions are completed.

3. The method according to claim 2, characterized in that, The process involves updating the loop execution parameters until the termination instruction in the current loop is completed, obtaining the updated loop execution parameters corresponding to the completion of the current loop, and generating corresponding current loop record parameters based on the updated loop execution parameters, including: When the current instruction is detected as a termination instruction during the read instruction stage of the preset pipeline structure, the remaining execution count of the current loop is updated to obtain the updated remaining execution count of the current loop. The current loop record parameters corresponding to the hardware loop instruction are generated based on the current remaining number of executions and the updated current remaining number of executions.

4. The method according to claim 3, characterized in that, The step of generating the current loop record parameters corresponding to the hardware loop instruction based on the remaining execution count of the current loop and the updated remaining execution count of the current loop includes: The number of loop changes is determined based on the remaining number of executions in the current loop and the updated remaining number of executions in the current loop. Bitmap data is generated based on the number of loop changes, and the bitmap data is used as the current loop record parameter corresponding to the hardware loop instruction, and the current loop record parameter is saved.

5. The method according to claim 1, characterized in that, The step of obtaining the corresponding current loop record parameters based on the current loop execution parameters corresponding to the branch instruction includes: Obtain the loop record parameter queue, which is obtained by writing the generated loop record parameters sequentially during the loop execution; The loop record parameter corresponding to the tail position is obtained from the loop record parameter queue, and the current loop record parameter corresponding to the current loop execution parameter is obtained.

6. The method according to claim 1, characterized in that, When the branch instruction is detected to have failed to predict its prediction during the instruction execution phase of the preset pipeline structure, the corresponding target loop record parameters are obtained based on the target loop execution parameters corresponding to the branch instruction during the instruction execution phase of the preset pipeline structure, including: During the instruction execution phase of the preset pipeline structure, the target execution instruction corresponding to the branch instruction is determined. Obtain the initial execution instruction predicted by the branch instruction during the instruction read stage; if the target execution instruction does not match the initial execution instruction, determine that the branch instruction prediction has failed. When the branch instruction prediction fails, the corresponding target loop record parameter is obtained based on the target loop execution parameter corresponding to the branch instruction in the instruction execution stage of the preset pipeline structure.

7. The method according to claim 1, characterized in that, The process of performing loop restoration calculations based on the current loop record parameters and the target loop record parameters to obtain loop restoration parameters includes: Obtain the loop record parameter queue, which is obtained by writing the generated loop record parameters sequentially during the loop execution; Determine the current queue position of the current loop record parameter and the target queue position of the target loop record parameter from the loop record parameter queue; Based on the current queue position and the target queue position, obtain each cycle record parameter from the cycle record parameter queue; Based on the various cyclic recording parameters, a cyclic restoration calculation is performed to obtain the cyclic restoration parameters.

8. The method according to claim 7, characterized in that, The cyclic restoration calculation based on the various cyclic record parameters, to obtain the cyclic restoration parameters, includes: The loop record parameters to be calculated are determined from the various loop record parameters, and the loop record parameters to be calculated are divided according to the preset division conditions to obtain the division parameters. The number of preset target values ​​in each of the partitioning parameters is counted to obtain the number of each partitioning target value. The sum of the number of each partitioning target value is calculated to obtain the number of target values ​​corresponding to the loop record parameter to be calculated. The loop record parameters are iterated through to obtain the number of target values ​​corresponding to each loop record parameter. The sum of the number of target values ​​corresponding to each loop record parameter is calculated to obtain the loop restoration parameter.

9. The method according to claim 1, characterized in that, The process of restoring the target loop execution parameters based on the loop restoration parameters to obtain the restored loop execution parameters includes: Obtain the loop record parameter queue corresponding to the branch instruction in the submission stage of the preset pipeline structure, and restore the loop record parameter queue based on the loop restoration parameters to obtain the restored loop record parameter queue. The loop restoration parameters are used to restore the loop execution parameters corresponding to the branch instruction in the submission stage of the preset pipeline structure, so as to obtain the restored loop execution parameters.

10. The method according to claim 1, characterized in that, The hardware loop instruction includes a sub-hardware loop instruction; The loop execution parameters are updated and corresponding loop record parameters are generated during the loop execution process, including: The number of loop instructions is obtained by counting the number of instructions based on the hardware loop instruction and the sub-hardware loop instruction. The number of loop record parameters is determined based on the number of loop instructions, and the initial loop record parameters are determined based on the number of loop record parameters. During the loop execution, the loop execution parameters are updated to obtain the updated loop execution parameters. Based on the updated loop execution parameters, the values ​​corresponding to each item in the initial loop record parameters are determined to obtain the loop record parameters corresponding to the updated loop execution parameters.

11. The method according to claim 1, characterized in that, After restoring the target loop execution parameters based on the loop restoration parameters to obtain the restored loop execution parameters, and re-executing the branch instruction according to the restored loop execution parameters, the method further includes: When the execution of the hardware loop instruction is detected to be complete, the execution result corresponding to the hardware loop instruction is obtained and output.

12. A command control device, characterized in that, The device includes: The instruction acquisition module is used to acquire hardware loop instructions, which include branch instructions, and to generate loop execution parameters based on the hardware loop instructions, which include the remaining number of executions in the current loop. The parameter generation module is used to execute the hardware loop instruction in a loop according to the loop execution parameters and the preset pipeline structure. The loop execution parameters are updated and corresponding loop record parameters are generated during the loop execution. The loop record parameters are used to record the update of the loop execution parameters, including: determining the number of loop changes based on the current remaining number of loop executions and the updated current remaining number of loop executions, generating bitmap data based on the number of loop changes, and using the bitmap data as the current loop record parameter corresponding to the hardware loop instruction. The current parameter acquisition module is used to acquire the corresponding current loop record parameters based on the current loop execution parameters corresponding to the branch instruction when the branch instruction enters the read instruction stage of the preset pipeline structure. The target parameter acquisition module is used to acquire the corresponding target loop record parameters based on the target loop execution parameters corresponding to the branch instruction in the instruction execution stage of the preset pipeline structure when the branch instruction is detected to have failed to predict the branch instruction. The restoration parameter calculation module is used to perform a cycle restoration calculation based on the current cycle record parameter and the target cycle record parameter to obtain the cycle restoration parameter. The module includes: obtaining all cycle record parameters saved during the time period from recording the current cycle record parameter to recording the target cycle record parameter; calculating the degree of change of the cycle execution parameter based on all cycle record parameters during the time period; obtaining the change amount corresponding to the cycle execution parameter during the time period; and using the change amount as the cycle restoration parameter. The restore module is used to restore the target loop execution parameters based on the loop restore parameters to obtain the restored loop execution parameters, and to re-execute the branch instruction according to the restored loop execution parameters.

13. The apparatus according to claim 12, characterized in that, The parameter generation module includes: An execution unit is configured to: determine the current instruction in the current loop from the hardware loop instructions according to the loop execution parameters; execute the current instruction according to the preset pipeline structure, and when the current instruction passes through the instruction fetching stage of the preset pipeline structure, determine the next instruction corresponding to the current instruction from the current loop; use the next instruction as the current instruction, and return to the steps of executing the current instruction according to the preset pipeline structure and determining the next instruction corresponding to the current instruction from the current loop when the current instruction passes through the instruction fetching stage of the preset pipeline structure, until the termination instruction in the current loop is executed; update the loop execution parameters to obtain the updated loop execution parameters corresponding to the completion of the current loop execution, and generate corresponding current loop record parameters based on the updated loop execution parameters; use the updated loop execution parameters as loop execution parameters, and return to the steps of determining the current instruction in the current loop from the hardware loop instructions according to the loop execution parameters, until the hardware loop instructions are executed.

14. The apparatus according to claim 13, characterized in that, The execution unit is further configured to update the remaining number of executions in the current loop when the current instruction is detected as a termination instruction during the read instruction stage of the preset pipeline structure, so as to obtain the updated remaining number of executions in the current loop; The current loop record parameters corresponding to the hardware loop instruction are generated based on the current remaining number of executions and the updated current remaining number of executions.

15. The apparatus according to claim 14, characterized in that, The execution unit is further configured to determine the number of loop changes based on the remaining number of executions of the current loop and the updated remaining number of executions of the current loop; generate bitmap data based on the number of loop changes, use the bitmap data as the current loop record parameter corresponding to the hardware loop instruction, and save the current loop record parameter.

16. The apparatus according to claim 12, characterized in that, The current parameter acquisition module is also used to acquire a loop record parameter queue, which is obtained by writing the generated loop record parameters sequentially during the loop execution. The loop record parameter corresponding to the tail position is obtained from the loop record parameter queue, and the current loop record parameter corresponding to the current loop execution parameter is obtained.

17. The apparatus according to claim 12, characterized in that, The target parameter acquisition module is further configured to determine the target execution instruction corresponding to the branch instruction during the instruction execution phase of the preset pipeline structure; acquire the initial execution instruction predicted by the branch instruction during the instruction read phase; determine that the branch instruction prediction has failed when the target execution instruction does not match the initial execution instruction; and acquire the corresponding target loop record parameter based on the target loop execution parameter corresponding to the branch instruction during the instruction execution phase of the preset pipeline structure when the branch instruction prediction has failed.

18. The apparatus according to claim 12, characterized in that, The restoration parameter calculation module is also used to obtain a loop record parameter queue, which is obtained by writing the generated loop record parameters sequentially during the loop execution. Determine the current queue position of the current loop record parameter and the target queue position of the target loop record parameter from the loop record parameter queue; Based on the current queue position and the target queue position, obtain each cycle record parameter from the cycle record parameter queue; Based on the various cyclic recording parameters, a cyclic restoration calculation is performed to obtain the cyclic restoration parameters.

19. The apparatus according to claim 18, characterized in that, The restoration parameter calculation module is further configured to determine the loop record parameter to be calculated from each loop record parameter, and divide the loop record parameter to be calculated according to a preset division condition to obtain each division parameter; count the number of preset target values ​​in each division parameter to obtain the number of target values ​​for each division, calculate the sum of the number of target values ​​for each division to obtain the number of target values ​​corresponding to the loop record parameter to be calculated; traverse each loop record parameter to obtain the number of target values ​​corresponding to each loop record parameter, calculate the sum of the number of target values ​​corresponding to each loop record parameter, and obtain the loop restoration parameter.

20. The apparatus according to claim 12, characterized in that, The restoration module is also used to obtain the loop record parameter queue corresponding to the branch instruction in the submission stage of the preset pipeline structure, and restore the loop record parameter queue based on the loop restoration parameters to obtain the restored loop record parameter queue. The loop restoration parameters are used to restore the loop execution parameters corresponding to the branch instruction in the submission stage of the preset pipeline structure, so as to obtain the restored loop execution parameters.

21. The apparatus according to claim 12, characterized in that, The hardware loop instruction includes a sub-hardware loop instruction; The parameter generation module is also used to perform instruction count based on the hardware loop instruction and the sub-hardware loop instruction to obtain the number of loop instructions; determine the number of loop record parameters based on the number of loop instructions; and determine the initial loop record parameters based on the number of loop record parameters. During the loop execution, the loop execution parameters are updated to obtain the updated loop execution parameters. Based on the updated loop execution parameters, the values ​​corresponding to each item in the initial loop record parameters are determined to obtain the loop record parameters corresponding to the updated loop execution parameters.

22. The apparatus according to claim 12, characterized in that, The device further includes: The result acquisition module is used to obtain the execution result corresponding to the hardware loop instruction when the hardware loop instruction is detected to have completed execution, and to output the execution result corresponding to the hardware loop instruction.

23. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 11.

24. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 11.

25. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Loop buffer guided by loop predictor

    CN104298488A

  • Apparatus and method for performing branch prediction

    US20200065111A1