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

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

1.1       maekawa     1: /* mpn_add_n -- Add 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_add_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_add_n (c, a, b, n);
                     60:       TMP_FREE (marker);
                     61:       return carry_out;
                     62:     }
                     63:
                     64:   carry_out = a[nm1] + b[nm1] < a[nm1];
                     65:
                     66: #pragma _CRI ivdep                     /* Cray PVP systems */
                     67:   for (i = nm1; i > 0; i--)
                     68:     {
                     69:       int cy_in;
                     70:       cy_in = a[i - 1] + b[i - 1] < a[i - 1];
                     71:       c[i] = a[i] + b[i] + cy_in;
                     72:       more_carries += c[i] < cy_in;
                     73:     }
                     74:   c[0] = a[0] + b[0];
                     75:
                     76:   if (more_carries)
                     77:     {
                     78:       /* This won't vectorize, but we should come here rarely.  */
                     79:       int cy;
                     80:     sequential:
                     81:       cy = 0;
                     82:       for (i = 0; i < n; i++)
                     83:        {
                     84:          mp_limb_t ai, ci, t;
                     85:          ai = a[i];
                     86:          t = b[i] + cy;
                     87:          cy = t < cy;
                     88:          ci = ai + t;
                     89:          cy += ci < ai;
                     90:          c[i] = ci;
                     91:        }
                     92:       carry_out = cy;
                     93:     }
                     94:
                     95:   return carry_out;
                     96: }

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