Instruction processing method, terminal device, and computer-readable storage medium
By merging and updating the storage location index information of target data instructions and arithmetic instructions in the WebAssembly code, the problem of excessive register space occupation was solved, and storage space optimization was achieved.
Patent Information
- Application Number
- CN202211085662.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-06
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2042-09-06
AI Technical Summary
When WebAssembly code transitions from a stack-based to a register-based architecture, the instruction bloat increases, leading to a greater use of register space.
By determining the storage location index information of the target data instructions and arithmetic instructions in the instruction set, the target data instructions are merged and the target arithmetic instructions are updated, thereby reducing storage space.
It reduces the storage space of the instruction set, alleviates the storage burden on registers, and does not affect the execution efficiency of instructions.
Smart Images

Figure CN115878183B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to an instruction processing method, a terminal device and a computer readable storage medium. BACKGROUND
[0002] In WebAssembly code (also known as wasm code), the runtime will first convert the stack-based wasm code into register-based wasm code, and then perform the entire code execution. When the structure of the wasm code is converted from stack-based to register-based, some index information is added, so that each instruction in the entire code instruction set is longer than the original instruction, which will cause the bytecode of the entire wasm to expand and become larger, and further cause the space occupation of the register. Therefore, it is necessary to reduce the storage burden of the register. SUMMARY
[0003] The instruction processing method provided by the present application can update and merge the target data instruction and the target operation instruction according to the index information of the target data instruction in the instruction set, thereby reducing the storage burden of the register.
[0004] In a first aspect, the present application provides an instruction processing method, which comprises:
[0005] determining a storage space corresponding to a preset instruction set, the storage space comprising a plurality of storage locations, each storage location corresponding to index information, and the storage location being used to store running data corresponding to each instruction in the instruction set;
[0006] determining a target data instruction in the instruction set and determining first target index information of a storage location where first running data corresponding to the target data instruction is located;
[0007] determining a target operation instruction in the instruction set and determining second target index information of a storage location where second running data corresponding to the target operation instruction is located, the second running data corresponding to the target operation instruction representing an operation result of operating the first running data corresponding to the target data instruction;
[0008] deleting the target data instruction, and updating the target operation instruction according to the first target index information and the second target index information.
[0009] In some embodiments of the present application, the determination of the storage space corresponding to the preset instruction set comprises:
[0010] obtaining an instruction input parameter of the instruction set;
[0011] determining a first space division parameter according to the instruction input parameter;
[0012] acquiring a quantity of target instructions in the instruction set;
[0013] determining a spatial second division parameter according to the quantity of target instructions;
[0014] dividing an initial storage space according to the spatial first division parameter and the spatial second division parameter to obtain a storage space corresponding to the instruction set.
[0015] In some embodiments of the present application, dividing the initial storage space according to the spatial first division parameter and the spatial second division parameter to obtain the storage space corresponding to the instruction set comprises:
[0016] determining first index information and second index information in the initial storage space;
[0017] dividing the initial storage space according to the first index information and the second index information to obtain a first storage space and an initial second storage space;
[0018] dividing the initial second storage space according to the spatial first division parameter and the spatial second division parameter to obtain a second storage space, a third storage space and a fourth storage space, the first storage space and the second storage space being used to store running data corresponding to the target data instruction, the third storage space being used to store running data corresponding to a target operation instruction, and the fourth storage space being used to store temporary running data.
[0019] In some embodiments of the present application, determining the first target index information of the storage location of the first running data corresponding to the target data instruction comprises:
[0020] determining an instruction type of the target data instruction;
[0021] determining the first target index information of the storage location of the first running data corresponding to the target data instruction according to the instruction type.
[0022] In some embodiments of the present application, determining the first target index information of the storage location of the first running data corresponding to the target data instruction according to the instruction type comprises:
[0023] if the target data instruction is of a constant type, determining an occupation condition of the first storage space of the storage space, and determining the first target index information of the storage location of the first running data corresponding to the target data instruction according to the occupation condition of the first storage space;
[0024] If the target data instruction is of the call type, determining index information in each storage location in the second storage space of the storage space that matches an immediate number of the target data instruction, and determining the matching index information as first target index information;
[0025] If the target data instruction is of the assignment type, determining first target index information that matches the target data instruction according to an immediate number of the target data instruction and an execution order of instructions in the instruction set.
[0026] In some embodiments of the present application, the determining, if the target data instruction is of the assignment type, first target index information that matches the target data instruction according to an immediate number of the target data instruction and an execution order of instructions in the instruction set, comprises:
[0027] According to the execution order, determining a previous instruction adjacent to the target data instruction;
[0028] If the previous instruction is a target operation instruction and the previous instruction writes an operation result of an operation into a third storage space of the storage space, determining index information in each storage location in the second storage space of the storage space that matches an immediate number of the target data instruction, and determining the matching index information as first target index information.
[0029] In some embodiments of the present application, the determining second target index information of a storage location where second running data corresponding to the target operation instruction is located comprises:
[0030] Determining an occupancy of the third storage space of the storage space, and determining the second target index information of the storage location where the second running data corresponding to the target operation instruction is located according to the occupancy of the third storage space.
[0031] In some embodiments of the present application, before the deleting the target data instruction and updating the target operation instruction according to the first target index information and the second target index information, the method further comprises:
[0032] According to an execution rule of the instruction set, putting the first target index information and the second target index information into an index stack for in-stack and out-stack calculation by the index stack, to obtain in-stacked and out-stacked index information;
[0033] The updating the target operation instruction according to the first target index information and the second target index information comprises:
[0034] According to the in-stacked and out-stacked index information, updating the target operation instruction.
[0035] In a second aspect, the embodiments of the present application further provide an instruction processing apparatus, the apparatus comprising:
[0036] a first determining module configured to determine a storage space corresponding to a preset instruction set, the storage space comprising a plurality of storage locations, each storage location corresponding to index information, and each storage location being configured to store running data corresponding to each instruction in the instruction set;
[0037] a second determining module configured to determine a target data instruction in the instruction set and determine first target index information of a storage location where first running data corresponding to the target data instruction is located;
[0038] a third determining module configured to determine a target operation instruction in the instruction set and determine second target index information of a storage location where second running data corresponding to the target operation instruction is located, the second running data corresponding to the target operation instruction representing an operation result of performing an operation on the first running data corresponding to the target data instruction;
[0039] an updating module configured to delete the target data instruction and update the target operation instruction according to the first target index information and the second target index information.
[0040] In some embodiments of the present application, the first determining module is specifically configured to:
[0041] obtain an instruction input parameter of the instruction set;
[0042] determine a first space division parameter according to the instruction input parameter;
[0043] obtain a number of target instructions in the instruction set;
[0044] determine a second space division parameter according to the number of target instructions;
[0045] divide an initial storage space according to the first space division parameter and the second space division parameter to obtain the storage space corresponding to the instruction set.
[0046] In some embodiments of the present application, the first determining module is specifically further configured to:
[0047] determine first index information and second index information in the initial storage space;
[0048] divide the initial storage space according to the first index information and the second index information to obtain a first storage space and an initial second storage space;
[0049] According to the first space division parameter and the second space division parameter, the initial second storage space is divided to obtain a second storage space, a third storage space and a fourth storage space, the first storage space and the second storage space are used to store running data corresponding to the target data instruction, the third storage space is used to store running data corresponding to a target operation instruction, and the fourth storage space is used to store temporary running data.
[0050] In some embodiments of the present application, the second determining module is specifically configured to:
[0051] determine an instruction type of the target data instruction;
[0052] According to the instruction type, determine first target index information of a storage location of the first running data corresponding to the target data instruction.
[0053] In some embodiments of the present application, the second determining module is specifically further configured to:
[0054] If the target data instruction is of a constant type, determine an occupation condition of a first storage space of the storage space, and according to the occupation condition of the first storage space, determine the first target index information of the storage location of the first running data corresponding to the target data instruction;
[0055] If the target data instruction is of a call type, determine index information in each storage location of a second storage space of the storage space that matches an immediate number of the target data instruction, and determine the matching index information as the first target index information;
[0056] If the target data instruction is of an assignment type, according to the immediate number of the target data instruction and an execution order of instructions in the instruction set, determine the first target index information matched by the target data instruction.
[0057] In some embodiments of the present application, the second determining module is specifically further configured to:
[0058] According to the execution order, determine a previous instruction adjacent to the target data instruction;
[0059] If the previous instruction is a target operation instruction, and the previous instruction writes an operation result of an operation into a third storage space of the storage space, determine index information in each storage location of a second storage space of the storage space that matches an immediate number of the target data instruction, and determine the matching index information as the first target index information.
[0060] In some embodiments of the present application, the updating module is specifically further configured to:
[0061] The first target index information and the second target index information are put into the index stack according to an execution rule of the instruction set by a preset index stack to perform in-stack and out-stack calculation, and index information after in-stack and out-stack is obtained.
[0062] The updating the target operation instruction according to the first target index information and the second target index information comprises:
[0063] The target operation instruction is updated according to the index information after in-stack and out-stack.
[0064] In a third aspect, an embodiment of the present application further provides a terminal device, which comprises a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor executes the computer program to implement steps in the instruction processing method.
[0065] In a fourth aspect, an embodiment of the present application further provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement steps in the instruction processing method.
[0066] The instruction processing method provided by the present application determines a target data instruction in an instruction set and first target index information of a first running data corresponding to the target data instruction, determines a target operation instruction in the instruction set and second target index information of a second running data corresponding to the target operation instruction, and updates the target operation instruction according to the first target index information and the second target index information, so that the target operation instruction carries index information of the running data corresponding to the target data instruction, in which case, the target data instruction can be deleted, the instruction set can be reduced, the storage burden of the register is reduced, and meanwhile, the operation of the instruction is not affected. BRIEF DESCRIPTION OF DRAWINGS
[0067] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort.
[0068] Figure 1 is a scene schematic diagram of the instruction processing system provided in the embodiments of the present application;
[0069] Figure 2 is a flowchart schematic diagram of one embodiment of the instruction processing method in the embodiments of the present application;
[0070] Figure 3is a functional module schematic diagram of the instruction processing device in the embodiment of the present application.
[0071] Figure 4 is a structural schematic diagram of the terminal device in the embodiment of the present application. DETAILED DESCRIPTION
[0072] The technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person skilled in the art without creative work fall within the scope of protection of the present application.
[0073] In the description of the present application, it should be understood that the terms "first", "second" are used only for the purpose of description, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first", "second" can explicitly or implicitly include one or more of the features. In the description of the present application, the meaning of "multiple" is two or more, unless otherwise specifically limited.
[0074] In the present application, the word "exemplary" is used to mean "serving as an example, instance, or illustration." Any implementation described as "exemplary" in the present application is not necessarily to be construed as preferred or advantageous over other implementations. The following description is presented to enable any person skilled in the art to make and use the present application. In the following description, for the purpose of explanation, details are set forth. It is apparent to those skilled in the art that the present application can be practiced without using these specific details. In other instances, well-known structures and processes are not described in detail in order to avoid obscuring the description of the present application. Therefore, the present application is not intended to be limited to the embodiments shown, but is to be accorded the widest scope consistent with the principles and features disclosed herein.
[0075] The present application provides an instruction processing method, a terminal device and a computer readable storage medium, which are described in detail below.
[0076] Please refer to Figure 1 , Figure 1 is a scene schematic diagram of the instruction processing system provided by the embodiment of the present application. The instruction processing system can include a terminal device 100 and a storage device 200, and the storage device 200 can transmit data to the terminal device 100. As shown in Figure 1 , the terminal device 100 in the present application can acquire the instruction set stored in the storage device 200 to execute the instruction processing method in the present application.
[0077] In the embodiments of the present application, the terminal device 100 can be, but is not limited to, a desktop computer, a laptop computer, a network server, a personal digital assistant (PDA), a tablet computer, a wireless terminal device, an embedded device, and the like.
[0078] In the embodiments of the present application, the terminal device 100 and the storage device 200 can communicate through any communication mode, including but not limited to mobile communication based on the 3rd Generation Partnership Project (3GPP), Long Term Evolution (LTE), Worldwide Interoperability for Microwave Access (WiMAX), or computer network communication based on the TCP / IP Protocol Suite (TCP / IP), User Datagram Protocol (UDP), and the like.
[0079] It should be noted that, Figure 1 The scenario diagram of the instruction processing system shown is only an example, and the instruction processing system and scenario described in the embodiments of the present application are used to more clearly illustrate the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application. It can be known by those skilled in the art that, as the instruction processing system evolves and new business scenarios appear, the technical solutions provided by the embodiments of the present application are also applicable to similar technical problems.
[0080] As Figure 2 shown, Figure 2 is a flowchart of an embodiment of the instruction processing method in the embodiments of the present application. The instruction processing method can include the following steps 201-204.
[0081] 201, determine a storage space corresponding to a preset instruction set, the storage space including a plurality of storage locations, each storage location corresponding to index information, and the storage location being used to store running data corresponding to each instruction in the instruction set.
[0082] The instruction set mentioned in the embodiments of the present application can refer to the instruction set of the wasm code, and the wasm code is a binary instruction format based on a stack virtual machine. Wasm is designed for a portable target, and can be used for compiling high-level languages such as C / C+ / RUST, so that client and server applications can be deployed on the Web. Wasm has multiple implementations, including browsers and standalone systems, and can be used for applications such as video and audio codecs, graphics and 3D, multimedia and games, cryptographic calculations, or portable language implementations.
[0083] In addition, the storage space mentioned in the embodiments of the present application can be any type of storage device. The storage space can include a plurality of storage locations, and the index information corresponding to a storage location. The correspondence between the index information and the storage location can be set when the storage space is established. Since the purposes of the programs are different, the instructions in the instruction set will also vary, and therefore the size of the storage space required by the instruction set will also vary. Therefore, to determine the storage space corresponding to the instruction set, the size of the storage space used can be determined according to the size of the space occupied by the instruction set itself. For example: assume that the storage space includes 100 storage locations, and each storage location corresponds to an index information, for example, location 1 corresponds to index 1, location 2 corresponds to index 2, and so on. If according to the size of the current instruction set, only 50 storage locations are used, then the 50 storage locations in the storage space including 100 storage locations can be provided for the instruction set.
[0084] 202, determining a target data instruction in the instruction set and determining first target index information of a storage location where first running data corresponding to the target data instruction is located.
[0085] Since the purpose of an instruction set is to calculate various parameters, it is well known that data used for calculation needs to be obtained first before calculation is performed according to the corresponding set calculation rule. Therefore, the instruction set can at least include data acquisition instructions and related operation instructions, so the target data instruction in the embodiments of the present application can at least refer to data acquisition instructions, such as data call instructions and the like. The data call instruction is not used for calculation, but only for data acquisition or movement and the like. In order to facilitate understanding, for example, in 1+1=2, "1" can correspond to the data called from the database in the target data instruction, and how to obtain 1 is obtained through the target data instruction. Of course, 1+1=2 does not represent the instruction set referred to in the embodiments of the present application.
[0086] Therefore, after the storage space corresponding to the instruction set is acquired, the called data or acquired data corresponding to the target data instruction can be placed in an arbitrary position in the storage space. For example, assuming that there are two target data instructions in the instruction set, "local.get0" and "local.get1", the "local.get0" instruction means that the data at the param1 position is placed in the stack to prepare a function call, and therefore the data at the param1 position can be placed in an arbitrary storage position in the storage space, such as position 1. The "local.get1" means that the data at the param2 position is placed in the stack to prepare a function call, and therefore the data at the param2 position can be placed in an arbitrary storage position in the storage space, such as position 2, and the data at the param1 position and the param2 position is the first running data. At this time, the first target index information of the "local.get0" instruction is 1, and the first target index information of the "local.get1" is 2. Therefore, the first target index information of the target data instruction is determined based on the position in the storage space.
[0087] 203. determining a target operation instruction in the instruction set and determining second target index information of a second running data position of the target operation instruction corresponding to the target operation instruction, the second running data corresponding to the target operation instruction representing an operation result of operating the first running data corresponding to the target data instruction.
[0088] In the embodiment of the present application, the target operation instruction can be an instruction that actually operates in the instruction set. For ease of understanding, the example of 1+1=2 in the above embodiment can still be used for understanding, where "+" can correspond to the target operation instruction in the embodiment of the present application. For example, in the embodiment of the present application, the target operation instruction can be i32.add, and if combined with the target data instruction in step 202, it can be assumed that the instruction set is:
[0089] {local.get0
[0090] local.get1
[0091] i32.add}
[0092] Firstly, the meaning of i32.add needs to be explained, which represents adding the top two data in the stack and putting the result into the stack. Therefore, according to the description of step 202, if the first target index information of local.get0 is 1 and the first target index information of local.get1 is 2, the first running data X stored in position 1 and the first running data Y stored in position 2 are added to obtain X+Y, which is the running result of the i32.add instruction. At this time, the result X+Y can be placed in a storage position other than position 1 and position 2, such as position 3. The position 3 can be the second target index information of the i32.add instruction, that is, the second target index information of the target operation instruction.
[0093] 204. deleting the target data instruction and updating the target operation instruction according to the first target index information and the second target index information.
[0094] According to the above steps, since the first running data corresponding to the target data instruction has been called and stored, the target data instruction can be deleted. Here, deletion can mean direct deletion.
[0095] In addition, in order to facilitate understanding, the case in the above steps can still be taken, the first target index information corresponding to local.get0 is 1, the first target index information corresponding to local.get1 is 2, and the second target index information corresponding to i32.add is 3. At this time, when updating the i32.add instruction according to the first target index information and the second target index information, it can be updated to: [3] i32.add [] [1, 2], where 3 represents the meaning of placing the operation result of i32.add in position 3 of the storage space; [1, 2] represents the meaning of obtaining the first running data stored in position 1 and position 2 of the storage space.
[0096] As can be seen, the initial instruction set includes 3 instructions, and the updated instruction has only 1 instruction, greatly simplifying the instruction, so that the storage space occupied by the instruction is smaller.
[0097] It should be noted that in actual situations, the wasm instruction set will not include only 3 instructions. The instruction set provided in the embodiments of the present application is only for the convenience of understanding and description, and does not constitute a limitation on the wasm instruction set.
[0098] In order to better implement the present application, in an embodiment of the present application, the storage space corresponding to the predetermined instruction set is determined, including:
[0099] An instruction input parameter of the instruction set is acquired; a first space division parameter is determined according to the instruction input parameter; a quantity of target instructions in the instruction set is acquired; a second space division parameter is determined according to the quantity of the target instructions; and the initial storage space is divided according to the first space division parameter and the second space division parameter, so that a storage space corresponding to the instruction set is obtained.
[0100] According to the above embodiment, when the data corresponding to each instruction in the instruction set is stored in the storage space, the storage can be performed in any manner. In order to more conveniently acquire the related running data, the storage space can be divided, and the running data is specified to be stored, so that the subsequent data searching is facilitated.
[0101] In the embodiment, since the instruction set can be regarded as a function, the instruction input parameter can be understood as a function input parameter, wherein the function input parameter is a concept commonly used in the field, and specific details are not described herein. In order to facilitate understanding, if the instruction set is as follows at this time:
[0102] {local.get0
[0103] local.get1
[0104] i32.add
[0105] i32.const 1
[0106] i32.add}
[0107] First, it needs to be noted that the meaning of the "i32. const 1" instruction as a constant instruction is to write the constant 1 into the stack, and the "i32. add" instruction is to write the operation result into the stack. Therefore, at this time, "i32. const 1" and "i32. add" can be regarded as the same type of instruction, so "i32. const 1" and "i32. add" can be regarded as target instructions. And "local. get0" and "local. get1" calling instructions, so two values are called into the stack, at least 2 parameters are written, so the first storage space division parameter can be 2. In the instruction set, the target instructions include one "i32. const 1" and two "i32. add", so the number of target instructions is 3. Therefore, the first space division parameter 2 and the second space division parameter 3 can be obtained. If the storage space includes 5 storage locations, for example: storage location 0, storage location 1, storage location 2, storage location 3, storage location 4, if the first space division parameter is 2 and the second space division parameter is 3, then the storage space can be divided into [0, 2), [2, 3) and [3, 4), so the space division is completed. At this time, the running data of the local instruction can be stored in the [0, 2) interval, the operation data of the i32. add is stored in the [2, 3) interval, and the constant data of the i32. const 1 is stored in the [3, 4) interval, which facilitates data management.
[0108] In order to better implement the embodiments of the present application, in an embodiment of the present application, the initial storage space is divided according to the first space division parameter and the second space division parameter to obtain the storage space corresponding to the instruction set, comprising:
[0109] determining the first index information and the second index information in the initial storage space; dividing the initial storage space according to the first index information and the second index information to obtain a first storage space and an initial second storage space; dividing the initial second storage space according to the first space division parameter and the second space division parameter to obtain a second storage space, a third storage space and a fourth storage space, the first storage space and the second storage space are used to store the running data corresponding to the target data instruction, the third storage space is used to store the running data corresponding to the target operation instruction, and the fourth storage space is used to store temporary running data.
[0110] According to the above embodiment, the storage space is only applicable to positive numbers as index information. In this embodiment, negative numbers can also be used as information. At this time, the index information of each storage location in the storage space can correspond to [negative infinity, -1] and [0, positive infinity], wherein [negative infinity, -1] corresponds to the first index information, and [0, positive infinity] corresponds to the second index information.
[0111] Therefore, according to the space division parameters obtained in the above embodiment, the index space corresponding to the second index information can be divided. The division manner can refer to the above embodiment, and details are not described here.
[0112] When negative numbers are introduced as the first storage space, the first storage space is used to store constant values of constant instructions, the second storage space is used to store calling data of local instructions, and the third storage space is used to store operation results of operation instructions. It should be noted that when the third storage space is used to store operation results of operation instructions, the operation results can be stored according to the occupation of the third storage space, for example, if the first position in the third storage space is not occupied, the operation result is placed in the first position of the third storage space, if the first position of the third storage space is occupied, the second position is placed, and so on. In addition, the instruction set can also include other types of instructions, and the fourth storage space is used to store temporary data generated by other instructions.
[0113] In order to better implement the present application, in one embodiment of the present application, the first target index information of the storage location where the first running data corresponding to the target data instruction is located is determined, comprising:
[0114] Determining the instruction type of the target data instruction; according to the instruction type, determining the first target index information of the storage location where the first running data corresponding to the target data instruction is located.
[0115] According to the above embodiment, the index information of the running data corresponding to the target data instruction can be determined in a random manner. Therefore, in order to facilitate the subsequent simplification and merging of instructions, the storage space corresponding to the instruction can be determined according to the instruction type, that is, the index information.
[0116] According to the above embodiment, the local instruction can include the local.get instruction, however, the local instruction can also include the local.set instruction, which means assignment. If the calling instruction is of the local.get type, the data corresponding to the local.get instruction can be placed in the first storage space mentioned in the above embodiment. If the instruction is of the local.set type, the result of the assignment can be placed in a position in the fourth storage space, i.e., the first target index information corresponding to the first running data of the target data instruction is determined according to different instruction types.
[0117] In order to better implement the embodiments of the present application, in an embodiment of the present application, the determining of the first target index information of the storage position of the first running data corresponding to the target data instruction according to the instruction type includes:
[0118] If the target data instruction is of the constant type, the occupation of the first storage space of the storage space is determined, and the first target index information of the storage position of the first running data corresponding to the target data instruction is determined according to the occupation of the first storage space. If the target data instruction is of the calling type, the index information matching the immediate number of the target data instruction in the index information of each storage position in the second storage space of the storage space is determined, and the matching index information is determined as the first target index information. If the target data instruction is of the assignment type, the first target index information matching the target data instruction is determined according to the immediate number of the target data instruction and the execution order of the instructions in the instruction set.
[0119] In the above embodiment, when the space division parameters are determined, the constant instruction and the operation instruction can be regarded as a type of instruction, and according to the above embodiment, the constant instruction is to write a constant into the stack, so it can also be understood as calling a constant in a database, therefore, at this time, the constant instruction and the local instruction can also be regarded as target data instructions.
[0120] In addition, according to the above embodiment, the constant value of the constant instruction is written into the first storage space. At this time, if the storage position corresponding to the -1 index information of the first storage space is not occupied, the constant is written into the storage position corresponding to the -1 index information, if the storage position corresponding to the -1 index information is occupied, the constant is written into the storage position corresponding to the -2 index information, and so on.
[0121] If the local.get instruction is called, the index information is determined according to the immediate number of the local.get. If the local.get instruction is local.get 0, the data corresponding to the local.get 0 is stored in the storage location with the index information 0 of the second storage space, that is, the second storage space.
[0122] If the local.set instruction is called, the index information of the local.set instruction is determined according to the previous instruction of the local.set instruction.
[0123] If the target data instruction is of the assignment type, the first target index information matched with the target data instruction is determined according to the immediate number of the target data instruction and the execution order of the instructions in the instruction set.
[0124] According to the execution order, the previous instruction adjacent to the target data instruction is determined. If the previous instruction is a target operation instruction and the operation result of the previous instruction is written into the third storage space of the storage space, the index information matched with the immediate number of the target data instruction in the index information of each storage location in the second storage space of the storage space is determined as the first target index information.
[0125] The execution order of the instruction set is determined after the instruction set is generated. Therefore, if the instruction set is:
[0126] {local.get 0
[0127] local.get 1
[0128] i32.add
[0129] i32.const 1
[0130] i32.add
[0131] local.set 0}
[0132] The execution order of the instruction set is executed from top to bottom. At this time, the previous instruction of the local.set instruction is i32.add, and the operation result of i32.add needs to be written into the third storage space. At this time, the immediate number of the local.set is 0, and the first target index information of the local.set is 0.
[0133] According to the description of the above embodiment, the constant instruction is only regarded as the same type as the operation instruction when determining the division space parameter, and in other cases, the constant instruction is regarded as the same type of instruction as the local instruction, i.e., the target data instruction. Therefore, according to the merging manner of the above embodiment and the determination manner of the index information, the final update result of the instruction set can be determined as shown in Table 1:
[0134]
[0135] Table 1
[0136] From the above embodiment, when the local instruction and the constant instruction, i.e., the target data instruction, generate corresponding index information, the target data instruction can be directly deleted, i.e., corresponding to the third row in Table 1, the positions corresponding to the target data instruction are all blank, at this time, the deletion of the instruction has been completed. And, according to the scheme of the above embodiment, the first target index information of the storage space corresponding to local.get 0 and local.get 1 is 0 and 1 of the first storage space, so the next instruction of local.get 1, i32.add, is to add the data corresponding to position 0 and position 1, and put the addition result into position 2 of the third storage space, i.e., corresponding to the first merging instruction [2] i32.add [][0, 1]. At this time, since the first storage space is completely empty, the constant instruction puts the constant 1 into the storage position of the index information -1 of the first storage space; the next second i32.add is to add the data of the storage position 2 and the constant data of the position -1, at this time, the data of the first i32.add has been calculated, at this time, the index information of the third storage space is 2. The position appears empty, so the second i32.add generates the instruction [2] i32.add [][2, -1], i.e., the operation result of the second i32.add is still written into position 2 of the third storage space. Since the last instruction local.set is an assignment instruction, the operation result of the second i32.add needs to be assigned to the position of the index information 0, so [2] i32.add [][2, -1] becomes [0] i32.add [][2, -1], i.e., the result of position 2 is assigned to the data of position 0, i.e., the data of position 0 is overwritten. The index information technology can be calculated by setting a corresponding calculation function, which is not limited here.
[0137] In addition, it should be noted that in the embodiments of the present application, the conversion manner of the stack instruction into the register instruction does not belong to the scope involved by the present application, and therefore is not described in detail.
[0138] Therefore, the instruction processing method provided in the embodiments of the present application can convert the original 6-stack instructions into 6 register instructions, but the same function can be realized by 2 instructions after instruction merging, so that the storage space occupation is greatly reduced.
[0139] In order to better realize the embodiments of the present application, in one embodiment of the present application, the second target index information of the storage location of the second running data corresponding to the target operation instruction is determined, including:
[0140] The occupation of the third storage space of the storage space is determined, and the second target index information of the storage location of the second running data corresponding to the target operation instruction is determined according to the occupation of the third storage space.
[0141] In the above embodiments, the operation result of the target operation instruction is stored in the third storage space, which can be stored in a random manner, and in the present embodiment, the second target index information matched with the target operation instruction can be determined according to the occupation of the third storage space.
[0142] For example, when the first position of the third storage space is not occupied, the operation result is stored in the first position; if the second position of the third storage space is occupied, the operation result is stored in the second position of the third storage space, and so on.
[0143] In order to better realize the embodiments of the present application, in one embodiment of the present application, before the target data instruction is deleted and the target operation instruction is updated according to the first target index information and the second target index information, the method further comprises:
[0144] The first target index information and the second target index information are put into the index stack according to the execution rule of the instruction set for in-stack and out-stack calculation to obtain in-stack and out-stack index information; and the target operation instruction is updated according to the first target index information and the second target index information, including updating the target operation instruction according to the in-stack and out-stack index information.
[0145] According to the above embodiments, the corresponding calculation function can be set for calculation, and in order to save the setting of the calculation function, the embodiments themselves provide a way of calculating the index information of each instruction by setting an index stack. As shown in Table 2:
[0146]
[0147] Table 2
[0148] According to Table 2, the index stack can record the results of each time the index information is stacked in and stacked out, and thus, the target operation instruction can be directly updated and merged according to the calculation results of each time of the index stack.
[0149] The instruction processing method provided in the present application determines a target data instruction in an instruction set and first target index information of a storage location of first running data corresponding to the target data instruction, determines a target operation instruction in the instruction set and second target index information of a storage location of second running data corresponding to the target operation instruction, and updates the target operation instruction according to the first target index information and the second target index information, so that the target operation instruction carries index information of the running data corresponding to the target data instruction. In this case, the target data instruction is deleted, the instruction set is reduced, the storage burden of the register is reduced, and meanwhile, the operation of the instruction is not affected.
[0150] In order to better implement the instruction processing method in the embodiments of the present application, on the basis of the instruction processing method, the embodiments of the present application further provide an instruction processing device, as shown in Figure 3 The device 300 includes:
[0151] A first determining module 301 is configured to determine a storage space corresponding to a preset instruction set, the storage space includes a plurality of storage locations, each storage location corresponds to index information, and the storage location is used to store running data corresponding to each instruction in the instruction set.
[0152] A second determining module 302 is configured to determine a target data instruction in the instruction set and first target index information of a storage location of first running data corresponding to the target data instruction.
[0153] A third determining module 303 is configured to determine a target operation instruction in the instruction set and second target index information of a storage location of second running data corresponding to the target operation instruction, and the second running data corresponding to the target operation instruction represents an operation result of the first running data corresponding to the target data instruction.
[0154] An updating module 304 is configured to delete the target data instruction and update the target operation instruction according to the first target index information and the second target index information.
[0155] The instruction processing method provided in the application, through the first determining module 301, determines the storage space of the instruction set for storing running data, and then through the second determining module 302 and the third determining module 303, the corresponding index information of different instructions in the instruction set in the storage space is determined, and finally through the updating module 304, the target data instruction is deleted, and the index information of the target data instruction is updated to the instruction that does not need to be deleted, so as to reduce the instruction set and reduce the storage burden of the register.
[0156] In some embodiments of the application, the first determining module 301 is specifically used for:
[0157] Obtaining the instruction input parameter of the instruction set;
[0158] According to the instruction input parameter, the first space division parameter is determined;
[0159] Obtaining the number of target instructions in the instruction set;
[0160] According to the number of target instructions, the second space division parameter is determined;
[0161] According to the first space division parameter and the second space division parameter, the initial storage space is divided to obtain the storage space corresponding to the instruction set.
[0162] In some embodiments of the application, the first determining module 301 is specifically used for:
[0163] Determine the first index information and the second index information in the initial storage space;
[0164] According to the first index information and the second index information, the initial storage space is divided to obtain the first storage space and the initial second storage space;
[0165] According to the first space division parameter and the second space division parameter, the initial second storage space is divided to obtain the second storage space, the third storage space and the fourth storage space, the first storage space and the second storage space are used to store the running data corresponding to the target data instruction, the third storage space is used to store the running data corresponding to the target operation instruction, and the fourth storage space is used to store the temporary running data.
[0166] In some embodiments of the application, the second determining module 302 is specifically used for:
[0167] Determine the instruction type of the target data instruction;
[0168] According to the instruction type, the first target index information of the storage location of the first running data corresponding to the target data instruction is determined.
[0169] In some embodiments of the present application, the second determining module 302 is further configured to:
[0170] if the target data instruction is of a constant type, determining an occupation condition of a first storage space of the storage space, and determining first target index information of a storage location where first running data corresponding to the target data instruction is located according to the occupation condition of the first storage space;
[0171] if the target data instruction is of a call type, determining index information matched with an immediate number of the target data instruction from index information of each storage location in a second storage space of the storage space, and determining the matched index information as the first target index information;
[0172] if the target data instruction is of an assignment type, determining the first target index information matched with the target data instruction according to the immediate number of the target data instruction and an execution order of instructions in the instruction set.
[0173] In some embodiments of the present application, the second determining module 302 is further configured to:
[0174] determining a previous instruction adjacent to the target data instruction according to the execution order;
[0175] if the previous instruction is a target operation instruction and the previous instruction writes an operation result of an operation into a third storage space of the storage space, determining index information matched with the immediate number of the target data instruction from index information of each storage location in a second storage space of the storage space, and determining the matched index information as the first target index information.
[0176] In some embodiments of the present application, the third determining module 303 is further configured to:
[0177] determining an occupation condition of the third storage space of the storage space, and determining second target index information of a storage location where second running data corresponding to the target operation instruction is located according to the occupation condition of the third storage space.
[0178] In some embodiments of the present application, the updating module 304 is further configured to:
[0179] putting the first target index information and the second target index information into an index stack according to an execution rule of the instruction set for in-stack and out-stack calculation, to obtain in-stacked and out-stacked index information;
[0180] the updating the target operation instruction according to the first target index information and the second target index information comprises:
[0181] According to the index information after the stack and the index information after the de-stack, the target operation instruction is updated.
[0182] The embodiment of the application further provides a terminal device, which comprises a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor executes the computer program to implement the steps in the instruction processing method of any of the embodiments of the application. The terminal device integrates any of the instruction processing methods provided by the embodiments of the application, as shown in the following Figure 4
[0183] The terminal device can comprise a processor 401 with one or more than one processing core, a memory 402 with one or more than one computer readable storage medium, a power supply 403, an input unit 404, and the like. Those skilled in the art can understand that the terminal device structure shown in the embodiment of the application does not constitute a limitation on the terminal device, and can comprise more or fewer components than those shown in the figure, or some components can be combined, or different components can be arranged. Among them: Figure 4
[0184] The processor 401 is the control center of the terminal device, and connects each part of the terminal device through various interfaces and lines. The processor 401 executes the software programs and / or modules stored in the memory 402 and the data stored in the memory 402, processes the data, and performs the various functions of the terminal device, thereby overall monitoring the terminal device. Optionally, the processor 401 can comprise one or more than one processing core. The processor 401 can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or the like. The general-purpose processor can be a microprocessor or any conventional processor, or the like. Preferably, the processor 401 can integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, the user interface, and the application programs, and the modem processor mainly processes wireless communication. It can be understood that the modem processor can also not be integrated into the processor 401.
[0185] The memory 402 can be used to store software programs and modules, and the processor 401 executes various function applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, application programs required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; and the data storage area can store data created according to the use of the terminal device, etc. In addition, the memory 402 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state memory device. Accordingly, the memory 402 can also include a memory controller to provide the processor 401 with access to the memory 402.
[0186] The terminal device also includes a power supply 403 for supplying power to various components. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, so as to realize functions such as management of charging, discharging, and power consumption management through the power management system. The power supply 403 can also include one or more than one direct current or alternating current power supply, a recharging system, a power supply fault detection circuit, a power supply converter or inverter, a power supply state indicator, and the like.
[0187] The terminal device can also include an input unit 404, which can be used to receive input digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function controls.
[0188] Although not shown, the terminal device can also include a display unit, etc., which will not be described here. Specifically, in the present embodiment, the processor 401 in the terminal device loads executable files corresponding to the processes of one or more than one application program into the memory 402 according to the following instructions, and runs the application programs stored in the memory 402 by the processor 401, so as to realize various functions, such as:
[0189] determining a storage space corresponding to a preset instruction set, the storage space including a plurality of storage locations, each storage location corresponding to index information, and the storage locations being used to store running data corresponding to each instruction in the instruction set;
[0190] determining a target data instruction in the instruction set and determining first target index information of a storage location where first running data corresponding to the target data instruction is located;
[0191] determining a target data instruction in the instruction set and determining first target index information of a storage location where first running data corresponding to the target data instruction is located, the first running data corresponding to the target data instruction representing the first running data corresponding to the target data instruction;
[0192] deleting the target data instruction and updating the target operation instruction according to the first target index information and the second target index information.
[0193] Those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructions, or by related hardware controlled by the instructions, which can be stored in a computer readable storage medium and loaded and executed by a processor.
[0194] To this end, the embodiments of the present application provide a computer readable storage medium, which can include a read only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc. A computer program is stored on the storage medium, and the computer program is loaded by a processor to execute the steps in any of the instruction processing methods provided by the embodiments of the present application. For example, the computer program loaded by the processor can execute the following steps:
[0195] determining a storage space corresponding to a preset instruction set, the storage space including a plurality of storage locations, each storage location corresponding to index information, and the storage locations being used to store running data corresponding to each instruction in the instruction set;
[0196] determining a target data instruction in the instruction set and determining first target index information of a storage location where first running data corresponding to the target data instruction is located, the first running data corresponding to the target data instruction representing the first running data corresponding to the target data instruction;
[0197] determining a target operation instruction in the instruction set and determining second target index information of a storage location where second running data corresponding to the target operation instruction is located, the second running data corresponding to the target operation instruction representing an operation result of operating the first running data corresponding to the target data instruction;
[0198] deleting the target data instruction and updating the target operation instruction according to the first target index information and the second target index information.
[0199] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the detailed description of other embodiments above, which will not be repeated here.
[0200] In practice, the above various units or structures can be implemented as independent entities, or combined as the same or several entities, and the specific implementation of the above various units or structures can refer to the method embodiments in the foregoing, which will not be repeated here.
[0201] The specific implementation of the above various operations can refer to the foregoing embodiments, which will not be repeated here.
[0202] The above has introduced in detail the instruction processing method and device provided by the embodiments of the present application, the principle and implementation mode of the present application have been described in this paper, and the above embodiment is only used to help understand the method and its core idea of the present application; at the same time, for those skilled in the art, according to the idea of the present application, the specific implementation mode and application range will be changed, and the above description should not be understood as the limitation of the present application.
Claims
1. An instruction processing method, characterized by, The method comprises: determining a storage space corresponding to a preset instruction set, the storage space comprising a plurality of storage locations, each storage location corresponding to index information, the storage locations being used to store running data corresponding to each instruction in the instruction set; determining a target data instruction in the instruction set and determining first target index information of a storage location where first running data corresponding to the target data instruction is located; determining a target operation instruction in the instruction set and determining second target index information of a storage location where second running data corresponding to the target operation instruction is located, the second running data corresponding to the target operation instruction representing an operation result of operating the first running data corresponding to the target data instruction; deleting the target data instruction and updating the target operation instruction according to the first target index information and the second target index information.
2. The instruction processing method of claim 1, wherein, The determining of the storage space corresponding to the preset instruction set comprises: obtaining instruction parameters of the instruction set; determining a first space division parameter according to the instruction parameters; obtaining a number of target instructions in the instruction set; determining a second space division parameter according to the number of target instructions; dividing an initial storage space according to the first space division parameter and the second space division parameter to obtain the storage space corresponding to the instruction set.
3. The instruction processing method of claim 2, wherein, The dividing of the initial storage space according to the first space division parameter and the second space division parameter to obtain the storage space corresponding to the instruction set comprises: determining first index information and second index information in the initial storage space; dividing the initial storage space according to the first index information and the second index information to obtain a first storage space and an initial second storage space; dividing the initial second storage space according to the first space division parameter and the second space division parameter to obtain a second storage space, a third storage space and a fourth storage space, the first storage space and the second storage space being used to store running data corresponding to the target data instruction, the third storage space being used to store running data corresponding to the target operation instruction, and the fourth storage space being used to store temporary running data.
4. The instruction processing method of claim 1, wherein, The determining of the first target index information of the storage location where the first running data corresponding to the target data instruction is located comprises: determining an instruction type of the target data instruction; determining the first target index information of the storage location where the first running data corresponding to the target data instruction is located according to the instruction type.
5. The instruction processing method of claim 4, wherein, The determining of the first target index information of the storage location where the first running data corresponding to the target data instruction is located according to the instruction type comprises: if the target data instruction is of a constant type, determining an occupancy of the first storage space of the storage space, and determining the first target index information of the storage location where the first running data corresponding to the target data instruction is located according to the occupancy of the first storage space; If the target data instruction is of the call type, determining index information in the index information of each storage location in the second storage space of the storage space that matches an immediate number of the target data instruction, and determining the matching index information as first target index information; If the target data instruction is of the assignment type, determining first target index information matched by the target data instruction according to an immediate number of the target data instruction and an execution order of instructions in the instruction set.
6. The instruction processing method of claim 5, wherein, The determining, if the target data instruction is of the assignment type, first target index information matched by the target data instruction according to an immediate number of the target data instruction and an execution order of instructions in the instruction set, includes: determining a previous instruction adjacent to the target data instruction according to the execution order; If the previous instruction is a target operation instruction and the previous instruction writes an operation result of an operation into a third storage space of the storage space, determining index information in the index information of each storage location in the second storage space of the storage space that matches an immediate number of the target data instruction, and determining the matching index information as first target index information.
7. The instruction processing method of claim 1, wherein, The determining of the second target index information of the storage location where the second running data corresponding to the target operation instruction is located includes: determining an occupation condition of the third storage space of the storage space, and determining the second target index information of the storage location where the second running data corresponding to the target operation instruction is located according to the occupation condition of the third storage space.
8. The instruction processing method of claim 1, wherein, The method further includes, before the deleting of the target data instruction and the updating of the target operation instruction according to the first target index information and the second target index information: putting the first target index information and the second target index information into an index stack according to an execution rule of the instruction set to perform in-stack and out-stack calculation, and obtaining in-stack and out-stack index information; The updating of the target operation instruction according to the first target index information and the second target index information includes: updating the target operation instruction according to the in-stack and out-stack index information.
9. A terminal device, comprising: The terminal device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor executes the computer program to implement steps in the instruction processing method of any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement steps in the instruction processing method of any one of claims 1 to 8.
Citation Information
Patent Citations
Instruction translation device and method, instruction processing device and processor
CN102541611A
Method and device for executing functional module in virtual machine
WO2021179697A1