Skip to content

Fix #10513 - powmod is slow for ulong #10688

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

Merged
merged 30 commits into from
Mar 27, 2025
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b889996
The current implementation of powmod is very slow for the ulong type …
Aditya-132 Mar 18, 2025
f860160
some imports changes
Aditya-132 Mar 18, 2025
7fc002d
made asm functions for mulmod and
Aditya-132 Mar 18, 2025
43c35de
changes made for x86 32 bits system
Aditya-132 Mar 18, 2025
394af25
Merge branch 'dlang:master' into issue-#10513
Aditya-132 Mar 19, 2025
e1cb9a9
implmented the given changes
Aditya-132 Mar 20, 2025
d58ac9d
fixing styleing
Aditya-132 Mar 20, 2025
dafec4d
Implmented changes in review
Aditya-132 Mar 20, 2025
c036af6
Merge branch 'dlang:master' into issue-#10513
Aditya-132 Mar 21, 2025
7ca9b77
revied changes
Aditya-132 Mar 21, 2025
ef53e0c
changes in function title
Aditya-132 Mar 21, 2025
fb04cca
some minute changes
Aditya-132 Mar 21, 2025
776880c
testing on why it failed on Alpine x64 system
Aditya-132 Mar 21, 2025
1411386
styling changes
Aditya-132 Mar 21, 2025
6abb199
updated reviewed suggestion
Aditya-132 Mar 22, 2025
3a02c67
changes made as per reviewd suggestions
Aditya-132 Mar 22, 2025
5f11dbd
removing low variable
Aditya-132 Mar 22, 2025
2e67c29
removed extra conditions
Aditya-132 Mar 23, 2025
23dffa7
Merge branch 'dlang:master' into issue-#10513
Aditya-132 Mar 24, 2025
933d72f
added method with core.int128
Aditya-132 Mar 24, 2025
2bf559a
removed line 61 to 65
Aditya-132 Mar 24, 2025
ef8a738
styling changees
Aditya-132 Mar 24, 2025
dfcfb4c
styling changes
Aditya-132 Mar 25, 2025
8f643bb
changes udivmod implementaion
Aditya-132 Mar 25, 2025
71a1e9f
removed Cent from mul operation
Aditya-132 Mar 26, 2025
4f79940
changed to Cent(lo: c)
Aditya-132 Mar 26, 2025
6e7531c
changes as per review
Aditya-132 Mar 26, 2025
c8a2400
indentation changes
Aditya-132 Mar 27, 2025
6d6fad6
indentation changes
Aditya-132 Mar 27, 2025
bced460
Merge branch 'dlang:master' into issue-#10513
Aditya-132 Mar 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions std/math/exponential.d
Original file line number Diff line number Diff line change
Expand Up @@ -830,28 +830,39 @@ if (isUnsigned!F && isUnsigned!G && isUnsigned!H)
{
static if (T.sizeof == 8)
{
static T addmod(T a, T b, T c)
if (c <= 0x100000000)
{
b = c - b;
if (a >= b)
return a - b;
else
return c - b + a;
T result = a * b;
return result % c;
}
else
{
import core.int128 : Cent, mul, udivmod;

T result = 0, tmp;
auto product = mul(a, b);

b %= c;
while (a > 0)
{
if (a & 1)
result = addmod(result, b, c);
if (product.hi >= c)
{
product.hi %= c;
}

a >>= 1;
b = addmod(b, b, c);
T remainder = void;
udivmod(product, c, remainder);
return remainder;
}
}
else static if (T.sizeof == 4)
{
if (c <= 0x10000)
{
T result = a * b;
return result % c;
}
else
{
DoubleT result = cast(DoubleT) (cast(DoubleT) a * cast(DoubleT) b);
return result % c;
}

return result;
}
else
{
Expand Down
Loading