[BACK]Return to sub_n.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpn / cray

Annotation of OpenXM_contrib/gmp/mpn/cray/sub_n.c, Revision 1.1.1.1

1.1       maekawa     1: /* mpn_sub_n -- Subtract two limb vectors of equal, non-zero length.
                      2:    For Cray vector processors.
                      3:
                      4:    Copyright (C) 1996, 2000 Free Software Foundation, Inc.
                      5:
                      6:    This file is part of the GNU MP Library.
                      7:
                      8:    The GNU MP Library is free software; you can redistribute it and/or modify
                      9:    it under the terms of the GNU Lesser General Public License as published by
                     10:    the Free Software Foundation; either version 2.1 of the License, or (at your
                     11:    option) any later version.
                     12:
                     13:    The GNU MP Library is distributed in the hope that it will be useful, but
                     14:    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     15:    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
                     16:    License for more details.
                     17:
                     18:    You should have received a copy of the GNU Lesser General Public License
                     19:    along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
                     20:    the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
                     21:    MA 02111-1307, USA.  */
                     22:
                     23: #include "gmp.h"
                     24: #include "gmp-impl.h"
                     25:
                     26: mp_limb_t
                     27: mpn_sub_n (c, a, b, n)
                     28:      mp_ptr c;
                     29:      mp_srcptr a, b;
                     30:      mp_size_t n;
                     31: {
                     32:   mp_size_t i;
                     33:   mp_size_t nm1 = n - 1;
                     34:   int more_carries = 0;
                     35:   int carry_out;
                     36:
                     37:   /* For small operands the non-vector code is faster.  */
                     38:   if (n < 16)
                     39:     goto sequential;
                     40:
                     41:   if (a == c || b == c)
                     42:     {
                     43:       TMP_DECL (marker);
                     44:       TMP_MARK (marker);
                     45:       if (c == a)
                     46:        {
                     47:          /* allocate temp space for a */
                     48:          mp_ptr ax = (mp_ptr) TMP_ALLOC (n * BYTES_PER_MP_LIMB);
                     49:          MPN_COPY (ax, a, n);
                     50:          a = (mp_srcptr) ax;
                     51:        }
                     52:       if (c == b)
                     53:        {
                     54:          /* allocate temp space for b */
                     55:          mp_ptr bx = (mp_ptr) TMP_ALLOC (n * BYTES_PER_MP_LIMB);
                     56:          MPN_COPY (bx, b, n);
                     57:          b = (mp_srcptr) bx;
                     58:        }
                     59:       carry_out = mpn_sub_n (c, a, b, n);
                     60:       TMP_FREE (marker);
                     61:       return carry_out;
                     62:     }
                     63:
                     64:   carry_out = a[nm1] < b[nm1];
                     65:
                     66: #pragma _CRI ivdep                     /* Cray PVP systems */
                     67:   for (i = nm1; i > 0; i--)
                     68:     {
                     69:       int cy_in; mp_limb_t t;
                     70:       cy_in = a[i - 1] < b[i - 1];
                     71:       t = a[i] - b[i];
                     72:       more_carries += t < cy_in;
                     73:       c[i] = t - cy_in;
                     74:     }
                     75:   c[0] = a[0] - b[0];
                     76:
                     77:   if (more_carries)
                     78:     {
                     79:       /* This won't vectorize, but we should come here rarely.  */
                     80:       int cy;
                     81:     sequential:
                     82:       cy = 0;
                     83:       for (i = 0; i < n; i++)
                     84:        {
                     85:          mp_limb_t ai, ci, t;
                     86:          ai = a[i];
                     87:          t = b[i] + cy;
                     88:          cy = t < cy;
                     89:          ci = ai - t;
                     90:          cy += ci > ai;
                     91:          c[i] = ci;
                     92:        }
                     93:       carry_out = cy;
                     94:     }
                     95:
                     96:   return carry_out;
                     97: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>