Multiplication of integers optimization method based on platform red fox browser JIT engines of soaring
Technical field
The invention belongs to communication technique fields, more particularly, to a kind of based on platform red fox browser JIT engines of soaring
Multiplication of integers optimization method.
Background technology
Along with the fast development of internet, browser becomes the main Internet portal of desktop terminal user.Now
Web site contents it is more and more abundant, function also becomes increasingly complex, most dynamic in order to which the Fast rendering page promotes user experience
State page rendering and data processing work can be carried out in browser end.This performance to browser, the especially performance of JS engines
More stringent requirements are proposed.
The JS engines of early stage are all based on interpreter realization, and it is short that interpreter has the advantages that code load and execution is delayed, but
It is that the code executed repeatedly is needed to reinterpret every time, results in the reduction of operational efficiency.It is executed to promote JS engines
Performance, browser manufacturer have developed the JIT optimisation techniques suitable for dynamic languages such as JS.
JIT:Just-In-Time (Just-in-time compilation), a kind of form of on-the-flier compiler are a kind of raisings
The method of program operational efficiency.In red fox browser, there are two JIT compilers:Baseline JIT compiler and optimization jit compiling
Device.
Bailout:Also be " going to optimize " (Deoptimize), height optimization level JIT done very radical optimization (such as
Assuming that it be not centainly the pointed object of null, some reference must be some that some class, which will not have other subclass, some reference,
Concrete type, etc.), and if if this radical hypothesis fails, must just return to do not do these optimization " peace
Low optimization level JIT entirely " goes to continue to execute.
The code operation information that JIT compiler is recorded according to interpreter, by hot spot code by compiling optimization means compiling
Corresponding JIT codes are directly executed at local machine code, when running to respective code next time, so as to which JS is substantially improved
Engine performance.There are two JIT compilers inside red fox browser at present:Baseline compiler and Optimizing Compiler.Baseline compiler
It can be by " " code compilation will not do code structure and optimize hot spot at local machine code;It was executed in baseline compiler
Many times " very it is hot " code can be admitted to optimization JIT compiler, and a variety of optimization hands can be called by optimizing inside JIT compiler
Section (constant folding, dead code elimination etc.), adjustment code structure is to generate most efficient local machine code.
Red fox browser does not support optimization JIT functions in platform of soaring at present, because lacking the optimization for platform of soaring
JIT code buildings rear end.And baseline JIT degree of optimization is insufficient, causes the complicated webpage timeliness rate of JS engines processing too low, to draw
It is slow to play page response.Especially JS codes are required for first judging to operate in the multiplying of interpreter and baseline JIT compiler
Then operand is converted to floating number again, then passes through floating-point multiply instruction result of calculation by several types.Floating-point multiply instruction exists
Platform of soaring needs five clock cycle, and other arithmetic instructions can execute completion in clock cycle greatly, especially
When recycling execution, performance issue is more prominent.
In the existing browser technology based on red fox exploitation, a kind of JS engines for upper red fox browser of soaring without energy solution
The performance issue of multiplication of integers.Multiplication operation in current basic line JIT compiler is completed by floating-point multiply instruction, is needed more
A clock cycle, inefficiency.
Chinese invention patent " the JIT code buildings that profile is oriented to " (application number 201210330925.3), the invention propose
A kind of JIT code generating methods that profile is oriented to, specific implementation are:First, the source code encoded with dynamic language is received
Bytecode is converted to through parsing;Then, interpreter explains bytecode, generates the profile information about bytecode, stores profile
Information;Finally, when JIT compiler is configured to execute controller, JIT compiler is based on profile information and executes compiling bytecode
Function.This method improves the efficiency of code building by generating profile information, but there is no be based on certain types of word
Section code does targetedly code building optimization.
Invention content
The invention aims to solve the problems in background technology, provide a kind of based on platform red fox browser of soaring
The multiplication of integers optimization method of JIT engines, the categorical data collected according to JS engines do type inference and data analysis, are optimizing
Floating-point multiply instruction before is replaced with into other equivalent instructions in JIT code generation processes, is realized complete in an instruction cycle
It is operated at multiplication, to achieve the purpose that optimize multiplication of integers efficiency.
In order to solve the above technical problems, the technical solution adopted by the present invention is:Based on soaring, platform red fox browser JIT draws
The multiplication of integers optimization method held up, in turn includes the following steps:
S110:Start to optimize jit compiling process;
S120:MIR is generated;
S130:Execute optimization time;
S140:MIR degrades;
S150:Code building, including:
A. multiplication of integers code building;
B. right operand in LMulI objects is read, corresponding operation is executed according to the type of right operand;
S160:Terminate.
Preferably, right operand in the reading LMulI objects executes corresponding operation according to the type of right operand,
Including judging whether right operand is constant,
If constant, S151 is thened follow the steps;
If it is not, thening follow the steps S152;
S151:Execute the code building subprocess that right operand is constant;
S152:Execute the code building subprocess that right operand is register.
Preferably, described to execute the code building subprocess that right operand is constant, include the following steps:
S1511:Generate left operand and 0 instruction compared;
S1512:Judge whether right operand is 0;
Preferably, described to generate left operand and 0 instruction compared, including:
Judge whether canBeNegativeZero marks are set in MulI;
If canBeNegativeZero marks are set in MulI, instruction checking multiplication of integers operation result is generated
Whether it is -0,
Preferably, described to judge whether right operand is 0, including:
If right operand is 0, the instruction that Bailout entrances are jumped to when LessThan marks are set is generated;
Otherwise the instruction that Bailout entrances are jumped to when Equal marks are set is generated;
Preferably, including judge r value, corresponding operation executed according to r value type,
When r value is constant 0, then generates instruction and constant 0 is moved to output register;
When r value is constant 1, then generates instruction and the content of left operand device register is moved to output register;
When r value is constant 2, then generates instruction and result is saved in output register by left operand phase adduction;
When r value is 2 n times power, then generates left shift instruction and result is saved in output register;
When r value is other constants, then move is generated by right operand load to rough draft register, and generate and multiply
Method instructs and result is saved in output register, judges the canOverflow flag bits of MulI, if if true, generated
Overflow marks jump to the instruction of Bailout entrances when being set;
Preferably, described to execute the code building subprocess that right operand is register, include the following steps:
S1521:It generates multiplying order and result is saved in output register, judge the canOverflow marks of MulI
Position;
S1522:Judge the canBeNegativeZero marks of MulI;
Preferably, the canOverflow flag bits for judging MulI, including, if if true, generating Overflow marks
The instruction of Bailout entrances is jumped to when will is set.
Preferably, judge the canBeNegativeZero marks of MulI, including:
If it is true, result register and 0 instruction compared are generated, because multiplication of integers result is only deposited here when being -0
An operand is 0 and another operand is less than 0 the case where, it is possible to generate two behaviour of CMN instruction testing
Whether addition of counting is less than zero, and Bailout entrances are jumped to when Signed flag bits are set.
The invention has the advantages and positive effects that:
1. the present invention proposes the multiplication of integers code building optimization method based on platform red fox browser JIT engines of soaring,
The categorical data collected according to JS engines does type inference and data analysis, will before in optimize JIT code generation processes
Floating-point multiply instruction replaces with other equivalent instructions, realizes and completes multiplication operation in an instruction cycle, whole to reach optimization
The purpose of number multiplication efficiency.
2. providing a kind of multiplication of integers instruction generation optimization side specifically for platform red fox browser JIT engines of soaring
Case, to achieve the purpose that optimize multiplication of integers efficiency.
Description of the drawings
Fig. 1 is the flow chart for the platform red fox browser optimization JIT engines of soaring being not optimised;
Fig. 2 is the flow chart of the platform red fox browser optimization JIT engines of soaring after optimization;
Fig. 3 is the multiplication of integers code generation process for optimizing JIT in the present invention based on platform red fox browser of soaring;
Fig. 4 is that optimize right operand based on platform red fox browser JIT engine multiplications of integers of soaring in the present invention be constant
Subprocess flow chart;
Fig. 5 is that optimize right operand based on platform red fox browser JIT engine multiplications of integers of soaring in the present invention be deposit
The subprocess flow chart of device;
Specific implementation mode
The present embodiment provides the multiplication of integers optimization methods based on platform red fox browser JIT engines of soaring, such as Fig. 3 institutes
Show, is one embodiment of optimization JIT multiplication of integers code building optimization process according to an embodiment of the invention, it is main
Include the code building subprocess that operand r value is constant and the code building subprocess that right operand is register, simultaneously
A kind of data structure is also used:LMulI objects.The content and type of object record multiplication of integers operation lvalue, r value
And the range information of destination register information and result of calculation.Specific implementation step is as follows:
Step S301:The isConstant marks for reading right operand in LMulI objects judge whether right operand is normal
Amount, S302 is thened follow the steps if constant, no to then follow the steps S303;
Step S302:Execute the code building subprocess that right operand is constant;
Step S303:Execute the code building subprocess that right operand is register;
Next, describing multiplication of integers code building that right operand according to the present invention is constant below with reference to Fig. 4
One embodiment of process.
Step S401:If canBeNegativeZero marks are set in MulI, instruction checking multiplication of integers is generated
Whether operation result is -0.Left operand and 0 instruction (CMP) compared are generated, if right operand is 0, is generated
LessThan marks jump to the instruction of Bailout entrances when being set, otherwise generate when Equal marks are set and jump to
The instruction of Bailout entrances.
Step S402:When r value be constant 0, then generate instruction by constant 0 move (MOV) arrive output register;
Step S403:When r value is constant 1, then generates instruction and arrive the content of left operand device register movement (MOV)
Output register;
Step S404:When r value is constant 2, then generates instruction and left operand is added (ADD) and is saved in result defeated
Go out register;
Step S405:When r value is 2 n times power, then generates left shift instruction and result is saved in output register;
Step S406:When r value is other constants, then generates move (MOV) and post right operand load to rough draft
Storage, and generate multiplying order and result is saved in output register, judge the canOverflow flag bits of MulI, if
If true, generating the instruction for jumping to Bailout entrances when Overflow marks are set;
Next, describing the multiplication of integers code building that right operand according to the present invention is register below with reference to Fig. 5
One embodiment of subprocess.
Step S501:It generates multiplying order and result is saved in output register, judge the canOverflow marks of MulI
Will position, if if true, generating the instruction for jumping to Bailout entrances when Overflow marks are set;
Step S502:Judge that the canBeNegativeZero marks of MulI generate result register and 0 if it is true
Compare the instruction of (CBNZ), because it is 0 and another operand to only exist an operand when multiplication of integers result is -0 here
Be less than 0 the case where, it is possible to generate two operands of CMN instruction testing and be added whether be less than zero, and in Signed
Bailout entrances are jumped to when flag bit is set.
The invention has the advantages that compared with prior art:
1. the present invention proposes the multiplication of integers code building optimization method based on platform red fox browser JIT engines of soaring,
The categorical data collected according to JS engines does type inference and data analysis, will before in optimize JIT code generation processes
Floating-point multiply instruction replaces with other equivalent instructions, realizes and completes multiplication operation in an instruction cycle, whole to reach optimization
The purpose of number multiplication efficiency.
2. providing a kind of multiplication of integers instruction generation optimization side specifically for platform red fox browser JIT engines of soaring
Case, to achieve the purpose that optimize multiplication of integers efficiency.
One embodiment of the present invention has been described in detail above, but the content be only the present invention preferable implementation
Example should not be construed as limiting the practical range of the present invention.It is all according to all the changes and improvements made by the present patent application range
Deng should all still fall within the scope of the patent of the present invention.