From 5c4660605bb13d99d946a8044ca80b92076d5512 Mon Sep 17 00:00:00 2001 From: stepan <stepan.sindelar@oracle.com> Date: Fri, 2 Dec 2016 00:00:51 +0100 Subject: [PATCH] Performance improvements --- .../truffle/r/library/stats/RandGenerationFunctions.java | 9 ++++++--- .../com/oracle/truffle/r/runtime/rng/RNGInitAdapter.java | 6 +++--- .../oracle/truffle/r/runtime/rng/mt/MersenneTwister.java | 4 +--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RandGenerationFunctions.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RandGenerationFunctions.java index 32d44ac1c9..b3548e5ea3 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RandGenerationFunctions.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RandGenerationFunctions.java @@ -101,15 +101,16 @@ public final class RandGenerationFunctions { final BranchProfile nan = BranchProfile.create(); final VectorLengthProfile resultVectorLengthProfile = VectorLengthProfile.create(); final LoopConditionProfile loopConditionProfile = LoopConditionProfile.createCountingProfile(); - final ValueProfile randClassProfile = ValueProfile.createClassProfile(); - final ValueProfile normKindProfile = ValueProfile.createEqualityProfile(); + private final ValueProfile randClassProfile = ValueProfile.createClassProfile(); + private final ValueProfile generatorProfile = ValueProfile.createIdentityProfile(); + private final ValueProfile normKindProfile = ValueProfile.createEqualityProfile(); public static RandGenerationProfiles create() { return new RandGenerationProfiles(); } public RandomNumberProvider createRandProvider() { - return new RandomNumberProvider(randClassProfile.profile(RRNG.currentGenerator()), normKindProfile.profile(RRNG.currentNormKind())); + return new RandomNumberProvider(randClassProfile.profile(generatorProfile.profile(RRNG.currentGenerator())), normKindProfile.profile(RRNG.currentNormKind())); } } @@ -133,6 +134,7 @@ public final class RandGenerationFunctions { int[] result = new int[length]; RRNG.getRNGState(); RandomNumberProvider rand = profiles.createRandProvider(); + profiles.loopConditionProfile.profileCounted(length); for (int i = 0; profiles.loopConditionProfile.inject(i < length); i++) { double aValue = a.getDataAt(i % aLength); double bValue = b.getDataAt(i % bLength); @@ -172,6 +174,7 @@ public final class RandGenerationFunctions { result = new double[length]; RRNG.getRNGState(); RandomNumberProvider rand = profiles.createRandProvider(); + profiles.loopConditionProfile.profileCounted(length); for (int i = 0; profiles.loopConditionProfile.inject(i < length); i++) { double aValue = a.getDataAt(i % aLength); double bValue = b.getDataAt(i % bLength); diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/rng/RNGInitAdapter.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/rng/RNGInitAdapter.java index a7f110a81d..ca4a665de1 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/rng/RNGInitAdapter.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/rng/RNGInitAdapter.java @@ -29,15 +29,15 @@ public abstract class RNGInitAdapter implements RandomNumberGenerator { } @Override - public int[] getSeeds() { + public final int[] getSeeds() { return iSeed; } - protected int getISeedItem(int index) { + protected final int getISeedItem(int index) { return iSeed[index + 1]; } - protected void setISeedItem(int index, int value) { + protected final void setISeedItem(int index, int value) { iSeed[index + 1] = value; } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/rng/mt/MersenneTwister.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/rng/mt/MersenneTwister.java index d9472bda68..1bccf6eb4b 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/rng/mt/MersenneTwister.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/rng/mt/MersenneTwister.java @@ -64,7 +64,6 @@ package com.oracle.truffle.r.runtime.rng.mt; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.rng.RNGInitAdapter; import com.oracle.truffle.r.runtime.rng.RRNG; import com.oracle.truffle.r.runtime.rng.RRNG.Kind; @@ -159,8 +158,7 @@ public final class MersenneTwister extends RNGInitAdapter { int localMti = localDummy0; // It appears that this never happens // sgenrand(4357); - RInternalError.guarantee(localMti != N + 1); - + assert localMti != N + 1; int pos = 0; while (true) { int loopCount = Math.min(BUFFER_SIZE - pos, N - localMti); -- GitLab