Blame stdlib/addmul_1.c

Packit 6c4009
/* mpn_addmul_1 -- multiply the S1_SIZE long limb vector pointed to by S1_PTR
Packit 6c4009
   by S2_LIMB, add the S1_SIZE least significant limbs of the product to the
Packit 6c4009
   limb vector pointed to by RES_PTR.  Return the most significant limb of
Packit 6c4009
   the product, adjusted for carry-out from the addition.
Packit 6c4009
Packit 6c4009
Copyright (C) 1992-2018 Free Software Foundation, Inc.
Packit 6c4009
Packit 6c4009
This file is part of the GNU MP Library.
Packit 6c4009
Packit 6c4009
The GNU MP Library is free software; you can redistribute it and/or modify
Packit 6c4009
it under the terms of the GNU Lesser General Public License as published by
Packit 6c4009
the Free Software Foundation; either version 2.1 of the License, or (at your
Packit 6c4009
option) any later version.
Packit 6c4009
Packit 6c4009
The GNU MP Library is distributed in the hope that it will be useful, but
Packit 6c4009
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
Packit 6c4009
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
Packit 6c4009
License for more details.
Packit 6c4009
Packit 6c4009
You should have received a copy of the GNU Lesser General Public License
Packit 6c4009
along with the GNU MP Library; see the file COPYING.LIB.  If not, see
Packit 6c4009
<http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <gmp.h>
Packit 6c4009
#include "gmp-impl.h"
Packit 6c4009
#include "longlong.h"
Packit 6c4009
Packit 6c4009
mp_limb_t
Packit 6c4009
mpn_addmul_1 (register mp_ptr res_ptr, register mp_srcptr s1_ptr,
Packit 6c4009
	      mp_size_t s1_size, register mp_limb_t s2_limb)
Packit 6c4009
{
Packit 6c4009
  register mp_limb_t cy_limb;
Packit 6c4009
  register mp_size_t j;
Packit 6c4009
  register mp_limb_t prod_high, prod_low;
Packit 6c4009
  register mp_limb_t x;
Packit 6c4009
Packit 6c4009
  /* The loop counter and index J goes from -SIZE to -1.  This way
Packit 6c4009
     the loop becomes faster.  */
Packit 6c4009
  j = -s1_size;
Packit 6c4009
Packit 6c4009
  /* Offset the base pointers to compensate for the negative indices.  */
Packit 6c4009
  res_ptr -= j;
Packit 6c4009
  s1_ptr -= j;
Packit 6c4009
Packit 6c4009
  cy_limb = 0;
Packit 6c4009
  do
Packit 6c4009
    {
Packit 6c4009
      umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb);
Packit 6c4009
Packit 6c4009
      prod_low += cy_limb;
Packit 6c4009
      cy_limb = (prod_low < cy_limb) + prod_high;
Packit 6c4009
Packit 6c4009
      x = res_ptr[j];
Packit 6c4009
      prod_low = x + prod_low;
Packit 6c4009
      cy_limb += (prod_low < x);
Packit 6c4009
      res_ptr[j] = prod_low;
Packit 6c4009
    }
Packit 6c4009
  while (++j != 0);
Packit 6c4009
Packit 6c4009
  return cy_limb;
Packit 6c4009
}