Instruction fetching methods, central processing units, devices, media, and program products

By dynamically adjusting the confidence threshold and optimizing instruction cache space allocation, the CPU performance problem caused by a fixed threshold is solved, and the CPU performance under different workloads is improved.

CN119127311BActive Publication Date: 2026-11-17TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311733099.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-15
Publication Date
2026-11-17
Estimated Expiration
2043-12-15

AI Technical Summary

Technical Problem

In existing technologies, the uneven number of branch instructions and the fixed threshold lead to insufficient instruction cache space, which affects CPU performance.

Method used

By dynamically adjusting the confidence threshold, the confidence classification ratio is determined based on the number of historical error predictions of branch instructions and the size of the confidence threshold. This ratio is then used as a control target to adjust the confidence threshold, avoiding a fixed threshold that is too small or too large, thus optimizing the use of the instruction cache.

Benefits of technology

It effectively avoids or reduces the problem of unreasonable allocation of instruction cache space due to fixed thresholds, and improves the performance of the CPU under different workload programs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127311B_ABST
    Figure CN119127311B_ABST
Patent Text Reader

Abstract

This application discloses an instruction fetching method, a central processing unit, a device, a medium, and a program product, belonging to the field of processors. The method includes: obtaining the predicted main path for each branch instruction; determining the confidence classification of the main path corresponding to each branch instruction based on the relationship between the number of historical error predictions of the main path of the same branch instruction and a confidence threshold; determining the confidence classification ratio, where the confidence classification ratio is the proportion of branch instructions corresponding to the first classification to the total instructions, and the first classification is the confidence classification where the number of historical error predictions is greater than the confidence threshold; and adjusting the confidence threshold with the confidence classification ratio as the desired ratio as the control target. By dynamically adjusting the confidence threshold, the problem of the first branch instruction accounting for an excessively large proportion of the total instructions can be avoided by fixing the threshold too small for different workload programs. The first branch instruction is the branch instruction corresponding to the main path whose confidence classification is the first classification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of processors, and in particular to an instruction fetching method, a central processing unit, a device, a medium, and a program product. Background Technology

[0002] In the design of a Central Processing Unit (CPU), a branch predictor within the CPU predicts the subsequent execution path of a branch instruction. The subsequent execution path corresponds to the instruction following the branch instruction. The CPU's instruction cache is used to pre-cache the instruction following the branch instruction, allowing the CPU to quickly fetch it from the instruction cache when executing the next instruction.

[0003] In related technologies, the concept of confidence classification is introduced. Confidence classification indicates the probability that the prediction of the main path is accurate. Branch instructions correspond to two candidate subsequent execution paths. The main path is the predicted execution path among the two subsequent execution paths, and the secondary path is a subsequent execution path different from the main path. Confidence classification includes a first classification and a second classification. Related technologies determine the confidence classification based on whether the value of a counter in the branch predictor is greater than a fixed threshold. In the first classification, a first caching method is used, which caches instructions based on the address of the main path or the address of the secondary path. In the second classification, a second caching method is used, which caches instructions based on the address of the main path.

[0004] However, the total number of instructions in a program includes branch instructions and other instructions. With a fixed total number of instructions, when dealing with a load program containing varying numbers of branch instructions, the large number of branch instructions and the small fixed threshold can lead to a situation where the proportion of the first branch instruction (the branch instruction corresponding to the main path in the first confidence classification) is too high. In this case, it can result in an excessive number of cached instructions and insufficient instruction cache space. Summary of the Invention

[0005] This application provides an instruction fetching method, a central processing unit, a device, a medium, and a program product, the technical solution of which includes at least:

[0006] According to one aspect of the embodiments of this application, an instruction acquisition method is provided, the method comprising:

[0007] Obtain the predicted main path for each branch instruction. Each branch instruction has two candidate subsequent execution paths. The main path is the path predicted to be executed between the two subsequent execution paths.

[0008] Based on the magnitude between the number of historical erroneous predictions of the main path for the same branch instruction and the confidence threshold, the confidence classification of the main path corresponding to each branch instruction is determined. The confidence classification is used to indicate the probability classification of the accuracy of the main path prediction.

[0009] Determine the confidence level classification ratio, which is the proportion of branch instructions corresponding to the first category to the total instructions. The first category is the confidence level classification where the number of historical false predictions is greater than the confidence level threshold.

[0010] The confidence level threshold is adjusted by using the expected proportion of the confidence level classification as the control target.

[0011] According to another aspect of the embodiments of this application, a central processing unit is provided, the central processing unit comprising:

[0012] The branch predictor is used to obtain the predicted main path for each branch instruction. Each branch instruction has two candidate subsequent execution paths. The main path is the path predicted to be executed between the two subsequent execution paths.

[0013] The branch predictor is used to determine the confidence classification of the main path corresponding to each branch instruction based on the size between the number of historical erroneous predictions of the main path for the same branch instruction and the confidence threshold. The confidence classification is used to indicate the probability classification of the accuracy of the main path prediction.

[0014] The branch predictor is used to determine the confidence classification ratio, which is the proportion of branch instructions corresponding to the first classification to the total instructions. The first classification is the confidence classification where the number of historical false predictions is greater than the confidence threshold.

[0015] The branch predictor is used to adjust the confidence threshold with the expected proportion of the confidence classification as the control objective.

[0016] According to another aspect of the embodiments of this application, a computer device is provided, the computer device including: a processor and a memory, the memory storing at least a program; the processor is used to execute the at least a program in the memory to implement the above-described instruction fetching method.

[0017] According to another aspect of the embodiments of this application, a computer-readable storage medium is provided, which stores at least one program that is loaded and executed by a processor to implement the instruction acquisition method described above.

[0018] According to another aspect of the embodiments of this application, a computer program product or computer program is provided, which includes computer instructions stored in a computer-readable storage medium, a processor retrieving the computer instructions from the computer-readable storage medium, and the processor executing the computer instructions to implement the instruction retrieval method as described above.

[0019] The technical solutions provided in this application embodiment may include the following beneficial effects:

[0020] This method obtains the predicted main path for each branch instruction, with each branch instruction corresponding to two candidate subsequent execution paths. The main path is the path predicted to be executed between these two subsequent execution paths. Based on the relationship between the number of historical erroneous predictions of the main path for the same branch instruction and a confidence threshold, a confidence classification is determined for the main path corresponding to each branch instruction. This confidence classification indicates the probability that the main path prediction is accurate. A confidence classification ratio is determined, which is the proportion of branch instructions corresponding to the first category out of the total instructions. The first category is the confidence classification where the number of historical erroneous predictions exceeds the confidence threshold. Using the confidence classification ratio as the desired ratio as the control target, the confidence threshold is adjusted to avoid or reduce the problem of the first branch instruction out of the total instructions being too large due to a fixed threshold that is too small for different workloads. The first branch instruction is the branch instruction corresponding to the main path whose confidence classification is the first category. Attached Figure Description

[0021] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 A schematic diagram of a CPU provided in an exemplary embodiment of this application is shown;

[0023] Figure 2 A schematic diagram of an instruction acquisition system provided in an exemplary embodiment of this application is shown;

[0024] Figure 3 A flowchart illustrating an exemplary embodiment of the present application for an instruction acquisition method is shown.

[0025] Figure 4 A flowchart illustrating an exemplary embodiment of the present application for an instruction acquisition method is shown.

[0026] Figure 5 A flowchart illustrating an exemplary embodiment of the present application for an instruction acquisition method is shown.

[0027] Figure 6 This is a structural block diagram of a computer device provided in an exemplary embodiment of this application. Detailed Implementation

[0028] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0029] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0030] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used in this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.

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

[0032] It should be understood that although the terms first, second, etc., may be used in this application to describe various information, this information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, a first parameter may also be referred to as a second parameter, and similarly, a second parameter may also be referred to as a first parameter. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."

[0033] The terminal devices involved in the embodiments of this application include, but are not limited to, mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle terminals, and aircraft. The embodiments of this application can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, and assisted driving.

[0034] First, let me introduce the relevant content involved in this application:

[0035] Central Processing Unit (CPU): One of the main components of an electronic computer, and the core component of a computer. The main function of the CPU is to interpret computer instructions and process data in the computer software. The CPU is the core component of a computer responsible for reading instructions, decoding instructions, and executing instructions.

[0036] Instruction fetch: Instruction fetch refers to the CPU retrieving the next instruction to be executed from the instruction cache. During execution, the CPU needs to fetch instructions from the instruction cache and then execute those instructions.

[0037] Instruction hit: This means that when the CPU needs to fetch a certain instruction, it can find the instruction because the instruction or its address is already stored in the instruction cache. Finding the instruction means that the instruction is hit, and not finding the instruction means that the instruction is missed.

[0038] Branch instructions: A type of instruction in computer programs used to change the flow of execution during program execution. A branch instruction determines the next step in program execution based on whether a certain condition is true or false.

[0039] Branch instruction prediction: Branch instruction prediction refers to the CPU's prediction of the subsequent execution path when executing a branch instruction. Branch instruction prediction typically has two outcomes: taken and not taken. If the prediction is a take, the CPU believes the branch instruction will be executed and will jump to the target address to continue execution; if the prediction is not taken, the CPU believes the branch instruction will not be executed and will continue executing the instruction following the branch instruction.

[0040] Primary path / secondary path: A branch instruction corresponds to two candidate subsequent execution paths. The primary path is the path predicted to be executed among the two subsequent execution paths, and the secondary path is a subsequent execution path that is different from the primary path.

[0041] Confidence Classification: Confidence classification is used to indicate the probability that the main path prediction is accurate. It includes a first classification and a second classification. For example, the first classification indicates that the main path prediction is low, and the second classification indicates that the main path prediction is high.

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

[0043] Artificial intelligence (AI) is a comprehensive discipline encompassing a wide range of fields, including both hardware and software technologies. Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, pre-trained model technology, operating / interactive systems, and mechatronics. Among these, pre-trained models, also known as large-scale models or foundational models, can be widely applied to downstream tasks across various AI fields after fine-tuning. AI software technologies primarily include computer vision, speech processing, natural language processing, and machine learning / deep learning.

[0044] With the research and advancement of artificial intelligence (AI) technology, AI is being studied and applied in various fields, such as smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, autonomous driving, drones, digital twins, virtual humans, robots, AI-generated content, conversational interaction, smart healthcare, smart customer service, and game AI. As the technology develops, AI will be applied in more fields and play an increasingly important role.

[0045] In CPU design, a branch predictor within the CPU predicts the subsequent execution path of a branch instruction. This subsequent execution path corresponds to the instruction following the branch instruction. The CPU's instruction cache is used to fetch and store the next instruction beforehand, allowing for quick retrieval when executing the next instruction. If the CPU detects an error in predicting the subsequent execution path of a branch instruction, it will clear the instruction cache and re-fetch the instruction (re-fetch the next instruction to be executed). Re-fetching requires retrieving instructions from a cache lower than the instruction cache within the CPU, or even from external memory. This reduces instruction fetching efficiency and impacts CPU performance.

[0046] In related technologies, when predicting the execution path of a branch instruction using the branch predictor in the CPU, since each branch instruction corresponds to two candidate subsequent execution paths, the address of the predicted execution path (main path) is used as the prefetch address of the main path and stored in the instruction cache. Similarly, the address of a subsequent execution path (secondary path) different from the main path is used as the prefetch address of the secondary path and stored in the instruction cache. The instruction cache then retrieves the corresponding instructions based on the prefetch addresses of the main and secondary paths. When the CPU re-fetches instructions, it retrieves the instruction corresponding to the prefetch address of the secondary path from the instruction cache to mitigate this problem. Confidence classification is used to indicate the probability that the main path prediction is accurate. Confidence classification includes a first category and a second category. The first category indicates a low probability that the main path prediction is accurate, while the second category indicates a high probability. The relevant technology determines the confidence level classification based on whether the value of the counter in the branch predictor is greater than a fixed threshold. Each counter is used to count the number of correct predictions in the history of a single branch instruction. For example, if the value of the counter is greater than the fixed threshold, the confidence level classification is the second category, and if the value of the counter is less than or equal to the fixed threshold, the confidence level classification is the first category.

[0047] In related technologies, there are two methods for representing confidence level classifications:

[0048] Method 1: Classify confidence levels based on the value of the counter in the branch predictor.

[0049] The counter is used to count the number of correct predictions in the history of branch instructions. The confidence level classification of the branch instruction is determined by whether the value of the counter is greater than a fixed threshold. If the value of the counter is less than or equal to the fixed threshold, it means that the confidence level classification is the first category.

[0050] Method 2: Confidence classification is represented by calculating the error prediction rate of branch instructions.

[0051] The error prediction rate is obtained by counting the number of historical incorrect predictions of branch instructions using an error counter and the number of historical correct predictions using a correct counter. The error prediction rate is then calculated by dividing the error counter value by the sum of the error and correct counter values. This error prediction rate is compared to a fixed prediction rate threshold. If the error prediction rate is greater than the threshold, the confidence classification is considered to be the first classification.

[0052] However, the total number of instructions in a program includes branch instructions and other instructions. When dealing with workloads containing varying numbers of branch instructions with a fixed total number of instructions, the related technology, based on a fixed threshold for confidence classification, may result in a situation where the number of branch instructions is large and the fixed threshold is small, leading to a situation where the proportion of first branch instructions (those belonging to the first confidence category) is excessively high. For example, a first workload program may contain 10 branch instructions, and a second workload program may contain 50 branch instructions. Assuming a fixed threshold of 3, in the first workload program, there are 4 branch instructions belonging to the first confidence category of the main path, and therefore 4 instructions corresponding to the prefetched addresses of the secondary paths. In the second workload program, there are 20 branch instructions belonging to the first confidence category of the main path, and therefore 20 instructions corresponding to the prefetched addresses of the secondary paths. Compared to the first workload program, the second workload program has a larger proportion of first branch instructions and a larger number of instructions corresponding to the prefetched addresses of the secondary paths, impacting CPU performance.

[0053] To address the aforementioned issues, this application provides an instruction acquisition method, which can be applied to a processor, such as the CPU in a server or terminal device. The server can be a standalone physical server, a server cluster consisting of multiple physical servers, or a distributed system, but is not limited to these. The terminal device can be an electronic device such as a personal computer (PC), mobile phone, tablet computer, in-vehicle terminal (vehicle infotainment system), wearable device, etc.

[0054] Figure 1 A schematic diagram of a CPU 100 provided in an exemplary embodiment of this application is shown. The CPU 100 includes at least one of the following: a branch predictor 110, an address selector 120, an instruction fetch queue 130, a prefetch queue 140, a first cache 150, a second cache 160, and a third cache 170.

[0055] The branch predictor 110 predicts the subsequent execution path of a branch instruction, obtaining the prediction result of the branch instruction. Each branch instruction corresponds to two candidate subsequent execution paths, and the main path is the predicted execution path among these two paths. The prediction result of the branch instruction carries the address of the main path. The branch predictor 110 sends the address of the main path to the instruction fetch queue 130, which temporarily stores the address of the main path. When it is not the branch instruction's turn to be executed, the instruction fetch queue 130 sends the address of the main path as the prefetch address of the main path to the first cache 150, which can be referred to as the instruction cache.

[0056] In some embodiments, the prediction result of the branch instruction also carries the confidence classification of the main path. If the confidence classification of the main path is the first category, the address selector 120 needs to select the address of a subsequent execution path different from the main path as the address of the secondary path and send it to the prefetch queue 140. The prefetch queue 140, which can be called the secondary path prefetch queue, is used to temporarily store the addresses of the secondary paths. When it is not the branch instruction's turn to be executed, the prefetch queue 140 sends the address of the secondary path as the prefetch address of the secondary path to the first cache 150. In this embodiment, the confidence classification is simply referred to as confidence, which indicates the probability classification of the main path prediction accuracy. The confidence classification includes a first category and a second category. The first category indicates a low probability of the main path prediction accuracy (low confidence), and the second category indicates a high probability of the main path prediction accuracy (high confidence).

