Blame stdlib/sub_n.c

Packit 6c4009
/* mpn_sub_n -- Subtract two limb vectors of equal, non-zero length.
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
Packit 6c4009
mp_limb_t
Packit 6c4009
mpn_sub_n (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size)
Packit 6c4009
{
Packit 6c4009
  register mp_limb_t x, y, cy;
Packit 6c4009
  register mp_size_t j;
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 = -size;
Packit 6c4009
Packit 6c4009
  /* Offset the base pointers to compensate for the negative indices.  */
Packit 6c4009
  s1_ptr -= j;
Packit 6c4009
  s2_ptr -= j;
Packit 6c4009
  res_ptr -= j;
Packit 6c4009
Packit 6c4009
  cy = 0;
Packit 6c4009
  do
Packit 6c4009
    {
Packit 6c4009
      y = s2_ptr[j];
Packit 6c4009
      x = s1_ptr[j];
Packit 6c4009
      y += cy;			/* add previous carry to subtrahend */
Packit 6c4009
      cy = (y < cy);		/* get out carry from that addition */
Packit 6c4009
      y = x - y;		/* main subtract */
Packit 6c4009
      cy = (y > x) + cy;	/* get out carry from the subtract, combine */
Packit 6c4009
      res_ptr[j] = y;
Packit 6c4009
    }
Packit 6c4009
  while (++j != 0);
Packit 6c4009
Packit 6c4009
  return cy;
Packit 6c4009
}