Instruction processing method, processor, chip and electronic equipment

By using the recursive call record table to record the number of reads of the return address in instruction processing, the problem of excessive storage resource occupation caused by repeated storage in multi-loop instructions is solved, which reduces instruction processing overhead, improves the processor's processing efficiency and the prediction accuracy of branch instructions.

CN120386559APending Publication Date: 2025-07-29HYGON INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410331085.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-21
Publication Date
2025-07-29

AI Technical Summary

Technical Problem

In the existing instruction processing process, the overhead of instruction processing is relatively large, especially in multi-cycle instructions, the repeated return address storage occupies too much storage resources, affecting the prediction accuracy and processing efficiency of other instructions.

Method used

By using the recursive call record table to record the number of reads of the return address, avoiding repeated storing of the same return address to the return address stack, and only updating the recursive call record table when the call command is in the call, keeping the pointer position of the return address stack unchanged, reducing unnecessary storage operations.

Benefits of technology

It reduces the overhead of instruction processing, reduces the use of storage resources, improves the prediction accuracy of branch instructions, and avoids the problem of hardware resource crowding caused by repeated storage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120386559A_ABST
    Figure CN120386559A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an instruction processing method, a processor, a chip and electronic equipment. The method comprises the steps of obtaining a to-be-pushed return address corresponding to a currently predicted and hit calling instruction; determining whether the to-be-pushed return address is the same as a return address pointed by a return pointer in a return address stack or not; the return address stack is used for storing the return addresses in sequence, and the return pointer is used for pointing to the return address newly stored to the return address stack; if yes, the positions pointed by a return pointer and a call pointer of the return address stack are kept, and a recursive call record table is updated, so that the number of read times of a return address pointed by the return pointer recorded in the recursive call record table is increased by 1; the recursive call record table is used for recording the number of times of reading the return instruction corresponding to each return address in the return address stack. The method can reduce the overhead of instruction processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the technical field of processors, and more particularly to an instruction processing method, a processor, a chip, and an electronic device. Background Art

[0002] In modern processors, instructions need to go through processing procedures such as instruction fetching, decoding, and execution. Among them, instruction fetching is used to obtain the instructions to be executed, decoding is used to parse and translate the fetched instructions to obtain the micro-operations (Uops) corresponding to the instructions, and execution is used to execute the corresponding instruction operations based on the micro-operations obtained by decoding.

[0003] However, in the existing instruction processing flow, the overhead of instruction processing is relatively large. Summary of the Invention

[0004] In view of this, the embodiments of the present application provide an instruction processing method, a processor, a chip, and an electronic device to reduce the overhead of instruction processing.

[0005] To achieve the above object, the embodiments of the present application provide the following technical solutions.

[0006] In a first aspect, the embodiments of the present application provide an instruction processing method, including:

[0007] Obtain the return address to be pushed onto the stack corresponding to the currently predicted hit call instruction, where the return address to be pushed onto the stack is the return address corresponding to the currently predicted hit call instruction, and the return address is the instruction address of the return instruction corresponding to the call instruction;

[0008] Determine whether the return address to be pushed onto the stack is the same as the return address pointed to by the return pointer in the return address stack; the return address stack is used to sequentially store the return addresses, and the return pointer is used to point to the latest stored return address in the return address stack;

[0009] If so, maintain the positions pointed to by the return pointer and the call pointer in the return address stack, and update the recursive call record table so that the read count of the return address pointed to by the return pointer in the recursive call record table is incremented by 1; the recursive call record table is used to record the number of times the return instructions corresponding to the respective return addresses in the return address stack need to be read.

[0010] Optionally, the updating of the recursive call record table includes:

[0011] Search for the entry corresponding to the return pointer in the recursive call record table;

[0012] Increment the value of the counter in the corresponding entry by 1.

[0013] Optionally, the entry in the lookup recursive call record table corresponding to the return pointer is specifically obtained by indexing based on the pointing identifier of the return pointer to obtain the corresponding entry in the recursive call record table; wherein, the recursive call record table marks the entries in the return address stack based on the pointing identifier.

[0014] Optionally, after determining whether the return address to be pushed onto the stack is the same as the return address pointed to by the return pointer in the return address stack, it further includes:

[0015] If not, store the return address to be pushed onto the stack in the return address stack, and update the positions pointed to by the call pointer and the return pointer based on the storage position of the return address to be pushed onto the stack.

[0016] Optionally, updating the positions pointed to by the call pointer and the return pointer based on the storage position of the return address to be pushed onto the stack includes:

[0017] Configure the call pointer to point to the next entry of the original position, and configure the return pointer to point to the entry storing the return address to be pushed onto the stack.

[0018] Second method, an embodiment of the present application provides another instruction processing method, including:

[0019] When the currently predicted hit instruction is a return instruction, determine the return address pointed to by the return pointer in the return address stack;

[0020] Read the return address pointed to by the return pointer, and update the recursive call record table so that the read count of the return address pointed to by the return pointer in the recursive call record table is decreased by 1;

[0021] After updating the recursive call record table, if the read count of the return address pointed to by the return pointer is greater than 0, maintain the positions pointed to by the return pointer and the call pointer of the return address stack so that the return address pointed to by the return pointer can be continuously read.

[0022] Optionally, updating the recursive call record table includes:

[0023] Search for the entry in the recursive call record table corresponding to the return pointer;

[0024] Decrease the value of the counter in the corresponding entry by 1.

[0025] Optionally, the entry in the lookup recursive call record table corresponding to the return pointer is specifically obtained by indexing based on the pointing identifier of the return pointer to obtain the corresponding entry in the recursive call record table; wherein, the recursive call record table marks the entries in the return address stack based on the pointing identifier.

[0026] Optionally, the method further includes:

[0027] After updating the recursive call record table, if the number of times the return address pointed to by the return pointer is read is equal to 0, update the positions pointed to by the call pointer and the return pointer based on the storage position of the return address.

[0028] Optionally, the updating the positions pointed to by the call pointer and the return pointer based on the storage position of the return address includes:

[0029] Configure the call pointer to point to the entry of the read return address;

[0030] Configure the return pointer to point to the entry previous to the original position.

[0031] Optionally, after updating the positions pointed to by the call pointer and the return pointer based on the storage position of the return address, it further includes:

[0032] Delete the return address in the entry pointed to by the call pointer before the recursive call record table is updated.

[0033] In a third aspect, an embodiment of the present application further provides a processor, which is used to execute the instruction processing method provided in the first aspect of the embodiment of the present application, and execute the instruction processing method provided in the second aspect of the embodiment of the present application.

[0034] In a fourth aspect, an embodiment of the present application further provides a chip, including the processor provided in the third aspect of the embodiment of the present application.

[0035] In a fifth aspect, an embodiment of the present application further provides an electronic device, including the chip provided in the fourth aspect of the embodiment of the present application.

[0036] For the instruction processing method, processor, chip, and electronic device provided in the embodiments of the present application, the method includes obtaining a return address to be pushed onto the stack corresponding to a currently predicted hit call instruction, where the return address to be pushed onto the stack is the return address corresponding to the currently predicted hit call instruction, and the return address is the instruction address of the return instruction corresponding to the call instruction; determining whether the return address to be pushed onto the stack is the same as the return address pointed to by the return pointer in the return address stack, where the return address stack is used to sequentially store the return addresses, and the return pointer is used to point to the latest stored return address in the return address stack; if so, keep the positions pointed to by the return pointer and the call pointer of the return address stack, and update the recursive call record table, so that the number of times the return address pointed to by the return pointer in the recursive call record table is read is incremented by 1; the recursive call record table is used to record the number of times the return instructions corresponding to the respective return addresses in the return address stack need to be read.

[0037] It can be seen that the instruction processing method, processor, chip, and electronic device provided by the embodiments of the present application use a recursive call record table to record the number of times the return instructions corresponding to each return address need to be executed. Thus, when the return address to be pushed onto the stack corresponding to the currently predicted hit call instruction is the same as the return address pointed to by the return pointer in the return address stack, the positions pointed to by the return pointer and the call pointer of the return address stack are maintained, and the recursive call record table is updated so that the execution count of the return address pointed to by the return pointer in the recursive call record table is incremented by 1, without the need to repeatedly store the corresponding return address into the return address stack, thereby reducing excessive occupation of storage resources and reducing the overhead of instruction processing. Description of the Drawings

[0038] To more clearly illustrate the technical solutions in the embodiments of the present application or in the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on the provided drawings.

[0039] Figure 1 It is an optional schematic diagram of the instruction processing flow.

[0040] Figure 2 It is an optional flow schematic diagram of a branch instruction prediction.

[0041] Figure 3 It is an optional processing flow schematic diagram of a multiple call instruction.

[0042] Figure 4 It is an optional structural diagram of the return address stack.

[0043] Figure 5 It is an optional schematic diagram of the update change of the return address stack.

[0044] Figure 6 It is another optional schematic diagram of the update change of the return address stack.

[0045] Figure 7 It is an optional flowchart of an instruction processing method provided by the embodiments of the present application.

[0046] Figure 8 It is an optional structural schematic diagram of a recursive call record table provided by the embodiments of the present application.

[0047] Figure 9 It is an optional flowchart of another instruction processing method provided by the embodiments of the present application. Detailed Embodiments

[0048] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.

[0049] In a general instruction processing flow, referring to Figure 1 the optional schematic diagram of the instruction processing flow shown, an instruction usually needs to go through processing processes such as instruction fetch, instruction decode, and execute. Instruction fetch is to fetch the instruction corresponding to the program operation from the cache or main memory of the processor; the decode operation is to decode the fetched instruction to determine the operation code and / or address code, etc. of the instruction; the execute operation is to execute the instruction operation according to the obtained operation code and / or address code, etc. to implement the program operation. Among them, the processor generally uses the instruction pipeline technology to implement the processing of instructions. In this technology, different hardware modules are configured for different processing processes. In the pipeline operation of the processor, multiple instructions in different processing processes can be processed and transferred in the corresponding hardware modules in sequence.

[0050] However, when processing branch instructions in the instructions, a branch prediction mechanism needs to be based on to reduce the instruction delay. It can be understood that a branch instruction is an instruction that can change the program flow. In a specific program flow, a branch instruction can execute different instruction sequences (i.e., enter different branch processes) based on different instruction results. Referring to Figure 2 the optional flow schematic diagram of a branch instruction prediction shown, the branch instruction N needs to enter different branch processes, i.e., branch N1 and branch N2, based on the result of the instruction M. At this time, if the instruction is executed according to the normal logic, the result of the instruction M needs to be waited for, such as result M1 or result M2. However, in the pipeline operation of the processor, multiple instructions in different processing stages are processed in different hardware logics at the same time. The delay of one instruction will block the processing processes of multiple other instructions on the subsequent pipeline, thereby causing pipeline delay. To reduce the pipeline delay caused by the processor waiting for the instruction result of the branch instruction to determine the next instruction fetch, a branch prediction mechanism of the instruction can be based on to determine in advance which instruction to execute next (such as Figure 2 the branch Ni shown, where i can be 1 or 2), reducing the waiting time of the processor when executing the branch instruction.

[0051] In an optional prediction mechanism, corresponding predictions can be made based on the target address of a branch instruction. Specifically, the address of the branch instruction and its corresponding target address are stored in the BTB (Branch Target Buffer), so as to make predictions for the branch instruction based on the target address. Among them, for the subroutine call instruction in the branch instruction, a return address stack is further configured to further improve the accuracy of instruction prediction.

[0052] Specifically, the subroutine call instruction realizes the processing of the instruction by calling a subroutine. The subroutine call instruction includes a call instruction (CALL) and a return instruction (RET). The call instruction is used to enter the subroutine, and the return instruction is used to return from the subroutine. Therefore, the call instruction and the return instruction are a corresponding pair of instructions.

[0053] When there is a double call in the subroutine call, a corresponding pair of call instructions and return instructions can be nested between the previous pair of call instructions and return instructions; correspondingly, when there are multiple calls, refer to Figure 3 the schematic diagram of an optional processing flow of a multiple call instruction shown, and multiple groups of call instructions and return instructions are nested and executed in sequence, such as Figure 3 , the call instruction 2 and the return instruction 2 are embedded between the call instruction 1 and the return instruction 1, and the call instruction 3 and the return instruction 3 are embedded between the call instruction 2 and the return instruction 2. Specifically, the call instructions are executed in the nested order, and the instruction addresses of the corresponding return instructions (hereinafter referred to as return addresses) can be stored in the return address stack in sequence according to the corresponding nested order, and when it is necessary to execute the return instruction, the corresponding return addresses are taken out from the return address stack in the last-in-first-out order, and the corresponding return instruction is executed based on the return address.

