From 00ab4df39bfae90a8f3f197a637b5546265eb5a4 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 28 Nov 2023 23:08:04 -0600 Subject: [PATCH] Implement integer math JIT for IR --- .../ir/instructions/IntegerMathInstr.java | 6 ++++- .../java/org/jruby/ir/targets/JVMVisitor.java | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/jruby/ir/instructions/IntegerMathInstr.java b/core/src/main/java/org/jruby/ir/instructions/IntegerMathInstr.java index d80625a4e85e..a2be073aa255 100644 --- a/core/src/main/java/org/jruby/ir/instructions/IntegerMathInstr.java +++ b/core/src/main/java/org/jruby/ir/instructions/IntegerMathInstr.java @@ -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; + } } diff --git a/core/src/main/java/org/jruby/ir/targets/JVMVisitor.java b/core/src/main/java/org/jruby/ir/targets/JVMVisitor.java index 4121a8233d12..9985a40bc49f 100644 --- a/core/src/main/java/org/jruby/ir/targets/JVMVisitor.java +++ b/core/src/main/java/org/jruby/ir/targets/JVMVisitor.java @@ -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()));