Multi-branch selection statement processing method and device for shenwei JavaScript engine, electronic equipment and storage medium

CN117608583BActive Publication Date: 2026-10-09WUXI ADVANCED TECH RES INST
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311561104.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-21
Publication Date
2026-10-09
Estimated Expiration
2043-11-21

AI Technical Summary

Technical Problem

[0004]针对上述问题,本发明提出多分支选择语句处理方法一种面向申威JavaScript引擎的多分支选择语句处理方法、装置、电子设备及存储介质,能够解决跳转表的内存空间占用大以及访存开销大的技术问题

Benefits of technology

[0043] This invention optimizes the compilation method of multi-branch selection statements in JavaScript engines by replacing memory access instructions with non-memory access instructions, thereby generating a jump table for multi-branch selection statements. This jump table stores unconditional jump instructions, avoiding the problem of inefficiency caused by excessive memory access, improving the overall performance of the program, and reducing the storage space occupied by the jump table.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117608583B_ABST
    Figure CN117608583B_ABST
Patent Text Reader

Abstract

The application discloses a multi-branch selection statement processing method and device for a Shenwei JavaScript engine, electronic equipment and a storage medium, and the method comprises the following steps: compiling a multi-branch selection statement to generate a corresponding jump table, wherein each table entry of the jump table stores an unconditional branch instruction corresponding to each branch selection statement; obtaining a current PC value; finding out a corresponding index in the jump table according to the obtained argument, calculating an offset in the jump table based on the found index and the length of the table entry; obtaining the number of instructions between the current PC value and the jump table, multiplying the number of instructions by the length of the instruction to calculate an offset outside the jump table; adding the PC value, the offset in the jump table and the offset outside the jump table to obtain a jump address; and executing the corresponding unconditional branch instruction in the jump table according to the jump address to jump to a program corresponding to the branch statement. The application can reduce the storage space used by the jump table and improve the overall performance of the program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of just-in-time compilation technology, specifically relating to a method, apparatus, electronic device, and storage medium for processing multi-branch selection statements in Shenwei JavaScript. Background Technology

[0002] For common multi-branch selection scenarios in JavaScript programs, JavaScript engines use a jump table data structure to handle multi-branch selection statements. The specific implementation of the jump table varies across different processor platforms. For example, the Shenwei platform JavaScript engine first stores the starting address of the branch processing segment to be jumped to in the jump table during the code generation stage, and then loads the target address and jumps to achieve correct program processing.

[0003] The existing jump table handling method in the Shenwei platform's JavaScript engine retrieves entries in the jump table (the starting address of the actual branch processing segment) through memory access instructions, and then jumps to the corresponding branch statement segment. This implementation generates jump table code that consumes memory, and memory access operations involving frequent jump address retrieval incur significant overhead. In JavaScript applications using numerous multi-branch selection statements, this jump table handling method negatively impacts overall program performance. Summary of the Invention

[0004] To address the aforementioned problems, this invention proposes a multi-branch selection statement processing method, apparatus, electronic device, and storage medium for the Shenwei JavaScript engine, which can solve the technical problems of large memory space occupation and high memory access overhead of jump tables.

[0005] To achieve the above-mentioned technical objectives and effects, the present invention is implemented through the following technical solution:

[0006] Firstly, this invention provides a method for processing multi-branch selection statements, specifically for the Shenwei JavaScript engine, comprising:

[0007] The multi-branch selection statement is compiled to generate a corresponding jump table. Each entry in the jump table stores the unconditional jump instruction corresponding to each branch selection statement.

[0008] Get the current PC value;

[0009] Based on the obtained actual parameters, find the corresponding index in the jump table, and calculate the offset in the jump table based on the found index and the length of the table entry;

[0010] Obtain the number of instructions between the current PC value and the jump table, multiply the number of instructions by the length of the instruction, and calculate the offset outside the jump table;

[0011] Adding the PC value, the offset within the jump table and the offset outside the jump table to obtain a jump address;

[0012] According to the jump address, execute the corresponding unconditional branch instruction in the jump table, and jump to the program corresponding to the branch statement.

[0013] Optionally, before the step of compiling the multi-branch selection statement and generating the corresponding jump table, the method further comprises:

[0014] Obtain the number of branch judgment conditions and case values in the multi-branch selection statement;

[0015] Judge whether to use a jump table according to the number of branch judgment conditions and case values of the multi-branch selection statement.

[0016] Optionally, the step of judging whether to use a jump table according to the number of branch judgment conditions and case values of the multi-branch selection statement specifically comprises the following steps:

[0017] If the number of branch judgment conditions n<N, where N is a preset number threshold, the jump table is not used;

[0018] If the number of branch judgment conditions n≥N and the case values are arranged in sequence, the jump table is used;

[0019] If the number of branch judgment conditions n≥N, the case values are out of order, and (max case -min case )≤kn, where kn is a preset multiple threshold, the jump table is used, max case represents the maximum case value, min case represents the minimum case value;

[0020] If the number of branch judgment conditions n≥N, the case values are out of order, and (max case -min case )>kn, the jump table is not used.

[0021] Optionally, if the jump table is not used, the multi-branch selection statements are executed in sequence.

[0022] Optionally, the unconditional branch instruction is 4 bytes.

[0023] In a second aspect, the present invention provides a multi-branch selection statement processing apparatus for a Shenwei JavaScript engine, comprising:

[0024] a compilation module, configured to compile a multi-branch selection statement and generate a corresponding jump table, wherein each entry of the jump table stores an unconditional branch instruction corresponding to each branch selection statement;

[0025] acquiring a current PC value;

[0026] an in-jump-table offset calculation module, configured to find a corresponding index in the jump table according to an obtained actual argument, and calculate an in-jump-table offset based on the found index and an entry length;

[0027] an out-jump-table offset calculation module, configured to obtain the number of instructions between the current PC value and the jump table, and multiply the number of instructions by the instruction length to calculate an out-jump-table offset;

[0028] an addition module, configured to add the PC value, the in-jump-table offset and the out-jump-table offset to obtain a jump address;

[0029] an execution module, configured to execute a corresponding unconditional branch instruction in the jump table according to the jump address, and jump to a program corresponding to the branch statement.

[0030] Optionally, before the step of compiling the multi-branch selection statement and generating the corresponding jump table, the method further comprises:

[0031] acquiring the number of branch judgment conditions and case values in the multi-branch selection statement;

[0032] judging whether to use a jump table according to the number of branch judgment conditions and the case values of the multi-branch selection statement.

[0033] Optionally, the step of judging whether to use a jump table according to the number of branch judgment conditions and the case values of the multi-branch selection statement specifically comprises the following steps:

[0034] if the number of branch judgment conditions n<N, where N is a preset number threshold, not using a jump table;

[0035] if the number of branch judgment conditions n≥N and the case values are arranged in sequence, using a jump table;

[0036] if the number of branch judgment conditions n≥N, the case values are not arranged in sequence, and (max case -min case )≤kn, where kn is a preset multiple threshold, using a jump table, where max case represents a maximum case value, and min case represents a minimum case value;

[0037] If the number of branch judgment conditions n≥N and the case values ​​are not ordered and (max) case -min case If )>kn, then the jump table is not used.

[0038] Thirdly, the present invention provides an electronic device, including a processor and a storage medium;

[0039] The storage medium is used to store instructions;

[0040] The processor is configured to operate according to the instructions to perform the method according to any one of the first aspects.

[0041] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, characterized in that, when executed by a processor, the program implements the steps of the method described in any one of the first aspects.

[0042] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0043] This invention optimizes the compilation method of multi-branch selection statements in JavaScript engines by replacing memory access instructions with non-memory access instructions, thereby generating a jump table for multi-branch selection statements. This jump table stores unconditional jump instructions, avoiding the problem of inefficiency caused by excessive memory access, improving the overall performance of the program, and reducing the storage space occupied by the jump table. Attached Figure Description

