raw
mpi-genesis             1 /* mpihelp-mul_3.c  -  MPI helper functions
mpi_second_cut 2 * Modified by No Such Labs. (C) 2015. See README.
mpi-genesis 3 *
mpi_second_cut 4 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
mpi_second_cut 5 * SHA256(gnupg-1.4.10.tar.gz):
mpi_second_cut 6 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
mpi_second_cut 7 * (C) 1994-2005 Free Software Foundation, Inc.
mpi-genesis 8 *
mpi_second_cut 9 * This program is free software: you can redistribute it and/or modify
mpi-genesis 10 * it under the terms of the GNU General Public License as published by
mpi_second_cut 11 * the Free Software Foundation, either version 3 of the License, or
mpi-genesis 12 * (at your option) any later version.
mpi-genesis 13 *
mpi_second_cut 14 * This program is distributed in the hope that it will be useful,
mpi-genesis 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mpi-genesis 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
mpi-genesis 17 * GNU General Public License for more details.
mpi-genesis 18 *
mpi-genesis 19 * You should have received a copy of the GNU General Public License
mpi_second_cut 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
mpi-genesis 21 */
mpi-genesis 22
mpi-genesis 23 #include <stdio.h>
mpi-genesis 24 #include <stdlib.h>
mpi_second_cut 25
mpi_second_cut 26 #include "knobs.h"
mpi-genesis 27 #include "mpi-internal.h"
mpi-genesis 28 #include "longlong.h"
mpi-genesis 29
mpi-genesis 30
mpi-genesis 31 mpi_limb_t
mpi-genesis 32 mpihelp_submul_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
mpi-genesis 33 mpi_size_t s1_size, mpi_limb_t s2_limb)
mpi-genesis 34 {
mpi-genesis 35 mpi_limb_t cy_limb;
mpi-genesis 36 mpi_size_t j;
mpi-genesis 37 mpi_limb_t prod_high, prod_low;
mpi-genesis 38 mpi_limb_t x;
mpi-genesis 39
mpi-genesis 40 /* The loop counter and index J goes from -SIZE to -1. This way
mpi-genesis 41 * the loop becomes faster. */
mpi-genesis 42 j = -s1_size;
mpi-genesis 43 res_ptr -= j;
mpi-genesis 44 s1_ptr -= j;
mpi-genesis 45
mpi-genesis 46 cy_limb = 0;
mpi-genesis 47 do {
mpi-genesis 48 umul_ppmm( prod_high, prod_low, s1_ptr[j], s2_limb);
mpi-genesis 49
mpi-genesis 50 prod_low += cy_limb;
mpi-genesis 51 cy_limb = (prod_low < cy_limb?1:0) + prod_high;
mpi-genesis 52
mpi-genesis 53 x = res_ptr[j];
mpi-genesis 54 prod_low = x - prod_low;
mpi-genesis 55 cy_limb += prod_low > x?1:0;
mpi-genesis 56 res_ptr[j] = prod_low;
mpi-genesis 57 } while( ++j );
mpi-genesis 58
mpi-genesis 59 return cy_limb;
mpi-genesis 60 }
mpi-genesis 61
mpi-genesis 62