1 /* Cray PVP/IEEE mpn_submul_1 -- multiply a limb vector with a limb and
2 subtract the result from a second limb vector.
4 Copyright 2000-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 either:
11 * the GNU Lesser General Public License as published by the Free
12 Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
17 * the GNU General Public License as published by the Free Software
18 Foundation; either version 2 of the License, or (at your option) any
21 or both in parallel, as here.
23 The GNU MP Library is distributed in the hope that it will be useful, but
24 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 You should have received copies of the GNU General Public License and the
29 GNU Lesser General Public License along with the GNU MP Library. If not,
30 see https://www.gnu.org/licenses/. */
32 /* This code runs at just under 9 cycles/limb on a T90. That is not perfect,
33 mainly due to vector register shortage in the main loop. Assembly code
34 should bring it down to perhaps 7 cycles/limb. */
36 #include <intrinsics.h>
41 mpn_submul_1 (mp_ptr rp
, mp_srcptr up
, mp_size_t n
, mp_limb_t vl
)
44 mp_limb_t a
, b
, r
, s0
, s1
, c0
, c1
;
50 /* The algorithm used below cannot handle overlap. Handle it here by
51 making a temporary copy of the source vector, then call ourselves. */
54 return mpn_submul_1 (rp
, xp
, n
, vl
);
61 c1
= ((s0
& a
) | ((s0
| a
) & ~r
)) >> 63;
64 /* Main multiply loop. Generate a raw accumulated output product in rp[]
65 and a carry vector in cy[]. */
67 for (i
= 1; i
< n
; i
++)
70 b
= _int_mult_upper (up
[i
- 1], vl
);
72 c0
= ((a
& b
) | ((a
| b
) & ~s0
)) >> 63;
76 c1
= ((s1
& s0
) | ((s1
| s0
) & ~r
)) >> 63;
79 /* Carry subtract loop. Subtract the carry vector cy[] from the raw result
80 rp[] and store the new result back to rp[]. */
83 for (i
= 1; i
< n
; i
++)
92 /* If that second loop generated carry, handle that in scalar loop. */
96 /* Look for places where rp[k] == ~0 and cy[k-1] == 1 or
97 rp[k] == ~1 and cy[k-1] == 2.
98 These are where we got a recurrency carry. */
99 for (i
= 1; i
< n
; i
++)
105 c1
= (s0
& ~r
) >> 63;
108 return _int_mult_upper (up
[n
- 1], vl
) + cyrec
+ cy
[n
- 1];
111 return _int_mult_upper (up
[n
- 1], vl
) + cy
[n
- 1];