Instant number configuration method and device of jump instruction, equipment and storage medium
By classifying and collecting the instruction addresses in the instruction stream during the processor core verification stage, the immediate number of jump instructions of the immediate number is automatically calculated, which solves the problems of manual calculation accuracy and efficiency in the prior art, and realizes efficient and accurate immediate number calculation and jump instructions execution.
Patent Information
- Application Number
- CN202510449650.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-10
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2045-04-10
AI Technical Summary
The prior art relies on manual determination of the immediate number of jump instructions for immediate number in the processor core verification stage, resulting in low computational accuracy and efficiency.
By generating the instruction stream, an instruction address is generated for each instruction, and the address of the jump target instruction is added to the first address set, the address of the instant number jump instruction is added to the second address set, and the immediate number of the instant number jump instruction is calculated based on these address sets.
Automatic immediate number calculation is realized, reducing dependence on human resources, improving the accuracy and efficiency of immediate number calculation, and enabling immediate number jump instructions to jump to specified jump target instructions.
Smart Images

Figure CN119960830A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of integrated circuit technology, and in particular to a method, device, electronic device and computer-readable storage medium for configuring an immediate value of a jump instruction. Background Art
[0002] During the verification phase of the processor (CPU, Central Processing Unit) core, an instruction stream is generated by an instruction generator, and each instruction in the instruction stream is often used to verify the CPU module.
[0003] During the verification process, the instruction stream usually includes an immediate jump instruction. After the immediate jump instruction is generated, the jump address of the immediate jump instruction is calculated, and the instruction is jumped to the jump target instruction according to the jump address for execution. The relevant technology has the need to control the immediate jump instruction to jump to the specified jump target instruction. In order to achieve this requirement, a manual method is used to separately determine the value of the immediate number that each immediate jump instruction should have.
[0004] However, related technologies rely on manual implementation, resulting in low calculation accuracy and efficiency. Summary of the invention
[0005] The embodiments of the present application provide a method, device, electronic device and computer-readable storage medium for configuring an immediate value of a jump instruction to solve the problems in the related art.
[0006] In a first aspect, an embodiment of the present application provides a method for configuring an immediate value of a jump instruction, the method comprising: When generating an instruction stream, a corresponding instruction address is generated for each instruction generated; When the instruction belongs to a preset jump target instruction set, adding the instruction address of the instruction as the first address to the first address set; When the instruction is an immediate jump instruction, adding the instruction address of the instruction as the second address into the second address set; According to the first address set and the second address set, an immediate number is generated for the immediate number jump instruction corresponding to each second address in the second address set, so that when the immediate number jump instruction is subsequently executed, it jumps to the jump target instruction in the jump target instruction set based on the immediate number.
[0007] In a second aspect, an embodiment of the present application provides a device for configuring an immediate value of a jump instruction, the device comprising: A generation module, used for generating a corresponding instruction address for each instruction generated when generating an instruction stream; A first adding module, configured to add the instruction address of the instruction as the first address to the first address set when the instruction belongs to a preset jump target instruction set; A second adding module, used for adding the instruction address of the instruction as the second address into the second address set when the instruction is an immediate jump instruction; An immediate number module is used to generate an immediate number for the immediate number jump instruction corresponding to each second address in the second address set according to the first address set and the second address set, so that when the immediate number jump instruction is subsequently executed, it jumps to the jump target instruction in the jump target instruction set based on the immediate number.
[0008] In a third aspect, an embodiment of the present application further provides an electronic device, comprising a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the method of the first aspect.
[0009] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, which, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, enables the electronic device to execute the method of the first aspect.
[0010] In an embodiment of the present application, the generated instructions can be classified in the process of generating an instruction stream. If a jump target instruction is generated, the instruction address of the jump target instruction is added to the first address set as the first address; if an immediate jump instruction is generated, the instruction address of the immediate jump instruction is added to the second address set as the second address. Subsequently, based on the known second address set and the first address set, the correct value of the immediate number in each immediate jump instruction can be reversely calculated. The value of the immediate number can realize the requirement that each immediate jump instruction can jump to the jump target instruction in a directional manner. The entire process of the present application can be automated, reducing the dependence on human resources and improving the accuracy and efficiency of immediate number calculation.
[0011] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0013] Figure 1 It is a flowchart of the steps of a method for configuring an immediate value of a jump instruction provided by an embodiment of the present application; Figure 2 It is a flowchart of the specific steps of a method for configuring an immediate value of a jump instruction provided in an embodiment of the present application; Figure 3 It is a flow chart of an implementation method of an immediate value configuration method of a jump instruction provided in an embodiment of the present application; Figure 4 It is a block diagram of an immediate number configuration device for a jump instruction provided in an embodiment of the present application; Figure 5 is a block diagram of a first electronic device provided in an embodiment of the present application; Figure 6 This is a block diagram of a second electronic device according to another embodiment of the present application. DETAILED DESCRIPTION
[0014] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0015] The terms "first", "second", etc. in the specification of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally a class, and the number of objects is not limited, for example, the first object can be one or more. In addition, the term "and / or" in the specification is used to describe the association relationship of associated objects, indicating that three kinds of relationships can exist, for example, A and / or B can be represented: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally represents that the associated objects before and after are a kind of "or" relationship. In the embodiment of the present application, the term "multiple" refers to two or more, and other quantifiers are similar.
[0016] Figure 1is a flowchart of the steps of a method for configuring an immediate value of a jump instruction provided by an embodiment of the present application, such as Figure 1 As shown, the method may include: Step 101: When generating an instruction stream, a corresponding instruction address is generated for each instruction generated.
[0017] In an embodiment of the present application, for the core verification of the CPU, it is necessary to generate an instruction stream through an instruction generator to simulate and verify the functions of the CPU by executing each instruction in the instruction stream. Each instruction in the instruction stream is an instruction in the instruction set of the processor, for example, it can be an addition instruction, a subtraction instruction, a write instruction, a read instruction, a jump instruction, and other instructions.
[0018] Among them, the instruction address of the instruction is the base address, which is the address assigned to the instruction in the process of generating the instruction. The instruction address is used to indicate the storage location of the instruction in the memory. When executing the program, the CPU will use the program counter to store the instruction address of the next instruction to be executed.
[0019] Specifically, the instructions contained in the instruction stream are sequentially stored and maintained in the memory according to the order in which the instructions are generated, and a corresponding number is set for each instruction according to the order in which each instruction is generated, that is, the instruction numbers are also arranged in sequence. In addition, each instruction occupies a fixed bit width. Based on this characteristic, the embodiment of the present application can determine the instruction address of the instruction based on the instruction number and the preset bit width, thereby realizing the generation and maintenance of the instruction address of the instruction by the instruction stream.
[0020] Step 102: When the instruction belongs to a preset jump target instruction set, add the instruction address of the instruction as a first address to a first address set.
[0021] In the embodiment of the present application, the jump target instruction refers to the instruction to which the immediate jump instruction is expected to jump based on the verification requirements. For example, assuming that it is expected that an immediate jump instruction can jump to the addition instruction (ADD) for further execution when executed, then the addition instruction is the jump target instruction of the immediate jump instruction.
[0022] In the verification scenario of the embodiment of the present application, specifying a jump target instruction for an immediate jump instruction can increase the controllability and directionality of the verification, so that the verification requirements can be completed in a targeted manner.
[0023] It should be noted that the jump target instruction set can be preset in advance according to the verification requirements. When the instruction generated by the instruction stream is in the jump target instruction set, the instruction can be used as the jump target instruction, and its instruction address can be added to the first address set as the first address, that is, the first address set stores the instruction address of the jump target instruction generated in the instruction stream.
[0024] Step 103: When the instruction is an immediate jump instruction, add the instruction address of the instruction as the second address into the second address set.
[0025] For example, the jump instruction generated in the instruction stream can be an immediate jump instruction, that is, an immediate-addressed jump instruction, and the jump address of the jump instruction is the sum of the instruction address and the address offset of the jump instruction. In an immediate jump instruction with immediate addressing, the instruction includes an immediate number, and the immediate number is used to represent the address offset of the jump address. In addition, in a register-addressed jump instruction, the jump instruction includes a register identifier and an immediate number, and the address stored in the register represented by the register identifier is the instruction address of the jump instruction.
[0026] In an embodiment of the present application, an immediate jump instruction set can be preset in advance according to verification requirements. When the instruction generated by the instruction stream is in the immediate jump instruction set, the instruction can be used as an immediate jump instruction, and its instruction address can be added to the second address set as the second address, that is, the second address set stores the instruction addresses of the immediate jump instructions generated in the instruction stream.
[0027] It should be noted that when it is determined that an instruction generated by the instruction stream is an immediate jump instruction, the immediate value of the instruction may not be assigned a value first, that is, the immediate value may be set to null first.
[0028] For example, assuming that an immediate jump instruction set is preset in advance, including two immediate jump instructions {JPI, BRI}, when the instruction generated by the subsequent instruction stream is a JPI instruction or a BRI instruction, it is confirmed that the generated instruction is an immediate jump instruction.
[0029] Step 104, based on the first address set and the second address set, generates an immediate number for the immediate number jump instruction corresponding to each second address in the second address set, so that when the immediate number jump instruction is subsequently executed, it jumps to the jump target instruction in the jump target instruction set based on the immediate number.
[0030] In an embodiment of the present application, the first address set stores the instruction addresses of the jump target instructions generated in the instruction stream, and the second address set stores the instruction addresses of the immediate jump instructions generated in the instruction stream. In order to achieve the requirement that each immediate jump instruction can jump to the jump target instruction in a directed manner, the embodiment of the present application needs to assign a value to the immediate number of the immediate jump instruction, so that the immediate jump instruction can jump to the jump target instruction based on the instruction address and the assigned immediate number.
[0031] That is, the embodiment of the present application can reversely calculate the value of the immediate number in each immediate jump instruction based on the known second address set (the starting point of the jump) and the first address set (the destination of the jump), thereby realizing the requirement that each immediate jump instruction can jump to the jump target instruction in a directed manner.
[0032] In summary, in the embodiment of the present application, the generated instructions can be classified in the process of generating the instruction stream. If a jump target instruction is generated, the instruction address of the jump target instruction is added to the first address set as the first address; if an immediate jump instruction is generated, the instruction address of the immediate jump instruction is added to the second address set as the second address. Subsequently, based on the known second address set and the first address set, the correct value of the immediate number in each immediate jump instruction can be calculated in reverse, and the value of the immediate number can realize the requirement that each immediate jump instruction can jump to the jump target instruction in a directional manner. The entire process of the present application can be automated, reducing the dependence on human resources and improving the accuracy and efficiency of immediate number calculation.
[0033] Figure 2 is a flowchart of the specific steps of a method for configuring an immediate value of a jump instruction provided in an embodiment of the present application, such as Figure 2 As shown, the method may include: Step 201: Set a corresponding number for each instruction according to the generation order of each instruction.
[0034] Step 202: Calculate the instruction address of the instruction according to the instruction number and the preset bit width; the preset bit width is the size occupied by one instruction.
[0035] In the embodiment of the present application, for steps 201-202, in the process of generating an instruction stream, each instruction generated can be numbered according to the order in which the instruction is generated, that is, the instruction numbers in the instruction stream are arranged in order, and the instruction numbers can not only identify the instructions, but also describe the order in which the instructions are generated. In addition, each instruction occupies a fixed bit width, so based on this characteristic, the embodiment of the present application can determine the instruction address of the instruction based on the product of the instruction number and the preset bit width, so as to realize the generation and maintenance of the instruction address of the instruction by the instruction stream.
[0036] For example, the following Table 1 shows 20 instructions generated sequentially in an instruction stream:
[0037] Table 1 In Table 1 above, the instruction stream randomly generates instructions from the following instruction set: RAND_GEN_INST_SET={ADD,SUB,MUL,DIV,SLLI,JPI,BRI}; Among them, the sequence number is the instruction number, and the instruction number increases according to the order in which the instructions are generated, and the value of each increase is 1. For example, the first instruction ADD generated is numbered 1, the second instruction MUL generated is numbered 2, and the third instruction JPL generated is numbered 3... In addition, in the instruction stream containing 20 instructions, the addresses of two adjacent instructions differ by 4, which is preset before generating the instruction stream, that is, the preset bit width is 4. Specifically, the instruction address of the instruction = (instruction number-1) × preset bit width. That is, the instruction address of the first instruction ADD generated = (1-1) × 4 = 0, the instruction address of the second instruction MUL generated = (2-1) × 4 = 8, and the instruction address of the third instruction JPL generated = (3-1) × 4 = 12... In this way, the instruction address of each instruction can be obtained, and the instruction addresses of the instructions are arranged with a difference of 4 between adjacent ones, which meets the setting requirements of the instruction stream.
[0038] Step 203: When the instruction belongs to a preset jump target instruction set, add the instruction address of the instruction as the first address to the first address set.
[0039] This step may specifically refer to the above step 102, which will not be described in detail here.
[0040] Step 204: Obtain a preset set of immediate jump instructions.
[0041] Step 205: When the instruction belongs to the immediate jump instruction set, determine that the instruction is an immediate jump instruction, and add the instruction address of the instruction as the second address into the second address set.
[0042] In the embodiment of the present application, for steps 204-205, an immediate jump instruction set can be preset in advance according to the verification requirements, and when the instruction generated by the instruction stream is in the immediate jump instruction set, the instruction can be used as an immediate jump instruction. The embodiment of the present application does not specifically limit which immediate jump instructions are included in the immediate jump instruction set.
[0043] For example, for the above Table 1, assuming that an immediate jump instruction set {JPI, BRI} is preset in advance, when the instruction generated by the subsequent instruction stream is a JPI instruction or a BRI instruction, the generated instruction is confirmed to be an immediate jump instruction, and the instruction address 8 of the JPI instruction and the instruction address 28 of the BRI instruction are added to the second address set.
[0044] Step 206: Calculate the offset address of the immediate jump instruction corresponding to each second address in the second address set.
[0045] The offset address reflects the address deviation between the instruction address of the immediate jump instruction and the first address of a jump target instruction in the first address set.
[0046] Step 207: Calculate the immediate value of the immediate value jump instruction based on the offset address and an immediate value calculation method that matches the type of the immediate value jump instruction.
[0047] In the embodiment of the present application, for steps 206-207, since each instruction in the instruction stream is generated in sequence and the difference between the instruction addresses of two adjacent instructions is a fixed value, the storage of the instructions in the instruction stream in the memory is regular. Based on this regularity, in the process of implementing an immediate jump instruction to accurately jump to a corresponding jump target instruction, the address deviation of the immediate jump instruction relative to the jump target instruction (the jump target instruction can be a jump target instruction specified in the second address set, or a jump target instruction randomly selected from the second address set) can be calculated first, and the address deviation can be used as the offset address of the immediate jump instruction.
[0048] After determining the offset address of the instruction address of the immediate jump instruction compared to the instruction address of the jump target instruction, that is, determining the interval distance between the instruction address of the immediate jump instruction and the instruction address of the jump target instruction in the instruction stream, since the immediate number reflects the address deviation between the immediate jump instruction and the jump target instruction, the correct immediate number can be calculated based on the offset address of the immediate jump instruction and the immediate number calculation method that matches the type of the immediate jump instruction, so that the immediate jump instruction can be accurately jumped to the jump target instruction through the immediate number, realizing the need to specify the jump target instruction for the immediate jump instruction, and increasing the controllability and directionality of verification. Among them, each type of immediate jump instruction has a corresponding immediate number calculation method, and different types of immediate jump instructions have different immediate number calculation methods.
[0049] Optionally, step 206 may specifically include sub-steps 2061-2062: Sub-step 2061: For each immediate jump instruction corresponding to the second address in the second address set, randomly select a target first address from the first address set.
[0050] Sub-step 2062: Calculate the difference between the target first address and the second address, and use the difference as the offset address of the immediate jump instruction corresponding to the second address.
[0051] In the embodiment of the present application, for sub-steps 2061-2062, since the requirement for the immediate jump instruction is that it can jump to the jump target instruction set, when calculating the immediate number of the immediate jump instruction, a target first address can be quickly selected from the first address set (maintaining the address of the jump target instruction) as the jump object, and then the difference between the target first address and the second address of the immediate jump instruction is calculated, and the difference is used as the offset address of the immediate jump instruction. The difference can reflect the address deviation between the immediate jump instruction and the jump target instruction, and the subsequent immediate number can be calculated based on the address deviation.
[0052] For example, for the above Table 1, the first address set obtained is: JUMP_TARGET_ADDR_SET={0,16,32,40,64,72} The second address set obtained is: JUMP_ADDR_SET={8,28,56} For the immediate jump instruction JPI with instruction address 8 in the second address set, assuming that the jump target instruction DIV with instruction address 64 is randomly selected from the first address set, the offset address of the immediate jump instruction JPI = 64-8 = 56, and the offset address 56 reflects that the address deviation between the immediate jump instruction JPI and the jump target instruction DIV is 56.
[0053] Optionally, the immediate number calculation method includes: immediate number=offset address / preset coefficient; the value of the preset coefficient in different immediate number calculation methods is different; step 207 may specifically include sub-step 2071: Sub-step 2071: use the offset address and the ratio of a preset coefficient in an immediate number calculation method that matches the type of the immediate number jump instruction as the immediate number of the immediate number jump instruction.
[0054] In an embodiment of the present application, when the offset address is calculated and the immediate number is further calculated, the immediate number can be calculated in the manner of immediate number = offset address / preset coefficient, wherein different types of immediate number jump instructions correspond to different immediate number calculation methods, and the values of the preset coefficients in different immediate number calculation methods are different, and the embodiment of the present application does not make any specific limitations on this.
[0055] For example, for the above Table 1, the 1st, 5th, 9th, 11th, 17th, and 19th instructions are all instructions in the jump target instruction set, and the first address set obtained is: JUMP_TARGET_ADDR_SET={0,16,32,40,64,72}; The 3rd, 8th and 15th instructions are all immediate jump instructions, so the second address set is: JUMP_ADDR_SET={8,28,56}; Assume that the calculation method of the immediate value of the immediate value jump instruction JPI is: offset address = immediate value × 4; the calculation method of the immediate value of the immediate value jump instruction BRI is: offset address = immediate value × 2.
[0056] When the first address 8 in the second address set is selected, the immediate jump instruction JPI corresponding to the address is found in the instruction stream. Assuming that the address 64 is randomly selected from the first address set, the offset address of the JPI instruction is 64-8=56, and the corresponding immediate value of the JPI instruction can be calculated to be 56 / 4=14, so the immediate value of the JPI instruction is 14.
[0057] When the second address 28 in the second address set is selected, the immediate jump instruction BRI corresponding to the address is found in the instruction stream. Assuming that the address 72 is randomly selected from the first address set, the offset address of the JPI instruction is 72-28=44, and the corresponding immediate value of the BRI instruction can be calculated to be 44 / 2=22, so the immediate value of the BRI instruction is 22.
[0058] When the third address 56 in the second address set is selected, the immediate jump instruction JPI corresponding to the address is found in the instruction stream. Assuming that the address 16 is randomly selected from the first address set, the offset address of the JPI instruction is 16-56=-40, and the corresponding immediate value of the JPI instruction can be calculated to be -40 / 4=-10, so the immediate value of the JPI instruction is -10.
[0059] After the above steps, the immediate values of the three immediate jump instructions in the instruction stream are generated. When the instruction stream is subsequently executed, it can be achieved that: the immediate jump instruction JPI with address 8 jumps to the jump target instruction DIV with address 64, the immediate jump instruction BRI with address 28 jumps to the jump target instruction ADD with address 72, and the immediate jump instruction JPI with address 56 jumps to the jump target instruction DIV with address 16, thereby achieving the purpose of the immediate jump instruction jumping to the specified jump target instruction set.
[0060] Optionally, the jump target instruction corresponding to each of the immediate jump instructions is in the same instruction set; the instruction address of the jump target instruction is in the second address set; Or, the jump target instructions corresponding to the different immediate jump instructions are in different instruction sets.
[0061] In an embodiment of the present application, the jump target instructions corresponding to each immediate jump instruction are in the same instruction set. In this way, the specified jump of the immediate jump instruction can be implemented by setting only one jump target instruction set, thereby reducing the operation complexity and improving the verification efficiency.
[0062] In addition, the embodiment of the present application can also be configured: the jump target instructions corresponding to different immediate jump instructions are placed in different instruction sets, respectively, so that the jump object of each immediate jump instruction can be individually constrained, further improving the directionality of the verification and being more accurate when reproducing the problem.
[0063] Reference Figure 3 , which shows a flowchart of the implementation method of the immediate value configuration method of the jump instruction in the embodiment of the present application, including: S1. Set the jump target instruction set.
[0064] S2. Set a jump target instruction address set (second address set) and an immediate jump instruction address set (first address set), and initialize them to an empty set.
[0065] S3. Generate instructions randomly, and do not generate immediate data for immediate jump instructions.
[0066] S4, determine whether the generated instruction is an immediate jump instruction; if so, execute S5, add the address of the instruction to the immediate jump instruction address set.
[0067] S6, determine whether the generated instruction belongs to the jump target instruction set; if so, execute S7, add the address of the instruction to the jump target instruction address set.
[0068] S8. All instructions are generated.
[0069] S9. Generate an immediate value for the instruction corresponding to the i-th address in the immediate jump instruction address set, where the initial value of i is 1.
[0070] S10. Randomly select an address from the jump target instruction address set.
[0071] S11. Calculate the difference between the random address and the address of the immediate jump instruction as the offset address.
[0072] S12. Calculate the immediate value according to the offset address.
[0073] S13, determine whether i is less than or equal to the total number of elements in the immediate jump instruction address set.
[0074] If not, add 1 to i and go to step S9.
[0075] If so, generation is complete.
[0076] In summary, in the embodiment of the present application, the generated instructions can be classified in the process of generating the instruction stream. If a jump target instruction is generated, the instruction address of the jump target instruction is added to the first address set as the first address; if an immediate jump instruction is generated, the instruction address of the immediate jump instruction is added to the second address set as the second address. Subsequently, based on the known second address set and the first address set, the correct value of the immediate number in each immediate jump instruction can be calculated in reverse, and the value of the immediate number can realize the requirement that each immediate jump instruction can jump to the jump target instruction in a directional manner. The entire process of the present application can be automated, reducing the dependence on human resources and improving the accuracy and efficiency of immediate number calculation.
[0077] Figure 4 : is a block diagram of an immediate value configuration device for a jump instruction provided in an embodiment of the present application, the device comprising: A generating module 301, used for generating a corresponding instruction address for each instruction generated when generating an instruction stream; A first adding module 302, configured to add the instruction address of the instruction as the first address to the first address set when the instruction belongs to a preset jump target instruction set; A second adding module 303, configured to add the instruction address of the instruction as the second address into the second address set when the instruction is an immediate jump instruction; The immediate number module 304 is used to generate an immediate number for the immediate number jump instruction corresponding to each second address in the second address set according to the first address set and the second address set, so that when the immediate number jump instruction is subsequently executed, it jumps to the jump target instruction in the jump target instruction set based on the immediate number.
[0078] Optionally, the generating module 301 includes: The numbering submodule is used to set a corresponding number for each instruction according to the generation order of each instruction; The first calculation submodule is used to calculate the instruction address of the instruction according to the instruction number and the preset bit width; the preset bit width is the occupied size of one instruction.
[0079] Optionally, the second adding module 303 includes: An acquisition submodule is used to acquire a preset set of immediate jump instructions; The determination submodule is used to determine that the instruction is an immediate jump instruction when the instruction belongs to the immediate jump instruction set, and add the instruction address of the instruction as the second address into the second address set.
[0080] Optionally, the immediate number module 304 includes: A second calculation submodule is used to calculate the offset address of the immediate jump instruction corresponding to each second address in the second address set; the offset address reflects the address deviation between the instruction address of the immediate jump instruction and the first address of a jump target instruction in the first address set; The third calculation submodule is used to calculate the immediate value of the immediate value jump instruction based on the offset address and an immediate value calculation method that matches the type of the immediate value jump instruction.
[0081] Optionally, the second computing submodule includes: A selection unit, configured to randomly select a target first address from the first address set for an immediate jump instruction corresponding to each second address in the second address set; A difference calculation unit is used to calculate the difference between the target first address and the second address, and use the difference as the offset address of the immediate jump instruction corresponding to the second address.
[0082] Optionally, the immediate number calculation method includes: immediate number=offset address / preset coefficient; the value of the preset coefficient in different immediate number calculation methods is different; The third computing submodule includes: The ratio calculation unit is used to use the ratio of the offset address to a preset coefficient in an immediate number calculation method that matches the type of the immediate number jump instruction as the immediate number of the immediate number jump instruction.
[0083] Optionally, the jump target instruction corresponding to each of the immediate jump instructions is in the same instruction set; the instruction address of the jump target instruction is in the second address set; Or, the jump target instructions corresponding to the different immediate jump instructions are in different instruction sets.
[0084] In summary, in the embodiment of the present application, the generated instructions can be classified in the process of generating the instruction stream. If a jump target instruction is generated, the instruction address of the jump target instruction is added to the first address set as the first address; if an immediate jump instruction is generated, the instruction address of the immediate jump instruction is added to the second address set as the second address. Subsequently, based on the known second address set and the first address set, the correct value of the immediate number in each immediate jump instruction can be calculated in reverse, and the value of the immediate number can realize the requirement that each immediate jump instruction can jump to the jump target instruction in a directional manner. The entire process of the present application can be automated, reducing the dependence on human resources and improving the accuracy and efficiency of immediate number calculation.
[0085] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0086] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0087] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0088] An embodiment of the present application provides an immediate value configuration device for a jump instruction, including a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors to include methods for performing one or more of the methods described in the above-mentioned embodiments.
[0089] Figure 5 4 is a block diagram of a first electronic device 400 according to an exemplary embodiment. For example, the first electronic device 400 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0090] Reference Figure 5 The first electronic device 400 may include one or more of the following components: a processing component 402 , a first memory 404 , a power component 406 , a multimedia component 408 , an audio component 410 , an input / output (I / O) interface 412 , a sensor component 414 , and a communication component 416 .
[0091] The processing component 402 generally controls the overall operation of the first electronic device 400, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 402 may include one or more processors 420 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 402 may include one or more modules to facilitate the interaction between the processing component 402 and other components. For example, the processing component 402 may include a multimedia module to facilitate the interaction between the multimedia component 408 and the processing component 402.
[0092] The first memory 404 is used to store various types of data to support the operation of the first electronic device 400. Examples of such data include instructions for any application or method operating on the first electronic device 400, contact data, phone book data, messages, pictures, multimedia, etc. The first memory 404 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0093] The power supply component 406 provides power to various components of the first electronic device 400. The power supply component 406 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the first electronic device 400.
[0094] The multimedia component 408 includes a screen that provides an output interface between the first electronic device 400 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the demarcation of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 408 includes a front camera and / or a rear camera. When the first electronic device 400 is in an operating mode, such as a shooting mode or a multimedia mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and the rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0095] The audio component 410 is used to output and / or input audio signals. For example, the audio component 410 includes a microphone (MIC), and when the first electronic device 400 is in an operation mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is used to receive an external audio signal. The received audio signal can be further stored in the first memory 404 or sent via the communication component 416. In some embodiments, the audio component 410 also includes a speaker for outputting audio signals.
[0096] I / O interface 412 provides an interface between processing component 402 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0097] The sensor assembly 414 includes one or more sensors for providing various aspects of status assessment for the first electronic device 400. For example, the sensor assembly 414 can detect the open / closed state of the first electronic device 400, the relative positioning of components, such as the display and keypad of the first electronic device 400, and the sensor assembly 414 can also detect the position change of the first electronic device 400 or a component of the first electronic device 400, the presence or absence of user contact with the first electronic device 400, the orientation or acceleration / deceleration of the first electronic device 400, and the temperature change of the first electronic device 400. The sensor assembly 414 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 414 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 414 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0098] The communication component 416 is used to facilitate wired or wireless communication between the first electronic device 400 and other devices. The first electronic device 400 can access a wireless network based on a communication standard, such as WiFi, an operator network (such as 2G, 3G, 4G or 5G), or a combination thereof. In an exemplary embodiment, the communication component 416 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 416 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0099] In an exemplary embodiment, the first electronic device 400 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to implement the methods provided in the embodiments of the present application.
[0100] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a first memory 404 including instructions, and the instructions can be executed by a processor 420 of the first electronic device 400 to complete the above method. For example, the non-transitory storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0101] Figure 6 is a block diagram of a second electronic device 500 according to an exemplary embodiment. For example, the second electronic device 500 may be provided as a server. Figure 6 , the second electronic device 500 includes a processing component 522, which further includes one or more processors, and a memory resource represented by a second memory 532, for storing instructions that can be executed by the processing component 522, such as an application. The application stored in the second memory 532 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 522 is configured to execute instructions to perform the method provided in the embodiment of the present application.
[0102] The second electronic device 500 may further include a power supply component 526 configured to perform power management of the second electronic device 500, a wired or wireless network interface 550 configured to connect the second electronic device 500 to a network, and an input / output (I / O) interface 558. The second electronic device 500 may operate based on an operating system stored in the second memory 532, such as Windows Server TM, Mac OS X TM, Unix TM, Linux TM, FreeBSD TM or the like.
[0103] An embodiment of the present application further provides a computer program product, including a computer program, which implements the method described in the above embodiment when executed by a processor.
[0104] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the application disclosed herein. The present application is intended to cover any variation, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only.
[0105] It should be understood that the present application is not limited to the exact construction that has been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof.
Claims
1. A method for configuring an immediate value of a jump instruction, characterized in that: The method comprises: When generating an instruction stream, a corresponding instruction address is generated for each instruction generated; When the instruction belongs to a preset jump target instruction set, adding the instruction address of the instruction as the first address to the first address set; When the instruction is an immediate jump instruction, adding the instruction address of the instruction as the second address into the second address set; According to the first address set and the second address set, an immediate number is generated for the immediate number jump instruction corresponding to each second address in the second address set, so that when the immediate number jump instruction is subsequently executed, it jumps to the jump target instruction in the jump target instruction set based on the immediate number.
2. The method according to claim 1, characterized in that When generating the instruction stream, generating a corresponding instruction address for each instruction generated includes: According to the generation order of each instruction, set a corresponding number for each instruction; The instruction address of the instruction is calculated according to the instruction number and the preset bit width; the preset bit width is the occupied size of one instruction.
3. The method according to claim 1, characterized in that When the instruction is an immediate jump instruction, adding the instruction address of the instruction as the second address into the second address set includes: Get the preset immediate jump instruction set; When the instruction belongs to the immediate jump instruction set, the instruction is determined to be an immediate jump instruction, and the instruction address of the instruction is added into the second address set as the second address.
4. The method according to claim 1, characterized in that: The step of generating an immediate value for an immediate value jump instruction corresponding to each second address in the second address set according to the first address set and the second address set includes: Calculating an offset address of an immediate jump instruction corresponding to each second address in the second address set; the offset address reflects an address deviation between the instruction address of the immediate jump instruction and a first address of a jump target instruction in the first address set; The immediate value of the immediate value jump instruction is calculated based on the offset address and an immediate value calculation method that matches the type of the immediate value jump instruction.
5. The method according to claim 4, characterized in that The calculating the offset address of the immediate jump instruction corresponding to each second address in the second address set includes: For each immediate jump instruction corresponding to the second address in the second address set, randomly select a target first address from the first address set; The difference between the target first address and the second address is calculated, and the difference is used as the offset address of the immediate jump instruction corresponding to the second address.
6. The method according to claim 4, characterized in that The immediate number calculation method includes: immediate number = offset address / preset coefficient; the value of the preset coefficient in different immediate number calculation methods is different; The calculating the immediate value of the immediate value jump instruction based on the offset address and the immediate value calculation method matching the type of the immediate value jump instruction includes: The offset address and the ratio of the preset coefficient in the immediate value calculation method matching the type of the immediate value jump instruction are used as the immediate value of the immediate value jump instruction.
7. The method according to claim 1, characterized in that The jump target instructions corresponding to each of the immediate jump instructions are in the same instruction set; the instruction addresses of the jump target instructions are in the second address set; Or, the jump target instructions corresponding to the different immediate jump instructions are in different instruction sets.
8. A device for configuring an immediate value of a jump instruction, characterized in that: The device comprises: A generation module, used for generating a corresponding instruction address for each instruction generated when generating an instruction stream; A first adding module, configured to add the instruction address of the instruction as the first address to the first address set when the instruction belongs to a preset jump target instruction set; A second adding module, used for adding the instruction address of the instruction as the second address into the second address set when the instruction is an immediate jump instruction; An immediate number module is used to generate an immediate number for the immediate number jump instruction corresponding to each second address in the second address set according to the first address set and the second address set, so that when the immediate number jump instruction is subsequently executed, it jumps to the jump target instruction in the jump target instruction set based on the immediate number.
9. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the method as claimed in any one of claims 1 to 7.
Citation Information
Patent Citations
Instruction recombining method and device
CN103677746A
Non-immediate address jump protection method and corresponding computing device
CN110597571A
Test program generation method and device, equipment and readable storage medium
CN115017053A
Optimization method and device of jump instruction, jump method and device of instruction and electronic equipment
CN116627502A
AVX instruction simulation execution optimization method based on cyclic dependency analysis
CN119473394A