addmul_1.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* mpn_addmul_1 -- multiply the S1_SIZE long limb vector pointed to by S1_PTR
  2. by S2_LIMB, add the S1_SIZE least significant limbs of the product to the
  3. limb vector pointed to by RES_PTR. Return the most significant limb of
  4. the product, adjusted for carry-out from the addition.
  5. Copyright (C) 1992, 1993, 1994, 1996 Free Software Foundation, Inc.
  6. This file is part of the GNU MP Library.
  7. The GNU MP Library is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU Lesser General Public License as published by
  9. the Free Software Foundation; either version 2.1 of the License, or (at your
  10. option) any later version.
  11. The GNU MP Library is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  13. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  14. License for more details.
  15. You should have received a copy of the GNU Lesser General Public License
  16. along with the GNU MP Library; see the file COPYING.LIB. If not, write to
  17. the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  18. MA 02111-1307, USA. */
  19. #include <config.h>
  20. #include "gmp-impl.h"
  21. mp_limb_t
  22. mpn_addmul_1 (res_ptr, s1_ptr, s1_size, s2_limb)
  23. register mp_ptr res_ptr;
  24. register mp_srcptr s1_ptr;
  25. mp_size_t s1_size;
  26. register mp_limb_t s2_limb;
  27. {
  28. register mp_limb_t cy_limb;
  29. register mp_size_t j;
  30. register mp_limb_t prod_high, prod_low;
  31. register mp_limb_t x;
  32. /* The loop counter and index J goes from -SIZE to -1. This way
  33. the loop becomes faster. */
  34. j = -s1_size;
  35. /* Offset the base pointers to compensate for the negative indices. */
  36. res_ptr -= j;
  37. s1_ptr -= j;
  38. cy_limb = 0;
  39. do
  40. {
  41. umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb);
  42. prod_low += cy_limb;
  43. cy_limb = (prod_low < cy_limb) + prod_high;
  44. x = res_ptr[j];
  45. prod_low = x + prod_low;
  46. cy_limb += (prod_low < x);
  47. res_ptr[j] = prod_low;
  48. }
  49. while (++j != 0);
  50. return cy_limb;
  51. }