WebAssembly instruction set optimization conversion method and device and limited equipment

By converting the operation code and operand of virtual machine instructions in the WebAssembly instruction set, the problem of large function bytecode space and low operation efficiency caused by LEB data encoding is solved, and more efficient instruction set optimization is achieved.

CN119088394APending Publication Date: 2024-12-06BEIJING TONGFANG MICROELECTRONICS

Patent Information

Application Number
CN202411202535.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-29
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

The virtual machine instruction operands of the WebAssembly instruction set on resource-constrained devices are encoded using LEB data, resulting in large space occupancy and low operational efficiency.

Method used

Search the original instructions from the function bytecode of WebAssembly binary intermediate file code segment, and convert the opcode and/or operands to obtain a new instruction without operands or operands that are unsigned 1 byte or 2 bytes. New instructions reduce bytecode operands and improve operational efficiency.

Benefits of technology

Through instruction conversion, the space occupation of function bytecode is reduced, the parsing efficiency is improved at runtime, and the inefficiency problem caused by over-encoding of LEB operands is solved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119088394A_ABST
    Figure CN119088394A_ABST
Patent Text Reader

Abstract

The invention discloses a WebAssembly instruction set optimization conversion method, a WebAssembly instruction set optimization conversion device and limited equipment. The method comprises the following steps of: retrieving a first original instruction from a code segment function byte code of a WebAssembly binary intermediate file; the method comprises the following steps: for any first original instruction, converting an operation code and / or an operand of the first original instruction to obtain a new instruction corresponding to the first original instruction, and converting the operation code and / or the operand to obtain a new instruction without the operand or a new instruction with the operand being unsigned 1-byte or unsigned 2-byte data, therefore, the problems of large function byte code space and low LEB operand analysis efficiency during operation are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of instruction optimization, and in particular to a WebAssembly instruction set optimization conversion method, device and restricted device. Background Art

[0002] The WebAssembly instruction set is a virtual machine instruction set architecture. Based on this virtual machine instruction set architecture, programs written in languages ​​such as C / C++ can be compiled and run safely and quickly on the Web platform.

[0003] When WebAssembly technology is applied to the operating system of resource-constrained devices, the virtual machine instruction operands use LEB data encoding, which will cause the function bytecode to occupy a large space and have low operating efficiency. Summary of the invention

[0004] The present invention provides a WebAssembly instruction set optimization conversion method, device and restricted device to solve the problem that the virtual machine instruction operands are encoded with LEB data, resulting in a large space occupied by function bytecode and low operating efficiency.

[0005] According to one aspect of the present invention, a WebAssembly instruction set optimization conversion method is provided, the method comprising:

[0006] Retrieving a first original instruction from the WebAssembly binary intermediate file code segment function bytecode;

[0007] For any first original instruction, the operation code and / or the operand of the first original instruction are converted to obtain a new instruction corresponding to the first original instruction.

[0008] According to another aspect of the present invention, a WebAssembly instruction set optimization conversion device is provided, the device comprising:

[0009] A retrieval module, configured to retrieve a first original instruction from a WebAssembly binary intermediate file;

[0010] The conversion module is used for converting the operation code and / or operand of any first original instruction to obtain a new instruction corresponding to the first original instruction.

[0011] According to another aspect of the present invention, a resource-constrained device is provided, wherein an embedded operating system is installed on the resource-constrained device, a runtime environment is executed in the embedded operating system, and the resource-constrained device comprises:

[0012] at least one processor; and

[0013] a memory communicatively connected to at least one processor; wherein,

[0014] The memory stores a computer program executable by at least one processor, and the computer program is executed by at least one processor so that the at least one processor can execute the instruction set converted by the WebAssembly instruction set optimization method provided in any embodiment of the present invention.

[0015] According to another aspect of the present invention, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the WebAssembly instruction set optimization conversion method provided by any embodiment of the present invention is implemented.

[0016] The technical solution of the embodiment of the present invention retrieves the first original instruction from the function bytecode of the WebAssembly binary intermediate file code segment; for any first original instruction, the operation code and / or the operand of the first original instruction are converted to obtain a new instruction corresponding to the first original instruction, and after converting the operation code and / or the operand, a new instruction without an operand is obtained, or a new instruction whose operand is an unsigned 1-byte or unsigned 2-byte data, thereby solving the problem of large function bytecode space and low efficiency of parsing LEB operands at runtime.

[0017] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. 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 creative work.

[0019] Figure 1 A flowchart of a WebAssembly instruction set optimization conversion method is provided for the first embodiment of the present invention;

[0020] Figure 2 A flowchart of a WebAssembly instruction set optimization conversion method is provided for Embodiment 2 of the present invention;

[0021] Figure 3 A flowchart of a WebAssembly instruction set optimization conversion method is provided for Embodiment 3 of the present invention;

[0022] Figure 4A flowchart of a WebAssembly instruction set optimization conversion method is provided for Embodiment 4 of the present invention;

[0023] Figure 5 A schematic diagram of the structure of a WebAssembly instruction set optimization conversion device provided in Embodiment 5 of the present invention;

[0024] Figure 6 This is a schematic diagram of the structure of a restricted device provided in Embodiment 6 of the present invention. DETAILED DESCRIPTION

[0025] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings 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 should fall within the scope of protection of the present invention.

[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0027] Embodiment 1

[0028] Figure 1 A flowchart of a WebAssembly instruction set optimization conversion method is provided for the first embodiment of the present invention. This embodiment is applicable to WebAssembly instruction set optimization conversion. The method can be executed by a WebAssembly instruction set optimization conversion device, which can be implemented in the form of hardware and / or software. Figure 1 As shown, the method includes:

[0029] Step 101: Retrieve a first original instruction from a WebAssembly binary intermediate file code segment function bytecode.

[0030] In this step, the program is compiled to obtain a binary intermediate file, in which the code segment of the binary intermediate file contains function bytecodes, and the function bytecodes are composed of a virtual machine instruction stream defined by the WebAssembly instruction set.

[0031] Each bytecode corresponds to a virtual machine instruction, also called an operation code, through which the operand information corresponding to the operation code can be determined.

[0032] When searching, each time a bytecode is retrieved, it can be determined whether the operation code corresponding to the bytecode is a pre-set virtual machine instruction that needs to be optimized. If not, it is necessary to continue searching backward to find the next bytecode.

[0033] When retrieving function bytecodes, it is necessary to parse the operands in all bytecodes of the function byte by byte in order to find the next bytecode.

[0034] If the operation code corresponding to the retrieved bytecode is a pre-set virtual machine instruction that needs to be optimized, the instruction corresponding to the bytecode is determined as the first original instruction retrieved in this step.

[0035] In this step, the instruction type of the determined first original instruction belongs to the set optimized instruction type, and the first original instruction contains LEB-encoded operands, and the LEB-encoded operands are over-encoded LEB operands or non-over-encoded LEB operands.

[0036] It should be noted that if an LEB-encoded operand in an instruction uses more bytes to represent than actually required, the LEB-encoded operand is determined to be an over-encoded LEB operand.

[0037] In a specific example, the LEB-encoded operand in an instruction can be represented by a corresponding unsigned number using 1 byte, but the operand is represented using 5-byte LEB encoding. This LEB-encoded operand is an over-encoded LEB operand.

[0038] Step 102: For any first original instruction, convert the operation code and / or operand of the first original instruction to obtain a new instruction corresponding to the first original instruction.

[0039] For the first original instruction, the opcode or operand or the opcode and operand are converted mainly to reduce the function bytecode space. Compared with the first original instruction, the new instruction after conversion has less bytecode operand space and higher operating efficiency.

[0040] An instruction set usually includes multiple categories of instructions, and the instructions in each category usually have commonalities. Therefore, a corresponding conversion strategy is set for each category of instructions to achieve the conversion of the first original instruction. The specific conversion process can be referred to in subsequent embodiments and will not be repeated here.

[0041] It should be noted that after the above conversion, in order to ensure the original running logic of the code, after obtaining the new instructions corresponding to each first original instruction in the binary intermediate file, the jump instructions in the binary intermediate file are obtained, and the jump addresses of the jump instructions are updated.

[0042] For example, before instruction optimization, there is a jump instruction in the binary intermediate file whose operand is 20, indicating that it can jump to the A instruction position with a relative address of 20 bytes behind it for execution. After the above instruction optimization, the number of byte codes between the jump instruction and the A instruction is reduced to 10 bytes. At this time, the operand of the jump instruction needs to be modified to 10 so as not to change the original code running logic.

[0043] In this embodiment, the first original instruction is retrieved from the function bytecode of the WebAssembly binary intermediate file code segment; for any first original instruction, the opcode and / or operand of the first original instruction is converted to obtain a new instruction corresponding to the first original instruction, and after converting the opcode and / or operand, a new instruction without an operand is obtained, or a new instruction whose operand is an unsigned 1-byte or unsigned 2-byte data, thereby solving the problem of large function bytecode space and low efficiency of parsing LEB operands at runtime.

[0044] Embodiment 2

[0045] Figure 2 This is a flowchart of a WebAssembly instruction set optimization conversion method provided in Embodiment 2 of the present invention. This embodiment mainly relates to the conversion process when the first original instruction is a memory instruction. Figure 2 As shown, the method includes:

[0046] Step 201: If the first original instruction is a memory instruction, determine whether the value of the operand identifying the address offset in the first original instruction exceeds a first preset threshold; if not, determine one byte as the target byte number; otherwise, determine two bytes as the target byte number.

[0047] In this step, the memory instructions mainly include memory read instructions and memory write instructions. Both the memory read instructions and the memory write instructions include two operands, wherein the first operand is the memory alignment mode, and the second operand is the memory address offset in the LEB encoding format.

[0048] In a specific example, the mnemonics and operation codes of the current memory read instruction and memory write instruction before conversion can refer to the following Table 1.

[0049] Table 1

[0050]

[0051] When a bytecode of a function is retrieved, if the corresponding instruction is a memory read instruction or a memory write instruction, the corresponding memory address offset operand in the LEB encoding format is parsed. Usually, the size of the operand value is positively correlated with the required number of bytes. Therefore, a first preset threshold can be set to determine whether the size of the operand exceeds the first preset threshold. If it does not exceed, it can be represented by one byte. If it exceeds, it needs to be represented by two bytes.

[0052] In this step, it should be noted that the memory address offset is not greater than the global variable memory address limit value 0xFFFE.

[0053] In this step, it is determined whether the value of the operand identifying the address offset in the first original instruction exceeds the first preset threshold. In a specific example, the first preset threshold may be 0xFF in hexadecimal.

[0054] If the value of the operand identifying the address offset exceeds 0xFF, the target byte number is 2, that is, two bytes; if it does not exceed 0xFF, the target byte number is 1, that is, one byte.

[0055] Step 202: Convert the operand identifying the address offset in the first original instruction to an unsigned number of the target byte number of equal value, and obtain a new instruction corresponding to the memory instruction and containing only the unsigned number of the target byte number as an operand.

[0056] After the target number of bytes is determined in the above step, this step directly converts the operand identifying the address offset into an unsigned number of the same value as the target number of bytes, and determines the converted unsigned number as the only operand in the memory instruction.

[0057] That is to say, this step can clear the operands of the first original instruction, and then use the unsigned number as its only operand to obtain a new instruction. Therefore, the operands in the new instruction obtained in this step only contain unsigned numbers of the target number of bytes.

[0058] In addition, in this embodiment, a new operation code and mnemonic may be allocated to a new instruction with a target byte number of 1, and details may be referred to the following Table 2.

[0059] Table 2

[0060]

[0061]

[0062] It should be noted that after the above conversion, in order to ensure the original running logic of the code, after obtaining the new instructions corresponding to each first original instruction in the binary intermediate file, the jump instructions in the binary intermediate file are obtained, and the jump addresses of the jump instructions are updated.

[0063] For example, before instruction optimization, there is a jump instruction in the binary intermediate file whose operand is 20, indicating that it can jump to the A instruction position with a relative address of 20 bytes behind it for execution. After the above instruction optimization, the number of byte codes between the jump instruction and the A instruction is reduced to 10 bytes. At this time, the operand of the jump instruction needs to be modified to 10 so as not to change the original code running logic.

