1 /* Cray PVP/IEEE mpn_mul_1 -- multiply a limb vector with a limb and store the
2 result in a second limb vector.
4 Copyright 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 5 cycles/limb on a T90. That would probably
22 be hard to improve upon, even with assembly code. */
24 #include <intrinsics.h>
29 mpn_mul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)
32 mp_limb_t a, b, r, s0, s1, c0, c1;
38 /* The algorithm used below cannot handle overlap. Handle it here by
39 making a temporary copy of the source vector, then call ourselves. */
42 return mpn_mul_1 (rp, xp, n, vl);
49 /* Main multiply loop. Generate a raw accumulated output product in rp[]
50 and a carry vector in cy[]. */
52 for (i = 1; i < n; i++)
55 b = _int_mult_upper (up[i - 1], vl);
57 c0 = ((a & b) | ((a | b) & ~s0)) >> 63;
61 /* Carry add loop. Add the carry vector cy[] to the raw sum rp[] and
62 store the new sum back to rp[0]. */
65 for (i = 2; i < n; i++)
74 /* If that second loop generated carry, handle that in scalar loop. */
78 /* Look for places where rp[k] is zero and cy[k-1] is non-zero.
79 These are where we got a recurrency carry. */
80 for (i = 2; i < n; i++)
83 c0 = (r == 0 && cy[i - 1] != 0);
89 return _int_mult_upper (up[n - 1], vl) + cyrec + cy[n - 1];
92 return _int_mult_upper (up[n - 1], vl) + cy[n - 1];