# US 2021/0004234 A1 · Branch prediction circuit and control method therefor

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2021/0004234 A1
- Document ID: US20210004234A1
- Status: Published application
- Kind: A1
- Application number: 16/969,537
- Filed: 2019-02-03
- Published: 2021-01-07
- Earliest claimed: 2018-02-13
- Assignees: Loongson Technology Corporation Limited
- Applicants: Loongson Technology Corporation Limited
- Inventors: WEIWU HU; WENXIANG WANG; RUIYANG WU
- Web page: https://patentgrep.com/patent/US20210004234A1

## CPC

- G06F 9/3806: {using address prediction, e.g. return stack, branch history buffer}
- G06F 9/3844: {using dynamic branch prediction, e.g. using branch history tables}
- G06F 21/52: during program execution, e.g. stack integrity {; Preventing unwanted data erasure; Buffer overflow}
- G06F 21/71: to assure secure computing or processing of information
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A branch prediction circuit and a control method therefor relate to the field of computer technologies. The branch prediction circuit includes at least one branch predictor 110, where the branch predictor 110 includes a prediction information determining module 120, a readout circuit 130 and a branch prediction table 140. The prediction information determining module 120 determines target prediction information corresponding to a to-be-predicted branch instruction according to program identification information 150 corresponding to the to-be-predicted branch instruction and a branch prediction table 140; and the readout circuit 130 sends the target prediction information to a branch instruction execution and control unit 200, so that the branch instruction execution and control unit 200 performs prediction processing according to the target prediction information, and generates a prediction result corresponding to the to-be-predicted branch instruction.

## Claims

### Claim 1

A branch prediction circuit, applied to a processor having an ability to execute a branch instruction, wherein the branch prediction circuit comprises at least one branch predictor, and the branch predictor comprises a prediction information determining module, a readout circuit and a branch prediction table; wherein,
the prediction information determining module determines target prediction information corresponding to a to-be-predicted branch instruction according to program identification information corresponding to the to-be-predicted branch instruction and the branch prediction table;
the readout circuit sends the target prediction information to a branch instruction execution and control unit, so that the branch instruction execution and control unit performs prediction processing according to the target prediction information and generates a prediction result corresponding to the to-be-predicted branch instruction.

### Claim 2 (depends on 1)

The branch prediction circuit according to claim 1, wherein the branch predictor further comprises an update circuit; the update circuit updates record information in the branch prediction table according to a branch instruction being executed by the processor and program identification information corresponding to the branch instruction being executed, wherein the record information comprises branch prediction information corresponding to the branch instruction being executed, and the branch prediction information comprises at least one of the following: jump target information and jump direction information.

### Claim 3 (depends on 1)

The branch prediction circuit according to claim 1, wherein the prediction information determining module comprises a first search circuit and a second search circuit;
the first search circuit searches, in the branch prediction table, for preset branch prediction information corresponding to the to-be-predicted branch instruction;
the second search circuit searches, in the branch prediction table, for program identification information corresponding to the branch prediction information which is found by the first search circuit; extracts the target prediction information from the branch prediction information when the found program identification information is the same as current program identification information corresponding to the to-be-predicted branch instruction; and generates random prediction information for the to-be-predicted branch instruction when the found program identification information is different from the current program identification information, and determines the random prediction information as the target prediction information.

### Claim 4 (depends on 1)

The branch prediction circuit according to claim 1, wherein the prediction information determining module comprises a third search circuit;
the third search circuit searches for program identification information corresponding to branch prediction information in the branch prediction table according to current program identification information corresponding to the to-be-predicted branch instruction; extracts the target prediction information from the branch prediction information when the found program identification information is the same as the current program identification information corresponding to the to-be-predicted branch instruction; and generates random prediction information for the to-be-predicted branch instruction when the found program identification information is different from the current program identification information, and determines the random prediction information as the target prediction information.

### Claim 5 (depends on 1)

