Skip to content

Commit

Permalink
Showing 7 changed files with 102 additions and 3 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/ir/IRVisitor.java
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import org.jruby.ir.instructions.defined.GetErrorInfoInstr;
import org.jruby.ir.instructions.defined.RestoreErrorInfoInstr;
import org.jruby.ir.instructions.specialized.OneFixnumArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneFloatArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneOperandArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.ZeroOperandArgNoBlockCallInstr;
import org.jruby.ir.operands.*;
@@ -79,6 +80,7 @@ private void error(Object object) {
public void NopInstr(NopInstr nopinstr) { error(nopinstr); }
public void NoResultCallInstr(NoResultCallInstr noresultcallinstr) { error(noresultcallinstr); }
public void OneFixnumArgNoBlockCallInstr(OneFixnumArgNoBlockCallInstr oneFixnumArgNoBlockCallInstr) { error(oneFixnumArgNoBlockCallInstr); }
public void OneFloatArgNoBlockCallInstr(OneFloatArgNoBlockCallInstr oneFloatArgNoBlockCallInstr) { error(oneFloatArgNoBlockCallInstr); }
public void OneOperandArgNoBlockCallInstr(OneOperandArgNoBlockCallInstr oneOperandArgNoBlockCallInstr) { error(oneOperandArgNoBlockCallInstr); }
public void OptArgMultipleAsgnInstr(OptArgMultipleAsgnInstr optargmultipleasgninstr) { error(optargmultipleasgninstr); }
public void PopBindingInstr(PopBindingInstr popbindinginstr) { error(popbindinginstr); }
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ir/Operation.java
Original file line number Diff line number Diff line change
@@ -68,6 +68,7 @@ public enum Operation {

/* specialized calls */
CALL_1F(OpFlags.f_has_side_effect | OpFlags.f_is_call | OpFlags.f_can_raise_exception),
CALL_1D(OpFlags.f_has_side_effect | OpFlags.f_is_call | OpFlags.f_can_raise_exception),
CALL_1O(OpFlags.f_has_side_effect | OpFlags.f_is_call | OpFlags.f_can_raise_exception),
CALL_1OB(OpFlags.f_has_side_effect | OpFlags.f_is_call | OpFlags.f_can_raise_exception),
CALL_0O(OpFlags.f_has_side_effect | OpFlags.f_is_call | OpFlags.f_can_raise_exception),
9 changes: 9 additions & 0 deletions core/src/main/java/org/jruby/ir/instructions/CallBase.java
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import org.jruby.ir.IRScope;
import org.jruby.ir.Operation;
import org.jruby.ir.operands.*;
import org.jruby.ir.operands.Float;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
@@ -149,6 +150,14 @@ public boolean isAllFixnums() {
return true;
}

public boolean isAllFloats() {
for (Operand argument : arguments) {
if (!(argument instanceof Float)) return false;
}

return true;
}

@Override
public boolean computeScopeFlags(IRScope scope) {
boolean modifiedScope = false;
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/ir/instructions/CallInstr.java
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.specialized.OneFixnumArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneFloatArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneOperandArgBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneOperandArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.ZeroOperandArgNoBlockCallInstr;
@@ -62,6 +63,7 @@ public CallBase specializeForInterpretation() {
return hasClosure() ? this : new ZeroOperandArgNoBlockCallInstr(this);
case 1:
if (isAllFixnums() && !hasClosure()) return new OneFixnumArgNoBlockCallInstr(this);
if (isAllFloats() && !hasClosure()) return new OneFloatArgNoBlockCallInstr(this);

return hasClosure() ? new OneOperandArgBlockCallInstr(this) : new OneOperandArgNoBlockCallInstr(this);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.jruby.ir.instructions.specialized;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.CallInstr;
import org.jruby.ir.operands.Float;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class OneFloatArgNoBlockCallInstr extends CallInstr {
private final double flote;

public OneFloatArgNoBlockCallInstr(CallInstr call) {
super(Operation.CALL_1D, call);

assert getCallArgs().length == 1;

this.flote = ((Float) getCallArgs()[0]).value;
}

@Override
public String toString() {
return super.toString() + "{1F}";
}

public double getFloatArg() {
return flote;
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope dynamicScope, IRubyObject self, Object[] temp) {
IRubyObject object = (IRubyObject) receiver.retrieve(context, self, currScope, dynamicScope, temp);
return getCallSite().call(context, self, object, flote);
}

@Override
public void visit(IRVisitor visitor) {
visitor.OneFloatArgNoBlockCallInstr(this);
}
}
7 changes: 7 additions & 0 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Original file line number Diff line number Diff line change
@@ -273,6 +273,13 @@ private static void processCall(ThreadContext context, Instr instr, Operation op
setResult(temp, currDynScope, call.getResult(), result);
break;
}
case CALL_1D: {
OneFloatArgNoBlockCallInstr call = (OneFloatArgNoBlockCallInstr)instr;
IRubyObject r = (IRubyObject)retrieveOp(call.getReceiver(), context, self, currDynScope, currScope, temp);
result = call.getCallSite().call(context, self, r, call.getFloatArg());
setResult(temp, currDynScope, call.getResult(), result);
break;
}
case CALL_1O: {
OneOperandArgNoBlockCallInstr call = (OneOperandArgNoBlockCallInstr)instr;
IRubyObject r = (IRubyObject)retrieveOp(call.getReceiver(), context, self, currDynScope, currScope, temp);
42 changes: 39 additions & 3 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import org.jruby.ir.instructions.defined.GetErrorInfoInstr;
import org.jruby.ir.instructions.defined.RestoreErrorInfoInstr;
import org.jruby.ir.instructions.specialized.OneFixnumArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneFloatArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneOperandArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.ZeroOperandArgNoBlockCallInstr;
import org.jruby.ir.operands.*;
@@ -1295,9 +1296,6 @@ public void OneFixnumArgNoBlockCallInstr(OneFixnumArgNoBlockCallInstr oneFixnumA
String name = oneFixnumArgNoBlockCallInstr.getName();
long fixnum = oneFixnumArgNoBlockCallInstr.getFixnumArg();
Operand receiver = oneFixnumArgNoBlockCallInstr.getReceiver();
Operand closure = oneFixnumArgNoBlockCallInstr.getClosureArg(null);
boolean hasClosure = closure != null;
CallType callType = oneFixnumArgNoBlockCallInstr.getCallType();
Variable result = oneFixnumArgNoBlockCallInstr.getResult();

m.loadContext();
@@ -1326,6 +1324,44 @@ public void OneFixnumArgNoBlockCallInstr(OneFixnumArgNoBlockCallInstr oneFixnumA
}
}

@Override
public void OneFloatArgNoBlockCallInstr(OneFloatArgNoBlockCallInstr oneFloatArgNoBlockCallInstr) {
if (MethodIndex.getFastFloatOpsMethod(oneFloatArgNoBlockCallInstr.getName()) == null) {
CallInstr(oneFloatArgNoBlockCallInstr);
return;
}
IRBytecodeAdapter m = jvmMethod();
String name = oneFloatArgNoBlockCallInstr.getName();
double flote = oneFloatArgNoBlockCallInstr.getFloatArg();
Operand receiver = oneFloatArgNoBlockCallInstr.getReceiver();
Variable result = oneFloatArgNoBlockCallInstr.getResult();

m.loadContext();

// for visibility checking without requiring frame self
// TODO: don't bother passing when fcall or vcall, and adjust callsite appropriately
m.loadSelf(); // caller

visit(receiver);

String signature = sig(IRubyObject.class, params(ThreadContext.class, IRubyObject.class, IRubyObject.class));

m.adapter.invokedynamic(
"floatOperator:" + JavaNameMangler.mangleMethodName(name),
signature,
InvokeDynamicSupport.getFloatOperatorHandle(),
flote,
"",
0);

if (result != null) {
jvmStoreLocal(result);
} else {
// still need to drop, since all dyncalls return something (FIXME)
m.adapter.pop();
}
}

@Override
public void OneOperandArgNoBlockCallInstr(OneOperandArgNoBlockCallInstr oneOperandArgNoBlockCallInstr) {
CallInstr(oneOperandArgNoBlockCallInstr);

0 comments on commit 25fdaa3

Please sign in to comment.