80
80
import com .oracle .truffle .api .frame .VirtualFrame ;
81
81
import com .oracle .truffle .api .library .CachedLibrary ;
82
82
import com .oracle .truffle .api .profiles .ConditionProfile ;
83
+ import com .oracle .truffle .api .profiles .LoopConditionProfile ;
83
84
84
85
@ CoreFunctions (defineModule = "math" )
85
86
public class MathModuleBuiltins extends PythonBuiltins {
@@ -2696,6 +2697,8 @@ public abstract static class DistNode extends PythonBuiltinNode {
2696
2697
2697
2698
@ Child private TupleNodes .ConstructTupleNode tupleCtor = TupleNodes .ConstructTupleNode .create ();
2698
2699
@ Child private SequenceNodes .GetObjectArrayNode getObjectArray = SequenceNodes .GetObjectArrayNode .create ();
2700
+ private final LoopConditionProfile loopProfile1 = LoopConditionProfile .createCountingProfile ();
2701
+ private final LoopConditionProfile loopProfile2 = LoopConditionProfile .createCountingProfile ();
2699
2702
2700
2703
@ Specialization
2701
2704
public double doGeneric (VirtualFrame frame , Object p , Object q ,
@@ -2710,7 +2713,8 @@ public double doGeneric(VirtualFrame frame, Object p, Object q,
2710
2713
double [] diffs = new double [len ];
2711
2714
double max = 0.0 ;
2712
2715
boolean foundNan = false ;
2713
- for (int i = 0 ; i < len ; ++i ) {
2716
+ loopProfile1 .profileCounted (len );
2717
+ for (int i = 0 ; loopProfile1 .inject (i < len ); ++i ) {
2714
2718
double a = lib .asJavaDoubleWithState (ps [i ], PArguments .getThreadState (frame ));
2715
2719
double b = lib .asJavaDoubleWithState (qs [i ], PArguments .getThreadState (frame ));
2716
2720
double x = Math .abs (a - b );
@@ -2732,7 +2736,8 @@ public double doGeneric(VirtualFrame frame, Object p, Object q,
2732
2736
2733
2737
double csum = 1.0 ;
2734
2738
double frac = 0.0 ;
2735
- for (int i = 0 ; i < len ; ++i ) {
2739
+ loopProfile2 .profileCounted (len );
2740
+ for (int i = 0 ; loopProfile2 .inject (i < len ); ++i ) {
2736
2741
double x = diffs [i ];
2737
2742
x /= max ;
2738
2743
x = x * x ;
0 commit comments