summaryrefslogtreecommitdiff
path: root/patches/gmp/5.1.1/110-mpz_powm_ui.patch
blob: f0d240c62a5c48a864adbddc431165c243ffff8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# HG changeset patch
# User Torbjorn Granlund <tege@gmplib.org>
# Date 1363174284 -3600
# Node ID ec4d88674036804b26f22c6a2bfca6ae1e92d370
# Parent  e616ff715c34e112d0a5f7535d31ffe1194a5c7d
(mod): Adhere to mpn_mu_div_qr's overlap requirements.

diff -r e616ff715c34 -r ec4d88674036 mpz/powm_ui.c
--- a/mpz/powm_ui.c	Sun Feb 17 19:40:16 2013 +0100
+++ b/mpz/powm_ui.c	Wed Mar 13 12:31:24 2013 +0100
@@ -2,8 +2,8 @@
 
    Contributed to the GNU project by Torbjorn Granlund.
 
-Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2002, 2005, 2008,
-2009, 2011, 2012 Free Software Foundation, Inc.
+Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2002, 2005, 2008, 2009,
+2011, 2012, 2013 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -70,9 +70,14 @@
     }
   else
     {
+      /* We need to allocate separate remainder area, since mpn_mu_div_qr does
+	 not handle overlap between the numerator and remainder areas.
+	 FIXME: Make it handle such overlap.  */
+      mp_ptr rp = TMP_ALLOC_LIMBS (dn);
       mp_size_t itch = mpn_mu_div_qr_itch (nn, dn, 0);
       mp_ptr scratch = TMP_ALLOC_LIMBS (itch);
-      mpn_mu_div_qr (qp, np, np, nn, dp, dn, scratch);
+      mpn_mu_div_qr (qp, rp, np, nn, dp, dn, scratch);
+      MPN_COPY (np, rp, dn);
     }
 
   TMP_FREE;