Method and apparatus for determining branch history for branch prediction

Update the global branch history through the bitwise XOR function and variable shift logic of branch signatures, solving the problems of loss of training information of branch predictors and difficulty in distinguishing patterns in the prior art, and improving the flexibility and accuracy of branch prediction.

CN109643236BActive Publication Date: 2024-11-29ADVANCED MICRO DEVICES INC
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN201680088627.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2016-09-09
Publication Date
2024-11-29
Estimated Expiration
2036-09-09

AI Technical Summary

Technical Problem

Existing branch predictors lose previous branch predictor training when discovering new branches, and it is difficult to distinguish the adoption/unadoption patterns of different code locations, resulting in inflexible branch history updates.

Method used

Using branch signature bitwise XOR (XOR) function and variable shift logic, update the global branch history, update the current global branch history when the branch is adopted through shift and XOR operations, avoid losing previous information, and not using it. Stay unchanged.

Benefits of technology

Branch history tracking for longer sequences at different code locations is implemented, avoiding information loss in traditional methods and improving the accuracy and flexibility of branch prediction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN109643236B_ABST
    Figure CN109643236B_ABST
Patent Text Reader

Abstract

A method and processing device are disclosed that involve determining a global branch history for branch prediction. The method includes: shifting a first bit of a branch signature into a current global branch history; and performing a bitwise exclusive OR (XOR) function on a second bit of the branch signature and the shifted bits of the current global branch history. In this way, the current global branch history is updated. The processing device implements the method using the following items: shift logic, which is configured to store bits representing the current global branch history and shift the bits; a register, which is configured to store the current global branch history; a decision circuit, which is configured to determine whether a branch is taken; and an XOR gate.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0001] In computer architecture, a branch predictor is a digital circuit that attempts to guess which way a branch, such as an if-then-else construct in a program or code, will go before it is known for sure. A branch predictor implements a method of branch prediction. Branch prediction improves the flow of the instruction pipeline and plays a role in achieving efficient performance in many microprocessor architectures.

[0002] Branch prediction is based on branch history, that is, a record of how often a given branch is taken and not taken. In a global branch history, the branch history for multiple branches is stored in a set of bits.

[0003] FIG. 2 illustrates a conventional type of processing apparatus and method for updating a global branch history. The circuit determines whether a branch has been found (step 225). When a branch has not been found, the current global history remains unchanged (step 220). When a branch is found, the current global branch history is shifted one position (step 215; shown as a left shift) and the oldest history bit (bit 3) is discarded. The rightmost bit in the current global branch history is replaced by a bit indicating whether the branch is taken (step 230), for example, 0 is not taken and 1 is taken. In this way, the current global branch history is updated. The current branch history is used in a branch predictor to predict whether a branch will be taken in the future. BRIEF DESCRIPTION OF THE DRAWINGS

[0004] A more detailed understanding may be obtained from the following description given by way of example in conjunction with the accompanying drawings, in which:

[0005] Figure 1 is a block diagram of an example apparatus in which one or more disclosed aspects may be implemented;

[0006] FIG2 illustrates a processing device configured to update a global branch history;

[0007] Figure 3 Another processing device configured to update a global branch history is shown;

[0008] Figure 4 Another processing device configured to update a global branch history is shown;

[0009] Figure 5 A method for determining and updating a global branch history is shown; and

[0010] Figure 6 Another method for determining and updating the global branch history is shown. DETAILED DESCRIPTION

[0011] Compared to conventional global branch history methods and apparatus such as previously described, the disclosed methods and apparatus improve timing and avoid losing previous branch predictor training when new branches are discovered. The disclosed methods and apparatus also provide the benefit of being able to distinguish the same taken / not taken (T / NT) pattern at different code locations. If the executed computer code contains discovered NT branches, the disclosed methods and apparatus are able to track longer sequences than conventional global history update methods and apparatus.

