# US 2021/0173653 A1 · Instruction prefetching method, device and medium

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

- Number: US 2021/0173653 A1
- Document ID: US20210173653A1
- Status: Published application
- Kind: A1
- Application number: 17/036,596
- Filed: 2020-09-29
- Published: 2021-06-10
- Earliest claimed: 2019-12-04
- Assignees: Beijing Baidu Netcom Science Technology Co., Ltd.
- Applicants: Beijing Baidu Netcom Science and Technology Co., Ltd.
- Inventors: Chao TANG; Xueliang DU; Yingnan XU
- Web page: https://patentgrep.com/patent/US20210173653A1

## CPC

- G06F 9/3804: {for branches, e.g. hedging, branch folding}
- G06F 9/30047: {Prefetch instructions; cache control instructions}
- G06F 9/3814: {Implementation provisions of instruction buffers, e.g. prefetch buffer; banks}
- G06F 9/3844: {using dynamic branch prediction, e.g. using branch history tables}
- G06F 9/3861: {Recovery, e.g. branch miss-prediction, exception handling (error detection or correction G06F11/00)}
- Y02D 10/00: Energy efficient computing, e.g. low power processors, power management or thermal management
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- Y02D: CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE

## Abstract

The present disclosure discloses an instruction prefetching method, a device and a medium. The present disclosure relates to a data storage technology, the method includes the following. Instructions in a target buffer are precompiled before a processor core fetches a required instruction from the target buffer corresponding to the processor core; if it is determined that a jump instruction exists in the target buffer and a branch instruction corresponding to the jump instruction is not cached in the target buffer according to a precompiled result, the branch instruction is prefetched from an icache into a candidate buffer corresponding to the processor core to wait for the processor core to fetch the branch instruction from the candidate buffer; the target buffer and the candidate buffer are alternately reused during instruction prefetching.

## Claims

### Claim 1

An instruction prefetching method, comprising:
before a processor core fetches a required instruction from a target buffer corresponding to the processor core, precompiling instructions in the target buffer; and
in response to determining that a jump instruction exists in the target buffer and a branch instruction corresponding to the jump instruction is not cached in the target buffer according to a precompiled result, prefetching the branch instruction from an icache into a candidate buffer corresponding to the processor core to wait for the processor core to fetch the branch instruction from the candidate buffer;
in which the target buffer and the candidate buffer are alternately reused during instruction prefetching.

### Claim 2 (depends on 1)

The method of claim 1, wherein prefetching the branch instruction from the icache into the candidate buffer corresponding to the processor core comprises:
taking a minimum instruction address in the branch instruction as a head address, prefetching a preset number of instructions from the icache, and caching the preset number of instructions into the candidate buffer corresponding to the processor core, in which the branch instruction is comprised in the preset number of instructions.

### Claim 3 (depends on 1)

The method of claim 1, wherein prefetching the branch instruction from the icache into the candidate buffer corresponding to the processor core comprises:
determining whether the branch instruction is cached in the candidate buffer corresponding to the processor core; and
in response to determining that the branch instruction is not cached in the candidate buffer corresponding to the processor core, prefetching the branch instruction from the icache into the candidate buffer.

### Claim 4 (depends on 1)

The method of claim 1, wherein in response to the processor core fetching the branch instruction from the candidate buffer, a current instruction fetching buffer is switched from the target buffer to the candidate buffer; and
the method further comprises:
before the processor core fetches the branch instruction corresponding to the jump instruction from the candidate buffer, precompiling instructions in the candidate buffer to determine a branch instruction not cached in the candidate buffer.

### Claim 5 (depends on 1)

The method of claim 1, wherein precompiling the instructions in the target buffer comprises:
precompiling the instructions in the target buffer by using a branch prediction algorithm.

### Claim 6 (depends on 5)

The method of claim 5, wherein after precompiling the instructions in the target buffer, the method further comprises:
in response to receiving prediction failure information, sequentially executing an instruction address matching in a register of the target buffer and a register of the candidate buffer in a process of executing a target jump instruction by the processor core, to determine a buffer where a branch instruction corresponding to the target jump instruction is located.

### Claim 7 (depends on 6)

The method of claim 6, further comprising:
in response to determining that the branch instruction corresponding to the target jump instruction is not in the target buffer and the candidate buffer based on the instruction address matching, taking an address of the branch instruction corresponding to the target jump instruction as a head address, prefetching a preset number of instructions from the icache and caching the preset number of instructions into the candidate buffer.

### Claim 8 (depends on 1)

The method of claim 1, further comprising:
in response to determining that no jump instruction exists in the target buffer according to the precompiled result, taking a maximum instruction address of the instructions in the target buffer as a head address, prefetching a preset number of instructions from the icache into the candidate buffer.

### Claim 9

