# US 2025/0147769 A1 · Method for processing instruction, processor, electronic apparatus and storage medium

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

- Number: US 2025/0147769 A1
- Document ID: US20250147769A1
- Status: Published application
- Kind: A1
- Application number: 18/935,154
- Filed: 2024-11-01
- Published: 2025-05-08
- Earliest claimed: 2023-11-03
- Assignees: Beijing ESWIN Computing Technology Co., Ltd.
- Applicants: Beijing ESWIN Computing Technology Co., Ltd.
- Inventors: Yongbin YAO
- Web page: https://patentgrep.com/patent/US20250147769A1

## CPC

- G06F 9/3861: {Recovery, e.g. branch miss-prediction, exception handling (error detection or correction G06F11/00)}
- G06F 9/3804: {for branches, e.g. hedging, branch folding}
- 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

A method for processing an instruction, a processor, an electronic apparatus and a storage medium are provided. The method for processing the instruction includes: writing an instruction stream into an instruction data cache and a branch prediction error determination unit in parallel in an instruction processing pipeline, and determining a branch instruction in the instruction stream and whether a branch prediction error exists for the branch instruction in the branch prediction error determination unit; and in response to the branch prediction error existing for the branch instruction, performing a flush operation on an object instruction in the instruction processing pipeline that is fetched due to the branch prediction error.

## Claims

### Claim 1

A method for processing an instruction, comprising:
writing an instruction stream into an instruction data cache and a branch prediction error determination unit in parallel in an instruction processing pipeline, and determining a branch instruction in the instruction stream and whether a branch prediction error exists for the branch instruction in the branch prediction error determination unit; and
in response to the branch prediction error existing for the branch instruction, performing a flush operation on an object instruction in the instruction processing pipeline that is fetched due to the branch prediction error.

### Claim 2 (depends on 1)

The method according to claim 1, wherein the determining a branch instruction in the instruction stream and whether a branch prediction error exists for the branch instruction comprises:
performing a first instruction segmentation on the instruction stream written into the branch prediction error determination unit to obtain a first set of instructions;
in response to the branch instruction existing in the first set of instructions, computing a computation target address of the branch instruction, and checking whether the computation target address is consistent with a branch prediction target address for the branch instruction; and
in response to the computation target address being inconsistent with the branch prediction target address, determining that the branch prediction error exists for the branch instruction.

### Claim 3 (depends on 2)

The method according to claim 2, wherein the computing a computation target address of the branch instruction comprises:
computing the computation target address based on instruction jump information of the branch instruction.

### Claim 4 (depends on 1)

The method according to claim 1, further comprising:
in response to the branch prediction error existing, correcting a write pointer of the instruction data cache to move the write pointer to a location of the object instruction in the instruction data cache.

### Claim 5 (depends on 1)

The method according to claim 1, further comprising:
performing a second instruction segmentation on the instruction stream written into the instruction data cache to obtain a second set of instructions; and
reading the second set of instructions and in response to the second set of instructions comprising the object instruction, blocking an execution of the object instruction.

### Claim 6 (depends on 5)

The method according to claim 5, wherein the performing a second instruction segmentation on the instruction stream written into the instruction data cache to obtain a second set of instructions comprises:
reading first control information of the instruction stream from the instruction data cache;
performing an instruction segmentation on the instruction stream based on the first control information to obtain location information in the instruction data cache for each instruction in the second set of instructions; and
providing the location information to enable reading the second set of instructions from the instruction data cache based on the location information for decoding.

### Claim 7 (depends on 6)

The method according to claim 6, wherein the in response to the second set of instructions comprising the object instruction, blocking an execution of the object instruction comprises:
reading the second set of instructions from the instruction data cache based on the location information via a data path from the instruction data cache to a decoding unit;
in response to the second set of instructions comprising the object instruction, marking the object instruction as an invalid state; and
in response to the invalid state, disabling a decoding operation for the object instruction or decoding the object instruction as an invalid instruction.

### Claim 8 (depends on 5)

The method according to claim 5, further comprising:
in response to the second set of instructions not comprising the object instruction, continuing an execution of each instruction in the second set of instructions.

### Claim 9 (depends on 1)

The method according to claim 1, further comprising:
performing an instruction fetch operation to acquire the instruction stream in the instruction processing pipeline.

