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