[0044] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the embodiments will be briefly described below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort, wherein:

[0045] Figure 1 This is a flowchart of a multi-branch selection statement processing method provided in an embodiment of the present invention. Detailed Implementation

[0046] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.

[0047] Furthermore, if the embodiments of this invention involve descriptions such as "first" or "second," these descriptions are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first" or "second" may explicitly or implicitly include at least one of those features. Additionally, the technical solutions of the various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed by this invention.

[0048] Example 1

[0049] This invention provides a method for processing multi-branch selection statements, specifically for the Shenwei JavaScript engine. Figure 1 As shown, it includes the following steps:

[0050] (1) Compile the multi-branch selection statement to generate the corresponding jump table. Each entry of the jump table stores the unconditional jump instruction corresponding to each branch selection statement. The unconditional jump instruction is 4 bytes. In actual application, the jump table is generated by a for loop.

[0051] (2) Get the current PC value;

[0052] (3) Based on the obtained actual parameters, find the corresponding index in the jump table, and calculate the offset in the jump table based on the found index and the length of the table entry;

[0053] (4) Obtain the number of instructions between the current PC value and the jump table, multiply the number of instructions by the length of the instructions, and calculate the offset outside the jump table;

[0054] (5) Add the PC value, the offset in the jump table, and the offset outside the jump table to obtain the jump address;

[0055] (6) Based on the jump address, execute the corresponding unconditional jump instruction in the jump table and jump to the program corresponding to the branch statement.

[0056] It can be seen that, compared with the existing processing method, the processing method for multi-branch selection statements in the embodiment of the present invention adopts non-memory access instructions to replace memory access instructions, and does not need to load long words from memory into registers, which realizes the generation of the jump table for the multi-branch selection statement, wherein the jump table stores unconditional branch instructions. This avoids the problem of low efficiency caused by more consumption resulting from memory access, and improves the overall performance of the program. Meanwhile, since each entry in the jump table of the present invention stores an unconditional branch instruction (4 bytes) corresponding to each branch selection statement, compared with the existing jump table that stores target addresses (8 bytes), the storage space occupied by the jump table is reduced by half compared with the processing method of the prior art.

[0057] In a specific embodiment of the present invention, before the step of compiling the multi-branch selection statement and generating the corresponding jump table, the method further comprises:

[0058] acquiring the number of branch judgment conditions and case values in a multi-branch selection statement;

[0059] judging whether to use a jump table according to the number of branch judgment conditions and the case values of the multi-branch selection statement.

[0060] wherein the step of judging whether to use a jump table according to the number of branch judgment conditions and the case values of the multi-branch selection statement specifically comprises the following steps:

[0061] if the number of branch judgment conditions n<N, where N is a preset number threshold, the jump table is not used;

[0062] if the number of branch judgment conditions n≥N and the case values are arranged sequentially, the jump table is used;

[0063] if the number of branch judgment conditions n≥N, the case values are in non-sequential arrangement and (max case -min case )≤kn, where kn is a preset multiple threshold, the jump table is used, max case represents a maximum case value, min case represents a minimum case value;

[0064] if the number of branch judgment conditions n≥N, the case values are in non-sequential arrangement and (max case -min case )>kn, the jump table is not used.

[0065] if the jump table is not used, the multi-branch selection statement is executed in sequence.

[0066] The processing method in the embodiment of the present invention is described in detail below with reference to a specific embodiment.

[0067] Step S1: Acquire the number of branch judgment conditions and case values in the multi-branch selection statement;

[0068] Take the multi-branch selection statement shown in Table 1 as an example:

[0069] Table 1

[0070]

[0071]

[0072] Wherein, the number of branch judgment conditions is 7; the case values are 0, 1, 2, 3, 4, 5, 6, 7.

[0073] Step S2: Determine whether to use a jump table according to the number of branch judgment conditions and the case values;

[0074] Specifically in this embodiment, the given judgment conditions are:

[0075] ① If the number of branch judgment conditions n<N, where N is a preset quantity threshold, do not use a jump table;

[0076] ② If the number of branch judgment conditions n≥N and the case values are arranged in order, use a jump table;

[0077] ③ If the number of branch judgment conditions n≥N, the case values are not arranged in order, and (max case -min case )≤kn, where k is a preset multiple threshold, use a jump table;

[0078] ④ If the number of branch judgment conditions n≥N, the case values are not arranged in order, and (max case -min case )>kn,

[0079] do not use a jump table.

[0080] In an optional embodiment, the quantity threshold N is set to 6, and the multiple threshold k is set to 3. Taking Table 1 as an example again, n=7>6 and the case values are arranged in order, so a jump table needs to be used.

[0081] Step S3: If no jump table is used, execute the multi-branch selection statement in sequence and end the processing flow.

[0082] Step S4: If a jump table is used, compile the multi-branch selection statement to generate a corresponding jump table, wherein each entry of the jump table stores an unconditional branch instruction corresponding to each branch selection statement; in an actual application process, the jump table is generated through a for loop;

[0083] Step S5: Obtain the current PC value; the PC value refers to the address of the next instruction after the currently executing instruction.

[0084] Step S6: Based on the obtained actual parameters, find the corresponding index in the jump table, and calculate the offset in the jump table based on the found index and the table entry length.

[0085] The jump table entry has been optimized from an 8-byte jump address to a 4-byte jump instruction. Therefore, the instruction used to calculate the offset of the target address in the jump table has also changed. The original jump table index was multiplied by 8, but now it is multiplied by 4. The memory occupied by the jump table is reduced by half compared to the original method.

[0086] Step S7: Obtain the number of instructions between the current PC value and the jump table, multiply the number of instructions by the length of the instructions, and calculate the offset outside the jump table;

[0087] Step S8: Add the PC value, the offset in the jump table, and the offset outside the jump table to obtain the jump address;

[0088] Step S9: Based on the jump address, execute the corresponding unconditional jump instruction in the jump table to jump to the program corresponding to the branch statement.

[0089] The method used in this embodiment (Solution 2) is compared with the method currently used by the Shenwei platform JavaScript engine (Solution 1), as shown in Table 2-3:

[0090] Table 2

[0091]

[0092] Note: In Table 2, ① represents the running address; ② represents the offset within the jump table; ③ represents the offset outside the jump table; ④ represents the temporary register; PC is the instruction counter in the usual sense.

[0093] Comparison between Option 2 and Option 1:

[0094] First, the implementation of the jump table was optimized. In the process of generating the jump table, a single jump instruction was used to replace the function in the original method (the function's role is to store the target address of the jump table in memory). This changed the contents of the jump table entries from 64-bit addresses to 32-bit jump instructions. The function implementation operation was changed to first locate the target position in the jump table, and then jump to the target address of the subsequent branch operation through an unconditional jump.

[0095] Secondly, the operation of locating the target address in the jump table has been optimized. A long word addition instruction is used instead of the instruction to load a long word from memory into a register to achieve the same effect, reducing the number of instruction ticks and avoiding memory access operations. At the same time, the offset is also reduced due to the changes in the jump table contents.

[0096] The effectiveness of this invention was evaluated using two methods: one was to test the score changes before and after optimization using sub-topics in an existing performance test suite; the other was to write corresponding JavaScript examples to compare the changes in code execution time before and after the modification. The performance test scores were calculated according to the method specified in the test suite. The tests showed that the sub-topic scores increased by approximately 0.96%; the JavaScript examples used a method of calculating the average execution time based on multiple calls to the switch function, and the time for this example to run 500 million times was reduced by approximately 2.89%.

[0097] Example 2

[0098] Based on the same inventive concept as Embodiment 1, this embodiment of the invention provides a multi-branch selection statement processing device for the Shenwei JavaScript engine, comprising:

[0099] The compilation module is used to compile multi-branch selection statements and generate corresponding jump tables. Each entry in the jump table stores the unconditional jump instruction corresponding to each branch selection statement. In practical applications, the jump table is generated using a for loop.

[0100] Get the current PC value;

[0101] The offset calculation module within the jump table is used to find the corresponding index in the jump table based on the obtained actual parameters, and calculate the offset within the jump table based on the found index and the length of the table entry.

[0102] The offset calculation module outside the jump table is used to obtain the number of instructions between the current PC value and the jump table, and multiply the number of instructions by the length of the instructions to calculate the offset outside the jump table.

[0103] The addition module is used to add the PC value, the offset in the jump table, and the offset outside the jump table to obtain the jump address;

[0104] The execution module is used to execute the corresponding unconditional jump instruction in the jump table according to the jump address, and jump to the program corresponding to the branch statement.

[0105] In one specific embodiment of the present invention, the method further includes the following step before compiling the multi-branch selection statement to generate the corresponding jump table:

[0106] Acquiring the number of branch judgment conditions and case values in a multi-branch selection statement;

[0107] Judging whether to use a jump table according to the number of branch judgment conditions and case values of the multi-branch selection statement.

[0108] Wherein, the step of judging whether to use a jump table according to the number of branch judgment conditions and case values of the multi-branch selection statement specifically comprises the following steps:

[0109] If the number n of said branch judgment conditions < N, where N is a preset number threshold, no jump table is used;

[0110] If the number n of said branch judgment conditions ≥ N and the case values are arranged in sequence, a jump table is used;

[0111] If the number n of said branch judgment conditions ≥ N, the case values are non-sequentially arranged, and (max case -min case )≤kn, where kn is a preset multiple threshold, a jump table is used, and max case represents the maximum case value, and min case represents the minimum case value;

[0112] If the number n of said branch judgment conditions ≥ N, the case values are non-sequentially arranged, and (max case -min case )>kn, no jump table is used.

[0113] If no jump table is used, the multi-branch selection statement is executed in sequence.

[0114] Embodiment 3

[0115] Based on the same inventive concept as Embodiment 1, an embodiment of the present invention provides an electronic device, comprising a processor and a storage medium;

[0116] said storage medium is configured to store instructions;

[0117] said processor is configured to operate according to said instructions to execute the method according to any one of Embodiment 1.

[0118] Embodiment 4

[0119] Based on the same inventive concept as Embodiment 1, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, characterized in that, when the program is executed by a processor, the steps of the method according to any one of Embodiment 1 are implemented.

[0120] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0121] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0122] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0123] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0124] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims. All of these forms are within the protection scope of the present invention.

[0125] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely illustrative of the principles of the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the present invention as claimed. The scope of protection of this invention is defined by the appended claims and their equivalents.

Claims

1. A method for processing multi-branch selection statements in the Shenwei JavaScript engine, characterized in that, comprising: compiling a multi-branch selection statement to generate a corresponding jump table, wherein each entry of the jump table stores an unconditional branch instruction corresponding to each branch selection statement; acquiring a current PC value; finding a corresponding index in the jump table according to an acquired actual parameter, and calculating an offset within the jump table based on the found index and the entry length; acquiring the number of instructions between the current PC value and the jump table, multiplying the number of instructions by the instruction length to calculate an offset outside the jump table; adding the PC value, the offset within the jump table and the offset outside the jump table to obtain a jump address; executing, according to the jump address, a corresponding unconditional branch instruction in the jump table to jump to a program corresponding to the branch statement.

