Skip to content

Commit

Permalink
Implement integer math JIT for IR
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Nov 29, 2023
1 parent 03f2559 commit 00ab4df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco
case DIVIDE:
return value1 / value2;
default:
throw new RuntimeException("BIntInstr has unknown op");
throw new RuntimeException("IntegerMathInstr has unknown op");
}
}

public Op getOp() {
return op;
}
}
22 changes: 22 additions & 0 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,28 @@ private void superCommon(String name, CallInstr instr, Operand[] args, Operand d
jvmStoreLocal(instr.getResult());
}

@Override
public void IntegerMathInstr(IntegerMathInstr instr) {
visit(instr.getOperand1());
visit(instr.getOperand2());
switch (instr.getOp()) {
case ADD:
jvmAdapter().iadd();
break;
case SUBTRACT:
jvmAdapter().isub();
break;
case MULTIPLY:
jvmAdapter().imul();
break;
case DIVIDE:
jvmAdapter().idiv();
default:
throw new NotCompilableException("IntegerMathInstr has unknown op: " + instr);
}
jvmStoreLocal(instr.getResult());
}

@Override
public void JumpInstr(JumpInstr jumpinstr) {
jvmMethod().goTo(getJVMLabel(jumpinstr.getJumpTarget()));
Expand Down

0 comments on commit 00ab4df

Please sign in to comment.