summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2012-04-22 12:17:09 +0200
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2012-04-22 12:17:09 +0200
commitbbd1f5f7aee9035eb3eb98967096d5b14a5f9055 (patch)
tree7c9db5b67449adc173d4b78be394061d9fa4c08f
parent48700d5f6b8e6b0cd92cbb7ab09e62e1e8540db5 (diff)
downloadgmp-bbd1f5f7aee9035eb3eb98967096d5b14a5f9055.tar.gz
Renamed files with constants for combinatorics.
-rw-r--r--ChangeLog8
-rw-r--r--Makefile.am16
-rw-r--r--gen-fac.c (renamed from gen-fac_ui.c)4
-rw-r--r--gmp-impl.h1
-rw-r--r--mpz/2fac_ui.c2
-rw-r--r--mpz/bin_ui.c11
-rw-r--r--mpz/bin_uiui.c2
-rw-r--r--mpz/fac_ui.c2
-rw-r--r--mpz/oddfac_1.c6
-rw-r--r--mpz/primorial_ui.c1
10 files changed, 26 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index 9310f6a82..b02c57571 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-04-22 Marco Bodrato <bodrato@mail.dm.unipi.it>
+
+ * gen-fac.c: Renamed, was gen-fac_ui.c .
+ * Makefile.am: Renamed gen-fac.c and fac_table.h .
+ * gmp-impl.h: #include "fac_table.h".
+ * mpz/oddfac_1.c: Use generated constant.
+ * mpz/bin_ui.c: Small optimisations.
+
2012-04-21 Torbjorn Granlund <tege@gmplib.org>
* mpn/arm/mul_1.asm: Cleanup.
diff --git a/Makefile.am b/Makefile.am
index 2e8d850d5..6bced1388 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -313,14 +313,14 @@ install-data-hook:
EXTRA_DIST += bootstrap.c
-fac_ui.h: gen-fac_ui$(EXEEXT_FOR_BUILD)
- ./gen-fac_ui $(GMP_LIMB_BITS) $(GMP_NAIL_BITS) >fac_ui.h || (rm -f fac_ui.h; exit 1)
-BUILT_SOURCES += fac_ui.h
-
-gen-fac_ui$(EXEEXT_FOR_BUILD): gen-fac_ui$(U_FOR_BUILD).c bootstrap.c
- $(CC_FOR_BUILD) `test -f 'gen-fac_ui$(U_FOR_BUILD).c' || echo '$(srcdir)/'`gen-fac_ui$(U_FOR_BUILD).c -o gen-fac_ui$(EXEEXT_FOR_BUILD)
-DISTCLEANFILES += gen-fac_ui$(EXEEXT_FOR_BUILD)
-EXTRA_DIST += gen-fac_ui.c
+fac_table.h: gen-fac$(EXEEXT_FOR_BUILD)
+ ./gen-fac $(GMP_LIMB_BITS) $(GMP_NAIL_BITS) >fac_table.h || (rm -f fac_table.h; exit 1)
+BUILT_SOURCES += fac_table.h
+
+gen-fac$(EXEEXT_FOR_BUILD): gen-fac$(U_FOR_BUILD).c bootstrap.c
+ $(CC_FOR_BUILD) `test -f 'gen-fac$(U_FOR_BUILD).c' || echo '$(srcdir)/'`gen-fac$(U_FOR_BUILD).c -o gen-fac$(EXEEXT_FOR_BUILD)
+DISTCLEANFILES += gen-fac$(EXEEXT_FOR_BUILD)
+EXTRA_DIST += gen-fac.c
fib_table.h: gen-fib$(EXEEXT_FOR_BUILD)
diff --git a/gen-fac_ui.c b/gen-fac.c
index 4ec816fb2..735253b47 100644
--- a/gen-fac_ui.c
+++ b/gen-fac.c
@@ -1,4 +1,4 @@
-/* Generate mpz_fac_ui data.
+/* Generate data for combinatorics: fac_ui, bin_uiui, ...
Copyright 2002, 2011, 2012 Free Software Foundation, Inc.
@@ -39,7 +39,7 @@ gen_consts (int numb, int nail, int limb)
unsigned long a, b;
unsigned long ofl, ofe;
- printf ("/* This file is automatically generated by gen-fac_ui.c */\n\n");
+ printf ("/* This file is automatically generated by gen-fac.c */\n\n");
printf ("#if GMP_NUMB_BITS != %d\n", numb);
printf ("Error , error this data is for %d GMP_NUMB_BITS only\n", numb);
printf ("#endif\n");
diff --git a/gmp-impl.h b/gmp-impl.h
index f881db23b..8700eaf2c 100644
--- a/gmp-impl.h
+++ b/gmp-impl.h
@@ -133,6 +133,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include "config.h"
#include "gmp-mparam.h"
#include "fib_table.h"
+#include "fac_table.h"
#include "mp_bases.h"
#if WANT_FAT_BINARY
#include "fat.h"
diff --git a/mpz/2fac_ui.c b/mpz/2fac_ui.c
index db89a14bb..b1606bfbd 100644
--- a/mpz/2fac_ui.c
+++ b/mpz/2fac_ui.c
@@ -22,8 +22,6 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include "gmp.h"
#include "gmp-impl.h"
-#include "fac_ui.h"
-
#define FACTOR_LIST_STORE(P, PR, MAX_PR, VEC, I) \
do { \
if ((PR) > (MAX_PR)) { \
diff --git a/mpz/bin_ui.c b/mpz/bin_ui.c
index ff79d1498..5f63dda42 100644
--- a/mpz/bin_ui.c
+++ b/mpz/bin_ui.c
@@ -46,7 +46,7 @@ mpz_bin_ui (mpz_ptr r, mpz_srcptr n, unsigned long int k)
mp_limb_t kacc;
mp_size_t negate;
- if (mpz_sgn (n) < 0)
+ if (SIZ (n) < 0)
{
/* bin(n,k) = (-1)^k * bin(-n+k-1,k), and set ni = -n+k-1 - k = -n-1 */
mpz_init (ni);
@@ -60,7 +60,7 @@ mpz_bin_ui (mpz_ptr r, mpz_srcptr n, unsigned long int k)
(no test for this under the n<0 case, since -n+k-1 >= k there) */
if (mpz_cmp_ui (n, k) < 0)
{
- mpz_set_ui (r, 0L);
+ SIZ (r) = 0;
return;
}
@@ -72,7 +72,7 @@ mpz_bin_ui (mpz_ptr r, mpz_srcptr n, unsigned long int k)
/* Now wanting bin(ni+k,k), with ni positive, and "negate" is the sign (0
for positive, 1 for negative). */
- mpz_set_ui (r, 1L);
+ SIZ (r) = 1; PTR (r)[0] = 1;
/* Rewrite bin(n,k) as bin(n,n-k) if that is smaller. In this case it's
whether ni+k-k < k meaning ni<k, and if so change to denominator ni+k-k
@@ -108,19 +108,18 @@ mpz_bin_ui (mpz_ptr r, mpz_srcptr n, unsigned long int k)
mpz_add_ui (ni, ni, 1L);
mpz_mul (nacc, nacc, ni);
umul_ppmm (k1, k0, kacc, i << GMP_NAIL_BITS);
- k0 >>= GMP_NAIL_BITS;
if (k1 != 0)
{
/* Accumulator overflow. Perform bignum step. */
mpz_mul (r, r, nacc);
- mpz_set_ui (nacc, 1L);
+ SIZ (nacc) = 1; PTR (nacc)[0] = 1;
DIVIDE ();
kacc = i;
}
else
{
/* Save new products in accumulators to keep accumulating. */
- kacc = k0;
+ kacc = k0 >> GMP_NAIL_BITS;
}
}
diff --git a/mpz/bin_uiui.c b/mpz/bin_uiui.c
index fbd293938..65a68957f 100644
--- a/mpz/bin_uiui.c
+++ b/mpz/bin_uiui.c
@@ -23,8 +23,6 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include "gmp-impl.h"
#include "longlong.h"
-#include "fac_ui.h"
-
#ifndef BIN_GOETGHELUCK_THRESHOLD
#define BIN_GOETGHELUCK_THRESHOLD 1000
#endif
diff --git a/mpz/fac_ui.c b/mpz/fac_ui.c
index cbc075d2b..998327b24 100644
--- a/mpz/fac_ui.c
+++ b/mpz/fac_ui.c
@@ -23,8 +23,6 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include "gmp.h"
#include "gmp-impl.h"
-#include "fac_ui.h"
-
#define FACTOR_LIST_STORE(P, PR, MAX_PR, VEC, I) \
do { \
if ((PR) > (MAX_PR)) { \
diff --git a/mpz/oddfac_1.c b/mpz/oddfac_1.c
index 6662f251b..282f4f3a3 100644
--- a/mpz/oddfac_1.c
+++ b/mpz/oddfac_1.c
@@ -28,8 +28,6 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include "gmp-impl.h"
#include "longlong.h"
-#include "fac_ui.h"
-
/* TODO:
- split this file in smaller parts with functions that can be recycled for different computations.
*/
@@ -288,9 +286,9 @@ mpz_oddfac_1 (mpz_ptr x, mp_limb_t n, unsigned flag)
{
static const mp_limb_t tablef[] = { ONE_LIMB_ODD_FACTORIAL_TABLE };
- ASSERT (flag == 0 || (flag == 1 && n >= numberof (tablef) && ABOVE_THRESHOLD (n, FAC_DSC_THRESHOLD)));
+ ASSERT (flag == 0 || (flag == 1 && n > ODD_FACTORIAL_TABLE_LIMIT && ABOVE_THRESHOLD (n, FAC_DSC_THRESHOLD)));
- if (n < numberof (tablef))
+ if (n <= ODD_FACTORIAL_TABLE_LIMIT)
{
PTR (x)[0] = tablef[n];
SIZ (x) = 1;
diff --git a/mpz/primorial_ui.c b/mpz/primorial_ui.c
index ccd0e2089..4acbf321a 100644
--- a/mpz/primorial_ui.c
+++ b/mpz/primorial_ui.c
@@ -24,7 +24,6 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
/* TODO: Remove duplicated constants / macros / static functions...
*/
-#include "fac_ui.h"
/*************************************************************/
/* Section macros: common macros, for swing/fac/bin (&sieve) */