2. The multi-branch selection statement processing method according to claim 1, a multi-branch selection statement processing method for the Shenwei JavaScript engine, characterized in that, before the step of compiling a multi-branch selection statement to generate a corresponding jump table, the method further comprises: acquiring the number of branch judgment conditions and case values in the multi-branch selection statement; judging whether to use a jump table according to the number of branch judgment conditions and the case values of the multi-branch selection statement.

3. The multi-branch selection statement processing method according to claim 2, a multi-branch selection statement processing method for the Shenwei JavaScript engine, characterized in that: the step of judging whether to use a jump table according to the number of branch judgment conditions and the case values of the multi-branch selection statement specifically comprises the following steps: if the number n of branch judgment conditions is less than N, where N is a preset number threshold, then the jump table is not used; if the number n of branch judgment conditions is greater than or equal to N and the case values are arranged in sequence, then the jump table is used; If the number of branch judgment conditions n≥N and the case values ​​are not ordered and (max) case -min case If the value is less than or equal to kn, where kn is a preset multiple threshold, then a jump table is used, and max... case Min represents the maximum case value. case Indicates the minimum case value; If the number of branch judgment conditions n≥N and the case values ​​are not ordered and (max) case -min case If )>kn, then the jump table is not used.

4. The multi-branch selection statement processing method according to claim 3, a multi-branch selection statement processing method for the Shenwei JavaScript engine, characterized in that: if the jump table is not used, the multi-branch selection statement is executed in sequence.

5. The multi-branch selection statement processing method according to claim 1, a multi-branch selection statement processing method for the Shenwei JavaScript engine, characterized in that: the unconditional branch instruction is 4 bytes.

6. A multi-branch selection statement processing device for the Shenwei JavaScript engine, characterized in that, comprising: a compiling module, configured to compile a multi-branch selection statement to generate a corresponding jump table, wherein each entry of the jump table stores an unconditional branch instruction corresponding to each branch selection statement; acquiring a current PC value; an intra-jump-table offset calculation module, configured to find a corresponding index in the jump table according to an acquired actual parameter, and calculate an offset within the jump table based on the found index and the entry length; an extra-jump-table offset calculation module, configured to acquire the number of instructions between the current PC value and the jump table, multiply the number of instructions by the instruction length to calculate an offset outside the jump table; an adding module, configured to add the PC value, the offset within the jump table and the offset outside the jump table to obtain a jump address; an execution module, configured to execute, according to the jump address, a corresponding unconditional branch instruction in the jump table to jump to a program corresponding to the branch statement.

7. The multi-branch selection statement processing device according to claim 6, characterized in that, before the step of compiling a multi-branch selection statement to generate a corresponding jump table, the apparatus further comprises: acquiring the number of branch judgment conditions and case values in the multi-branch selection statement; judging whether to use a jump table according to the number of branch judgment conditions and the case values of the multi-branch selection statement.

8. The multi-branch selection statement processing device according to claim 7, characterized in that, the step of judging whether to use a jump table according to the number of branch judgment conditions and the case values of the multi-branch selection statement specifically comprises the following steps: if the number n of branch judgment conditions is less than N, where N is a preset number threshold, then the jump table is not used; if the number n of branch judgment conditions is greater than or equal to N and the case values are arranged in sequence, then the jump table is used; If the number of branch judgment conditions n≥N and the case values ​​are not ordered and (max) case -min case If the value is less than or equal to kn, where kn is a preset multiple threshold, then a jump table is used, and max... case Min represents the maximum case value. case Indicates the minimum case value; If the number of branch judgment conditions n≥N and the case values ​​are not ordered and (max) case -min case If )>kn, then the jump table is not used.

9. An electronic device, characterized in that, comprising a processor and a storage medium; the storage medium is configured to store instructions; The processor is configured to operate according to the instructions to perform the method according to any one of claims 1-5.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the program implements the steps of the method according to any one of claims 1-5.

Citation Information

Patent Citations

  • Method and device for positioning ARM firmware loading base address based on a jumping table

    CN107273177A

  • Low-cost high-efficiency branch predictor implementation method

    CN115328552A