diff --git a/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/binary/MaxShortNode.java b/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/binary/MaxShortNode.java index 0556d45a..4d672a58 100644 --- a/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/binary/MaxShortNode.java +++ b/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/binary/MaxShortNode.java @@ -84,20 +84,7 @@ public void doBytecodeGenMulti(BytecodeGen.Context context, InstructionAdapter m m.goTo(end); m.visitLabel(minLabel); - - m.load(0, InstructionAdapter.OBJECT_TYPE); - m.load(2, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(3, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(4, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(5, InstructionAdapter.OBJECT_TYPE); - m.invokevirtual(context.className, rightMethodSingle, BytecodeGen.Context.SINGLE_DESC, false); - + context.callDelegateSingleFromMulti(m, rightMethodSingle, idx); m.invokestatic( Type.getInternalName(Math.class), "max", diff --git a/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/binary/MinShortNode.java b/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/binary/MinShortNode.java index 50729215..44fd85e8 100644 --- a/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/binary/MinShortNode.java +++ b/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/binary/MinShortNode.java @@ -84,18 +84,7 @@ public void doBytecodeGenMulti(BytecodeGen.Context context, InstructionAdapter m m.goTo(end); m.visitLabel(minLabel); - m.load(0, InstructionAdapter.OBJECT_TYPE); - m.load(2, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(3, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(4, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(5, InstructionAdapter.OBJECT_TYPE); - m.invokevirtual(context.className, rightMethodSingle, BytecodeGen.Context.SINGLE_DESC, false); + context.callDelegateSingleFromMulti(m, rightMethodSingle, idx); m.invokestatic( Type.getInternalName(Math.class), "min", diff --git a/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/binary/MulNode.java b/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/binary/MulNode.java index e6259e79..0c3acba2 100644 --- a/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/binary/MulNode.java +++ b/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/binary/MulNode.java @@ -79,18 +79,7 @@ public void doBytecodeGenMulti(BytecodeGen.Context context, InstructionAdapter m m.goTo(end); m.visitLabel(minLabel); - m.load(0, InstructionAdapter.OBJECT_TYPE); - m.load(2, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(3, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(4, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(5, InstructionAdapter.OBJECT_TYPE); - m.invokevirtual(context.className, rightMethodSingle, BytecodeGen.Context.SINGLE_DESC, false); + context.callDelegateSingleFromMulti(m, rightMethodSingle, idx); m.mul(Type.DOUBLE_TYPE); m.visitLabel(end); diff --git a/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/misc/RangeChoiceNode.java b/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/misc/RangeChoiceNode.java index c584d0ef..4cac0a3b 100644 --- a/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/misc/RangeChoiceNode.java +++ b/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/misc/RangeChoiceNode.java @@ -278,18 +278,7 @@ public void doBytecodeGenMulti(BytecodeGen.Context context, InstructionAdapter m m.load(idx, Type.INT_TYPE); m.aload(Type.DOUBLE_TYPE); } else { - m.load(0, InstructionAdapter.OBJECT_TYPE); - m.load(2, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(3, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(4, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(5, InstructionAdapter.OBJECT_TYPE); - m.invokevirtual(context.className, whenInRangeSingle, BytecodeGen.Context.SINGLE_DESC, false); + context.callDelegateSingleFromMulti(m, whenInRangeSingle, idx); } m.goTo(end); @@ -299,18 +288,7 @@ public void doBytecodeGenMulti(BytecodeGen.Context context, InstructionAdapter m m.load(idx, Type.INT_TYPE); m.aload(Type.DOUBLE_TYPE); } else { - m.load(0, InstructionAdapter.OBJECT_TYPE); - m.load(2, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(3, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(4, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(5, InstructionAdapter.OBJECT_TYPE); - m.invokevirtual(context.className, whenOutOfRangeSingle, BytecodeGen.Context.SINGLE_DESC, false); + context.callDelegateSingleFromMulti(m, whenOutOfRangeSingle, idx); } m.visitLabel(end); diff --git a/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/spline/SplineAstNode.java b/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/spline/SplineAstNode.java index d3ed9c2c..417997ac 100644 --- a/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/spline/SplineAstNode.java +++ b/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/spline/SplineAstNode.java @@ -416,7 +416,7 @@ private record ValuesMethodDef(boolean isConst, String generatedMethod, float co @Override public void doBytecodeGenMulti(BytecodeGen.Context context, InstructionAdapter m, BytecodeGen.Context.LocalVarConsumer localVarConsumer) { - context.delegateToSingle(m, localVarConsumer, this); + context.delegateAllToSingle(m, localVarConsumer, this); m.areturn(Type.VOID_TYPE); } diff --git a/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/gen/BytecodeGen.java b/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/gen/BytecodeGen.java index daa1f01a..423bffc8 100644 --- a/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/gen/BytecodeGen.java +++ b/c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/gen/BytecodeGen.java @@ -5,7 +5,6 @@ import com.ishland.c2me.opts.dfc.common.ast.McToAst; import com.ishland.c2me.opts.dfc.common.ast.dfvisitor.StripBlending; import com.ishland.c2me.opts.dfc.common.ast.misc.ConstantNode; -import com.ishland.c2me.opts.dfc.common.ast.misc.DelegateNode; import com.ishland.c2me.opts.dfc.common.ast.misc.RootNode; import com.ishland.c2me.opts.dfc.common.ast.misc.YClampedGradientNode; import com.ishland.c2me.opts.dfc.common.ast.noise.DFTNoiseNode; @@ -467,6 +466,27 @@ public void callDelegateSingle(InstructionAdapter m, String target) { m.invokevirtual(this.className, target, SINGLE_DESC, false); } + public void callDelegateSingleFromMulti(InstructionAdapter m, String target, int indexLocal) { + m.load(0, InstructionAdapter.OBJECT_TYPE); + m.load(2, InstructionAdapter.OBJECT_TYPE); + m.load(indexLocal, Type.INT_TYPE); + m.aload(Type.INT_TYPE); + m.load(3, InstructionAdapter.OBJECT_TYPE); + m.load(indexLocal, Type.INT_TYPE); + m.aload(Type.INT_TYPE); + m.load(4, InstructionAdapter.OBJECT_TYPE); + m.load(indexLocal, Type.INT_TYPE); + m.aload(Type.INT_TYPE); + m.load(5, InstructionAdapter.OBJECT_TYPE); + + m.invokevirtual( + this.className, + target, + BytecodeGen.Context.SINGLE_DESC, + false + ); + } + public void callDelegateMulti(InstructionAdapter m, String target) { m.load(0, InstructionAdapter.OBJECT_TYPE); m.load(1, InstructionAdapter.OBJECT_TYPE); @@ -515,32 +535,13 @@ public void doCountedLoop(InstructionAdapter m, LocalVarConsumer localVarConsume m.visitLabel(end); } - public void delegateToSingle(InstructionAdapter m, BytecodeGen.Context.LocalVarConsumer localVarConsumer, AstNode current) { + public void delegateAllToSingle(InstructionAdapter m, BytecodeGen.Context.LocalVarConsumer localVarConsumer, AstNode current) { String singleMethod = this.newSingleMethod(current); this.doCountedLoop(m, localVarConsumer, idx -> { m.load(1, InstructionAdapter.OBJECT_TYPE); m.load(idx, Type.INT_TYPE); - { - m.load(0, InstructionAdapter.OBJECT_TYPE); - m.load(2, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(3, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(4, InstructionAdapter.OBJECT_TYPE); - m.load(idx, Type.INT_TYPE); - m.aload(Type.INT_TYPE); - m.load(5, InstructionAdapter.OBJECT_TYPE); - - m.invokevirtual( - this.className, - singleMethod, - BytecodeGen.Context.SINGLE_DESC, - false - ); - } + this.callDelegateSingleFromMulti(m, singleMethod, idx); m.astore(Type.DOUBLE_TYPE); });