# US 2024/0004658 A1 · Instruction simulation device and method thereof

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

- Number: US 2024/0004658 A1
- Document ID: US20240004658A1
- Status: Published application
- Kind: A1
- Application number: 18/465,189
- Filed: 2023-09-12
- Published: 2024-01-04
- Earliest claimed: 2020-12-29
- Assignees: Shanghai Zhaoxin Semiconductor Co., Ltd.
- Applicants: Shanghai Zhaoxin Semiconductor Co., Ltd.
- Inventors: Weilin Wang; Yingbing Guan; Mengchen Yang
- Web page: https://patentgrep.com/patent/US20240004658A1

## CPC

- G06F 9/30145: {Instruction analysis, e.g. decoding, instruction word fields}
- G06F 9/30014: {with variable precision}
- G06F 9/30047: {Prefetch instructions; cache control instructions}
- G06F 9/30101: {Special purpose registers}
- G06F 9/3017: {Runtime instruction translation, e.g. macros}
- G06F 9/30174: {for non-native instruction set, e.g. Javabyte, legacy code}
- G06F 9/30185: {according to one or more bits in the instruction, e.g. prefix, sub-opcode}
- G06F 9/30189: {according to execution mode, e.g. mode flag}
- G06F 9/3814: {Implementation provisions of instruction buffers, e.g. prefetch buffer; banks}
- G06F 9/3854: {Instruction completion, e.g. retiring, committing or graduating}
- G06F 9/3858: {Result writeback, i.e. updating the architectural state or memory}
- G06F 9/455: Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F 9/45516: {Runtime code conversion or optimisation}
- G06F 9/4812: {by interrupt, e.g. masked}
- G06F 11/0772: {Means for error signaling, e.g. using interrupts, exception flags, dedicated error registers}
- G06F 30/33: Design verification, e.g. functional simulation or model checking
- G06F 30/333: Design for testability [DFT], e.g. scan chain or built-in self-test [BIST]
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

An instruction simulation device and a method thereof are provided. The instruction simulation device includes a processor. The processor includes an instruction decoder which generates format information of a ready-for-execution instruction. The processor determines whether the ready-for-execution instruction currently executed by the processor is a compatible instruction or an extended instruction based on the format information of the ready-for-execution instruction. If the ready-for-execution instruction is an extended instruction under the new instruction set or the extended instruction set, the processor converts the ready-for-execution instruction into a simulation program corresponding to the extended instruction, and simulates an execution result of the ready-for-execution instruction by executing the simulation program. The simulation program is composed of at least one compatible instructions of the processor. If the ready-for-execution instruction is a compatible instruction, the processor executes the ready-for-execution instruction.

## Claims

### Claim 1

An instruction simulation device, comprising a processor, the processor comprising:
an instruction decoder, configured to generate format information of a ready-for-execution instruction; and
the processor is configured to determine whether the ready-for-execution instruction currently executed by the processor is a compatible instruction or an extended instruction based on the format information of the ready-for-execution instruction, wherein the compatible instruction is an instruction under a current instruction set of the processor, and the extended instruction is not an instruction under the current instruction set of the processor but is an instruction under a new instruction set or an extended instruction set, wherein the new instruction set and the extended instruction set are instruction sets that do not belong to a native instruction set of the processor; wherein
if the ready-for-execution instruction is an extended instruction under the new instruction set or the extended instruction set, the processor converts the ready-for-execution instruction into a simulation program corresponding to the extended instruction, and simulates an execution result of the ready-for-execution instruction by executing the simulation program; and
if the ready-for-execution instruction is a compatible instruction, the processor executes the ready-for-execution instruction;
wherein the simulation program is composed of at least one compatible instructions of the processor.

### Claim 2 (depends on 1)

The instruction simulation device according to claim 1, wherein a computer system embodied with the processor comprises a system memory, the system memory comprising:
a processor-current-state store region, configured to store a current-context state of the processor;
a conversion-information store region, configured to store temporary information in a process of translating the ready-for-execution instruction into the corresponding simulation program; and
an execution-result store region, configured to store the execution result after executing the simulation program.

### Claim 3 (depends on 1)

The instruction simulation device according to claim 1, wherein when the ready-for-execution instruction is the extended instruction, the processor asserts an emulation flag to obtain the corresponding simulation program by means of an interrupt service program.

### Claim 4 (depends on 1)

The instruction simulation device according to claim 1, wherein the processor comprises:
a plurality of registers, comprising a register configured to indicate an address of a storage space caching a current state of the processor, a register configured to indicate an address of a storage space caching a conversion intermediate result when calling the corresponding simulation program, a register configured to indicate an address of a storage space caching a simulation execution result, a simulation register configured to map a target register indicated by the extended instruction, and a register configured to cache an address indicative of a real-time conversion mode state store region.

### Claim 5 (depends on 1)