### Claim 10 (depends on 9)

The method according to claim 9, wherein the performing an instruction fetch operation to acquire the instruction stream comprises:
in response to receiving an instruction acquisition request, based on a tag part of a destination address comprised in the instruction acquisition request, querying a tag memory of an instruction cache to determine whether the tag part hits the tag memory;
in response to the tag part hitting the tag memory, reading instruction data corresponding to the instruction acquisition request from a data memory of the instruction cache as the instruction stream; or in response to the tag part not hitting the tag memory, reading instruction data corresponding to the instruction acquisition request from a main memory or a next level cache.

### Claim 11 (depends on 1)

The method according to claim 1, wherein the instruction stream comprises a plurality of non-fix length instructions.

### Claim 12

A processor, comprising an instruction data cache, an instruction stream transmission unit, and a branch prediction error determination unit,
wherein the instruction stream transmission unit is configured to write an instruction stream into the instruction data cache and the branch prediction error determination unit in parallel in an instruction processing pipeline; and
the branch prediction error determination unit is configured to:
determine a branch instruction in the instruction stream and whether a branch prediction error exists for the branch instruction; and
in response to the branch prediction error existing for the branch instruction, perform a flush operation on an object instruction in the instruction processing pipeline that is fetched due to the branch prediction error.

### Claim 13 (depends on 12)

The processor according to claim 12, wherein the branch prediction error determination unit comprises:
a first instruction segmentation unit, configured to perform a first instruction segmentation on the instruction stream written into the branch prediction error determination unit to obtain a first set of instructions; and
a branch result computation and checking unit, configured to, in response to the branch instruction existing in the first set of instructions, compute a computation target address of the branch instruction, and check whether the computation target address is consistent with a branch prediction target address for the branch instruction, and in response to the computation target address being inconsistent with the branch prediction target address, determine that the branch prediction error exists for the branch instruction.

### Claim 14 (depends on 12)

The processor according to claim 12, wherein the branch prediction error determination unit is further configured to:
in response to the branch prediction error existing, correct a write pointer of the instruction data cache to move the write pointer to a location of the object instruction in the instruction data cache.

### Claim 15 (depends on 12)

The processor according to claim 12, further comprising:
a second instruction segmentation unit, configured to perform a second instruction segmentation on the instruction stream written into the instruction data cache to obtain a second set of instructions; and
a block unit, configured to read the second set of instructions and in response to the second set of instructions comprising the object instruction, block an execution of the object instruction.

### Claim 16 (depends on 15)

The processor according to claim 15, wherein the second instruction segmentation unit is further configured to:
read first control information of the instruction stream from the instruction data cache;
perform an instruction segmentation on the instruction stream based on the first control information to obtain location information in the instruction data cache for each instruction in the second set of instructions; and
provide the location information to enable reading the second set of instructions from the instruction data cache based on the location information for decoding.

### Claim 17 (depends on 16)

The processor according to claim 16, wherein the block unit comprises:
a reading unit, configured to read the second set of instructions from the instruction data cache based on the location information via a data path from the instruction data cache to a decoding unit;
a marking unit, configured to, in response to the second set of instructions comprising the object instruction, mark the object instruction as an invalid state; and
a decoding unit, configured to, in response to the invalid state, disable a decoding operation for the object instruction or decode the object instruction as an invalid instruction.

### Claim 18 (depends on 15)

The processor according to claim 15, wherein the block unit is further configured to:
in response to the second set of instructions not comprising the object instruction, continue an execution of each instruction in the second set of instructions.

### Claim 19

An electronic apparatus, comprising:
at least one processor;
at least one memory storing one or more computer program modules,
wherein the one or more computer program modules are configured to be executed by the at least one processor to implement a method for processing an instruction, and the method comprises:
writing an instruction stream into an instruction data cache and a branch prediction error determination unit in parallel in an instruction processing pipeline, and determining a branch instruction in the instruction stream and whether a branch prediction error exists for the branch instruction in the branch prediction error determination unit; and
in response to the branch prediction error existing for the branch instruction, performing a flush operation on an object instruction in the instruction processing pipeline that is fetched due to the branch prediction error.

### Claim 20 (depends on 1)

A non-transitory computer-readable storage medium storing computer executable instructions, wherein the computer executable instructions, upon being executed by one or more processors, implement the method according to claim 1.
