diff options
author | Werner Koch <[email protected]> | 1997-11-27 11:44:13 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 1997-11-27 11:44:13 +0000 |
commit | 649eae8f1b689e90695bbf24b636ca941dfb9689 (patch) | |
tree | 60b137945a1dc6a64dd5846864229c33dc86cf49 /mpi/mpi-div.c | |
parent | How with some assembly support (diff) | |
download | gnupg-649eae8f1b689e90695bbf24b636ca941dfb9689.tar.gz gnupg-649eae8f1b689e90695bbf24b636ca941dfb9689.zip |
Improved prime number test
Diffstat (limited to 'mpi/mpi-div.c')
-rw-r--r-- | mpi/mpi-div.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/mpi/mpi-div.c b/mpi/mpi-div.c index 2b39cb4cf..527375748 100644 --- a/mpi/mpi-div.c +++ b/mpi/mpi-div.c @@ -278,6 +278,37 @@ mpi_tdiv_qr( MPI quot, MPI rem, MPI num, MPI den) mpi_free_limb_space(marker[--markidx]); } +void +mpi_tdiv_q_2exp( MPI w, MPI u, unsigned count ) +{ + mpi_size_t usize, wsize; + mpi_size_t limb_cnt; + + usize = u->nlimbs; + limb_cnt = count / BITS_PER_MPI_LIMB; + wsize = usize - limb_cnt; + if( limb_cnt >= usize ) + w->nlimbs = 0; + else { + mpi_ptr_t wp; + mpi_ptr_t up; + + RESIZE_IF_NEEDED( w, wsize ); + wp = w->d; + up = u->d; + + count %= BITS_PER_MPI_LIMB; + if( count ) { + mpihelp_rshift( wp, up + limb_cnt, wsize, count ); + wsize -= !wp[wsize - 1]; + } + else { + MPN_COPY_INCR( wp, up + limb_cnt, wsize); + } + + w->nlimbs = wsize; + } +} /**************** * Check wether dividend is divisible by divisor |