[0054] Correspondingly, refer to Figure 4 the optional structural diagram of the return address stack shown. The return address stack is used to store the instruction addresses of the return instructions corresponding to the call instructions (hereinafter referred to as return addresses). The return address stack is configured with a call pointer (Call Ptr) and a return pointer (Retn Ptr). Among them, the call pointer is used to point to the entry where the return address will be stored (that is, the empty entry adjacent to the entry where the latest return address is stored), and the return pointer is used to point to the entry where the return address will be taken out (that is, the entry storing the return address adjacent to the empty entry). That is to say, when a call instruction is predicted, the call pointer is used to point to the entry where the return address corresponding to the call instruction will be stored, and when a return instruction is predicted, the return pointer points to the entry where the return address corresponding to the return instruction will be taken out. Based on the processing logic of the call instruction, the return pointer essentially always points to the entry corresponding to the return address that is latest stored in the return address stack. Figure 4Take the return address n as an example. It can be understood that, based on the rule that the return addresses are stored in the return address stack from bottom to top, it can be understood that the entry that will store the return address corresponding to the call instruction is the entry immediately above the entry of the return address to be taken out. Therefore, the entry pointed to by the call pointer is usually the entry immediately above the entry pointed to by the return pointer, and the entry pointed to by the return pointer is usually the entry immediately below the entry pointed to by the call pointer.

[0055] Among them, the return pointer and the call pointer mark each entry of the return address stack based on the pointing identifier. The pointing identifier can be, for example, the identification information or address information of each entry of the return address stack. In a specific example, both the return pointer and the call pointer can be a register that records the corresponding pointing identifier. When storing and taking out the return address stack, based on the pointing identifier recorded in the return pointer and the call pointer, the entry to be operated on in the return address stack is determined.

[0056] When a return address stack is configured, when a predicted branch instruction is predicted as a call instruction (CALL) and hits, refer to Figure 5 An optional update change schematic diagram of the return address stack shown, the update process of the corresponding return address stack is as follows: push the return address corresponding to the call instruction (usually the linear address of the current call instruction plus 1, that is, the next instruction of the current call instruction, shown as return address n+1 in the figure) onto the stack, and set the return pointer (Retn Ptr) configured to the return address stack to point to the newly pushed return address (refer to the change shown by the arrow in the figure), specifically, for example, the return pointer can be incremented by 1; while the call pointer (Call Ptr) configured to the return address stack points to the next empty data stack entry (refer to the change shown by the arrow in the figure), specifically, for example, the call pointer can be incremented by 1.

[0057] Correspondingly, when the predicted branch instruction is a return instruction (RET), refer to Figure 6 Another optional update change schematic diagram of the return address stack shown, the update process of the corresponding return address stack is as follows: take out the return address pointed to by the current return pointer (Retn Ptr) (shown as return address n+1 in the figure) as the target address to execute the subsequent process, and set the return pointer (Retn Ptr) configured to the return address stack to point to the next return address in the return address stack (refer to the change shown by the arrow in the figure), specifically, for example, the return pointer can be decremented by 1, and the call pointer (Call Ptr) configured to the return address stack points to the entry immediately above the return pointer (refer to the change shown by the arrow in the figure), specifically, for example, the call pointer can be decremented by 1.

[0058] However, the overhead of processing such instructions is relatively large. To solve this problem, the inventor believes that it is possible to consider starting from the repeated information in multi-loop instructions to simplify the relevant information and reduce the overhead of instruction processing.

[0059] Specifically, the inventor believes that when dealing with multi-loop instructions (for example, recursive call instructions in multi-loops, and the recursive call instruction is a special type of subroutine call instruction), the return address corresponding to the call address is the same address. Correspondingly, the processing flow will repeatedly write the same return address into the return address stack multiple times, and as a result, multiple entries in the return address stack will be successively written with duplicate information. This duplicate information occupies too much storage resources, resulting in an excessive overhead for instruction processing. At the same time, this duplicate information occupying too much storage resources will also squeeze the available resources of other instructions, which may have an adverse impact on the prediction accuracy of other branch instructions.

[0060] In view of this, the embodiments of the present application provide an instruction processing method, a processor, a chip, and an electronic device. The method includes: obtaining the return address to be pushed onto the stack corresponding to the currently predicted hit call instruction, where the return address to be pushed onto the stack is the return address corresponding to the currently predicted hit call instruction, and the return address is the instruction address of the return instruction corresponding to the call instruction; determining whether the return address to be pushed onto the stack is the same as the return address pointed to by the return pointer in the return address stack; the return address stack is used to sequentially store the return addresses, and the return pointer is used to point to the most recently stored return address in the return address stack; if so, maintaining the positions pointed to by the return pointer and the call pointer of the return address stack, and updating the recursive call record table so that the number of times the return address pointed to by the return pointer in the recursive call record table is read is incremented by 1; the recursive call record table is used to record the number of times the return instructions corresponding to each return address in the return address stack need to be read.

