WO2025232322A1 - Instruction processing method, instruction processing system and system-on-chip - Google Patents
Instruction processing method, instruction processing system and system-on-chipInfo
- Publication number
- WO2025232322A1 WO2025232322A1 PCT/CN2025/079089 CN2025079089W WO2025232322A1 WO 2025232322 A1 WO2025232322 A1 WO 2025232322A1 CN 2025079089 W CN2025079089 W CN 2025079089W WO 2025232322 A1 WO2025232322 A1 WO 2025232322A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- instruction
- processed
- toolchain
- language
- elements
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/30003—Arrangements for executing specific machine instructions
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/30145—Instruction analysis, e.g. decoding, instruction word fields
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/38—Concurrent instruction execution, e.g. pipeline or look ahead
- G06F9/3836—Instruction issuing, e.g. dynamic instruction scheduling or out of order instruction execution
Definitions
- This disclosure relates to the field of processors, and more specifically, to an instruction processing method, an instruction processing system, and a system-on-a-chip.
- tools within different toolchains abstract and interpret the semantics of instruction sets. Taking a single instruction as an example, a simulator interprets it as simulated execution, a compiler interprets it as matching the corresponding operator sequence in the upper-level language, and an assembler interprets it as matching a specific assembly string sequence.
- the core content revolving around these processes is the semantic description of the instruction set.
- the semantic description of the instruction set is described in a specification document using natural or mathematical language. Implementers of different tools use the same document for unified understanding and implementation. However, in this process, discrepancies in understanding or implementation can easily arise, leading to toolchain errors and lower accuracy in instruction processing.
- This disclosure provides an instruction processing method, an instruction processing system, and a system-on-a-chip to at least address the technical problem of low accuracy in instruction processing in related technologies.
- an instruction processing system including: a toolchain, comprising at least an execution component and an interpretation component; wherein, the execution component is used to process the processing flow of a source instruction file in a first language and determine whether the instruction to be processed in the source instruction file is a preset instruction; the interpretation component is used to process the instruction description information of the instruction to be processed to obtain multiple instruction elements in a second language; the execution component is also used to execute the multiple instruction elements in the second language to obtain the processing result of the instruction to be processed.
- a system-on-a-chip including: an instruction processing system of any one of the above embodiments.
- a computer terminal including: a memory storing an executable program; and a processor for running the program, wherein the program executes the methods in the various embodiments of this disclosure when it runs.
- a computer-readable storage medium including a stored executable program, wherein, when the executable program is executed, it controls the device where the computer-readable storage medium is located to perform the methods of the various embodiments of the present disclosure.
- a computer program product including a computer program that, when executed by a processor, implements the methods of various embodiments of this disclosure.
- a computer program product including a non-volatile computer-readable storage medium storing a computer program that, when executed by a processor, implements the methods in various embodiments of this disclosure.
- a computer program which, when executed by a processor, implements the methods in the various embodiments of this disclosure.
- the processing flow of a source instruction file in a first language processed by a toolchain is monitored to determine whether the instruction to be processed in the source instruction file is a preset instruction; if the instruction to be processed is a preset instruction, an interpretation component in the toolchain is invoked to process the instruction description information of the instruction to be processed, obtaining multiple instruction elements in a second language; the multiple instruction elements in the second language are executed by the toolchain to obtain the processing result of the instruction to be processed, thereby improving the accuracy of instruction processing.
- the interpretation component in the toolchain can be invoked to interpret the instruction description information of the instruction to be processed, so as to obtain multiple instruction elements in the second language that the toolchain can execute. This allows the toolchain to efficiently and accurately process and execute the source instruction file without introducing additional language learning costs, thereby improving the accuracy of instruction processing and solving the technical problem of low accuracy in instruction processing in related technologies.
- Figure 1 is a hardware structure block diagram of a RISC-V system for implementing an instruction processing method according to an embodiment of the present disclosure
- Figure 2 is a schematic diagram of a system-on-a-chip according to an embodiment of the present disclosure
- FIG. 3 is a flowchart of the instruction processing method according to Embodiment 1 of this disclosure.
- Figure 4 is a schematic diagram of a directed acyclic graph according to an embodiment of the present disclosure.
- Figure 5 is a schematic diagram of a character representation matching relationship according to an embodiment of the present disclosure.
- Figure 6 is a schematic diagram of a simulator scene according to an embodiment of the present disclosure.
- Figure 7 is a schematic diagram of an instruction processing apparatus according to an embodiment of the present disclosure.
- Figure 8 is a schematic diagram of an instruction processing system according to an embodiment of the present disclosure.
- Figure 9 is a structural block diagram of an electronic device according to an embodiment of the present disclosure.
- ISA Instruction Set Architecture
- DSA Domain-Specific Accelerator
- DSL Domain-Specific Language
- Toolchain A set of software tools that work together, typically used for compiling, debugging, and building software for programming languages.
- Python A widely used high-level programming language known for its readability and concise syntax, suitable for a wide range of programming tasks, from web development to data science.
- Abstract Interpretation A method of analyzing a program by using simplified (or "abstract") data to represent the actual data in the program, in order to simplify the understanding or prediction of the program's behavior.
- EDSL Embedded Domain-Specific Language
- processor core design CPU IP core
- the instruction set of this accelerator is defined by the customer, but the toolchain is provided by the CPU IP core vendor because the generated DSA instructions are integrated into the normal CPU instruction sequence.
- CPU vendors cannot support customers' DSA instruction customization needs during the toolchain development phase; they can only deliver general toolchain binary distribution packages. Therefore, after receiving the general toolchain, customers need to perform secondary development or configuration of the toolchain in their own environment. At this point, customers need to describe the semantics of their designed DSA instructions so that the toolchain can read and support them.
- this disclosure provides a method for using Python as a host language to express instruction semantics, and defines the interface for how to use this library during toolchain development. This facilitates unified instruction implementation for toolchain developers and allows DSA customers to dynamically perform secondary development and configuration of the toolchain.
- an instruction processing method is provided. It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowcharts, in some cases, the steps shown or described may be executed in a different order than that shown here.
- FIG. 1 is a hardware structure block diagram of a RISC-V system for implementing an instruction processing method according to an embodiment of this disclosure.
- the RISC-V system 100 can be divided into the following layers from bottom to top: Reduced Instruction Set Architecture 101 (including basic instruction set 101-1 and extended instruction set 101-2), hardware layer 102 (including processor 102-1, peripheral hardware circuits 102-2, etc.), interface layer 103, operating system layer 104 (supporting multiple operating systems 104-1, 104-2, ..., 104-n, such as Linux, Free SBD, RT-Tread, etc.), middleware and library layer 105 (including system library 105-1, API 105-2, and middleware service 105-3), and application layer 106 (including multiple user programs and services 106-1, 106-2, ..., 106-n).
- Reduced Instruction Set Architecture 101 including basic instruction set 101-1 and extended instruction set 101-2
- hardware layer 102 including processor 102-1, peripheral hardware circuits 102-2, etc.
- interface layer 103 interface layer 103
- operating system layer 104 supporting multiple operating systems 104-1, 104-2, ..., 104-n, such as Linux, Free SBD, RT-Tread,
- the RISC-V system 100 also includes a toolchain 107 that runs from the underlying hardware to the application layer.
- This toolchain may include compilers and assemblers 107-1, linkers 107-2, debuggers 107-3, simulators and emulators 107-4, integrated development environments 107-5, hardware description language tools 107-6, performance analysis tools 107-7, and version control systems 107-8, etc.
- the instruction set architecture 101 defines the basic operations and instruction sets supported by the processor 102-1, including the basic instruction set and the extended instruction set.
- the basic instruction set represents the basic integer instruction set, such as RV32I and RV64I, while the extended instruction set can be floating-point, atomic operations, compressed instructions, etc.
- Interface layer 103 includes the specific design of the processor, such as pipeline design, cache structure, execution units, branch prediction, etc. This layer is the process of mapping abstract instructions to physical hardware.
- the operating system layer 104 resides in the hardware layer, providing a hardware abstraction layer and management mechanisms, enabling applications to interact with hardware through system calls.
- the operating system is responsible for managing processor resources, memory, device drivers, task scheduling, and more.
- the middleware and library layer 105 provides a rich set of services and interfaces to help applications run more efficiently.
- the standard library provides functions such as file operations and mathematical calculations, while middleware can provide complex services such as network communication and graphical user interfaces.
- the application layer 106 utilizes the functions and services provided by the lower layer to implement specific application logic. These applications can be command-line tools, graphical interface applications, server-side services, etc.
- Toolchain 107 is a key component connecting the underlying hardware to the upper-level software.
- the various tools in toolchain 107 play a role at different levels to support the entire process from hardware design to software development, ensuring the coherence and effectiveness of the entire system design.
- the layered design of the RISC-V architecture allows for decoupling between different layers, enabling each layer to be developed and improved independently.
- FIG2 is a schematic diagram of a system-on-chip according to an embodiment of the present disclosure.
- FIG2 shows a schematic diagram of a system-on-chip (SOC) using the RISC-V architecture shown in FIG1 above.
- the SOC contains at least one RISC-V core 202 (only one is shown in the figure).
- the RISC-V core 202 is connected to peripheral devices through bus 204, including but not limited to ROM 206, RAM 208, timer 210, UART (Universal Asynchronous Receiver/Transmitter) 212, GPIO (General Purpose Input/Output) 214, SPI (Serial Peripheral Interface Bus) 216, etc.
- bus 204 including but not limited to ROM 206, RAM 208, timer 210, UART (Universal Asynchronous Receiver/Transmitter) 212, GPIO (General Purpose Input/Output) 214, SPI (Serial Peripheral Interface Bus) 216, etc.
- Figure 3 is a flowchart of the instruction processing method according to Embodiment 1 of this disclosure. The method includes:
- Step S302 Monitor the processing flow of the source instruction file of the first language through the toolchain, and determine whether the instruction to be processed in the source instruction file is a preset instruction.
- the aforementioned toolchain refers to a collection of tools used in the software development process to support different stages of work, such as development, building, testing, and deployment.
- the aforementioned preset instructions can be pre-defined instructions or unknown instructions. If the instruction to be processed is a preset instruction, it needs to be interpreted by the toolchain to obtain instruction elements that the toolchain can recognize.
- the source code file mentioned above is a file containing the original code of a computer program, typically written in a specific programming language.
- Source code files are usually processed by a compiler or interpreter, converting them into an executable program or allowing for interpreted execution.
- Source code files can contain different file formats (C, C++, Java, Python, etc.).
- source code files are fundamental to program development; the design and functionality of a program can be implemented by editing and modifying source code files.
- the first language mentioned above can include, but is not limited to, various programming languages (C, C++, Java, Python), and no limitation is made on the first language here.
- the processing flow of source instruction files in the first language processed by the toolchain can be monitored to see if the toolchain encounters preset instructions that need to be interpreted when processing the source instruction files, so that the toolchain can successfully execute and process the source instruction files.
- Step S304 If the instruction to be processed is a preset instruction, the interpretation component in the toolchain is called to process the instruction description information of the instruction to be processed, and multiple instruction elements in the second language are obtained.
- the instruction description information of the instruction to be processed can be interpreted by calling the interpretation component in the toolchain, so as to convert the instruction to be processed into multiple instruction elements in a second language that the toolchain can recognize.
- the aforementioned interpreting component can refer to an interpreter, which is a software component capable of directly interpreting and executing program source code.
- An interpreter interprets the program source code line by line and executes the code on demand, without first converting the code into machine code or intermediate code.
- Interpreters are often used to interpret and execute dynamic languages such as Python, Ruby, and JavaScript. In some cases, interpreters can also be used to execute programs in statically typed languages, such as executing Java source code via an interpreter instead of first compiling it into bytecode.
- the aforementioned interpretation component is used to process the instruction description information of the instructions to be processed, in order to obtain multiple instruction elements in the second language.
- the interpreter can parse the source code of the first language and convert it into multiple instruction elements in the second language for subsequent processing and execution.
- This disclosure uses a Python interpreter as an example for illustration.
- the instruction description information of the aforementioned instructions to be processed can be the description information of instructions or commands that need to be executed and are contained in a program or script. Instruction description information can include the command name, parameters, options, and other relevant information. In computer programming and scripting, programmers typically write a series of instructions to be executed. This instruction description information is processed and executed by an interpreter, compiler, or other tools. The instruction description information can include the program's control flow, function calls, variable assignments, etc. The interpreter can convert the instruction description information of the instructions to be processed into instruction elements in a second language, enabling the toolchain to process and execute the predefined instructions.
- instruction elements of a second language can be instruction elements that can be recognized by the toolchain.
- Instruction elements can be basic instructions or primitive operations in the second language. Specifically, instruction elements may refer to basic program operations, such as variable assignment, conditional statements, loop operations, and function calls. These instruction elements are the fundamental components of a program; after being processed by the interpreter or compiler, they are ultimately converted into instructions or code that the computer can execute.
- the interpretation component in the toolchain can be invoked to interpret the instruction description information of the instruction to be processed, thereby obtaining multiple instruction elements in the second language. This allows the toolchain to process the multiple instruction elements in the second language and obtain the processing result of the instruction to be processed.
- Step S306 Execute multiple instruction elements of the second language through the toolchain to obtain the processing result of the instruction to be processed.
- the instruction description information of the instructions to be processed is processed by invoking the interpretation component in the toolchain to obtain multiple instruction elements in a second language that the toolchain can recognize.
- the type of the toolchain can be determined first, and then the semantic actions corresponding to that type can be performed on the multiple instruction elements through the toolchain to obtain the aforementioned processing result.
- the core of this disclosure is a Python library used to describe instruction semantics.
- This library models the basic operands and opcodes used in the description of instruction semantics using predefined elements, making it easy for users to construct complex instruction semantics using these basic elements.
- element modeling means the Python library pre-standardizes and defines the semantics of some basic operation types and operations, allowing users to directly combine and use these elements.
- the definition and set of basic elements are similar to the basic instructions and types in the Low-Level Virtual Instruction Set (LLVM Intermediate Representation, or LLVM IR for short), while also reserving space for user-defined types.
- the Low-Level Virtual Instruction Set is used to represent the intermediate representation of a program in the compiler. This Low-Level Virtual Instruction Set can be a type-safe, low-level representation that can be used by high-level language compilers to generate machine code or other forms of object code.
- class CustomOp1 TripleOp(Custom class CustomOp1, which inherits from class TripleOp);
- ⁇ TripleOp ⁇ is a defined class library representing ternary operators
- ⁇ CustomOp1 ⁇ is a user-defined class that is used through inheritance.
- the user defines the semantics of this instruction using ⁇ def execute ⁇ , which is operand 1 * operand 2 + operand 3.
- ⁇ r1 ⁇ , ⁇ r2 ⁇ , and ⁇ r3 ⁇ are all basic operand element types defined in this publication.
- Multiplication (*) and addition (+) are defined basic opcode elements. Because classes like ⁇ r1 ⁇ , ⁇ r2 ⁇ , and ⁇ r3 ⁇ define operator overloading capabilities, users can directly construct operations using addition (+) and multiplication (*).
- ⁇ asmString ⁇ This character representation is used to represent the names of ternary operators and is generally used in assembly and disassembly.
- the ⁇ asmString ⁇ function is used to convert a string into assembly code, transforming it into a series of assembly instructions that allow the program to dynamically generate and execute.
- the processing flow of the first language source instruction file processed by the toolchain is monitored to determine whether the instruction to be processed in the source instruction file is a preset instruction. If the instruction to be processed is a preset instruction, the interpretation component in the toolchain is called to process the instruction description information of the instruction to be processed, thereby obtaining multiple instruction elements in the second language. The toolchain executes the multiple instruction elements in the second language to obtain the processing result of the instruction to be processed, thus improving the accuracy of instruction processing.
- the interpretation component in the toolchain can be called to interpret the instruction description information of the instruction to be processed, so as to obtain multiple instruction elements in the second language that the toolchain can execute. This allows the toolchain to efficiently and accurately process and execute the source instruction file without introducing additional language learning costs, thereby improving the accuracy of instruction processing and solving the technical problem of low accuracy in instruction processing in related technologies.
- the interpretation component in the toolchain is invoked to process the instruction description information of the instruction to be processed to obtain multiple instruction elements in the second language. This includes: processing the instruction description information through the interpretation component to generate a directed acyclic graph, wherein the multiple nodes contained in the directed acyclic graph correspond one-to-one with the multiple instruction elements, and the edges connecting different nodes in the directed acyclic graph are used to represent the association relationship between different instruction elements.
- the Directed Acyclic Graph (DAG) described above is a graph structure composed of multiple nodes and directed edges between them. Each node corresponds one-to-one with an instruction element, and the edges represent the relationships between different instruction elements. DAGs can be used to represent the instruction flow and dependencies during program execution. Each node represents an instruction element, such as variable assignment, conditional judgment, or function call. Directed edges represent the relationships between different instruction elements, such as dependencies and execution order.
- the interpretation component can generate a directed acyclic graph (DAG) based on this description information.
- DAG directed acyclic graph
- the nodes in the graph represent various instruction elements of the program, such as assignment operations, conditional statements, and loop operations, while the edges represent the execution order and dependencies between these instruction elements.
- DAG can help with program analysis and improvement, and also visually represent the program's execution flow and the relationships between instructions.
- a directed acyclic graph describing the instruction semantics can be constructed on the Python side.
- This DAG can then be loaded into different toolchains, each capable of performing different semantic actions on the DAG for different purposes.
- the entire DAG can be loaded into a toolchain. For example, if the DAG is loaded into a simulator, the semantic actions on each node are executed within the simulator, representing the semantics of that node. If the DAG is loaded into a compiler, the semantic actions on each node are matched against the higher-level representative of the corresponding semantics to generate the user-described instruction.
- Figure 4 is a schematic diagram of a directed acyclic graph according to an embodiment of the present disclosure.
- instruction description information can be input into a Python interpreter.
- the Python interpreter can process the instruction description information to generate a directed acyclic graph of instruction description information.
- the directed acyclic graph includes +, *, R1, R2, and R3.
- the directed acyclic graph is interpreted and executed to perform a semantic action on each node in the directed acyclic graph.
- the method further includes: loading a configuration file into the toolchain, wherein the configuration file contains instruction description information of at least one preset instruction; matching the character representation of at least one preset instruction with the character representation of an instruction to be processed to determine the instruction description information of the instruction to be processed.
- Python code can be interpreted and executed by embedding a Python interpreter in the toolchain to obtain a directed acyclic graph of at least one preset instruction. This directed acyclic graph can then be interpreted and executed by mutual calls between Python and other languages through binding relationships, such as C++ calling Python's binding.
- the instruction description information of preset instructions can be stored in a configuration file, and then the configuration file is loaded into the toolchain.
- This instruction description information may include the instruction's name, parameters, options, and other instruction-related information.
- the toolchain can use this information to determine the instruction description information of the instruction to be processed.
- the configuration file contains a preset instruction named "print,” which represents the print operation.
- the toolchain can determine the instruction description information of the instruction to be processed by matching the instruction description information of the preset instruction in the configuration file, so as to facilitate subsequent processing and execution.
- the toolchain can automatically identify and process the instruction to be processed based on the instruction description information of the preset instruction, thereby improving the flexibility and configurability of the toolchain. This makes it easier for developers to define and use their own instruction description information to adapt to different development needs.
- an assembler performs text matching, matching different nodes to complete an instruction matching, a simulator performs a simulated execution operation on different nodes, and a compiler performs intermediate code matching of a higher-level language on different nodes.
- Figure 5 is a schematic diagram of a character representation matching relationship according to an embodiment of the present disclosure.
- instruction description information can be input into different toolchains for execution.
- the upper toolchain shown in Figure 5 can be a simulation toolchain, and the executor of the simulation toolchain can be a simulator.
- the lower toolchain shown in Figure 5 can be a compilation toolchain, and the executor of the compilation toolchain can be a compiler.
- the Python interpreter in the simulation toolchain can generate a directed acyclic graph (DAG) based on the instruction description information and interpret and execute the DAG. This interpretation and execution process can be simulated execution based on the DAG.
- the Python interpreter in the compilation toolchain can generate a DAG based on the instruction description information and interpret and execute the DAG. This interpretation and execution process can be instruction selection based on the DAG.
- DAG directed acyclic graph
- matching the character representation of at least one preset instruction with the character representation of an instruction to be processed to determine the instruction description information of the instruction to be processed includes: if the character representation of any preset instruction is the same as the character representation of the instruction to be processed, determining the instruction description information of any preset instruction as the instruction description information of the instruction to be processed.
- determining the instruction description information of any preset instruction as the instruction description information of the instruction to be processed means that when the character representation of the instruction to be processed matches the character representation in the preset instruction, the toolchain will set the instruction description information of the instruction to be processed to the instruction description information of the matched preset instruction.
- a similarity match can be performed between the character representations of the preset instructions and the character representations of the instruction to be processed, thereby determining the instruction description information of the instruction to be processed based on the instruction description information of any preset instruction.
- the processing result of the instruction to be processed is obtained by executing multiple instruction elements of the second language through a toolchain, including: determining the target type of the toolchain and determining the target semantic action corresponding to the target type; and performing target semantic actions on multiple instruction elements through the toolchain to obtain the processing result.
- Toolchain target types include compiler chains, interpreter chains, and build toolchains.
- Compiler chains include, but are not limited to, preprocessing, compilation, assembly, and linking processes; interpreter chains include, but are not limited to, translating source code into machine code for immediate execution; and build toolchains include, but are not limited to, those used for automating software building, testing, and deployment.
- target semantic actions corresponding to the aforementioned target types can be determined based on the specific toolchain and target type.
- target types may include executable files, dynamic link libraries, static libraries, etc.
- the corresponding target semantic actions may include translating the source code into the machine code or intermediate code required by the target type, and performing linking operations.
- target semantic actions refer to the operations performed by the toolchain when processing instruction elements in software development to satisfy a specific target type. These operations are to transform the source code into the form required by the target type or to perform specific functions.
- Target semantic actions can include compilation, linking, improvement, and interpreted execution, depending on the toolchain type and the target type.
- the target type might be executing a specific script or program, while the target semantic action is interpreting and executing the instructions in the source code. This is only an illustrative example; the specific target semantic actions corresponding to a particular target type can be determined based on the actual situation.
- the target type of the toolchain can be determined first, and the target semantic action corresponding to the target type can be obtained.
- the toolchain can execute the target semantic action on multiple instruction elements, thereby enabling the toolchain to process multiple instruction elements accurately and obtain processing results.
- Figure 6 is a schematic diagram of a simulator scenario according to an embodiment of the present disclosure.
- instruction description information written in Python can be loaded into the simulator's toolchain as a configuration file. Then, the source file input of the toolchain is processed normally. The source file can be a target assembly language. When an unknown instruction or a user-defined instruction is encountered, the custom instruction description information loaded in the Python interpreter is called back.
- the instruction description information can be processed by the Python interpreter to generate a directed acyclic graph. Multiple instruction elements are obtained through the directed acyclic graph, and the multiple instruction elements are executed by the executor to obtain the target semantic action of the instruction elements.
- determining the target semantic action corresponding to the target type includes: when the target type is a simulator, determining the target semantic action as executing the semantics of multiple instruction elements in the simulator; when the target type is an assembler, determining the target semantic action as matching multiple instruction elements with text; and when the target type is a compiler, determining the target semantic action as matching multiple instruction elements with intermediate instructions of a first language.
- the simulator described above can be a computer program that simulates the behavior of a hardware platform, allowing users to execute instructions from an instruction set architecture in a simulated environment for software development, debugging, and performance analysis. Simulators are typically used to simulate specific computer architectures, processors, or devices, enabling developers to develop and test software without actual hardware.
- the assembler described above is a tool that translates assembly language code into machine code or object files. An assembler converts programmer-written assembly language instructions into executable binary code that a computer can directly execute. The assembler is an important component of the programming toolchain, used to convert assembly language code into machine code for computer execution.
- the compiler described above is a tool that translates high-level programming language code into machine code or intermediate code for a target platform.
- a compiler converts programmer-written high-level language code (such as C, C++, Java, etc.) into executable code for the target platform, including executable files, library files, etc.
- a compiler can also translate high-level language code into an intermediate representation for subsequent improvements and target code generation.
- the target semantic action is the semantics of executing multiple instruction elements in the simulator.
- the toolchain can simulate the behavior of the target hardware platform, executing multiple instruction elements one by one, so as to observe and analyze the program's behavior and performance in a simulation environment.
- the target semantic action is to match multiple instruction elements with text.
- the toolchain can translate these instruction elements into their corresponding assembly text representations; this process is the assembly process.
- the target semantic action is to match multiple instruction elements with intermediate instructions in the first language.
- the toolchain can translate these instruction elements into an intermediate representation in the first language; this process is the compilation process.
- the preset instruction is used to characterize an instruction not included in the simplified instruction set, or an instruction set by the target object.
- RV architecture is a reduced instruction set computer architecture designed to simplify the instruction set and improve processor performance and power efficiency. If a computer's processor uses the RV architecture, it means that the computer can use the RV instruction set and can execute specific instructions from the RV architecture, thereby achieving higher performance and power efficiency.
- the target object mentioned above can be a user or any object.
- the toolchain described above can be used to process a reduced instruction set.
- the preset instructions can be unknown instructions or instructions pre-set by the user.
- This disclosure standardizes the implementation of instruction set semantics in toolchains, resolving potential semantic inconsistencies that may arise when individual tools implement instruction set semantics independently, and reducing errors and redundant work during toolchain implementation. Furthermore, this disclosure can be applied to the semantic description and implementation of extended instruction sets used by customer-specific accelerators, facilitating customers' independent description of extended instruction set semantics and enabling immediate toolchain support for extended instructions.
- the innovation of this disclosure lies in its avoidance of Stahling a new instruction semantic description language; instead, it utilizes existing programming languages as the host language to describe instruction semantics, creating a domain-specific accelerator that simplifies the learning curve and allows for easy and immediate embedding into various toolchains.
- the nodes in the aforementioned directed acyclic graph can be any data node in the DAG, representing a specific element or entity in the graph and connected to other nodes via directed edges.
- nodes in a DAG typically represent a specific processing step or operation within the toolchain.
- the user information including but not limited to user device information, user personal information, etc.
- data including but not limited to data used for analysis, data stored, data displayed, etc.
- the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.
- FIG7 is a schematic diagram of an instruction processing device according to an embodiment of the present disclosure. As shown in FIG7, the device 700 includes: a monitoring module 702, a calling module 704, and an execution module 706.
- the monitoring module is used to monitor the processing flow of the source instruction file of the first language through the toolchain and determine whether the instruction to be processed in the source instruction file is a preset instruction; the calling module is used to call the interpretation component in the toolchain to process the instruction description information of the instruction to be processed when the instruction to be processed is a preset instruction, so as to obtain multiple instruction elements of the second language; the execution module is used to execute multiple instruction elements of the second language through the toolchain to obtain the processing result of the instruction to be processed.
- the monitoring module 702, the calling module 704, and the execution module 706 mentioned above correspond to steps S302 to S306 in Embodiment 1.
- the three modules and their corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in Embodiment 1.
- the above modules or units can be hardware or software components stored in memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n).
- the above modules can also be part of a device and run in the computer terminal 10 provided in Embodiment 1.
- the calling module is further configured to process the instruction description information through the interpretation component to generate a directed acyclic graph, wherein the multiple nodes contained in the directed acyclic graph correspond one-to-one with multiple instruction elements, and the edges connecting different nodes in the directed acyclic graph are used to characterize the association relationship between different instruction elements.
- the device further includes: a loading module and a matching module.
- the loading module is used to load the configuration file into the toolchain.
- the configuration file contains instruction description information for at least one preset instruction.
- the matching module is used to match the character representation of at least one preset instruction with the character representation of the instruction to be processed to determine the instruction description information of the instruction to be processed.
- the matching module is further configured to determine the instruction description information of any preset instruction as the instruction description information of the instruction to be processed when the character representation of any preset instruction is the same as the character representation of the instruction to be processed.
- the execution module is further configured to determine the target type of the toolchain and the target semantic action corresponding to the target type; and to perform target semantic actions on multiple instruction elements through the toolchain to obtain the processing result.
- the execution module is further configured to determine the target semantic action as executing multiple instruction elements in the simulator when the target type is a simulator; determine the target semantic action as matching multiple instruction elements with text when the target type is an assembler; and determine the target semantic action as matching multiple instruction elements with intermediate instructions of the first language when the target type is a compiler.
- the preset instruction is used to characterize an instruction not included in the simplified instruction set, or an instruction set by the target object.
- FIG8 is a schematic diagram of an instruction processing system according to an embodiment of the present disclosure.
- the system 800 includes: a toolchain 802, which includes at least an execution component 8021 and an interpretation component 8022.
- the toolchain includes at least an execution component and an interpretation component.
- the execution component is used to process the source instruction file of the first language and determine whether the instruction to be processed in the source instruction file is a preset instruction.
- the interpretation component is used to process the instruction description information of the instruction to be processed to obtain multiple instruction elements of the second language.
- the execution component is also used to execute the multiple instruction elements of the second language to obtain the processing result of the instruction to be processed.
- execution components mentioned above can refer to components used to execute program source code. They translate the source code into machine code or intermediate code, and then run it on the target platform. Execution components can be compilers, assemblers, linkers, etc., which are responsible for converting source code into executable programs or libraries.
- the aforementioned interpreting component can represent a component used to interpret and execute program source code. It can achieve the program's functionality by interpreting and executing the source code line by line.
- the interpreting component can be an interpreter, which can directly interpret and execute scripts or program source code.
- the interpretation component includes: an interpreter, used to process instruction description information and generate a directed acyclic graph, wherein the multiple nodes in the directed acyclic graph correspond one-to-one with multiple instruction elements, and the edges connecting different nodes in the directed acyclic graph are used to characterize the association relationship between different instruction elements; wherein the execution component is used to execute the directed acyclic graph to obtain the processing result.
- the interpreter mentioned above can be a Python interpreter. This is just an example and is not a limitation. The specific interpreter can be adjusted according to the actual use case.
- the execution component includes one of the following: a simulator for executing the semantics of multiple instruction elements; an assembler for matching the multiple instruction elements with text; and a compiler for matching the multiple instruction elements with intermediate instructions of a first language.
- a system-on-a-chip including: an instruction processing system according to any one of the above embodiments.
- Embodiments of this disclosure can provide an electronic device, which can be any one of a group of electronic devices.
- the aforementioned electronic device can also be replaced with a terminal device such as a mobile terminal.
- the aforementioned electronic device may be located in at least one of a plurality of network devices in a computer network.
- the computer terminal described above can execute the program code in the method.
- FIG9 is a structural block diagram of an electronic device according to an embodiment of the present disclosure.
- the electronic device A may include: one or more (only one is shown in the figure) processors 102, memory 104, memory controller, and peripheral interface, wherein the peripheral interface is connected to a radio frequency module, an audio module, and a display.
- the memory can be used to store software programs and modules, such as the program instructions/modules corresponding to the methods and apparatus in the embodiments of this disclosure.
- the processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby implementing the methods in the above embodiments.
- the memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory.
- the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to terminal A via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
- the processor can access information and applications stored in memory via a transmission device to perform the following steps: monitor the processing flow of a source instruction file in the first language processed by a toolchain, and determine whether the instruction to be processed in the source instruction file is a preset instruction; if the instruction to be processed is a preset instruction, call the interpretation component in the toolchain to process the instruction description information of the instruction to be processed to obtain multiple instruction elements in the second language; execute the multiple instruction elements in the second language through the toolchain to obtain the processing result of the instruction to be processed.
- the processor may also execute program code that performs the following steps: processes instruction description information through an interpretation component to generate a directed acyclic graph, wherein multiple nodes in the directed acyclic graph correspond one-to-one with multiple instruction elements, and the edges connecting different nodes in the directed acyclic graph are used to characterize the association between different instruction elements.
- the processor may also execute program code that performs the following steps: loading a configuration file into the toolchain, wherein the configuration file contains instruction description information for at least one preset instruction; matching the character representation of at least one preset instruction with the character representation of the instruction to be processed to determine the instruction description information of the instruction to be processed.
- the processor may also execute program code that performs the following steps: if the character representation of any preset instruction is the same as the character representation of the instruction to be processed, determine the instruction description information of any preset instruction as the instruction description information of the instruction to be processed.
- the processor may also execute program code that performs the following steps: determines the target type of the toolchain and the target semantic action corresponding to the target type; performs target semantic actions on multiple instruction elements through the toolchain to obtain the processing result.
- the processor may also execute program code that performs the following steps: when the target type is a simulator, determines the target semantic action as executing multiple instruction elements in the simulator; when the target type is an assembler, determines the target semantic action as matching multiple instruction elements with text; when the target type is a compiler, determines the target semantic action as matching multiple instruction elements with intermediate instructions of the first language.
- the processor may also execute program code that includes the following steps: preset instructions used to characterize instructions not included in the reduced instruction set, or instructions set by the target object.
- the processing flow of a source instruction file in a first language processed by a toolchain is monitored to determine whether the instruction to be processed in the source instruction file is a preset instruction. If the instruction to be processed is a preset instruction, the interpretation component in the toolchain is invoked to process the instruction description information of the instruction to be processed, thereby obtaining multiple instruction elements in a second language. The multiple instruction elements in the second language are executed by the toolchain to obtain the processing result of the instruction to be processed, thus improving the accuracy of instruction processing.
- the interpretation component in the toolchain can be invoked to interpret the instruction description information of the instruction to be processed, so as to obtain multiple instruction elements in the second language that the toolchain can execute. This allows the toolchain to efficiently and accurately process and execute the source instruction file without introducing additional language learning costs, thereby improving the accuracy of instruction processing and solving the technical problem of low accuracy in instruction processing in related technologies.
- the structure shown in Figure 9 is merely illustrative, and the electronic device may also be a smartphone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile internet device (MID), a PAD, or other terminal device.
- Figure 9 does not limit the structure of the aforementioned electronic device.
- electronic device A may include more or fewer components (such as a network interface, a display device, etc.) than shown in the figure, or may have a different configuration than that shown in Figure 9.
- the program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
- Embodiments of this disclosure also provide a computer-readable storage medium.
- the computer-readable storage medium can be used to store program code executed by the method provided in the above embodiments.
- the storage medium may be located in any one of the electronic devices in the group of electronic devices in the computer network, or in any one of the mobile terminals in the group of mobile terminals.
- the computer-readable storage medium is configured to store program code for performing the following steps: monitoring the processing flow of a source instruction file of the first language processed by a toolchain, and determining whether the instruction to be processed in the source instruction file is a preset instruction; if the instruction to be processed is a preset instruction, calling the interpretation component in the toolchain to process the instruction description information of the instruction to be processed to obtain multiple instruction elements of the second language; executing the multiple instruction elements of the second language through the toolchain to obtain the processing result of the instruction to be processed.
- the computer-readable storage medium is further configured to store program code for performing the following steps: processing instruction description information through an interpretation component to generate a directed acyclic graph, wherein the directed acyclic graph contains multiple nodes that correspond one-to-one with multiple instruction elements, and the edges connecting different nodes in the directed acyclic graph are used to characterize the association relationships between different instruction elements.
- the computer-readable storage medium is further configured to store program code for performing the following steps: loading a configuration file into a toolchain, wherein the configuration file contains instruction description information for at least one preset instruction; matching the character representation of at least one preset instruction with the character representation of an instruction to be processed to determine the instruction description information of the instruction to be processed.
- the computer-readable storage medium is further configured to store program code for performing the following steps: determining the instruction description information of any preset instruction as the instruction description information of the instruction to be processed, provided that the character representation of any preset instruction is the same as the character representation of the instruction to be processed.
- the computer-readable storage medium is further configured to store program code for performing the following steps: determining the target type of the toolchain and determining the target semantic action corresponding to the target type; performing target semantic actions on multiple instruction elements through the toolchain to obtain the processing result.
- the computer-readable storage medium is further configured to store program code for performing the following steps: if the target type is an emulator, determining the target semantic action as executing multiple instruction elements in the emulator; if the target type is an assembler, determining the target semantic action as matching multiple instruction elements with text; if the target type is a compiler, determining the target semantic action as matching multiple instruction elements with intermediate instructions of a first language.
- the computer-readable storage medium is also configured to store program code for performing the following steps: preset instructions for characterizing instructions not included in the reduced instruction set, or instructions set by the target object.
- the processing flow of a source instruction file in a first language processed by a toolchain is monitored to determine whether the instruction to be processed in the source instruction file is a preset instruction. If the instruction to be processed is a preset instruction, the interpretation component in the toolchain is invoked to process the instruction description information of the instruction to be processed, thereby obtaining multiple instruction elements in a second language. The multiple instruction elements in the second language are executed by the toolchain to obtain the processing result of the instruction to be processed, thus improving the accuracy of instruction processing.
- the interpretation component in the toolchain can be invoked to interpret the instruction description information of the instruction to be processed, so as to obtain multiple instruction elements in the second language that the toolchain can execute. This allows the toolchain to efficiently and accurately process and execute the source instruction file without introducing additional language learning costs, thereby improving the accuracy of instruction processing and solving the technical problem of low accuracy in instruction processing in related technologies.
- Embodiments of this disclosure also provide a computer program product.
- the computer program product may include a computer program that, when executed by a processor, implements the methods provided in the embodiments described above.
- Embodiments of this disclosure also provide a computer program product.
- the computer program product may include a non-volatile computer-readable storage medium, which can be used to store a computer program that, when executed by a processor, implements the methods provided in the embodiments described above.
- Embodiments of this disclosure also provide a computer program.
- the computer program when executed by a processor, it implements the method provided in the above embodiments.
- the units described as separate components may or may not be physically separate.
- the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
- the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
- the integrated unit can be implemented in hardware or as a software functional unit.
- the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium.
- 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 steps 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 a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
Description
本公开涉及处理器领域,具体而言,涉及一种指令处理方法、指令处理系统以及片上系统。This disclosure relates to the field of processors, and more specifically, to an instruction processing method, an instruction processing system, and a system-on-a-chip.
在工具链软件开发过程中,不同工具链中的工具都是在对指令集的语义进行抽象解释。以一条指令为例,比如模拟器将该指令解释为模拟执行,编译器将该指令解释为匹配到上层语言的对应的操作符序列,汇编器则将该指令解释为匹配到特定的汇编字符串序列。这些过程中围绕的核心内容就是指令集的语义描述。一般情况下,指令集的语义描述是在规范文档中,通过自然或数学语言描述,不同工具的实现者使用同一的文档进行统一的理解和实现,但在这个过程中,很可能出现理解或实现的偏差,从而引发工具链出错,导致对指令进行处理的准确度较低。In toolchain software development, tools within different toolchains abstract and interpret the semantics of instruction sets. Taking a single instruction as an example, a simulator interprets it as simulated execution, a compiler interprets it as matching the corresponding operator sequence in the upper-level language, and an assembler interprets it as matching a specific assembly string sequence. The core content revolving around these processes is the semantic description of the instruction set. Generally, the semantic description of the instruction set is described in a specification document using natural or mathematical language. Implementers of different tools use the same document for unified understanding and implementation. However, in this process, discrepancies in understanding or implementation can easily arise, leading to toolchain errors and lower accuracy in instruction processing.
针对上述的问题,目前尚未提出有效的解决方案。There is currently no effective solution to the above problems.
本公开实施例提供了一种指令处理方法、指令处理系统以及片上系统,以至少解决相关技术中对指令进行处理的准确度较低的技术问题。This disclosure provides an instruction processing method, an instruction processing system, and a system-on-a-chip to at least address the technical problem of low accuracy in instruction processing in related technologies.
根据本公开实施例的一个方面,提供了一种指令处理方法,包括:监测通过工具链处理第一语言的源指令文件的处理流程,确定源指令文件中的待处理指令是否为预设指令;在待处理指令是预设指令的情况下,调用工具链中的解释组件对待处理指令的指令描述信息进行处理,得到第二语言的多个指令元素;通过工具链执行第二语言的多个指令元素,得到待处理指令的处理结果。According to one aspect of the present disclosure, an instruction processing method is provided, comprising: monitoring the processing flow of a source instruction file of a first language processed by a toolchain, and determining whether the instruction to be processed in the source instruction file is a preset instruction; if the instruction to be processed is a preset instruction, calling an interpretation component in the toolchain to process the instruction description information of the instruction to be processed to obtain multiple instruction elements of a second language; and executing the multiple instruction elements of the second language through the toolchain to obtain the processing result of the instruction to be processed.
根据本公开实施例的另一方面,还提供了一种指令处理系统,包括:工具链,至少包含执行组件和解释组件;其中,执行组件用于处理第一语言的源指令文件的处理流程,并确定源指令文件中的待处理指令是否为预设指令;解释组件用于对待处理指令的指令描述信息进行处理,得到第二语言的多个指令元素;执行组件还用于执行第二语言的多个指令元素,得到待处理指令的处理结果。According to another aspect of the embodiments of this disclosure, an instruction processing system is also provided, including: a toolchain, comprising at least an execution component and an interpretation component; wherein, the execution component is used to process the processing flow of a source instruction file in a first language and determine whether the instruction to be processed in the source instruction file is a preset instruction; the interpretation component is used to process the instruction description information of the instruction to be processed to obtain multiple instruction elements in a second language; the execution component is also used to execute the multiple instruction elements in the second language to obtain the processing result of the instruction to be processed.
根据本公开实施例的另一方面,还提供了一种片上系统,包括:上述实施例中任意一项的指令处理系统。According to another aspect of the embodiments of this disclosure, a system-on-a-chip is also provided, including: an instruction processing system of any one of the above embodiments.
根据本公开实施例的另一方面,还提供了一种计算机终端,包括:存储器,存储有可执行程序;处理器,用于运行程序,其中,程序运行时执行本公开各个实施例中的方法。According to another aspect of the embodiments of this disclosure, a computer terminal is also provided, including: a memory storing an executable program; and a processor for running the program, wherein the program executes the methods in the various embodiments of this disclosure when it runs.
根据本公开实施例的另一方面,还提供了一种计算机可读存储介质,计算机可读存储介质包括存储的可执行程序,其中,在可执行程序运行时控制计算机可读存储介质所在设备执行本公开各个实施例中的方法。According to another aspect of the embodiments of the present disclosure, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored executable program, wherein, when the executable program is executed, it controls the device where the computer-readable storage medium is located to perform the methods of the various embodiments of the present disclosure.
根据本公开实施例的另一方面,还提供了一种计算机程序产品,包括计算机程序,计算机程序在被处理器执行时实现本公开各个实施例中的方法。According to another aspect of the embodiments of this disclosure, a computer program product is also provided, including a computer program that, when executed by a processor, implements the methods of various embodiments of this disclosure.
根据本公开实施例的另一方面,还提供了一种计算机程序产品,包括非易失性计算机可读存储介质,非易失性计算机可读存储介质存储计算机程序,计算机程序被处理器执行时实现本公开各个实施例中的方法。According to another aspect of the embodiments of this disclosure, a computer program product is also provided, including a non-volatile computer-readable storage medium storing a computer program that, when executed by a processor, implements the methods in various embodiments of this disclosure.
根据本公开实施例的另一方面,还提供了一种计算机程序,计算机程序被处理器执行时实现本公开各个实施例中的方法。在本公开实施例中,监测通过工具链处理第一语言的源指令文件的处理流程,确定源指令文件中的待处理指令是否为预设指令;在待处理指令是预设指令的情况下,调用工具链中的解释组件对待处理指令的指令描述信息进行处理,得到第二语言的多个指令元素;通过工具链执行第二语言的多个指令元素,得到待处理指令的处理结果,实现了提高对指令进行处理的准确度;容易注意到的是,在通过工具链处理第一语言的源指令文件时,若存在待处理指令为预设指令,可以调用工具链中的解释组件对待处理指令的指令描述信息进行解释,以便得到工具链可以执行的第二语言的多个指令元素,可以在不引入额外的语言学习成本的基础上,使得工具链可以顺利的对源指令文件进行高效准确的处理并执行,从而提高了对指令进行处理的准确度,进而解决了相关技术中对指令进行处理的准确度较低的技术问题。According to another aspect of the embodiments of this disclosure, a computer program is also provided, which, when executed by a processor, implements the methods in the various embodiments of this disclosure. In the embodiments of this disclosure, the processing flow of a source instruction file in a first language processed by a toolchain is monitored to determine whether the instruction to be processed in the source instruction file is a preset instruction; if the instruction to be processed is a preset instruction, an interpretation component in the toolchain is invoked to process the instruction description information of the instruction to be processed, obtaining multiple instruction elements in a second language; the multiple instruction elements in the second language are executed by the toolchain to obtain the processing result of the instruction to be processed, thereby improving the accuracy of instruction processing. It is noteworthy that when processing a source instruction file in a first language through a toolchain, if there is an instruction to be processed that is a preset instruction, the interpretation component in the toolchain can be invoked to interpret the instruction description information of the instruction to be processed, so as to obtain multiple instruction elements in the second language that the toolchain can execute. This allows the toolchain to efficiently and accurately process and execute the source instruction file without introducing additional language learning costs, thereby improving the accuracy of instruction processing and solving the technical problem of low accuracy in instruction processing in related technologies.
容易注意到的是,上面的通用描述和后面的详细描述仅仅是为了对本公开进行举例和解释,并不构成对本公开的限定。It is worth noting that the above general description and the following detailed description are merely for illustrative and explanatory purposes and do not constitute a limitation thereof.
此处所说明的附图用来提供对本公开的进一步理解,构成本公开的一部分,本公开的示意性实施例及其说明用于解释本公开,并不构成对本公开的不当限定。在附图中:The accompanying drawings, which are included to provide a further understanding of this disclosure and form part of this disclosure, illustrate exemplary embodiments of the present disclosure and are used to explain the disclosure, but do not constitute an undue limitation of the disclosure. In the drawings:
图1是根据本公开实施例的一种用于实现指令处理方法的RISC-V系统的硬件结构框图;Figure 1 is a hardware structure block diagram of a RISC-V system for implementing an instruction processing method according to an embodiment of the present disclosure;
图2是根据本公开实施例的一种片上系统的示意图;Figure 2 is a schematic diagram of a system-on-a-chip according to an embodiment of the present disclosure;
图3是根据本公开实施例1的指令处理方法的流程图;Figure 3 is a flowchart of the instruction processing method according to Embodiment 1 of this disclosure;
图4是根据本公开实施例的一种有向无环图的示意图;Figure 4 is a schematic diagram of a directed acyclic graph according to an embodiment of the present disclosure;
图5是根据本公开实施例的一种字符表示的匹配关系示意图;Figure 5 is a schematic diagram of a character representation matching relationship according to an embodiment of the present disclosure;
图6是根据本公开实施例的一种模拟器场景的示意图;Figure 6 is a schematic diagram of a simulator scene according to an embodiment of the present disclosure;
图7是根据本公开实施例的一种指令处理装置的示意图;Figure 7 is a schematic diagram of an instruction processing apparatus according to an embodiment of the present disclosure;
图8是根据本公开实施例的一种指令处理系统的示意;Figure 8 is a schematic diagram of an instruction processing system according to an embodiment of the present disclosure;
图9是根据本公开实施例的一种电子设备的结构框图。Figure 9 is a structural block diagram of an electronic device according to an embodiment of the present disclosure.
为了使本技术领域的人员更好地理解本公开方案,下面将结合本公开实施例中的附图,对本公开实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本公开一部分的实施例,而不是全部的实施例。基于本公开中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于本公开保护的范围。To enable those skilled in the art to better understand the present disclosure, the technical solutions of the present disclosure will be clearly and completely described below with reference to the accompanying drawings of the embodiments. Obviously, the described embodiments are only some embodiments of the present disclosure, and not all embodiments. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present disclosure.
需要说明的是,本公开的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的本公开的实施例能够以除了在这里图示或描述的那些以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
首先,在对本公开实施例进行描述的过程中出现的部分名词或术语适用于如下解释:First, some nouns or terms that appear in the description of the embodiments of this disclosure shall be interpreted as follows:
指令集架构(Instruction Set Architecture,简称为ISA):定义计算机执行指令、寄存器、数据类型等核心接口的一组硬件架构标准;Instruction Set Architecture (ISA): A set of hardware architecture standards that defines the core interfaces of a computer, such as instructions, registers, and data types.
特定领域加速器(Domain-Specific Accelerator,简称为DSA):为改进某一特定应用领域的性能和效率而设计的专用硬件计算设备;Domain-Specific Accelerator (DSA): A dedicated hardware computing device designed to improve the performance and efficiency of a specific application domain;
特定领域语言(Domain-Specific Language,简称为DSL):一种专注于特定问题领域、用途、或任务的计算机编程语言,旨在简化与该领域相关的编程任务。Domain-Specific Language (DSL): A computer programming language that focuses on a specific problem domain, purpose, or task, and is designed to simplify programming tasks related to that domain.
工具链:一组协同工作的软件工具,通常用于编程语言的编译、调试、和构建软件。Toolchain: A set of software tools that work together, typically used for compiling, debugging, and building software for programming languages.
程序语言(Python):一种广泛使用的高级编程语言,以其易读性和简洁的语法而著称,适用于各种编程任务,从网页(Web)开发到数据科学。Python: A widely used high-level programming language known for its readability and concise syntax, suitable for a wide range of programming tasks, from web development to data science.
抽象解释:一种分析程序的方法,通过使用简化(或“抽象”)的数据来代表程序中的实际数据,以简化对程序行为的理解或预测。Abstract Interpretation: A method of analyzing a program by using simplified (or "abstract") data to represent the actual data in the program, in order to simplify the understanding or prediction of the program's behavior.
宿主嵌入式特定领域语言(Embedded Domain-Specific Language,简称为EDSL):建立在另一种(宿主)编程语言中的DSL,利用宿主语言的语法和功能来表达特定领域的逻辑和操作。Embedded Domain-Specific Language (EDSL): A DSL built on another (host) programming language, which uses the syntax and features of the host language to express domain-specific logic and operations.
目前,不同的工具链不能复用实现,一定程度上造成了重复工作。在工具链的使用场景中,处理器核心设计(CPU IP核)的客户有自己定制特定领域加速器的需求,这个加速器的指令集是由客户自己定义的,但工具链是由CPU IP核的厂商提供,因为生成的DSA指令是融合在正常的CPU指令序列中。并且,因为客户指令的保密性和防止工具链碎片化的原因,CPU厂商不能在工具链的开发阶段支持客户的DSA指令定制需求,只能交付一般的工具链二进制发布包。所以,客户需要在收到一般工具链后,在自己的环境中进行工具链的二次开发或配置。此时客户需要对自己设计的DSA指令的语义进行描述,并可以让工具链读取和支持。Currently, different toolchains cannot reuse implementations, leading to some degree of duplication of work. In toolchain use cases, processor core design (CPU IP core) customers often have needs for customized domain-specific accelerators. The instruction set of this accelerator is defined by the customer, but the toolchain is provided by the CPU IP core vendor because the generated DSA instructions are integrated into the normal CPU instruction sequence. Furthermore, due to the confidentiality of customer instructions and the need to prevent toolchain fragmentation, CPU vendors cannot support customers' DSA instruction customization needs during the toolchain development phase; they can only deliver general toolchain binary distribution packages. Therefore, after receiving the general toolchain, customers need to perform secondary development or configuration of the toolchain in their own environment. At this point, customers need to describe the semantics of their designed DSA instructions so that the toolchain can read and support them.
相关技术可以提供指令描述的语言和解析工具,来自动生成工具链的支持代码,但是需要用户学习新语法,且生成器模式会引入一个中间层,对调试和构建都变得复杂和难以跟踪调试。本公开采用Python库的方式将具备更低的语言学习成本和更好的动态加载和灵活性。Related technologies can provide instruction description languages and parsing tools to automatically generate support code for toolchains, but users need to learn new syntax, and the generator pattern introduces an intermediate layer, making debugging and building complex and difficult to trace. This disclosure uses Python libraries, which offers lower language learning costs and better dynamic loading and flexibility.
基于上述的问题和需求,本公开可以把Python作为一种宿主语言来表达指令语义的方法,并将工具链开发过程中如何使用该库做了接口的定义,方便工具链开发者统一指令的实现,也方便DSA客户动态的进行工具链的二次开发和配置。Based on the aforementioned problems and needs, this disclosure provides a method for using Python as a host language to express instruction semantics, and defines the interface for how to use this library during toolchain development. This facilitates unified instruction implementation for toolchain developers and allows DSA customers to dynamically perform secondary development and configuration of the toolchain.
实施例1Example 1
根据本公开实施例,提供了一种指令处理方法,需要说明的是,在附图的流程图示出的步骤可以在诸如一组计算机可执行指令的计算机系统中执行,并且,虽然在流程图中示出了逻辑顺序,但是在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤。According to embodiments of this disclosure, an instruction processing method is provided. It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowcharts, in some cases, the steps shown or described may be executed in a different order than that shown here.
本公开实施例一所提供的方法实施例可以在RISC-V系统、RISC-V芯片或类似装置中执行。图1是根据本公开实施例的一种用于实现指令处理方法的RISC-V系统的硬件结构框图。如图1所示,RISC-V系统100从底层到上层可以分为精简指令集架构101(包含基础指令集101-1和扩展指令集101-2)、硬件层102(包括处理器102-1、外围硬件电路102-2等)、接口层103、操作系统层104(支持多种操作系统104-1,104-2,…,104-n,例如Linux、Free SBD、RT-Tread等)、中间件和库层105(包含系统库105-1、API 105-2和中间件服务105-3)和应用程序层106(包括多种用户程序和服务106-1,106-2,…,106-n)。RISC-V系统100还包含一个从底层硬件到应用程序层之间的工具链107,该工具链可以包括编译器和汇编器107-1、链接器107-2、调试器107-3、模拟器和仿真器107-4、集成开发环境107-5、硬件描述语言工具107-6、性能分析工具107-7和版本控制系统107-8等。The method embodiment provided in Embodiment 1 of this disclosure can be executed in a RISC-V system, a RISC-V chip, or a similar device. Figure 1 is a hardware structure block diagram of a RISC-V system for implementing an instruction processing method according to an embodiment of this disclosure. As shown in Figure 1, the RISC-V system 100 can be divided into the following layers from bottom to top: Reduced Instruction Set Architecture 101 (including basic instruction set 101-1 and extended instruction set 101-2), hardware layer 102 (including processor 102-1, peripheral hardware circuits 102-2, etc.), interface layer 103, operating system layer 104 (supporting multiple operating systems 104-1, 104-2, ..., 104-n, such as Linux, Free SBD, RT-Tread, etc.), middleware and library layer 105 (including system library 105-1, API 105-2, and middleware service 105-3), and application layer 106 (including multiple user programs and services 106-1, 106-2, ..., 106-n). The RISC-V system 100 also includes a toolchain 107 that runs from the underlying hardware to the application layer. This toolchain may include compilers and assemblers 107-1, linkers 107-2, debuggers 107-3, simulators and emulators 107-4, integrated development environments 107-5, hardware description language tools 107-6, performance analysis tools 107-7, and version control systems 107-8, etc.
指令集架构101定义了处理器102-1支持的基本操作和指令集,包括基础指令集和扩展指令集,其中,基础指令集表征基础的整数指令集,如RV32I和RV64I,扩展指令集可以是浮点、原子操作、压缩指令等。The instruction set architecture 101 defines the basic operations and instruction sets supported by the processor 102-1, including the basic instruction set and the extended instruction set. The basic instruction set represents the basic integer instruction set, such as RV32I and RV64I, while the extended instruction set can be floating-point, atomic operations, compressed instructions, etc.
接口层103包括处理器的具体设计,如流水线设计、缓存结构、执行单元、分支预测等。这一层是将抽象指令映射到物理硬件上的过程。Interface layer 103 includes the specific design of the processor, such as pipeline design, cache structure, execution units, branch prediction, etc. This layer is the process of mapping abstract instructions to physical hardware.
操作系统层104位于硬件智商,提供了硬件抽象层和管理机制,使得应用长须能够通过系统调用与硬件交互。操作系统负责管理处理器资源、内存、设备驱动、任务调度等。The operating system layer 104 resides in the hardware layer, providing a hardware abstraction layer and management mechanisms, enabling applications to interact with hardware through system calls. The operating system is responsible for managing processor resources, memory, device drivers, task scheduling, and more.
中间件和库层105提供了一组丰富的服务和接口,帮助应用程序更高效地运行。例如,标准库提供了文件操作、数学计算等功能,而中间件可以提供网络通信、图形用户界面等复杂服务。The middleware and library layer 105 provides a rich set of services and interfaces to help applications run more efficiently. For example, the standard library provides functions such as file operations and mathematical calculations, while middleware can provide complex services such as network communication and graphical user interfaces.
应用程序层106利用下层提供的功能和服务来实现具体的应用逻辑,这些应用程序可以是命令行工具、图形界面应用、服务器端服务等。The application layer 106 utilizes the functions and services provided by the lower layer to implement specific application logic. These applications can be command-line tools, graphical interface applications, server-side services, etc.
工具链107是连接底层硬件到上层软件的关键组件,工具链107中的各种工具在不同层次上发挥作用,以支持从硬件设计到软件开发的整个过程,确保整个系统设计的连贯性和有效性。Toolchain 107 is a key component connecting the underlying hardware to the upper-level software. The various tools in toolchain 107 play a role at different levels to support the entire process from hardware design to software development, ensuring the coherence and effectiveness of the entire system design.
需要说明的是,RISC-V架构的分层设计允许不同层次之间的解耦,使得每一层都可以独立开发和改进。It should be noted that the layered design of the RISC-V architecture allows for decoupling between different layers, enabling each layer to be developed and improved independently.
一种可选实施例中,图2是根据本公开实施例的一种片上系统的示意图,图2示出了使用上述图1所示的RISC-V架构的片上系统(System On Chip,SOC)的示意图。如图2所示,该SOC内部包含至少一个RISC-V内核202(图中仅示出一个),RISC-V内核202通过总线204与外设设备连接,包括但不限于ROM 206、RAM 208、定时器210、UART(通用异步收发传输器,Universal Asynchronous Receiver/Transmitter)212、GPIO(通用输入/输出端口,General Purpose Input/Output)214、SPI(串行外设接口,Serial Peripheral Interface Bus)216等。In one alternative embodiment, FIG2 is a schematic diagram of a system-on-chip according to an embodiment of the present disclosure. FIG2 shows a schematic diagram of a system-on-chip (SOC) using the RISC-V architecture shown in FIG1 above. As shown in FIG2, the SOC contains at least one RISC-V core 202 (only one is shown in the figure). The RISC-V core 202 is connected to peripheral devices through bus 204, including but not limited to ROM 206, RAM 208, timer 210, UART (Universal Asynchronous Receiver/Transmitter) 212, GPIO (General Purpose Input/Output) 214, SPI (Serial Peripheral Interface Bus) 216, etc.
在上述运行环境下,本公开提供了如图3所示的指令处理方法。图3是根据本公开实施例1的指令处理方法的流程图。该方法包括:Under the above operating environment, this disclosure provides an instruction processing method as shown in Figure 3. Figure 3 is a flowchart of the instruction processing method according to Embodiment 1 of this disclosure. The method includes:
步骤S302,监测通过工具链处理第一语言的源指令文件的处理流程,确定源指令文件中的待处理指令是否为预设指令;Step S302: Monitor the processing flow of the source instruction file of the first language through the toolchain, and determine whether the instruction to be processed in the source instruction file is a preset instruction.
上述的工具链是指在软件开发过程中使用的一系列工具的集合,用于支持开发、构建、测试和部署等不同阶段的工作。The aforementioned toolchain refers to a collection of tools used in the software development process to support different stages of work, such as development, building, testing, and deployment.
上述的预设指令可以为预先自定义的指令或者未知指令。若该待处理指令为预设指令,则需要通过工具链对该预设指令进行解释,得到工具链可以识别的指令元素。The aforementioned preset instructions can be pre-defined instructions or unknown instructions. If the instruction to be processed is a preset instruction, it needs to be interpreted by the toolchain to obtain instruction elements that the toolchain can recognize.
上述的源指令文件是计算机程序源代码的文件,可以包含程序的原始代码,一般是使用特定的编程语言编写的。源指令文件通常被编译器或解释器处理,转换成可执行的程序或者解释执行。源指令文件可以包含不同的文件格式(C、C++、Java、Python)等。在软件开发中,源指令文件是程序开发的基础,可以通过编辑和修改源指令文件来实现程序的设计和功能。The source code file mentioned above is a file containing the original code of a computer program, typically written in a specific programming language. Source code files are usually processed by a compiler or interpreter, converting them into an executable program or allowing for interpreted execution. Source code files can contain different file formats (C, C++, Java, Python, etc.). In software development, source code files are fundamental to program development; the design and functionality of a program can be implemented by editing and modifying source code files.
上述的第一语言可以包括但不限于多种程序语言(C、C++、Java、Python),此处对第一语言不做任何限定。The first language mentioned above can include, but is not limited to, various programming languages (C, C++, Java, Python), and no limitation is made on the first language here.
在一种可选的实施例中,可以监测通过工具链处理第一语言的源指令文件的处理流程,以便查看该工具链在处理源指令文件时,是否遇到需要进行解释的预设指令,以便工具链可以顺利的对源指令文件进行执行处理。In one alternative embodiment, the processing flow of source instruction files in the first language processed by the toolchain can be monitored to see if the toolchain encounters preset instructions that need to be interpreted when processing the source instruction files, so that the toolchain can successfully execute and process the source instruction files.
步骤S304,在待处理指令是预设指令的情况下,调用工具链中的解释组件对待处理指令的指令描述信息进行处理,得到第二语言的多个指令元素;Step S304: If the instruction to be processed is a preset instruction, the interpretation component in the toolchain is called to process the instruction description information of the instruction to be processed, and multiple instruction elements in the second language are obtained.
在待处理指令是预设指令的情况下,可以通过调用工具链中的解释组件对待处理指令的指令描述信息进行解释,以便将待处理指令转换为工具链可以识别的第二语言的多个指令元素。When the instruction to be processed is a preset instruction, the instruction description information of the instruction to be processed can be interpreted by calling the interpretation component in the toolchain, so as to convert the instruction to be processed into multiple instruction elements in a second language that the toolchain can recognize.
上述的解释组件可以是指解释器,该解释器可以是一种能够直接解释并执行程序源代码的软件组件。解释器通过逐行解释程序源代码,并即时执行代码,而不需要事先将代码转换成机器码或者中间代码。解释器常常用于解释执行动态语言,如Python、Ruby、JavaScript等。在某些情况下,解释器也可以用于执行静态语言的程序,比如通过解释器执行Java源代码而不是先将其编译成字节码再执行。The aforementioned interpreting component can refer to an interpreter, which is a software component capable of directly interpreting and executing program source code. An interpreter interprets the program source code line by line and executes the code on demand, without first converting the code into machine code or intermediate code. Interpreters are often used to interpret and execute dynamic languages such as Python, Ruby, and JavaScript. In some cases, interpreters can also be used to execute programs in statically typed languages, such as executing Java source code via an interpreter instead of first compiling it into bytecode.
上述的解释组件被用于处理待处理指令的指令描述信息,以得到第二语言的多个指令元素。解释器可以通过解析第一语言的源代码,并将其转换成第二语言的多个指令元素,以便后续处理和执行。本公开以解释组件为Python解释器为例进行说明。The aforementioned interpretation component is used to process the instruction description information of the instructions to be processed, in order to obtain multiple instruction elements in the second language. The interpreter can parse the source code of the first language and convert it into multiple instruction elements in the second language for subsequent processing and execution. This disclosure uses a Python interpreter as an example for illustration.
上述待处理指令的指令描述信息可以是程序或脚本中包含的需要执行的指令或命令的描述信息。指令描述信息可以包括命令的名称、参数、选项和其他相关信息。在计算机编程和脚本编写中,程序员通常会编写一系列需要执行的指令,这些指令描述信息会被解释器、编译器或其他工具进行处理和执行。其中,指令描述信息可以是程序的控制流、函数调用、变量赋值等,解释器可将待处理指令的指令描述信息转换成第二语言的指令元素,使得工具链可以对预设指令进行处理和执行。The instruction description information of the aforementioned instructions to be processed can be the description information of instructions or commands that need to be executed and are contained in a program or script. Instruction description information can include the command name, parameters, options, and other relevant information. In computer programming and scripting, programmers typically write a series of instructions to be executed. This instruction description information is processed and executed by an interpreter, compiler, or other tools. The instruction description information can include the program's control flow, function calls, variable assignments, etc. The interpreter can convert the instruction description information of the instructions to be processed into instruction elements in a second language, enabling the toolchain to process and execute the predefined instructions.
上述的第二语言的多个指令元素可以是能够被工具链所识别的指令元素,指令元素可以是第二语言中的基本指令或原始操作。其中,指令元素可能是指程序的基本操作,例如变量赋值、条件判断、循环操作、函数调用等。这些指令元素是程序的基本组成部分,它们被解释器或编译器处理后,最终转换成计算机能够执行的指令或代码。The aforementioned instruction elements of a second language can be instruction elements that can be recognized by the toolchain. Instruction elements can be basic instructions or primitive operations in the second language. Specifically, instruction elements may refer to basic program operations, such as variable assignment, conditional statements, loop operations, and function calls. These instruction elements are the fundamental components of a program; after being processed by the interpreter or compiler, they are ultimately converted into instructions or code that the computer can execute.
在一种可选的实施例中,在待处理指令为预设指令的情况下,可以调用工具链中的解释组件对待处理指令的指令描述信息进行解释,得到第二语言的多个指令元素,以便后续工具链可以对第二语言的多个指令元素进行处理,得到待处理指令的处理结果。In an optional embodiment, when the instruction to be processed is a preset instruction, the interpretation component in the toolchain can be invoked to interpret the instruction description information of the instruction to be processed, thereby obtaining multiple instruction elements in the second language. This allows the toolchain to process the multiple instruction elements in the second language and obtain the processing result of the instruction to be processed.
步骤S306,通过工具链执行第二语言的多个指令元素,得到待处理指令的处理结果。Step S306: Execute multiple instruction elements of the second language through the toolchain to obtain the processing result of the instruction to be processed.
在一种可选的实施例中,通过调用工具链中的解释组件对待处理指令的指令描述信息进行处理,得到工具链可以识别的第二语言的多个指令元素。可以先确定工具链的类型,通过该工具链对多个指令元素执行该类型对应的语义动作,从而得到上述的处理结果。In one optional embodiment, the instruction description information of the instructions to be processed is processed by invoking the interpretation component in the toolchain to obtain multiple instruction elements in a second language that the toolchain can recognize. The type of the toolchain can be determined first, and then the semantic actions corresponding to that type can be performed on the multiple instruction elements through the toolchain to obtain the aforementioned processing result.
本公开的核心为用来描述指令语义的Python库,该Python库会对指令语义的描述过程中用到的基础操作数和基础操作码进行预定义的元素建模,便于用户使用这些基础元素来构建复杂的指令语义。需要说明的是,元素建模是指Python库会把用到一些基础操作类型和操作预先规范好语义,并定义好该语义,作为库可以直接被用户组合使用。基础元素的定义和集合,类似于低级虚拟指令集IR(LLVM Intermediate Representation,简称为LLVM IR)中的基础指令和类型,同时也预留出用户自定义类型的方式。低级虚拟指令集用于在编译器中表示程序的中间表示形式,该低级虚拟指令集可以是一种类型安全、低级的表示形式,可以被高级语言编译器用来生成机器码或者其他形式的目标代码。The core of this disclosure is a Python library used to describe instruction semantics. This library models the basic operands and opcodes used in the description of instruction semantics using predefined elements, making it easy for users to construct complex instruction semantics using these basic elements. It should be noted that element modeling means the Python library pre-standardizes and defines the semantics of some basic operation types and operations, allowing users to directly combine and use these elements. The definition and set of basic elements are similar to the basic instructions and types in the Low-Level Virtual Instruction Set (LLVM Intermediate Representation, or LLVM IR for short), while also reserving space for user-defined types. The Low-Level Virtual Instruction Set is used to represent the intermediate representation of a program in the compiler. This Low-Level Virtual Instruction Set can be a type-safe, low-level representation that can be used by high-level language compilers to generate machine code or other forms of object code.
示例性的,当用户需要描述一个3操作数输入的指令的时候,可以通过如下方式进行表示:For example, when a user needs to describe an instruction with 3 operands as input, it can be represented as follows:
import TripleOp from thead.dsa.op(从thead.dsa.op类中导入TripleOp类);import TripleOp from thead.dsa.op;
class CustomOp1:TripleOp(自定义类CustomOp1,继承自TripleOp类);class CustomOp1: TripleOp(Custom class CustomOp1, which inherits from class TripleOp);
def asmString():def asmString():
return“muladd”(定义asmString方法,返回字符串“muladd”);return "muladd" (define the asmString method, which returns the string "muladd");
def execute(r1,r2,r3):def execute(r1, r2, r3):
return r1*r2+r3(定义execute方法,接受三个参数r1,r2,r3,并返回r1乘以r2加上r3的结果)。return r1*r2+r3(Define the execute method, which accepts three parameters r1, r2, and r3, and returns the result of r1 multiplied by r2 and r3).
上述的TripleOp是定义的代表3元操作符的类库,CustomOp1是用户自己定义的类,通过继承的方式来使用TripleOp类。用户使用def execute定义了自己这条指令的语义,是操作数1*操作数2+操作数3。execute函数中的r1、r2、r3都是本公开定义的基础操作数元素类型。乘法操作(*)和加法操作(+)为定义的基础操作码元素,由于r1,r2,r3这样的类定义了操作符重载功能,所以用户可以直接用加(+)和乘(*)来构建。The aforementioned `TripleOp` is a defined class library representing ternary operators, while `CustomOp1` is a user-defined class that is used through inheritance. The user defines the semantics of this instruction using `def execute`, which is operand 1 * operand 2 + operand 3. In the `execute` function, `r1`, `r2`, and `r3` are all basic operand element types defined in this publication. Multiplication (*) and addition (+) are defined basic opcode elements. Because classes like `r1`, `r2`, and `r3` define operator overloading capabilities, users can directly construct operations using addition (+) and multiplication (*).
用户可以通过使用预先定义的Python库完成自身指令的语义表达,还可以包括该指令的字符表示,也即上述的asmString函数,字符表示用于表示3元操作符的名称,一般可以用于汇编和反汇编。其中,asmString函数是一种用于将字符串转换为汇编代码的函数,可以将一个字符串转换为一系列的汇编指令,使得程序可以动态地生成和执行这些指令。Users can use predefined Python libraries to express the semantics of their own instructions, including a character representation of the instruction, as described in the `asmString` function. This character representation is used to represent the names of ternary operators and is generally used in assembly and disassembly. The `asmString` function is used to convert a string into assembly code, transforming it into a series of assembly instructions that allow the program to dynamically generate and execute.
通过上述步骤,监测通过工具链处理第一语言的源指令文件的处理流程,确定源指令文件中的待处理指令是否为预设指令;在待处理指令是预设指令的情况下,调用工具链中的解释组件对待处理指令的指令描述信息进行处理,得到第二语言的多个指令元素;通过工具链执行第二语言的多个指令元素,得到待处理指令的处理结果,实现了提高对指令进行处理的准确度;容易注意到的是,在通过工具链处理第一语言的源指令文件时,若存在待处理指令为预设指令,可以调用工具链中的解释组件对待处理指令的指令描述信息进行解释,以便得到工具链可以执行的第二语言的多个指令元素,可以在不引入额外的语言学习成本的基础上,使得工具链可以顺利的对源指令文件进行高效准确的处理并执行,从而提高了对指令进行处理的准确度,进而解决了相关技术中对指令进行处理的准确度较低的技术问题。Through the above steps, the processing flow of the first language source instruction file processed by the toolchain is monitored to determine whether the instruction to be processed in the source instruction file is a preset instruction. If the instruction to be processed is a preset instruction, the interpretation component in the toolchain is called to process the instruction description information of the instruction to be processed, thereby obtaining multiple instruction elements in the second language. The toolchain executes the multiple instruction elements in the second language to obtain the processing result of the instruction to be processed, thus improving the accuracy of instruction processing. It is worth noting that when processing the first language source instruction file through the toolchain, if there is an instruction to be processed that is a preset instruction, the interpretation component in the toolchain can be called to interpret the instruction description information of the instruction to be processed, so as to obtain multiple instruction elements in the second language that the toolchain can execute. This allows the toolchain to efficiently and accurately process and execute the source instruction file without introducing additional language learning costs, thereby improving the accuracy of instruction processing and solving the technical problem of low accuracy in instruction processing in related technologies.
本公开上述实施例中,调用工具链中的解释组件对待处理指令的指令描述信息进行处理,得到第二语言的多个指令元素,包括:通过解释组件对指令描述信息进行处理,生成有向无环图,其中,有向无环图包含的多个节点与多个指令元素一一对应,有向无环图中连接在不同节点之间的边用于表征不同指令元素之间的关联关系。In the above embodiments of this disclosure, the interpretation component in the toolchain is invoked to process the instruction description information of the instruction to be processed to obtain multiple instruction elements in the second language. This includes: processing the instruction description information through the interpretation component to generate a directed acyclic graph, wherein the multiple nodes contained in the directed acyclic graph correspond one-to-one with the multiple instruction elements, and the edges connecting different nodes in the directed acyclic graph are used to represent the association relationship between different instruction elements.
上述的有向无环图(Directed Acyclic Graph,DAG)是一种图形结构,由多个节点和节点之间的有向边组成,节点与指令元素一一对应,边用于表征不同指令元素之间的关联关系。有向无环图可以用来表示程序执行过程中的指令流程和依赖关系。每个节点代表一个指令元素,比如变量赋值、条件判断、函数调用等。有向边表示不同指令元素之间的关系,比如依赖关系、执行顺序等。The Directed Acyclic Graph (DAG) described above is a graph structure composed of multiple nodes and directed edges between them. Each node corresponds one-to-one with an instruction element, and the edges represent the relationships between different instruction elements. DAGs can be used to represent the instruction flow and dependencies during program execution. Each node represents an instruction element, such as variable assignment, conditional judgment, or function call. Directed edges represent the relationships between different instruction elements, such as dependencies and execution order.
如果待处理的指令描述信息包含了一段程序的控制流,解释组件可以根据这些描述信息生成一个有向无环图。图中的节点代表程序的各个指令元素,比如赋值操作、条件判断、循环操作等,而边则表示这些指令元素之间的执行顺序和依赖关系。这样的有向无环图可以帮助程序分析和改进,同时也能够直观地展现程序的执行流程和指令之间的关系。If the instruction description information to be processed contains a section of program control flow, the interpretation component can generate a directed acyclic graph (DAG) based on this description information. The nodes in the graph represent various instruction elements of the program, such as assignment operations, conditional statements, and loop operations, while the edges represent the execution order and dependencies between these instruction elements. Such a DAG can help with program analysis and improvement, and also visually represent the program's execution flow and the relationships between instructions.
在确定待处理指令的指令描述信息之后,可以在Python侧构建一个描述指令语义的有向无环图,然后,可以将该有向无环图载入到不同的工具链中,不同工具链可以对这个有向无环图做出不同的语义动作,从而形成不同的用途。可选的,可以将整个有向无环图载入到工具链中。示例性的,如果将有向无环图载入到模拟器中,那么对各个节点的语义动作就是在模拟器里执行各个节点所表示的语义。如果将有向无环图载入到编译器中,那么对各个节点的语义动作就是匹配到各个节点对应语义的上层代表,以生成这条用户描述的指令。After determining the instruction description information of the instruction to be processed, a directed acyclic graph (DAG) describing the instruction semantics can be constructed on the Python side. This DAG can then be loaded into different toolchains, each capable of performing different semantic actions on the DAG for different purposes. Optionally, the entire DAG can be loaded into a toolchain. For example, if the DAG is loaded into a simulator, the semantic actions on each node are executed within the simulator, representing the semantics of that node. If the DAG is loaded into a compiler, the semantic actions on each node are matched against the higher-level representative of the corresponding semantics to generate the user-described instruction.
图4是根据本公开实施例的一种有向无环图的示意图,如图4所示,可以将指令描述信息输入至Python解释器中,通过该Python解释器可以对指令描述信息进行处理,生成指令描述信息的有向无环图,该有向无环图中包括加+、*、R1、R2、R3,对该有向无环图进行解释执行,为有向无环图中的各个节点执行一个语义动作。Figure 4 is a schematic diagram of a directed acyclic graph according to an embodiment of the present disclosure. As shown in Figure 4, instruction description information can be input into a Python interpreter. The Python interpreter can process the instruction description information to generate a directed acyclic graph of instruction description information. The directed acyclic graph includes +, *, R1, R2, and R3. The directed acyclic graph is interpreted and executed to perform a semantic action on each node in the directed acyclic graph.
本公开上述实施例中,该方法还包括:载入配置文件至工具链,其中,配置文件包含至少一个预设指令的指令描述信息;将至少一个预设指令的字符表示与待处理指令的字符表示进行匹配,确定待处理指令的指令描述信息。In the above embodiments of this disclosure, the method further includes: loading a configuration file into the toolchain, wherein the configuration file contains instruction description information of at least one preset instruction; matching the character representation of at least one preset instruction with the character representation of an instruction to be processed to determine the instruction description information of the instruction to be processed.
在一种可选的实施例中,可以通过工具链中嵌入Python解释器来完成Python代码的解释执行,得到至少一个预设指令的有向无环图,可以将该有向无环图通过Python与其他语言的绑定关系(binding)来完成相互调用解释执行,例如C++调用Python的binding。In one alternative embodiment, Python code can be interpreted and executed by embedding a Python interpreter in the toolchain to obtain a directed acyclic graph of at least one preset instruction. This directed acyclic graph can then be interpreted and executed by mutual calls between Python and other languages through binding relationships, such as C++ calling Python's binding.
在另一种可选的实施例中,可以将预设指令的指令描述信息保存在配置文件中,然后将该配置文件加载到工具链中,该指令描述信息可以包括指令的名称、参数、选项、以及其他与指令相关的信息。在待处理指令的字符表示与配置文件中的预设指令的字符表示进行匹配时,工具链可以使用这些信息来确定待处理指令的指令描述信息。In another alternative embodiment, the instruction description information of preset instructions can be stored in a configuration file, and then the configuration file is loaded into the toolchain. This instruction description information may include the instruction's name, parameters, options, and other instruction-related information. When the character representation of the instruction to be processed is matched with the character representation of the preset instructions in the configuration file, the toolchain can use this information to determine the instruction description information of the instruction to be processed.
示例性的,配置文件中包含了一个名为“print”的预设指令,该预设指令表示打印输出的操作。在待处理指令的字符表示中包含了“print”这个指令时,工具链可以通过匹配配置文件中预设指令的指令描述信息,确定待处理指令的指令描述信息,以便后续的处理和执行。工具链可以根据预设指令的指令描述信息,自动识别和处理待处理指令,从而提高了工具链的灵活性和可配置性,从而便于开发人员能够更加方便地定义和使用自己的指令描述信息,以适应不同的开发需求。For example, the configuration file contains a preset instruction named "print," which represents the print operation. When the character representation of the instruction to be processed contains the instruction "print," the toolchain can determine the instruction description information of the instruction to be processed by matching the instruction description information of the preset instruction in the configuration file, so as to facilitate subsequent processing and execution. The toolchain can automatically identify and process the instruction to be processed based on the instruction description information of the preset instruction, thereby improving the flexibility and configurability of the toolchain. This makes it easier for developers to define and use their own instruction description information to adapt to different development needs.
不同的工具软件对有向无环图的解释执行的语义动作不同,比如汇编器是做文字的匹配,不同节点完成一个指令的匹配,模拟器是对不同节点完成一个模拟执行的操作,编译器是对不同节点完成一个上层语言的中间代码匹配。Different software tools perform different semantic actions when interpreting directed acyclic graphs. For example, an assembler performs text matching, matching different nodes to complete an instruction matching, a simulator performs a simulated execution operation on different nodes, and a compiler performs intermediate code matching of a higher-level language on different nodes.
图5是根据本公开实施例的一种字符表示的匹配关系示意图,如图5所示,可以将指令描述信息分别输入到不同的工具链中进行执行,图5中示出的上方的工具链可以为模拟工具链,模拟工具链的执行器可以为模拟器(Simulator),图5中示出的下方的工具链可以为编译工具链,编译工具链的执行器可以为编译器(Compiler),模拟工具链中的Python解释器可以根据指令描述信息生成有向无环图,对该有向无环图进行解释执行,该解释执行过程可以为基于有向无环图进行模拟执行;编译工具链中的Python解释器可以根据指令描述信息生成有向无环图,对该有向无环图进行解释执行,该解释执行过程可以为基于有向无环图进行指令选择。通过图5的方式,达到了使用同一份指令描述信息来构建不同工具链的目的。Figure 5 is a schematic diagram of a character representation matching relationship according to an embodiment of the present disclosure. As shown in Figure 5, instruction description information can be input into different toolchains for execution. The upper toolchain shown in Figure 5 can be a simulation toolchain, and the executor of the simulation toolchain can be a simulator. The lower toolchain shown in Figure 5 can be a compilation toolchain, and the executor of the compilation toolchain can be a compiler. The Python interpreter in the simulation toolchain can generate a directed acyclic graph (DAG) based on the instruction description information and interpret and execute the DAG. This interpretation and execution process can be simulated execution based on the DAG. Similarly, the Python interpreter in the compilation toolchain can generate a DAG based on the instruction description information and interpret and execute the DAG. This interpretation and execution process can be instruction selection based on the DAG. Through the method shown in Figure 5, the purpose of using the same instruction description information to construct different toolchains is achieved.
本公开上述实施例中,将至少一个预设指令的字符表示与待处理指令的字符表示进行匹配,确定待处理指令的指令描述信息,包括:在任意一个预设指令的字符表示与待处理指令的字符表示相同的情况下,确定任意一个预设指令的指令描述信息为待处理指令的指令描述信息。In the above embodiments of this disclosure, matching the character representation of at least one preset instruction with the character representation of an instruction to be processed to determine the instruction description information of the instruction to be processed includes: if the character representation of any preset instruction is the same as the character representation of the instruction to be processed, determining the instruction description information of any preset instruction as the instruction description information of the instruction to be processed.
在一种可选的实施例中,在任意一个预设指令的字符表示与待处理指令的字符表示相同的情况下,确定任意一个预设指令的指令描述信息为待处理指令的指令描述信息意味着当待处理指令的字符表示与预设指令中的字符表示相匹配时,工具链会将待处理指令的指令描述信息设置为匹配到的预设指令的指令描述信息。可选的,可以对预设指令的字符表示和待处理指令的字符表示进行相似度匹配,从而根据任意一个预设指令的指令描述信息确定出待处理指令的指令描述信息。In an optional embodiment, if the character representation of any preset instruction is the same as the character representation of the instruction to be processed, determining the instruction description information of any preset instruction as the instruction description information of the instruction to be processed means that when the character representation of the instruction to be processed matches the character representation in the preset instruction, the toolchain will set the instruction description information of the instruction to be processed to the instruction description information of the matched preset instruction. Optionally, a similarity match can be performed between the character representations of the preset instructions and the character representations of the instruction to be processed, thereby determining the instruction description information of the instruction to be processed based on the instruction description information of any preset instruction.
本公开上述实施例中,通过工具链执行第二语言的多个指令元素,得到待处理指令的处理结果,包括:确定工具链的目标类型,并确定目标类型对应的目标语义动作;通过工具链对多个指令元素进行目标语义动作,得到处理结果。In the above embodiments of this disclosure, the processing result of the instruction to be processed is obtained by executing multiple instruction elements of the second language through a toolchain, including: determining the target type of the toolchain and determining the target semantic action corresponding to the target type; and performing target semantic actions on multiple instruction elements through the toolchain to obtain the processing result.
上述的目标类型可以根据工具链的用途和功能进行分类,工具链的目标类型包括编译器链、解释器链、构建工具链等。其中,编译器链包括但不限于预处理、编译、汇编、链接等过程,解释器链包括但不限于将源代码翻译成机器代码并立即执行,构建工具链包括但不限于用于自动化构建、测试和部署软件。The target types mentioned above can be categorized based on the purpose and function of the toolchain. Toolchain target types include compiler chains, interpreter chains, and build toolchains. Compiler chains include, but are not limited to, preprocessing, compilation, assembly, and linking processes; interpreter chains include, but are not limited to, translating source code into machine code for immediate execution; and build toolchains include, but are not limited to, those used for automating software building, testing, and deployment.
上述目标类型对应的目标语义动作可以根据具体的工具链和目标类型而定。例如,对于编译器链,目标类型可能包括可执行文件、动态链接库、静态库等,而对应的目标语义动作包括将源代码翻译成目标类型所需的机器码或中间代码,并进行链接等操作。The target semantic actions corresponding to the aforementioned target types can be determined based on the specific toolchain and target type. For example, for a compiler chain, target types may include executable files, dynamic link libraries, static libraries, etc., and the corresponding target semantic actions may include translating the source code into the machine code or intermediate code required by the target type, and performing linking operations.
上述的目标语义动作是指在软件开发中,工具链对指令元素进行处理时所执行的操作,以满足特定的目标类型。这些操作是为了将源代码转换为目标类型所需的形式或执行特定的功能。其中,目标语义动作可以包括编译、链接、改进、解释执行等,具体取决于工具链的类型和目标类型。对于解释器链,目标类型可能是执行特定的脚本或程序,而目标语义动作则是解释和执行源代码中的指令。此处仅作示例说明,具体的目标类型对应的目标语义动作可以根据实际情况确定。The aforementioned target semantic actions refer to the operations performed by the toolchain when processing instruction elements in software development to satisfy a specific target type. These operations are to transform the source code into the form required by the target type or to perform specific functions. Target semantic actions can include compilation, linking, improvement, and interpreted execution, depending on the toolchain type and the target type. For interpreter chains, the target type might be executing a specific script or program, while the target semantic action is interpreting and executing the instructions in the source code. This is only an illustrative example; the specific target semantic actions corresponding to a particular target type can be determined based on the actual situation.
在一种可选的实施例中,可以先确定工具链的目标类型,并获取到该目标类型对应的目标语义动作,工具链可以对多个指令元素执行目标语义动作,从而使得工具链可以对多个指令元素进行准确无误的处理,得到处理结果。In one optional embodiment, the target type of the toolchain can be determined first, and the target semantic action corresponding to the target type can be obtained. The toolchain can execute the target semantic action on multiple instruction elements, thereby enabling the toolchain to process multiple instruction elements accurately and obtain processing results.
图6是根据本公开实施例的一种模拟器场景的示意图,如图6所示,可以将Python写的指令描述信息作为配置文件载入至模拟器的工具链中,然后正常处理该工具链的源文件输入,该源文件可以为目标汇编语言,当碰到未知指令或者用户自定义指令的时候再回调Python解释器中载入的自定义的指令描述信息,可以通过Python解释器对指令描述信息进行处理,生成有向无环图,通过该有向无环图得到多个指令元素,并通过执行器对多个指令元素进行执行,得到指令元素的目标语义动作。Figure 6 is a schematic diagram of a simulator scenario according to an embodiment of the present disclosure. As shown in Figure 6, instruction description information written in Python can be loaded into the simulator's toolchain as a configuration file. Then, the source file input of the toolchain is processed normally. The source file can be a target assembly language. When an unknown instruction or a user-defined instruction is encountered, the custom instruction description information loaded in the Python interpreter is called back. The instruction description information can be processed by the Python interpreter to generate a directed acyclic graph. Multiple instruction elements are obtained through the directed acyclic graph, and the multiple instruction elements are executed by the executor to obtain the target semantic action of the instruction elements.
本公开上述实施例中,确定目标类型对应的目标语义动作,包括:在目标类型为模拟器的情况下,确定目标语义动作为在模拟器中执行多个指令元素的语义;在目标类型为汇编器的情况下,确定目标语义动作为将多个指令元素与文本进行匹配;在目标类型为编译器的情况下,确定目标语义动作为将多个指令元素与第一语言的中间指令进行匹配。In the above embodiments of this disclosure, determining the target semantic action corresponding to the target type includes: when the target type is a simulator, determining the target semantic action as executing the semantics of multiple instruction elements in the simulator; when the target type is an assembler, determining the target semantic action as matching multiple instruction elements with text; and when the target type is a compiler, determining the target semantic action as matching multiple instruction elements with intermediate instructions of a first language.
上述的模拟器可以是一种计算机程序,可以模拟硬件平台的行为,允许用户在模拟环境中执行指令集架构中的指令,以便进行软件开发、调试和性能分析。模拟器通常用于模拟特定的计算机体系结构、处理器或设备,使得开发人员能够在没有实际硬件的情况下进行软件开发和测试。上述的汇编器是一种将汇编语言代码翻译成机器码或者目标文件的工具。汇编器将程序员编写的汇编语言指令转换为可执行的二进制代码,使得计算机可以直接执行。汇编器是编程工具链中的重要组成部分,用于将汇编语言代码转换成机器码,以便计算机执行。上述的编译器是一种将高级编程语言代码翻译成目标平台的机器码或中间代码的工具。编译器将程序员编写的高级语言代码(如C、C++、Java等)转换成目标平台可执行的代码,包括可执行文件、库文件等。编译器也可以将高级语言代码翻译成中间表示形式,以便后续的改进和目标代码生成。The simulator described above can be a computer program that simulates the behavior of a hardware platform, allowing users to execute instructions from an instruction set architecture in a simulated environment for software development, debugging, and performance analysis. Simulators are typically used to simulate specific computer architectures, processors, or devices, enabling developers to develop and test software without actual hardware. The assembler described above is a tool that translates assembly language code into machine code or object files. An assembler converts programmer-written assembly language instructions into executable binary code that a computer can directly execute. The assembler is an important component of the programming toolchain, used to convert assembly language code into machine code for computer execution. The compiler described above is a tool that translates high-level programming language code into machine code or intermediate code for a target platform. A compiler converts programmer-written high-level language code (such as C, C++, Java, etc.) into executable code for the target platform, including executable files, library files, etc. A compiler can also translate high-level language code into an intermediate representation for subsequent improvements and target code generation.
在目标类型为模拟器的情况下,目标语义动作是在模拟器中执行多个指令元素的语义。工具链可以模拟目标硬件平台的行为,逐条执行多个指令元素,以便在模拟环境中观察和分析程序的行为和性能。When the target type is a simulator, the target semantic action is the semantics of executing multiple instruction elements in the simulator. The toolchain can simulate the behavior of the target hardware platform, executing multiple instruction elements one by one, so as to observe and analyze the program's behavior and performance in a simulation environment.
在目标类型为汇编器的情况下,目标语义动作是将多个指令元素与文本进行匹配。工具链可以把多个指令元素翻译成对应的汇编文本表示,这个过程也就是汇编的过程。When the target type is an assembler, the target semantic action is to match multiple instruction elements with text. The toolchain can translate these instruction elements into their corresponding assembly text representations; this process is the assembly process.
在目标类型为编译器的情况下,目标语义动作是将多个指令元素与第一语言的中间指令进行匹配。工具链可以把多个指令元素翻译成第一语言的中间表示形式,这个过程也就是编译的过程。When the target type is a compiler, the target semantic action is to match multiple instruction elements with intermediate instructions in the first language. The toolchain can translate these instruction elements into an intermediate representation in the first language; this process is the compilation process.
本公开上述实施例中,预设指令用于表征未包含在精简指令集中的指令,或者由目标对象设定的指令。In the embodiments described above, the preset instruction is used to characterize an instruction not included in the simplified instruction set, or an instruction set by the target object.
上述的精简指令集可以通过开源指令集架构(RV架构)得到,RV架构是一种精简指令集计算机架构,该结构的设计目标是简化指令集,提高处理器性能和功耗效率。计算机中的处理器采用了RV架构则说明该计算机可以使用RV指令集,能够执行RV架构的特定指令集,从而实现了更高的性能和功耗效率。The aforementioned reduced instruction set architecture can be obtained through the open-source instruction set architecture (RV architecture). RV architecture is a reduced instruction set computer architecture designed to simplify the instruction set and improve processor performance and power efficiency. If a computer's processor uses the RV architecture, it means that the computer can use the RV instruction set and can execute specific instructions from the RV architecture, thereby achieving higher performance and power efficiency.
上述的目标对象可以为用户,也可以为任意对象。The target object mentioned above can be a user or any object.
上述的工具链可以用于对精简指令集进行处理,预设指令可以为未知指令或者由用户预先设置的指令。The toolchain described above can be used to process a reduced instruction set. The preset instructions can be unknown instructions or instructions pre-set by the user.
本公开统一了指令集在工具链中语义的实现方式,解决了各个工具独自实现指令集语义过程中可能出现的语义不一致的问题,减少了工具链实现过程中的错误和重复劳动。同时,本公开还可以应用到客户特定加速器所使用的扩展指令集的语义描述和实现中,便于客户自主描述扩展指令集的语义,并即时完成工具链对扩展指令的支持。本公开的创新点在于没有重新发明新的指令语义描述语言,而是采用目前已有的程序语言作为宿主语言来描述指令语义,创建了一种特定领域加速器,简化了学习成本,并且可以方便即时嵌入各个工具链中使用。This disclosure standardizes the implementation of instruction set semantics in toolchains, resolving potential semantic inconsistencies that may arise when individual tools implement instruction set semantics independently, and reducing errors and redundant work during toolchain implementation. Furthermore, this disclosure can be applied to the semantic description and implementation of extended instruction sets used by customer-specific accelerators, facilitating customers' independent description of extended instruction set semantics and enabling immediate toolchain support for extended instructions. The innovation of this disclosure lies in its avoidance of reinventing a new instruction semantic description language; instead, it utilizes existing programming languages as the host language to describe instruction semantics, creating a domain-specific accelerator that simplifies the learning curve and allows for easy and immediate embedding into various toolchains.
用户可以通过Python自主描述扩展指令集的语义,生成配置文件,从而特定领域加速器可以通过Python到特定语言的触发操作(binding)来回调扩展指令集的语义,针对有向无环图(Directed Acyclic Graph,简称为DAG)的节点做响应,以处理特定处理,从而增加了工具链的能力。Users can independently describe the semantics of the extended instruction set using Python and generate configuration files. This allows domain-specific accelerators to use Python-to-language bindings to call back the semantics of the extended instruction set and respond to nodes in the Directed Acyclic Graph (DAG) to handle specific processes, thereby increasing the capabilities of the toolchain.
上述有向无环图的节点可以是有向无环图中的任意一个数据节点,该数据节点可以表示图中的一个特定元素或实体,并与其他节点通过有向边相连。在工具链中,有向无环图的节点通常代表工具链中的一个特定处理步骤或操作。The nodes in the aforementioned directed acyclic graph (DAG) can be any data node in the DAG, representing a specific element or entity in the graph and connected to other nodes via directed edges. In toolchains, nodes in a DAG typically represent a specific processing step or operation within the toolchain.
在本公开中,由于没有使用新的特定领域语言来描述指令的语义,因此,不会引入额外的语言学习成本,不需要构建新语言的解释器,并且没有设计模式(Generator模式)造成的中间层,调试过程会更加直接。可选的,通过使用Python这样的动态语言,因此可以方便用户在已有的工具链发布包上快速加载的调试,方便二次开发。本公开中,采用Python作为宿主语言描述指令集的语义,比其他方法具备更大的动态性和灵活性,可以降低二次开发的成本,通过设计Python语义描述库,降低了语义描述的门槛,提供了统一的指令描述接口和范式,减少重复工作。In this disclosure, since no new domain-specific language is used to describe the semantics of instructions, no additional language learning costs are introduced, there is no need to build an interpreter for a new language, and there is no intermediate layer caused by design patterns (Generator pattern), making the debugging process more direct. Optionally, by using a dynamic language like Python, users can easily load and debug on existing toolchain distribution packages, facilitating secondary development. This disclosure, using Python as the host language to describe the semantics of the instruction set, offers greater dynamism and flexibility than other methods, reducing the cost of secondary development. By designing a Python semantic description library, the threshold for semantic description is lowered, providing a unified instruction description interface and paradigm, reducing repetitive work.
需要说明的是,本公开所涉及的用户信息(包括但不限于用户设备信息、用户个人信息等)和数据(包括但不限于用于分析的数据、存储的数据、展示的数据等),均为经用户授权或者经过各方充分授权的信息和数据,并且相关数据的收集、使用和处理需要遵守相关国家和地区的相关法律法规和标准,并提供有相应的操作入口,供用户选择授权或者拒绝。It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.
需要说明的是,对于前述的各方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本公开并不受所描述的动作顺序的限制,因为依据本公开,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作和模块并不一定是本公开所必须的。It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this disclosure is not limited to the described order of actions, because according to this disclosure, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this disclosure.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到根据上述实施例的方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,本公开的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本公开各个实施例的方法。Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, they can also be implemented by hardware. Based on this understanding, the technical solutions of this disclosure, in essence, or the parts that contribute to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of this disclosure.
实施例2Example 2
根据本公开实施例,还提供了一种用于实施上述指令处理方法的指令处理装置,图7是根据本公开实施例的一种指令处理装置的示意图,如图7所示,该装置700包括:监测模块702、调用模块704、执行模块706。According to an embodiment of the present disclosure, an instruction processing device for implementing the above-described instruction processing method is also provided. FIG7 is a schematic diagram of an instruction processing device according to an embodiment of the present disclosure. As shown in FIG7, the device 700 includes: a monitoring module 702, a calling module 704, and an execution module 706.
其中,监测模块用于监测通过工具链处理第一语言的源指令文件的处理流程,确定源指令文件中的待处理指令是否为预设指令;调用模块用于在待处理指令是预设指令的情况下,调用工具链中的解释组件对待处理指令的指令描述信息进行处理,得到第二语言的多个指令元素;执行模块用于通过工具链执行第二语言的多个指令元素,得到待处理指令的处理结果。The monitoring module is used to monitor the processing flow of the source instruction file of the first language through the toolchain and determine whether the instruction to be processed in the source instruction file is a preset instruction; the calling module is used to call the interpretation component in the toolchain to process the instruction description information of the instruction to be processed when the instruction to be processed is a preset instruction, so as to obtain multiple instruction elements of the second language; the execution module is used to execute multiple instruction elements of the second language through the toolchain to obtain the processing result of the instruction to be processed.
此处需要说明的是,上述监测模块702、调用模块704、执行模块706对应于实施例1中的步骤S302至步骤S306,三个模块与对应的步骤所实现的实例和应用场景相同,但不限于上述实施例一所公开的内容。需要说明的是,上述模块或单元可以是存储在存储器(例如,存储器104)中并由一个或多个处理器(例如,处理器102a、102b,……,102n)处理的硬件组件或软件组件,上述模块也可以作为装置的一部分可以运行在实施例一提供的计算机终端10中。It should be noted that the monitoring module 702, the calling module 704, and the execution module 706 mentioned above correspond to steps S302 to S306 in Embodiment 1. The three modules and their corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in Embodiment 1. It should be noted that the above modules or units can be hardware or software components stored in memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n). The above modules can also be part of a device and run in the computer terminal 10 provided in Embodiment 1.
本公开上述实施例中,调用模块还用于通过解释组件对指令描述信息进行处理,生成有向无环图,其中,有向无环图包含的多个节点与多个指令元素一一对应,有向无环图中连接在不同节点之间的边用于表征不同指令元素之间的关联关系。In the above embodiments of this disclosure, the calling module is further configured to process the instruction description information through the interpretation component to generate a directed acyclic graph, wherein the multiple nodes contained in the directed acyclic graph correspond one-to-one with multiple instruction elements, and the edges connecting different nodes in the directed acyclic graph are used to characterize the association relationship between different instruction elements.
本公开上述实施例中,该装置还包括:载入模块、匹配模块。In the above embodiments of this disclosure, the device further includes: a loading module and a matching module.
其中,载入模块用于载入配置文件至工具链,其中,配置文件包含至少一个预设指令的指令描述信息;匹配模块用于将至少一个预设指令的字符表示与待处理指令的字符表示进行匹配,确定待处理指令的指令描述信息。The loading module is used to load the configuration file into the toolchain. The configuration file contains instruction description information for at least one preset instruction. The matching module is used to match the character representation of at least one preset instruction with the character representation of the instruction to be processed to determine the instruction description information of the instruction to be processed.
本公开上述实施例中,匹配模块还用于在任意一个预设指令的字符表示与待处理指令的字符表示相同的情况下,确定任意一个预设指令的指令描述信息为待处理指令的指令描述信息。In the above embodiments of this disclosure, the matching module is further configured to determine the instruction description information of any preset instruction as the instruction description information of the instruction to be processed when the character representation of any preset instruction is the same as the character representation of the instruction to be processed.
本公开上述实施例中,执行模块还用于确定工具链的目标类型,并确定目标类型对应的目标语义动作;通过工具链对多个指令元素进行目标语义动作,得到处理结果。In the above embodiments of this disclosure, the execution module is further configured to determine the target type of the toolchain and the target semantic action corresponding to the target type; and to perform target semantic actions on multiple instruction elements through the toolchain to obtain the processing result.
本公开上述实施例中,执行模块还用于在目标类型为模拟器的情况下,确定目标语义动作为在模拟器中执行多个指令元素的语义;在目标类型为汇编器的情况下,确定目标语义动作为将多个指令元素与文本进行匹配;在目标类型为编译器的情况下,确定目标语义动作为将多个指令元素与第一语言的中间指令进行匹配。In the above embodiments of this disclosure, the execution module is further configured to determine the target semantic action as executing multiple instruction elements in the simulator when the target type is a simulator; determine the target semantic action as matching multiple instruction elements with text when the target type is an assembler; and determine the target semantic action as matching multiple instruction elements with intermediate instructions of the first language when the target type is a compiler.
本公开上述实施例中,预设指令用于表征未包含在精简指令集中的指令,或者由目标对象设定的指令。In the embodiments described above, the preset instruction is used to characterize an instruction not included in the simplified instruction set, or an instruction set by the target object.
需要说明的是,本公开上述实施例中涉及到的优选实施方案与实施例1提供的方案以及应用场景、实施过程相同,但不仅限于实施例1所提供的方案。It should be noted that the preferred implementation schemes involved in the above embodiments of this disclosure are the same as the schemes, application scenarios and implementation processes provided in Embodiment 1, but are not limited to the schemes provided in Embodiment 1.
实施例3Example 3
根据本公开实施例,还提供了一种指令处理系统,图8是根据本公开实施例的一种指令处理系统的示意图,如图8所示,该系统800包括:工具链802,工具链802至少包含执行组件8021和解释组件8022。According to an embodiment of the present disclosure, an instruction processing system is also provided. FIG8 is a schematic diagram of an instruction processing system according to an embodiment of the present disclosure. As shown in FIG8, the system 800 includes: a toolchain 802, which includes at least an execution component 8021 and an interpretation component 8022.
其中,工具链,至少包含执行组件和解释组件;其中,执行组件用于处理第一语言的源指令文件的处理流程,并确定源指令文件中的待处理指令是否为预设指令;解释组件用于对待处理指令的指令描述信息进行处理,得到第二语言的多个指令元素;执行组件还用于执行第二语言的多个指令元素,得到待处理指令的处理结果。The toolchain includes at least an execution component and an interpretation component. The execution component is used to process the source instruction file of the first language and determine whether the instruction to be processed in the source instruction file is a preset instruction. The interpretation component is used to process the instruction description information of the instruction to be processed to obtain multiple instruction elements of the second language. The execution component is also used to execute the multiple instruction elements of the second language to obtain the processing result of the instruction to be processed.
上述的执行组件可以表示用于执行程序源代码的组件,可以将源代码翻译成机器码或中间代码,然后在目标平台上运行。执行组件可以是编译器、汇编器、链接器等,它们负责将源代码转换成可执行的程序或库。The execution components mentioned above can refer to components used to execute program source code. They translate the source code into machine code or intermediate code, and then run it on the target platform. Execution components can be compilers, assemblers, linkers, etc., which are responsible for converting source code into executable programs or libraries.
上述的解释组件可以表示用于解释执行程序源代码的组件,可以通过逐行解释执行源代码,以实现程序的功能。解释组件可以是解释器,可以直接解释执行脚本或程序源代码。The aforementioned interpreting component can represent a component used to interpret and execute program source code. It can achieve the program's functionality by interpreting and executing the source code line by line. The interpreting component can be an interpreter, which can directly interpret and execute scripts or program source code.
本公开上述实施例中,解释组件包括:解释器,用于对指令描述信息进行处理,生成有向无环图,其中,有向无环图包含的多个节点与多个指令元素一一对应,有向无环图中连接在不同节点之间的边用于表征不同指令元素之间的关联关系;其中,执行组件用于执行有向无环图,得到处理结果。In the above embodiments of this disclosure, the interpretation component includes: an interpreter, used to process instruction description information and generate a directed acyclic graph, wherein the multiple nodes in the directed acyclic graph correspond one-to-one with multiple instruction elements, and the edges connecting different nodes in the directed acyclic graph are used to characterize the association relationship between different instruction elements; wherein the execution component is used to execute the directed acyclic graph to obtain the processing result.
上述的解释器可以为Python解释器,此处仅作示例,不做限定,具体可以根据实际使用场景进行调整。The interpreter mentioned above can be a Python interpreter. This is just an example and is not a limitation. The specific interpreter can be adjusted according to the actual use case.
本公开上述实施例中,执行组件包括如下之一:模拟器,用于执行多个指令元素的语义;汇编器,用于将多个指令元素与文本进行匹配;编译器,用于将多个指令元素与第一语言的中间指令进行匹配。In the embodiments disclosed above, the execution component includes one of the following: a simulator for executing the semantics of multiple instruction elements; an assembler for matching the multiple instruction elements with text; and a compiler for matching the multiple instruction elements with intermediate instructions of a first language.
需要说明的是,本公开上述实施例中涉及到的优选实施方案与实施例1提供的方案以及应用场景、实施过程相同,但不仅限于实施例1所提供的方案。It should be noted that the preferred implementation schemes involved in the above embodiments of this disclosure are the same as the schemes, application scenarios and implementation processes provided in Embodiment 1, but are not limited to the schemes provided in Embodiment 1.
实施例4Example 4
根据本公开实施例,还提供了一种片上系统,包括:上述实施例中任意一项的指令处理系统。According to embodiments of this disclosure, a system-on-a-chip is also provided, including: an instruction processing system according to any one of the above embodiments.
实施例5Example 5
本公开的实施例可以提供一种电子设备,该电子设备可以是电子设备群中的任意一个电子设备。可选地,在本实施例中,上述电子设备也可以替换为移动终端等终端设备。Embodiments of this disclosure can provide an electronic device, which can be any one of a group of electronic devices. Optionally, in this embodiment, the aforementioned electronic device can also be replaced with a terminal device such as a mobile terminal.
可选地,在本实施例中,上述电子设备可以位于计算机网络的多个网络设备中的至少一个网络设备。Optionally, in this embodiment, the aforementioned electronic device may be located in at least one of a plurality of network devices in a computer network.
在本实施例中,上述计算机终端可以执行方法中的程序代码。In this embodiment, the computer terminal described above can execute the program code in the method.
可选地,图9是根据本公开实施例的一种电子设备的结构框图。如图9所示,该电子设备A可以包括:一个或多个(图中仅示出一个)处理器102、存储器104、存储控制器、以及外设接口,其中,外设接口与射频模块、音频模块和显示器连接。Optionally, FIG9 is a structural block diagram of an electronic device according to an embodiment of the present disclosure. As shown in FIG9, the electronic device A may include: one or more (only one is shown in the figure) processors 102, memory 104, memory controller, and peripheral interface, wherein the peripheral interface is connected to a radio frequency module, an audio module, and a display.
其中,存储器可用于存储软件程序以及模块,如本公开实施例中的方法和装置对应的程序指令/模块,处理器通过运行存储在存储器内的软件程序以及模块,从而执行各种功能应用以及数据处理,即实现上述实施例中的方法。存储器可包括高速随机存储器,还可以包括非易失性存储器,如一个或者多个磁性存储装置、闪存、或者其他非易失性固态存储器。在一些实例中,存储器可进一步包括相对于处理器远程设置的存储器,这些远程存储器可以通过网络连接至终端A。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。The memory can be used to store software programs and modules, such as the program instructions/modules corresponding to the methods and apparatus in the embodiments of this disclosure. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby implementing the methods in the above embodiments. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to terminal A via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
处理器可以通过传输装置调用存储器存储的信息及应用程序,以执行下述步骤:监测通过工具链处理第一语言的源指令文件的处理流程,确定源指令文件中的待处理指令是否为预设指令;在待处理指令是预设指令的情况下,调用工具链中的解释组件对待处理指令的指令描述信息进行处理,得到第二语言的多个指令元素;通过工具链执行第二语言的多个指令元素,得到待处理指令的处理结果。The processor can access information and applications stored in memory via a transmission device to perform the following steps: monitor the processing flow of a source instruction file in the first language processed by a toolchain, and determine whether the instruction to be processed in the source instruction file is a preset instruction; if the instruction to be processed is a preset instruction, call the interpretation component in the toolchain to process the instruction description information of the instruction to be processed to obtain multiple instruction elements in the second language; execute the multiple instruction elements in the second language through the toolchain to obtain the processing result of the instruction to be processed.
可选的,上述处理器还可以执行如下步骤的程序代码:通过解释组件对指令描述信息进行处理,生成有向无环图,其中,有向无环图包含的多个节点与多个指令元素一一对应,有向无环图中连接在不同节点之间的边用于表征不同指令元素之间的关联关系。Optionally, the processor may also execute program code that performs the following steps: processes instruction description information through an interpretation component to generate a directed acyclic graph, wherein multiple nodes in the directed acyclic graph correspond one-to-one with multiple instruction elements, and the edges connecting different nodes in the directed acyclic graph are used to characterize the association between different instruction elements.
可选的,上述处理器还可以执行如下步骤的程序代码:载入配置文件至工具链,其中,配置文件包含至少一个预设指令的指令描述信息;将至少一个预设指令的字符表示与待处理指令的字符表示进行匹配,确定待处理指令的指令描述信息。Optionally, the processor may also execute program code that performs the following steps: loading a configuration file into the toolchain, wherein the configuration file contains instruction description information for at least one preset instruction; matching the character representation of at least one preset instruction with the character representation of the instruction to be processed to determine the instruction description information of the instruction to be processed.
可选的,上述处理器还可以执行如下步骤的程序代码:在任意一个预设指令的字符表示与待处理指令的字符表示相同的情况下,确定任意一个预设指令的指令描述信息为待处理指令的指令描述信息。Optionally, the processor may also execute program code that performs the following steps: if the character representation of any preset instruction is the same as the character representation of the instruction to be processed, determine the instruction description information of any preset instruction as the instruction description information of the instruction to be processed.
可选的,上述处理器还可以执行如下步骤的程序代码:确定工具链的目标类型,并确定目标类型对应的目标语义动作;通过工具链对多个指令元素进行目标语义动作,得到处理结果。Optionally, the processor may also execute program code that performs the following steps: determines the target type of the toolchain and the target semantic action corresponding to the target type; performs target semantic actions on multiple instruction elements through the toolchain to obtain the processing result.
可选的,上述处理器还可以执行如下步骤的程序代码:在目标类型为模拟器的情况下,确定目标语义动作为在模拟器中执行多个指令元素的语义;在目标类型为汇编器的情况下,确定目标语义动作为将多个指令元素与文本进行匹配;在目标类型为编译器的情况下,确定目标语义动作为将多个指令元素与第一语言的中间指令进行匹配。Optionally, the processor may also execute program code that performs the following steps: when the target type is a simulator, determines the target semantic action as executing multiple instruction elements in the simulator; when the target type is an assembler, determines the target semantic action as matching multiple instruction elements with text; when the target type is a compiler, determines the target semantic action as matching multiple instruction elements with intermediate instructions of the first language.
可选的,上述处理器还可以执行如下步骤的程序代码:预设指令用于表征未包含在精简指令集中的指令,或者由目标对象设定的指令。Optionally, the processor may also execute program code that includes the following steps: preset instructions used to characterize instructions not included in the reduced instruction set, or instructions set by the target object.
采用本公开实施例,监测通过工具链处理第一语言的源指令文件的处理流程,确定源指令文件中的待处理指令是否为预设指令;在待处理指令是预设指令的情况下,调用工具链中的解释组件对待处理指令的指令描述信息进行处理,得到第二语言的多个指令元素;通过工具链执行第二语言的多个指令元素,得到待处理指令的处理结果,实现了提高对指令进行处理的准确度;容易注意到的是,在通过工具链处理第一语言的源指令文件时,若存在待处理指令为预设指令,可以调用工具链中的解释组件对待处理指令的指令描述信息进行解释,以便得到工具链可以执行的第二语言的多个指令元素,可以在不引入额外的语言学习成本的基础上,使得工具链可以顺利的对源指令文件进行高效准确的处理并执行,从而提高了对指令进行处理的准确度,进而解决了相关技术中对指令进行处理的准确度较低的技术问题。By employing the embodiments of this disclosure, the processing flow of a source instruction file in a first language processed by a toolchain is monitored to determine whether the instruction to be processed in the source instruction file is a preset instruction. If the instruction to be processed is a preset instruction, the interpretation component in the toolchain is invoked to process the instruction description information of the instruction to be processed, thereby obtaining multiple instruction elements in a second language. The multiple instruction elements in the second language are executed by the toolchain to obtain the processing result of the instruction to be processed, thus improving the accuracy of instruction processing. It is noteworthy that when processing a source instruction file in a first language through a toolchain, if there is an instruction to be processed that is a preset instruction, the interpretation component in the toolchain can be invoked to interpret the instruction description information of the instruction to be processed, so as to obtain multiple instruction elements in the second language that the toolchain can execute. This allows the toolchain to efficiently and accurately process and execute the source instruction file without introducing additional language learning costs, thereby improving the accuracy of instruction processing and solving the technical problem of low accuracy in instruction processing in related technologies.
本领域普通技术人员可以理解,如图9所示的结构仅为示意,电子设备也可以是智能手机(如Android手机、iOS手机等)、平板电脑、掌上电脑以及移动互联网设备(Mobile Internet Devices,MID)、PAD等终端设备。该图9其并不对上述电子装置的结构造成限定。例如,电子设备A还可包括比该图中所示更多或者更少的组件(如网络接口、显示装置等),或者具有与该图9所示不同的配置。It will be understood by those skilled in the art that the structure shown in Figure 9 is merely illustrative, and the electronic device may also be a smartphone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile internet device (MID), a PAD, or other terminal device. Figure 9 does not limit the structure of the aforementioned electronic device. For example, electronic device A may include more or fewer components (such as a network interface, a display device, etc.) than shown in the figure, or may have a different configuration than that shown in Figure 9.
本领域普通技术人员可以理解上述实施例的各种方法中的全部或部分步骤是可以通过程序来指令终端设备相关的硬件来完成,该程序可以存储于一计算机可读存储介质中,存储介质可以包括:闪存盘、只读存储器(Read-Only Memory,ROM)、随机存取器(Random Access Memory,RAM)、磁盘或光盘等。Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
实施例6Example 6
本公开的实施例还提供了一种计算机可读存储介质。可选地,在本实施例中,上述计算机可读存储介质可以用于保存上述实施例所提供的方法所执行的程序代码。Embodiments of this disclosure also provide a computer-readable storage medium. Optionally, in this embodiment, the computer-readable storage medium can be used to store program code executed by the method provided in the above embodiments.
可选地,在本实施例中,上述存储介质可以位于计算机网络中电子设备群中的任意一个电子设备中,或者位于移动终端群中的任意一个移动终端中。Optionally, in this embodiment, the storage medium may be located in any one of the electronic devices in the group of electronic devices in the computer network, or in any one of the mobile terminals in the group of mobile terminals.
可选地,在本实施例中,计算机可读存储介质被设置为存储用于执行以下步骤的程序代码:监测通过工具链处理第一语言的源指令文件的处理流程,确定源指令文件中的待处理指令是否为预设指令;在待处理指令是预设指令的情况下,调用工具链中的解释组件对待处理指令的指令描述信息进行处理,得到第二语言的多个指令元素;通过工具链执行第二语言的多个指令元素,得到待处理指令的处理结果。Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: monitoring the processing flow of a source instruction file of the first language processed by a toolchain, and determining whether the instruction to be processed in the source instruction file is a preset instruction; if the instruction to be processed is a preset instruction, calling the interpretation component in the toolchain to process the instruction description information of the instruction to be processed to obtain multiple instruction elements of the second language; executing the multiple instruction elements of the second language through the toolchain to obtain the processing result of the instruction to be processed.
可选地,计算机可读存储介质还被设置为存储用于执行以下步骤的程序代码:通过解释组件对指令描述信息进行处理,生成有向无环图,其中,有向无环图包含的多个节点与多个指令元素一一对应,有向无环图中连接在不同节点之间的边用于表征不同指令元素之间的关联关系。Optionally, the computer-readable storage medium is further configured to store program code for performing the following steps: processing instruction description information through an interpretation component to generate a directed acyclic graph, wherein the directed acyclic graph contains multiple nodes that correspond one-to-one with multiple instruction elements, and the edges connecting different nodes in the directed acyclic graph are used to characterize the association relationships between different instruction elements.
可选地,计算机可读存储介质还被设置为存储用于执行以下步骤的程序代码:载入配置文件至工具链,其中,配置文件包含至少一个预设指令的指令描述信息;将至少一个预设指令的字符表示与待处理指令的字符表示进行匹配,确定待处理指令的指令描述信息。Optionally, the computer-readable storage medium is further configured to store program code for performing the following steps: loading a configuration file into a toolchain, wherein the configuration file contains instruction description information for at least one preset instruction; matching the character representation of at least one preset instruction with the character representation of an instruction to be processed to determine the instruction description information of the instruction to be processed.
可选地,计算机可读存储介质还被设置为存储用于执行以下步骤的程序代码:在任意一个预设指令的字符表示与待处理指令的字符表示相同的情况下,确定任意一个预设指令的指令描述信息为待处理指令的指令描述信息。Optionally, the computer-readable storage medium is further configured to store program code for performing the following steps: determining the instruction description information of any preset instruction as the instruction description information of the instruction to be processed, provided that the character representation of any preset instruction is the same as the character representation of the instruction to be processed.
可选地,计算机可读存储介质还被设置为存储用于执行以下步骤的程序代码:确定工具链的目标类型,并确定目标类型对应的目标语义动作;通过工具链对多个指令元素进行目标语义动作,得到处理结果。Optionally, the computer-readable storage medium is further configured to store program code for performing the following steps: determining the target type of the toolchain and determining the target semantic action corresponding to the target type; performing target semantic actions on multiple instruction elements through the toolchain to obtain the processing result.
可选地,计算机可读存储介质还被设置为存储用于执行以下步骤的程序代码:在目标类型为模拟器的情况下,确定目标语义动作为在模拟器中执行多个指令元素的语义;在目标类型为汇编器的情况下,确定目标语义动作为将多个指令元素与文本进行匹配;在目标类型为编译器的情况下,确定目标语义动作为将多个指令元素与第一语言的中间指令进行匹配。Optionally, the computer-readable storage medium is further configured to store program code for performing the following steps: if the target type is an emulator, determining the target semantic action as executing multiple instruction elements in the emulator; if the target type is an assembler, determining the target semantic action as matching multiple instruction elements with text; if the target type is a compiler, determining the target semantic action as matching multiple instruction elements with intermediate instructions of a first language.
可选地,计算机可读存储介质还被设置为存储用于执行以下步骤的程序代码:预设指令用于表征未包含在精简指令集中的指令,或者由目标对象设定的指令。Optionally, the computer-readable storage medium is also configured to store program code for performing the following steps: preset instructions for characterizing instructions not included in the reduced instruction set, or instructions set by the target object.
采用本公开实施例,监测通过工具链处理第一语言的源指令文件的处理流程,确定源指令文件中的待处理指令是否为预设指令;在待处理指令是预设指令的情况下,调用工具链中的解释组件对待处理指令的指令描述信息进行处理,得到第二语言的多个指令元素;通过工具链执行第二语言的多个指令元素,得到待处理指令的处理结果,实现了提高对指令进行处理的准确度;容易注意到的是,在通过工具链处理第一语言的源指令文件时,若存在待处理指令为预设指令,可以调用工具链中的解释组件对待处理指令的指令描述信息进行解释,以便得到工具链可以执行的第二语言的多个指令元素,可以在不引入额外的语言学习成本的基础上,使得工具链可以顺利的对源指令文件进行高效准确的处理并执行,从而提高了对指令进行处理的准确度,进而解决了相关技术中对指令进行处理的准确度较低的技术问题。By employing the embodiments of this disclosure, the processing flow of a source instruction file in a first language processed by a toolchain is monitored to determine whether the instruction to be processed in the source instruction file is a preset instruction. If the instruction to be processed is a preset instruction, the interpretation component in the toolchain is invoked to process the instruction description information of the instruction to be processed, thereby obtaining multiple instruction elements in a second language. The multiple instruction elements in the second language are executed by the toolchain to obtain the processing result of the instruction to be processed, thus improving the accuracy of instruction processing. It is noteworthy that when processing a source instruction file in a first language through a toolchain, if there is an instruction to be processed that is a preset instruction, the interpretation component in the toolchain can be invoked to interpret the instruction description information of the instruction to be processed, so as to obtain multiple instruction elements in the second language that the toolchain can execute. This allows the toolchain to efficiently and accurately process and execute the source instruction file without introducing additional language learning costs, thereby improving the accuracy of instruction processing and solving the technical problem of low accuracy in instruction processing in related technologies.
实施例7Example 7
本公开的实施例还提供了一种计算机程序产品。可选地,在本实施例中,上述计算机程序产品可以包括计算机程序,上述计算机程序在被处理器执行时实现上述实施例所提供的方法。Embodiments of this disclosure also provide a computer program product. Optionally, in this embodiment, the computer program product may include a computer program that, when executed by a processor, implements the methods provided in the embodiments described above.
实施例8Example 8
本公开的实施例还提供了一种计算机程序产品。可选地,上述计算机程序产品可以包括非易失性计算机可读存储介质,上述非易失性计算机可读存储介质可以用于存储计算机程序,上述计算机程序被处理器执行时实现上述实施例所提供的方法。Embodiments of this disclosure also provide a computer program product. Optionally, the computer program product may include a non-volatile computer-readable storage medium, which can be used to store a computer program that, when executed by a processor, implements the methods provided in the embodiments described above.
实施例9Example 9
本公开的实施例还提供了一种计算机程序。可选地,在本实施例中,上述计算机程序被处理器执行时实现上述实施例所提供的方法。Embodiments of this disclosure also provide a computer program. Optionally, in this embodiment, when the computer program is executed by a processor, it implements the method provided in the above embodiments.
上述本公开实施例序号仅仅为了描述,不代表实施例的优劣。The sequence numbers of the embodiments disclosed above are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
在本公开的上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。In the above embodiments of this disclosure, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
在本公开所提供的几个实施例中,应该理解到,所揭露的技术内容,可通过其它的方式实现。其中,以上所描述的装置实施例仅仅是示意性的,例如所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,单元或模块的间接耦合或通信连接,可以是电性或其它的形式。In the several embodiments provided in this disclosure, it should be understood that the disclosed technical content 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. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some interfaces; indirect couplings or communication connections between units or modules may be electrical or other forms.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
另外,在本公开各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。Furthermore, the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本公开的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可为个人计算机、服务器或者网络设备等)执行本公开各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, or all or part of the technical solution, 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 steps 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 a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
以上所述仅是本公开的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本公开原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本公开的保护范围。The above description is only a preferred embodiment of this disclosure. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principles of this disclosure, and these improvements and modifications should also be considered within the scope of protection of this disclosure.
Claims (15)
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410566940.0 | 2024-05-08 | ||
| CN202410566940.0A CN118394409A (en) | 2024-05-08 | 2024-05-08 | Instruction processing method, instruction processing system and system on chip |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2025232322A1 true WO2025232322A1 (en) | 2025-11-13 |
Family
ID=91993969
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2025/079089 Pending WO2025232322A1 (en) | 2024-05-08 | 2025-02-25 | Instruction processing method, instruction processing system and system-on-chip |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN118394409A (en) |
| WO (1) | WO2025232322A1 (en) |
Families Citing this family (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN118394409A (en) * | 2024-05-08 | 2024-07-26 | 达摩院(上海)科技有限公司 | Instruction processing method, instruction processing system and system on chip |
| CN120491976B (en) * | 2025-07-16 | 2025-12-05 | 中国科学院软件研究所 | Compilation methods, apparatus, electronic devices, storage media and products |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101916179A (en) * | 2010-07-12 | 2010-12-15 | 清华大学 | Access method of the flag bits in the control register |
| CN113238759A (en) * | 2021-04-14 | 2021-08-10 | 西安电子科技大学 | Interpretation system and method of Python-like programming language XD-M |
| CN114035805A (en) * | 2021-11-16 | 2022-02-11 | 北京字节跳动网络技术有限公司 | Code conversion method, apparatus, medium, and device for pre-compiler |
| US11513818B1 (en) * | 2020-09-30 | 2022-11-29 | Cadence Design Systems, Inc. | Method, product, and system for integrating a hardware accelerator with an extensible processor |
| CN118394409A (en) * | 2024-05-08 | 2024-07-26 | 达摩院(上海)科技有限公司 | Instruction processing method, instruction processing system and system on chip |
-
2024
- 2024-05-08 CN CN202410566940.0A patent/CN118394409A/en active Pending
-
2025
- 2025-02-25 WO PCT/CN2025/079089 patent/WO2025232322A1/en active Pending
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101916179A (en) * | 2010-07-12 | 2010-12-15 | 清华大学 | Access method of the flag bits in the control register |
| US11513818B1 (en) * | 2020-09-30 | 2022-11-29 | Cadence Design Systems, Inc. | Method, product, and system for integrating a hardware accelerator with an extensible processor |
| CN113238759A (en) * | 2021-04-14 | 2021-08-10 | 西安电子科技大学 | Interpretation system and method of Python-like programming language XD-M |
| CN114035805A (en) * | 2021-11-16 | 2022-02-11 | 北京字节跳动网络技术有限公司 | Code conversion method, apparatus, medium, and device for pre-compiler |
| CN118394409A (en) * | 2024-05-08 | 2024-07-26 | 达摩院(上海)科技有限公司 | Instruction processing method, instruction processing system and system on chip |
Also Published As
| Publication number | Publication date |
|---|---|
| CN118394409A (en) | 2024-07-26 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| WO2025232322A1 (en) | Instruction processing method, instruction processing system and system-on-chip | |
| US7996816B2 (en) | Method and apparatus for dynamically binding service component implementations for specific unit test cases | |
| CN106776343A (en) | A kind of web application automated test tool and method | |
| US20070011669A1 (en) | Software migration | |
| US9329985B1 (en) | Using emulation to disassociate verification from stimulus in functional test | |
| US10042658B1 (en) | Automatically adding bytecode to a software application to determine network communication information | |
| CN100492387C (en) | Method and system for software protection development based on Keil C51 | |
| WO2015130675A2 (en) | Apparatus and method for testing computer program implementation against a design model | |
| Bruce et al. | Enabling reproducible and agile full-system simulation | |
| GB2616340A (en) | Methods, systems, and computer readable media for customizing data plane pipeline processing using Berkeley packet filter (BPF) hook entry points | |
| CN118916886A (en) | RISC-V architecture-oriented binary program verification method and system | |
| US11379353B1 (en) | Platform for test environments | |
| CN119668576B (en) | Low-code software development system | |
| WO2024239815A1 (en) | Automated test architecture for instruction set and micro-architecture of processor | |
| CN114168150B (en) | Application compilation method, device, electronic device and storage medium | |
| CN114174983B (en) | Method and system for optimized automatic verification of advanced constructs | |
| CN113986744A (en) | Method and device for testing warehouse and table components and storage medium | |
| US20240362154A1 (en) | Smart test code generation | |
| Tinnerholm | An LLVM backend for the Open Modelica Compiler | |
| CN119494299B (en) | A verification method, device, electronic device and readable storage medium | |
| CN118672918B (en) | A method and device for obtaining observability data of Go source code | |
| CN113467861B (en) | File calling method and device, storage medium and electronic equipment | |
| Weidinger | Software testing reconsidered: Evaluation and comparison of symbolic execution tools in the context of aviation | |
| US8135943B1 (en) | Method, apparatus, and computer-readable medium for generating a dispatching function | |
| Yasin | Graphical User Interface Test Case Generation for Android Apps Using Q-Learning |