Instruction processing method, processor, chip and electronic equipment
By distinguishing between recursive and ordinary call instructions and using a recursive call record table to record the number of times the return address is executed, the problem of excessive storage resource usage caused by recursive call instructions is solved, the instruction processing overhead is reduced, and the processing efficiency of the processor is improved.
Patent Information
- Application Number
- CN202510770206.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-10
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2045-06-10
AI Technical Summary
In the existing instruction processing flow, the instruction processing overhead is relatively high. In particular, the repeated storage of return addresses caused by recursive call instructions occupies too many storage resources, affecting the prediction accuracy of other branch instructions.
By distinguishing recursive call instructions from ordinary call instructions, the return address of the recursive call instruction is stored in the recursive address stack, and the recursive call record table is used to record the number of times the return address is executed, while ordinary call instructions are stored in the ordinary address stack, reducing duplicate storage and lowering hardware overhead.
It reduces the instruction processing overhead, reduces the occupancy of storage resources, avoids the impact on the prediction accuracy of other branch instructions, and improves the efficiency of the processor.
Smart Images

Figure CN120704743A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of processor technology, and specifically to instruction processing methods, processors, chips, and electronic devices. Background Art
[0002] In modern processors, instructions need to go through the processes of instruction fetch, decoding and execution; among them, instruction fetch is used to obtain the instructions to be executed, decoding is used to parse and translate the fetched instructions to obtain the micro-instructions (micro-op, Uop) corresponding to the instructions, and execution is used to perform the corresponding instruction operations based on the micro-instructions obtained by decoding.
[0003] However, the existing instruction processing flow has a large instruction processing overhead. Summary of the Invention
[0004] In view of this, 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 objectives, the embodiments of the present application provide the following technical solutions.
[0006] In a first aspect, an embodiment of the present application provides an instruction processing method, comprising:
[0007] Obtaining a return address to be pushed into a stack corresponding to a currently predicted hit call instruction, wherein the return address to be pushed into a stack is used to indicate an instruction address of a return instruction corresponding to the call instruction;
[0008] Determining whether the type of the call instruction is a recursive call instruction;
[0009] If the call instruction is a recursive call instruction, the return address to be pushed is stored in the recursive address stack, and the recursive call record table of the recursive address stack is updated; if the call instruction is not a recursive call instruction, the return address to be pushed is stored in the ordinary 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 be executed.
[0010] Optionally, determining whether the type of the call instruction is a recursive call instruction includes:
[0011] Determining a target return address in an address stack, where the target return address is a 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 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 a non-recursive calling instruction.
[0014] Optionally, the target return address is a return address in a recursive address stack, and updating the recursive call record table of the recursive address stack includes:
[0015] Searching for an entry in a recursive call record table corresponding to the recursive return pointer;
[0016] Increment the counter in the corresponding entry by 1.
[0017] Optionally, the target return address is a return address in a common address stack, and the transferring the target return address to the recursive address stack and updating the recursive call record table include:
[0018] Reading the target return address in the common address stack, and updating the pointing information of the common call pointer and the common return pointer in the common address stack;
[0019] The target return address is stored in the entry pointed to by the recursive call pointer in the recursive address stack, and the pointing information of the recursive call pointer is updated;
[0020] The execution count value corresponding to the entry of the return address to be pushed into the stack is configured in the recursive call record table as an initial value.
[0021] Optionally, updating the pointing information of the normal call pointer and the normal return pointer in the normal address stack includes:
[0022] The current indication information of the common call pointer is configured to point to the previous entry of the original position, and the current indication information of the common return pointer is configured to point to the previous entry of the original position;
[0023] and configuring the pre-pointing information of the common call pointer and the post-pointing information of the common return pointer as a target return address stored in a location on a 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 pointing information of the recursive call pointer includes:
[0026] Configuring the recursive call pointer to point to the next entry of the original position, and configuring the recursive return pointer to point to the next entry of the original position;
[0027] and configuring the preceding pointing information of the recursive return pointer to be the entry pointed to by the ordinary return pointer of the ordinary address stack;
[0028] The execution count value corresponding to the entry of the return address to be pushed into the stack is configured in the recursive call record table as an initial value.
[0029] Optionally, storing the return address to be pushed into a common address stack includes:
[0030] Storing the return address to be pushed into the stack in the entry pointed to by the common call pointer;
[0031] The current pointing information of the common call pointer is configured to point to the next entry at the original position, and the current pointing information of the common return pointer is configured to point to the entry where the return address to be pushed is located;
[0032] The leading pointing information of the common call pointer and the trailing pointing information of the common return pointer are configured as the entry where the target return address is located.
[0033] Optionally, also include:
[0034] Alternative pointing information is configured for the common return pointer; the alternative pointing information is used to indicate the position of the previous return address of the return address pointed to by the pointer in the common address stack.
[0035] In a second aspect, an embodiment of the present invention provides another instruction processing method, including:
[0036] When the currently predicted hit instruction is a return instruction, determining a return address to be read from the recursive address stack and the normal address stack; wherein the return address to be read is the return address that is stored closest to the current moment in terms of timing;
[0037] If the return address to be read is located in the normal address stack, the return address to be read is read; if the return address to be read is located in the recursive address stack, the return address to be read is read, and the recursive call record table is updated so that the number of times the return address to be read recorded in the recursive call record table is executed indicates the remaining number of times the return address to be read is executed after being read.
[0038] Optionally, updating the recursive call record table includes:
[0039] Searching for an entry in a recursive call record table corresponding to the recursive return pointer;
[0040] Decrement the counter in the corresponding entry by 1.
[0041] Optionally, after updating the recursive call record table, the method further includes:
[0042] If the number of remaining executions of 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 of the recursive address stack are maintained so that the return address pointed to by the recursive return pointer continues to be executed; if the number of remaining executions of 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 position where the return address to be read is stored.
[0043] In a third aspect, an embodiment of the present invention further provides a processor, which is used to execute the instruction processing method provided in the first aspect of the embodiment of the present invention, and to execute the instruction processing method provided in the second aspect of the embodiment of the present invention.
[0044] In a fourth aspect, an embodiment of the present invention further provides a chip, comprising the processor provided in the third aspect of the embodiment of the present invention.
[0045] In a fifth aspect, an embodiment of the present invention further provides an electronic device, comprising the chip provided in the fourth aspect of the embodiment of the present invention.
[0046] An instruction processing method, processor, chip, and electronic device provided by an embodiment of the present invention include: obtaining a return address to be pushed onto a stack corresponding to a currently predicted hit call instruction, wherein the return address to be pushed onto a stack is used to indicate the instruction address of a 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 return address to be pushed onto a recursive address stack and updating a recursive call record table of the recursive address stack; if the call instruction is not a recursive call instruction, storing the return address to be pushed onto 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] It can be seen that the instruction processing method, processor, chip and electronic device provided by the embodiments of the present invention determine the address stack in which the return address to be pushed is stored based on the type of the call instruction. Specifically, when the call instruction is a recursive call instruction, the return address to be pushed is stored in 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, so that the corresponding return address does not need to be repeatedly stored in the address stack, thereby reducing the excessive occupation of storage resources and reducing the overhead of instruction processing.
[0048] At the same time, when the call instruction is not a recursive call instruction, the return address to be pushed into the stack is stored in the common address stack, thereby not occupying the storage resources of the recursive call record table, further reducing the hardware overhead of instruction processing.
[0049] Furthermore, based on the embodiment of the present invention, there is no need to repeatedly store the corresponding return address in the address stack, thereby providing more available resources for other instructions and avoiding adverse effects on the prediction accuracy of other branch instructions. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without any creative work.
[0051] Figure 1 An optional flow diagram for branch instruction prediction.
[0052] Figure 2 A schematic diagram of an optional processing flow for a multiple call instruction.
[0053] Figure 3 An optional structure diagram for the return address stack.
[0054] Figure 4 This is another optional structure diagram of the return address stack.
[0055] Figure 5 An optional structural diagram of an address stack provided by an embodiment of the present invention.
[0056] Figure 6 A schematic diagram of pointer pointing information provided by an embodiment of the present invention.
[0057] Figure 7 An optional flow chart of an instruction processing method provided by an embodiment of the present invention.
[0058] Figure 8 An optional flowchart of another instruction processing method provided by an embodiment of the present invention.
[0059] Figure 9 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 a schematic diagram of an optional flow chart of step S120 provided in an embodiment of the present invention.
[0061] Figure 11 An optional flowchart of another instruction processing method provided by an embodiment of the present invention.
[0062] Figure 12 An optional flowchart of another instruction processing method provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0063] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0064] In a general instruction processing flow, instructions usually need to go through the processes of instruction fetch, decoding, and execution. Instruction fetch is to fetch the instruction corresponding to the program execution from the processor's cache or main memory; the decoding operation is to decode the instruction fetched to determine the instruction's operation code and / or address code, etc.; the execution operation is to perform the instruction operation according to the obtained operation code and / or address code, etc., to realize the program execution. Among them, the processor generally uses the instruction pipeline technology to realize the processing of instructions. In this technology, different processing processes are correspondingly configured with different hardware modules. In the pipeline operation of the processor, multiple instructions in different processing processes can be processed and circulated in the corresponding hardware modules in sequence.
[0065] However, when processing branch instructions in instructions, it is necessary to rely on the branch prediction mechanism to reduce instruction latency. 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 flows) based on different instruction results. Figure 1 The figure shows an optional flow chart of branch instruction prediction. Branch instruction N needs to enter different branch processes based on the result of instruction M, namely branch N1 and branch N2. At this time, if the instruction is executed according to normal logic, it is necessary to wait for the result of instruction M, such as result M1 or result M2. However, in the pipeline operation of the processor, multiple instructions at different processing stages are processed simultaneously in different hardware logics. The delay of one instruction will block the processing of multiple other instructions on the subsequent pipeline, thereby causing pipeline delay. In order to reduce the pipeline delay caused by the processor waiting for the instruction result of the branch instruction to determine the next instruction fetch, it is possible to determine in advance which instruction to execute next (such as Figure 1 The branches Ni shown, where i can be 1 or 2, reduce the waiting time of the processor when executing the branch instruction.
[0066] An optional prediction mechanism can make predictions 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), and the branch instruction prediction is made based on the target address. For subroutine call instructions in branch instructions, a return address stack is further configured to further improve the accuracy of instruction prediction.
[0067] Specifically, a subroutine call instruction implements instruction processing by calling a subroutine. Subroutine call instructions include a call instruction (CALL) and a return instruction (RET). The call instruction is used to enter a subroutine, and the return instruction is used to return from a subroutine. Therefore, the call instruction and the return instruction form a corresponding set of instructions.
[0068] When a subroutine is called twice, the corresponding set of call instructions and return instructions can be nested between the previous set of call instructions and return instructions; accordingly, when there are multiple calls, refer to Figure 2 The diagram shows an optional processing flow diagram of a multiple call instruction, where multiple groups of call instructions and return instructions are nested and executed in sequence, 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 a 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 the return instruction needs to be executed, the corresponding return addresses are taken out in the return address stack in a first-in, last-out order, and the corresponding return instruction is executed based on the return address.
[0069] Accordingly, reference Figure 3 The optional structure diagram of the return address stack shown is used to store the instruction address of the return instruction corresponding to the call 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), wherein the call pointer is used to point to the entry where the return address will be stored (i.e., the empty entry adjacent to the most recently stored return address entry), and the return pointer is used to point to the entry where the return address will be retrieved (i.e., the entry adjacent to the empty entry that stores the return address).
[0070] Among them, when the predicted branch instruction is predicted to be a call instruction (CALL) and hits, 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) can be pushed into 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 taken out as the target address.
[0071] However, this instruction processing flow has a high instruction processing overhead. To solve this problem, the inventor believes that it is possible to simplify the relevant information starting from the repeated information appearing in the multi-cycle instruction to reduce the instruction processing overhead.
[0072] Specifically, the inventors believe that when a multi-loop instruction (e.g., a multi-loop recursive call instruction, which is a special subroutine call instruction) is involved, the return address corresponding to the call address is the same address. Accordingly, the processing flow will repeatedly write the same return address into the return address stack, thereby causing duplicate information to be written into multiple return address stack entries. This duplicate information occupies too much storage resources, resulting in excessive instruction processing overhead. At the same time, because this duplicate information occupies too much storage resources, it will also squeeze out the available resources of other instructions, which may have an adverse effect on the prediction accuracy of other branch instructions.
[0073] Accordingly, the inventors further considered that a recursive call record table can be configured for the return address stack, and the 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, so that the repeated return addresses corresponding to the recursive call can be stored in one entry without occupying too much storage resources. In an optional implementation, refer to Figure 4 Another optional structural diagram of the return address stack is shown. The recursive call record table can configure a cnt value for each entry (cnt0, cnt1...cntn in the figure) to record the number of times the return instruction corresponding to the return address needs to return. When the cnt value of the entry to be read in the return address stack is not 0, the return address in the entry can be repeatedly read, and the cnt value can be reduced by 1 until the cnt value is 0.
[0074] However, in an actual instruction processing flow, the probability of a recursive call instruction appearing is relatively low. Accordingly, the inventors believe that other solutions can be considered to further reduce the hardware overhead.
[0075] In view of this, an embodiment of the present invention provides an instruction processing method, a processor, a chip and an electronic device, the method comprising: obtaining a return address to be pushed onto the stack corresponding to the currently predicted hit call instruction, the return address to be pushed onto the stack being 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 return address to be pushed onto the stack 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 return address to be pushed onto the stack 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] It can be seen that the instruction processing method, processor, chip and electronic device provided by the embodiments of the present invention determine the address stack in which the return address to be pushed is stored based on the type of the call instruction. Specifically, when the call instruction is a recursive call instruction, the return address to be pushed is stored in 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, so that the corresponding return address does not need to be repeatedly stored in the address stack, thereby reducing the excessive occupation of storage resources and reducing the overhead of instruction processing.
[0077] At the same time, when the call instruction is not a recursive call instruction, the return address to be pushed into the stack is stored in the common address stack, thereby not occupying the storage resources of the recursive call record table, further reducing the hardware overhead of instruction processing.
[0078] Furthermore, based on the embodiment of the present invention, there is no need to repeatedly store the corresponding return address in 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 an alternative implementation, reference Figure 5 An optional structural diagram of an address stack provided by an embodiment of the present invention is shown. The address stack provided by the embodiment of the present invention may include a recursive address stack and a normal address stack, wherein 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 is used to record the number of times the return instruction corresponding to each return address in the recursive address stack needs to return. In a specific example, corresponding to any entry in the recursive address stack, the recursive call record table can be configured with a corresponding counter cnt, which is used to record the number of times the return instruction corresponding to each return address in the recursive address stack needs to return (that is, 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 too much storage resources.
[0081] It is understood that each entry in the address stack (including the recursive address stack and the normal address stack) is accessed based on a first-in, last-out mechanism, i.e., read in reverse order of the order in which it was stored. In a specific implementation, the address stack indicates the access order of the return address based on a pointer.
[0082] In an optional implementation, refer to Figure 6 The following diagram shows pointer information. Pointers in the address stack can be structured as a doubly linked list. That is, a pointer at a node includes information pointing to both the previous node and the next node. For example, the pointer at node d1 points to both the previous node, head, and the next node, d2.
[0083] In a specific implementation, the pointing information of the pointer may include preceding pointing information and following pointing information, as well as current pointing information; wherein, the current pointing information is used to indicate the entry currently pointed to by the pointer, the preceding pointing information is used to indicate the entry corresponding to the previous node of the current pointing information, and the following pointing information is used to indicate the entry corresponding to the next node of the current pointing information; it should be noted that, based on the fact that the call pointer and the return pointer are executed in opposite directions, the corresponding preceding pointing information and following pointing information have opposite directions. For example, the call pointer can be executed one by one from the head node to the dn node, while the return pointer goes back one by one along the dn node to the head node. Accordingly, the preceding pointing information of the call pointer indicates in the direction from the head node to the dn node, and the following pointing information indicates in the direction from the dn node to the head node; the preceding pointing information of the return pointer indicates in the direction from the dn node to the head node, and the following pointing information indicates in the direction from the head node to the dn node.
[0084] It can be understood that the pointer structured based on the doubly linked list structure can fully record the storage order of return addresses in the address stack, and then determine the order in which return addresses are read based on the reverse order of this storage order. Furthermore, based on the doubly linked list structure, after an instruction prediction error occurs, a rollback can be performed based on the error point. Accordingly, during the instruction processing flow, only the pointer needs to be modified and a new doubly linked list structure is formed, eliminating the need to flush the address stack, thus reducing the instruction overhead caused by the prediction error.
[0085] For details, please refer to Figure 5 The pointers configured in the recursive address stack may be a recursive call pointer (DutyCall Ptr) and a recursive return pointer (DutyRetn Ptr), wherein the recursive call pointer is used to indicate the position to be pushed into the recursive address stack (i.e., the position of the current pointing information), and the recursive return pointer is used to indicate the position of the return address to be taken out from the recursive address stack (i.e., the position of the current pointing information).
[0086] Among them, based on the processing logic of the call instruction, the current pointing information of the recursive return pointer actually always points to the entry corresponding to the return address most recently stored in the recursive address stack. Therefore, based on the rule of storing return addresses in the recursive address stack from bottom to top, it can be understood that the entry corresponding to the return address of the call instruction is about to be stored is the next entry of the entry of the return address to be taken out (which can be regarded as the entry above the entry of the return address to be taken out). Therefore, in the recursive address stack, the entry pointed to by the current pointing information of the recursive call pointer is usually the next entry of the entry pointed to by the recursive return pointer, and the entry pointed to by the current pointing information of the recursive return pointer is usually the previous entry of the entry pointed to by the current pointing information of the recursive call pointer (which can be regarded as the entry below the entry of the return address to be taken out).
[0087] When pointers are configured in a doubly linked list format, the preamble of the recursive return pointer is configured with the location of the previous return address of the return address it points to, which was pushed onto the address stack. The location of the previous return address pushed onto the address stack can be a location in the recursive address stack or a location in the normal address stack. In other words, when cross-site storage occurs from the normal address stack to the recursive address stack, the preamble of the recursive return pointer can record the corresponding location information, thereby enabling a return from the recursive address stack to the corresponding location in the normal address stack based on the preamble of the recursive return pointer.
[0088] In contrast, the pointers configured for the ordinary address stack may be an ordinary call pointer (Call Ptr) and an ordinary return pointer (Retn Ptr), wherein the ordinary call pointer is used to indicate the position to be pushed into the ordinary address stack (i.e., the position of the current pointing information), and the ordinary return pointer is used to indicate the position to be taken out of the return address (i.e., the position of the current pointing information).
[0089] Among them, based on the processing logic of the call instruction, the current pointing information of the ordinary return pointer actually always points to the entry corresponding to the return address most recently stored in the ordinary address stack. Therefore, based on the rule of storing return addresses in sequence from bottom to top in the ordinary address stack, it can be understood that the entry corresponding to the return address of the call instruction is about to be stored is the next entry of the entry of the return address to be taken out (the position can be regarded as the entry above the entry of the return address to be taken out). Therefore, in the ordinary address stack, the entry pointed to by the current pointing information of the ordinary call pointer is usually the next entry of the entry pointed to by the current pointing information of the ordinary return pointer, and the entry pointed to by the current pointing information of the ordinary return pointer is usually the previous entry of the entry pointed to by the current pointing information of the ordinary call pointer (the position can be regarded as the entry below the entry of the return address to be taken out).
[0090] When pointers are configured in a doubly linked list format, the preamble of the normal return pointer is configured with the location of the previous return address of the return address it points to, which was pushed onto the address stack. The location of the previous return address pushed onto the address stack can be a location in the normal address stack or a location in the recursive address stack. In other words, when cross-site storage occurs from the recursive address stack to the normal address stack, the preamble of the normal return pointer can record the corresponding location information, thereby enabling a return from the normal address stack to the corresponding location on the recursive address stack based on the preamble of the normal return pointer.
[0091] In a further optional example, the ordinary return pointer can also be configured with alternative pointing information, and the alternative pointing information is used to indicate the location of the previous return address of the return address it points to 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 the entry n.
[0092] It is understandable that in the event of a malicious attack that pollutes the RAS through recursive calls to obtain data cache information, a feasible approach is to revert to the instruction processing flow before the recursive call. Corresponding methods can, for example, disable the use of recursive calls in the hardware circuit or flush recursive calls. By configuring alternative pointing information, it is possible to jump 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, thereby adjusting the instruction processing flow based solely on the pointer pointing information. Compared with disabling the use of recursive calls in the hardware circuit or flushing recursive calls, this can significantly reduce the corresponding instruction overhead.
[0093] In an alternative implementation, reference Figure 7 An optional flow chart of an instruction processing method provided by an embodiment of the present invention is shown. The embodiment of the present invention provides an instruction processing method, which is applied to a scenario where a call instruction is predicted, and the method includes:
[0094] Step S100: obtaining the return address to be pushed into the stack corresponding to the currently predicted hit call instruction;
[0095] The return address to be pushed into the stack is used to indicate the instruction address of the return instruction corresponding to the call instruction.
[0096] When the branch instruction is predicted to be a call instruction, the instruction address of the return instruction corresponding to the call instruction needs to be updated to the address stack so that the subsequent predicted return instruction controls the subsequent execution flow based on the return address updated to the address stack. Accordingly, the return address to be pushed corresponding to the currently predicted call instruction is obtained to perform the update of the return address stack.
[0097] In a specific example, the instruction address may be a linear address. When it is predicted that the instruction corresponding to a linear address is a call instruction (i.e., a call branch type), the linear address may be obtained and added by 1 as the corresponding return address to be pushed onto the stack.
[0098] Step S110: determining whether the type of the call instruction is a recursive call instruction;
[0099] The types of the call instructions may include recursive call instructions and common call instructions. The recursive call instructions are used to indicate call instructions whose return addresses are the same address. Common call instructions may be understood as other call instructions other than recursive call instructions.
[0100] In an optional example, the type of the call instruction can be determined based on the previous return address stored in the address stack, wherein the previous return address stored in the address stack is used as the target return address. The call instruction can be determined to be a recursive call instruction by judging whether the return address to be pushed into the stack is the same as the target return address. If they are the same, the call instruction is a recursive call instruction; if they are different, the call instruction is a non-recursive call instruction.
[0101] In a specific example, refer to Figure 8 The optional flow chart of another instruction processing method provided by an embodiment of the present invention is shown. This step may be:
[0102] Step S111: determining 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. Accordingly, the previous return address stored in the address stack indicates the most recently stored return address among all return addresses stored in the recursive address stack and the normal address stack. It is 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 an optional example, the target return address can be confirmed based on the timing information of the stored return address, or can be confirmed based on the pointing information of the pointer. In a specific example, when the pointer of the address stack (i.e., the pointer of the recursive address stack and the ordinary address stack) is 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 extends from the head to the tail in terms of timing, the position pointed to by the node at the tail of the doubly linked list structure is the target return address.
[0105] Step S112: Determine whether the return address to be pushed into 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: storing the return address to be pushed into the recursive address stack, and updating 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, so that multiple consecutive identical return addresses can be recorded in the same entry based on the recursive call record table, saving storage space of 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 in the recursive address stack, the return address to be pushed can be understood as having been stored in the recursive address stack, and the recursive call record table is updated to record the number of times the return instruction corresponding to the return address to be pushed needs to be executed.
[0110] The recursive call record table is updated to increase the number of times the return address pointed to by the return pointer in the recursive call record table has been read by 1. This allows the corresponding instruction processing flow to be controlled based on the number of times the return address has been read as recorded in the updated recursive call record table when the return address is subsequently read. After the return address has been read a corresponding number of times, the previous return address corresponding to the return address is read based on the pointing information of the recursive return pointer.
[0111] In a corresponding example, the process of updating the recursive call record table may include: searching the recursive call record table for an entry corresponding to the recursive return pointer; and adding 1 to the value of a counter in the corresponding entry.
[0112] It is understandable that the entries in the recursive call record table may correspond to the entries in the recursive address stack one by one, so as to record the number of times each entry in the recursive address stack is read. n entries, and accordingly, the recursive call record table also includes 2 n Each entry in the recursive call record table may correspond to each entry in the recursive address stack based on identification information or address information of each entry in the recursive address stack.
[0113] The recursive return pointer and the recursive call pointer are based on the pointing identifier to mark each entry in the return address stack. The pointing identifier can be, for example, the identification information or address information of each entry in the recursive address stack. The return address stack can include 2 n When there are 1 entry, the pointer flag can be n bits. Figure 9 The diagram shows an optional structure of a recursive call record table provided by an embodiment of the present invention. In the recursive call record table, entries in the return address stack can be marked based on a pointing identifier (such as identification information or address information). When searching for an entry in the recursive call record table corresponding to the recursive return pointer, the corresponding entry in the recursive call record table can be retrieved based on the pointing identifier index of the recursive return pointer.
[0114] Continue to refer Figure 9 In the recursive call record table, each entry may be configured with a multi-bit counter that records the number of times the corresponding address has been read. Accordingly, the number of times the return address pointed to by the recursive return pointer in the recursive call record table has been read is incremented by 1, specifically, the value of the counter in the corresponding entry is incremented by 1.
[0115] It can be understood that when the target return address is a return address in the recursive address stack, the return address to be pushed can be understood as having been stored in the recursive address stack, and its corresponding pointer remains unchanged, and only the number of times the return instruction corresponding to the return address to be pushed needs to be executed is recorded by updating the recursive call record table.
[0116] When the target return address is a return address in a normal address stack, the target return address can be transferred to the recursive address stack, and the recursive call record table is updated to record the number of times the return instruction corresponding to the return address to be pushed into the stack needs to be executed.
[0117] It should be noted that, when the target return address is a return address in the ordinary address stack, based on the fact that the call instruction is a recursive call instruction, that is, the return address to be pushed is the same as the target return address, accordingly, the target return address is transferred to the recursive address stack, that is, the return address to be pushed is stored in the recursive address stack, and the target return address in the ordinary address stack is read out.
[0118] Specifically, when the target return address is a return address in a normal address stack, refer to Figure 10 The optional flow diagram of step S120 shown in FIG. 1 , wherein step S120 transfers the target return address to the recursive address stack, includes:
[0119] Step S121: reading the target return address in the common address stack, and updating the pointing information of the common call pointer and the common return pointer in the common address stack;
[0120] The target return address in the common address stack is read to update the pointing information of the corresponding pointer.
[0121] It is understandable that when cross-stack address transfer is required, the pointing information in the normal address stack needs to be rolled back. Accordingly, triggering the pointer rollback process based on the reading process can reduce the complexity of the instruction processing process.
[0122] Specifically, updating the pointing information of the ordinary call pointer and the ordinary return pointer in the ordinary address stack may include configuring the current indication information of the ordinary call pointer to point to the previous entry at the original location (in a specific example, the call pointer minus 1), and configuring the current indication information of the ordinary return pointer to point to the previous entry at the original location (in a specific example, the call pointer minus 1). At the same time, the leading pointing information of the ordinary call pointer and the trailing pointing information of the ordinary return pointer may be configured to store the target return address in the recursive address stack, thereby achieving a cross-stack jump based on the corresponding pointing information.
[0123] Step S122: storing the target return address into the entry pointed to by the recursive call pointer in the recursive address stack, and updating the pointing information of the recursive call pointer;
[0124] The target return address is stored in the entry pointed to by the recursive call pointer in the recursive address stack, so as to realize cross-stack transfer of the return address in the address stack.
[0125] When updating the pointing information of the recursive call pointer, the recursive call pointer can be configured to point to the next entry of the original position (in a specific example, the recursive call pointer can be increased by 1), and at the same time, the recursive return pointer can be configured to point to the next entry of the original position (in a specific example, the recursive return pointer can be increased by 1), so that the recursive return pointer points to the target return address. At the same time, the leading pointing information of the recursive return pointer is configured to be the entry pointed to by the ordinary return pointer of the ordinary address stack, thereby realizing a cross-stack jump based on the corresponding pointing information.
[0126] Step S123: configuring the execution count value corresponding to the entry of the return address to be pushed into the recursive call record table as an initial value;
[0127] When the target return address is a return address in a normal address stack, it indicates that there are two target return addresses. Accordingly, when updating the execution count value corresponding to the entry corresponding to the return address to be pushed into the stack in the recursive call record table, the execution count value corresponding to the entry of the return address to be pushed into the stack can be configured as an initial value, which can be, for example, "2".
[0128] Step S130: storing the return address to be pushed into the common address stack;
[0129] It can be understood 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 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 position where the return address to be pushed is stored.
[0130] In a specific example, the return address to be pushed into the normal address stack is stored, specifically, the return address to be pushed into the entry pointed to by the normal call pointer. At the same time, the positions pointed to by the normal call pointer and the normal return pointer are updated, specifically, the current pointing information of the normal call pointer is configured to point to the next entry of the original position (in the specific example, the call pointer can be plus 1), and the current pointing information of the normal return pointer is configured to point to the entry where the return address to be pushed 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 leading pointing information of the ordinary call pointer and the trailing pointing information of the ordinary return pointer can be further configured as the entry where the target return address is located to indicate the previous entry of the entry pointed to by the ordinary return pointer.
[0132] In an optional example, alternative pointing information can be further configured for the ordinary return pointer, and the alternative pointing information is used to indicate the position of the previous return address of the return address it points to in the ordinary address stack, so that in the event of a malicious attack in which recursive calls pollute the RAS to obtain data cache information, the instruction processing flow can be rolled back based on the alternative pointing information, thereby reducing the corresponding instruction overhead.
[0133] In an alternative implementation, reference Figure 11 FIG2 shows an optional flow chart of another instruction processing method provided by an embodiment of the present invention. The embodiment of the present invention provides an instruction processing method, which is applied to a scenario where a return instruction is executed. The method includes:
[0134] Step S200: when the currently predicted hit instruction is a return instruction, determining a return address to be read from the recursive address stack and the normal address stack;
[0135] It is understood that in the call instruction processing flow, the call instruction and the return instruction form a corresponding set of instructions. Furthermore, when there are multiple calls, the call instruction and the return instruction are nested between the previous call instruction and the return instruction. Accordingly, after a call instruction appears, the subsequent return instruction can be predicted. If the currently predicted instruction is a return instruction, the corresponding return address to be read can be read from the address stack.
[0136] The address stack includes a recursive address stack and a normal address stack, and accordingly, 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 that is stored closest to the current moment in terms of timing.
[0137] The recursive address stack is configured with a recursive return pointer, and the corresponding current pointing information is used to indicate the return address in the recursive address stack that is stored closest to the current time in terms of timing, that is, the position in the recursive address stack where the return address is about to be retrieved. The normal address stack is configured with a normal return pointer, and the corresponding current pointing information is used to indicate the return address in the normal address stack that is stored closest to the current time in terms of timing, that is, the position in the normal address stack where the return address is about to be retrieved. Accordingly, the return address to be read can be determined based on the pointing information of the recursive return pointer and the normal return pointer.
[0138] In an optional example, the return address to be read can be confirmed based on the timing information of the return address pointed to by the recursive return pointer and the ordinary return pointer, or can be confirmed based on the pointing information of the recursive return pointer and the ordinary return pointer. In a specific example, when the pointer of the address stack (i.e., the pointer of the recursive address stack and the ordinary address stack) is 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 extended from the beginning to the end in terms of timing, the position pointed to by the pointer corresponding to the node at the end of 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 to be read. 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 after the return address to be read is determined, the return address to be read can be read.
[0142] Wherein, the return address to be read is located in the ordinary address stack, and accordingly, it is indicated based on the ordinary return pointer. When reading the return address to be read, the positions pointed to by the ordinary call pointer and the ordinary return pointer are also updated at the same time. Specifically, this step can first read the return address to be read pointed to by the current pointing information of the ordinary return pointer, configure the ordinary return pointer to roll back so that the current pointing information of the ordinary return pointer points to the previous entry of the return address to be read (in a specific example, it can be the ordinary return pointer minus 1). At the same time, the ordinary call pointer rolls back to the position of the return address to be read, that is, the previous entry of the original position (in a specific example, it can be the ordinary call pointer minus 1). That is, the ordinary return pointer and the ordinary call pointer are configured to roll back so that the current pointing information of the ordinary return pointer points to the previous entry of the return address to be read, and the current pointing information of the ordinary call pointer points to the position of the return address to be read.
[0143] It should be noted that even if the current pointing information of the ordinary return pointer points to the previous entry of the return address to be read, the node corresponding to the entry can still confirm the corresponding preceding pointing information and following pointing information, so that there will be no 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 optional example, the portion of data may not be deleted, but the original return address stored in the entry may be overwritten when the return address needs to be written to the entry. The present invention does not make any specific limitation here.
[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 being read.
[0147] After determining the return address to be read, the return address to be read can be read. The return address to be read is located in the recursive address stack and is indicated based on 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 pointing information of the recursive return pointer, configure the recursive return pointer to roll back so that the current pointing information of the recursive return pointer points to the previous entry of the return address to be read (in a specific example, it can be the recursive return pointer minus 1), and at the same time, the recursive call pointer rolls back to the position of the return address to be read, that is, the previous entry of the original position (in a specific example, it can be the recursive call pointer minus 1). That is, the recursive return pointer and the recursive call pointer are configured to roll back so that the current pointing information of the recursive return pointer points to the previous entry of the return address to be read, and the current pointing information 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 pointing information of the ordinary return pointer points to the previous entry of the return address to be read, the node corresponding to the entry can still confirm the corresponding preceding pointing information and following pointing information, so that there will be no confusion in the instruction execution order.
[0150] It should be noted that, unlike the aforementioned step of retrieving the corresponding return address to be read (reading and deleting the data at the original location), the return address to be read needs to be processed accordingly based on the information recorded in the recursive call record table after being read (i.e., executed).
[0151] 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 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 recorded in the recursive call record table is executed indicates the remaining number of times the return address to be read is executed.
[0152] In an optional example, the updating of the recursive call record table may specifically be to reduce by 1 the number of times the return address to be read, which is recorded in the recursive call record table, is executed.
[0153] Accordingly, in a specific example, the process of updating the recursive call record table may include: searching the recursive call record table for an entry corresponding to the recursive return pointer; and decrementing the value of a 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 searched in the recursive call record table, and then the corresponding execution count is updated.
[0155] When the recursive call record table marks the entries in the recursive address stack based on the pointing identifier (such as identification information or address information), the entry corresponding to the recursive return pointer in the recursive call record table is searched. Specifically, based on the pointing identifier of the recursive return pointer, the corresponding entry in the recursive call record table is indexed.
[0156] In the recursive call record table, each entry may be configured with a multi-bit counter that records the number of times the corresponding entry has been executed. Accordingly, the number of times the return address to be read pointed to by the recursive return pointer in the recursive call record table has been executed is reduced by 1, specifically, the value of the counter in the corresponding entry is reduced by 1.
[0157] It is understandable that, based on the information recorded in the updated recursive call record table, it can be determined whether to update the recursive address stack. Figure 12 The illustrated optional flowchart of another instruction processing method provided by an embodiment of the present invention, after updating the recursive call record table, when the remaining number of executions of the return address to be read pointed to by the recursive return pointer is greater than 0, step S230 can be executed to allow the return address to be read to still be executed; after updating the recursive call record table, when the remaining number of executions of the return address to be read pointed to by the recursive return pointer is equal to 0, step S240 is executed to allow the recursive return pointer to point to the next return address.
[0158] Step S230: maintaining 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 is continued to be executed;
[0159] After the recursive call record table is updated, when the number of times the return address pointed to by the recursive return pointer is 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 a subsequent step. Therefore, the positions pointed to by the recursive return pointer and the recursive call pointer of the recursive address stack are maintained so that the return address pointed to by the recursive return pointer continues to be read and executed.
[0160] Step S240: updating the locations 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 has been 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 recursive call pointer and the position pointed to by the recursive return pointer, the subsequent process can read the next return address in the recursive address stack.
[0162] The positions pointed to by the recursive call pointer and the recursive return pointer are updated. Specifically, the recursive return address can be configured to roll back to point to the previous entry of the return address to be read (in a specific example, it can be the recursive return pointer minus 1). At the same time, the recursive call pointer rolls back to the position of the return address to be read, that is, the previous entry of the original position (in a specific example, it can be the recursive call pointer minus 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 deletes the return address in the entry pointed to by the call pointer.
[0164] It can be understood 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. Based on the fact that the number of reads of the return address has returned to zero, the return address of the 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 optional example, the portion of data may not be deleted, but the original return address stored in the entry may be overwritten when the return address needs to be written to the entry. The present invention does not make any specific limitation here.
[0166] It can be understood that the solution provided by the embodiment of the present invention can avoid the excessive occupation of return data stack entries due to multiple storage of return addresses caused by repeated recursive calls; 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 embodiment of the present invention can further prevent the situation where the return data stack is occupied by duplicate data stored multiple times and the existing data in the return data stack is overwritten, thereby improving the accuracy of instruction prediction to a certain extent and preventing some specific security attacks on the processor.
[0167] An embodiment of the present application also provides a processor, which is used to execute an instruction processing method provided by an embodiment of the present invention, and to execute another instruction processing method provided by an embodiment of the present invention.
[0168] An embodiment of the present application also provides a chip, which may include the above-mentioned processor.
[0169] An embodiment of the present application also provides an electronic device, which may include the above-mentioned chip.
[0170] The above describes multiple embodiment schemes provided by the embodiments of the present application. The various optional methods introduced in each embodiment scheme can be combined and cross-referenced with each other without conflict, thereby extending a variety of possible embodiment schemes, which can all be considered as embodiment schemes disclosed and open in the embodiments of the present application.
[0171] Although the embodiments of the present application are disclosed above, the present application is not limited thereto. Any person skilled in the art may make various changes and modifications without departing from the spirit and scope of the present application. Therefore, the scope of protection of the present application shall be based on the scope defined by the claims.
Claims
1. A method for processing an instruction, characterized in that: include: Obtaining a return address to be pushed into a stack corresponding to a currently predicted hit call instruction, wherein the return address to be pushed into a stack is used to indicate an instruction address of a 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, the return address to be pushed is stored in the recursive address stack, and the recursive call record table of the recursive address stack is updated; if the call instruction is not a recursive call instruction, the return address to be pushed is stored in the ordinary 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 be executed.
2. The instruction processing method according to claim 1, characterized in that: Determining whether the type of the call instruction is a recursive call instruction includes: Determining a target return address in an address stack, where the target return address is a previous return address stored in the address stack, and the address stack includes a recursive address stack and a normal address stack; Determine whether the return address to be pushed 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 a non-recursive calling instruction.
3. The instruction processing method according to claim 2, wherein: The target return address is a return address in the recursive address stack, and updating the recursive call record table of the recursive address stack includes: Searching for an entry in a recursive call record table corresponding to the recursive return pointer; Increment the counter in the corresponding entry by 1.
4. The instruction processing method according to claim 2, wherein: The target return address is a return address in a common address stack, and the target return address is transferred to the recursive address stack and a recursive call record table is updated, including: Reading the target return address in the common address stack, and updating the pointing information of the common call pointer and the common return pointer in the common address stack; The target return address is stored in the entry pointed to by the recursive call pointer in the recursive address stack, and the pointing information of the recursive call pointer is updated; The execution count value corresponding to the entry of the return address to be pushed into the stack is configured in the recursive call record table as an initial value.
5. The instruction processing method according to claim 4, characterized in that: The updating of the pointing information of the normal call pointer and the normal return pointer in the normal address stack includes: The current indication information of the common call pointer is configured to point to the previous entry of the original position, and the current indication information of the common return pointer is configured to point to the previous entry of the original position; and configuring the pre-pointing information of the common call pointer and the post-pointing information of the common return pointer as a target return address stored in a location on a 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.
6. The instruction processing method according to claim 4, characterized in that: The updating of the pointing information of the recursive call pointer includes: Configuring the recursive call pointer to point to the next entry of the original position, and configuring the recursive return pointer to point to the next entry of the original position; and configuring the preceding pointing information of the recursive return pointer to be the entry pointed to by the ordinary return pointer of the ordinary address stack; The execution count value corresponding to the entry of the return address to be pushed into the stack is configured in the recursive call record table as an initial value.
7. The instruction processing method according to claim 2, wherein: The step of storing the return address to be pushed into the common address stack includes: Storing the return address to be pushed into the stack in the entry pointed to by the common call pointer; The current pointing information of the common call pointer is configured to point to the next entry at the original position, and the current pointing information of the common return pointer is configured to point to the entry where the return address to be pushed is located; The leading pointing information of the common call pointer and the trailing pointing information of the common return pointer are configured as the entry where the target return address is located.
8. The instruction processing method according to claim 5 or 7, characterized in that: Also includes: Configuring alternative pointing information for the common return pointer; The candidate pointing information is used to indicate the location of the previous return address of the return address pointed to by the candidate pointing information in the normal address stack.
9. A method for processing an instruction, characterized in that: include: When the currently predicted hit instruction is a return instruction, determining a return address to be read from the recursive address stack and the normal address stack; wherein the return address to be read is the return address that is stored closest to the current moment in terms of timing; If the return address to be read is located in the normal address stack, the return address to be read is read; if the return address to be read is located in the recursive address stack, the return address to be read is read, and the recursive call record table is updated so that the number of times the return address to be read recorded in the recursive call record table is executed indicates the remaining number of times the return address to be read is executed after being read.
10. The instruction processing method according to claim 9, characterized in that: The updating recursive call record table includes: Searching for an entry in a recursive call record table corresponding to the recursive return pointer; Decrement the counter in the corresponding entry by 1.
11. The instruction processing method according to claim 9, wherein: After the recursive call record table is updated, the following steps are also included: If the number of remaining executions of 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 of the recursive address stack are maintained so that the return address pointed to by the recursive return pointer continues to be executed; if the number of remaining executions of 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 position where the return address to be read is stored.
12. A processor, characterized in that: The processor is configured to execute the instruction processing method according to any one of claims 1 to 8, and to execute the instruction processing method according to any one of claims 9 to 11.
13. A chip, characterized in that: Comprising the processor of claim 12.
14. An electronic device, characterized in that: Comprising the chip as claimed in claim 13.
Citation Information
Patent Citations
Processor instructions for determining two minimum and two maximum values
CN108228238A
Apparatus and method for controlling branch prediction
CN111886580A
Fetch unit for predicting target of subprogram return instruction
CN114546485A
Recursive function analysis execution method and device and storage medium
CN114594960A
Computer provided with return stack
JP1996076998A