]> Shamusworld >> Repos - architektonas/blob - fparser/fpoptimizer.cc
Adding fparser v4.3...
[architektonas] / fparser / fpoptimizer.cc
1 /***************************************************************************\
2 |* Function Parser for C++ v4.3                                            *|
3 |*-------------------------------------------------------------------------*|
4 |* Function optimizer                                                      *|
5 |*-------------------------------------------------------------------------*|
6 |* Copyright: Joel Yliluoma                                                *|
7 |*                                                                         *|
8 |* This library is distributed under the terms of the                      *|
9 |* GNU Lesser General Public License version 3.                            *|
10 |* (See lgpl.txt and gpl.txt for the license text.)                        *|
11 \***************************************************************************/
12
13 /* NOTE:
14  This file contains generated code (from the optimizer sources) and is
15  not intended to be modified by hand. If you want to modify the optimizer,
16  download the development version of the library.
17 */
18
19 #include "fpconfig.hh"
20 #ifdef FP_SUPPORT_OPTIMIZER
21 #include "fparser.hh"
22 #include "fptypes.hh"
23 #define i43 nW1 a),
24 #define i33 info.yH
25 #define i23 ,cAtan2
26 #define i13 =false;
27 #define i03 cAbsIf
28 #define tZ3 "Found "
29 #define tY3 },{{2,
30 #define tX3 {if(apos
31 #define tW3 stackpos
32 #define tV3 "dup(%u) "
33 #define tU3 GetOpcode
34 #define tT3 eR{assert
35 #define tS3 "%d, cost "
36 #define tR3 "immed "<<
37 #define tQ3 mFuncParsers
38 #define tP3 "PUSH ";xE3(
39 #define tO3 stderr
40 #define tN3 sep2=" "
41 #define tM3 FPHASH_CONST
42 #define tL3 cache_needed[
43 #define tK3 fprintf
44 #define tJ3 ::cout<<"Applying "
45 #define tI3 ||tree.tU3
46 #define tH3 HANDLE_UNARY_CONST_FUNC
47 #define tG3 within,
48 #define tF3 y21){if
49 #define tE3 c_count
50 #define tD3 s_count
51 #define tC3 MaxOp
52 #define tB3 2)lS 2*
53 #define tA3 x11.cG3
54 #define t93 l7 0,2,
55 #define t83 <eS1(0)
56 #define t73 );else{
57 #define t63 (n6)nN3
58 #define t53 b.Value)
59 #define t43 b.Opcode
60 #define t33 .nB synth
61 #define t23 ].swap(
62 #define t13 =synth.
63 #define t03 codes[b
64 #define eZ3 Value){
65 #define eY3 whydump
66 #define eX3 i01 eF2
67 #define eW3 for(x53
68 #define eV3 ;for yS{
69 #define eU3 );synth
70 #define eT3 info.SaveMatchedParamIndex(
71 #define eS3 for(;a<
72 #define eR3 nparams
73 #define eQ3 first!=
74 #define eP3 i03,
75 #define eO3 l3 4,1,
76 #define eN3 cTan,xJ
77 #define eM3 cLog,xJ
78 #define eL3 l3 0,1,
79 #define eK3 cHypot,
80 #define eJ3 nR 0,
81 #define eI3 cAbs nR
82 #define eH3 std::cO
83 #define eG3 fp_pow(
84 #define eF3 ,cM2 lD
85 #define eE3 .second
86 #define eD3 ]eE3
87 #define eC3 ].first
88 #define eB3 Ne_Mask
89 #define eA3 Gt_Mask
90 #define e93 Lt_Mask
91 #define e83 {nL eS1(
92 #define e73 131,4,1,
93 #define e63 tC1 max
94 #define e53 tU cMul);
95 #define e43 131,8,1
96 #define e33 FindPos
97 #define e23 nN yL
98 #define e13 public:
99 #define e03 result xM
100 #define cZ3 result))lA2
101 #define cY3 result(
102 #define cX3 {data->
103 #define cW3 .eW1 n]
104 #define cV3 eG cK1);
105 #define cU3 eG yR1
106 #define cT3 if(eY1==
107 #define cS3 ),has_max(
108 #define cR3 (count
109 #define cQ3 .empty()
110 #define cP3 .iH1 a);
111 #define cO3 GetParamCount(nQ
112 #define cN3 GetParamCount();
113 #define cM3 ;}case
114 #define cL3 pclone
115 #define cK3 sim.x3
116 #define cJ3 fpdata
117 #define cI3 cCosh nR
118 #define cH3 cCosh,
119 #define cG3 Immeds
120 #define cF3 l6 1,
121 #define cE3 x8(tB2
122 #define cD3 newpow
123 #define cC3 change
124 #define cB3 133,2,
125 #define cA3 i01 x2
126 #define c93 Params
127 #define c83 Needs
128 #define c73 byteCode
129 #define c63 eT1&occ=
130 #define c53 child)
131 #define c43 AddFrom(
132 #define c33 lT1 nE==
133 #define c23 ;for xK2
134 #define c13 tC1 lY1
135 #define c03 factor_t
136 #define yZ3 tree.xJ1
137 #define yY3 yA tmp2)
138 #define yX3 value1
139 #define yW3 model.
140 #define yV3 true;n31
141 #define yU3 &&p0.max
142 #define yT3 p2 eT ifp2
143 #define yS3 yJ p2;p2
144 #define yR3 cAbsNot
145 #define yQ3 switch(tX
146 #define yP3 tZ case
147 #define yO3 IsNever
148 #define yN3 }switch
149 #define yM3 stackptr
150 #define yL3 nN[++IP]
151 #define yK3 const xH
152 #define yJ3 yE cPow)
153 #define yI3 default_function_handling
154 #define yH3 cLog);x9
155 #define yG3 ;sim.Push(
156 #define yF3 eS1(0.5)
157 #define yE3 iJ 1,
158 #define yD3 [funcno].
159 #define yC3 :start_at()
160 #define yB3 Rehash(tT yA
161 #define yA3 .size()
162 #define y93 IsLogicalValue nW1
163 #define y83 (tree))e5
164 #define y73 stack[stack yA3-
165 #define y63 stack yL
166 #define y53 tmp yC 0))
167 #define y43 ));tmp tU
168 #define y33 ,(long tG1
169 #define y23 );tmp2 yC
170 #define y13 cMul);xK
171 #define y03 1),eS1(1))
172 #define xZ3 constvalue
173 #define xY3 lD 0));
174 #define xX3 )nG1 xK
175 #define xW3 nN[IP]==
176 #define xV3 opcodes
177 #define xU3 did_muli
178 #define xT3 switch(lF3.first iY2
179 #define xS3 ;for iL1
180 #define xR3 Ge0Lt1
181 #define xQ3 &&p.max
182 #define xP3 :tree.
183 #define xO3 =y6 a));if(
184 #define xN3 used[b]
185 #define xM3 e8(),yG<
186 #define xL3 size_t n
187 #define xK3 sizeof(
188 #define xJ3 cNotNot,
189 #define xI3 cOr yF
190 #define xH3 359463,
191 #define xG3 2,7168,
192 #define xF3 param.
193 #define xE3 DumpTree
194 #define xD3 Gt0Le1
195 #define xC3 y21){eS1
196 #define xB3 base,eS1
197 #define xA3 ==cOr)l9
198 #define x93 cAdd iU1
199 #define x83 (cM2 lD
200 #define x73 lD 2));
201 #define x63 eT cond
202 #define x53 iX2 0;b<
203 #define x43 {}range(
204 #define x33 .n_int_sqrt
205 #define x23 ,cPow,xJ
206 #define x13 ,{1,218,
207 #define x03 lD 1))
208 #define nZ3 tmp yA tree
209 #define nY3 eS1(1)))
210 #define nX3 iterator
211 #define nW3 begin();
212 #define nV3 TreeSet
213 #define nU3 parent
214 #define nT3 insert(i
215 #define nS3 newrel
216 #define nR3 eS1(2)));
217 #define nQ3 {eS1 tmp
218 #define nP3 iU.hash1
219 #define nO3 (tree)!=
220 #define nN3 )n5 lC
221 #define nM3 break;}
222 #define nL3 b_needed
223 #define nK3 cachepos
224 #define nJ3 half=
225 #define nI3 src_pos
226 #define nH3 reserve(
227 #define nG3 treeptr
228 #define nF3 iC2 size()
229 #define nE3 .resize(
230 #define nD3 eU1 void
231 #define nC3 ImmedTag
232 #define nB3 a,const
233 #define nA3 RefCount
234 #define n93 Birth();
235 #define n83 mulgroup
236 #define n73 template
237 #define n63 cost_t
238 #define n53 n72 nZ
239 #define n43 middle
240 #define n33 ))break;eS1
241 #define n23 };enum
242 #define n13 if(op==
243 #define n03 (p1.xJ1
244 #define lZ3 cLog2by);
245 #define lY3 sqrt_cost
246 #define lX3 const int
247 #define lW3 mul_count
248 #define lV3 maxValue1
249 #define lU3 minValue1
250 #define lT3 maxValue0
251 #define lS3 minValue0
252 #define lR3 ValueType
253 #define lQ3 >(eS1(1),
254 #define lP3 abs_mul
255 #define lO3 pos_set
256 #define lN3 goto e3
257 #define lM3 nF1);}if(
258 #define lL3 yE cAdd);
259 #define lK3 subtree
260 #define lJ3 invtree
261 #define lI3 lV1=r.specs;if(r.found){
262 #define lH3 ,lV1,info
263 #define lG3 a;if(&t91
264 #define lF3 parampair
265 #define lE3 rulenumit
266 #define lD3 cIf,l6 3,
267 #define lC3 MakeEqual
268 #define lB3 nH1,l4::
269 #define lA3 nH1,{l4::
270 #define l93 newbase
271 #define l83 branch1op
272 #define l73 branch2op
273 #define l63 overlap
274 #define l53 truth_a
275 #define l43 ),Value(
276 #define l33 );nW l4::
277 #define l23 if nW1 0)
278 #define l13 found_dup
279 #define l03 &1)?(poly^(
280 #define iZ2 (xF3
281 #define iY2 ){case
282 #define iX2 size_t b=
283 #define iW2 i0 xQ3
284 #define iV2 has_min
285 #define iU2 Plan_Has(
286 #define iT2 ;if(half
287 #define iS2 ;}void
288 #define iR2 )iS2
289 #define iQ2 const nI2
290 #define iP2 yV1 class
291 #define iO2 namespace
292 #define iN2 rhs.hash2;}
293 #define iM2 rhs.hash1
294 #define iL2 ::res,b8<
295 #define iK2 inverted
296 #define iJ2 has_max=
297 #define iI2 has_max)
298 #define iH2 iftree
299 #define iG2 depcodes
300 #define iF2 explicit
301 #define iE2 VarBegin
302 #define iD2 cM3 lZ2
303 #define iC2 c93.
304 #define iB2 ].data);
305 #define iA2 y4)));nW
306 #define i92 .what eX
307 #define i82 ;if(fp_equal(
308 #define i72 x02 yJ
309 #define i62 begin(),
310 #define i52 cond_add
311 #define i42 cond_mul
312 #define i32 cond_and
313 #define i22 yG n91
314 #define i12 bool e31
315 #define i02 unsigned
316 #define tZ2 costree
317 #define tY2 sintree
318 #define tX2 leaf_count
319 #define tW2 =GetParam(
320 #define tV2 sub_params
321 #define tU2 printf(
322 #define tT2 cbrt_count
323 #define tS2 sqrt_count
324 #define tR2 Finite
325 #define tQ2 p1 eT ifp1
326 #define tP2 pcall_tree
327 #define tO2 after_powi
328 #define tN2 grammar
329 #define tM2 lE 0,1,
330 #define tL2 cCos,xJ
331 #define tK2 cEqual,
332 #define tJ2 ,eO3 507 tS
333 #define tI2 ,t71 l7 2,2,
334 #define tH2 cLog nR
335 #define tG2 l0 2,
336 #define tF2 cPow,nU
337 #define tE2 cAdd,xZ 2,
338 #define tD2 cInv,xZ 1,
339 #define tC2 cNeg,xZ 1,
340 #define tB2 ),0},{
341 #define tA2 x11.SubTrees
342 #define t92 x11.Others
343 #define t82 param=*i01
344 #define t72 std::move(
345 #define t62 nM3 switch(
346 #define t52 constraints=
347 #define t42 .constraints
348 #define t32 data;data.
349 #define t22 MakeNEqual
350 #define t12 for yS eC1
351 #define t02 yA mul)
352 #define eZ2 Dump(std::
353 #define eY2 isInteger(
354 #define eX2 (cond.cI cA2
355 #define eW2 yA3;++
356 #define eV2 nG1 r;r tU
357 #define eU2 Comparison
358 #define eT2 needs_flip
359 #define eS2 {data xB lM
360 #define eR2 ,eQ,synth);
361 #define eQ2 (half&63)-1;
362 #define eP2 value]
363 #define eO2 ));TriTruthValue
364 #define eN2 );range.nN2
365 #define eM2 ,2,1,4,1,2,
366 #define eL2 >StackMax)
367 #define eK2 ~size_t(0)
368 #define eJ2 );t4=!t4;}
369 #define eI2 ;}yV1 static
370 #define eH2 info.lQ[b].
371 #define eG2 const std::eO
372 #define eF2 Rule&rule,
373 #define eE2 .GetHash().
374 #define eD2 (list.first
375 #define eC2 ;iU.hash2+=
376 #define eB2 ,xA1);lC
377 #define eA2 ,const e1&
378 #define e92 struct
379 #define e82 cGreater,
380 #define e72 tree lD 0)
381 #define e62 const eS1&
382 #define e52 mul_item
383 #define e42 innersub
384 #define e32 cbrt_cost
385 #define e22 best_cost
386 #define e12 )))l81 lH
387 #define e02 result i0
388 #define cZ2 fp_mod(m.
389 #define cY2 Compare>
390 #define cX2 (*x6)[a].info
391 #define cW2 tree y21 yI
392 #define cV2 tree nE==
393 #define cU2 condition
394 #define cT2 per_item
395 #define cS2 item_type
396 #define cR2 first2
397 #define cQ2 ,l8 0,2,
398 #define cP2 tS 396676
399 #define cO2 Decision
400 #define cN2 not_tree
401 #define cM2 leaf1
402 #define cL2 =tree lD
403 #define cK2 group_by
404 #define cJ2 ->second
405 #define cI2 targetpos
406 #define cH2 eat_count
407 #define cG2 ParamSpec
408 #define cF2 Forget()
409 #define cE2 exponent
410 #define cD2 ,bool abs){
411 #define cC2 synth.Find(
412 #define cB2 params
413 #define cA2 &&cond eH))
414 #define c92 source_tree
415 #define c82 nE==cLog2&&
416 #define c72 =lT1;bool iQ
417 #define c62 <t8,n63>
418 #define c52 p1_evenness
419 #define c42 c32 i13 if(
420 #define c32 tC1 iV2
421 #define c22 isNegative(
422 #define c12 n73 i5
423 #define c02 neg_set
424 #define yZ2 StackTopIs(
425 #define yY2 cNop,cNop}}
426 #define yX2 synth.PushImmed(
427 #define yW2 FPoptimizer_ByteCode yU2
428 #define yV2 FPoptimizer_ByteCode::
429 #define yU2 ::ByteCodeSynth x8
430 #define yT2 cTanh,cNop,
431 #define yS2 matches
432 #define yR2 goto fail;}
433 #define yQ2 cSin,xJ
434 #define yP2 cTan nR
435 #define yO2 cCos nR
436 #define yN2 negated
437 #define yM2 i7,1,iX+1);
438 #define yL2 CodeTree
439 #define yK2 yL2 x8
440 #define yJ2 ifdata
441 #define yI2 best_score
442 #define yH2 mulvalue
443 #define yG2 pow_item
444 #define yF2 nE==cPow&&tJ
445 #define yE2 PowiResult
446 #define yD2 maxValue
447 #define yC2 minValue
448 #define yB2 ;pow tU cPow);pow
449 #define yA2 result cM3
450 #define y92 fp_min(xA,
451 #define y82 set_min_max(
452 #define y72 div_tree
453 #define y62 pow_tree
454 #define y52 preserve
455 #define y42 PullResult()
456 #define y32 dup_or_fetch
457 #define y22 nominator]
458 #define y12 Rehash(false
459 #define y02 test_order
460 #define xZ2 lF3,
461 #define xY2 .param_count
462 #define xX2 shift(index)
463 #define xW2 rulenumber
464 #define xV2 cTanh nR
465 #define xU2 (tree nE
466 #define xT2 GetDepth()
467 #define xS2 factor_immed
468 #define xR2 changes
469 #define xQ2 tU tree nE);
470 #define xP2 tU cond nE
471 #define xO2 Become nW1
472 #define xN2 },0,0x1},{{1,
473 #define xM2 ,lJ 0x7 tY3
474 #define xL2 ;n41 eT y9 lD
475 #define xK2 (size_t a=
476 #define xJ2 ;}static yN1
477 #define xI2 tree lD a)
478 #define xH2 for(typename
479 #define xG2 exp_diff
480 #define xF2 ExponentInfo
481 #define xE2 lower_bound(
482 #define xD2 factor
483 #define xC2 is_logical
484 #define xB2 newrel_and
485 #define xA2 Suboptimal
486 #define x92 cW[c tO
487 #define x82 IsAlways;if(
488 #define x72 n73 nA1
489 #define x62 res_stackpos
490 #define x52 half_pos
491 #define x42 ;}else{x6=new
492 #define x32 )lS 3*
493 #define x22 {e1 start_at;
494 #define x12 ,(long double)
495 #define x02 .Rehash()
496 #define nZ2 )return
497 #define nY2 );cK3 iJ 2,
498 #define nX2 return false;}
499 #define nW2 );nM3
500 #define nV2 xD1 tA+1);
501 #define nU2 ;i7.Remember(
502 #define nT2 .match_tree
503 #define nS2 l81 true;}
504 #define nR2 nD OPCODE
505 #define nQ2 yG x8&immed,
506 #define nP2 >>1)):(
507 #define nO2 CodeTreeData
508 #define nN2 multiply(
509 #define nM2 i0 i13
510 #define nL2 .n73
511 #define nK2 var_trees
512 #define nJ2 cOr,lP 2,
513 #define nI2 yL2&
514 #define nH2 ::Optimize(){
515 #define nG2 second eE3;
516 #define nF2 second.first;
517 #define nE2 log2_exponent
518 #define nD2 tT.swap(tmp);
519 #define nC2 Value(Value::
520 #define nB2 dup_fetch_pos
521 #define nA2 nN,size_t&l31
522 #define n92 *)&*start_at;
523 #define n82 yO3 yI lC
524 #define n72 ,tree))
525 #define n62 ContainsOtherCandidates(
526 #define n52 ,cPow l7 2,2,
527 #define n42 cSin nR
528 #define n32 lK 2},0,iR 1,
529 #define n22 lK 1},0,iR 1,
530 #define n12 Value_EvenInt
531 #define n02 Sign_Negative
532 #define lZ2 SubFunction:{
533 #define lY2 ParamHolder:{
534 #define lX2 MakeFalse,{l4
535 #define lW2 if(xW lD a)iA
536 #define lV2 ConditionType
537 #define lU2 SpecialOpcode
538 #define lT2 synth_it
539 #define lS2 fp_max(xA);
540 #define lR2 assimilated
541 #define lQ2 fraction
542 #define lP2 0x12},{{
543 #define lO2 DUP_BOTH();
544 #define lN2 -1-offset].
545 #define lM2 tU3()
546 #define lL2 parent_opcode)
547 #define lK2 TreeCounts
548 #define lJ2 bool t4 i13
549 #define lI2 SetOpcode(
550 #define lH2 found_log2
551 #define lG2 div_params
552 #define lF2 .CopyOnWrite()
553 #define lE2 immed_sum
554 #define lD2 OPCODE(opcode)
555 #define lC2 std::cout<<"POP "
556 #define lB2 (stack yA3-
557 #define lA2 break;result*=
558 #define l92 FactorStack x8
559 #define l82 IsAlways yI lC
560 #define l72 l7 2,2,lB1
561 #define l62 248024 tS
562 #define l52 cAnd,lP 2,
563 #define l42 cNot nR
564 #define l32 cMul,xZ 2,
565 #define l22 DumpHashesFrom
566 #define l12 replacing_slot
567 #define l02 RefParams
568 #define iZ1 if_always[
569 #define iY1 WhatDoWhenCase
570 #define iX1 exponent_immed
571 #define iW1 new_base_immed
572 #define iV1 base_immed
573 #define iU1 ||op1==
574 #define iT1 (size_t a xX
575 #define iS1 data[a eD3
576 #define iR1 AddCollection(
577 #define iQ1 if(newrel_or==
578 #define iP1 DUP_ONE(apos);
579 #define iO1 flipped
580 #define iN1 .UseGetNeeded(
581 #define iM1 e9 2,131,
582 #define iL1 (i02
583 #define iK1 OptimizedUsing
584 #define iJ1 Var_or_Funcno
585 #define iI1 iJ1;
586 #define iH1 DelParam(
587 #define iG1 typename nX1::nX3
588 #define iF1 )nZ2 true
589 #define iE1 GetParams(
590 #define iD1 crc32_t
591 #define iC1 fphash_value_t
592 #define iB1 signed_chain
593 #define iA1 IsDefined())
594 #define i91 MinusInf
595 #define i81 n_immeds
596 #define i71 FindClone(xK
597 #define i61 denominator]
598 #define i51 needs_rehash
599 #define i41 AnyWhere_Rec
600 #define i31 minimum_need
601 #define i21 ~i02(0)
602 #define i11 tC1 min
603 #define i01 (const
604 #define tZ1 ,i01 void*)&
605 #define tY1 41,42,43,44,
606 #define tX1 constraints&
607 #define tW1 tT.iH1
608 #define tV1 p1_logical_b
609 #define tU1 p0_logical_b
610 #define tT1 p1_logical_a
611 #define tS1 p0_logical_a
612 #define tR1 ,PowiCache&i7,
613 #define tQ1 synth.DoDup(
614 #define tP1 else if(
615 #define tO1 cache_needed
616 #define tN1 e9 2,1,e9 2,
617 #define tM1 treelist
618 #define tL1 IsDescendantOf(
619 #define tK1 has_bad_balance
620 #define tJ1 (tree,std::cout)
621 #define tI1 .SetParamsMove(
622 #define tH1 c03 xD2
623 #define tG1 double)cE2
624 #define tF1 {case IsAlways:
625 #define tE1 e02=false
626 #define tD1 ;cE2.Rehash(
627 #define tC1 result.
628 #define tB1 range x8 result
629 #define tA1 TopLevel)
630 #define t91 *start_at){x6=(
631 #define t81 (rule,tree,info
632 #define t71 cNEqual
633 #define t61 ,cEqual l7 2,2,
634 #define t51 cAdd,AnyParams,
635 #define t41 lP2 xG3
636 #define t31 ,cNotNot nR
637 #define t21 ,cLess l7 2,2,
638 #define t11 Oneness_NotOne|
639 #define t01 Value_IsInteger
640 #define eZ1 iK1(
641 #define eY1 reltype
642 #define eX1 SequenceOpcodes
643 #define eW1 sep_list[
644 #define eV1 );eG n83);
645 #define eU1 l02);
646 #define eT1 TreeCountItem
647 #define eS1 Value_t
648 #define eR1 divgroup
649 #define eQ1 ,eS1(-1)))xF
650 #define eP1 set_min(fp_floor
651 #define eO1 pihalf_limits
652 #define eN1 y41 p0.min>=0.0)
653 #define eM1 MaxChildDepth
654 #define eL1 situation_flags&
655 #define eK1 i02 opcode)
656 #define eJ1 =yM|i02(nN yA3
657 #define eI1 std::pair<It,It>
658 #define eH1 eO3 483 tS
659 #define eG1 ,l8 0,1,
660 #define eF1 tG2 7168,
661 #define eE1 Value_Logical
662 #define eD1 new_factor_immed
663 #define eC1 if(remaining[a])
664 #define eB1 occurance_pos
665 #define eA1 exponent_hash
666 #define e91 exponent_list
667 #define e81 CollectionSet x8
668 #define e71 CollectMulGroup(
669 #define e61 source_set
670 #define e51 cE2,nV3
671 #define e41 produce_count
672 #define e31 operator
673 #define e21 )yJ3;lC
674 #define e11 back().thenbranch
675 #define e01 ParamSpec_Extract
676 #define cZ1 retry_anyparams_3
677 #define cY1 retry_anyparams_2
678 #define cX1 needlist_cached_t
679 #define cW1 grammar_rules[*r]
680 #define cV1 tF2 0x1 tY3
681 #define cU1 CodeTreeImmed x8(
682 #define cT1 GetParamCount()==
683 #define cS1 by_float_exponent
684 #define cR1 fp_equal(cE2
685 #define cQ1 new_exp
686 #define cP1 end()&&i->first==
687 #define cO1 yB3 r);}
688 #define cN1 return BecomeZero;
689 #define cM1 return BecomeOne;
690 #define cL1 if(lQ yA3<=n2)
691 #define cK1 addgroup
692 #define cJ1 found_log2by
693 #define cI1 ())yE cMul);lC
694 #define cH1 >=eS1(0)
695 #define cG1 nE==yR3)
696 #define cF1 ParsePowiMuli(
697 #define cE1 branch1_backup
698 #define cD1 branch2_backup
699 #define cC1 exponent_map
700 #define cB1 plain_set
701 #define cA1 LightWeight(
702 #define c91 }nM3 case
703 #define c81 cN3++b)
704 #define c71 synth.x5 1
705 #define c61 ,i7 eR2
706 #define c51 if(value
707 #define c41 set_max(fp_ceil cY
708 #define c31 e62 v,n7
709 #define c21 {eS1 cE2=
710 #define c11 should_regenerate=true;
711 #define c01 should_regenerate,
712 #define yZ1 Collection
713 #define yY1 RelationshipResult
714 #define yX1 Subdivide_Combine(
715 #define yW1 long value
716 #define yV1 n73 lT
717 #define yU1 yV1 cA
718 #define yT1 yV1 e92
719 #define yS1 eP nE3 StackMax
720 #define yR1 subgroup
721 #define yQ1 best_sep_factor
722 #define yP1 tP1!result
723 #define yO1 needlist_cached
724 #define yN1 inline i02
725 #define yM1 221646 tS 24803
726 #define yL1 Constness_Const
727 #define yK1 opcode,bool pad
728 #define yJ1 n_occurrences
729 #define yI1 changed=true;
730 #define yH1 iH1 a);}
731 #define yG1 MakesInteger(
732 #define yF1 e62 value
733 #define yE1 best_sep_cost
734 #define yD1 MultiplicationRange
735 #define yC1 ;p1.yB3 p1
736 #define yB1 yV1 eS1
737 #define yA1 n_stacked
738 #define y91 AnyParams_Rec
739 #define y81 continue;
740 #define y71 Become(value lD 0))
741 #define y61 ,cGreater l7 2,2,
742 #define y51 yV1 inline TriTruthValue
743 #define y41 .iV2&&
744 #define y31 ));n41 y3 op1 tT.DelParams(
745 #define y21 .IsImmed()
746 #define y11 =comp.AddItem(atree
747 #define y01 needs_sincos
748 #define xZ1 Recheck_RefCount_Div
749 #define xY1 Recheck_RefCount_Mul
750 #define xX1 n83.
751 #define xW1 n83;n83 tU
752 #define xV1 MultiplyAndMakeLong(
753 #define xU1 cMul);y53;tmp
754 #define xT1 covers_plus1
755 #define xS1 lD2);
756 #define xR1 if(synth.FindAndDup(
757 #define xQ1 SynthesizeParam(
758 #define xP1 public e8,public yG<
759 #define xO1 grammar_func
760 #define xN1 221426 tS 237795
761 #define xM1 t93 165888 tS
762 #define xL1 Modulo_Radians},
763 #define xK1 tT.SetParam(
764 #define xJ1 GetImmed()
765 #define xI1 PositionType
766 #define xH1 CollectionResult
767 #define xG1 yV1 bool
768 #define xF1 const_offset
769 #define xE1 stacktop_desired
770 #define xD1 SetStackTop(
771 #define xC1 ,cLessOrEq l7 2,2,
772 #define xB1 yV1 void
773 #define xA1 cond_type
774 #define x91 Recheck_RefCount_RDiv
775 #define x81 static const range x8
776 #define x71 fPExponentIsTooLarge(
777 #define x61 CollectMulGroup_Item(
778 #define x51 pair<eS1,nV3>
779 #define x41 covers_full_cycle
780 #define x31 AssembleSequence(
781 #define x21 x8(rule.repl_param_list,
782 #define x11 NeedList
783 #define x01 )lF3 eE3
784 #define nZ1 <<std::dec<<")";}
785 #define nY1 &&IsLogicalValue(
786 #define nX1 TreeCountType x8
787 #define nW1 (tree lD
788 #define nV1 <yK2>
789 #define nU1 std::pair<T1,T2>&
790 #define nT1 n73<typename
791 #define nS1 has_good_balance_found
792 #define nR1 Rehash();tV2 yL
793 #define nQ1 found_log2_on_exponent
794 #define nP1 covers_minus1
795 #define nO1 needs_resynth
796 #define nN1 immed_product
797 #define nM1 }},{ProduceNewTree,2,1,
798 #define nL1 ,2,1)nS if(found[data.
799 #define nK1 t62 bitmask&
800 #define nJ1 Sign_Positive
801 #define nI1 {DataP slot_holder(xY[
802 #define nH1 ::MakeTrue
803 #define nG1 {yK2
804 #define nF1 tree.iH1 a
805 #define nE1 tree lD 1)y21&&
806 #define nD1 },{l4::MakeNotP0,l4::
807 #define nC1 SetParamMove(
808 #define nB1 CodeTreeImmed(eS1(
809 #define nA1 <i02 cY2 void
810 #define n91 <yL2>&
811 #define n81 yG<i02>&c73,
812 #define n71 void ByteCodeSynth x8::
813 #define n61 )const{return
814 #define n51 rhs n61 hash1
815 #define n41 changed_if
816 #define n31 min=eS1(0);
817 #define n21 opposite=
818 #define n11 7168 tS 279818,
819 #define n01 l81 xA2;
820 #define lZ1 MatchResultType
821 #define lY1 resulting_exponent
822 #define lX1 Unknown:default:;}
823 #define lW1 ,lE 2,1,
824 #define lV1 (*x6)[a].start_at
825 #define lU1 ,cAdd,SelectedParams,0},0,
826 #define lT1 GetParam(a)
827 #define lS1 inverse_nominator]
828 #define lR1 void FunctionParserBase
829 #define lQ1 ,nN,IP,limit,y1,stack);
830 #define lP1 ByteCodeSynth x8&synth)
831 #define lO1 xS3 a=0;a<xT;++a)
832 #define lN1 ;std::cout<<
833 #define lM1 const yK2
834 #define lL1 const yG nV1
835 #define lK1 synth.AddOperation(
836 #define lJ1 tQ1 found[data.
837 #define lI1 SetParams(iE1));
838 #define lH1 o<<"("<<std::hex<<data.
839 #define lG1 IfBalanceGood(
840 #define lF1 n_as_tan_param
841 #define lE1 changed_exponent
842 #define lD1 retry_positionalparams_2
843 #define lC1 i02 index
844 #define lB1 463 tS 273436,
845 #define lA1 l7 2,2,473304 tS
846 #define l91 {l4::MakeNotP1,l4::
847 #define l81 ;return
848 #define l71 yO3 l81 Unknown;}
849 #define l61 PlanNtimesCache(
850 #define l51 AddFunctionOpcode_Float(
851 #define l41 FPoptimizer_Grammar
852 #define l31 IP,size_t limit,size_t y1
853 #define l21 AddOperation(cInv,1,1)nS}
854 #define l11 e92 ImmedHashGenerator
855 #define l01 GetPositivityInfo nO3
856 #define iZ tB2 eS1(
857 #define iY CopyOnWrite();
858 #define iX recursioncount
859 #define iW ParamSpec_SubFunctionData
860 #define iV inverse_denominator]
861 #define iU NewHash
862 #define iT tree.GetParamCount()
863 #define iS PositionalParams_Rec
864 #define iR 0x4},{{
865 #define iQ needs_cow=GetRefCount()>1;
866 #define iP );nC1 0,cE2);iH1 1);
867 #define iO DumpTreeWithIndent(*this);
868 #define iN switch(type iY2 cond_or:
869 #define iM CalculateResultBoundaries(
870 #define iL e62 v,eS1(lN
871 #define iK AddFunctionOpcode_Integer(
872 #define iJ sim.Eat(
873 #define iI edited_powgroup
874 #define iH has_unknown_max
875 #define iG has_unknown_min
876 #define iF if(keep_powi
877 #define iE synthed_tree
878 #define iD 356668 tS 24852
879 #define iC +2]=yM|i02(Immed yA3);
880 #define iB matched_params
881 #define iA .IsIdenticalTo(
882 #define i9 by_exponent
883 #define i8 collections
884 #define i7 cache
885 #define i6 }inline
886 #define i5 lT void range x8::
887 #define i4 yA comp.cB1[a].value);
888 #define i3 AnyParams,2},0,0x0},{{
889 #define i2 cS1.data
890 #define i1 iF2 nO2(
891 #define i0 .has_max
892 #define tZ goto ReplaceTreeWithZero;
893 #define tY :goto ReplaceTreeWithOne;case
894 #define tX GetLogicalValue nW1
895 #define tW lN1 std::endl;DumpHashes(
896 #define tV ;p2.yB3 p2);tH iH2 nE);e5}
897 #define tU .lI2
898 #define tT );tree
899 #define tS ,{2,
900 #define tR lZ 0x0},{{
901 #define tQ yV1 nA
902 #define tP MakeFalse,l4::
903 #define tO ].relationship
904 #define tN <=fp_const_negativezero x8())
905 #define tM .hash1|=key;iC1 n9
906 #define tL [n2 eC3=true;lQ[n2 eD3
907 #define tK l41::Grammar*
908 #define tJ powgroup lD
909 #define tI ;pow tU cLog);tH cMul);
910 #define tH tree tU
911 #define tG eK2&&found[data.
912 #define tF },{l4::MakeNotNotP1,l4::
913 #define tE },{l4::MakeNotNotP0,l4::
914 #define tD cN3 a-->0;)if(
915 #define tC nB1(
916 #define tB has_mulgroups_remaining
917 #define tA StackTop
918 #define t9 MatchInfo x8&
919 #define t8 int_exponent_t
920 #define t7 RootPowerTable x8::RootPowers[
921 #define t6 MatchPositionSpec_AnyParams x8
922 #define t5 iO2 FPoptimizer_ByteCode
923 #define t4 is_signed
924 #define t3 iE1));xX1 Rehash();
925 #define t2 result_positivity
926 #define t1 biggest_minimum
927 #define t0 const iW
928 #define eZ ParamSpec_NumConstant x8
929 #define eY yK2&tree,std::ostream&o
930 #define eX !=Unchanged)if(TestCase(
931 #define eW cond_tree
932 #define eV else_tree
933 #define eU then_tree
934 #define eT .AddParam(
935 #define eS ;xE3(tree)lN1"\n";
936 #define eR yK2&tree)
937 #define eQ sequencing
938 #define eP StackState
939 #define eO string FP_GetOpcodeName(
940 #define eN if_stack
941 #define eM {return yK2(
942 #define eL n_as_sin_param
943 #define eK n_as_cos_param
944 #define eJ PowiResolver::
945 #define eI ];};extern"C"{
946 #define eH .BalanceGood
947 #define eG AddParamMove(
948 #define eF valueType
949 #define eE best_factor
950 #define eD back().endif_location
951 #define eC iC1(iJ1)
952 #define eB iC1 key
953 #define eA l8 2,1,
954 #define e9 130,1,
955 #define e8 MatchPositionSpecBase
956 #define e7 iF2 yL2(
957 #define e6 smallest_maximum
958 #define e5 goto redo;
959 #define e4 ++IP;y81}if(xW3 xV3.
960 #define e3 ReplaceTreeWithParam0;
961 #define e2 factor_needs_rehashing
962 #define e1 MatchPositionSpecBaseP
963 #define e0 nL eS1(-y03;
964 #define cZ 79,112,113,117,118,123,124,127,128,
965 #define cY )l81 m cM3
966 #define cX e01 x8(nM.param_list,
967 #define cW relationships
968 #define cV 28,29,30,31,32,33,34,35,36,
969 #define cU cIf,l0 3,
970 #define cT lK 2},0,0x0},{{
971 #define cS data.subfunc_opcode
972 #define cR }if eD2.xJ1==eS1(
973 #define cQ otherhalf
974 #define cP :{AdoptChildrenWithSameOpcode(tree);
975 #define cO map<fphash_t,std::set<std::string> >
976 #define cN const SequenceOpCode x8
977 #define cM =fp_cosh(m.min);m.max=fp_cosh(m.max);
978 #define cL MatchPositionSpec_PositionalParams x8
979 #define cK eS1(1.5)*fp_const_pi x8()
980 #define cJ !=Unchanged nZ2 iZ1
981 #define cI FoundChild
982 #define cH CalculatePowiFactorCost(
983 #define cG T1,typename T2>inline i12()(
984 #define cF yK2 tmp;tmp tU
985 #define cE has_nonlogical_values
986 #define cD from_logical_context)
987 #define cC for xK2 xW.cN3 a-->0;)
988 #define cB POWI_CACHE_SIZE
989 #define cA static inline yK2
990 #define c9 BalanceResultType
991 #define c8 cIf,eL3
992 #define c7 nA3(0),Opcode(
993 #define c6 const{return data->
994 #define c5 +=fp_const_twopi x8();
995 #define c4 .AddOperation(lM2,
996 #define c3 for xK2 0;a<cN3++a){if(
997 #define c2 static void MakeHash(nD fphash_t&iU,
998 #define c1 l2 2,
999 #define c0 MatchPositionSpec_AnyWhere
1000 #define yZ if iZ2 data.match_type==
1001 #define yY }PACKED_GRAMMAR_ATTRIBUTE;
1002 #define yX ,cGreaterOrEq l7 2,2,
1003 #define yW void OutFloatHex(std::ostream&o,
1004 #define yV yV1 x72 range x8::
1005 #define yU b;}};n73<>e92 Comp<
1006 #define yT eT CodeTreeImmed(
1007 #define yS xK2 0;a<iT;++a)
1008 #define yR t93 115824 tS 122999,
1009 #define yQ t93 129136 tS 128123,
1010 #define yP t93 472176 tS 24699,
1011 #define yO ,typename yK2::
1012 #define yN AssembleSequence_Subdivide(
1013 #define yM 0x80000000u
1014 #define yL .push_back(
1015 #define yK !=eK2){lJ1
1016 #define yJ ;yK2
1017 #define yI nZ2 false;
1018 #define yH paramholder_matches
1019 #define yG std::vector
1020 #define yF ,AnyParams,0 l1 0,1,
1021 #define yE ;iJ 2,
1022 #define yD for(lE3 r=range.first;r!=range eE3;++r){
1023 #define yC eT tree lD
1024 #define yB ComparisonSetBase::
1025 #define yA .eG
1026 #define y9 branch2
1027 #define y8 fp_const_twopi x8());if(
1028 #define y7 n73 set_min_max_if<cGreater>(eS1(0),
1029 #define y6 iM tree lD
1030 #define y5 =y6 0));range x8
1031 #define y4 tree lD 1).xJ1
1032 #define y3 x02;tH
1033 #define y2 lX&&tree lD 1)y21
1034 #define y1 factor_stack_base
1035 #define y0 cPow,l6 2,
1036 #define xZ GroupFunction,0},n0{{
1037 #define xY data->c93
1038 #define xX =0;a<nU3.cN3++a)if(
1039 #define xW branch1
1040 #define xV {lK2.erase(i);y81}
1041 #define xU xK2 iT;a-->0;)
1042 #define xT nM xY2
1043 #define xS i02 c;i02 char l[
1044 #define xR 158,167,168,169,178,179,191,195,203,207,215,227,229,232,233,234,235,236,239,240,241,242,245,246,247,248,250,251}};}e92
1045 #define xQ using iO2 FUNCTIONPARSERTYPES;
1046 #define xP const eY=std::cout
1047 #define xO IsIdenticalTo(leaf2 lD
1048 #define xN FPOPT_autoptr
1049 #define xM +=result l81 result;}yV1 inline eS1
1050 #define xL int_exponent
1051 #define xK newnode
1052 #define xJ l3 2,1,
1053 #define xI ParamSpec_SubFunction
1054 #define xH ParamSpec_ParamHolder
1055 #define xG has_highlevel_opcodes
1056 #define xF {if(needs_cow){iY goto
1057 #define xE ;if(fp_nequal(tmp,eS1(0)))lL eS1(1)/tmp)n5}lC
1058 #define xD },{l4::Unchanged,l4::Never},{l4::Unchanged,l4::Never}}
1059 #define xC best_selected_sep
1060 #define xB ->Recalculate_Hash_NoRecursion();}
1061 #define xA fp_sin(min),fp_sin(max))
1062 #define x9 sim.AddConst(
1063 #define x8 <eS1>
1064 #define x7 :nG1 tmp,tmp2;tmp2 tU
1065 #define x6 position
1066 #define x5 GetStackTop()-
1067 #define x4 for yS{range x8
1068 #define x3 SwapLastTwoInStack();
1069 #define x2 FPoptimizer_CodeTree::yK2&tree
1070 #define x1 SetParam(0,iH2 lD 0))yJ p1;p1 tU
1071 #define x0 TestImmedConstraints(param t42,tree)yI
1072 #define nZ {tree.FixIncompleteHashes();}
1073 #define nY {yE3 cInv nW2 x9-1 e21
1074 #define nX paramholder_index
1075 #define nW return true;case
1076 #define nV occurance_counts
1077 #define nU PositionalParams,0},0,
1078 #define nT xQ xD1 tA-1);
1079 #define nS ;synth.yZ2*this)l81;}
1080 #define nR ,l0 1,
1081 #define nQ );a-->0;){lM1&powgroup=lT1;if(powgroup
1082 #define nP ;a<iT;++a)if(ApplyGrammar(tN2,xI2,
1083 #define nO lK 1},0,0x0},{{
1084 #define nN ByteCode
1085 #define nM model_tree
1086 #define nL return range x8(
1087 #define nK yG nV1&l02
1088 #define nJ ConstantFolding_LogicCommon(tree,yB
1089 #define nI eS1>p xO3 p.
1090 #define nH nT1 Ref>inline void xN<Ref>::
1091 #define nG ;tmp2 yC 0 y43 cInv);tmp yY3 l81
1092 #define nF ):data(new nO2 x8(
1093 #define nE .lM2
1094 #define nD FUNCTIONPARSERTYPES::
1095 #define nC iJ1(),c93(),Hash(),Depth(1),eZ1 0){}
1096 #define nB SynthesizeByteCode(synth);
1097 #define nA nO2 x8::nO2(
1098 #define n9 crc=(key>>10)|(key<<(64-10))eC2((~iC1(crc))*3)^1234567;}};
1099 #define n8 GetIntegerInfo nW1 0))==IsAlways)lN3
1100 #define n7 eS1(*const func)(eS1),range x8 model){
1101 #define n6 e72.xJ1
1102 #define n5 ;goto do_return;}
1103 #define n4 while(ApplyGrammar(i01 Grammar&)
1104 #define n3 DumpParams x8 iZ2 data.param_list,xF3 data xY2,o);
1105 #define n2 restholder_index
1106 #define n1 yK2 cE2;cE2 e53 cE2 eT
1107 #define n0 yL1,0x0},
1108 #define lZ t51 1},0,
1109 #define lY ;tree yA n41)nS2
1110 #define lX l23 y21
1111 #define lW eG pow x03;pow.iH1 1);pow.Rehash(tT.nC1 0,pow);goto NowWeAreMulGroup;}
1112 #define lV {cF cPow);y53;tmp yT eS1(
1113 #define lU :if(ParamComparer x8()(c93[1],c93[0])){std::swap(c93[0],c93[1]);Opcode=
1114 #define lT <typename eS1>
1115 #define lS ,eS1(1)/eS1(
1116 #define lR SetParam(0,e72 lD 0)xK1 1,CodeTreeImmed(
1117 #define lQ restholder_matches
1118 #define lP SelectedParams,0},0,0x0},{{
1119 #define lO n41;n41 xQ2 n41 yA e72);n41 eT xW lD
1120 #define lN *const func)(eS1),range x8 model=range x8());
1121 #define lM yV1 yK2::yL2(
1122 #define lL {tree.ReplaceWithImmed(
1123 #define lK cMul,AnyParams,
1124 #define lJ cMul,SelectedParams,0},0,
1125 #define lI cPow,l0 2
1126 #define lH iM tmp)cM3
1127 #define lG :cC3=comp.AddRelationship(atree lD 0),atree lD 1),yB
1128 #define lF typename eS1>i12()i01 eS1&a,e62 b){return a
1129 #define lE t51 0 l1
1130 #define lD .GetParam(
1131 #define lC break;case
1132 #define lB {range x8 m=y6 0));
1133 #define lA xB1 yK2::
1134 #define l9 ?0:1))yJ n41;n41 xQ2 n41 tI1 tree.iE1));n41 y3
1135 #define l8 lK 0 l1
1136 #define l7 ,PositionalParams,0 l1
1137 #define l6 nU iR
1138 #define l5 cAdd,lP 2,
1139 #define l4 RangeComparisonData
1140 #define l3 PositionalParams,0}},{ProduceNewTree,
1141 #define l2 lJ 0x0},{{
1142 #define l1 }},{ReplaceParams,
1143 #define l0 nU 0x0},{{
1144 #ifdef _MSC_VER
1145 typedef
1146 i02
1147 int
1148 iD1;
1149 #else
1150 #include <stdint.h>
1151 typedef
1152 uint_least32_t
1153 iD1;
1154 #endif
1155 iO2
1156 crc32{enum{startvalue=0xFFFFFFFFUL,poly=0xEDB88320UL}
1157 ;n73<iD1
1158 crc>e92
1159 b8{enum{b1=(crc
1160 l03
1161 crc
1162 nP2
1163 crc>>1),b2=(b1
1164 l03
1165 b1
1166 nP2
1167 b1>>1),b3=(b2
1168 l03
1169 b2
1170 nP2
1171 b2>>1),b4=(b3
1172 l03
1173 b3
1174 nP2
1175 b3>>1),b5=(b4
1176 l03
1177 b4
1178 nP2
1179 b4>>1),b6=(b5
1180 l03
1181 b5
1182 nP2
1183 b5>>1),b7=(b6
1184 l03
1185 b6
1186 nP2
1187 b6>>1),res=(b7
1188 l03
1189 b7
1190 nP2
1191 b7>>1)}
1192 ;}
1193 ;inline
1194 iD1
1195 update(iD1
1196 crc,i02
1197 b){
1198 #define B4(n) b8<n>iL2 n+1>iL2 n+2>iL2 n+3>::res
1199 #define R(n) B4(n),B4(n+4),B4(n+8),B4(n+12)
1200 static
1201 const
1202 iD1
1203 table[256]={R(0x00),R(0x10),R(0x20),R(0x30),R(0x40),R(0x50),R(0x60),R(0x70),R(0x80),R(0x90),R(0xA0),R(0xB0),R(0xC0),R(0xD0),R(0xE0),R(0xF0)}
1204 ;
1205 #undef R
1206 #undef B4
1207 return((crc>>8))^table[(crc^b)&0xFF];i6
1208 iD1
1209 calc_upd(iD1
1210 c,const
1211 i02
1212 char*buf,size_t
1213 size){iD1
1214 value=c;for(size_t
1215 p=0;p<size;++p)value=update(value,buf[p])l81
1216 value;i6
1217 iD1
1218 calc
1219 i01
1220 i02
1221 char*buf,size_t
1222 size){return
1223 calc_upd(startvalue,buf,size);}
1224 }
1225 #ifndef FPOptimizerAutoPtrHH
1226 #define FPOptimizerAutoPtrHH
1227 nT1
1228 Ref>class
1229 xN{e13
1230 xN():p(0){}
1231 xN(Ref*b):p(b){n93}
1232 xN
1233 i01
1234 xN&b):p(b.p){n93
1235 i6
1236 Ref&e31*(n61*p;i6
1237 Ref*e31->(n61
1238 p;}
1239 xN&e31=(Ref*b){Set(b)l81*this;}
1240 xN&e31=i01
1241 xN&b){Set(b.p)l81*this;}
1242 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1243 xN(xN&&b):p(b.p){b.p=0;}
1244 xN&e31=(xN&&b){if(p!=b.p){cF2;p=b.p;b.p=0;}
1245 return*this;}
1246 #endif
1247 ~xN(){cF2
1248 iS2
1249 UnsafeSetP(Ref*newp){p=newp
1250 iS2
1251 swap(xN<Ref>&b){Ref*tmp=p;p=b.p;b.p=tmp;}
1252 private:inline
1253 static
1254 void
1255 Have(Ref*p2);inline
1256 void
1257 cF2;inline
1258 void
1259 n93
1260 inline
1261 void
1262 Set(Ref*p2);private:Ref*p;}
1263 ;nH
1264 cF2{if(!p
1265 nZ2;p->nA3-=1;if(!p->nA3)delete
1266 p;}
1267 nH
1268 Have(Ref*p2){if(p2)++(p2->nA3);}
1269 nH
1270 Birth(){Have(p);}
1271 nH
1272 Set(Ref*p2){Have(p2);cF2;p=p2;}
1273 #endif
1274 #include <utility>
1275 e92
1276 Compare2ndRev{nT1
1277 T>inline
1278 i12()i01
1279 T&nB3
1280 T&b
1281 n61
1282 a
1283 eE3>b
1284 eE3;}
1285 }
1286 ;e92
1287 Compare1st{nT1
1288 cG
1289 const
1290 nU1
1291 nB3
1292 nU1
1293 b
1294 n61
1295 a.first<b.first;}
1296 nT1
1297 cG
1298 const
1299 nU1
1300 a,T1
1301 b
1302 n61
1303 a.first<b;}
1304 nT1
1305 cG
1306 T1
1307 nB3
1308 nU1
1309 b
1310 n61
1311 a<b.first;}
1312 }
1313 ;
1314 #ifndef FPoptimizerHashHH
1315 #define FPoptimizerHashHH
1316 #ifdef _MSC_VER
1317 typedef
1318 i02
1319 long
1320 long
1321 iC1;
1322 #define FPHASH_CONST(x) x##ULL
1323 #else
1324 #include <stdint.h>
1325 typedef
1326 uint_fast64_t
1327 iC1;
1328 #define FPHASH_CONST(x) x##ULL
1329 #endif
1330 iO2
1331 FUNCTIONPARSERTYPES{e92
1332 fphash_t{iC1
1333 hash1,hash2;fphash_t():hash1(0),hash2(0){}
1334 fphash_t
1335 i01
1336 iC1&nB3
1337 iC1&b):hash1(a),hash2(b){}
1338 i12==i01
1339 fphash_t&n51==iM2&&hash2==iN2
1340 i12!=i01
1341 fphash_t&n51!=iM2||hash2!=iN2
1342 i12<i01
1343 fphash_t&n51!=iM2?hash1<iM2:hash2<iN2}
1344 ;}
1345 #endif
1346 #ifndef FPOptimizer_CodeTreeHH
1347 #define FPOptimizer_CodeTreeHH
1348 #ifdef FP_SUPPORT_OPTIMIZER
1349 #include <vector>
1350 #include <utility>
1351 iO2
1352 l41{e92
1353 Grammar;}
1354 t5{iP2
1355 ByteCodeSynth;}
1356 iO2
1357 FPoptimizer_CodeTree{iP2
1358 yL2;yT1
1359 nO2;iP2
1360 yL2{typedef
1361 xN<nO2
1362 x8>DataP;DataP
1363 data;e13
1364 yL2();~yL2();e92
1365 OpcodeTag{}
1366 ;e7
1367 nR2
1368 o,OpcodeTag);e92
1369 FuncOpcodeTag{}
1370 ;e7
1371 nR2
1372 o,i02
1373 f,FuncOpcodeTag);e92
1374 nC3{}
1375 ;e7
1376 e62
1377 v,nC3);
1378 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1379 e7
1380 eS1&&v,nC3);
1381 #endif
1382 e92
1383 VarTag{}
1384 ;e7
1385 i02
1386 varno,VarTag);e92
1387 CloneTag{}
1388 ;e7
1389 iQ2
1390 b,CloneTag);void
1391 GenerateFrom
1392 i01
1393 n81
1394 const
1395 nQ2
1396 const
1397 typename
1398 FunctionParserBase
1399 x8::Data&data,bool
1400 keep_powi=false);void
1401 GenerateFrom
1402 i01
1403 n81
1404 const
1405 nQ2
1406 const
1407 typename
1408 FunctionParserBase
1409 x8::Data&data,const
1410 i22
1411 nK2,bool
1412 keep_powi=false);void
1413 SynthesizeByteCode(n81
1414 nQ2
1415 size_t&stacktop_max);void
1416 SynthesizeByteCode(yW2&synth,bool
1417 MustPopTemps=true)const;size_t
1418 SynthCommonSubExpressions(yV2
1419 lP1
1420 const;void
1421 SetParams
1422 i01
1423 i22
1424 nD3
1425 SetParamsMove(i22
1426 eU1
1427 yL2
1428 GetUniqueRef();
1429 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1430 void
1431 SetParams(yG<yL2>&&eU1
1432 #endif
1433 void
1434 SetParam(size_t
1435 which,iQ2
1436 b);void
1437 nC1
1438 size_t
1439 which,nI2
1440 b);void
1441 AddParam
1442 i01
1443 nI2
1444 param);void
1445 eG
1446 nI2
1447 param);void
1448 AddParams
1449 i01
1450 i22
1451 nD3
1452 AddParamsMove(i22
1453 nD3
1454 AddParamsMove(i22
1455 l02,size_t
1456 l12);void
1457 iH1
1458 size_t
1459 index);void
1460 DelParams();void
1461 Become
1462 i01
1463 nI2
1464 b);inline
1465 size_t
1466 GetParamCount(n61
1467 iE1)yA3;i6
1468 nI2
1469 GetParam(xL3){return
1470 iE1)[n];i6
1471 iQ2
1472 GetParam(xL3
1473 n61
1474 iE1)[n];i6
1475 void
1476 lI2
1477 nR2
1478 o)cX3
1479 Opcode=o;i6
1480 nR2
1481 lM2
1482 c6
1483 Opcode;i6
1484 nD
1485 fphash_t
1486 GetHash()c6
1487 Hash;i6
1488 const
1489 i22
1490 iE1
1491 n61
1492 xY;i6
1493 i22
1494 iE1){return
1495 xY;i6
1496 size_t
1497 xT2
1498 c6
1499 Depth;i6
1500 e62
1501 xJ1
1502 c6
1503 Value;i6
1504 i02
1505 GetVar()c6
1506 iI1
1507 i6
1508 i02
1509 GetFuncNo()c6
1510 iI1
1511 i6
1512 bool
1513 IsDefined(n61
1514 lM2!=nD
1515 cNop;i6
1516 bool
1517 IsImmed(n61
1518 lM2==nD
1519 cImmed;i6
1520 bool
1521 IsVar(n61
1522 lM2==nD
1523 iE2;i6
1524 i02
1525 GetRefCount()c6
1526 nA3
1527 iS2
1528 ReplaceWithImmed
1529 i01
1530 eS1&i);void
1531 Rehash(bool
1532 constantfolding=true);void
1533 Sort();inline
1534 void
1535 Mark_Incompletely_Hashed()cX3
1536 Depth=0;i6
1537 bool
1538 Is_Incompletely_Hashed()c6
1539 Depth==0;i6
1540 const
1541 tK
1542 GetOptimizedUsing()c6
1543 iK1;i6
1544 void
1545 SetOptimizedUsing
1546 i01
1547 tK
1548 g)cX3
1549 iK1=g;}
1550 bool
1551 RecreateInversionsAndNegations(bool
1552 prefer_base2=false);void
1553 FixIncompleteHashes();void
1554 swap(nI2
1555 b){data.swap(b.data);}
1556 bool
1557 IsIdenticalTo
1558 i01
1559 nI2
1560 b)const;void
1561 iY}
1562 ;yT1
1563 nO2{int
1564 nA3;nR2
1565 Opcode;eS1
1566 Value;i02
1567 iI1
1568 yG
1569 nV1
1570 c93;nD
1571 fphash_t
1572 Hash;size_t
1573 Depth;const
1574 tK
1575 iK1;nO2();nO2
1576 i01
1577 nO2&b);i1
1578 nR2
1579 o);i1
1580 nR2
1581 o,i02
1582 f);i1
1583 e62
1584 i);
1585 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1586 i1
1587 eS1&&i);nO2(nO2&&b);
1588 #endif
1589 bool
1590 IsIdenticalTo
1591 i01
1592 nO2&b)const;void
1593 Sort();void
1594 Recalculate_Hash_NoRecursion();private:void
1595 e31=i01
1596 nO2&b);}
1597 ;yU1
1598 CodeTreeImmed
1599 i01
1600 eS1&i)eM
1601 i
1602 yO
1603 nC3());}
1604 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1605 yU1
1606 CodeTreeImmed(eS1&&i)eM
1607 t72
1608 i)yO
1609 nC3());}
1610 #endif
1611 yU1
1612 CodeTreeOp(nR2
1613 opcode)eM
1614 opcode
1615 yO
1616 OpcodeTag());}
1617 yU1
1618 CodeTreeFuncOp(nR2
1619 opcode,i02
1620 f)eM
1621 opcode,f
1622 yO
1623 FuncOpcodeTag());}
1624 yU1
1625 CodeTreeVar
1626 iL1
1627 varno)eM
1628 varno
1629 yO
1630 VarTag());}
1631 #ifdef FUNCTIONPARSER_SUPPORT_DEBUGGING
1632 xB1
1633 DumpHashes(xP);xB1
1634 xE3(xP);xB1
1635 DumpTreeWithIndent(xP,const
1636 std::string&indent="\\"
1637 );
1638 #endif
1639 }
1640 #endif
1641 #endif
1642 #ifndef FPOPT_NAN_CONST
1643 #include <iostream>
1644 #define FPOPT_NAN_CONST (-1712345.25)
1645 iO2
1646 FPoptimizer_CodeTree{iP2
1647 yL2;}
1648 iO2
1649 l41{enum
1650 ImmedConstraint_Value{ValueMask=0x07,Value_AnyNum=0x0,n12=0x1,Value_OddInt=0x2,t01=0x3,Value_NonInteger=0x4,eE1=0x5
1651 n23
1652 ImmedConstraint_Sign{SignMask=0x18,Sign_AnySign=0x00,nJ1=0x08,n02=0x10,Sign_NoIdea=0x18
1653 n23
1654 ImmedConstraint_Oneness{OnenessMask=0x60,Oneness_Any=0x00,Oneness_One=0x20,Oneness_NotOne=0x40
1655 n23
1656 ImmedConstraint_Constness{ConstnessMask=0x180,Constness_Any=0x00,yL1=0x80,Constness_NotConst=0x100
1657 n23
1658 Modulo_Mode{Modulo_None=0,Modulo_Radians=1
1659 n23
1660 Situation_Flags{LogicalContextOnly=0x01,NotForIntegers=0x02,OnlyForIntegers=0x04
1661 n23
1662 lU2{NumConstant,ParamHolder,SubFunction
1663 n23
1664 ParamMatchingType{PositionalParams,SelectedParams,AnyParams,GroupFunction
1665 n23
1666 RuleType{ProduceNewTree,ReplaceParams}
1667 ;
1668 #ifdef __GNUC__
1669 # define PACKED_GRAMMAR_ATTRIBUTE __attribute__((packed))
1670 #else
1671 # define PACKED_GRAMMAR_ATTRIBUTE
1672 #endif
1673 typedef
1674 std::pair<lU2,const
1675 void*>cG2;yV1
1676 cG2
1677 e01
1678 iL1
1679 paramlist,lC1);xG1
1680 ParamSpec_Compare
1681 i01
1682 void*nB3
1683 void*b,lU2
1684 type);i02
1685 ParamSpec_GetDepCode
1686 i01
1687 cG2&b);e92
1688 xH{lC1:8;i02
1689 constraints:9;i02
1690 depcode:15;yY
1691 yT1
1692 ParamSpec_NumConstant{eS1
1693 xZ3;i02
1694 modulo;yY
1695 e92
1696 iW{i02
1697 param_count:2;i02
1698 param_list:30;nR2
1699 subfunc_opcode:8;ParamMatchingType
1700 match_type:3;i02
1701 n2:5;yY
1702 e92
1703 xI{iW
1704 data;i02
1705 constraints:9;i02
1706 depcode:7;yY
1707 e92
1708 Rule{RuleType
1709 ruletype:2;i02
1710 situation_flags:3;i02
1711 repl_param_count:2+11;i02
1712 repl_param_list:30;iW
1713 match_tree;yY
1714 e92
1715 Grammar{i02
1716 rule_count;i02
1717 char
1718 rule_list[999
1719 eI
1720 extern
1721 const
1722 Rule
1723 grammar_rules[];}
1724 xB1
1725 DumpParam
1726 i01
1727 cG2&p,std::ostream&o=std::cout);xB1
1728 DumpParams
1729 iL1
1730 paramlist,i02
1731 count,std::ostream&o=std::cout);}
1732 #endif
1733 #ifndef M_PI
1734 #define M_PI 3.1415926535897932384626433832795
1735 #endif
1736 #define CONSTANT_POS_INF HUGE_VAL
1737 #define CONSTANT_NEG_INF (-HUGE_VAL)
1738 iO2
1739 FUNCTIONPARSERTYPES{yV1
1740 inline
1741 eS1
1742 fp_const_pihalf(){return
1743 fp_const_pi
1744 x8()*yF3;}
1745 yV1
1746 inline
1747 eS1
1748 fp_const_twopi(){eS1
1749 cY3
1750 fp_const_pi
1751 x8());e03
1752 fp_const_twoe(){eS1
1753 cY3
1754 fp_const_e
1755 x8());e03
1756 fp_const_twoeinv(){eS1
1757 cY3
1758 fp_const_einv
1759 x8());e03
1760 fp_const_negativezero(){
1761 #ifdef FP_EPSILON
1762 return-fp_epsilon
1763 x8();
1764 #else
1765 return
1766 eS1(-1e-14);
1767 #endif
1768 }
1769 }
1770 #ifdef FP_SUPPORT_OPTIMIZER
1771 #include <vector>
1772 #include <utility>
1773 #include <iostream>
1774 iO2
1775 FPoptimizer_Optimize{using
1776 iO2
1777 l41;using
1778 iO2
1779 FPoptimizer_CodeTree;xQ
1780 iP2
1781 MatchInfo{e13
1782 yG<std::pair<bool,yG
1783 nV1> >lQ;yG
1784 nV1
1785 yH;yG<i02>iB;e13
1786 MatchInfo():lQ(),yH(),iB(){}
1787 e13
1788 bool
1789 SaveOrTestRestHolder
1790 iL1
1791 n2,lL1&tM1){cL1{lQ
1792 nE3
1793 n2+1);lQ
1794 tL=tM1
1795 nS2
1796 if(lQ[n2
1797 eC3==false){lQ
1798 tL=tM1
1799 nS2
1800 lL1&found=lQ[n2
1801 eD3;if(tM1
1802 yA3!=found
1803 yA3
1804 yI
1805 for
1806 xK2
1807 0;a<tM1
1808 eW2
1809 a)if(!tM1[a]iA
1810 found[a])yI
1811 return
1812 true
1813 iS2
1814 SaveRestHolder
1815 iL1
1816 n2,yG
1817 nV1&tM1){cL1
1818 lQ
1819 nE3
1820 n2+1);lQ
1821 tL.swap(tM1);}
1822 bool
1823 SaveOrTestParamHolder
1824 iL1
1825 nX,lM1&nG3){if(yH
1826 yA3<=nX){yH.nH3
1827 nX+1);yH
1828 nE3
1829 nX);yH
1830 yL
1831 nG3)nS2
1832 if(!yH[nX].iA1{yH[nX]=nG3
1833 nS2
1834 return
1835 nG3
1836 iA
1837 yH[nX]iR2
1838 SaveMatchedParamIndex(lC1){iB
1839 yL
1840 index);}
1841 lM1&GetParamHolderValueIfFound
1842 iL1
1843 nX)const{static
1844 lM1
1845 dummytree;if(yH
1846 yA3<=nX
1847 nZ2
1848 dummytree
1849 l81
1850 yH[nX];}
1851 lM1&GetParamHolderValue
1852 iL1
1853 nX
1854 n61
1855 yH[nX];}
1856 bool
1857 HasRestHolder
1858 iL1
1859 n2
1860 n61
1861 lQ
1862 yA3>n2&&lQ[n2
1863 eC3==true;}
1864 lL1&GetRestHolderValues
1865 iL1
1866 n2)const{static
1867 lL1
1868 empty_result;cL1
1869 return
1870 empty_result
1871 l81
1872 lQ[n2
1873 eD3;}
1874 const
1875 yG<i02>&GetMatchedParamIndexes(n61
1876 iB
1877 iS2
1878 swap(t9
1879 b){lQ.swap(b.lQ);yH.swap(b.yH);iB.swap(b.iB);}
1880 t9
1881 e31=i01
1882 t9
1883 b){lQ=b.lQ;yH=b.yH;iB=b.iB
1884 l81*this;}
1885 }
1886 ;class
1887 e8;typedef
1888 xN<e8>e1;class
1889 e8{e13
1890 int
1891 nA3;e13
1892 e8():nA3(0){}
1893 virtual~e8(){}
1894 }
1895 ;e92
1896 lZ1{bool
1897 found;e1
1898 specs;lZ1(bool
1899 f):found(f),specs(){}
1900 lZ1(bool
1901 f
1902 eA2
1903 s):found(f),specs(s){}
1904 }
1905 ;xB1
1906 SynthesizeRule
1907 eX3
1908 yK2&tree,t9
1909 info);yV1
1910 lZ1
1911 TestParam
1912 i01
1913 cG2&xZ2
1914 lM1&tree
1915 eA2
1916 start_at,t9
1917 info);yV1
1918 lZ1
1919 TestParams(t0&nM,lM1&tree
1920 eA2
1921 start_at,t9
1922 info,bool
1923 tA1;xG1
1924 ApplyGrammar
1925 i01
1926 Grammar&tN2,x2,bool
1927 from_logical_context=false);xB1
1928 ApplyGrammars(x2);xG1
1929 IsLogisticallyPlausibleParamsMatch(t0&cB2,const
1930 eR;}
1931 iO2
1932 l41{xB1
1933 DumpMatch
1934 eX3
1935 const
1936 x2,const
1937 FPoptimizer_Optimize::t9
1938 info,bool
1939 DidMatch,std::ostream&o=std::cout);xB1
1940 DumpMatch
1941 eX3
1942 const
1943 x2,const
1944 FPoptimizer_Optimize::t9
1945 info,const
1946 char*eY3,std::ostream&o=std::cout);}
1947 #endif
1948 #include <string>
1949 eG2
1950 l41::lU2
1951 yK1=false);eG2
1952 nR2
1953 yK1=false);
1954 #include <string>
1955 #include <sstream>
1956 #include <assert.h>
1957 #include <iostream>
1958 using
1959 iO2
1960 l41;xQ
1961 eG2
1962 l41::lU2
1963 yK1){
1964 #if 1
1965 const
1966 char*p=0;switch(opcode
1967 iY2
1968 NumConstant:p="NumConstant"
1969 ;lC
1970 ParamHolder:p="ParamHolder"
1971 ;lC
1972 SubFunction:p="SubFunction"
1973 ;nM3
1974 std::ostringstream
1975 tmp;assert(p);tmp<<p;if(pad)while(tmp.str()yA3<12)tmp<<' 'l81
1976 tmp.str();
1977 #else
1978 std::ostringstream
1979 tmp;tmp<<opcode;if(pad)while(tmp.str()yA3<5)tmp<<' 'l81
1980 tmp.str();
1981 #endif
1982 }
1983 eG2
1984 nR2
1985 yK1){
1986 #if 1
1987 const
1988 char*p=0;switch(opcode
1989 iY2
1990 cAbs:p="cAbs"
1991 ;lC
1992 cAcos:p="cAcos"
1993 ;lC
1994 cAcosh:p="cAcosh"
1995 ;lC
1996 cAsin:p="cAsin"
1997 ;lC
1998 cAsinh:p="cAsinh"
1999 ;lC
2000 cAtan:p="cAtan"
2001 ;lC
2002 cAtan2:p="cAtan2"
2003 ;lC
2004 cAtanh:p="cAtanh"
2005 ;lC
2006 cCbrt:p="cCbrt"
2007 ;lC
2008 cCeil:p="cCeil"
2009 ;lC
2010 cCos:p="cCos"
2011 ;lC
2012 cCosh:p="cCosh"
2013 ;lC
2014 cCot:p="cCot"
2015 ;lC
2016 cCsc:p="cCsc"
2017 ;lC
2018 cEval:p="cEval"
2019 ;lC
2020 cExp:p="cExp"
2021 ;lC
2022 cExp2:p="cExp2"
2023 ;lC
2024 cFloor:p="cFloor"
2025 ;lC
2026 cHypot:p="cHypot"
2027 ;lC
2028 cIf:p="cIf"
2029 ;lC
2030 cInt:p="cInt"
2031 ;lC
2032 cLog:p="cLog"
2033 ;lC
2034 cLog2:p="cLog2"
2035 ;lC
2036 cLog10:p="cLog10"
2037 ;lC
2038 cMax:p="cMax"
2039 ;lC
2040 cMin:p="cMin"
2041 ;lC
2042 cPow:p="cPow"
2043 ;lC
2044 cSec:p="cSec"
2045 ;lC
2046 cSin:p="cSin"
2047 ;lC
2048 cSinh:p="cSinh"
2049 ;lC
2050 cSqrt:p="cSqrt"
2051 ;lC
2052 cTan:p="cTan"
2053 ;lC
2054 cTanh:p="cTanh"
2055 ;lC
2056 cTrunc:p="cTrunc"
2057 ;lC
2058 cImmed:p="cImmed"
2059 ;lC
2060 cJump:p="cJump"
2061 ;lC
2062 cNeg:p="cNeg"
2063 ;lC
2064 cAdd:p="cAdd"
2065 ;lC
2066 cSub:p="cSub"
2067 ;lC
2068 cMul:p="cMul"
2069 ;lC
2070 cDiv:p="cDiv"
2071 ;lC
2072 cMod:p="cMod"
2073 ;lC
2074 cEqual:p="cEqual"
2075 ;lC
2076 t71:p="cNEqual"
2077 ;lC
2078 cLess:p="cLess"
2079 ;lC
2080 cLessOrEq:p="cLessOrEq"
2081 ;lC
2082 cGreater:p="cGreater"
2083 ;lC
2084 cGreaterOrEq:p="cGreaterOrEq"
2085 ;lC
2086 cNot:p="cNot"
2087 ;lC
2088 cAnd:p="cAnd"
2089 ;lC
2090 cOr:p="cOr"
2091 ;lC
2092 cDeg:p="cDeg"
2093 ;lC
2094 cRad:p="cRad"
2095 ;lC
2096 cFCall:p="cFCall"
2097 ;lC
2098 cPCall:p="cPCall"
2099 ;break;
2100 #ifdef FP_SUPPORT_OPTIMIZER
2101 case
2102 cFetch:p="cFetch"
2103 ;lC
2104 cPopNMov:p="cPopNMov"
2105 ;lC
2106 cLog2by:p="cLog2by"
2107 ;lC
2108 cNop:p="cNop"
2109 ;break;
2110 #endif
2111 case
2112 cSinCos:p="cSinCos"
2113 ;lC
2114 yR3:p="cAbsNot"
2115 ;lC
2116 cAbsNotNot:p="cAbsNotNot"
2117 ;lC
2118 cAbsAnd:p="cAbsAnd"
2119 ;lC
2120 cAbsOr:p="cAbsOr"
2121 ;lC
2122 i03:p="cAbsIf"
2123 ;lC
2124 cDup:p="cDup"
2125 ;lC
2126 cInv:p="cInv"
2127 ;lC
2128 cSqr:p="cSqr"
2129 ;lC
2130 cRDiv:p="cRDiv"
2131 ;lC
2132 cRSub:p="cRSub"
2133 ;lC
2134 cNotNot:p="cNotNot"
2135 ;lC
2136 cRSqrt:p="cRSqrt"
2137 ;lC
2138 iE2:p="VarBegin"
2139 ;nM3
2140 std::ostringstream
2141 tmp;assert(p);tmp<<p;if(pad)while(tmp.str()yA3<12)tmp<<' 'l81
2142 tmp.str();
2143 #else
2144 std::ostringstream
2145 tmp;tmp<<opcode;if(pad)while(tmp.str()yA3<5)tmp<<' 'l81
2146 tmp.str();
2147 #endif
2148 }
2149 #ifdef FP_SUPPORT_OPTIMIZER
2150 #include <vector>
2151 #include <utility>
2152 #ifndef FP_GENERATING_POWI_TABLE
2153 enum{MAX_POWI_BYTECODE_LENGTH=20}
2154 ;
2155 #else
2156 enum{MAX_POWI_BYTECODE_LENGTH=999}
2157 ;
2158 #endif
2159 enum{MAX_MULI_BYTECODE_LENGTH=3}
2160 ;t5{iP2
2161 ByteCodeSynth{e13
2162 ByteCodeSynth():nN(),Immed(),eP(),tA(0),StackMax(0){nN.nH3
2163 64);Immed.nH3
2164 8);eP.nH3
2165 16
2166 iR2
2167 Pull(yG<i02>&bc,yG
2168 x8&imm,size_t&StackTop_max){for
2169 iL1
2170 a=0;a<nN
2171 eW2
2172 a){nN[a]&=~yM;}
2173 nN.swap(bc);Immed.swap(imm);StackTop_max=StackMax;}
2174 size_t
2175 GetByteCodeSize(n61
2176 nN
2177 yA3;}
2178 size_t
2179 GetStackTop(n61
2180 tA
2181 iS2
2182 PushVar
2183 iL1
2184 varno){e23
2185 varno);nV2}
2186 void
2187 PushImmed(eS1
2188 immed){xQ
2189 e23
2190 cImmed);Immed
2191 yL
2192 immed);nV2}
2193 void
2194 StackTopIs
2195 cA3,int
2196 offset=0){if((int)tA>offset){eP[tA
2197 lN2
2198 first=true;eP[tA
2199 lN2
2200 second=tree;}
2201 }
2202 bool
2203 IsStackTop
2204 cA3,int
2205 offset=0
2206 n61(int)tA>offset&&eP[tA
2207 lN2
2208 first&&eP[tA
2209 lN2
2210 second
2211 iA
2212 tree);i6
2213 void
2214 EatNParams
2215 iL1
2216 cH2){tA-=cH2
2217 iS2
2218 ProducedNParams
2219 iL1
2220 e41){xD1
2221 tA+e41
2222 iR2
2223 AddOperation
2224 iL1
2225 opcode,i02
2226 cH2,i02
2227 e41=1){EatNParams(cH2);xQ
2228 AddFunctionOpcode(opcode);ProducedNParams(e41
2229 iR2
2230 DoPopNMov(size_t
2231 cI2,size_t
2232 srcpos){xQ
2233 e23
2234 cPopNMov);e23
2235 yM|iL1)cI2);e23
2236 yM|iL1)srcpos);xD1
2237 srcpos+1);eP[cI2]=eP[srcpos];xD1
2238 cI2+1
2239 iR2
2240 DoDup(size_t
2241 nI3){xQ
2242 if(nI3==tA-1){e23
2243 cDup);}
2244 else{e23
2245 cFetch);e23
2246 yM|iL1)nI3);}
2247 nV2
2248 eP[tA-1]=eP[nI3];}
2249 size_t
2250 e33
2251 cA3)const{for
2252 xK2
2253 tA;a-->0;)if(eP[a
2254 eC3&&eP[a
2255 eD3
2256 iA
2257 tree)nZ2
2258 a
2259 l81
2260 eK2;}
2261 bool
2262 Find
2263 cA3
2264 n61
2265 e33
2266 nO3
2267 eK2;}
2268 bool
2269 FindAndDup
2270 cA3){size_t
2271 pos=e33(tree);if(pos!=eK2){
2272 #ifdef DEBUG_SUBSTITUTIONS
2273 std::cout<<tZ3"duplicate at ["
2274 <<pos<<"]: "
2275 ;xE3(tree)lN1" -- issuing cDup or cFetch\n"
2276 ;
2277 #endif
2278 DoDup(pos)nS2
2279 nX2
2280 e92
2281 IfData{size_t
2282 ofs;}
2283 ;void
2284 SynthIfStep1(IfData&yJ2,nR2
2285 op){nT
2286 yJ2.ofs=nN
2287 yA3;e23
2288 op);e23
2289 yM);e23
2290 yM
2291 iR2
2292 SynthIfStep2(IfData&yJ2){nT
2293 nN[yJ2.ofs+1]eJ1+2);nN[yJ2.ofs
2294 iC
2295 yJ2.ofs=nN
2296 yA3;e23
2297 cJump);e23
2298 yM);e23
2299 yM
2300 iR2
2301 SynthIfStep3(IfData&yJ2){nT
2302 nN.back()|=yM;nN[yJ2.ofs+1]eJ1-1);nN[yJ2.ofs
2303 iC
2304 nV2
2305 for
2306 xK2
2307 0;a<yJ2.ofs;++a){if(nN[a]==cJump&&nN[a+1]==(yM|(yJ2.ofs-1))){nN[a+1]eJ1-1);nN[a
2308 iC
2309 yN3(nN[a]iY2
2310 i03:case
2311 cIf:case
2312 cJump:case
2313 cPopNMov:a+=2;lC
2314 cFCall:case
2315 cPCall:case
2316 cFetch:a+=1;break;default:nM3}
2317 }
2318 protected:void
2319 xD1
2320 size_t
2321 value){tA=value;if(tA
2322 eL2{StackMax=tA;yS1);}
2323 }
2324 void
2325 l51
2326 eK1;void
2327 iK
2328 eK1;void
2329 AddFunctionOpcode(eK1;private:yG<i02>nN;yG
2330 x8
2331 Immed;yG<std::pair<bool,FPoptimizer_CodeTree::yK2> >eP;size_t
2332 tA;size_t
2333 StackMax;}
2334 ;yT1
2335 SequenceOpCode;yT1
2336 eX1{static
2337 cN
2338 AddSequence;static
2339 cN
2340 MulSequence;}
2341 ;xB1
2342 x31
2343 long
2344 count,cN&eQ,lP1;}
2345 #endif
2346 #ifdef FP_SUPPORT_OPTIMIZER
2347 xQ
2348 t5{yT1
2349 SequenceOpCode{eS1
2350 basevalue;i02
2351 op_flip;i02
2352 op_normal,op_normal_flip;i02
2353 op_inverse,op_inverse_flip;}
2354 ;yV1
2355 cN
2356 eX1
2357 x8::AddSequence={eS1(0),cNeg,cAdd,cAdd,cSub,cRSub}
2358 ;yV1
2359 cN
2360 eX1
2361 x8::MulSequence={eS1(1),cInv,cMul,cMul,cDiv,cRDiv}
2362 ;yV1
2363 n71
2364 l51
2365 eK1{int
2366 mStackPtr=0;
2367 #define incStackPtr() do{if(tA+2 eL2 yS1=tA+2);}while(0)
2368 #define findName(a,b,c) "var"
2369 #define TryCompilePowi(o) false
2370 #define mData this
2371 #define mByteCode nN
2372 #define mImmed Immed
2373 # define FP_FLOAT_VERSION 1
2374 # include "fp_opcode_add.inc"
2375 # undef FP_FLOAT_VERSION
2376 #undef mImmed
2377 #undef mByteCode
2378 #undef mData
2379 #undef TryCompilePowi
2380 #undef incStackPtr
2381 }
2382 yV1
2383 n71
2384 iK
2385 eK1{int
2386 mStackPtr=0;
2387 #define incStackPtr() do{if(tA+2 eL2 yS1=tA+2);}while(0)
2388 #define findName(a,b,c) "var"
2389 #define TryCompilePowi(o) false
2390 #define mData this
2391 #define mByteCode nN
2392 #define mImmed Immed
2393 # define FP_FLOAT_VERSION 0
2394 # include "fp_opcode_add.inc"
2395 # undef FP_FLOAT_VERSION
2396 #undef mImmed
2397 #undef mByteCode
2398 #undef mData
2399 #undef TryCompilePowi
2400 #undef incStackPtr
2401 }
2402 yV1
2403 n71
2404 AddFunctionOpcode(eK1{if(IsIntType
2405 x8::result)iK
2406 opcode);else
2407 l51
2408 opcode);}
2409 }
2410 using
2411 t5;
2412 #define POWI_TABLE_SIZE 256
2413 #define POWI_WINDOW_SIZE 3
2414 t5{
2415 #ifndef FP_GENERATING_POWI_TABLE
2416 extern
2417 const
2418 i02
2419 char
2420 powi_table[POWI_TABLE_SIZE];const
2421 #endif
2422 i02
2423 char
2424 powi_table[POWI_TABLE_SIZE]={0,1,1,1,2,1
2425 eM2
2426 1,4,1,2,e43
2427 eM2
2428 1,8,cB3
2429 e73
2430 15,1,16,1
2431 eM2
2432 e43,2,1,4,cB3
2433 1,16,1,25,e73
2434 27,5,8,3,2,1,30,1,31,3,32,1
2435 eM2
2436 1,8,1,2,e73
2437 39,1,16,137,2,1,4,cB3
2438 e43,45,135,4,31,2,5,32,1,2,131,50,1,51,1,8,3,2,1,54,1,55,3,16,1,57,133,4,137,2,135,60,1,61,3,62,133,63,1,tN1
2439 131,tN1
2440 139,iM1
2441 e9
2442 30,1,130,137,2,31,iM1
2443 e9
2444 e9
2445 130,cB3
2446 1,e9
2447 e9
2448 2,1,130,133,tN1
2449 61,130,133,62,139,130,137,e9
2450 iM1
2451 e9
2452 e9
2453 tN1
2454 131,e9
2455 e9
2456 130,131,2,133,iM1
2457 130,141,e9
2458 130,cB3
2459 1,e9
2460 5,135,e9
2461 iM1
2462 e9
2463 iM1
2464 130,133,130,141,130,131,e9
2465 e9
2466 2,131}
2467 ;}
2468 static
2469 lX3
2470 cB=256;
2471 #define FPO(x)
2472 iO2{class
2473 PowiCache{private:int
2474 i7[cB];int
2475 tO1[cB];e13
2476 PowiCache():i7(),tO1(){i7[1]=1;}
2477 bool
2478 Plan_Add(yW1,int
2479 count){c51>=cB
2480 yI
2481 tO1[eP2+=count
2482 l81
2483 i7[eP2!=0
2484 iS2
2485 iU2
2486 yW1){c51<cB)i7[eP2=1
2487 iS2
2488 Start(size_t
2489 value1_pos){for(int
2490 n=2;n<cB;++n)i7[n]=-1;Remember(1,value1_pos);DumpContents();}
2491 int
2492 Find(yW1)const{c51<cB){if(i7[eP2>=0){FPO(tK3(tO3,"* I found %ld from cache (%u,%d)\n",value,(unsigned)cache[value],tL3 value]))l81
2493 i7[eP2;}
2494 }
2495 return-1
2496 iS2
2497 Remember(yW1,size_t
2498 tW3){c51>=cB
2499 nZ2;FPO(tK3(tO3,"* Remembering that %ld can be found at %u (%d uses remain)\n",value,(unsigned)tW3,tL3 value]));i7[eP2=(int)tW3
2500 iS2
2501 DumpContents()const{FPO(for(int a=1;a<POWI_CACHE_SIZE;++a)if(cache[a]>=0||tL3 a]>0){tK3(tO3,"== cache: sp=%d, val=%d, needs=%d\n",cache[a],a,tL3 a]);})}
2502 int
2503 UseGetNeeded(yW1){c51>=0&&value<cB
2504 nZ2--tO1[eP2
2505 l81
2506 0;}
2507 }
2508 ;yV1
2509 size_t
2510 yN
2511 long
2512 count
2513 tR1
2514 cN&eQ,lP1;xB1
2515 yX1
2516 size_t
2517 apos,long
2518 aval,size_t
2519 bpos,long
2520 bval
2521 tR1
2522 i02
2523 cumulation_opcode,i02
2524 cimulation_opcode_flip,lP1;void
2525 l61
2526 yW1
2527 tR1
2528 int
2529 need_count,int
2530 iX=0){c51<1
2531 nZ2;
2532 #ifdef FP_GENERATING_POWI_TABLE
2533 if(iX>32)throw
2534 false;
2535 #endif
2536 if(i7.Plan_Add(value,need_count)nZ2;long
2537 nJ3
2538 1;c51<POWI_TABLE_SIZE){nJ3
2539 powi_table[eP2
2540 iT2&128){half&=127
2541 iT2&64)nJ3-eQ2
2542 FPO(tK3(tO3,"value=%ld, half=%ld, otherhalf=%ld\n",value,half,value/half));l61
2543 half,yM2
2544 i7.iU2
2545 half)l81;}
2546 tP1
2547 half&64){nJ3-eQ2}
2548 }
2549 else
2550 c51&1)nJ3
2551 value&((1<<POWI_WINDOW_SIZE)-1);else
2552 nJ3
2553 value/2;long
2554 cQ=value-half
2555 iT2>cQ||half<0)std::swap(half,cQ);FPO(tK3(tO3,"value=%ld, half=%ld, otherhalf=%ld\n",value,half,otherhalf))iT2==cQ){l61
2556 half,i7,2,iX+1);}
2557 else{l61
2558 half,yM2
2559 l61
2560 cQ>0?cQ:-cQ,yM2}
2561 i7.iU2
2562 value);}
2563 yV1
2564 size_t
2565 yN
2566 yW1
2567 tR1
2568 cN&eQ,lP1{int
2569 nK3=i7.Find(value);if(nK3>=0){return
2570 nK3;}
2571 long
2572 nJ3
2573 1;c51<POWI_TABLE_SIZE){nJ3
2574 powi_table[eP2
2575 iT2&128){half&=127
2576 iT2&64)nJ3-eQ2
2577 FPO(tK3(tO3,"* I want %ld, my plan is %ld * %ld\n",value,half,value/half));size_t
2578 x52=yN
2579 half
2580 c61
2581 if(i7
2582 iN1
2583 half)>0||x52!=c71){tQ1
2584 x52)nU2
2585 half,c71);}
2586 x31
2587 value/half
2588 eR2
2589 size_t
2590 tW3=c71
2591 nU2
2592 value,tW3);i7.DumpContents()l81
2593 tW3;}
2594 tP1
2595 half&64){nJ3-eQ2}
2596 }
2597 else
2598 c51&1)nJ3
2599 value&((1<<POWI_WINDOW_SIZE)-1);else
2600 nJ3
2601 value/2;long
2602 cQ=value-half
2603 iT2>cQ||half<0)std::swap(half,cQ);FPO(tK3(tO3,"* I want %ld, my plan is %ld + %ld\n",value,half,value-half))iT2==cQ){size_t
2604 x52=yN
2605 half
2606 c61
2607 yX1
2608 x52,half,x52,half,i7,eQ.op_normal,eQ.op_normal_flip,synth);}
2609 else{long
2610 part1=half;long
2611 part2=cQ>0?cQ:-cQ;size_t
2612 part1_pos=yN
2613 part1
2614 c61
2615 size_t
2616 part2_pos=yN
2617 part2
2618 c61
2619 FPO(tK3(tO3,"Subdivide(%ld: %ld, %ld)\n",value,half,otherhalf));yX1
2620 part1_pos,part1,part2_pos,part2,i7,cQ>0?eQ.op_normal:eQ.op_inverse,cQ>0?eQ.op_normal_flip:eQ.op_inverse_flip,synth);}
2621 size_t
2622 tW3=c71
2623 nU2
2624 value,tW3);i7.DumpContents()l81
2625 tW3;}
2626 xB1
2627 yX1
2628 size_t
2629 apos,long
2630 aval,size_t
2631 bpos,long
2632 bval
2633 tR1
2634 i02
2635 cumulation_opcode,i02
2636 cumulation_opcode_flip,lP1{int
2637 a_needed=i7
2638 iN1
2639 aval);int
2640 nL3=i7
2641 iN1
2642 bval);bool
2643 iO1
2644 i13
2645 #define DUP_BOTH() do tX3<bpos){size_t tmp=apos;apos=bpos;bpos=tmp;iO1=!iO1;}FPO(tK3(tO3,"-> "tV3 tV3"op\n",(unsigned)apos,(unsigned)bpos));tQ1 apos);tQ1 apos==bpos?c71:bpos);}while(0)
2646 #define DUP_ONE(p) do{FPO(tK3(tO3,"-> "tV3"op\n",(unsigned)p));tQ1 p);}while(0)
2647 if(a_needed>0){if(nL3>0){lO2}
2648 else{if(bpos!=c71)lO2
2649 else{iP1
2650 iO1=!iO1;}
2651 }
2652 }
2653 tP1
2654 nL3>0)tX3!=c71)lO2
2655 else
2656 DUP_ONE(bpos);}
2657 else
2658 tX3==bpos&&apos==c71)iP1
2659 tP1
2660 apos==c71&&bpos==synth.x5
2661 2){FPO(tK3(tO3,"-> op\n"));iO1=!iO1;}
2662 tP1
2663 apos==synth.x5
2664 2&&bpos==c71)FPO(tK3(tO3,"-> op\n"));tP1
2665 apos==c71)DUP_ONE(bpos);tP1
2666 bpos==c71){iP1
2667 iO1=!iO1;}
2668 else
2669 lO2}
2670 lK1
2671 iO1?cumulation_opcode_flip:cumulation_opcode,2);}
2672 xB1
2673 cA1
2674 long
2675 count,cN&eQ,lP1{while
2676 cR3<256){int
2677 nJ3
2678 yV2
2679 powi_table[count]iT2&128){half&=127;cA1
2680 half
2681 eR2
2682 count/=half;}
2683 else
2684 nM3
2685 if
2686 cR3==1
2687 nZ2;if(!cR3&1)){lK1
2688 cSqr,1);cA1
2689 count/2
2690 eR2}
2691 else{tQ1
2692 c71);cA1
2693 count-1
2694 eR2
2695 lK1
2696 cMul,2);}
2697 }
2698 }
2699 t5{xB1
2700 x31
2701 long
2702 count,cN&eQ,lP1{if
2703 cR3==0)yX2
2704 eQ.basevalue
2705 t73
2706 bool
2707 eT2
2708 i13
2709 if
2710 cR3<0){eT2=true;count=-count;}
2711 if(false)cA1
2712 count
2713 eR2
2714 tP1
2715 count>1){PowiCache
2716 i7;l61
2717 count,i7,1);size_t
2718 xE1
2719 t13
2720 GetStackTop();i7.Start(c71);FPO(tK3(tO3,"Calculating result for %ld...\n",count));size_t
2721 x62=yN
2722 count
2723 c61
2724 size_t
2725 n_excess
2726 t13
2727 x5
2728 xE1;if(n_excess>0||x62!=xE1-1){synth.DoPopNMov(xE1-1,x62);}
2729 }
2730 if(eT2)lK1
2731 eQ.op_flip,1);}
2732 }
2733 }
2734 #endif
2735 #ifndef FPOptimizer_RangeEstimationHH
2736 #define FPOptimizer_RangeEstimationHH
2737 iO2
2738 FPoptimizer_CodeTree{enum
2739 TriTruthValue{IsAlways,yO3,Unknown}
2740 ;yT1
2741 range{eS1
2742 min,max;bool
2743 iV2,has_max;range():min(),max(),iV2(false
2744 cS3
2745 false)x43
2746 eS1
2747 mi,eS1
2748 ma):min(mi),max(ma),iV2(true
2749 cS3
2750 true)x43
2751 bool,eS1
2752 ma):min(),max(ma),iV2(false
2753 cS3
2754 true)x43
2755 eS1
2756 mi,bool):min(mi),max(),iV2(true
2757 cS3
2758 false){}
2759 void
2760 set_abs();void
2761 set_neg();x72
2762 set_min_max_if(iL
2763 x72
2764 set_min_if(iL
2765 x72
2766 set_max_if(iL
2767 void
2768 set_min(eS1(lN
2769 void
2770 set_max(eS1(lN
2771 void
2772 y82
2773 eS1(lN}
2774 ;yV1
2775 inline
2776 bool
2777 IsLogicalTrueValue
2778 i01
2779 range
2780 x8&p
2781 cD2
2782 if(p
2783 y41
2784 p.min>=0.5
2785 nZ2
2786 true;if(!abs&&p
2787 iW2<=-0.5
2788 nZ2
2789 true
2790 l81
2791 false;}
2792 yV1
2793 inline
2794 bool
2795 IsLogicalFalseValue
2796 i01
2797 range
2798 x8&p
2799 cD2
2800 if(abs
2801 nZ2
2802 p
2803 iW2<0.5;else
2804 return
2805 p
2806 y41
2807 p
2808 i0&&p.min>-0.5
2809 xQ3<0.5;}
2810 yV1
2811 range
2812 x8
2813 iM
2814 const
2815 eR;xG1
2816 IsLogicalValue
2817 i01
2818 eR;yV1
2819 TriTruthValue
2820 GetIntegerInfo
2821 i01
2822 eR;y51
2823 GetEvennessInfo
2824 i01
2825 eR{if(!tree
2826 y21
2827 nZ2
2828 Unknown;yF1=yZ3;if(isEvenInteger(value)nZ2
2829 x82
2830 isOddInteger(value)nZ2
2831 l71
2832 y51
2833 GetPositivityInfo
2834 i01
2835 eR{range
2836 x8
2837 p=iM
2838 tree);if(p
2839 y41
2840 p.min
2841 cH1
2842 nZ2
2843 x82
2844 p
2845 iW2
2846 t83
2847 nZ2
2848 l71
2849 y51
2850 GetLogicalValue(lM1&tree
2851 cD2
2852 range
2853 x8
2854 p=iM
2855 tree);if(IsLogicalTrueValue(p,abs)nZ2
2856 x82
2857 IsLogicalFalseValue(p,abs)nZ2
2858 l71}
2859 #endif
2860 #ifndef FPOptimizer_ConstantFoldingHH
2861 #define FPOptimizer_ConstantFoldingHH
2862 iO2
2863 FPoptimizer_CodeTree{xB1
2864 ConstantFolding(eR;}
2865 #endif
2866 iO2{xQ
2867 using
2868 iO2
2869 FPoptimizer_CodeTree;e92
2870 ComparisonSetBase{enum{e93=0x1,Eq_Mask=0x2,Le_Mask=0x3,eA3=0x4,eB3=0x5,Ge_Mask=0x6}
2871 ;static
2872 int
2873 Swap_Mask(int
2874 m){return(m&Eq_Mask)|((m&e93)?eA3:0)|((m&eA3)?e93:0);}
2875 enum
2876 yY1{Ok,BecomeZero,BecomeOne,xA2
2877 n23
2878 lV2{cond_or,i32,i42,i52}
2879 ;}
2880 ;yT1
2881 ComparisonSet:public
2882 ComparisonSetBase{e92
2883 eU2
2884 nG1
2885 a
2886 yJ
2887 b;int
2888 relationship;eU2():a(),b(),relationship(){}
2889 }
2890 ;yG<eU2>cW;e92
2891 Item
2892 nG1
2893 value;bool
2894 yN2;Item():value(),yN2(false){}
2895 }
2896 ;yG<Item>cB1;int
2897 xF1;ComparisonSet():cW(),cB1(),xF1(0){}
2898 yY1
2899 AddItem(lM1&a,bool
2900 yN2,lV2
2901 type){for(size_t
2902 c=0;c<cB1
2903 eW2
2904 c)if(cB1[c].value
2905 iA
2906 a)){if(yN2!=cB1[c].yN2){iN
2907 cM1
2908 case
2909 i52:cB1.erase(cB1.begin()+c);xF1+=1
2910 n01
2911 case
2912 i32:case
2913 i42:cN1}
2914 }
2915 return
2916 xA2;}
2917 Item
2918 pole;pole.value=a;pole.yN2=yN2;cB1
2919 yL
2920 pole)l81
2921 Ok;}
2922 yY1
2923 AddRelationship(yK2
2924 a,yK2
2925 b,int
2926 eY1,lV2
2927 type){iN
2928 cT3
2929 7)cM1
2930 lC
2931 i52:cT3
2932 7){xF1+=1
2933 n01}
2934 lC
2935 i32:case
2936 i42:cT3
2937 0)cN1
2938 nM3
2939 if(!(a.GetHash()<b.GetHash())){a.swap(b);eY1=Swap_Mask(eY1);}
2940 for(size_t
2941 c=0;c<cW
2942 eW2
2943 c){if(cW[c].a
2944 iA
2945 a)&&cW[c].b
2946 iA
2947 b)){iN{int
2948 nS3=x92|eY1;if(nS3==7)cM1
2949 x92=nS3;nM3
2950 case
2951 i32:case
2952 i42:{int
2953 nS3=x92&eY1;if(nS3==0)cN1
2954 x92=nS3;nM3
2955 case
2956 i52:{int
2957 newrel_or=x92|eY1;int
2958 xB2=x92&eY1;iQ1
2959 5&&xB2==0){x92=eB3
2960 n01}
2961 iQ1
2962 7&&xB2==0){xF1+=1;cW.erase(cW.begin()+c)n01}
2963 iQ1
2964 7&&xB2==Eq_Mask){x92=Eq_Mask;xF1+=1
2965 n01}
2966 y81}
2967 }
2968 return
2969 xA2;}
2970 }
2971 eU2
2972 comp;comp.a=a;comp.b=b;comp.relationship=eY1;cW
2973 yL
2974 comp)l81
2975 Ok;}
2976 }
2977 ;nT1
2978 eS1,typename
2979 CondType>bool
2980 ConstantFolding_LogicCommon(yK2&tree,CondType
2981 xA1,bool
2982 xC2){bool
2983 should_regenerate
2984 i13
2985 ComparisonSet
2986 x8
2987 comp
2988 eV3
2989 typename
2990 yB
2991 yY1
2992 cC3=yB
2993 Ok;lM1&atree=xI2;switch(atree
2994 nE
2995 iY2
2996 cEqual
2997 lG
2998 Eq_Mask
2999 eB2
3000 t71
3001 lG
3002 eB3
3003 eB2
3004 cLess
3005 lG
3006 e93
3007 eB2
3008 cLessOrEq
3009 lG
3010 Le_Mask
3011 eB2
3012 cGreater
3013 lG
3014 eA3
3015 eB2
3016 cGreaterOrEq
3017 lG
3018 Ge_Mask
3019 eB2
3020 cNot:cC3
3021 y11
3022 lD
3023 0),true
3024 eB2
3025 cNotNot:cC3
3026 y11
3027 lD
3028 0),false,xA1);break;default:if(xC2||IsLogicalValue(atree))cC3
3029 y11,false,xA1);yN3(cC3){ReplaceTreeWithZero
3030 xP3
3031 ReplaceWithImmed(0)l81
3032 true;ReplaceTreeWithOne
3033 xP3
3034 ReplaceWithImmed(1);nW
3035 yB
3036 Ok:lC
3037 yB
3038 BecomeZero:yP3
3039 yB
3040 BecomeOne
3041 tY
3042 yB
3043 xA2:c11
3044 nM3}
3045 if(should_regenerate){
3046 #ifdef DEBUG_SUBSTITUTIONS
3047 std::cout<<"Before ConstantFolding_LogicCommon: "
3048 eS
3049 #endif
3050 if(xC2){tree.DelParams();}
3051 else{for
3052 xU{lM1&atree=xI2;if(IsLogicalValue(atree))nF1);}
3053 }
3054 for
3055 xK2
3056 0;a<comp.cB1
3057 eW2
3058 a){if(comp.cB1[a].yN2)eV2
3059 cNot);r
3060 i4
3061 r.cO1
3062 tP1!xC2)eV2
3063 cNotNot);r
3064 i4
3065 r.cO1
3066 else
3067 tree
3068 i4}
3069 for
3070 xK2
3071 0;a<comp.cW
3072 eW2
3073 a)eV2
3074 cNop);switch(comp.cW[a
3075 tO
3076 iY2
3077 yB
3078 e93:r
3079 tU
3080 cLess);lC
3081 yB
3082 Eq_Mask:r
3083 tU
3084 cEqual);lC
3085 yB
3086 eA3:r
3087 tU
3088 cGreater);lC
3089 yB
3090 Le_Mask:r
3091 tU
3092 cLessOrEq);lC
3093 yB
3094 eB3:r
3095 tU
3096 t71);lC
3097 yB
3098 Ge_Mask:r
3099 tU
3100 cGreaterOrEq
3101 nW2
3102 r
3103 yA
3104 comp.cW[a].a);r
3105 yA
3106 comp.cW[a].b);r.cO1
3107 if(comp.xF1!=0)tree
3108 yT
3109 eS1(comp.xF1)));
3110 #ifdef DEBUG_SUBSTITUTIONS
3111 std::cout<<"After ConstantFolding_LogicCommon: "
3112 eS
3113 #endif
3114 return
3115 true;}
3116 nX2
3117 xG1
3118 ConstantFolding_AndLogic(tT3(tree.tU3()==cAnd
3119 tI3()==cAbsAnd)l81
3120 nJ
3121 i32,true);}
3122 xG1
3123 ConstantFolding_OrLogic(tT3(tree.tU3()==cOr
3124 tI3()==cAbsOr)l81
3125 nJ
3126 cond_or,true);}
3127 xG1
3128 ConstantFolding_AddLogicItems(tT3(tree.tU3()==cAdd)l81
3129 nJ
3130 i52,false);}
3131 xG1
3132 ConstantFolding_MulLogicItems(tT3(tree.tU3()==cMul)l81
3133 nJ
3134 i42,false);}
3135 }
3136 #include <vector>
3137 #include <map>
3138 #include <algorithm>
3139 iO2{xQ
3140 using
3141 iO2
3142 FPoptimizer_CodeTree;e92
3143 CollectionSetBase{enum
3144 xH1{Ok,xA2}
3145 ;}
3146 ;yT1
3147 CollectionSet:public
3148 CollectionSetBase{e92
3149 yZ1
3150 nG1
3151 value
3152 yJ
3153 xD2;bool
3154 e2;yZ1():value(),xD2(),e2(false){}
3155 yZ1(lM1&v,lM1&f):value(v),xD2(f),e2(false){}
3156 }
3157 ;std::multimap<fphash_t,yZ1>i8;typedef
3158 typename
3159 std::multimap<fphash_t,yZ1>::nX3
3160 xI1;CollectionSet():i8(){}
3161 xI1
3162 FindIdenticalValueTo(lM1&value){fphash_t
3163 hash=value.GetHash();for(xI1
3164 i=i8.xE2
3165 hash);i!=i8.cP1
3166 hash;++i){c51
3167 iA
3168 i
3169 cJ2.value)nZ2
3170 i;}
3171 return
3172 i8.end();}
3173 bool
3174 Found
3175 i01
3176 xI1&b){return
3177 b!=i8.end();}
3178 xH1
3179 AddCollectionTo(lM1&xD2,const
3180 xI1&into_which){yZ1&c=into_which
3181 cJ2;if(c.e2)c.xD2
3182 eT
3183 xD2);else
3184 nG1
3185 add;add
3186 tU
3187 cAdd);add
3188 yA
3189 c.xD2);add
3190 eT
3191 xD2);c.xD2.swap(add);c.e2=true;}
3192 return
3193 xA2;}
3194 xH1
3195 iR1
3196 lM1&value,lM1&xD2){const
3197 fphash_t
3198 hash=value.GetHash();xI1
3199 i=i8.xE2
3200 hash);for(;i!=i8.cP1
3201 hash;++i){if(i
3202 cJ2.value
3203 iA
3204 value)nZ2
3205 AddCollectionTo(xD2,i);}
3206 i8.nT3,std::make_pair(hash,yZ1(value,xD2)))l81
3207 Ok;}
3208 xH1
3209 iR1
3210 lM1&a){return
3211 iR1
3212 a,nB1
3213 1)));}
3214 }
3215 ;yT1
3216 ConstantExponentCollection{typedef
3217 yG
3218 nV1
3219 nV3;typedef
3220 std::x51
3221 xF2;yG<xF2>data;ConstantExponentCollection():data(){}
3222 void
3223 MoveToSet_Unique
3224 i01
3225 eS1&e51&e61){data
3226 yL
3227 std::x51(e51()));data.back()eE3.swap(e61
3228 iR2
3229 MoveToSet_NonUnique
3230 i01
3231 eS1&e51&e61){typename
3232 yG<xF2>::nX3
3233 i=std::xE2
3234 data.i62
3235 data.end(),cE2,Compare1st());if(i!=data.cP1
3236 cE2){i
3237 cJ2.nT3
3238 cJ2.end(),e61.i62
3239 e61.end());}
3240 else{data.nT3,std::x51(cE2,e61));}
3241 }
3242 bool
3243 Optimize(){bool
3244 changed
3245 i13
3246 std::sort(data.i62
3247 data.end(),Compare1st());redo:for
3248 xK2
3249 0;a<data
3250 eW2
3251 a){eS1
3252 exp_a=data[a
3253 eC3
3254 i82
3255 exp_a,nY3
3256 y81
3257 for(iX2
3258 a+1;b<data
3259 eW2
3260 b){eS1
3261 exp_b=data[b
3262 eC3;eS1
3263 xG2=exp_b-exp_a;if(xG2>=fp_abs(exp_a
3264 n33
3265 exp_diff_still_probable_integer=xG2*eS1(16);if(eY2
3266 exp_diff_still_probable_integer)&&!(eY2
3267 exp_b)&&!eY2
3268 xG2))){nV3&a_set=iS1;nV3&b_set=data[b
3269 eD3;
3270 #ifdef DEBUG_SUBSTITUTIONS
3271 std::cout<<"Before ConstantExponentCollection iteration:\n"
3272 ;eZ2
3273 cout);
3274 #endif
3275 if(isEvenInteger(exp_b)&&!isEvenInteger(xG2+exp_a))nG1
3276 tmp2;tmp2
3277 e53
3278 tmp2
3279 tI1
3280 b_set);tmp2
3281 i72
3282 tmp;tmp
3283 tU
3284 cAbs);tmp
3285 yY3;tmp
3286 x02;b_set
3287 nE3
3288 1);b_set[0
3289 t23
3290 tmp);}
3291 a_set.insert(a_set.end(),b_set.i62
3292 b_set.end());nV3
3293 b_copy=b_set;data.erase(data.begin()+b);MoveToSet_NonUnique(xG2,b_copy);yI1
3294 #ifdef DEBUG_SUBSTITUTIONS
3295 std::cout<<"After ConstantExponentCollection iteration:\n"
3296 ;eZ2
3297 cout);
3298 #endif
3299 e5}
3300 }
3301 }
3302 return
3303 changed;}
3304 #ifdef DEBUG_SUBSTITUTIONS
3305 void
3306 eZ2
3307 ostream&out){for
3308 xK2
3309 0;a<data
3310 eW2
3311 a){out.precision(12);out<<data[a
3312 eC3<<": "
3313 ;eW3
3314 iS1
3315 eW2
3316 b){if(b>0)out<<'*';xE3(iS1[b],out);}
3317 out<<std::endl;}
3318 }
3319 #endif
3320 }
3321 ;yV1
3322 static
3323 yK2
3324 x61
3325 yK2&value,bool&xG){switch(value
3326 nE
3327 iY2
3328 cPow:nG1
3329 cE2=value
3330 lD
3331 1);value.y71
3332 l81
3333 cE2
3334 cM3
3335 cRSqrt:value.y71;xG=true
3336 l81
3337 nB1-0.5));case
3338 cInv:value.y71;xG=true
3339 l81
3340 nB1-1));default:nM3
3341 return
3342 nB1
3343 1))eI2
3344 void
3345 e71
3346 e81&mul,lM1&tree,lM1&xD2,bool&c01
3347 bool&xG){for
3348 yS
3349 nG1
3350 value
3351 nW1
3352 a))yJ
3353 cE2(x61
3354 value,xG));if(!xD2
3355 y21||xD2.xJ1!=1.0)nG1
3356 cQ1;cQ1
3357 e53
3358 cQ1
3359 eT
3360 cE2);cQ1
3361 eT
3362 xD2);cQ1
3363 x02;cE2.swap(cQ1);}
3364 #if 0 /* FIXME: This does not work */
3365 c51
3366 nE==cMul){if(1){bool
3367 exponent_is_even=cE2
3368 y21&&isEvenInteger(cE2.xJ1);eW3
3369 value.c81{bool
3370 tmp=false
3371 yJ
3372 val(value
3373 lD
3374 b))yJ
3375 exp(x61
3376 val,tmp));if(exponent_is_even||(exp
3377 y21&&isEvenInteger(exp.xJ1)))nG1
3378 cQ1;cQ1
3379 e53
3380 cQ1
3381 eT
3382 cE2);cQ1
3383 yA
3384 exp);cQ1.ConstantFolding();if(!cQ1
3385 y21||!isEvenInteger(cQ1.xJ1)){goto
3386 cannot_adopt_mul;}
3387 }
3388 }
3389 }
3390 e71
3391 mul,value,cE2,c01
3392 xG);}
3393 else
3394 cannot_adopt_mul:
3395 #endif
3396 {if(mul.iR1
3397 value,cE2)==CollectionSetBase::xA2)c11}
3398 }
3399 }
3400 xG1
3401 ConstantFolding_MulGrouping(eR{bool
3402 xG
3403 i13
3404 bool
3405 should_regenerate
3406 i13
3407 e81
3408 mul;e71
3409 mul,tree,nB1
3410 1)),c01
3411 xG);typedef
3412 std::pair<yK2,yG
3413 nV1>e91;typedef
3414 std::multimap<fphash_t,e91>cC1;cC1
3415 i9;xH2
3416 e81::xI1
3417 j=mul.i8.nW3
3418 j!=mul.i8.end();++j)nG1&value=j
3419 cJ2.value
3420 yJ&cE2=j
3421 cJ2.xD2;if(j
3422 cJ2.e2)cE2
3423 x02;const
3424 fphash_t
3425 eA1=cE2.GetHash();typename
3426 cC1::nX3
3427 i=i9.xE2
3428 eA1);for(;i!=i9.cP1
3429 eA1;++i)if(i
3430 cJ2.first
3431 iA
3432 cE2)){if(!cE2
3433 y21||!cR1.xJ1,nY3
3434 c11
3435 i
3436 cJ2
3437 eE3
3438 yL
3439 value);goto
3440 skip_b;}
3441 i9.nT3,std::make_pair(eA1,std::make_pair(cE2,yG
3442 nV1(size_t(1),value))));skip_b:;}
3443 #ifdef FP_MUL_COMBINE_EXPONENTS
3444 ConstantExponentCollection
3445 x8
3446 cS1;xH2
3447 cC1::nX3
3448 j,i=i9.nW3
3449 i!=i9.end();i=j){j=i;++j;e91&list=i
3450 cJ2;if
3451 eD2
3452 y21)c21
3453 list.first.xJ1;if(!(cE2==eS1(0)))cS1.MoveToSet_Unique(cE2,list
3454 eE3);i9.erase(i);}
3455 }
3456 if(cS1.Optimize())c11
3457 #endif
3458 if(should_regenerate)nG1
3459 before=tree;before.iY
3460 #ifdef DEBUG_SUBSTITUTIONS
3461 std::cout<<"Before ConstantFolding_MulGrouping: "
3462 ;xE3(before)lN1"\n"
3463 ;
3464 #endif
3465 tree.DelParams();xH2
3466 cC1::nX3
3467 i=i9.nW3
3468 i!=i9.end();++i){e91&list=i
3469 cJ2;
3470 #ifndef FP_MUL_COMBINE_EXPONENTS
3471 if
3472 eD2
3473 y21)c21
3474 list.first.xJ1;if(cE2==eS1(0))y81
3475 if(cR1,nY3{tree.AddParamsMove(list
3476 eE3);y81}
3477 }
3478 #endif
3479 yK2
3480 mul;mul
3481 e53
3482 mul
3483 tI1
3484 list
3485 eE3);mul
3486 x02;if(xG&&list.first
3487 tF3
3488 eD2.xJ1==eS1(1)/eS1(3))nG1
3489 cbrt;cbrt
3490 tU
3491 cCbrt);cbrt
3492 t02;cbrt.yB3
3493 cbrt);y81
3494 cR
3495 0.5))nG1
3496 sqrt;sqrt
3497 tU
3498 cSqrt);sqrt
3499 t02;sqrt.yB3
3500 sqrt);y81
3501 cR-0.5))nG1
3502 rsqrt;rsqrt
3503 tU
3504 cRSqrt);rsqrt
3505 t02;rsqrt.yB3
3506 rsqrt);y81
3507 cR-1))nG1
3508 inv;inv
3509 tU
3510 cInv);inv
3511 t02;inv.yB3
3512 inv);y81}
3513 }
3514 yK2
3515 pow
3516 yB2
3517 t02;pow
3518 yA
3519 list.first);pow.yB3
3520 pow);}
3521 #ifdef FP_MUL_COMBINE_EXPONENTS
3522 i9.clear()c23
3523 0;a<i2
3524 eW2
3525 a)c21
3526 i2[a
3527 eC3;if(cR1,nY3{tree.AddParamsMove(i2[a
3528 eD3);y81}
3529 yK2
3530 mul;mul
3531 e53
3532 mul
3533 tI1
3534 i2[a
3535 eD3);mul
3536 i72
3537 pow
3538 yB2
3539 t02;pow
3540 yT
3541 cE2));pow.yB3
3542 pow);}
3543 #endif
3544 #ifdef DEBUG_SUBSTITUTIONS
3545 std::cout<<"After ConstantFolding_MulGrouping: "
3546 eS
3547 #endif
3548 return!tree
3549 iA
3550 before);}
3551 nX2
3552 xG1
3553 ConstantFolding_AddGrouping(eR{bool
3554 should_regenerate
3555 i13
3556 e81
3557 add
3558 eV3
3559 if
3560 nW1
3561 a)nE==cMul)y81
3562 if(add.AddCollection
3563 nW1
3564 a))==CollectionSetBase::xA2)c11}
3565 yG<bool>remaining(iT);size_t
3566 tB=0
3567 eV3
3568 lM1&n83=xI2;if(n83
3569 nE==cMul){eW3
3570 xX1
3571 c81{if(n83
3572 lD
3573 b)y21)y81
3574 typename
3575 e81::xI1
3576 c=add.FindIdenticalValueTo(n83
3577 lD
3578 b));if(add.Found(c))nG1
3579 tmp(n83
3580 yO
3581 CloneTag());tmp.iH1
3582 b);tmp
3583 x02;add.AddCollectionTo(tmp,c);c11
3584 goto
3585 done_a;}
3586 }
3587 remaining[a]=true;tB+=1;done_a:;}
3588 }
3589 if(tB>0){if(tB>1){yG<std::pair<yK2,size_t> >nV;std::multimap<fphash_t,size_t>eB1;bool
3590 l13
3591 i13
3592 t12{eW3
3593 xI2.c81{lM1&p=xI2
3594 lD
3595 b);const
3596 fphash_t
3597 p_hash=p.GetHash();for(std::multimap<fphash_t,size_t>::const_iterator
3598 i=eB1.xE2
3599 p_hash);i!=eB1.cP1
3600 p_hash;++i){if(nV[i
3601 cJ2
3602 eC3
3603 iA
3604 p)){nV[i
3605 cJ2
3606 eD3+=1;l13=true;goto
3607 found_mulgroup_item_dup;}
3608 }
3609 nV
3610 yL
3611 std::make_pair(p,size_t(1)));eB1.insert(std::make_pair(p_hash,nV
3612 yA3-1));found_mulgroup_item_dup:;}
3613 }
3614 if(l13)nG1
3615 cK2;{size_t
3616 max=0;for(size_t
3617 p=0;p<nV
3618 eW2
3619 p)if(nV[p
3620 eD3<=1)nV[p
3621 eD3=0;else{nV[p
3622 eD3*=nV[p
3623 eC3.xT2;if(nV[p
3624 eD3>max){cK2=nV[p
3625 eC3;max=nV[p
3626 eD3;}
3627 }
3628 }
3629 yK2
3630 group_add;group_add
3631 tU
3632 cAdd);
3633 #ifdef DEBUG_SUBSTITUTIONS
3634 std::cout<<"Duplicate across some trees: "
3635 ;xE3(cK2)lN1" in "
3636 eS
3637 #endif
3638 t12
3639 eW3
3640 xI2.c81
3641 if(cK2
3642 iA
3643 xI2
3644 lD
3645 b)))nG1
3646 tmp
3647 nW1
3648 a)yO
3649 CloneTag());tmp.iH1
3650 b);tmp
3651 x02;group_add
3652 yA
3653 tmp);remaining[a]i13
3654 nM3
3655 group_add
3656 i72
3657 group;group
3658 e53
3659 group
3660 yA
3661 cK2);group
3662 yA
3663 group_add);group
3664 x02;add.iR1
3665 group);c11}
3666 }
3667 t12{if(add.AddCollection
3668 nW1
3669 a))==CollectionSetBase::xA2)c11}
3670 }
3671 if(should_regenerate){
3672 #ifdef DEBUG_SUBSTITUTIONS
3673 std::cout<<"Before ConstantFolding_AddGrouping: "
3674 eS
3675 #endif
3676 tree.DelParams();xH2
3677 e81::xI1
3678 j=add.i8.nW3
3679 j!=add.i8.end();++j)nG1&value=j
3680 cJ2.value
3681 yJ&coeff=j
3682 cJ2.xD2;if(j
3683 cJ2.e2)coeff
3684 x02;if(coeff
3685 tF3(fp_equal(coeff.xJ1,eS1(0)))y81
3686 if(fp_equal(coeff.xJ1,nY3{tree
3687 yA
3688 value);y81}
3689 }
3690 yK2
3691 mul;mul
3692 e53
3693 mul
3694 yA
3695 value);mul
3696 yA
3697 coeff);mul.Rehash(tT
3698 t02;}
3699 #ifdef DEBUG_SUBSTITUTIONS
3700 std::cout<<"After ConstantFolding_AddGrouping: "
3701 eS
3702 #endif
3703 return
3704 true;}
3705 nX2}
3706 iO2{xQ
3707 using
3708 iO2
3709 FPoptimizer_CodeTree;xG1
3710 ConstantFolding_IfOperations(tT3(tree.tU3()==cIf
3711 tI3()==i03);for(;;){l23
3712 nE==cNot){tH
3713 cIf
3714 tT
3715 lD
3716 0).xO2
3717 0)lD
3718 0)tT
3719 lD
3720 1).swap
3721 nW1
3722 2));}
3723 else
3724 l23
3725 cG1{tH
3726 i03
3727 tT
3728 lD
3729 0).xO2
3730 0)lD
3731 0)tT
3732 lD
3733 1).swap
3734 nW1
3735 2));}
3736 else
3737 t62
3738 tX
3739 0),cV2
3740 i03))tF1
3741 tree.xO2
3742 1));nW
3743 yO3
3744 xP3
3745 xO2
3746 2));nW
3747 lX1
3748 l23
3749 nE==cIf||e72
3750 nE==i03)nG1
3751 cond
3752 cL2
3753 0)yJ
3754 l53;l53
3755 xP2==cIf?cNotNot:cAbsNotNot);l53
3756 x63
3757 x03;ConstantFolding(l53)yJ
3758 truth_b;truth_b
3759 xP2==cIf?cNotNot:cAbsNotNot);truth_b
3760 x63
3761 x73
3762 ConstantFolding(truth_b);if(l53
3763 y21||truth_b
3764 y21)nG1
3765 eU;eU
3766 xP2);eU
3767 x63
3768 x03;eU
3769 yC
3770 1));eU
3771 yC
3772 2));eU
3773 i72
3774 eV;eV
3775 xP2);eV
3776 x63
3777 x73
3778 eV
3779 yC
3780 1));eV
3781 yC
3782 2));eV
3783 y3
3784 cond
3785 nE
3786 xK1
3787 0,cond
3788 lD
3789 0)tT.nC1
3790 1,eU
3791 tT.nC1
3792 2,eV)nS2}
3793 if
3794 nW1
3795 1)nE==tree
3796 lD
3797 2)nE&&nW1
3798 1)nE==cIf||tree
3799 lD
3800 1)nE==i03))nG1&cM2
3801 cL2
3802 1)yJ&leaf2
3803 cL2
3804 2);if
3805 x83
3806 0).xO
3807 0))&&x83
3808 1).xO
3809 1))||cM2
3810 lD
3811 2).xO
3812 2))))nG1
3813 eU;eU
3814 xQ2
3815 eU
3816 yC
3817 0));eU
3818 eT
3819 cM2
3820 x03;eU
3821 eT
3822 leaf2
3823 x03;eU
3824 i72
3825 eV;eV
3826 xQ2
3827 eV
3828 yC
3829 0));eV
3830 eT
3831 cM2
3832 x73
3833 eV
3834 eT
3835 leaf2
3836 x73
3837 eV
3838 y3
3839 cM2
3840 nE
3841 xK1
3842 0
3843 eF3
3844 0)tT.nC1
3845 1,eU
3846 tT.nC1
3847 2,eV)nS2
3848 if
3849 x83
3850 1).xO
3851 1))&&cM2
3852 lD
3853 2).xO
3854 2)))nG1
3855 eW;eW
3856 xQ2
3857 eW
3858 yA
3859 e72);eW
3860 eT
3861 cM2
3862 xY3
3863 eW
3864 eT
3865 leaf2
3866 xY3
3867 eW
3868 y3
3869 cM2
3870 nE
3871 tT.nC1
3872 0,eW
3873 xK1
3874 2
3875 eF3
3876 2)xK1
3877 1,cM2
3878 x03
3879 nS2
3880 if
3881 x83
3882 1).xO
3883 2))&&cM2
3884 lD
3885 2).xO
3886 1)))nG1
3887 cN2;cN2
3888 tU
3889 leaf2
3890 nE==cIf?cNot:yR3);cN2
3891 eT
3892 leaf2
3893 xY3
3894 cN2
3895 i72
3896 eW;eW
3897 xQ2
3898 eW
3899 yA
3900 e72);eW
3901 eT
3902 cM2
3903 xY3
3904 eW
3905 yA
3906 cN2);eW
3907 y3
3908 cM2
3909 nE
3910 tT.nC1
3911 0,eW
3912 xK1
3913 2
3914 eF3
3915 2)xK1
3916 1,cM2
3917 x03
3918 nS2}
3919 yK2&xW
3920 cL2
3921 1)yJ&y9
3922 cL2
3923 2);if(xW
3924 iA
3925 y9)){tree.xO2
3926 1))nS2
3927 const
3928 OPCODE
3929 op1=xW
3930 nE;const
3931 OPCODE
3932 op2=y9
3933 nE;if(op1==op2){if(xW.cT1
3934 1)nG1
3935 lO
3936 0))xL2
3937 0
3938 y31)lY
3939 if(xW.cT1
3940 2&&y9.cT1
3941 2){if(xW
3942 lD
3943 0)iA
3944 y9
3945 lD
3946 0)))nG1
3947 param0=xW
3948 lD
3949 0)yJ
3950 lO
3951 1))xL2
3952 1
3953 y31
3954 tT
3955 yA
3956 param0)lY
3957 if(xW
3958 lD
3959 1)iA
3960 y9
3961 x03)nG1
3962 param1=xW
3963 lD
3964 1)yJ
3965 lO
3966 0))xL2
3967 0
3968 y31
3969 tT
3970 yA
3971 n41
3972 tT
3973 yA
3974 param1)nS2}
3975 if(op1==x93
3976 cMul
3977 iU1
3978 cAnd
3979 iU1
3980 cOr
3981 iU1
3982 cAbsAnd
3983 iU1
3984 cAbsOr
3985 iU1
3986 cMin
3987 iU1
3988 cMax){yG
3989 nV1
3990 l63;cC{for(iX2
3991 y9.cN3
3992 b-->0;){lW2
3993 y9
3994 lD
3995 b))){if(l63
3996 cQ3){xW.iY
3997 y9.iY}
3998 l63
3999 yL
4000 xW
4001 lD
4002 a));y9.iH1
4003 b);xW.iH1
4004 a
4005 nW2}
4006 }
4007 if(!l63
4008 cQ3){xW
4009 x02;y9
4010 i72
4011 n41;n41
4012 xQ2
4013 n41
4014 tI1
4015 tree.iE1));n41
4016 y3
4017 op1
4018 tT
4019 tI1
4020 l63)lY}
4021 }
4022 if(op1==x93
4023 cMul||(op1==cAnd
4024 nY1
4025 y9))||(op1==cOr
4026 nY1
4027 y9))){cC
4028 lW2
4029 y9)){xW.iY
4030 xW
4031 cP3
4032 xW
4033 i72
4034 cD1=y9;y9=tC
4035 op1==x93
4036 cOr)l9
4037 op1
4038 tT
4039 yA
4040 cD1)lY}
4041 if((op1==cAnd
4042 iU1
4043 cOr)&&op2==cNotNot)nG1&l73=y9
4044 lD
4045 0);cC
4046 lW2
4047 l73)){xW.iY
4048 xW
4049 cP3
4050 xW
4051 i72
4052 cD1=l73;y9=tC
4053 op1
4054 xA3
4055 op1
4056 tT
4057 yA
4058 cD1)lY}
4059 if(op2==cAdd||op2==cMul||(op2==cAnd
4060 nY1
4061 xW))||(op2==cOr
4062 nY1
4063 xW))){for
4064 xK2
4065 y9.tD
4066 y9
4067 lD
4068 a)iA
4069 xW)){y9.iY
4070 y9
4071 cP3
4072 y9
4073 i72
4074 cE1=xW;xW=tC
4075 op2==cAdd||op2
4076 xA3
4077 op2
4078 tT
4079 yA
4080 cE1)lY}
4081 if((op2==cAnd||op2==cOr)&&op1==cNotNot)nG1&l83=xW
4082 lD
4083 0)c23
4084 y9.tD
4085 y9
4086 lD
4087 a)iA
4088 l83)){y9.iY
4089 y9
4090 cP3
4091 y9
4092 i72
4093 cE1=l83;xW=tC
4094 op2
4095 xA3
4096 op2
4097 tT
4098 yA
4099 cE1)lY}
4100 nX2}
4101 #include <limits>
4102 iO2{xQ
4103 using
4104 iO2
4105 FPoptimizer_CodeTree;yV1
4106 int
4107 maxFPExponent(){return
4108 std::numeric_limits
4109 x8::max_exponent;}
4110 xG1
4111 x71
4112 eS1
4113 xB3
4114 cE2){if(base<eS1(0
4115 iF1
4116 i82
4117 xB3(0))||fp_equal(xB3(1))yI
4118 return
4119 cE2>=eS1(maxFPExponent
4120 x8())/fp_log2(base);}
4121 xG1
4122 ConstantFolding_PowOperations(tT3(tree.tU3()==cPow);y2){eS1
4123 const_value=eG3
4124 n6,y4
4125 tT.ReplaceWithImmed(const_value)l81
4126 false;}
4127 if(nE1
4128 fp_equal(y4,nY3{tree.xO2
4129 0))nS2
4130 lX&&fp_equal(n6,nY3
4131 lL
4132 1)l81
4133 false;}
4134 lX&&tree
4135 lD
4136 1)nE==cMul){bool
4137 xR2
4138 i13
4139 eS1
4140 iV1=n6
4141 yJ
4142 n83
4143 cL2
4144 1)c23
4145 xX1
4146 tD
4147 n83
4148 lD
4149 a)xC3
4150 imm=n83
4151 lD
4152 a).xJ1;{if(x71
4153 iV1,imm
4154 n33
4155 iW1=eG3
4156 iV1,imm)i82
4157 iW1,eS1(0)))break;if(!xR2){xR2=true;xX1
4158 iY}
4159 iV1=iW1;xX1
4160 iH1
4161 a
4162 nW2}
4163 if(xR2){xX1
4164 Rehash();
4165 #ifdef DEBUG_SUBSTITUTIONS
4166 std::cout<<"Before pow-mul change: "
4167 eS
4168 #endif
4169 e72.Become(cU1
4170 iV1)tT
4171 lD
4172 1).Become(n83);
4173 #ifdef DEBUG_SUBSTITUTIONS
4174 std::cout<<"After pow-mul change: "
4175 eS
4176 #endif
4177 }
4178 }
4179 if(nE1
4180 e72
4181 nE==cMul){eS1
4182 iX1=y4;eS1
4183 xS2=1.0;bool
4184 xR2=false
4185 yJ&n83
4186 cL2
4187 0)c23
4188 xX1
4189 tD
4190 n83
4191 lD
4192 a)xC3
4193 imm=n83
4194 lD
4195 a).xJ1;{if(x71
4196 imm,iX1
4197 n33
4198 eD1=eG3
4199 imm,iX1)i82
4200 eD1,eS1(0)))break;if(!xR2){xR2=true;xX1
4201 iY}
4202 xS2*=eD1;xX1
4203 iH1
4204 a
4205 nW2}
4206 if(xR2){xX1
4207 Rehash()yJ
4208 cD3;cD3
4209 tU
4210 cPow);cD3
4211 tI1
4212 tree.iE1));cD3.y12);tH
4213 cMul
4214 tT
4215 yA
4216 cD3
4217 tT
4218 eT
4219 cU1
4220 xS2))nS2}
4221 l23
4222 nE==cPow&&nE1
4223 e72
4224 lD
4225 1)xC3
4226 a
4227 cL2
4228 0)lD
4229 1).xJ1;eS1
4230 b=y4;eS1
4231 c=a*b;if(isEvenInteger(a)&&!isEvenInteger(c))nG1
4232 l93;l93
4233 tU
4234 cAbs);l93
4235 yC
4236 0)xY3
4237 l93.Rehash(tT.nC1
4238 0,l93);}
4239 else
4240 tree.SetParam(0,e72
4241 lD
4242 0)xK1
4243 1,cU1
4244 c));}
4245 nX2}
4246 iO2{xQ
4247 using
4248 iO2
4249 FPoptimizer_CodeTree;e92
4250 l4{enum
4251 cO2{MakeFalse=0,MakeTrue=1,t22=2,lC3=3,MakeNotNotP0=4,MakeNotNotP1=5,MakeNotP0=6,MakeNotP1=7,Unchanged=8
4252 n23
4253 iY1{Never=0,Eq0=1,Eq1=2,xD3=3,xR3=4}
4254 ;cO2
4255 if_identical;cO2
4256 iZ1
4257 4];e92{cO2
4258 what:4;iY1
4259 when:4;}
4260 tS1,tT1,tU1,tV1;yV1
4261 cO2
4262 Analyze(lM1&a,lM1&b)const{if(a
4263 iA
4264 b)nZ2
4265 if_identical;range
4266 x8
4267 p0=iM
4268 a);range
4269 x8
4270 p1=iM
4271 b);if(p0
4272 i0&&p1.iV2){if(p0.max<p1.min&&iZ1
4273 0]cJ
4274 0];if(p0.max<=p1.min&&iZ1
4275 1]cJ
4276 1];}
4277 if(p0
4278 y41
4279 p1
4280 i0){if(p0.min>p1.max&&iZ1
4281 2]cJ
4282 2];if(p0.min>=p1.max&&iZ1
4283 3]cJ
4284 3];}
4285 if(IsLogicalValue(a)){if(tS1
4286 i92
4287 tS1.when,p1)nZ2
4288 tS1.what;if(tU1
4289 i92
4290 tU1.when,p1)nZ2
4291 tU1.what;}
4292 if(IsLogicalValue(b)){if(tT1
4293 i92
4294 tT1.when,p0)nZ2
4295 tT1.what;if(tV1
4296 i92
4297 tV1.when,p0)nZ2
4298 tV1.what;}
4299 return
4300 Unchanged
4301 eI2
4302 bool
4303 TestCase(iY1
4304 when,const
4305 range
4306 x8&p){if(!p.iV2||!p
4307 i0
4308 yI
4309 switch(when
4310 iY2
4311 Eq0:return
4312 p.min==0.0
4313 xQ3==p.min;case
4314 Eq1:return
4315 p.min==1.0
4316 xQ3==p.max;case
4317 xD3:return
4318 p.min>0
4319 xQ3<=1;case
4320 xR3:return
4321 p.min>=0
4322 xQ3<1;default:;}
4323 nX2}
4324 ;iO2
4325 RangeComparisonsData{static
4326 const
4327 l4
4328 Data[6]={{l4
4329 lA3
4330 tP
4331 Unchanged,l4::tP
4332 Unchanged
4333 tE
4334 Eq1
4335 tF
4336 Eq1
4337 nD1
4338 Eq0}
4339 ,l91
4340 Eq0}
4341 }
4342 ,{l4::lX2
4343 lB3
4344 Unchanged,l4
4345 lB3
4346 Unchanged
4347 tE
4348 Eq0
4349 tF
4350 Eq0
4351 nD1
4352 Eq1}
4353 ,l91
4354 Eq1}
4355 }
4356 ,{l4::lX2
4357 lB3
4358 t22,l4::tP
4359 MakeFalse
4360 nD1
4361 xD3
4362 tF
4363 xR3
4364 xD,{l4
4365 lA3
4366 Unchanged,l4
4367 lB3
4368 tP
4369 lC3
4370 nD1
4371 xR3
4372 tF
4373 xD3
4374 xD,{l4::lX2::tP
4375 tP
4376 MakeTrue,l4::t22
4377 tE
4378 xR3}
4379 ,l91
4380 xD3
4381 xD,{l4
4382 lA3
4383 tP
4384 lC3,l4::Unchanged,l4
4385 nH1
4386 tE
4387 xD3}
4388 ,l91
4389 xR3
4390 xD}
4391 ;}
4392 xG1
4393 ConstantFolding_Comparison(eR{using
4394 iO2
4395 RangeComparisonsData;assert(tree.tU3()>=cEqual&&tree.tU3()<=cGreaterOrEq);switch(Data[tree
4396 nE-cEqual].Analyze
4397 nW1
4398 0),tree
4399 x03
4400 iY2
4401 l4::MakeFalse
4402 xP3
4403 ReplaceWithImmed(0);nW
4404 l4
4405 nH1
4406 xP3
4407 ReplaceWithImmed(1
4408 l33
4409 lC3:tH
4410 cEqual
4411 l33
4412 t22:tH
4413 t71
4414 l33
4415 MakeNotNotP0:tH
4416 cNotNot
4417 tW1
4418 1
4419 l33
4420 MakeNotNotP1:tH
4421 cNotNot
4422 tW1
4423 0
4424 l33
4425 MakeNotP0:tH
4426 cNot
4427 tW1
4428 1
4429 l33
4430 MakeNotP1:tH
4431 cNot
4432 tW1
4433 0
4434 l33
4435 Unchanged:;}
4436 if
4437 nW1
4438 1)y21)switch
4439 nW1
4440 0)nE
4441 iY2
4442 cAsin
4443 xP3
4444 lR
4445 fp_sin(iA2
4446 cAcos
4447 xP3
4448 lR
4449 fp_cos(y4)));tH
4450 cV2
4451 cLess?cGreater:cV2
4452 cLessOrEq?cGreaterOrEq:cV2
4453 cGreater?cLess:cV2
4454 cGreaterOrEq?cLessOrEq:tree
4455 nE);nW
4456 cAtan
4457 xP3
4458 lR
4459 fp_tan(iA2
4460 cLog
4461 xP3
4462 lR
4463 fp_exp(iA2
4464 cSinh
4465 xP3
4466 lR
4467 fp_asinh(iA2
4468 cTanh:if(fp_less(fp_abs(y4),nY3{tree.lR
4469 fp_atanh(y4)))nS2
4470 break;default:nM3
4471 nX2}
4472 #include <list>
4473 #include <algorithm>
4474 #ifdef FP_SUPPORT_OPTIMIZER
4475 xQ
4476 iO2{
4477 #ifdef DEBUG_SUBSTITUTIONS
4478 yW
4479 double
4480 d){union{double
4481 d;uint_least64_t
4482 h;}
4483 t32
4484 d=d;lH1
4485 h
4486 nZ1
4487 #ifdef FP_SUPPORT_FLOAT_TYPE
4488 yW
4489 float
4490 f){union{float
4491 f;uint_least32_t
4492 h;}
4493 t32
4494 f=f;lH1
4495 h
4496 nZ1
4497 #endif
4498 #ifdef FP_SUPPORT_LONG_DOUBLE_TYPE
4499 yW
4500 long
4501 double
4502 ld){union{long
4503 double
4504 ld;e92{uint_least64_t
4505 a;i02
4506 short
4507 b;}
4508 s;}
4509 t32
4510 ld=ld;lH1
4511 s.b<<data.s.a
4512 nZ1
4513 #endif
4514 #ifdef FP_SUPPORT_LONG_INT_TYPE
4515 yW
4516 long
4517 ld){o<<"("
4518 <<std::hex<<ld
4519 nZ1
4520 #endif
4521 #endif
4522 }
4523 iO2
4524 FPoptimizer_CodeTree{lM
4525 nF)){}
4526 lM
4527 e62
4528 i
4529 yO
4530 nC3
4531 nF
4532 i)){data
4533 xB
4534 #ifdef __GXX_EXPERIMENTAL_CXX0X__
4535 lM
4536 eS1&&i
4537 yO
4538 nC3
4539 nF
4540 t72
4541 i))){data
4542 xB
4543 #endif
4544 lM
4545 i02
4546 v
4547 yO
4548 VarTag
4549 nF
4550 iE2,v))eS2
4551 nR2
4552 o
4553 yO
4554 OpcodeTag
4555 nF
4556 o))eS2
4557 nR2
4558 o,i02
4559 f
4560 yO
4561 FuncOpcodeTag
4562 nF
4563 o,f))eS2
4564 lM1&b
4565 yO
4566 CloneTag
4567 nF*b.data)){}
4568 yV1
4569 yK2::~yL2(){}
4570 lA
4571 ReplaceWithImmed
4572 i01
4573 eS1&i){
4574 #ifdef DEBUG_SUBSTITUTIONS
4575 std::cout<<"Replacing "
4576 ;xE3(*this);if(IsImmed())OutFloatHex(std::cout,xJ1)lN1" with const value "
4577 <<i;OutFloatHex(std::cout,i)lN1"\n"
4578 ;
4579 #endif
4580 data=new
4581 nO2
4582 x8(i);}
4583 yT1
4584 ParamComparer{i12()(lM1&a,lM1&b)const{if(a.xT2!=b.xT2
4585 nZ2
4586 a.xT2<b.xT2
4587 l81
4588 a.GetHash()<b.GetHash();}
4589 }
4590 ;xB1
4591 nO2
4592 x8::Sort(){switch(Opcode
4593 iY2
4594 cAdd:case
4595 cMul:case
4596 cMin:case
4597 cMax:case
4598 cAnd:case
4599 cAbsAnd:case
4600 cOr:case
4601 cAbsOr:case
4602 cHypot:case
4603 cEqual:case
4604 t71:std::sort(iC2
4605 i62
4606 iC2
4607 end(),ParamComparer
4608 x8());lC
4609 cLess
4610 lU
4611 cGreater;}
4612 lC
4613 cLessOrEq
4614 lU
4615 cGreaterOrEq;}
4616 lC
4617 cGreater
4618 lU
4619 cLess;}
4620 lC
4621 cGreaterOrEq
4622 lU
4623 cLessOrEq;}
4624 break;default:nM3}
4625 lA
4626 AddParam(lM1&param){xY
4627 yL
4628 param);}
4629 lA
4630 eG
4631 yK2&param){xY
4632 yL
4633 yK2());xY.back().swap(param);}
4634 lA
4635 SetParam(size_t
4636 which,lM1&b)nI1
4637 which
4638 iB2
4639 xY[which]=b;}
4640 lA
4641 nC1
4642 size_t
4643 which,yK2&b)nI1
4644 which
4645 iB2
4646 xY[which
4647 t23
4648 b);}
4649 lA
4650 AddParams
4651 i01
4652 nK){xY.insert(xY.end(),l02.i62
4653 l02.end());}
4654 lA
4655 AddParamsMove(nK){size_t
4656 endpos=xY
4657 yA3,added=l02
4658 yA3;xY
4659 nE3
4660 endpos+added,yK2());for(size_t
4661 p=0;p<added;++p)xY[endpos+p
4662 t23
4663 l02[p]);}
4664 lA
4665 AddParamsMove(nK,size_t
4666 l12)nI1
4667 l12
4668 iB2
4669 iH1
4670 l12);AddParamsMove(eU1}
4671 lA
4672 SetParams
4673 i01
4674 nK){yG
4675 nV1
4676 tmp(eU1
4677 xY.swap(tmp);}
4678 lA
4679 SetParamsMove(nK){xY.swap(eU1
4680 l02.clear();}
4681 #ifdef __GXX_EXPERIMENTAL_CXX0X__
4682 lA
4683 SetParams(yG
4684 nV1&&l02){SetParamsMove(eU1}
4685 #endif
4686 lA
4687 iH1
4688 size_t
4689 index){yG
4690 nV1&c93=xY;
4691 #ifdef __GXX_EXPERIMENTAL_CXX0X__
4692 iC2
4693 erase(iC2
4694 begin()+index);
4695 #else
4696 c93[index].data=0;for(size_t
4697 p=index;p+1<c93
4698 eW2
4699 p)c93[p].data.UnsafeSetP(&*c93[p+1
4700 iB2
4701 c93[nF3-1].data.UnsafeSetP(0);iC2
4702 resize(nF3-1);
4703 #endif
4704 }
4705 lA
4706 DelParams(){xY.clear();}
4707 xG1
4708 yK2::IsIdenticalTo(lM1&b)const{if(&*data==&*b.data
4709 nZ2
4710 true
4711 l81
4712 data->IsIdenticalTo(*b.data);}
4713 xG1
4714 nO2
4715 x8::IsIdenticalTo
4716 i01
4717 nO2
4718 x8&b)const{if(Hash!=b.Hash
4719 yI
4720 if(Opcode!=t43
4721 yI
4722 switch(Opcode
4723 iY2
4724 cImmed:return
4725 fp_equal(Value,t53;case
4726 iE2:return
4727 iJ1==b.iI1
4728 case
4729 cFCall:case
4730 cPCall:if(iJ1!=b.iJ1
4731 yI
4732 break;default:nM3
4733 if(nF3!=b.nF3
4734 yI
4735 for
4736 xK2
4737 0;a<c93
4738 eW2
4739 a){if(!c93[a]iA
4740 b.c93[a])yI}
4741 return
4742 true;}
4743 lA
4744 Become(lM1&b){if(&b!=this&&&*data!=&*b.data){DataP
4745 tmp=b.data;iY
4746 data.swap(tmp);}
4747 }
4748 lA
4749 CopyOnWrite(){if(GetRefCount()>1)data=new
4750 nO2
4751 x8(*data);}
4752 yV1
4753 yK2
4754 yK2::GetUniqueRef(){if(GetRefCount()>1
4755 nZ2
4756 yK2(*this,CloneTag())l81*this;}
4757 tQ):c7
4758 cNop
4759 l43),nC
4760 tQ
4761 const
4762 nO2&b):c7
4763 t43
4764 l43
4765 t53,iJ1(b.iJ1),c93(b.c93),Hash(b.Hash),Depth(b.Depth),eZ1
4766 b.iK1){}
4767 tQ
4768 e62
4769 i):c7
4770 cImmed
4771 l43
4772 i),nC
4773 #ifdef __GXX_EXPERIMENTAL_CXX0X__
4774 tQ
4775 nO2
4776 x8&&b):c7
4777 t43
4778 l43
4779 t72
4780 t53),iJ1(b.iJ1),c93(t72
4781 b.c93)),Hash(b.Hash),Depth(b.Depth),eZ1
4782 b.iK1){}
4783 tQ
4784 eS1&&i):c7
4785 cImmed
4786 l43
4787 t72
4788 i)),nC
4789 #endif
4790 tQ
4791 nR2
4792 o):c7
4793 o
4794 l43),nC
4795 tQ
4796 nR2
4797 o,i02
4798 f):c7
4799 o
4800 l43),iJ1(f),c93(),Hash(),Depth(1),eZ1
4801 0){}
4802 }
4803 #endif
4804 #ifdef FP_SUPPORT_OPTIMIZER
4805 #include <sstream>
4806 #include <string>
4807 #include <map>
4808 #include <set>
4809 #include <iostream>
4810 xQ
4811 #ifdef FUNCTIONPARSER_SUPPORT_DEBUGGING
4812 iO2{xB1
4813 l22
4814 cA3,eH3&done,std::ostream&o){for
4815 yS
4816 l22
4817 i43
4818 done,o);std::ostringstream
4819 buf;xE3(tree,buf);done[tree.GetHash()].insert(buf.str());}
4820 }
4821 #endif
4822 iO2
4823 FPoptimizer_CodeTree{
4824 #ifdef FUNCTIONPARSER_SUPPORT_DEBUGGING
4825 xB1
4826 DumpHashes
4827 i01
4828 eY){eH3
4829 done;l22(tree,done,o);for(eH3::const_iterator
4830 i=done.nW3
4831 i!=done.end();++i){const
4832 std::set<std::string>&flist=i
4833 cJ2;if(flist
4834 yA3!=1)o<<"ERROR - HASH COLLISION?\n"
4835 ;for(std::set<std::string>::const_iterator
4836 j=flist.nW3
4837 j!=flist.end();++j){o<<'['<<std::hex<<i->first.hash1<<','<<i->first.hash2<<']'<<std::dec;o<<": "
4838 <<*j<<"\n"
4839 ;}
4840 }
4841 }
4842 xB1
4843 xE3
4844 i01
4845 eY){const
4846 char*tN3;switch
4847 xU2
4848 iY2
4849 cImmed:o<<yZ3
4850 l81;case
4851 iE2:o<<"Var"
4852 <<(tree.GetVar()-iE2)l81;case
4853 cAdd:tN3"+"
4854 ;lC
4855 cMul:tN3"*"
4856 ;lC
4857 cAnd:tN3"&"
4858 ;lC
4859 cOr:tN3"|"
4860 ;lC
4861 cPow:tN3"^"
4862 ;break;default:tN3;o<<FP_GetOpcodeName
4863 xU2);if
4864 xU2==cFCall||cV2
4865 cPCall)o<<':'<<tree.GetFuncNo();}
4866 o<<'(';if(iT<=1&&sep2[1])o<<(sep2+1)<<' 'eV3
4867 if(a>0)o<<' ';xE3
4868 i43
4869 o);if(a+1<iT)o<<sep2;}
4870 o<<')';}
4871 xB1
4872 DumpTreeWithIndent
4873 i01
4874 eY,const
4875 std::string&indent){o<<'['<<std::hex<<(void*)(&tree.iE1))<<std::dec<<','<<tree.GetRefCount()<<']';o<<indent<<'_';switch
4876 xU2
4877 iY2
4878 cImmed:o<<"cImmed "
4879 <<yZ3;o<<'\n'l81;case
4880 iE2:o<<"VarBegin "
4881 <<(tree.GetVar()-iE2);o<<'\n'l81;default:o<<FP_GetOpcodeName
4882 xU2);if
4883 xU2==cFCall||cV2
4884 cPCall)o<<':'<<tree.GetFuncNo();o<<'\n';}
4885 for
4886 yS{std::string
4887 ind=indent;for(size_t
4888 p=0;p<ind
4889 yA3;p+=2)if(ind[p]=='\\')ind[p]=' ';ind+=(a+1<iT)?" |"
4890 :" \\"
4891 ;DumpTreeWithIndent
4892 i43
4893 o,ind);}
4894 o<<std::flush;}
4895 #endif
4896 }
4897 #endif
4898 using
4899 iO2
4900 l41;xQ
4901 #include <cctype>
4902 iO2
4903 l41{xG1
4904 ParamSpec_Compare
4905 i01
4906 void*aa,const
4907 void*bb,lU2
4908 type){switch(type
4909 iY2
4910 lY2
4911 xH&a=*(xH*)aa;xH&b=*(xH*)bb
4912 l81
4913 a
4914 t42==b
4915 t42&&a.index==b.index&&a.depcode==b.depcode
4916 cM3
4917 NumConstant:{eZ&a=*(eZ*)aa;eZ&b=*(eZ*)bb
4918 l81
4919 fp_equal(a.xZ3,b.xZ3)&&a.modulo==b.modulo
4920 iD2
4921 xI&a=*(xI*)aa;xI&b=*(xI*)bb
4922 l81
4923 a
4924 t42==b
4925 t42&&a.cS==b.cS&&a.data.match_type==b.data.match_type&&a.data
4926 xY2==b.data
4927 xY2&&a.data.param_list==b.data.param_list&&a.data.n2==b.data.n2&&a.depcode==b.depcode;}
4928 }
4929 return
4930 true;}
4931 i02
4932 ParamSpec_GetDepCode
4933 i01
4934 cG2&b){switch(b.first
4935 iY2
4936 lY2
4937 yK3*s=i01
4938 xH*)b
4939 eE3
4940 l81
4941 s->depcode
4942 iD2
4943 const
4944 xI*s=i01
4945 xI*)b
4946 eE3
4947 l81
4948 s->depcode;}
4949 default:nM3
4950 return
4951 0;}
4952 xB1
4953 DumpParam
4954 i01
4955 cG2&xZ2
4956 std::ostream&o){static
4957 const
4958 char
4959 ParamHolderNames[][2]={"%"
4960 ,"&"
4961 ,"x"
4962 ,"y"
4963 ,"z"
4964 ,"a"
4965 ,"b"
4966 ,"c"
4967 }
4968 ;i02
4969 t52
4970 0;xT3
4971 NumConstant:{const
4972 eZ&t82
4973 eZ*x01;o.precision(12);o<<xF3
4974 xZ3;nM3
4975 case
4976 lY2
4977 yK3&t82
4978 xH*x01;o<<ParamHolderNames[xF3
4979 index];t52
4980 param
4981 t42;break
4982 iD2
4983 const
4984 xI&t82
4985 xI*x01;t52
4986 param
4987 t42;yZ
4988 GroupFunction){if
4989 iZ2
4990 cS==cNeg){o<<"-"
4991 ;n3}
4992 tP1
4993 xF3
4994 cS==cInv){o<<"/"
4995 ;n3}
4996 else{std::string
4997 opcode=FP_GetOpcodeName((nR2)xF3
4998 cS).substr(1)c23
4999 0;a<opcode
5000 eW2
5001 a)opcode[a]=(char)std::toupper(opcode[a]);o<<opcode<<"( "
5002 ;n3
5003 o<<" )"
5004 ;}
5005 }
5006 else{o<<'('<<FP_GetOpcodeName((nR2)xF3
5007 cS)<<' ';yZ
5008 PositionalParams)o<<'[';yZ
5009 SelectedParams)o<<'{';n3
5010 if
5011 iZ2
5012 data.n2!=0)o<<" <"
5013 <<xF3
5014 data.n2<<'>';yZ
5015 PositionalParams)o<<"]"
5016 ;yZ
5017 SelectedParams)o<<"}"
5018 ;o<<')';}
5019 nM3
5020 yN3(ImmedConstraint_Value(tX1
5021 ValueMask)iY2
5022 ValueMask:lC
5023 Value_AnyNum:lC
5024 n12:o<<"@E"
5025 ;lC
5026 Value_OddInt:o<<"@O"
5027 ;lC
5028 t01:o<<"@I"
5029 ;lC
5030 Value_NonInteger:o<<"@F"
5031 ;lC
5032 eE1:o<<"@L"
5033 ;t62
5034 ImmedConstraint_Sign(tX1
5035 SignMask)iY2
5036 SignMask:lC
5037 Sign_AnySign:lC
5038 nJ1:o<<"@P"
5039 ;lC
5040 n02:o<<"@N"
5041 ;t62
5042 ImmedConstraint_Oneness(tX1
5043 OnenessMask)iY2
5044 OnenessMask:lC
5045 Oneness_Any:lC
5046 Oneness_One:o<<"@1"
5047 ;lC
5048 Oneness_NotOne:o<<"@M"
5049 ;t62
5050 ImmedConstraint_Constness(tX1
5051 ConstnessMask)iY2
5052 ConstnessMask:lC
5053 yL1:if(lF3.first==ParamHolder){yK3&t82
5054 xH*x01;if
5055 iZ2
5056 index<2)nM3
5057 o<<"@C"
5058 ;lC
5059 Constness_NotConst:o<<"@V"
5060 ;lC
5061 Oneness_Any:nM3}
5062 xB1
5063 DumpParams
5064 iL1
5065 paramlist,i02
5066 count,std::ostream&o){for
5067 iL1
5068 a=0;a<count;++a){if(a>0)o<<' ';const
5069 cG2&param=e01
5070 x8(paramlist,a);DumpParam
5071 x8(param,o);i02
5072 depcode=ParamSpec_GetDepCode(param);if(depcode!=0)o<<"@D"
5073 <<depcode;}
5074 }
5075 }
5076 #include <algorithm>
5077 using
5078 iO2
5079 l41;xQ
5080 iO2{yK3
5081 plist_p[36]={{2,0,0x0}
5082 tS
5083 0,0x4}
5084 tS
5085 nJ1,0x0}
5086 tS
5087 n02|Constness_NotConst,0x0}
5088 tS
5089 Sign_NoIdea,0x0}
5090 tS
5091 eE1,0x0}
5092 ,{3,Sign_NoIdea,0x0}
5093 ,{3,0,0x0}
5094 ,{3,eE1,0x0}
5095 ,{3,0,0x8}
5096 ,{3,Value_OddInt,0x0}
5097 ,{3,Value_NonInteger,0x0}
5098 ,{3,n12,0x0}
5099 ,{3,nJ1,0x0}
5100 ,{0,n02|n0{0,n0{0,nJ1|n0{0,n12|n0{0,yL1,0x1}
5101 ,{0,t01|nJ1|n0{0,t11
5102 yL1,0x1}
5103 ,{0,t11
5104 n0{0,Oneness_One|n0{0,eE1|n0{1,n0{1,n12|n0{1,t11
5105 n0{1,t01|n0{1,nJ1|n0{6,0,0x0}
5106 ,{4,0,0x0}
5107 ,{4,t01,0x0}
5108 ,{4,n0{4,0,0x16}
5109 ,{5,0,0x0}
5110 ,{5,n0}
5111 ;yT1
5112 plist_n_container{static
5113 const
5114 eZ
5115 plist_n[19];}
5116 ;yV1
5117 const
5118 eZ
5119 plist_n_container
5120 x8::plist_n[19]={{eS1(-2
5121 iZ-1
5122 iZ-0.5
5123 iZ
5124 0
5125 tB2
5126 fp_const_deg_to_rad
5127 cE3
5128 fp_const_einv
5129 cE3
5130 fp_const_log10inv
5131 x8(iZ
5132 0.5
5133 tB2
5134 fp_const_log2
5135 x8(iZ
5136 1
5137 tB2
5138 fp_const_log2inv
5139 x8(iZ
5140 2
5141 tB2
5142 fp_const_log10
5143 cE3
5144 fp_const_e
5145 cE3
5146 fp_const_rad_to_deg
5147 cE3-fp_const_pihalf
5148 x8(),xL1{eS1(0),xL1{fp_const_pihalf
5149 x8(),xL1{fp_const_pi
5150 x8(),xL1}
5151 ;const
5152 xI
5153 plist_s[464]={{{1,15,tC2
5154 15,cNeg,GroupFunction,0}
5155 ,yL1,0x1}
5156 ,{{1,422,tC2
5157 423,tC2
5158 15,tD2
5159 24,tD2
5160 410,tD2
5161 411,cInv,xZ
5162 2,301330,cAdd,tG2
5163 271397
5164 lU1
5165 0x5
5166 tY3
5167 271397,l5
5168 45
5169 lU1
5170 iR
5171 2,58413,l5
5172 140333,l5
5173 194605
5174 lU1
5175 0x1
5176 tY3
5177 224301,l5
5178 270373,l5
5179 270381,l5
5180 271405,l5
5181 271405
5182 lU1
5183 0x5
5184 tY3
5185 140341,l5
5186 223285,l5
5187 286757,l5
5188 286765,l5
5189 322605,l5
5190 232501,l5
5191 7168,l5
5192 30727,l5
5193 141312,l5
5194 179207,l5
5195 58383,l5
5196 59407,l5
5197 285718
5198 lU1
5199 iR
5200 2,59416,l5
5201 29726,l5
5202 34823,l5
5203 18597,l5
5204 46264,l5
5205 15764,l5
5206 57509,l5
5207 293049,l5
5208 292026,l5
5209 161979,l5
5210 161980,l5
5211 172265,l5
5212 173308,l5
5213 243951,l5
5214 247024,l5
5215 38152,l5
5216 46344,l5
5217 293147,l5
5218 1332,l5
5219 24980,l5
5220 183473,l5
5221 183570,l5
5222 418001,l5
5223 420248,cAdd,lP
5224 0,0,tR
5225 0,0,cAdd,i3
5226 1,43,tR
5227 1,51,tR
5228 1,52,tR
5229 1,53,tR
5230 1,54,tR
5231 1,0,lZ
5232 iR
5233 1,0,t51
5234 2}
5235 ,0,iR
5236 1,0,tR
5237 1,21,tR
5238 1,15,tR
5239 1,26,tR
5240 1,24,cAdd,i3
5241 2,56344,cAdd,i3
5242 1,219,tR
5243 1,230,cAdd,i3
5244 1,245,lZ
5245 0x16}
5246 ,{{1,329,lZ
5247 0x16}
5248 ,{{1,399,lZ
5249 iR
5250 1,401,lZ
5251 iR
5252 0,0,t51
5253 1}
5254 ,nJ1,0x0
5255 tY3
5256 46095,tE2
5257 24591,tE2
5258 32783,tE2
5259 37,c1
5260 7205,c1
5261 114725,c1
5262 288805,lJ
5263 0x6
5264 tY3
5265 347173,lJ
5266 0x6
5267 tY3
5268 331813,c1
5269 350245,c1
5270 372773,c1
5271 377893,c1
5272 378917,c1
5273 383013,c1
5274 388133,c1
5275 439333,c1
5276 442405,c1
5277 447525,c1
5278 450597,c1
5279 459813,c1
5280 468005,c1
5281 305201,l2
5282 3,61910016,c1
5283 7168,c1
5284 114688,c1
5285 512000,l2
5286 3,45508608,c1
5287 15,c1
5288 30727,c1
5289 71695,c1
5290 130063,c1
5291 286735,lJ
5292 0x1
5293 tY3
5294 29726,c1
5295 34823,c1
5296 115736,c1
5297 114712,c1
5298 299008,c1
5299 288783
5300 xM2
5301 300032,c1
5302 347151
5303 xM2
5304 357376,l2
5305 3,65425438,c1
5306 420864,c1
5307 280611,c1
5308 358407,c1
5309 301088,c1
5310 55,c1
5311 38143,c1
5312 38143,lJ
5313 iR
5314 2,38145,lJ
5315 iR
5316 2,38152,c1
5317 38171,c1
5318 15631,c1
5319 15711,c1
5320 56671,c1
5321 38262,lJ
5322 iR
5323 2,60820,c1
5324 38325,lJ
5325 iR
5326 3,15777143,c1
5327 37303,c1
5328 48505,l2
5329 3,15777207,c1
5330 347191
5331 xM2
5332 48571,c1
5333 103714,c1
5334 104739,c1
5335 266538,c1
5336 307547,c1
5337 304475,c1
5338 353627,c1
5339 48490,c1
5340 310338,c1
5341 376173,lJ
5342 lP2
5343 3,39173485,lJ
5344 lP2
5345 2,436589,lJ
5346 lP2
5347 2,7578,c1
5348 376232,lJ
5349 lP2
5350 2,436648,lJ
5351 lP2
5352 3,39233901,lJ
5353 lP2
5354 3,39233960,lJ
5355 lP2
5356 2,7651,c1
5357 7675,l2
5358 0,0,nO
5359 0,0,cT
5360 1,37,nO
5361 1,37,cT
5362 1,2,n22
5363 2,n32
5364 3,n22
5365 3,n32
5366 0,nO
5367 1,0,n32
5368 0,cT
5369 1,14,nO
5370 1,16,nO
5371 1,16,lK
5372 1
5373 xN2
5374 21,nO
5375 1,15,nO
5376 1,24,cT
5377 2,24591,nO
5378 1,55,nO
5379 1,55,lK
5380 2
5381 xN2
5382 275,n22
5383 278,n32
5384 284,cT
5385 1,287,nO
5386 1,288,nO
5387 1,289,cT
5388 1,462,cT
5389 2,413757,lK
5390 1
5391 xN2
5392 295,nO
5393 1,329,cT
5394 2,414025,lK
5395 1}
5396 ,0,0x16}
5397 ,{{1,351,nO
5398 1,404,nO
5399 1,410,nO
5400 2,60459,l32
5401 44047,l32
5402 24591,l32
5403 32783,l32
5404 44056,l32
5405 41,lI,41,y0
5406 49,lI,49,y0
5407 365609,lI,222257,lI,365617,lI,366633,lI,366641,lI,48128,lI,15,lI,15,cV1
5408 16,lI,10240,lI,11264,lI,7170,lI,7168,lI,7168,y0
5409 7183,cV1
5410 17408,lI,19456,lI,16384,lI,15360,lI,27648,lI,30720,lI,30722,lI,24,tF2
5411 0x6
5412 tY3
5413 24,lI,7192,lI,68608,lI,83968,lI,86040,lI,87040,lI,88064,lI,90112,lI,432128,lI,433152,lI,37895,lI,14342,lI,25607,lI,7183,lI,56327,lI,114703,lI,114718,lI,257024,lI,419840,lI,260103,lI,37953,tF2
5414 0x5
5415 tY3
5416 37956,y0
5417 37961,tF2
5418 0x5
5419 tY3
5420 38105,lI,38114,y0
5421 38984,y0
5422 44103,y0
5423 44104,y0
5424 38991,lI,44111,lI,44135,lI,44124,y0
5425 44136,lI,48240,lI,60693,lI,38253,y0
5426 38253,lI,38259,tF2
5427 0x5
5428 tY3
5429 38260,cV1
5430 38262,y0
5431 38262,lI,48493,y0
5432 48493,lI,15734,y0
5433 137590,lI,38264,tF2
5434 0x5
5435 tY3
5436 38292,lI,38294,lI,38300,lI,38301,lI,38312,y0
5437 38325,y0
5438 38332,y0
5439 38332,lI,38341,lI,38341,y0
5440 38343,lI,60,lI,60,tF2
5441 0x6
5442 tY3
5443 48552,y0
5444 48552,lI,257198,lI,260274,lI,24792,lI,7172,cPow,PositionalParams,0}
5445 ,nJ1,0x0
5446 tY3
5447 24591,cPow,xZ
5448 2,60440,cPow,xZ
5449 2,60451,cPow,xZ
5450 2,61472,cPow,xZ
5451 1,0,eI3
5452 7,eI3
5453 157,eI3
5454 0,cAcos
5455 eJ3
5456 cAcosh
5457 eJ3
5458 cAsin
5459 eJ3
5460 cAsinh
5461 nR
5462 112,cAsinh
5463 eJ3
5464 cAtan,eF1
5465 cAtan2,tG2
5466 303104
5467 i23
5468 eJ3
5469 cAtanh
5470 eJ3
5471 cCeil,cF3
5472 216,cCeil
5473 eJ3
5474 yO2
5475 0,cCos,cF3
5476 7,yO2
5477 81,yO2
5478 83,yO2
5479 112,yO2
5480 180,yO2
5481 234,yO2
5482 0,cH3
5483 cF3
5484 0,cI3
5485 176,cI3
5486 180,cI3
5487 409,cI3
5488 0,cFloor,cF3
5489 216,cFloor,tG2
5490 308523,eK3
5491 tG2
5492 352555,eK3
5493 tG2
5494 352599,eK3
5495 l0
5496 3,31464448,cU
5497 507534336,cU
5498 508566528,cU
5499 33579008,cU
5500 30443520,lD3
5501 31464448,lD3
5502 7836672,cU
5503 24612864,cU
5504 93415424,cU
5505 142744576,cU
5506 174234624,cU
5507 265547776,cU
5508 435585024,cU
5509 439783424,cU
5510 519553024,cU
5511 526900224,cU
5512 58739160,cU
5513 58739160,lD3
5514 58739166,cU
5515 58739166,cIf,cF3
5516 112,cInt
5517 eJ3
5518 tH2
5519 7,tH2
5520 30,tH2
5521 157,tH2
5522 216,tH2
5523 282,tH2
5524 15,cLog,xZ
5525 1,24,cLog,xZ
5526 1,0,cLog10
5527 eJ3
5528 cLog2,eF1
5529 cMax,tG2
5530 29726,cMax,tG2
5531 34823,cMax
5532 eJ3
5533 cMax,AnyParams,1}
5534 ,0,iR
5535 xG3
5536 cMin,tG2
5537 29726,cMin,tG2
5538 34823,cMin
5539 eJ3
5540 cMin,AnyParams,1}
5541 ,0,iR
5542 2,46095,cMin,xZ
5543 2,24591,cMin,xZ
5544 1,0,n42
5545 0,cSin,cF3
5546 7,n42
5547 81,n42
5548 83,n42
5549 112,n42
5550 139,n42
5551 161,cSin,nU
5552 0x5}
5553 ,{{1,216,n42
5554 227,n42
5555 231,cSin,nU
5556 0x1}
5557 ,{{1,234,n42
5558 0,cSinh,cF3
5559 0,cSinh
5560 nR
5561 161,cSinh,nU
5562 0x5}
5563 ,{{1,176,cSinh
5564 nR
5565 216,cSinh
5566 nR
5567 227,cSinh
5568 nR
5569 234,cSinh
5570 nR
5571 409,cSinh
5572 eJ3
5573 yP2
5574 0,cTan,cF3
5575 75,cTan,cF3
5576 76,yP2
5577 161,yP2
5578 216,yP2
5579 231,yP2
5580 227,yP2
5581 234,yP2
5582 0,xV2
5583 0,cTanh,cF3
5584 160,xV2
5585 161,xV2
5586 216,xV2
5587 227,xV2
5588 234,xV2
5589 0,cTrunc,tG2
5590 15384,cSub,xZ
5591 2,15384,cDiv,xZ
5592 2,420251,cDiv,xZ
5593 xG3
5594 tK2
5595 nU
5596 t41
5597 tK2
5598 tG2
5599 30720,tK2
5600 nU
5601 0x20
5602 tY3
5603 30727,tK2
5604 nU
5605 0x24
5606 tY3
5607 30727,tK2
5608 tG2
5609 114743,tK2
5610 tG2
5611 114743,t71,tG2
5612 39936,cLess,l6
5613 2,39936,cLess,tG2
5614 7,cLess,eF1
5615 cLess,nU
5616 t41
5617 cLessOrEq,tG2
5618 256216,cLessOrEq,tG2
5619 39936,e82
5620 l6
5621 2,39936,e82
5622 tG2
5623 7,e82
5624 eF1
5625 e82
5626 nU
5627 t41
5628 cGreaterOrEq,tG2
5629 256216,cGreaterOrEq
5630 eJ3
5631 l42
5632 7,l42
5633 15,l42
5634 30,l42
5635 156,l42
5636 494,l42
5637 497,l42
5638 498,l42
5639 501,l42
5640 504,l42
5641 505,cNot,eF1
5642 l52
5643 29726,l52
5644 34823,l52
5645 394270,l52
5646 398366,l52
5647 7651,cAnd,lP
5648 0,0,cAnd,AnyParams,1}
5649 ,0,0x0}
5650 ,{{xG3
5651 nJ2
5652 29726,nJ2
5653 34823,nJ2
5654 394270,nJ2
5655 398366,nJ2
5656 7651,cOr,lP
5657 1,0
5658 t31
5659 81
5660 t31
5661 121
5662 t31
5663 156
5664 t31
5665 159
5666 t31
5667 216,cDeg
5668 nR
5669 216,cRad,eF1
5670 cAbsAnd,lP
5671 xG3
5672 cAbsOr,lP
5673 1,0,yR3
5674 eJ3
5675 cAbsNotNot,l0
5676 3,31464448,eP3
5677 nU
5678 0x0}
5679 ,}
5680 ;}
5681 iO2
5682 l41{const
5683 Rule
5684 grammar_rules[253]={{ProduceNewTree,1,1,0,{1,0,cAbs,xJ
5685 361,{1,172,cAtan,xJ
5686 354
5687 tS
5688 1337
5689 i23,xJ
5690 356
5691 tS
5692 320513
5693 i23
5694 l7
5695 2,2,222424
5696 tS
5697 226524
5698 i23
5699 l7
5700 2,2,224474
5701 tS
5702 228574
5703 i23,xJ
5704 148
5705 x13
5706 cCeil,xJ
5707 435,{1,80,tL2
5708 429,{1,115,tL2
5709 430,{1,117,tL2
5710 146,{1,118,tL2
5711 370,{1,116,tL2
5712 0,{1,354,cCos
5713 l7
5714 2,1,0,{1,351,cCos
5715 l7
5716 2,1,216
5717 x13
5718 tL2
5719 314,{1,357,cCosh
5720 l7
5721 2,1,0,{1,351,cCosh
5722 l7
5723 2,1,216
5724 x13
5725 cH3
5726 xJ
5727 144
5728 x13
5729 cFloor,xJ
5730 403,{1,114,cFloor,eL3
5731 214,{3,7379968,c8
5732 518,{3,31464450,c8
5733 499,{3,8428544,c8
5734 501,{3,8434688,c8
5735 215,{3,40901632,c8
5736 494,{3,40902656,c8
5737 507,{3,40940544,c8
5738 506,{3,47194112,c8
5739 483,{3,47225856,c8
5740 414,{3,1058266,c8
5741 418,{3,1058272,c8
5742 418,{3,9438682,c8
5743 414,{3,9438688,c8
5744 460,{3,396733911,c8
5745 460,{3,381020637,cIf
5746 l7
5747 0,3,31492569,{3,35682779,cIf
5748 l7
5749 0,3,31492575,{3,35682785,cIf,xJ
5750 111,{1,228,eM3
5751 110,{1,244,eM3
5752 355,{1,106,eM3
5753 204,{1,205,cLog
5754 l7
5755 0,1,395
5756 cP2,cMax
5757 yF
5758 0
5759 tS
5760 431105,cMax
5761 yF
5762 396
5763 cP2,cMin
5764 yF
5765 0
5766 tS
5767 427009,cMin,AnyParams,0}
5768 }
5769 ,{ProduceNewTree,0,1,203
5770 tS
5771 24804,cPow,eL3
5772 203
5773 tS
5774 25827,cPow,eL3
5775 202
5776 tS
5777 126991,cPow
5778 xM1
5779 30988,cPow
5780 xM1
5781 30989,cPow
5782 xM1
5783 30990,cPow
5784 t93
5785 166239
5786 tS
5787 31066,cPow
5788 xM1
5789 32015,cPow
5790 t93
5791 7168
5792 tS
5793 12639,cPow
5794 t93
5795 7392
5796 tS
5797 12535
5798 x23
5799 380
5800 tS
5801 44095
5802 x23
5803 381
5804 tS
5805 44141
5806 x23
5807 382
5808 tS
5809 44140
5810 x23
5811 201
5812 tS
5813 109583
5814 x23
5815 200
5816 tS
5817 132129
5818 x23
5819 155
5820 tS
5821 133153
5822 n52
5823 419840
5824 tS
5825 413711
5826 n52
5827 254976
5828 tS
5829 253967
5830 n52
5831 221184
5832 tS
5833 251937
5834 n52
5835 221184
5836 tS
5837 248850
5838 x23
5839 150
5840 x13
5841 yQ2
5842 372,{1,80,yQ2
5843 146,{1,115,yQ2
5844 370,{1,117,yQ2
5845 149,{1,118,yQ2
5846 429,{1,116,yQ2
5847 0,{1,356,yQ2
5848 152
5849 x13
5850 cSinh,xJ
5851 312,{1,355,cSinh,xJ
5852 153
5853 x13
5854 eN3
5855 0,{1,359,eN3
5856 170,{1,360,eN3
5857 154
5858 x13
5859 cTanh
5860 l7
5861 0,1,392
5862 tS
5863 395279,tM2
5864 391
5865 cP2,tM2
5866 199
5867 tS
5868 242924,tM2
5869 198
5870 tS
5871 230636,tM2
5872 164
5873 tS
5874 240869,tM2
5875 163
5876 tS
5877 240660,t51
5878 0
5879 nM1
5880 263,{1,311,t51
5881 1
5882 nM1
5883 262,{1,310,t51
5884 1
5885 l1
5886 2,1,261
5887 tS
5888 1333
5889 lW1
5890 259
5891 tS
5892 1331
5893 lW1
5894 407
5895 tS
5896 415124
5897 lW1
5898 45
5899 tS
5900 331093
5901 lW1
5902 324
5903 tS
5904 146477
5905 lW1
5906 342
5907 tS
5908 145453
5909 lW1
5910 427
5911 tS
5912 213202
5913 lW1
5914 428
5915 tS
5916 217298
5917 lW1
5918 368
5919 tS
5920 216270
5921 lW1
5922 145
5923 tS
5924 216271
5925 lW1
5926 369
5927 tS
5928 218318
5929 lW1
5930 197
5931 tS
5932 144665
5933 lW1
5934 194
5935 tS
5936 348441
5937 lW1
5938 193
5939 tS
5940 348300
5941 lW1
5942 195
5943 tS
5944 200875
5945 lW1
5946 192
5947 tS
5948 177323
5949 lW1
5950 257
5951 tS
5952 446837
5953 lW1
5954 181
5955 tS
5956 446653
5957 lW1
5958 151
5959 tS
5960 187765
5961 lW1
5962 147
5963 tS
5964 187828
5965 lW1
5966 255
5967 tS
5968 195957
5969 lW1
5970 374
5971 tS
5972 264383
5973 lW1
5974 437
5975 tS
5976 264381
5977 lW1
5978 437
5979 tS
5980 186741
5981 lW1
5982 374
5983 tS
5984 262580
5985 lW1
5986 151
5987 tS
5988 262333,tM2
5989 98
5990 tS
5991 1155
5992 eG1
5993 97
5994 tS
5995 1156
5996 eG1
5997 305
5998 tS
5999 1330
6000 eG1
6001 99
6002 tS
6003 24704
6004 eG1
6005 100
6006 tS
6007 24698
6008 eG1
6009 394
6010 tS
6011 395279
6012 eG1
6013 393
6014 cP2
6015 eG1
6016 353
6017 tS
6018 360799
6019 eG1
6020 96
6021 tS
6022 89360
6023 eG1
6024 105
6025 tS
6026 80155
6027 eG1
6028 95
6029 tS
6030 79131
6031 cQ2
6032 56671
6033 tS
6034 1424
6035 cQ2
6036 15711
6037 tS
6038 1426
6039 cQ2
6040 107535
6041 tS
6042 93467
6043 cQ2
6044 97295
6045 tS
6046 96539,l8
6047 1,1,0,{1,351,l8
6048 1,1,55,{1,14,lK
6049 0
6050 nM1
6051 93
6052 tS
6053 70674,cMul,SelectedParams,0
6054 nM1
6055 512,{1,50,lK
6056 1
6057 nM1
6058 513,{1,40,lK
6059 1
6060 l1
6061 2,1,435
6062 tS
6063 443429,eA
6064 442
6065 tS
6066 451621,eA
6067 336
6068 tS
6069 382285,eA
6070 437
6071 tS
6072 382406,eA
6073 374
6074 tS
6075 446801,eA
6076 365
6077 tS
6078 435534,eA
6079 444
6080 tS
6081 325033,eA
6082 318
6083 tS
6084 340413,eA
6085 335
6086 tS
6087 375116,eA
6088 424
6089 tS
6090 375229,eA
6091 45
6092 tS
6093 456126,eA
6094 450
6095 tS
6096 328114,eA
6097 45
6098 tS
6099 460223,eA
6100 452
6101 tS
6102 461861,eA
6103 453
6104 tS
6105 329140,eA
6106 322
6107 tS
6108 341446,eA
6109 456
6110 tS
6111 335286,eA
6112 448
6113 tS
6114 327087,eA
6115 459
6116 tS
6117 469029,eA
6118 455
6119 tS
6120 311360,eA
6121 338
6122 tS
6123 309322,eA
6124 412
6125 tS
6126 43412,eA
6127 330
6128 tS
6129 49480,eA
6130 413
6131 tS
6132 47508,eA
6133 331
6134 tS
6135 45384,l8
6136 2,2,334277
6137 tS
6138 333236
6139 cQ2
6140 39936
6141 tS
6142 xH3
6143 cEqual
6144 yP
6145 cEqual
6146 yQ
6147 cEqual
6148 yR
6149 cEqual
6150 lA1
6151 24807
6152 t61
6153 iD
6154 t61
6155 l62
6156 237799
6157 t61
6158 n11
6159 cEqual
6160 l72
6161 tK2
6162 eH1
6163 39,tK2
6164 eO3
6165 0
6166 tS
6167 5165,cEqual
6168 t93
6169 39936
6170 tS
6171 xH3
6172 t71
6173 yP
6174 t71
6175 yQ
6176 t71
6177 yR
6178 t71
6179 lA1
6180 24807
6181 tI2
6182 iD
6183 tI2
6184 l62
6185 237799
6186 tI2
6187 n11
6188 t71
6189 l72
6190 t71
6191 tJ2
6192 39,t71,eH1
6193 5165,t71
6194 yP
6195 cLess
6196 yQ
6197 cLess
6198 yR
6199 cLess,xJ
6200 516
6201 tS
6202 44032,cLess
6203 lA1
6204 24804
6205 t21
6206 yM1
6207 t21
6208 iD
6209 t21
6210 l62
6211 237796
6212 t21
6213 xN1
6214 t21
6215 n11
6216 cLess
6217 l72
6218 cLess
6219 tJ2
6220 xH3
6221 cLess
6222 yP
6223 cLessOrEq
6224 yQ
6225 cLessOrEq
6226 yR
6227 cLessOrEq,xJ
6228 510
6229 tS
6230 359439,cLessOrEq
6231 lA1
6232 24804
6233 xC1
6234 yM1
6235 xC1
6236 iD
6237 xC1
6238 l62
6239 237796
6240 xC1
6241 xN1
6242 xC1
6243 n11
6244 cLessOrEq
6245 l72
6246 cLessOrEq
6247 tJ2
6248 359469,cLessOrEq
6249 yP
6250 cGreater
6251 yQ
6252 cGreater
6253 yR
6254 e82
6255 xJ
6256 487
6257 tS
6258 359439,cGreater
6259 lA1
6260 24804
6261 y61
6262 yM1
6263 y61
6264 iD
6265 y61
6266 l62
6267 237796
6268 y61
6269 xN1
6270 y61
6271 n11
6272 cGreater
6273 l72
6274 e82
6275 eH1
6276 359469,cGreater
6277 yP
6278 cGreaterOrEq
6279 yQ
6280 cGreaterOrEq
6281 yR
6282 cGreaterOrEq,xJ
6283 517
6284 tS
6285 44032
6286 yX
6287 473304
6288 tS
6289 24804
6290 yX
6291 yM1
6292 yX
6293 iD
6294 yX
6295 l62
6296 237796
6297 yX
6298 xN1
6299 yX
6300 7168
6301 tS
6302 279818
6303 yX
6304 lB1
6305 cGreaterOrEq,eH1
6306 xH3
6307 cGreaterOrEq,eL3
6308 516,{1,2,cNot,eO3
6309 469,{1,123,cNot,eL3
6310 511,{1,5,cAnd,AnyParams,1
6311 l1
6312 0,1,514
6313 tS
6314 13314,cAnd
6315 yF
6316 397
6317 cP2,cAnd
6318 yF
6319 491
6320 tS
6321 496099,cAnd
6322 yF
6323 492
6324 tS
6325 399846,cAnd
6326 yF
6327 493
6328 tS
6329 393702,cAnd,AnyParams,0
6330 l1
6331 0,2,479697,{3,489115088,cAnd
6332 yF
6333 515
6334 tS
6335 13314,xI3
6336 508
6337 tS
6338 8197,xI3
6339 398
6340 cP2,xI3
6341 488
6342 tS
6343 496099,xI3
6344 489
6345 tS
6346 399846,xI3
6347 490
6348 tS
6349 393702,xI3
6350 509
6351 tS
6352 136197,cOr,AnyParams,0}
6353 }
6354 ,{ProduceNewTree,0,1,517,{1,2,xJ3
6355 l3
6356 1,1,0,{1,0,xJ3
6357 eO3
6358 470,{1,123,xJ3
6359 xJ
6360 482,{1,228,cAbsNotNot,AnyParams,0
6361 nM1
6362 476,{1,227,cAbsNotNot,AnyParams,0}
6363 }
6364 ,{ProduceNewTree,0,1,383,{3,31464955,eP3
6365 eL3
6366 517,{3,40940544,eP3
6367 eL3
6368 516,{3,47225856,i03
6369 l7
6370 0,3,31492569,{3,35682779,eP3
6371 PositionalParams,0}
6372 }
6373 ,}
6374 ;e92
6375 grammar_optimize_abslogical_type{xS
6376 9
6377 eI
6378 grammar_optimize_abslogical_type
6379 grammar_optimize_abslogical={9,{21,183,219,228,231,237,244,249,252}
6380 }
6381 ;}
6382 e92
6383 grammar_optimize_ignore_if_sideeffects_type{xS
6384 59
6385 eI
6386 grammar_optimize_ignore_if_sideeffects_type
6387 grammar_optimize_ignore_if_sideeffects={59,{0,20,22,23,24,25,26,27,cV
6388 tY1
6389 78,cZ
6390 xR
6391 grammar_optimize_nonshortcut_logical_evaluation_type{xS
6392 56
6393 eI
6394 grammar_optimize_nonshortcut_logical_evaluation_type
6395 grammar_optimize_nonshortcut_logical_evaluation={56,{0,26,cV
6396 tY1
6397 78,cZ
6398 158,167,168,169,178,179,191,195,203,207,215,227,229,230,232,233,234,235,236,238,239,240,241,242,243,245,246,247,248,250,251}
6399 }
6400 ;}
6401 e92
6402 grammar_optimize_round1_type{xS
6403 118
6404 eI
6405 grammar_optimize_round1_type
6406 grammar_optimize_round1={118,{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,18,26,cV
6407 37,38,tY1
6408 45,46,47,48,49,50,51,52,53,54,58,59,60,61,62,63,64,65,66,67,68,69,70,71,78,79,80,81,82,83,88,89,90,91,92,93,94,95,96,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,132,xR
6409 grammar_optimize_round2_type{xS
6410 100
6411 eI
6412 grammar_optimize_round2_type
6413 grammar_optimize_round2={100,{0,15,16,17,26,cV
6414 39,40,tY1
6415 45,46,47,48,49,50,51,52,53,54,59,60,72,73,78,79,84,85,86,87,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,117,118,119,120,121,122,123,124,125,126,127,128,133,157,xR
6416 grammar_optimize_round3_type{xS
6417 79
6418 eI
6419 grammar_optimize_round3_type
6420 grammar_optimize_round3={79,{74,75,76,77,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,159,160,161,162,163,164,165,166,170,171,172,173,174,175,176,177,180,181,182,184,185,186,187,188,189,190,192,193,194,196,197,198,199,200,201,202,204,205,206,208,209,210,211,212,213,214,216,217,218,220,221,222,223,224,225,226}
6421 }
6422 ;}
6423 e92
6424 grammar_optimize_round4_type{xS
6425 10
6426 eI
6427 grammar_optimize_round4_type
6428 grammar_optimize_round4={10,{19,55,56,57,130,131,153,154,155,156}
6429 }
6430 ;}
6431 e92
6432 grammar_optimize_shortcut_logical_evaluation_type{xS
6433 53
6434 eI
6435 grammar_optimize_shortcut_logical_evaluation_type
6436 grammar_optimize_shortcut_logical_evaluation={53,{0,26,cV
6437 tY1
6438 78,cZ
6439 158,167,168,169,178,179,191,195,203,207,215,227,229,232,233,234,235,236,239,240,241,242,245,246,247,248,250,251}
6440 }
6441 ;}
6442 }
6443 iO2
6444 l41{yV1
6445 cG2
6446 e01
6447 iL1
6448 paramlist,lC1){index=(paramlist>>(index*10))&1023;if(index>=55
6449 nZ2
6450 cG2(SubFunction
6451 tZ1
6452 plist_s[index-55]);if(index>=36
6453 nZ2
6454 cG2(NumConstant
6455 tZ1
6456 plist_n_container
6457 x8::plist_n[index-36])l81
6458 cG2(ParamHolder
6459 tZ1
6460 plist_p[index]);}
6461 }
6462 #ifdef FP_SUPPORT_OPTIMIZER
6463 #include <stdio.h>
6464 #include <algorithm>
6465 #include <map>
6466 #include <sstream>
6467 xQ
6468 using
6469 iO2
6470 l41;using
6471 iO2
6472 FPoptimizer_CodeTree;using
6473 iO2
6474 FPoptimizer_Optimize;iO2{nT1
6475 It,typename
6476 T,typename
6477 Comp>eI1
6478 MyEqualRange(It
6479 first,It
6480 last,const
6481 T&val,Comp
6482 comp){size_t
6483 len=last-first;while(len>0){size_t
6484 nJ3
6485 len/2;It
6486 n43(first);n43+=half;if(comp(*n43,val)){first=n43;++first;len=len-half-1;}
6487 tP1
6488 comp(val,*n43)){len=half;}
6489 else{It
6490 left(first);{It&cR2=left;It
6491 last2(n43);size_t
6492 len2=last2-cR2;while(len2>0){size_t
6493 half2=len2/2;It
6494 middle2(cR2);middle2+=half2;if(comp(*middle2,val)){cR2=middle2;++cR2;len2=len2-half2-1;}
6495 else
6496 len2=half2;}
6497 }
6498 first+=len;It
6499 right(++n43);{It&cR2=right;It&last2=first;size_t
6500 len2=last2-cR2;while(len2>0){size_t
6501 half2=len2/2;It
6502 middle2(cR2);middle2+=half2;if(comp(val,*middle2))len2=half2;else{cR2=middle2;++cR2;len2=len2-half2-1;}
6503 }
6504 }
6505 return
6506 eI1(left,right);}
6507 }
6508 return
6509 eI1(first,first);}
6510 yT1
6511 OpcodeRuleCompare{i12()(lM1&tree,i02
6512 xW2)const{const
6513 Rule&rule=grammar_rules[xW2]l81
6514 tree
6515 nE<rule
6516 nT2.subfunc_opcode;}
6517 i12()iL1
6518 xW2,const
6519 eR
6520 const{const
6521 Rule&rule=grammar_rules[xW2]l81
6522 rule
6523 nT2.subfunc_opcode<tree
6524 nE;}
6525 }
6526 ;xG1
6527 TestRuleAndApplyIfMatch
6528 eX3
6529 yK2&tree,bool
6530 cD{MatchInfo
6531 x8
6532 info;lZ1
6533 found(false,e1());if((rule.eL1
6534 LogicalContextOnly)&&!cD{yR2
6535 if(nD
6536 IsIntType
6537 x8::result){if(rule.eL1
6538 NotForIntegers)yR2
6539 else{if(rule.eL1
6540 OnlyForIntegers)yR2
6541 for(;;){
6542 #ifdef DEBUG_SUBSTITUTIONS
6543 #endif
6544 found=TestParams(rule
6545 nT2,tree,found.specs,info,true);if(found.found)break;if(!&*found.specs){fail:;
6546 #ifdef DEBUG_SUBSTITUTIONS
6547 DumpMatch
6548 t81,false);
6549 #endif
6550 nX2}
6551 #ifdef DEBUG_SUBSTITUTIONS
6552 DumpMatch
6553 t81,true);
6554 #endif
6555 SynthesizeRule
6556 t81)nS2}
6557 iO2
6558 FPoptimizer_Optimize{xG1
6559 ApplyGrammar
6560 i01
6561 Grammar&tN2,yK2&tree,bool
6562 cD{if(tree.GetOptimizedUsing()==&tN2){
6563 #ifdef DEBUG_SUBSTITUTIONS
6564 std::cout<<"Already optimized:  "
6565 ;xE3(tree)lN1"\n"
6566 <<std::flush;
6567 #endif
6568 nX2
6569 if(true){bool
6570 changed
6571 i13
6572 switch
6573 xU2
6574 iY2
6575 cNot:case
6576 cNotNot:case
6577 cAnd:case
6578 cOr:for
6579 xK2
6580 0
6581 nP
6582 true))yI1
6583 lC
6584 cIf:case
6585 i03:if(ApplyGrammar(tN2,e72,cV2
6586 cIf))yI1
6587 for
6588 xK2
6589 1
6590 nP
6591 cD)yI1
6592 break;default:for
6593 xK2
6594 0
6595 nP
6596 false))yI1}
6597 if(changed){tree.Mark_Incompletely_Hashed()nS2}
6598 typedef
6599 const
6600 i02
6601 char*lE3;std::pair<lE3,lE3>range=MyEqualRange(tN2.rule_list,tN2.rule_list+tN2.rule_count,tree,OpcodeRuleCompare
6602 x8());if(range.eQ3
6603 range
6604 eE3){
6605 #ifdef DEBUG_SUBSTITUTIONS
6606 yG<i02
6607 char>rules;rules.nH3
6608 range
6609 eE3-range.first);yD
6610 if(IsLogisticallyPlausibleParamsMatch(cW1
6611 nT2
6612 n72
6613 rules
6614 yL*r);}
6615 range.first=&rules[0];range
6616 eE3=&rules[rules
6617 yA3-1]+1;if(range.eQ3
6618 range
6619 eE3){std::cout<<"Input ("
6620 <<FP_GetOpcodeName
6621 xU2)<<")["
6622 <<iT<<"]"
6623 ;if(cD
6624 std::cout<<"(Logical)"
6625 ;i02
6626 first=i21,prev=i21;const
6627 char*sep=", rules "
6628 ;yD
6629 if(first==i21)first=prev=*r;tP1*r==prev+1)prev=*r;else{std::cout<<sep<<first;sep=","
6630 ;if(prev!=first)std::cout<<'-'<<prev;first=prev=*r;}
6631 }
6632 if(eQ3
6633 i21){std::cout<<sep<<first;if(prev!=first)std::cout<<'-'<<prev;}
6634 std::cout<<": "
6635 ;xE3(tree)lN1"\n"
6636 <<std::flush;}
6637 #endif
6638 bool
6639 changed
6640 i13
6641 yD
6642 #ifndef DEBUG_SUBSTITUTIONS
6643 if(!IsLogisticallyPlausibleParamsMatch(cW1
6644 nT2
6645 n72
6646 y81
6647 #endif
6648 if(TestRuleAndApplyIfMatch(cW1,tree,cD){yI1
6649 nM3}
6650 if(changed){
6651 #ifdef DEBUG_SUBSTITUTIONS
6652 std::cout<<"Changed."
6653 <<std::endl
6654 lN1"Output: "
6655 ;xE3(tree)lN1"\n"
6656 <<std::flush;
6657 #endif
6658 tree.Mark_Incompletely_Hashed()nS2}
6659 tree.SetOptimizedUsing(&tN2)l81
6660 false;}
6661 xB1
6662 ApplyGrammars(x2){
6663 #ifdef DEBUG_SUBSTITUTIONS
6664 std
6665 tJ3"grammar_optimize_round1\n"
6666 ;
6667 #endif
6668 n4
6669 grammar_optimize_round1
6670 n53
6671 #ifdef DEBUG_SUBSTITUTIONS
6672 std
6673 tJ3"grammar_optimize_round2\n"
6674 ;
6675 #endif
6676 n4
6677 grammar_optimize_round2
6678 n53
6679 #ifdef DEBUG_SUBSTITUTIONS
6680 std
6681 tJ3"grammar_optimize_round3\n"
6682 ;
6683 #endif
6684 n4
6685 grammar_optimize_round3
6686 n53
6687 #ifndef FP_ENABLE_SHORTCUT_LOGICAL_EVALUATION
6688 #ifdef DEBUG_SUBSTITUTIONS
6689 std
6690 tJ3"grammar_optimize_nonshortcut_logical_evaluation\n"
6691 ;
6692 #endif
6693 n4
6694 grammar_optimize_nonshortcut_logical_evaluation
6695 n53
6696 #endif
6697 #ifdef DEBUG_SUBSTITUTIONS
6698 std
6699 tJ3"grammar_optimize_round4\n"
6700 ;
6701 #endif
6702 n4
6703 grammar_optimize_round4
6704 n53
6705 #ifdef FP_ENABLE_SHORTCUT_LOGICAL_EVALUATION
6706 #ifdef DEBUG_SUBSTITUTIONS
6707 std
6708 tJ3"grammar_optimize_shortcut_logical_evaluation\n"
6709 ;
6710 #endif
6711 n4
6712 grammar_optimize_shortcut_logical_evaluation
6713 n53
6714 #endif
6715 #ifdef FP_ENABLE_IGNORE_IF_SIDEEFFECTS
6716 #ifdef DEBUG_SUBSTITUTIONS
6717 std
6718 tJ3"grammar_optimize_ignore_if_sideeffects\n"
6719 ;
6720 #endif
6721 n4
6722 grammar_optimize_ignore_if_sideeffects
6723 n53
6724 #endif
6725 #ifdef DEBUG_SUBSTITUTIONS
6726 std
6727 tJ3"grammar_optimize_abslogical\n"
6728 ;
6729 #endif
6730 n4
6731 grammar_optimize_abslogical
6732 n53
6733 #undef C
6734 }
6735 }
6736 #endif
6737 #ifdef FP_SUPPORT_OPTIMIZER
6738 #include <algorithm>
6739 #include <assert.h>
6740 #include <cstring>
6741 #include <cmath>
6742 #include <memory> /* for auto_ptr */
6743 xQ
6744 using
6745 iO2
6746 l41;using
6747 iO2
6748 FPoptimizer_CodeTree;using
6749 iO2
6750 FPoptimizer_Optimize;iO2{xG1
6751 TestImmedConstraints
6752 iL1
6753 bitmask,const
6754 eR{switch(bitmask&ValueMask
6755 iY2
6756 Value_AnyNum:case
6757 ValueMask:lC
6758 n12:if(GetEvennessInfo
6759 nO3
6760 l82
6761 Value_OddInt:if(GetEvennessInfo
6762 nO3
6763 n82
6764 t01:if(GetIntegerInfo
6765 nO3
6766 l82
6767 Value_NonInteger:if(GetIntegerInfo
6768 nO3
6769 n82
6770 eE1:if(!IsLogicalValue(tree)yI
6771 nK1
6772 SignMask
6773 iY2
6774 Sign_AnySign:lC
6775 nJ1:if(l01
6776 l82
6777 n02:if(l01
6778 n82
6779 Sign_NoIdea:if(l01
6780 Unknown
6781 yI
6782 nK1
6783 OnenessMask
6784 iY2
6785 Oneness_Any:case
6786 OnenessMask:lC
6787 Oneness_One:if(!cW2
6788 if(!fp_equal(fp_abs(yZ3),eS1(1))yI
6789 lC
6790 Oneness_NotOne:if(!cW2
6791 if(fp_equal(fp_abs(yZ3),eS1(1))yI
6792 nK1
6793 ConstnessMask
6794 iY2
6795 Constness_Any:lC
6796 yL1:if(!cW2
6797 lC
6798 Constness_NotConst:if(cW2
6799 nM3
6800 return
6801 true;}
6802 n73<i02
6803 extent,i02
6804 nbits,typename
6805 cS2=i02
6806 int>e92
6807 nbitmap{private:static
6808 const
6809 i02
6810 bits_in_char=8;static
6811 const
6812 i02
6813 cT2=(xK3
6814 cS2)*bits_in_char)/nbits;cS2
6815 data[(extent+cT2-1)/cT2];e13
6816 void
6817 inc(lC1,int
6818 by=1){data[pos(index)]+=by*cS2(1<<xX2);i6
6819 void
6820 dec(lC1){inc(index,-1);}
6821 int
6822 get(lC1
6823 n61(data[pos(index)]>>xX2)&mask()xJ2
6824 pos(lC1){return
6825 index/cT2
6826 xJ2
6827 shift(lC1){return
6828 nbits*(index%cT2)xJ2
6829 mask(){return(1<<nbits)-1
6830 xJ2
6831 mask(lC1){return
6832 mask()<<xX2;}
6833 }
6834 ;e92
6835 c83{int
6836 SubTrees:8;int
6837 Others:8;int
6838 i31:8;int
6839 cG3:8;nbitmap<iE2,2>SubTreesDetail;c83(){std::memset(this,0,xK3*this));}
6840 c83
6841 i01
6842 c83&b){std::memcpy(this,&b,xK3
6843 b));}
6844 c83&e31=i01
6845 c83&b){std::memcpy(this,&b,xK3
6846 b))l81*this;}
6847 }
6848 ;yV1
6849 c83
6850 CreateNeedList_uncached(t0&cB2){c83
6851 x11
6852 xS3
6853 a=0;a<cB2
6854 xY2;++a){const
6855 cG2&lF3=e01
6856 x8(cB2.param_list,a);xT3
6857 lZ2
6858 const
6859 xI&t82
6860 xI*x01;yZ
6861 GroupFunction)++tA3;else{++tA2;assert(param.data.subfunc_opcode<VarBegin);x11.SubTreesDetail.inc
6862 iZ2
6863 cS);}
6864 ++x11.i31;nM3
6865 case
6866 NumConstant:case
6867 ParamHolder:++t92;++x11.i31;nM3}
6868 return
6869 x11;}
6870 yV1
6871 c83&CreateNeedList(t0&cB2){typedef
6872 std::map<t0*,c83>cX1;static
6873 cX1
6874 yO1;cX1::nX3
6875 i=yO1.xE2&cB2);if(i!=yO1.cP1&cB2
6876 nZ2
6877 i
6878 cJ2
6879 l81
6880 yO1.nT3,std::make_pair(&cB2,CreateNeedList_uncached
6881 x8(cB2)))cJ2;}
6882 yV1
6883 yK2
6884 CalculateGroupFunction
6885 i01
6886 cG2&xZ2
6887 const
6888 t9
6889 info){xT3
6890 NumConstant:{const
6891 eZ&t82
6892 eZ*x01
6893 l81
6894 CodeTreeImmed
6895 iZ2
6896 xZ3)cM3
6897 lY2
6898 yK3&t82
6899 xH*x01
6900 l81
6901 info.GetParamHolderValueIfFound
6902 iZ2
6903 index)iD2
6904 const
6905 xI&t82
6906 xI*x01
6907 yJ
6908 result;result
6909 tU
6910 xF3
6911 cS);tC1
6912 iE1).reserve
6913 iZ2
6914 data
6915 xY2)xS3
6916 a=0;a<xF3
6917 data
6918 xY2;++a)nG1
6919 tmp(CalculateGroupFunction(e01
6920 x8
6921 iZ2
6922 data.param_list,a),info));result
6923 yA
6924 tmp);}
6925 tC1
6926 Rehash()l81
6927 result;}
6928 }
6929 return
6930 yK2();}
6931 }
6932 iO2
6933 FPoptimizer_Optimize{xG1
6934 IsLogisticallyPlausibleParamsMatch(t0&cB2,const
6935 eR{c83
6936 x11(CreateNeedList
6937 x8(cB2));size_t
6938 eR3=iT;if(eR3<size_t(x11.i31)){nX2
6939 for
6940 xK2
6941 0;a<eR3;++a){i02
6942 opcode=xI2
6943 nE;switch(opcode
6944 iY2
6945 cImmed:if(tA3>0)--tA3;else--t92;lC
6946 iE2:case
6947 cFCall:case
6948 cPCall:--t92;break;default:assert(opcode<VarBegin);if(tA2>0&&x11.SubTreesDetail.get(opcode)>0){--tA2;x11.SubTreesDetail.dec(opcode);}
6949 else--t92;}
6950 }
6951 if(tA3>0||tA2>0||t92>0){nX2
6952 if(cB2.match_type!=AnyParams){if(0||tA2<0||t92<0){nX2}
6953 return
6954 true;}
6955 yV1
6956 lZ1
6957 TestParam
6958 i01
6959 cG2&xZ2
6960 lM1&tree
6961 eA2
6962 start_at,t9
6963 info){xT3
6964 NumConstant:{const
6965 eZ&t82
6966 eZ*x01;if(!cW2
6967 eS1
6968 imm=yZ3;switch
6969 iZ2
6970 modulo
6971 iY2
6972 Modulo_None:lC
6973 Modulo_Radians:imm=fp_mod(imm,y8
6974 imm<0)imm
6975 c5
6976 if(imm>fp_const_pi
6977 x8())imm-=fp_const_twopi
6978 x8(nW2
6979 return
6980 fp_equal(imm,xF3
6981 xZ3)cM3
6982 lY2
6983 yK3&t82
6984 xH*x01;if(!x0
6985 return
6986 info.SaveOrTestParamHolder
6987 iZ2
6988 index,tree)iD2
6989 const
6990 xI&t82
6991 xI*x01;yZ
6992 GroupFunction){if(!x0
6993 yK2
6994 xO1=CalculateGroupFunction(xZ2
6995 info);
6996 #ifdef DEBUG_SUBSTITUTIONS
6997 DumpHashes(xO1)lN1*i01
6998 void**)&xO1.xJ1
6999 lN1"\n"
7000 lN1*i01
7001 void**)&yZ3
7002 lN1"\n"
7003 ;DumpHashes(tree)lN1"Comparing "
7004 ;xE3(xO1)lN1" and "
7005 ;xE3(tree)lN1": "
7006 lN1(xO1
7007 iA
7008 tree)?"true"
7009 :"false"
7010 )lN1"\n"
7011 ;
7012 #endif
7013 return
7014 xO1
7015 iA
7016 tree);}
7017 else{if(!&*start_at){if(!x0
7018 if
7019 xU2!=xF3
7020 cS
7021 yI}
7022 return
7023 TestParams
7024 iZ2
7025 data,tree,start_at,info,false);}
7026 }
7027 }
7028 nX2
7029 yT1
7030 iS
7031 x22
7032 MatchInfo
7033 x8
7034 info;iS()yC3,info(){}
7035 }
7036 ;iP2
7037 MatchPositionSpec_PositionalParams:xP1
7038 iS
7039 x8>{e13
7040 iF2
7041 MatchPositionSpec_PositionalParams(xL3):xM3
7042 iS
7043 x8>(n){}
7044 }
7045 ;e92
7046 i41
7047 x22
7048 i41()yC3{}
7049 }
7050 ;class
7051 c0:xP1
7052 i41>{e13
7053 i02
7054 trypos;iF2
7055 c0(xL3):xM3
7056 i41>(n),trypos(0){}
7057 }
7058 ;yV1
7059 lZ1
7060 TestParam_AnyWhere
7061 i01
7062 cG2&xZ2
7063 lM1&tree
7064 eA2
7065 start_at,t9
7066 info,yG<bool>&used,bool
7067 tA1{xN<c0>x6;i02
7068 lG3
7069 c0
7070 n92
7071 a=x6->trypos;goto
7072 retry_anywhere_2
7073 x42
7074 c0(iT);a=0;}
7075 eS3
7076 iT;++a){if(used[a])y81
7077 retry_anywhere:{lZ1
7078 r=TestParam(xZ2
7079 xI2
7080 lH3);lI3
7081 used[a]=true;if(tA1
7082 eT3
7083 a);x6->trypos=a
7084 l81
7085 lZ1(true,&*x6);}
7086 }
7087 retry_anywhere_2:if(&*lV1){goto
7088 retry_anywhere;}
7089 }
7090 nX2
7091 yT1
7092 y91
7093 x22
7094 MatchInfo
7095 x8
7096 info;yG<bool>used;iF2
7097 y91(size_t
7098 eR3)yC3,info(),used(eR3){}
7099 }
7100 ;iP2
7101 MatchPositionSpec_AnyParams:xP1
7102 y91
7103 x8>{e13
7104 iF2
7105 MatchPositionSpec_AnyParams(xL3,size_t
7106 m):xM3
7107 y91
7108 x8>(n,y91
7109 x8(m)){}
7110 }
7111 ;yV1
7112 lZ1
7113 TestParams(t0&nM,lM1&tree
7114 eA2
7115 start_at,t9
7116 info,bool
7117 tA1{if(nM.match_type!=AnyParams){if(xT!=iT
7118 yI}
7119 if(!IsLogisticallyPlausibleParamsMatch(nM
7120 n72{nX2
7121 switch(nM.match_type
7122 iY2
7123 PositionalParams:{xN<cL>x6;i02
7124 lG3
7125 cL
7126 n92
7127 a=xT-1;goto
7128 lD1
7129 x42
7130 cL(xT);a=0;}
7131 eS3
7132 xT;++a){cX2=info;retry_positionalparams:{lZ1
7133 r=TestParam(cX
7134 a),xI2
7135 lH3);lI3
7136 y81}
7137 }
7138 lD1:if(&*lV1){info=cX2;goto
7139 retry_positionalparams;}
7140 if(a>0){--a;goto
7141 lD1;}
7142 info=(*x6)[0].info
7143 l81
7144 false;}
7145 if(tA1
7146 for
7147 iL1
7148 a=0;a<xT;++a)eT3
7149 a)l81
7150 lZ1(true,&*x6)cM3
7151 SelectedParams:case
7152 AnyParams:{xN<t6>x6;yG<bool>used(iT);yG<i02>iG2(xT);yG<i02>y02(xT)lO1{const
7153 cG2
7154 lF3=cX
7155 a);iG2[a]=ParamSpec_GetDepCode(lF3);}
7156 {i02
7157 b=0
7158 lO1
7159 if(iG2[a]!=0)y02[b++]=a
7160 lO1
7161 if(iG2[a]==0)y02[b++]=a;}
7162 i02
7163 lG3
7164 t6
7165 n92
7166 if(xT==0){a=0;goto
7167 retry_anyparams_4;}
7168 a=xT-1;goto
7169 cY1
7170 x42
7171 t6(xT,iT);a=0;if(xT!=0){(*x6)[0].info=info;(*x6)[0].used=used;}
7172 }
7173 eS3
7174 xT;++a){if(a>0){cX2=info;(*x6)[a].used=used;}
7175 retry_anyparams:{lZ1
7176 r=TestParam_AnyWhere
7177 x8(cX
7178 y02[a]),tree
7179 lH3,used,tA1;lI3
7180 y81}
7181 }
7182 cY1:if(&*lV1){info=cX2;used=(*x6)[a].used;goto
7183 retry_anyparams;}
7184 cZ1:if(a>0){--a;goto
7185 cY1;}
7186 info=(*x6)[0].info
7187 l81
7188 false;}
7189 retry_anyparams_4:if(nM.n2!=0){if(!TopLevel||!info.HasRestHolder(nM.n2)){yG
7190 nV1
7191 yS2;yS2.nH3
7192 iT)xS3
7193 b=0;b<iT;++b){if(xN3)y81
7194 yS2
7195 yL
7196 tree
7197 lD
7198 b));xN3=true;if(tA1
7199 eT3
7200 b);}
7201 if(!info.SaveOrTestRestHolder(nM.n2,yS2)){goto
7202 cZ1;}
7203 }
7204 else{lL1&yS2=info.GetRestHolderValues(nM.n2)c23
7205 0;a<yS2
7206 eW2
7207 a){bool
7208 found=false
7209 xS3
7210 b=0;b<iT;++b){if(xN3)y81
7211 if(yS2[a]iA
7212 tree
7213 lD
7214 b))){xN3=true;if(tA1
7215 eT3
7216 b);found=true;nM3}
7217 if(!found){goto
7218 cZ1;}
7219 }
7220 }
7221 }
7222 return
7223 lZ1(true,xT?&*x6:0)cM3
7224 GroupFunction:nM3
7225 nX2}
7226 #endif
7227 #ifdef FP_SUPPORT_OPTIMIZER
7228 #include <algorithm>
7229 #include <assert.h>
7230 using
7231 iO2
7232 FPoptimizer_CodeTree;using
7233 iO2
7234 FPoptimizer_Optimize;iO2{yV1
7235 yK2
7236 xQ1
7237 const
7238 cG2&xZ2
7239 t9
7240 info,bool
7241 inner=true){xT3
7242 NumConstant:{const
7243 eZ&t82
7244 eZ*x01
7245 l81
7246 CodeTreeImmed
7247 iZ2
7248 xZ3)cM3
7249 lY2
7250 yK3&t82
7251 xH*x01
7252 l81
7253 info.GetParamHolderValue
7254 iZ2
7255 index)iD2
7256 const
7257 xI&t82
7258 xI*x01
7259 yJ
7260 tree;tH
7261 xF3
7262 cS)xS3
7263 a=0;a<xF3
7264 data
7265 xY2;++a)nG1
7266 nparam=xQ1
7267 e01
7268 x8
7269 iZ2
7270 data.param_list,a),info,true
7271 tT
7272 yA
7273 nparam);}
7274 if
7275 iZ2
7276 data.n2!=0){yG
7277 nV1
7278 trees(info.GetRestHolderValues
7279 iZ2
7280 data.n2)tT.AddParamsMove(trees);if(iT==1){assert(tree.tU3()==cAdd tI3()==cMul tI3()==cMin tI3()==cMax tI3()==cAnd tI3()==cOr tI3()==cAbsAnd tI3()==cAbsOr);tree.xO2
7281 0));}
7282 tP1
7283 iT==0){switch
7284 xU2
7285 iY2
7286 cAdd:case
7287 cOr:tree=nB1
7288 0));lC
7289 cMul:case
7290 cAnd:tree=nB1
7291 1));default:nM3}
7292 }
7293 if(inner)tree
7294 x02
7295 l81
7296 tree;}
7297 }
7298 return
7299 yK2();}
7300 }
7301 iO2
7302 FPoptimizer_Optimize{xB1
7303 SynthesizeRule
7304 eX3
7305 yK2&tree,t9
7306 info){switch(rule.ruletype
7307 iY2
7308 ProduceNewTree:{tree.Become(xQ1
7309 e01
7310 x21
7311 0),info,false)nW2
7312 case
7313 ReplaceParams:default:{yG<i02>list=info.GetMatchedParamIndexes();std::sort(list.i62
7314 list.end())c23
7315 list
7316 yA3;a-->0;)tree.iH1
7317 list[a])xS3
7318 a=0;a<rule.repl_param_count;++a)nG1
7319 nparam=xQ1
7320 e01
7321 x21
7322 a),info,true
7323 tT
7324 yA
7325 nparam);}
7326 nM3}
7327 }
7328 }
7329 #endif
7330 #ifdef DEBUG_SUBSTITUTIONS
7331 #include <sstream>
7332 #include <cstring>
7333 xQ
7334 using
7335 iO2
7336 l41;using
7337 iO2
7338 FPoptimizer_CodeTree;using
7339 iO2
7340 FPoptimizer_Optimize;iO2
7341 l41{xB1
7342 DumpMatch
7343 eX3
7344 lM1&tree,const
7345 t9
7346 info,bool
7347 DidMatch,std::ostream&o){DumpMatch
7348 t81,DidMatch?tZ3"match"
7349 :tZ3"mismatch"
7350 ,o);}
7351 xB1
7352 DumpMatch
7353 eX3
7354 lM1&tree,const
7355 t9
7356 info,const
7357 char*eY3,std::ostream&o){static
7358 const
7359 char
7360 ParamHolderNames[][2]={"%"
7361 ,"&"
7362 ,"x"
7363 ,"y"
7364 ,"z"
7365 ,"a"
7366 ,"b"
7367 ,"c"
7368 }
7369 ;o<<eY3<<" (rule "
7370 <<(&rule-grammar_rules)<<")"
7371 <<":\n  Pattern    : "
7372 ;{cG2
7373 tmp;tmp.first=SubFunction;xI
7374 tmp2;tmp2.data=rule
7375 nT2;tmp
7376 eE3=i01
7377 void*)&tmp2;DumpParam
7378 x8(tmp,o);}
7379 o<<"\n  Replacement: "
7380 ;DumpParams
7381 x21
7382 rule.repl_param_count,o);o<<"\n"
7383 ;o<<"  Tree       : "
7384 ;xE3(tree,o);o<<"\n"
7385 ;if(!std::strcmp(eY3,tZ3"match"
7386 ))DumpHashes(tree,o)c23
7387 0;a<i33
7388 eW2
7389 a){if(!i33[a].iA1
7390 y81
7391 o<<"           "
7392 <<ParamHolderNames[a]<<" = "
7393 ;xE3(i33[a],o);o<<"\n"
7394 ;}
7395 eW3
7396 info.lQ
7397 eW2
7398 b){if(!eH2
7399 first)y81
7400 for
7401 xK2
7402 0;a<eH2
7403 second
7404 eW2
7405 a){o<<"         <"
7406 <<b<<"> = "
7407 ;xE3(eH2
7408 second[a],o);o<<std::endl;}
7409 }
7410 o<<std::flush;}
7411 }
7412 #endif
7413 #include <list>
7414 #include <algorithm>
7415 #ifdef FP_SUPPORT_OPTIMIZER
7416 xQ
7417 iO2{xG1
7418 MarkIncompletes(x2){if(tree.Is_Incompletely_Hashed(iF1;bool
7419 i51
7420 i13
7421 for
7422 yS
7423 i51|=MarkIncompletes
7424 nW1
7425 a));if(i51)tree.Mark_Incompletely_Hashed()l81
7426 i51;}
7427 xB1
7428 FixIncompletes(x2){if(tree.Is_Incompletely_Hashed()){for
7429 yS
7430 FixIncompletes
7431 nW1
7432 a)tT
7433 x02;}
7434 }
7435 }
7436 iO2
7437 FPoptimizer_CodeTree{lA
7438 Sort()cX3
7439 Sort();}
7440 lA
7441 Rehash(bool
7442 constantfolding){if(constantfolding)ConstantFolding(*this);else
7443 Sort();data
7444 xB
7445 yV1
7446 l11{c2
7447 e62
7448 eZ3
7449 nP3=0;
7450 #if 0
7451 long
7452 double
7453 value=Value;eB=crc32::calc(i01
7454 i02
7455 char*)&value,xK3
7456 value));key^=(key<<24);
7457 #elif 0
7458 union{e92{i02
7459 char
7460 filler1[16];eS1
7461 v;i02
7462 char
7463 filler2[16];}
7464 buf2;e92{i02
7465 char
7466 filler3[xK3
7467 eS1)+16-x
7468 K3
7469 iC1)];eB;}
7470 buf1;}
7471 data;memset(&data,0,xK3
7472 data));data.buf2.v=Value;eB=data.buf1.key;
7473 #else
7474 int
7475 cE2;eS1
7476 lQ2=std::frexp(Value,&cE2);eB=iL1(cE2+0x8000)&0xFFFF);if(lQ2<0){lQ2=-lQ2;key=key^0xFFFF;}
7477 else
7478 key+=0x10000;lQ2-=yF3;key<<=39;key|=iC1((lQ2+lQ2)*eS1(1u<<31))<<8;
7479 #endif
7480 iU
7481 tM
7482 #ifdef FP_SUPPORT_LONG_INT_TYPE
7483 n73<>l11<long>{c2
7484 long
7485 eZ3
7486 eB=Value;iU
7487 tM
7488 #endif
7489 #ifdef FP_SUPPORT_GMP_INT_TYPE
7490 n73<>l11<GmpInt>{c2
7491 const
7492 GmpInt&eZ3
7493 eB=Value.toInt();iU
7494 tM
7495 #endif
7496 xB1
7497 nO2
7498 x8::Recalculate_Hash_NoRecursion(){fphash_t
7499 iU(iC1(Opcode)<<56,Opcode*tM3(0x1131462E270012B));Depth=1;switch(Opcode
7500 iY2
7501 cImmed:{ImmedHashGenerator
7502 x8::MakeHash(iU,Value
7503 nW2
7504 case
7505 iE2:{nP3|=eC<<48
7506 eC2((eC)*11)^tM3(0x3A83A83A83A83A0);nM3
7507 case
7508 cFCall:case
7509 cPCall:{nP3|=eC<<48
7510 eC2((~eC)*7)^3456789;}
7511 default:{size_t
7512 eM1=0
7513 c23
7514 0;a<c93
7515 eW2
7516 a){if(c93[a].xT2>eM1)eM1=c93[a].xT2;nP3+=((c93[a]eE2
7517 hash1*(a+1))>>12)eC2
7518 c93[a]eE2
7519 hash1
7520 eC2(3)*tM3(0x9ABCD801357);iU.hash2*=tM3(0xECADB912345)eC2(~c93[a]eE2
7521 hash2)^4567890;}
7522 Depth+=eM1;}
7523 }
7524 if(Hash!=iU){Hash=iU;iK1=0;}
7525 }
7526 lA
7527 FixIncompleteHashes(){MarkIncompletes(*this);FixIncompletes(*this);}
7528 }
7529 #endif
7530 #include <cmath>
7531 #include <list>
7532 #include <cassert>
7533 #ifdef FP_SUPPORT_OPTIMIZER
7534 xQ
7535 iO2{using
7536 iO2
7537 FPoptimizer_CodeTree;xG1
7538 x31
7539 lM1&tree,long
7540 count,const
7541 yV2
7542 SequenceOpCode
7543 x8&eQ,yW2&synth,size_t
7544 max_bytecode_grow_length);static
7545 const
7546 e92
7547 SinCosTanDataType{OPCODE
7548 whichopcode;OPCODE
7549 inverse_opcode;enum{nominator,denominator,inverse_nominator,inverse_denominator}
7550 ;OPCODE
7551 codes[4];}
7552 SinCosTanData[12]={{cTan,cCot,{cSin,cCos,cCsc,cSec}
7553 }
7554 ,{cCot,cCot,{cCos,cSin,cSec,cCsc}
7555 }
7556 ,{cCos,cSec,{cSin,cTan,cCsc,cCot}
7557 }
7558 ,{cSec,cCos,{cTan,cSin,cCot,cCsc}
7559 }
7560 ,{cSin,cCsc,{cCos,cCot,cSec,cTan}
7561 }
7562 ,{cCsc,cSin,{cCot,cCos,cTan,cSec}
7563 }
7564 ,{yT2{cSinh,cH3
7565 yY2,{cSinh,cNop,{yT2
7566 cNop,cCosh}
7567 }
7568 ,{cH3
7569 cNop,{cSinh,yT2
7570 cNop}
7571 }
7572 ,{cNop,cTanh,{cH3
7573 cSinh,yY2,{cNop,cSinh,{cNop,cTanh,cH3
7574 cNop}
7575 }
7576 ,{cNop,cH3{cTanh,cSinh,yY2}
7577 ;}
7578 iO2
7579 FPoptimizer_CodeTree{lA
7580 SynthesizeByteCode(yG<i02>&nN,yG
7581 x8&Immed,size_t&stacktop_max){
7582 #ifdef DEBUG_SUBSTITUTIONS
7583 std::cout<<"Making bytecode for:\n"
7584 ;iO
7585 #endif
7586 while(RecreateInversionsAndNegations()){
7587 #ifdef DEBUG_SUBSTITUTIONS
7588 std::cout<<"One change issued, produced:\n"
7589 ;iO
7590 #endif
7591 FixIncompleteHashes();}
7592 #ifdef DEBUG_SUBSTITUTIONS
7593 std::cout<<"Actually synthesizing, after recreating inv/neg:\n"
7594 ;iO
7595 #endif
7596 yW2
7597 synth;SynthesizeByteCode(synth,false
7598 eU3.Pull(nN,Immed,stacktop_max);}
7599 lA
7600 SynthesizeByteCode(yW2&synth,bool
7601 MustPopTemps)const{xR1*this)){return;}
7602 for
7603 xK2
7604 0;a<12;++a){const
7605 SinCosTanDataType&data=SinCosTanData[a];if(data.whichopcode!=cNop){if(lM2!=data.whichopcode)y81
7606 yL2
7607 lJ3;lJ3.lI1
7608 lJ3
7609 tU
7610 data.inverse_opcode);lJ3.y12);xR1
7611 lJ3)){synth.l21
7612 else{if(lM2!=cInv)y81
7613 if(GetParam(0)nE!=data.inverse_opcode)y81
7614 xR1
7615 GetParam(0))){synth.l21
7616 size_t
7617 found[4];eW3
7618 4;++b){yL2
7619 tree;if(data.t03]==cNop){tH
7620 cInv);yL2
7621 lK3;lK3.lI1
7622 lK3
7623 tU
7624 data.t03^2]);lK3.y12
7625 tT
7626 yA
7627 lK3);}
7628 else{tree.lI1
7629 tH
7630 data.t03]);}
7631 tree.y12);found[b]t13
7632 e33(tree);}
7633 if(found[data.y22!=tG
7634 i61
7635 yK
7636 y22);lJ1
7637 i61);lK1
7638 cDiv
7639 nL1
7640 y22!=tG
7641 iV
7642 yK
7643 y22);lJ1
7644 iV);lK1
7645 cMul
7646 nL1
7647 lS1!=tG
7648 iV
7649 yK
7650 lS1);lJ1
7651 iV);lK1
7652 cRDiv
7653 nL1
7654 lS1!=tG
7655 i61
7656 yK
7657 lS1);lJ1
7658 i61);lK1
7659 cMul,2,1
7660 eU3.l21
7661 size_t
7662 n_subexpressions_synthesized=SynthCommonSubExpressions(synth);switch(lM2
7663 iY2
7664 iE2:synth.PushVar(GetVar());lC
7665 cImmed:yX2
7666 xJ1);lC
7667 cAdd:case
7668 cMul:case
7669 cMin:case
7670 cMax:case
7671 cAnd:case
7672 cOr:case
7673 cAbsAnd:case
7674 cAbsOr:{if(lM2==cMul){bool
7675 xU3
7676 i13
7677 c3
7678 lT1
7679 y21&&isLongInteger(lT1.xJ1)){yW1=makeLongInteger(lT1.xJ1);yL2
7680 tmp(*this,typename
7681 yL2::CloneTag());tmp
7682 cP3
7683 tmp
7684 x02;if(x31
7685 tmp,value,yV2
7686 eX1
7687 x8::AddSequence,synth,MAX_MULI_BYTECODE_LENGTH)){xU3=true;nM3}
7688 }
7689 if(xU3)nM3
7690 int
7691 yA1=0;yG<bool>done(GetParamCount(),false);yL2
7692 iE;iE
7693 tU
7694 lM2);for(;;){bool
7695 found
7696 i13
7697 c3
7698 done[a])y81
7699 if(synth.IsStackTop(lT1)){found=true;done[a]=true;lT1.nB
7700 iE
7701 eT
7702 lT1);if(++yA1>1){synth
7703 c4
7704 2);iE.y12
7705 eU3.yZ2
7706 iE);yA1=yA1-2+1;}
7707 }
7708 }
7709 if(!found)nM3
7710 c3
7711 done[a])y81
7712 lT1.nB
7713 iE
7714 eT
7715 lT1);if(++yA1>1){synth
7716 c4
7717 2);iE.y12
7718 eU3.yZ2
7719 iE);yA1=yA1-2+1;}
7720 }
7721 if(yA1==0){switch(lM2
7722 iY2
7723 cAdd:case
7724 cOr:case
7725 cAbsOr:yX2
7726 0);lC
7727 cMul:case
7728 cAnd:case
7729 cAbsAnd:yX2
7730 1);lC
7731 cMin:case
7732 cMax:yX2
7733 0);break;default:nM3++yA1;}
7734 assert(n_stacked==1);nM3
7735 case
7736 cPow:{iQ2
7737 p0
7738 tW2
7739 0);iQ2
7740 p1
7741 tW2
7742 1);if(!p1
7743 y21||!isLongInteger
7744 n03)||!x31
7745 p0,makeLongInteger
7746 n03),yV2
7747 eX1
7748 x8::MulSequence,synth,MAX_POWI_BYTECODE_LENGTH)){p0.nB
7749 p1
7750 t33
7751 c4
7752 2);c91
7753 cIf:case
7754 i03:{typename
7755 yW2::IfData
7756 yJ2;GetParam(0)t33.SynthIfStep1(yJ2,lM2);GetParam(1)t33.SynthIfStep2(yJ2);GetParam(2)t33.SynthIfStep3(yJ2
7757 nW2
7758 case
7759 cFCall:case
7760 cPCall:{for
7761 xK2
7762 0;a<cN3++a)lT1
7763 t33
7764 c4
7765 iL1)GetParamCount());lK1
7766 yM|GetFuncNo(),0,0
7767 nW2
7768 default:{for
7769 xK2
7770 0;a<cN3++a)lT1
7771 t33
7772 c4
7773 iL1)GetParamCount()nW2}
7774 synth.yZ2*this);if(MustPopTemps&&n_subexpressions_synthesized>0){size_t
7775 top
7776 t13
7777 GetStackTop(eU3.DoPopNMov(top-1-n_subexpressions_synthesized,top-1);}
7778 }
7779 }
7780 iO2{xG1
7781 x31
7782 lM1&tree,long
7783 count,const
7784 yV2
7785 SequenceOpCode
7786 x8&eQ,yW2&synth,size_t
7787 max_bytecode_grow_length){if
7788 cR3!=0){yW2
7789 backup=synth;tree.nB
7790 size_t
7791 bytecodesize_backup
7792 t13
7793 GetByteCodeSize();yV2
7794 x31
7795 count
7796 eR2
7797 size_t
7798 bytecode_grow_amount
7799 t13
7800 GetByteCodeSize()-bytecodesize_backup;if(bytecode_grow_amount>max_bytecode_grow_length){synth=backup
7801 l81
7802 false;}
7803 return
7804 true;}
7805 else{yV2
7806 x31
7807 count,eQ,synth)nS2}
7808 }
7809 #endif
7810 #include <cmath>
7811 #include <cassert>
7812 #ifdef FP_SUPPORT_OPTIMIZER
7813 xQ
7814 iO2{using
7815 iO2
7816 FPoptimizer_CodeTree;
7817 #define FactorStack yG
7818 const
7819 e92
7820 PowiMuliType{i02
7821 opcode_square;i02
7822 opcode_cumulate;i02
7823 opcode_invert;i02
7824 opcode_half;i02
7825 opcode_invhalf;}
7826 iseq_powi={cSqr,cMul,cInv,cSqrt,cRSqrt}
7827 ,iseq_muli={i21,cAdd,cNeg,i21,i21}
7828 ;yB1
7829 cF1
7830 const
7831 PowiMuliType&xV3,const
7832 yG<i02>&nA2,l92&stack){eS1
7833 cY3
7834 1);while(IP<limit){if(xW3
7835 xV3.opcode_square){if(!eY2
7836 cZ3
7837 2;e4
7838 opcode_invert){result=-result;e4
7839 opcode_half){if(result>eS1(0)&&isEvenInteger(cZ3
7840 yF3;e4
7841 opcode_invhalf){if(result>eS1(0)&&isEvenInteger(cZ3
7842 eS1(-0.5);++IP;y81}
7843 size_t
7844 nB2=IP;eS1
7845 lhs(1);if(xW3
7846 cFetch){lC1=yL3;if(index<y1||size_t(index-y1)>=stack
7847 yA3){IP=nB2;nM3
7848 lhs=stack[index-y1];goto
7849 y32;}
7850 if(xW3
7851 cDup){lhs=result;goto
7852 y32;y32:y63
7853 result);++IP;eS1
7854 subexponent=cF1
7855 xV3
7856 lQ1
7857 if(IP>=limit||nN[IP]!=xV3.opcode_cumulate){IP=nB2;nM3++IP;stack.pop_back();result+=lhs*subexponent;y81}
7858 nM3
7859 return
7860 result;}
7861 yB1
7862 ParsePowiSequence
7863 i01
7864 yG<i02>&nA2){l92
7865 stack;y63
7866 eS1(1))l81
7867 cF1
7868 iseq_powi
7869 lQ1}
7870 yB1
7871 ParseMuliSequence
7872 i01
7873 yG<i02>&nA2){l92
7874 stack;y63
7875 eS1(1))l81
7876 cF1
7877 iseq_muli
7878 lQ1}
7879 iP2
7880 CodeTreeParserData{e13
7881 iF2
7882 CodeTreeParserData(bool
7883 k_powi):stack(),clones(),keep_powi(k_powi){}
7884 void
7885 Eat(size_t
7886 eR3,OPCODE
7887 opcode
7888 xX3;xK
7889 tU
7890 opcode);yG
7891 nV1
7892 cB2=Pop(eR3);xK
7893 tI1
7894 cB2);if(!keep_powi)switch(opcode
7895 iY2
7896 cTanh:nG1
7897 sinh,cosh;sinh
7898 tU
7899 cSinh);sinh
7900 eT
7901 xK
7902 xY3
7903 sinh
7904 x02;cosh
7905 tU
7906 cCosh);cosh
7907 yA
7908 xK
7909 xY3
7910 cosh
7911 i72
7912 pow
7913 yB2
7914 yA
7915 cosh);pow
7916 yT
7917 eS1(-1)));pow
7918 x02;xK
7919 tU
7920 y13.nC1
7921 0,sinh);xK
7922 yA
7923 pow
7924 nW2
7925 case
7926 cTan:nG1
7927 sin,cos;sin
7928 tU
7929 cSin);sin
7930 eT
7931 xK
7932 xY3
7933 sin
7934 x02;cos
7935 tU
7936 cCos);cos
7937 yA
7938 xK
7939 xY3
7940 cos
7941 i72
7942 pow
7943 yB2
7944 yA
7945 cos);pow
7946 yT
7947 eS1(-1)));pow
7948 x02;xK
7949 tU
7950 y13.nC1
7951 0,sin);xK
7952 yA
7953 pow
7954 nW2
7955 case
7956 cPow:{lM1&p0=xK
7957 lD
7958 0);lM1&p1=xK
7959 lD
7960 1);if(p1
7961 nE==cAdd){yG
7962 nV1
7963 n83(p1.GetParamCount())c23
7964 0;a<p1.cN3++a)nG1
7965 pow
7966 yB2
7967 eT
7968 p0);pow
7969 eT
7970 p1
7971 lD
7972 a));pow
7973 x02;n83[a
7974 t23
7975 pow);}
7976 xK
7977 tU
7978 y13
7979 tI1
7980 n83);}
7981 nM3
7982 default:nM3
7983 xK.Rehash(!keep_powi);i71,false);
7984 #ifdef DEBUG_SUBSTITUTIONS
7985 lC2<<eR3<<", "
7986 <<FP_GetOpcodeName(opcode)<<"->"
7987 <<FP_GetOpcodeName(xK
7988 nE)<<": "
7989 tP3
7990 xK)tW
7991 xK);
7992 #endif
7993 y63
7994 xK
7995 iR2
7996 EatFunc(size_t
7997 eR3,OPCODE
7998 opcode,i02
7999 funcno
8000 xX3=CodeTreeFuncOp
8001 x8(opcode,funcno);yG
8002 nV1
8003 cB2=Pop(eR3);xK
8004 tI1
8005 cB2);xK.y12);
8006 #ifdef DEBUG_SUBSTITUTIONS
8007 lC2<<eR3<<", "
8008 tP3
8009 xK)tW
8010 xK);
8011 #endif
8012 i71);y63
8013 xK
8014 iR2
8015 AddConst(yF1
8016 xX3=CodeTreeImmed(value);i71);Push(xK
8017 iR2
8018 AddVar
8019 iL1
8020 varno
8021 xX3=CodeTreeVar
8022 x8(varno);i71);Push(xK
8023 iR2
8024 SwapLastTwoInStack(){y73
8025 1
8026 t23
8027 y73
8028 2]iR2
8029 Dup(){Fetch
8030 lB2
8031 1
8032 iR2
8033 Fetch(size_t
8034 which){Push(stack[which]);}
8035 nT1
8036 T>void
8037 Push(T
8038 tree){
8039 #ifdef DEBUG_SUBSTITUTIONS
8040 std::cout<<tP3
8041 tree)tW
8042 tree);
8043 #endif
8044 y63
8045 tree
8046 iR2
8047 PopNMov(size_t
8048 target,size_t
8049 source){stack[target]=stack[source];stack
8050 nE3
8051 target+1);}
8052 yK2
8053 y42{clones.clear()yJ
8054 cY3
8055 stack.back());stack.resize
8056 lB2
8057 1)l81
8058 result;}
8059 yG
8060 nV1
8061 Pop(size_t
8062 n_pop){yG
8063 nV1
8064 cY3
8065 n_pop)xS3
8066 n=0;n<n_pop;++n)result[n
8067 t23
8068 y73
8069 n_pop+n]);
8070 #ifdef DEBUG_SUBSTITUTIONS
8071 for(xL3=n_pop;n-->0;){lC2;xE3(result[n])tW
8072 result[n]);}
8073 #endif
8074 stack.resize
8075 lB2
8076 n_pop)l81
8077 result;}
8078 size_t
8079 GetStackTop(n61
8080 stack
8081 yA3;}
8082 private:void
8083 FindClone(yK2&,bool=true){return;}
8084 private:yG
8085 nV1
8086 stack;std::multimap<fphash_t,yK2>clones;bool
8087 keep_powi;private:CodeTreeParserData
8088 i01
8089 CodeTreeParserData&);CodeTreeParserData&e31=i01
8090 CodeTreeParserData&);}
8091 ;yT1
8092 IfInfo
8093 nG1
8094 cU2
8095 yJ
8096 thenbranch;size_t
8097 endif_location;IfInfo():cU2(),thenbranch(),endif_location(){}
8098 }
8099 ;}
8100 iO2
8101 FPoptimizer_CodeTree{lA
8102 GenerateFrom
8103 i01
8104 yG<i02>&nN,const
8105 yG
8106 x8&Immed,const
8107 typename
8108 FunctionParserBase
8109 x8::Data&cJ3,bool
8110 keep_powi){yG
8111 nV1
8112 nK2;nK2.nH3
8113 cJ3.mVariablesAmount)xS3
8114 n=0;n<cJ3.mVariablesAmount;++n){nK2
8115 yL
8116 CodeTreeVar
8117 x8(n+iE2));}
8118 GenerateFrom(nN,Immed,cJ3,nK2,keep_powi);}
8119 lA
8120 GenerateFrom
8121 i01
8122 yG<i02>&nN,const
8123 yG
8124 x8&Immed,const
8125 typename
8126 FunctionParserBase
8127 x8::Data&cJ3,const
8128 i22
8129 nK2,bool
8130 keep_powi){
8131 #ifdef DEBUG_SUBSTITUTIONS
8132 std::cout<<"ENTERS GenerateFrom()\n"
8133 ;
8134 #endif
8135 CodeTreeParserData
8136 x8
8137 sim(keep_powi);yG<IfInfo
8138 x8>eN;for(size_t
8139 IP=0,DP=0;;++IP){tO2:while(!eN
8140 cQ3&&(eN.eD==IP||(IP<nN
8141 yA3&&xW3
8142 cJump&&eN.e11.iA1)){yL2
8143 elsebranch=sim.y42
8144 yG3
8145 eN.back().cU2)yG3
8146 eN.e11)yG3
8147 elsebranch);iJ
8148 3,cIf);eN.pop_back();}
8149 if(IP>=nN
8150 yA3)break;i02
8151 opcode=nN[IP];if((opcode==cSqr||opcode==cDup||(opcode==cInv&&!IsIntType
8152 x8::result)||opcode==cNeg||opcode==cSqrt||opcode==cRSqrt||opcode==cFetch)){size_t
8153 was_ip=IP;eS1
8154 cE2=ParsePowiSequence
8155 x8(nN,IP,eN
8156 cQ3?nN
8157 yA3:eN.eD,sim.x5
8158 1);if(cE2!=1.0){x9
8159 cE2)yJ3;goto
8160 tO2;}
8161 if(opcode==cDup||opcode==cFetch||opcode==cNeg){eS1
8162 xD2=ParseMuliSequence
8163 x8(nN,IP,eN
8164 cQ3?nN
8165 yA3:eN.eD,sim.x5
8166 1);if(xD2!=1.0){x9
8167 xD2)yE
8168 cMul);goto
8169 tO2;}
8170 }
8171 IP=was_ip;}
8172 if(lD2>=iE2){sim.Push(nK2[opcode-iE2]);}
8173 else{switch(lD2
8174 iY2
8175 cIf:case
8176 i03:{eN
8177 nE3
8178 eN
8179 yA3+1);yL2
8180 res(sim.y42);eN.back().cU2.swap(res);eN.eD=nN
8181 yA3;IP+=2;y81}
8182 case
8183 cJump:{yL2
8184 res(sim.y42);eN.e11.swap(res);eN.eD=nN[IP+1]+1;IP+=2;y81}
8185 case
8186 cImmed:x9
8187 Immed[DP++]);lC
8188 cDup:sim.Dup();lC
8189 cNop:lC
8190 cFCall:{i02
8191 funcno=yL3;assert(funcno<fpdata.mFuncPtrs.size());i02
8192 cB2=cJ3.mFuncPtrs
8193 yD3
8194 mParams;sim.EatFunc(cB2,lD2,funcno
8195 nW2
8196 case
8197 cPCall:{i02
8198 funcno=yL3;assert(funcno<fpdata.tQ3.size());const
8199 FunctionParserBase
8200 x8&p=*cJ3.tQ3
8201 yD3
8202 mParserPtr;i02
8203 cB2=cJ3.tQ3
8204 yD3
8205 mParams;yG<yL2>paramlist=sim.Pop(cB2);yL2
8206 tP2;tP2.GenerateFrom(p.mData->mByteCode,p.mData->mImmed,*p.mData,paramlist)yG3
8207 tP2
8208 nW2
8209 case
8210 cInv:x9
8211 1
8212 nY2
8213 cDiv);lC
8214 cNeg:yE3
8215 cNeg);break;x9
8216 0
8217 nY2
8218 cSub);lC
8219 cSqr:x9
8220 2
8221 e21
8222 cSqrt:x9
8223 yF3
8224 e21
8225 cRSqrt:x9
8226 eS1(-0.5)e21
8227 cCbrt:x9
8228 eS1(1)/eS1(3)e21
8229 cDeg:x9
8230 fp_const_rad_to_deg
8231 x8
8232 cI1
8233 cRad:x9
8234 fp_const_deg_to_rad
8235 x8
8236 cI1
8237 cExp:iF)goto
8238 yI3;x9
8239 fp_const_e
8240 x8()nY2
8241 cPow);lC
8242 cExp2:iF)goto
8243 yI3;x9
8244 2.0
8245 nY2
8246 cPow);lC
8247 cCot:yE3
8248 cTan);iF)nY
8249 cCsc:yE3
8250 cSin);iF)nY
8251 cSec:yE3
8252 cCos);iF)nY
8253 cInt:
8254 #ifndef __x86_64
8255 iF){yE3
8256 cInt
8257 nW2
8258 #endif
8259 x9
8260 yF3)lL3
8261 yE3
8262 cFloor);lC
8263 cLog10:yE3
8264 yH3
8265 fp_const_log10inv
8266 x8
8267 cI1
8268 cLog2:yE3
8269 yH3
8270 fp_const_log2inv
8271 x8
8272 cI1
8273 cLog2by:cK3
8274 yE3
8275 yH3
8276 fp_const_log2inv
8277 x8());iJ
8278 3,cMul);lC
8279 cHypot:x9
8280 2)yJ3;cK3
8281 x9
8282 2)yJ3
8283 lL3
8284 x9
8285 yF3
8286 e21
8287 cSinCos:sim.Dup();yE3
8288 cSin);cK3
8289 yE3
8290 cCos);lC
8291 cRSub:cK3
8292 case
8293 cSub:iF){iJ
8294 2,cSub
8295 nW2
8296 x9-1)yE
8297 cMul)lL3
8298 lC
8299 cRDiv:cK3
8300 case
8301 cDiv:iF||IsIntType
8302 x8::result){iJ
8303 2,cDiv
8304 nW2
8305 x9-1)yJ3
8306 yE
8307 cMul);lC
8308 cAdd:case
8309 cMul:case
8310 cMod:case
8311 cPow:case
8312 cEqual:case
8313 cLess:case
8314 cGreater:case
8315 t71:case
8316 cLessOrEq:case
8317 cGreaterOrEq:case
8318 cAnd:case
8319 cOr:case
8320 cAbsAnd:case
8321 cAbsOr:iJ
8322 2,xS1
8323 lC
8324 cNot:case
8325 cNotNot:case
8326 yR3:case
8327 cAbsNotNot:yE3
8328 xS1
8329 lC
8330 cFetch:sim.Fetch(yL3);lC
8331 cPopNMov:{i02
8332 stackOffs_target=yL3;i02
8333 stackOffs_source=yL3;sim.PopNMov(stackOffs_target,stackOffs_source
8334 nW2
8335 #ifndef FP_DISABLE_EVAL
8336 case
8337 cEval:{size_t
8338 paramcount=cJ3.mVariablesAmount;iJ
8339 paramcount,xS1
8340 nM3
8341 #endif
8342 default:yI3:;i02
8343 funcno=opcode-cAbs;assert(funcno<FUNC_AMOUNT);const
8344 FuncDefinition&func=Functions[funcno];iJ
8345 func.cB2,xS1
8346 nM3}
8347 }
8348 Become(sim.y42);
8349 #ifdef DEBUG_SUBSTITUTIONS
8350 std::cout<<"Produced tree:\n"
8351 ;iO
8352 #endif
8353 }
8354 }
8355 #endif
8356 #include <algorithm>
8357 #ifdef FP_SUPPORT_OPTIMIZER
8358 #include <assert.h>
8359 #define FP_MUL_COMBINE_EXPONENTS
8360 iO2{xQ
8361 using
8362 iO2
8363 FPoptimizer_CodeTree;yV1
8364 static
8365 void
8366 AdoptChildrenWithSameOpcode(eR{
8367 #ifdef DEBUG_SUBSTITUTIONS
8368 bool
8369 lR2
8370 i13
8371 #endif
8372 for
8373 xU
8374 if
8375 nW1
8376 a)nE==tree
8377 nE){
8378 #ifdef DEBUG_SUBSTITUTIONS
8379 if(!lR2){std::cout<<"Before assimilation: "
8380 eS
8381 lR2=true;}
8382 #endif
8383 tree.AddParamsMove
8384 nW1
8385 a).GetUniqueRef().iE1),a);}
8386 #ifdef DEBUG_SUBSTITUTIONS
8387 if(lR2){std::cout<<"After assimilation:   "
8388 eS}
8389 #endif
8390 }
8391 }
8392 iO2
8393 FPoptimizer_CodeTree{xB1
8394 ConstantFolding(eR{tree.Sort();
8395 #ifdef DEBUG_SUBSTITUTIONS
8396 void*yM3=0
8397 lN1"["
8398 <<(&yM3)<<"]Runs ConstantFolding for: "
8399 eS
8400 DumpHashes(tree);
8401 #endif
8402 if(false){redo:;tree.Sort();
8403 #ifdef DEBUG_SUBSTITUTIONS
8404 std::cout<<"["
8405 <<(&yM3)<<"]Re-runs ConstantFolding: "
8406 eS
8407 DumpHashes(tree);
8408 #endif
8409 }
8410 if
8411 xU2!=cImmed){range
8412 x8
8413 p=iM
8414 tree);if(p
8415 y41
8416 p
8417 i0&&p.min==p.max)lL
8418 p.min)n5}
8419 if(false){ReplaceTreeWithOne
8420 xP3
8421 ReplaceWithImmed(eS1(1));goto
8422 do_return;ReplaceTreeWithZero
8423 xP3
8424 ReplaceWithImmed(eS1(0));goto
8425 do_return;ReplaceTreeWithParam0:
8426 #ifdef DEBUG_SUBSTITUTIONS
8427 std::cout<<"Before replace: "
8428 lN1
8429 std::hex<<'['<<tree
8430 eE2
8431 hash1<<','<<tree
8432 eE2
8433 hash2<<']'<<std::dec
8434 eS
8435 #endif
8436 tree.xO2
8437 0));
8438 #ifdef DEBUG_SUBSTITUTIONS
8439 std::cout<<"After replace: "
8440 lN1
8441 std::hex<<'['<<tree
8442 eE2
8443 hash1<<','<<tree
8444 eE2
8445 hash2<<']'<<std::dec
8446 eS
8447 #endif
8448 e5
8449 yN3
8450 xU2
8451 iY2
8452 cImmed:lC
8453 iE2:lC
8454 cAnd:case
8455 cAbsAnd
8456 cP
8457 bool
8458 cE
8459 i13
8460 for
8461 xU{if(!y93
8462 a)))cE=true;yQ3
8463 a),cV2
8464 cAbsAnd)iY2
8465 yO3:yP3
8466 IsAlways:nF1);lC
8467 lX1
8468 yN3(iT
8469 iY2
8470 0
8471 tY
8472 1:tH
8473 cV2
8474 cAnd?cNotNot:cAbsNotNot);e5
8475 default:if
8476 xU2==cAnd||!cE)if(ConstantFolding_AndLogic
8477 y83
8478 c91
8479 cOr:case
8480 cAbsOr
8481 cP
8482 bool
8483 cE
8484 i13
8485 for
8486 xU{if(!y93
8487 a)))cE=true;yQ3
8488 a),cV2
8489 cAbsOr)iY2
8490 IsAlways
8491 tY
8492 yO3:nF1);lC
8493 lX1
8494 yN3(iT
8495 iY2
8496 0:yP3
8497 1:tH
8498 cV2
8499 cOr?cNotNot:cAbsNotNot);e5
8500 default:if
8501 xU2==cOr||!cE)if(ConstantFolding_OrLogic
8502 y83
8503 c91
8504 cNot:case
8505 yR3:{i02
8506 n21
8507 0;switch
8508 nW1
8509 0)nE
8510 iY2
8511 cEqual:n21
8512 t71;lC
8513 t71:n21
8514 cEqual;lC
8515 cLess:n21
8516 cGreaterOrEq;lC
8517 cGreater:n21
8518 cLessOrEq;lC
8519 cLessOrEq:n21
8520 cGreater;lC
8521 cGreaterOrEq:n21
8522 cLess;lC
8523 cNotNot:n21
8524 cNot;lC
8525 cNot:n21
8526 cNotNot;lC
8527 yR3:n21
8528 cAbsNotNot;lC
8529 cAbsNotNot:n21
8530 yR3;break;default:nM3
8531 if(opposite){tH
8532 OPCODE(opposite)tT.SetParamsMove
8533 nW1
8534 0).GetUniqueRef().iE1));e5
8535 yN3(tX
8536 0),tree
8537 cG1)tF1
8538 yP3
8539 yO3
8540 tY
8541 lX1
8542 if
8543 xU2==cNot&&GetPositivityInfo
8544 nW1
8545 0))==IsAlways)tH
8546 yR3);l23
8547 nE==cIf||e72
8548 nE==i03)nG1
8549 iH2
8550 cL2
8551 0);lM1&ifp1=iH2
8552 lD
8553 1);lM1&ifp2=iH2
8554 lD
8555 2);if(ifp1
8556 nE==cNot||ifp1
8557 cG1{tree.x1
8558 ifp1
8559 nE==cNot?cNotNot:cAbsNotNot);tQ2
8560 lD
8561 0))yC1)yS3
8562 xQ2
8563 yT3)tV
8564 if(ifp2
8565 nE==cNot||ifp2
8566 cG1{tree.x1
8567 tree
8568 nE);tQ2)yC1)yS3
8569 tU
8570 ifp2
8571 nE==cNot?cNotNot:cAbsNotNot);yT3
8572 lD
8573 0))tV
8574 c91
8575 cNotNot:case
8576 cAbsNotNot:{if(y93
8577 0)))lN3
8578 yQ3
8579 0),cV2
8580 cAbsNotNot)iY2
8581 yO3:yP3
8582 IsAlways
8583 tY
8584 lX1
8585 if
8586 xU2==cNotNot&&GetPositivityInfo
8587 nW1
8588 0))==IsAlways)tH
8589 cAbsNotNot);l23
8590 nE==cIf||e72
8591 nE==i03)nG1
8592 iH2
8593 cL2
8594 0);lM1&ifp1=iH2
8595 lD
8596 1);lM1&ifp2=iH2
8597 lD
8598 2);if(ifp1
8599 nE==cNot||ifp1
8600 cG1{tree.SetParam(0,iH2
8601 lD
8602 0)tT
8603 eT
8604 ifp1)yS3
8605 xQ2
8606 yT3)tV
8607 if(ifp2
8608 nE==cNot||ifp2
8609 cG1{tree.x1
8610 tree
8611 nE);tQ2)yC1
8612 tT
8613 eT
8614 ifp2);tH
8615 iH2
8616 nE);e5}
8617 c91
8618 cIf:case
8619 i03:{if(ConstantFolding_IfOperations
8620 y83
8621 nM3
8622 case
8623 cMul:{NowWeAreMulGroup:;AdoptChildrenWithSameOpcode(tree);eS1
8624 nN1=eS1(1);size_t
8625 i81=0;bool
8626 nO1=false
8627 eV3
8628 if(!xI2
8629 y21)y81
8630 eS1
8631 immed=xI2.xJ1;if(immed==eS1(0))tZ
8632 nN1*=immed;++i81;}
8633 if(i81>1||(i81==1&&fp_equal(nN1,nY3)nO1=true;if(nO1){
8634 #ifdef DEBUG_SUBSTITUTIONS
8635 std::cout<<"cMul: Will add new "
8636 tR3
8637 nN1<<"\n"
8638 ;
8639 #endif
8640 for
8641 xU
8642 if
8643 nW1
8644 a)y21){
8645 #ifdef DEBUG_SUBSTITUTIONS
8646 std::cout<<" - For that, deleting "
8647 tR3
8648 xI2.xJ1
8649 lN1"\n"
8650 ;
8651 #endif
8652 lM3!fp_equal(nN1,nY3
8653 tree
8654 eT
8655 cU1
8656 nN1));yN3(iT
8657 iY2
8658 0
8659 tY
8660 1:lN3
8661 default:if(ConstantFolding_MulGrouping
8662 y83
8663 if(ConstantFolding_MulLogicItems
8664 y83
8665 c91
8666 cAdd
8667 cP
8668 eS1
8669 lE2=0.0;size_t
8670 i81=0;bool
8671 nO1=false
8672 eV3
8673 if(!xI2
8674 y21)y81
8675 eS1
8676 immed=xI2.xJ1;lE2+=immed;++i81;}
8677 if(i81>1||(i81==1&&lE2==0.0))nO1=true;if(nO1){
8678 #ifdef DEBUG_SUBSTITUTIONS
8679 std::cout<<"cAdd: Will add new "
8680 tR3
8681 lE2<<"\n"
8682 lN1"In: "
8683 eS
8684 #endif
8685 for
8686 xU
8687 if
8688 nW1
8689 a)y21){
8690 #ifdef DEBUG_SUBSTITUTIONS
8691 std::cout<<" - For that, deleting "
8692 tR3
8693 xI2.xJ1
8694 lN1"\n"
8695 ;
8696 #endif
8697 lM3!(lE2==0.0))tree
8698 eT
8699 cU1
8700 lE2));yN3(iT
8701 iY2
8702 0:yP3
8703 1:lN3
8704 default:if(ConstantFolding_AddGrouping
8705 y83
8706 if(ConstantFolding_AddLogicItems
8707 y83
8708 c91
8709 cMin
8710 cP
8711 size_t
8712 y52=0;range
8713 x8
8714 e6
8715 eV3
8716 while(a+1<iT&&xI2
8717 iA
8718 tree
8719 lD
8720 a+1)))nF1+1);range<nI
8721 has_max&&(!e6
8722 i0||(p.max)<e6.max)){e6.max=p.max;e6
8723 i0=true;y52=a;}
8724 }
8725 if(e6
8726 i0)for
8727 xU{range<nI
8728 iV2&&a!=y52&&p.min>=e6.max)lM3
8729 iT==1){lN3
8730 c91
8731 cMax
8732 cP
8733 size_t
8734 y52=0;range
8735 x8
8736 t1
8737 eV3
8738 while(a+1<iT&&xI2
8739 iA
8740 tree
8741 lD
8742 a+1)))nF1+1);range<nI
8743 iV2&&(!t1.iV2||p.min>t1.min)){t1.min=p.min;t1.iV2=true;y52=a;}
8744 }
8745 if(t1.iV2){for
8746 xU{range<nI
8747 has_max&&a!=y52&&(p.max)<t1.min){nF1);}
8748 }
8749 }
8750 if(iT==1){lN3
8751 c91
8752 cEqual:case
8753 t71:case
8754 cLess:case
8755 cGreater:case
8756 cLessOrEq:case
8757 cGreaterOrEq:if(ConstantFolding_Comparison
8758 y83
8759 lC
8760 cAbs:{range
8761 x8
8762 p0=y6
8763 0));if(p0
8764 eN1
8765 lN3
8766 if(p0
8767 i0
8768 yU3
8769 tN{tH
8770 cMul
8771 tT
8772 yT
8773 nY3;goto
8774 NowWeAreMulGroup;}
8775 l23
8776 nE==cMul){lM1&p
8777 cL2
8778 0);yG
8779 nV1
8780 lO3;yG
8781 nV1
8782 c02
8783 c23
8784 0;a<p.cN3++a){p0=iM
8785 p
8786 lD
8787 a));if(p0
8788 eN1{lO3
8789 yL
8790 p
8791 lD
8792 a));}
8793 if(p0
8794 i0
8795 yU3
8796 tN{c02
8797 yL
8798 p
8799 lD
8800 a));}
8801 }
8802 #ifdef DEBUG_SUBSTITUTIONS
8803 std::cout<<"Abs: mul group has "
8804 <<lO3
8805 yA3<<" pos, "
8806 <<c02
8807 yA3<<"neg\n"
8808 ;
8809 #endif
8810 if(!lO3
8811 cQ3||!c02
8812 cQ3){
8813 #ifdef DEBUG_SUBSTITUTIONS
8814 std::cout<<"AbsReplace-Before: "
8815 ;xE3(tree)lN1"\n"
8816 <<std::flush;DumpHashes
8817 tJ1;
8818 #endif
8819 yK2
8820 cL3;cL3
8821 tU
8822 cMul)c23
8823 0;a<p.cN3++a){p0=iM
8824 p
8825 lD
8826 a));if((p0
8827 eN1||(p0
8828 i0
8829 yU3
8830 tN){}
8831 else
8832 cL3
8833 eT
8834 p
8835 lD
8836 a));}
8837 cL3
8838 i72
8839 lP3;lP3
8840 tU
8841 cAbs);lP3
8842 yA
8843 cL3);lP3
8844 i72
8845 xW1
8846 cMul);n83
8847 yA
8848 lP3);xX1
8849 AddParamsMove(lO3);if(!c02
8850 cQ3){if(c02
8851 yA3%2)n83
8852 yT
8853 eS1(-1)));xX1
8854 AddParamsMove(c02);}
8855 tree.Become(n83);
8856 #ifdef DEBUG_SUBSTITUTIONS
8857 std::cout<<"AbsReplace-After: "
8858 ;xE3
8859 tJ1
8860 lN1"\n"
8861 <<std::flush;DumpHashes
8862 tJ1;
8863 #endif
8864 goto
8865 NowWeAreMulGroup;}
8866 }
8867 nM3
8868 #define HANDLE_UNARY_CONST_FUNC(funcname) lX)lL funcname(n6))n5
8869 case
8870 cLog:tH3(fp_log);l23
8871 nE==cPow)nG1
8872 pow
8873 cL2
8874 0);if(GetPositivityInfo(pow
8875 lD
8876 0))==IsAlways){pow
8877 lF2
8878 tI
8879 tree.lW
8880 if(GetEvennessInfo(pow
8881 x03==IsAlways){pow
8882 lF2
8883 yJ
8884 abs;abs
8885 tU
8886 cAbs);abs
8887 yA
8888 pow
8889 xY3
8890 abs
8891 x02
8892 tI
8893 pow.nC1
8894 0,abs
8895 tT.lW}
8896 else
8897 l23
8898 nE==cAbs)nG1
8899 pow
8900 cL2
8901 0)lD
8902 0);if(pow
8903 nE==cPow){pow
8904 lF2
8905 yJ
8906 abs;abs
8907 tU
8908 cAbs);abs
8909 yA
8910 pow
8911 xY3
8912 abs
8913 x02
8914 tI
8915 pow.nC1
8916 0,abs
8917 tT.lW}
8918 lC
8919 cAcosh:tH3(fp_acosh);lC
8920 cAsinh:tH3(fp_asinh);lC
8921 cAtanh:tH3(fp_atanh);lC
8922 cAcos:tH3(fp_acos);lC
8923 cAsin:tH3(fp_asin);lC
8924 cAtan:tH3(fp_atan);lC
8925 cCosh:tH3(fp_cosh);lC
8926 cSinh:tH3(fp_sinh);lC
8927 cTanh:tH3(fp_tanh);lC
8928 cSin:tH3(fp_sin);lC
8929 cCos:tH3(fp_cos);lC
8930 cTan:tH3(fp_tan);lC
8931 cCeil:if(n8
8932 tH3(fp_ceil);lC
8933 cTrunc:if(n8
8934 tH3(fp_trunc);lC
8935 cFloor:if(n8
8936 tH3(fp_floor);lC
8937 cInt:if(n8
8938 tH3(fp_int);lC
8939 cCbrt:tH3(fp_cbrt);lC
8940 cSqrt:tH3(fp_sqrt);lC
8941 cExp:tH3(fp_exp);lC
8942 cLog2:tH3(fp_log2);lC
8943 cLog10:tH3(fp_log10);lC
8944 cLog2by:y2)lL
8945 fp_log2(n6)*y4
8946 nN3
8947 cMod:y2)lL
8948 fp_mod(n6,y4)nN3
8949 cAtan2:{range
8950 x8
8951 p0
8952 y5
8953 p1=y6
8954 1));lX&&fp_equal(n6,eS1(0))){if(p1
8955 i0&&(p1.max)<0)lL
8956 fp_const_pi
8957 x8())n5
8958 if(p1
8959 y41
8960 p1.min>=0.0)lL
8961 eS1(0))n5}
8962 if(nE1
8963 fp_equal(y4,eS1(0))){if(p0
8964 i0&&(p0.max)<0)lL-fp_const_pihalf
8965 x8())n5
8966 if(p0
8967 y41
8968 p0.min>0)lL
8969 fp_const_pihalf
8970 x8())n5}
8971 y2)lL
8972 fp_atan2(n6,y4))n5
8973 if((p1
8974 y41
8975 p1.min>0.0)||(p1
8976 i0&&(p1.max)<fp_const_negativezero
8977 x8()))nG1
8978 y62;y62
8979 tU
8980 cPow);y62
8981 yA
8982 tree
8983 x03;y62
8984 yT
8985 eS1(-1)));y62
8986 i72
8987 y72;y72
8988 e53
8989 y72
8990 yA
8991 e72);y72
8992 yA
8993 y62);y72
8994 y3
8995 cAtan
8996 tT.nC1
8997 0,y72
8998 tW1
8999 1);c91
9000 cPow:{if(ConstantFolding_PowOperations
9001 y83
9002 nM3
9003 case
9004 cDiv:y2&&y4!=0.0)lL
9005 n6/y4
9006 nN3
9007 cInv:lX&&n6!=0.0)lL
9008 eS1(1)/n6
9009 nN3
9010 cSub:y2)lL
9011 n6-y4
9012 nN3
9013 cNeg:lX)lL-n6
9014 nN3
9015 cRad:lX)lL
9016 RadiansToDegrees
9017 t63
9018 cDeg:lX)lL
9019 DegreesToRadians
9020 t63
9021 cSqr:lX)lL
9022 n6*n6
9023 nN3
9024 cExp2:tH3(fp_exp2);lC
9025 cRSqrt:lX)lL
9026 eS1(1)/fp_sqrt
9027 t63
9028 cCot:lX)nQ3=fp_tan(n6)xE
9029 cSec:lX)nQ3=fp_cos(n6)xE
9030 cCsc:lX)nQ3=fp_sin(n6)xE
9031 cHypot:y2)lL
9032 fp_hypot(n6,y4)nN3
9033 cRDiv:case
9034 cRSub:case
9035 cDup:case
9036 cFetch:case
9037 cPopNMov:case
9038 cSinCos:case
9039 cNop:case
9040 cJump:lC
9041 cPCall:case
9042 cFCall:case
9043 cEval:nM3
9044 do_return:;
9045 #ifdef DEBUG_SUBSTITUTIONS
9046 std::cout<<"["
9047 <<(&yM3)<<"]Done ConstantFolding, result: "
9048 eS
9049 DumpHashes(tree);
9050 #endif
9051 }
9052 }
9053 #endif
9054 #ifdef FP_SUPPORT_OPTIMIZER
9055 xQ
9056 using
9057 iO2
9058 FPoptimizer_CodeTree;iO2{n73<i02
9059 cY2
9060 e92
9061 Comp{}
9062 ;n73<>e92
9063 Comp<cLess>{n73<lF<yU
9064 cLessOrEq>{n73<lF<=yU
9065 cGreater>{n73<lF>yU
9066 cGreaterOrEq>{n73<lF>=yU
9067 cEqual>{n73<lF==yU
9068 t71>{n73<lF!=b;}
9069 }
9070 ;}
9071 iO2
9072 FPoptimizer_CodeTree{c12
9073 set_abs(){if(!iV2&&!iI2{iV2=yV3}
9074 tP1!iV2&&max
9075 t83){iV2=true;min=-max;iJ2
9076 false;}
9077 tP1!iV2){iV2=yV3
9078 iJ2
9079 false;}
9080 tP1
9081 min
9082 cH1
9083 nZ2;tP1!iI2{iV2=yV3}
9084 tP1
9085 max
9086 t83)nQ3(-max);max=-min;min=tmp;}
9087 tP1-min>=max){max=-min;n31}
9088 else{n31}
9089 }
9090 c12
9091 set_neg(){std::swap(iV2,iI2;std::swap(min,max);min=-min;max=-max;}
9092 yV
9093 set_min_if(c31
9094 if(iV2&&Comp<cY2()(min,v))min=func(min
9095 t73
9096 iV2=yW3
9097 iV2;min=yW3
9098 min;}
9099 }
9100 yV
9101 set_max_if(c31
9102 if(has_max&&Comp<cY2()(max,v))max=func(max
9103 t73
9104 iJ2
9105 model
9106 i0;max=yW3
9107 max;}
9108 }
9109 yV
9110 set_min_max_if(c31
9111 set_min_if<cY2(v,func,model);set_max_if<cY2(v,func,model);}
9112 c12
9113 set_min(n7
9114 if(iV2)min=func(min
9115 t73
9116 iV2=yW3
9117 iV2;min=yW3
9118 min;}
9119 }
9120 c12
9121 set_max(n7
9122 if(iI2
9123 max=func(max
9124 t73
9125 iJ2
9126 model
9127 i0;max=yW3
9128 max;}
9129 }
9130 c12
9131 y82
9132 n7
9133 set_min(func,model);set_max(func,model);}
9134 yV1
9135 range
9136 x8
9137 iM
9138 const
9139 eR
9140 #ifdef DEBUG_SUBSTITUTIONS_extra_verbose
9141 {range
9142 x8
9143 tmp=CalculateResultBoundaries_do(tree)lN1"Estimated boundaries: "
9144 ;if(tmp.iV2)std::cout<<tmp.min;else
9145 std::cout<<"-inf"
9146 lN1" .. "
9147 ;if(tmp
9148 i0)std::cout<<tmp.max;else
9149 std::cout<<"+inf"
9150 lN1": "
9151 ;xE3(tree)lN1
9152 std::endl
9153 l81
9154 tmp;}
9155 yV1
9156 range
9157 x8
9158 yK2::CalculateResultBoundaries_do
9159 i01
9160 eR
9161 #endif
9162 {x81
9163 eO1(-fp_const_pihalf
9164 x8(),fp_const_pihalf
9165 x8());x81
9166 pi_limits(-fp_const_pi
9167 x8(),fp_const_pi
9168 x8());x81
9169 abs_pi_limits(eS1(0),fp_const_pi
9170 x8());using
9171 iO2
9172 std;switch
9173 xU2
9174 iY2
9175 cImmed:nL
9176 yZ3,yZ3);case
9177 cAnd:case
9178 cAbsAnd:case
9179 cOr:case
9180 cAbsOr:case
9181 cNot:case
9182 yR3:case
9183 cNotNot:case
9184 cAbsNotNot:case
9185 cEqual:case
9186 t71:case
9187 cLess:case
9188 cLessOrEq:case
9189 cGreater:case
9190 cGreaterOrEq:e83
9191 0),eS1(1))cM3
9192 cAbs:lB
9193 m.set_abs(cY
9194 cLog:lB
9195 m.y7
9196 fp_log
9197 cY
9198 cLog2:lB
9199 m.y7
9200 fp_log2
9201 cY
9202 cLog10:lB
9203 m.y7
9204 fp_log10
9205 cY
9206 cAcosh:lB
9207 m
9208 nL2
9209 set_min_max_if<cGreaterOrEq
9210 lQ3
9211 fp_acosh
9212 cY
9213 cAsinh:lB
9214 m.y82
9215 fp_asinh
9216 cY
9217 cAtanh:lB
9218 m
9219 nL2
9220 set_min_if<cGreater>(eS1(-1),fp_atanh);m
9221 nL2
9222 set_max_if<cLess
9223 lQ3
9224 fp_atanh
9225 cY
9226 cAcos:lB
9227 nL(m
9228 i0&&(m.max)<eS1(1))?fp_acos(m.max):eS1(0),(m
9229 y41(m.min)>=eS1(-1))?fp_acos(m.min):fp_const_pi
9230 x8())cM3
9231 cAsin:lB
9232 m
9233 nL2
9234 set_min_if<cGreater>(eS1(-1),fp_asin,eO1);m
9235 nL2
9236 set_max_if<cLess
9237 lQ3
9238 fp_asin,eO1
9239 cY
9240 cAtan:lB
9241 m.y82
9242 fp_atan,eO1
9243 cY
9244 cAtan2:{range
9245 x8
9246 p0
9247 y5
9248 p1=y6
9249 1));lX&&fp_equal(n6,eS1(0))){return
9250 abs_pi_limits;}
9251 if(nE1
9252 fp_equal(y4,eS1(0))){return
9253 eO1;}
9254 return
9255 pi_limits
9256 cM3
9257 cSin:lB
9258 bool
9259 x41=!m.iV2||!m
9260 i0||(m.max-m.min)>=(y8
9261 x41)e0
9262 eS1
9263 min=cZ2
9264 min,y8
9265 min
9266 t83)min
9267 c5
9268 eS1
9269 max=cZ2
9270 max,y8
9271 max
9272 t83)max
9273 c5
9274 if(max<min)max
9275 c5
9276 bool
9277 xT1=(min<=fp_const_pihalf
9278 x8()&&max>=fp_const_pihalf
9279 x8());bool
9280 nP1=(min<=cK&&max>=cK);if(xT1&&nP1)e0
9281 if(nP1)nL
9282 eS1(-1),lS2
9283 if(xT1)nL
9284 y92
9285 eS1(1));nL
9286 y92
9287 lS2}
9288 case
9289 cCos:lB
9290 if(m.iV2)m.min+=fp_const_pihalf
9291 x8();if(m
9292 i0)m.max+=fp_const_pihalf
9293 x8();bool
9294 x41=!m.iV2||!m
9295 i0||(m.max-m.min)>=(y8
9296 x41)e0
9297 eS1
9298 min=cZ2
9299 min,y8
9300 min
9301 t83)min
9302 c5
9303 eS1
9304 max=cZ2
9305 max,y8
9306 max
9307 t83)max
9308 c5
9309 if(max<min)max
9310 c5
9311 bool
9312 xT1=(min<=fp_const_pihalf
9313 x8()&&max>=fp_const_pihalf
9314 x8());bool
9315 nP1=(min<=cK&&max>=cK);if(xT1&&nP1)e0
9316 if(nP1)nL
9317 eS1(-1),lS2
9318 if(xT1)nL
9319 y92
9320 eS1(1));nL
9321 y92
9322 lS2}
9323 case
9324 cTan:{nL)cM3
9325 cCeil:lB
9326 m.c41
9327 cFloor:lB
9328 m.eP1
9329 cY
9330 cTrunc:lB
9331 m.eP1);m.c41
9332 cInt:lB
9333 m.eP1);m.c41
9334 cSinh:lB
9335 m.y82
9336 fp_sinh
9337 cY
9338 cTanh:lB
9339 m.y82
9340 fp_tanh,range
9341 x8(eS1(-y03
9342 cY
9343 cCosh:lB
9344 if(m.iV2){if(m
9345 i0){if(m.min
9346 cH1&&m.max
9347 cH1){m.min
9348 cM}
9349 tP1(m.min)t83&&m.max
9350 cH1)nQ3
9351 cM
9352 if(tmp>m.max)m.max=tmp;m.min=eS1(1);}
9353 else{m.min
9354 cM
9355 std::swap(m.min,m.max);}
9356 }
9357 else{if(m.min
9358 cH1){m
9359 nM2
9360 m.min=fp_cosh(m.min);}
9361 else{m
9362 nM2
9363 m.min=eS1(1);}
9364 }
9365 }
9366 else{m.iV2=true;m.min=eS1(1);if(m
9367 i0){m.min=fp_cosh(m.max);m
9368 nM2}
9369 else
9370 m
9371 nM2}
9372 return
9373 m
9374 cM3
9375 cIf:case
9376 i03:{range
9377 x8
9378 res1=y6
9379 1));range
9380 x8
9381 res2=y6
9382 2));if(!res2.iV2)res1.iV2
9383 i13
9384 tP1
9385 res1
9386 y41(res2.min)<res1.min)res1.min=res2.min;if(!res2
9387 i0)res1
9388 nM2
9389 tP1
9390 res1
9391 i0&&(res2.max)>res1.max)res1.max=res2.max
9392 l81
9393 res1
9394 cM3
9395 cMin:{bool
9396 iG
9397 i13
9398 bool
9399 iH
9400 i13
9401 tB1;x4
9402 m
9403 xO3!m.iV2)iG=true;yP1.iV2||(m.min)<i11)i11=m.min;if(!m
9404 i0)iH=true;yP1
9405 i0||(m.max)<e63)e63=m.max;}
9406 if(iG)c42
9407 iH)tE1
9408 l81
9409 yA2
9410 cMax:{bool
9411 iG
9412 i13
9413 bool
9414 iH
9415 i13
9416 tB1;x4
9417 m
9418 xO3!m.iV2)iG=true;yP1.iV2||m.min>i11)i11=m.min;if(!m
9419 i0)iH=true;yP1
9420 i0||m.max>e63)e63=m.max;}
9421 if(iG)c42
9422 iH)tE1
9423 l81
9424 yA2
9425 cAdd:{tB1(eS1(0),eS1(0));x4
9426 item
9427 xO3
9428 item.iV2)i11+=item.min;else
9429 c42
9430 item
9431 i0)e63+=item.max;else
9432 tE1;if(!result
9433 y41!e02)nM3
9434 if(result
9435 y41
9436 e02&&i11>e63)std::swap(i11,e63)l81
9437 yA2
9438 cMul:{e92
9439 Value{enum
9440 lR3{tR2,i91,PlusInf}
9441 ;lR3
9442 eF;eS1
9443 value;Value(lR3
9444 t):eF(t),value(0){}
9445 Value(eS1
9446 v):eF(tR2),value(v){}
9447 bool
9448 c22
9449 n61
9450 eF==i91||(eF==tR2&&value
9451 t83
9452 iR2
9453 e31*=i01
9454 Value&rhs){if(eF==tR2&&rhs.eF==tR2)value*=rhs.value;else
9455 eF=(c22)!=rhs.c22)?i91:PlusInf);}
9456 i12<i01
9457 Value&rhs
9458 n61(eF==i91&&rhs.eF!=i91)||(eF==tR2&&(rhs.eF==PlusInf||(rhs.eF==tR2&&value<rhs.value)));}
9459 }
9460 ;e92
9461 yD1{Value
9462 yC2,yD2;yD1():yC2(Value::PlusInf),yD2(Value::i91){}
9463 void
9464 nN2
9465 Value
9466 yX3,const
9467 Value&value2){yX3*=value2;if(yX3<yC2)yC2=yX3;if(yD2<yX3)yD2=yX3;}
9468 }
9469 ;tB1(eS1(y03;x4
9470 item
9471 xO3!item
9472 y41!item
9473 i0)nL);Value
9474 lS3=c32?Value(i11):nC2
9475 i91);Value
9476 lT3=e02?Value(e63):nC2
9477 PlusInf);Value
9478 lU3=item.iV2?Value(item.min):nC2
9479 i91);Value
9480 lV3=item
9481 i0?Value(item.max):nC2
9482 PlusInf);yD1
9483 range;range.nN2
9484 lS3,lU3
9485 eN2
9486 lS3,lV3
9487 eN2
9488 lT3,lU3
9489 eN2
9490 lT3,lV3);if(range.yC2.eF==Value::tR2)i11=range.yC2.value;else
9491 c42
9492 range.yD2.eF==Value::tR2)e63=range.yD2.value;else
9493 tE1;if(!result
9494 y41!e02)nM3
9495 if(result
9496 y41
9497 e02&&i11>e63)std::swap(i11,e63)l81
9498 yA2
9499 cMod:{range
9500 x8
9501 x
9502 y5
9503 y=y6
9504 1));if(y
9505 i0){if(y.max
9506 cH1){if(!x.iV2||(x.min)<0)nL-y.max,y.max);else
9507 nL
9508 eS1(0),y.max);}
9509 else{if(!x
9510 i0||(x.max)>=0)nL
9511 y.max,-y.max);else
9512 nL
9513 y.max,fp_const_negativezero
9514 x8());}
9515 }
9516 else
9517 nL)cM3
9518 cPow:{if(nE1
9519 y4==eS1(0))e83
9520 y03;}
9521 lX&&n6==eS1(0))e83
9522 0),eS1(0));}
9523 lX&&fp_equal(n6,nY3
9524 e83
9525 y03;}
9526 if(nE1
9527 y4>0&&GetEvennessInfo
9528 nW1
9529 1))==IsAlways)c21
9530 y4;range
9531 x8
9532 tmp
9533 y5
9534 result;c32=true;i11=0;if(tmp
9535 y41
9536 tmp.min>=0)i11=eG3
9537 tmp.min,cE2);tP1
9538 tmp
9539 i0&&tmp.max<=0)i11=eG3
9540 tmp.max,cE2);tE1;if(tmp
9541 y41
9542 tmp
9543 i0){e02=true;e63=std::max(fp_abs(tmp.min),fp_abs(tmp.max));e63=eG3
9544 e63,cE2);}
9545 return
9546 result;}
9547 range
9548 x8
9549 p0
9550 y5
9551 p1=y6
9552 1
9553 eO2
9554 p0_positivity=(p0
9555 y41(p0.min)cH1)?IsAlways:(p0
9556 i0&&(p0.max)t83?yO3:Unknown);TriTruthValue
9557 c52=GetEvennessInfo
9558 nW1
9559 1
9560 eO2
9561 t2=Unknown;switch(p0_positivity)tF1
9562 t2=IsAlways;lC
9563 yO3:{t2=c52;nM3
9564 default:switch(c52)tF1
9565 t2=IsAlways;lC
9566 yO3:lC
9567 Unknown:{if(nE1!eY2
9568 y4)&&y4
9569 cH1){t2=IsAlways;}
9570 nM3}
9571 yN3(t2)tF1{eS1
9572 n31
9573 if(p0
9574 y41
9575 p1.iV2){min=eG3
9576 p0.min,p1.min);if(p0.min
9577 t83&&(!p1
9578 i0||p1.max
9579 cH1)&&min
9580 cH1)n31}
9581 if(p0
9582 y41
9583 p0.min
9584 cH1&&p0
9585 i0&&p1
9586 i0){eS1
9587 max=eG3
9588 p0.max,p1.max);if(min>max)std::swap(min,max);nL
9589 min,max);}
9590 nL
9591 min,false)cM3
9592 yO3:{nL
9593 false,fp_const_negativezero
9594 x8());}
9595 default:{nM3
9596 c91
9597 cNeg:lB
9598 m.set_neg(cY
9599 cSub
9600 x7
9601 cNeg
9602 y23
9603 1
9604 y43
9605 cAdd);y53;tmp
9606 yY3
9607 l81
9608 lH
9609 cInv:lV-1
9610 e12
9611 cDiv
9612 x7
9613 cInv
9614 y23
9615 1
9616 y43
9617 xU1
9618 yY3
9619 l81
9620 lH
9621 cRad:{cF
9622 xU1
9623 yT
9624 fp_const_rad_to_deg
9625 x8(e12
9626 cDeg:{cF
9627 xU1
9628 yT
9629 fp_const_deg_to_rad
9630 x8(e12
9631 cSqr:lV
9632 2
9633 e12
9634 cExp:{cF
9635 cPow);tmp
9636 yT
9637 fp_const_e
9638 x8()));y53
9639 l81
9640 lH
9641 cExp2:{cF
9642 cPow);tmp
9643 yT
9644 nR3
9645 y53
9646 l81
9647 lH
9648 cCbrt:lB
9649 m.y82
9650 fp_cbrt
9651 cY
9652 cSqrt:lB
9653 if(m.iV2)m.min=(m.min)<0?0:fp_sqrt(m.min);if(m
9654 i0)m.max=(m.max)<0?0:fp_sqrt(m.max
9655 cY
9656 cRSqrt:lV-0.5
9657 e12
9658 cHypot:nG1
9659 xsqr,ysqr,add,sqrt;xsqr
9660 yC
9661 0));xsqr
9662 yT
9663 nR3
9664 ysqr
9665 yC
9666 1));ysqr
9667 yT
9668 nR3
9669 xsqr
9670 tU
9671 cPow);ysqr
9672 tU
9673 cPow);add
9674 yA
9675 xsqr);add
9676 yA
9677 ysqr);add
9678 tU
9679 cAdd);sqrt
9680 yA
9681 add);sqrt
9682 tU
9683 cSqrt)l81
9684 iM
9685 sqrt)cM3
9686 cLog2by
9687 x7
9688 cLog2
9689 y23
9690 0
9691 y43
9692 cMul);tmp
9693 yY3;tmp
9694 yC
9695 1))l81
9696 lH
9697 cCot
9698 x7
9699 cTan)nG
9700 lH
9701 cSec
9702 x7
9703 cCos)nG
9704 lH
9705 cCsc
9706 x7
9707 cSin)nG
9708 iM
9709 tmp);}
9710 lC
9711 cRDiv:case
9712 cRSub:case
9713 cDup:case
9714 cFetch:case
9715 cPopNMov:case
9716 cSinCos:case
9717 cNop:case
9718 cJump:case
9719 iE2:lC
9720 cPCall:lC
9721 cFCall:lC
9722 cEval:nM3
9723 nL);}
9724 yV1
9725 TriTruthValue
9726 GetIntegerInfo
9727 i01
9728 eR{switch
9729 xU2
9730 iY2
9731 cImmed:return
9732 eY2
9733 yZ3)?IsAlways:yO3;case
9734 cFloor:case
9735 cCeil:case
9736 cTrunc:case
9737 cInt:return
9738 IsAlways;case
9739 cAnd:case
9740 cOr:case
9741 cNot:case
9742 cNotNot:case
9743 cEqual:case
9744 t71:case
9745 cLess:case
9746 cLessOrEq:case
9747 cGreater:case
9748 cGreaterOrEq:return
9749 IsAlways;case
9750 cIf:{TriTruthValue
9751 a=GetIntegerInfo
9752 nW1
9753 1
9754 eO2
9755 b=GetIntegerInfo
9756 nW1
9757 2));if(a==b
9758 nZ2
9759 a
9760 l81
9761 Unknown
9762 cM3
9763 cAdd:case
9764 cMul:{for
9765 xU
9766 if(GetIntegerInfo
9767 nW1
9768 a))!=IsAlways
9769 nZ2
9770 Unknown
9771 l81
9772 IsAlways;}
9773 default:nM3
9774 return
9775 Unknown;}
9776 xG1
9777 IsLogicalValue
9778 i01
9779 eR{switch
9780 xU2
9781 iY2
9782 cImmed:return
9783 fp_equal(yZ3,eS1(0))||fp_equal(yZ3,eS1(1));case
9784 cAnd:case
9785 cOr:case
9786 cNot:case
9787 cNotNot:case
9788 cAbsAnd:case
9789 cAbsOr:case
9790 yR3:case
9791 cAbsNotNot:case
9792 cEqual:case
9793 t71:case
9794 cLess:case
9795 cLessOrEq:case
9796 cGreater:case
9797 cGreaterOrEq:nW
9798 cMul:{for
9799 xU
9800 if(!y93
9801 a))yI
9802 return
9803 true
9804 cM3
9805 cIf:case
9806 i03:{return
9807 y93
9808 1))&&y93
9809 2));}
9810 default:nM3
9811 nX2}
9812 #endif
9813 #ifdef FP_SUPPORT_OPTIMIZER
9814 xQ
9815 #if defined(__x86_64) || !defined(FP_SUPPORT_CBRT)
9816 # define CBRT_IS_SLOW
9817 #endif
9818 #if defined(DEBUG_POWI) || defined(DEBUG_SUBSTITUTIONS)
9819 #include <cstdio>
9820 #endif
9821 t5{extern
9822 const
9823 i02
9824 char
9825 powi_table[256];}
9826 iO2{using
9827 iO2
9828 FPoptimizer_CodeTree;xG1
9829 IsOptimizableUsingPowi(long
9830 immed,long
9831 penalty=0){yW2
9832 synth;synth.PushVar(iE2);size_t
9833 bytecodesize_backup
9834 t13
9835 GetByteCodeSize();yV2
9836 x31
9837 immed,yV2
9838 eX1
9839 x8::MulSequence,synth);size_t
9840 bytecode_grow_amount
9841 t13
9842 GetByteCodeSize()-bytecodesize_backup
9843 l81
9844 bytecode_grow_amount<size_t(MAX_POWI_BYTECODE_LENGTH-penalty);}
9845 xB1
9846 ChangeIntoRootChain(yK2&tree,bool
9847 iK2,long
9848 tS2,long
9849 tT2){while(tT2>0){cF
9850 cCbrt);nZ3);tmp.Rehash(nD2--tT2;}
9851 while(tS2>0){cF
9852 cSqrt);if(iK2){tmp
9853 tU
9854 cRSqrt);iK2
9855 i13}
9856 nZ3);tmp.Rehash(nD2--tS2;}
9857 if(iK2){cF
9858 cInv);nZ3
9859 nD2}
9860 }
9861 yT1
9862 RootPowerTable{static
9863 const
9864 eS1
9865 RootPowers[(1+4)*(1+3)];}
9866 ;yV1
9867 const
9868 eS1
9869 t7(1+4)*(1+3)]={eS1(1)lS
9870 tB3
9871 tB3
9872 2*tB3
9873 2*2*2)lS
9874 3
9875 x32
9876 2
9877 x32
9878 2*2
9879 x32
9880 2*2*2
9881 x32
9882 2*2*2*2
9883 x32
9884 3
9885 x32
9886 3*2
9887 x32
9888 3*2*2
9889 x32
9890 3*2*2*2
9891 x32
9892 3*2*2*2*2
9893 x32
9894 3*3
9895 x32
9896 3*3*2
9897 x32
9898 3*3*2*2
9899 x32
9900 3*3*2*2*2
9901 x32
9902 3*3*2*2*2*2)}
9903 ;e92
9904 PowiResolver{static
9905 const
9906 i02
9907 MaxSep=4;static
9908 lX3
9909 tC3=5;typedef
9910 int
9911 c03;typedef
9912 long
9913 n63;typedef
9914 long
9915 t8;e92
9916 yE2{yE2():n_int_sqrt(0),n_int_cbrt(0),sep_list(),lY1(0){}
9917 int
9918 n_int_sqrt;int
9919 n_int_cbrt;int
9920 eW1
9921 MaxSep];t8
9922 lY1;}
9923 ;yV1
9924 static
9925 yE2
9926 CreatePowiResult(eS1
9927 cE2){yE2
9928 result;c03
9929 eE=FindIntegerFactor(cE2);if(eE==0){
9930 #ifdef DEBUG_POWI
9931 tU2"no factor found for %Lg\n"
9932 y33);
9933 #endif
9934 return
9935 result;}
9936 c13=xV1
9937 cE2,eE);n63
9938 e22=EvaluateFactorCost(eE,0,0,0)+cH
9939 c13);int
9940 tD3=0;int
9941 tE3=0;int
9942 lW3=0;
9943 #ifdef DEBUG_POWI
9944 tU2"orig = %Lg\n"
9945 y33);tU2"plain factor = "
9946 tS3"%ld\n"
9947 ,(int)eE,(long)e22);
9948 #endif
9949 for
9950 iL1
9951 n_s=0;n_s<MaxSep;++n_s){int
9952 xC=0;n63
9953 yE1=e22;c03
9954 yQ1=eE;for(int
9955 s=1;s<tC3*4;++s){
9956 #ifdef CBRT_IS_SLOW
9957 if(s>=tC3)break;
9958 #endif
9959 int
9960 n_sqrt=s%tC3;int
9961 n_cbrt=s/tC3;if(n_sqrt+n_cbrt>4)y81
9962 eS1
9963 lE1=cE2;lE1-=t7
9964 s];tH1=FindIntegerFactor(lE1);if(xD2!=0){t8
9965 xL=xV1
9966 lE1,xD2);n63
9967 cost=EvaluateFactorCost(xD2,tD3+n_sqrt,tE3+n_cbrt,lW3+1)+cH
9968 xL);
9969 #ifdef DEBUG_POWI
9970 tU2"Candidate sep %u (%d*sqrt %d*cbrt)factor = "
9971 tS3"%ld (for %Lg to %ld)\n"
9972 ,s,n_sqrt,n_cbrt,xD2,(long)cost
9973 x12
9974 lE1,(long)xL);
9975 #endif
9976 if(cost<yE1){xC=s;yQ1=xD2;yE1=cost;}
9977 }
9978 }
9979 if(!xC)break;
9980 #ifdef DEBUG_POWI
9981 tU2"CHOSEN sep %u (%d*sqrt %d*cbrt)factor = "
9982 tS3"%ld, exponent %Lg->%Lg\n"
9983 ,xC,xC%tC3,xC/tC3,yQ1,yE1
9984 x12(cE2)x12(cE2-t7
9985 xC]));
9986 #endif
9987 tC1
9988 eW1
9989 n_s]=xC;cE2-=t7
9990 xC];tD3+=xC%tC3;tE3+=xC/tC3;e22=yE1;eE=yQ1;lW3+=1;}
9991 c13=xV1
9992 cE2,eE);
9993 #ifdef DEBUG_POWI
9994 tU2"resulting exponent is %ld (from exponent=%Lg, best_factor=%Lg)\n"
9995 ,c13
9996 y33
9997 x12
9998 eE);
9999 #endif
10000 while(eE%2==0){++tC1
10001 n_int_sqrt;eE/=2;}
10002 while(eE%3==0){++tC1
10003 n_int_cbrt;eE/=3;}
10004 return
10005 result;}
10006 private:static
10007 n63
10008 cH
10009 t8
10010 xL){static
10011 std::map
10012 c62
10013 i7;if(xL<0){n63
10014 cost=22
10015 l81
10016 cost+cH-xL);}
10017 std::map
10018 c62::nX3
10019 i=i7.xE2
10020 xL);if(i!=i7.cP1
10021 xL
10022 nZ2
10023 i
10024 cJ2;std::pair
10025 c62
10026 cY3
10027 xL,0.0);n63&cost=tC1
10028 second;while(xL>1){int
10029 xD2=0;if(xL<256){xD2=yV2
10030 powi_table[xL];if(xD2&128)xD2&=127;else
10031 xD2=0;if(xD2&64)xD2=-(xD2&63)-1;}
10032 if(xD2){cost+=cH
10033 xD2);xL/=xD2;y81}
10034 if(!(xL&1)){xL/=2;cost+=6;}
10035 else{cost+=7;xL-=1;}
10036 }
10037 i7.nT3,result)l81
10038 cost
10039 eI2
10040 t8
10041 xV1
10042 yF1,tH1){return
10043 makeLongInteger(value*eS1(xD2))eI2
10044 bool
10045 yG1
10046 yF1,tH1){eS1
10047 v=value*eS1(xD2)l81
10048 isLongInteger(v)eI2
10049 c03
10050 FindIntegerFactor(yF1){tH1=(2*2*2*2);
10051 #ifdef CBRT_IS_SLOW
10052 #else
10053 xD2*=(3*3*3);
10054 #endif
10055 c03
10056 result=0;if(yG1
10057 value,xD2)){result=xD2;while((xD2%2)==0&&yG1
10058 value,xD2/2))result=xD2/=2;while((xD2%3)==0&&yG1
10059 value,xD2/3))result=xD2/=3;}
10060 #ifdef CBRT_IS_SLOW
10061 if(result==0){if(yG1
10062 value,3)nZ2
10063 3;}
10064 #endif
10065 return
10066 result;}
10067 static
10068 int
10069 EvaluateFactorCost(int
10070 xD2,int
10071 s,int
10072 c,int
10073 nmuls){lX3
10074 lY3=6;
10075 #ifdef CBRT_IS_SLOW
10076 lX3
10077 e32=25;
10078 #else
10079 lX3
10080 e32=8;
10081 #endif
10082 int
10083 result=s*lY3+c*e32;while(xD2%2==0){xD2/=2;result+=lY3;}
10084 while(xD2%3==0){xD2/=3;result+=e32;}
10085 result+=nmuls
10086 l81
10087 result;}
10088 }
10089 ;}
10090 iO2
10091 FPoptimizer_CodeTree{xG1
10092 yK2::RecreateInversionsAndNegations(bool
10093 prefer_base2){bool
10094 changed=false
10095 c23
10096 0;a<cN3++a)if(lT1.RecreateInversionsAndNegations(prefer_base2))yI1
10097 if(changed){exit_changed:Mark_Incompletely_Hashed()nS2
10098 switch(lM2
10099 iY2
10100 cMul:{yG
10101 nV1
10102 lG2
10103 yJ
10104 lH2,cJ1;if(true){bool
10105 nQ1
10106 i13
10107 eS1
10108 nE2=0
10109 c23
10110 cO3
10111 yF2
10112 0)c82
10113 tJ
10114 1)y21){nQ1=true;nE2=tJ
10115 1).xJ1;nM3}
10116 if(nQ1){eS1
10117 immeds=1.0
10118 c23
10119 cO3
10120 y21){immeds*=powgroup.xJ1;yH1}
10121 for
10122 xK2
10123 cN3
10124 a-->0;)nG1&powgroup=lT1;if(powgroup
10125 yF2
10126 0)c82
10127 tJ
10128 1)y21)nG1&log2=tJ
10129 0);log2.iY
10130 log2
10131 tU
10132 lZ3
10133 log2
10134 yT
10135 eG3
10136 immeds,eS1(1)/nE2)));log2.Rehash(nW2}
10137 }
10138 }
10139 for
10140 xK2
10141 cO3
10142 yF2
10143 1)y21){lM1&exp_param=tJ
10144 1);eS1
10145 cE2=exp_param.xJ1;if(cR1,eS1(-1))){iY
10146 lG2
10147 yL
10148 lT1
10149 xY3
10150 yH1
10151 tP1
10152 cE2<0&&eY2
10153 cE2))nG1
10154 iI;iI
10155 tU
10156 cPow);iI
10157 eT
10158 tJ
10159 0));iI
10160 yT-cE2));iI
10161 x02;lG2
10162 yL
10163 iI);iY
10164 yH1}
10165 tP1
10166 powgroup
10167 c82!lH2.iA1{lH2=tJ
10168 0);iY
10169 yH1
10170 tP1
10171 powgroup
10172 nE==cLog2by&&!cJ1.iA1{cJ1=powgroup;iY
10173 yH1}
10174 if(!lG2
10175 cQ3){changed=true
10176 yJ
10177 eR1;eR1
10178 e53
10179 eR1
10180 tI1
10181 lG2);eR1
10182 i72
10183 xW1
10184 cMul);xX1
10185 SetParamsMove(t3
10186 if(xX1
10187 IsImmed()&&fp_equal(xX1
10188 xJ1,nY3{lI2
10189 cInv);eG
10190 eR1);}
10191 else{if(xX1
10192 xT2>=eR1.xT2){lI2
10193 cDiv
10194 eV1
10195 eG
10196 eR1);}
10197 else{lI2
10198 cRDiv);eG
10199 eR1
10200 eV1}
10201 }
10202 }
10203 if(lH2.iA1
10204 nG1
10205 xW1
10206 lM2);xX1
10207 SetParamsMove(t3
10208 while(xX1
10209 RecreateInversionsAndNegations(prefer_base2))xX1
10210 FixIncompleteHashes();lI2
10211 lZ3
10212 eG
10213 lH2
10214 eV1
10215 yI1}
10216 if(cJ1.iA1
10217 nG1
10218 xW1
10219 cMul);n83
10220 yA
10221 cJ1
10222 x03;xX1
10223 AddParamsMove(t3
10224 while(xX1
10225 RecreateInversionsAndNegations(prefer_base2))xX1
10226 FixIncompleteHashes();DelParams();lI2
10227 lZ3
10228 eG
10229 cJ1
10230 lD
10231 0)eV1
10232 yI1
10233 c91
10234 cAdd:{yG
10235 nV1
10236 tV2
10237 c23
10238 tD
10239 c33
10240 cMul){lJ2
10241 xY1:yJ&n83
10242 c72
10243 for(iX2
10244 xX1
10245 cN3
10246 b-->0;){if(n83
10247 lD
10248 b)xC3
10249 xD2=n83
10250 lD
10251 b).xJ1
10252 i82
10253 xD2
10254 eQ1
10255 xY1;}
10256 xX1
10257 iY
10258 xX1
10259 iH1
10260 b
10261 eJ2
10262 tP1
10263 fp_equal(xD2,eS1(-2)))xF
10264 xY1;}
10265 xX1
10266 iY
10267 xX1
10268 iH1
10269 b);n83
10270 yT
10271 eS1(2))eJ2}
10272 }
10273 if(t4){xX1
10274 nR1
10275 n83);yH1}
10276 tP1
10277 c33
10278 cDiv&&!IsIntType
10279 x8::result){lJ2
10280 xZ1:yJ&eR1
10281 c72
10282 if(eR1
10283 lD
10284 0)tF3(fp_equal(eR1
10285 lD
10286 0).xJ1
10287 eQ1
10288 xZ1;}
10289 eR1.iY
10290 eR1.iH1
10291 0);eR1
10292 tU
10293 cInv
10294 eJ2}
10295 if(t4)xF
10296 xZ1;}
10297 eR1.nR1
10298 eR1);yH1}
10299 tP1
10300 c33
10301 cRDiv&&!IsIntType
10302 x8::result){lJ2
10303 x91:yJ&eR1
10304 c72
10305 if(eR1
10306 lD
10307 1)tF3(fp_equal(eR1
10308 lD
10309 1).xJ1
10310 eQ1
10311 x91;}
10312 eR1.iY
10313 eR1.iH1
10314 1);eR1
10315 tU
10316 cInv
10317 eJ2}
10318 if(t4)xF
10319 x91;}
10320 eR1.nR1
10321 eR1);yH1}
10322 if(!tV2
10323 cQ3){
10324 #ifdef DEBUG_SUBSTITUTIONS
10325 tU2"Will make a Sub conversion in:\n"
10326 );fflush(stdout);iO
10327 #endif
10328 yK2
10329 yR1;yR1
10330 tU
10331 cAdd);yR1
10332 tI1
10333 tV2);yR1
10334 i72
10335 cK1;cK1
10336 tU
10337 cAdd);cK1
10338 tI1
10339 iE1));cK1
10340 x02;if(cK1
10341 y21&&fp_equal(cK1.xJ1,eS1(0))){lI2
10342 cNeg);cU3);}
10343 else{if(cK1.xT2==1){lI2
10344 cRSub);cU3);cV3}
10345 tP1
10346 yR1
10347 nE==cAdd){lI2
10348 cSub);cV3
10349 cU3
10350 xY3
10351 for
10352 xK2
10353 1;a<yR1.cN3++a)nG1
10354 e42;e42
10355 tU
10356 cSub);e42
10357 tI1
10358 iE1));e42.y12);eG
10359 e42);cU3
10360 lD
10361 a));}
10362 }
10363 else{lI2
10364 cSub);cV3
10365 cU3);}
10366 }
10367 #ifdef DEBUG_SUBSTITUTIONS
10368 tU2"After Sub conversion:\n"
10369 );fflush(stdout);iO
10370 #endif
10371 c91
10372 cPow:{lM1&p0
10373 tW2
10374 0);lM1&p1
10375 tW2
10376 1);if(p1
10377 tF3
10378 n03!=eS1(0)&&!eY2
10379 p1.xJ1)){eJ
10380 yE2
10381 r=eJ
10382 CreatePowiResult(fp_abs
10383 n03));if(r.lY1!=0){bool
10384 iB1
10385 i13
10386 if
10387 n03<0&&r.eW1
10388 0]==0&&r
10389 x33>0){iB1=true;}
10390 #ifdef DEBUG_POWI
10391 tU2"Will resolve powi %Lg as powi(chain(%d,%d),%ld)"
10392 x12
10393 fp_abs
10394 n03),r
10395 x33,r.n_int_cbrt,r.lY1)xS3
10396 n=0;n<eJ
10397 MaxSep;++n){if(r
10398 cW3==0)break;int
10399 n_sqrt=r
10400 cW3%eJ
10401 tC3;int
10402 n_cbrt=r
10403 cW3/eJ
10404 tC3;tU2"*chain(%d,%d)"
10405 ,n_sqrt,n_cbrt);}
10406 tU2"\n"
10407 );
10408 #endif
10409 yK2
10410 c92
10411 tW2
10412 0)yJ
10413 yG2=c92;yG2.iY
10414 ChangeIntoRootChain(yG2,iB1,r
10415 x33,r.n_int_cbrt);yG2
10416 i72
10417 pow;if(r.lY1!=1){pow
10418 tU
10419 cPow);pow
10420 yA
10421 yG2);pow
10422 yT
10423 eS1(r.lY1)));}
10424 else
10425 pow.swap(yG2)yJ
10426 mul;mul
10427 e53
10428 mul
10429 yA
10430 pow)xS3
10431 n=0;n<eJ
10432 MaxSep;++n){if(r
10433 cW3==0)break;int
10434 n_sqrt=r
10435 cW3%eJ
10436 tC3;int
10437 n_cbrt=r
10438 cW3/eJ
10439 tC3
10440 yJ
10441 e52=c92;e52.iY
10442 ChangeIntoRootChain(e52,false,n_sqrt,n_cbrt);e52
10443 x02;mul
10444 yA
10445 e52);}
10446 if
10447 n03<0&&!iB1){mul
10448 x02;lI2
10449 cInv);nC1
10450 0,mul);iH1
10451 1);}
10452 else{lI2
10453 cMul);SetParamsMove(mul.iE1));}
10454 #ifdef DEBUG_POWI
10455 iO
10456 #endif
10457 yI1
10458 nM3}
10459 }
10460 if(lM2==cPow&&(!p1
10461 y21||!isLongInteger
10462 n03)||!IsOptimizableUsingPowi
10463 x8(makeLongInteger
10464 n03)))){if(p0
10465 y21&&p0.xJ1>0.0){if(prefer_base2){eS1
10466 yH2=fp_log2(p0.xJ1)i82
10467 yH2,nY3{iH1
10468 0);}
10469 else{n1
10470 cU1
10471 yH2));cE2
10472 eT
10473 p1)tD1
10474 iP}
10475 lI2
10476 cExp2);yI1}
10477 else{eS1
10478 yH2=fp_log(p0.xJ1)i82
10479 yH2,nY3{iH1
10480 0);}
10481 else{n1
10482 cU1
10483 yH2));cE2
10484 eT
10485 p1)tD1
10486 iP}
10487 lI2
10488 cExp);yI1}
10489 }
10490 tP1
10491 GetPositivityInfo(p0)==IsAlways){if(prefer_base2)nG1
10492 log;log
10493 tU
10494 cLog2);log
10495 eT
10496 p0);log
10497 x02;n1
10498 p1);cE2
10499 yA
10500 log)tD1);lI2
10501 cExp2
10502 iP
10503 yI1}
10504 else
10505 nG1
10506 log;log
10507 tU
10508 cLog);log
10509 eT
10510 p0);log
10511 x02;n1
10512 p1);cE2
10513 yA
10514 log)tD1);lI2
10515 cExp
10516 iP
10517 yI1}
10518 }
10519 c91
10520 cDiv:{if(GetParam(0)y21&&fp_equal(GetParam(0).xJ1,nY3{lI2
10521 cInv);iH1
10522 0);}
10523 nM3
10524 default:nM3
10525 if(changed)goto
10526 exit_changed
10527 l81
10528 changed;}
10529 }
10530 #endif
10531 #ifdef FP_SUPPORT_OPTIMIZER
10532 xQ
10533 iO2{using
10534 iO2
10535 FPoptimizer_CodeTree;class
10536 eT1{size_t
10537 yJ1;size_t
10538 eK;size_t
10539 eL;size_t
10540 lF1;e13
10541 eT1():yJ1(0),eK(0),eL(0),lF1(0){}
10542 void
10543 c43
10544 OPCODE
10545 op){yJ1+=1;n13
10546 cCos)++eK;n13
10547 cSin)++eL;n13
10548 cSec)++eK;n13
10549 cCsc)++eL;n13
10550 cTan)++lF1;n13
10551 cCot)++lF1;}
10552 size_t
10553 GetCSEscore()const{size_t
10554 result=yJ1
10555 l81
10556 result;}
10557 int
10558 NeedsSinCos()const{bool
10559 always_sincostan=(yJ1==(eK+eL+lF1));if((lF1&&(eL||eK))||(eL&&eK)){if(always_sincostan
10560 nZ2
10561 1
10562 l81
10563 2;}
10564 return
10565 0;}
10566 size_t
10567 MinimumDepth()const{size_t
10568 n_sincos=std::min(eK,eL);if(n_sincos==0
10569 nZ2
10570 2
10571 l81
10572 1;}
10573 }
10574 ;iP2
10575 TreeCountType:public
10576 std::multimap<fphash_t,std::pair<eT1,yK2> >{}
10577 ;xB1
10578 FindTreeCounts(nX1&lK2,lM1&tree,OPCODE
10579 lL2{iG1
10580 i=lK2.xE2
10581 tree.GetHash());bool
10582 found
10583 i13
10584 for(;i!=lK2.cP1
10585 tree.GetHash();++i){if(tree
10586 iA
10587 i
10588 cJ2
10589 eE3)){i
10590 cJ2.first.c43
10591 lL2;found=true;nM3}
10592 if(!found){eT1
10593 count;count.c43
10594 lL2;lK2.nT3,std::make_pair(tree.GetHash(),std::make_pair
10595 cR3
10596 n72);}
10597 for
10598 yS
10599 FindTreeCounts(lK2,xI2,tree
10600 nE);}
10601 e92
10602 c9{bool
10603 BalanceGood;bool
10604 cI;}
10605 ;yV1
10606 c9
10607 lG1
10608 lM1&root,lM1&c53{if(root
10609 iA
10610 c53){c9
10611 result={true,true}
10612 l81
10613 result;}
10614 c9
10615 result={true,false}
10616 ;if(root
10617 nE==cIf||root
10618 nE==i03){c9
10619 cond=lG1
10620 root
10621 lD
10622 0),c53;c9
10623 xW=lG1
10624 root
10625 lD
10626 1),c53;c9
10627 y9=lG1
10628 root
10629 lD
10630 2),c53;if(cond.cI||xW.cI||y9.cI){tC1
10631 cI=true;}
10632 result
10633 eH=((xW.cI==y9.cI)||eX2&&(cond
10634 eH||(xW.cI&&y9.cI))&&(xW
10635 eH||eX2&&(y9
10636 eH||eX2;}
10637 else{bool
10638 tK1
10639 i13
10640 bool
10641 nS1
10642 i13
10643 for(iX2
10644 root.GetParamCount(),a=0;a<b;++a){c9
10645 tmp=lG1
10646 root
10647 lD
10648 a),c53;if(tmp.cI)tC1
10649 cI=true;if(tmp
10650 eH==false)tK1=true;tP1
10651 tmp.cI)nS1=true;}
10652 if(tK1&&!nS1)result
10653 eH
10654 i13}
10655 return
10656 result;}
10657 xG1
10658 n62
10659 lM1&tG3
10660 lM1&tree,const
10661 yW2&synth,const
10662 nX1&lK2){for(iX2
10663 iT,a=0;a<b;++a){lM1&leaf=xI2;iG1
10664 lT2;xH2
10665 nX1::const_iterator
10666 i=lK2.nW3
10667 i!=lK2.end();++i){if(i->eQ3
10668 leaf.GetHash())y81
10669 const
10670 c63
10671 i->nF2
10672 size_t
10673 score=occ.GetCSEscore();lM1&candidate=i->nG2
10674 if(cC2
10675 candidate))y81
10676 if(leaf.xT2<occ.MinimumDepth())y81
10677 if(score<2)y81
10678 if(lG1
10679 tG3
10680 leaf)eH==false)continue
10681 nS2
10682 if(n62
10683 tG3
10684 leaf,synth,lK2
10685 iF1;}
10686 nX2
10687 xG1
10688 tL1
10689 lM1&nU3,lM1&expr){for
10690 iT1
10691 nU3
10692 lD
10693 a)iA
10694 expr
10695 iF1;for
10696 iT1
10697 tL1
10698 nU3
10699 lD
10700 a),expr
10701 iF1
10702 l81
10703 false;}
10704 xG1
10705 GoodMomentForCSE(lM1&nU3,lM1&expr){if(nU3
10706 nE==cIf
10707 nZ2
10708 true;for
10709 iT1
10710 nU3
10711 lD
10712 a)iA
10713 expr
10714 iF1;size_t
10715 tX2=0;for
10716 iT1
10717 tL1
10718 nU3
10719 lD
10720 a),expr))++tX2
10721 l81
10722 tX2!=1;}
10723 }
10724 iO2
10725 FPoptimizer_CodeTree{yV1
10726 size_t
10727 yK2::SynthCommonSubExpressions(yV2
10728 lP1
10729 const{size_t
10730 stacktop_before
10731 t13
10732 GetStackTop();nX1
10733 lK2;FindTreeCounts(lK2,*this,lM2);
10734 #ifdef DEBUG_SUBSTITUTIONS_CSE
10735 DumpHashes(*this);
10736 #endif
10737 for(;;){size_t
10738 yI2=0;iG1
10739 lT2;for(iG1
10740 j,i=lK2.nW3
10741 i!=lK2.end();i=j){j=i;++j;const
10742 c63
10743 i->nF2
10744 size_t
10745 score=occ.GetCSEscore();lM1&tree=i->nG2
10746 #ifdef DEBUG_SUBSTITUTIONS_CSE
10747 std::cout<<"Score "
10748 <<score<<":\n"
10749 ;DumpTreeWithIndent(tree);
10750 #endif
10751 if(cC2
10752 tree))xV
10753 if(tree.xT2<occ.MinimumDepth())xV
10754 if(score<2)xV
10755 if(lG1*this,tree)eH==false)xV
10756 if(n62*this,tree,synth,lK2)){y81}
10757 if(!GoodMomentForCSE(*this
10758 n72
10759 xV
10760 score*=tree.xT2;if(score>yI2){yI2=score;lT2=i;}
10761 }
10762 if(yI2<=0)break;const
10763 c63
10764 lT2->nF2
10765 lM1&tree=lT2->nG2
10766 #ifdef DEBUG_SUBSTITUTIONS_CSE
10767 std::cout<<tZ3"Common Subexpression:"
10768 ;xE3
10769 x8(tree)lN1"\n"
10770 ;
10771 #endif
10772 int
10773 y01=occ.NeedsSinCos()yJ
10774 tY2,tZ2;if(y01){tY2
10775 eT
10776 tree);tY2
10777 tU
10778 cSin);tY2
10779 x02;tZ2
10780 eT
10781 tree);tZ2
10782 tU
10783 cCos);tZ2
10784 x02;if(cC2
10785 tY2)||cC2
10786 tZ2)){if(y01==2){lK2.erase(lT2);y81}
10787 y01=0;}
10788 }
10789 tree.SynthesizeByteCode(synth,false);lK2.erase(lT2);
10790 #ifdef DEBUG_SUBSTITUTIONS_CSE
10791 std::cout<<"Done with Common Subexpression:"
10792 ;xE3
10793 x8(tree)lN1"\n"
10794 ;
10795 #endif
10796 if(y01){if(y01==2){tQ1
10797 c71);}
10798 lK1
10799 cSinCos,1,2
10800 eU3.yZ2
10801 tY2,1
10802 eU3.yZ2
10803 tZ2,0);}
10804 }
10805 return
10806 synth.x5
10807 stacktop_before;}
10808 }
10809 #endif
10810 #ifdef FP_SUPPORT_OPTIMIZER
10811 yV1
10812 lR1
10813 x8
10814 nH2
10815 using
10816 iO2
10817 FPoptimizer_CodeTree;CopyOnWrite()yJ
10818 tree;tree.GenerateFrom(mData->mByteCode,mData->mImmed,*mData);FPoptimizer_Optimize::ApplyGrammars(tree);yG<i02>c73;yG
10819 x8
10820 immed;size_t
10821 stacktop_max=0;tree.SynthesizeByteCode(c73,immed,stacktop_max);if(mData->mStackSize!=stacktop_max){mData->mStackSize=i02(stacktop_max);
10822 #if !defined(FP_USE_THREAD_SAFE_EVAL) && \
10823     !defined(FP_USE_THREAD_SAFE_EVAL_WITH_ALLOCA)
10824 mData->mStack
10825 nE3
10826 stacktop_max);
10827 #endif
10828 }
10829 mData->mByteCode.swap(c73);mData->mImmed.swap(immed);}
10830 #ifdef FP_SUPPORT_MPFR_FLOAT_TYPE
10831 n73<>lR1<MpfrFloat>nH2}
10832 #endif
10833 #ifdef FP_SUPPORT_GMP_INT_TYPE
10834 n73<>lR1<GmpInt>nH2}
10835 #endif
10836 FUNCTIONPARSER_INSTANTIATE_TYPES
10837 #endif
10838
10839 #endif