Skip to content

Commit

Permalink
refactor: introduce callDelegateSingleFromMulti
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Nov 19, 2024
1 parent 4f2c87d commit a490047
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit a490047

Please sign in to comment.