Instruction decoding method, device, electronic device and readable medium
By presetting pattern matching code and instruction type format, hexadecimal instructions in the CPU verification process are identified and parsed, which solves the problem of difficult instruction decoding, and realizes convenient acquisition of instruction detailed information, improving verification efficiency.
Patent Information
- Application Number
- CN202411116860.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-14
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2044-08-14
AI Technical Summary
During the CPU verification process, the verification engineer cannot directly obtain the detailed information of the instruction from the instruction signal represented by the hexadecimal system, which leads to difficulty in decoding operations.
The preset pattern matching code recognizes the instructions to be decoded, determines their instruction name, type and operand information, defines the operand bit field in combination with the format of the instruction type, and outputs the decoding result to obtain detailed information of the instruction.
It realizes convenient and intuitive decoding of decoded instructions, provides detailed information on instruction names, types and operands, and improves users' understanding of instruction execution logic and problem positioning efficiency.
Smart Images

Figure CN118626147B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an instruction decoding method, device, electronic equipment and readable medium. Background Art
[0002] At present, with the continuous development of computer technology, there are more and more scenarios that require instruction decoding. For example, during the verification of the central protocol unit (CPU), if an instruction flow fails, the verification engineer usually needs to track the execution path of the instruction through the dump waveform. However, all signals in the waveform are represented in hexadecimal. The verification engineer can only see the hexadecimal representation of the instruction and cannot obtain more detailed instruction information of the instruction.
[0003] Therefore, how to implement the decoding operation of the instruction to obtain the instruction information of the instruction has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] The embodiments of the present invention provide an instruction decoding method, device, electronic device and readable medium, which can implement a decoding operation on an instruction to obtain instruction information of the instruction.
[0005] In order to solve the above problem, an embodiment of the present invention discloses an instruction decoding method, the method comprising:
[0006] Based on the preset pattern matching codes of each instruction, a pattern matching code matching the instruction to be decoded is identified as a target matching code; the pattern matching code of the instruction is used to represent the operation code and other fixed contents of the instruction;
[0007] Based on the instruction related information pre-associated with the target matching code, determining the instruction name, instruction type and operand type of the instruction to be decoded; the pattern matching code of each instruction is pre-associated with the instruction related information of each instruction;
[0008] Determine the operand indicator and operand content of the operand based on the operand bit field defined in the type format of the instruction type of the instruction to be decoded;
[0009] An instruction decoding result is output based on the instruction name, the instruction type, the operand type of the operand, the operand indicator and the operand content.
[0010] On the other hand, an embodiment of the present invention discloses an instruction decoding device, the device comprising:
[0011] An identification module, used for identifying a pattern matching code matching the instruction to be decoded based on the preset pattern matching codes of each instruction as a target matching code; the pattern matching code of the instruction is used to represent the operation code and other fixed contents of the instruction;
[0012] A first determination module is used to determine the instruction name, instruction type and operand type of the instruction to be decoded based on the instruction related information pre-associated with the target matching code; the pattern matching code of each instruction is pre-associated with the instruction related information of each instruction;
[0013] A second determination module is used to determine the operand indicator and operand content of the operand based on the operand bit field defined in the type format of the instruction type of the instruction to be decoded;
[0014] The first output module is used to output the instruction decoding result based on the instruction name, the instruction type, the operand type of the operand, the operand indicator and the operand content.
[0015] On the other hand, an embodiment of the present invention discloses an electronic device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store executable instructions, and the executable instructions enable the processor to execute the aforementioned method.
[0016] The embodiment of the present invention further discloses a machine-readable medium on which instructions are stored. When executed by one or more processors, the processors are enabled to execute the method described above.
[0017] The embodiment of the present invention includes the following advantages: In the instruction decoding method provided in the embodiment of the present invention, based on the preset pattern matching code of each instruction, the pattern matching code matching the instruction to be decoded is identified as the target matching code; the pattern matching code of the instruction is used to characterize the operation code and other fixed contents of the instruction. Then, based on the instruction related information pre-associated with the target matching code, the instruction name, instruction type and operand type of the instruction to be decoded are determined; the pattern matching code of each instruction is pre-associated with the instruction related information of each instruction. Then, based on the operand bit field defined in the type format of the instruction type of the instruction to be decoded, the operand indicator and operand content of the operand are determined. Based on the instruction name, instruction type, operand type, operand indicator and operand content of the operand, the instruction decoding result is output. In this way, the decoding operation of the instruction to be decoded is realized, and at the same time, by obtaining the instruction name, instruction type and operand indicator and operand content of the instruction to be decoded, the instruction decoding result is output, providing more convenient and intuitive instruction information, so that the user can more conveniently and intuitively know the detailed instruction information of the instruction based on the instruction decoding result. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0019] Figure 1 is a flowchart of a method for decoding instructions provided by an embodiment of the present invention;
[0020] Figure 2 It is a schematic diagram of the instruction format of a part of instructions provided by an embodiment of the present invention;
[0021] Figure 3 is a schematic diagram of a type of format and special instructions provided by an embodiment of the present invention;
[0022] Figure 4 is a block diagram of an instruction decoding device provided by an embodiment of the present invention;
[0023] Figure 5 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0024] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0025] Reference Figure 1 , shows a flowchart of the steps of an instruction decoding method provided by an embodiment of the present invention, such as Figure 1 As shown, the method may specifically include the following steps:
[0026] Step 101: Based on the preset pattern matching codes of each instruction, identify the pattern matching code that matches the instruction to be decoded as the target matching code; the pattern matching code of the instruction is used to represent the operation code and other fixed content of the instruction.
[0027] In an embodiment of the present invention, the instruction to be decoded may be an instruction that needs to be decoded, and the instruction to be decoded may be an instruction in binary form or an instruction in hexadecimal form, and the embodiment of the present invention does not limit this. In the CPU verification process, the instruction corresponding to the abnormal waveform can be obtained as the instruction to be decoded. In this way, by decoding the instruction to be decoded, the verification engineer can easily obtain the detailed information of the instruction corresponding to the abnormal waveform. The instruction to be decoded may also be actively input by the user as needed, and accordingly, the instruction input by the user can be received as the instruction to be decoded.
[0028] The pattern matching code may be pre-set for instructions in the instruction architecture. Exemplarily, for each instruction defined in the instruction architecture, a pattern matching code may be set accordingly. The pattern matching codes for different types of instructions are different. Specifically, the opcodes and other fixed contents of instructions of the same type are often the same, while the opcodes and other fixed contents of instructions of different types may differ. Therefore, there are differences in the fixed bits of different pattern matching codes. Among them, the opcode belongs to a fixed content, and other fixed contents may be the function code of the instruction. That is, if the opcodes and function codes of two instructions are the same, then it can be determined that the two instructions perform the same basic operation, and the two instructions are the same instruction. Therefore, for any instruction, the pattern matching code can be used to uniquely determine whether a certain instruction is that type of instruction.
[0029] Specifically, the pattern matching code may include fixed bits corresponding to the opcode and other fixed contents of the instruction, and non-fixed bits corresponding to the operand. The total length of the pattern matching code may be the same as the total length of the instruction. For example, for a 32-bit instruction, the pattern matching code may also include 32 bits. The value of the non-fixed bit may be set to a preset symbol. For example, the "?" symbol may be used to represent the non-fixed bit. The specific content of the fixed bit in the pattern matching code may be the content specified in the architecture manual of the preset instruction architecture. Among them, the preset instruction architecture supported by the instruction decoding method may be set as needed. For example, the preset instruction architecture may be the fifth generation reduced instruction set computing (Five Reduced Instruction Set Compute, RISC-V) instruction architecture. Accordingly, the pattern matching code may be generated in advance for each instruction format specified in the architecture manual of the RISC-V instruction architecture for subsequent use. Among them, an instruction format defined in the architecture manual represents an instruction, and the architecture manual is the instruction set manual.
[0030] Specifically, the bits with fixed values in the instruction format can be used as fixed bits, and the values of these fixed bits can be retained, and the bits with non-fixed values in the instruction format can be used as non-fixed bits, and the values of the non-fixed bits can be set to preset symbols, and then the instruction format can be represented as binary to obtain the pattern matching code of the instruction represented by the instruction format. Exemplarily, the fixed bits can be filled with the original fixed values. Non-fixed bits, such as registers such as rs2, rs1, rd, or immediate values, can be replaced with "?" in the corresponding bit fields to generate a pattern matching code. Among them, rs2, rs1, and rd represent source register 2, source register 1, and destination register, respectively. Figure 2 FIG. 1 is a schematic diagram of an instruction format of a part of instructions provided by an embodiment of the present invention, such as Figure 2 As shown in the figure, from top to bottom, they are the instruction formats of the add instruction, the addi instruction, and the addiw instruction. For these instruction formats, the pattern matching codes below the instruction formats can be generated respectively.
[0031] Step 102: Determine the instruction name, instruction type and operand type of the instruction to be decoded based on the instruction related information pre-associated with the target matching code; the pattern matching code of each instruction is pre-associated with the instruction related information of each instruction.
[0032] In an embodiment of the present invention, the instruction-related information associated with the pattern matching code of the instruction may include the instruction name, instruction type, and operand type of the operand of the instruction. Exemplarily, the operand may include a source register (src), a destination register (dest), and an immediate number, wherein the type of dest may be int, fp, vector, etc., the type of src may be int, fp, vec, simm5, X, zimm11, zimm10, imm6, simm8, etc., and the type of the immediate number may include an immediate number extension type.
[0033] Specifically, after generating pattern matching codes for different instruction formats in advance, instruction-related information of the pattern matching code of the instruction format can be generated according to the instruction description information defined for each instruction format in the architecture manual. For example, the instruction name, instruction type, and operand type of the operand defined in the instruction description information can be extracted. Among them, the instruction-related information associated with the pattern matching code is the instruction-related information of the instruction represented by the pattern matching code. The instruction represented by the pattern matching code is the instruction represented by the instruction format used when generating the pattern matching code.
[0034] Optionally, in some embodiments, the step of determining the instruction name, instruction type, and operand type of the instruction to be decoded based on the instruction related information pre-associated with the target matching code may specifically include: extracting the instruction name, instruction type, and operand type of the operand from the instruction related information pre-associated with the target matching code as the instruction name, instruction type, and operand type of the instruction to be decoded. In the embodiment of the present invention, by first identifying the target matching code that matches the instruction to be decoded, the instruction name, instruction type, and operand type of the instruction to be decoded can be obtained directly based on the instruction related information pre-associated with the target matching code, so that the efficiency of information acquisition can be ensured.
[0035] Specifically, each pattern matching code and its associated instruction-related information can form a pattern matching format. After determining the target matching code, the instruction-related information associated with the target matching code in the pattern matching format can be extracted. In this way, the instruction-related information of the instruction to be decoded can be obtained through pattern matching. The instruction-related information of the instruction to be decoded is used as the preliminary matching result. Subsequently, the target format can be further determined according to the instruction type in the instruction-related information, and further decoding operations can be completed based on the target format. For example, for Figure 2 There are three pattern matching codes in the pattern matching format, which can be expressed as:
[0036] INST_PATTERN("b0000000??????000???0110011", ADD, R, int, int, int, X, X);
[0037] INST_PATTERN("b????????????000???0010011",ADDI,I,int,int,simm5,X,IMM_I);
[0038] INST_PATTERN("b?????????000????0011011",ADDIW,I,int,int,simm5,X,IMM_I);
[0039] Among them, b is used to indicate that the pattern matching code is in binary form, and the instruction-related information is expressed as: instruction name, instruction type, operand type of rd, operand type of rs1, operand type of rs2, operand type of rs3, and operand type of immediate value. For the first pattern matching format, the associated instruction-related information is: ADD, R, int, int, int, X, X; for the second pattern matching format, the associated instruction-related information is: ADDI, I, int, int, simm5, X, IMM_I; for the third pattern matching format, the associated instruction-related information is: ADDIW, I, int, int, simm5, X, IMM_I. Among them, X represents the type of a non-existent operand. For example, since the operands of the add instruction do not include rs3 and immediate values, the last two parts are represented by X.
[0040] Since the target matching code is a pattern matching code that matches the instruction to be decoded, it can be determined that the instruction to be decoded is the instruction represented by the pattern matching code. Exemplarily, assuming that the target matching code is generated based on the instruction format of the add instruction, that is, the target matching code represents the add instruction, then it can be determined that the instruction to be decoded is the add instruction. Assuming that the target matching code is 0000000? ??? ??? ??? ??? ??? 000? ??? ??? ??? 0110011, it can be determined that the instruction name of the instruction to be decoded is ADD, the instruction type is R type, the type of rd is integer (int), the type of rs1 is int, and the type of rs2 is int.
[0041] Step 103: Determine the operand indicator and operand content of the operand based on the operand bit field defined in the type format of the instruction type of the instruction to be decoded.
[0042] In an embodiment of the present invention, different instruction types may be pre-divided according to factors such as operating characteristics, operand type, addressing mode, and instruction length. The bit fields of each operand defined in the instructions of the same instruction type are the same. The same instruction type may include instructions of different types, that is, instructions of different types may conform to the same type format. For example, for the above-mentioned ADDI instruction and ADDIW instruction, the instruction types of these two instructions are both type I, and the bit fields of each operand in these two instructions are the same. For example, these two instructions both include operands: rd, rs1, and an immediate number, wherein the bit fields of rd are all from the 7th to the 11th, the bit fields of rs1 are all from the 15th to the 19th, and the bit fields of the immediate number are all from the 20th to the 31st.
[0043] The type format may refer to the format followed by the instructions of this instruction type. In the type format corresponding to any instruction type, the operand indicators of each operand included in the instruction of this instruction type and the bit fields of each operand may be defined, wherein the bit fields of the operands are the above-mentioned operand bit fields. The type format corresponding to the instruction type can be obtained from the architecture manual. The operand indicator is used to distinguish different operands. Exemplarily, the operand indicator may include: rs1, rs2, rd, imm, vd, vs2, vs3, and so on. The type format of the instruction type of the instruction to be decoded may be a target format.
[0044] Step 104: output the instruction decoding result based on the instruction name, the instruction type, the operand type, the operand indicator and the operand content of the operand.
[0045] In the embodiment of the present invention, an instruction decoding result may be generated and output based on the instruction name, instruction type, operand type of each operand, operand indicator and operand content.
[0046] In summary, in the instruction decoding method provided by the embodiment of the present invention, firstly, based on the preset pattern matching codes of each instruction, the pattern matching code matching the instruction to be decoded is identified as the target matching code; the pattern matching code of the instruction is used to characterize the operation code and other fixed contents of the instruction. Then, based on the instruction related information pre-associated with the target matching code, the instruction name, instruction type and operand type of the instruction to be decoded are determined; the pattern matching code of each instruction is pre-associated with the instruction related information of each instruction. Then, based on the operand bit field defined in the type format of the instruction type of the instruction to be decoded, the operand indicator and operand content of the operand are determined. Based on the instruction name, instruction type, operand type, operand indicator and operand content of the operand, the instruction decoding result is output. In this way, the decoding operation of the instruction to be decoded is realized, and at the same time, by obtaining the instruction name, instruction type and operand indicator and operand content of the instruction to be decoded, the instruction decoding result is output, which provides more convenient and intuitive instruction information, so that the user can more conveniently and intuitively know the detailed instruction information of the instruction based on the instruction decoding result.
[0047] Optionally, in some embodiments, the embodiments of the present invention may further include the following steps:
[0048] Step S21: Run a preset decoding tool to display a preset interactive interface.
[0049] Step S22: receiving a command input by a user based on the preset interactive interface as the command to be decoded.
[0050] The instruction decoding method provided in the embodiment of the present invention can be implemented in the form of an instruction decoding tool, so as to facilitate the use by users. The instruction decoding tool can be the preset decoding tool in the above steps. Accordingly, the preset decoding tool can be run first. Exemplarily, the preset decoding tool can be started by double-clicking so that the electronic device runs the preset decoding tool. Alternatively, the preset decoding tool is automatically started when the computer is turned on so that the electronic device runs the preset decoding tool, which is not limited in the embodiment of the present invention. Further, after the preset decoding tool runs, a preset interactive interface can be displayed. The preset interactive interface can include an instruction input area, and the user can enter the instruction to be decoded in the instruction input area. For example, a 32-bit instruction code in hexadecimal form is entered through the preset interactive interface. Exemplarily, a prompt message can be displayed in the instruction input area: Enter instruction (or 'q' to quit): .... Among them, the "..." part in the prompt message can be used to enter the instruction. The preset interactive interface can also display information such as the tool name, version, author, and current date, which is not limited in the embodiment of the present invention.
[0051] Accordingly, the instruction input through the instruction input area can be obtained to obtain the instruction to be decoded. In an embodiment of the present invention, by running a preset decoding tool and obtaining the input instruction to be decoded based on the displayed preset interactive interface, the instruction to be decoded can be obtained conveniently. Alternatively, the preset decoding tool can also dynamically capture the instruction corresponding to the abnormal waveform. For example, when a decoding trigger operation is received, the most recently executed instruction in the instruction stream is obtained as the instruction to be decoded.
[0052] Among them, the preset decoding tool can be a script written in Python language. After obtaining the instruction to be decoded, the target code can be called based on the Direct Programming Interface for C (DPI-C) technology, and the instruction to be decoded can be passed into the target code as a parameter. By running the target code, the instruction to be decoded can be decoded according to the above instruction decoding method. Correspondingly, after obtaining the instruction decoding result, the instruction decoding result can be returned to the preset decoding tool through DPI-C and printed out, thereby outputting the instruction decoding result and completing the interaction with the target script.
[0053] DPI-C is a technology for simulation and emulation, which allows the code written in C language to directly interact with the simulation environment. The target code can be a source program code written in C language, and the target code is used to implement each step of the instruction decoding method in the embodiment of the present invention.
[0054] In some embodiments, the present invention may further include the following steps:
[0055] Step S31, calling a preset backup decoding tool, and using the instruction to be decoded as input of the backup decoding tool.
[0056] Step S32: Obtain the output of the backup decoding tool to obtain the verification decoding result of the instruction to be decoded.
[0057] Step S33, outputting the verification decoding result and the instruction decoding result synchronously.
[0058] In an embodiment of the present invention, a standby decoding tool can be integrated in the above-mentioned preset decoding tool to facilitate calling. The decoding method of the standby decoding tool can be different from the decoding logic of the above-mentioned instruction decoding method, or it can be the same, that is, the standby decoding is used to decode again. By synchronously outputting the verification decoding result, it can be conveniently used to compare the verification decoding result with the instruction decoding result to achieve double verification. Specifically, if the contents of the two are consistent, it can be determined that the instruction decoding result has a high credibility and the instruction decoding result has a high accuracy. On the contrary, if the contents of the two are inconsistent, it can be determined that the instruction decoding result has a low credibility, and accordingly, the user can perform manual decoding. Further, after completing manual decoding, the instruction decoding result and the accuracy of the verification decoding result can be determined based on the result of manual decoding, and then it can be determined whether there is a problem with the target code integrated in the preset decoding tool, and whether there is a problem with the standby decoding tool, and feedback is given to the developer so that the developer can modify it. In this way, the maintenance cost can be reduced to a certain extent, and the update and maintenance can be performed in real time according to user needs.
[0059] Exemplarily, the standby decoding tool may be a third-party decoding tool. In an embodiment of the present invention, the decoding method of the standby decoding tool may be: split the instruction to be decoded to extract the operation code and function code therein, and then match the instruction type and instruction name one by one based on the operation code and function code. Finally, extract the operand content of each operand based on the instruction format, convert it into a disassembly code, and obtain the verification decoding result. Among them, the verification decoding result may only include the instruction name and the operand content of each operand, so that the amount of data used to compare the subsequent verification decoding result with the instruction decoding result can be reduced, thereby improving the verification efficiency. Accordingly, when the instruction name and the operand content of each operand of the two are consistent, it can be determined that the verification decoding result is consistent with the instruction decoding result. Exemplarily, the standby decoding tool may be spike_dasm, and the preset decoding tool may call the disassembly file of spike_dasm when obtaining the verification decoding result, thereby obtaining the verification decoding result. Among them, spike is a C language implemented simulator officially maintained by RISC-V. The tool is a full-function simulator that can simulate the instruction flow of the CPU. In the embodiment of the present invention, the decoding function can be called, and the decoding function of spike can decode the input instruction code more accurately.
[0060] In an embodiment of the present invention, by further calling a preset backup decoding tool, and taking the instruction to be decoded as the input of the backup decoding tool, and then obtaining the output of the backup decoding tool, a verification decoding result of the instruction to be decoded is obtained, and finally, the verification decoding result and the instruction decoding result are output synchronously, which can facilitate users to compare based on the two results, thereby achieving double verification.
[0061] In some embodiments, in the embodiments of the present invention, before outputting the verification decoding result and the instruction decoding result, it is also possible to detect whether the verification decoding result is consistent with the instruction decoding result. If the verification decoding result is inconsistent with the instruction decoding result, the result abnormality prompt information is output synchronously. Among them, the abnormal prompt information can be used to characterize that the result may be abnormal. Accordingly, the user can directly perform manual decoding when receiving the abnormal prompt information. At the same time, the preset decoding tool can be verified and corrected to improve the accuracy of the preset decoding tool when performing decoding.
[0062] In some embodiments, the pattern matching code of the instruction includes a fixed bit, and the fixed bit is set based on the operation code of the instruction and other fixed contents. Accordingly, the step of identifying the pattern matching code matching the instruction to be decoded as the target matching code based on the preset pattern matching code of each instruction may specifically include:
[0063] Step 1011: Determine the binary code of the instruction to be decoded as the target binary code.
[0064] Step 1012: For any of the pattern matching codes, compare the content of the fixed bit included in the pattern matching code with the content of the binary bit corresponding to the fixed bit in the target binary code.
[0065] Step 1013: If the contents are consistent, the pattern matching code is determined as the target matching code.
[0066] In an embodiment of the present invention, when the instruction to be decoded is not currently in binary form, the instruction to be decoded can be first converted into binary to obtain a target binary code. When the instruction to be decoded is currently in binary form, the instruction to be decoded can be directly used as the target binary code. For example, assuming that the instruction to be decoded is 0x003102b3 (where 0x represents hexadecimal), the instruction to be decoded can be converted into binary code according to the conversion rule from hexadecimal to binary to obtain the target binary code: 00000000001100010000001010110011.
[0067] Furthermore, the target binary code can be matched bit by bit with the fixed bits in the pattern matching code. When the content of each fixed bit in the target binary code is consistent with the content of the fixed bit in the pattern matching code, the pattern matching code is determined as the target matching code. In the embodiment of the present invention, the content of the non-fixed bit in the target matching code is the operand content of each operand in the instruction to be decoded, which can be obtained through subsequent decoding operations.
[0068] In the embodiment of the present invention, the instruction to be decoded is taken as a whole, and the binary code of the instruction to be decoded is directly used to compare the content with the fixed bits included in the pattern matching code, so as to identify the target matching code that matches the instruction to be decoded, and then the instruction name, instruction type and operand type of the instruction to be decoded can be directly determined based on the target matching code. In this way, since there is no need to split, the complexity of the recognition process can be reduced to a certain extent, and the recognition efficiency can be improved.
[0069] In some implementations, the present invention may further include the following steps:
[0070] Step S41: When the operand includes a register operand, based on a preset correspondence between a register number and a register name and the operand content of the register operand, determine the register name corresponding to the register operand as the target register name.
[0071] Accordingly, the step of outputting the instruction decoding result based on the instruction name, the instruction type, the operand type, the operand indicator and the operand content of the operand may specifically include:
[0072] Step 1041: Generate the instruction decoding result based on the instruction name, the instruction type, the operand type, the operand indicator, the operand content and the target register name, and output the instruction decoding result.
[0073] In the embodiment of the present invention, based on the preset register number and register name correspondence and the operand content of the register operand, the register name corresponding to the register operand is determined as the target register name, and the instruction decoding result is further generated and output in combination with the target register name. Based on the instruction decoding result, the user can also know the register name corresponding to the register operand in the instruction to be decoded, providing the user with more detailed and intuitive information, and thus to a certain extent, the efficiency of locating problems in the CPU verification process can be improved based on the instruction decoding result.
[0074] Specifically, the correspondence between the register number and the register name can be pre-set, and the correspondence can include the register numbers and register names (i.e., register number aliases) of all registers supported by the instruction architecture. Exemplarily, the correspondence can include 32 fixed-point registers, each of which has a corresponding name, for example, x5 corresponds to t0, and x11 corresponds to a1. The operand content of the register operand in the instruction to be decoded is the register number of the register operand. Accordingly, the operand content of the register operand in the instruction to be decoded can be compared with each register number in the correspondence to determine the register number consistent with the operand content of the register operand. Then, the register name corresponding to the register number with the consistent content is determined as the register name corresponding to the register operand, and the target register name is obtained. Accordingly, the instruction name, instruction type, operand type of each operand, operand indicator, operand content, and target register name of the register operand of the instruction to be decoded can be used as the instruction decoding result and output according to the preset output format. For example, assume that the instruction name of the instruction to be decoded is C_SUBW, the type is CA, and the operands include rd and rs2, wherein the operand indicator of operand rd is rd, the operand content is 14, the operand type is integer, and the target register name is a4, and the operand indicator of operand rs2 is rs2, the operand content is 12, the operand type is integer, and the target register name is a2. Then the instruction output result output according to the preset output format can be expressed as:
[0075] asm: C_SUBW x14 x12
[0076] decode_info: name=C_SUBW, type=CA, rd=14 (a4), rs2=12 (a2)
[0077] Among them, the x in x14 and x12 indicates that the operand type is integer.
[0078] Furthermore, the verification instruction result of the synchronous output can be expressed as:
[0079] spike_asm: c.subwa4, a2
[0080] In the embodiment of the present invention, the input instructions to be decoded may be further displayed simultaneously, for example, the following may be displayed:
[0081] Enter instruction (or 'q' to quit): 9f11
[0082] inst:9f11
[0083] In actual applications, there may be multiple instructions to be decoded, so the final display interface can display the decoding results of multiple instructions to be decoded. Take the instructions to be decoded including 9f11 and cla8f7f3 as an example. The final output result can be expressed as:
[0084] Enter instruction (or 'q' to quit): 9f11
[0085] inst:9f11
[0086] asm: C_SUBW x14 x12
[0087] decode_info: name=C_SUBW, type=CA, rd=14 (a4), rs2=12 (a2)
[0088] spike_asm: c.subwa4, a2
[0089] Enter instruction (or 'q' to quit): cla8f7f3
[0090] inst:cla8f7f3
[0091] asm: CSRRCI x15, hpmcounter26, #17
[0092] decode_info: name= CSRRCI, type=I, rd=x15(a5), zim=17, csr=0xcla(hpmcounter26)
[0093] spike_asm: cssrcia5, hpmcounter26, 17
[0094] Exemplarily, the correspondence between the preset register numbers and register names may be shown in Table 1 below:
[0095] Register number and register name correspondence table
[0096]
[0097] Table 1
[0098] During the CPU verification process, verification engineers often need to view waveform files. During the waveform viewing process, if an abnormal situation is encountered, it is urgent to understand what instruction this instruction is, that is, to understand the instruction name, instruction type, operand value, operand type, etc. If there is no decoding tool, then the verification engineer needs to obtain the disassembly code of the instruction through the instruction stream. However, based on the disassembly code, it is impossible to directly obtain the detailed information of each register. For example, the disassembly code is c.subwa4, a2. Based on the disassembly code, it is impossible to directly get which register a4 and a2 correspond to, nor is it possible to know whether a4 is rd or rs1, and whether a2 is rs1 or rs2.
[0099] The instruction decoding result of the embodiment of the present invention includes the instruction name, instruction type, and detailed information of the operands of the instruction to be decoded: operand type, operand indicator, operand content, and target register name, which improves the readability of the decoding result. In this way, based on the instruction decoding result of the embodiment of the present invention, the user can intuitively and conveniently know the register numbers of a4 and a2 without performing additional query operations, and know that a4 and a2 correspond to the 14th register and the 12th register respectively, a4 is rd, a2 is rs2, and the operand types of a4 and a2 are both integers. At the same time, based on the name in the instruction decoding result, the user can know what operation the instruction to be decoded needs to perform. For example, if the instruction name is add, it can be determined what addition operation the instruction to be decoded needs to perform. And based on the detailed operand information in the instruction decoding result, it can be known which two register values (source registers) are added, and which register (destination register) the result is stored in, so that engineers can quickly and conveniently understand the execution logic of the instruction, thereby quickly locating the problem.
[0100] In some embodiments, the present invention may further include the following steps:
[0101] Step S51, generating annotation information for the operand content; the annotation information is used to characterize the acquisition method of the operand content.
[0102] Accordingly, the step of generating the instruction decoding result based on the instruction name, the instruction type, the operand type, the operand indicator, the operand content and the target register name may specifically include:
[0103] Step 1041a, determine the instruction name, the instruction type, the operand type, the operand indicator, the operand content, the target register name and the comment information as the instruction decoding result.
[0104] Specifically, when the operand content is obtained after further processing based on the content carried in the instruction to be decoded, annotation information can be generated for the operand content, so that the user can more clearly understand the decoding process of the instruction based on the annotation information. Further, the instruction name, instruction type, operand type of each operand, operand indicator, operand content, target register name of register operand and annotation information of the instruction to be decoded can be used as the instruction decoding result and output according to the preset output format.
[0105] In the embodiment of the present invention, annotation information for characterizing the method of obtaining the operand content is further generated for the operand content, and the instruction decoding result is further generated and output in combination with the annotation information. Based on the instruction decoding result, the user can also know the method of obtaining the operand content in the instruction to be decoded, thereby improving the richness, detail and intuitiveness of the instruction decoding result, so that the user can understand the relevant information of the decoding more intuitively.
[0106] In some embodiments, the step of determining the operand indicator and operand content of the operand based on the operand bit field defined in the type format of the instruction type of the instruction to be decoded may specifically include:
[0107] Step 1031: If the instruction name of the instruction to be decoded is not a preset special instruction name, the type format of the instruction type of the instruction to be decoded is determined as a target format; an operand bit field defined in the target format represents an operand of the instruction to be decoded.
[0108] Step 1032: For any operand bit field in the target format, obtain the operand indicator of the operand bit field as the operand indicator of the target operand; the target operand is the operand represented by the operand bit field.
[0109] Step 1033: Obtain the content of the binary bits corresponding to the operand bit field in the instruction to be decoded as the target content.
[0110] Step 1034: Determine the operand content of the target operand based on the target content.
[0111] In an embodiment of the present invention, the special instruction name may be the instruction name of a special instruction, and the special instruction may include instructions whose instruction formats in each instruction type are different from the type format of the instruction type. Specifically, for each instruction type, all instructions belonging to the instruction type can be obtained from the architecture manual, and then the operand types and bit fields defined in the instruction formats of these instructions are compared with the operand types and bit fields defined in the type format of the instruction type. If they are inconsistent, the instruction can be determined as a special instruction, and the instruction type and the instruction name of the instruction are stored correspondingly, and finally the special instruction name corresponding to each instruction type can be obtained. It is possible to find out whether there is an instruction name of the instruction to be decoded from the special instruction name corresponding to the instruction type of the instruction to be decoded. If it exists, it can be determined that the instruction name of the instruction to be decoded is a preset special instruction name.
[0112] Accordingly, the type format corresponding to the instruction name of the instruction to be decoded can be loaded from the type format pre-set for the special instruction as the target format. Among them, the type format set for the special instruction can represent the decoding rules set for the special instruction, and the type format set for each special instruction can be defined as: the operand bit field of each operand included in each special instruction. The type format is set corresponding to the special instruction so that the subsequent decoding can obtain the correct instruction information. For example, for special instructions: vset type instructions, the information of each bit field of the immediate number can be further decoded through the immediate number, such as vill, vma, vta, vsew, vlmul and other more detailed decoding information.
[0113] If it does not exist, it can be determined that the instruction name of the instruction to be decoded is not a preset special instruction name, and the subsequent steps are executed. Figure 3 is a schematic diagram of a type of format and special instructions provided by an embodiment of the present invention, such as Figure 3 As shown, for the R type, the R type type format defines three register operands, rd, rs1, and rs2, where rd represents the register used to store the result, that is, the destination register, and rs1 and rs2 represent the registers used to provide operands, that is, the source registers. That is to say, under normal circumstances, instructions of the R type instruction type will include rd, rs1, and rs2. However, in actual applications, there may be instructions in which rs2 is a fixed value, that is, there is no rs2 bit field. For the I type, the 31st to 20th bits in the I type type format are immediate numbers, and also include rs1 and rd. Among them, the R type represents the register type, and the I type represents the immediate number type.
[0114] However, for instruction a and instruction b of type R, the 24th to 20th bits of these two instructions are 00001 and 00000 respectively. Among them, rm represents the rounding mode, and instruction a and instruction b can be fcvt.wu.d instruction and fcvt.ws instruction respectively. For instruction c and instruction d of type I, the 31st to 20th bits of these two instructions are not immediate values. Among them, instruction c and instruction d can be fence instruction and fence.i instruction respectively, and parameter 1 and parameter 2 are two parameters in the fence instruction: pred and succ respectively. Therefore, special instructions of type R can include fcvt.wu.d instruction and fcvt.ws instruction, and special instructions of type I can include fence instruction and fence.i instruction, so as to facilitate subsequent decoding based on the decoding rules of separate instructions for special instructions.
[0115] Among them, the operand bit field in the type format can carry information: the operand indicator and the bits occupied by the operand represented by the operand bit field. Accordingly, for any operand bit field, the indicator carried therein can be extracted to obtain the operand indicator of the operand represented by the operand bit field, and, according to the bits occupied by the operand bit field, the content of the corresponding bit in the instruction to be decoded is extracted to obtain the target content of the operand represented by the operand bit field. Further, the operand content of the operand represented by the operand bit field can be determined based on the target content of the operand represented by the operand bit field. The type format set for an instruction can represent the decoding rules set for this type of instruction.
[0116] Assuming the target format is R type, refer to Figure 3 The R-type format in the instruction includes three operand bit fields. From left to right, the identifier included in the first operand bit field can be extracted to obtain the operand identifier rs2 of the first target operand. Based on the target format, it can be determined that the bits occupied by the first target operand are bits 24 to 20. Accordingly, the contents of bits 24 to 20 in the instruction to be decoded can be extracted to obtain the target contents of the first target operand.
[0117] Then, the expression included in the second operand bit field can be extracted to obtain the operand expression rs1 of the second target operand. And based on the target format, it can be determined that the bits occupied by the second target operand are bits 19 to 15, and accordingly, the contents of bits 19 to 15 in the instruction to be decoded can be extracted to obtain the target content of the second target operand. Then, the expression included in the third operand bit field can be extracted to obtain the operand expression rd of the third target operand. And based on the target format, it can be determined that the bits occupied by the third target operand are bits 11 to 7, and accordingly, the contents of bits 11 to 7 in the instruction to be decoded can be extracted to obtain the target content of the third target operand. Among them, the target operand is the operand included in the instruction to be decoded, that is, the operand bit field defined in the target format is the operand bit field of each operand in the instruction to be decoded.
[0118] Take the instruction to be decoded as 0x003102b3 as an example, the binary code of the instruction to be decoded is 00000000001100010000001010110011. The target matching code of the target binary code is: 0000000? ? ? ? ? ? ? ? 000? ? ? ? ? 0110011. Correspondingly, based on the above steps, it can be obtained that the instruction name of the instruction to be decoded is ADD, the instruction type is R type, the type of rd is integer (int), the type of rs1 is int, and the type of rs2 is int. Furthermore, for the R-type format, it can be known that the 31st to 25th bits of the instruction are function bits, and the 24th to 20th bits are the rs2 bit field, so the 24th to 20th bits in the target binary code can be extracted: 00011, where the decimal value corresponding to the binary 00011 is 3, that is, the register number of rs2 is 3, and because its operand type is int, the register corresponding to rs2 is an integer register, which can be expressed as x3. The 19th to 15th bits are the rs1 bit field, so the 19th to 15th bits in the target binary code can be extracted: 00010, where the decimal value corresponding to the binary 00010 is 2, that is, the register number of rs1 is 2, and because its operand type is int, the register corresponding to rs1 is an integer register, which can be expressed as x2, and so on, the information of all operands can be obtained.
[0119] In the embodiment of the present invention, the pattern matching code is first used to perform pattern matching to obtain the instruction type of the instruction to be decoded, and then the corresponding type format is determined according to the instruction type. The type format of the instruction type of the instruction to be decoded can be used to decode the values corresponding to each operand bit field in the instruction to be decoded, and then the operand identifier and operand content of each operand included in the instruction to be decoded can be obtained. In this way, the decoding efficiency can be ensured to a certain extent, and the instruction decoding can be realized quickly.
[0120] In some embodiments, the step of determining the operand content of the target operand based on the target content may specifically include:
[0121] Step 1034a: When the operand identifier of the target operand does not carry a preset identifier, determine the target content as the operand content of the target operand.
[0122] Step 1034b: When the operand identifier of the target operand carries the preset identifier, add a preset value to the target content as the operand content of the target operand.
[0123] In the embodiment of the present invention, specifically, the above steps 1034a-1034b may be performed when the operand identifier of the target operand is used to represent the register. In the rule of the instruction architecture, the designated identifier may be used to indicate that the operand is in compressed form, and the designated identifier may be represented as '. Exemplarily, for rd, rs1, rs2, rs3, and imme, these operand identifiers do not carry the designated identifier. For rd', rs1', etc., these operand identifiers carry the designated identifier.
[0124] Accordingly, if the operand indicator of the target operand does not carry a preset identifier, it can be explained that the target content extracted by direct decoding before is the actual operand content, and therefore, the target content can be directly determined as the operand content of the target operand. If the operand indicator of the target operand carries a preset identifier, it can be explained that the target content extracted by direct decoding before needs to be increased by a preset value. Therefore, a preset value can be added to the target content as the operand content of the target operand. Among them, the preset value can be 2^n, where n is the number of bits occupied by the operand whose operand indicator is the second indicator under the instruction architecture, for example, the preset value can be 8. Exemplarily, assuming that the instruction to be decoded is a compressed instruction, after direct decoding, the target content of the operand with the operand indicator rd' is extracted as 6, then the real rd value is rd'+8=6+8=14, that is, the rd register of the instruction to be decoded is register No. 14. It should be noted that when determining the operand indicator of the operand, the preset identifier can be removed, that is, in the instruction decoding result, the preset identifier carried by the operand indicator can be not displayed.
[0125] Correspondingly, the above-mentioned step of generating annotation information for the operand content specifically includes: step S51a, generating annotation information for the target operand when the target operand identifier carries the preset identifier; the annotation information is used to indicate that the operand content of the target operand is obtained by adding the preset value to the target content.
[0126] In the embodiment of the present invention, the annotation information can be specifically used to indicate the special situation of the decoding of the instruction to be decoded, so as to facilitate the user to understand how the decoding result is obtained. Specifically, the annotation information can be generated in the form of operand indicator without preset mark = operand indicator carrying preset mark (target content) + preset value.
[0127] For example, for the instruction to be decoded with the instruction name C_SUBW, the decoding result of the relevant bit field of rd in the 32-bit instruction code of the instruction to be decoded is actually rd'=6, and the decoding result of the relevant bit field of rs2 in the 32-bit instruction code of the instruction to be decoded is actually rs2'=4, then the comment information can be generated:
[0128] Note: rd= rd'(6)+8, rs2= rs2'(4)+8.
[0129] Furthermore, the comment information may also include the contents of the operands obtained by the final calculation and the types of the operands. Accordingly, the comment information may be expressed as: Note: rd(x14) = rd'(x6)+8, rs2(x12) = rs2'(x4)+8.
[0130] The decoding result finally outputted for the instruction to be decoded can be expressed as:
[0131] Enter instruction (or 'q' to quit): 9f11
[0132] inst:9f11
[0133] asm: C_SUBW x14 x12
[0134] decode_info: name=C_SUBW, type=CA, rd=14(a4), rs2=12(a2) [Note: rd(x14)=rd'(x6)+8, rs2(x12)=rs2'(x4)+8]
[0135] spike_asm: c.subwa4, a2
[0136] In this way, based on the annotation information, the user can know that a4 (ie, x14) is not the result of direct decoding, and a4 needs to be obtained through rd'+8, and a2 (ie, x12) is not the result of direct decoding, and a2 needs to be obtained through rs2'+8.
[0137] In the embodiment of the present invention, the actual operand content is adaptively determined according to the target content according to whether the operand indicator of the target operand carries a preset identifier, so that the requirements of the instruction architecture can be met and the accuracy of the operand content can be ensured. At the same time, corresponding annotation information is generated so that the user can conveniently know that the operand content of the target operand is in a manner of adding a preset value to the target content based on the final instruction decoding result, thereby providing the user with more accurate information and facilitating the user's analysis.
[0138] It should be noted that, in the case where the operand indicator of the target operand is used to represent an immediate number, and the operand indicator belongs to an indicator used to indicate a specific processing (for example, sign extension, zero extension or shift operation), the specific processing is performed on the target content to obtain the operand content of the target operand. If the operand indicator does not belong to an indicator used to indicate a specific processing, the target content is directly determined as the operand content of the target operand. Accordingly, in the case where the operand indicator of the target operand is used to represent an immediate number, and the operand indicator belongs to an indicator used to indicate a specific processing, annotation information can be generated, and the annotation information can be used to indicate that the operand content of the target operand is obtained by performing the specific processing on the target content.
[0139] Taking the RISC-V instruction architecture as an example, the instructions in this instruction architecture can be divided into three major categories: fixed and floating point (i.e., integer and floating point), vector extension, and compressed instruction. Among them, fixed and floating point can be specifically divided into six types: I, S, B, U, J, and R; compressed instruction can be specifically divided into nine types: CR, CI, CSS, CIW, CL, CS, CA, CB, and CJ; vector extension can be specifically divided into four types: load, store, arithmetic, and vset-related. If the support for the instruction set is not complete, then during the CPU verification process, if you need to quickly determine the decoding information through the 32-bit instruction code, you need to determine it by viewing the disassembly code of the instruction stream or manually decoding it, which will reduce the verification efficiency.
[0140] In an embodiment of the present invention, the above-mentioned pattern matching code and its associated instruction related information, as well as the type format can be stored in the form of a table. Accordingly, if it is necessary to increase the support for the instruction of a certain existing instruction type, for example, RISC_V adds a new instruction, then by maintaining the table, adding the pattern matching code of the newly added instruction and its associated instruction related information in the table, the expansion of new instruction support can be achieved. If it is to increase the support for the instruction of the newly added instruction type, for example, to add support for the instruction of the H-type instruction format, the type format of the newly added instruction type can be further increased, and then the decoding rules for the newly added instruction type can be increased. In this way, it is relatively easy to add support for new instructions, and the scalability is good. By adding, the preset decoding tool can make the support for the instruction set more complete, and provide users with a more convenient, easy-to-use, and more user-friendly instruction decoding tool. At the same time, based on the independent preset decoding tool, decoding is performed according to the above-mentioned instruction decoding method to provide users with more intuitive, convenient and detailed instruction information.
[0141] In an embodiment of the present invention, based on the type format for different instruction types, the decoding results of the instructions to be decoded can be correspondingly decoded. For example, in the dump waveform, the verification engineer can only see the hexadecimal value of the waveform signal, without disassembly information, and cannot know what instruction is executed, and cannot obtain detailed information of the instruction. Assuming that there is a problem with the execution behavior of instruction: 95f02a57 in the instruction stream, if the verification engineer needs to quickly know the execution behavior of the instruction, the above-mentioned preset decoding tool can be used for decoding. Accordingly, the preset decoding tool can output the following results:
[0142] Enter instruction (or 'q' to quit): 95f02a57
[0143] vd:v, vs1:v, vs2:v
[0144] inst:95f02a57
[0145] asm: VMUL_VV v20, v31, v0, masked
[0146] decode_info: name=VMUL_VV, type=V, vd=20, vs2=31, vs1=0, vm=0
[0147] spike_asm: vmul.vvv20, v31, v0, v0.t
[0148] Based on the above results, verification engineers can easily know that the instruction is a vector extension instruction and a multiplication instruction, the operand vs2 is the value of register No. 31, vs1 is the value of register No. 0, the execution result is stored in register No. 20, and other information.
[0149] Reference Figure 4 , shows a block diagram of an instruction decoding device provided by an embodiment of the present invention, such as Figure 4 As shown, the device may specifically include:
[0150] The recognition module 201 is used to identify the pattern matching code that matches the instruction to be decoded based on the preset pattern matching code of each instruction as the target matching code; the pattern matching code of the instruction is used to represent the operation code and other fixed content of the instruction;
[0151] A first determination module 202 is used to determine the instruction name, instruction type and operand type of the instruction to be decoded based on the instruction related information pre-associated with the target matching code; the pattern matching code of each instruction is pre-associated with the instruction related information of each instruction;
[0152] A second determination module 203, configured to determine an operand indicator and operand content of the operand based on an operand bit field defined in a type format of an instruction type of the instruction to be decoded;
[0153] The first output module 204 is used to output the instruction decoding result based on the instruction name, the instruction type, the operand type, the operand indicator and the operand content of the operand.
[0154] Optionally, the pattern matching code of the instruction includes a fixed bit, and the fixed bit is set based on the operation code of the instruction and other fixed contents; the identification module 201 is specifically used for:
[0155] Determine the binary code of the instruction to be decoded as the target binary code;
[0156] For any of the pattern matching codes, comparing the content of the fixed bit included in the pattern matching code with the content of the binary bit corresponding to the fixed bit in the target binary code;
[0157] If the contents are consistent, the pattern matching code is determined as the target matching code.
[0158] Optionally, the device further comprises:
[0159] A third determining module is used to determine, when the operand includes a register operand, based on a preset correspondence between a register number and a register name and the operand content of the register operand, a register name corresponding to the register operand as a target register name;
[0160] The first output module 204 is specifically used for:
[0161] The instruction decoding result is generated based on the instruction name, the instruction type, the operand type, the operand indicator, the operand content and the target register name, and the instruction decoding result is output.
[0162] Optionally, the device further comprises:
[0163] A generating module, used for generating annotation information for the operand content; the annotation information is used for representing the acquisition method of the operand content;
[0164] The first output module 204 is further configured to:
[0165] The instruction name, the instruction type, the operand type, the operand indicator, the operand content, the target register name and the comment information are determined as the instruction decoding result.
[0166] Optionally, the second determining module 203 is specifically configured to:
[0167] If the instruction name of the instruction to be decoded is not a preset special instruction name, the type format of the instruction type of the instruction to be decoded is determined as a target format; one of the operand bit fields defined in the target format represents an operand of the instruction to be decoded;
[0168] For any of the operand bit fields in the target format, obtaining an operand indicator of the operand bit field as an operand indicator of a target operand; the target operand is the operand indicated by the operand bit field;
[0169] Obtaining the content of the binary bits corresponding to the operand bit field in the instruction to be decoded as the target content;
[0170] Based on the target content, operand content of the target operand is determined.
[0171] Optionally, the second determining module 203 is further configured to:
[0172] In a case where the operand indicator of the target operand does not carry a preset identifier, determining the target content as the operand content of the target operand;
[0173] In a case where the operand indicator of the target operand carries the preset identifier, adding a preset value to the target content as the operand content of the target operand;
[0174] The generation module is specifically used to: generate annotation information for the target operand when the target operand identifier carries the preset identifier; the annotation information is used to indicate that the operand content of the target operand is obtained by adding the preset value to the target content.
[0175] Optionally, the device further comprises:
[0176] A calling module, used for calling a preset standby decoding tool, and using the instruction to be decoded as an input of the standby decoding tool;
[0177] An acquisition module, used for acquiring the output of the backup decoding tool to obtain the verification decoding result of the instruction to be decoded;
[0178] The second output module is used to synchronously output the verification decoding result and the instruction decoding result.
[0179] Optionally, the first determining module 202 is specifically configured to:
[0180] The instruction name, instruction type and operand type of the operand in the instruction related information pre-associated with the target matching code are extracted as the instruction name, instruction type and operand type of the instruction to be decoded.
[0181] In summary, in the instruction decoding device provided by the embodiment of the present invention, based on the preset pattern matching codes of each instruction, the pattern matching code matching the instruction to be decoded is identified as the target matching code; the pattern matching code of the instruction is used to characterize the operation code and other fixed contents of the instruction. Then, based on the instruction related information pre-associated with the target matching code, the instruction name, instruction type and operand type of the instruction to be decoded are determined; the pattern matching code of each instruction is pre-associated with the instruction related information of each instruction. Then, based on the operand bit field defined in the type format of the instruction type of the instruction to be decoded, the operand indicator and operand content of the operand are determined. Based on the instruction name, instruction type, operand type, operand indicator and operand content of the operand, the instruction decoding result is output. In this way, the decoding operation of the instruction to be decoded is realized. At the same time, by obtaining the instruction name, instruction type and operand indicator and operand content of the instruction to be decoded, the instruction decoding result is output, providing more convenient and intuitive instruction information, so that the user can more conveniently and intuitively know the detailed instruction information of the instruction based on the instruction decoding result.
[0182] Reference Figure 5, is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. Figure 5 As shown, the electronic device includes: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the instruction decoding method of the above embodiment. The executable instructions can form a program.
[0183] An embodiment of the present invention provides a readable medium having instructions stored thereon, which, when executed by one or more processors, enables the processors to execute the instruction decoding method of the aforementioned embodiment.
[0184] 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.
[0185] It should be understood by those skilled in the art that the embodiments of the present invention can be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes. It should be noted that all actions of acquiring signals, information or data in this application are carried out under the premise of complying with the corresponding data protection laws and policies of the country of residence and with the authorization given by the owner of the corresponding device. The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the process Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0186] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal device to operate in a predictable manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0187] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0188] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0189] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0190] The above is a detailed introduction to an instruction decoding method, an instruction decoding device, an electronic device and a readable medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for a general technician in this field, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A method for decoding an instruction, It is characterized in that The method comprises: Based on the preset pattern matching codes of each instruction, a pattern matching code matching the instruction to be decoded is identified as a target matching code; the pattern matching code of the instruction is used to represent the operation code and other fixed contents of the instruction; Based on the instruction related information pre-associated with the target matching code, determining the instruction name, instruction type and operand type of the instruction to be decoded; the pattern matching code of each instruction is pre-associated with the instruction related information of each instruction; Determine the operand indicator and operand content of the operand based on the operand indicator of the operand bit field defined in the type format of the instruction type of the instruction to be decoded and the content of the corresponding binary bit; one of the operand bit fields defined in the type format of the instruction type of the instruction to be decoded represents an operand of the instruction to be decoded; An instruction decoding result is output based on the instruction name, the instruction type, the operand type of the operand, the operand indicator and the operand content.
2. The method according to claim 1, It is characterized in that The pattern matching code of the instruction includes a fixed bit, and the fixed bit is set based on the operation code and other fixed contents of the instruction; the pattern matching code based on the preset pattern matching code of each instruction, identifying the pattern matching code matching the instruction to be decoded as the target matching code, includes: Determine the binary code of the instruction to be decoded as the target binary code; For any of the pattern matching codes, comparing the content of the fixed bit included in the pattern matching code with the content of the binary bit corresponding to the fixed bit in the target binary code; If the contents are consistent, the pattern matching code is determined as the target matching code.
3. The method according to claim 1 or 2, It is characterized in that The method further comprises: In the case where the operand includes a register operand, based on a preset correspondence between a register number and a register name and the operand content of the register operand, determining a register name corresponding to the register operand as a target register name; The outputting the instruction decoding result based on the instruction name, the instruction type, the operand type, the operand indicator and the operand content of the operand comprises: The instruction decoding result is generated based on the instruction name, the instruction type, the operand type, the operand indicator, the operand content and the target register name, and the instruction decoding result is output.
4. The method according to claim 3, It is characterized in that The method further comprises: Generate annotation information for the operand content; the annotation information is used to characterize the acquisition method of the operand content; The step of generating the instruction decoding result based on the instruction name, the instruction type, the operand type, the operand indicator, the operand content and the target register name comprises: The instruction name, the instruction type, the operand type, the operand indicator, the operand content, the target register name and the comment information are determined as the instruction decoding result.
5. The method according to claim 4, It is characterized in that The determining of the operand indicator and the operand content of the operand based on the operand indicator of the operand bit field defined in the type format of the instruction type of the instruction to be decoded and the content of the corresponding binary bit comprises: If the instruction name of the instruction to be decoded is not a preset special instruction name, the type format of the instruction type of the instruction to be decoded is determined as a target format; one of the operand bit fields defined in the target format represents an operand of the instruction to be decoded; For any of the operand bit fields in the target format, obtaining an operand indicator of the operand bit field as an operand indicator of a target operand; the target operand is the operand indicated by the operand bit field; Obtaining the content of the binary bits corresponding to the operand bit field in the instruction to be decoded as the target content; Based on the target content, operand content of the target operand is determined.
6. The method according to claim 5, It is characterized in that The step of determining the operand content of the target operand based on the target content includes: In a case where the operand indicator of the target operand does not carry a preset identifier, determining the target content as the operand content of the target operand; In a case where the operand indicator of the target operand carries the preset identifier, adding a preset value to the target content as the operand content of the target operand; The generating of annotation information for the operand content includes: generating annotation information for the target operand when the target operand identifier carries the preset identifier; the annotation information is used to indicate that the operand content of the target operand is obtained by adding the preset value to the target content.
7. The method according to claim 1, It is characterized in that The method further comprises: Calling a preset backup decoding tool, and using the instruction to be decoded as input of the backup decoding tool; Obtaining the output of the backup decoding tool to obtain a verification decoding result of the instruction to be decoded; The verification decoding result and the instruction decoding result are output synchronously.
8. The method according to claim 1, It is characterized in that The step of determining the instruction name, instruction type, and operand type of the instruction to be decoded based on the instruction related information pre-associated with the target matching code comprises: The instruction name, instruction type and operand type of the operand in the instruction related information pre-associated with the target matching code are extracted as the instruction name, instruction type and operand type of the instruction to be decoded.
9. An instruction decoding device, It is characterized in that The device comprises: An identification module, used for identifying a pattern matching code matching the instruction to be decoded based on the preset pattern matching codes of each instruction as a target matching code; the pattern matching code of the instruction is used to represent the operation code and other fixed contents of the instruction; A first determination module is used to determine the instruction name, instruction type and operand type of the instruction to be decoded based on the instruction related information pre-associated with the target matching code; the pattern matching code of each instruction is pre-associated with the instruction related information of each instruction; A second determination module is used to determine the operand indicator and operand content of the operand based on the operand indicator of the operand bit field defined in the type format of the instruction type of the instruction to be decoded and the content of the corresponding binary bit; one of the operand bit fields defined in the type format of the instruction type of the instruction to be decoded represents an operand of the instruction to be decoded; The first output module is used to output the instruction decoding result based on the instruction name, the instruction type, the operand type of the operand, the operand indicator and the operand content.
10. An electronic device, It is characterized in that include: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store executable instructions, and the executable instructions enable the processor to execute the method according to any one of claims 1 to 8.
11. A readable medium, It is characterized in that Instructions are stored thereon, which, when executed by one or more processors, cause the processors to perform the method as claimed in any one of claims 1 to 8.
