Skip to content

Commit efb3952

Browse files
committed
[GR-17457] Reduce the number of calls to create a Complex
PullRequest: truffleruby/2858
2 parents c711cd6 + 5ed935a commit efb3952

18 files changed

+227
-42
lines changed

src/main/java/org/truffleruby/core/inlined/CoreMethodAssumptions.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ public class CoreMethodAssumptions {
7373
final Assumption integerBitOrAssumption;
7474
final Assumption integerBitAndAssumption;
7575

76-
final Assumption integerEqualAssumption;
7776
final Assumption integerCaseEqualAssumption;
78-
final Assumption integerLessThanAssumption, integerLessOrEqualAssumption;
79-
final Assumption integerGreaterThanAssumption, integerGreaterOrEqualAssumption;
77+
final Assumption integerEqualAssumption, floatEqualAssumption;
78+
final Assumption integerLessThanAssumption, floatLessThanAssumption;
79+
final Assumption integerLessOrEqualAssumption, floatLessOrEqualAssumption;
80+
final Assumption integerGreaterThanAssumption, floatGreaterThanAssumption;
81+
final Assumption integerGreaterOrEqualAssumption, floatGreaterOrEqualAssumption;
8082

8183
final Assumption nilClassIsNilAssumption;
8284

@@ -114,12 +116,18 @@ public CoreMethodAssumptions(RubyLanguage language) {
114116
integerBitOrAssumption = registerAssumption((cl) -> cl.integerClass, "Integer", "|");
115117
integerBitAndAssumption = registerAssumption((cl) -> cl.integerClass, "Integer", "&");
116118

117-
integerEqualAssumption = registerAssumption((cl) -> cl.integerClass, "Integer", "==");
118119
integerCaseEqualAssumption = registerAssumption((cl) -> cl.integerClass, "Integer", "===");
120+
121+
integerEqualAssumption = registerAssumption((cl) -> cl.integerClass, "Integer", "==");
122+
floatEqualAssumption = registerAssumption((cl) -> cl.floatClass, "Float", "==");
119123
integerLessThanAssumption = registerAssumption((cl) -> cl.integerClass, "Integer", "<");
124+
floatLessThanAssumption = registerAssumption((cl) -> cl.floatClass, "Float", "<");
120125
integerLessOrEqualAssumption = registerAssumption((cl) -> cl.integerClass, "Integer", "<=");
126+
floatLessOrEqualAssumption = registerAssumption((cl) -> cl.floatClass, "Float", "<=");
121127
integerGreaterThanAssumption = registerAssumption((cl) -> cl.integerClass, "Integer", ">");
128+
floatGreaterThanAssumption = registerAssumption((cl) -> cl.floatClass, "Float", ">");
122129
integerGreaterOrEqualAssumption = registerAssumption((cl) -> cl.integerClass, "Integer", ">=");
130+
floatGreaterOrEqualAssumption = registerAssumption((cl) -> cl.floatClass, "Float", ">=");
123131

124132
nilClassIsNilAssumption = registerAssumption((cl) -> cl.nilClass, "Nil", "nil?");
125133

src/main/java/org/truffleruby/core/inlined/InlinedAddNode.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ protected double floatAdd(double a, double b) {
4545
return a + b;
4646
}
4747

48+
@Specialization(assumptions = "assumptions")
49+
protected double longDouble(long a, double b) {
50+
return a + b;
51+
}
52+
53+
@Specialization(assumptions = "assumptions")
54+
protected double doubleLong(double a, long b) {
55+
return a + b;
56+
}
57+
4858
@Specialization
4959
protected Object fallback(VirtualFrame frame, Object a, Object b) {
5060
return rewriteAndCall(frame, a, b);

src/main/java/org/truffleruby/core/inlined/InlinedDivNode.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ protected double floatDiv(double a, double b) {
4343
return a / b;
4444
}
4545

46+
@Specialization(assumptions = "assumptions")
47+
protected double longDouble(long a, double b) {
48+
return a / b;
49+
}
50+
51+
@Specialization(assumptions = "assumptions")
52+
protected double doubleLong(double a, long b) {
53+
return a / b;
54+
}
55+
4656
@Specialization
4757
protected Object fallback(VirtualFrame frame, Object a, Object b) {
4858
return rewriteAndCall(frame, a, b);

src/main/java/org/truffleruby/core/inlined/InlinedEqualNode.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ public abstract class InlinedEqualNode extends BinaryInlinedOperationNode {
2626
protected static final String METHOD = "==";
2727

2828
final Assumption integerEqualAssumption;
29+
final Assumption floatEqualAssumption;
2930

3031
public InlinedEqualNode(RubyLanguage language, RubyCallNodeParameters callNodeParameters) {
3132
super(language, callNodeParameters);
3233
this.integerEqualAssumption = language.coreMethodAssumptions.integerEqualAssumption;
34+
this.floatEqualAssumption = language.coreMethodAssumptions.floatEqualAssumption;
3335
}
3436

3537
@Specialization(assumptions = { "assumptions", "integerEqualAssumption" })
@@ -42,6 +44,21 @@ protected boolean longEqual(long a, long b) {
4244
return a == b;
4345
}
4446

47+
@Specialization(assumptions = { "assumptions", "floatEqualAssumption" })
48+
protected boolean doDouble(double a, double b) {
49+
return a == b;
50+
}
51+
52+
@Specialization(assumptions = { "assumptions", "integerEqualAssumption" })
53+
protected boolean longDouble(long a, double b) {
54+
return a == b;
55+
}
56+
57+
@Specialization(assumptions = { "assumptions", "floatEqualAssumption" })
58+
protected boolean doubleLong(double a, long b) {
59+
return a == b;
60+
}
61+
4562
@Specialization(
4663
guards = {
4764
"stringsSelf.isRubyString(self)",

src/main/java/org/truffleruby/core/inlined/InlinedGreaterOrEqualNode.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public InlinedGreaterOrEqualNode(RubyLanguage language, RubyCallNodeParameters c
2121
super(
2222
language,
2323
callNodeParameters,
24-
language.coreMethodAssumptions.integerGreaterOrEqualAssumption);
24+
language.coreMethodAssumptions.integerGreaterOrEqualAssumption,
25+
language.coreMethodAssumptions.floatGreaterOrEqualAssumption);
2526
}
2627

2728
@Specialization(assumptions = "assumptions")
@@ -34,6 +35,21 @@ protected boolean doLong(long a, long b) {
3435
return a >= b;
3536
}
3637

38+
@Specialization(assumptions = "assumptions")
39+
protected boolean doDouble(double a, double b) {
40+
return a >= b;
41+
}
42+
43+
@Specialization(assumptions = "assumptions")
44+
protected boolean longDouble(long a, double b) {
45+
return a >= b;
46+
}
47+
48+
@Specialization(assumptions = "assumptions")
49+
protected boolean doubleLong(double a, long b) {
50+
return a >= b;
51+
}
52+
3753
@Specialization
3854
protected Object fallback(VirtualFrame frame, Object a, Object b) {
3955
return rewriteAndCall(frame, a, b);

src/main/java/org/truffleruby/core/inlined/InlinedGreaterThanNode.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public InlinedGreaterThanNode(RubyLanguage language, RubyCallNodeParameters call
2121
super(
2222
language,
2323
callNodeParameters,
24-
language.coreMethodAssumptions.integerGreaterThanAssumption);
24+
language.coreMethodAssumptions.integerGreaterThanAssumption,
25+
language.coreMethodAssumptions.floatGreaterThanAssumption);
2526
}
2627

2728
@Specialization(assumptions = "assumptions")
@@ -34,6 +35,21 @@ protected boolean doLong(long a, long b) {
3435
return a > b;
3536
}
3637

38+
@Specialization(assumptions = "assumptions")
39+
protected boolean doDouble(double a, double b) {
40+
return a > b;
41+
}
42+
43+
@Specialization(assumptions = "assumptions")
44+
protected boolean longDouble(long a, double b) {
45+
return a > b;
46+
}
47+
48+
@Specialization(assumptions = "assumptions")
49+
protected boolean doubleLong(double a, long b) {
50+
return a > b;
51+
}
52+
3753
@Specialization
3854
protected Object fallback(VirtualFrame frame, Object a, Object b) {
3955
return rewriteAndCall(frame, a, b);

src/main/java/org/truffleruby/core/inlined/InlinedLessOrEqualNode.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public InlinedLessOrEqualNode(RubyLanguage language, RubyCallNodeParameters call
2121
super(
2222
language,
2323
callNodeParameters,
24-
language.coreMethodAssumptions.integerLessOrEqualAssumption);
24+
language.coreMethodAssumptions.integerLessOrEqualAssumption,
25+
language.coreMethodAssumptions.floatLessOrEqualAssumption);
2526
}
2627

2728
@Specialization(assumptions = "assumptions")
@@ -34,6 +35,21 @@ protected boolean doLong(long a, long b) {
3435
return a <= b;
3536
}
3637

38+
@Specialization(assumptions = "assumptions")
39+
protected boolean doDouble(double a, double b) {
40+
return a <= b;
41+
}
42+
43+
@Specialization(assumptions = "assumptions")
44+
protected boolean longDouble(long a, double b) {
45+
return a <= b;
46+
}
47+
48+
@Specialization(assumptions = "assumptions")
49+
protected boolean doubleLong(double a, long b) {
50+
return a <= b;
51+
}
52+
3753
@Specialization
3854
protected Object fallback(VirtualFrame frame, Object a, Object b) {
3955
return rewriteAndCall(frame, a, b);

src/main/java/org/truffleruby/core/inlined/InlinedLessThanNode.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public InlinedLessThanNode(RubyLanguage language, RubyCallNodeParameters callNod
2121
super(
2222
language,
2323
callNodeParameters,
24-
language.coreMethodAssumptions.integerLessThanAssumption);
24+
language.coreMethodAssumptions.integerLessThanAssumption,
25+
language.coreMethodAssumptions.floatLessThanAssumption);
2526
}
2627

2728
@Specialization(assumptions = "assumptions")
@@ -34,6 +35,21 @@ protected boolean doLong(long a, long b) {
3435
return a < b;
3536
}
3637

38+
@Specialization(assumptions = "assumptions")
39+
protected boolean doDouble(double a, double b) {
40+
return a < b;
41+
}
42+
43+
@Specialization(assumptions = "assumptions")
44+
protected boolean longDouble(long a, double b) {
45+
return a < b;
46+
}
47+
48+
@Specialization(assumptions = "assumptions")
49+
protected boolean doubleLong(double a, long b) {
50+
return a < b;
51+
}
52+
3753
@Specialization
3854
protected Object fallback(VirtualFrame frame, Object a, Object b) {
3955
return rewriteAndCall(frame, a, b);

src/main/java/org/truffleruby/core/inlined/InlinedMulNode.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ protected double floatMul(double a, double b) {
4545
return a * b;
4646
}
4747

48+
@Specialization(assumptions = "assumptions")
49+
protected double longDouble(long a, double b) {
50+
return a * b;
51+
}
52+
53+
@Specialization(assumptions = "assumptions")
54+
protected double doubleLong(double a, long b) {
55+
return a * b;
56+
}
57+
4858
@Specialization
4959
protected Object fallback(VirtualFrame frame, Object a, Object b) {
5060
return rewriteAndCall(frame, a, b);

src/main/java/org/truffleruby/core/inlined/InlinedOperationNode.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
package org.truffleruby.core.inlined;
1111

1212
import com.oracle.truffle.api.Assumption;
13+
import com.oracle.truffle.api.CompilerDirectives;
1314
import com.oracle.truffle.api.frame.VirtualFrame;
1415

1516
import org.truffleruby.RubyLanguage;
17+
import org.truffleruby.core.array.ArrayUtils;
1618
import org.truffleruby.language.dispatch.RubyCallNodeParameters;
19+
import org.truffleruby.language.methods.TranslateExceptionNode;
1720

1821
public abstract class InlinedOperationNode extends InlinedReplaceableNode {
1922

@@ -30,6 +33,12 @@ protected Object rewriteAndCall(VirtualFrame frame, Object receiver, Object... a
3033

3134
protected Object rewriteAndCallWithBlock(VirtualFrame frame, Object receiver, Object block,
3235
Object... arguments) {
36+
CompilerDirectives.transferToInterpreterAndInvalidate();
37+
if (getContext().getOptions().BASICOPS_LOG_REWRITE) {
38+
RubyLanguage.LOGGER.info(
39+
"Rewrite " + this + " with arguments" + TranslateExceptionNode
40+
.argumentsToString(new StringBuilder(), ArrayUtils.unshift(arguments, receiver)));
41+
}
3342
return rewriteToCallNode().executeWithArgumentsEvaluated(frame, receiver, block, arguments);
3443
}
3544

0 commit comments

Comments
 (0)