A software code compiling method and instruction software implementation method, device, electronic equipment and storage medium

CN118069110BActive Publication Date: 2026-10-23MOORE THREADS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410346104.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-25
Publication Date
2026-10-23
Estimated Expiration
2044-03-25

AI Technical Summary

Technical Problem

而生成一条指令往往需要数十行代码,一条复杂指令的替换可能需要数百行的代码,一个编译器有时需要软实现数十条复杂指令,因此编译器的开发工作量巨大,导致编译器的开发效率较低

Benefits of technology

[0041]在本公开实施例中,响应于编译器执行到复杂指令,通过检测所述复杂指令对应的功能函数的标识;基于所述功能函数的标识,调用预先对所述功能函数进行编译得到的中间指令;对所述中间指令进行编译,得到所述复杂指令的编译结果。由于功能函数基于高级语言编写,且中间指令是预先对所述功能函数进行编译得到的,因此,使用高级语言软实现中间指令,开发人员只需要输入高级语言的函数即可,由于高级语言是对低级语言(中间指令的语言)的抽象概况,因此可以用更简洁的方式表达复杂的逻辑和算法,可以用较少的代码实现低级语言需要更多代码才能完成的功能,高级语言在实现一个中间指令时往往只需要几行代码,大大简化了指令软实现的开发工作,提升了编译器的开发效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118069110B_ABST
    Figure CN118069110B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a software code compiling method and instruction software implementation method, device, electronic equipment and storage medium. The method comprises: in response to a complex instruction executed by a compiler, detecting an identifier of a function function corresponding to the complex instruction, the function function being written based on a high-level language; based on the identifier of the function function, calling an intermediate instruction obtained by previously compiling the function function; and compiling the intermediate instruction to obtain a compiling result of the complex instruction. The present disclosure can improve the development efficiency of the compiler.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to a software code compilation method, instruction software implementation method, apparatus, electronic device, and storage medium. Background Technology

[0002] Intermediate Representation (IR) is intermediate code generated by the compiler during the process of converting code to be compiled into machine code. The compiler typically translates the code to be compiled into intermediate code, and then translates the intermediate code into machine code. Intermediate code is an intermediate representation of the code to be compiled.

[0003] As compiler intermediate instructions and high-level languages ​​become increasingly complex and diverse, while actual hardware functionality may be quite limited and unable to provide corresponding hardware instructions, compilers need to implement the compilation of these intermediate instructions or high-level languages ​​through software implementation, that is, replacing a complex instruction with a set of equivalent simple instructions.

[0004] In related technologies, when implementing intermediate instructions in software, the instructions are replaced in the compiler's source code. This means that when developing the compiler code, the instruction type, source register, destination register, and other instruction parameters are specified in the code. Generating a single instruction often requires dozens of lines of code, and replacing a complex instruction may require hundreds of lines. A compiler sometimes needs to software implement dozens of complex instructions, resulting in a huge workload and low development efficiency. Summary of the Invention

[0005] This disclosure proposes a technical solution for software code compilation and instruction software implementation.

[0006] According to one aspect of this disclosure, a software code compilation method is provided, comprising:

[0007] In response to the compiler executing a complex instruction, the identifier of the function corresponding to the complex instruction is detected, and the function is written in a high-level language;

[0008] Based on the identifier of the function, the intermediate instructions obtained by pre-compiling the function are invoked;

[0009] The intermediate instructions are compiled to obtain the compilation result of the complex instructions.

[0010] In one possible implementation, the invocation of intermediate instructions obtained by pre-compiling the function includes:

[0011] The procedure call instruction invokes intermediate instructions that have been pre-compiled from the function.

[0012] In one possible implementation, the input of the function corresponds to the source register of the complex instruction, the output of the function corresponds to the target register of the complex instruction, and the function performs the same function as the complex instruction.

[0013] In one possible implementation, the intermediate instructions are obtained by compiling the function using an offline compiler, which is used to compile a high-level language into the language of the intermediate instructions.

[0014] In one possible implementation, the offline compiler generation steps include:

[0015] Based on the first language type of the function, a parsing module is determined for parsing the function, the parsing including: syntax parsing and semantic parsing;

[0016] Based on the second language type of the intermediate instructions, a generation module for generating intermediate instructions of the second language type based on the parsing result of the parsing module is determined;

[0017] An offline compiler is built based on the parsing module and the generation module.

[0018] In one possible implementation, the procedure call instruction is generated based on the identifier of the function, and the procedure call instruction is used to call intermediate instructions obtained by compiling the function.

[0019] According to one aspect of this disclosure, a method for soft implementation of instructions is provided, comprising:

[0020] Receive complex instructions from the user that require software implementation;

[0021] A function that receives user input to implement the complex instructions, the function being written in a high-level language;

[0022] The function is compiled from a high-level language into an intermediate instruction language, and the compilation result is used as the soft implementation result of the complex instruction.

[0023] According to one aspect of this disclosure, a software code compilation apparatus is provided, comprising:

[0024] A detection unit is used to detect the identifier of a function corresponding to a complex instruction when the compiler executes a complex instruction. The function is written in a high-level language.

[0025] The calling unit is used to call intermediate instructions that have been pre-compiled from the function based on the identifier of the function.

[0026] The compilation unit is used to compile the intermediate instructions to obtain the compilation result of the complex instructions.

[0027] In one possible implementation, the calling unit is used to invoke intermediate instructions obtained by pre-compiling the function through a procedure call instruction.

[0028] In one possible implementation, the input of the function corresponds to the source register of the complex instruction, the output of the function corresponds to the target register of the complex instruction, and the function performs the same function as the complex instruction.

[0029] In one possible implementation, the intermediate instructions are obtained by compiling the function using an offline compiler, which is used to compile a high-level language into the language of the intermediate instructions.

[0030] In one possible implementation, the offline compiler's generation apparatus includes:

[0031] A parsing module determining unit is configured to determine a parsing module for parsing the function based on the first language type of the function, wherein the parsing includes: syntax parsing and semantic parsing;

[0032] The generation module determining unit is used to determine, based on the second language type of the intermediate instructions, a generation module for generating intermediate instructions of the second language type according to the parsing result of the parsing module;

[0033] The building unit is used to build an offline compiler based on the parsing module and the generation module.

[0034] In one possible implementation, the procedure call instruction is generated based on the identifier of the function, and the procedure call instruction is used to call intermediate instructions obtained by compiling the function.

[0035] According to one aspect of this disclosure, an instruction soft implementation apparatus is provided, comprising:

[0036] The instruction receiving unit is used to receive complex instructions that require software implementation from user input;

[0037] A function receiving unit is used to receive user input of a function to implement the complex instruction, the function being written in a high-level language;

[0038] A soft implementation unit is used to compile the function from a high-level language into an intermediate instruction language, and use the compilation result as the soft implementation result of the complex instruction.

[0039] According to one aspect of this disclosure, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to invoke the instructions stored in the memory to perform the method described above.

[0040] According to one aspect of this disclosure, a computer-readable storage medium is provided that stores computer program instructions thereon, which, when executed by a processor, implement the above-described method.

[0041] In this embodiment of the disclosure, in response to the compiler executing a complex instruction, the identifier of the function corresponding to the complex instruction is detected; based on the identifier of the function, intermediate instructions obtained by pre-compiling the function are called; the intermediate instructions are compiled to obtain the compilation result of the complex instruction. Since the function is written in a high-level language and the intermediate instructions are pre-compiled from the function, using a high-level language to implement intermediate instructions only requires developers to input the high-level language function. Because a high-level language is an abstract generalization of a low-level language (the language of intermediate instructions), it can express complex logic and algorithms in a more concise way, and can achieve with less code the functionality that would require more code in a low-level language. Implementing an intermediate instruction in a high-level language often only requires a few lines of code, greatly simplifying the development work of instruction software implementation and improving the development efficiency of the compiler.

[0042] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Other features and aspects of this disclosure will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. Attached Figure Description

[0043] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the specification, serve to illustrate the technical solutions of this disclosure.

[0044] Figure 1 A flowchart illustrating a software code compilation method according to an embodiment of the present disclosure is shown.

[0045] Figure 2 A flowchart illustrating a method for soft implementation of instructions according to an embodiment of this disclosure is shown.

[0046] Figure 3 A schematic diagram illustrating a specific application scenario of the compiler instruction soft implementation method according to an embodiment of the present disclosure is shown.

[0047] Figure 4 A block diagram of a software code compilation apparatus according to an embodiment of the present disclosure is shown.

[0048] Figure 5 A block diagram illustrating a software implementation of instructions according to an embodiment of this disclosure is shown.

[0049] Figure 6 A block diagram of an electronic device according to an embodiment of the present disclosure is shown. Detailed Implementation

[0050] Various exemplary embodiments, features, and aspects of this disclosure will now be described in detail with reference to the accompanying drawings. The same reference numerals in the drawings denote elements that have the same or similar functions. Although various aspects of the embodiments are shown in the drawings, they are not necessarily drawn to scale unless specifically indicated otherwise.

[0051] The term “exemplary” as used herein means “serving as an example, embodiment, or illustration.” Any embodiment illustrated herein as “exemplary” is not necessarily to be construed as superior to or better than other embodiments.

[0052] In this document, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent three cases: A alone, A and B simultaneously, and B alone. Furthermore, the term "at least one" in this document means any combination of at least two of any one or more elements. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.

[0053] Furthermore, to better illustrate this disclosure, numerous specific details are set forth in the following detailed description. Those skilled in the art will understand that this disclosure can be practiced without certain specific details. In some instances, methods, means, components, and circuits well known to those skilled in the art have not been described in detail in order to highlight the main points of this disclosure.

[0054] Intermediate instructions are a special representation used within the compiler to represent its internal data structures and algorithms. The compiler typically converts source code into intermediate instructions, and then converts these intermediate instructions into object code. During this process, intermediate instructions can represent various information about the program, such as the syntax tree, control flow, and data flow.

[0055] The software implementation replaces a complex instruction with a set of equivalent simple instructions. These simple instructions can be directly compiled into a hardware-supported language and thus executed on actual hardware. When the compiler encounters a "complex instruction" during compilation, it retrieves the intermediate instructions (simple instruction sequences) that have been pre-implemented in software for that complex instruction. It then uses these intermediate instructions directly as the compilation result, or further compiles the intermediate instructions to obtain the final compilation result.

[0056] In related technologies, compiler development involves directly writing compiler code to implement intermediate instructions. This process requires consideration of factors such as instruction set architecture, hardware platform, and optimization needs, demanding significant work and coding from developers. For example, since not all hardware supports the complex instruction set for double-precision floating-point numbers, simpler instructions like integer and bitwise operations are typically used to simulate addition, subtraction, multiplication, and division. Replacing intermediate instructions for double-precision floating-point numbers often requires hundreds of lines of code, resulting in low compiler development efficiency. Furthermore, manually writing hundreds of lines of code is prone to errors, leading to lower compiler reliability.

[0057] In this embodiment of the disclosure, in response to the compiler executing a complex instruction, the identifier of the function corresponding to the complex instruction is detected; based on the identifier of the function, intermediate instructions obtained by pre-compiling the function are called; the intermediate instructions are compiled to obtain the compilation result of the complex instruction. Since the function is written in a high-level language and the intermediate instructions are pre-compiled from the function, using a high-level language to implement intermediate instructions only requires developers to input the high-level language function. Because a high-level language is an abstract generalization of a low-level language (the language of intermediate instructions), it can express complex logic and algorithms in a more concise way, and can achieve with less code the functionality that would require more code in a low-level language. Implementing an intermediate instruction in a high-level language often only requires a few lines of code, greatly simplifying the development work of instruction software implementation and improving the development efficiency of the compiler.

[0058] Figure 1 A flowchart illustrating a software code compilation method according to an embodiment of the present disclosure is shown, such as... Figure 1 As shown, the method includes:

[0059] In step S11, in response to the compiler executing a complex instruction, the identifier of the function corresponding to the complex instruction is detected, and the function is written in a high-level language;

[0060] Complex instructions are instructions written based on source code to be compiled. This source code can be a program written in a programming language (such as C, C++, Java, Python, etc.).

[0061] A mapping between complex instructions and function identifiers can be pre-established. When a complex instruction is executed, the corresponding function identifier can be detected based on this mapping.

[0062] The complex instructions here can be instructions that are pre-implemented as intermediate instructions in software. Software-implemented complex instructions typically include the following types:

[0063] Hardware-unsupported instructions: When the target hardware platform does not support certain instructions or operations, the compiler may need to implement these instructions through software simulation. For example, some older or special hardware platforms may not support floating-point arithmetic, in which case the compiler needs to implement the intermediate instructions for floating-point arithmetic in software.

[0064] Instructions requiring performance optimization: Due to performance optimization needs, even if the hardware supports certain instructions or operations, the compiler may choose to implement these instructions in software for performance reasons. For example, some complex mathematical operations or special functions (such as trigonometric functions, logarithmic functions, etc.) may be implemented faster using lookup tables or approximation algorithms.

[0065] Poorly portable instructions: To improve compiler portability and enable it to run on different hardware platforms, the compiler may choose to use a general-purpose intermediate instruction set that is independent of specific hardware. This allows the compiler to generate appropriate target code for different hardware platforms without modifying the intermediate instruction set itself.

[0066] Poorly compatible instructions: When developing new hardware platforms or processors, to ensure compatibility with existing software, it may be necessary to provide a way to emulate older or standard instruction sets. In this case, the behavior of these instructions can be simulated through software implementation.

[0067] Instructions with lower security: In some security-sensitive applications, in order to prevent certain hardware instructions from being maliciously exploited (such as for executing malicious code or conducting side-channel attacks), it may be necessary to implement these instructions securely in software.

[0068] In summary, complex instructions implemented in software can also include other types of instructions, depending on specific project requirements, hardware platform characteristics, and compiler design goals, and this disclosure does not limit them.

[0069] In step S12, based on the identifier of the function, intermediate instructions obtained by pre-compiling the function are invoked;

[0070] The compiler transforms the source code into an intermediate representation, which, for ease of description, will be referred to here as the intermediate compilation result. This intermediate compilation result typically consists of a set of intermediate instructions, implemented using the software implementation methods provided in this disclosure. Software implementation means that these instructions are not executed directly on the hardware, but rather through software simulation or interpretation.

[0071] Intermediate instructions are obtained by compiling function tags. A pre-established correspondence can be made between intermediate instructions and function tags. Based on this correspondence, the corresponding intermediate instructions can be called based on the function tag. Function tags are written in high-level languages. During the compiler development phase, developers input function tags written in high-level languages, and then the offline compiler compiles these function tags into intermediate instructions.

[0072] In step S13, the intermediate instructions are compiled to obtain the first intermediate instruction set as the compilation result of the complex instructions.

[0073] Since intermediate instructions are not machine-executable instructions, the compilation result of complex instructions can be obtained by further compiling and transcoding the intermediate instructions. In this process, the intermediate instructions are transcoded into target code, which can be machine code that the machine can execute. The intermediate instructions are code that lies between high-level language and machine language.

[0074] In this embodiment of the disclosure, in response to the compiler executing a complex instruction, the identifier of the function corresponding to the complex instruction is detected; based on the identifier of the function, intermediate instructions obtained by pre-compiling the function are called; the intermediate instructions are compiled to obtain the compilation result of the complex instruction. Since the function is written in a high-level language and the intermediate instructions are pre-compiled from the function, using a high-level language to implement intermediate instructions only requires developers to input the high-level language function. Because a high-level language is an abstract generalization of a low-level language (the language of intermediate instructions), it can express complex logic and algorithms in a more concise way, and can achieve with less code the functionality that would require more code in a low-level language. Implementing an intermediate instruction in a high-level language often only requires a few lines of code, greatly simplifying the development work of instruction software implementation and improving the development efficiency of the compiler.

[0075] In one possible implementation, the invocation of intermediate instructions pre-compiled from the functional function includes: invoking the pre-compiled intermediate instructions from the functional function via a procedure call instruction. That is, the pre-compiled intermediate instructions from the functional function can also be invoked via a procedure call. The procedure call instruction contains a function identifier (e.g., function name) of the specific functional function to be called. During compilation, the procedure call instruction corresponding to the high-level function is determined through the intermediate instruction set. The procedure call instruction invokes the function using the function identifier, resulting in an intermediate compilation result composed of software-implemented intermediate instructions.

[0076] In one possible implementation, the input of the function corresponds to the source register of the complex instruction, the output of the function corresponds to the target register of the complex instruction, and the function performs the same function as the instruction.

[0077] Intermediate instructions typically include a source register and a destination register. The source register stores the data to be operated on, while the destination register stores the result of the operation. For example, in arithmetic operation instructions, the source register typically stores the operands, while the destination register stores the result. In data transfer instructions, the source register stores the data to be loaded, while the destination register stores the loaded data.

[0078] Therefore, when implementing a function through intermediate instructions, the input of the function can be mapped to the source register of the complex instruction requiring software implementation, and the output of the function can be mapped to the destination register of the complex instruction requiring software implementation. In other words, the input of the instruction is the input parameter of the function, and the output of the instruction is the output parameter of the function. The function's functionality is then implemented according to the instruction's function. For example, a 64-bit floating-point multiplication instruction can be implemented using a high-level language, such as C or Java. The specific implementation details of the function are not elaborated here.

[0079] In this embodiment, the input of the function corresponds to the source register of the complex instruction, and the output of the function corresponds to the target register of the complex instruction. The function implements the same function as the instruction. Therefore, the functionality of complex instructions can be implemented through function calls, thereby improving the efficiency of compiler development.

[0080] In one possible implementation, the intermediate instructions are obtained by compiling the function using an offline compiler, which is used to compile a high-level language into the language of the intermediate instructions.

[0081] In this embodiment of the disclosure, since the number of complex instructions requiring software implementation is often limited, a simple offline compiler can be used to compile the function from a high-level language into the intermediate instruction language, allowing developers to achieve better performance and faster compilation speed. Furthermore, since the offline compiler does not rely on an internet connection, the risk of data leakage and cyberattacks can be reduced.

[0082] In one possible implementation, the offline compiler generation step includes: determining a parsing module for parsing the function based on a first language type of the function, the parsing including syntax parsing and semantic parsing; determining a generation module for generating intermediate instructions of the second language type based on the parsing result of the parsing module based on a second language type of the intermediate instructions; and constructing an offline compiler based on the parsing module and the generation module.

[0083] When determining the parsing module, an appropriate module is selected or determined based on the primary language type of the function (e.g., Python, Java, C++, etc.). This parsing module performs both syntax and semantic analysis on the function. Syntax analysis checks the code's grammatical correctness, such as matching brackets and complete statements; while semantic analysis delves deeper into the code's meaning, such as whether variables and functions are defined and whether their types match.

[0084] When determining the generation module, a generation module is selected based on the second language type of the intermediate instructions (e.g., it could be an intermediate notation language or another low-level language). This generation module is able to generate intermediate instructions of the corresponding second language type based on the parsing results from the parsing module.

[0085] After the parsing and generation modules are determined, they are combined to build a complete offline compiler. This compiler can accept function names of the first language type as input, parse and convert them, and finally output intermediate instructions of the second language type.

