Repository navigation
Fix edge case rounding issue with FMA instructions - #64
Open
bobjrsenior wants to merge 1 commit into
Open
bobjrsenior wants to merge 1 commit into
bobjrsenior wants to merge 1 commit into
Conversation
In get_node_child of Instance.cl, there is a multiply then add that can be combined into an FMA. That can cause rare issues due to differing rounding, Balatro does mult->round->add0>round. With FMA, it becomes mult->add->round instead. FMA is one less rounding operation than Balatro does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There are a few seeds Immolate can output which don't actually match the game.
One example is for seed 124Q
It thinks the run survives 4 skips but Bull doesn't appear so it should be 0.
Insance.cl has the get_node_child function with
Mirrors Balatro's Lua from misc_functions.lua:
Balatro's math rounds
G.GAME.pseudorandom[key]*1.72431234to a double. It then adds 2.134453429141 and rounds it to 13 digits. For OpenCL, the GPU may use an FMA (Fused Multiple Add) instead of two separate operations which causes the value to only be rounded once instead of twice. In rare cases, the rounding difference can change the last digit of the value.The FMA can be prevented by adding this pragma at the top of lib/Immolate.cl
With the change, Immolate sees that Bull doesn't exist and returns 0.
Another example is 2X3T. Once again, Bull doesn't exist but Immolate thought it did.
Pre-Fix:
Post Fix:
It can go the other way too but it's easier to verify examples where Immolate thought the Bull exists when it doesn't.
Note: I had the help of AI in figuring this out though I manually verified the seeds in game to see that it matches Immolate after adding the pragma. I also wrote the PR text myself.