Assembly method and combination method, device, equipment, medium and product of instructions
By introducing composition syntax into the processor instruction set architecture, and unifying the description of assembly syntax and encoding fields, the maintenance complexity and scalability issues caused by separation are resolved, enabling efficient and accurate instruction set maintenance and expansion.
Patent Information
- Application Number
- CN202611664057.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-26
- Publication Date
- 2026-11-24
AI Technical Summary
In the prior art, the separation of assembly syntax and encoding fields in the processor instruction set architecture leads to scattered descriptions and inconsistent updates, which increases the complexity of design and maintenance. It is also prone to problems such as missing writes, overwriting, or retaining expired content, which limits the scalability and maintenance efficiency of the ISA.
By adopting an instruction set-based combination syntax, a unified combination syntax is generated by determining the common parent syntax and unique child syntax of multiple instructions. This enables the description of assembly syntax and encoding fields in the same system, supporting automated assembly and real-time expansion.
It improves the accuracy and efficiency of instruction assembly, enhances the scalability and maintenance efficiency of the instruction set, solves the inconsistency problem caused by the separation of assembly syntax and encoding fields, and improves the robustness and development efficiency of the toolchain.
Smart Images

Figure CN123157178A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to, but is not limited to, the field of computer technology, and in particular to a method and apparatus for assembling and combining processor instructions, a computer device, a computer-readable storage medium, and a computer program product. Background Technology
[0002] In processor design, the definition of the Instruction Set Architecture (ISA) typically includes two parts: assembly syntax and encoding fields. These are addressed to programmers and hardware implementations respectively, but are maintained independently. While this separation facilitates use by different roles, it leads to scattered instruction format descriptions, inconsistent updates, and increases the complexity of ISA design and maintenance.
[0003] In related technologies, assembly syntax and encoding fields are defined separately. For example, assembly syntax is described in text form (such as "ADD R1, R2, R3"), while encoding fields specify the location of opcodes, register fields, etc., through bit field diagrams or encoding tables. Because assembly syntax and encoding fields are defined separately, this approach is prone to problems such as omissions, overwriting, or retention of expired content when local changes occur in instructions. This makes instruction maintenance difficult and limits the scalability and maintenance efficiency of the instruction ISA. Summary of the Invention
[0004] In view of the above, the present disclosure provides at least one method for assembling and combining processor instructions, an apparatus, a computer device, a computer-readable storage medium, and a computer program product.
[0005] The technical solution of this disclosure embodiment is implemented as follows: On one hand, embodiments of this disclosure provide a method for assembling processor instructions, including: Obtain the selection criteria for the target instructions to be compiled; the selection criteria for target instructions are determined based on the unique parts of the target instructions. Based on the selection criteria of the target instruction, the target syntax corresponding to the target instruction is determined from the combination syntax of the instruction set; the instruction set includes multiple instructions of the same type; the combination syntax is used to represent the format string and operand field of each of the multiple instructions. Based on the target syntax, determine the assembly text of the target instructions.
[0006] On one hand, embodiments of this disclosure provide a method for combining processor instructions, including: Based on the common parts in the instruction descriptions of multiple instructions in the instruction set, the common parent syntax of the multiple instructions is determined; the instruction set includes multiple instructions of the same type. Based on the unique parts of the instruction description, determine the sub-sentences unique to the instruction; The selection criteria for an instruction are determined based on a unique portion of the instruction description. Based on the parent syntax, the selection conditions of each instruction, and the sub-syntax, the combination syntax of the instruction set is determined.
[0007] On the other hand, embodiments of this disclosure provide an assembly apparatus for processor instructions, comprising: The acquisition module is configured to acquire selection criteria for the target instructions to be compiled; the selection criteria for the target instructions are determined based on the unique parts of the target instructions. The selection module is configured to determine the target syntax corresponding to the target instruction from the combination syntax of the instruction set based on the selection criteria of the target instruction; the instruction set includes multiple instructions of the same type; the combination syntax is used to represent the format string and operand field of each of the multiple instructions. The first processing module is configured to determine the assembly text of the target instructions based on the target syntax.
[0008] On the other hand, embodiments of this disclosure provide a processor instruction combining device, comprising: The second processing module is configured to determine the common parent syntax of multiple instructions based on the common parts in the instruction descriptions of multiple instructions in the instruction set; the instruction set includes multiple instructions of the same type. The second processing module is also configured to determine the sub-syntax unique to the instruction based on the unique part of the instruction description. The second processing module is also configured to determine the selection criteria of instructions based on a unique part of the instruction description. The combination module is also configured to determine the combination syntax of the instruction set based on the parent syntax, the selection conditions of each of the multiple instructions, and the sub-syntax.
[0009] In another aspect, embodiments of this disclosure provide a computer device, including a memory and a processor. The memory stores a computer program that can run on the processor, and the processor executes the computer program to implement some or all of the steps in the above-described method.
[0010] In another aspect, embodiments of this disclosure provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements some or all of the steps in the above-described method.
[0011] In another aspect, embodiments of this disclosure provide a computer program including computer-readable code, which, when executed in a computer device, causes a processor in the computer device to perform some or all of the steps in the above-described method.
[0012] In another aspect, embodiments of this disclosure provide a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program. When the computer program is read and executed by a computer device, it implements some or all of the steps in the above-described method.
[0013] In this embodiment, based on the selection criteria of the target instruction, the corresponding target syntax is accurately located from the combination syntax of the instruction set, and the assembly text of the target instruction is generated based on the target syntax, thus realizing the automated assembly of the target instruction. Since the combination syntax of the instruction set can represent the format strings and operand fields of multiple instructions, and its assembly syntax and encoding fields are described in the same system, it effectively solves the problem in the prior art where, due to the separate definition of assembly syntax and encoding fields, omissions, duplicates, or retention of expired content are prone to occur when the instruction undergoes local changes, thus improving the accuracy and efficiency of instruction assembly. The combination syntax of the instruction set can be expanded and modified in real time according to actual needs, improving the scalability and maintenance efficiency of the instruction set.
[0014] It should be understood that the above general description and the following detailed description are merely exemplary and explanatory, and are not intended to limit the technical solutions of this disclosure. Attached Figure Description
[0015] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the specification, serve to illustrate the technical solutions of this disclosure.
[0016] Figure 1 A schematic diagram illustrating the implementation flow of a processor instruction assembly method provided in this embodiment of the disclosure; Figure 2 A schematic diagram illustrating the processing flow of the encoded field in a processor instruction assembly method provided in this embodiment of the disclosure; Figure 3 A schematic diagram illustrating the implementation flow of a processor instruction combination method provided in an embodiment of this disclosure; Figure 4 A schematic diagram illustrating the structural composition of a processor instruction assembly device provided in an embodiment of this disclosure; Figure 5 A schematic diagram of the composition structure of a processor instruction combination device provided in an embodiment of this disclosure; Figure 6 This is a schematic diagram of the hardware entity of a computer device provided in an embodiment of this disclosure. Detailed Implementation
[0017] To make the objectives, technical solutions, and advantages of this disclosure clearer, the disclosure will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this disclosure. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0018] To make the objectives, technical solutions, and advantages of this disclosure clearer, the technical solutions of this disclosure are further described in detail below with reference to the accompanying drawings and embodiments. The described embodiments should not be regarded as limitations on this disclosure. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0019] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0020] If similar descriptions such as "first / second" appear in the application documents, the following explanation shall be added: the terms "first / second / third" are used only to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first / second / third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this disclosure described herein can be implemented in an order other than that illustrated or described herein.
[0021] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this disclosure pertains. The terminology used herein is for descriptive purposes only and is not intended to limit the scope of this disclosure.
[0022] To better understand the assembly and combination methods of processor instructions provided in the embodiments of this disclosure, the solutions in related technologies will be described below.
[0023] Current processor instruction description methods typically write the complete format for each assembly syntax directly. For example, when the same type of instruction has multiple addressing modes, multiple operand syntaxes, or multiple postfix modes, each combination is written as an independent syntax rule. Some architecture description languages support syntax non-terminal symbols or macros, but these non-terminal symbols are often only used for text reuse and lack integrated linkage with field conditions, field assignment, sample generation, assembly parsing, and disassembly selection.
[0024] For encoded fields that do not appear directly in the assembly text, the relevant techniques typically involve writing additional logic in the assembler code. For example, setting another field to B based on whether a certain field is A. If this kind of logic is scattered throughout the assembler, disassembler, documentation, and test code, it can easily lead to inconsistencies between the specification and the implementation.
[0025] The relevant technologies have at least the following problems: 1. Assembly syntax and encoding fields are described separately, and the same syntax may be interpreted repeatedly in the documentation, parser, and encoder.
[0026] 2. Once the operand order is maintained manually, the text position, instruction register (IR) field, and machine code field are prone to misbinding.
[0027] 3. When there are multiple local variations of the same type of instruction, the number of complete writing methods increases rapidly, making it easy to omit, duplicate, or retain expired branches.
[0028] 4. Fields that do not appear in the assembly code but must be written into the machine code are often derived by different tools, which can easily lead to inconsistent results.
[0029] 5. The lack of advance checks at the specification layer regarding whether a certain syntax can be matched and whether hidden fields can be determined often leads to problems only being exposed during code generation or testing phases.
[0030] This disclosure provides a method for combining processor instructions, which can be executed by a processor of a computer device. The computer device refers to a device with data processing capabilities, such as a server, laptop, tablet, desktop computer, smart TV, set-top box, or mobile device (e.g., mobile phone, portable video player, personal digital assistant, dedicated messaging device, portable gaming device). Figure 1 As shown, the method includes the following steps 101 to 104: Step 101: Based on the common parts in the instruction descriptions of multiple instructions in the instruction set, determine the common parent syntax of the multiple instructions; the instruction set includes multiple instructions of the same type.
[0031] Processor instructions refer to the smallest command units that processing units such as the Central Processing Unit (CPU) and Graphics Processing Unit (GPU) execute basic operations. An instruction set refers to a group of similar instructions with the same basic structure but differences in local details. For example, the same type of data movement instructions, although their core function is data transfer, may have multiple variations due to differences in addressing modes, the number of operands, or different modifiers.
[0032] Parent syntax refers to the syntactic structure formed by extracting common parts from the instruction descriptions of multiple instructions of the same type in an instruction set. Parent syntax can include the mnemonic base, common format string, and common operand field shared by these multiple instructions. Parent syntax defines the overall framework of the instructions, reserving placeholders (i.e., insertion points) for inserting local variations, but does not contain details unique to any specific instruction.
[0033] In some implementations, the parent syntax, also known as the root syntax, defines the structure of the complete instruction, including mnemonics, operands, operand roles, format strings, selection conditions (when conditions) for different branches, miscellaneous fields, and assignment rules for hidden fields.
[0034] In some implementations, the instruction descriptions of multiple instructions in an instruction set can be compared to identify the common parts in the instruction descriptions of the multiple instructions. The common parts may include common field values in the opcode field, common instruction format, and common operand field shared by the multiple instructions.
[0035] In some implementations, the common parent syntax of multiple instructions can be determined based on the common field values in the opcode field, the common instruction format, and the common operand field.
[0036] For example, the xsem instruction set includes the following two instructions: Instruction 1: xsem.sig dst0.mod, src0,src1; Instruction 2: xsem.abp dst0, dst1, src0, imm. Both instructions begin with xsem and contain src0 in the middle. Therefore, the common field value in the opcode field shared by both instructions is xsem; the common operand field is src0; the common instruction format can be "$0 {c0}, $1, {c1}"; {c0} and {c1} are the different parts (insertion points) between the two instructions.
[0037] Step 102: Based on the unique parts of the instruction description, determine the sub-syntax unique to the instruction.
[0038] Child syntax refers to a local syntactic structure determined by the unique part of an individual instruction that distinguishes it from other instructions in the instruction set. It supplements local details not covered in the parent syntax, ensuring the final generated instruction description is complete and accurate. Child syntax describes the unique format string, unique operand field, and insertion point within the parent syntax for each individual instruction. Child syntax does not contain the main body of the mnemonic; instead, it exists as modular fragments, filled into specified positions in the parent syntax through insertion points, thus forming a complete instruction syntax.
[0039] Sub-concepts differ from parent-concepts. Sub-concepts cannot define mnemonics, nor can they use the mnemonic placeholder $0 in the format string. Sub-concepts only declare local operands, local operand roles / types, local format strings, local when conditions, local misc fields, and local hidden field assignment rules.
[0040] In some implementations, the instruction descriptions of multiple instructions in an instruction set can be compared to obtain a unique portion of the instruction description for a single instruction. This unique portion may include the type and location of the operand field unique to the instruction, and the specific content of that operand field.
[0041] In some implementations, the unique syntax of an instruction can be determined based on the type and location of the operand field and the specific content of the operand field.
[0042] For example, the xsem command set includes the following two commands: Command 1: xsem.sig dst0.mod, src0, src1; Command 2: xsem.abp dst0, dst1, src0, imm. The common format frame for both commands can be "$0{c0}, $1, {c1}"; {c0} and {c1} are the two insertion points within the current format frame. For insertion point c0, the format string unique to command 1 can be: text: "$1"; the operand field unique to command 1 can be: operands:{name: dst0, role: dst, modifier: mod}. For insertion point c1, the format string unique to command 1 can be: text:"{c1_tail}"; the operand field unique to command 1 can be: operands: {ame: src1, role: src}. For insertion point c0, the format string unique to instruction 2 can be: text:"$1, $2"; the operand field unique to instruction 2 can be: { name: dst0, role: dst}, { name: dst1, role: dst}. For insertion point c1, the format string unique to instruction 2 can be: text: "$1"; the operand field unique to instruction 2 can be: operands:{ name: imm, role: src}.
[0043] Step 103: Determine the selection criteria for the instruction based on the unique part of the instruction description.
[0044] Selection criteria are used to uniquely identify a specific instruction in an instruction set.
[0045] In some implementations, selection criteria can be determined based on the characteristic features of a unique portion of the instruction description. These characteristic features may include, but are not limited to, instruction type, operand type, unique modifiers, and specific bit values of the opcode.
[0046] For example, the xsem instruction set includes the following two instructions: Instruction 1: xsem.sig dst0.mod, src0, src1; Instruction 2: xsem.abp dst0, dst1, src0, imm. In this case, the selection condition for each instruction can be determined based on the specific bit values of the opcode. For example, the selection condition for instruction 1 could be if: "op == sig", and the selection condition for instruction 2 could be if: "op == abp".
[0047] Step 104: Determine the combination syntax of the instruction set based on the parent syntax, the selection conditions of each instruction, and the sub-syntax.
[0048] Combinatorial syntax is a complete syntactic structure composed of parent and child syntaxes. It can include not only parent and child syntaxes and their selection conditions, but also additional field information and assignment rules for hidden fields. Combinatorial syntax is the core data structure for generating assembly text, driving the compiler backend, and disassembler.
[0049] The role of combination syntax is to provide a unified descriptive framework, supporting the traversal of all sub-syntaxes based on the parent syntax to generate a complete instruction set description. During the compilation phase, sub-syntaxes matching the selection conditions (such as opcode field values and other field values) can be dynamically activated to generate specific assembly text or machine code. Furthermore, combination syntax can also be used to automatically generate codec code, improving development efficiency.
[0050] In some implementations, the parent syntax can be combined with the sub-syntaxes of each instruction based on their respective selection conditions to obtain a combined syntax for the instruction set. In this case, the combined syntax of the instruction set includes the parent syntax common to the multiple instructions and the sub-syntax unique to each instruction.
[0051] In some implementations, the parent syntax can be combined with the child syntaxes of multiple instructions according to a preset combination order and their respective selection conditions to obtain a combined syntax for the instruction set. The preset combination order can be set in advance, such as based on the instruction number, the frequency of instruction use, and the special characteristics of the instruction.
[0052] In some implementations, the parent syntax can be combined with the child syntax of each instruction based on the selection conditions of each instruction to obtain the expansion syntax of each instruction; the combination syntax of the instruction set is then determined based on the expansion syntax of each instruction. In this case, the combination syntax of the instruction set includes the expansion syntax of each instruction.
[0053] In this embodiment, a common parent syntax for multiple instructions is determined based on the common parts of their instruction descriptions. This abstracts the common features of multiple instructions into a unified parent syntax, achieving high reusability of instruction descriptions, reducing redundant definitions, and improving the efficiency and consistency of instruction set maintenance. It also lays the foundation for the subsequent definition and combination of sub-syntaxes. Compared to the existing method of writing complete syntax rules independently for each instruction, the introduction of the parent syntax allows for focusing only on the differences when adding similar instructions, significantly reducing the size of the specification file and fundamentally avoiding structural errors caused by manual copying and pasting. A unique sub-syntax for an instruction is determined based on the unique parts of its instruction description. This defines an independent sub-syntax for each instruction, preserving its individual characteristics and allowing local changes to be managed, reused, and even nested independently. For example, if a new variant is added in the future, only a new sub-syntax fragment needs to be defined, without modifying the parent syntax or other existing variant definitions. Finally, the unique parts of the instruction description determine the selection conditions for an instruction, enabling the selection conditions to quickly locate a specific instruction in the instruction set. The combination syntax of the instruction set is determined based on the parent node, the selection conditions of multiple instructions, and the sub-syntax. This combination of the parent syntax and the sub-syntaxes of multiple instructions, based on their respective selection conditions, constructs a unified, scalable, and easily maintainable instruction description system. This achieves integrated and automated instruction set description, resolving the inconsistencies caused by the separation of syntax and encoding in existing technologies. It significantly improves the consistency and maintainability of instruction descriptions, and enhances their scalability and adaptability. Furthermore, any modification to the instruction description can be automatically and synchronously updated across all downstream artifacts (including but not limited to instruction documentation, release specifications, assembly parsing logic, disassembly printing logic, test listings, and sample generation processes) by re-executing the combination process, greatly improving the robustness of the toolchain and development efficiency.
[0054] In some embodiments, the instruction description includes an instruction format, an opcode field, and an operand field; step 101 above can be implemented by the following steps 1011 to 1014: Step 1011: Based on the common field value in the opcode field shared by multiple instructions, determine the common mnemonic shared by multiple instructions.
[0055] An instruction consists of an opcode field and several operand fields, together forming a complete instruction description. For example, in a RISC architecture, an ADD instruction might contain an opcode field and three operand fields (source register 1, source register 2, and destination register). The opcode field identifies the instruction type and operation function; its value determines the specific operation performed, such as addition, subtraction, or a jump. The operand fields specify the objects or parameters that the instruction operates on, such as register numbers, memory addresses, or immediate values. The opcode field can be a fixed-length binary string, such as 8-bit, 16-bit, or 32-bit; the operand fields can be variable-length or fixed-length fields depending on the instruction type and processor architecture.
[0056] In practical applications, the opcode field can be located in the high-order part of the instruction, and the operand field can be distributed in the low-order part. This layout helps the compiler and decoder to quickly identify the instruction type and extract the operands.
[0057] Common field values refer to the same field values in the opcode fields of multiple instructions. Common mnemonics are symbolic names shared by multiple instructions to represent the operation of an instruction, such as xsem, ADD, SUB, MOV, etc.
[0058] In some implementations, when multiple instructions have the same opcode field value, the common mnemonic of the parent syntax can be determined based on the same field value and the opcode placeholder, so that these multiple instructions can share a common mnemonic, thus forming a unified entry point for the parent syntax. For example, for two instructions in the xsem instruction set, where the opcode field of instruction 1 is xsem.sig and the opcode field of instruction 2 is xsem.abp, the common mnemonic of the parent syntax can be defined as xsem. In this case, the pseudocode of the common mnemonic of the parent syntax can be: name: xsem. <op>.
[0059] Step 1012: Based on the instruction formats of multiple instructions, determine the first format string common to the multiple instructions.
[0060] Instruction format refers to the template describing the structure of instructions in assembly text. It defines the relative positions of mnemonics and operands. The first format string, also known as the format string in the parent syntax, is a string template extracted from the instruction formats of multiple instructions, preserving common structural features while abstracting the differences. The first format string not only records the order of operands but also implicitly contains the logical connection method between operands (such as serial, parallel, or nested).
[0061] In some implementations, fixed text portions (such as commas, spaces, parentheses, etc.) remain unchanged in the first format string, while variable operand positions are represented by placeholders. Specifically, the first format string can be used to represent the relative positions of fields such as mnemonic positions, operand positions, and insertion point positions. Mnemonic positions are represented by mnemonic placeholders, operand positions by operand placeholders, and insertion point positions by insertion point placeholders. Insertion points are used to bind sub-syntax, giving subsequent sub-syntax insertions a clear semantic location. This allows new sub-syntax to be added without affecting the overall framework, enhancing the maintainability and scalability of the instruction set architecture.
[0062] In some implementations, the instruction formats of multiple instructions can be parsed, and the field position and / or width information of the multiple instructions can be extracted; based on the field position and / or width information of the multiple instructions, the format string of the parent syntax can be determined.
[0063] In some implementations, the format string of the parent syntax also supports nesting and conditional branching structures to represent selective fields, further enhancing descriptive capabilities.
[0064] Step 1013: Based on the specific content of the operand field shared by multiple instructions, determine the first operand field shared by multiple instructions.
[0065] The operand field is used to specify the data source or data destination, including registers, immediate values, memory addresses, etc. In a specific context, the content of the operand field refers to the field attributes, roles, or constraints bound to each operand slot in the common operations of the instruction group mentioned above. The first operand field refers to the set of operands located in the same position across multiple instructions and having the same semantic role and constraints.
[0066] In some implementations, the operand segments of multiple instructions can be compared sequentially to determine the operand segments that are common to all instructions and are in the same position; based on the operand segments that are common to all instructions and are in the same position, a first operand segment common to all instructions can be determined. The operand segment includes the operand name, operand role / type, and modifier.
[0067] For example, for the xsem instruction set, the operand field shared by instruction 1 and instruction 2 is src0. In this case, the operand field of the parent syntax can be described as: operands:{ name: src0, role: src}.
[0068] Step 1014: Determine the parent syntax based on the common mnemonic, the first format string, and the first operand field.
[0069] The parent syntax is a grammar object composed of a common mnemonic, a first format string, and a first operand field. The parent syntax forms the foundational framework for subsequent subsyntax insertion and the generation of the final leaf syntax. The common mnemonic provides the identifier for the instructions, determining the scope of the instruction family to which the parent syntax applies. The first format string provides the structural skeleton for the text layout, specifying the positions and number of segments during text parsing. The first operand field fills in the semantic constraints at key positions in the structural skeleton, such as imposing type and role constraints on placeholders in the format string. The common mnemonic, the first format string, and the first operand field combine to form a grammar container with well-defined boundaries and internal rules.
[0070] For example, for the xsem instruction set, the parent syntax of this instruction set can be represented as: base: name: xsem. <op>; / / Common mnemonic; text: "$0 {c0}, $1, {c1}"; / / First format string; operands: - { name: src0, role: src}; / / First operand field.
[0071] In some implementations, when a compiler or assembler processes a new instruction, it may first attempt to match an existing parent syntax. If the opcode core of the new instruction matches the common mnemonic of the parent syntax, and the text structure of the new instruction conforms to the first format string of the parent syntax, while the operands of the new instruction satisfy the constraints of the first operand field, then the new instruction is considered an instance of the parent syntax. Subsequently, the unique differences specific to the new instruction (such as specific addressing mode suffixes or modifiers) are injected as sub-syntax or local variables into the corresponding positions of the parent syntax, thereby generating a complete leaf syntax.
[0072] In this embodiment, a common mnemonic is determined based on the common field value of the opcode field shared by multiple instructions. This identifies mnemonics common to multiple instructions, facilitating unified management and description of them. The first format string in the parent syntax is determined based on the instruction formats of multiple instructions, unifying the scattered instruction formats into a standard string expression and providing a basic framework for subsequent syntax combinations. The first operand segment in the parent syntax is determined based on the specific content of the operand segment shared by multiple instructions, enabling a unified description of this shared operand segment and reducing the cost of repeatedly describing it. The parent syntax, formed based on the common mnemonic, the first format string, and the first operand segment, achieves efficient abstraction and unified description of the common features of the instruction set, thereby reducing duplicate code and maintenance costs, and ultimately improving the design flexibility and scalability of the instruction set architecture.
[0073] In some embodiments, step 1012 above can be implemented by the following steps 1012a to 1012b: Step 1012a: Based on the positions of different types of fields in the instruction format of multiple instructions, determine the different types of placeholders; the different types of fields include at least one of the opcode field and operand field common to multiple instructions, and the operand field unique to each instruction.
[0074] Different types of fields can be categorized based on their semantic roles and the scope of the instructions they belong to. The position of different types of fields refers to their linear index or relative order within the instruction format. Placeholders are abstract symbols used in the format string to represent specific field values.
[0075] In some implementations, fields in the instruction format of multiple instructions can be analyzed to determine the positions of different types of fields in the instruction format of multiple instructions; and different types of placeholders can be determined based on the positions of the different types of fields.
[0076] Step 1012b: Determine the first format string based on different types of placeholders.
[0077] In some implementations, placeholders of different types and fixed delimiters are concatenated according to the positions of different types of fields in the instruction format of multiple instructions to obtain a first format string.
[0078] In this embodiment of the disclosure, different types of placeholders are determined based on the position of different types of fields in the instruction format of multiple instructions, and the different types of placeholders are combined into a first format string. This can clearly separate the stable part (common fields) and the variable part (unique fields) in the instruction description, thereby constructing a general format template that is compatible with multiple instruction variants. This enables subsequent automated combination expansion and field binding, avoiding the risk of errors and inconsistencies caused by manually maintaining the format string line by line.
[0079] In some embodiments, different types of fields include an opcode field and an operand field common to multiple instructions, and an operand field unique to a single instruction; in this case, step 1012a above can be implemented by the following steps A1 to A4: Step A1: Use the position of the opcode field common to multiple instructions as the position of the common mnemonic, and set a common mnemonic placeholder at the position of the common mnemonic.
[0080] A common mnemonic refers to the mnemonic portion shared by all instructions in a set that share the same basic operational intent. Mnemonics are symbolic representations that are easy for humans to read, such as mov and ld. When multiple instructions belong to the same instruction set (e.g., different addressing mode variants), they often share the same root mnemonic.
[0081] A common mnemonic placeholder is a symbolic marker used to identify the location of a common mnemonic within a format string. The purpose of a common mnemonic placeholder is to reserve space for the specific command name when building a generic template. By setting a common mnemonic placeholder, the name part of the command can be decoupled from the specific parameter part. For example, $0 can be used as a common mnemonic placeholder. A common mnemonic placeholder can be a simple index variable or a macro definition with a namespace.
[0082] There is a direct mapping relationship between common mnemonic placeholders and opcode fields. The opcode field is a machine code-level concept, while the common mnemonic placeholder is an abstraction at the syntax parsing level. By mapping the position of the opcode field to the position of the common mnemonic and setting common mnemonic placeholders, semantic alignment from the underlying hardware coding to the upper-level syntax structure is achieved. For example, in a specific processor design, if three instructions, add.r, add.w, and add.d, all share the same opcode prefix, a common mnemonic placeholder will be set at the beginning of the first format string to uniformly carry the core semantic meaning of "add".
[0083] In some implementations, when processing a set of floating-point addition instructions, both single-precision and double-precision addition are included. Although the suffixes of single-precision and double-precision addition instructions differ, the core `fadd` opcode portion is shared. The location of this shared portion within the instruction format can be identified and marked as a common mnemonic region. A common mnemonic placeholder is then inserted at the location of this region. This allows subsequent instruction encoding to directly reference the common mnemonic placeholder, eliminating the need to hardcode the complete instruction name each time, thus improving code generation flexibility and maintainability.
[0084] Step A2: Take the position of the operand field common to multiple instructions as the position of the first operand field, and set a common operand placeholder at the position of the first operand field; the common mnemonic placeholder and the common operand placeholder are numbered according to the order of the corresponding fields in the instruction format; The operand field refers to the data field in an instruction used to specify the operands (such as registers, memory addresses, immediate values, etc.). In the instruction format, the operand field is usually located after the opcode field. Different instructions may contain different numbers or types of operands, but certain instruction sets may have operands with similar structures or semantics in certain locations.
[0085] The first operand field refers to the operand field shared by multiple instructions. Common operand placeholders are symbols used to identify the location of the first operand field. By setting common operand placeholders at the locations of common operands, space can be reserved in the template for filling in common operands.
[0086] The order of arrangement refers to the linear order in which the fields (including opcode, operands, etc.) appear in the instruction format. Numbering refers to assigning a unique identifier (such as an integer index) to each placeholder according to the order of arrangement. Common mnemonic placeholders and common operand placeholders can be numbered uniformly. For example, if the common mnemonic placeholder is in the first position, it is represented by $0; if the first common operand is in the second position, the second common operand placeholder is represented by $2.
[0087] In some implementations, for instruction sets with the same operand structure, the location of the common operand segment can be determined by analyzing the instruction format, and a common operand placeholder can be set at the location of the common operand segment. This method makes the alignment and mapping of operands between different instructions intuitive and efficient, improving the standardization and readability of instruction descriptions.
[0088] Step A3: Use the position of the operand field unique to the instruction as the insertion point position, and set an insertion point placeholder at the insertion point position; the insertion point placeholders are numbered according to the order of the unique operand fields in the instruction format.
[0089] An operand field unique to an instruction refers to an operand field that exists only in that instruction and is absent or structurally different in other instructions. An insertion point is a specific position within the first format string of the parent syntax used to accommodate a unique operand field. Since unique operand fields are not common to all instructions, they cannot be fixed in the first format string of the parent syntax but must be dynamically inserted when generating specific instructions. The concept of insertion points distinguishes the static template structure from dynamic instruction instances, allowing the system to flexibly add local variations while maintaining overall consistency.
[0090] Insertion point placeholders are symbols used to mark the insertion point position. They declare the insertion position of each sub-syntax corresponding to different instructions within the parent syntax, thus associating the unique operand fields of each instruction. Insertion point placeholders differ from common operand placeholders because they do not represent a fixed, globally existing field, but rather a slot. When an instruction is detected to have unique operands, the corresponding content is filled into the insertion point placeholder. For example, non-numeric or specially named placeholders such as {c0} can be used to distinguish them from ordinary $N operand placeholders.
[0091] If an instruction has multiple unique operand fields scattered in different locations, a separate insertion point placeholder is assigned to each location and numbered in the order of appearance (e.g., c0, c1, c2...). This numbering method helps to track the relative position of each insertion point in the final generated complete instruction string.
[0092] The insertion point placeholder and the common operand placeholder are complementary. The common operand placeholder deals with the invariant parts, while the insertion point placeholder deals with the variable parts. Together, the common operand placeholder and the insertion point placeholder cover all operand positions in the instruction format.
[0093] In some implementations, when the instruction set contains multiple variants of the instruction (such as the ADD instruction with immediate values and the ADD instruction with registers), the location of each instruction's unique operand field can be identified, and an insertion point placeholder can be set at the location of the unique operand field to associate it with the corresponding subsyntactic. This allows for the flexible addition of different subsyntactics within the parent syntax framework without modifying the parent syntax framework, significantly reducing maintenance costs.
[0094] Accordingly, step 1012b above can be achieved through step B1 as follows: Step B1: Determine the first format string based on the common mnemonic placeholder, the common operand placeholder, and the insertion point placeholder.
[0095] In some implementations, the common mnemonic placeholder, common operand placeholder, and insertion point placeholder can be combined according to the order of multiple fields in the instruction format and the delimiters (such as commas, spaces, and parentheses) to obtain the first format string.
[0096] For example, for the xsem instruction set, the first format string of the parent syntax can be: $0 {c0}, $1, {c1}; where $0 represents the common mnemonic placeholder, {c0} represents the first insertion point placeholder, $1 represents the common operand placeholder, and {c1} represents the second insertion point placeholder.
[0097] In this embodiment, the position of the opcode field common to multiple instructions is used as the position of the common mnemonic, and a common mnemonic placeholder is set at the position of the common mnemonic. This eliminates the need to repeatedly define the structure of the instruction name when processing a series of similar instructions; only parameter changes need to be considered. The position of the operand field common to multiple instructions is used as the position of the first operand field, and a common operand placeholder is set at the position of the first operand field. This eliminates the need to define the operand field common to multiple instructions only once when processing a series of similar instructions, avoiding multiple definitions. The position of the operand field unique to each instruction is used as the position of the insertion point, and an insertion point placeholder is set at the insertion point. This insertion point placeholder can accommodate the unique operands of different instructions. Therefore, a first format string common to multiple instructions is formed based on the common mnemonic placeholder, the common operand placeholder, and the insertion point placeholder, realizing the construction of a unified syntax framework for the instruction set. The insertion point placeholder supports flexible insertion and combination of sub-syntax, thereby improving the standardization and maintainability of instruction descriptions and reducing the complexity of instruction set architecture development and maintenance.
[0098] In some embodiments, after determining the format string in the parent syntax, the processor instruction combination method provided in this disclosure may further perform the following steps C1 to C2: Step C1: Obtain the attribute information of the common operand placeholders in the first format string and the attribute information of the insertion point placeholders in the first format string; wherein, the attribute information includes the number, quantity and sorting order.
[0099] The attribute information of the common operand placeholder is used to indicate the status of the common operands shared by multiple instructions in the first format string. The attribute information of the insertion point placeholder is used to indicate the status of the operands unique to the instruction in the second format string.
[0100] In some implementations, the first format string of the parent syntax can be parsed to extract all common operand placeholders and all insertion point placeholders, and the number, quantity, and order of the common operand placeholders, as well as the number, quantity, and order of the insertion point placeholders, can be recorded.
[0101] In some implementations, since the common operand placeholders are numbered according to the order of the common operands and the insertion point placeholders are numbered according to the order of the insertion points, the order of the common operands can be determined based on the number of the common operand placeholders, and the number of operand placeholders can be determined based on the largest number of the common operand placeholders; the order of the insertion points can be determined based on the number of the insertion point placeholders, and the number of insertion point placeholders can be determined based on the largest number of the insertion point placeholders.
[0102] Step C2: Based on the attribute information of the common operand placeholder and the insertion point placeholder, determine whether there is an anomaly in the first format string; wherein, the anomaly includes at least one of the following: an anomaly in the placeholder number, a mismatch between the number of placeholders and the number of fields in the instruction format, or a mismatch between the order of the placeholders and the order of the fields in the instruction format.
[0103] In some implementations, the number and order of common operand placeholders can be compared with the number and position order of operand segments shared by multiple instructions in the instruction set, and the number and order of insertion point placeholders can be compared with the number and position order of operand segments unique to the instruction, to determine whether there is an anomaly in the first format string.
[0104] In some implementations, it can be determined whether the number of common operand placeholders is the same as the number of operand fields shared by multiple instructions, and whether the order of the common operand placeholders is the same as the positional order of the operand fields shared by multiple instructions in the instruction format; simultaneously, it can be determined whether the number of insertion point placeholders is the same as the operand fields unique to the instruction, and whether the order of the insertion point placeholders is the same as the positional order of the operand fields unique to the instruction in the instruction format; if the number of common operand placeholders is the same as the number of operand fields shared by multiple instructions, the order of the common operand placeholders is the same as the positional order of the operand fields shared by multiple instructions in the instruction format, the number of insertion point placeholders is the same as the operand fields unique to the instruction, and the order of the insertion point placeholders is the same as the positional order of the operand fields unique to the instruction in the instruction format, then it is determined that there is no anomaly in the format string of the parent syntax. If the number of common operand placeholders is different from the number of operand fields shared by multiple instructions, or the order of common operand placeholders is different from the positional order of operand fields shared by multiple instructions in the instruction format, or the number of insertion point placeholders is different from the operand fields unique to the instruction, or the order of insertion point placeholders is different from the positional order of operand fields unique to the instruction in the instruction format, then the format string in the parent syntax is determined to be abnormal.
[0105] In some implementations, the anomaly detection of the first format string in the parent syntax can be performed automatically by the detection tool to ensure the standardization and consistency of the first format string. Furthermore, specific detection results can be output, such as insufficient number of common operand placeholders or disordered insertion point placeholder order, helping developers quickly locate and fix problems.
[0106] In this embodiment, by obtaining the attribute information of the common operand placeholders and the insertion point placeholders in the first format string, and performing anomaly detection on the first format string based on these attribute information, structural errors in the first format string can be detected in advance. This ensures that the structure of the first format string is consistent with the layout of the actual fields in the instruction, effectively preventing instruction combination failures caused by errors in the first format string description, thereby improving the accuracy and reliability of the instruction set architecture description.
[0107] In some embodiments, the instruction description includes an operand field; step 102 above can be implemented by the following steps 1021 to 1024: Step 1021: Determine the second format string unique to the instruction based on the type and position of the operand field unique to the instruction.
[0108] The operand field type can include, but is not limited to, register-type, memory-type, and immediate-type operand fields; the position of the operand field refers to its order in the instruction format. The second format string is a format string unique to a single instruction, used to describe the layout structure of this unique part of the instruction.
[0109] In some implementations, the type and location of the operand field unique to the instruction can be identified; and a second format string can be automatically selected based on the type and location of the operand field unique to the instruction. For example, when processing floating-point arithmetic instructions, %fp_reg can be used as the format string for the insertion point; while when processing displacement instructions, %shift_imm can be used.
[0110] In some implementations, when the unique operand field is of type target operand, the second format string of the instruction's unique sub-syntax is determined based on the representation of the operand placeholders and the position of the unique operand field in the first format string. For example, if the unique operand field is dst0 and is located after the common mnemonic placeholder in the first format string, the second format string of the corresponding sub-syntax can be set to $1.
[0111] In some implementations, when the unique operand field is of type source operand, the second format string of the instruction's unique subsyntactic is determined based on the insertion point placeholder and position identifier corresponding to the unique operand field. For example, if the unique operand field is src1, the corresponding insertion point placeholder is c1, and the unique operand field is at the end of the first format string (the end position identifier is tail), then the format string of the corresponding subsyntactic can be set to c1_tail.
[0112] Step 1022: Based on the specific content of the operand field unique to the instruction, determine the second operand field unique to the instruction; the operand field in the sub-syntax should include at least one of the identifier, type, and modifier of the corresponding operand.
[0113] The second operand field is a unique operand field for each instruction.
[0114] In some implementations, the second operand field unique to the instruction can be determined based on the operand identifier, type, and modifiers of the operand field unique to the instruction. For example, if the unique operand field is dst0, then the second operand field in the corresponding sub-syntax can be represented as: operands: - { name: dst0, role: dst, modifier: mod}; Where name represents the operand name, role represents the operand role, and modifier represents the operand modifier.
[0115] In some implementations, if the second format string of the instruction-unique sub-syntax is determined based on the insertion point placeholder and position identifier corresponding to the instruction-unique operand field, then the second format string of the instruction-unique sub-syntax is used as an intermediate insertion point, and the instruction-unique second operand field is determined based on the intermediate insertion point and the instruction-unique operand field. For example, if the unique operand field is src1, then the operand field in the corresponding sub-syntax can be represented as: c1_tail: text: "$1" operands: - { name: src1, role: src}; Where c1_tail is the insertion point, text represents the format string of the insertion point, and operands represents the operands of the format string.
[0116] Step 1023: Determine the insertion point corresponding to the second operand segment based on the position of the operand segment unique to the instruction.
[0117] The insertion point is a reserved position in the first format string to indicate the specific location where the subsyntactic should be embedded. In complex instruction sets, different variations of an instruction often differ only in certain local areas; these differing areas are the insertion points. The determination of the insertion point depends on the relative position of the operand fields within the instruction format.
[0118] Step 1024: Determine the sub-syntax of the instruction based on the second format string, the second operand field, and the corresponding insertion point.
[0119] In some implementations, the second format string, the second operand field, and the corresponding insertion point can be combined according to the order of description of the sub-syntax to obtain the instruction sub-syntax.
[0120] In this embodiment, a second format string is automatically generated based on the type and position of the operand segment unique to the instruction; a second operand segment is automatically generated based on the specific content of the operand segment unique to the instruction; and the insertion point corresponding to the second operand is determined based on the position of the operand segment unique to the instruction. Thus, the sub-syntax of the instruction is obtained based on the second format string, the second operand segment, and the corresponding insertion point. This transforms the unique part of the instruction description into a structured local syntax object, avoiding inconsistencies that arise from manually maintaining format templates and field bindings. Furthermore, it ensures that documentation, assembly parsing, disassembly selection, and test cases are all generated and processed based on the same accurate set of local syntax information, significantly improving the development efficiency and reliability of the processor instruction set toolchain.
[0121] In some embodiments, step 1024 above can be implemented by the following steps 1024a to 1024b: Step 1024a: For any insertion point, determine the sub-syntax of the insertion point based on the second format string and the second operand field corresponding to the insertion point; the parent syntax includes multiple insertion points; the multiple insertion points are numbered according to the order of the operand fields of each instruction in the instruction format.
[0122] When an instruction has multiple operand fields, the first format string includes multiple insertion points. In this case, the sub-syntax of the insertion point can be determined first based on the second format string and the second operand field corresponding to the insertion point. Then, the sub-syntaxes of the multiple insertion points corresponding to the instruction can be combined according to the numbers of the multiple insertion points to obtain all the sub-syntaxes of the instruction.
[0123] In some implementations, the second format string and the second operand field corresponding to the insertion point can be combined based on the insertion point to obtain the sub-syntax of the insertion point.
[0124] For example, for instruction 1 in the xsem instruction set: xsem.sig dst0.mod, src0, src1; with the first format string "$0 {c0}, $1, {c1}", the subsyntactic of the first insertion point c0 can be represented as: c0: text: "$1"; operands: - { name: dst0, role: dst, modifier: mod}.
[0125] Step 1024b: Combine the sub-syntaxes of the multiple insertion points corresponding to the instruction according to the numbers of the multiple insertion points, and use the combined sub-syntaxes as the sub-syntaxes of the instruction.
[0126] In some implementations, the sub-syntax of multiple insertion points corresponding to an instruction can be combined in ascending order of their numbers to obtain the instruction's sub-syntax.
[0127] For example, for instruction 1 in the xsem instruction set: xsem.sig dst0.mod, src0, src1; the first format string is "$0 {c0}, $1, {c1}", which includes two insertion points. Therefore, instruction 1 corresponds to two subsyntaxes, which can be represented as: c0: text: "$1"; operands: - { name: dst0, role: dst, modifier: mod}; c1: text: "{c1_tail}"; children: c1_tail: text: "$1"; operands: - { name: src1, role: src}.
[0128] In this embodiment, the sub-syntax of the insertion point is first determined based on the second format string and the second operand field corresponding to the insertion point. Then, the sub-syntaxes of multiple insertion points corresponding to the instruction are combined according to the numbers of multiple insertion points to obtain all the sub-syntaxes of the instruction. In this way, complex instruction variants can be decomposed into independent local modules for management, thereby avoiding the problems of missing branches or duplicate generation that are easy to occur when manually enumerating complete syntax. This enables the automatic generation of all legal complete instruction syntax objects and ensures that the text format, operand field, selection conditions, and hidden field assignment rules remain consistent across all products.
[0129] In some embodiments, step 103 above can be implemented by the following steps 1031 to 1032: Step 1031: Based on the unique part of the instruction description, determine the distinguishing features of the instruction; the distinguishing features are the characteristic features that distinguish the instruction from other instructions in the instruction set.
[0130] Differential characteristics are key attributes extracted from the unique parts of the instruction description that can uniquely or significantly identify an instruction. Differential characteristics can be specific values of a single field (such as the difference value in the opcode field), instruction type, unique operands, or combined constraints of multiple fields (such as the source operand must be an immediate value and the destination operand must be a register).
[0131] In some implementations, manual screening can be used to select distinctive and representative features from the unique parts of the instruction description. Alternatively, model-based screening can be used to select distinctive and representative features from the unique parts of the instruction description.
[0132] Step 1032: Determine the selection criteria for instructions based on the differences in instruction characteristics.
[0133] In some implementations, the differences in instructions can be directly used as the selection criteria for instructions. Alternatively, the selection criteria can be determined based on the differences in instructions and the attribute information of the instructions. Or, the differences in instructions can be optimized based on the attribute information of the instructions to obtain the selection criteria.
[0134] In this embodiment, representative difference features are first determined based on the unique parts of the instruction description, and then selection conditions are determined based on these difference features. This decomposes the complex instruction differentiation logic into two clear stages: feature extraction and condition construction. This ensures that the selection conditions closely match the essential differences between the instructions, avoiding the introduction of irrelevant or redundant judgment factors. Consequently, it improves the accuracy and efficiency of instruction matching and selection, and reduces coding errors or disassembly ambiguities caused by ambiguous conditions.
[0135] In some embodiments, step 104 above can be implemented by the following steps 1041 to 1044: Step 1041: Renumber the placeholders in the first format string according to the position of the different types of placeholders in the first format string of the parent syntax to obtain the expanded format string.
[0136] Renumbering refers to the process of uniformly numbering all placeholders in the first format string according to their order of appearance. This process aims to eliminate potential index jumps or irregularities in the original definition, ensuring a strict one-to-one correspondence between the placeholder indices in the generated expanded format string and the order of the actual operand list. The expanded format string is the format string after renumbering. The expanded operand field contains not only the first operand field of the parent syntax but also the second operand field inserted by the sub-syntax, and each operand field retains metadata such as operand name, role (src / dst / src_dst), and modifiers.
[0137] Compared to the first format string, all placeholders in the expanded format string have been replaced with consecutive ordinal numbers, and the insertion point marker is no longer included. Instead, the complete text structure after the insertion subsyntactic content is directly presented.
[0138] For example, if the first format string is "$0 {c0}, $1, {c1}", then the expanded format string is "$0 $1, $2, $3", which correspond to the common mnemonic, the first operand, the second operand, and the third operand, respectively.
[0139] Step 1042: Based on the expanded format string, the second mapping relationship, and the third mapping relationship, determine the expanded operand field of the instruction; wherein, the second mapping relationship is used to characterize the correspondence between the first operand field in the parent syntax and the common operand placeholder, and the third mapping relationship is used to characterize the correspondence between the second operand field of each sub-syntax of the instruction and the insertion point placeholder.
[0140] The second mapping records the correspondence between the first operand field in the parent syntax and the common operand placeholders in the first format string. For example, if the parent syntax defines an operand named "src0" and represents it using "$1" in the format string, then the second mapping contains the correspondence between "$1" and the operand named "src0". The second mapping ensures that the first operand field in the parent syntax can be accurately matched with the common operand placeholders during expansion.
[0141] The third mapping records the correspondence between the second operand field in the sub-syntax and the insertion point placeholder in the first format string. For example, if the sub-syntax of insertion point c0 defines two operands "dst0" and "dst1", then the third mapping contains the correspondence between c0 and the two operands "dst0" and "dst1".
[0142] Expanding the operand field refers to the operand field formed by combining the first operand field in the parent syntax and the second operand field in the instruction's child syntax according to the placeholders in the expanded format string.
[0143] In some implementations, for each operand placeholder in the expanded string with a new index (e.g., 1 to n), if the new index's position originates from a common operand placeholder in the parent syntax, the corresponding first operand segment is found using a second mapping; if the new index's position originates from the insertion point of the sub-syntax, the corresponding second operand segment is found using a third mapping. The found first operand segments and the found second operand segments are then combined into the expanded operand segment according to the order of the new indices.
[0144] Step 1043: Determine the instruction expansion syntax based on the instruction's selection criteria, common mnemonic, expansion format string, and expansion operand field.
[0145] In some implementations, the instruction's selection conditions, common mnemonics, expansion format strings, and expansion operand fields can be combined according to a preset expansion order to obtain the instruction's expansion syntax.
[0146] For example, for instruction 1 in the xsem instruction set: xsem.sig dst0.mod, src0, src1, the selection condition for instruction 1 is: if: "op == sig".
[0147] The parent syntax of instruction 1 is: base: name: xsem. <op>; text: "$0 {c0}, $1, {c1}"; operands: - { name: src0, role: src}; The sub-syntax of instruction 1 is: if: "op == sig"; children: c0: text: "$1"; operands: - { name: dst0, role: dst, modifier: mod}; c1: text: "{c1_tail}"; children: c1_tail: text: "$1"; operands: - { name: src1, role: src}.
[0148] The expanded syntax of instruction 1 is: if: "op == sig"; name: xsem. <op>; text: "$0 $1, $2, $3"; operands: - { name: dst0, role: dst, modifier: mod}; - { name: src0, role: src}; - { name: src1, role: src}.
[0149] Step 1044: Determine the combination syntax of the instruction set based on the expansion syntax of each instruction.
[0150] In some implementations, the expansion syntax of multiple instructions can be combined according to their numbers to obtain a combined syntax for the instruction set. Alternatively, the expansion syntax of multiple instructions can be combined according to their predetermined order to obtain a combined syntax for the instruction set.
[0151] For the xsem instruction set, an example of its instruction set composition syntax is as follows: instr: xsem; fields: visible: [dst0, dst1, src0, src1, imm, op]; hidden: [trig]; base: if: "op == sig"; name: xsem. <op>; text: "$0 $1, $2, $3"; operands: - { name: dst0, role: dst, modifier: mod}; - { name: src0, role: src}; - { name: src1, role: src}; base: if: "op == abp"; name: xsem. <op>; text: "$0 $1, $2, $3, $4"; operands: - { name: dst0, role: dst}; - { name: dst1, role: dst}; - { name: src0, role: src}; - { name: imm, role: src}.
[0152] In this embodiment, placeholders in the first format string are renumbered to obtain the expanded format string. The expanded operand field of the instruction is automatically inferred based on the expanded format string, the second mapping relationship, and the third mapping relationship. The expanded syntax of the instruction is formed based on the instruction's selection conditions, common mnemonics, the expanded format string, and the expanded operand field. The combined syntax of the instruction set is formed by aggregating the expanded syntaxes of multiple instructions. This automatically resolves the issues of operand order disorder and field misbinding when combining multiple local variations, ensuring consistency between the assembly text, intermediate representation fields, and machine code fields under a single data source. This significantly reduces the risks of missed branches, duplicate definitions, and information drift between multiple artifacts caused by manually maintaining multiple independent syntax rules, thereby improving the efficiency and reliability of processor instruction set architecture development.
[0153] In some embodiments, step 1042 above can be implemented by the following steps 1042a to 1042b: Step 1042a: Update the second and third mapping relationships based on the expanded format string.
[0154] In some implementations, based on the expanded format string, the correspondence between the first operand field and the common operand placeholder in the first format string in the second mapping relationship is updated to the correspondence between the first operand field and the operand placeholder in the expanded format string, resulting in an updated second mapping relationship. Based on the expanded format string, the correspondence between the second operand field and the insertion point placeholder in the first format string in the third mapping relationship is updated to the correspondence between the second operand field and the operand placeholder in the expanded format string, resulting in an updated third mapping relationship.
[0155] Step 1042b: Based on the updated second mapping relationship and the updated third mapping relationship, describe the specific content of the first operand segment in the parent syntax and the specific content of the second operand segment in the target sub-syntax of each of the multiple instructions in turn to obtain the expanded operand segments of each of the multiple instructions.
[0156] In some implementations, based on the updated second and third mapping relationships, the specific contents of the first operand segment in the parent syntax and the second operand segment in the target subsyntactic of each instruction are described sequentially according to the order in which the operand placeholders appear in the expanded format string, so as to obtain the expanded operand segments of each instruction.
[0157] In this embodiment, the second and third mapping relationships are dynamically updated based on the expanded format string. Based on the updated second and third mapping relationships, the first operand segment of the parent syntax and the second operand segment of the child syntax are sequentially integrated to obtain the expanded operand segment. This eliminates the risk of misbinding text positions, IR fields, and machine code fields caused by manually maintaining the operand order. This ensures that the same assembly language uses completely consistent field interpretation in the documentation, parser, encoder, and test cases, thereby significantly reducing the drift risk between multiple products and improving the automation and reliability of the instruction set architecture toolchain.
[0158] In some embodiments, such as Figure 2 As shown, the processor instruction combination method provided in this embodiment further includes the following steps 201 to 204: Step 201: Obtain all fields in the instruction description of multiple instructions.
[0159] In some implementations, all fields in the instruction descriptions of multiple instructions can be extracted, and duplicate fields can be removed.
[0160] Step 202: Based on all fields and the types of all fields, determine the encoding fields of the combination syntax; the encoding fields shall include at least one of the visible fields, hidden fields, and extended fields.
[0161] Visible fields are those that appear directly in the assembly instruction text and can be parsed by the assembler and are visually apparent to the user. The purpose of visible fields is to establish a direct mapping between human-readable assembly language and the machine's internal representation, ensuring that user-written code can be correctly parsed.
[0162] Hidden fields are fields that do not appear in the standard assembly text but must be written into specific fields during machine code encoding or need to be deduced during disassembly. Examples include postfix flags for certain instructions and implicit operation mode bits. The purpose of hidden fields is to carry control information that is transparent to the user but crucial to hardware execution, keeping the assembly text concise while enriching the functionality of the machine code.
[0163] Extension fields are additional fields used to support instruction set extensions, debugging features, or future compatibility. Extension fields are not defined in the base instruction set but take effect under specific extension modes. Their purpose is to provide flexibility and scalability, allowing new instruction functionalities or diagnostic capabilities to be added without breaking the infrastructure.
[0164] In some implementations, all fields can be divided into three categories based on their type: visible fields, hidden fields, and extended fields.
[0165] In some implementations, a manual screening method can be used to classify all fields into three categories: visible fields, hidden fields, and extended fields, based on their type. Alternatively, a list of visible fields, a list of hidden fields, and a list of extended fields can be pre-defined; and all fields can be classified into these three categories based on these lists.
[0166] For example, for the xsem instruction set, the encoded field of the combination syntax can be represented as: fields: visible: [dst0, dst1, src0, src1, imm, op]; hidden: [trig]; Wherein, visible is the visible field, and hidden is the hidden field.
[0167] Step 203: When determining the first operand field of the parent syntax and the second operand fields of each sub-syntax of the instruction, directly reference the visible fields and / or extended fields to set the specific content of the corresponding operand field.
[0168] In some implementations, if the parent syntax requires a destination operand, a field of type dst and marked as visible can be automatically found and used as the first operand field. Similarly, if a subsyntactic requires a specific immediate value, the corresponding extended field can be referenced as the second operand field.
[0169] The direct referencing mechanism ensures consistency between operand fields and actual encoded fields. For example, in an instruction supporting multiple addressing modes, the parent syntax defines the basic register operands, while the child syntax defines the offsets. In this way, the generated composite syntax automatically carries the correct field binding information, avoiding the problem of misbinding text positions with IR fields.
[0170] Step 204: When determining the subsyntax of an instruction with a hidden field, reference the hidden field to add the assignment rule of the hidden field after the subsyntax of the instruction.
[0171] Assignment rules refer to logical expressions or conditional statements that define how to calculate or determine the value of a hidden field. For example, if the operand is an immediate value, the hidden field type can be set to 1; otherwise, it can be set to 0. Assignment rules can exist in the form of field=value or if field=value.
[0172] In some implementations, when the instruction variant corresponding to a subsyntax involves a hidden field, the hidden field determined in step 902 can be referenced, and the relevant assignment rules can be appended to the subsyntax. Specifically, a set-hidden or similar attribute can be added after the description of the subsyntax, and the set-hidden or similar attribute contains the evaluation logic for the hidden field.
[0173] For example, for the xsem.abp variant, if the hidden field trig needs to be set to true when matching the xsem.abp variant, then the rule trig: true is added after the description of the subsyntax. This way, when the subsyntax is composed into the final leaf grammar object, the assignment rule for trig: true is also preserved.
[0174] In some implementations, after parsing the visible fields, the assembler can sequentially execute the assignment rules contained in the currently matched sub-syntax to calculate the values of the hidden fields and write these values into the intermediate representation (IR). For example, when parsing `xsem.abp dst0, dst1, src0, imm`, if the sub-syntax contains the rule `trig: true`, the `trig` field in the IR is set to true. This process of calculating and writing the hidden field values eliminates the need for complex derivation logic to be manually written in the assembler code, thus ensuring consistency between documentation, specifications, and implementation.
[0175] In this embodiment, by pre-acquiring and classifying all fields before combination expansion, the encoded fields, including visible fields, hidden fields, and extended fields, are determined. This allows for direct reference to the corresponding fields when determining the operand fields of the parent and child syntaxes, ensuring precise binding between operand positions and field definitions. Furthermore, it enables the automatic attachment of assignment rules for hidden fields when determining the child syntax, resulting in a generated combination syntax that not only includes text formatting but also carries complete encoding and implicit field evaluation logic. This achieves unified management and consistency assurance of assembly text, IR fields, and machine code fields at the specification layer.
[0176] In some embodiments, the processor instruction combination method provided in this disclosure further includes at least one of the following detection operations: The first detection operation involves performing anomaly detection on the common mnemonics, the first format string, and the first operand field in the parent syntax.
[0177] Performing anomaly detection on the parent syntax can ensure the standardization and stability of the parent syntax as the instruction set skeleton, and avoid the failure of the entire instruction set assembly or the generation of incorrect assembly code due to errors in the basic structure.
[0178] In some implementations, anomaly detection can be performed on the integrity, consistency, and grammatical correctness of the parent syntax, such as checking whether the common mnemonics of the parent syntax conform to preset rules, and whether there are any anomalies such as missing or incorrectly numbered placeholders in the first format string.
[0179] In some implementations, if an anomaly is detected, an alarm or repair process is immediately triggered. For example, during the compilation phase, if a parent syntax is found to be missing a necessary insertion point placeholder, the parent syntax is determined to be abnormal, preventing subsequent child syntaxes from failing to embed correctly.
[0180] Operation 2: Perform anomaly detection on the second format string, the second operand field, and the insertion point in the sub-syntax.
[0181] Performing anomaly detection on sub-syntax can ensure that sub-syntax can be accurately and legally embedded into parent syntax, improve the accuracy and reliability of instruction combination, and reduce compilation failures or runtime exceptions caused by factor syntax errors.
[0182] In some implementations, anomaly detection can be performed on the legality, completeness, and matching of the insertion point of the sub-syntax. For example, it can check whether the operand type of the sub-syntax supports the requirements of the insertion point in the parent syntax, whether the field length in the sub-syntax is compliant, and whether the format string in the sub-syntax is consistent with the parent syntax.
[0183] In some implementations, the insertion point definition of the sub-syntax can be compared with that of the corresponding parent syntax. If the operand field type in the sub-syntax does not match the operand type required by the insertion point, it is considered an exception. For example, if the insertion point of the parent syntax requires a register type operand, but the operand type provided by the sub-syntax is an immediate type, it is considered an exception.
[0184] The third step in the detection process is to perform anomaly detection on the visibility of all fields in the combined syntax.
[0185] Field visibility refers to the attribute of whether fields (such as opcodes, operands, hidden fields, etc.) in the parent syntax are exposed or accessible in the final machine code during instruction encoding. Anomaly detection of field visibility in the parent syntax ensures the coding standardization and security of the instruction set, prevents coding ambiguities or security vulnerabilities caused by incorrect field visibility configuration in the parent syntax, and improves the professionalism and maintainability of instruction set design.
[0186] In some implementations, anomaly detection is performed on the field visibility of the parent syntax, mainly to determine whether the field visibility declaration of the parent syntax is reasonable and whether the visibility settings conform to the design specifications, such as whether there are fields that should be hidden that are incorrectly marked as visible.
[0187] In some implementations, the visibility of each field in the parent syntax can be validated according to the instruction set specification. For example, if a hidden field is incorrectly configured to be visible in the parent syntax, the assembler may incorrectly output the hidden field to the assembly text, resulting in a syntax error or confusing the developer.
[0188] Detection Operation 4: Perform anomaly detection on the selection conditions corresponding to the sub-syntax.
[0189] Anomaly detection of the selection conditions of sub-sentences can ensure that the selection logic of sub-sentences is clear and unambiguous, avoid multiple selection or omission problems in the instruction combination process, and improve the predictability and execution efficiency of the instruction set.
[0190] In some implementations, the selection conditions of each sub-syntax can be parsed and logically reasoned. If the selection condition expression of a sub-syntax contains undefined variables, syntax errors, or condition conflicts (such as two sub-syntaxes simultaneously satisfying the same condition), it is determined to be an anomaly. For example, if the selection conditions of two sub-syntaxes are both opcode == 0x0A, then a conflict exists, and modification should be prompted.
[0191] Fifth, perform anomaly detection on the assignment norms of the parent and child syntaxes respectively.
[0192] Assignment validity in parent and child syntax refers to whether the assignment operations of each field in the parent and child syntax conform to requirements such as data type, value range, and encoding standards. For example, the values of operand fields must be within the allowed range (e.g., register numbers 0 to 31), and the assignment of hidden fields must follow preset rules (e.g., derived from the values of other fields). Performing anomaly detection on assignment validity in both parent and child syntax ensures data consistency and correctness during instruction encoding, prevents hardware malfunctions or software crashes caused by illegal assignments, and enhances the robustness and reliability of the instruction set.
[0193] In some implementations, anomaly detection is performed on the legality of assignments in the parent and child syntaxes, including checking whether field assignments in the parent and child syntaxes are out of bounds, violate coding constraints, or depend on uninitialized fields.
[0194] In some implementations, each assignment operation can be validated based on the type and constraints defined in the field definition. For example, if an operand field is assigned the value 32, while the maximum allowed value for that field is 31, it is considered an out-of-bounds exception; if the assignment of a hidden field depends on a parent syntactic field that has not yet been determined, it is considered a dependency exception.
[0195] In this embodiment, anomaly detection is performed on both the parent and child syntaxes to ensure structural correctness; anomaly detection is performed on the field visibility of the parent syntax to ensure coding standardization; anomaly detection is performed on the selection conditions of the child syntax to ensure the rationality of logical branches; and anomaly detection is performed on the assignment validity in both the parent and child syntaxes to ensure instruction executableness at the data level. These detection steps complement each other, forming a multi-layered, comprehensive quality assurance mechanism that jointly supports efficient and reliable instruction set design and implementation. This allows for the early identification and avoidance of potential design flaws and coding errors, significantly improving the accuracy and robustness of the instruction set description, and consequently ensuring the stability and reliability of subsequent compilation, assembly, and hardware execution processes.
[0196] This disclosure provides an assembly method for processor instructions, which can be executed by the processor of a computer device. For example... Figure 3 As shown, the method includes the following steps 301 to 303: Step 301: Obtain the selection criteria for the target instructions to be compiled; the selection criteria for the target instructions are determined based on the unique parts of the target instructions.
[0197] The target instruction is the instruction to be compiled.
[0198] In some implementations, after obtaining the combination syntax of the instruction set, the selection conditions of multiple instructions in the instruction set can be recorded separately, such as storing the selection conditions of multiple instructions in the instruction set in a table according to the instruction number; in this way, after obtaining the target instruction to be compiled, the selection conditions of the target instruction can be retrieved from the table according to the target instruction number.
[0199] In some implementations, the criteria for determining instruction selection conditions can be pre-stored; thus, the selection conditions for the target instruction to be compiled can be determined in real time based on these criteria. For example, the unique characteristics of the instruction can be determined based on the unique parts of the instruction description of the target instruction, and the selection conditions for the target instruction can be determined based on these unique characteristics.
[0200] Step 302: Based on the selection criteria of the target instruction, determine the target syntax corresponding to the target instruction from the combination syntax of the instruction set; the instruction set includes multiple instructions of the same type; the combination syntax is used to represent the format string and operand field of each of the multiple instructions.
[0201] The target syntax consists of the parent and child syntaxes corresponding to the target instruction.
[0202] In some implementations, the combination syntax of the instruction set includes the syntax of each of the multiple instructions; the target syntax corresponding to the target instruction can be located from the combination syntax of the instruction set by using the selection condition of the target instruction as an index.
[0203] Step 303: Determine the assembly text of the target instructions based on the target syntax.
[0204] In some implementations, the target syntax can be converted into assembly text of target instructions based on the syntax type of the target syntax.
[0205] In this embodiment, based on the selection criteria of the target instruction, the corresponding target syntax is accurately located from the combination syntax of the instruction set, and the assembly text of the target instruction is generated based on the target syntax, thus realizing the automated assembly of the target instruction. Since the combination syntax of the instruction set can represent the format strings and operand fields of multiple instructions, and its assembly syntax and encoding fields are described in the same system, it effectively solves the problem in the prior art where, due to the separate definition of assembly syntax and encoding fields, omissions, duplicates, or retention of expired content are prone to occur when the instruction undergoes local changes, thus improving the accuracy and efficiency of instruction assembly. The combination syntax of the instruction set can be expanded and modified in real time according to actual needs, improving the scalability and maintenance efficiency of the instruction set.
[0206] In some embodiments, step 302 above can be implemented by the following step 3021: Step 3021: When the combination syntax of the instruction set includes the expansion syntax of multiple instructions, based on the selection conditions of the target instruction, determine the target expansion syntax corresponding to the target instruction from the combination syntax of the instruction set; the expansion syntax of the instruction is determined based on the parent syntax common to multiple instructions and the child syntax unique to the instruction; the target syntax includes the target expansion syntax.
[0207] The target expansion syntax is a unique and determined expansion syntax selected from the combination syntax of the instruction set based on the selection criteria of the target instruction (such as specific opcode values, register types, etc.). The target expansion syntax is the direct data source for subsequent generation of assembly text.
[0208] In some implementations, the expansion syntax of multiple instructions includes selection conditions for multiple instructions; thus, the target expansion syntax corresponding to the target instruction can be determined from the combined syntax of the instruction set containing the expansion syntax of multiple instructions, based on the selection conditions of the target instruction.
[0209] Accordingly, the target expansion syntax includes common mnemonics, expansion format strings, and expansion operand fields; step 303 above can be implemented through the following steps 3031 to 3032: Step 3031: Determine the instruction mnemonic of the target instruction based on the selection conditions and common mnemonic of the target instruction.
[0210] In some implementations, if the selection criteria for the target instruction include the difference field value in the opcode field unique to the target instruction, then the difference field value in the opcode field unique to the target instruction and the common mnemonic can be combined to obtain the instruction mnemonic of the target instruction.
[0211] In some implementations, if the selection criteria for the target instruction do not include the difference field value in the opcode field unique to the target instruction, the difference field value in the opcode field unique to the target instruction can be determined based on the selection criteria for the target instruction; the difference field value in the opcode field unique to the target instruction and the common mnemonic are combined to obtain the instruction mnemonic of the target instruction.
[0212] For example, the difference field value in the opcode field unique to the target instruction can be directly filled into the opcode placeholder in the common mnemonic to obtain the instruction mnemonic of the target instruction.
[0213] For example, the selection condition for the target instruction is if: "op == sig", and the common mnemonic is: name: xsem. <op>The instruction mnemonic for the target instruction is xsem.sig.
[0214] Step 3032: Fill the instruction mnemonic in the target expansion syntax into the mnemonic placeholder in the expansion format string, and fill the expansion operand field in the target expansion syntax into the operand placeholder in the expansion format string in sequence to obtain the assembly text of the target instruction.
[0215] Here, padding refers to the process of replacing the corresponding placeholders in the expanded format string with specific content.
[0216] For example, the expanded format string of the target instruction is Where $0 is a mnemonic placeholder; $1, $2, and $3 are placeholders for the three operands; the mnemonic for the target instruction is xsem.sig, and the expanded operand field of the target instruction is... ; ; Then the assembly text of the target instruction is: .
[0217] In this embodiment, since the instruction set's combination syntax includes the expansion syntax of multiple instructions, the target expansion syntax corresponding to the target instruction can be directly determined from the instruction set's combination syntax based on the target instruction's selection criteria, achieving rapid location of the target expansion syntax. Since the target expansion syntax includes a common mnemonic, an expansion format string, and an expansion operand field, the assembly text of the target instruction can be quickly obtained by simply filling the common mnemonic and the expansion operand field into the expansion format string, achieving rapid conversion from modular syntax definition to instruction assembly text. This ensures that the order, type, and internal field binding relationships of operands in the generated assembly text are always accurate, eliminating the risk of incorrect field binding caused by manually maintaining multiple versions of instruction templates. Furthermore, it ensures that the assembler, disassembler, and documentation generation tools use the same consistent set of instruction semantics, improving the reliability of the entire toolchain.
[0218] In some embodiments, step 302 above can also be implemented by the following step 3033: Step 3033: When the combination syntax of the instruction set includes a parent syntax common to multiple instructions and a sub-syntax unique to each instruction, based on the selection conditions of the target instruction, determine the target sub-syntax and parent syntax corresponding to the target instruction from the combination syntax of the instruction set; the parent syntax includes the format string and operand field common to multiple instructions, and the sub-syntax includes the format string and operand field unique to each instruction; the target syntax includes the parent syntax and the target sub-syntax.
[0219] The target clause method is a clause method unique to target instructions.
[0220] In some implementations, if the combination syntax of the instruction set includes a parent syntax common to multiple instructions and a sub-syntax unique to each instruction, the parent syntax can be directly determined from the combination syntax of the instruction set, and the target sub-syntax corresponding to the target instruction can be determined from the combination syntax of the instruction set based on the selection criteria of the target instruction.
[0221] Accordingly, step 303 above can also be implemented through the following step 3033: Step 3033: Based on the insertion point of the target sub-syntax, combine the target sub-syntax and the parent syntax to obtain the assembly text of the target instruction.
[0222] In some implementations, based on the insertion point of the target subsyntactic, the instruction mnemonic of the target instruction, the operand field in the target subsyntactic, and the operand field in the parent syntax are directly filled into the format string in the parent syntax to obtain the assembly text of the target instruction.
[0223] In some implementations, the target sub-syntax and parent syntax are first expanded based on the insertion point of the target sub-syntax to obtain the target expanded syntax of the target instruction, and then the assembly text of the target instruction is determined based on the target expanded syntax.
[0224] In this embodiment, since the instruction set's composition syntax includes a parent syntax common to multiple instructions and a sub-syntax unique to each instruction (i.e., the instruction set's composition syntax includes the unexpanded syntax of multiple instructions), the assembly text of the target instruction is obtained by first determining the target sub-syntax corresponding to the target instruction from the instruction set's composition syntax based on the target instruction's selection criteria, and then combining the parent and sub-syntaxes based on the insertion point of the target sub-syntax. This achieves automated conversion from modular syntax definition to instruction assembly text. This ensures that the order, type, and internal field binding relationships of operands in the generated assembly text are always accurate, eliminating the risk of incorrect field binding caused by manually maintaining multiple versions of instruction templates. Furthermore, it ensures that the assembler, disassembler, and documentation generation tools use the same consistent set of instruction semantics, improving the reliability of the entire toolchain.
[0225] In some embodiments, step 3033 described above can be implemented by the following steps D1 to D3: Step D1: Determine the instruction mnemonic of the target instruction based on the selection conditions of the target instruction and the common mnemonic in the parent syntax.
[0226] Here, step D1 corresponds to the aforementioned step 3031. When implementing it, the specific implementation of the aforementioned step 3031 can be referred to, and this embodiment will not be described in detail here.
[0227] In some implementations, if the selection criteria for the target instruction include the difference field value in the opcode field unique to the target instruction, then the difference field value in the opcode field unique to the target instruction and the common mnemonic can be combined to obtain the instruction mnemonic of the target instruction.
[0228] Step D2: Based on the insertion points of each target subsyntactic, determine the first mapping relationship between the second operand field of each target subsyntactic and the insertion point placeholders in the parent syntax.
[0229] The first mapping relation is used to indicate the positions in the first format string of the parent syntax where the operand fields in each target subsyntax should be filled. For example, the first mapping relation might specify that the dst0 field in subsyntax A corresponds to the {c0} position in the first format string, and the src1 field in subsyntax A corresponds to the {c1} position in the first format string.
[0230] There is a spatial and content correspondence between the insertion point and the second operand field. The insertion point provides the spatial coordinates of where to place it, while the second operand field provides the content entity of what to place it in.
[0231] In some implementations, the establishment of the first mapping relationship can be automated: the order of insertion points in the parent syntax can be scanned, while the declaration order of operand fields in each target subsyntactic can be scanned, and alignment and binding can be performed according to the position index. This automatic mapping mechanism avoids misalignment errors that are prone to occur when manually maintaining operand numbers, and ensures the consistency of text position, IR field, and machine code field.
[0232] For example, in the abp variant of the XSEM instruction, the parent syntax has two insertion points, {c0} and {c1}. The sub-syntax c0 defines dst0 and dst1, and the sub-syntax c1 defines imm. The mappings dst0->c0, dst1->c0 (subsequent position), and imm->c1 can be automatically established to ensure the correct order of the final text.
[0233] Step D3: Fill the instruction mnemonic of the target instruction into the common mnemonic placeholder in the parent syntax, fill the specific content of the first operand field in the parent syntax into the common operand placeholder in the parent syntax, and based on the first mapping relationship, fill the specific content of the second operand field of each target sub-syntax into the insertion point placeholder in the parent syntax to obtain the assembly text of the target instruction.
[0234] The padding here refers to the process of replacing the corresponding placeholders in the first format string with specific content. The padding process is not simply text concatenation; it also involves renumbering the operand fields. Because after an operand field is inserted into the sub-syntax, the insertion point placeholder in the parent syntax changes to the specific operand field. At this point, the parent syntax no longer contains the insertion point placeholder but instead contains all the operand fields corresponding to the instruction. Therefore, during the padding process, the numbering of all operand fields needs to be recalculated based on the final arrangement order to ensure that the generated assembly text conforms to the syntax rules.
[0235] For example, if the first format string corresponding to the target instruction is: text: "$0 {c0}, $1, {c1}", the target subsyntactic corresponding to the target instruction is: children: c0: text: "$1" operands: - { name: dst0, role: dst, modifier: mod} c1: text: "{c1_tail}" children: c1_tail: text: "$1" operands: - { name: src1, role: src}; At this point, we need to replace $0 with xsem.sig, $1 with src0, {c0} with dst0.mod, and {c1} with src1; thus, we obtain the assembly text of the target instructions: .
[0236] In this embodiment, the instruction mnemonic of the target instruction, the specific content of the first operand field in the parent syntax, and the specific content of the second operand field of the target sub-syntax are directly filled into the corresponding placeholders in the first format string of the parent syntax in sequence, thereby automatically generating the assembly text of the target instruction. This can significantly reduce the manual enumeration work during instruction assembly, avoid omissions or duplicate definitions, and enable the use of data from the same source for documentation, spec, assembly parsing, disassembly selection, and test cases. This can reduce the drift risk between multiple artifacts and improve development efficiency and maintenance quality.
[0237] In some embodiments, step 3033 above can be implemented by the following steps E1 to E2: Step E1: Based on the insertion point of each target sub-syntax, expand and describe each target sub-syntax and its parent syntax to obtain the target expanded syntax of the target instruction.
[0238] Expanding the description refers to the process of replacing the abstract insertion point in the parent syntax with the operand segment in the specific child syntax.
[0239] In some implementations, the placeholders in the first format string can be renumbered according to the position of different types of placeholders in the first format string of the parent syntax to obtain the expanded format string; based on the expanded format string, the first mapping relationship and the second mapping relationship, the expanded operand field of the target instruction is determined; based on the selection conditions of the target instruction, the common mnemonic, the expanded format string and the expanded operand field, the expanded syntax of the target instruction is determined.
[0240] In some implementations, the specific way to determine the expanded operand segment of the target instruction can be as follows: based on the expanded format string, update the first mapping relationship and the second mapping relationship respectively; based on the updated first mapping relationship and the updated second mapping relationship, describe the specific content of the first operand segment in the parent syntax and the specific content of the second operand segment in the target sub-syntax in turn to obtain the expanded operand segment of the target instruction.
[0241] Step E2: Based on the target expansion syntax, determine the assembly text of the target instruction.
[0242] In some implementations, the instruction mnemonic of the target instruction can be determined based on the selection conditions and common mnemonics of the target instruction; the instruction mnemonic in the target expansion syntax is filled into the mnemonic placeholders in the expansion format string, and the expansion operand field in the target expansion syntax is sequentially filled into the operand placeholders in the expansion format string to obtain the assembly text of the target instruction.
[0243] In this embodiment, by dividing the composition description process into two steps—expansion description and text determination—automatic conversion from modular syntax definition to instruction assembly text is achieved. This method ensures seamless merging of parent and child syntax in operand order, thereby automatically generating accurate and unambiguous complete syntax objects. This eliminates issues such as branch omissions, operand misbinding, and inconsistencies between multiple products caused by manual enumeration, significantly improving the efficiency and reliability of the toolchain for instruction set architecture definition. Furthermore, dividing the composition description process into expansion description and text determination steps allows for timely location and handling of anomalies in the instruction assembly text.
[0244] In some embodiments, step 303 above can also be implemented by the following steps F1 to F3: Step F1: If the target instruction contains hidden fields, determine the scope of the hidden fields and the assignment rules.
[0245] The scope of application refers to the range within which the assignment rules for a hidden field are executed only when specific conditions are met. An assignment rule is a logical expression that establishes a mapping between the value of a hidden field and known variables (such as properties of visible operands, values of other fields, or constants). Assignment rules can be simple constant assignments (e.g., field = 1) or complex logic that depends on other fields.
[0246] In some implementations, a mapping table between instructions and hidden fields can be pre-defined; thus, the effective scope and assignment rules of the hidden fields corresponding to the target instruction can be determined from the mapping table based on the number of the target instruction.
[0247] Step F2: Based on the target syntax, determine the assembly text to be determined for the target instructions.
[0248] The assembly text to be determined refers to the assembly text of the target instructions that have not been written into the hidden fields.
[0249] In some implementations, if the target syntax is a target expansion syntax, the instruction mnemonic of the target instruction can be determined based on the selection conditions of the target instruction and the common mnemonic; the instruction mnemonic in the target expansion syntax is filled into the mnemonic placeholder in the expansion format string, and the expansion operand field in the target expansion syntax is sequentially filled into the operand placeholder in the expansion format string to obtain the assembly text to be determined for the target instruction.
[0250] In some implementations, if the target syntax consists of a parent syntax and a target sub-syntax, the target sub-syntax and the parent syntax can be combined and described based on the insertion point of the target sub-syntax to obtain the assembly text to be determined for the target instruction.
[0251] Step F3: According to the determination order of different types of fields in the target syntax, based on the effective scope and assignment rules of the hidden fields, write the hidden fields into the assembly text to be determined, and obtain the assembly text of the target instructions.
[0252] The order in which different types of fields are determined refers to the sequential logic that should be followed when processing the various components of an instruction. The order can be: process visible fields and additional fields first, then process hidden fields. This is because the value of a hidden field often depends on the values of the visible and additional fields determined in previous steps, or the results of conditional judgments. This order ensures the unidirectionality and determinism of the data flow, avoiding circular dependencies or undefined behavior. A write operation does not refer to modifying the user-visible assembly text, but rather to assigning values at the data structure level in memory. For example, if the assignment rule determines that the hidden field `trig` should be 1, the compiler frontend will store the binary value 1 in the `trig` member variable of the IR object so that the subsequent encoder can convert the binary value 1 into a binary stream of machine code. Writing refers to the process of filling the corresponding bit width of the hidden field into the internal intermediate representation (IR) or machine code encoding buffer.
[0253] In this embodiment, by introducing explicit definitions of the effective scope and assignment rules of hidden fields during the assembly text generation process, and writing the hidden fields into the intermediate representation under unified sequence control, the logical consistency between invisible encoded fields and visible fields in the assembly text can be ensured. This avoids inconsistencies caused by the assembler, disassembler, or documentation independently deriving hidden fields, thereby improving the maintainability of the instruction set specification, the reliability of the toolchain, and the efficiency of hardware-software co-design.
[0254] The following describes the application of the processor instruction combination method provided in the embodiments of this disclosure in a real-world scenario.
[0255] The technical problem that this disclosure can solve at least is: to keep the values of visible text, operand fields, selection conditions and implicit fields consistent when there are local changes in assembly syntax and hidden encoded fields, and to ensure that the documentation, spec, assembler, disassembler selection and test cases use the same and unique source.
[0256] The purpose of this disclosure is to provide a method for combining processor instructions. This method does not simply reuse assembly text, but rather processes the assembly syntax, operand fields, field roles, selection conditions, and hidden encoded field values within the same definition chain. The combination of parent and child syntaxes generates a complete leaf syntax object that is used by subsequent documentation, parsing, disassembly, encoding, and testing.
[0257] This disclosure addresses a specific syntactic combination generation mechanism: during the combination process, it automatically determines the operand positions, selects conditions and additional fields, retains the assignment rules for hidden fields, and fills in the fields required by the machine code but not present in the text according to the rules after assembly parsing.
[0258] This disclosure actually solves the problem of how to maintain consistency between assembly text, IR fields, and machine code fields. The technical effects include: the same assembly syntax is interpreted using the same fields in all products; operands are not misbound due to manual numbering; local variation combinations do not miss branches; hidden coded fields are evaluated by unified rules; and problems such as invisible or ununique fields can be detected in advance at the specification level.
[0259] The technical solution disclosed herein includes the following steps.
[0260] 1. Parent Syntax Definition: A single instruction can define and bind several parent syntaxes. Each parent syntax defines the complete instruction's mnemonic, operands, operand roles, format string, when condition (corresponding to selection condition), misc field, and hidden field assignment rules, among other structures. In the format string, $0 represents the mnemonic position, and $1 to $N represent the operand positions in sequence; it can also contain one or more child insertion points. Assembly text positions and field information are placed in the same structure from the beginning.
[0261] 2. Sub-sentence definition: Unlike root / parent syntax, sub-sentence cannot define mnemonics, nor can it use $0 in the format string; it only declares local operands, local operand types, local format strings, local when conditions, local misc fields, and local hidden field assignment rules.
[0262] 3. Sub-syntax Grouping: Sub-syntax grouping is used to establish the correspondence between "insertion points" and sub-syntaxes. If the parent syntax has only one child insertion point, then any sub-syntax represents a local form of that child position. If the parent syntax contains multiple child insertion points, multiple sets are created according to the order in which the insertion points appear in the parent format string. Each set contains sub-syntaxes corresponding to multiple child insertion points, representing a local form of the parent syntax. This clearly distinguishes between "multiple choices at the same position" and "independent variations at different positions," preventing two unrelated local variations from being mixed into the same syntax branch.
[0263] 4. Insertion Position Inference: Scan the parent format string for the order of the $N placeholder and child elements. Determine the insertion position of each child syntax based on the number of parent operands (corresponding to the first operand segment mentioned above). Simultaneously check if the order of parent operand placeholders satisfies the consecutive order or total number of $1 to $N. This proactively exposes potential binding / expansion errors.
[0264] 5. Combinatorial Expansion: The parent syntax iterates through the optional options in multiple sub-syntax groups, extracting all possible collocations for each group. If a sub-syntax also has its own sub-syntax, it is expanded level by level. Ultimately, each collocation generates a leaf syntax (corresponding to the expansion description of the above instructions), i.e., a complete leaf syntax object. For each leaf syntax, a new operand list is first constructed, and sub-operands (corresponding to the second operand segment mentioned above) are inserted at the specified insertion positions, while the parent operand is preserved. The src / dst / src_dst roles of all operands are retained. This method allows for the unified generation of complete syntax for any new local modification, eliminating the need for manual completion.
[0265] 6. Placeholder Renumbering: First, scan the order of occurrence of $1 to $N and the CHILD insertion point in the parent format string to determine the position of each group of child operands in the parent operand list. Then, renumber them starting from 1 according to the operand order of the final leaf syntax, and record the mapping from the old index to the new index for both the parent operand and each child operand. $0 in the parent format string always points to the mnemonic, while the placeholders ($1...$N) in the parent and child format strings are rewritten according to this mapping.
[0266] 7. Combining Conditions and Additional Fields: The selection condition of the leaf syntax is a logical AND of the selection condition of the parent syntax and the selection conditions of all child syntaxes. The misc field of the leaf syntax is the parent misc field appended with the child misc field. The hidden field assignment rules of the leaf syntax are appended to the parent rule, maintaining the declaration order. This way, the combination of parent and child syntaxes not only yields the text format but also a complete set of fields that can drive encoding, disassembly selection, and sample generation.
[0267] 8. Field binding: After the leaf syntax is generated, it will be bound to the current instruction. All field names referenced in the leaf syntax will be replaced with the field objects in this instruction.
[0268] 9. Assembly Parsing: When generating assembly text parsing logic, matching rules are first generated based on the format string, component, modifier, and misc fields of the leaf syntax. After parsing the assembly text, the values of visible and conditional fields are obtained, and then the hidden field assignment rules are executed sequentially. When the condition of a certain assignment rule is true, the specified hidden field is written into the assembly IR, so that encoded fields that do not appear in the assembly text can also obtain definite machine code values, avoiding different products from deriving hidden fields independently.
[0269] 10. Product Generation Module: The expanded leaf syntax can be incorporated into subsequent workflows, including but not limited to the generation of instruction documents, release specifications, assembly parsing logic, disassembly printing logic, test lists, and samples. Original field linkage information is also incorporated into the field assignment descriptions in the release specifications, ensuring that documents, specifications, parsing, printing, and testing use the same source.
[0270] The specific embodiments provided in this disclosure are described below: An abstract instruction set XSEM is constructed for the purpose of illustrating this method only and does not correspond to real ISA instructions.
[0271] The explicit fields of the XSEM instruction set are dst0 / dst1 / src0 / src1 / imm / op, and the implicit field is trig. The XSEM instruction set includes two instructions, meaning it supports two syntaxes: Command 1: `xsem.sig dst0.mod, src0, src1`; Command 2: `xsem.abp dst0, dst1, src0,imm`. Both begin with `xsem` and include `src0` in the middle. The changes are placed at the two child insertion points, `c0` and `c1`. This can be represented by the following naive configuration; this format only describes the data relationship and does not limit the specific implementation or API: instr: xsem; fields: visible: [dst0, dst1, src0, src1, imm, op]; hidden: [trig]; base: name: xsem. <op>; text: "$0 {c0}, $1, {c1}"; operands: - { name: src0, role: src}; cases: - if: "op == sig"; children: c0: text: "$1"; operands: - { name: dst0, role: dst, modifier: mod}; c1: text: "{c1_tail}"; children: c1_tail: text: "$1"; operands: - { name: src1, role: src}; - if: "op == abp"; children: c0: text: "$1, $2"; operands: - { name: dst0, role: dst}; - { name: dst1, role: dst}; c1: text: "$1" operands: - { name: imm, role: src}; set-hidden: trig: true wherein, name: xsem. <op>The `op` directive determines whether the suffix is `sig` or `abp`. `$0` is the mnemonic position, `$1` is `src0` in the root notation, and `{c0}` and `{c1}` are two local insertion points. Each `child` is a fragment object of the same type; you can directly provide `text / operands` or continue to include `children`.
[0272] When op is sig, c0 expands to dst0.mod, and c1 expands further to src1, resulting in: xsem.sigdst0.mod, src0, src1; When op is abb, c0 expands to dst0, dst1, and c1 expands to imm, resulting in: xsem.abp dst0,dst1, src0, imm; When expanding, the tool processes the child operands layer by layer, starting from the parent syntax, and renumbers them uniformly. For example, in the ABP syntax, the final operand order is dst0, dst1, src0, imm, and the field bindings are generated in this order, eliminating the need for manual re-maintenance of the numbering.
[0273] `trig` does not appear in the assembly text, but the machine code requires it. `set-hidden` means that `trig=true` is set when matching the `abp` syntax; the `sig` syntax does not trigger this assignment. Therefore, the same definition simultaneously overrides text composition, field binding, and hidden field evaluation.
[0274] The unfolded form: instr: xsem; fields: visible: [dst0, dst1, src0, src1, imm, op]; hidden: [trig]; base: if: "op == sig"; name: xsem. <op>; text: "$0 $1, $2, $3"; operands: - { name: dst0, role: dst, modifier: mod}; - { name: src0, role: src}; - { name: src1, role: src}; base: if: "op == abp"; name: xsem. <op>; text: "$0 $1, $2, $3, $4"; operands: - { name: dst0, role: dst}; - { name: dst1, role: dst}; - { name: src0, role: src}; - { name: imm, role: src}; set-hidden: trig: true; The expanded spec defines the roles of each part in the assembler, compiler, and RTL: 1. if condition: The conditional logical AND of the parent syntax and the combined child syntax limits the selection field values applicable to the complete leaf syntax object. The assembler uses this to match valid syntax and completes the fields that can be determined by the single-valued condition; the compiler backend uses this to select the valid instruction encoding form; RTL does not evaluate this condition, but only decodes the field values that are finally written into the machine code.
[0275] 2. `text` (format string): `$0` indicates the mnemonic position, and `$1` to `$N` indicate the order of the final operands after renumbering. The assembler uses this to generate text matching rules and binds the text positions to the assembly IR fields; the compiler backend can then output the standard assembly text; RTL does not consume text formatting.
[0276] 3. Name (Mnemonic): Contains the main mnemonic and its modifier fields, defining the instruction name, suffix, and display tokens for corresponding fields. The assembler uses it to identify and parse instructions, and the compiler backend uses it to output assembly or select the appropriate instruction form; RTL does not recognize mnemonics, only receiving the corresponding machine code.
[0277] 4. operands: Defines the operand fields, operand roles (src, dst, or src_dst), and their modifier fields; after subsyntactic insertion, their list order is the final text operand order. The assembler fills the assembly IR in this order, and the compiler backend completes operand mapping and instruction downscaling based on roles; the RTL decodes the machine code bits of each operand field, but does not reinterpret their text order or roles.
[0278] 5. misc field: Defined as...<FIELD=value> The non-operational numeric field is appended to the assembly text. The assembler generates its optional key-value parsing, and the compiler backend can output this appended field according to the same rules; when this field is encoded, RTL only decodes it according to its field position, without processing the text key-value form.
[0279] 6. Set-hidden (Hidden Field Assignment Rule): Can be composed of `field=value`, and its scope is determined by the `if` condition of the corresponding complete leaf syntax object. After parsing visible fields, the assembler writes implicitly encoded fields into the assembly IR (Intermediate Representation) in the order of declaration; the compiler backend must apply the same rule when directly constructing the IR; RTL (Registry Transfer Language) only reads the encoded implicit fields and does not repeatedly perform assignments or condition deductions. Static verification simultaneously ensures the validity of the assignment target and that the relevant condition fields are visible or uniquely identifiable.
[0280] The disclosed technical solution has at least the following beneficial effects: 1. The IR and machine code fields within the same assembly syntax and assembler come from the same leaf syntax object, reducing inconsistencies caused by repeated interpretations.
[0281] 2. Operand positions are uniformly renumbered and bound by the tool to avoid errors in IR fields or machine code fields even when the text position is correct.
[0282] 3. Multiple sets of local changes are automatically combined and expanded, reducing the generation of legal code, duplicate generation, or old branch residue.
[0283] 4. Encoded fields that do not appear in the assembly text are evaluated using a unified rule to avoid separate derivation by the assembler, disassembler, spec, and sample generator.
[0284] 5. Issues such as invisible fields, undeterminable conditions, and illegal assignment targets can be exposed in advance during the standardization review stage.
[0285] 6. Documents, specs, parsing, printing, and test samples share the same expansion result, reducing the risk of multi-product drift.
[0286] This disclosure has at least the following key points and points that need to be protected: 1. Combine the assembly text frame, operand field, selection criteria, additional fields, and hidden field assignment rules into a complete leaf syntax object, which serves as the common source for subsequent products.
[0287] 2. Combine and expand multiple local code groups to generate all valid and complete codes, avoiding missed branches or old branch remnants caused by manual enumeration.
[0288] 3. Declare the insertion position of the local syntax through the child insertion point, and bind the text position, operand field, and field role together.
[0289] 4. Based on the order of placeholders in the parent format string and the child insertion point, automatically infer the insertion position and renumber the operands to avoid incorrect field binding.
[0290] 5. During the combination process, merge the parent-child selection conditions, additional fields, and hidden field assignment rules to ensure that each complete statement has complete encoding information.
[0291] 6. After assembly parsing, hidden field assignments are performed in the order of declaration, and the encoded fields not appearing in the text are deduced from the parsed fields.
[0292] 7. Perform static validation on local syntax structure, field visibility, condition decidability, and assignment validity to expose expansion and coding risks in advance.
[0293] Compared with the closest related technologies, this disclosure has at least the following technical advantages: 1. Compared with macro substitution or include that only generates assembly text, this disclosure simultaneously preserves the assignment rules for operand fields, conditions, additional fields, and hidden fields.
[0294] 2. Compared with the manual enumeration method, this disclosure reduces the omission of branches and the misbinding of operand segments.
[0295] 3. Compared to manually writing hidden field derivations in the assembler, this disclosure puts the hidden field rules back into the instruction specification, making the documentation, spec, C++ parsing and test cases use the same source, and performing visibility and assignment validity checks before generating code.
[0296] Based on the foregoing embodiments, this disclosure provides a processor instruction assembly apparatus, which includes the included units and the modules included in each unit, which can be implemented by a processor in a computer device; of course, it can also be implemented by specific logic circuits; in the implementation process, the processor can be a central processing unit (CPU), a microprocessor unit (MPU), a digital signal processor (DSP), or a field-programmable gate array (FPGA), etc.
[0297] Figure 4 This is a schematic diagram illustrating the structural composition of an assembly device for processor instructions provided in an embodiment of the present disclosure, as shown below. Figure 4 As shown, the processor instruction assembler 400 includes: a fetch module 410, a select module 420, and a first processing module 430, wherein: The acquisition module 410 is configured to acquire selection criteria for the target instructions to be compiled; the selection criteria for the target instructions are determined based on the unique parts of the target instructions. The selection module 420 is configured to determine the target syntax corresponding to the target instruction from the combination syntax of the instruction set based on the selection criteria of the target instruction; the instruction set includes multiple instructions of the same type; the combination syntax is used to represent the format string and operand field of each of the multiple instructions. The first processing module 430 is configured to determine the assembly text of the target instructions based on the target syntax.
[0298] In some embodiments, the selection module 420 is further configured to: when the combination syntax of the instruction set includes the expansion syntax of multiple instructions, determine the target expansion syntax corresponding to the target instruction from the combination syntax of the instruction set based on the selection conditions of the target instruction; the expansion syntax of the instruction is determined based on the parent syntax common to multiple instructions and the child syntax unique to the instruction; the target syntax includes the target expansion syntax; Accordingly, the target expansion syntax includes a common mnemonic, an expansion format string, and an expansion operand field; the first processing module 430 is further configured to: determine the instruction mnemonic of the target instruction based on the selection conditions of the target instruction and the common mnemonic; fill the instruction mnemonic in the target expansion syntax into the mnemonic placeholders in the expansion format string, and sequentially fill the expansion operand field in the target expansion syntax into the operand placeholders in the expansion format string to obtain the assembly text of the target instruction.
[0299] In some embodiments, the selection module 420 is further configured to: when the combination syntax of the instruction set includes a parent syntax common to multiple instructions and a sub-syntax unique to each instruction, determine the target sub-syntax and parent syntax corresponding to the target instruction from the combination syntax of the instruction set based on the selection criteria of the target instruction; the parent syntax includes a format string and operand field common to multiple instructions, and the sub-syntax includes a format string and operand field unique to each instruction; the target syntax includes the parent syntax and the target sub-syntax. Accordingly, the first processing module 430 is also configured to: combine and describe the target sub-syntax and the parent syntax based on the insertion point of the target sub-syntax to obtain the assembly text of the target instruction.
[0300] In some embodiments, the first processing module 430 is further configured to: determine the instruction mnemonic of the target instruction based on the selection conditions of the target instruction and the common mnemonic in the parent syntax; determine the first mapping relationship between the second operand field of each target sub-syntax and the insertion point placeholder in the parent syntax based on the insertion point of each target sub-syntax; fill the instruction mnemonic of the target instruction into the common mnemonic placeholder in the parent syntax, fill the specific content of the first operand field in the parent syntax into the common operand placeholder in the parent syntax, and fill the specific content of the second operand field of each target sub-syntax into the insertion point placeholder in the parent syntax based on the first mapping relationship, thereby obtaining the assembly text of the target instruction.
[0301] In some embodiments, the first processing module 430 is further configured to: expand and describe each target sub-syntax and its parent syntax based on the insertion point of each target sub-syntax to obtain the target expanded syntax of the target instruction; and determine the assembly text of the target instruction based on the target expanded syntax.
[0302] In some embodiments, the first processing module 430 is further configured to: determine the effective scope and assignment rules of the hidden fields when the target instruction contains hidden fields; determine the assembly text to be determined of the target instruction based on the target syntax; and write the hidden fields into the assembly text to be determined according to the determination order of different types of fields in the target syntax, based on the effective scope and assignment rules of the hidden fields, to obtain the assembly text of the target instruction.
[0303] Based on the foregoing embodiments, this disclosure provides a processor instruction combination device, which includes the included units and the modules included in each unit, which can be implemented by a processor in a computer device; of course, it can also be implemented by specific logic circuits; in the implementation process, the processor can be a central processing unit (CPU), microprocessor (MPU), digital signal processor (DSP) or field programmable gate array (FPGA), etc.
[0304] Figure 5 This is a schematic diagram of the composition structure of a processor instruction combination device provided in an embodiment of the present disclosure, such as... Figure 5 As shown, the processor instruction combination device 500 includes: a second processing module 510 and a combination module 520, wherein: The second processing module 510 is configured to determine the common parent syntax of multiple instructions based on the common parts in the instruction descriptions of multiple instructions in the instruction set; the instruction set includes multiple instructions of the same type. The second processing module 510 is also configured to determine the sub-syntax unique to the instruction based on the unique part of the instruction description. The second processing module 510 is also configured to determine the selection criteria of the instruction based on a unique part of the instruction description. Combination module 520 is also configured to determine the combination syntax of the instruction set based on the parent syntax, the selection conditions of each of the multiple instructions, and the sub-syntax.
[0305] In some embodiments, the instruction description includes an instruction format, an opcode field, and an operand field; the second processing module 510 is further configured to: determine a common mnemonic shared by multiple instructions based on the common field value in the opcode field shared by multiple instructions; determine a first format string shared by multiple instructions based on the instruction format of multiple instructions; determine a first operand field shared by multiple instructions based on the specific content of the operand field shared by multiple instructions; and determine a parent syntax based on the common mnemonic, the first format string, and the first operand field.
[0306] In some embodiments, the second processing module 510 is further configured to: determine different type placeholders based on the positions of different type fields in the instruction format of multiple instructions; the different type fields include at least one of the opcode field and operand field common to multiple instructions and the operand field unique to the instruction; and determine a first format string based on the different type placeholders.
[0307] In some embodiments, the second processing module 510 is further configured to: use the position of the opcode field common to multiple instructions as the position of the common mnemonic, and set a common mnemonic placeholder at the position of the common mnemonic; use the position of the operand field common to multiple instructions as the position of the first operand field, and set a common operand placeholder at the position of the first operand field; number the common mnemonic placeholder and the common operand placeholder according to the order of the corresponding fields in the instruction format; use the position of the operand field unique to each instruction as the position of the insertion point, and set an insertion point placeholder at the position of the insertion point; number the insertion point placeholder according to the order of the unique operand field in the instruction format; and determine a first format string based on the common mnemonic placeholder, the common operand placeholder, and the insertion point placeholder.
[0308] In some embodiments, the second processing module 510 is further configured to: obtain attribute information of common operand placeholders in the first format string and attribute information of insertion point placeholders in the first format string; wherein the attribute information includes number, quantity, and arrangement order; and determine whether there is an anomaly in the first format string based on the attribute information of the common operand placeholders and the attribute information of the insertion point placeholders; wherein the anomaly includes at least one of the following: an anomaly in the placeholder number, a mismatch between the number of placeholders and the number of fields in the instruction format, and a mismatch between the arrangement order of placeholders and the arrangement order of fields in the instruction format.
[0309] In some embodiments, the second processing module 510 is further configured to: determine a second format string unique to the instruction based on the type and position of the operand field unique to the instruction; determine a second operand field unique to the instruction based on the specific content of the operand field unique to the instruction; the operand field in the sub-syntax includes at least one of the identifier, type, and modifier of the corresponding operand; determine the insertion point corresponding to the second operand field based on the position of the operand field unique to the instruction; and determine the sub-syntax of the instruction based on the second format string, the second operand field, and the corresponding insertion point.
[0310] In some embodiments, the second processing module 510 is further configured to: for any insertion point, determine the sub-syntax of the insertion point based on the second format string and the second operand field corresponding to the insertion point; the parent syntax includes multiple insertion points; the multiple insertion points are numbered according to the arrangement order of the operand fields unique to each instruction in the instruction format; the sub-syntaxes of the multiple insertion points corresponding to the instruction are combined according to the numbering of the multiple insertion points, and the combined sub-syntax is used as the sub-syntax of the instruction.
[0311] In some embodiments, the second processing module 510 is further configured to: determine the distinguishing features of an instruction based on a unique portion of the instruction description; the distinguishing features are characteristic features that differentiate an instruction from other instructions in the instruction set; and determine the selection conditions of the instruction based on the distinguishing features.
[0312] In some embodiments, the combination module 520 is further configured to: renumber the placeholders in the first format string according to the positions of different types of placeholders in the first format string of the parent syntax to obtain an expanded format string; determine the expanded operand field of the instruction based on the expanded format string, a second mapping relationship, and a third mapping relationship; wherein the second mapping relationship is used to characterize the correspondence between the first operand field and the common operand placeholder in the parent syntax, and the third mapping relationship is used to characterize the correspondence between the second operand field of the instruction's sub-syntax and the insertion point placeholder; determine the expanded syntax of the instruction based on the instruction's selection conditions, common mnemonics, expanded format string, and expanded operand field; and determine the combination syntax of the instruction set based on the expanded syntax of each of the multiple instructions.
[0313] In some embodiments, the combination module 520 is further configured to: update the second mapping relationship and the third mapping relationship respectively based on the expanded format string; and describe the specific content of the first operand segment in the parent syntax and the specific content of the second operand segment in the child syntax of each of the multiple instructions in turn based on the updated second mapping relationship and the updated third mapping relationship, so as to obtain the expanded operand segment of each of the multiple instructions.
[0314] In some embodiments, the second processing module 510 is further configured to: obtain all fields in the instruction description of multiple instructions; determine the encoding fields of the combined syntax based on all fields and the types of all fields; the encoding fields include at least one of visible fields, hidden fields, and extended fields; when determining the first operand field of the parent syntax and the second operand field of each sub-syntax of the instruction, directly reference the visible fields and / or extended fields to set the specific content of the corresponding operand field; when determining the sub-syntax of the instruction with hidden fields, reference the hidden fields to add the assignment rules of the hidden fields to the sub-syntax of the instruction.
[0315] The descriptions of the apparatus embodiments above are similar to those of the method embodiments above, and have similar beneficial effects. In some embodiments, the functions or modules included in the apparatus provided in this disclosure can be used to perform the methods described in the method embodiments above. For technical details not disclosed in the apparatus embodiments of this disclosure, please refer to the descriptions of the method embodiments of this disclosure for understanding.
[0316] It should be noted that, in the embodiments of this disclosure, if the above methods are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this disclosure, or the parts that contribute to related technologies, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods of the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks. Thus, the embodiments of this disclosure are not limited to any specific hardware, software, or firmware, or any combination of hardware, software, and firmware.
[0317] This disclosure provides a computer device including a memory and a processor. The memory stores a computer program that can run on the processor. When the processor executes the program, it implements some or all of the steps in the above-described method.
[0318] This disclosure provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements some or all of the steps in the above-described method. The computer-readable storage medium can be transient or non-transient.
[0319] This disclosure provides a computer program including computer-readable code. When the computer-readable code is executed in a computer device, a processor in the computer device performs some or all of the steps in the above-described method.
[0320] This disclosure provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program. When the computer program is read and executed by a computer device, it implements some or all of the steps in the above-described method. This computer program product can be implemented specifically through hardware, software, or a combination thereof. In some embodiments, the computer program product is specifically embodied as a computer storage medium; in other embodiments, the computer program product is specifically embodied as a software product, such as a software development kit (SDK), etc.
[0321] It should be noted that the descriptions of the various embodiments above tend to emphasize the differences between them, while their similarities or commonalities can be referenced interchangeably. The descriptions of the above embodiments of the device, storage medium, computer program, and computer program product are similar to the descriptions of the above method embodiments and have similar beneficial effects. For technical details not disclosed in the embodiments of the device, storage medium, computer program, and computer program product of this disclosure, please refer to the descriptions of the method embodiments of this disclosure for understanding.
[0322] It should be noted that, Figure 6 This is a schematic diagram of a hardware entity of a computer device in an embodiment of this disclosure, such as... Figure 6 As shown, the hardware entity of the computer device 600 includes: a processor 601, a communication interface 602, and a memory 603, wherein: Processor 601 typically controls the overall operation of computer device 600.
[0323] Communication interface 602 enables computer devices to communicate with other terminals or servers via a network.
[0324] The memory 603 is configured to store instructions and applications executable by the processor 601, and can also cache data to be processed or already processed (e.g., image data, audio data, voice communication data, and video communication data) in the processor 601 and various modules in the computer device 600. It can be implemented using flash memory or random access memory (RAM). Data transfer between the processor 601, the communication interface 602, and the memory 603 can be performed via bus 604.
[0325] It should be understood that the phrase "an embodiment" or "one embodiment" throughout the specification means that a specific feature, structure, or characteristic related to the embodiment is included in at least one embodiment of this disclosure. Therefore, "in one embodiment" or "one embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. It should be understood that in the various embodiments of this disclosure, the sequence numbers of the above steps / processes do not imply a sequential order of execution; the execution order of each step / process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this disclosure. The sequence numbers of the above embodiments of this disclosure are merely descriptive and do not represent the superiority or inferiority of the embodiments.
[0326] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0327] In the several embodiments provided in this disclosure, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components may be combined, or integrated into another system, or some features may be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed may be through some interfaces, and the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0328] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units. They may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.
[0329] In addition, each functional unit in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.
[0330] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as mobile storage devices, read-only memory (ROM), magnetic disks, or optical disks.
[0331] Alternatively, if the integrated units described above are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, or the part that contributes to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROM, magnetic disks, or optical disks.
[0332] The above description is merely an embodiment of this disclosure, but the scope of protection of this disclosure is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this disclosure should be included within the scope of protection of this disclosure.< / op> < / op> < / op> < / op> < / op> < / op> < / op> < / op> < / op> < / op> < / op>
Claims
1. A method for assembling processor instructions, characterized in that, The method includes: The selection criteria for the target instruction to be compiled are obtained; the selection criteria for the target instruction are determined based on the characteristic features of the unique part of the target instruction, and the characteristic features include at least one of the following: instruction type, operand type, unique modifier, and specific bit value of opcode; Based on the selection criteria of the target instruction, the target syntax corresponding to the target instruction is determined from the combination syntax of the instruction set; the instruction set includes multiple instructions of the same type; the combination syntax is used to characterize the format string and operand field of each of the multiple instructions. Based on the target syntax, the assembly text of the target instruction is determined.
2. The method according to claim 1, characterized in that, Based on the selection criteria of the target instruction, the target syntax corresponding to the target instruction is determined from the combination syntax of the instruction set, including: When the combination syntax of the instruction set includes the expansion syntax of the multiple instructions, based on the selection criteria of the target instruction, the target expansion syntax corresponding to the target instruction is determined from the combination syntax of the instruction set; the expansion syntax of the instruction is determined based on the parent syntax common to the multiple instructions and the child syntax unique to the instruction; the target syntax includes the target expansion syntax; Accordingly, the target expansion syntax includes common mnemonics, expansion format strings, and expansion operand fields; based on the target syntax, the assembly text of the target instruction is determined, including: Based on the selection criteria of the target instruction and the common mnemonic, the instruction mnemonic of the target instruction is determined; The instruction mnemonic in the target expansion syntax is filled into the mnemonic placeholder in the expansion format string, and the expansion operand field in the target expansion syntax is sequentially filled into the operand placeholder in the expansion format string to obtain the assembly text of the target instruction.
3. The method according to claim 1, characterized in that, Based on the selection criteria of the target instruction, the target syntax corresponding to the target instruction is determined from the combination syntax of the instruction set, including: When the combination syntax of the instruction set includes a parent syntax common to the multiple instructions and a sub-syntax unique to the instruction, based on the selection criteria of the target instruction, the target sub-syntax and the parent syntax corresponding to the target instruction are determined from the combination syntax of the instruction set; the parent syntax includes a format string and operand field common to the multiple instructions, and the sub-syntax includes a format string and operand field unique to the instruction; the target syntax includes the parent syntax and the target sub-syntax. Accordingly, based on the target syntax, the assembly text of the target instruction is determined, including: Based on the insertion point of the target sub-syntax, the target sub-syntax and the parent syntax are combined and described to obtain the assembly text of the target instruction.
4. The method according to claim 3, characterized in that, Based on the insertion point of the target sub-syntax, the target sub-syntax and the parent syntax are combined and described to obtain the assembly text of the target instruction, including: Based on the selection criteria of the target instruction and the common mnemonic in the parent syntax, the instruction mnemonic of the target instruction is determined; Based on the insertion point of each target sub-syntax, a first mapping relationship is determined between the second operand field of each target sub-syntax and the insertion point placeholders in the parent syntax; The instruction mnemonic of the target instruction is filled into the common mnemonic placeholder in the parent syntax. The specific content of the first operand field in the parent syntax is filled into the common operand placeholder in the parent syntax. Based on the first mapping relationship, the specific content of the second operand field of each target sub-syntax is filled into the insertion point placeholder in the parent syntax to obtain the assembly text of the target instruction.
5. The method according to claim 3, characterized in that, Based on the insertion point of the target sub-syntax, the target sub-syntax and the parent syntax are combined and described to obtain the assembly text of the target instruction, including: Based on the insertion point of each target sub-syntax, each target sub-syntax and the parent syntax are expanded and described to obtain the target expanded syntax of the target instruction; Based on the target expansion syntax, the assembly text of the target instruction is determined.
6. The method according to any one of claims 1 to 5, characterized in that, Based on the target syntax, the assembly text of the target instruction is determined, including: If the target instruction contains a hidden field, determine the scope of effect and assignment rules of the hidden field; Based on the target syntax, determine the assembly text to be determined for the target instruction; According to the determination order of different types of fields in the target syntax, and based on the effective scope and assignment rules of the hidden fields, the hidden fields are written into the assembly text to be determined, thereby obtaining the assembly text of the target instruction.
7. A method for combining processor instructions, characterized in that, The method includes: Based on the common parts in the instruction descriptions of multiple instructions in the instruction set, the common parent syntax of the multiple instructions is determined; the instruction set includes multiple instructions of the same type. Based on the unique portion of the instruction description of the instruction, determine the sub-syntax unique to the instruction; The selection criteria for the instruction are determined based on a unique portion of the instruction description. Based on the parent syntax, the selection conditions of each of the multiple instructions, and the sub-syntax, the combination syntax of the instruction set is determined.
8. The method according to claim 7, characterized in that, The instruction description includes the instruction format, opcode field, and operand field; Based on the common parts in the instruction descriptions of the multiple instructions, the common parent syntax of the multiple instructions is determined, including: Based on the common field value in the opcode field shared by the multiple instructions, determine the common mnemonic for the multiple instructions. Based on the instruction format of the multiple instructions, a first format string common to the multiple instructions is determined; Based on the specific content of the operand field common to the multiple instructions, the first operand field common to the multiple instructions is determined; The parent syntax is determined based on the common mnemonic, the first format string, and the first operand field.
9. The method according to claim 8, characterized in that, Based on the instruction formats of the multiple instructions, a first format string common to the multiple instructions is determined, including: Based on the position of different types of fields in the instruction format of the multiple instructions, placeholders of different types are determined; the different types of fields include at least one of the opcode field and operand field common to the multiple instructions, and the operand field unique to the instruction. The first format string is determined based on the different types of placeholders.
10. The method according to claim 9, characterized in that, Based on the positions of different types of fields in the instruction format of the multiple instructions, placeholders of different types are determined, including: The position of the opcode field common to the multiple instructions is taken as the position of the common mnemonic, and a common mnemonic placeholder is set at the position of the common mnemonic; The position of the operand segment common to the multiple instructions is taken as the position of the first operand segment, and a common operand placeholder is set at the position of the first operand segment; the common mnemonic placeholder and the common operand placeholder are numbered according to the order of the corresponding fields in the instruction format; The position of the operand field unique to the instruction is used as the insertion point, and an insertion point placeholder is set at the insertion point position; the insertion point placeholders are numbered according to the order of the unique operand field in the instruction format; Accordingly, based on the different types of placeholders, the first format string is determined, including: The first format string is determined based on the common mnemonic placeholder, the common operand placeholder, and the insertion point placeholder.
11. The method according to claim 10, characterized in that, The method further includes: The attribute information of the common operand placeholders in the first format string and the attribute information of the insertion point placeholders in the first format string are obtained respectively; wherein, the attribute information includes number, quantity and sorting order; Based on the attribute information of the common operand placeholder and the attribute information of the insertion point placeholder, determine whether the first format string is abnormal; The anomalies include at least one of the following: an anomaly in the placeholder numbering; a mismatch between the number of placeholders and the number of fields in the instruction format; or a mismatch between the order of placeholders and the order of fields in the instruction format.
12. The method according to any one of claims 7 to 11, characterized in that, The instruction description includes an operand field; based on unique portions of the instruction description, the sub-syntax unique to the instruction is determined, including: Based on the type and position of the operand field unique to the instruction, determine the second format string unique to the instruction; Based on the specific content of the operand field unique to the instruction, a second operand field unique to the instruction is determined; the operand field in the sub-syntax includes at least one of the corresponding operand's identifier, type, and modifier; Based on the position of the operand segment unique to the instruction, determine the insertion point corresponding to the second operand segment; The sub-syntax of the instruction is determined based on the second format string, the second operand field, and the corresponding insertion point.
13. The method according to claim 12, characterized in that, The step of determining the subsyntactic of the instruction based on the second format string, the second operand field, and the corresponding insertion point includes: For any insertion point, the sub-syntax of the insertion point is determined based on the second format string and the second operand field corresponding to the insertion point; the parent syntax includes multiple insertion points; the multiple insertion points are numbered according to the order of the operand fields unique to each of the multiple instructions in the instruction format; The sub-syntaxes corresponding to the multiple insertion points are combined according to the numbering of the multiple insertion points, and the combined sub-syntaxes are used as the sub-syntaxes of the instruction.
14. The method according to any one of claims 7 to 11, characterized in that, The selection criteria for the instruction are determined based on a unique portion of the instruction description, including: Based on the unique portion of the instruction description, the distinguishing features of the instruction are determined; the distinguishing features are characteristic features that differentiate the instruction from other instructions in the instruction set. Based on the differences in the instructions, the selection criteria for the instructions are determined.
15. The method according to any one of claims 7 to 11, characterized in that, Based on the parent syntax, the selection conditions of each of the multiple instructions, and the sub-syntax, the combination syntax of the instruction set is determined, including: Based on the position of different types of placeholders in the first format string of the parent syntax, the placeholders in the first format string are renumbered to obtain the expanded format string; Based on the expanded format string, the second mapping relationship, and the third mapping relationship, the expanded operand field of the instruction is determined; wherein, the second mapping relationship is used to characterize the correspondence between the first operand field in the parent syntax and the common operand placeholder, and the third mapping relationship is used to characterize the correspondence between the second operand field in the sub-syntax of the instruction and the insertion point placeholder; The expansion syntax of the instruction is determined based on the selection conditions, common mnemonic, expansion format string, and expansion operand field of the instruction. Based on the expansion syntax of each of the multiple instructions, the combination syntax of the instruction set is determined.
16. The method according to claim 15, characterized in that, Based on the expanded format string, the second mapping relationship, and the third mapping relationship, the expanded operand fields of each of the plurality of instructions are determined, including: Based on the expanded format string, update the second mapping relationship and the third mapping relationship respectively; Based on the updated second mapping relationship and the updated third mapping relationship, the specific content of the first operand segment in the parent syntax and the specific content of the second operand segment in the sub-syntax of each of the plurality of instructions are described in sequence to obtain the expanded operand segment of each of the plurality of instructions.
17. The method according to any one of claims 7 to 11, characterized in that, The method further includes: Obtain all fields in the instruction description of the plurality of instructions; Based on all the fields and the types of all the fields, the encoding fields of the combination syntax are determined; the encoding fields include at least one of visible fields, hidden fields, and extended fields; When determining the first operand field of the parent syntax and the second operand fields of each sub-syntax of the instruction, the visible fields and / or extended fields are directly referenced to set the specific content of the corresponding operand field; When determining the subsyntax of an instruction with a hidden field, the hidden field is referenced to add the assignment rule of the hidden field after the subsyntax of the instruction.
18. An assembler for processor instructions, characterized in that, The device includes: The acquisition module is configured to acquire selection conditions for the target instruction to be compiled; the selection conditions for the target instruction are determined based on the characteristic features of the unique part of the target instruction, and the characteristic features include at least one of the following: instruction type, operand type, unique modifier, and specific bit value of opcode; The selection module is configured to determine the target syntax corresponding to the target instruction from the combination syntax of the instruction set based on the selection criteria of the target instruction; the instruction set includes multiple instructions of the same type; the combination syntax is used to characterize the format string and operand field of each of the multiple instructions; The first processing module is configured to determine the assembly text of the target instruction based on the target syntax.
19. A processor instruction combination device, characterized in that, The device includes: The second processing module is configured to determine the common parent syntax of the multiple instructions based on the common parts in the instruction descriptions of multiple instructions in the instruction set; the instruction set includes multiple instructions of the same type. The second processing module is further configured to determine the sub-syntax unique to the instruction based on a unique portion of the instruction description. The second processing module is further configured to determine the selection conditions of the instruction based on a unique portion of the instruction description of the instruction; The combination module is also configured to determine the combination syntax of the instruction set based on the parent syntax, the selection conditions of each of the multiple instructions, and the sub-syntax.
20. A computer device comprising a memory and a processor, the memory storing a computer program executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 17.
21. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 17.
22. A computer program product, characterized in that, The computer program product includes a non-transitory computer-readable storage medium storing a computer program that, when read and executed by a computer device, implements the steps of the method according to any one of claims 1 to 17.