[0057] In some embodiments, the fetch queue 130 and the prefetch queue 140 send instruction requests to their respective caches. Each instruction request includes at least one of: an instruction fetch request, a primary path prefetch request, and a secondary path prefetch request. For example, the fetch queue 130 sends instruction fetch requests to the first cache 150 and the second cache 160, the fetch queue 130 sends primary path prefetch requests to the first cache 150, and the prefetch queue 140 sends secondary path prefetch requests to the first cache 150. The primary path prefetch request is used to request the instruction corresponding to the prefetch address of the primary path, and the secondary path prefetch request is used to request the instruction corresponding to the prefetch address of the secondary path. Each of the three instruction requests carries a corresponding request address. The first cache 150 determines whether the instruction request has a hit by comparing the request address with the address stored in the first cache 150. If the request address matches the stored address, the instruction request has a hit; if the request address does not match the stored address, the instruction request has a miss.

[0058] In some embodiments, for a missed instruction request, the instruction needs to be retrieved from the third cache 170. Missed instruction requests include at least one of: instruction fetch requests, primary path prefetch requests, and secondary path prefetch requests. The third cache 170 is a lower-level cache than the first cache 150, for example, a cache lower than the instruction cache.

[0059] Based on a missed instruction request, the third cache 170 returns the corresponding instruction to the first cache 150 or the second cache 160, respectively. The instruction includes at least one of the following: the instruction currently to be executed, the instruction in the main path (the instruction corresponding to the prefetch address of the main path), or the instruction in the secondary path (the instruction corresponding to the prefetch address of the secondary path). For example, the third cache 170 returns the instruction currently to be executed or the instruction in the main path to the first cache 150, and returns the instruction in the secondary path to the second cache 160.

[0060] Figure 2This illustration shows a schematic diagram of an instruction fetching system 200 provided in an exemplary embodiment of this application. In some embodiments, where the CPU does not include any caches other than the first cache 150 and the second cache 160, for a missed instruction request, it is necessary to request instruction fetching from memory 210. Missed instruction requests include at least one of: instruction fetch request, main path prefetch request, and secondary path prefetch request.

[0061] Based on a missed instruction request, memory 210 returns the corresponding instruction to either the first cache 150 or the second cache 160. The instruction includes at least one of the following: the instruction currently to be executed, the instruction in the main path (the instruction corresponding to the prefetch address of the main path), or the instruction in the secondary path (the instruction corresponding to the prefetch address of the secondary path). For example, memory 210 returns the instruction currently to be executed or the instruction in the main path to the first cache 150, and the instruction in the secondary path to the second cache 160.

[0062] In some embodiments, if an instruction fetch request hits an instruction in the second cache 160, i.e., an instruction of the secondary path, the second cache 160 stores the instruction of the secondary path into the first cache 150.

[0063] In some embodiments, the branch predictor 110 includes a first storage unit 112, such as a branch target buffer (BTB), which stores branch prediction information, including the confidence classification of the main path. The first storage unit 112 includes multiple items (multiple branch prediction information), each item corresponding to a counter. For example, if the counter is a saturation counter, it occupies a small number of bits, such as 3 bits. When the branch predictor makes a prediction error, it increments the value of the corresponding item's saturation counter by 1. Once the saturation counter is saturated (equal to 7 in the case of 3 bits), it stops incrementing.

[0064] To extend the lifespan of the saturation counter, when the total number of mispredictions for branch instructions reaches a certain threshold, the value of the saturation counter for all items is decremented by 1. For example, after the total number of mispredictions for branch instructions reaches 32, the value of the saturation counter for all items is decremented by 1. When the value of the saturation counter is 0, it will no longer be decremented.

[0065] When the branch predictor 110 makes a prediction, if it hits an item in the first storage unit 112, it determines whether the value of the saturation counter corresponding to the hit item is greater than a preset confidence threshold. If it is greater than the confidence threshold, the confidence classification of the item is marked as the first category (low confidence); if it is less than or equal to the confidence threshold, the confidence classification of the item is marked as the second category (high confidence). For example, the confidence classification can be represented by one bit, where a bit value of 1 indicates low confidence and a bit value of 0 indicates high confidence; or a bit value of 1 indicates high confidence and a bit value of 0 indicates low confidence. This embodiment of the application does not limit this.

[0066] In some embodiments, the confidence threshold is dynamically adjusted for workloads that include different numbers of branch instructions.

[0067] For different branch instructions, the confidence classification ratio is compared with the expected ratio. The confidence classification ratio is the proportion of branch instructions corresponding to the first category to the total number of instructions. For example, when the total number of instructions is 1000, the number of branch instructions that are classified as the first category is accumulated by a 10-bit threshold counter. The confidence classification ratio is the ratio of the value of the threshold counter to the total number of instructions. The expected ratio represents the expected confidence classification ratio.

[0068] If the confidence level classification ratio is greater than the expected ratio, increase the confidence level threshold; if the confidence level classification ratio is less than the expected ratio, decrease the confidence level threshold.

[0069] In some embodiments, the confidence threshold can be changed based on a predetermined step size or a dynamic step size determined by the difference between the confidence classification ratio and the expected ratio. Taking a predetermined step size of 1 as an example, if the confidence classification ratio is greater than the expected ratio, the confidence threshold value is incremented by 1; otherwise, the confidence threshold value is decremented by 1. For example, with an expected ratio of 15%, an initial confidence threshold value of 4, and a total instruction count of 1000, the threshold counter value is 100, and the confidence classification ratio is 10%, which is less than 15%. Therefore, the confidence threshold value is adjusted to 3.

[0070] The counter used to represent the confidence threshold is also a saturation counter. When it occupies 3 bits, the saturation counter will not decrease after its value is 0, and will not increase after it is saturated (its value is 7).

[0071] In summary, the method provided in this embodiment, by using the confidence classification ratio as the desired ratio as the control target and adjusting the confidence threshold, can avoid or reduce the problem that the fixed confidence threshold is too large or too small for different load programs, which leads to an unreasonable ratio of the number of first branch instructions to the total number of instructions. The first branch instruction is the branch instruction corresponding to the main path of the confidence classification is the first category.

[0072] The method provided in this embodiment also adds a second cache to store the instructions corresponding to the prefetch address of the secondary path. When the instruction fetch request hits the instruction corresponding to the prefetch address of the secondary path, the instruction corresponding to the prefetch address of the secondary path is then stored in the first cache, which can avoid overwriting the instructions in the first cache.

[0073] Figure 3 A flowchart of an instruction fetching method provided in an exemplary embodiment of this application is shown. The method is executed by a CPU and includes:

[0074] Step 310: Obtain the predicted main path for each branch instruction.

[0075] In some embodiments, each branch instruction corresponds to two candidate subsequent execution paths, and the main path is the path predicted to be executed among the two subsequent execution paths. For example, if the subsequent execution paths are other instructions and the next instruction in sequence, the main path is other instructions when the predicted execution path of the branch instruction is to jump to other instructions; and the main path is the next instruction in sequence when the predicted execution path of the branch instruction is not to jump and to continue executing the next instruction in sequence.

[0076] Step 320: Based on the relationship between the number of historical incorrect predictions of the main path of the same branch instruction and the confidence threshold, determine the confidence classification of the main path corresponding to each branch instruction.

[0077] In some embodiments, the confidence threshold is a dynamically adjusted threshold value.

[0078] In some embodiments, the confidence level classification is used to indicate the probability that the prediction of the main path is accurate. The confidence level classification can also be called the prediction confidence level, or simply confidence level, and includes a first classification and a second classification. For example, if the confidence level classification is the first classification, it indicates that the probability of the prediction of the main path is accurate is low, i.e., the confidence level classification is low; if the confidence level classification of the main path is the second classification, it indicates that the probability of the prediction of the main path is accurate is high, i.e., the confidence level classification is high.

[0079] Step 330: Determine the confidence level classification ratio.

[0080] In some embodiments, the confidence classification ratio is the proportion of branch instructions corresponding to the first classification to the total instructions, and the first classification is the confidence classification where the number of historical false predictions is greater than the confidence threshold.

[0081] In some embodiments, the CPU includes a first storage unit for storing branch prediction information corresponding to the main path, each branch prediction information corresponding to a prediction counter, and the prediction counter for indicating the number of historical erroneous predictions corresponding to the branch prediction information.

[0082] If the value of the prediction counter is greater than the confidence threshold, the confidence classification is the first classification;

[0083] If the value of the prediction counter is less than or equal to the confidence threshold, the confidence classification is a secondary classification.

[0084] Step 340: Adjust the confidence threshold with the expected proportion of confidence classification as the control target.

[0085] In some embodiments, the expected ratio is a preset confidence classification ratio, used to represent a desired, relatively stable confidence classification ratio.

[0086] For different workloads, if the fixed confidence threshold is too small, it will lead to an excessively high confidence classification ratio. An excessively high confidence classification ratio results in an excessive number of instructions prefetched, leaving insufficient space in the instruction cache. Conversely, if the fixed confidence threshold is too large, it will lead to an excessively low confidence classification ratio. An excessively low confidence classification ratio results in an insufficient number of instructions prefetched, which may prevent the CPU from quickly finding the required instructions in the instruction cache, wasting cache space. Adjusting the confidence threshold can avoid or reduce these problems.

[0087] In summary, the method provided in this embodiment, by using the confidence classification ratio as the desired ratio as the control target and adjusting the confidence threshold, can avoid or reduce the problem that the fixed confidence threshold is too large or too small for different load programs, which would lead to an unreasonable proportion of the number of first branch instructions to the total number of instructions. The first branch instruction is the branch instruction corresponding to the main path whose confidence classification is the first category.

[0088] In some embodiments, if the confidence level classification ratio is greater than or less than the expected ratio, the confidence level threshold is adjusted. Figure 4 A flowchart of an instruction fetching method provided in an exemplary embodiment of this application is shown. The method is executed by a CPU and includes:

[0089] Step 310: Obtain the predicted main path for each branch instruction.

[0090] In some embodiments, each branch instruction corresponds to two candidate subsequent execution paths, and the main path is the path predicted to be executed among the two subsequent execution paths. For example, if the subsequent execution paths are other instructions and the next instruction in sequence, the main path is other instructions when the predicted execution path of the branch instruction is to jump to other instructions; and the main path is the next instruction in sequence when the predicted execution path of the branch instruction is not to jump and to continue executing the next instruction in sequence.

[0091] Step 320: Based on the relationship between the number of historical incorrect predictions of the main path of the same branch instruction and the confidence threshold, determine the confidence classification of the main path corresponding to each branch instruction.

[0092] In some embodiments, the confidence threshold is a dynamically adjusted threshold value.

[0093] In some embodiments, the confidence level classification is used to indicate the probability that the prediction of the main path is accurate. The confidence level classification can also be called the prediction confidence level, or simply confidence level, and includes a first classification and a second classification. For example, if the confidence level classification is the first classification, it indicates that the probability of the prediction of the main path is accurate is low, i.e., the confidence level classification is low; if the confidence level classification of the main path is the second classification, it indicates that the probability of the prediction of the main path is accurate is high, i.e., the confidence level classification is high.

[0094] Step 330: Determine the confidence level classification ratio.

[0095] In some embodiments, the confidence classification ratio is the proportion of branch instructions corresponding to the first classification to the total instructions, and the first classification is the confidence classification where the number of historical false predictions is greater than the confidence threshold.

[0096] In some embodiments, the CPU includes a first storage unit for storing branch prediction information corresponding to the main path, each branch prediction information corresponding to a prediction counter, and the prediction counter for indicating the number of historical erroneous predictions corresponding to the branch prediction information.

[0097] If the value of the prediction counter is greater than the confidence threshold, the confidence classification is the first classification;

[0098] If the value of the prediction counter is less than or equal to the confidence threshold, the confidence classification is a secondary classification.

[0099] Step 342: If the confidence level classification ratio is less than the expected ratio, lower the confidence level threshold.

[0100] If the confidence level classification ratio is less than the expected ratio, the confidence level threshold is lowered based on a predetermined step size, or the confidence level threshold is lowered based on a dynamic step size determined by the difference between the confidence level classification ratio and the expected ratio.

[0101] like Figure 1 As shown, the branch predictor 110 is used to adjust the confidence threshold. The branch predictor 110 includes a first storage unit 112, which stores branch prediction information, including the confidence classification of the main path. The first storage unit 112 includes multiple items (multiple branch prediction information), each item corresponding to a counter. Taking a saturation counter as an example, the saturation counter occupies a small number of bits, such as 3 bits. When the branch predictor makes a prediction error, it increments the value of the corresponding item's saturation counter by 1. Once the saturation counter is saturated (equal to 7 in the case of 3 bits), it stops incrementing.

[0102] When the branch predictor 110 makes a prediction, if it hits an item in the first storage unit 112, it determines whether the value of the saturation counter corresponding to the hit item is greater than a preset confidence threshold. If it is greater than the confidence threshold, the confidence classification of the item is marked as the first category (low confidence); if it is less than or equal to the confidence threshold, the confidence classification of the item is marked as the second category (high confidence). For example, the confidence classification can be represented by one bit, where a bit value of 1 indicates low confidence and a bit value of 0 indicates high confidence; or a bit value of 1 indicates high confidence and a bit value of 0 indicates low confidence. This embodiment of the application does not limit this.

[0103] For different branch instructions, the confidence classification ratio is compared with the expected ratio. The confidence classification ratio is the proportion of branch instructions corresponding to the first category to the total number of instructions. For example, when the total number of instructions is 1000, the number of branch instructions that are classified as the first category is accumulated by a 10-bit threshold counter. The confidence classification ratio is the ratio of the value of the threshold counter to the total number of instructions. The expected ratio represents the expected confidence classification ratio.

[0104] If the confidence level classification ratio is greater than the expected ratio, increase the confidence level threshold; if the confidence level classification ratio is less than the expected ratio, decrease the confidence level threshold.

[0105] In some embodiments, the confidence threshold can be changed based on a predetermined step size. Taking a predetermined step size of 1 as an example, if the confidence classification ratio is greater than the expected ratio, the confidence threshold value is incremented by 1; otherwise, the confidence threshold value is decremented by 1. For example, if the expected ratio is 15%, the initial confidence threshold value is 4, and the total number of instructions is 1000, the threshold counter value is 100, and the confidence classification ratio is 10%, which is less than 15%. Therefore, the confidence threshold value is adjusted to 3.

[0106] In some embodiments, the confidence threshold can be changed based on a dynamic step size determined by the difference between the confidence classification ratio and the expected ratio. For example, with an expected ratio of 15%, an initial confidence threshold value of 5, and a total number of instructions of 1000, the threshold counter value is 100, and the confidence classification ratio is 10%, which is less than 15%. Therefore, the confidence threshold value is adjusted to 3, so that when the total number of instructions is 1000, the threshold counter value is 150, and the confidence classification ratio is 15%.

[0107] Step 344: If the confidence level classification ratio is greater than the expected ratio, increase the confidence level threshold.

[0108] In some embodiments, when the confidence classification ratio is greater than the expected ratio, the confidence threshold is increased based on a predetermined step size, or the confidence threshold is increased based on a dynamic step size determined by the difference between the confidence classification ratio and the expected ratio.

[0109] The principle of raising the confidence threshold is the same as that of lowering the confidence threshold. For specific implementation details, please refer to step 342, which will not be repeated here.

[0110] In summary, the method provided in this embodiment adjusts the confidence threshold by using the confidence classification ratio as the desired ratio as the control target. For example, the confidence threshold is adjusted according to a predetermined step size or a dynamic step size determined by the difference between the confidence classification ratio and the desired ratio. This can avoid or reduce the problem that the fixed confidence threshold is too large or too small for different load programs, which would lead to an unreasonable proportion of the number of first branch instructions to the total number of instructions. The first branch instruction is the branch instruction corresponding to the main path where the confidence classification is the first category.

[0111] In some embodiments, different caching methods are used depending on the confidence level classification. Figure 5 A flowchart of an instruction fetching method provided in an exemplary embodiment of this application is shown. The method is executed by a CPU and includes:

[0112] Step 310: Obtain the predicted main path for each branch instruction.

[0113] In some embodiments, each branch instruction corresponds to two candidate subsequent execution paths, and the main path is the path predicted to be executed among the two subsequent execution paths. For example, if the subsequent execution paths are other instructions and the next instruction in sequence, the main path is other instructions when the predicted execution path of the branch instruction is to jump to other instructions; and the main path is the next instruction in sequence when the predicted execution path of the branch instruction is not to jump and to continue executing the next instruction in sequence.

[0114] Step 320: Based on the relationship between the number of historical incorrect predictions of the main path of the same branch instruction and the confidence threshold, determine the confidence classification of the main path corresponding to each branch instruction.

[0115] In some embodiments, the confidence threshold is a dynamically adjusted threshold value.

[0116] In some embodiments, the confidence level classification is used to indicate the probability that the prediction of the main path is accurate. The confidence level classification can also be called the prediction confidence level, or simply confidence level, and includes a first classification and a second classification. For example, if the confidence level classification is the first classification, it indicates that the probability of the prediction of the main path is accurate is low, i.e., the confidence level classification is low; if the confidence level classification of the main path is the second classification, it indicates that the probability of the prediction of the main path is accurate is high, i.e., the confidence level classification is high.

[0117] Step 322: Obtain instruction request.

[0118] In some embodiments, an instruction request includes at least one of the following: an instruction fetch request; a primary path prefetch request; and a secondary path prefetch request.

[0119] Specifically, the instruction fetch request is used to request the fetch of the instruction to be executed; the main path prefetch request is used to request the prefetch of the instruction in the main path, which is the instruction corresponding to the prefetch address of the main path; and the secondary path prefetch request is used to request the prefetch of the instruction in the secondary path, which is the instruction corresponding to the prefetch address of the secondary path.

[0120] Step 3242: If the confidence classification is the first category, use the first caching method.

[0121] In some embodiments, the CPU includes a first cache for storing the prefetch address of the main path and the prefetch address of the secondary path. The prefetch address of the main path is the address of the main path, and the prefetch address of the secondary path is the address of a subsequent execution path different from the main path. The confidence classification includes a first classification and a second classification, where the second classification is a confidence classification where the number of historical error predictions is less than or equal to a confidence threshold. The first cache is also used to store the instructions corresponding to the prefetch addresses of the main path and the instructions corresponding to the prefetch addresses of the secondary paths.

[0122] In some embodiments, the instruction request includes a primary path prefetch request or a secondary path prefetch request, and the first caching method includes: obtaining the instruction of the primary path based on the primary path prefetch request and the hit status of the primary path prefetch address, wherein the instruction of the primary path is the instruction corresponding to the primary path prefetch address; or, obtaining the instruction of the secondary path based on the secondary path prefetch request and the hit status of the secondary path prefetch address, wherein the instruction of the secondary path is the instruction corresponding to the secondary path prefetch address.

[0123] Commands for the main path:

[0124] In some embodiments, the central processing unit further includes a third cache, which is a lower-level cache of the first cache. Based on the main path prefetch request and the hit status of the main path's prefetch address, the instructions for obtaining the main path are included, including:

[0125] If the main path prefetch request hits the main path prefetch address, the main path instruction is retrieved from the first cache.

[0126] If the main path prefetch request does not hit the main path prefetch address, the first cache sends the main path prefetch request to the third cache, and the third cache stores the main path instruction into the first cache.

[0127] In some embodiments, if a primary path prefetch request hits the prefetch address of a secondary path, the instruction for the primary path is retrieved from the first cache.

[0128] If the primary path prefetch request does not hit the secondary path prefetch address, the first cache sends the primary path prefetch request to the third cache, and the third cache stores the primary path instruction into the first cache.

[0129] In some embodiments, if the main path prefetch request hits the address of the instruction fetch request, the main path instruction is retrieved from the first cache.

[0130] If the main path prefetch request does not hit the address of the instruction fetch request, the first cache sends the main path prefetch request to the third cache, and the third cache stores the main path instruction into the first cache.

[0131] like Figure 1 As shown, the instruction fetch queue 130 and the prefetch queue 140 send instruction requests to their respective caches. Instruction requests include at least one of the following: instruction fetch request, primary path prefetch request, and secondary path prefetch request. For example, instruction fetch queue 130 sends instruction fetch requests to the first cache 150 and the second cache 160; instruction fetch queue 130 sends primary path prefetch requests to the first cache 150; and prefetch queue 140 sends secondary path prefetch requests to the first cache 150. The primary path prefetch request is used to request the instruction corresponding to the prefetch address of the primary path, and the secondary path prefetch request is used to request the instruction corresponding to the prefetch address of the secondary path. Each of the three instruction requests carries a corresponding request address. The first cache 150 determines whether the instruction request has a hit by comparing the request address with the address stored in the first cache 150. If the request address matches the stored address, the instruction request has a hit; if the request address does not match the stored address, the instruction request has a miss.

[0132] For instruction requests that miss, the instruction needs to be retrieved from the third cache. Instruction requests that miss include at least one of the following: instruction fetch requests, main path prefetch requests, and secondary path prefetch requests. The third cache is a lower-level cache than the first cache, such as a cache lower than the instruction cache. Optionally, for instruction requests that miss, the instruction needs to be retrieved from memory.

[0133] Based on a missed instruction request, the third cache returns the corresponding instruction. After the third cache returns the corresponding instruction, different instructions are stored in their respective memories. Instructions include at least one of the following: instruction fetch result, main path prefetch result, and secondary path prefetch result. Specifically, the instruction fetch result includes the instruction currently to be executed, the main path prefetch result includes the instruction of the main path (the instruction corresponding to the prefetch address of the main path), and the secondary path prefetch result includes the instruction of the secondary path (the instruction corresponding to the prefetch address of the secondary path). For example, the third cache stores the main path instruction into the first cache.

[0134] In some embodiments, when the central processing unit (CPU) first starts up, the first cache does not contain any stored addresses or instructions. 1. Taking other instructions A, branch instructions B, other instructions C, and other instructions D in sequence as an example, when other instructions A need to be executed, the instruction fetch queue sends a first fetch request to the first cache. The first fetch request carries the address of other instructions A. If the instruction is not fetched, the first cache stores the address of other instructions A and sends the first fetch request to the third cache. If the instruction is fetched, other instructions A are returned to the first cache.

[0135] 2. The instruction fetch queue sends the first main path prefetch request, which carries the address of the main path of branch instruction B. It is sent to the first cache. If there is no hit, the first cache stores the address of the main path and sends the first main path prefetch request to the third cache. If there is a hit, the instruction corresponding to the address of the main path is returned to the first cache.

[0136] 3. The instruction fetch queue sends a second main path prefetch request, which carries the address of other instruction C. It is sent to the first cache. If there is a miss, the first cache stores the address of other instruction C and sends the second main path prefetch request to the third cache. If there is a hit, the instruction corresponding to the address of other instruction C is returned to the first cache.

[0137] 4. The instruction fetch queue sends a third main path prefetch request, which carries the address of other instruction D. It is sent to the first cache. If there is a miss, the first cache stores the address of other instruction D and sends the third main path prefetch request to the third cache. If there is a hit, the instruction corresponding to the address of other instruction D is returned to the first cache.

[0138] 5. When the instruction fetch queue sends a main path prefetch request, the CPU continues to execute instructions. When the CPU executes branch instruction B, the instruction fetch queue sends a second instruction fetch request to the first cache. The second instruction fetch request carries the address of the main path of branch instruction B. If the address of the main path of branch instruction B is hit in the first cache, the main path of branch instruction B is executed, for example, jumping to other instruction D.

[0139] 6. When the CPU executes another instruction D, the fetch queue sends a third fetch request to the first cache. The third fetch request carries the address of the other instruction D. If the address of the other instruction D is found in the first cache, the other instruction D is fetched.

[0140] 7. The instruction fetch queue then continues to send main path prefetch requests. If the subsequent main path prefetch request carries the address of other instruction A, the main path address of branch instruction B, the address of other instruction C, and the address of other instruction D, the main path prefetch request will be able to hit the cache and directly retrieve the corresponding instruction from the first cache without having to retrieve the corresponding instruction from the third cache.

[0141] Instructions for the secondary path:

[0142] In some embodiments, the central processing unit further includes: a second cache and a third cache, wherein the third cache is a lower-level cache of the first cache. Based on the secondary path prefetch request and the hit status of the secondary path's prefetch address, the instructions for obtaining the secondary path are obtained, including:

[0143] If the secondary path prefetch request hits the secondary path prefetch address, the first cache retrieves the instruction for the secondary path;

[0144] If the secondary path prefetch request does not hit the secondary path prefetch address, the first cache sends the secondary path prefetch request to the third cache, and the third cache stores the secondary path instruction into the second cache.

[0145] In some embodiments, if a secondary path prefetch request hits the prefetch address of the primary path, the first cache retrieves the instruction for the secondary path.

[0146] If the secondary path prefetch request does not hit the prefetch address of the primary path, the first cache sends the secondary path prefetch request to the third cache, and the third cache stores the secondary path instruction into the second cache.

[0147] In some embodiments, if the secondary path prefetch request hits the address of the instruction fetch request, the first cache fetches the instruction of the secondary path.

[0148] If the secondary path prefetch request does not hit the address of the instruction fetch request, the first cache sends the secondary path prefetch request to the third cache, and the third cache stores the instruction of the secondary path into the second cache.

[0149] like Figure 1 As shown, the instruction fetch queue 130 and the prefetch queue 140 send instruction requests to their respective caches. Instruction requests include at least one of the following: instruction fetch request, primary path prefetch request, and secondary path prefetch request. For example, instruction fetch queue 130 sends instruction fetch requests to the first cache 150 and the second cache 160; instruction fetch queue 130 sends primary path prefetch requests to the first cache 150; and prefetch queue 140 sends secondary path prefetch requests to the first cache 150. The primary path prefetch request is used to request the instruction corresponding to the prefetch address of the primary path, and the secondary path prefetch request is used to request the instruction corresponding to the prefetch address of the secondary path. Each of the three instruction requests carries a corresponding request address. The first cache 150 determines whether the instruction request has a hit by comparing the request address with the address stored in the first cache 150. If the request address matches the stored address, the instruction request has a hit; if the request address does not match the stored address, the instruction request has a miss.

[0150] For instruction requests that miss, the instruction needs to be retrieved from the third cache. Instruction requests that miss include at least one of the following: instruction fetch requests, main path prefetch requests, and secondary path prefetch requests. The third cache is a lower-level cache than the first cache, such as a cache lower than the instruction cache. Optionally, for instruction requests that miss, the instruction needs to be retrieved from memory.

[0151] Based on a missed instruction request, the third cache returns the corresponding instruction. After the third cache returns the corresponding instruction, different instructions are stored in their respective memories. Instructions include at least one of the following: instruction fetch result, main path prefetch result, and secondary path prefetch result. Specifically, the instruction fetch result includes the instruction currently to be executed, the main path prefetch result includes the instruction of the main path (the instruction corresponding to the prefetch address of the main path), and the secondary path prefetch result includes the instruction of the secondary path (the instruction corresponding to the prefetch address of the secondary path). For example, the third cache stores the main path instruction in the first cache and the secondary path instruction in the second cache.

[0152] In some embodiments, the instruction request further includes an instruction fetch request, in which the second cache stores the instruction of the secondary path into the first cache if the instruction fetch request hits an instruction of the secondary path in the second cache.

[0153] In related technologies, instructions for the secondary path are directly stored in the first cache, which may lead to the replacement of currently executed instructions or other stored instructions, thus overwriting the instructions in the first cache. By first storing the instructions corresponding to the prefetch address of the secondary path in the second cache, and then storing the instructions corresponding to the prefetch address of the secondary path into the first cache when the instruction fetch request hits the instruction corresponding to the prefetch address of the secondary path, the overwriting of the instructions in the first cache can be avoided.

[0154] Step 3244: If the confidence classification is the second classification, use the second caching method.

[0155] In some embodiments, the second caching method includes: obtaining instructions for the main path based on the main path prefetch request and the hit status of the main path prefetch address.

[0156] The second caching method is the same as the instruction for the main path in step 3242. For specific implementation details, please refer to step 3242, which will not be repeated here.

[0157] Step 330: Determine the confidence level classification ratio.

[0158] In some embodiments, the confidence classification ratio is the proportion of branch instructions corresponding to the first classification to the total instructions, and the first classification is the confidence classification where the number of historical false predictions is greater than the confidence threshold.

[0159] In some embodiments, the CPU includes a first storage unit for storing branch prediction information corresponding to the main path, each branch prediction information corresponding to a prediction counter, and the prediction counter for indicating the number of historical erroneous predictions corresponding to the branch prediction information.

[0160] If the value of the prediction counter is greater than the confidence threshold, the confidence classification is the first classification;

[0161] If the value of the prediction counter is less than or equal to the confidence threshold, the confidence classification is a secondary classification.

[0162] Step 340: Adjust the confidence threshold with the expected proportion of confidence classification as the control target.

[0163] In some embodiments, the expected ratio is a preset confidence classification ratio, used to represent a desired, relatively stable confidence classification ratio.

[0164] For different workloads, if the fixed confidence threshold is too small, it will lead to an excessively high confidence classification ratio. An excessively high confidence classification ratio results in an excessive number of instructions prefetched, leaving insufficient space in the instruction cache. Conversely, if the fixed confidence threshold is too large, it will lead to an excessively low confidence classification ratio. An excessively low confidence classification ratio results in an insufficient number of instructions prefetched, which may prevent the CPU from quickly finding the required instructions in the instruction cache, wasting cache space. Adjusting the confidence threshold can avoid or reduce these problems.

[0165] In summary, the method provided in this embodiment adds a second cache to store the instructions corresponding to the prefetch address of the secondary path. When the instruction fetch request hits the instruction corresponding to the prefetch address of the secondary path, the instruction corresponding to the prefetch address of the secondary path is then stored in the first cache, which can avoid overwriting the instructions in the first cache.

[0166] In the above embodiments, steps with the same sequence number can be considered as the same step. Wherein, Figure 3 Corresponding implementation examples, Figure 4 Corresponding embodiments and Figure 5 The corresponding embodiments can be implemented individually or in combination, and this application does not limit them.

[0167] This application provides a central processing unit (CPU) with the following structure: Figure 1 As shown, it includes:

[0168] Branch predictor 110 is used to obtain the main path predicted for each branch instruction. Each branch instruction corresponds to two candidate subsequent execution paths. The main path is the path predicted to be executed among the two subsequent execution paths.

[0169] Branch predictor 110 is used to determine the confidence classification of the main path corresponding to each branch instruction based on the size between the number of historical erroneous predictions of the main path for the same branch instruction and the confidence threshold. The confidence classification is used to indicate the probability classification of the accuracy of the main path prediction.

[0170] Branch predictor 110 is used to determine the confidence classification ratio, which is the proportion of branch instructions corresponding to the first classification to the total instructions. The first classification is the confidence classification where the number of historical false predictions is greater than the confidence threshold.

[0171] Branch predictor 110 is used to adjust the confidence threshold with the expected proportion of confidence classification as the control target.

[0172] In one possible design of this embodiment, the branch predictor 110 is used to increase the confidence threshold when the confidence classification ratio is greater than the expected ratio, and to decrease the confidence threshold when the confidence classification ratio is less than the expected ratio.

[0173] In one possible design of this embodiment, the branch predictor 110 is used to increase the confidence threshold based on a predetermined step size when the confidence classification ratio is greater than the expected ratio, or to increase the confidence threshold based on a dynamic step size determined by the difference between the confidence classification ratio and the expected ratio.

[0174] Branch predictor 110 is used to reduce the confidence threshold based on a predetermined step size when the confidence classification ratio is less than the expected ratio, or to reduce the confidence threshold based on a dynamic step size determined by the difference between the confidence classification ratio and the expected ratio.

[0175] In one possible design of this embodiment, the central processing unit includes a first cache 150, which is used to store the prefetch address of the main path and the prefetch address of the secondary path. The prefetch address of the main path is the address of the main path, and the prefetch address of the secondary path is the address of the subsequent execution path that is different from the main path. The confidence classification includes a first classification and a second classification. The second classification is a confidence classification in which the number of historical error predictions is less than or equal to the confidence threshold.

[0176] The first cache (150) is also used to retrieve instruction requests; the first cache method is used when the confidence classification is the first category; the second cache method is used when the confidence classification is the second category.

[0177] The instruction request includes a primary path prefetch request or a secondary path prefetch request. The first caching method includes: obtaining the primary path instruction based on the primary path prefetch request and the hit status of the primary path prefetch address, wherein the primary path instruction is the instruction corresponding to the primary path prefetch address; or, obtaining the secondary path instruction based on the secondary path prefetch request and the hit status of the secondary path prefetch address, wherein the secondary path instruction is the instruction corresponding to the secondary path prefetch address. The second caching method includes: obtaining the primary path instruction based on the primary path prefetch request and the hit status of the primary path prefetch address.

[0178] In one possible design of this embodiment, the central processing unit further includes: a second cache 160 and a third cache 170, wherein the third cache 170 is a lower-level cache of the first cache;

[0179] If a secondary path prefetch request hits the secondary path prefetch address, the first cache 150 is used to retrieve the instruction for the secondary path.

[0180] If the secondary path prefetch request does not hit the prefetch address of the secondary path, the first cache 150 sends the secondary path prefetch request to the third cache 170, and the third cache 170 stores the instruction of the secondary path into the second cache 160.

[0181] In one possible design of this embodiment, the instruction request also includes an instruction fetch request, and the second cache 160 is further configured to: if the instruction fetch request hits an instruction of the secondary path in the second cache 160, the second cache 160 stores the instruction of the secondary path into the first cache 150.

[0182] In one possible design of this embodiment, the central processing unit further includes a third cache 170, which is a lower-level cache of the first cache 150;

[0183] If the main path prefetch request hits the main path prefetch address, the instruction to retrieve the main path is retrieved from the first cache 150;

[0184] If the main path prefetch request does not hit the main path prefetch address, the first cache sends the main path prefetch request to the third cache 170, and the third cache 170 stores the main path instruction into the first cache 150.

[0185] For detailed information on the central processing unit architecture, please refer to [link / reference]. Figure 1 Examples are not described here.

[0186] This application also provides a computer device, which includes a processor and a memory, wherein the memory stores at least one program; the processor is used to execute the at least one program in the memory to implement the instruction fetching method provided in the above method embodiments.

[0187] In some embodiments, a branch instruction corresponds to two candidate subsequent execution paths, the main path is the path predicted to be executed among the two subsequent execution paths, and the secondary path is a subsequent execution path different from the main path; the processor also includes a second cache, which is used to retrieve and store the instruction corresponding to the address of the secondary path, and the processor is also used to execute at least one program in memory to implement, as shown in the example. Figure 5 For details on the instruction fetching method and the specific implementation of the second cache in this embodiment, please refer to [link / reference]. Figure 1 Examples and Figure 5 Examples are not described here.

[0188] Figure 6 This is a structural block diagram of a computer device 600 provided in an exemplary embodiment of this application. Typically, the computer device 600 includes a processor 601 and a memory 602.

[0189] Processor 601 may include one or more processing cores, such as a quad-core processor, an octa-core processor, etc. Processor 601 may be implemented using at least one hardware form selected from Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA). Processor 601 may also include a main processor and a coprocessor. The main processor, also known as a Central Processing Unit (CPU), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 601 may include a Graphics Processing Unit (GPU), which is responsible for rendering and drawing the content required to be displayed on the screen. In some embodiments, processor 601 may also include an Artificial Intelligence (AI) processor, which is used to handle computational operations related to machine learning.

[0190] The memory 602 may include one or more computer-readable storage media, which may be non-transitory. The memory 602 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 602 are used to store at least one instruction, which is executed by the processor 601 to implement the instruction fetching method provided in the method embodiments of this application.

[0191] In some embodiments, the computer device 600 may optionally include an input interface 603 and an output interface 604. The processor 601, memory 602, and input interfaces 603 and 604 can be connected via a bus or signal lines. Various peripheral devices can be connected to the input interfaces 603 and 604 via a bus, signal lines, or a circuit board. The input interfaces 603 and 604 can be used to connect at least one input / output related peripheral device to the processor 601 and memory 602. In some embodiments, the processor 601, memory 602, and input interfaces 603 and 604 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 601, memory 602, and input interfaces 603 and 604 can be implemented on separate chips or circuit boards, and this application does not limit this aspect.

[0192] Those skilled in the art will understand that the structure shown above does not constitute a limitation on the computer device 600, and may include more or fewer components than shown, or combine certain components, or employ different component arrangements.

[0193] In an exemplary embodiment, a chip is also provided, the chip including programmable logic circuits and / or program instructions, which, when the chip is run on a computer device 600, are used to implement the instruction acquisition method provided in the method embodiments of this application.

[0194] In an exemplary embodiment, a computer program product is also provided, which includes computer instructions stored in a computer-readable storage medium. A processor retrieves the computer instructions from the computer-readable storage medium and executes the computer instructions to implement the instruction retrieval method provided in the method embodiments of this application.

[0195] In an exemplary embodiment, a computer-readable storage medium is also provided, which stores at least one program that is loaded and executed by a processor to implement the instruction acquisition method provided in the method embodiments of this application.

[0196] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0197] Those skilled in the art will recognize that the functions described in the embodiments of this application in one or more of the above examples can be implemented using hardware, software, firmware, or any combination thereof. When implemented using software, these functions can be stored in a computer-readable storage medium or transmitted as one or more instructions or code on a computer-readable storage medium. Computer-readable storage media include computer storage media and communication media, wherein communication media include any medium that facilitates the transmission of a computer program from one place to another. Storage media can be any available medium accessible to a general-purpose or special-purpose computer.

[0198] The above are merely optional embodiments of this application and are not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for acquiring instructions, characterized in that, The method is executed by a central processing unit, and the method includes: Obtain the predicted main path for each branch instruction, where each branch instruction corresponds to two candidate subsequent execution paths, and the main path is the path predicted to be executed among the two subsequent execution paths; Based on the magnitude between the number of historical erroneous predictions of the main path for the same branch instruction and the confidence threshold, the confidence classification of the main path corresponding to each branch instruction is determined, and the confidence classification is used to indicate the probability classification of the accuracy of the prediction of the main path. Determine the confidence level classification ratio, which is the proportion of branch instructions corresponding to the first category to the total instructions, where the first category is the confidence level classification where the number of historical error predictions is greater than the confidence level threshold; The confidence threshold is adjusted by using the expected proportion of the confidence level classification as the control target. Each branch instruction corresponds to a branch prediction information corresponding to a saturation counter. The saturation counter is used to record the number of historical erroneous predictions of the main path of the branch instruction. When the main path is erroneously predicted, the value of the saturation counter is incremented by 1. After the saturation counter is saturated, the value of the saturation counter no longer increases. When the total number of erroneous predictions of the branch instruction reaches a preset threshold, the value of all saturation counters is decremented by 1. When the value of the saturation counter is 0, the value of the saturation counter no longer decreases.

2. The method according to claim 1, characterized in that, The step of adjusting the confidence threshold using the confidence level classification ratio as the desired ratio as the control target includes: If the confidence level classification ratio is greater than the expected ratio, the confidence threshold is increased. If the confidence level classification ratio is less than the expected ratio, the confidence level threshold is lowered.

3. The method according to claim 2, characterized in that, The step of raising the confidence threshold when the confidence classification ratio is greater than the expected ratio includes: If the confidence classification ratio is greater than the expected ratio, the confidence threshold is increased based on a predetermined step size, or the confidence threshold is increased based on a dynamic step size determined by the difference between the confidence classification ratio and the expected ratio. The step of lowering the confidence threshold when the confidence classification ratio is less than the expected ratio includes: If the confidence classification ratio is less than the expected ratio, the confidence threshold is reduced based on the predetermined step size, or the confidence threshold is reduced based on the dynamic step size determined by the difference between the confidence classification ratio and the expected ratio.

4. The method according to any one of claims 1 to 3, characterized in that, The central processing unit includes a first cache for storing the prefetch address of the main path and the prefetch address of the secondary path. The prefetch address of the main path is the address of the main path, and the prefetch address of the secondary path is the address of a subsequent execution path different from the main path. The confidence classification includes a first classification and a second classification. The second classification is a confidence classification where the number of historical error predictions is less than or equal to the confidence threshold. The method further includes: Obtain instruction request; if the confidence classification is the first classification, use the first caching method; if the confidence classification is the second classification, use the second caching method. The instruction request includes a primary path prefetch request or a secondary path prefetch request. The first caching method includes: obtaining the instruction of the primary path based on the hit status of the primary path prefetch request and the prefetch address of the primary path, wherein the instruction of the primary path is the instruction corresponding to the prefetch address of the primary path; or, obtaining the instruction of the secondary path based on the hit status of the secondary path prefetch request and the prefetch address of the secondary path, wherein the instruction of the secondary path is the instruction corresponding to the prefetch address of the secondary path. The second caching method includes: obtaining the instruction of the primary path based on the hit status of the primary path prefetch request and the prefetch address of the primary path.

5. The method according to claim 4, characterized in that, The central processing unit further includes: a second cache and a third cache, wherein the third cache is a lower-level cache of the first cache; The instruction to obtain the secondary path based on the secondary path prefetch request and the hit status of the secondary path's prefetch address includes: If the secondary path prefetch request hits the prefetch address of the secondary path, the first cache retrieves the instruction for the secondary path; If the secondary path prefetch request fails to find the prefetch address of the secondary path, the first cache sends the secondary path prefetch request to the third cache, and the third cache stores the instruction of the secondary path into the second cache.

6. The method according to claim 5, characterized in that, The instruction request further includes an instruction fetch request, and the method further includes: If the instruction fetch request hits the instruction of the secondary path in the second cache, the second cache stores the instruction of the secondary path into the first cache.

7. The method according to claim 4, characterized in that, The central processing unit also includes a third cache, which is a lower-level cache than the first cache; The instruction to obtain the main path based on the main path prefetch request and the hit status of the main path's prefetch address includes: If the main path prefetch request hits the prefetch address of the main path, the instruction for the main path is retrieved from the first cache; If the main path prefetch request fails to hit the prefetch address of the main path, the first cache sends the main path prefetch request to the third cache, and the third cache stores the main path instruction into the first cache.

8. A central processing unit, characterized in that, The central processing unit includes: A branch predictor is used to obtain the predicted main path for each branch instruction, each branch instruction having two candidate subsequent execution paths, and the main path being the path predicted to be executed among the two subsequent execution paths; The branch predictor is used to determine the confidence classification of the main path corresponding to each branch instruction based on the size between the number of historical erroneous predictions of the main path for the same branch instruction and the confidence threshold. The confidence classification is used to indicate the probability classification of the accuracy of the prediction of the main path. The branch predictor is used to determine the confidence classification ratio, which is the proportion of branch instructions corresponding to the first classification to the total instructions, and the first classification is the confidence classification in which the number of historical false predictions is greater than the confidence threshold. The branch predictor is used to adjust the confidence threshold with the expected proportion of the confidence classification as the control target. The central processing unit further includes a saturation counter, wherein each branch prediction information corresponding to a branch instruction corresponds to a saturation counter, and the saturation counter is used to record the number of historical mispredictions of the main path of the branch instruction; when the main path is mispredicted, the value of the saturation counter is incremented by 1, and after the saturation counter is saturated, the value of the saturation counter no longer increases; when the total number of mispredictions of the branch instruction reaches a preset threshold, the value of all saturation counters is decremented by 1; when the value of the saturation counter is 0, the value of the saturation counter no longer decreases.

9. The central processing unit according to claim 8, characterized in that, The branch predictor is also used to increase the confidence threshold when the confidence classification ratio is greater than the expected ratio; The branch predictor is also used to lower the confidence threshold when the confidence classification ratio is less than the expected ratio.

10. The central processing unit according to claim 9, characterized in that, The branch predictor is further configured to, when the confidence classification ratio is greater than the expected ratio, increase the confidence threshold based on a predetermined step size, or increase the confidence threshold based on a dynamic step size determined by the difference between the confidence classification ratio and the expected ratio. The branch predictor is further configured to, when the confidence classification ratio is less than the expected ratio, reduce the confidence threshold based on the predetermined step size, or reduce the confidence threshold based on the dynamic step size determined by the difference between the confidence classification ratio and the expected ratio.

11. The central processing unit according to any one of claims 8 to 10, characterized in that, The central processing unit includes a first cache, which stores the prefetch address of the main path and the prefetch address of the secondary path. The prefetch address of the main path is the address of the main path, and the prefetch address of the secondary path is the address of the subsequent execution path that is different from the main path. The confidence classification includes a first classification and a second classification. The second classification is a confidence classification in which the number of historical error predictions is less than or equal to the confidence threshold. The first cache is used to retrieve instruction requests. When the confidence classification is the first classification, a first caching method is used; when the confidence classification is the second classification, a second caching method is used. The instruction request includes a primary path prefetch request or a secondary path prefetch request. The first caching method includes: obtaining the instruction of the primary path based on the hit status of the primary path prefetch request and the prefetch address of the primary path, wherein the instruction of the primary path is the instruction corresponding to the prefetch address of the primary path; or, obtaining the instruction of the secondary path based on the hit status of the secondary path prefetch request and the prefetch address of the secondary path, wherein the instruction of the secondary path is the instruction corresponding to the prefetch address of the secondary path. The second caching method includes: obtaining the instruction of the primary path based on the hit status of the primary path prefetch request and the prefetch address of the primary path.

12. The central processing unit according to claim 11, characterized in that, The central processing unit further includes a second cache and a third cache, wherein the third cache is a lower-level cache of the first cache; The first cache is also used to obtain the instruction of the secondary path when the secondary path prefetch request hits the prefetch address of the secondary path; If the secondary path prefetch request fails to find the prefetch address of the secondary path, the first cache sends the secondary path prefetch request to the third cache, and the third cache stores the instruction of the secondary path into the second cache.

13. The central processing unit according to claim 12, characterized in that, The instruction request also includes an instruction fetch request; The second cache stores the instruction of the secondary path into the first cache when the instruction fetch request hits the instruction of the secondary path in the second cache.

14. The central processing unit according to claim 11, characterized in that, The central processing unit also includes a third cache, which is a lower-level cache than the first cache; The third cache is also used to retrieve the instruction of the main path from the first cache when the main path prefetch request hits the prefetch address of the main path; If the main path prefetch request fails to hit the prefetch address of the main path, the first cache is further configured to send the main path prefetch request to the third cache, and the third cache is further configured to store the instruction of the main path into the first cache.

15. A computer device, characterized in that, The computer device includes a processor and a memory, wherein the memory stores at least one program; the processor is configured to execute the at least one program in the memory to implement the instruction fetching method as described in any one of claims 1 to 4 or the instruction fetching method as described in claim 7.

16. The computer device according to claim 15, characterized in that, A branch instruction corresponds to two candidate subsequent execution paths. The main path is the path predicted to be executed among the two subsequent execution paths, and the secondary path is a subsequent execution path that is different from the main path. The processor further includes a second cache for acquiring and storing instructions corresponding to the address of the secondary path, and the processor is also used to execute the at least one program in the memory to implement the instruction acquisition method as described in claim 5 or 6.

17. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one program, which is loaded and executed by a processor to implement the instruction fetching method as described in any one of claims 1 to 7.

18. A computer program product, characterized in that, The computer program product includes computer instructions stored in a computer-readable storage medium, a processor retrieving the computer instructions from the computer-readable storage medium, and the processor executing the computer instructions to implement the instruction retrieval method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method and Apparatus for Dynamically Managing Instruction Buffer Depths for Non-Predicted Branches

    US20090063819A1

  • Controlling population size of confidence assignments

    US6625744B1