[0012] The method includes: shifting a first bit of a branch signature into a current global branch history; and performing a bitwise exclusive OR (XOR) function on a second bit of the branch signature and the shifted bits of the current global branch history. The second bit is different from the first bit. The branch signature includes bits that identify a particular branch whose branch history is updated. The shifting includes discarding one or more of the oldest bits in the current global branch history. The shifting and the performing of the bitwise XOR function are performed when a branch identified by the branch signature is taken. The current global branch history is not changed when a branch identified by the branch signature is not taken.

[0013] In an implementation, the method further includes: shifting one or more newest bits in the current global branch history by a first number of positions; shifting one or more oldest bits in the current global branch history by a second number of positions, the second number of positions being different from the first number of positions; and performing a bitwise XOR function between the bits shifted by the second number of positions and the newer bits in the current global branch history. These portions of the method are performed when a branch identified by the branch signature is taken, and the current global branch history is not changed when a branch identified by the branch signature is not taken. For example, the second number of positions is less than the first number of positions (e.g., the first number of positions is three and the second number of positions is one).

[0014] In an implementation, the method is performed such that the updated current global branch history is included in the first stage of a two-stage adaptive predictor.

[0015] In an implementation, a processing device configured to determine and update a global branch history for branch prediction includes: shift logic configured to shift bits representing a current global branch history; a register configured to store the current global branch history; a decision circuit configured to determine whether a branch is taken; and a first plurality of exclusive OR (XOR) gates.

[0016] In an implementation, the determination and update of the global branch history includes: the shift logic shifts the bits representing the current global branch history and stores one or more of the shifted bits in the register; the register receives and stores the first bit of the branch signature; the first plurality of XOR gates performs a bit-by-bit XOR function on the second bit of the branch signature and the shifted bits of the current global branch history; and the result of the bit-by-bit XOR function is stored in the register.

[0017] In an implementation, the processing device is configured to determine and update a global branch history when the decision circuit determines that the branch identified by the branch signature has been taken. In an implementation, the processing device is configured to not change the current global branch history when the decision circuit determines that the branch identified by the branch signature has not been taken.

[0018] In an implementation, the processing device is also configured to perform compression of branch history information and branch signature information. In this implementation, the processing device is configured to shift one or more of the newest bits in the current global branch history by a first number of positions, and shift one or more of the oldest bits in the current global branch history by a second number of positions, the second number of positions being different from the first number of positions. The processing device also includes a second plurality of XOR gates, the second plurality of XOR gates being configured to perform a bitwise XOR function between the bits shifted by the second number of positions and the newer bits in the current global branch history. This implementation of the processing device is also configured to perform compression of branch history information and branch signature information when the decision circuit determines that the branch identified by the branch signature has been taken. The processing device does not change the current global branch history when the decision circuit determines that the branch identified by the branch signature has not been taken.

[0019] In a particular implementation of the processing device configured to perform compression, the second number of positions may be less than the first number of positions. The first number of positions may be three and the second number of positions may be one. Another particular implementation may include multiple levels of compression. As an example, newer bits in the current global branch history may be shifted three positions, older bits two positions, and even older bits one position. For efficient compression, the amount of shifting tends to decrease as the history age of the bits increases.

[0020] The processing apparatus comprises a two-stage adaptive predictor device configured to receive an updated current global branch history in a first stage.

[0021] Figure 11 is a block diagram of an example device 100 for implementing one or more disclosed embodiments. Examples of device 100 include a computer, a gaming device, a handheld device, a set-top box, a television, a mobile phone, or a tablet computer. Device 100 includes a processor 102, a memory 104, a storage device 106, one or more input devices 108, and one or more output devices 110. Optionally, device 100 includes an input driver 112 and an output driver 114. It should be understood that device 100 may include Figure 1 Additional components not shown.

[0022] The processor 102 includes a central processing unit (CPU), a graphics processing unit (GPU), a CPU and a GPU on the same die, or one or more processor cores, where each processor core can be a CPU or a GPU. The memory 104 is located on the same die as the processor 102, or the memory 104 is located separately from the processor 102. The memory 104 includes volatile or non-volatile memory, such as random access memory (RAM), dynamic RAM, or cache.

[0023] Storage device 106 includes fixed or removable storage devices, such as hard disk drives, solid-state drives, optical disks, or flash drives. Input device 108 includes a keyboard, a key, a touch screen, a touch pad, a detector, a microphone, an accelerometer, a gyroscope, a biometric scanner, or a network connection (e.g., a wireless LAN card for transmitting and / or receiving wireless IEEE 802 signals). Output device 110 includes a display, a speaker, a printer, a tactile feedback device, one or more lights, an antenna, or a network connection (e.g., a wireless LAN card for transmitting and / or receiving wireless IEEE 802 signals).

[0024] The input driver 112 communicates with the processor 102 and the input device 108, and permits the processor 102 to receive input from the input device 108. The output driver 114 communicates with the processor 102 and the output device 110, and permits the processor 102 to send output to the output device 110. It should be noted that the input driver 112 and the output driver 114 are optional components, and if the input driver 112 and the output driver 114 are not present, the device 100 will operate in the same manner.

[0025] Figure 3 An example implementation of an electronic processing device 300 configured to determine and update a global branch history for branch prediction is shown. Characteristics of the electronic processing device 300, such as the exact number of bits, should not be considered limiting.

[0026] The current global branch history is stored as a bit sequence in register 310. Figure 3, the current global branch history is shown as having eight bits, but this number should not be viewed as limiting. When a branch is found, a determination is made by decision circuit 325 as to whether the branch has been taken. If the branch has not been taken, the current global history 320 is not changed and is re-stored in register 310. If the branch has been taken, the current global branch history is updated, as in the following examples, which should not be viewed as limiting.

[0027] The update begins with shift logic 315 shifting the bits representing the current global branch history and storing the shifted bits in register 310. Figure 3 As shown, for example, bits 0 through 5 are shifted left by two positions. In this process, the older bits 6 and 7 of this branch history are discarded. One or more of the shifted bits (such as, bits 2 through 5) are stored directly in register 310. Register 310 receives and stores the first bits S[1] and S[0] of a branch signature, which identifies the particular branch whose branch history is updated. As a non-limiting example, a branch signature can be as simple as the least significant bits of a linear address, or it can be as complex as (first linear address portion) XOR (second linear address portion) XOR (bits indicating branch type) XOR (bits indicating other attributes of the branch). If, for example, a 4-bit branch signature is desired, the 12 least significant bits of the linear address (LINAD) can be XORed with the four bits indicating the branch type, as follows:

[0028] LINAD[11:8]XOR

[0029] LINAD[7:4]XOR

[0030] LINAD[3:0]XOR

[0031] Type[3:0].

[0032] The updating of the current global branch history continues with a plurality of XOR gates 330 performing a bitwise XOR function on the second bits of the branch signature (such as S[3] and S[2]) and the shifted bits of the current global branch history (such as bits 0 and 1). The bits resulting from such execution of the bitwise XOR function are stored in register 310, thereby updating the current global branch history stored in register 310.

[0033] The global branch history stored in register 310 is transmitted to branch predictor 335, which is an electronic circuit that uses the current branch history to predict the likelihood that a branch will be taken. In an implementation, branch predictor 335 is a two-stage adaptive predictor device that is configured to receive an updated current global branch history in its first stage. Alternative implementations may include other types of branch predictors.

[0034] Figure 4 An alternative example implementation of an electronic processing device 400 configured to determine and update a global branch history for branch prediction is shown. Characteristics of the electronic processing device 400, such as the exact number of bits, should not be considered limiting. Figure 4 The implementation method includes compressing the branch history information and branch signature information through variable shift and additional XOR function.

[0035] Similar to Figure 3 In the example of , the current global branch history is stored as a bit sequence in register 410. Figure 4 , the current global branch history is shown as having 19 bits, but this number should not be considered limiting.

