Encoding and decoding method and system of immediate operand, and storage medium

The automatic generation of encoding and decoding functions for immediate operands addresses manual implementation errors and inefficiencies by leveraging a structure and linked list to integrate into an LLVM compiler, ensuring rapid and accurate compiler support.

CN119105760APending Publication Date: 2024-12-10CHIPEASY TECHNOLOGY (SHANGHAI) LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310685956.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-09
Publication Date
2024-12-10

AI Technical Summary

Technical Problem

Current processor instruction encoding and decoding methods rely heavily on manual development, leading to errors and inefficiencies due to outdated instruction manuals and lengthy development times.

Method used

An encoding and decoding method that automatically generates functions for immediate operands by analyzing processor design information through a structure and bidirectional linked list, using a dynamic link library to load and integrate these functions into an LLVM compiler, thereby avoiding manual errors and accelerating the compiler generation process.

Benefits of technology

Automatically generates accurate and timely encoding and decoding functions for immediate operands, ensuring rapid and error-free compiler support by directly reflecting design adjustments in logical descriptions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119105760A_ABST
    Figure CN119105760A_ABST
Patent Text Reader

Abstract

The invention discloses an immediate operand encoding and decoding method and system and a storage medium, and relates to the field of processor design, and the method comprises the steps: storing processor design information in a core.so file in the form of a structural body and a double linked list; the core.so file is loaded, and the core.so file is loaded and recovered to a memory; calling an interface provided for the outside in the loaded core.so file by using a C / C + + code; the immediate operand type operands are recovered to a memory through a structural body and a double linked list; generating a coding function; all coding functions are integrated into an LLVM compiler source code, and an LLVM compiler is reconstructed; and encoding the immediate operand by using the reconstructed LLVM compiler. According to the method, the encoding and decoding functions of the immediate operands can be automatically generated, automatic generation of the compiler is accelerated, and the problem that errors are prone to occurring due to manual implementation is also avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of processor design, and in particular to an encoding and decoding method, system and storage medium for an immediate operand. Background Art

[0002] Instruction design is a key module in processor design. When the instruction design plan is adjusted, the compiler needs to be able to quickly and accurately provide the corresponding instruction encoding and decoding support. Currently, when implementing support for processor instruction encoding and decoding, it mainly relies on developers to manually read the instruction manual and then develop code implementation. If the instruction manual is not updated or the developer has a misunderstanding, the instruction encoding and decoding function that is finally implemented is prone to errors. At the same time, manual development requires development planning and scheduling, which takes a certain amount of development time and cannot achieve rapid support. Summary of the invention

[0003] The purpose of the present invention is to provide an encoding and decoding method, system and storage medium for immediate operands, which can realize automatic generation of encoding and decoding functions for immediate operands, accelerate the automatic generation of compilers, and avoid the problem of easy errors in manual implementation.

[0004] To achieve the above object, the present invention provides the following solutions:

[0005] A method for encoding and decoding an immediate operand, comprising:

[0006] The processor design information in the processor design result file is represented in the form of a structure and a bidirectional linked list, and stored in a core.so file; the core.so file is used to provide a series of interfaces;

[0007] Use the dynamic link library loading function provided by the operating system to load the core.so file, and load and restore the static core.so file on the disk into the memory;

[0008] Use C / C++ code to call the interface provided by the loaded core.so file; and restore the immediate operand type in the processor design result to the memory through the structure and the doubly linked list;

[0009] Traverse the immediate type operands one by one and generate the corresponding encoding function;

[0010] Integrate all encoding functions into the LLVM compiler source code and rebuild the LLVM compiler;

[0011] Leverage the rebuilt LLVM compiler to encode immediate values.

[0012] Optionally, the dynamic link library loading function is a dynamic link library loading function dlopen provided by a Linux operating system.

[0013] Optionally, the immediate operand type in the processor design result is restored to the memory through a structure and a bidirectional linked list, specifically including:

[0014] Create a structure instance according to each immediate type operand, and use the member variables of the structure instance to store the operand information;

[0015] Adding the structure instance to a doubly linked list; the doubly linked list is used to store operands; each node on the doubly linked list is a structure instance and corresponds to an operand;

[0016] Associate the doubly linked list with the structure instance; and complete it through the C language assignment statement farm->operands=operandsList.

[0017] Optionally, the step of traversing the immediate type operands one by one to generate corresponding encoding functions specifically includes:

[0018] Using the initialized farm variable as the entry point, obtain the list of all immediate operands in the current processor through farm->operands, and traverse and process them one by one;

[0019] Access each operation in each immediate operand list in reverse order, and generate C++ code for the inverse operation corresponding to the operation;

[0020] Concatenate the C++ codes corresponding to all operations in each immediate type operand to obtain the corresponding encoding function.

[0021] A coding and decoding system for an immediate operand, comprising:

[0022] The core.so file determination module is used to represent the processor design information in the processor design result file in the form of a structure and a bidirectional linked list, and store it in the core.so file; the core.so file is used to provide a series of interfaces;

[0023] The loading module is used to load the core.so file using the dynamic link library loading function provided by the operating system, and load and restore the static core.so file on the disk into the memory;

[0024] The calling module is used to use C / C++ code to call the interface provided by the loaded core.so file; and restore the immediate type operands in the processor design results to the memory through the structure and the doubly linked list;

[0025] An encoding function generation module, used for traversing immediate type operands one by one and generating corresponding encoding functions;

[0026] LLVM compiler reconstruction module, which is used to integrate all encoding functions into the LLVM compiler source code and rebuild the LLVM compiler;

[0027] Encoding module for encoding immediate values ​​using the rebuilt LLVM compiler.

[0028] A storage medium stores computer program instructions, which implement the method when the computer program instructions are executed by a processor.

[0029] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects:

[0030] The present invention provides an encoding and decoding method, system and storage medium for immediate operands, which analyzes the processor design result file, extracts the immediate type operands, analyzes the corresponding hardware behavior description, converts the hardware behavior described in the processor design file into an equivalent C++ code, and serves as an operand decoding function of the disassembler when disassembling instructions; at the same time, the hardware behavior described in the processor design file is reversely deduced to derive its corresponding reverse operation, and an equivalent C++ code is also generated as an encoding function of the immediate operand when assembling instructions. Finally, the encoding and decoding function of the immediate operand is automatically generated, which speeds up the automatic generation of the compiler and avoids the problem of easy errors in manual implementation. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0032] Figure 1 The present invention provides a flowchart of an encoding and decoding method for an immediate operand. DETAILED DESCRIPTION

[0033] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0034] The purpose of the present invention is to provide an encoding and decoding method, system and storage medium for immediate operands, which can realize automatic generation of encoding and decoding functions for immediate operands, accelerate the automatic generation of compilers, and avoid the problem of easy errors in manual implementation.

[0035] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0036] like Figure 1 As shown, a method for encoding and decoding an immediate operand provided by the present invention includes:

[0037] S101, the processor design information in the processor design result file is represented in the form of a structure and a bidirectional linked list, and stored in a core.so file; the core.so file is used to provide a series of interfaces.

[0038] Load the core.so file and call the interface it provides to restore the processor design information of the core.so file to the memory. In the memory, the processor design information is also stored and represented in the form of structures and bidirectional linked lists for easy retrieval.

[0039] S102, using the dynamic link library loading function provided by the operating system to load the core.so file, and load and restore the static core.so file on the disk into the memory.

[0040] The dynamic link library loading function is a dynamic link library loading function dlopen provided by the Linux operating system. Dlopen is a standard dynamic link library loading function provided by the operating system, which is used to load and restore the static file core.so stored on the disk into the memory, and complete the functions such as symbol resolution and binding. After loading is completed, the external module can call the interface (function) provided in core.so. The method described in this scheme is developed and implemented by C / C++, and the loading of the core.so dynamic link library is completed by the following code in the C / C++ code.

[0041] mycore=dlopen(core.so); / / The dlopen function is a dynamic link library loading function provided by the operating system.

[0042] S103, using C / C++ code to call the interface (farm_create_core) provided to the outside in the loaded core.so file; and restore the immediate type operands in the processor design result to the memory through the structure and the bidirectional linked list.

[0043] The loading process is:

[0044] farm_t farm;

[0045] core_create=dlsym(mycore,"farm_create_core");

[0046] farm = farm_create_core();

[0047] mycore is the handle handler returned by the dlopen function.

[0048] "farm_create_core" is the interface (function) provided to the outside world in core.so.

[0049] S103 specifically includes:

[0050] Create a structure instance based on each immediate type operand, and use the member variables of the structure instance to store the operand information.

[0051] Add the structure instance to a doubly linked list (operandsList); the doubly linked list is used to store operands; each node on the doubly linked list is a structure instance and corresponds to an operand.

[0052] The doubly linked list is associated with the structure instance; and this is done through the C language assignment statement farm->operands=operandsList. After the above steps, the operands in the processor design have been restored to the memory, which is convenient for query and use in subsequent steps.

[0053] S104, traverse the immediate type operands one by one and generate corresponding encoding functions.

[0054] S104 specifically includes:

[0055] Using the initialized farm variable as the entry point, obtain the list of all immediate operands in the current processor through farm->operands, and traverse and process them one by one. Each immediate operand will have a list recording its hardware logic description. The hardware logic description is a collection of a series of operations that define how the hardware processes the immediate values ​​contained in the immediate operand. These operations are:

[0056] 1)OP_SEXT: Perform sign extension on the input immediate value.

[0057] 2) OP_SLICE: Slice the input immediate value, specifying the bits in advance.

[0058] 3)OP_REPL: Perform a copy operation on the specified bit.

[0059] 4)OP_CONCAT: Connect two input data into one.

[0060] 5)OP_ZEXT: Perform unsigned extension on input data.

[0061] 6)OP_SLL: Perform left shift operation on input data.

[0062] 7)OP_ADD: Perform addition operation on input data.

[0063] For example, for an immediate operand immB, the corresponding hardware logic description list is as follows:

[0064] operand immB

[0065] OP_SLICE…

[0066] OP_REPL…

[0067] OP_CONCAT…

[0068] Access each operation in each immediate operand list in reverse order, and generate C++ code for the inverse operation corresponding to the operation. For example, for immB in the above example, which contains three operations, the method described in this solution will generate three segments of C++ code, which together constitute the encoding method of the immediate operand immB.

[0069] The C++ codes corresponding to all operations in each immediate type operand are concatenated to obtain the corresponding encoding function. The corresponding C++ codes are generated according to the operations in the hardware logic description list to form the encoding function of the operand.

[0070] S105, integrating all encoding functions into the LLVM compiler source code and rebuilding the LLVM compiler.

[0071] S106, using the rebuilt LLVM compiler to encode the immediate value.

[0072] The present invention provides a logical description corresponding to an immediate operand of type, which is a combination of a series of operations. The types of these operations are limited. As long as the correct C++ code corresponding to each operation type is established, the correct C++ code combination, i.e., the encoding and decoding function, can be automatically generated for any type of immediate operand according to its logical description. At the same time, since the encoding and decoding function is directly generated from the logical description of the operand, any design adjustment of the immediate operand can be immediately reflected in its logical description, and then its corresponding encoding and decoding function can also be immediately updated.

[0073] The present invention automatically generates corresponding encoding and decoding functions by automatically analyzing the logical description of immediate type operands. When the compiler encodes and decodes the immediate type operands, these automatically generated encoding and decoding functions can be directly called, thereby ensuring timeliness and accuracy.

[0074] As another specific embodiment, the present invention provides an immediate operand encoding and decoding system, including:

[0075] The core.so file determination module is used to represent the processor design information in the processor design result file in the form of a structure and a bidirectional linked list, and store it in the core.so file; the core.so file is used to provide a series of interfaces.

