-
-
Notifications
You must be signed in to change notification settings - Fork 93
Remove redundant comparator inputs #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
I think the correct implementation of this optimization would be to fuse both inputs together into one far input. There are situations where a comparator gets both inputs from a single one where it outputs something that is different. Example: C R C = Comparator on subtract mode The comparator will actually output 15 - 13 = 2 when the lever is pressed, but if I understand your implementation correctly the comparator would output 15. Though I don't know how viable removing/replacing comparator input links is, because this could disrupt some sub-tick timings MCHPRS does simulate, but ultimately I don't know the codebase enough to be certain. |
|
Looks like I didn't think things through. A comparator on subtract mode does subtraction and not just comparison 🤦. Fusing the inputs into 15 - 13 = 2 doesn't work if the comparator has other inputs, so in case of subtract mode, we'll also need to check if the links we're fusing are the only links. I'm putting the PR back to draft until I can fix it after work. |
|
Have you considered how far-inputs might effect this? |
I think currently the order with which each output link is evaluated is not accurate to vanilla at all anyway since we do not take into account locationallity fully and the direct backend also reorders output links to improve performance, not to mention some passes also remove entire nodes which would cause similar issues. |
|
I also compared this with my implementation, this PR seems to remove the same amount of edges, but this does it seem slightly slower (9.6..9.9ms vs 5..5.6ms). |
|
It looks like our implementations optimize the same cases. The only difference I can spot is that you don't handle duplicate edges, i.e. multiple edges from the same node to the same comparator input side, but that shouldn't matter as long as the new pass runs after the edge dedup pass. It also wasn't my goal to maximize the performance of the optimization pass. The performance just has to be "good enough". |
|
On another topic, ideally, #216 gets merged before this PR so I can add tests for the new optimization pass. |

Whenever a node has links to both the default input and the side input of a comparator, one of those links is often completely irrelevant because it gets cancelled out by the other. This PR adds a new optimization pass to remove those redundant links.
IRIS Mandelbrot benchmark: