Skip to content

Commit 5f5cafe

Browse files
committed
Use loop profile in math.dist()
1 parent 2318fe6 commit 5f5cafe

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import com.oracle.truffle.api.frame.VirtualFrame;
8181
import com.oracle.truffle.api.library.CachedLibrary;
8282
import com.oracle.truffle.api.profiles.ConditionProfile;
83+
import com.oracle.truffle.api.profiles.LoopConditionProfile;
8384

8485
@CoreFunctions(defineModule = "math")
8586
public class MathModuleBuiltins extends PythonBuiltins {
@@ -2696,6 +2697,8 @@ public abstract static class DistNode extends PythonBuiltinNode {
26962697

26972698
@Child private TupleNodes.ConstructTupleNode tupleCtor = TupleNodes.ConstructTupleNode.create();
26982699
@Child private SequenceNodes.GetObjectArrayNode getObjectArray = SequenceNodes.GetObjectArrayNode.create();
2700+
private final LoopConditionProfile loopProfile1 = LoopConditionProfile.createCountingProfile();
2701+
private final LoopConditionProfile loopProfile2 = LoopConditionProfile.createCountingProfile();
26992702

27002703
@Specialization
27012704
public double doGeneric(VirtualFrame frame, Object p, Object q,
@@ -2710,7 +2713,8 @@ public double doGeneric(VirtualFrame frame, Object p, Object q,
27102713
double[] diffs = new double[len];
27112714
double max = 0.0;
27122715
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) {
27142718
double a = lib.asJavaDoubleWithState(ps[i], PArguments.getThreadState(frame));
27152719
double b = lib.asJavaDoubleWithState(qs[i], PArguments.getThreadState(frame));
27162720
double x = Math.abs(a - b);
@@ -2732,7 +2736,8 @@ public double doGeneric(VirtualFrame frame, Object p, Object q,
27322736

27332737
double csum = 1.0;
27342738
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) {
27362741
double x = diffs[i];
27372742
x /= max;
27382743
x = x * x;

0 commit comments

Comments
 (0)