The instruction simulation device according to claim 1, wherein an interrupt service program calls a simulation module to query if there is a simulation program corresponding to the extended instruction, wherein if the simulation program corresponding to the extended instruction is found, the simulation module executes the simulation program and obtains a simulation execution result for simulating the execution result of the ready-for-execution instruction.

### Claim 6 (depends on 5)

The instruction simulation device according to claim 5, wherein the simulation execution result is reserved after terminating the calling to the simulation module, and when the simulation program corresponding to the extended instruction is not found, a failure result is returned to notify the processor and the calling to the simulation module is terminated in responsive to the failure result.

### Claim 7 (depends on 6)

The instruction simulation device according to claim 6, wherein after terminating the calling to the simulation module, the processor reads the reserved simulation execution result or receives the failure result, wherein the processor notifies an application program arising the ready-for-execution instruction of the failure result.

### Claim 8 (depends on 6)

The instruction simulation device according to claim 6, wherein if a subsequent ready-for-execution instruction is an extended instruction and the subsequent ready-for-execution instruction is converted into a simulation program corresponding to the subsequent ready-for-execution instruction, the reserved simulation execution result serves as a reference when executing the simulation program corresponding to the subsequent ready-for-execution instruction.

### Claim 9 (depends on 5)

The instruction simulation device according to claim 5, wherein the simulation module is embodied in a processor driver, in a kernel of an operating system running on the processor, or stored in a basic input/output system of a computer system embodied with the processor.

### Claim 10 (depends on 1)

The instruction simulation device according to claim 1, wherein the compatible instruction and the extended instruction are both instructions under an x86 instruction set architecture or a reduced instruction set computer (RISC) architecture.

### Claim 11

An instruction simulation method, performed by a processor including an instruction decoder, the instruction simulation method comprising:
using the instruction decoder of the processor to generate format information of a ready-for-execution instruction;
determining by the processor whether the ready-for-execution instruction currently executed by the processor is a compatible instruction or an extended instruction based on the format information of the ready-for-execution instruction, wherein the compatible instruction is an instruction under a current instruction set of the processor, and the extended instruction is not an instruction under the current instruction set of the processor, but is an instruction under a new instruction set or an extended instruction set, wherein the new instruction set and the extended instruction set are instruction sets that do not belong to a native instruction set of the processor;
translating the ready-for-execution instruction into a simulation program corresponding to the extended instruction wherein an execution result of the ready-for-execution instruction is generated by means of a simulation execution result generated by the simulation program if the read-for-execution instruction is an extended instruction under the new instruction set or the extended instruction set; and
executing the ready-for-execution instruction by the processor if the read-for-execution instruction is a compatible instruction;
wherein the simulation program is composed of at least one compatible instruction of the processor.

### Claim 12 (depends on 11)

The instruction simulation method according to claim 11, wherein a computer system embodied the processor comprises a system memory, the system memory comprising:
a processor-current-state store region, configured to store a current context state of the processor;
a conversion-information store region, configured to store temporary information in a process of translating the ready-for-execution instruction into the corresponding simulation program; and
an execution-result store region, configured to store the simulation execution result after executing the simulation program.

### Claim 13 (depends on 11)

The instruction simulation method according to claim 11, wherein when the ready-for-execution instruction is the extended instruction, the processor asserts an emulation flag to obtain the corresponding simulation program by means of an interrupt service program.

### Claim 14 (depends on 11)

The instruction simulation method according to claim 11, further comprising:
calling a simulation module by an interrupt service program to read the ready-for-execution instruction;
querying whether there is the simulation program corresponding to the extended instruction by the simulation module; and
generating the simulation execution result by executing the simulation program by the simulation module when the simulation program corresponding to the extended instruction is found.

### Claim 15 (depends on 14)

The instruction simulation method according to claim 14, further comprising:
reserving the simulation execution result after terminating the calling to the simulation module; and
providing a failure result by the simulation module to the processor and terminating the calling to the simulation module when the simulation program corresponding to the extended instruction is not found.

### Claim 16 (depends on 15)

The instruction simulation method according to claim 15, further comprising:
reading the simulation execution result reserving by the processor after terminating the calling to the simulation module, or obtaining the failure result and notifying an application program arising the ready-for-execution instruction of the failure result.

### Claim 17 (depends on 16)

The instruction simulation method according to claim 16, wherein if a subsequent ready-for-execution instruction is an extended instruction and the subsequent ready-for-execution instruction is converted into a simulation program corresponding to the subsequent ready-for-execution instruction, the reserved execution result serves as a reference when executing the simulation program of the subsequent ready-for-execution instruction.

### Claim 18 (depends on 15)

The instruction simulation method according to claim 15, wherein the simulation module is embodied in a processor driver, in a kernel of an operating system running on the processor, or stored in a basic input/output system of a computer system embodied with the processor.

### Claim 19 (depends on 11)

The instruction simulation method according to claim 11, wherein the compatible instruction and the extended instruction are both instructions under an x86 instruction set architecture or a reduced instruction set computer (RISC) architecture.

