[libmath-prime-util-perl] 81/181: Modifications to previous merge
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:51:09 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.36
in repository libmath-prime-util-perl.
commit 2fe6d93cc04896db45d0a207132edd2f4cadd61b
Author: Dana Jacobsen <dana at acm.org>
Date: Tue Dec 31 05:35:45 2013 -0800
Modifications to previous merge
---
cache.c | 13 ++++++-------
mulmod.h | 11 +++++------
ptypes.h | 12 +++++-------
util.c | 27 ++++++++++++---------------
4 files changed, 28 insertions(+), 35 deletions(-)
diff --git a/cache.c b/cache.c
index b47618e..2aec994 100644
--- a/cache.c
+++ b/cache.c
@@ -237,19 +237,18 @@ void prime_precalc(UV n)
void prime_memfree(void)
{
- unsigned char* local_prime_segment = 0;
+ unsigned char* old_segment = 0;
MPUassert(mutex_init == 1, "cache mutexes have not been initialized");
MUTEX_LOCK(&segment_mutex);
/* Don't free if another thread is using it */
- if ( (prime_segment != local_prime_segment) && (prime_segment_is_available) ) {\
- /* hint to use xchg op */
- unsigned char* local_prime_segment2 = local_prime_segment;
- local_prime_segment = prime_segment;
- prime_segment = local_prime_segment2;
+ if ( (prime_segment != 0) && (prime_segment_is_available) ) {\
+ unsigned char* new_segment = old_segment;
+ old_segment = prime_segment;
+ prime_segment = new_segment; /* Exchanged old_segment / prime_segment */
}
MUTEX_UNLOCK(&segment_mutex);
- if(local_prime_segment) Safefree(local_prime_segment);
+ if (old_segment) Safefree(old_segment);
WRITE_LOCK_START;
/* Put primary cache back to initial state */
diff --git a/mulmod.h b/mulmod.h
index c03851d..da56608 100644
--- a/mulmod.h
+++ b/mulmod.h
@@ -105,20 +105,19 @@
#endif
#ifndef addmod
- #define addmod(a,b,n) ((((n)-(a)) > (b)) ? ((a)+(b)) : ((a)+(b)-(n)))
+ static INLINE UV addmod(UV a, UV b, UV n) {
+ return ((n-a) > b) ? a+b : a+b-n;
+ }
#endif
-/* We need to make sure a and b get evaluated into UVs, then do the
- * subtract into a UV before the addmod. */
static INLINE UV submod(UV a, UV b, UV n) {
- UV t1 = n - b;
- return addmod(a, t1, n);
+ UV t = n-b; /* Evaluate as UV, then hand to addmod */
+ return addmod(a, t, n);
}
/* a^2 + c mod n */
#define sqraddmod(a, c, n) addmod(sqrmod(a,n), c, n)
/* a*b + c mod n */
-/* TODO mulmod is a function, addmod is a multi eval macro == mulmod called 3x uselessly */
#define muladdmod(a, b, c, n) addmod(mulmod(a,b,n), c, n)
/* a*b - c mod n */
#define mulsubmod(a, b, c, n) submod(mulmod(a,b,n), c, n)
diff --git a/ptypes.h b/ptypes.h
index 860977c..1d7dc20 100644
--- a/ptypes.h
+++ b/ptypes.h
@@ -2,14 +2,10 @@
#define MPU_PTYPES_H
#ifdef _MSC_VER
- /* No stdint.h for MS C, so we lose the chance to possibly optimize
- * some operations on 64-bit machines running a 32-bit Perl. It's probably
- * a rare enough case that we don't need to be too concerned. If we do want,
- * see: http://gauss.cs.ucsb.edu/~aydin/CombBLAS/html/stdint_8h_source.html
- * for some ideas.
+ /* No stdint.h for MS C, but all the types can be defined.
*
- * Thanks to Sisyphus for bringing the MSC issue to my attention (and even
- * submitting a working patch!).
+ * Thanks to Sisyphus and bulk88 for all the help with MSC,
+ * including working patches.
*/
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
@@ -94,6 +90,8 @@ typedef __int8 int8_t;
#undef HAVE_STD_U64
#define HAVE_STD_U64 1
#endif
+#elif defined(_MSC_VER) /* We set up the types earlier */
+ #define HAVE_STD_U64 1
#endif
#define MAXBIT (BITS_PER_WORD-1)
diff --git a/util.c b/util.c
index 718a005..ec25126 100644
--- a/util.c
+++ b/util.c
@@ -292,13 +292,11 @@ UV _XS_prev_prime(UV n)
m = n - d*30;
if (n < 30*NPRIME_SIEVE30) {
- /* don't merge this loop with the next loop prime_sieve30 is a C static,
- which on CISC CPUs can be accessed with instruction pointer relative
- addressing, instead of a pointer in a register deref addressing which
- frees a register */
+ /* Don't try to merge this loop with the next one. prime_sieve30 is a
+ * static, so this can be faster. */
do {
m = prevwheel30[m];
- if (m==29) { MPUassert(d>0, "d 0 in prev_prime"); d--; }
+ if (m==29) d--;
} while (prime_sieve30[d] & masktab30[m]);
return(d*30+m);
}
@@ -307,14 +305,14 @@ UV _XS_prev_prime(UV n)
if (n < sieve_size) {
do {
m = prevwheel30[m];
- if (m==29) { MPUassert(d>0, "d 0 in prev_prime"); d--; }
+ if (m==29) d--;
} while (sieve[d] & masktab30[m]);
release_prime_cache(sieve);
} else {
release_prime_cache(sieve);
do {
m = prevwheel30[m];
- if (m==29) { MPUassert(d>0, "d 0 in prev_prime"); d--; }
+ if (m==29) d--;
} while (!_is_prime7(d*30+m));
}
return(d*30+m);
@@ -381,12 +379,13 @@ static UV count_segment_maxcount(const unsigned char* sieve, UV base, UV nbytes,
*/
static UV count_segment_ranged(const unsigned char* sieve, UV nbytes, UV lowp, UV highp)
{
+ UV count, hi_d, lo_d, lo_m;
+
MPUassert( sieve != 0, "count_segment_ranged incorrect args");
if (nbytes == 0) return 0;
-{
- UV count = 0;
- UV hi_d = highp/30;
+ count = 0;
+ hi_d = highp/30;
if (hi_d >= nbytes) {
hi_d = nbytes-1;
@@ -403,9 +402,9 @@ static UV count_segment_ranged(const unsigned char* sieve, UV nbytes, UV lowp, U
END_DO_FOR_EACH_SIEVE_PRIME;
return count;
#endif
-{
- UV lo_d = lowp/30;
- UV lo_m = lowp - lo_d*30;
+
+ lo_d = lowp/30;
+ lo_m = lowp - lo_d*30;
/* Count first fragment */
if (lo_m > 1) {
UV upper = (highp <= (lo_d*30+29)) ? highp : (lo_d*30+29);
@@ -440,8 +439,6 @@ static UV count_segment_ranged(const unsigned char* sieve, UV nbytes, UV lowp, U
return count;
}
-}
-}
/*
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git
More information about the Pkg-perl-cvs-commits
mailing list