[0076] The loading module is used to load the core.so file by using the dynamic link library loading function provided by the operating system, and load and restore the static core.so file on the disk into the memory.

[0077] The calling module is used to use C / C++ code to call the external interface in the loaded core.so file; and restore the immediate type operands in the processor design results to the memory through the structure and the doubly linked list.

[0078] The encoding function generation module is used to traverse the immediate type operands one by one and generate corresponding encoding functions.

[0079] LLVM compiler reconstruction module, used to integrate all encoding functions into the LLVM compiler source code and rebuild the LLVM compiler.

[0080] Encoding module for encoding immediate values ​​using the rebuilt LLVM compiler.

[0081] In order to execute the methods corresponding to the above embodiments to achieve corresponding functions and technical effects, the present invention provides a storage medium on which computer program instructions are stored. When the computer program instructions are executed by a processor, the described methods are implemented.

[0082] Based on the above description, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the methods of various embodiments of the present invention. The aforementioned computer storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory, a random access memory, a magnetic disk or an optical disk.

[0083] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0084] The principles and implementation methods of the present invention are described in this article using specific examples. The description of the above embodiments is only used to help understand the method and core idea of ​​the present invention. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.

Claims

1. A method for encoding and decoding immediate operands, It is characterized in that include: The processor design information in the processor design result file is represented in the form of a structure and a bidirectional linked list, and stored in the core.so file; The core.so file is used to provide a series of interfaces; Use the dynamic link library loading function provided by the operating system to load the core.so file, and load and restore the static core.so file on the disk into the memory; Use C / C++ code to call the interface provided by the loaded core.so file; And restore the immediate operands in the processor design result to the memory through the structure and the doubly linked list; Traverse the immediate type operands one by one and generate the corresponding encoding function; Integrate all encoding functions into the LLVM compiler source code and rebuild the LLVM compiler; Leverage the rebuilt LLVM compiler to encode immediate values.

2. The method for encoding and decoding an immediate operand according to claim 1, It is characterized in that The dynamic link library loading function is a dynamic link library loading function dlopen provided by the Linux operating system.

3. The method for encoding and decoding an immediate operand according to claim 1, It is characterized in that The immediate operand type in the processor design result is restored to the memory through the structure and the bidirectional linked list, specifically including: Create a structure instance according to each immediate type operand, and use the member variables of the structure instance to store the operand information; Adding the structure instance to a doubly linked list; the doubly linked list is used to store operands; each node on the doubly linked list is a structure instance and corresponds to an operand; Associate the doubly linked list with the structure instance; and complete it through the C language assignment statement farm->operands=operandsList.

4. The method for encoding and decoding an immediate operand according to claim 3, It is characterized in that The step of traversing the immediate type operands one by one and generating corresponding encoding functions specifically includes: Using the initialized farm variable as the entry point, obtain the list of all immediate operands in the current processor through farm->operands, and traverse and process them one by one; Access each operation in each immediate operand list in reverse order, and generate C++ code for the inverse operation corresponding to the operation; Concatenate the C++ codes corresponding to all operations in each immediate type operand to obtain the corresponding encoding function.

5. A coding and decoding system for immediate operands, It is characterized in that include: The core.so file determination module is used to represent the processor design information in the processor design result file in the form of a structure and a bidirectional linked list, and store it in the core.so file; the core.so file is used to provide a series of interfaces; The loading module is used to load the core.so file using the dynamic link library loading function provided by the operating system, and load and restore the static core.so file on the disk into the memory; The calling module is used to use C / C++ code to call the interface provided by the loaded core.so file; And restore the immediate operands in the processor design result to the memory through the structure and the doubly linked list; An encoding function generation module, used for traversing immediate type operands one by one and generating corresponding encoding functions; LLVM compiler reconstruction module, which is used to integrate all encoding functions into the LLVM compiler source code and rebuild the LLVM compiler; Encoding module for encoding immediate values ​​using the rebuilt LLVM compiler.

6. A storage medium having computer program instructions stored thereon, It is characterized in that When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 4 is implemented.