[0086] In this embodiment, the parsing module and the generation module are determined based on a first language type and a second language type, respectively. Since the parsing and generation modules are independent, this solution has high reusability; the parsing and generation modules can be reused in different compiler projects, thus saving development time and resources. This facilitates the construction of a series of related compiler toolchains, improving development efficiency. Furthermore, the constructed offline compiler has good cross-platform compatibility. By selecting an appropriate generation module, cross-platform compatibility of the compiler can be easily achieved, enabling the use of the same compiler to generate intermediate instructions for different language types for the target platform, thereby simplifying the complexity of cross-platform development.

[0087] In one possible implementation, the procedure call instruction is generated based on the identifier of the function, and the procedure call instruction is used to call intermediate instructions obtained by compiling the function.

[0088] Procedure call instructions are used to call and return subroutines or functions. In this embodiment of the disclosure, intermediate instructions are implemented in the form of procedure call instructions, which can enable the reuse of function code by intermediate instructions, thereby avoiding code redundancy and improving the efficiency of compiler development.

[0089] According to another aspect of this disclosure, a method for compiling software code is provided. Figure 2 A flowchart illustrating an instruction soft implementation method according to an embodiment of the present disclosure is shown, such as... Figure 2 As shown, the method includes:

[0090] In step S21, complex instructions requiring software implementation are received from user input;

[0091] Complex instructions requiring software implementation can be user-inputted. Users can select the complex instructions requiring software implementation through a graphical user interface, or they can manually input the complex instructions requiring software implementation. Complex instructions requiring software implementation typically include the following types:

[0092] Hardware-unsupported instructions: When the target hardware platform does not support certain instructions or operations, the compiler may need to implement these instructions through software simulation. For example, some older or special hardware platforms may not support floating-point arithmetic, in which case the compiler needs to implement the intermediate instructions for floating-point arithmetic in software.

[0093] Instructions requiring performance optimization: Due to performance optimization needs, even if the hardware supports certain instructions or operations, the compiler may choose to implement these instructions in software for performance reasons. For example, some complex mathematical operations or special functions (such as trigonometric functions, logarithmic functions, etc.) may be implemented faster using lookup tables or approximation algorithms.

[0094] Poorly portable instructions: To improve compiler portability and enable it to run on different hardware platforms, the compiler may choose to use a general-purpose intermediate instruction set that is independent of specific hardware. This allows the compiler to generate appropriate target code for different hardware platforms without modifying the intermediate instruction set itself.

[0095] Poorly compatible instructions: When developing new hardware platforms or processors, to ensure compatibility with existing software, it may be necessary to provide a way to emulate older or standard instruction sets. In this case, the behavior of these instructions can be simulated through software implementation.

[0096] Instructions with lower security: In some security-sensitive applications, in order to prevent certain hardware instructions from being maliciously exploited (such as for executing malicious code or conducting side-channel attacks), it may be necessary to implement these instructions securely in software.

[0097] In summary, situations requiring software implementation of complex instructions may also include other cases, depending on specific project requirements, hardware platform characteristics, and compiler design goals, and this disclosure does not limit these situations.

[0098] In step S22, a function input by the user to implement the complex instruction is received, and the function is written in a high-level language;

[0099] Complex instructions can perform certain functions, such as double-precision floating-point arithmetic. In this case, the user can be prompted to write functions in a high-level language to implement the functionality of the complex instructions.

[0100] A high-level programming language is a machine-independent, procedural, or object-oriented language. High-level languages ​​are more abstract than intermediate instruction languages, therefore, intermediate instructions can be implemented with less code. Intermediate instructions are typically a more abstract representation similar to machine language, used to represent source code or object code. Intermediate instructions are generally closer to machine language (object code) than source code (high-level languages), but are easier to understand and modify than machine language.

[0101] It should be noted that, in the embodiments of this disclosure, the intermediate instructions may not be in a specific programming language. That is, this disclosure does not limit the language type of the intermediate instructions. On different compilers and / or different hardware platforms, the specific form and representation of the intermediate instructions may be different. Those skilled in the art can write them according to specific application scenarios.

[0102] Compared to high-level languages, intermediate instructions are closer to machine language, facilitating code translation and optimization by the compiler. Furthermore, intermediate instructions should be as easy to understand and modify as possible to aid compiler development and debugging.

[0103] In step S23, the function is compiled from a high-level language into an intermediate instruction language, and the compilation result is used as the soft implementation result of the complex instruction.

[0104] After receiving a function from the user to implement complex instructions, since the intermediate instruction language supported by the compiler is specific, the input function can be compiled from a high-level language into an intermediate instruction language, thus enabling the complex instructions to be soft-implemented as intermediate instructions.

[0105] Multiple intermediate instructions obtained from the software implementation can form an intermediate instruction set. After the compiler is developed, when the compiler is working, it will select intermediate instructions from the intermediate instruction set to combine and represent the source code to be compiled. Then, the intermediate code represented by the intermediate instructions will be further compiled and transcoded to obtain machine code.

