Skip to content

Improve radix_invmod_bn and add more profile programs#2584

Merged
fredrik-johansson merged 1 commit intoflintlib:mainfrom
fredrik-johansson:radix3
Feb 23, 2026
Merged

Improve radix_invmod_bn and add more profile programs#2584
fredrik-johansson merged 1 commit intoflintlib:mainfrom
fredrik-johansson:radix3

Conversation

@fredrik-johansson
Copy link
Collaborator

Newton iteration for $r = 1/x$ mod $B^n$ is updated to use the evaluation formula $r (rx)$ with middle product instead of the naive $r x^2$. Timings for inverse mod $(7^{22})^N$ vs old timings from #2561:

       N       old       new  speedup
       1  3.09e-08  3.02e-08  1.02x
       2  5.19e-08   5.1e-08  1.02x
       4  1.12e-07  1.03e-07  1.09x
       8  2.36e-07  2.07e-07  1.14x
      16  5.75e-07  3.71e-07  1.55x
      32  1.56e-06  9.84e-07  1.59x
      64  4.26e-06  2.55e-06  1.67x
     128  1.28e-05  7.55e-06  1.70x
     256  2.84e-05  2.21e-05  1.29x
     512  5.97e-05  4.59e-05  1.30x
    1024  0.000125  9.65e-05  1.30x
    2048  0.000266  0.000201  1.32x
    4096  0.000561  0.000423  1.33x
    8192   0.00117  0.000901  1.30x
   16384   0.00246   0.00187  1.32x
   32768   0.00508   0.00392  1.30x
   65536    0.0104   0.00817  1.27x
  131072    0.0221    0.0172  1.28x
  262144    0.0469    0.0371  1.26x
  524288     0.102    0.0823  1.24x
 1048576     0.223     0.193  1.16x
 2097152      0.48     0.422  1.14x
 4194304      1.06     0.917  1.16x
 8388608      2.22      1.92  1.16x

This PR also adds profile programs for add, sub mulmod_bn, invmod_bn.

@fredrik-johansson fredrik-johansson merged commit 846b916 into flintlib:main Feb 23, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant