# US 2021/0240476 A1 · Indirect Branch Predictor for Dynamic Indirect Branches

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

- Number: US 2021/0240476 A1
- Document ID: US20210240476A1
- Status: Published application
- Kind: A1
- Application number: 16/778,913
- Filed: 2020-01-31
- Published: 2021-08-05
- Earliest claimed: 2020-01-31
- Assignees: Apple Inc.
- Applicants: Apple Inc.
- Inventors: Ian D. Kountanis
- Web page: https://patentgrep.com/patent/US20210240476A1

## CPC

- G06F 9/3844: {using dynamic branch prediction, e.g. using branch history tables}
- G06F 9/30054: {Unconditional branch instructions}
- G06F 9/30058: {Conditional branch instructions}
- G06F 9/30061: {Multi-way branch instructions, e.g. CASE}
- G06F 9/323: {for indirect branch instructions}
- G06F 9/3806: {using address prediction, e.g. return stack, branch history buffer}
- G06F 9/3848: {using hybrid branch prediction, e.g. selection between prediction techniques}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

In an embodiment, an indirect branch predictor generates indirect branch predictions for indirect branch instructions. For relatively static branch instructions, the indirect branch predictor may be configured to use a PC corresponding to the indirect branch instruction to generate a target prediction. The indirect branch predictor may be configured to identify at least one dynamic indirect branch instruction and may use a different PC than the PC corresponding to the indirect branch instruction to generate the target prediction (e.g. the most recent previous PC associated with a taken branch (“the previous taken PC”). For some dynamic indirect branch instructions, the previous taken PC may disambiguate different target addresses (e.g. there may be a correlation between the previous taken PC and the target address of the indirect branch instruction).

## Claims

### Claim 1

An indirect branch predictor comprising:
one or more memories configured to store target addresses of indirect branch instructions previously executed by a processor that includes the indirect branch predictor; and
an index selection circuit coupled to the one or more memories and configured to select at least a first address, wherein the indirect branch predictor is configured to generate at least one index into the one or more memories for a first indirect branch instruction based on the first address, wherein the index selection circuit is configured to select between a first fetch address corresponding to an indirect branch instruction and a second fetch address different from the first fetch address to generate the at least one index, wherein the index select circuit is configured to select the second fetch address as the first address responsive to identifying the first indirect branch instruction as an instance of a second indirect branch instruction, and wherein the index selection circuit is configured to select the first fetch address as the first address responsive to the first indirect branch instruction not being the instance of the second indirect branch instruction.

### Claim 2 (depends on 1)

The indirect branch predictor as recited in claim 1 wherein the index selection circuit comprises a register programmable with a third fetch address corresponding to the second indirect branch instruction, wherein the index selection circuit is configured to identify the first indirect branch instruction as the instance of the second indirect branch instruction responsive to the first fetch address matching the third fetch address.

### Claim 3 (depends on 1)

The indirect branch predictor as recited in claim 1 wherein the second fetch address corresponds to a previous predicted taken branch instruction, wherein the previous predicted taken branch instruction was fetched prior to the first indirect branch instruction.

### Claim 4 (depends on 3)

The indirect branch predictor as recited in claim 3 further comprising a capture circuit having a second register, wherein the capture circuit is configured to capture the second fetch address in the second register, and wherein the capture circuit is coupled to the index selection circuit and is configured to provide the second fetch address to the index selection circuit.

### Claim 5 (depends on 4)

The indirect branch predictor as recited in claim 4 wherein the index selection circuit is further configured to receive a top of stack address from a return address stack predictor, and wherein the one or more memories are a plurality of memories, and wherein the index selection circuit is configured to select the second fetch address as the first address for a first subset of the plurality of memories and to select the top of stack address from which to generate an index a second subset of the plurality of memories.

### Claim 6 (depends on 1)

The indirect branch predictor as recited in claim 1 wherein the second fetch address is a top of stack address received from a return address stack predictor.

### Claim 7 (depends on 1)

The indirect branch predictor as recited in claim 1 further comprising a return address stack predictor, wherein a top of stack address in the return address stack predictor is the second fetch address, and wherein the return address stack predictor is configured to push the first fetch address onto the return address stack predictor responsive to detecting that a target address of a branch instruction at the first fetch address matches a routine that includes the second indirect branch instruction.

### Claim 8 (depends on 7)

The indirect branch predictor as recited in claim 7 wherein the return address stack predictor is configured to pop the first fetch address responsive to execution of the instance of the second indirect branch instruction.

### Claim 9

A processor comprising:
a fetch address generation circuit configured to generate fetch addresses to fetch instructions from an instruction cache; and
an indirect branch predictor coupled to the fetch address generation circuit, wherein the indirect branch predictor comprises at least one memory configured to store target addresses of previously executed indirect branch instructions, and wherein the indirect branch predictor comprises a first register that is programmable with data to identify a specific indirect branch instruction, and wherein the indirect branch predictor is configured to generate an index into the at least one memory based on a first address to generate a prediction for a first indirect branch instruction, wherein the indirect branch predictor is configured to select the first address from a plurality of addresses, and wherein the indirect branch predictor is configured to select the first address based on whether or not the first indirect branch instruction is the specific indirect branch instruction.

### Claim 10 (depends on 9)

The processor as recited in claim 9 wherein the plurality of addresses comprise a first fetch address corresponding to the first indirect branch instruction, and wherein the indirect branch predictor is configured to select the first fetch address as the first address responsive to the first indirect branch instruction not being the specific indirect branch instruction.

### Claim 11 (depends on 9)

The processor as recited in claim 9 wherein the plurality of addresses comprise a second fetch address corresponding to a previously-fetched, predicted-taken branch instruction, and wherein the indirect branch predictor is configured to select the second fetch address as the first address responsive to the first indirect branch instruction being the specific indirect branch instruction.

### Claim 12 (depends on 9)

The processor as recited in claim 9 further comprising a return address stack predictor, wherein the plurality of addresses comprise a top of stack address from the return address stack predictor, and wherein the indirect branch predictor is configured to select the top of stack address as the first address responsive to the first indirect branch instruction being the specific indirect branch instruction.

### Claim 13 (depends on 9)

The processor as recited in claim 9 wherein the indirect branch predictor further comprises a return address stack predictor dedicated to a routine that includes the specific indirect branch instruction, wherein the indirect branch predictor is configured to push return addresses on the return address stack predictor responsive to branches to the routine and pop addresses from the return address stack predictor responsive to executing the specific indirect branch instruction.

### Claim 14 (depends on 13)

The processor as recited in claim 13 wherein the plurality of addresses include a top of stack address from the return address stack predictor.

### Claim 15 (depends on 14)

The processor as recited in claim 14 wherein the indirect branch predictor is configured to select the top of stack address responsive to the first indirect branch instruction being the specific indirect branch instruction.

### Claim 16 (depends on 9)

The processor as recited in claim 9 wherein the at least one memory is a plurality of memories, and wherein the indirect branch predictor is configured to provide the first address to generate the index to a subset of the plurality of memories, and wherein the indirect branch predictor is configured to provide a second address of the plurality of addresses to generate the index to remaining ones of the plurality of memories responsive to the first indirect branch instruction being the specific indirect branch instruction.

### Claim 17 (depends on 16)

The processor as recited in claim 16 wherein the indirect branch predictor is configured to provide the first address to generate the index to the remaining ones of the plurality of memories responsive to the first indirect branch instruction not being the specific indirect branch instruction.

### Claim 18

A method comprising:
receiving a fetch address corresponding to a first indirect branch instruction to an indirect branch predictor to predict a first target address of the first indirect branch instruction; and
indexing one or more memories in the indirect branch predictor to determine the first target address to predict for the first indirect branch instruction, wherein the indexing is modified from the indexing used for other indirect branch instructions responsive to detecting that the first indirect branch instruction is a specific indirect branch instruction.

### Claim 19 (depends on 18)

The method as recited in claim 18 wherein the indexing is modified by selecting a different address from a plurality of addresses to use for the indexing when the first indirect branch instruction is the specific indirect branch instruction, wherein the different address is different from a first address selected to use for indexing when the first indirect branch instruction is not the specific indirect branch instruction.

### Claim 20 (depends on 19)

The method as recited in claim 19 wherein the different address is associated with a previously-predicted taken branch instruction.
