1 /* Cray PVP mpn_sub_n -- subtract two limb vectors and store their difference
2 in a third limb vector.
4 Copyright 1996, 2000, 2001 Free Software Foundation, Inc.
6 This file is part of the GNU MP Library.
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 3 of the License, or (at your
11 option) any later version.
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.
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
21 /* This code runs at 4 cycles/limb. It may be possible to bring it down
28 mpn_sub_n (mp_ptr rp, mp_srcptr up, mp_srcptr vp, mp_size_t n)
31 mp_limb_t a, b, r, s0, c0, c1;
35 /* Main subtract loop. Generate a raw output difference in rp[] and a
36 borrow vector in cy[]. */
38 for (i = 0; i < n; i++)
42 s0 = a - b; /* a = s0 + b */
44 c0 = ((s0 & b) | ((s0 | b) & ~a)) >> 63;
47 /* Borrow subtract loop. Subtract the borrow vector cy[] from the raw
48 difference rp[] and store the new difference back to rp[0]. If this
49 generates further borrow, set more_carries. */
52 for (i = 1; i < n; i++)
56 s0 = r - c0; /* r = s0 + c0 */
61 /* If that second loop generated borrow, handle that in scalar loop. */
65 /* Look for places where rp[k] contains just ones and cy[k-1] is
66 non-zero. These are where we got a recurrency borrow. */
67 for (i = 1; i < n; i++)
70 c0 = (~r == 0 && cy[i - 1] != 0);
76 return cyrec | cy[n - 1];