[0036] When a branch is found, a determination is made as to whether the branch has been taken by decision circuit 425. If the branch has not been taken, the current global history 420 is not changed and is restored in register 410. If the branch has been taken, the current global branch history is updated, as in the following example, which should not be considered limiting.

[0037] exist Figure 4 In the implementation shown, the update begins with shift logic 415 shifting the bits representing the current global branch history and storing the shifted bits in register 410. Figure 3 In contrast, however, one or more of the newest bits of the current global branch history are shifted a first number of positions, and one or more of the oldest bits are shifted a second number of positions, the first number of positions being unequal to the second number of positions. Specifically, the second number of positions is less than the first number of positions. Figure 4 As shown, bits 0 to 7 are shifted left by three positions, while bits 10 to 16 are shifted left by one position. One or more of the shifted bits are stored directly into register 410. Figure 4 In the example of , these bits are 3 to 7, 15, 16, and 17. In this process, the oldest bit 18 of this branch history is discarded.

[0038] Similar to Figure 3 , register 410 receives and stores the first bits S[2], S[1], and S[0] of the branch signature. Similar to Figure 3 , the update of the current global branch history continues to the first plurality of XOR gates 430 at the second bit of the branch signature (at Figure 4 In the example of , S[5], S[4], and S[3]) and the shifted bits of the current global branch history (in Figure 4In the example of , a bitwise XOR function is performed on bits 0, 1, and 2. The bits resulting from such a bitwise XOR function are stored in register 410 as part of the updated current branch history.

[0039] and Figure 3 In contrast, Figure 4 The device uses a second plurality of XOR gates 433 to perform compression. The XOR gates 433 are configured to perform a bitwise XOR function between the current global branch history bits shifted by a second number of positions and the newer bits of the current global branch history. The bits resulting from such a bitwise XOR function are stored in register 410 to complete the update of the current global branch history. Figure 4 In the specific example of , the following XOR functions are performed: 10XOR 5, 11XOR 6, 12XOR 7, 13XOR 8, and 14XOR 9.

[0040] In an implementation, the global branch history stored in register 410 is transmitted to branch predictor 435, which uses the current global branch history to predict the likelihood that a branch will be taken. In an implementation, branch predictor 435 is a two-stage adaptive predictor device that is configured to receive an updated current global branch history in its first stage. Alternative implementations may include other types of branch predictors.

[0041] Figure 5 A method 500 of determining a global branch history for branch prediction is shown. The exact order of the steps shown need not be construed as limiting. During execution of the code, a branch is encountered (step 510). A determination is made whether this branch is taken (step 515). When the branch is not taken, the current global branch history is not changed (step 520), and the method returns to wait for the next encountered branch (step 510).

[0042] When the branch is taken, the current global branch history is updated. The update begins by shifting the first bit of the branch signature into the current global branch history (step 525). The shifting includes discarding one or more of the oldest bits in the current global branch history. A bitwise XOR function is performed on the second bit of the branch signature and the shifted bits of the current global branch history (step 530). The current global branch history is now updated and stored in a register, as described above. The method returns to waiting for the next encountered branch (step 510).

[0043] Figure 6 Another implementation 600 of a method for determining global branch history for branch prediction is shown. The exact order of the steps shown is not necessarily to be construed as limiting. Figure 5 In addition to the methods shown, Figure 6 The implementation shown also includes compression of branch history information and branch signature information by variable shift and additional XOR function. Figure 5 In , a branch is encountered (step 610) and a determination is made whether this branch has been taken (step 615). If the branch is not taken, then as in Figure 5 In step 610, the current global branch history is not changed (step 620), and the method returns to wait for the next branch to be encountered (step 610).

[0044] When the branch is taken, one or more of the most recent bits in the current global branch history are shifted a first number of positions (step 625). The first bit of the branch signature is shifted into the current global branch history (step 627). A unique XOR function is performed on the second bit of the branch signature and the bits of the current global branch history shifted the first number of positions (step 630).

[0045] One or more of the oldest bits in the current global branch history are shifted a second number of positions, the second number of positions being different from the first number of positions (step 635). In a particular implementation, the second number of positions is less than the first number of positions. As an example, the first number of positions is three and the second number of positions is one. As a result of the two shifts, one or more of the oldest bits in the current global branch history are discarded.

[0046] A bitwise XOR function is performed between the bits of the current global branch history shifted the second number of positions and the newer bits in the current global branch history (step 640). One or more of the shifted bits of the current global branch history become bits of the updated branch history without further processing.

[0047] The current global branch history is now updated. In an implementation, the updated global branch history is stored in a register, as described above. The method returns to wait for the next encountered branch (step 610).

[0048] It should be understood that many variations are possible based on the disclosure herein. Although features and elements are described above in particular combinations, each feature or element may be used alone without the other features and elements or in various combinations with or without the other features and elements.

[0049] The provided methods are implemented in a general purpose computer, processor, or processor core. Suitable processors include, for example, a general purpose processor, a special purpose processor, a conventional processor, a digital signal processor (DSP), a plurality of microprocessors, one or more microprocessors associated with a DSP core, a controller, a microcontroller, an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) circuit, any other type of integrated circuit (IC), and / or a state machine. Such processors can be manufactured by configuring a manufacturing process using the result of processing hardware description language (HDL) instructions and other intermediate data including a netlist (such instructions can be stored on a computer readable medium). The result of such processing can be a mask piece that is subsequently used in a semiconductor manufacturing process to manufacture a processor that implements aspects of the embodiment.