[0106] In this embodiment of the disclosure, when developing the compiler, complex instructions requiring soft implementation are rewritten as functions in a high-level language, and then the functions written in the high-level language are compiled into the language of intermediate instructions, thus obtaining the soft-implemented intermediate instructions. This method uses a high-level language to soft-implement intermediate instructions, and developers only need to input the functions in the high-level language. Since a high-level language is an abstract generalization of a low-level language (the language of intermediate instructions), it can express complex logic and algorithms in a more concise way, and can achieve with less code the functionality that would require more code in a low-level language. A high-level language often only needs a few lines of code to implement an intermediate instruction, greatly simplifying the development of soft-implementation instructions and improving the development efficiency of the compiler.

[0107] Figure 3 A schematic diagram illustrating a specific application scenario of the compiler instruction soft implementation method according to an embodiment of the present disclosure is shown. Figure 3 A specific embodiment of the method is shown. For example... Figure 3 As shown in section a, the complex instruction requiring software implementation is the mul instruction (64-bit floating-point multiplication instruction), which has two source registers and one destination register. For example... Figure 3As shown in section b, this complex instruction is implemented in software using a high-level language function named `softfloat_fp64_mul`. The source register (src0, src1) corresponds to the input parameters (x, y) of the function, and the destination register (dst) corresponds to the return value of the function. `softfloat_fp64_mul` is compiled using an offline compiler to generate intermediate instructions, as follows... Figure 3 As shown in section c, these are the intermediate instructions for softfloat_fp64_mul. Figure 3 As shown in part d, the mul instruction is soft-implemented as a procedure call instruction for softfloat_fp64_mul, which is represented in code as: call softfloat_fp64_mul.

[0108] During compilation, when the compiler encounters a complex `mul` instruction, it checks the identifier of the corresponding function. Based on this identifier, it finds the procedure call instruction `call softfloat_fp64_mul`, executes it, and calls the `softfloat_fp64_mul` function to obtain... Figure 3 The intermediate instructions shown in section C are then further compiled into machine code that the machine can execute, which serves as the compilation result of the complex instructions.

[0109] In this application scenario, since not all hardware supports the mul instruction, a software implementation of the mul instruction is required. In related technologies, integer and bitwise operations are used to simulate addition, subtraction, multiplication, and division to implement intermediate instructions, resulting in hundreds of lines of code. However, in this embodiment, developers only need to write a few lines of high-level language code and then compile it with a compiler to obtain the software-implemented intermediate instructions, reducing the code size by several orders of magnitude.

[0110] In one possible implementation, the software code compilation method and instruction software implementation method can be executed by electronic devices such as terminal devices and servers. The terminal devices can be user equipment (UE), mobile devices, user terminals, terminals, cellular phones, cordless phones, personal digital assistants (PDAs), handheld devices, computing devices, in-vehicle devices, wearable devices, etc. The method can be executed by the processor calling computer-readable instructions stored in the memory.

[0111] This method is specifically technically related to the internal structure of computer systems and can solve technical problems of how to improve hardware computing efficiency or execution performance (including reducing data storage, reducing data transmission, and increasing hardware processing speed), thereby achieving technical effects that improve the internal performance of computer systems in accordance with natural laws.

[0112] In addition, this disclosure also provides a software code compilation apparatus, an electronic device, a computer-readable storage medium, and a program, all of which can be used to implement any of the software code compilation methods provided in this disclosure. The corresponding technical solutions and descriptions are described in the corresponding section of the method and will not be repeated here.

[0113] Figure 4 A block diagram of a software code compilation apparatus according to an embodiment of the present disclosure is shown, such as Figure 4 As shown, the device 40 includes:

[0114] The detection unit 41 is used to detect the identifier of the function corresponding to the complex instruction in response to the compiler executing the complex instruction. The function is written in a high-level language.

[0115] Calling unit 42 is used to call intermediate instructions that have been pre-compiled from the function based on the identifier of the function;

[0116] The compilation unit 43 is used to compile the intermediate instructions to obtain the compilation result of the complex instructions.

[0117] In one possible implementation, the calling unit is used to invoke intermediate instructions obtained by pre-compiling the function through a procedure call instruction.

[0118] In one possible implementation, the input of the function corresponds to the source register of the complex instruction, the output of the function corresponds to the target register of the complex instruction, and the function performs the same function as the complex instruction.

[0119] In one possible implementation, the intermediate instructions are obtained by compiling the function using an offline compiler, which is used to compile a high-level language into the language of the intermediate instructions.

[0120] In one possible implementation, the offline compiler's generation apparatus includes:

[0121] A parsing module determining unit is configured to determine a parsing module for parsing the function based on the first language type of the function, wherein the parsing includes: syntax parsing and semantic parsing;

