1 /* Cray PVP/IEEE mpn_addmul_1 -- multiply a limb vector with a limb and add the
2 result to a second limb vector.
4 Copyright 2000, 2001, 2002 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 just under 9 cycles/limb on a T90. That is not perfect,
22 mainly due to vector register shortage in the main loop. Assembly code
23 should bring it down to perhaps 7 cycles/limb. */
25 #include <intrinsics.h>
30 mpn_addmul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)
33 mp_limb_t a, b, r, s0, s1, c0, c1;
39 /* The algorithm used below cannot handle overlap. Handle it here by
40 making a temporary copy of the source vector, then call ourselves. */
43 return mpn_addmul_1 (rp, xp, n, vl);
50 c0 = ((a & r) | ((a | r) & ~s0)) >> 63;
53 /* Main multiply loop. Generate a raw accumulated output product in rp[]
54 and a carry vector in cy[]. */
56 for (i = 1; i < n; i++)
59 b = _int_mult_upper (up[i - 1], vl);
61 c0 = ((a & b) | ((a | b) & ~s0)) >> 63;
65 c1 = ((s0 & r) | ((s0 | r) & ~s1)) >> 63;
68 /* Carry add loop. Add the carry vector cy[] to the raw result rp[] and
69 store the new result back to rp[]. */
72 for (i = 1; i < n; i++)
81 /* If that second loop generated carry, handle that in scalar loop. */
85 /* Look for places where rp[k] == 0 and cy[k-1] == 1 or
86 rp[k] == 1 and cy[k-1] == 2.
87 These are where we got a recurrency carry. */
88 for (i = 1; i < n; i++)
97 return _int_mult_upper (up[n - 1], vl) + cyrec + cy[n - 1];
100 return _int_mult_upper (up[n - 1], vl) + cy[n - 1];