[0064] After the above conversion, the new instruction obtained has a simpler bytecode operand structure than the first original instruction, and occupies fewer bytes. After converting the LEB format operand instruction to the equivalent 1-byte unsigned or 2-byte unsigned format new instruction, the program is directly read and used according to the instruction operand data format when executing, and no longer reads and parses the LEB encoded operands in the instruction one by one, thereby improving the code running speed.

[0065] Embodiment 3

[0066] Figure 3 This is a flowchart of a WebAssembly instruction set optimization conversion method provided in Embodiment 3 of the present invention. This embodiment mainly relates to the conversion process when the first original instruction is a numerical instruction. Figure 3 As shown, the method includes:

[0067] Step 301: If the first original instruction is a constant push instruction in a numerical instruction, and the operand of the constant push instruction is an over-encoded LEB operand, determine that the constant push instruction is an address constant push instruction.

[0068] Numerical instructions provide basic operations on numerical values ​​of a specified type. In this embodiment, constant push instructions of constant instructions in numerical instructions are mainly converted. Generally, if the operand of the constant push instruction is an over-encoded LEB operand, this type of constant push instruction is an address constant push instruction. The mnemonic of the first original instruction in this step is i32.const, and the corresponding opcode is 0x41. The i32.const instruction contains an LEB-encoded operand.

[0069] It should be noted that the address identified by the address constant value corresponding to the over-encoded LEB is a memory address or a function pointer address.

[0070] Step 302, determine whether the address constant value corresponding to the over-encoded LEB operand in the address constant push instruction exceeds a first preset threshold, if not, determine one byte as the target byte number, otherwise, determine two bytes as the target byte number.

[0071] In this step, the first thing to note is that the address constant value is not greater than the global variable memory address limit value 0xFFFE, or is not greater than the sum of the number of external functions referenced by the module and the number of internal functions defined by the module 0x0FFF.

[0072] Similarly, the size of the operand value is positively correlated with the number of bytes required. Therefore, a first preset threshold can be set to determine whether the size of the operand exceeds the first preset threshold. If it does not exceed, it can be represented by one byte. If it exceeds, it needs to be represented by two bytes.

[0073] In a specific example, the first preset threshold may be hexadecimal 0xFF. If the value of the operand exceeds 0xFF, the target byte number is 2, i.e., two bytes. If it does not exceed 0xFF, the target byte number is 1, i.e., one byte.

[0074] Step 303: convert the address constant value corresponding to the over-encoded LEB operand in the address constant push instruction into an unsigned number of the target byte number of equal value, and obtain a new instruction corresponding to the address constant push instruction with the unsigned number of the target byte number as the operand.

[0075] After the target number of bytes is determined in the aforementioned step 303, the address constant value is converted into an unsigned number of the equivalent target number of bytes, the operand in the address constant push instruction is replaced with the unsigned number, and the operation code is replaced according to the target number of bytes of the operand, thereby obtaining a new instruction corresponding to the address constant push instruction with the unsigned number of the target number of bytes as the operand.

[0076] In a specific example, a new instruction after a first original instruction is converted may be shown in Table 3 below.

[0077] Table 3

[0078]

[0079] Step 304: If the first original instruction is a constant push instruction in a numerical instruction, and the operand of the constant push instruction is a non-over-encoded LEB operand, and the constant value represented by the non-over-encoded LEB operand is 0x07 to 0xFFFE, determine whether the constant value represented by the non-over-encoded LEB operand in the constant push instruction exceeds a first preset threshold value. If not, determine one byte as the target byte number; otherwise, determine two bytes as the target byte number.

[0080] This step is mainly for the conversion of non-over-encoded constant push instructions. The constant value represented by the non-over-encoded LEB operand is usually between 0x07 and 0xFFFE (including edge values).

[0081] Then, it can be determined whether the constant value exceeds a first preset threshold value, which is the same as the above step and will not be described in detail here. The determination process can refer to the relevant steps and will not be described in detail here.

[0082] Step 305: Convert the non-over-encoded LEB operand in the constant push instruction to an unsigned number of the target byte number of equal value, and obtain a new instruction corresponding to the constant push instruction and taking the unsigned number of the target byte number as an operand.

[0083] After determining the target byte number, this step converts the non-over-encoded LEB operand into an unsigned number of the equivalent target byte number, and replaces the operand in the constant push instruction with the unsigned number, thereby obtaining a new instruction corresponding to the constant push instruction with the unsigned number of the target byte number as the operand.

[0084] In a specific example, a new instruction after a first original instruction is converted may be shown in Table 4 below.

[0085] Table 4

[0086]

[0087] Step 306: If the first original instruction is a constant push instruction in a numerical instruction, the operand of the constant push instruction is a non-over-encoded LEB operand, and the constant value represented by the non-over-encoded LEB operand is a preset specific value, then the first original instruction is converted into a new instruction without an operand.

[0088] In this step, the conversion is mainly performed on constant push instructions whose constant values ​​are preset specific values, and the preset specific values ​​are 0, 1, 2, 3, 4, 5, 6, 0xFFFF and -1.

[0089] This step has certain particularity, and the operands need to be directly eliminated, and the new instruction obtained does not contain operands.

[0090] In a specific example, the new instructions obtained in this step can be shown in Table 5 below.

[0091] Table 5

[0092]

[0093] It should be noted that after the above conversion, in order to ensure the original running logic of the code, after obtaining the new instructions corresponding to each first original instruction in the binary intermediate file, the jump instructions in the binary intermediate file are obtained, and the jump addresses of the jump instructions are updated.

[0094] For example, before instruction optimization, there is a jump instruction in the binary intermediate file whose operand is 20, indicating that it can jump to the A instruction position with a relative address of 20 bytes behind it for execution. After the above instruction optimization, the number of byte codes between the jump instruction and the A instruction is reduced to 10 bytes. At this time, the operand of the jump instruction needs to be modified to 10 so as not to change the original code running logic.

[0095] Embodiment 4

[0096] Figure 4 This is a flowchart of a WebAssembly instruction set optimization conversion method provided in Embodiment 4 of the present invention. This embodiment mainly relates to the conversion process when the first original instruction is a function call instruction. Figure 4 As shown, the method includes:

[0097] Step 401: If the first original instruction is a call instruction in a function call instruction, determine the target number of bytes according to the LEB operand of the call instruction and the total number of external functions.

[0098] In this step, the mnemonic of the first original instruction is call, the corresponding operation code is 0x10, and the call instruction contains an operand in LEB format over-encoded.

[0099] For the call instruction, this step needs to use the total number of external functions in the binary intermediate file module to determine the target number of bytes. Specifically, the corresponding value of the LEB operand of the call instruction should not be greater than the sum of the external functions that can be referenced by a single module and the defined internal functions 0xFFF. The LEB data represents the function index. The external function starts from 0, and the internal function starts from the total number of external functions. If the function index represented by the LEB data is less than the total number of external functions, it is a call to an external function. Otherwise, it is a call to an internal function.

[0100] Therefore, in this step, if the LEB operand is less than the total number of external functions and is not greater than the first preset threshold, one byte is determined as the target byte number, and call_outer_u8 is determined as the mnemonic of the new instruction.

[0101] If the LEB operand is greater than or equal to the total number of external functions and the difference between the LEB operand and the total number of external functions is not greater than a first preset threshold, one byte is determined as the target byte number, and call_inner_u8 is determined as the mnemonic of the new instruction.

[0102] If the LEB operand is less than the total number of external functions and greater than the first preset threshold, or the LEB operand is greater than the total number of external functions and the difference between the LEB operand and the total number of external functions is greater than the first preset threshold, two bytes are determined as the target number of bytes, and call_u16 is determined as the mnemonic of the new instruction.

[0103] Step 402: Convert the LEB operand to an unsigned number of the same target byte number, and obtain a new instruction corresponding to the call instruction.

[0104] After the target byte number and mnemonic are determined in the above steps, this step converts the corresponding operands into unsigned numbers of equal target byte number, converts the opcode into the opcode corresponding to the above determined new instruction mnemonic, and obtains the new instruction corresponding to the call instruction. The operand in the obtained new instruction is the unsigned number obtained by the above conversion.

[0105] In a specific example, the obtained new instruction can be illustrated as shown in Table 6 below.

[0106] Table 6

[0107]

[0108] Step 403: If the first original instruction is a call_indirect instruction in a function call instruction, convert the call_indirect instruction into a new instruction without an operand.

[0109] In this step, the mnemonic of the first original instruction is call_indirect, and the corresponding opcode is 0x11. The first operand of the call_indirect instruction is LEB over-encoded format data, which represents the index of the function to be called in the binary intermediate file table segment, and the second operand represents the number of parameters passed when calling the function.

[0110] In this step, the operand in the instruction can be directly deleted. In a specific example, the mnemonic and operation code of the corresponding new instruction can remain unchanged, and the operand is none.

[0111] It should be noted that after the above conversion, in order to ensure the original running logic of the code, after obtaining the new instructions corresponding to each first original instruction in the binary intermediate file, the jump instructions in the binary intermediate file are obtained, and the jump addresses of the jump instructions are updated.

[0112] For example, before instruction optimization, there is a jump instruction in the binary intermediate file whose operand is 20, indicating that it can jump to the A instruction position with a relative address of 20 bytes behind it for execution. After the above instruction optimization, the number of byte codes between the jump instruction and the A instruction is reduced to 10 bytes. At this time, the operand of the jump instruction needs to be modified to 10 so as not to change the original code running logic.

[0113] Embodiment 5

[0114] Figure 5 A schematic diagram of the structure of a WebAssembly instruction set optimization conversion device provided in Embodiment 5 of the present invention. Figure 5 As shown, the device comprises:

[0115] A retrieval module 501 is used to retrieve a first original instruction from a WebAssembly binary intermediate file code segment function bytecode;

[0116] The conversion module 502 is used for converting the operation code and / or operand of any first original instruction to obtain a new instruction corresponding to the first original instruction.

[0117] In this embodiment, the first original instruction is retrieved from the function bytecode of the WebAssembly binary intermediate file code segment; for any first original instruction, the opcode and / or operand of the first original instruction is converted to obtain a new instruction corresponding to the first original instruction, and after converting the opcode and / or operand, a new instruction without an operand is obtained, or a new instruction whose operand is an unsigned 1-byte or unsigned 2-byte data, thereby solving the problem of large function bytecode space and low efficiency of parsing LEB operands at runtime.

[0118] Embodiment 6

[0119] Figure 6 A schematic diagram of the structure of a restricted device provided for Embodiment 6 of the present invention. The restricted device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The restricted device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or claimed herein.

[0120] like Figure 6As shown, an embedded operating system is installed on the restricted device, a runtime environment is executed in the embedded operating system, and the restricted device runs the instruction set optimized by the above-mentioned embodiment. The restricted device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a non-volatile memory (NVM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the non-volatile memory (NVM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the restricted device 10 can also be stored. The processor 11, the NVM 12 and the RAM 13 are connected to each other through a bus 14. The input / output (I / O) interface 15 is also connected to the bus 14.

[0121] A number of components in the restricted device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the restricted device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0122] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the function bytecode after the instruction set optimization conversion described above.

[0123] In some embodiments, the WebAssembly instruction set optimization conversion method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the restricted device 10 via the NVM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, the function bytecode after the instruction set optimization conversion described above may be executed. Alternatively, in other embodiments, the processor 11 may be configured to execute the function bytecode after the instruction set optimization conversion described above by any other appropriate means (e.g., by means of firmware).

[0124] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0125] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0126] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0127] To provide interaction with a user, the systems and techniques described herein may be implemented on a constrained device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the constrained device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0128] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0129] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0130] Embodiment 7

[0131] This embodiment provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the WebAssembly instruction set optimization conversion method provided in any embodiment of the present application.

[0132] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0133] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A WebAssembly instruction set optimization conversion method, It is characterized in that The method comprises: Retrieving a first original instruction from the WebAssembly binary intermediate file code segment function bytecode; the instruction type of the first original instruction belongs to the set optimization instruction type; For any of the first original instructions, the operation code and / or the operand of the first original instruction are converted to obtain a new instruction corresponding to the first original instruction.