The branch prediction circuit according to claim 1, wherein the prediction information determining module comprises an arithmetic circuit and a fourth search circuit;
the arithmetic circuit determines index address information according to instruction address information of the to-be-predicted branch instruction; and
performs hash processing according to the program identification information and the index address information to obtain target index address information;
the fourth search circuit searches, in the branch prediction table, for the target prediction information corresponding to the to-be-predicted branch instruction according to the target index address information.

### Claim 6 (depends on 5)

The branch prediction circuit according to claim 5, wherein the fourth search circuit comprises: a comparison sub-circuit and an adaptation sub-circuit;
the comparison sub-circuit searches, in the branch prediction table, for branch prediction information corresponding to the target index address information, and compares preset program identification information corresponding to the branch prediction information with the program identification information corresponding to the to-be-predicted branch instruction;
the adaptation sub-circuit extracts the target prediction information from the branch prediction information when the preset program identification information is the same as the program identification information corresponding to the to-be-predicted branch instruction; and generates random prediction information for the to-be-predicted branch instruction when the preset program identification information is different from the program identification information corresponding to the to-be-predicted branch instruction, and determines the random prediction information as the target prediction information.

### Claim 7

(canceled)

### Claim 8

A control method for a branch prediction circuit, comprising:
determining target prediction information corresponding to a to-be-predicted branch instruction according to program identification information corresponding to the to-be-predicted branch instruction and a branch prediction table of the branch prediction circuit;
sending the target prediction information to a branch instruction execution and control unit, so that the branch instruction execution and control unit performs prediction processing according to the target prediction information and generates a prediction result corresponding to the to-be-predicted branch instruction.

### Claim 9 (depends on 8)

The method according to claim 8, further comprising:
updating record information in the branch prediction table according to a branch instruction being currently executed and program identification information corresponding thereto, wherein the record information comprises branch prediction information corresponding to the branch instruction being executed, and the branch prediction information comprises at least one of the following: jump target information and jump direction information.

### Claim 10 (depends on 8)

The method according to claim 8, wherein the determining the target prediction information corresponding to the to-be-predicted branch instruction according to the program identification information corresponding to the to-be-predicted branch instruction and the branch prediction table of the branch prediction circuit comprises:
searching, in the branch prediction table, for preset branch prediction information corresponding to the to-be-predicted branch instruction;
searching, in the branch prediction table, for program identification information corresponding to the branch prediction information; extracting the target prediction information from the branch prediction information when the found program identification information is the same as current program identification information corresponding to the to-be-predicted branch instruction; and generating random prediction information for the to-be-predicted branch instruction when the found program identification information is different from the current program identification information, and determining the random prediction information as the target prediction information.

### Claim 11 (depends on 8)

The method according to claim 8, wherein the determining the target prediction information corresponding to the to-be-predicted branch instruction according to the program identification information corresponding to the to-be-predicted branch instruction and the branch prediction table of the branch prediction circuit comprises:
searching for program identification information corresponding to branch prediction information in the branch prediction table according to current program identification information corresponding to the to-be-predicted branch instruction;
extracting the target prediction information from the branch prediction information when the found program identification information is the same as the current program identification information corresponding to the to-be-predicted branch instruction;
generating random prediction information for the to-be-predicted branch instruction when the found program identification information is different from the current program identification information, and determining the random prediction information as the target prediction information.

### Claim 12 (depends on 8)

The method according to claim 8, wherein the determining the target prediction information corresponding to the to-be-predicted branch instruction according to the program identification information corresponding to the to-be-predicted branch instruction and the branch prediction table of the branch prediction circuit comprises:
determining index address information according to instruction address information of the to-be-predicted branch instruction;
preforming hash processing according to the program identification information and the index address information to obtain target index address information;
searching, in the branch prediction table, for the target prediction information corresponding to the to-be-predicted branch instruction according to the target index address information.

### Claim 13 (depends on 12)

The method according to claim 12, wherein the searching, in the branch prediction table, for the target prediction information corresponding to the to-be-predicted branch instruction according to the target index address information comprises:
searching, in the branch prediction table, for branch prediction information corresponding to the target index address information, and comparing preset program identification information corresponding to the branch prediction information with the program identification information corresponding to the to-be-predicted branch instruction;
extracting the target prediction information from the branch prediction information when the preset program identification information is the same as the program identification information corresponding to the to-be-predicted branch instruction;
generating random prediction information for the to-be-predicted branch instruction when the preset program identification information is different from the program identification information corresponding to the to-be-predicted branch instruction, and determining the random prediction information as the target prediction information.

### Claim 14

A processor, comprising a branch prediction circuit, wherein,
the branch prediction circuit comprises at least one branch predictor, and the branch predictor comprises a prediction information determining module, a readout circuit and a branch prediction table; wherein,
the prediction information determining module determines target prediction information corresponding to a to-be-predicted branch instruction according to program identification information corresponding to the to-be-predicted branch instruction and the branch prediction table;
the readout circuit sends the target prediction information to a branch instruction execution and control unit, so that the branch instruction execution and control unit performs prediction processing according to the target prediction information and generates a prediction result corresponding to the to-be-predicted branch instruction.

### Claim 15 (depends on 14)

The processor according to claim 14, wherein the branch predictor further comprises an update circuit; the update circuit updates record information in the branch prediction table according to a branch instruction being executed by the processor and program identification information corresponding to the branch instruction being executed, wherein the record information comprises branch prediction information corresponding to the branch instruction being executed, and the branch prediction information comprises at least one of the following: jump target information and jump direction information.

### Claim 16 (depends on 14)

The processor according to claim 14, wherein the prediction information determining module comprises a first search circuit and a second search circuit;
the first search circuit searches, in the branch prediction table, for preset branch prediction information corresponding to the to-be-predicted branch instruction;
the second search circuit searches, in the branch prediction table, for program identification information corresponding to the branch prediction information which is found by the first search circuit; extracts the target prediction information from the branch prediction information when the found program identification information is the same as the program identification information corresponding to the to-be-predicted branch instruction; and generates random prediction information for the to-be-predicted branch instruction when the found program identification information is different from the program identification information, and determines the random prediction information as the target prediction information.

### Claim 17 (depends on 14)

The processor according to claim 14, wherein the prediction information determining module comprises a third search circuit;
the third search circuit searches for program identification information corresponding to branch prediction information in the branch prediction table according to the program identification information corresponding to the to-be-predicted branch instruction; extracts the target prediction information from the branch prediction information when the found program identification information is the same as the program identification information corresponding to the to-be-predicted branch instruction; and generates random prediction information for the to-be-predicted branch instruction when the found program identification information is different from the program identification information, and determines the random prediction information as the target prediction information.

### Claim 18 (depends on 14)

The processor according to claim 14, wherein the prediction information determining module comprises an arithmetic circuit and a fourth search circuit;
the arithmetic circuit determines index address information according to instruction address information of the to-be-predicted branch instruction; and performs hash processing according to the program identification information and the index address information to obtain target index address information;
the fourth search circuit searches, in the branch prediction table, for the target prediction information corresponding to the to-be-predicted branch instruction according to the target index address information.

### Claim 19 (depends on 18)

The processor according to claim 18, wherein the fourth search circuit comprises: a comparison sub-circuit and an adaptation sub-circuit;
the comparison sub-circuit searches, in the branch prediction table, for branch prediction information corresponding to the target index address information, and compares preset program identification information corresponding to the branch prediction information with the program identification information corresponding to the to-be-predicted branch instruction;
the adaptation sub-circuit extracts the target prediction information from the branch prediction information when the preset program identification information is the same as the program identification information corresponding to the to-be-predicted branch instruction; and generates random prediction information for the to-be-predicted branch instruction when the preset program identification information is different from the program identification information corresponding to the to-be-predicted branch instruction, and determines the random prediction information as the target prediction information.