[0061] It can be seen that the instruction processing method, processor, chip, and electronic device provided by the embodiments of the present application use the recursive call record table to record the number of times the return instructions corresponding to each return address need to be executed. Thus, when the return address to be pushed onto the stack corresponding to the currently predicted hit call instruction is the same as the return address pointed to by the return pointer in the return address stack, maintaining the positions pointed to by the return pointer and the call pointer of the return address stack, and updating the recursive call record table so that the number of execution times of the return address pointed to by the return pointer in the recursive call record table is incremented by 1, without the need to repeatedly store the corresponding return address into the return address stack, thereby reducing the excessive occupation of storage resources and reducing the overhead of instruction processing.

[0062] Meanwhile, since the embodiments of the present application do not need to repeatedly store the corresponding return address to the return address stack, more available resources can be provided for other instructions, avoiding adverse effects on the prediction accuracy of other branch instructions.

[0063] In an alternative implementation, referring to Figure 7 the optional flowchart of an instruction processing method provided by the embodiments of the present application shown in

[0064] Step S100: Obtain the return address to be pushed onto the stack corresponding to the currently predicted hit call instruction;

[0065] Wherein, the return address to be pushed onto the stack is the return address corresponding to the currently predicted hit call instruction, and the return address is the instruction address of the return instruction corresponding to the call instruction.

[0066] When predicting that a branch instruction is a call instruction, it is necessary to update the instruction address of the return instruction corresponding to the call instruction to the return address stack, so that the subsequent predicted return instruction controls the subsequent execution flow based on the return address updated to the return address stack. Correspondingly, obtain the return address to be pushed onto the stack corresponding to the currently predicted hit call instruction to perform the update of the return address stack.

[0067] In a specific example, the instruction address may be a linear address. When predicting that the instruction corresponding to a certain linear address is a call instruction (i.e., the call branch type), the linear address can be obtained, and the linear address plus 1 can be used as the corresponding return address to be pushed onto the stack.

[0068] Step S110: Determine whether the return address to be pushed onto the stack is the same as the return address pointed to by the return pointer in the return address stack;

[0069] The return address stack is used to sequentially store the return addresses corresponding to the call instructions. Among them, in the return address stack, the call pointer can sequentially indicate the storage position of the return address, and the return pointer can sequentially indicate the position of the return address to be retrieved. The return pointer and the call pointer indicate the return address based on pointing to an entry in the return address stack.

[0070] Specifically, relative to the currently obtained return address to be pushed onto the stack, the return pointer is used to point to the return address that was most recently stored in the return address stack. After obtaining a new return address to be pushed onto the stack, it is possible to determine whether the return address to be pushed onto the stack is the same as the return address that was most recently stored in the return address stack, thereby determining how to update the return address stack.

[0071] Among them, the return address stack is a last-in-first-out data structure for storing return addresses. When storing a return address, the return pointer points to the entry corresponding to the most recently stored return address, that is, the entry corresponding to the previous return address stored in the return address stack.

[0072] Specifically, it is possible to determine whether the return address to be pushed onto the stack is the same as the return address pointed to by the return pointer in the return address stack. If they are the same, there is no need to re-store the return address to be pushed onto the stack into the return address stack. Instead, step S120 is executed to update the recursive call record table to increase the read count of the entry corresponding to the return address pointed to by the return pointer. If they are different, step S130 is executed to store the return address to be pushed onto the stack into the return address stack.

[0073] Step S120: Keep the positions pointed to by the return pointer and the call pointer of the return address stack, and update the recursive call record table;

[0074] The recursive call record table is used to record the number of times each return address in the return address stack needs to be read. Thus, based on the recursive call record table, multiple consecutive identical return addresses can be recorded in the same entry, saving the storage space of the return address stack and reducing the hardware overhead of the instruction processing for the return address stack.

[0075] Furthermore, by updating the recursive call record table, the read count of the return address pointed to by the return pointer in the recursive call record table is incremented by 1. As a result, when the return address is subsequently read, the instruction processing flow corresponding to it can be controlled based on the read count of the return address recorded in the updated recursive call record table. After the corresponding return address has been read the corresponding number of times, the return address stored in the next entry of the return address stack is read.

