Dynamic instruction test sequence generation method based on instruction machine code, computer equipment and storage medium

By constructing instruction machine code models and test templates, semantically effective instruction machine code test sequences are directly generated, which solves the problems of high performance overhead and incomplete verification in the existing technology, and achieves comprehensive verification and efficient detection of each module of the processor.

CN118535405APending Publication Date: 2024-08-23ZHEJIANG UNIV +1
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410792791.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-19
Publication Date
2024-08-23

Smart Images

  • Figure CN118535405A
    Figure CN118535405A
Patent Text Reader

Abstract

The invention provides an instruction machine code-based dynamic instruction test sequence generation method. The method comprises the following steps of: constructing a plurality of instruction machine code models according to instruction set system architecture specifications; constructing a test template based on the test scene, wherein the test template comprises a definition of an instruction category and a generation demand of an instruction; generating an instruction machine code through an instruction machine code model based on an instruction category and an instruction generation demand defined by the test template; sending the generated instruction machine codes into an instruction simulator for detection, and storing the detected instruction machine codes until the generation number of the instruction machine codes meets the generation requirement in the test template; and respectively sending all the generated instruction machine codes into a to-be-verified processor and an instruction simulator for execution, and comparing and analyzing execution logs of each instruction. According to the method, more efficient and more comprehensive verification is performed on the processor by directly generating the instruction machine code test sequence with effective semantics, and the test sequence generation problem of instruction set architecture function verification in the pre-silicon stage of the processor is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of processor design and verification, and in particular to a method for generating a dynamic instruction test sequence based on an instruction machine code of a processor, which is used for functional verification of an instruction set architecture of a processor at a pre-silicon stage. Background Art

[0002] With the rapid development of information technology, information systems have been widely used in various fields of people's production and life, from intelligent computing systems to unmanned driving systems, providing many conveniences for people's lives. The security of information systems is an important prerequisite for people to enjoy these conveniences. As the core circuit of the information system, the processor is one of the most core and critical components in modern computer systems. It is responsible for control, calculation and processing tasks and is widely used in information systems. It can be said that processor hardware security is the premise for the safe use of information systems. Modern processors are usually equipped with billions of transistors and multiple cores. Hardware vulnerabilities in design and preparation will not only lead to incorrect calculation results, but also pose a serious security threat to the entire processor system. Considering the difficulty of fixing hardware vulnerabilities and the large amount of time and economic costs required, it is crucial to use efficient verification methods to detect vulnerabilities early in the pre-silicon stage. However, fierce competitive pressure and the need for rapid market launch often put processor suppliers under strict restrictions on the time and resources for verification, making exhaustive verification an unrealistic goal.

[0003] Most of the existing random generation methods of test instruction sequences are based on assembly code, which uses a simple and direct method to randomize the parameters in the assembly instructions to generate assembly instruction test sequences. Each assembly test needs to be converted into machine code by the assembler, loaded into the simulator, and a log file is generated to compare with the reference model. Therefore, this generation method based on assembly code has an inherent performance overhead caused by a large amount of file system communication. In addition, these test sequences are also limited by the assembler itself and cannot generate instruction machine code sequences that are legal but non-standard in the instruction set specification, that is, they cannot fully verify each module in the processor. Summary of the invention

[0004] Based on the above background, the present invention proposes a dynamic instruction test sequence generation method based on instruction machine code, which directly generates semantically valid instruction machine code test sequences to perform more efficient and comprehensive verification of the processor, so as to solve the test sequence generation problem of processor pre-silicon stage instruction set architecture function verification.

[0005] To achieve the above object, the present invention adopts the following technical solutions:

[0006] A first aspect of the present invention provides a method for generating a dynamic instruction test sequence based on an instruction machine code, comprising the following steps:

[0007] Build multiple instruction machine code models based on instruction set architecture specifications;

[0008] Building a test template based on the test scenario, wherein the test template includes a definition of an instruction category and a generation requirement of an instruction;

[0009] Generate instruction machine code through instruction machine code model based on instruction category and instruction generation requirements defined by test template;

[0010] Send the generated instruction machine code to the instruction simulator for detection, and save the instruction machine code that passes the detection until the number of instruction machine codes generated meets the generation requirements in the test template;

