Instruction processing method, processor, chip and electronic device
Patent Information
- Application Number
- CN202510770206.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-10
- Publication Date
- 2026-09-15
- Estimated Expiration
- 2045-06-10
AI Technical Summary
[0003]然而,现有的指令处理流程,指令处理的开销较大
[0046] The present invention provides an instruction processing method, processor, chip, and electronic device. The method includes: obtaining the pending stack return address corresponding to a currently predicted hit call instruction, wherein the pending stack return address is used to indicate the instruction address of the return instruction corresponding to the call instruction; determining whether the type of the call instruction is a recursive call instruction; if the call instruction is a recursive call instruction, storing the pending stack return address into a recursive address stack and updating the recursive call record table of the recursive address stack; if the call instruction is not a recursive call instruction, storing the pending stack return address into a normal address stack; wherein the recursive call record table is used to record the number of times the return instruction corresponding to each return address in the recursive address stack needs to return.
Smart Images

Figure CN120704743B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of processor technology, specifically to instruction processing methods, processors, chips, and electronic devices. Background Technology
[0002] In modern processors, instructions need to go through processes such as fetching, decoding, and execution. Fetching is used to obtain the instruction to be executed, decoding is used to parse and translate the fetched instruction to obtain the corresponding micro-instruction (micro-op, Uop), and execution is used to execute the corresponding instruction operation based on the micro-instruction obtained by decoding.
[0003] However, the existing instruction processing flow has a large overhead. Summary of the Invention
[0004] In view of this, embodiments of this application provide an instruction processing method, processor, chip, and electronic device to reduce the overhead of instruction processing.
[0005] To achieve the above objectives, the embodiments of this application provide the following technical solutions.
[0006] In a first aspect, embodiments of this 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, wherein the return address to be pushed onto the stack is used to indicate the instruction address of the return instruction corresponding to the call instruction;
[0008] Determine whether the type of the invocation instruction is a recursive invocation instruction;
[0009] If the calling instruction is a recursive calling instruction, the return address to be pushed onto the stack is stored in the recursive address stack, and the recursive calling record table of the recursive address stack is updated; if the calling instruction is not a recursive calling instruction, the return address to be pushed onto the stack is stored in the ordinary address stack; wherein, the recursive calling record table is used to record the number of times the return instruction corresponding to each return address in the recursive address stack needs to be executed.
[0010] Optionally, determining whether the type of the invocation instruction is a recursive invocation instruction includes:
[0011] Determine the target return address in the address stack, wherein the target return address is the previous return address stored in the address stack, and the address stack includes a recursive address stack and a normal address stack;
[0012] Determine whether the return address to be pushed onto the stack is the same as the target return address;
[0013] If they are the same, the calling instruction is a recursive calling instruction; if they are different, the calling instruction is not a recursive calling instruction.
[0014] Optionally, the target return address is the return address within the recursive address stack, and updating the recursive call record table of the recursive address stack includes:
[0015] Find the entry in the recursive call record table that corresponds to the recursive return pointer;
[0016] Increment the value of the counter in the corresponding entry by 1.
[0017] Optionally, the target return address is a return address within the normal address stack, and the step of transferring the target return address to the recursive address stack and updating the recursive call record table includes:
[0018] Read the target return address from the normal address stack, and update the pointer information of the normal call pointer and normal return pointer in the normal address stack;
[0019] Store the target return address into the entry pointed to by the recursive call pointer in the recursive address stack, and update the pointing information of the recursive call pointer;
[0020] Configure the execution count value corresponding to the entry of the return address to be pushed onto the stack in the recursive call record table as an initial value.
[0021] Optionally, updating the pointer information of the ordinary call pointer and the ordinary return pointer in the ordinary address stack includes:
[0022] Configure the current pointer of the normal call pointer to point to the previous entry at the original position, and configure the current pointer of the normal return pointer to point to the previous entry at the original position.
[0023] In addition, the forward pointer information of the normal call pointer and the backward pointer information of the normal return pointer are configured as the location where the target return address is stored in the recursive address stack;
[0024] The preceding pointing information is used to indicate the entry corresponding to the previous node of the current pointing information; the following pointing information is used to indicate the entry corresponding to the next node of the current pointing information.
[0025] Optionally, updating the pointer to the recursive call includes:
[0026] Configure the recursive call pointer to point to the next entry at the original position, and configure the recursive return pointer to point to the next entry at the original position;
[0027] In addition, the preceding pointer information of the recursive return pointer is configured to be the entry pointed to by the ordinary return pointer of the ordinary address stack;
[0028] Configure the execution count value corresponding to the entry of the return address to be pushed onto the stack in the recursive call record table as an initial value.
[0029] Optionally, storing the return address to be pushed onto the stack into a normal address stack includes:
[0030] Store the return address to be pushed onto the stack in the entry pointed to by the normal call pointer;
[0031] Configure the current pointer of the normal call pointer to point to the next entry at the original position, and configure the current pointer of the normal return pointer to point to the entry where the return address to be pushed onto the stack is located;
[0032] Configure the preceding pointer information of the normal call pointer and the following pointer information of the normal return pointer as the entry where the target return address is located.
[0033] Optional, also includes:
[0034] Configure alternative pointer information for the ordinary return pointer; the alternative pointer information is used to indicate the location of the previous return address in the ordinary address stack.
[0035] Secondly, embodiments of the present invention provide another instruction processing method, including:
[0036] When the currently predicted hit instruction is a return instruction, the return address to be read is determined from the recursive address stack and the normal address stack; wherein, the return address to be read is the return address whose storage timing is closest to the current moment.
[0037] If the return address to be read is located in the normal address stack, read the return address to be read; if the return address to be read is located in the recursive address stack, read the return address to be read and update the recursive call record table so that the number of times the return address to be read is executed recorded in the recursive call record table indicates the remaining number of times the return address to be read will be executed after it has been read.
[0038] Optionally, the update recursive call record table includes:
[0039] Find the entry in the recursive call record table that corresponds to the recursive return pointer;
[0040] Decrease the value of the counter in the corresponding entry by 1.
[0041] Optionally, after updating the recursive call record table, the method further includes:
[0042] If the remaining number of executions at the return address to be read, pointed to by the recursive return pointer, is greater than 0, the positions pointed to by the recursive return pointer and the recursive call pointer in the recursive address stack are maintained so that the return address pointed to by the recursive return pointer can continue to be executed; if the remaining number of executions at the return address to be read, pointed to by the recursive return pointer, is equal to 0, the positions pointed to by the recursive call pointer and the recursive return pointer are updated based on the storage position of the return address to be read.
[0043] Thirdly, embodiments of the present invention also provide a processor, the processor being configured to execute the instruction processing method provided in the first aspect of embodiments of the present invention, and to execute the instruction processing method provided in the second aspect of embodiments of the present invention.
[0044] Fourthly, embodiments of the present invention also provide a chip, including the processor provided in the third aspect of embodiments of the present invention.
[0045] Fifthly, embodiments of the present invention also provide an electronic device, including the chip provided in the fourth aspect of embodiments of the present invention.
[0046] The present invention provides an instruction processing method, processor, chip, and electronic device. The method includes: obtaining the pending stack return address corresponding to a currently predicted hit call instruction, wherein the pending stack return address is used to indicate the instruction address of the return instruction corresponding to the call instruction; determining whether the type of the call instruction is a recursive call instruction; if the call instruction is a recursive call instruction, storing the pending stack return address into a recursive address stack and updating the recursive call record table of the recursive address stack; if the call instruction is not a recursive call instruction, storing the pending stack return address into a normal address stack; wherein the recursive call record table is used to record the number of times the return instruction corresponding to each return address in the recursive address stack needs to return.
[0047] As can be seen, the instruction processing method, processor, chip, and electronic device provided in the embodiments of the present invention determine the address stack to which the return address to be pushed onto the stack is stored based on the type of the calling instruction. Specifically, when the calling instruction is a recursive calling instruction, the return address to be pushed onto the stack is stored into the recursive address stack, and the recursive call record table of the recursive address stack is updated. The recursive call record table is used to record the number of times the return instruction corresponding to each return address needs to be executed, thereby eliminating the need to repeatedly store the corresponding return address into the address stack, reducing excessive occupation of storage resources, and reducing the overhead of instruction processing.
[0048] Meanwhile, in non-recursive call instructions, the return address to be pushed onto the stack is stored in the normal address stack, thus avoiding the need to occupy the storage resources of the recursive call record table and further reducing the hardware overhead of instruction processing.
[0049] Furthermore, based on the embodiments of the present invention, it is not necessary to repeatedly store the corresponding return address on the address stack, thereby providing more available resources for other instructions and avoiding adverse effects on the prediction accuracy of other branch instructions. Attached Figure Description
[0050] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0051] Figure 1 This is a schematic diagram of an optional flow for predicting branch instructions.
[0052] Figure 2 This is a schematic diagram of the optional processing flow for a multi-call instruction.
[0053] Figure 3 An optional structure diagram for the return address stack.
[0054] Figure 4 This is another optional structure diagram for returning the address stack.
[0055] Figure 5 This is an optional structure diagram of an address stack provided in an embodiment of the present invention.
[0056] Figure 6 This is a schematic diagram illustrating pointer pointing information provided in an embodiment of the present invention.
[0057] Figure 7 An optional flowchart of an instruction processing method provided in an embodiment of the present invention.
[0058] Figure 8 An optional flowchart of another instruction processing method provided in an embodiment of the present invention.
[0059] Figure 9 This is a schematic diagram of an optional structure of a recursive call record table provided in an embodiment of the present invention.
[0060] Figure 10 This is an optional flowchart of step S120 provided in an embodiment of the present invention.
[0061] Figure 11 An optional flowchart of another instruction processing method provided in an embodiment of the present invention.
[0062] Figure 12 An optional flowchart of another instruction processing method provided in an embodiment of the present invention. Detailed Implementation
[0063] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0064] In a typical instruction processing flow, instructions usually undergo instruction fetch, instruction decode, and execution. Instruction fetch involves retrieving the instruction corresponding to the program's execution from the processor's cache or main memory; the decoding operation involves decoding the fetched instruction to determine its opcode and / or address code; and the execution operation involves executing the instruction based on the obtained opcode and / or address code to run the program. Processors typically use instruction pipeline technology to implement instruction processing. In this technology, different processing stages are configured with different hardware modules, and multiple instructions at different processing stages can be processed and flow sequentially within their corresponding hardware modules during the processor's pipelined operation.
[0065] However, when processing branch instructions, a branch prediction mechanism is needed to reduce instruction latency. It's 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 flows) based on different instruction results, as shown in the reference. Figure 1 The diagram illustrates an optional flow for branch instruction prediction. Branch instruction N needs to enter different branch flows, namely branch N1 and branch N2, based on the result of instruction M. If the instruction is executed according to normal logic, it needs to wait for the result of instruction M, such as result M1 or result M2. However, in processor pipeline operations, multiple instructions at different processing stages are processed simultaneously within different hardware logic. The delay of one instruction can block the processing of multiple other instructions in the subsequent pipeline, thus causing pipeline delay. To reduce pipeline delay caused by the processor waiting for the result of a branch instruction to determine the next instruction fetch, a branch prediction mechanism can be used to predetermine which instruction will be executed next (e.g., ...). Figure 1 The branch Ni shown (where i can be 1 or 2) reduces the processor's waiting time when executing branch instructions.
[0066] In one optional prediction mechanism, prediction can be made based on the target address of the branch instruction. Specifically, the address of the branch instruction and its corresponding target address are stored in a BTB (Branch Target Buffer), thereby predicting the branch instruction based on this target address. Furthermore, for subroutine call instructions within the branch instructions, the return address stack is configured to further improve the accuracy of instruction prediction.
[0067] Specifically, subroutine call instructions process instructions by calling subroutines. Subroutine call instructions include call instructions (CALL) and return instructions (RET). Call instructions are used to enter a subroutine, and return instructions are used to return from a subroutine. Therefore, call instructions and return instructions are a corresponding set of instructions.
[0068] When a subroutine call involves double calls, the corresponding set of call and return instructions can be nested between the previous set of call and return instructions; similarly, when multiple calls exist, refer to... Figure 2 The diagram illustrates an optional processing flow for multiple call instructions, where multiple sets of call instructions and return instructions are executed nested sequentially, such as... Figure 2 Call instruction 2 and return instruction 2 are embedded between call instruction 1 and return instruction 1, and call instruction 3 and return instruction 3 are embedded between call instruction 2 and return instruction 2. Specifically, the call instructions are executed in nested order, and the instruction addresses of the corresponding return instructions (hereinafter referred to as return addresses) can be stored sequentially in the return address stack according to the corresponding nested order. When a return instruction needs to be executed, the corresponding return address is retrieved from the return address stack in a last-in-first-out order, and the corresponding return instruction is executed based on the return address.
[0069] Accordingly, refer to Figure 3 The diagram shows an optional structure of the return address stack, which stores the instruction address of the return instruction corresponding to the calling instruction (hereinafter referred to as the return address). The return address stack is configured with a call pointer (Call Ptr) and a return pointer (Retn Ptr). The call pointer points to the entry where the return address will be stored (i.e., the empty entry adjacent to the latest stored return address entry), and the return pointer points to the entry where the return address will be retrieved (i.e., the entry containing the return address adjacent to the empty entry).
[0070] Specifically, when the predicted branch instruction is a call instruction (CALL) and a hit occurs, the return address corresponding to the call instruction (usually the linear address of the current call instruction plus 1, i.e., the next instruction after the current call instruction) can be pushed onto the entry pointed to by the call pointer on the stack; when the predicted branch instruction is a return instruction (RET), the return address in the entry pointed to by the current return pointer can be retrieved as the target address.
[0071] However, this instruction processing flow incurs significant overhead. To address this issue, the inventors suggest simplifying repetitive information within multi-loop instructions to reduce processing overhead.
[0072] Specifically, the inventors believe that when dealing with multi-loop instructions (e.g., recursive call instructions with multiple loops, which are a special type of subroutine call instruction), the return address corresponding to the call address is the same address. Consequently, the processing flow repeatedly writes the same return address into the return address stack, resulting in multiple entries in the return address stack being written with duplicate information. This duplicate information consumes excessive storage resources, leading to excessive overhead in instruction processing. Furthermore, because this duplicate information consumes excessive storage resources, it also crowds out the available resources for other instructions, potentially adversely affecting the prediction accuracy of other branch instructions.
[0073] Accordingly, the inventors further considered configuring a recursive call record table for the return address stack. This recursive call record table can record the number of times the return instruction corresponding to each return address in the recursive address stack needs to return, thus allowing repeated return addresses corresponding to recursive calls to be stored in a single entry without consuming excessive storage resources. In an optional implementation, refer to... Figure 4 The diagram shows another optional structure of the return address stack. The recursive call record table can be configured with a cnt value for each entry (in the diagram, cnt0, cnt1...cntn) to record the number of times the return instruction corresponding to the return address needs to return. When the cnt value is non-zero in an entry that needs to be read in the return address stack, the return address in that entry can be read repeatedly, and the cnt value can be decremented by 1 until the cnt value is 0.
[0074] However, in actual instruction processing, the probability of recursive call instructions is relatively small. Accordingly, the inventors believe that other solutions can be considered to further reduce hardware overhead.
[0075] In view of this, embodiments of the present invention provide an instruction processing method, a processor, a chip, and an electronic device. The method includes: obtaining the pending stack return address corresponding to a currently predicted hit call instruction, wherein the pending stack return address is used to indicate the instruction address of the return instruction corresponding to the call instruction; determining whether the type of the call instruction is a recursive call instruction; if the call instruction is a recursive call instruction, storing the pending stack return address into a recursive address stack and updating the recursive call record table of the recursive address stack; if the call instruction is not a recursive call instruction, storing the pending stack return address into a normal address stack; wherein the recursive call record table is used to record the number of times the return instruction corresponding to each return address in the recursive address stack needs to return.
[0076] As can be seen, the instruction processing method, processor, chip, and electronic device provided in the embodiments of the present invention determine the address stack to which the return address to be pushed onto the stack is stored based on the type of the calling instruction. Specifically, when the calling instruction is a recursive calling instruction, the return address to be pushed onto the stack is stored into the recursive address stack, and the recursive call record table of the recursive address stack is updated. The recursive call record table is used to record the number of times the return instruction corresponding to each return address needs to be executed, thereby eliminating the need to repeatedly store the corresponding return address into the address stack, reducing excessive occupation of storage resources, and reducing the overhead of instruction processing.
[0077] Meanwhile, in non-recursive call instructions, the return address to be pushed onto the stack is stored in the normal address stack, thus avoiding the need to occupy the storage resources of the recursive call record table and further reducing the hardware overhead of instruction processing.
[0078] Furthermore, based on the embodiments of the present invention, it is not necessary to repeatedly store the corresponding return address on the address stack, thereby providing more available resources for other instructions and avoiding adverse effects on the prediction accuracy of other branch instructions.
[0079] In one alternative implementation, refer to Figure 5 The diagram shown is an optional structure diagram of an address stack provided by an embodiment of the present invention. The address stack provided by the embodiment of the present invention may include a recursive address stack and a normal address stack. The recursive address stack is used to store the return address corresponding to the recursive call instruction, and the normal address stack is used to store the return address corresponding to the normal recursive instruction of the non-recursive call instruction.
[0080] The recursive address stack is configured with a recursive call record table, which records the number of times the return instruction corresponding to each return address in the recursive address stack needs to return. In a specific example, for any entry in the recursive address stack, the recursive call record table can be configured with a corresponding counter cnt. This counter cnt records the number of times the return instruction corresponding to each return address in the recursive address stack needs to return (i.e., the number of times it is continuously stored in the recursive address stack), so that repeated return addresses corresponding to recursive calls can be stored in one entry without occupying excessive storage resources.
[0081] It is understandable that entries in the address stack (including recursive and normal address stacks) are accessed based on a last-in, first-out (LIFO) mechanism, meaning they are read in reverse order of their insertion. In specific implementations, the address stack uses pointers to indicate the order in which the return address is accessed.
[0082] In the optional implementation, refer to Figure 6 The diagram illustrates the pointer information. The pointers in the address stack can be a doubly linked list structure. That is, the pointer at a node simultaneously includes information pointing to the previous node and information pointing to the next node. Taking the pointer of node d1 as an example, it points to the previous node head on one hand and to the next node d2 on the other.
[0083] In a concrete implementation, the pointer's pointing information can include preceding and following pointer information, as well as current pointer information. The current pointer information indicates the entry the pointer currently points to, the preceding pointer information indicates the entry corresponding to the node preceding the current pointer, and the following pointer information indicates the entry corresponding to the node following the current pointer. It should be noted that since the calling pointer and the returning pointer execute in opposite directions, their corresponding preceding and following pointer information are reversed. For example, the calling pointer can execute from the head node to the dn node, while the returning pointer retreats from the dn node back to the head node. Accordingly, the calling pointer's preceding pointer information indicates the direction from the head node to the dn node, and its following pointer information indicates the direction from the dn node to the head node; similarly, the returning pointer's preceding pointer information indicates the direction from the dn node to the head node, and its following pointer information indicates the direction from the head node to the dn node.
[0084] Understandably, pointers based on a doubly linked list structure can completely record the storage order of return addresses in the address stack, and then determine the reading order of return addresses based on the reverse of this storage order. Furthermore, based on the doubly linked list structure, if an instruction prediction error occurs, a rollback can be performed based on the error point. Consequently, in the instruction processing flow, only the pointer needs to be modified and a new doubly linked list structure formed, without needing to flush the address stack, thus reducing the overhead of instruction errors.
[0085] For details, please refer to [link / reference]. Figure 5 The pointers configured in the recursive address stack can be a recursive call pointer (DutyCall Ptr) and a recursive return pointer (DutyRetn Ptr). The recursive call pointer is used to indicate the position that is about to be pushed onto the recursive address stack (i.e., the current pointer information), and the recursive return pointer is used to indicate the position of the return address that is about to be retrieved from the recursive address stack (i.e., the current pointer information).
[0086] In this context, based on the processing logic of the call instruction, the current pointer of the recursive return pointer always points to the entry corresponding to the latest return address stored in the recursive address stack. Therefore, based on the rule that the recursive address stack stores return addresses sequentially from bottom to top, it can be understood that the entry storing the return address corresponding to the call instruction is the next entry after the entry of the return address to be retrieved (positionally, it can be considered as the entry above the entry of the return address to be retrieved). Thus, in the recursive address stack, the entry pointed to by the current pointer of the recursive call pointer is usually the next entry after the entry pointed to by the recursive return pointer, while the entry pointed to by the current pointer of the recursive return pointer is usually the previous entry (positionally, it can be considered as the entry below the entry of the return address to be retrieved).
[0087] When pointers are configured in the form of a doubly linked list, the preceding information of the recursive return pointer includes the position of the previous return address pushed onto the address stack. This previous return address can be located in either the recursive address stack or the normal address stack. In other words, when there is cross-site storage between the normal address stack and the recursive address stack, the preceding information of the recursive return pointer can record the corresponding position information, allowing the pointer to return from the recursive address stack to the corresponding position in the normal address stack based on this preceding information.
[0088] Conversely, the pointers configured in the ordinary address stack can be ordinary call pointers (Call Ptr) and ordinary return pointers (Retn Ptr). The ordinary call pointer is used to indicate the position that is about to be pushed onto the ordinary address stack (i.e., the position of the current pointing information), and the ordinary return pointer is used to indicate the position that is about to be retrieved from the return address (i.e., the position of the current pointing information).
[0089] In this context, based on the processing logic of the call instruction, the current pointer of the ordinary return pointer always points to the entry corresponding to the most recently stored return address in the ordinary address stack. Therefore, based on the rule that the ordinary address stack stores return addresses sequentially from bottom to top, it can be understood that the entry storing the return address corresponding to the call instruction is the next entry after the entry of the return address to be retrieved (positionally, it can be considered the entry above the entry of the return address to be retrieved). Thus, in the ordinary address stack, the entry pointed to by the current pointer of the ordinary call pointer is usually the next entry after the entry pointed to by the current pointer of the ordinary return pointer, while the entry pointed to by the current pointer of the ordinary return pointer is usually the previous entry (positionally, it can be considered the entry below the entry of the return address to be retrieved).
[0090] When pointers are configured in the form of a doubly linked list, the preceding information of the ordinary return pointer specifies the position of the previous return address pushed onto the address stack. This previous return address can be located in either the ordinary address stack or the recursive address stack. In other words, when there is cross-site storage between the recursive and ordinary address stacks, the preceding information of the ordinary return pointer can record the corresponding position information, allowing the pointer to return from the ordinary address stack to the corresponding position in the recursive address stack based on this preceding information.
[0091] In a further optional example, the ordinary return pointer may also be configured with alternative pointing information, which is used to indicate the position of the previous return address in the ordinary address stack. Taking the ordinary return pointer pointing to entry n in the ordinary address stack as an example, the alternative pointing information is used to indicate the entry n-1 below entry n.
[0092] Understandably, in the event of a malicious attack that pollutes the RAS (Recurrent Access System) through recursive calls to obtain data cache information, a feasible approach is to revert to the instruction processing flow before the recursive call. This could be achieved by disabling recursion in hardware or flushing the recursive call. However, by configuring alternative pointer information, a jump can be made from the return address of a normal address stack to the return address of the previous normal address stack based on the corresponding pointer information. This allows for adjustment of the instruction processing flow solely based on the pointer's pointer information, significantly reducing instruction overhead compared to disabling or flushing recursion in hardware.
[0093] In one alternative implementation, refer to Figure 7 The illustrated flowchart represents an optional instruction processing method provided by an embodiment of the present invention. This embodiment provides an instruction processing method applied to a scenario where a call instruction is predicted. The method includes:
[0094] Step S100: Obtain the return address to be pushed onto the stack corresponding to the currently predicted hit call instruction;
[0095] The return address to be pushed onto the stack is used to indicate the address of the return instruction corresponding to the call instruction.
[0096] When the predicted branch instruction is a call instruction, the address of the return instruction corresponding to the call instruction needs to be updated on the address stack. This ensures that subsequent predicted return instructions control the subsequent execution flow based on the updated return address on the address stack. Accordingly, the return address to be pushed onto the stack corresponding to the currently predicted call instruction is obtained, and the update of that return address stack is performed.
[0097] In a specific example, the instruction address can be a linear address. When it is predicted that the instruction corresponding to a certain linear address is a call instruction (i.e., a call branch type), the linear address can be obtained and incremented by 1 to become the corresponding return address to be pushed onto the stack.
[0098] Step S110: Determine whether the type of the calling instruction is a recursive calling instruction;
[0099] The type of the calling instruction can include recursive calling instructions and normal calling instructions. The recursive calling instruction is used to indicate a calling instruction that returns to the same address. The normal calling instruction can be understood as other calling instructions that are not recursive calling instructions.
[0100] In an optional example, the type of the calling instruction can be determined based on the previous return address stored in the address stack. With the previous return address stored in the address stack as the target return address, it can be determined whether the calling instruction is a recursive calling instruction by judging whether the return address to be pushed onto the stack is the same as the target return address. If they are the same, the calling instruction is a recursive calling instruction; if they are different, the calling instruction is not a recursive calling instruction.
[0101] In specific examples, refer to Figure 8 The illustrated flowchart shows an alternative instruction processing method provided by another embodiment of the present invention. This step can be:
[0102] Step S111: Determine the target return address in the address stack;
[0103] The target return address is the previous return address stored in the address stack, which includes a recursive address stack and a normal address stack. Correspondingly, the previous return address stored in the address stack indicates the most recently stored return address among all return addresses stored in the recursive and normal address stacks. It can be understood that the previous return address stored in the address stack can be the return address pointed to by the recursive return pointer in the recursive address stack, or the return address pointed to by the normal return pointer in the normal address stack.
[0104] In optional examples, the target return address can be confirmed based on the timing information of the stored return address or based on the pointer's pointing information. In a specific example, when the pointers to the address stack (i.e., the pointers to the recursive address stack and the normal address stack) are a doubly linked list structure, the previous return address stored in the address stack can be determined based on the pointing information indicated by the doubly linked list structure. That is, when the doubly linked list structure is configured to extend from the head to the tail in timing, the target return address is the position pointed to by the node at the tail of the doubly linked list structure.
[0105] Step S112: Determine whether the return address to be pushed onto the stack is the same as the target return address;
[0106] Specifically, the return address to be pushed onto the stack and the target return address can be compared to determine whether they are the same. If they are the same, the call instruction is a recursive call instruction, and step S120 is executed; if they are different, the call instruction is not a recursive call instruction, and step S130 is executed.
[0107] Step S120: Store the return address to be pushed onto the stack into the recursive address stack, and update the recursive call record table of the recursive address stack;
[0108] The recursive call record table is used to record the number of times each return address in the recursive address stack needs to be read. Thus, based on the recursive call record table, multiple consecutive identical return addresses can be recorded into the same entry, saving storage space in the address stack and reducing the hardware overhead of instruction processing on the address stack.
[0109] When the target return address is a return address within the recursive address stack, the return address to be pushed onto the stack can be understood as already stored in the recursive address stack. By updating the recursive call record table, the number of times the return instruction corresponding to the return address to be pushed onto the stack needs to be executed can be recorded.
[0110] Specifically, by updating the recursive call record table, the number of times the return address pointed to by the return pointer in the recursive call record table has been read is incremented by 1. This allows the corresponding instruction processing flow to be controlled based on the number of times the corresponding return address has been read in the updated recursive call record table when the return address is read subsequently. After the corresponding return address has been read a sufficient number of times, the previous return address corresponding to the return address is read based on the information pointed to by the recursive return pointer.
[0111] In a corresponding example, the process of updating the recursive call record table may include: finding the entry in the recursive call record table corresponding to the recursive return pointer; and incrementing the value of the counter in the corresponding entry by 1.
[0112] It is understood that the entries in the recursive call record table can correspond one-to-one with the entries in the recursive address stack to record the number of times each entry in the recursive address stack is read. For example, the recursive address stack may include 2 n There are 2 entries, and correspondingly, the recursive call record table also includes 2. n Each entry in the recursive call record table can be matched with the entries in the recursive address stack based on the identification or address information of each entry in the recursive address stack.
[0113] The recursive return pointer and the recursive call pointer are based on pointers that mark each entry in the return address stack. These pointers can be, for example, identifiers or address information for each entry in the recursive address stack. The return address stack can include 2... n When there are multiple entries, this pointer can be n bits. Accordingly, refer to... Figure 9 The illustrated embodiment of the present invention provides an optional structure diagram of a recursive call record table. In the recursive call record table, entries in the return address stack can be marked based on pointer identifiers (such as identifier information or address information). When it is necessary to find the entry in the recursive call record table corresponding to the recursive return pointer, the corresponding entry in the recursive call record table can be obtained based on the pointer identifier index of the recursive return pointer.
[0114] Continue to refer to Figure 9 In the recursive call record table, each entry can be configured with a multi-bit counter, which records the number of times the corresponding entry has been accessed. Accordingly, the number of times the return address pointed to by the recursive return pointer in the recursive call record table has been accessed is incremented by 1, specifically by incrementing the counter value in the corresponding entry.
[0115] It is understandable that when the target return address is a return address in the recursive address stack, the return address to be pushed onto the stack can be understood as already stored in the recursive address stack, and its corresponding pointer remains unchanged. Only the number of times the return instruction corresponding to the return address to be pushed onto the stack needs to be executed is recorded by updating the recursive call record table.
[0116] When the target return address is a return address in the normal address stack, the target return address can be transferred to the recursive address stack, and the recursive call record table can be updated to record the number of times the return instruction corresponding to the return address to be pushed onto the stack needs to be executed.
[0117] It should be noted that when the target return address is a return address in the normal address stack, since the call instruction is a recursive call instruction, that is, the return address to be pushed onto the stack is the same as the target return address, the target return address is transferred to the recursive address stack. That is, the return address to be pushed onto the stack is stored in the recursive address stack, and the target return address in the normal address stack is read out.
[0118] Specifically, when the target return address is a return address within the normal address stack, refer to Figure 10 The illustrated optional flowchart of step S120 shows that step S120 transfers the target return address to the recursive address stack, including:
[0119] Step S121: Read the target return address in the normal address stack, and update the pointing information of the normal call pointer and normal return pointer in the normal address stack;
[0120] Specifically, the target return address is read from the normal address stack to update the pointer's pointing information.
[0121] It is understandable that when cross-stack address transfer is required, the pointer information in the ordinary address stack needs to be rolled back. Accordingly, the rollback process triggered by the read process can reduce the complexity of the instruction processing flow.
[0122] Specifically, updating the pointer information of the ordinary call pointer and the ordinary return pointer in the ordinary address stack can include configuring the current pointer of the ordinary call pointer to point to the previous entry at the original position (in a specific example, this could be the call pointer being decremented by 1), and configuring the current pointer of the ordinary return pointer to point to the previous entry at the original position (in a specific example, this could be the call pointer being decremented by 1). Simultaneously, the preceding pointer information of the ordinary call pointer and the following pointer information of the ordinary return pointer can be configured to the position where the target return address is stored in the recursive address stack, thereby enabling cross-stack jumps based on the corresponding pointer information.
[0123] Step S122: Store the target return address into the entry pointed to by the recursive call pointer in the recursive address stack, and update the pointing information of the recursive call pointer;
[0124] Specifically, the target return address is stored in the entry pointed to by the recursive call pointer in the recursive address stack to realize the cross-stack transfer of the return address in the address stack.
[0125] When updating the recursive call pointer's pointing information, the recursive call pointer can be configured to point to the next entry at the original position (in a specific example, the recursive call pointer can be incremented by 1). At the same time, the recursive return pointer can be configured to point to the next entry at the original position (in a specific example, the recursive return pointer can be incremented by 1), so that the recursive return pointer points to the target return address. Meanwhile, the preceding pointing information of the recursive return pointer is configured to the entry pointed to by the ordinary return pointer of the ordinary address stack, thereby realizing cross-stack jump based on the corresponding pointing information.
[0126] Step S123: Configure the execution count value corresponding to the entry of the return address to be pushed onto the stack in the recursive call record table as an initial value;
[0127] When the target return address is a return address within the normal address stack, it indicates that there are two target return addresses. Accordingly, when updating the execution count value corresponding to the entry of the return address to be pushed onto the stack in the recursive call record table, the execution count value corresponding to the entry of the return address to be pushed onto the stack can be configured as an initial value, such as "2".
[0128] Step S130: Store the return address to be pushed onto the stack into the normal address stack;
[0129] It is understandable that when the call instruction is not a recursive call instruction, the normal address stack is updated normally. That is, the return address to be pushed onto the stack is stored in the normal address stack, and the positions pointed to by the normal call pointer and the normal return pointer are updated based on the storage position of the return address to be pushed onto the stack.
[0130] In a specific example, the return address to be pushed onto the stack is stored in the ordinary address stack. Specifically, the return address to be pushed onto the stack is stored in the entry pointed to by the ordinary call pointer. At the same time, the positions pointed to by the ordinary call pointer and the ordinary return pointer are updated. Specifically, the current pointing information of the ordinary call pointer is configured to point to the next entry at the original position (in the specific example, the call pointer can be incremented by 1), and the current pointing information of the ordinary return pointer is configured to point to the entry where the return address to be pushed onto the stack is located.
[0131] In a further example, in step S130, the target return address can also be configured based on the corresponding pointing information. Specifically, the preceding pointing information of the normal call pointer and the following pointing information of the normal return pointer can be further configured as the entry where the target return address is located, so as to indicate the previous entry of the entry pointed to by the normal return pointer.
[0132] In an optional example, alternative pointer information can be further configured for the ordinary return pointer. The alternative pointer information is used to indicate the location of the previous return address in the ordinary address stack, so as to reduce the corresponding instruction overhead by rolling back the instruction processing flow based on the alternative pointer information in the event of a malicious attack that pollutes the RAS by recursively calling to obtain data cache information.
[0133] In one alternative implementation, refer to Figure 11 The illustrated flowchart represents another optional instruction processing method provided by an embodiment of the present invention. This embodiment provides an instruction processing method applied to a scenario involving the execution of a return instruction. The method includes:
[0134] Step S200: When the currently predicted hit instruction is a return instruction, determine the return address to be read from the recursive address stack and the normal address stack;
[0135] Understandably, in the processing flow of a call instruction, the call instruction and the return instruction are a corresponding set of instructions. Furthermore, when multiple calls exist, the call and return instructions are nested between the previous call and return instructions. Accordingly, after a call instruction occurs, the subsequent return instruction can be predicted. And when the currently predicted instruction is a return instruction, the corresponding return address can be read from the address stack.
[0136] The address stack includes a recursive address stack and a normal address stack. Correspondingly, the return address to be read can be determined from the recursive address stack and the normal address stack. The return address to be read is the return address whose storage timing is closest to the current moment.
[0137] The recursive address stack is configured with a recursive return pointer, whose current pointer information indicates the return address in the recursive address stack that is closest in timing to the current time when it is stored; that is, the position in the recursive address stack where the return address is about to be retrieved. The ordinary address stack is configured with an ordinary return pointer, whose current pointer information indicates the return address in the ordinary address stack that is closest in timing to the current time; that is, the position in the ordinary address stack where the return address is about to be retrieved. Accordingly, the return address to be read can be determined based on the pointer information of the recursive return pointer and the ordinary return pointer.
[0138] In optional examples, the return address to be read can be determined based on the timing information of the return addresses pointed to by the recursive return pointer and the normal return pointer, or it can be determined based on the pointing information of the recursive return pointer and the normal return pointer. In a specific example, when the pointers of the address stack (i.e., the pointers of the recursive address stack and the normal address stack) are a doubly linked list structure, the return address to be read can be determined based on the pointing information indicated by the doubly linked list structure. That is, when the doubly linked list structure is configured to extend from the head to the tail in timing, the position pointed to by the pointer corresponding to the tail node in the doubly linked list structure is the return address to be read.
[0139] After obtaining the return address to be read, the information in the address stack can be updated based on the location of the return address. Specifically, if the return address to be read is located in the normal address stack, step S210 is executed; if the return address to be read is located in the recursive address stack, step S220 is executed.
[0140] Step S210: Read the return address to be read.
[0141] It is understandable that once the return address to be read is determined, the return address to be read can be read.
[0142] The return address to be read is located in the normal address stack, and is indicated by the normal return pointer. When reading the return address, the positions pointed to by the normal call pointer and the normal return pointer are simultaneously updated. Specifically, this step can first read the return address to be read pointed to by the current pointer of the normal return pointer, configure the normal return pointer to backtrack so that its current pointer points to the previous entry of the return address to be read (in a specific example, this can be the normal return pointer being decremented by 1), and simultaneously, the normal call pointer backtracks to the position of the return address to be read, that is, the previous entry of its original position (in a specific example, this can be the normal call pointer being decremented by 1). In other words, the normal return pointer and the normal call pointer are configured to backtrack so that the current pointer of the normal return pointer points to the previous entry of the return address to be read, and the current pointer of the normal call pointer points to the position of the return address to be read.
[0143] It should be noted that even if the current pointer of a normal return pointer points to the previous entry of the return address to be read, the node corresponding to that entry can still confirm the preceding and following pointer information, thus preventing confusion in the instruction execution order.
[0144] In an optional example, after updating the positions pointed to by the normal call pointer and the normal return pointer, step S210 further deletes the read return address to be read.
[0145] In a further alternative example, this part of the data may not be deleted. Instead, the original return address stored in the entry may be overwritten when the return address needs to be written to the entry. This invention does not impose any specific limitations on this.
[0146] Step S220: Read the return address to be read and update the recursive call record table so that the number of times the return address to be read is executed recorded in the recursive call record table indicates the remaining number of times the return address to be read is executed after it is read.
[0147] After determining the return address to be read, the return address to be read can be read. This return address is located on the recursive address stack and is indicated by the recursive return pointer.
[0148] When reading the return address to be read, the positions pointed to by the recursive call pointer and the recursive return pointer are also updated simultaneously. Specifically, this step can first read the return address to be read pointed to by the current pointer of the recursive return pointer, configure the recursive return pointer to backtrack so that its current pointer points to the previous entry of the return address to be read (in a specific example, this can be the recursive return pointer being decremented by 1), and simultaneously, the recursive call pointer backtracks to the position of the return address to be read, that is, the previous entry of the original position (in a specific example, this can be the recursive call pointer being decremented by 1). In other words, the recursive return pointer and the recursive call pointer are configured to backtrack so that the current pointer of the recursive return pointer points to the previous entry of the return address to be read, and the current pointer of the recursive call pointer points to the position of the return address to be read.
[0149] It should be noted that even if the current pointer of a normal return pointer points to the previous entry of the return address to be read, the node corresponding to that entry can still confirm the preceding and following pointer information, thus preventing confusion in the instruction execution order.
[0150] It should be noted that, unlike the steps mentioned above where the corresponding return address to be read is retrieved (reading and deleting the data at the original position), the return address to be read, after being read (i.e. executed), needs to be processed based on the information recorded in the recursive call record table.
[0151] It is understandable that the recursive call record table records the number of times each return address in the return address stack needs to be executed. Therefore, after the return address to be read is read once, the recursive call record table is updated so that the number of times the return address to be read is executed recorded in the recursive call record table indicates the remaining number of times the return address to be read is executed after it has been read.
[0152] In an optional example, updating the recursive call record table can specifically be done by subtracting 1 from the number of times the return address to be read is recorded in the recursive call record table.
[0153] Accordingly, in a specific example, the process of updating the recursive call record table may include: finding the entry in the recursive call record table corresponding to the recursive return pointer; and decrementing the value of the counter in the corresponding entry by 1.
[0154] Based on the one-to-one correspondence between the entries in the recursive call record table and the entries in the recursive address stack, the entry corresponding to the return address to be read can be found in the recursive call record table, and then the corresponding execution count can be updated.
[0155] When the recursive call record table marks entries in the recursive address stack based on pointer identifiers (such as identifier information or address information), the step of finding the entry in the recursive call record table corresponding to the recursive return pointer specifically involves indexing the corresponding entry in the recursive call record table based on the pointer identifier of the recursive return pointer.
[0156] In the recursive call record table, each entry can be configured with a multi-bit counter, which records the number of times the corresponding entry has been executed. Accordingly, the number of times the return address pointed to by the recursive return pointer in the recursive call record table has been executed is decremented by 1, specifically by decrementing the value of the counter in the corresponding entry.
[0157] Understandably, based on the information recorded in the updated recursive call log table, it can be determined whether to update the recursive address stack. For details, refer to... Figure 12 The illustrated optional flowchart of another instruction processing method provided by the embodiment of the present invention shows that, after updating the recursive call record table, if the remaining number of executions of the return address to be read pointed to by the recursive return pointer is greater than 0, then step S230 can be executed so that the return address to be read is still executed; after updating the recursive call record table, if the remaining number of executions of the return address to be read pointed to by the recursive return pointer is equal to 0, then step S240 is executed so that the recursive return pointer points to the next return address.
[0158] Step S230: Maintain the positions pointed to by the recursive return pointer and the recursive call pointer of the recursive address stack so that the return address pointed to by the recursive return pointer can continue to be executed;
[0159] After updating the recursive call record table, if the number of times the return address pointed to by the recursive return pointer has been executed is greater than 0, it indicates that the return address pointed to by the recursive return pointer still needs to be read and executed in subsequent steps. Therefore, the positions pointed to by the recursive return pointer and the recursive call pointer in the recursive address stack are maintained so that the return address pointed to by the recursive return pointer can continue to be read and executed.
[0160] Step S240: Update the positions pointed to by the recursive call pointer and the recursive return pointer based on the location where the return address to be read is stored;
[0161] After updating the recursive call record table, if the number of times the return address pointed to by the recursive return pointer is executed is equal to 0, it indicates that the return address pointed to by the recursive return pointer does not need to be read and executed again. Therefore, by updating the positions pointed to by the recursive call pointer and the recursive return pointer, the subsequent process can read the next return address in the recursive address stack.
[0162] The update of the positions pointed to by the recursive call pointer and the recursive return pointer can specifically be configured so that the recursive return address is backtracked to point to the previous entry of the return address to be read (in a specific example, the recursive return pointer can be decremented by 1). At the same time, the recursive call pointer is backtracked to the position of the return address to be read, that is, the previous entry of the original position (in a specific example, the recursive call pointer can be decremented by 1).
[0163] In an optional example, after updating the positions pointed to by the recursive call pointer and the recursive return pointer, step S240 further removes the return address from the entry pointed to by the call pointer.
[0164] It is understandable that, based on the aforementioned reading of only the corresponding return data, the data in the entry pointed to by the recursive call pointer is still the return address that has been read. Since the number of reads of this return address has reached zero, the return address of this entry no longer needs to be read. By deleting this part of the data, it is convenient to write a new return address later.
[0165] In a further alternative example, this part of the data may not be deleted. Instead, the original return address stored in the entry may be overwritten when the return address needs to be written to the entry. This invention does not impose any specific limitations on this.
[0166] It is understood that the solution provided by the embodiments of the present invention can avoid the excessive occupation of return data stack entries caused by multiple recursive calls and repeated storage of return addresses. At the same time, based on the fact that the data in the return data stack will overwrite the previous existing data after it is full, the embodiments of the present invention can further prevent the situation where repeated storage of duplicate data occupies the return data stack and causes the existing data in the return data stack to be overwritten. This improves the accuracy of instruction prediction to a certain extent and also prevents some specific security attacks on the processor.
[0167] This application also provides a processor for executing an instruction processing method provided in this embodiment of the invention, and for executing another instruction processing method provided in this embodiment of the invention.
[0168] This application also provides a chip that may include the processor described above.
[0169] This application also provides an electronic device that may include the chip described above.
[0170] The foregoing describes multiple embodiment schemes provided by the embodiments of this application. The optional methods described in each embodiment scheme can be combined and cross-referenced with each other without conflict, thereby extending to a variety of possible embodiment schemes. These can all be considered as the embodiment schemes disclosed and published by the embodiments of this application.
[0171] While the embodiments disclosed above are described in this application, this application is not limited thereto. Any person skilled in the art can make various modifications and alterations without departing from the spirit and scope of this application; therefore, the scope of protection of this application should be determined by the scope defined in the claims.
Claims
1. An instruction processing method, characterized by, include: Obtain the return address to be pushed onto the stack corresponding to the currently predicted hit call instruction, wherein the return address to be pushed onto the stack is used to indicate the instruction address of the return instruction corresponding to the call instruction; Determining whether the type of the calling instruction is a recursive calling instruction; wherein, determining whether the type of the calling instruction is a recursive calling instruction includes: determining the target return address in the address stack, the target return address being the previous return address stored in the address stack, the address stack including a recursive address stack and a normal address stack; determining whether the return address to be pushed onto the stack is the same as the target return address; if they are the same, then the calling instruction is a recursive calling instruction; if they are different, then the calling instruction is not a recursive calling instruction; If the calling instruction is a recursive calling instruction, the return address to be pushed onto the stack is stored in the recursive address stack, and the recursive calling record table of the recursive address stack is updated; if the calling instruction is not a recursive calling instruction, the return address to be pushed onto the stack is stored in the ordinary address stack; wherein, the recursive calling record table is used to record the number of times the return instruction corresponding to each return address in the recursive address stack needs to be executed.
2. The instruction processing method of claim 1, wherein, The target return address is the return address in the recursive address stack, which is configured with a recursive return pointer. The recursive return pointer is used to indicate the position of the return address that is about to be retrieved from the recursive address stack. The updating of the recursive call record table of the recursive address stack includes: Find the entry in the recursive call record table that corresponds to the recursive return pointer; Increment the value of the counter in the corresponding entry by 1.
3. The instruction processing method of claim 1, wherein, The target return address is the return address in the normal address stack. The recursive address stack is configured with a recursive call pointer, which indicates the position to be pushed onto the recursive address stack. The step of transferring the target return address to the recursive address stack and updating the recursive call record table includes: Read the target return address from the normal address stack, and update the pointer information of the normal call pointer and normal return pointer in the normal address stack; Store the target return address into the entry pointed to by the recursive call pointer in the recursive address stack, and update the pointing information of the recursive call pointer; Configure the execution count value corresponding to the entry of the return address to be pushed onto the stack in the recursive call record table as an initial value.
4. The instruction processing method according to claim 3, characterized in that, Updating the pointer information of the ordinary call pointer and ordinary return pointer in the ordinary address stack includes: Configure the current pointer of the normal call pointer to point to the previous entry at the original position, and configure the current pointer of the normal return pointer to point to the previous entry at the original position. In addition, the forward pointer information of the normal call pointer and the backward pointer information of the normal return pointer are configured as the location where the target return address is stored in the recursive address stack; The preceding pointing information is used to indicate the entry corresponding to the previous node of the current pointing information; the following pointing information is used to indicate the entry corresponding to the next node of the current pointing information.
5. The instruction processing method according to claim 3, characterized in that, The recursive address stack is also configured with a recursive return pointer, which indicates the position of the return address to be retrieved from the recursive address stack. Updating the recursive call pointer's pointing information includes: Configure the recursive call pointer to point to the next entry at the original position, and configure the recursive return pointer to point to the next entry at the original position; In addition, the preceding pointer information of the recursive return pointer is configured to be the entry pointed to by the ordinary return pointer of the ordinary address stack; Configure the execution count value corresponding to the entry of the return address to be pushed onto the stack in the recursive call record table as an initial value.
6. The instruction processing method according to claim 1, characterized in that, The ordinary address stack is configured with an ordinary call pointer, which indicates the position where the call will be pushed onto the ordinary address stack. The step of storing the return address to be pushed onto the ordinary address stack includes: Store the return address to be pushed onto the stack in the entry pointed to by the normal call pointer; Configure the current pointer of the normal call pointer to point to the next entry at the original position, and configure the current pointer of the normal return pointer to point to the entry where the return address to be pushed onto the stack is located; Configure the preceding pointer information of the normal call pointer and the following pointer information of the normal return pointer as the entry where the target return address is located.
7. The instruction processing method according to claim 4 or 6, characterized in that, Also includes: Configure alternative pointer information for the ordinary return pointer; The alternative pointer information is used to indicate the location of the previous return address in the normal address stack.
8. An instruction processing method, characterized in that, include: When the currently predicted hit instruction is a return instruction, the return address to be read is determined from the recursive address stack and the normal address stack; wherein, the return address to be read is the return address whose storage timing is closest to the current time; the recursive address stack is configured with a recursive return pointer, and the normal address stack is configured with a normal return pointer. Based on the pointing information of the recursive return pointer and the normal return pointer, the return address to be read is determined to be the return address whose storage timing is closest to the current time. If the return address to be read is located in the normal address stack, read the return address to be read; if the return address to be read is located in the recursive address stack, read the return address to be read and update the recursive call record table so that the number of times the return address to be read is executed recorded in the recursive call record table indicates the remaining number of times the return address to be read will be executed after it has been read.
9. The instruction processing method according to claim 8, characterized in that, The updated recursive call record table includes: Find the entry in the recursive call record table that corresponds to the recursive return pointer; Decrease the value of the counter in the corresponding entry by 1.
10. The instruction processing method according to claim 8, characterized in that, After updating the recursive call record table, the following is also included: If the remaining number of executions at the return address to be read, pointed to by the recursive return pointer, is greater than 0, the positions pointed to by the recursive return pointer and the recursive call pointer in the recursive address stack are maintained so that the return address pointed to by the recursive return pointer can continue to be executed; if the remaining number of executions at the return address to be read, pointed to by the recursive return pointer, is equal to 0, the positions pointed to by the recursive call pointer and the recursive return pointer are updated based on the storage position of the return address to be read.
11. A processor, characterized in that, The processor is configured to execute the instruction processing method according to any one of claims 1 to 7, and to execute the instruction processing method according to any one of claims 8 to 10.
12. A chip, characterized in that, Includes the processor as described in claim 11.
13. An electronic device, characterized in that, Including the chip as described in claim 12.
Citation Information
Patent Citations
Apparatus and method for controlling branch prediction
CN111886580A
Apparatus and method for performing subroutine call and return operations
US5974543A