[0076] In the corresponding example, the process of updating the recursive call record table may include: searching for the entry corresponding to the return pointer in the recursive call record table; and incrementing the value of the counter in the corresponding entry by 1.

[0077] It can be understood that the entries in the recursive call record table can correspond one-to-one with the entries in the return address stack to record the read counts of the entries in the return address stack. For example, the return address stack may include 2 n entries. Correspondingly, the recursive call record table also includes 2 n entries. Each entry in the recursive call record table can correspond to the entries in the return address stack based on the identification information or address information of the entries in the return address stack.

[0078] Among them, the return pointer and the call pointer are based on the pointing identifiers that mark each entry of the return address stack. The pointing identifier can be, for example, the identifier information or the address information of each entry of the return address stack. When the return address stack can include 2 n entries, the pointing identifier can be n bits. Correspondingly, referring to Figure 8 FIG. shown is an optional structural schematic diagram of a recursive call record table provided by an embodiment of the present application. In the recursive call record table, the entries in the return address stack can be marked based on the pointing identifier (such as identifier information or address information). When it is necessary to find the entry corresponding to the return pointer in the recursive call record table, the entry corresponding in the recursive call record table can be obtained by indexing based on the pointing identifier of the return pointer.

[0079] Continue to refer to Figure 8 , in the recursive call record table, each entry can be correspondingly configured with a multi-bit counter. The counter can record the corresponding number of times of being read. Correspondingly, the number of times of being read of the return address pointed to by the return pointer in the recursive call record table is incremented by 1, specifically, the value of the counter in the corresponding entry is incremented by 1.

[0080] It can be understood that when the return address to be pushed onto the return address stack is the same as the return address pointed to by the return pointer in the return address stack, the return address to be pushed onto the stack is no longer stored in a new entry. Correspondingly, the positions pointed to by the return pointer and the call pointer corresponding to the return address stack do not need to be updated, but the positions originally pointed to by the return pointer and the call pointer of the return address stack are maintained.

[0081] Step S130: Store the return address to be pushed onto the stack into the return address stack, and update the positions pointed to by the call pointer and the return pointer based on the position where the return address to be pushed onto the stack is stored;

[0082] It can be understood that when the return address to be pushed onto the stack is different from the return address pointed to by the return pointer in the return address stack, the return address stack is normally updated, that is, the return address to be pushed onto the stack is stored in the return address stack, and the positions pointed to by the call pointer and the return pointer are updated based on the position where the return address to be pushed onto the stack is stored.

[0083] In a specific example, storing the return address to be pushed onto the stack into the return address stack is specifically to store the return address to be pushed onto the stack in the entry pointed to by the call pointer. Correspondingly, updating the positions pointed to by the call pointer and the return pointer is specifically to configure the call pointer to point to the next entry of the original position (which can be the call pointer incremented by 1 in a specific example), and configure the return pointer to point to the entry storing the return address to be pushed onto the stack, that is, the next entry of the original position (which can be the return pointer incremented by 1 in a specific example).

[0084] In an alternative implementation, referring to Figure 9 the alternative flowchart of another instruction processing method provided by the embodiments of the present application shown in the figure, the embodiments of the present application provide an instruction processing method, which is applied to the scenario where a return instruction is predicted. The method includes:

[0085] Step S200: When the currently predicted hit instruction is a return instruction, determine the return address pointed to by the return pointer in the return address stack;

[0086] It can be understood that in the processing flow of a subroutine call instruction, the call instruction and the return instruction are a corresponding pair of instructions. At the same time, in the case of multiple calls, the call instruction and the return instruction are nested between the previous call instruction and the return instruction. Correspondingly, after a call instruction appears, the subsequent return instruction can be predicted. And when the currently predicted hit instruction is a return instruction, the corresponding return address to be read can be read from the return address stack.

[0087] Based on the return address stack, the return pointer can sequentially indicate the return address to be read. Therefore, the return address to be read can be determined based on the pointing position of the return pointer.

[0088] Step S210: Read the return address pointed to by the return pointer and update the recursive call record table, so that the number of times the return address pointed to by the return pointer recorded in the recursive call record table is read is decreased by 1;

[0089] Among them, after determining the return address to be read, the return address pointed to by the return pointer can be read. It should be noted that different from the corresponding return address taken out (read and delete the data at the original position) in the foregoing solution, when the number of times the return address is read is not 0, the return address still needs to be read again. Therefore, in this step, only the return address is read after confirmation, and the data at the original position is not deleted.

[0090] It can be understood that the recursive call record table records the number of times each return address in the return address stack needs to be read. Therefore, after the return address is read once, the number of times the return address needs to be read recorded in the recursive call record table is decreased by 1.

[0091] Correspondingly, in a specific example, the process of updating the recursive call record table may include: searching for the entry corresponding to the return pointer in the recursive call record table; decreasing the value of the counter in the corresponding entry by 1.

[0092] Based on the one-to-one correspondence between the entries in the recursive call record table and the entries in the return address stack, an entry corresponding to the return address can be found in the recursive call record table, and then the update of the corresponding read count can be performed.

[0093] When the recursive call record table marks the entries in the return address stack based on a pointing identifier (such as identification information or address information), the finding of the entry corresponding to the return pointer in the recursive call record table is specifically to index the entry corresponding in the recursive call record table based on the pointing identifier of the return pointer.

[0094] In the recursive call record table, each entry can be correspondingly configured with a multi-bit counter, and this counter can record the corresponding read count. Correspondingly, the reduction of the read count of the return address pointed to by the return pointer in the recursive call record table is specifically the value of the counter in the corresponding entry

[0095] minus 1.

[0096] It can be understood that based on the information recorded in the updated recursive call record table, it can be determined whether to update the return address stack. Specifically, after updating the recursive call record table, when the read count of the return address pointed to by the return pointer is greater than 0, step S220 is executed to enable the return address to be still read; after updating the recursive call record table, when the read count of the return address pointed to by the return pointer is equal to 0, step S230 is executed to enable the return pointer to point to the next return address.

[0097] Step S220: Keep the positions pointed to by the return pointer and the call pointer of the return address stack so that the return address pointed to by the return pointer is continuously read;

[0098] After updating the recursive call record table, when the read count of the return address pointed to by the return pointer is greater than 0, it indicates that the return address pointed to by the return pointer still needs to be read in subsequent steps. Therefore, keep the positions pointed to by the return pointer and the call pointer of the return address stack so that the return address pointed to by the return pointer is continuously read.

[0099] Step S230: Update the positions pointed to by the call pointer and the return pointer based on the position where the return address is stored;

[0100] After updating the recursive call record table, if the read count of the return address pointed to by the return pointer is equal to 0, it indicates that the return address pointed to by the return pointer does not need to be read anymore. Therefore, by updating the positions pointed to by the call pointer and the return pointer, the subsequent process can read the next return address in the return address stack.

[0101] Updating the positions pointed to by the call pointer and the return pointer may specifically be configuring the call pointer to point to the entry of the read return address, that is, the previous entry of the original position (which may be the call pointer minus 1 in a specific example); configuring the return pointer to point to the previous entry of the original position (which may be the return pointer minus 1 in a specific example).

[0102] In an alternative example, after step S230 updates the positions pointed to by the call pointer and the return pointer, it further deletes the return address in the entry pointed to by the call pointer.

[0103] It can be understood that based on the foregoing, only the corresponding return data is read, so that the data in the entry pointed to by the call pointer is still the read return address. Based on this, the read count of the return address has reached zero, and at this time, the return address of this entry no longer needs to be read. By deleting this part of the data, it is convenient to write new return addresses subsequently.

[0104] In a further alternative example, it is also possible not to delete this part of the data, but to overwrite the original return address stored in this entry when a return address needs to be written to this entry. The present application does not make specific limitations here.

[0105] It can be understood that the solution provided in the embodiments of the present application can avoid excessive occupation of the return data stack entries caused by multiple repeated recursive calls resulting in multiple storage of return addresses; at the same time, based on the fact that the data in the return data stack will overwrite the existing data when it is full, the embodiments of the present application can further prevent the repeated data stored multiple times from occupying the return data stack and causing the existing data in the return data stack to be overwritten. Thus, to a certain extent, it improves the accuracy of instruction prediction while also preventing some specific security attacks on the processor.

[0106] The embodiments of the present application also provide a processor, which is used to execute an instruction processing method provided in the embodiments of the present application, and to execute another instruction processing method provided in the embodiments of the present application.

[0107] The embodiments of the present application also provide a chip, which may include the above-mentioned processor.

[0108] The embodiments of the present application also provide an electronic device, which may include the above-mentioned chip.

[0109] The above describes multiple embodiment solutions provided in the embodiments of the present application. The various alternative ways described in each embodiment solution can be combined and cross-referenced with each other without conflict, thereby extending a variety of possible embodiment solutions, all of which can be considered as the embodiment solutions disclosed and made public in the embodiments of the present application.

[0110] Although the embodiments of the present application are disclosed as above, the present application is not limited thereto. Any person skilled in the art can make various changes and modifications without departing from the spirit and scope of the present application. Therefore, the protection scope of the present application shall be subject to the scope defined by the claims.

Claims

1. An instruction processing method, characterized in that, including: obtaining a return address to be pushed onto the stack corresponding to a currently predicted hit call instruction, where the return address to be pushed onto the stack is the return address corresponding to the currently predicted hit call instruction, and the return address is the instruction address of the return instruction corresponding to the call instruction; determining whether the return address to be pushed onto the stack is the same as the return address pointed to by the return pointer in the return address stack; the return address stack is used to sequentially store the return addresses, and the return pointer is used to point to the most recently stored return address in the return address stack; if so, maintaining the positions pointed to by the return pointer and the call pointer of the return address stack, and updating a recursive call record table such that the read count of the return address pointed to by the return pointer recorded in the recursive call record table is incremented by 1; the recursive call record table is used to record the number of times the return instructions corresponding to each return address in the return address stack need to be read.

2. The instruction processing method according to claim 1, wherein The updating of the recursive call record table includes: finding an entry in the recursive call record table corresponding to the return pointer; incrementing the value of the counter in the corresponding entry by 1.

3. The instruction processing method according to claim 2, wherein The finding of the entry in the recursive call record table corresponding to the return pointer is specifically based on the pointing identifier index of the return pointer to obtain the corresponding entry in the recursive call record table; wherein, the recursive call record table marks the entries in the return address stack based on the pointing identifier.

4. The instruction processing method according to claim 1, characterized in that, After determining whether the return address to be pushed onto the stack is the same as the return address pointed to by the return pointer in the return address stack, it further includes: if not, storing the return address to be pushed onto the stack in the return address stack, and updating the positions pointed to by the call pointer and the return pointer based on the storage position of the return address to be pushed onto the stack.

5. The instruction processing method according to claim 4, wherein The updating of the positions pointed to by the call pointer and the return pointer based on the storage position of the return address to be pushed onto the stack includes: configuring the call pointer to point to the next entry of the original position, and configuring the return pointer to point to the entry storing the return address to be pushed onto the stack.

6. An instruction processing method, characterized in that, including: when the currently predicted hit instruction is a return instruction, determining the return address pointed to by the return pointer in the return address stack; reading the return address pointed to by the return pointer, and updating the recursive call record table such that the read count of the return address pointed to by the return pointer recorded in the recursive call record table is decremented by 1; after updating the recursive call record table, if the read count of the return address pointed to by the return pointer is greater than 0, maintaining the positions pointed to by the return pointer and the call pointer of the return address stack such that the return address pointed to by the return pointer is continuously read.

7. The instruction processing method according to claim 6, characterized in that, The updating of the recursive call record table includes: finding an entry in the recursive call record table corresponding to the return pointer; decrementing the value of the counter in the corresponding entry by 1.

8. The instruction processing method according to claim 7, wherein The finding of the entry in the recursive call record table corresponding to the return pointer is specifically based on the pointing identifier index of the return pointer to obtain the corresponding entry in the recursive call record table; wherein, the recursive call record table marks the entries in the return address stack based on the pointing identifier.

9. The instruction processing method according to claim 6, wherein It further includes: After updating the recursive call record table, if the number of times the return address pointed to by the return pointer is read is equal to 0, update the positions pointed to by the call pointer and the return pointer based on the storage position of the return address.

10. The instruction processing method according to claim 9, characterized in that, The updating the positions pointed to by the call pointer and the return pointer based on the storage position of the return address includes: Configure the call pointer to point to the entry of the read return address; Configure the return pointer to point to the entry previous to the original position.

11. The instruction processing method according to claim 9, characterized in that, After updating the positions pointed to by the call pointer and the return pointer based on the storage position of the return address, further include: Delete the return address in the entry pointed to by the call pointer before the recursive call record table is updated.

12. A processor, characterized in that, The processor is used to execute the instruction processing method according to any one of claims 1 to 5, and execute the instruction processing method according to any one of claims 6 to 11.

13. A chip, characterized in that, Comprising a processor as claimed in claim 12.

14. An electronic device, characterized in that, Comprising a chip as claimed in claim 13.