A processing device, method and compiler for converting code

By configuring preset function properties in the code to obtain the actual instruction consumption value, the problem of low execution efficiency caused by clock cycle deviation in the compiler is solved, adaptive scheduling is realized, the execution efficiency of machine instructions is improved, and development costs are saved.

CN114443014BActive Publication Date: 2026-01-23BEIJING ESWIN COMPUTING TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210107379.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-28
Publication Date
2026-01-23
Estimated Expiration
2042-01-28

AI Technical Summary

Technical Problem

In existing technologies, when compilers generate machine instructions, there is a discrepancy between the estimated clock cycles and the actual clock cycles consumed, resulting in low program instruction execution efficiency.

Method used

By configuring preset function attributes in the code, the actual instruction consumption value is obtained, and sorting and instruction scheduling are performed based on this value. The logical processing method of the preset function attributes is encapsulated by the attribute mechanism to achieve adaptive scheduling of the code.

Benefits of technology

It improves the compatibility between the machine instructions generated after code conversion and hardware devices, enhances execution efficiency, saves development costs, and eliminates the need for additional hardware.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114443014B_ABST
    Figure CN114443014B_ABST
Patent Text Reader

Abstract

The embodiment of the application provides a processing device, a method and a compiler for converting code, and relates to the technical field of software compilation. The device comprises a memory for storing code; a logic circuit coupled with the memory, the logic circuit being configured to acquire code to be converted; and acquire an actual instruction consumption value of the code based on a preset function attribute, and sort and schedule instructions of the code according to the actual instruction consumption value; wherein the preset function attribute is configured in the code; and the preset function attribute is used to determine the instruction consumption value of the code. The embodiment of the application determines the actual instruction consumption value of the code through the preset function attribute, thereby effectively improving the execution efficiency of machine instructions generated after code conversion.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of software compilation, in particular, the present application relates to a processing device, method and compiler for converting code. BACKGROUND

[0002] Compilation refers to the translation process from source code to target code that can be directly executed by a computer or a virtual machine; wherein the source code is usually a high-level language, and the target code is usually a low-level language or machine language. In the process of generating machine code, the compiler will sort and schedule each instruction corresponding to the program instruction based on a certain clock cycle.

[0003] In the prior art, an instruction consumption model is usually used to estimate the clock cycle required for instruction execution, and the estimated clock cycle is generally fixed, which may deviate from the actual clock cycle consumed by the instruction, resulting in a decrease in the execution efficiency of the program instruction. SUMMARY

[0004] The embodiments of the present application provide a processing device, method and compiler for converting code, which can solve the problem of low execution efficiency of program instructions in the prior art. The technical solution is as follows:

[0005] According to another aspect of the embodiments of the present application, a processing device for converting code is provided, which comprises:

[0006] a memory for storing code;

[0007] a logic circuit coupled to the memory, the logic circuit being configured to obtain code to be converted, and obtain actual instruction consumption values of the code based on preset function attributes, and sort and schedule instructions of the code according to the actual instruction consumption values; wherein the preset function attributes are configured in the code; and the preset function attributes are used to determine the instruction consumption values of the code.

[0008] Optionally, the logic circuit is configured to encapsulate a logical processing mode of the preset function attributes into a preset keyword, and configure the preset function attributes for the code based on the keyword.

[0009] Optionally, the logic circuit is configured to perform syntax analysis on the keyword to obtain the logical processing mode of the preset function attributes, and obtain the actual instruction consumption values of the code according to the logical processing mode.

[0010] Optionally, when the number of actual instruction consumption values is at least two, the logic circuit is configured to detect the code based on the actual instruction consumption values, determine a target instruction consumption value, and sort and schedule instructions of the code according to the target instruction consumption value.

[0011] Optionally, the above logic circuit is used to detect the execution efficiency of the code for each actual instruction consumption value; and to determine the actual instruction consumption value corresponding to the highest value of the obtained execution efficiency as the target instruction consumption value.

[0012] Optionally, the above actual instruction consumption value includes at least one of the maximum, minimum, average, and highest frequency values ​​of instruction consumption corresponding to the code.

[0013] According to one aspect of the embodiments of this application, a method for processing conversion codes is provided, the method comprising:

[0014] Obtain the code to be converted; the code is configured with corresponding preset function properties; the preset function properties are used to determine the instruction consumption value of the code;

[0015] Get the actual instruction consumption value of the code based on preset function attributes;

[0016] The code is sorted and instructions are scheduled based on the actual instruction consumption value.

[0017] Optionally, the configuration process for the above-mentioned preset function attributes includes:

[0018] The logical processing method of the preset function attributes is encapsulated in the preset keyword;

[0019] Configure preset function properties for code based on keywords.

[0020] Optionally, the above-mentioned actual instruction consumption value of the code obtained based on preset function attributes includes:

[0021] The keywords are parsed to obtain the logical processing method of the preset function attributes;

[0022] Based on the logical processing method, obtain the actual instruction consumption value of the code.

[0023] Optionally, the above-mentioned sorting of code and instruction scheduling based on actual instruction consumption values ​​includes:

[0024] If the number of actual instruction consumption values ​​is at least two, the code is inspected based on the actual instruction consumption values ​​to determine the target instruction consumption value.

[0025] The code is sorted and instructions are scheduled based on the target instruction consumption value.

[0026] Optionally, the above-mentioned code detection based on actual instruction consumption values ​​to determine the target instruction consumption value includes:

[0027] For each actual instruction consumption value, the execution efficiency of the corresponding code is tested;

[0028] The actual instruction consumption value corresponding to the highest obtained execution efficiency value is determined as the target instruction consumption value.

[0029] Optionally, the above actual instruction consumption value includes at least one of the maximum, minimum, average, and highest frequency values ​​of instruction consumption corresponding to the code.

[0030] According to another aspect of the embodiments of this application, a compiler is provided, which includes an instruction consumption feedback module and an instruction scheduling module; wherein...

[0031] The instruction consumption feedback module is configured to obtain the code to be converted; obtain the actual instruction consumption value of the code based on preset function attributes; wherein, the preset function attributes are configured in the code; the preset function attributes are used to determine the instruction consumption value of the code;

[0032] The instruction scheduling module is configured to sort the code and schedule instructions based on the actual instruction consumption value.

[0033] Optionally, the compiler described above also includes a configuration module for:

[0034] The logical processing method of the preset function attributes is encapsulated in the preset keyword;

[0035] Configure preset function properties for code based on keywords.

[0036] Optionally, the above instruction consumption feedback module is used for:

[0037] The keywords are parsed to obtain the logical processing method of the preset function attributes;

[0038] Based on the logical processing method, obtain the actual instruction consumption value of the code.

[0039] Optionally, the above instruction scheduling module is used for:

[0040] If the number of actual instruction consumption values ​​is at least two, the code is inspected based on the actual instruction consumption values ​​to determine the target instruction consumption value.

[0041] The code is sorted and instructions are scheduled based on the target instruction consumption value.

[0042] Optionally, the above instruction scheduling module is also used for:

[0043] For each actual instruction consumption value, the execution efficiency of the corresponding code is tested;

[0044] The actual instruction consumption value corresponding to the highest obtained execution efficiency value is determined as the target instruction consumption value.

[0045] Optionally, the above actual instruction consumption value includes at least one of the maximum, minimum, average, and highest frequency values ​​of instruction consumption corresponding to the code.

[0046] According to another aspect of the present application, an electronic device is provided, comprising: a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the method shown in the second aspect of the present application.

[0047] According to another aspect of the embodiments of this application, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the steps of the method shown in the second aspect of the embodiments of this application.

[0048] According to one aspect of the present application, a computer program product is provided, which includes a computer program that, when executed by a processor, implements the steps of the method shown in the second aspect of the present application.

[0049] The beneficial effects of the technical solutions provided in this application are:

[0050] This application's embodiments determine the code to be converted and obtain the actual instruction consumption value of the code based on the preset function attributes configured in the code. This enables the code to be sorted and instructions to be scheduled according to the actual instruction consumption value, making the machine instructions generated after code conversion more closely match the actual operating conditions of the hardware device. Compared to the prior art, which sorts and schedules code based on a fixed clock cycle, the actual instruction consumption value in this application can change with different actual hardware environments, improving the code's adaptability. Furthermore, since the preset function attributes are configured in the code, no additional hardware is required, saving development costs and effectively improving the execution efficiency of the machine instructions generated after code conversion. Attached Figure Description

[0051] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments of this application will be briefly introduced below.

[0052] Figure 1 A schematic diagram of a code conversion processing device provided in an embodiment of this application;

[0053] Figure 2 A flowchart illustrating the process of determining the actual instruction consumption value using a code conversion processing apparatus provided in this application embodiment;

[0054] Figure 3 A flowchart illustrating the sorting and instruction scheduling of a code conversion processing apparatus provided in this application embodiment;

[0055] Figure 4 A flowchart illustrating a method for processing converted codes provided in an embodiment of this application;

[0056] Figure 5 A flowchart illustrating an example of a method for processing conversion code, provided as an embodiment of this application;

[0057] Figure 6 A schematic diagram of the structure of a compiler provided in an embodiment of this application;

[0058] Figure 7 This is a schematic diagram of the structure of an electronic device for processing conversion codes, provided in an embodiment of this application. Detailed Implementation

[0059] The embodiments of this application are described below with reference to the accompanying drawings. It should be understood that the embodiments described below with reference to the accompanying drawings are exemplary descriptions for explaining the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions of the embodiments of this application.

[0060] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the terms “comprising” and “including” as used in embodiments of this application mean that the corresponding feature can be implemented as the presented feature, information, data, step, operation, element, and / or component, but do not exclude implementation as other features, information, data, step, operation, element, component, and / or combinations thereof supported by the art. It should be understood that when we say that an element is “connected” or “coupled” to another element, the one element can be directly connected or coupled to the other element, or it can mean that the one element and the other element establish a connection relationship through an intermediate element. Furthermore, “connected” or “coupled” as used herein can include wireless connection or wireless coupling. The term “and / or” as used herein indicates at least one of the items defined by the term; for example, “A and / or B” can be implemented as “A,” or as “B,” or as “A and B.”

[0061] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0062] A compiler is a program that translates one language (usually a high-level language) into another language (usually a low-level language). The main workflow of a modern compiler is as follows: source code is processed by a preprocessor and a compiler to generate object code, and the linker then uses the object code to generate executable programs.

[0063] High-level computer languages ​​are easy for humans to write, read, communicate, and maintain. Machine language is language that computers can directly interpret and run. A compiler takes assembly or high-level computer language source programs as input and translates them into equivalent programs in the target language's machine code. Source code is generally in a high-level language, such as Pascal (Philips Automatic Sequence Calculator), C (a procedural, abstract general-purpose programming language widely used in low-level development), C++ (a language derived from C), Java (an object-oriented programming language), Chinese programming languages, or assembly language. The target language is the object code of the machine language, sometimes also called machine code.

[0064] Taking CPU instructions as an example, each instruction requires a certain number of clock cycles to execute. A clock cycle, also called an oscillation cycle, is defined as the reciprocal of the clock frequency. The clock cycle is the most basic and smallest unit of time in a computer. Within one clock cycle, the CPU completes only one basic action. The clock cycle is a quantity of time. It represents the highest frequency that SDRAM (synchronous dynamic random-access memory) can operate at. Smaller clock cycles mean higher operating frequencies.

[0065] For some instructions, the number of clock cycles consumed is fixed. However, for other instructions, such as memory access instructions, the number of clock cycles consumed is not fixed and varies depending on the context and the actual hardware environment.

[0066] The inventors discovered that during the generation of machine instructions, the compiler's estimated instruction clock cycle often deviates from the actual clock cycle consumed by the instruction, affecting the execution efficiency of the machine instructions. On the hardware side, this deviation can be corrected by supporting out-of-order execution, but this method requires additional hardware design costs and may increase the size of the hardware chip, leading to increased production costs.

[0067] The processing apparatus, method, and compiler for converting code provided in this application are intended to solve the above-mentioned technical problems of the prior art.

[0068] The technical solutions of this application and their effects are described below through several exemplary embodiments. It should be noted that the following embodiments can be referenced, borrowed from, or combined with each other. Identical terms, similar features, and similar implementation steps in different embodiments will not be repeated.

[0069] This application provides a processing device for converting codes, such as... Figure 1 As shown, the device 10 includes:

[0070] Memory 101 stores code;

[0071] The logic circuit 102, coupled to the memory 101, is used to acquire the code to be converted; and to acquire the actual instruction consumption value of the code based on preset function attributes, and to sort and schedule the code according to the actual instruction consumption value; wherein, the preset function attributes are configured in the code; the preset function attributes are used to determine the instruction consumption value of the code.

[0072] The code to be converted can be selected from the code in memory 101 according to user instructions. The actual instruction consumption value can be the real-time clock cycles consumed when the machine instructions generated by the code conversion are executed in the hardware. This actual instruction consumption value can change in real time as the code context changes and / or the hardware environment differs.

[0073] In this embodiment, the preset function attributes configured in the code can be set based on the attribute mechanism (a computer language). The attribute mechanism is used to add attributes to elements, and it can set function attributes, variable attributes, and type attributes. Among them, function attributes can be used to add certain characteristics to function declarations, thereby making the compiler more powerful in terms of error checking.

[0074] Specifically, the processing device for converting code can receive user instructions and filter the code to be converted from memory 101 based on the user instructions, or it can directly extract the code to be converted from memory 101.

[0075] In the embodiments of this application, the processing device for converting code can be independent of the compiler or integrated with the compiler; no specific limitation is made in this application.

[0076] This application's embodiments determine the code to be converted and obtain the actual instruction consumption value of the code based on the preset function attributes configured in the code. This enables the code to be sorted and instructions to be scheduled according to the actual instruction consumption value, making the machine instructions generated after code conversion more closely match the actual operating conditions of the hardware device. Compared to the prior art, which sorts and schedules code based on a fixed clock cycle, the actual instruction consumption value in this application can change with different actual hardware environments, improving the code's adaptability. Furthermore, since the preset function attributes are configured in the code, no additional hardware is required, saving development costs and effectively improving the execution efficiency of the machine instructions generated after code conversion.

