# US 12,217,059 B1 · Systems and methods for programmed branch predictors

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

- Number: US 12,217,059 B1
- Document ID: US12217059B1
- Status: Granted
- Kind: B1
- Application number: 18/193,177
- Filed: 2023-03-30
- Granted: 2025-02-04
- Earliest claimed: 2023-03-30
- Assignees: Advanced Micro Devices, Inc.
- Applicants: Advanced Micro Devices, Inc.
- Inventors: Alexander Toufic Freij; Gabriel H. Loh; Onur Kayiran
- Web page: https://patentgrep.com/patent/US12217059B1

## CPC

- G06F 9/30065: {Loop control instructions; iterative instructions, e.g. LOOP, REPEAT}
- G06F 9/3016: {Decoding the operand specifier, e.g. specifier format}
- G06F 9/325: {for loops, e.g. loop detection or loop counter}
- G06F 9/381: {Loop buffering}
- G06F 9/3832: {Value prediction for operands; operand history buffers}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

The disclosed device a controller that sets an iteration counter for a loop based on an iteration value read from a loop iteration instruction for the loop. The controller also updates the iteration counter based on a number of times a loop heading instruction for the loop is decoded. When the iteration counter reaches an end value, the controller selects a not taken identifier for the loop to be fetched, to avoid a branch misprediction. Various other methods, systems, and computer-readable media are also disclosed.

## Claims

### Claim 1

A device comprising:
a controller configured to:
set an iteration counter for a loop based on an iteration value read from a loop iteration instruction corresponding to the loop;
update the iteration counter based on a number of times a loop heading instruction corresponding to the loop is decoded; and
select, in response to the iteration counter reaching an end value, a not taken identifier for the loop to be fetched.

### Claim 2 (depends on 1)

The device of claim 1, wherein updating the iteration counter further comprises updating the iteration counter when the loop heading instruction is decoded.

### Claim 3 (depends on 1)

The device of claim 1, wherein updating the iteration counter further comprises updating the iteration counter based on a number of times the loop heading instruction was previously decoded.

### Claim 4 (depends on 1)

The device of claim 1, wherein updating the iteration counter further comprises changing the iteration counter based on a stride value read from the loop iteration instruction.

### Claim 5 (depends on 1)

The device of claim 1, further comprising a loop iteration buffer, and wherein the controller is configured to create an entry in the loop iteration buffer based on the loop iteration instruction and the entry includes the iteration counter.

### Claim 6 (depends on 5)

The device of claim 5, wherein the entry includes a loop identifier corresponding to the loop heading instruction.

### Claim 7 (depends on 5)

The device of claim 5, wherein the entry includes a not taken identifier corresponding to a loop end instruction.

### Claim 8 (depends on 7)

The device of claim 7, wherein the controller is configured to clear the entry when a taken identifier for the loop and the not taken identifier for the loop have both been decoded.

### Claim 9 (depends on 5)

The device of claim 5, wherein the loop iteration buffer corresponds to a circular buffer.

### Claim 10

A system comprising:
a physical memory;
at least one physical processor;
a loop iteration buffer; and
a controller configured to:
create an entry in the loop iteration buffer for a loop based on a loop iteration instruction, wherein the entry includes an iteration counter based on an iteration value read from the loop iteration instruction, a loop identifier corresponding to a loop heading instruction for the loop, and a not taken identifier corresponding to a loop end instruction for the loop;
update the iteration counter based on a number of times the loop identifier is decoded; and
select, in response to the iteration counter reaching an end value, the not taken identifier to be fetched.

### Claim 11 (depends on 10)

The system of claim 10, wherein updating the iteration counter further comprises updating the iteration counter when the loop identifier is decoded.

### Claim 12 (depends on 10)

The system of claim 10, wherein updating the iteration counter further comprises updating the iteration counter based on a number of times the loop identifier was previously decoded.

### Claim 13 (depends on 10)

The system of claim 10, wherein the entry further includes a stride value read from the loop iteration instruction, and updating the iteration counter further comprises changing the iteration counter based on the stride value.

### Claim 14 (depends on 10)

The system of claim 10, wherein the entry further includes one or more status values.

### Claim 15 (depends on 14)

The system of claim 14, wherein the one or more status values include a taken flag corresponding to whether a predicted branch for the loop has been decoded, and a not taken flag corresponding to whether the not taken identifier has been decoded.

### Claim 16 (depends on 15)

The system of claim 15, wherein the controller is configured to clear the entry when the taken flag and the not taken flag are both set.

### Claim 17 (depends on 15)

The system of claim 15, wherein the one or more status values includes a valid flag, and the controller is configured to clear the entry by clearing the valid flag.

### Claim 18 (depends on 10)

The system of claim 10, wherein the loop iteration buffer corresponds to a circular buffer.

### Claim 19 (depends on 18)

The system of claim 18, wherein creating the entry further comprises updating a tail of the circular buffer with the created entry.

### Claim 20

A method comprising:
reading a loop iteration instruction for a loop, the loop iteration instruction including an iteration value;
identifying a loop identifier corresponding to a loop heading instruction for the loop;
identifying a not taken identifier corresponding to a loop end instruction for the loop;
creating an entry in a loop iteration buffer, the entry including an iteration counter based on the iteration value, the loop identifier, and the not taken identifier;
updating the iteration counter based on a number of times the loop identifier is decoded; and
selecting, in response to the iteration counter reaching an end value, the not taken identifier to be fetched.
