# US 12,112,173 B2 · Context-based loop branch prediction

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

- Number: US 12,112,173 B2
- Document ID: US12112173B2
- Status: Granted
- Kind: B2
- Application number: 17/128,816
- Filed: 2020-12-21
- Published: 2022-06-23
- Granted: 2024-10-08
- Earliest claimed: 2020-12-21
- Assignees: Intel Corporation
- Applicants: Intel Corporation
- Inventors: Ke Sun; Rodrigo Branco; Kekai Hu
- Web page: https://patentgrep.com/patent/US12112173B2

## CPC

- G06F 9/3842: {Speculative instruction execution}
- G06F 9/325: {for loops, e.g. loop detection or loop counter}
- 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: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

An embodiment of an integrated circuit may comprise a branch predictor to predict whether a conditional branch is taken for one or more instructions, the branch predictor including circuitry to identify a loop branch instruction in the one or more instructions, and provide a branch prediction for the loop branch instruction based on a context of the loop branch instruction. Other embodiments are disclosed and claimed.

## Claims

### Claim 1

An integrated circuit, comprising:
a branch predictor to predict whether a conditional branch is taken for one or more instructions, the branch predictor including circuitry to:
identify a loop branch instruction in the one or more instructions, wherein an operand of the loop branch instruction comprises a loop-control variable;
speculatively calculate a first value of the loop-control variable for a next iteration of the loop branch instruction, comprising extrapolating the first value based on respective values of the loop-control variable from a current iteration of the loop branch instruction and a previous iteration of the loop branch instruction; and
provide a branch prediction for the loop branch instruction based on a context of the first value.

### Claim 2 (depends on 1)

The integrated circuit of claim 1, wherein the circuitry is to provide the branch prediction based on whether the first value indicates that the loop branch instruction will exit a loop at the next iteration of the loop branch instruction.

### Claim 3 (depends on 1)

The integrated circuit of claim 1, wherein the circuitry is further to:
save the respective value of the loop-control variable from the previous iteration of the loop branch instruction.

### Claim 4 (depends on 3)

The integrated circuit of claim 3, wherein the circuitry is further to:
store an array of entries that each correspond to a respective loop branch instruction.

### Claim 5 (depends on 4)

The integrated circuit of claim 4, wherein an entry of the array includes a tag field calculated by the circuitry to identify loop branches, a field to store a previous value of a first loop-control variable, a prediction field with a predicted branch direction in terms of “taken” or “not taken”, a validity field to indicate a validity of the entry, and a usage field to store a usage information for entry replacement selection.

### Claim 6

A method, comprising:
processing one or more instructions by a branch prediction unit;
identifying a loop branch instruction in the one or more instructions, wherein an operand of the loop branch instruction comprises a loop-control variable;
speculatively calculating a first value of the loop-control variable for a next iteration of the loop branch instruction, comprising extrapolating the first value based on respective values of the loop-control variable from a current iteration of the loop branch instruction and a previous iteration of the loop branch instruction; and
providing a branch prediction for the loop branch instruction based on the first value.

### Claim 7 (depends on 6)

The method of claim 6, further comprising:
providing the branch prediction based on whether the first value indicates that the loop branch instruction will exit a loop at the next iteration of the loop branch instruction.

### Claim 8 (depends on 6)

The method of claim 6, further comprising:
saving the respective value of the loop-control variable from the previous iteration of the loop branch instruction.

### Claim 9 (depends on 8)

The method of claim 8, further comprising:
storing an array of entries that each correspond to a respective loop branch instruction.

### Claim 10 (depends on 9)

The method of claim 9, wherein an entry of the array includes a tag field calculated from a branch instruction pointer to identify loop branches, a field to store a previous value of a first loop-control variable, a prediction field with a predicted branch direction in terms of “taken” or “not taken”, a validity field to indicate a validity of the entry, and a usage field to store usage information for entry replacement selection.

### Claim 11

An electronic apparatus, comprising:
a front end unit to fetch and decode one or more instructions; and
an execution unit communicatively coupled to the front end unit to execute the one or more instructions and provide information to the front end unit,
wherein the front end unit includes a branch prediction unit to predict whether a branch is taken for the one or more instructions, the branch prediction unit including circuitry to:
identify a loop branch instruction in the one or more instructions, wherein an operand of the loop branch instruction comprises a loop-control variable;
speculatively calculate a first value of the loop-control variable for a next iteration of the loop branch instruction, comprising extrapolating the first value based on respective values of the loop-control variable from a current iteration of the loop branch instruction and a previous iteration of the loop branch instruction; and
provide a branch prediction for the loop branch instruction based on the first value.

### Claim 12 (depends on 11)

The electronic apparatus of claim 11, wherein the circuitry is to provide the branch prediction based on whether the first value indicates that the loop branch instruction will exit a loop at the next iteration of the loop branch instruction.

### Claim 13 (depends on 11)

The electronic apparatus of claim 11, wherein the circuitry is further to:
store respective loop-control variable values from previous iterations of loop branch instructions in an array of entries that each correspond to a respective loop branch instruction.

### Claim 14 (depends on 13)

The electronic apparatus of claim 13, wherein an entry of the array includes a tag field calculated by the circuitry to identify loop branches, a field to store a previous value of a first loop-control variable, a prediction field with a predicted branch direction in terms of “taken” or “not taken”, a validity field to indicate a validity of the entry, and a usage field to store usage information for entry replacement selection.
