-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Random failures in System.Numerics.Tests.modpowTest.ModPowAxiom test #70330
Comments
Tagging subscribers to this area: @dotnet/area-system-numerics Issue DetailsDescriptionWhen running System.Runtime.Numerics tests in a loop on wasm, like this: Sometimes there are failures:
The failure is not wasm specific however, happens with a console app as well.
In master/net7 preview 4, this prints:
while with net6, it prints:
So this looks like a regression which is triggered by the specific set of inputs in the test case. Reproduction StepsExpected behaviorActual behaviorRegression?No response Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsDescriptionWhen running System.Runtime.Numerics tests in a loop on wasm, like this: Sometimes there are failures:
The failure is not wasm specific however, happens with a console app as well.
In master/net7 preview 4, this prints:
while with net6, it prints:
So this looks like a regression which is triggered by the specific set of inputs in the test case. Reproduction StepsExpected behaviorActual behaviorRegression?No response Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
Here's our plan on this issue:
|
I've been looking into this, here's an update. The short of it is a fix will not be ready for the RC1 snap. The long story is I'm trying to break down the algorithms to figure out what is causing the difference. I'm also trying to verify which output is correct, the original behavior or the new behavior. The Given this discrepancy, it's hard for me to tell which output is actually correct. Regardless, either way I think the behavior change is probably due to this PR #35565. I'm going to spend some time tomorrow diving into that. |
@dakersnar , I'll take a look. |
@dakersnar , you can assign it to me. Will try to fix this quick, just returned from vacation with absolutely clean brain 😄 |
Can do, let me know if you need any help with that. |
@sakno Also, I have a more reproducible failing unit test set up here if you would like to cherry pick this commit https://github.com/dakersnar/runtime/tree/fix-70330 |
This is a correct output
Checked in java (it doesn't accept negative modulos, yay) import java.math.*;
class HelloWorld {
public static void main(String[] args) {
var n1 = new BigInteger ("8418");
var n2 = new BigInteger ("113");
var n3 = new BigInteger ("12421714448554955886377993147779372741715160061029778448376437168219030709121226880650783927927868674313412837516053211174986358043602622119800674680911960141623475683349428209");
System.out.println(n1.modPow(n2, n3));
}
} So .NET 6 behavior is correct. Something wrong with |
The ModPow algorithm is very interesting. I don't exactly know how it works and where it came from. But here is the key difference between ModPow and Pow + Remainder. Pow + Remainder does each half to completion sequentially. The Pow algorithm is here, it's pretty simple: https://source.dot.net/#System.Runtime.Numerics/System/Numerics/BigIntegerCalculator.PowMod.cs,46 ModPow basically does the Mod during the Pow algorithm. You can see it calling Reduce after each step, which is basically a Mod operation. I can't tell if it's correct or not: https://source.dot.net/#System.Runtime.Numerics/System/Numerics/BigIntegerCalculator.PowMod.cs,441 |
I think there is something very peculiar about this specific input that is making this test fail. Stepping through the very last call to Divide, here is the state of |
@dakersnar , yes, I found the same. The problem when the result is copying from the temp buffer back to the final buffer which contains the garbage at the highest elements. I found already the source of this garbage. |
@dakersnar , @jeffhandley , PR is ready for review. |
Noting that I believe |
As far as I can tell ModPow is computing a remainder and behaving the same as Pow + Remainder for all cases. https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEUCuA7AHwAEAmABgFgAoUgRmqLIAIjaA6AORwFsYoBLMAGcA3NWoA3AIZQmeWkwC8TAEL8A5gEk8GGOr5sACjKEwAFACI4JWhYCUYqtNl4SS1Ru279UIyfMWtg6SMnIAzO5qWjp6BsZQppYo9o4hsrBCCspRXrG+ALIQACaGEADuZvJociTVeGHBTqEZbtmeMT5sAEow3FL8eEV8TGY5HXHllbTVZgMYdq52dQ2OrACcIxm0jeubMEIkDkA= |
Description
When running System.Runtime.Numerics tests in a loop on wasm, like this:
while true; do ./dotnet.sh build /t:Test /p:TargetOS=Browser /p:TargetArchitecture=wasm /p:Configuration=Release /p:EnableAggressiveTrimming=true /p:RunAOTCompilation=true /p:WasmNativeStrip=false src/libraries/System.Runtime.Numerics/tests/ || break; done
Sometimes there are failures:
The failure is not wasm specific however, happens with a console app as well.
In master/net7 preview 4, this prints:
while with net6, it prints:
So this looks like a regression which is triggered by the specific set of inputs in the test case.
Reproduction Steps
Expected behavior
Actual behavior
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: