CN-121996298-A - Prediction method, branch predictor and processor
Abstract
The application provides a prediction method, a branch predictor and a processor, when different threads run the same program, if the branch predictor shares the data of each thread among the threads, whether the label in a history prediction table is the same as the label to be compared or not is compared, and the jump direction of a saturation counter is used as the prediction jump direction in the history prediction table corresponding to the branch histories with the same label to be compared and the longest history length. If the branch predictor independently stores the data of each thread, comparing whether the label in the history prediction table is the same as the label to be compared and whether the thread label is the same as the thread number, and taking the jump direction of the saturation counter as the prediction jump direction in the history prediction table corresponding to the branch history with the same label to be compared, the same thread label as the thread number and the longest history length, thereby not only sharing the table items among the threads, but also distinguishing the threads corresponding to the table items, reducing the misprediction rate of the branch prediction of the simultaneous multithread processor and improving the instruction fetching efficiency.
Inventors
- Tan Hongze
- WANG WENXIANG
Assignees
- 龙芯中科技术股份有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20251229
Claims (10)
- 1. A method of prediction for a branch predictor, the method comprising: Acquiring a program counter of a current thread and a plurality of branch histories with history lengths, and generating a history prediction table corresponding to the branch histories with the history lengths according to the program counter and the branch histories with the history lengths, wherein each history prediction table comprises a prediction item and a label to be compared, and the prediction item comprises a saturation counter, a label and a thread label; When different threads run the same program and the branch predictor shares the data of each thread among the threads, comparing whether the label in each history prediction table is the same as the label to be compared, and when the label in each history prediction table is different from the label to be compared, the jump direction of the saturation counter in the history prediction table corresponding to the branch history with the longest history length in the history prediction table with the label identical to the label to be compared is used as the predicted jump direction, and the jump direction predicted by the basic predictor is used as the predicted jump direction; When different threads run the same program and the branch predictors independently store the data of each thread, comparing whether the labels in each history prediction table are the same as the labels to be compared and whether the thread labels are the same as the thread numbers of the current thread, wherein in the history prediction table corresponding to the branch history with the longest history length, the jump direction of the saturation counter is used as the predicted jump direction, the labels in each history prediction table are different from the labels to be compared, and/or when the thread labels are different from the thread numbers, the jump direction predicted by the basic predictor is used as the predicted jump direction.
- 2. The method according to claim 1, wherein the method further comprises: Receiving an indication signal, wherein the indication signal comprises a shared signal or an unshared signal; The sharing signal is used for indicating different threads to run the same program and the branch predictor shares data of each thread among the threads; The unshared signals are used to instruct different threads to run the same program and the branch predictor independently stores data for each thread.
- 3. The method according to claim 1 or 2, wherein the generating a history prediction table corresponding to the branch history of each history length according to the program counter and the branch history of each history length specifically includes: Calculating indexes of a history prediction table corresponding to the branch histories of the history lengths and labels to be compared according to the program counter and the branch histories of the history lengths; and obtaining the prediction items in the history prediction table corresponding to the branch histories of the history lengths according to the indexes of the history prediction tables corresponding to the branch histories of the history lengths.
- 4. A method according to claim 3, wherein the calculating the index of the history prediction table and the label to be compared corresponding to the branch history of each history length according to the program counter and the branch history of each history length specifically comprises: Calculating indexes of a history prediction table corresponding to the branch histories of the history lengths according to the program counter and the branch histories of the history lengths by adopting a first hash algorithm; and calculating the label to be compared of the history prediction table corresponding to the branch histories of the histories according to the program counter and the branch histories of the histories by adopting a second hash algorithm.
- 5. The method according to claim 1 or 2, characterized in that the method further comprises: And comparing the actual jump result of the current thread with the predicted jump direction, and if the actual jump result is inconsistent with the predicted jump direction, updating a history prediction table in the branch predictor according to the actual jump result.
- 6. The method according to claim 1 or 2, wherein the obtaining the program counter of the current thread and the branch histories of a plurality of history lengths, in particular comprises: Selecting a program counter and a branch history of a current thread from program counters and branch histories of a plurality of threads according to the thread number of the current thread; and acquiring a plurality of branch histories with history lengths from the branch histories of the current thread.
- 7. A branch predictor comprising a base counter, a plurality of tag branch predictors, and a selector; the basic counter is used for predicting the jump direction according to the program counter of the current thread; Each marking branch predictor is used for comparing whether the labels in each history prediction table are the same as the labels to be compared when different threads run the same program and the branch predictors share the data of each thread among the threads, outputting the comparison result of each history prediction table, and comparing whether the labels in each history prediction table are the same as the labels to be compared and the thread numbers of the threads are the same as the thread labels of the current threads when different threads run the same program and the branch predictors independently store the data of each thread, and outputting the comparison result of each history prediction table; The selector is used for receiving the prediction result sent by the basic counter and the comparison result output by each marking branch predictor, when the comparison result comprises a history prediction table with the same label as the to-be-compared label, a history prediction table corresponding to the branch history with the longest history length is selected, the jump direction of the saturation counter is used as a prediction jump direction, when the label in each history prediction table is different from the to-be-compared label, the jump direction predicted by the basic predictor is used as a prediction jump direction, when the comparison result comprises a history prediction table with the same label as the to-be-compared label and the same thread label and thread number, a history prediction table corresponding to the branch history with the longest history length is selected, the jump direction of the saturation counter is used as a prediction jump direction, and the comparison result comprises a label in each history prediction table and the to-be-compared label, and/or when the thread label and the thread number are different, the jump direction predicted by the basic predictor is used as the prediction jump direction.
- 8. The predictor of claim 7, further comprising a sharing degree counter; The sharing degree counter is used for sending indication signals to each marked branch predictor, wherein the indication signals comprise sharing signals or non-sharing signals; The sharing signal is used for indicating different threads to run the same program and the branch predictor shares data of each thread among the threads; The unshared signals are used to instruct different threads to run the same program and the branch predictor independently stores data for each thread.
- 9. A branch predictor comprising a processor, and a memory communicatively coupled to the processor; The memory stores computer-executable instructions; The processor executes computer-executable instructions stored in the memory to implement the prediction method of any one of claims 1 to 6.
- 10. A simultaneous multithreaded processor comprising the branch predictor of claim 7 or 8 or the branch predictor of claim 9.
Description
Prediction method, branch predictor and processor Technical Field The present application relates to the field of processors, and in particular, to a prediction method, a branch predictor, and a processor. Background Branch prediction is based on statistical analysis of historical data by analyzing the historical execution of branch instructions in a program to predict the outcome of execution of a branch. With branch prediction techniques, a processor is able to predict a Program Counter (PC) of a subsequent instruction before the branch instruction actually executes, thereby fetching and executing instructions after the branch instruction in advance. Branch instructions generally include conditional jump instructions, which are instructions whose jump addresses are known but which require a determination of whether to actually jump based on the execution result, and indirect jump instructions, which are instructions that inevitably jump but require a retrieval of the jump address based on the execution result. Thus, a processor employing branch prediction techniques may need to use a branch predictor to guess whether a conditional branch instruction will jump in the future or the jump address of an indirect jump instruction in the future during the prediction phase. If the branch predictor predicts incorrectly, the problem of improving the instruction fetching efficiency of the processor cannot be solved. Disclosure of Invention The application provides a prediction method, a branch predictor and a processor, which reduce prediction error rate. In a first aspect, the present application provides a method of prediction for a branch predictor, the method comprising: acquiring a program counter of a current thread and a plurality of branch histories with history lengths, and generating a history prediction table corresponding to the branch history with each history length according to the program counter and the branch histories with each history length, wherein each history prediction table comprises a prediction item and a label to be compared, and the prediction item comprises a saturation counter, a label and a thread label; When different threads run the same program and the branch predictor shares the data of each thread among the threads, comparing whether the label in each history prediction table is the same as the label to be compared, and when the label in each history prediction table is different from the label to be compared, the jump direction of the saturation counter in the history prediction table corresponding to the branch history with the longest history length in the history prediction table with the label identical to the label to be compared is used as the predicted jump direction, and the jump direction predicted by the basic predictor is used as the predicted jump direction; When different threads run the same program and the branch predictors independently store the data of each thread, comparing whether the labels in each history prediction table are the same as the labels to be compared and whether the thread labels are the same as the thread numbers of the current thread, wherein in the history prediction table, the labels are the same as the labels to be compared and the thread labels are the same as the thread numbers of the current thread, the jump direction of the saturation counter is used as the predicted jump direction, and/or when the labels in each history prediction table are different from the labels to be compared, the jump direction predicted by the basic predictor is used as the predicted jump direction. Optionally, the method further comprises: Receiving an indication signal, wherein the indication signal comprises a shared signal or an unshared signal; The sharing signal is used for indicating different threads to run the same program and the branch predictor shares data of each thread among the threads; The unshared signals are used to instruct different threads to run the same program and the branch predictor independently stores data for each thread. Optionally, the generating a history prediction table of each history length according to the program counter and the branch history of each history length specifically includes: Calculating indexes of a history prediction table corresponding to the branch histories of the history lengths and labels to be compared according to the program counter and the branch histories of the history lengths; and obtaining the prediction items in the history prediction table corresponding to the branch histories of the history lengths according to the indexes of the history prediction tables corresponding to the branch histories of the history lengths. Optionally, the calculating, according to the program counter and the branch histories of the history lengths, the index of the history prediction table and the label to be compared corresponding to the branch histories of the history lengths specifically includes: Calculating ind