[0077] This application provides a possible implementation method in which the logic circuit 102 is used to encapsulate the logic processing method of the preset function attribute into the preset keyword, and configure the preset function attribute for the code based on the keyword.

[0078] Specifically, the processing device for converting code can receive user input instructions, determine the logical processing method of a preset function attribute based on the input instructions, and encapsulate the logical processing method into a preset keyword. The preset keyword can be obtained based on the input instructions or can be randomly generated; no specific limitation is made in this embodiment.

[0079] Meanwhile, the processing device used for code conversion can configure preset function attributes for the code based on the attribute mechanism through preset keywords, so as to perform logical processing on the code corresponding to the preset function attributes.

[0080] In this embodiment, a specific example is given of a processing flow based on an attribute mechanism to set preset function attributes and a logical processing method for obtaining the real-time cost value of an instruction. The processing device for converting code can determine the preset keyword "SetCost" and its configuration information (i.e., the code for obtaining the real-time cost value of an instruction) based on the user's input instruction. Then, it adds the keyword "SetCost" to the list of valid keywords in the attribute mechanism and configures the processing flow for obtaining the real-time cost value of an instruction based on the aforementioned configuration information. After the above configuration process, the processing device for converting code can perform syntax analysis on the keyword based on the attribute mechanism and perform corresponding logical processing.

[0081] This application encapsulates logical processing methods into preset keywords and configures preset function attributes based on the preset keywords. Users only need to add the preset function attributes to the code to achieve the corresponding logical processing. The above encapsulation method does not require additional hardware resources, can effectively control development costs, and has good flexibility and adjustability.

[0082] This application provides one possible implementation method, such as... Figure 2 As shown, the logic circuit 102 is used to perform syntax parsing on keywords to obtain the logical processing method of preset function attributes; and to obtain the actual instruction consumption value of the code according to the logical processing method.

[0083] Specifically, the processing device used for code conversion can parse the keyword based on the preset configuration information of the keyword and determine the logical processing method of the preset function attributes.

[0084] The aforementioned logical processing method can be a processing flow for obtaining the real-time consumption value of instructions. The processing device for converting code can obtain the actual instruction consumption value of the code according to this processing flow.

