A method for compiling instructions and a method for processing instructions
By extracting and packaging streamlined instruction set instructions, combining mode switching instructions or identification information, the mixed use of super-long instruction words and streamlined instruction sets is achieved, solving the problems of out-of-order execution and instruction-level parallelism degradation in traditional technology, and improving the CPU performance and resource saving effects.
Patent Information
- Application Number
- CN202411020461.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-29
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2044-07-29
AI Technical Summary
The traditional streamlined instruction set is expected to work in sequence during design, which leads to the need to simulate the execution in order when applying optimization, resulting in the implementation of out-of-order execution technology that consumes a lot of Die area and power consumption, and if the ultra-long instruction word is not valid, Packaging will lead to degradation of instruction-level parallelism, and it is impossible to efficiently utilize multiple execution units and multiple transmitters.
Provide an instruction compilation method. By obtaining multiple streamlined instruction set instructions, extracting a non-dependency instruction group and determining whether it can be packaged as a super long instruction word. If possible, package it. Otherwise, each instruction will be executed separately, and using mode switching Instructions or identification information represent instruction types, make full use of multiple pipelines of the CPU and save resources.
Improve CPU performance and save resources, realize efficient instruction execution under different instructions parallelism, avoiding the additional overhead of out-of-order execution, and combining high performance and low power consumption.
Smart Images

Figure CN118550587B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of chips, and in particular to an instruction compilation method and an instruction processing method. Background Art
[0002] Most instructions in traditional reduced instruction set computers (RISC) are simple and independent. However, since traditional reduced instruction sets are designed to expect instructions to work in order (sequential execution or "seemingly" sequential execution), the central processing unit (CPU) has to simulate sequential execution when optimizing applications, which results in the use of instruction-level parallel technologies such as out-of-order execution to improve performance, which consumes a large amount of die (silicon chip) area and power consumption.
[0003] Very long instruction words (VLIW) combine multiple independent instructions into one instruction word, which can effectively utilize multiple execution units and multiple issues, and can achieve a fairly high level of instruction-level parallelism without the need for out-of-order execution and other technologies. However, if multiple independent instructions cannot be found and packaged into a very long instruction word, the compiler can only insert no-operation instructions into the instruction word, resulting in an empty instruction word, which in turn leads to the degradation of instruction-level parallelism to a certain extent, and the inability to efficiently utilize multiple execution units and multiple issues.
[0004] Therefore, there is an urgent need for a solution to achieve the mixed use of very long instruction words and reduced instruction set instructions to fully utilize the advantages of very long instruction words and reduced instruction set instructions. Summary of the invention
[0005] The present application provides an instruction compilation method and an instruction processing method, which are used to realize the mixed use of very long instruction words and reduced instruction set instructions.
[0006] In a first aspect, the present application provides an instruction compilation method, which is applied to a compiler, and the method includes: obtaining multiple reduced instruction set instructions; extracting reduced instruction set instructions that have no dependencies among the multiple reduced instruction set instructions as an instruction group; judging whether the vacancy level of the super-long instruction word can be made less than or equal to a set threshold if each reduced instruction set instruction in the instruction group is packaged into an extra-long instruction word; if so, treating the extra-long instruction word packaged into the instruction group as an instruction; otherwise, treating each reduced instruction set instruction in the instruction group as an instruction.
[0007] In the above technical scheme, when the instruction parallelism is high, the reduced instruction set instructions with no dependencies are packaged into an ultra-long instruction word, so that the multiple pipelines of the CPU can be fully utilized when the instructions are executed, thereby improving the CPU performance; when the instruction parallelism is insufficient, each reduced instruction set is executed as an instruction, which can save the storage space of the instructions and avoid waste of resources.
[0008] In a possible design, after treating the very long instruction word as an instruction and treating each reduced instruction set instruction in the instruction group as an instruction, it also includes: if the instruction and the previous instruction of the instruction are instructions of different types, inserting a mode switching instruction before the instruction; the mode switching instruction is used to instruct the central processing unit to decode and execute according to the corresponding instruction type; the instruction types include reduced instruction set instructions and very long instruction words.
[0009] In the above technical solution, a mode switching instruction is inserted between two different types of instructions to inform the CPU to switch the instruction mode, and then the instructions are decoded and executed according to the mode indicated by the mode switching instruction until the next mode switching instruction is decoded.
[0010] In one possible design, each reduced instruction set instruction in the instruction group is packaged into an extra-long instruction word, including: packaging each reduced instruction set instruction in the instruction group and adding identification information to form an extra-long instruction word; the identification information indicates that the instruction type is an extra-long instruction word.
[0011] In the above technical solution, the instruction is characterized as a very long instruction word by adding representation information, and then when the CPU executes the instruction, it can be decoded in the mode of a very long instruction word.
[0012] In one possible design, the identification information is a specific main operation code; the adding of the identification information includes: adding the specific main operation code before each instruction word; the specific main operation code is a main operation code pre-set to characterize the instruction type as an extra-long instruction word.
[0013] In the above technical solution, since the main opcode determines not only the function of the instruction but also the format of other areas of the instruction and how other areas should be interpreted, a certain main opcode can be specified to mark an instruction as an extra-long instruction word.
[0014] In one possible design, the identification information is a specific instruction; the adding of the identification information includes: using the specific instruction as the first instruction of the super-long instruction word; the specific instruction is an instruction pre-set to characterize the instruction type as a super-long instruction word; the specific instruction is an instruction pre-set to characterize the instruction type as a super-long instruction word; the specific instruction is not executed by the CPU after being parsed as an instruction characterizing the instruction type, or has no effect on the execution result of the program after being executed by the CPU.
[0015] In one possible design, the destination register address of the mode switching instruction or the specific instruction is the address of a hard-wired zero register; all written values of the hard-wired zero register are ignored, and the read value is zero.
[0016] In the above technical solution, the execution result of the instruction whose destination register address is the address of the hard-wired zero register is equivalent to a nop (no operation) instruction. When encountering such an instruction, a CPU that implements the technical solution can regard it as identification information that indicates that the instruction is an extra-long instruction word and ignore the execution of such an instruction, and continue to obtain the entire extra-long instruction word. An existing CPU that does not implement the technical solution may execute such an instruction, but due to its property of being equivalent to a nop instruction, even if it is executed, it will not produce any side effects or cause any damage; then, the constituent instructions of the extra-long instruction word can be safely executed as ordinary reduced instruction set instructions. In this way, backward compatibility can be achieved.
[0017] In one possible design, the destination register address of the mode switching instruction or the specific instruction is the same as at least one source register address and satisfies at least one of the following conditions: (a) if the instruction requires multiple source registers, the other source register addresses are the register addresses of the hard-wired zero register; (b) if the instruction requires multiple source registers, the other source register addresses are also equal to the destination register address; (c) the immediate value is zero.
[0018] In the above technical solution, the execution result of the instruction whose source register address and destination register address are the same and whose immediate value is zero is equivalent to a nop (no operation) instruction. When encountering such an instruction, a CPU that implements the technical solution can regard it as identification information that indicates that the instruction is an extra-long instruction word and ignore the execution of such an instruction, while continuing to obtain the entire extra-long instruction word. Existing CPUs that do not implement the technical solution may execute such instructions, but due to its property of being equivalent to a nop instruction, even if it is executed, it will not produce any side effects or cause any damage; then, the constituent instructions of the extra-long instruction word can be safely executed as ordinary reduced instruction set instructions. In this way, backward compatibility can be achieved.
[0019] In a second aspect, an embodiment of the present application provides another instruction processing method, which is applied to a central processing unit, wherein the central processing unit includes multiple pipelines, several of which are enabled pipelines, and the method includes: obtaining an instruction; the instruction includes a very long instruction word and a reduced instruction set instruction; if the instruction is an extremely long instruction word, each reduced instruction set instruction in the extremely long instruction word is sent to the enabled pipeline for parallel execution; the extremely long instruction word is composed of a plurality of independent reduced instruction set instructions, and the plurality of independent reduced instruction set instructions make the vacancy degree of the extremely long instruction word less than a set threshold; if the instruction is a reduced instruction set instruction, the reduced instruction set instruction is sent to one of the enabled pipelines for execution.
[0020] In the above technical solution, when the instruction parallelism is high, the reduced instruction set instructions without dependencies are packaged into an ultra-long instruction word, so that multiple CPU pipelines can be fully utilized when the instructions are executed, thereby improving CPU performance; when the instruction parallelism is insufficient, each reduced instruction set instruction is executed as an instruction (exemplarily, single-issue sequential execution), which can save instruction storage space and avoid waste of resources.
[0021] In one possible design, if the instruction is a reduced instruction set instruction, the reduced instruction set instruction is sent to a decoding unit on one of the enabled pipelines for decoding; the instruction scheduling unit reorders the decoded multiple reduced instruction set instructions; the reordered multiple reduced instruction set instructions are sent to the enabled multiple pipelines for execution; the executed multiple reduced instruction set instructions are reordered to restore the original order of the multiple reduced instruction set instructions.
[0022] The above technical solution is conducive to improving the performance of low-power CPUs in specific application scenarios while controlling power consumption and cost. In scenarios where the composition of very long instruction words has a high degree of parallelism, the pipeline can be filled and the extra overhead and burden of out-of-order execution can be avoided. Multi-issue out-of-order execution is used for reduced instruction set instructions, so that it can maintain compatibility with existing binaries and directly use reduced instruction set instructions in scenarios where very long instruction words are empty to avoid waste of resources. Compared with single-issue sequential execution, the performance when using reduced instruction set instructions can also be improved.
[0023] In one possible design, the instruction acquisition includes: if the current instruction mode is a very long instruction word mode, then acquiring data whose length is equal to the very long instruction word length; if the current instruction mode is a reduced instruction set instruction mode, then acquiring data whose length is equal to the reduced instruction set instruction length.
[0024] In the above technical solution, the complete retrieval of super-long instruction words can be achieved.
[0025] In one possible design, the instruction mode is determined in the following manner, including: identifying whether the current instruction is a mode switching instruction; if it is not a mode switching instruction, maintaining the current instruction mode; if it is a mode switching instruction, changing the current instruction mode to the mode indicated in the mode switching instruction.
[0026] In one possible design, the instruction acquisition includes: acquiring data of a preset length, wherein the data of the preset length is used to determine whether there is identification information representing an extra-long instruction word in the data; determining whether there is identification information representing an extra-long instruction word in the data; if so, then trimming the acquired data, or retaining the acquired data as it is, or continuing to acquire data, so that the total length of the acquired data is equal to the length of the extra-long instruction word, and treating the data as an extra-long instruction word; otherwise, trimming the acquired data, or retaining the acquired data as it is, or continuing to acquire data, so that the total length of the acquired data is equal to the length of a reduced instruction set instruction, and treating the data as a reduced instruction set instruction.
[0027] In the above technical solution, the complete retrieval of super-long instruction words can be achieved.
[0028] In one possible design, the identification information representing the extra-long instruction word includes a specific main operation code or a specific instruction; the specific main operation code is a main operation code pre-set to represent the instruction type as an extra-long instruction word; the specific instruction is an instruction pre-set to represent the instruction type as an extra-long instruction word; the specific instruction is not executed by the CPU after being parsed as an instruction representing the instruction type, or has no effect on the execution result of the program after being executed by the CPU.
[0029] In one possible design, the destination register address of the mode switching instruction or the specific instruction is the address of a hard-wired zero register; all written values of the hard-wired zero register are ignored, and the read value is zero.
[0030] In one possible design, the destination register address of the mode switching instruction or the specific instruction is the same as at least one source register address and satisfies at least one of the following conditions: (a) if the instruction requires multiple source registers, the other source register addresses are the register addresses of the hard-wired zero register; (b) if the instruction requires multiple source registers, the other source register addresses are also equal to the destination register address; (c) the immediate value is zero.
[0031] In one possible design, the method further includes: shutting down at least one of the multiple pipelines and retaining at least one enabled pipeline; if the instruction is a very long instruction word, and the number of enabled pipeline lines M is less than the number N of reduced instruction set instructions in the very long instruction word, then sending the N reduced instruction set instructions in batches to each enabled pipeline for parallel execution; wherein M is greater than or equal to 1; and the number of reduced instruction set instructions sent in each batch is less than or equal to M.
[0032] In the above technical solution, some devices do not require computing speed at ordinary times, but only need high performance when certain important tasks come. In this way, only some pipelines can be kept and other pipelines can be closed. In this way, the operation can be maintained with extremely low power consumption, achieving the effect of saving electricity. In addition, in order to save costs, when the number of pipelines implemented on the CPU is less than the maximum number of component instructions allowed by the very long instruction word, some pipelines can also be shut down, thereby achieving flexibility in hardware implementation.
[0033] In a third aspect, an embodiment of the present application further provides a computing device, including:
[0034] A memory for storing program instructions;
[0035] A processor is used to obtain stored program instructions from the memory, and execute the method described in any possible design of the first aspect or the second aspect according to the obtained program instructions. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0037] Figure 1 A flowchart diagram of a compiler applicable to an embodiment of the present application;
[0038] Figure 2 A flow chart of an instruction compilation method provided in an embodiment of the present application Figure 1 ;
[0039] Figure 3 Schematic diagram of the instruction format provided in the embodiment of the present application Figure 1 ;
[0040] Figure 4 A flow chart of an instruction compilation method provided in an embodiment of the present application Figure 2 ;
[0041] Figure 5Schematic diagram of the instruction format provided in the embodiment of the present application Figure 2 ;
[0042] Figure 6 A flowchart of an instruction processing method provided in an embodiment of the present application;
[0043] Figure 7 A specific example of the CPU execution method provided in the embodiment of the present application;
[0044] Figure 8 Another specific example of the CPU execution method provided in the embodiment of the present application;
[0045] Fig. 9 A schematic diagram of the structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0047] In the embodiments of the present application, a plurality refers to two or more than two. The words "first", "second" and the like are only used for the purpose of distinguishing descriptions and cannot be understood as indicating or implying relative importance or order.
[0048] In the embodiment of the present application, the reduced instruction set instructions (RISC instructions) and the very long instruction words (VLIW instruction words or VLIW) are instructions in the basic ISA (instruction set architecture) or the compressed instruction ASE (application-specific extensions, equivalent to the extension of the basic ISA; hereinafter also referred to as "compressed instruction set"), and the basic ISA expects the instructions to be executed sequentially to some extent. The instructions in the compressed instruction ASE are functionally a subset of the instructions in the basic ISA, and can provide the most common and basic functions in the basic ISA, and are widely used in various tasks. Generally speaking, instructions with relatively basic functions will have a weaker dependence on the order of instruction execution, and thus are more easily extracted as instruction groups. Therefore, most of the instructions in the compressed instruction set meet the above characteristics, which is very conducive to using the instructions of the compressed instruction set as the constituent instructions of the very long instruction word. Moreover, the length of the instructions in the compressed instruction ASE is generally shorter than that of the basic ISA, which is conducive to significantly reducing the total length of the very long instruction word and reducing the program volume.
[0049] like Figure 1 As shown, the compiler is generally divided into a front end and a back end. The front end compiles a specific programming language into an intermediate code, and the back end compiles the intermediate code into a specific target code, i.e., a machine code. The intermediate code bridges the gap between different programming languages for the back end, and also bridges the gap between different instruction sets for the front end. When writing a compiler, it is not necessary to repeat the same logic in large quantities for different programming languages or instruction set architectures, but only needs to apply this part of the common logic to the generation or processing of the intermediate code. The instruction compilation method provided in the embodiment of the present application can be performed in the step of target code optimization, or a part can be completed in advance in the step of intermediate code optimization, but the final high optimization still needs to be achieved in the step of target code optimization.
[0050] Figure 2 A flowchart of an instruction compilation method provided in an embodiment of the present application is shown as follows: Figure 2 As shown, the method is applied to a compiler, and the method comprises the following steps:
[0051] Step 201: Obtain a plurality of reduced instruction set instructions.
[0052] Step 202: extracting RISC instructions without dependency from a plurality of RISC instructions into an instruction group.
[0053] RISC instructions without dependencies can be executed in parallel, so RISC instructions without dependencies among multiple RISC instructions are first extracted into an instruction group.
[0054] Step 203 : determining whether the vacancy level of the very long instruction word can be made less than or equal to a set threshold value if the RISC instructions in the instruction group are packaged into a very long instruction word.
[0055] If yes, execute step 204; otherwise, execute step 205.
[0056] Specifically, the vacancy degree of the instruction word can be judged by the number of reduced instruction set instructions (i.e., constituent instructions) in the instruction group. For example, assuming that an instruction word can be composed of 8 reduced instruction set instructions, the threshold is set to 6, that is, when the number of reduced instruction set instructions in the instruction group is greater than or equal to 6, the vacancy degree of the instruction word is less than or equal to the set threshold. Alternatively, the vacancy degree of the instruction word can also be judged by the length of all reduced instruction set instructions in the instruction group. For example, assuming that the length of an instruction word is 32Bytes, the threshold is set to 24Bytes, that is, when the instruction length of all reduced instruction set instructions in the instruction group is greater than or equal to 24Bytes, the vacancy degree of the instruction word is less than or equal to the set threshold.
[0057] Step 204: Pack the instruction group into a very long instruction word as one instruction.
[0058] If the reduced instruction set instructions in the instruction group are packed into a very long instruction word, so that the vacancy level of the very long instruction word is less than or equal to the set threshold, the very long instruction word packed into the instruction group is used as an instruction. Among them, there are two types of very long instruction words: fixed-length very long instruction words and variable-length very long instruction words. The fixed-length very long instruction word has a fixed length, refer to Figure 3 The instruction format of a in the above example means that the number of component instructions that can be accommodated is fixed. Usually, the number of component instructions corresponds to the number of CPU pipeline lines. In addition, the fixed-length very long instruction word can also have "extra information" that records some relevant information about the instruction. The extra information can be located at the beginning, end or other position of the instruction word. Figure 3 There are two instruction formats: b and c. The advantage of fixed-length VLIs is that the hardware implementation is simple, but the disadvantage is that it is not conducive to the evolution of CPU microarchitecture (it is difficult to change the number of pipeline lines).
[0059] The variable length super long instruction word can contain a variable number of instructions. The variable length super long instruction word can use the terminator as the separator between instruction words, refer to Figure 3 The instruction format of d can also record the number of instructions that make up the instruction word in the additional information to achieve a variable-length instruction word, where the additional information can be located at the beginning, end or other position of the instruction word, refer to Figure 3 There are two instruction formats, e and f. The advantage of variable-length VLIs is that they are conducive to the evolution of CPU microarchitecture and have no limit on the number of pipeline lines in the CPU. The disadvantage is that the hardware implementation is complex and requires certain instruction reordering and repackaging capabilities.
[0060] For fixed-length extra-long instruction words, when the reduced instruction set instructions in the instruction group make the vacancy level of the instruction word less than or equal to the set threshold, but cannot fill an instruction word, it is necessary to insert nop instructions to fill the remaining part of the instruction word. For variable-length extra-long instruction words, when the reduced instruction set instructions in the instruction group make the vacancy level of the instruction word less than or equal to the set threshold, but cannot fill an instruction word, it is not necessary to insert nop instructions, only the terminator needs to be inserted.
[0061] Step 205: Treat each RISC instruction in the instruction group as an instruction.
[0062] In the above technical solution, the compiler generates an executable file in which an ultra-long instruction word and a reduced instruction set instruction coexist by analyzing and optimizing the original reduced instruction set instruction. When each reduced instruction set instruction in the instruction group can make the vacancy degree of the instruction word less than or equal to the set threshold, each reduced instruction set instruction in the instruction group is packaged into an ultra-long instruction word, and the ultra-long instruction word is used as an instruction. The reduced instruction set instructions in the instruction are independent of each other, and the parallel execution of these reduced instruction set instructions can improve the performance of the central processing unit without errors (in contrast, for instructions with dependencies, they usually cannot be directly executed in parallel, otherwise it is likely to produce erroneous results; modern processors use very complex technologies, such as out-of-order execution, etc., to indirectly execute them in parallel). When each reduced instruction set instruction in the instruction group can make the vacancy degree of the instruction word greater than the set threshold, each reduced instruction set instruction in the instruction group is used as an instruction. For the reduced instruction set with low instruction-level parallelism in the instruction group, it is possible to save the storage space of the instruction.
[0063] In the embodiment of the present application, since the instructions generated by the compiler include two instruction types: very long instruction words and reduced instruction set instructions, it is necessary to mark the instruction type of the instruction so that the central processing unit can decode and execute according to the corresponding instruction type. Specifically, the instruction type of the instruction can be marked in the following two ways:
[0064] Method 1: A mode switching instruction can be inserted between a very long instruction word and a reduced instruction set instruction to indicate that the type of instruction currently being processed has changed. Specifically, after the very long instruction word is treated as an instruction in step 204, and each reduced instruction set instruction in the instruction group is treated as an instruction in step 205, the following steps are also included: if the instruction is of a different type from the previous instruction, a mode switching instruction is inserted before the instruction.
[0065] The mode switching instruction is used to instruct the central processing unit to decode and execute the corresponding instruction type, and the instruction type includes a reduced instruction set instruction and a very long instruction word. The mode switching instruction can be one instruction or multiple instructions. The mode switching instruction can directly switch the instruction mode or switch the instruction mode by modifying the control register. This application does not make specific restrictions here.
[0066] Specifically, refer to Figure 4 After treating the VLI as an instruction in step 204, step 206 is executed to determine whether the previous instruction is a RISC instruction. If so, step 208 is executed to insert a mode switching instruction before the instruction; otherwise, step 209 is executed to determine whether there are any instructions that have not been scheduled.
[0067] After treating each RISC instruction in the instruction group as an instruction in step 205, step 207 is executed to determine whether the previous instruction is an overlong instruction word. If so, step 208 is executed to insert a mode switching instruction before the instruction; otherwise, step 209 is executed to determine whether there are any instructions that have not been scheduled.
[0068] If there are still instructions that have not been scheduled, continue to execute step 201; otherwise, end.
[0069] More specifically, the mode switching instruction includes a very long instruction word mode switching instruction and a reduced instruction set instruction mode switching instruction. When the central processing unit decodes the current instruction as a very long instruction word mode switching instruction, the central processing unit switches to the very long instruction word mode, and decodes and executes subsequent instructions according to the very long instruction word until the next mode switching instruction is decoded; when the central processing unit decodes the current instruction as a reduced instruction set instruction mode switching instruction, the central processing unit switches to the reduced instruction set instruction mode, and decodes and executes subsequent instructions according to the reduced instruction set instruction until the next mode switching instruction is decoded.
[0070] Method 2: When the RISC instructions in the instruction group are packaged into a very long instruction word in step 204, the RISC instructions in the instruction group may be packaged and identification information may be added to form a very long instruction word.
[0071] Among them, the identification information characterizes that the instruction type of the instruction is an extra-long instruction word. The identification information can be a specific main operation code or a specific instruction. Specifically, when the identification information is a specific main operation code, the identification information is added, including: adding a specific main operation code before each instruction word, and the specific main operation code is a main operation code pre-set to characterize the instruction type as an extra-long instruction word. The main operation code is generally located at the beginning of the instruction. Since the main operation code determines the function of the instruction, the format of other areas of the instruction and how other areas should be interpreted, therefore, a certain main operation code can be specified to mark an instruction as an extra-long instruction word. For reference, Figure 5 In the example, a is a fixed-length instruction format and b is a variable-length instruction format. Figure 5 For example only, the "extra information" is optional and can be placed anywhere else, not just after the main opcode.
[0072] When the identification information is a specific instruction, adding the identification information includes: using the specific instruction as the first instruction of the super-long instruction word. The specific instruction is a pre-set instruction used to indicate that the instruction type is a super-long instruction word. After being parsed as an instruction indicating the instruction type, the specific instruction is not executed by the CPU, or after being executed by the CPU, it has no effect on the execution result of the program. In addition, the specific instruction can embed additional information of the instruction word, refer to Figure 5The fixed-length instruction format of c and the variable-length instruction format of d. When encountering such an instruction, the CPU implementing the technical solution can regard it as identification information indicating that the instruction is an extra-long instruction word and ignore the execution of such an instruction, and continue to obtain the entire extra-long instruction word.
[0073] Based on the consideration of forward compatibility, we hope that the instructions added to characterize the instructions as very long word instructions will not produce any side effects or damage on the existing CPU that does not implement the technical solution, and can make the instructions of the very long instruction word be safely executed as ordinary reduced instruction set instructions. This feature requires that such instructions will not produce any valid operations (i.e., equivalent to nop instructions, but not necessarily the conventional nop instructions specified by the instruction set) when executed on the existing CPU that does not implement the technical solution.
[0074] In order to achieve the above effect by the instructions added to characterize the instructions as very long word instructions, for example, the mode switching instructions of method 1 and the specific instructions of method 2 have the following characteristics:
[0075] 1. It is a legal instruction in the base ISA;
[0076] 2. After fixing certain areas in the instruction, its execution result is equivalent to the nop instruction;
[0077] 3. It is not the form of the conventional nop instruction;
[0078] Optionally, if additional information of the instruction word is to be embedded therein, the following characteristics must also be met:
[0079] 4. The instruction also has at least one area, and no matter how the area changes, the above three characteristics will not be affected.
[0080] In a possible implementation, the destination register address of the mode switching instruction or the specific instruction is the address of the hardwired zero register, wherein all written values of the hardwired zero register are ignored and the read value is zero.
[0081] Specifically, take the MIPS instruction set as an example. In the MIPS instruction set architecture, the read value of the hard-wired zero register (also called the $0 register, register 0) is always 0, and any value written to it will not take effect. This feature is often called hard-wired zero. In other words, an instruction that does not generate any exception (also called a trap, sometimes also called an interrupt) will be equivalent to doing nothing (nop) as long as its target register (that is, the register to be written) is a hard-wired zero register and does not cause any other registers or CPU status changes. Therefore, this feature can be used to set the destination register address of the mode switching instruction or a specific instruction to the address of the hard-wired zero register. The nop instruction form commonly used by MIPS is an SLL instruction in which the target register is specified as a hard-wired zero register. Therefore, the following examples all meet feature 3.
[0082] In one example, take the ADDIU instruction (satisfying features 1 and 3). The format of the ADDIU instruction is: ADDIU rt,rs, immediate. The rt field of this instruction is filled with the target register, the rs field is filled with the source register, and the immediate field is filled with the immediate value. The ADDIU instruction means that the value in the source register is added to the immediate value and then written to the target register, and no exception will be generated under any circumstances. Then, as long as the rt field (target register) of the ADDIU instruction is fixed to the address of the hard-wired zero register, the execution result of the instruction is always equivalent to the nop instruction (satisfying feature 2). Therefore, the ADDIU instruction of the form of "ADDIU $0, rs, immediate" can be used as a mode switching instruction or a specific instruction, in which the rs field and the immediate field of the ADDIU instruction can be changed freely (satisfying feature 4). Some bits in the rs field and the immediate field can be used to embed additional information of the instruction word, or some bits in the rs field and the immediate field can be specified to be a certain value, thereby reducing the possibility of the same instruction happening in the existing executable file.
[0083] In another example, take the XOR instruction (satisfying features 1 and 3). The format of the XOR instruction is: XOR rd, rs, rt. The rd field of the instruction is filled with the target register, the rs field is filled with the source register 1, and the rt field is filled with the source register 2. The XOR instruction means that the value in source register 1 and the value in source register 2 are logically exclusive ORed (XOR, Exclusive OR) and then written to the target register, and no exception will occur under any circumstances. Then, as long as the rd field (target register) of the XOR instruction is fixed to the address of the hard-wired zero register, the execution result of the instruction is always equivalent to the nop instruction (satisfying feature 2). Therefore, the XOR instruction of the form "XOR $0, rs, rt" can be used as a mode switching instruction or a specific instruction, in which the rs field and rt field of the XOR instruction can be freely changed (satisfying feature 4). Some bits in the rs field and rt field can be used to embed additional information of the instruction word, or some bits in the rs field and rt field can be specified to be a certain value, thereby reducing the possibility of the same instruction happening in the existing executable file.
[0084] In another possible implementation, the destination register address of the mode switching instruction or the specific instruction is the same as at least one source register address and satisfies at least one of the following conditions: (a) if the instruction requires multiple source registers, the other source register addresses are register addresses of hard-wired zero registers; (b) if the instruction requires multiple source registers, the other source register addresses are also equal to the destination register address; (c) the immediate value is zero.
[0085] (a): In another example, take the OR instruction (satisfying characteristics 1 and 3). The format of the OR instruction is: OR rd,rs,rt. The rd field of this instruction is filled with the target register, the rs field is filled with the source register 1, and the rt field is filled with the source register 2. The OR instruction means that the value in source register 1 and the value in source register 2 are logically ORed and written to the target register, and no exception will occur under any circumstances. Then, let the register filled with the rd field (target register) of the OR instruction be recorded as $n. As long as one of the rs or rt fields (source register) is filled with $n and the other is filled with $0, the execution result of this instruction is equivalent to: taking the value in $n, taking the logical OR with the read value of $0 (always 0), and then writing it to $n. Since any number taken logically ORed with 0 is equal to the number itself, the value in $n is written back as it is without change. Such an instruction is always equivalent to a nop instruction (satisfying characteristic 2). Therefore, an OR instruction of the form "OR $n, $n, $0" or "OR $n, $0, $n" can be used as a mode switching instruction or a specific instruction, where the above $n can be any register and n represents the register number or register address. In other words, n can be changed freely (satisfying feature 4). Some bits in n can be used to embed additional information of the instruction word, or some bits in n can be specified to be a certain value, thereby reducing the possibility of the same instruction happening in the existing executable file.
[0086] For instruction set architectures that do not have a hardwired zero register like MIPS, when (b) or (c) above is met, instructions that meet the above four characteristics can also be found (of course, they can also be used for instruction set architectures that have a hardwired zero register). For the sake of convenience, we still use MIPS as an example.
[0087] (b): Still taking the OR instruction (satisfying features 1 and 3) as an example. Fill the rd, rs, and rt fields of the OR instruction into the same register, denoted as $n, then the execution result of the instruction is equivalent to: taking the value in $n, taking the logical OR with itself, and then writing it into $n. Since any number taken logically OR with itself is equal to the number itself, the value in $n is written back as it is without change, and such an instruction is always equivalent to a nop instruction (satisfying feature 2). Therefore, the OR instruction of the form "OR $n, $n, $n" can be used as a mode switching instruction or a specific instruction, where the above $n can be any register and n represents the register number or register address. In other words, n can change freely (satisfying feature 4). Some bits in n can be used to embed additional information of the instruction word, or some bits in n can be specified to be a certain value, thereby reducing the possibility of the same instruction happening in the existing executable file. Since $n can be arbitrarily selected, the hardwired zero register can be completely omitted, that is, the methodology is also applicable to instruction set architectures that do not have a hardwired zero register.
[0088] (c): Still taking the ADDIU instruction (satisfying features 1 and 3) as an example, the rs (source register) and rt (destination register) fields of the ADDIU instruction are both filled into the same register, denoted as $n, and the immediate field is filled with the immediate value 0. Then the execution result of the instruction is equivalent to: taking the value in $n, adding it to 0, and then writing it into $n. Since any number added to 0 is equal to the number itself, the value in $n is written back as it is without change. Such an instruction is always equivalent to a nop instruction (satisfying feature 2). Therefore, the ADDIU instruction of the form "ADDIU $n, $n, 0" can be used as a mode switching instruction or a specific instruction, where the above $n can be any register and n represents the register number or register address. In other words, n can change freely (satisfying feature 4). Some bits in n can be used to embed additional information of the instruction word, or some bits in n can be specified to be a certain value, thereby reducing the possibility of the same instruction happening in the existing executable file. Since $n can be arbitrarily selected, the hardwired zero register can be completely omitted. In other words, this methodology is also applicable to instruction set architectures that do not have a hardwired zero register.
[0089] Figure 6 A flowchart of an instruction processing method provided in an embodiment of the present application is shown as follows: Figure 6 As shown, the method is applied to a central processing unit (CPU), the central processing unit includes multiple pipelines, several of which are enabled pipelines, and the method includes the following steps:
[0090] Step 601: Get instructions.
[0091] The instructions are obtained by the compiler during the compilation stage, and the instructions include very long instruction words and reduced instruction set instructions, wherein the very long instruction word is composed of multiple reduced instruction set instructions without dependencies, and the multiple reduced instruction set instructions without dependencies make the vacancy degree of the very long instruction word less than a set threshold.
[0092] For example, in the instruction fetching stage, the CPU can fetch instructions in the following two ways:
[0093] Method 1: If the current instruction mode is marked by a mode switching instruction, the CPU determines the length of the instruction to be obtained according to the current instruction mode. Specifically, if the current instruction mode is a very long instruction word mode, data with a length equal to the instruction word length is obtained; if the current instruction mode is a reduced instruction set instruction mode, data with a length equal to the reduced instruction set instruction length is obtained.
[0094] Among them, the CPU can determine the instruction mode in the following way: identify whether the current instruction is a mode switching instruction; if it is not a mode switching instruction, maintain the current instruction mode; if it is a mode switching instruction, change the current instruction mode to the mode indicated in the mode switching instruction.
[0095] Method 2: If the current instruction mode is marked by identification information, the CPU first obtains data of a preset length each time it fetches an instruction. The preset length of data is sufficient to determine whether the obtained data contains identification information representing an extra-long instruction word, and then determines whether the data contains identification information representing an extra-long instruction word. If there is identification information representing an extra-long instruction word, the obtained data is trimmed, or the obtained data is retained as it is, or data is continued to be acquired so that the total length of the acquired data is equal to the length of the extra-long instruction word, and the data is treated as an extra-long instruction word. If there is no identification information representing an extra-long instruction word, the obtained data is trimmed, or the obtained data is retained as it is, or data is continued to be acquired so that the total length of the acquired data is equal to the length of the reduced instruction set instruction, and the data is treated as a reduced instruction set instruction.
[0096] The identification information representing the very long instruction word includes a specific main operation code or a specific instruction. The specific main operation code is a main operation code pre-set to represent the instruction type as a very long instruction word, and the specific instruction is an instruction pre-set to represent the instruction type as a very long instruction word. After being parsed as an instruction representing the instruction type, the specific instruction is not executed by the CPU, or after being executed by the CPU, it has no effect on the execution result of the program.
[0097] In one possible implementation, the destination register address of the mode switching instruction or the specific instruction is the address of the hardwired zero register; all written values of the hardwired zero register are ignored, and the read value is zero.
[0098] In another possible implementation, the destination register address of the mode switching instruction or the specific instruction is the same as at least one source register address and satisfies at least one of the following conditions:
[0099] a) If the instruction requires multiple source registers, the other source register addresses are the register addresses of the hard-wired zero register; (b) If the instruction requires multiple source registers, the other source register addresses are also equal to the destination register address; (c) The immediate value is zero.
[0100] Step 602: If the instruction is a very long instruction word, each reduced instruction set instruction in the very long instruction word is sent to the enabled pipelines for parallel execution.
[0101] Step 603: If the instruction is a RISC instruction, send the RISC instruction to one of the enabled pipelines for execution.
[0102] The constituent instructions of the very long instruction words and the reduced instruction set instructions need to be decoded before being executed on the pipeline. Since the constituent instructions in the very long instruction words are reduced instruction set instructions, which are instructions in the basic ISA or instructions in the compressed instructions ASE, the CPU can decode the constituent instructions of the very long instruction words in the same way as decoding the basic ISA instructions or decoding the compressed instructions ASE instructions. In other words, the constituent instructions of the reduced instruction set instructions and the very long instruction words can share a completely identical decoder for decoding. If a decoder can complete the decoding of multiple instructions at the same time, we say that it has multiple decoding units.
[0103] Figure 7 As a specific example, assume that the very long instruction word VLIW is fixed-length, each very long instruction word can accommodate 3 reduced instruction set instructions RISC (three-issue), and each reduced instruction set instruction is executed sequentially using a single issue. As can be seen from the figure, there are three pipelines in the CPU, and each pipeline includes an instruction fetch unit, a decoding unit, an execution unit, and a write-back unit. If the instruction is a very long instruction word, the three reduced instruction set instructions in the very long instruction word are sent to each pipeline for parallel execution. If the instruction is a reduced instruction set instruction, each reduced instruction set instruction is sent to one of the enabled pipelines for execution. For example, Figure 7 The reduced instruction set instruction is sent to the first pipeline for execution. In this case, for some specific hardware implementations, it is necessary to send a nop instruction to each of the other two pipelines to make the two pipelines run idle. Alternatively, in other specific hardware implementations, it may be possible to achieve idle operation without sending a nop instruction pipeline.
[0104] The implementation of the above examples is conducive to improving the performance of low-power CPUs in specific application scenarios while controlling power consumption and cost. In scenarios where the composition of very long instruction words has high parallelism, the pipeline can be filled, and since the pipeline stages required for out-of-order execution are saved, power consumption and cost are effectively controlled. For the single-issue sequential execution of reduced instruction set instructions, it can maintain compatibility with existing binaries, and can directly use reduced instruction set instructions in scenarios where very long instruction words are empty to avoid waste of resources.
[0105] It should be noted that some documents combine the instruction fetch stage and the decoding stage. The reader should understand that whether the two stages are combined or not does not affect the implementation of this embodiment.
[0106] In one possible implementation, if the instruction is a reduced instruction set instruction, the reduced instruction set instruction is sent to a decoding unit on one of the enabled pipelines for decoding; the decoded multiple reduced instruction set instructions are reordered by an instruction scheduling unit; the reordered multiple reduced instruction set instructions are sent to the enabled pipeline for execution; the executed multiple reduced instruction set instructions are reordered to restore the original order of the multiple reduced instruction set instructions.
[0107] Figure 8 As another specific example, assume that the CPU currently has three enabled pipelines, the very long instruction word is fixed-length, each very long instruction word can accommodate three reduced instruction set instructions (three issues), and the reduced instruction set instructions use superscalar, three-issue, out-of-order execution. As can be seen from the figure, there are three pipelines in the CPU, and each pipeline includes an instruction fetch unit, a decoding unit, an execution unit, and a write-back unit. In addition, the CPU also has an instruction scheduling unit and a reordering unit. If the instruction is an extremely long instruction word, the three reduced instruction set instructions in the extremely long instruction word are sent to each pipeline for execution in parallel, and the instruction scheduling unit and the reordering unit are skipped. Therefore, the actual execution principle of the extremely long instruction word is exactly the same as the previous embodiment. If the instruction is a reduced instruction set instruction, the three reduced instruction set instructions are sent to each pipeline for execution. For example, Figure 8 In the RISC instruction 1, 2 and 3, the decoder units 1, 2 and 3 on the first, second and third pipelines are sent to decode, and the decoded results enter the instruction scheduling pipeline stage. The instruction scheduling unit reorders the three RISC instructions and sends them to each pipeline for execution. After executing to level n, it enters the reordering stage. The reordering unit restores the execution results of the three RISC instructions to the original order of the RISC instructions and then enters one of the write-back units in the write-back pipeline stage for writing back (submitting the execution results). For example, Figure 7 The RISC instructions are sent to the third write-back unit for write-back.
[0108] The implementation of the above examples is conducive to improving the performance of low-power CPUs in specific application scenarios while controlling power consumption and costs. In scenarios where the composition of very long instruction words has a high degree of parallelism, the pipeline can be filled and the extra overhead and burden of out-of-order execution can be avoided. For reduced instruction set instructions, multiple-issue out-of-order execution can maintain compatibility with existing binaries, and can directly use reduced instruction set instructions in scenarios where very long instruction words are empty to avoid waste of resources. Compared with single-issue sequential execution, the performance when using reduced instruction set instructions can also be improved. In addition, in this example, only the pipeline stages related to out-of-order execution need to be closed or skipped (corresponding to Figure 8 instruction scheduling and reordering stages), and fetches only one RISC instruction per instruction fetch instead of three RISC instructions at the same time (in Figure 8 In the example, it is equivalent to removing all dotted paths, so that the reduced instruction set instructions can directly enter the first pipeline. Of course, there is no problem in entering other pipelines), which can achieve something similar to Figure 7 The single issue of the example is executed sequentially to save power consumption.
[0109] It should be noted that instruction scheduling can be incorporated into the decoding stage, and reordering can be incorporated into the write-back stage. The write-back stage is sometimes also called the commit stage, which means that the out-of-order executed instructions will not have any effect (commit execution results) as long as they have not reached this stage.
[0110] In one possible implementation, in some scenarios, at least one of the multiple pipelines can be shut down, and at least one enabled pipeline can be retained; if the instruction is a very long instruction word, and the number of enabled pipeline lines M is less than the number N of reduced instruction set instructions in the very long instruction word, then the N reduced instruction set instructions are sent in batches to each enabled pipeline for parallel execution; wherein M is greater than or equal to 1; and the number of reduced instruction set instructions sent in each batch is less than or equal to M.
[0111] Specifically, since the reduced instruction set instructions in the very long instruction word are independent of each other, the reduced instruction set instructions can be executed in parallel or sequentially in any order. In other words, as long as the order between the very long instruction words is guaranteed, there is no need to guarantee the order between the component instructions within the very long instruction word. Therefore, in a scenario where there is no requirement for computing speed, at least one of the multiple pipelines can be shut down and at least one enabled pipeline can be retained. When the number of pipeline lines M enabled on the CPU is less than the number N of reduced instruction set instructions (component instructions) in the very long instruction word, the N component instructions are sent in batches to each enabled pipeline for parallel execution, and the number of component instructions sent in each batch is less than or equal to M.
[0112] Exemplarily, when only one pipeline is reserved, only one component instruction (reduced instruction set instruction) in the very long instruction word is sent to the enabled pipeline in each cycle, and the component instructions of the very long instruction word are executed in the order of the fetch stage and the decode stage as follows:
[0113] 1. The current clock cycle number is t. The instruction fetch stage fetches an extra-long instruction word, which has three components.
[0114] 2. The current clock cycle number is t+1. The instruction fetch stage suspends instruction fetching. The decode stage receives the first component instruction from the instruction fetch stage and completes decoding.
[0115] 3. The current clock cycle number is t+2. The instruction fetch stage suspends instruction fetching. The decode stage receives the second component instruction from the instruction fetch stage and completes decoding. The decoding result of the first component instruction enters the subsequent stage for processing.
[0116] 4. The current clock cycle number is t+3. The instruction fetch stage continues to fetch instructions. The decode stage receives the third component instruction from the instruction fetch stage and completes decoding. The decoding result of the second component instruction enters the subsequent stage for processing.
[0117] And so on.
[0118] When multiple pipelines are reserved, each time a very long instruction word is fetched at the instruction fetch stage, the constituent instructions of the very long instruction word can be grouped and sent to the next stage according to the number of pipelines M that have been enabled. However, the number N of reduced instruction set instructions (constituent instructions) in the very long instruction word may not be divisible by the number of pipeline lines M enabled on the CPU; at this time, when only the end of the very long instruction word is left at the instruction fetch stage and has not been sent to the next stage, the number of constituent instructions to be sent may be less than M. Exemplarily, when 2 pipelines are reserved, at most 2 constituent instructions (reduced instruction set instructions) in the very long instruction word are sent to the enabled pipelines in each cycle, and the constituent instructions of the very long instruction word are executed in the order of the instruction fetch stage and the decoding stage as follows:
[0119] 1. The current clock cycle number is t. The instruction fetch stage fetches a very long instruction word, which has three components.
[0120] 2. The current clock cycle number is t+1. The instruction fetch stage suspends instruction fetching. The decode stage receives the first and second (a total of 2) component instructions from the instruction fetch stage and completes decoding.
[0121] 3. The current clock cycle number is t+2. The instruction fetch stage continues to fetch instructions. The decode stage receives the third (of a total of 1) component instruction from the instruction fetch stage and completes decoding. The decoding results of the first and second component instructions are processed in the subsequent stages.
[0122] And so on.
[0123] Some devices do not have requirements for computing speed at ordinary times, but only need high performance when certain important tasks come. In this way, only some pipelines can be retained and other pipelines can be closed. In this way, the operation can be maintained with extremely low power consumption, achieving the effect of saving electricity; when important tasks come, all pipelines can be turned on, so that important tasks can be completed quickly with extremely high performance. In addition, in order to save costs or power consumption, it may sometimes be desirable to implement fewer pipelines on the CPU. At this time, the number of pipelines implemented on the CPU may be less than the maximum number of component instructions allowed by the very long instruction word. In order to ensure that such a CPU can correctly and efficiently execute the very long instruction word, the missing pipelines can be regarded as the "shutdown pipelines" in the above embodiment, and can be processed with reference to the above embodiment, thereby achieving a high degree of flexibility in hardware implementation.
[0124] The embodiments of the present application provide an instruction compilation method and an instruction processing method to achieve mixed use of very long instruction words and reduced instruction set instructions in the same CPU.
[0125] 1. For low-power CPUs that execute sequentially, executing reduced instruction set instructions sequentially can significantly improve CPU performance while only increasing die area and power consumption.
[0126] 2. For superscalar high-performance CPUs, through the method provided in the embodiments of the present application, very long instruction words can be used for specific tasks, thereby turning off circuits such as out-of-order execution and eliminating pipeline stages such as out-of-order execution, thereby achieving the effect of improving performance and reducing power consumption.
[0127] 3. In certain scenarios, the method provided in the embodiments of the present application also allows the parallelism of very long instruction words to be degraded, that is, part of the pipeline is shut down, thereby further saving power when necessary.
[0128] 4. The executable file compiled for this patent can be executed on a CPU that does not apply the method of this application (backward compatibility) under certain conditions without affecting the correctness of the execution result.
[0129] 5. Based on point 4, if the CPU to which the method of the present application is not applied is a superscalar high-performance CPU that applies technologies such as out-of-order execution, then the executable file compiled by the present application, because its various instructions have been well sorted, so that independent instructions are always close together, the instruction scheduling and reordering required for the out-of-order execution of the CPU becomes easy, and a fairly ideal result can be obtained.
[0130] The method provided in the embodiment of the present application is very suitable for specific application scenarios such as digital signal processing (DSP) and deep learning. The algorithms in the field of digital signal processing are relatively simple and stable, are computationally intensive programs, and do not require real-time control in general scenarios, so they are very suitable for taking advantage of ultra-long instruction words. Deep learning also has the characteristics of a simple and stable algorithm and intensive operations. The main operators of deep learning are matrix multiplication and accumulation and convolution, which have obvious operational characteristics, and the amount of calculation of deep learning is basically in T units, and the calculation is very intensive. Therefore, ultra-long instruction words also have advantages in deep learning.
[0131] Based on the same technical concept, the present application embodiment provides a computing device, such as Fig. 9 As shown, it includes at least one processor 901 and a memory 902 connected to the at least one processor. The specific connection medium between the processor 901 and the memory 902 is not limited in the embodiment of the present application. Fig. 9 For example, the processor 901 and the memory 902 are connected via a bus. The bus can be divided into an address bus, a data bus, a control bus, etc.
[0132] In the embodiment of the present application, the memory 902 stores instructions that can be executed by at least one processor 901, and the at least one processor 901 can execute the above-mentioned instruction compilation method by executing the instructions stored in the memory 902.
[0133] Among them, the processor 901 is the control center of the computing device, which can use various interfaces and lines to connect various parts of the computer device, and perform resource settings by running or executing instructions stored in the memory 902 and calling data stored in the memory 902.
[0134] Optionally, the processor 901 may include one or more processing units, and the processor 901 may integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the modem processor may not be integrated into the processor 901. In some embodiments, the processor 901 and the memory 902 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on separate chips.
[0135] The processor 901 may be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and may implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0136] The memory 902 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 902 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, and the like. The memory 902 is any other medium that can be used to carry or store the desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 902 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0137] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0138] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0139] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0140] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0141] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0142] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A method for compiling instructions, characterized in that: The method is applied to a compiler, and the method comprises: Get multiple RISC instructions; Extracting the reduced instruction set instructions having no dependency among the plurality of reduced instruction set instructions into an instruction group; Determining whether the vacancy degree of the very long instruction word can be made less than or equal to a set threshold value if the reduced instruction set instructions in the instruction group are packed into a very long instruction word; If yes, the very long instruction word packaged into the instruction group is used as one instruction; Otherwise, each reduced instruction set instruction in the instruction group is regarded as an instruction; If the instruction and the previous instruction of the instruction are of different types, inserting a mode switching instruction before the instruction; The mode switching instruction is used to instruct the central processing unit to decode and execute according to the corresponding instruction type; the instruction type includes reduced instruction set instructions and very long instruction words; The mode switching instruction satisfies any one of the following two implementation modes: (1) The destination register address of the mode switching instruction is the address of the hardwired zero register; all written values of the hardwired zero register are ignored, and the read value is zero; (2) The destination register address of the mode switching instruction is the same as at least one source register address and satisfies at least one of the following conditions: (a) If the instruction requires multiple source registers, the other source register addresses are the register addresses of the hard-wired zero register; (b) If the instruction requires multiple source registers, the other source register addresses are also equal to the destination register address; (c) The immediate value is zero.
2. A method for compiling instructions, characterized in that: The method is applied to a compiler, and the method comprises: Get multiple RISC instructions; Extracting the reduced instruction set instructions having no dependency among the plurality of reduced instruction set instructions into an instruction group; Determining whether the vacancy degree of the very long instruction word can be made less than or equal to a set threshold value if the reduced instruction set instructions in the instruction group are packed into a very long instruction word; If yes, the very long instruction word packaged into the instruction group is used as one instruction; Otherwise, each reduced instruction set instruction in the instruction group is regarded as an instruction; Packing the reduced instruction set instructions in the instruction group into a very long instruction word, including: packing the reduced instruction set instructions in the instruction group and using a specific instruction as the first instruction of the very long instruction word to form a very long instruction word; the specific instruction is a pre-set instruction used to characterize the instruction type as a very long instruction word; the specific instruction is not executed by the CPU after being parsed as an instruction characterizing the instruction type, or has no effect on the execution result of the program after being executed by the CPU; The specific instruction satisfies any one of the following two implementation modes: (1) The destination register address of the specific instruction is the address of the hardwired zero register; all written values of the hardwired zero register are ignored, and the read value is zero; (2) The destination register address of the specific instruction is the same as at least one source register address and satisfies at least one of the following conditions: (a) If the instruction requires multiple source registers, the other source register addresses are the register addresses of the hard-wired zero register; (b) If the instruction requires multiple source registers, the other source register addresses are also equal to the destination register address; (c) The immediate value is zero.
3. A command processing method, characterized in that: The method is applied to a central processing unit, the central processing unit includes a plurality of pipelines, wherein several pipelines are enabled pipelines, and the method includes: Acquire instructions according to the current instruction mode; the instructions include very long instruction words and reduced instruction set instructions; the current instruction mode is determined based on the mode switching instruction; If the instruction is a very long instruction word, each reduced instruction set instruction in the very long instruction word is sent to the enabled pipeline for parallel execution; the very long instruction word is composed of a plurality of reduced instruction set instructions without dependencies, and the plurality of reduced instruction set instructions without dependencies make the vacancy degree of the very long instruction word less than a set threshold; if the instruction is a reduced instruction set instruction, the reduced instruction set instruction is sent to one of the enabled pipelines for execution; The mode switching instruction satisfies any one of the following two implementation modes: (1) The destination register address of the mode switching instruction is the address of the hardwired zero register; all written values of the hardwired zero register are ignored, and the read value is zero; (2) The destination register address of the mode switching instruction is the same as at least one source register address and satisfies at least one of the following conditions: (a) If the instruction requires multiple source registers, the other source register addresses are the register addresses of the hard-wired zero register; (b) If the instruction requires multiple source registers, the other source register addresses are also equal to the destination register address; (c) The immediate value is zero.
4. The method according to claim 3, characterized in that The method further comprises: If the instruction is a reduced instruction set instruction, sending the reduced instruction set instruction to a decoding unit on one of the enabled pipelines for decoding; Reordering the decoded multiple reduced instruction set instructions through an instruction scheduling unit; Sending the reordered plurality of reduced instruction set instructions to the enabled pipeline for execution; The executed multiple reduced instruction set instructions are reordered to restore the original order of the multiple reduced instruction set instructions.
5. The method according to claim 3, characterized in that: The acquiring of instructions according to the current instruction mode includes: If the current instruction mode is the very long instruction word mode, then data with a length equal to the very long instruction word length is obtained; If the current instruction mode is a reduced instruction set instruction mode, data having a length equal to the reduced instruction set instruction length is obtained.
6. The method according to claim 5, characterized in that The instruction mode is determined by: Identify whether the current instruction is a mode switching instruction; If it is not a mode switching command, the current command mode is maintained; If it is a mode switching instruction, the current instruction mode is changed to the mode indicated in the mode switching instruction.
7. The method according to claim 3, characterized in that The method further comprises: Shutting down at least one of the plurality of pipelines and retaining at least one enabled pipeline; If the instruction is a very long instruction word, and the number of enabled pipeline lines M is less than the number N of reduced instruction set instructions in the very long instruction word, then the N reduced instruction set instructions are sent in batches to each enabled pipeline for parallel execution; where M is greater than or equal to 1; and the number of reduced instruction set instructions sent in each batch is less than or equal to M.
8. A command processing method, characterized in that: The method is applied to a central processing unit, the central processing unit includes a plurality of pipelines, wherein several pipelines are enabled pipelines, and the method includes: Obtaining instructions; the instructions include very long instruction words and reduced instruction set instructions; If the instruction is a very long instruction word, each reduced instruction set instruction in the very long instruction word is sent to the enabled pipeline for parallel execution; the very long instruction word is composed of a plurality of reduced instruction set instructions without dependencies, and the plurality of reduced instruction set instructions without dependencies make the vacancy degree of the very long instruction word less than a set threshold; if the instruction is a reduced instruction set instruction, the reduced instruction set instruction is sent to one of the enabled pipelines for execution; The very long instruction word includes identification information representing the very long instruction word; the identification information representing the very long instruction word includes a specific main operation code or a specific instruction; the specific instruction satisfies any one of the following two implementation modes: (1) The destination register address of the specific instruction is the address of the hardwired zero register; all written values of the hardwired zero register are ignored, and the read value is zero; (2) The destination register address of the specific instruction is the same as at least one source register address and satisfies at least one of the following conditions: (a) If the instruction requires multiple source registers, the other source register addresses are the register addresses of the hard-wired zero register; (b) If the instruction requires multiple source registers, the other source register addresses are also equal to the destination register address; (c) The immediate value is zero.
9. The method according to claim 8, characterized in that The acquisition instruction includes: Acquire data of a preset length, wherein the data of the preset length is used to determine whether there is identification information representing an extra-long instruction word in the data; Determining whether there is identification information representing an extra-long instruction word in the data; If so, the acquired data is trimmed, or the acquired data is retained as it is, or data is continuously acquired so that the total acquired data length is equal to the length of the very long instruction word, and the data is treated as one very long instruction word; Otherwise, the acquired data is trimmed, or the acquired data is retained as it is, or data is continued to be acquired so that the total acquired data length is equal to the reduced instruction set instruction length, and the data is used as a reduced instruction set instruction.
10. The method according to claim 8, characterized in that The specific main operation code is a main operation code pre-set to indicate that the instruction type is a very long instruction word; The specific instruction is a pre-set instruction used to characterize an instruction type as a very long instruction word; after being parsed as an instruction characterizing the instruction type, the specific instruction is not executed by the CPU, or after being executed by the CPU, it has no effect on the execution result of the program.
11. The method according to claim 8, characterized in that The method further comprises: Shutting down at least one of the plurality of pipelines and retaining at least one enabled pipeline; If the instruction is a very long instruction word, and the number of enabled pipeline lines M is less than the number N of reduced instruction set instructions in the very long instruction word, then the N reduced instruction set instructions are sent in batches to each enabled pipeline for parallel execution; where M is greater than or equal to 1; and the number of reduced instruction set instructions sent in each batch is less than or equal to M.
12. A computing device, characterized in that: include: A memory for storing program instructions; A processor is used to obtain stored program instructions from the memory, and execute the method according to any one of claims 1 to 11 according to the obtained program instructions.
Citation Information
Patent Citations
Processor architecture and instruction execution method integrating sequence and VLIW (Very Long Instruction Word)
CN102799418A
Program compiling method and equipment and computer readable medium
CN113360157A
Instruction processing method and system for variable-length instructions
US6023756A