An electronic device, comprising:
at least one processor; and
a memory, communicatively coupled to the at least one processor; wherein
the memory stores instructions executable by the at least one processor, when the instructions are executed by the at least one processor, the at least one processor is caused to perform the instruction prefetching method, comprising:
before a processor core fetches a required instruction from a target buffer corresponding to the processor core, precompiling instructions in the target buffer; and
in response to determining that a jump instruction exists in the target buffer and a branch instruction corresponding to the jump instruction is not cached in the target buffer according to a precompiled result, prefetching the branch instruction from an icache into a candidate buffer corresponding to the processor core to wait for the processor core to fetch the branch instruction from the candidate buffer;
in which the target buffer and the candidate buffer are alternately reused during instruction prefetching.

### Claim 10 (depends on 9)

The electronic device of claim 9, wherein prefetching the branch instruction from the icache into the candidate buffer corresponding to the processor core comprises:
taking a minimum instruction address in the branch instruction as a head address, prefetching a preset number of instructions from the icache, and caching the preset number of instructions into the candidate buffer corresponding to the processor core, in which the branch instruction is comprised in the preset number of instructions.

### Claim 11 (depends on 9)

The electronic device of claim 9, wherein prefetching the branch instruction from the icache into the candidate buffer corresponding to the processor core comprises:
determining whether the branch instruction is cached in the candidate buffer corresponding to the processor core; and
in response to determining that the branch instruction is not cached in the candidate buffer corresponding to the processor core, prefetching the branch instruction from the icache into the candidate buffer.

### Claim 12 (depends on 9)

The electronic device of claim 9, wherein in response to the processor core fetching the branch instruction from the candidate buffer, a current instruction fetching buffer is switched from the target buffer to the candidate buffer; and
the method further comprises:
before the processor core fetches the branch instruction corresponding to the jump instruction from the candidate buffer, precompiling instructions in the candidate buffer to determine a branch instruction not cached in the candidate buffer.

### Claim 13 (depends on 9)

The electronic device of claim 9, wherein precompiling the instructions in the target buffer comprises:
precompiling the instructions in the target buffer by using a branch prediction algorithm.

### Claim 14 (depends on 13)

The electronic device of claim 13, wherein after precompiling the instructions in the target buffer, the method further comprises:
in response to receiving prediction failure information, sequentially executing an instruction address matching in a register of the target buffer and a register of the candidate buffer in a process of executing a target jump instruction by the processor core, to determine a buffer where a branch instruction corresponding to the target jump instruction is located.

### Claim 15 (depends on 14)

The electronic device of claim 14, wherein the method further comprises:
in response to determining that the branch instruction corresponding to the target jump instruction is not in the target buffer and the candidate buffer based on the instruction address matching, taking an address of the branch instruction corresponding to the target jump instruction as a head address, prefetching a preset number of instructions from the icache and caching the preset number of instructions into the candidate buffer.

### Claim 16 (depends on 9)

The electronic device of claim 9, the method further comprises:
in response to determining that no jump instruction exists in the target buffer according to the precompiled result, taking a maximum instruction address of the instructions in the target buffer as a head address, prefetching a preset number of instructions from the icache into the candidate buffer.

### Claim 17

A non-transitory computer readable storage medium, having computer instructions stored thereon for causing a computer to perform the instruction prefetching method, comprising:
before a processor core fetches a required instruction from a target buffer corresponding to the processor core, precompiling instructions in the target buffer; and
in response to determining that a jump instruction exists in the target buffer and a branch instruction corresponding to the jump instruction is not cached in the target buffer according to a precompiled result, prefetching the branch instruction from an icache into a candidate buffer corresponding to the processor core to wait for the processor core to fetch the branch instruction from the candidate buffer;
in which the target buffer and the candidate buffer are alternately reused during instruction prefetching.

### Claim 18 (depends on 17)

The non-transitory computer readable storage medium of claim 17, wherein prefetching the branch instruction from the icache into the candidate buffer corresponding to the processor core comprises:
taking a minimum instruction address in the branch instruction as a head address, prefetching a preset number of instructions from the icache, and caching the preset number of instructions into the candidate buffer corresponding to the processor core, in which the branch instruction is comprised in the preset number of instructions.

### Claim 19 (depends on 17)

The non-transitory computer readable storage medium of claim 17, wherein prefetching the branch instruction from the icache into the candidate buffer corresponding to the processor core comprises:
determining whether the branch instruction is cached in the candidate buffer corresponding to the processor core; and
in response to determining that the branch instruction is not cached in the candidate buffer corresponding to the processor core, prefetching the branch instruction from the icache into the candidate buffer.

### Claim 20 (depends on 17)

The non-transitory computer readable storage medium of claim 17, wherein in response to the processor core fetching the branch instruction from the candidate buffer, a current instruction fetching buffer is switched from the target buffer to the candidate buffer; and
the method further comprises:
before the processor core fetches the branch instruction corresponding to the jump instruction from the candidate buffer, precompiling instructions in the candidate buffer to determine a branch instruction not cached in the candidate buffer.