### Claim 20

A processor instruction simulation method, comprising:
using an instruction decoder of a processor to generate format information of a ready-for-execution instruction;
determining, by the processor, whether the ready-for-execution instruction currently executed by the processor is an extended instruction based on the format information of the ready-for-execution instruction;
when the ready-for-execution instruction currently executed by the processor is the extended instruction, calling a simulation module by using an interrupt service program to obtain a simulation program corresponding to the extended instruction, wherein the extended instruction is not an instruction under a current instruction set of the processor, but is an instruction under a new instruction set or an extended instruction set, wherein the new instruction set and the extended instruction set are instruction sets that do not belong to a native instruction set of the processor; and
executing the simulation program to generate a simulation execution result for simulating an execution result of the ready-for-execution instruction.

### Claim 21 (depends on 20)

The processor instruction simulation method according to claim 20, wherein the ready-for-execution instruction is sent as a parameter when the simulation module is called.

### Claim 22 (depends on 21)

The processor instruction simulation method according to claim 21, wherein the processor executes the simulation module by means of a system call to an operating system performing on the processor.

### Claim 23 (depends on 22)

The processor instruction simulation method according to claim 22, wherein the simulation module is in a kernel of the operating system or is a callback function in a driver of the processor.

### Claim 24 (depends on 20)

The processor instruction simulation method according to claim 20, wherein the simulation module and the simulation program are stored in a basic input/output system of a computer system embodied with the processor, and when the computer system is turned on, the simulation module and the simulation program are loaded into a system memory of the computer system.

### Claim 25 (depends on 20)

The processor instruction simulation method according to claim 20, further comprising:
terminating the calling to the simulation module after reserving a simulation execution result of the simulation program in a system memory of a computer system embodied with the processor.

### Claim 26 (depends on 20)

The processor instruction simulation method according to claim 20, wherein the simulation execution result is reserved after terminating the calling to the simulation module, wherein if a subsequent ready-for-execution instruction is an extended instruction and the subsequent ready-for-execution instruction is converted into a simulation program corresponding to the subsequent ready-for-execution instruction, the reserved execution result serves as a reference when executing the simulation program of the subsequent ready-for-execution instruction.

### Claim 27 (depends on 20)

The processor instruction simulation method according to claim 20, wherein the simulation program is programmed by a processor designer beforehand by using at least one compatible instruction of the processors to simulate the execution result of the extended instruction.

### Claim 28 (depends on 20)

The processor instruction simulation method according to claim 20, wherein a compatible instruction and the extended instruction are both instructions under an x86 instruction set architecture or a reduced instruction set computer (RISC) architecture.

### Claim 29

A processor instruction simulation method, comprising:
using an instruction decoder of a processor to generate format information of a ready-for-execution instruction;
determining, by the processor, whether the ready-for-execution instruction currently executed by the processor is an extended instruction based on the format information of the ready-for-execution instruction;
when the ready-for-execution instruction currently executed by the processor is the extended instruction, calling an interrupt service program to obtain a simulation program corresponding to the extended instruction, wherein the extended instruction is not an instruction under a current instruction set of the processor, but is an instruction under a new instruction set or an extended instruction set, wherein the new instruction set and the extended instruction set are instruction sets that do not belong to a native instruction set of the processor; and
executing the simulation program to generate a simulation execution result for simulating the extended instruction.

### Claim 30 (depends on 29)

The processor instruction simulation method according to claim 29, wherein the interrupt service program obtains the simulation program corresponding to the extended instruction by means of a system call, and the ready-for-execution instruction is sent as a parameter when invoking the system call.

### Claim 31 (depends on 30)

The processor instruction simulation method according to claim 30, wherein the system call invokes a simulation module in a kernel of an operating system performing on the processor or in a processor driver to obtain the simulation program.

### Claim 32 (depends on 31)

The processor instruction simulation method according to claim 31, wherein the simulation module is a callback function.

### Claim 33 (depends on 31)

The processor instruction simulation method according to claim 31, wherein the calling to the simulation module is terminated after the simulation module executes the simulation program to generate the simulation execution result.

### Claim 34 (depends on 33)

The processor instruction simulation method according to claim 33, wherein the simulation execution result is reserved after terminating the calling to the simulation module, wherein if a subsequent ready-for-execution instruction is determined an extended instruction and the subsequent ready-for-execution instruction is converted into a simulation program corresponding to the subsequent ready-for-execution instruction, the reserved simulation execution result serves as a reference when executing the simulation program of the subsequent ready-for-execution instruction.

### Claim 35 (depends on 29)

The processor instruction simulation method according to claim 29, wherein the simulation program is programmed by a processor designer beforehand by using at least one compatible instruction of the processor to simulate the execution result of the extended instruction.

### Claim 36 (depends on 29)

The processor instruction simulation method according to claim 29, wherein a compatible instruction and the extended instruction are both instructions under an x86 instruction set architecture or a reduced instruction set computer (RISC) architecture.