2. The method according to claim 1, It is characterized in that For any of the first original instructions, converting the operation code and / or the operand of the first original instruction to obtain a new instruction corresponding to the first original instruction includes: If the first original instruction is a memory instruction, the operand identifying the address offset in the first original instruction is converted into an unsigned number of an equal target byte number, and a new instruction corresponding to the memory instruction and containing only the unsigned number of the target byte number as an operand is obtained.

3. The method according to claim 2, It is characterized in that Before converting the operand identifying the address offset in the first original instruction into an unsigned number of the same value as the target number of bytes, the method further includes: It is determined whether the value of the operand identifying the address offset in the first original instruction exceeds a first preset threshold value. If not, one byte is determined as the target byte number; otherwise, two bytes are determined as the target byte number.

4. The method according to claim 1, It is characterized in that For any of the first original instructions, converting the operation code and / or the operand of the first original instruction to obtain a new instruction corresponding to the first original instruction includes: If the first original instruction is a constant push instruction in a numerical instruction, and the operand of the constant push instruction is an over-encoded LEB operand, determining that the constant push instruction is an address constant push instruction; The address constant value corresponding to the over-encoded LEB operand in the address constant push instruction is converted into an unsigned number of the target byte number with the same value, and a new instruction corresponding to the address constant push instruction is obtained, which takes the unsigned number of the target byte number as an operand.

5. The method according to claim 4, It is characterized in that The method further comprises: If the first original instruction is a constant push instruction in a numerical instruction, and the operand of the constant push instruction is a non-over-encoded LEB operand, and the constant value represented by the non-over-encoded LEB operand is 0x07 to 0xFFFE, then the non-over-encoded LEB operand in the constant push instruction is converted into an unsigned number of an equivalent target byte number, and a new instruction corresponding to the constant push instruction is obtained, with the unsigned number of the target byte number as an operand.

6. The method according to claim 4, It is characterized in that The method further comprises: If the first original instruction is a constant push instruction in a numerical instruction, the operand of the constant push instruction is a non-over-encoded LEB operand, and the constant value represented by the non-over-encoded LEB operand is a preset specific value, then the first original instruction is converted into a new instruction without an operand.

7. The method according to claim 1, It is characterized in that For any of the first original instructions, converting the operation code and / or the operand of the first original instruction to obtain a new instruction corresponding to the first original instruction includes: If the first original instruction is a call instruction in a function call instruction, determining the target number of bytes according to the LEB operand of the call instruction and the total number of external functions; The LEB operand is converted into an unsigned number of the target byte number of equal value, and a new instruction corresponding to the call instruction is obtained.

8. The method according to claim 1, It is characterized in that For any of the first original instructions, converting the operation code and / or the operand of the first original instruction to obtain a new instruction corresponding to the first original instruction includes: If the first original instruction is a call_indirect instruction in a function call instruction, the call_indirect instruction is converted into a new instruction without an operand.

9. A WebAssembly instruction set optimization conversion device, It is characterized in that The device comprises: A retrieval module, configured to retrieve a first original instruction from a function bytecode of a code segment of a WebAssembly binary intermediate file; the instruction type of the first original instruction belongs to a set optimized instruction type; The conversion module is used to convert the operation code and / or operand of any of the first original instructions to obtain a new instruction corresponding to the first original instruction.

10. A restricted device, It is characterized in that The restricted device has an embedded operating system installed thereon, a runtime environment is executed in the embedded operating system, and the restricted device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to use the instruction set converted by the WebAssembly instruction set optimization method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Method and device for optimizing instructions and operands thereof based on composite instructions

    CN116466995A

  • WebAssembly instruction set optimization method and device

    CN117130722A

  • Object-oriented instruction set for resource-constrained devices

    CN1359491A

  • Optimised code generation

    CN1672133A

  • Micro-operating system bytecode reduced instruction set and resource restriction apparatus

    WO2022134538A1

Cited By

  • WebAssembly instruction set optimization conversion method and device and limited equipment

    CN121501284A