[0085] In this embodiment of the application, the specific description is based on the processing flow of parsing the keyword SetCost based on the attribute mechanism and obtaining the real-time consumption value of the instruction. When the function attribute configured in the code is: __attribute__((SetCost(max,min,average)), the processing device used to convert the code can perform syntax parsing on SetCost based on the attribute mechanism to determine the logical processing method of the corresponding function attribute as: obtaining the maximum value, minimum value and average value of the real-time consumption value of the instruction.

[0086] This application determines the logical processing method of preset function attributes by parsing keywords to obtain the actual instruction consumption value corresponding to the code. Since the actual instruction consumption value is obtained in real time during the code parsing stage, it can make the actual instruction consumption value more compatible with the current code context and hardware environment, enhance the accuracy and adaptability of the actual instruction consumption value, and effectively improve the execution efficiency of the machine instructions generated by code conversion.

[0087] This application provides a possible implementation method, wherein the actual instruction consumption value includes at least one of the maximum, minimum, average, and highest frequency values ​​of the instruction consumption corresponding to the code.

[0088] In the embodiments of this application, such as Figure 3 As shown, the number of actual instruction consumption values ​​can be one or more, and no specific limitation is made in this embodiment. When there is only one actual instruction consumption value, the instruction consumption value can be directly obtained, and subsequent scheduling processing of the code can be performed based on the instruction consumption value. When there are multiple actual instruction consumption values, a target instruction consumption value can be determined based on the multiple actual instruction consumption values, and subsequent scheduling processing of the code can be performed based on the target instruction consumption value. The specific process of determining the target instruction consumption value will be described in detail below.

[0089] This application obtains at least one of the maximum, minimum, average, and highest frequency values ​​of instruction consumption as the actual instruction consumption value, so that the actual instruction consumption value can represent the instruction consumption of the code from different dimensions, thereby increasing the matching degree between the actual instruction consumption value and the code.

[0090] This application provides a possible implementation method in which the above logic circuit 102 is used to detect the code based on the actual instruction consumption value when the number of actual instruction consumption values ​​is at least two, and determine the target instruction consumption value; and sort and schedule the code according to the target instruction consumption value.

[0091] Specifically, the processing device for converting code can filter out the target instruction consumption value from at least two actual instruction consumption values, or determine the target instruction consumption value based on the functional relationship between at least two actual instruction consumption values ​​and the target instruction consumption value, or determine the target instruction consumption value corresponding to at least two actual instruction consumption values ​​based on the user's operation instructions. No specific limitations are made in the embodiments of this application.

[0092] In some implementations, the processing device for transforming code can be combined with a compiler to sort the code and schedule instructions according to the target instruction consumption value in order to complete the compilation of the code.

[0093] In other embodiments, the processing device for code conversion can directly sort the code and schedule instructions based on the target instruction consumption value to complete the compilation of the source code. In this embodiment, the compiler is integrated into the processing device for code conversion.

[0094] This application determines the target instruction consumption value by using at least two actual instruction consumption values, and sorts and schedules the code based on the target instruction consumption value. Since the target instruction consumption value is generated by combining actual instruction consumption values ​​from different dimensions, it achieves a good match between the target instruction consumption value and the machine instructions, improves the execution efficiency of the machine instructions generated by code conversion without the need for additional hardware, and enhances the user experience.

[0095] This application provides a possible implementation method in which the logic circuit 102 is used to detect the execution efficiency of the code for each actual instruction consumption value; and to determine the actual instruction consumption value corresponding to the highest value of the obtained execution efficiency as the target instruction consumption value.

[0096] Specifically, the processing device used for code conversion can debug the code for each actual instruction consumption value and detect the machine instruction execution efficiency corresponding to each actual instruction consumption value according to the preset debugging code.

[0097] Meanwhile, the processing device used for code conversion can obtain the highest value of execution efficiency corresponding to all actual instruction consumption values, take the highest value as the target execution efficiency, and then determine the actual instruction consumption value corresponding to the target execution efficiency as the target instruction consumption value.

[0098] In this embodiment, a specific example is given of a process that uses an attribute mechanism to parse the keyword `SetCost` and obtains the real-time cost value of an instruction. When the function attribute configured in the code is `__attribute__((SetCost(max,min,average))`, the processing device used to convert the code can perform syntax parsing on `SetCost` based on the attribute mechanism to determine the logical processing method of the corresponding function attribute: obtaining the maximum, minimum, and average real-time cost value of the instruction. Through the aforementioned preset function attribute, the actual instruction cost value can be obtained as: a maximum of 5 clock cycles, a minimum of 4 clock cycles, and an average of 5 clock cycles. The code can be debugged for each of these clock cycle values, and the execution efficiency of the machine instructions corresponding to each clock cycle value can be detected based on the debugged code. When the execution efficiency corresponding to 5 clock cycles is found to be the highest, the target instruction cost value can be determined to be 5 clock cycles.

[0099] This application detects the execution efficiency of machine instructions by using different actual instruction consumption values, and determines the target instruction consumption value from the actual instruction consumption values ​​based on each execution efficiency. Since the execution efficiency corresponding to the target instruction consumption value is the highest, the matching degree between the target instruction consumption value and the code is further improved, effectively improving the actual execution efficiency of the machine instructions generated by code conversion.

[0100] This application provides a method for processing converted codes, such as... Figure 4 As shown, the method includes:

[0101] S401, Obtain the code to be converted; wherein, the code is configured with corresponding preset function attributes; the preset function attributes are used to determine the instruction consumption value of the code.

[0102] S402, obtain the actual instruction consumption value of the code based on the preset function attributes.

[0103] S403 sorts the code and schedules instructions based on the actual instruction consumption value.

[0104] This application provides a possible implementation method, in which the configuration process of the above-mentioned preset function attributes includes:

[0105] (1) Encapsulate the logical processing method of the preset function attributes into the preset keyword.

[0106] (2) Configure preset function properties for code based on keywords.

[0107] This application embodiment provides a possible implementation method, in which the above step S402, obtaining the actual instruction consumption value of the code based on preset function attributes, includes:

[0108] (1) Perform syntax parsing on the keywords to obtain the logical processing method of the preset function attributes.

[0109] (2) Obtain the actual instruction consumption value of the code according to the logical processing method.

[0110] This application provides a possible implementation method, wherein the actual instruction consumption value includes at least one of the maximum, minimum, average, and highest frequency values ​​of the instruction consumption corresponding to the code.

[0111] This application embodiment provides a possible implementation method, in which the above step S403, sorting the code and scheduling instructions according to the actual instruction consumption value, includes:

[0112] (1) When the number of actual instruction consumption values ​​is at least two, the code is detected based on the actual instruction consumption values ​​to determine the target instruction consumption value.

[0113] This application provides a possible implementation method in which the above-mentioned code detection based on actual instruction consumption value to determine the target instruction consumption value includes:

[0114] a. For each actual instruction consumption value, test the execution efficiency of the corresponding code.

[0115] b. Determine the actual instruction consumption value corresponding to the highest obtained execution efficiency value as the target instruction consumption value.

[0116] (2) Sort the code and schedule instructions according to the target instruction consumption value.

[0117] This application's embodiments determine the code to be converted and obtain the actual instruction consumption value of the code based on the preset function attributes configured in the code. This enables the code to be sorted and instructions to be scheduled according to the actual instruction consumption value, making the machine instructions generated after code conversion more closely match the actual operating conditions of the hardware device. Compared to the prior art, which sorts and schedules code based on a fixed clock cycle, the actual instruction consumption value in this application can change with different actual hardware environments, improving the code's adaptability. Furthermore, since the preset function attributes are configured in the code, no additional hardware is required, saving development costs and effectively improving the execution efficiency of the machine instructions generated after code conversion.

[0118] To better understand the processing methods used for code conversion described above, the following will combine... Figure 5 This paper details an example of a processing method for transforming code according to this application. This method is applied to a compiler and includes the following steps:

[0119] S501, the compiler determines the code to be converted; the code is configured with preset function attributes, which correspond to preset keywords; the preset function attributes are used to determine the instruction consumption value of the code.

[0120] The code to be converted can be obtained by filtering from the source code according to user instructions.

[0121] Specifically, the compiler can receive user instructions and determine the code to be converted from the source code based on those instructions, or it can directly extract the code to be converted from a preset database. The configuration process for preset function properties is as follows:

[0122] The logic processing method of the preset function properties is encapsulated in the preset keywords, and the preset function properties are configured for the code based on the keywords.

[0123] Specifically, the compiler can configure preset function attributes for the code using preset keywords based on the attribute mechanism, so as to perform the corresponding logical processing on the code for the preset function attributes.

[0124] S502 performs syntax parsing on keywords to obtain the logical processing method of preset function attributes.

[0125] Specifically, the compiler can parse the keyword based on its preset configuration information and determine the logical processing method for the preset function attributes.

[0126] S503 obtains the actual instruction consumption value of the code based on the logical processing method.

[0127] The aforementioned logical processing method can be a process for obtaining the real-time cost value of instructions. The compiler can obtain the actual instruction cost value of the code based on this process. The actual instruction cost value includes at least one of the following: the maximum, minimum, average, and most frequent value of the machine instruction cost corresponding to the code.

[0128] In this embodiment of the application, the processing flow of parsing the keyword SetCost based on the attribute mechanism and obtaining the real-time consumption value of the instruction is used as an example for specific explanation. When the function attribute configured in the code is: __attribute__((SetCost(max,min,average)), the compiler can perform syntax parsing on SetCost based on the attribute mechanism to determine the logical processing method of the corresponding function attribute as: obtaining the maximum value, minimum value and average value of the real-time consumption value of the corresponding machine instruction.

[0129] S504: When there are at least two actual instruction consumption values, the execution efficiency of the code is checked for each actual instruction consumption value.

[0130] Specifically, the compiler can debug the code for each actual instruction cost value separately, and detect the machine instruction execution efficiency corresponding to each actual instruction cost value according to the preset debugging code.

[0131] S505 determines the actual instruction consumption value corresponding to the highest obtained execution efficiency value as the target instruction consumption value.

[0132] Specifically, the compiler can obtain the highest execution efficiency value corresponding to all actual instruction consumption values, take the highest value as the target execution efficiency, and then determine the actual instruction consumption value corresponding to the target execution efficiency as the target instruction consumption value.

[0133] In this embodiment, a specific example is given of a process that uses an attribute mechanism to parse the keyword `SetCost` and obtains the real-time cost value of an instruction. When the function attribute configured in the code is `__attribute__((SetCost(max,min,average))`, the compiler can perform syntax parsing on `SetCost` based on the attribute mechanism to determine the logical processing method of the corresponding function attribute: obtaining the maximum, minimum, and average real-time cost value of the instruction. Through the aforementioned preset function attribute, the actual instruction cost values ​​can be obtained as follows: a maximum of 5 clock cycles, a minimum of 4 clock cycles, and an average of 5 clock cycles. The code can be debugged for each of these clock cycle values, and the execution efficiency of the machine instructions corresponding to each clock cycle value can be detected based on the debugged code. When the execution efficiency corresponding to 5 clock cycles is found to be the highest, the target instruction cost value can be determined to be 5 clock cycles.

[0134] S506 sorts the code and schedules instructions based on the target instruction consumption value.

[0135] This application's embodiments determine the code to be converted and obtain the actual instruction consumption value of the code based on the preset function attributes configured in the code. This enables the code to be sorted and instructions to be scheduled according to the actual instruction consumption value, making the machine instructions generated after code conversion more closely match the actual operating conditions of the hardware device. Compared to the prior art, which sorts and schedules code based on a fixed clock cycle, the actual instruction consumption value in this application can change with different actual hardware environments, improving the code's adaptability. Furthermore, since the preset function attributes are configured in the code, no additional hardware is required, saving development costs and effectively improving the execution efficiency of the machine instructions generated after code conversion.

[0136] The methods in this application embodiment can be applied to the apparatus provided in this application embodiment, and their implementation principles are similar. The steps in the methods of each embodiment of this application correspond to the actions performed by each module in the apparatus of each embodiment of this application. For detailed descriptions of the steps in the methods, please refer to the descriptions of the corresponding apparatuses shown above, which will not be repeated here.

[0137] This application's embodiments determine the code to be converted and obtain the actual instruction consumption value of the code based on the preset function attributes configured in the code. This enables the code to be sorted and instructions to be scheduled according to the actual instruction consumption value, making the machine instructions generated after code conversion more closely match the actual operating conditions of the hardware device. Compared to the prior art, which sorts and schedules code based on a fixed clock cycle, the actual instruction consumption value in this application can change with different actual hardware environments, improving the code's adaptability. Furthermore, since the preset function attributes are configured in the code, no additional hardware is required, saving development costs and effectively improving the execution efficiency of the machine instructions generated after code conversion.

[0138] This application provides a compiler in its embodiments, such as... Figure 6 As shown, the compiler 60 may include an instruction consumption feedback module 601 and an instruction scheduling module 602; wherein,

[0139] The instruction consumption feedback module 601 is configured to acquire the code to be converted; acquire the actual instruction consumption value of the code based on preset function attributes; wherein, the preset function attributes are configured in the code; the preset function attributes are used to determine the instruction consumption value of the code;

[0140] The instruction scheduling module 602 is configured to sort the code and schedule instructions based on the actual instruction consumption value.

[0141] This application embodiment provides a possible implementation, wherein the compiler further includes a configuration module 603, used for:

[0142] The logical processing method of the preset function attributes is encapsulated in the preset keyword;

[0143] Configure preset function properties for code based on keywords.

[0144] This application embodiment provides a possible implementation, wherein the above-mentioned instruction consumption feedback module 601 is used for:

[0145] The keywords are parsed to obtain the logical processing method of the preset function attributes;

[0146] Based on the logical processing method, obtain the actual instruction consumption value of the code.

[0147] This application embodiment provides a possible implementation, wherein the instruction scheduling module 602 described above is used for:

[0148] If the number of actual instruction consumption values ​​is at least two, the code is inspected based on the actual instruction consumption values ​​to determine the target instruction consumption value.

[0149] The code is sorted and instructions are scheduled based on the target instruction consumption value.

[0150] This application embodiment provides a possible implementation, wherein the instruction scheduling module 602 described above is further used for:

[0151] For each actual instruction consumption value, the execution efficiency of the corresponding code is tested;

[0152] The actual instruction consumption value corresponding to the highest obtained execution efficiency value is determined as the target instruction consumption value.

[0153] This application provides a possible implementation method, wherein the actual instruction consumption value includes at least one of the maximum, minimum, average, and highest frequency values ​​of the instruction consumption corresponding to the code.

[0154] This application's embodiments determine the code to be converted and obtain the actual instruction consumption value of the code based on the preset function attributes configured in the code. This enables the code to be sorted and instructions to be scheduled according to the actual instruction consumption value, making the machine instructions generated after code conversion more closely match the actual operating conditions of the hardware device. Compared to the prior art, which sorts and schedules code based on a fixed clock cycle, the actual instruction consumption value in this application can change with different actual hardware environments, improving the code's adaptability. Furthermore, since the preset function attributes are configured in the code, no additional hardware is required, saving development costs and effectively improving the execution efficiency of the machine instructions generated after code conversion.

[0155] This application provides an electronic device, including a memory, a processor, and a computer program stored in the memory. The processor executes the computer program to implement the steps of a processing method for converting code. Compared with related technologies, this application achieves the following: By determining the code to be converted and obtaining the actual instruction consumption value of the code based on the preset function attributes configured in the code, the code is sorted and instructions are scheduled according to the actual instruction consumption value, making the machine instructions generated after code conversion more compatible with the actual operating conditions of the hardware device. Compared with the prior art, which sorts and schedules code according to a fixed clock cycle, the actual instruction consumption value in this application can change with different actual hardware environments, improving the adaptability of the code. At the same time, the preset function attributes are configured in the code, eliminating the need for additional hardware, saving development costs, and effectively improving the execution efficiency of the machine instructions generated after code conversion.

[0156] In one alternative embodiment, an electronic device is provided, such as Figure 7 As shown, Figure 7The illustrated electronic device 700 includes a processor 701 and a memory 703. The processor 701 and the memory 703 are connected, for example, via a bus 702. Optionally, the electronic device 700 may further include a transceiver 704, which can be used for data interaction between the electronic device and other electronic devices, such as sending and / or receiving data. It should be noted that in practical applications, the transceiver 704 is not limited to one type, and the structure of this electronic device 700 does not constitute a limitation on the embodiments of this application.

[0157] Processor 701 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 701 may also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.

[0158] Bus 702 may include a pathway for transmitting information between the aforementioned components. Bus 702 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 702 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 7 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0159] The memory 703 may be ROM (Read Only Memory) or other types of static storage devices capable of storing static information and instructions, RAM (Random Access Memory) or other types of dynamic storage devices capable of storing information and instructions, or EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium capable of carrying or storing computer programs and capable of being read by a computer, without limitation herein.

[0160] The memory 703 stores computer programs that execute embodiments of this application, and the processor 701 controls their execution. The processor 701 executes the computer programs stored in the memory 703 to implement the steps shown in the foregoing method embodiments.

[0161] Electronic devices include, but are not limited to: mobile terminals such as mobile phones, laptops, and tablets, as well as fixed terminals such as digital TVs and desktop computers.

[0162] This application provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it can implement the steps and corresponding content of the aforementioned method embodiments.

[0163] This application provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the following actions:

[0164] Obtain the code to be converted; the code is configured with corresponding preset function properties; the preset function properties are used to determine the instruction consumption value of the code;

[0165] Get the actual instruction consumption value of the code based on preset function attributes;

[0166] The code is sorted and instructions are scheduled based on the actual instruction consumption value.

[0167] The terms "first," "second," "third," "fourth," "1," "2," etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in a sequence other than that shown in the figures or text.

[0168] It should be understood that although arrows indicate various operation steps in the flowcharts of this application's embodiments, the order in which these steps are implemented is not limited to the order indicated by the arrows. Unless explicitly stated herein, in some implementation scenarios of this application's embodiments, the implementation steps in each flowchart can be executed in other orders as required. Furthermore, some or all steps in each flowchart, based on the actual implementation scenario, may include multiple sub-steps or multiple stages. Some or all of these sub-steps or stages can be executed at the same time, and each sub-step or stage can also be executed at different times. In scenarios where execution times differ, the execution order of these sub-steps or stages can be flexibly configured according to requirements, and this application's embodiments do not limit this.

[0169] The above description is only an optional implementation method for some implementation scenarios of this application. It should be noted that for those skilled in the art, other similar implementation methods based on the technical concept of this application without departing from the technical concept of this application also fall within the protection scope of the embodiments of this application.

Claims

1. A processing apparatus for converting codes, characterized in that, include: The memory stores the code; A logic circuit coupled to the memory, the logic circuit being used to acquire the code to be converted; The code is then processed by obtaining the actual instruction consumption value of the code based on preset function attributes, and sorting and scheduling the code according to the actual instruction consumption value; wherein the preset function attributes are configured in the code. The preset function attribute is used to determine the instruction consumption value of the code; The logic circuit is used to encapsulate the logical processing method of the preset function attribute into a preset keyword, and configure the preset function attribute for the code based on the keyword.

2. The processing apparatus according to claim 1, characterized in that, The logic circuit is used to perform syntax parsing on the keyword to obtain the logical processing method of the preset function attribute; and to obtain the actual instruction consumption value of the code according to the logical processing method.

3. The processing apparatus according to claim 1, characterized in that, The logic circuit is used to detect the code based on the actual instruction consumption value when the number of actual instruction consumption values ​​is at least two, and determine the target instruction consumption value; and to sort and schedule the code according to the target instruction consumption value.

4. The processing apparatus according to claim 3, characterized in that, The logic circuit is used to detect the execution efficiency of the code for each actual instruction consumption value; and to determine the actual instruction consumption value corresponding to the highest value of the obtained execution efficiency as the target instruction consumption value.

5. The processing apparatus according to claim 1, characterized in that, The actual instruction consumption value includes at least one of the following: the maximum, minimum, average, and highest frequency value of instruction consumption corresponding to the code.

6. A processing method for converting codes, characterized in that, include: Obtain the code to be converted; wherein the code is configured with corresponding preset function attributes; the preset function attributes are used to determine the instruction consumption value of the code; The actual instruction consumption value of the code is obtained based on the preset function attributes; The code is sorted and instructions are scheduled based on the actual instruction consumption value; The method further includes: encapsulating the logical processing method of the preset function attribute into a preset keyword, and configuring the preset function attribute for the code based on the keyword.

7. A compiler, characterized in that, include: The instruction consumption feedback module and the instruction scheduling module; among them, An instruction consumption feedback module is configured to acquire the code to be converted; acquire the actual instruction consumption value of the code based on preset function attributes; wherein, the preset function attributes are configured in the code; the preset function attributes are used to determine the instruction consumption value of the code; An instruction scheduling module is configured to sort and schedule the code based on the actual instruction consumption value; The compiler is also used to encapsulate the logical processing method of the preset function attributes into preset keywords, and configure the preset function attributes for the code based on the keywords.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the steps of the method of claim 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method of claim 6.

Citation Information

Patent Citations

  • Lightweight efficient assembly code programming method and system for GPDSP

    CN113721899A