[0050] The methods or processes provided herein are implemented in a computer program, software or firmware incorporated in a non-transitory computer-readable storage medium so as to be executed by a general-purpose computer or processor. Examples of non-transitory computer-readable storage media include read-only memory (ROM), random access memory (RAM), registers, cache memory, semiconductor memory devices, magnetic media such as internal hard disks and removable disks, magneto-optical media, and optical media such as CD-ROMs and digital versatile disks (DVDs).

Claims

1. A method for determining a global branch history for branch prediction, the method include: Shifting a first bit of a branch signature into a lowest bit of a register storing a current global branch history, wherein the first bit of the branch signature shifted into the current global branch history is not modified by the current global branch history; performing a bitwise XOR function between the second bit of the branch signature and the shifted bits of the current global branch history to generate a third bit for storage in the register storing the current global branch history, thereby updating the current global branch history, wherein the second bit is different from and of higher order than the first bit, and wherein the third bit is stored in a bit position of the register that is of higher order than the lowest order bit of the register into which the unmodified first bit of the branch signature is shifted; performing a bitwise exclusive-OR function on different bit combinations of the current global branch history to obtain a fourth bit, and storing the fourth bit at a higher-order bit position of the register than the bit position in which the third bit is stored, wherein the different bit combinations on which the exclusive-OR function is performed include a first set of bits of the current global branch history and a second set of higher-order bits of the current global branch history; and storing bits of the current global branch history that are higher than the lowest bit order of the current global branch history in the global branch history register at positions that are higher than the third bit order for storage in the global branch history register and lower than the fourth bit order for storage in the global branch history register, the bits of the current global branch history that are higher than the lowest bit order of the global branch history and lower than each bit order of the different bit combinations from which the fourth bit is obtained.

2. The method of claim 1, wherein the branch signature includes bits identifying a specific branch whose branch history is updated. 3 . The method of claim 1 , further comprising discarding one or more oldest bits in the current global branch history.

4. The method of claim 1, wherein said shifting and said executing of said bitwise XOR function are performed when a branch identified by said branch signature is taken.

5. The method of claim 1, wherein the current global branch history is not changed when the branch identified by the branch signature is not taken.

