3 THIS FILE CONTAINS AN INTERNAL FUNCTION WITH A MUTABLE INTERFACE. IT IS
4 ONLY SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST
5 GUARANTEED THAT IT'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
7 Copyright 2013 Free Software Foundation, Inc.
9 This file is part of the GNU MP Library.
11 The GNU MP Library is free software; you can redistribute it and/or modify
12 it under the terms of either:
14 * the GNU Lesser General Public License as published by the Free
15 Software Foundation; either version 3 of the License, or (at your
16 option) any later version.
20 * the GNU General Public License as published by the Free Software
21 Foundation; either version 2 of the License, or (at your option) any
24 or both in parallel, as here.
26 The GNU MP Library is distributed in the hope that it will be useful, but
27 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
28 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
31 You should have received copies of the GNU General Public License and the
32 GNU Lesser General Public License along with the GNU MP Library. If not,
33 see https://www.gnu.org/licenses/. */
37 * Can we really use the high pi2 inverse limb for udiv_qrnnd_preinv?
39 * Are there any problems with generating n quotient limbs in the q area? It
40 surely simplifies things.
42 * Not yet adequately tested.
49 /* Define some longlong.h-style macros, but for wider operations.
50 * add_sssaaaa is like longlong.h's add_ssaaaa but propagating
51 carry-out into an additional sum operand.
53 #if defined (__GNUC__) && ! defined (__INTEL_COMPILER) && ! defined (NO_ASM)
55 #if HAVE_HOST_CPU_FAMILY_x86 && W_TYPE_SIZE == 32
56 #define add_sssaaaa(s2, s1, s0, a1, a0, b1, b0) \
57 __asm__ ("add\t%7, %k2\n\tadc\t%5, %k1\n\tadc\t$0, %k0" \
58 : "=r" (s2), "=&r" (s1), "=&r" (s0) \
59 : "0" ((USItype)(s2)), \
60 "1" ((USItype)(a1)), "g" ((USItype)(b1)), \
61 "%2" ((USItype)(a0)), "g" ((USItype)(b0)))
64 #if defined (__amd64__) && W_TYPE_SIZE == 64
65 #define add_sssaaaa(s2, s1, s0, a1, a0, b1, b0) \
66 __asm__ ("add\t%7, %q2\n\tadc\t%5, %q1\n\tadc\t$0, %q0" \
67 : "=r" (s2), "=&r" (s1), "=&r" (s0) \
68 : "0" ((UDItype)(s2)), \
69 "1" ((UDItype)(a1)), "rme" ((UDItype)(b1)), \
70 "%2" ((UDItype)(a0)), "rme" ((UDItype)(b0)))
73 #if HAVE_HOST_CPU_FAMILY_powerpc && !defined (_LONG_LONG_LIMB)
74 /* This works fine for 32-bit and 64-bit limbs, except for 64-bit limbs with a
75 processor running in 32-bit mode, since the carry flag then gets the 32-bit
77 #define add_sssaaaa(s2, s1, s0, a1, a0, b1, b0) \
78 __asm__ ("add%I7c\t%2,%6,%7\n\tadde\t%1,%4,%5\n\taddze\t%0,%0" \
79 : "=r" (s2), "=&r" (s1), "=&r" (s0) \
80 : "r" (s2), "r" (a1), "r" (b1), "%r" (a0), "rI" (b0))
86 #define add_sssaaaa(s2, s1, s0, a1, a0, b1, b0) \
88 UWtype __s0, __s1, __c0, __c1; \
96 (s2) += __c1 + (__s1 < __c0); \
100 struct precomp_div_1_pi2
108 mpn_div_qr_1u_pi2 (mp_ptr qp
,
109 mp_srcptr up
, mp_size_t un
,
110 struct precomp_div_1_pi2
*pd
)
113 mp_limb_t r
, u2
, u1
, u0
;
114 mp_limb_t d0
, di1
, di0
;
115 mp_limb_t q3a
, q2a
, q2b
, q1b
, q2c
, q1c
, q1d
, q0d
;
120 ASSERT ((pd
->d
& GMP_NUMB_HIGHBIT
) == 0);
121 ASSERT (! MPN_OVERLAP_P (qp
, un
-2, up
, un
) || qp
+2 >= up
);
130 r
= up
[2] >> (GMP_NUMB_BITS
- cnt
);
138 for (i
= un
- 3; i
>= 0; i
-= 2)
141 u1
= (up
[2] << cnt
) | (up
[1] >> (GMP_NUMB_BITS
- cnt
));
142 u0
= (up
[1] << cnt
) | (up
[0] >> (GMP_NUMB_BITS
- cnt
));
144 /* Dividend in {r,u1,u0} */
146 umul_ppmm (q1d
,q0d
, u1
, di0
);
147 umul_ppmm (q2b
,q1b
, u1
, di1
);
148 q2b
++; /* cannot spill */
149 add_sssaaaa (r
,q2b
,q1b
, q2b
,q1b
, u1
,u0
);
151 umul_ppmm (q2c
,q1c
, u2
, di0
);
152 add_sssaaaa (r
,q2b
,q1b
, q2b
,q1b
, q2c
,q1c
);
153 umul_ppmm (q3a
,q2a
, u2
, di1
);
155 add_sssaaaa (r
,q2b
,q1b
, q2b
,q1b
, q2a
,q1d
);
163 sub_ddmmss (q3
,q2
, q3
,q2
, 0,cnd
);
165 if (UNLIKELY (r
>= d0
))
168 add_ssaaaa (q3
,q2
, q3
,q2
, 0,1);
183 udiv_qrnnd_preinv (q3
, r
, u2
, u1
, d0
, di1
);
189 u1
= (up
[2] << cnt
) | (up
[1] >> (GMP_NUMB_BITS
- cnt
));
192 /* Dividend in {r,u1,u0} */
194 umul_ppmm (q1d
,q0d
, u1
, di0
);
195 umul_ppmm (q2b
,q1b
, u1
, di1
);
196 q2b
++; /* cannot spill */
197 add_sssaaaa (r
,q2b
,q1b
, q2b
,q1b
, u1
,u0
);
199 umul_ppmm (q2c
,q1c
, u2
, di0
);
200 add_sssaaaa (r
,q2b
,q1b
, q2b
,q1b
, q2c
,q1c
);
201 umul_ppmm (q3a
,q2a
, u2
, di1
);
203 add_sssaaaa (r
,q2b
,q1b
, q2b
,q1b
, q2a
,q1d
);
211 sub_ddmmss (q3
,q2
, q3
,q2
, 0,cnd
);
213 if (UNLIKELY (r
>= d0
))
216 add_ssaaaa (q3
,q2
, q3
,q2
, 0,1);