[0122] The generation module determining unit is used to determine, based on the second language type of the intermediate instructions, a generation module for generating intermediate instructions of the second language type according to the parsing result of the parsing module;

[0123] The building unit is used to build an offline compiler based on the parsing module and the generation module.

[0124] In one possible implementation, the procedure call instruction is generated based on the identifier of the function, and the procedure call instruction is used to call intermediate instructions obtained by compiling the function.

[0125] In addition, this disclosure also provides instruction software implementation apparatus, electronic device, computer-readable storage medium, and program, all of which can be used to implement any instruction software implementation method provided in this disclosure. The corresponding technical solutions and descriptions are described in the corresponding records in the method section and will not be repeated here.

[0126] Figure 5 A block diagram illustrating a software implementation of instructions according to an embodiment of this disclosure is shown, such as... Figure 5 As shown, the device 50 includes:

[0127] The instruction receiving unit 51 is used to receive complex instructions that require software implementation from user input;

[0128] The function receiving unit 52 is used to receive a function input by the user to implement the function of the complex instruction, and the function is written in a high-level language;

[0129] The soft implementation unit 53 is used to compile the function from a high-level language into an intermediate instruction language, and use the compilation result as the soft implementation result of the complex instruction.

[0130] In some embodiments, the functions or modules of the apparatus provided in this disclosure can be used to perform the methods described in the above method embodiments. The specific implementation can be referred to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0131] This disclosure also proposes a computer-readable storage medium storing computer program instructions that, when executed by a processor, implement the above-described method. The computer-readable storage medium can be volatile or non-volatile.

[0132] This disclosure also proposes an electronic device, including: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to invoke the instructions stored in the memory to execute the above-described method.

[0133] This disclosure also provides a computer program product, including computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code, wherein when the computer-readable code is run in a processor of an electronic device, the processor in the electronic device performs the above-described method.

[0134] Electronic devices can be provided as terminals, servers, or other forms of devices.

[0135] Figure 6 A block diagram of an electronic device 1900 according to an embodiment of the present disclosure is shown. For example, the electronic device 1900 may be provided as a server or a terminal device. (Refer to...) Figure 6 The electronic device 1900 includes a processing component 1922, which further includes one or more processors, and memory resources represented by memory 1932 for storing instructions, such as application programs, that can be executed by the processing component 1922. The application programs stored in memory 1932 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 1922 is configured to execute instructions to perform the methods described above.

[0136] Electronic device 1900 may also include a power supply component 1926 configured to perform power management of electronic device 1900, a wired or wireless network interface 1950 configured to connect electronic device 1900 to a network, and an input / output (I / O) interface 1958. Electronic device 1900 can operate on an operating system stored in memory 1932, such as Microsoft Server operating system (Windows Server). TM Apple's graphical user interface-based operating system (Mac OSX) TM ), a multi-user, multi-process computer operating system (Unix) TM Linux is a free and open-source Unix-like operating system. TM ), the open-source Unix-like operating system (FreeBSD) TM (or similar.)

[0137] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions that can be executed by a processing component 1922 of an electronic device 1900 to perform the above-described method.

[0138] This disclosure can be a system, method, and / or computer program product. A computer program product may include a computer-readable storage medium having computer-readable program instructions loaded thereon for causing a processor to implement various aspects of this disclosure.

[0139] Computer-readable storage media can be tangible devices capable of holding and storing instructions for use by an instruction execution device. Computer-readable storage media can be, for example, (but not limited to) electrical storage devices, magnetic storage devices, optical storage devices, electromagnetic storage devices, semiconductor storage devices, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disc read-only memory (CD-ROM), digital multifunction disc (DVD), memory sticks, floppy disks, mechanical encoding devices, such as punch cards or recessed protrusions storing instructions thereon, and any suitable combination of the foregoing. The computer-readable storage media used herein are not to be construed as transient signals themselves, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., light pulses through fiber optic cables), or electrical signals transmitted through wires.

[0140] The computer-readable program instructions described herein can be downloaded from computer-readable storage media to various computing / processing devices, or downloaded via a network, such as the Internet, local area network, wide area network, and / or wireless network, to an external computer or external storage device. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to the computer-readable storage media in the respective computing / processing device.

[0141] Computer program instructions used to perform the operations of this disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, status setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Smalltalk, C++, etc., and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), is personalized by utilizing the status information of the computer-readable program instructions to implement various aspects of this disclosure.

[0142] Various aspects of this disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.

[0143] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that, when executed by the processor of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner; thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of the flowchart and / or block diagram.

[0144] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.

[0145] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than those shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0146] The computer program product can be implemented specifically through hardware, software, or a combination thereof. In one alternative embodiment, the computer program product is specifically embodied in a computer storage medium; in another alternative embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.

[0147] The description of the various embodiments above tends to emphasize the differences between the various embodiments. The similarities or similarities between them can be referred to, and for the sake of brevity, they will not be repeated here.

[0148] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.