[0011] All generated instruction machine codes are sent to the processor to be verified and the instruction simulator for execution respectively, and the execution log of each instruction is compared and analyzed.

[0012] Furthermore, the instruction machine code model includes:

[0013] The encoding formats supported by the instruction set architecture specification;

[0014] All fields contained in each encoding format, including the opcode field and the operand field;

[0015] The specific attributes of each field, including field category, field type, field least significant bit and field width;

[0016] The encoding format and field values ​​corresponding to each instruction.

[0017] Furthermore, the specific values ​​of the field include legal values ​​clearly defined in the instruction set architecture specification and reserved non-standard values.

[0018] Furthermore, the construction of the instruction machine code model according to the instruction set architecture specification includes:

[0019] Create a format type for each encoding format according to the instruction set architecture specification;

[0020] Under each format type, define field variables, including operation code field variables and operand field variables;

[0021] According to the specification, the encoding format, the determined value of the opcode field and the value range of the operand field are determined for each instruction. Further, the test template constructed based on the test scenario includes:

[0022] Defining instruction categories and specifying instruction generation requirements, wherein the generation requirements include generation requirements for specific instructions and field constraints thereof, and generation requirements for instructions of a specific category, the number of instructions, and field constraints thereof;

[0023] Among them, for a specific instruction, an instruction that satisfies the constraints in the template is generated;

[0024] For instructions of a specific category, a random instruction belonging to the specified category that satisfies the generation constraint is generated until the number of generated instructions meets the counting requirement.

[0025] Furthermore, the instruction category and instruction generation requirement based on the test template, generating the instruction machine code through the instruction machine code model includes:

[0026] Determine the number of instructions to be generated according to instruction generation requirements;

[0027] If the instruction generation requirement is a specific instruction, then the instruction machine code model corresponding to the instruction is selected;

[0028] Determine the value of the operand field in the instruction machine code model according to the field constraint conditions in the test template, and randomly assign values ​​to the unconstrained operand fields within the value range;

[0029] Combine the opcode field and the instruction encoding format to generate the corresponding category of instruction machine code.

[0030] Furthermore, the instruction category and instruction generation requirement based on the test template, generating the instruction machine code through the instruction machine code model also includes:

[0031] If the generation requirement is a specific instruction category, an instruction belonging to the category is randomly selected, and the instruction machine code model corresponding to the instruction is selected;

[0032] Determine the value of the operand field of the instruction machine code model according to the constraint conditions, and randomly assign values ​​to the unconstrained operand fields within the value range;

[0033] Combine the opcode field and the instruction encoding format to generate the corresponding category of instruction machine code.

[0034] Furthermore, the step of sending the generated instruction machine code to an instruction simulator for detection includes:

[0035] If the instruction machine code forms an infinite loop with the previously generated instruction machine code or the instruction machine code causes illegal access in the memory, the instruction machine code is determined to have failed the test, and the instruction machine code is regenerated and sent to the instruction simulator for testing; if the instruction machine code passes the test, the instruction machine code that passes the test is saved.

[0036] A second aspect of the present invention provides a computer device, including a memory and a processor, wherein the memory stores computer instructions, and the processor executes the dynamic instruction test sequence generation method as described in the first aspect above by executing the computer instructions.

[0037] A third aspect of the present invention provides a computer-readable storage medium storing computer instructions, wherein the computer instructions are executed by a computer to execute the method for generating a dynamic instruction test sequence as described in the first aspect.

[0038] Beneficial effects of the present invention:

[0039] The present invention is based on the instruction set specification, and constructs an instruction machine code model for generating instruction machine code according to the instruction set specification, and then uses a test template to drive the instruction machine code model to generate instruction machine code. Compared with the existing instruction test sequence generation method, the present invention improves the detection efficiency of processor design defects while ensuring that the generated instruction machine code sequence is semantically correct, and can comprehensively verify each module of the processor, and is suitable for various types of reduced instruction set computer (RISC) processors, and discovers unknown design defects in the processor in the pre-silicon stage. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 The figure is a flow chart of an embodiment of the method for generating an instruction test sequence according to the present invention. DETAILED DESCRIPTION

[0041] Embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as being limited to the embodiments set forth herein. On the contrary, these embodiments are provided to provide a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments of the present invention are only for exemplary purposes and are not intended to limit the scope of protection of the present invention.

[0042] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.

[0043] The embodiment of the present invention provides a method for generating a dynamic instruction test sequence based on instruction machine code, such as Figure 1 As shown, it includes the following steps:

[0044] Step 1: Build multiple instruction machine code models according to the instruction set architecture specification.

[0045] In one illustrative example, the instruction code table in the instruction set architecture specification is shown in the following table:

[0046]

[0047] Furthermore, the constructed instruction machine code model should include the following according to the instruction code table content:

[0048] The encoding formats supported by the RISC-V instruction set architecture specification include the R-type instruction format for register-register operations, the I-type instruction format for short immediate and memory access load operations, the S-type instruction format for memory access storage operations, the B-type instruction format for branch jump operations, the U-type instruction format for long immediate operations, and the J-type instruction format for unconditional jumps;

[0049] All fields contained in each encoding format, including the opcode field (opcode field, function code field), operand field (destination register field, source register 1 field, source register 2 field, immediate field);

[0050] The specific attributes contained in each field include field category, field type, field minimum significant bit and field width;

[0051] The encoding format and field values ​​corresponding to each instruction.

[0052] In one illustrated example, the instruction machine code model is constructed in the following manner:

[0053] First, a format type is created for each encoding format according to the instruction set architecture specification, and then under each format type, specific field variables are defined, including opcode field variables and operand field variables.

[0054] In this embodiment, taking the R-type encoding format instruction machine code model as an example, the func7 field is classified as an opcode field, the type is function code, the least significant bit is 25, and the width is 7; the func3 field is classified as an opcode field, the type is function code, the least significant bit is 12, and the width is 3; the opcode field is classified as an opcode field, the type is opcode, the least significant bit is 0, and the width is 7; the rs2 field is classified as an operand field, the type is register operand, the least significant bit is 20, and the width is 5; the rs1 field is classified as an operand field, the type is register operand, the least significant bit is 15, and the width is 5; the rd field is classified as an operand field, the type is register operand, the least significant bit is 7, and the width is 5.

[0055] As a preferred implementation, when constructing a specific instruction machine code model, its fields can be inherited from its corresponding instruction format, and then the value range for the operand field therein is determined, including legal values ​​clearly defined in the instruction set architecture specification and reserved non-standard values.

[0056] In this example, the add instruction belongs to the R class encoding format, inherits the operand field and opcode field of the R class encoding format and determines the value. The func7 field value is 0000000, the func3 field value is 000, the opcode field value is 0010011, and the rs2, rs1, and rd fields have value ranges from 0 to 31.

[0057] Step 2: Construct a test template based on the test scenario, wherein the test template includes the definition of the instruction category and the generation requirements of the instruction.

[0058] In an illustrative example, a test template for verifying a processor memory access module is constructed as follows:

[0059]

[0060] This test template defines the instruction category specific to the test scenario (Definition domain) and describes the instruction generation requirements (Insts domain), including the generation requirements for specific instructions and their field constraints, namely, the addi instruction generation requirements in Insts and the value constraints on the rd and imm fields; the generation requirements and instruction quantity of instructions belonging to a specific category, namely, the load instruction generation requirement under Insts and its generation quantity is 500.

[0061] The above test template can control the degree of randomness of the test from completely random to completely directed by constraining the fields, thereby constructing various test scenarios required to verify the test plan.

[0062] Specifically, for a specific instruction requirement, an instruction that satisfies the constraints in the template is generated. For an instruction requirement belonging to a specific category, an instruction that satisfies the generation constraints and belongs to the specified category is randomly generated until the number of generated instructions meets the counting requirement.

[0063] In this illustrated example, an addi instruction with a target register field of x1 and an immediate value field of 0x10 is generated; then 500 instructions are randomly selected from the instruction categories consisting of lb, lbu, lh, lhu and lw.

[0064] Step 3: Based on the instruction category and instruction generation requirements defined by the test template, generate instruction machine code through the instruction machine code model.

[0065] In an example, the above steps are implemented as follows:

[0066] Firstly, the instruction generation quantity is determined according to the instruction generation requirement to cyclically generate the required instructions; then, a specific instruction machine code model is selected according to the instruction generation requirement to generate the instruction machine code.

[0067] Specifically, if the generation requirement is for a specific instruction, the instruction machine code model corresponding to the instruction is selected, the value in the operand field in the instruction machine code model is determined according to the constraints in the test template, and the unconstrained fields are randomly assigned values ​​within the value range. Finally, the opcode field and the instruction encoding format are combined to generate a complete, semantically valid instruction machine code that conforms to the instruction set specification.

[0068] If the generation requirement is an instruction category, an instruction belonging to the specified category is randomly selected, and the instruction machine code model corresponding to the instruction is selected; then, the value in the operand field in the instruction machine code model is determined according to the constraints in the test template, and the unconstrained fields are randomly assigned values ​​within the value range; finally, a semantically valid instruction machine code of this category is generated by combining the opcode field value and the instruction encoding format.

[0069] Step 4: Send the generated instruction machine code to the instruction simulator for detection, and save the instruction machine code that passes the detection until the number of instruction machine codes generated meets the generation requirements in the test template.

[0070] Specifically, the instruction machine code obtained in step 3 is sent to the instruction simulator for detection. If the instruction machine code forms an infinite loop with the previously generated instruction machine code or the instruction machine code causes illegal access in the memory, it is considered that the instruction machine code has not passed the detection and is directly discarded, and re-enters step 3; if the instruction machine code passes the detection, the instruction machine code is saved, and the number of instruction machine codes generated is checked. If the number of generated instruction machine codes meets the generation requirements in the test template, enter step 5, otherwise enter step 3 again to continue generating instruction machine codes until the generated number meets the generation requirements.

[0071] Step 5: Send all generated instruction machine codes to the processor to be verified and the instruction simulator for execution respectively, compare and analyze the execution log of each instruction.

[0072] In order to verify the beneficial effects of the present invention, the method shown in the above embodiment is applied to Western Digital's RISC-V VeeR EH2 open source commercial processor, and the EH2 processor is tested, successfully detecting previously unknown decoding errors in the processor. At the same time, the test results show that the average time for the method of the present invention to generate 10,000 instructions is 20.34 seconds, and a functional coverage rate of 96.80% is achieved. Compared with the RISC-V mainstream verification methods RISC-V DV and RISC-V Torture, the method of the present invention reduces the number of instructions by 62.50% and 86.11% respectively while achieving the same functional coverage. In addition, the method of the present invention increases the final converged functional coverage by 3.19% and 8.99%, respectively.

[0073] The method of the present invention is based on instruction specifications, constructs an instruction machine code model according to the instruction specifications, and then drives instruction machine code generation with a test template. Compared with other mainstream test sequence generation schemes, it gets rid of the limitations of the assembler, reduces the storage overhead required for processor testing, and effectively improves the detection efficiency of processor design defects and the functional coverage of test sequences. It can comprehensively verify each module of the processor and promptly discover unknown design defects in the processor.

[0074] Another embodiment of the present invention further provides a computer device, including a memory and a processor, wherein the memory stores computer instructions, and the processor executes the dynamic instruction test sequence generation method disclosed in the above embodiment by executing the computer instructions.

[0075] Another embodiment of the present invention further provides a computer-readable storage medium, which stores computer instructions. When the computer instructions are executed by a computer, the dynamic instruction test sequence generation method disclosed in the above embodiment is executed.

[0076] It should be noted that the method of the embodiment of the present invention can be performed by a single device, such as a computer or a server. The method of this embodiment can also be applied in a distributed scenario and completed by multiple devices cooperating with each other. In the case of such a distributed scenario, one of the multiple devices can only perform one or more steps in the method of the embodiment of the present invention, and the multiple devices will interact with each other to complete the described method.

