Blame stdlib/mul_1.c

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