6. The method of claim 1 further comprises compressing the branch history information and the branch signature information, wherein the compression include: shifting one or more most recent bits in the current global branch history by a first number of positions; shifting one or more oldest bits in the current global branch history by a second number of positions, the second number of positions being different from the first number of positions; and A bitwise XOR function is performed between the bits shifted the second number of positions and the newer bits in the current global branch history.

7. The method of claim 6, performed when a branch identified by the branch signature is taken.

8. The method of claim 6, wherein the current global branch history is not changed when the branch identified by the branch signature is not taken.

9. The method of claim 6, wherein the second number of positions is less than the first number of positions.

10. The method of claim 1, wherein the updated current global branch history is included in a first stage of a two-stage adaptive predictor.

11. A processing device configured to determine and update a global branch history for branch prediction, the processing device include: shift logic configured to shift bits representing a current global branch history; a register configured to store the current global branch history; a decision circuit configured to determine whether a branch is taken; as well as a first plurality of XOR gates and a second plurality of XOR gates; Determining and updating the global branch history includes: the shift logic shifting bits representing a current global branch history and storing one or more of the shifted bits in the register; the register receiving and storing a first bit of a branch signature into a least significant bit of the register, the branch signature comprising a bit identifying a particular branch whose branch history is updated, the first bit of the branch signature being unmodified by the current global branch history; the first plurality of XOR gates performing a bitwise XOR function between a second bit of the branch signature and a bit of the current global branch history to generate a third bit to be stored in the register storing the current global branch history, thereby updating the current global branch history, wherein the second bit is different from the first bit and has a higher order than the first bit; storing the third bit generated by the first plurality of XOR gates in the register to update the current global branch history, wherein the third bit is stored at a bit position in the register that is higher in order than the least significant bit of the register into which the unmodified first bit of the branch signature is shifted; the second plurality of XOR gates performing a bitwise XOR function on different bit combinations of the current global branch history to obtain a fourth bit for storage in the register, wherein the different bit combinations on which the XOR function is performed include a first set of bits of the current global branch history and a second set of higher order bits of the current global branch history; storing the fourth bit at a higher-order bit position of the register than the bit position in which the third bit is stored; and storing bits of the current global branch history that are higher than the lowest bit order of the current global branch history in the global branch history register at positions that are higher than the third bit order for storage in the global branch history register and lower than the fourth bit order for storage in the global branch history register, the bits of the current global branch history that are higher than the lowest bit order of the global branch history and lower than each bit order of the different bit combinations from which the fourth bit is obtained.

12. The processing device of claim 11, further configured to determine and update a global branch history for branch prediction when the decision circuit determines that the branch identified by the branch signature has been taken.

13. The processing device of claim 11, further configured to not change the current global branch history when the decision circuit determines that the branch identified by the branch signature is not taken.

14. The processing device of claim 11, further configured to perform compression of branch history information and branch signature information, in: The shift logic is configured to shift one or more most recent bits in the current global branch history by a first number of positions; the shift logic being configured to shift one or more oldest bits in the current global branch history a second number of positions, the second number of positions being different than the first number of positions; and The processing device also includes a second plurality of XOR gates configured to perform a bitwise XOR function between bits shifted the second number of positions and newer bits in the current global branch history.

15. The processing device of claim 14, further configured to perform compression of branch history information and branch signature information when the decision circuit determines that the branch identified by the branch signature has been taken.

16. The processing device of claim 14, further configured to not change the current global branch history when the decision circuit determines that the branch identified by the branch signature is not taken.

17. The processing device of claim 14, wherein the second number of positions is less than the first number of positions.

18. The processing apparatus of claim 14, further comprising a two-stage adaptive predictor device configured to receive an updated current global branch history in a first stage.

Citation Information

Patent Citations

  • Method, system, and computer program product for path-correlated indirect address predictions

    US20080256347A1

  • Global History Branch Prediction Updating Responsive to Taken Branches

    US20090198984A1

  • Branch prediction using multiple versions of history data

    US20150331691A1