[0077] It should be noted that some embodiments of the present invention are described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the above embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0078] The embodiments of the present invention are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for generating a dynamic instruction test sequence based on instruction machine code, characterized in that: The steps include: Build multiple instruction machine code models based on instruction set architecture specifications; Building a test template based on the test scenario, wherein the test template includes a definition of an instruction category and a generation requirement of an instruction; Generate instruction machine code through instruction machine code model based on instruction category and instruction generation requirements defined by test template; Send the generated instruction machine code to the instruction simulator for detection, and save the instruction machine code that passes the detection until the number of instruction machine codes generated meets the generation requirements in the test template; All generated instruction machine codes are sent to the processor to be verified and the instruction simulator for execution respectively, and the execution log of each instruction is compared and analyzed.

2. The method for generating a dynamic instruction test sequence based on instruction machine code according to claim 1, characterized in that: The instruction machine code model includes: The encoding formats supported by the instruction set architecture specification; All fields contained in each encoding format, including the opcode field and the operand field; The specific attributes of each field, including field category, field type, field least significant bit, and field width; The encoding format and field values ​​corresponding to each instruction.

3. The method for generating a dynamic instruction test sequence based on instruction machine code according to claim 2, characterized in that: The specific values ​​of the field include legal values ​​clearly defined in the instruction set architecture specification and reserved non-standard values.

4. The method for generating a dynamic instruction test sequence based on instruction machine code according to claim 3, characterized in that: The construction of the instruction machine code model according to the instruction set architecture specification includes: Create a format type for each encoding format according to the instruction set architecture specification; Under each format type, define field variables, including operation code field variables and operand field variables; The encoding format, the value of the opcode field, and the value range of the operand field are determined for each instruction according to the specification.

5. The method for generating a dynamic instruction test sequence based on instruction machine code according to claim 4, characterized in that: The construction of a test template based on a test scenario includes: Defining instruction categories and specifying instruction generation requirements, wherein the generation requirements include generation requirements for specific instructions and field constraints thereof, and generation requirements for instructions of a specific category, the number of instructions, and field constraints thereof; Among them, for a specific instruction, an instruction that satisfies the constraints in the template is generated; For instructions of a specific category, a random instruction belonging to the specified category that satisfies the generation constraint is generated until the number of generated instructions meets the counting requirement.

6. The method for generating a dynamic instruction test sequence based on instruction machine code according to claim 5, characterized in that: The instruction category and instruction generation requirement based on the test template, generating instruction machine code through the instruction machine code model includes: Determine the number of instructions to be generated according to instruction generation requirements; If the instruction generation requirement is a specific instruction, then the instruction machine code model corresponding to the instruction is selected; Determine the value of the operand field in the instruction machine code model according to the field constraint conditions in the test template, and randomly assign values ​​to the unconstrained operand fields within the value range; Combine the opcode field and the instruction encoding format to generate the instruction machine code.

7. The method for generating a dynamic instruction test sequence based on instruction machine code according to claim 5, characterized in that: The instruction category and instruction generation requirement based on the test template, generating instruction machine code through the instruction machine code model includes: If the generation requirement is a specific instruction category, an instruction belonging to the category is randomly selected, and the instruction machine code model corresponding to the instruction is selected; Determine the value of the operand field of the instruction machine code model according to the constraint conditions, and randomly assign values ​​to the unconstrained operand fields within the value range; Combine the opcode field and the instruction encoding format to generate the corresponding category of instruction machine code.

8. The method for generating a dynamic instruction test sequence based on instruction machine code according to claim 1, characterized in that: The step of sending the generated instruction machine code to the instruction simulator for detection includes: If the instruction machine code forms an infinite loop with the previously generated instruction machine code or the instruction machine code causes illegal access in the memory, the instruction machine code is determined to have failed the test, and the instruction machine code is regenerated and sent to the instruction simulator for testing; if the instruction machine code passes the test, the instruction machine code that passes the test is saved.

9. A computer device, characterized in that: It comprises a memory and a processor, wherein the memory stores computer instructions, and the processor executes the dynamic instruction test sequence generation method according to any one of claims 1 to 8 by executing the computer instructions.

10. A computer-readable storage medium, characterized in that: The storage medium stores computer instructions, and the computer instructions are executed by a computer to execute the dynamic instruction test sequence generation method according to any one of claims 1 to 8.

Citation Information

Cited By

  • Invalid instruction generation method and device, electronic equipment and storage medium

    CN119861971A

  • Instruction generation method and device, equipment and storage medium

    CN119862828A