[0149] If the technical solution of this application involves personal information, the product using this technical solution has clearly informed the user of the personal information processing rules and obtained the user's voluntary consent before processing the personal information. If the technical solution of this application involves sensitive personal information, the product using this technical solution has obtained the user's separate consent before processing the sensitive personal information, and also meets the requirement of "express consent". For example, at personal information collection devices such as cameras, clear and prominent signs are set up to inform users that they have entered the scope of personal information collection and that personal information will be collected. If an individual voluntarily enters the collection scope, it is deemed that they have agreed to the collection of their personal information; or on the personal information processing device, with clear signs / information informing users of the personal information processing rules, authorization is obtained from the individual through pop-up information or by asking the individual to upload their personal information; wherein, the personal information processing rules may include information such as the personal information processor, the purpose of personal information processing, the processing method, and the types of personal information processed.

[0150] The various embodiments of this disclosure have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical application, or improvement of the technology in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.

Claims

1. A software code compilation method, characterized in that, include: In response to the compiler executing a complex instruction, the identifier of the function corresponding to the complex instruction is detected. The function is written in a high-level language and performs the same function as the complex instruction. Based on the identifier of the function, intermediate instructions obtained by pre-compiling the function are invoked; the intermediate instructions are obtained by compiling the function using an offline compiler, which is used to compile a high-level language into the language of the intermediate instructions. The intermediate instructions are compiled to obtain the compilation result of the complex instructions; In this context, a pre-established correspondence exists between the intermediate instructions and the identifiers of the function. The intermediate instructions constitute an intermediate instruction set. When the compiler is working, it selects intermediate instructions from the intermediate instruction set and combines them to represent the source code to be compiled. The offline compiler generation steps include: determining a parsing module for parsing the function based on the first language type of the function, wherein the parsing includes: syntax parsing and semantic parsing; determining a generation module for generating intermediate instructions of the second language type based on the parsing result of the parsing module based on the second language type of the intermediate instructions; and constructing an offline compiler based on the parsing module and the generation module.

2. The method according to claim 1, characterized in that, The invocation of intermediate instructions obtained by pre-compiling the function includes: The procedure call instruction invokes intermediate instructions that have been pre-compiled from the function.

3. The method according to claim 1, characterized in that, The input of the function corresponds to the source register of the complex instruction, and the output of the function corresponds to the destination register of the complex instruction.

4. The method according to claim 2, characterized in that, The procedure call instruction is generated based on the identifier of the function, and the procedure call instruction is used to call the intermediate instructions obtained by compiling the function.

5. A method for soft implementation of instructions, characterized in that, include: Receive complex instructions from the user that require software implementation; A function that receives user input to implement the complex instructions, the function being written in a high-level language; Based on the software code compilation method according to any one of claims 1-4, the functional function is compiled from a high-level language into an intermediate instruction language, and the compilation result is used as the software implementation result of the complex instruction; The intermediate instructions constitute an intermediate instruction set, which the compiler selects and combines during operation to represent the source code to be compiled.

6. A software code compilation apparatus, characterized in that, include: The detection unit is used to detect the identifier of the function corresponding to the complex instruction in response to the compiler executing the complex instruction. The function is written in a high-level language and the function implemented by the function is the same as the function of the complex instruction. The calling unit is used to call intermediate instructions that have been pre-compiled from the function based on the identifier of the function; the intermediate instructions are obtained by an offline compiler that compiles the function into the language of the intermediate instructions. A compilation unit is used to compile the intermediate instructions to obtain the compilation result of the complex instructions; In this context, a pre-established correspondence exists between the intermediate instructions and the identifiers of the function. The intermediate instructions constitute an intermediate instruction set. When the compiler is working, it selects intermediate instructions from the intermediate instruction set and combines them to represent the source code to be compiled. The offline compiler generation steps include: determining a parsing module for parsing the function based on the first language type of the function, wherein the parsing includes: syntax parsing and semantic parsing; determining a generation module for generating intermediate instructions of the second language type based on the parsing result of the parsing module based on the second language type of the intermediate instructions; and constructing an offline compiler based on the parsing module and the generation module.

7. A software instruction implementation device, characterized in that, include: The instruction receiving unit is used to receive complex instructions that require software implementation from user input; A function receiving unit is used to receive user input of a function to implement the complex instruction, the function being written in a high-level language; A soft implementation unit is used to compile the function from a high-level language into an intermediate instruction language based on the software code compilation device of claim 6, and to use the compilation result as the soft implementation result of the complex instruction; The intermediate instructions constitute an intermediate instruction set, which is used by the compiler to select and combine intermediate instructions to represent the source code to be compiled.

8. An electronic device, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor is configured to invoke instructions stored in the memory to implement the method described in any one of claims 1 to 5.

9. A computer-readable storage medium having computer program instructions stored thereon, characterized in that, When the computer program instructions are executed by the processor, they implement the method described in any one of claims 1 to 5.